Commit dba9dc4e49e4d526a44178817a5aa0e06cdf4629

Authored by Eric Fernandez
1 parent 2beeeb906b
Exists in master

muestro pdf

Showing 2 changed files with 28 additions and 14 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearRemito') .controller('remitoController', 1 angular.module('focaCrearRemito') .controller('remitoController',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout',
4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', 4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService',
5 '$window',
5 function( 6 function(
6 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, 7 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService,
7 remitoBusinessService, $rootScope, focaBotoneraLateralService) 8 remitoBusinessService, $rootScope, focaBotoneraLateralService, $window)
8 { 9 {
9 config(); 10 config();
10 11
11 function config() { 12 function config() {
12 $scope.botonera = crearRemitoService.getBotonera(); 13 $scope.botonera = crearRemitoService.getBotonera();
13 $scope.isNumber = angular.isNumber; 14 $scope.isNumber = angular.isNumber;
14 $scope.datepickerAbierto = false; 15 $scope.datepickerAbierto = false;
15 $scope.show = false; 16 $scope.show = false;
16 $scope.cargando = true; 17 $scope.cargando = true;
17 $scope.now = new Date(); 18 $scope.now = new Date();
18 $scope.puntoVenta = rellenar(0, 4); 19 $scope.puntoVenta = rellenar(0, 4);
19 $scope.comprobante = rellenar(0, 8); 20 $scope.comprobante = rellenar(0, 8);
20 $scope.dateOptions = { 21 $scope.dateOptions = {
21 maxDate: new Date(), 22 maxDate: new Date(),
22 minDate: new Date(2010, 0, 1) 23 minDate: new Date(2010, 0, 1)
23 }; 24 };
24 25
25 var monedaPorDefecto; 26 var monedaPorDefecto;
26 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 27 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
27 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { 28 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) {
28 monedaPorDefecto = res.data[0]; 29 monedaPorDefecto = res.data[0];
29 30
30 $scope.remito.moneda = monedaPorDefecto; 31 $scope.remito.moneda = monedaPorDefecto;
31 $scope.inicial.remito.moneda = $scope.remito.moneda; 32 $scope.inicial.remito.moneda = $scope.remito.moneda;
32 33
33 $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; 34 $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0];
34 $scope.inicial.remito.cotizacion = $scope.remito.cotizacion; 35 $scope.inicial.remito.cotizacion = $scope.remito.cotizacion;
35 }); 36 });
36 37
37 //SETEO BOTONERA LATERAL 38 //SETEO BOTONERA LATERAL
38 $timeout(function() { 39 $timeout(function() {
39 focaBotoneraLateralService.showSalir(false); 40 focaBotoneraLateralService.showSalir(false);
40 focaBotoneraLateralService.showPausar(true); 41 focaBotoneraLateralService.showPausar(true);
41 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); 42 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito);
42 focaBotoneraLateralService.addCustomButton('Salir', salir); 43 focaBotoneraLateralService.addCustomButton('Salir', salir);
43 }); 44 });
44 45
45 init(); 46 init();
46 } 47 }
47 48
48 function init() { 49 function init() {
49 $scope.$broadcast('cleanCabecera'); 50 $scope.$broadcast('cleanCabecera');
50 51
51 $scope.remito = { 52 $scope.remito = {
52 id: 0, 53 id: 0,
53 estado: 0, 54 estado: 0,
54 vendedor: {}, 55 vendedor: {},
55 cliente: {}, 56 cliente: {},
56 proveedor: {}, 57 proveedor: {},
57 domicilio: {dom: ''}, 58 domicilio: {dom: ''},
58 moneda: {}, 59 moneda: {},
59 cotizacion: {} 60 cotizacion: {}
60 }; 61 };
61 62
62 $scope.notaPedido = { 63 $scope.notaPedido = {
63 id: 0 64 id: 0
64 }; 65 };
65 66
66 $scope.articulosTabla = []; 67 $scope.articulosTabla = [];
67 $scope.idLista = undefined; 68 $scope.idLista = undefined;
68 69
69 crearRemitoService.getNumeroRemito().then( 70 crearRemitoService.getNumeroRemito().then(
70 function(res) { 71 function(res) {
71 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 72 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
72 $scope.comprobante = rellenar(res.data.numeroRemito, 8); 73 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
73 }, 74 },
74 function(err) { 75 function(err) {
75 focaModalService.alert('La terminal no esta configurada correctamente'); 76 focaModalService.alert('La terminal no esta configurada correctamente');
76 console.info(err); 77 console.info(err);
77 } 78 }
78 ); 79 );
79 80
80 $scope.inicial = { 81 $scope.inicial = {
81 remito: angular.copy($scope.remito), 82 remito: angular.copy($scope.remito),
82 notaPedido: angular.copy($scope.notaPedido), 83 notaPedido: angular.copy($scope.notaPedido),
83 articulosTabla: angular.copy($scope.articulosTabla), 84 articulosTabla: angular.copy($scope.articulosTabla),
84 idLista: angular.copy($scope.idLista) 85 idLista: angular.copy($scope.idLista)
85 }; 86 };
86 } 87 }
87 88
88 $scope.seleccionarNotaPedido = function() { 89 $scope.seleccionarNotaPedido = function() {
89 if(varlidarRemitoFacturado()) { 90 if(varlidarRemitoFacturado()) {
90 var modalInstance = $uibModal.open( 91 var modalInstance = $uibModal.open(
91 { 92 {
92 ariaLabelledBy: 'Busqueda de Nota de Pedido', 93 ariaLabelledBy: 'Busqueda de Nota de Pedido',
93 templateUrl: 'foca-modal-nota-pedido.html', 94 templateUrl: 'foca-modal-nota-pedido.html',
94 controller: 'focaModalNotaPedidoController', 95 controller: 'focaModalNotaPedidoController',
95 size: 'lg', 96 size: 'lg',
96 resolve: { 97 resolve: {
97 usadoPor: function() { return 'remito'; }, 98 usadoPor: function() { return 'remito'; },
98 idVendedor: function() { return null; } 99 idVendedor: function() { return null; }
99 } 100 }
100 } 101 }
101 ); 102 );
102 modalInstance.result.then( 103 modalInstance.result.then(
103 function(notaPedido) { 104 function(notaPedido) {
104 //añado cabeceras 105 //añado cabeceras
105 $scope.notaPedido.id = notaPedido.id; 106 $scope.notaPedido.id = notaPedido.id;
106 $scope.$broadcast('removeCabecera', 'Bomba:'); 107 $scope.$broadcast('removeCabecera', 'Bomba:');
107 $scope.$broadcast('removeCabecera', 'Kilometros:'); 108 $scope.$broadcast('removeCabecera', 'Kilometros:');
108 var cabeceras = [ 109 var cabeceras = [
109 { 110 {
110 label: 'Moneda:', 111 label: 'Moneda:',
111 valor: notaPedido.cotizacion.moneda.DETALLE 112 valor: notaPedido.cotizacion.moneda.DETALLE
112 }, 113 },
113 { 114 {
114 label: 'Fecha cotizacion:', 115 label: 'Fecha cotizacion:',
115 valor: $filter('date')(notaPedido.cotizacion.FECHA, 116 valor: $filter('date')(notaPedido.cotizacion.FECHA,
116 'dd/MM/yyyy') 117 'dd/MM/yyyy')
117 }, 118 },
118 { 119 {
119 label: 'Cotizacion:', 120 label: 'Cotizacion:',
120 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 121 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
121 '2') 122 '2')
122 }, 123 },
123 { 124 {
124 label: 'Cliente:', 125 label: 'Cliente:',
125 valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + 126 valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) +
126 ' - ' + notaPedido.cliente.NOM 127 ' - ' + notaPedido.cliente.NOM
127 }, 128 },
128 { 129 {
129 label: 'Domicilio:', 130 label: 'Domicilio:',
130 valor: notaPedido.domicilioStamp 131 valor: notaPedido.domicilioStamp
131 }, 132 },
132 { 133 {
133 label: 'Vendedor:', 134 label: 'Vendedor:',
134 valor: $filter('rellenarDigitos')( 135 valor: $filter('rellenarDigitos')(
135 notaPedido.vendedor.NUM, 3 136 notaPedido.vendedor.NUM, 3
136 ) + ' - ' + notaPedido.vendedor.NOM 137 ) + ' - ' + notaPedido.vendedor.NOM
137 }, 138 },
138 { 139 {
139 label: 'Proveedor:', 140 label: 'Proveedor:',
140 valor: $filter('rellenarDigitos') 141 valor: $filter('rellenarDigitos')
141 (notaPedido.proveedor.COD, 5) + ' - ' + 142 (notaPedido.proveedor.COD, 5) + ' - ' +
142 notaPedido.proveedor.NOM 143 notaPedido.proveedor.NOM
143 }, 144 },
144 { 145 {
145 label: 'Precio condicion:', 146 label: 'Precio condicion:',
146 valor: valorPrecioCondicion() + ' ' + 147 valor: valorPrecioCondicion() + ' ' +
147 remitoBusinessService 148 remitoBusinessService
148 .plazoToString(notaPedido.notaPedidoPlazo) 149 .plazoToString(notaPedido.notaPedidoPlazo)
149 }, 150 },
150 { 151 {
151 label: 'Flete:', 152 label: 'Flete:',
152 valor: notaPedido.fob === 1 ? 'FOB' : ( 153 valor: notaPedido.fob === 1 ? 'FOB' : (
153 notaPedido.flete === 1 ? 'Si' : 'No') 154 notaPedido.flete === 1 ? 'Si' : 'No')
154 } 155 }
155 ]; 156 ];
156 157
157 function valorPrecioCondicion() { 158 function valorPrecioCondicion() {
158 if(notaPedido.idPrecioCondicion > 0) { 159 if(notaPedido.idPrecioCondicion > 0) {
159 return notaPedido.precioCondicion.nombre; 160 return notaPedido.precioCondicion.nombre;
160 }else { 161 }else {
161 return 'Ingreso Manual'; 162 return 'Ingreso Manual';
162 } 163 }
163 } 164 }
164 165
165 if(notaPedido.flete === 1) { 166 if(notaPedido.flete === 1) {
166 var cabeceraBomba = { 167 var cabeceraBomba = {
167 label: 'Bomba:', 168 label: 'Bomba:',
168 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 169 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
169 }; 170 };
170 if(notaPedido.kilometros) { 171 if(notaPedido.kilometros) {
171 var cabeceraKilometros = { 172 var cabeceraKilometros = {
172 label: 'Kilometros:', 173 label: 'Kilometros:',
173 valor: notaPedido.kilometros 174 valor: notaPedido.kilometros
174 }; 175 };
175 cabeceras.push(cabeceraKilometros); 176 cabeceras.push(cabeceraKilometros);
176 } 177 }
177 cabeceras.push(cabeceraBomba); 178 cabeceras.push(cabeceraBomba);
178 } 179 }
179 180
180 for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { 181 for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) {
181 notaPedido.articulosNotaPedido[i].id = 0; 182 notaPedido.articulosNotaPedido[i].id = 0;
182 } 183 }
183 184
184 $scope.articulosTabla = notaPedido.articulosNotaPedido; 185 $scope.articulosTabla = notaPedido.articulosNotaPedido;
185 remitoBusinessService.calcularArticulos($scope.articulosTabla, 186 remitoBusinessService.calcularArticulos($scope.articulosTabla,
186 notaPedido.cotizacion.VENDEDOR); 187 notaPedido.cotizacion.VENDEDOR);
187 188
188 if(notaPedido.idPrecioCondicion > 0) { 189 if(notaPedido.idPrecioCondicion > 0) {
189 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 190 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
190 }else { 191 }else {
191 $scope.idLista = -1; 192 $scope.idLista = -1;
192 } 193 }
193 194
194 delete notaPedido.id; 195 delete notaPedido.id;
195 $scope.remito = notaPedido; 196 $scope.remito = notaPedido;
196 $scope.remito.id = 0; 197 $scope.remito.id = 0;
197 $scope.remito.moneda = notaPedido.cotizacion.moneda; 198 $scope.remito.moneda = notaPedido.cotizacion.moneda;
198 $scope.plazosPagos = notaPedido.notaPedidoPlazo; 199 $scope.plazosPagos = notaPedido.notaPedidoPlazo;
199 enableObservaciones(notaPedido.observaciones ? true : false); 200 enableObservaciones(notaPedido.observaciones ? true : false);
200 addArrayCabecera(cabeceras); 201 addArrayCabecera(cabeceras);
201 202
202 }, function() { 203 }, function() {
203 // funcion ejecutada cuando se cancela el modal 204 // funcion ejecutada cuando se cancela el modal
204 } 205 }
205 ); 206 );
206 } 207 }
207 }; 208 };
208 209
209 $scope.seleccionarRemito = function() { 210 $scope.seleccionarRemito = function() {
210 var modalInstance = $uibModal.open( 211 var modalInstance = $uibModal.open(
211 { 212 {
212 ariaLabelledBy: 'Busqueda de Remito', 213 ariaLabelledBy: 'Busqueda de Remito',
213 templateUrl: 'foca-modal-remito.html', 214 templateUrl: 'foca-modal-remito.html',
214 controller: 'focaModalRemitoController', 215 controller: 'focaModalRemitoController',
215 size: 'lg', 216 size: 'lg',
216 resolve: {usadoPor: function() {return 'remito';}} 217 resolve: {usadoPor: function() {return 'remito';}}
217 } 218 }
218 ); 219 );
219 modalInstance.result.then( 220 modalInstance.result.then(
220 function(remito) { 221 function(remito) {
221 //añado cabeceras 222 //añado cabeceras
222 $scope.$broadcast('removeCabecera', 'Moneda:'); 223 $scope.$broadcast('removeCabecera', 'Moneda:');
223 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 224 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
224 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 225 $scope.$broadcast('removeCabecera', 'Cotizacion:');
225 var cabeceras = [ 226 var cabeceras = [
226 { 227 {
227 label: 'Moneda:', 228 label: 'Moneda:',
228 valor: remito.cotizacion.moneda.DETALLE 229 valor: remito.cotizacion.moneda.DETALLE
229 }, 230 },
230 { 231 {
231 label: 'Fecha cotizacion:', 232 label: 'Fecha cotizacion:',
232 valor: $filter('date')(remito.cotizacion.FECHA, 233 valor: $filter('date')(remito.cotizacion.FECHA,
233 'dd/MM/yyyy') 234 'dd/MM/yyyy')
234 }, 235 },
235 { 236 {
236 label: 'Cotizacion:', 237 label: 'Cotizacion:',
237 valor: $filter('number')(remito.cotizacion.VENDEDOR, 238 valor: $filter('number')(remito.cotizacion.VENDEDOR,
238 '2') 239 '2')
239 }, 240 },
240 { 241 {
241 label: 'Cliente:', 242 label: 'Cliente:',
242 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 243 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
243 remito.cliente.NOM 244 remito.cliente.NOM
244 }, 245 },
245 { 246 {
246 label: 'Domicilio:', 247 label: 'Domicilio:',
247 valor: remito.domicilioStamp 248 valor: remito.domicilioStamp
248 }, 249 },
249 { 250 {
250 label: 'Vendedor:', 251 label: 'Vendedor:',
251 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 252 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
252 ' - ' + remito.vendedor.NOM 253 ' - ' + remito.vendedor.NOM
253 }, 254 },
254 { 255 {
255 label: 'Proveedor:', 256 label: 'Proveedor:',
256 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 257 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
257 ' - ' + remito.proveedor.NOM 258 ' - ' + remito.proveedor.NOM
258 }, 259 },
259 { 260 {
260 label: 'Flete:', 261 label: 'Flete:',
261 valor: remito.fob === 1 ? 'FOB' : ( 262 valor: remito.fob === 1 ? 'FOB' : (
262 remito.flete === 1 ? 'Si' : 'No') 263 remito.flete === 1 ? 'Si' : 'No')
263 }, 264 },
264 { 265 {
265 label: 'Precio condicion:', 266 label: 'Precio condicion:',
266 valor: valorPrecioCondicion() + ' ' + 267 valor: valorPrecioCondicion() + ' ' +
267 remitoBusinessService.plazoToString(remito.remitoPlazo) 268 remitoBusinessService.plazoToString(remito.remitoPlazo)
268 } 269 }
269 ]; 270 ];
270 function valorPrecioCondicion() { 271 function valorPrecioCondicion() {
271 if(remito.idPrecioCondicion > 0) { 272 if(remito.idPrecioCondicion > 0) {
272 return remito.precioCondicion.nombre; 273 return remito.precioCondicion.nombre;
273 }else { 274 }else {
274 return 'Ingreso Manual'; 275 return 'Ingreso Manual';
275 } 276 }
276 } 277 }
277 278
278 if(remito.flete === 1) { 279 if(remito.flete === 1) {
279 var cabeceraBomba = { 280 var cabeceraBomba = {
280 label: 'Bomba', 281 label: 'Bomba',
281 valor: remito.bomba === 1 ? 'Si' : 'No' 282 valor: remito.bomba === 1 ? 'Si' : 'No'
282 }; 283 };
283 if(remito.kilometros) { 284 if(remito.kilometros) {
284 var cabeceraKilometros = { 285 var cabeceraKilometros = {
285 label: 'Kilometros', 286 label: 'Kilometros',
286 valor: remito.kilometros 287 valor: remito.kilometros
287 }; 288 };
288 cabeceras.push(cabeceraKilometros); 289 cabeceras.push(cabeceraKilometros);
289 } 290 }
290 cabeceras.push(cabeceraBomba); 291 cabeceras.push(cabeceraBomba);
291 } 292 }
292 $scope.articulosTabla = remito.articulosRemito; 293 $scope.articulosTabla = remito.articulosRemito;
293 remitoBusinessService.calcularArticulos($scope.articulosTabla, 294 remitoBusinessService.calcularArticulos($scope.articulosTabla,
294 remito.cotizacion.VENDEDOR); 295 remito.cotizacion.VENDEDOR);
295 if(remito.idPrecioCondicion > 0) { 296 if(remito.idPrecioCondicion > 0) {
296 $scope.idLista = remito.precioCondicion.idListaPrecio; 297 $scope.idLista = remito.precioCondicion.idListaPrecio;
297 }else { 298 }else {
298 $scope.idLista = -1; 299 $scope.idLista = -1;
299 } 300 }
300 $scope.puntoVenta = rellenar(remito.sucursal, 4); 301 $scope.puntoVenta = rellenar(remito.sucursal, 4);
301 $scope.comprobante = rellenar(remito.numeroRemito, 8); 302 $scope.comprobante = rellenar(remito.numeroRemito, 8);
302 $scope.remito = remito; 303 $scope.remito = remito;
303 $scope.remito.moneda = remito.cotizacion.moneda; 304 $scope.remito.moneda = remito.cotizacion.moneda;
304 $scope.plazosPagos = remito.remitoPlazo; 305 $scope.plazosPagos = remito.remitoPlazo;
305 addArrayCabecera(cabeceras); 306 addArrayCabecera(cabeceras);
306 }, function() { 307 }, function() {
307 // funcion ejecutada cuando se cancela el modal 308 // funcion ejecutada cuando se cancela el modal
308 } 309 }
309 ); 310 );
310 }; 311 };
311 312
312 //validacion por domicilio y por plazo pago 313 //validacion por domicilio y por plazo pago
313 $scope.crearRemito = function() { 314 $scope.crearRemito = function() {
314 if(!$scope.remito.vendedor) { 315 if(!$scope.remito.vendedor) {
315 focaModalService.alert('Ingrese Vendedor'); 316 focaModalService.alert('Ingrese Vendedor');
316 return; 317 return;
317 }else if(!$scope.remito.cliente) { 318 }else if(!$scope.remito.cliente) {
318 focaModalService.alert('Ingrese Cliente'); 319 focaModalService.alert('Ingrese Cliente');
319 return; 320 return;
320 }else if(!$scope.remito.proveedor) { 321 }else if(!$scope.remito.proveedor) {
321 focaModalService.alert('Ingrese Proveedor'); 322 focaModalService.alert('Ingrese Proveedor');
322 return; 323 return;
323 }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) { 324 }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) {
324 focaModalService.alert('Ingrese Moneda'); 325 focaModalService.alert('Ingrese Moneda');
325 return; 326 return;
326 }else if(!$scope.remito.cotizacion.ID) { 327 }else if(!$scope.remito.cotizacion.ID) {
327 focaModalService.alert('Ingrese Cotización'); 328 focaModalService.alert('Ingrese Cotización');
328 return; 329 return;
329 }else if( 330 }else if(
330 $scope.remito.flete === undefined || $scope.remito.flete === null) 331 $scope.remito.flete === undefined || $scope.remito.flete === null)
331 { 332 {
332 focaModalService.alert('Ingrese Flete'); 333 focaModalService.alert('Ingrese Flete');
333 return; 334 return;
334 }else if($scope.articulosTabla.length === 0) { 335 }else if($scope.articulosTabla.length === 0) {
335 focaModalService.alert('Debe cargar al menos un articulo'); 336 focaModalService.alert('Debe cargar al menos un articulo');
336 return; 337 return;
337 } 338 }
338 focaBotoneraLateralService.startGuardar(); 339 focaBotoneraLateralService.startGuardar();
339 $scope.saveLoading = true; 340 $scope.saveLoading = true;
340 var save = { 341 var save = {
341 remito: { 342 remito: {
342 id: $scope.remito.id, 343 id: $scope.remito.id,
343 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 344 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
344 idCliente: $scope.remito.cliente.COD, 345 idCliente: $scope.remito.cliente.COD,
345 nombreCliente: $scope.remito.cliente.NOM, 346 nombreCliente: $scope.remito.cliente.NOM,
346 cuitCliente: $scope.remito.cliente.CUIT, 347 cuitCliente: $scope.remito.cliente.CUIT,
347 responsabilidadIvaCliente: 0,//TODO, 348 responsabilidadIvaCliente: 0,//TODO,
348 descuento: 0,//TODO, 349 descuento: 0,//TODO,
349 importeNeto: 0,//TODO 350 importeNeto: 0,//TODO
350 importeExento: 0,//TODO 351 importeExento: 0,//TODO
351 importeIva: 0,//TODO 352 importeIva: 0,//TODO
352 importeIvaServicios: 0,//TODO 353 importeIvaServicios: 0,//TODO
353 importeImpuestoInterno: 0,//TODO 354 importeImpuestoInterno: 0,//TODO
354 importeImpuestoInterno1: 0,//TODO 355 importeImpuestoInterno1: 0,//TODO
355 importeImpuestoInterno2: 0,//TODO 356 importeImpuestoInterno2: 0,//TODO
356 percepcion: 0,//TODO 357 percepcion: 0,//TODO
357 percepcionIva: 0,//TODO 358 percepcionIva: 0,//TODO
358 redondeo: 0,//TODO 359 redondeo: 0,//TODO
359 total: $scope.getTotal(), 360 total: $scope.getTotal(),
360 numeroNotaPedido: $scope.remito.numeroNotaPedido, 361 numeroNotaPedido: $scope.remito.numeroNotaPedido,
361 anulado: false, 362 anulado: false,
362 planilla: 0,//TODO 363 planilla: 0,//TODO
363 lugar: 0,//TODO 364 lugar: 0,//TODO
364 cuentaMadre: 0,// 365 cuentaMadre: 0,//
365 cuentaContable: 0,//TODO 366 cuentaContable: 0,//TODO
366 asiento: 0,//TODO 367 asiento: 0,//TODO
367 e_hd: '',//TODO 368 e_hd: '',//TODO
368 c_hd: '', 369 c_hd: '',
369 numeroLiquidoProducto: 0,//TODO 370 numeroLiquidoProducto: 0,//TODO
370 idVendedor: $scope.remito.idVendedor, 371 idVendedor: $scope.remito.idVendedor,
371 idProveedor: $scope.remito.idProveedor, 372 idProveedor: $scope.remito.idProveedor,
372 idDomicilio: 0,//TODO 373 idDomicilio: 0,//TODO
373 idCotizacion: $scope.remito.cotizacion.ID, 374 idCotizacion: $scope.remito.cotizacion.ID,
374 idPrecioCondicion: $scope.remito.idPrecioCondicion, 375 idPrecioCondicion: $scope.remito.idPrecioCondicion,
375 flete: $scope.remito.flete, 376 flete: $scope.remito.flete,
376 fob: $scope.remito.fob, 377 fob: $scope.remito.fob,
377 bomba: $scope.remito.bomba, 378 bomba: $scope.remito.bomba,
378 kilometros: $scope.remito.kilometros, 379 kilometros: $scope.remito.kilometros,
379 domicilioStamp: $scope.remito.domicilioStamp, 380 domicilioStamp: $scope.remito.domicilioStamp,
380 estado: 0,//TODO 381 estado: 0,//TODO
381 destinoVenta: 0,//TODO 382 destinoVenta: 0,//TODO
382 operacionTipo: 0//TODO 383 operacionTipo: 0//TODO
383 }, 384 },
384 notaPedido: $scope.notaPedido 385 notaPedido: $scope.notaPedido
385 }; 386 };
386 crearRemitoService.crearRemito(save).then( 387 crearRemitoService.crearRemito(save).then(
387 function(data) { 388 function(data) {
388 remitoBusinessService.addArticulos($scope.articulosTabla, 389 remitoBusinessService.addArticulos($scope.articulosTabla,
389 data.data.id, $scope.remito.cotizacion.COTIZACION); 390 data.data.id, $scope.remito.cotizacion.COTIZACION);
390 391
391 focaBotoneraLateralService.endGuardar(true); 392 focaBotoneraLateralService.endGuardar(true);
392 $scope.saveLoading = false; 393 $scope.saveLoading = false;
393 //TODO: updatear plazos 394 //TODO: updatear plazos
394 if($scope.remito.id === 0) { 395 if($scope.remito.id === 0) {
395 var plazos = $scope.plazosPagos; 396 var plazos = $scope.plazosPagos;
396 397
397 for(var j = 0; j < plazos.length; j++) { 398 for(var j = 0; j < plazos.length; j++) {
398 var json = { 399 var json = {
399 idRemito: data.data.id, 400 idRemito: data.data.id,
400 dias: plazos[j].dias 401 dias: plazos[j].dias
401 }; 402 };
402 crearRemitoService.crearPlazosParaRemito(json); 403 crearRemitoService.crearPlazosParaRemito(json);
403 } 404 }
404 } 405 }
405 406 crearRemitoService.imprimirRemitoByIdRemito(data.data.id).then(
407 function(res) {
408
409 var printWindow = $window.open('', '', 'height=1000,width=800');
410 printWindow.document.write(res.data);
411 printWindow.document.close();
412 printWindow.print();
413
414 }
415 );
406 init(); 416 init();
407 }, function(error) { 417 }, function(error) {
408 focaModalService.alert('Hubo un error al crear el remito'); 418 focaModalService.alert('Hubo un error al crear el remito');
409 focaBotoneraLateralService.endGuardar(); 419 focaBotoneraLateralService.endGuardar();
410 $scope.saveLoading = false; 420 $scope.saveLoading = false;
411 console.info(error); 421 console.info(error);
412 } 422 }
413 ); 423 );
414 }; 424 };
415 425
416 $scope.seleccionarProductos = function() { 426 $scope.seleccionarProductos = function() {
417 if($scope.idLista === undefined) { 427 if($scope.idLista === undefined) {
418 focaModalService.alert( 428 focaModalService.alert(
419 'Primero seleccione una lista de precio y condicion'); 429 'Primero seleccione una lista de precio y condicion');
420 return; 430 return;
421 } 431 }
422 var modalInstance = $uibModal.open( 432 var modalInstance = $uibModal.open(
423 { 433 {
424 ariaLabelledBy: 'Busqueda de Productos', 434 ariaLabelledBy: 'Busqueda de Productos',
425 templateUrl: 'modal-busqueda-productos.html', 435 templateUrl: 'modal-busqueda-productos.html',
426 controller: 'modalBusquedaProductosCtrl', 436 controller: 'modalBusquedaProductosCtrl',
427 resolve: { 437 resolve: {
428 parametroProducto: { 438 parametroProducto: {
429 idLista: $scope.idLista, 439 idLista: $scope.idLista,
430 cotizacion: $scope.remito.cotizacion.COTIZACION, 440 cotizacion: $scope.remito.cotizacion.COTIZACION,
431 simbolo: $scope.remito.moneda.simbolo 441 simbolo: $scope.remito.moneda.simbolo
432 } 442 }
433 }, 443 },
434 size: 'lg' 444 size: 'lg'
435 } 445 }
436 ); 446 );
437 modalInstance.result.then( 447 modalInstance.result.then(
438 function(producto) { 448 function(producto) {
439 var newArt = 449 var newArt =
440 { 450 {
441 id: 0, 451 id: 0,
442 codigo: producto.codigo, 452 codigo: producto.codigo,
443 sector: producto.sector, 453 sector: producto.sector,
444 sectorCodigo: producto.sector + '-' + producto.codigo, 454 sectorCodigo: producto.sector + '-' + producto.codigo,
445 descripcion: producto.descripcion, 455 descripcion: producto.descripcion,
446 item: $scope.articulosTabla.length + 1, 456 item: $scope.articulosTabla.length + 1,
447 nombre: producto.descripcion, 457 nombre: producto.descripcion,
448 precio: parseFloat(producto.precio.toFixed(4)), 458 precio: parseFloat(producto.precio.toFixed(4)),
449 costoUnitario: producto.costo, 459 costoUnitario: producto.costo,
450 editCantidad: false, 460 editCantidad: false,
451 editPrecio: false, 461 editPrecio: false,
452 rubro: producto.CodRub, 462 rubro: producto.CodRub,
453 exentoUnitario: producto.precio, 463 exentoUnitario: producto.precio,
454 ivaUnitario: producto.IMPIVA, 464 ivaUnitario: producto.IMPIVA,
455 impuestoInternoUnitario: producto.ImpInt, 465 impuestoInternoUnitario: producto.ImpInt,
456 impuestoInterno1Unitario: producto.ImpInt2, 466 impuestoInterno1Unitario: producto.ImpInt2,
457 impuestoInterno2Unitario: producto.ImpInt3, 467 impuestoInterno2Unitario: producto.ImpInt3,
458 precioLista: producto.precio, 468 precioLista: producto.precio,
459 combustible: 1, 469 combustible: 1,
460 facturado: 0 470 facturado: 0
461 }; 471 };
462 $scope.articuloACargar = newArt; 472 $scope.articuloACargar = newArt;
463 $scope.cargando = false; 473 $scope.cargando = false;
464 }, function() { 474 }, function() {
465 // funcion ejecutada cuando se cancela el modal 475 // funcion ejecutada cuando se cancela el modal
466 } 476 }
467 ); 477 );
468 }; 478 };
469 479
470 $scope.seleccionarVendedor = function() { 480 $scope.seleccionarVendedor = function() {
471 if(varlidarRemitoFacturado()) { 481 if(varlidarRemitoFacturado()) {
472 var parametrosModal = { 482 var parametrosModal = {
473 titulo: 'Búsqueda vendedores', 483 titulo: 'Búsqueda vendedores',
474 query: '/vendedor', 484 query: '/vendedor',
475 columnas: [ 485 columnas: [
476 { 486 {
477 propiedad: 'NUM', 487 propiedad: 'NUM',
478 nombre: 'Código', 488 nombre: 'Código',
479 filtro: { 489 filtro: {
480 nombre: 'rellenarDigitos', 490 nombre: 'rellenarDigitos',
481 parametro: 3 491 parametro: 3
482 } 492 }
483 }, 493 },
484 { 494 {
485 propiedad: 'NOM', 495 propiedad: 'NOM',
486 nombre: 'Nombre' 496 nombre: 'Nombre'
487 } 497 }
488 ], 498 ],
489 size: 'md' 499 size: 'md'
490 }; 500 };
491 focaModalService.modal(parametrosModal).then( 501 focaModalService.modal(parametrosModal).then(
492 function(vendedor) { 502 function(vendedor) {
493 $scope.$broadcast('addCabecera',{ 503 $scope.$broadcast('addCabecera',{
494 label: 'Vendedor:', 504 label: 'Vendedor:',
495 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 505 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
496 vendedor.NOM 506 vendedor.NOM
497 }); 507 });
498 $scope.remito.idVendedor = vendedor.id; 508 $scope.remito.idVendedor = vendedor.id;
499 $scope.vendedor = vendedor; 509 $scope.vendedor = vendedor;
500 }, function() { 510 }, function() {
501 511
502 } 512 }
503 ); 513 );
504 } 514 }
505 }; 515 };
506 516
507 $scope.seleccionarProveedor = function() { 517 $scope.seleccionarProveedor = function() {
508 if(varlidarRemitoFacturado()) { 518 if(varlidarRemitoFacturado()) {
509 var parametrosModal = { 519 var parametrosModal = {
510 titulo: 'Búsqueda de Proveedor', 520 titulo: 'Búsqueda de Proveedor',
511 query: '/proveedor', 521 query: '/proveedor',
512 columnas: [ 522 columnas: [
513 { 523 {
514 nombre: 'Código', 524 nombre: 'Código',
515 propiedad: 'COD', 525 propiedad: 'COD',
516 filtro: { 526 filtro: {
517 nombre: 'rellenarDigitos', 527 nombre: 'rellenarDigitos',
518 parametro: 5 528 parametro: 5
519 } 529 }
520 }, 530 },
521 { 531 {
522 nombre: 'Nombre', 532 nombre: 'Nombre',
523 propiedad: 'NOM' 533 propiedad: 'NOM'
524 }, 534 },
525 { 535 {
526 nombre: 'CUIT', 536 nombre: 'CUIT',
527 propiedad: 'CUIT' 537 propiedad: 'CUIT'
528 } 538 }
529 ], 539 ],
530 tipo: 'POST', 540 tipo: 'POST',
531 json: {razonCuitCod: ''} 541 json: {razonCuitCod: ''}
532 }; 542 };
533 focaModalService.modal(parametrosModal).then( 543 focaModalService.modal(parametrosModal).then(
534 function(proveedor) { 544 function(proveedor) {
535 $scope.remito.idProveedor = proveedor.COD; 545 $scope.remito.idProveedor = proveedor.COD;
536 $scope.$broadcast('addCabecera',{ 546 $scope.$broadcast('addCabecera',{
537 label: 'Proveedor:', 547 label: 'Proveedor:',
538 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 548 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
539 proveedor.NOM 549 proveedor.NOM
540 }); 550 });
541 }, function() { 551 }, function() {
542 552
543 } 553 }
544 ); 554 );
545 } 555 }
546 }; 556 };
547 557
548 $scope.seleccionarCliente = function() { 558 $scope.seleccionarCliente = function() {
549 if(!$scope.vendedor) { 559 if(!$scope.vendedor) {
550 focaModalService.alert('Primero seleccione un vendedor'); 560 focaModalService.alert('Primero seleccione un vendedor');
551 return; 561 return;
552 } 562 }
553 563
554 if(varlidarRemitoFacturado()) { 564 if(varlidarRemitoFacturado()) {
555 var modalInstance = $uibModal.open( 565 var modalInstance = $uibModal.open(
556 { 566 {
557 ariaLabelledBy: 'Busqueda de Cliente', 567 ariaLabelledBy: 'Busqueda de Cliente',
558 templateUrl: 'foca-busqueda-cliente-modal.html', 568 templateUrl: 'foca-busqueda-cliente-modal.html',
559 controller: 'focaBusquedaClienteModalController', 569 controller: 'focaBusquedaClienteModalController',
560 resolve: { 570 resolve: {
561 vendedor: function() { return $scope.vendedor; } 571 vendedor: function() { return $scope.vendedor; }
562 }, 572 },
563 size: 'lg' 573 size: 'lg'
564 } 574 }
565 ); 575 );
566 modalInstance.result.then( 576 modalInstance.result.then(
567 function(cliente) { 577 function(cliente) {
568 $scope.abrirModalDomicilios(cliente); 578 $scope.abrirModalDomicilios(cliente);
569 }, function() { 579 }, function() {
570 580
571 } 581 }
572 ); 582 );
573 } 583 }
574 }; 584 };
575 585
576 $scope.abrirModalDomicilios = function(cliente) { 586 $scope.abrirModalDomicilios = function(cliente) {
577 var modalInstanceDomicilio = $uibModal.open( 587 var modalInstanceDomicilio = $uibModal.open(
578 { 588 {
579 ariaLabelledBy: 'Busqueda de Domicilios', 589 ariaLabelledBy: 'Busqueda de Domicilios',
580 templateUrl: 'modal-domicilio.html', 590 templateUrl: 'modal-domicilio.html',
581 controller: 'focaModalDomicilioController', 591 controller: 'focaModalDomicilioController',
582 size: 'lg', 592 size: 'lg',
583 resolve: { 593 resolve: {
584 idCliente: function() { return cliente.cod; }, 594 idCliente: function() { return cliente.cod; },
585 esNuevo: function() { return cliente.esNuevo; } 595 esNuevo: function() { return cliente.esNuevo; }
586 } 596 }
587 } 597 }
588 ); 598 );
589 modalInstanceDomicilio.result.then( 599 modalInstanceDomicilio.result.then(
590 function(domicilio) { 600 function(domicilio) {
591 //$scope.remito.domicilio.id = domicilio.nivel2; 601 //$scope.remito.domicilio.id = domicilio.nivel2;
592 $scope.remito.cliente = { 602 $scope.remito.cliente = {
593 COD: cliente.cod, 603 COD: cliente.cod,
594 CUIT: cliente.cuit, 604 CUIT: cliente.cuit,
595 NOM: cliente.nom 605 NOM: cliente.nom
596 }; 606 };
597 607
598 608
599 var domicilioStamp = 609 var domicilioStamp =
600 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 610 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
601 domicilio.Localidad + ', ' + domicilio.Provincia; 611 domicilio.Localidad + ', ' + domicilio.Provincia;
602 $scope.remito.domicilioStamp = domicilioStamp; 612 $scope.remito.domicilioStamp = domicilioStamp;
603 613
604 $scope.$broadcast('addCabecera',{ 614 $scope.$broadcast('addCabecera',{
605 label: 'Cliente:', 615 label: 'Cliente:',
606 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 616 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
607 }); 617 });
608 $scope.$broadcast('addCabecera',{ 618 $scope.$broadcast('addCabecera',{
609 label: 'Domicilio:', 619 label: 'Domicilio:',
610 valor: domicilioStamp 620 valor: domicilioStamp
611 }); 621 });
612 }, function() { 622 }, function() {
613 $scope.seleccionarCliente(); 623 $scope.seleccionarCliente();
614 return; 624 return;
615 } 625 }
616 ); 626 );
617 }; 627 };
618 628
619 $scope.mostrarFichaCliente = function() { 629 $scope.mostrarFichaCliente = function() {
620 $uibModal.open( 630 $uibModal.open(
621 { 631 {
622 ariaLabelledBy: 'Datos del Cliente', 632 ariaLabelledBy: 'Datos del Cliente',
623 templateUrl: 'foca-crear-remito-ficha-cliente.html', 633 templateUrl: 'foca-crear-remito-ficha-cliente.html',
624 controller: 'focaCrearRemitoFichaClienteController', 634 controller: 'focaCrearRemitoFichaClienteController',
625 size: 'lg' 635 size: 'lg'
626 } 636 }
627 ); 637 );
628 }; 638 };
629 639
630 $scope.getTotal = function() { 640 $scope.getTotal = function() {
631 var total = 0; 641 var total = 0;
632 var arrayTempArticulos = $scope.articulosTabla; 642 var arrayTempArticulos = $scope.articulosTabla;
633 for(var i = 0; i < arrayTempArticulos.length; i++) { 643 for(var i = 0; i < arrayTempArticulos.length; i++) {
634 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 644 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
635 } 645 }
636 return parseFloat(total.toFixed(2)); 646 return parseFloat(total.toFixed(2));
637 }; 647 };
638 648
639 $scope.getSubTotal = function() { 649 $scope.getSubTotal = function() {
640 if($scope.articuloACargar) { 650 if($scope.articuloACargar) {
641 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 651 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
642 } 652 }
643 }; 653 };
644 654
645 $scope.seleccionarPreciosYCondiciones = function() { 655 $scope.seleccionarPreciosYCondiciones = function() {
646 if(varlidarRemitoFacturado()) { 656 if(varlidarRemitoFacturado()) {
647 var modalInstance = $uibModal.open( 657 var modalInstance = $uibModal.open(
648 { 658 {
649 ariaLabelledBy: 'Busqueda de Precio Condición', 659 ariaLabelledBy: 'Busqueda de Precio Condición',
650 templateUrl: 'modal-precio-condicion.html', 660 templateUrl: 'modal-precio-condicion.html',
651 controller: 'focaModalPrecioCondicionController', 661 controller: 'focaModalPrecioCondicionController',
652 size: 'lg' 662 size: 'lg'
653 } 663 }
654 ); 664 );
655 modalInstance.result.then( 665 modalInstance.result.then(
656 function(precioCondicion) { 666 function(precioCondicion) {
657 var cabecera = ''; 667 var cabecera = '';
658 var plazosConcat = ''; 668 var plazosConcat = '';
659 if(!Array.isArray(precioCondicion)) { 669 if(!Array.isArray(precioCondicion)) {
660 $scope.remito.idPrecioCondicion = precioCondicion.id; 670 $scope.remito.idPrecioCondicion = precioCondicion.id;
661 $scope.plazosPagos = precioCondicion.plazoPago; 671 $scope.plazosPagos = precioCondicion.plazoPago;
662 $scope.idLista = precioCondicion.idListaPrecio; 672 $scope.idLista = precioCondicion.idListaPrecio;
663 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 673 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
664 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 674 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
665 } 675 }
666 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 676 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
667 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 677 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
668 }else { //Cuando se ingresan los plazos manualmente 678 }else { //Cuando se ingresan los plazos manualmente
669 $scope.remito.idPrecioCondicion = 0; 679 $scope.remito.idPrecioCondicion = 0;
670 //-1, el modal productos busca todos los productos 680 //-1, el modal productos busca todos los productos
671 $scope.idLista = -1; 681 $scope.idLista = -1;
672 $scope.plazosPagos = precioCondicion; 682 $scope.plazosPagos = precioCondicion;
673 for(var j = 0; j < precioCondicion.length; j++) { 683 for(var j = 0; j < precioCondicion.length; j++) {
674 plazosConcat += precioCondicion[j].dias + ' '; 684 plazosConcat += precioCondicion[j].dias + ' ';
675 } 685 }
676 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 686 cabecera = 'Ingreso manual ' + plazosConcat.trim();
677 } 687 }
678 $scope.articulosTabla = []; 688 $scope.articulosTabla = [];
679 $scope.$broadcast('addCabecera',{ 689 $scope.$broadcast('addCabecera',{
680 label: 'Precios y condiciones:', 690 label: 'Precios y condiciones:',
681 valor: cabecera 691 valor: cabecera
682 }); 692 });
683 }, function() { 693 }, function() {
684 694
685 } 695 }
686 ); 696 );
687 } 697 }
688 }; 698 };
689 699
690 $scope.seleccionarFlete = function() { 700 $scope.seleccionarFlete = function() {
691 if(varlidarRemitoFacturado()) { 701 if(varlidarRemitoFacturado()) {
692 var modalInstance = $uibModal.open( 702 var modalInstance = $uibModal.open(
693 { 703 {
694 ariaLabelledBy: 'Busqueda de Flete', 704 ariaLabelledBy: 'Busqueda de Flete',
695 templateUrl: 'modal-flete.html', 705 templateUrl: 'modal-flete.html',
696 controller: 'focaModalFleteController', 706 controller: 'focaModalFleteController',
697 size: 'lg', 707 size: 'lg',
698 resolve: { 708 resolve: {
699 parametrosFlete: 709 parametrosFlete:
700 function() { 710 function() {
701 return { 711 return {
702 flete: $scope.remito.flete ? '1' : 712 flete: $scope.remito.flete ? '1' :
703 ($scope.remito.fob ? 'FOB' : 713 ($scope.remito.fob ? 'FOB' :
704 ($scope.remito.flete === undefined ? null : '0')), 714 ($scope.remito.flete === undefined ? null : '0')),
705 bomba: $scope.remito.bomba ? '1' : 715 bomba: $scope.remito.bomba ? '1' :
706 ($scope.remito.bomba === undefined ? null : '0'), 716 ($scope.remito.bomba === undefined ? null : '0'),
707 kilometros: $scope.remito.kilometros 717 kilometros: $scope.remito.kilometros
708 }; 718 };
709 } 719 }
710 } 720 }
711 } 721 }
712 ); 722 );
713 modalInstance.result.then( 723 modalInstance.result.then(
714 function(datos) { 724 function(datos) {
715 $scope.remito.flete = datos.flete; 725 $scope.remito.flete = datos.flete;
716 $scope.remito.fob = datos.FOB; 726 $scope.remito.fob = datos.FOB;
717 $scope.remito.bomba = datos.bomba; 727 $scope.remito.bomba = datos.bomba;
718 $scope.remito.kilometros = datos.kilometros; 728 $scope.remito.kilometros = datos.kilometros;
719 729
720 $scope.$broadcast('addCabecera',{ 730 $scope.$broadcast('addCabecera',{
721 label: 'Flete:', 731 label: 'Flete:',
722 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 732 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
723 }); 733 });
724 if(datos.flete) { 734 if(datos.flete) {
725 $scope.$broadcast('addCabecera',{ 735 $scope.$broadcast('addCabecera',{
726 label: 'Bomba:', 736 label: 'Bomba:',
727 valor: datos.bomba ? 'Si' : 'No' 737 valor: datos.bomba ? 'Si' : 'No'
728 }); 738 });
729 $scope.$broadcast('addCabecera',{ 739 $scope.$broadcast('addCabecera',{
730 label: 'Kilometros:', 740 label: 'Kilometros:',
731 valor: datos.kilometros 741 valor: datos.kilometros
732 }); 742 });
733 }else { 743 }else {
734 $scope.$broadcast('removeCabecera', 'Bomba:'); 744 $scope.$broadcast('removeCabecera', 'Bomba:');
735 $scope.$broadcast('removeCabecera', 'Kilometros:'); 745 $scope.$broadcast('removeCabecera', 'Kilometros:');
736 $scope.remito.fob = false; 746 $scope.remito.fob = false;
737 $scope.remito.bomba = false; 747 $scope.remito.bomba = false;
738 $scope.remito.kilometros = null; 748 $scope.remito.kilometros = null;
739 } 749 }
740 }, function() { 750 }, function() {
741 751
742 } 752 }
743 ); 753 );
744 } 754 }
745 }; 755 };
746 756
747 $scope.seleccionarMoneda = function() { 757 $scope.seleccionarMoneda = function() {
748 if(varlidarRemitoFacturado()) { 758 if(varlidarRemitoFacturado()) {
749 var parametrosModal = { 759 var parametrosModal = {
750 titulo: 'Búsqueda de monedas', 760 titulo: 'Búsqueda de monedas',
751 query: '/moneda', 761 query: '/moneda',
752 columnas: [ 762 columnas: [
753 { 763 {
754 propiedad: 'DETALLE', 764 propiedad: 'DETALLE',
755 nombre: 'Nombre' 765 nombre: 'Nombre'
756 }, 766 },
757 { 767 {
758 propiedad: 'SIMBOLO', 768 propiedad: 'SIMBOLO',
759 nombre: 'Símbolo' 769 nombre: 'Símbolo'
760 } 770 }
761 ], 771 ],
762 size: 'md' 772 size: 'md'
763 }; 773 };
764 focaModalService.modal(parametrosModal).then( 774 focaModalService.modal(parametrosModal).then(
765 function(moneda) { 775 function(moneda) {
766 $scope.abrirModalCotizacion(moneda); 776 $scope.abrirModalCotizacion(moneda);
767 }, function() { 777 }, function() {
768 778
769 } 779 }
770 ); 780 );
771 } 781 }
772 }; 782 };
773 783
774 $scope.seleccionarObservaciones = function() { 784 $scope.seleccionarObservaciones = function() {
775 focaModalService 785 focaModalService
776 .prompt('Ingrese observaciones', $scope.remito.observaciones, true) 786 .prompt('Ingrese observaciones', $scope.remito.observaciones, true)
777 .then(function(observaciones) { 787 .then(function(observaciones) {
778 $scope.remito.observaciones = observaciones; 788 $scope.remito.observaciones = observaciones;
779 }); 789 });
780 }; 790 };
781 791
782 $scope.abrirModalCotizacion = function(moneda) { 792 $scope.abrirModalCotizacion = function(moneda) {
783 var modalInstance = $uibModal.open( 793 var modalInstance = $uibModal.open(
784 { 794 {
785 ariaLabelledBy: 'Busqueda de Cotización', 795 ariaLabelledBy: 'Busqueda de Cotización',
786 templateUrl: 'modal-cotizacion.html', 796 templateUrl: 'modal-cotizacion.html',
787 controller: 'focaModalCotizacionController', 797 controller: 'focaModalCotizacionController',
788 size: 'lg', 798 size: 'lg',
789 resolve: {idMoneda: function() {return moneda.ID;}} 799 resolve: {idMoneda: function() {return moneda.ID;}}
790 } 800 }
791 ); 801 );
792 modalInstance.result.then( 802 modalInstance.result.then(
793 function(cotizacion) { 803 function(cotizacion) {
794 var articulosTablaTemp = $scope.articulosTabla; 804 var articulosTablaTemp = $scope.articulosTabla;
795 for(var i = 0; i < articulosTablaTemp.length; i++) { 805 for(var i = 0; i < articulosTablaTemp.length; i++) {
796 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 806 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
797 $scope.remito.cotizacion.COTIZACION; 807 $scope.remito.cotizacion.COTIZACION;
798 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 808 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
799 cotizacion.COTIZACION; 809 cotizacion.COTIZACION;
800 } 810 }
801 $scope.articulosTabla = articulosTablaTemp; 811 $scope.articulosTabla = articulosTablaTemp;
802 $scope.remito.moneda = moneda; 812 $scope.remito.moneda = moneda;
803 $scope.remito.cotizacion = cotizacion; 813 $scope.remito.cotizacion = cotizacion;
804 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 814 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
805 $scope.$broadcast('removeCabecera', 'Moneda:'); 815 $scope.$broadcast('removeCabecera', 'Moneda:');
806 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 816 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
807 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 817 $scope.$broadcast('removeCabecera', 'Cotizacion:');
808 }else { 818 }else {
809 $scope.$broadcast('addCabecera',{ 819 $scope.$broadcast('addCabecera',{
810 label: 'Moneda:', 820 label: 'Moneda:',
811 valor: moneda.DETALLE 821 valor: moneda.DETALLE
812 }); 822 });
813 $scope.$broadcast('addCabecera',{ 823 $scope.$broadcast('addCabecera',{
814 label: 'Fecha cotizacion:', 824 label: 'Fecha cotizacion:',
815 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 825 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
816 }); 826 });
817 $scope.$broadcast('addCabecera',{ 827 $scope.$broadcast('addCabecera',{
818 label: 'Cotizacion:', 828 label: 'Cotizacion:',
819 valor: $filter('number')(cotizacion.COTIZACION, '2') 829 valor: $filter('number')(cotizacion.COTIZACION, '2')
820 }); 830 });
821 } 831 }
822 }, function() { 832 }, function() {
823 833
824 } 834 }
825 ); 835 );
826 }; 836 };
827 837
828 $scope.agregarATabla = function(key) { 838 $scope.agregarATabla = function(key) {
829 if(key === 13) { 839 if(key === 13) {
830 if($scope.articuloACargar.cantidad === undefined || 840 if($scope.articuloACargar.cantidad === undefined ||
831 $scope.articuloACargar.cantidad === 0 || 841 $scope.articuloACargar.cantidad === 0 ||
832 $scope.articuloACargar.cantidad === null ) { 842 $scope.articuloACargar.cantidad === null ) {
833 focaModalService.alert('El valor debe ser al menos 1'); 843 focaModalService.alert('El valor debe ser al menos 1');
834 return; 844 return;
835 } 845 }
836 delete $scope.articuloACargar.sectorCodigo; 846 delete $scope.articuloACargar.sectorCodigo;
837 $scope.articulosTabla.push($scope.articuloACargar); 847 $scope.articulosTabla.push($scope.articuloACargar);
838 $scope.cargando = true; 848 $scope.cargando = true;
839 } 849 }
840 }; 850 };
841 851
842 $scope.quitarArticulo = function(key) { 852 $scope.quitarArticulo = function(key) {
843 $scope.articulosTabla.splice(key, 1); 853 $scope.articulosTabla.splice(key, 1);
844 }; 854 };
845 855
846 $scope.editarArticulo = function(key, articulo) { 856 $scope.editarArticulo = function(key, articulo) {
847 if(key === 13) { 857 if(key === 13) {
848 if(articulo.cantidad === null || articulo.cantidad === 0 || 858 if(articulo.cantidad === null || articulo.cantidad === 0 ||
849 articulo.cantidad === undefined) { 859 articulo.cantidad === undefined) {
850 focaModalService.alert('El valor debe ser al menos 1'); 860 focaModalService.alert('El valor debe ser al menos 1');
851 return; 861 return;
852 } 862 }
853 articulo.editCantidad = false; 863 articulo.editCantidad = false;
854 articulo.editPrecio = false; 864 articulo.editPrecio = false;
855 } 865 }
856 }; 866 };
857 867
858 $scope.cambioEdit = function(articulo, propiedad) { 868 $scope.cambioEdit = function(articulo, propiedad) {
859 if(propiedad === 'cantidad') { 869 if(propiedad === 'cantidad') {
860 articulo.editCantidad = true; 870 articulo.editCantidad = true;
861 }else if(propiedad === 'precio') { 871 }else if(propiedad === 'precio') {
862 articulo.editPrecio = true; 872 articulo.editPrecio = true;
863 } 873 }
864 }; 874 };
865 875
866 $scope.limpiarFlete = function() { 876 $scope.limpiarFlete = function() {
867 $scope.remito.fleteNombre = ''; 877 $scope.remito.fleteNombre = '';
868 $scope.remito.chofer = ''; 878 $scope.remito.chofer = '';
869 $scope.remito.vehiculo = ''; 879 $scope.remito.vehiculo = '';
870 $scope.remito.kilometros = ''; 880 $scope.remito.kilometros = '';
871 $scope.remito.costoUnitarioKmFlete = ''; 881 $scope.remito.costoUnitarioKmFlete = '';
872 $scope.choferes = ''; 882 $scope.choferes = '';
873 $scope.vehiculos = ''; 883 $scope.vehiculos = '';
874 }; 884 };
875 885
876 $scope.limpiarPantalla = function() { 886 $scope.limpiarPantalla = function() {
877 $scope.limpiarFlete(); 887 $scope.limpiarFlete();
878 $scope.remito.flete = '0'; 888 $scope.remito.flete = '0';
879 $scope.remito.bomba = '0'; 889 $scope.remito.bomba = '0';
880 $scope.remito.precioCondicion = ''; 890 $scope.remito.precioCondicion = '';
881 $scope.articulosTabla = []; 891 $scope.articulosTabla = [];
882 $scope.remito.vendedor.nombre = ''; 892 $scope.remito.vendedor.nombre = '';
883 $scope.remito.cliente = {nombre: ''}; 893 $scope.remito.cliente = {nombre: ''};
884 $scope.remito.domicilio = {dom: ''}; 894 $scope.remito.domicilio = {dom: ''};
885 $scope.domiciliosCliente = []; 895 $scope.domiciliosCliente = [];
886 }; 896 };
887 897
888 $scope.resetFilter = function() { 898 $scope.resetFilter = function() {
889 $scope.articuloACargar = {}; 899 $scope.articuloACargar = {};
890 $scope.cargando = true; 900 $scope.cargando = true;
891 }; 901 };
892 //Recibe aviso si el teclado está en uso 902 //Recibe aviso si el teclado está en uso
893 $rootScope.$on('usarTeclado', function(event, data) { 903 $rootScope.$on('usarTeclado', function(event, data) {
894 if(data) { 904 if(data) {
895 $scope.mostrarTeclado = true; 905 $scope.mostrarTeclado = true;
896 return; 906 return;
897 } 907 }
898 $scope.mostrarTeclado = false; 908 $scope.mostrarTeclado = false;
899 }); 909 });
900 910
901 $scope.selectFocus = function($event) { 911 $scope.selectFocus = function($event) {
902 // Si el teclado esta en uso no selecciona el valor 912 // Si el teclado esta en uso no selecciona el valor
903 if($scope.mostrarTeclado) { 913 if($scope.mostrarTeclado) {
904 return; 914 return;
905 } 915 }
906 $event.target.select(); 916 $event.target.select();
907 }; 917 };
908 918
909 function addArrayCabecera(array) { 919 function addArrayCabecera(array) {
910 for(var i = 0; i < array.length; i++) { 920 for(var i = 0; i < array.length; i++) {
911 $scope.$broadcast('addCabecera',{ 921 $scope.$broadcast('addCabecera',{
912 label: array[i].label, 922 label: array[i].label,
913 valor: array[i].valor 923 valor: array[i].valor
914 }); 924 });
915 } 925 }
916 } 926 }
917 927
918 function rellenar(relleno, longitud) { 928 function rellenar(relleno, longitud) {
919 relleno = '' + relleno; 929 relleno = '' + relleno;
920 while (relleno.length < longitud) { 930 while (relleno.length < longitud) {
921 relleno = '0' + relleno; 931 relleno = '0' + relleno;
922 } 932 }
923 933
924 return relleno; 934 return relleno;
925 } 935 }
926 936
927 function varlidarRemitoFacturado() { 937 function varlidarRemitoFacturado() {
928 if($scope.remito.estado !== 5) { 938 if($scope.remito.estado !== 5) {
929 return true; 939 return true;
930 }else { 940 }else {
931 focaModalService.alert('No se puede editar un remito facturado'); 941 focaModalService.alert('No se puede editar un remito facturado');
932 return false(); 942 return false();
933 } 943 }
934 } 944 }
935 945
936 function salir() { 946 function salir() {
937 var confirmacion = false; 947 var confirmacion = false;
938 948
939 angular.forEach($scope.inicial, function(valor, key) { 949 angular.forEach($scope.inicial, function(valor, key) {
940 if (!angular.equals($scope[key], $scope.inicial[key])) { 950 if (!angular.equals($scope[key], $scope.inicial[key])) {
941 confirmacion = true; 951 confirmacion = true;
942 } 952 }
943 }); 953 });
944 954
945 if (confirmacion) { 955 if (confirmacion) {
946 focaModalService.confirm( 956 focaModalService.confirm(
947 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 957 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
948 ).then(function(data) { 958 ).then(function(data) {
949 if (data) { 959 if (data) {
950 $location.path('/'); 960 $location.path('/');
951 } 961 }
952 }); 962 });
953 } else { 963 } else {
954 $location.path('/'); 964 $location.path('/');
955 } 965 }
956 } 966 }
957 967
958 function enableObservaciones(val) { 968 function enableObservaciones(val) {
959 var boton = $scope.botonera.filter(function(botonObs) { 969 var boton = $scope.botonera.filter(function(botonObs) {
960 return botonObs.label === 'Observaciones'; 970 return botonObs.label === 'Observaciones';
961 }); 971 });
962 972
963 boton[0].disable = !val; 973 boton[0].disable = !val;
964 } 974 }
965 } 975 }
966 ]); 976 ]);
967 977
1 angular.module('focaCrearRemito') 1 angular.module('focaCrearRemito')
2 .service('crearRemitoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .service('crearRemitoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 return { 4 return {
5 crearRemito: function(remito) { 5 crearRemito: function(remito) {
6 // TODO: Cambiar para usar el servicio /remito 6 // TODO: Cambiar para usar el servicio /remito
7 return $http.post(route + '/remito', remito); 7 return $http.post(route + '/remito', remito);
8 }, 8 },
9 obtenerRemito: function() { 9 obtenerRemito: function() {
10 return $http.get(route +'/nota-pedido'); 10 return $http.get(route +'/nota-pedido');
11 }, 11 },
12 setRemito: function(remito) { 12 setRemito: function(remito) {
13 this.remito = remito; 13 this.remito = remito;
14 }, 14 },
15 clearRemito: function() { 15 clearRemito: function() {
16 this.remito = undefined; 16 this.remito = undefined;
17 }, 17 },
18 getRemito: function() { 18 getRemito: function() {
19 return this.remito; 19 return this.remito;
20 }, 20 },
21 getArticulosByIdRemito: function(id) { 21 getArticulosByIdRemito: function(id) {
22 return $http.get(route+'/articulos/nota-pedido/'+id); 22 return $http.get(route+'/articulos/nota-pedido/'+id);
23 }, 23 },
24 crearArticulosParaRemito: function(articuloRemito) { 24 crearArticulosParaRemito: function(articuloRemito) {
25 return $http.post(route + '/articulos/remito', 25 return $http.post(route + '/articulos/remito',
26 {articuloRemito: articuloRemito}); 26 {articuloRemito: articuloRemito});
27 }, 27 },
28 getDomiciliosByIdRemito: function(id) { 28 getDomiciliosByIdRemito: function(id) {
29 return $http.get(route +'/nota-pedido/'+id+'/domicilios'); 29 return $http.get(route +'/nota-pedido/'+id+'/domicilios');
30 }, 30 },
31 getDomiciliosByIdCliente: function(id) { 31 getDomiciliosByIdCliente: function(id) {
32 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 32 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
33 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 33 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
34 }, 34 },
35 getPrecioCondicion: function() { 35 getPrecioCondicion: function() {
36 return $http.get(route + '/precio-condicion'); 36 return $http.get(route + '/precio-condicion');
37 }, 37 },
38 getPrecioCondicionById: function(id) { 38 getPrecioCondicionById: function(id) {
39 return $http.get(route + '/precio-condicion/' + id); 39 return $http.get(route + '/precio-condicion/' + id);
40 }, 40 },
41 getPlazoPagoByPrecioCondicion: function(id) { 41 getPlazoPagoByPrecioCondicion: function(id) {
42 return $http.get(route + '/plazo-pago/precio-condicion/'+ id); 42 return $http.get(route + '/plazo-pago/precio-condicion/'+ id);
43 }, 43 },
44 crearFlete: function(flete) { 44 crearFlete: function(flete) {
45 return $http.post(route + '/flete', {flete : flete}); 45 return $http.post(route + '/flete', {flete : flete});
46 }, 46 },
47 crearPlazosParaRemito: function(plazos) { 47 crearPlazosParaRemito: function(plazos) {
48 return $http.post(route + '/plazo-pago/remito', plazos); 48 return $http.post(route + '/plazo-pago/remito', plazos);
49 }, 49 },
50 getCotizacionByIdMoneda: function(id) { 50 getCotizacionByIdMoneda: function(id) {
51 return $http.get(route + '/moneda/' + id); 51 return $http.get(route + '/moneda/' + id);
52 }, 52 },
53 crearEstadoParaRemito: function(estado) { 53 crearEstadoParaRemito: function(estado) {
54 return $http.post(route + '/estado', {estado: estado}); 54 return $http.post(route + '/estado', {estado: estado});
55 }, 55 },
56 getNumeroRemito: function() { 56 getNumeroRemito: function() {
57 return $http.get(route + '/remito/numero-siguiente'); 57 return $http.get(route + '/remito/numero-siguiente');
58 }, 58 },
59 imprimirRemitoByIdRemito: function(idRemito, original) {
60 var tipo = original ? '/original' : '';
61 return $http.get(route + '/remito/comprobante/' + idRemito + tipo);
62 },
59 getBotonera: function() { 63 getBotonera: function() {
60 return [ 64 return [
61 { 65 {
62 label: 'Nota pedido', 66 label: 'Nota pedido',
63 image: 'notaDePedido.png' 67 image: 'notaDePedido.png'
64 }, 68 },
65 { 69 {
66 label: 'Vendedor', 70 label: 'Vendedor',
67 image: 'vendedor.png' 71 image: 'vendedor.png'
68 }, 72 },
69 { 73 {
70 label: 'Cliente', 74 label: 'Cliente',
71 image: 'cliente.png' 75 image: 'cliente.png'
72 }, 76 },
73 { 77 {
74 label: 'Proveedor', 78 label: 'Proveedor',
75 image: 'proveedor.png' 79 image: 'proveedor.png'
76 }, 80 },
77 { 81 {
78 label: 'Moneda', 82 label: 'Moneda',
79 image: 'moneda.png' 83 image: 'moneda.png'
80 }, 84 },
81 { 85 {
82 label: 'Precios y condiciones', 86 label: 'Precios y condiciones',
83 image: 'precios-condiciones.png' 87 image: 'precios-condiciones.png'
84 }, 88 },
85 { 89 {
86 label: 'Flete', 90 label: 'Flete',
87 image: 'flete.png' 91 image: 'flete.png'
88 }, 92 },
89 { 93 {
90 label: 'Productos', 94 label: 'Productos',
91 image: 'productos.png' 95 image: 'productos.png'
92 }, 96 },
93 { 97 {
94 label: 'Observaciones', 98 label: 'Observaciones',
95 image: 'productos.png', 99 image: 'productos.png',
96 disable: true 100 disable: true
97 } 101 }
98 ]; 102 ];
99 } 103 }
100 }; 104 };
101 }]); 105 }]);
102 106