Commit be0c90f0211b0c04817eba730756f4eccca33167

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

See merge request !81
... ... @@ -60,7 +60,7 @@
60 60 "gulp-uglify-es": "^1.0.4",
61 61 "jasmine-core": "^3.3.0",
62 62 "jquery": "^3.3.1",
63   - "jshint": "^2.9.6",
  63 + "jshint": "^2.10.2",
64 64 "ladda": "1.0.6",
65 65 "pre-commit": "^1.2.2",
66 66 "pump": "^3.0.0",
src/js/businessService.js
... ... @@ -36,6 +36,19 @@ angular.module('focaCrearRemito')
36 36 result += plazos[i].dias + ' ';
37 37 }
38 38 return result.trim();
  39 + },
  40 + addPuntosDescarga: function(idRemito, puntosDescarga) {
  41 +
  42 + var puntos = [];
  43 +
  44 + puntosDescarga.forEach(function(punto) {
  45 + puntos.push({
  46 + idPuntoDescarga: punto.puntoDescarga.id,
  47 + idRemito: idRemito,
  48 + });
  49 + });
  50 +
  51 + return crearRemitoService.crearPuntosDescarga(puntos);
39 52 }
40 53 };
41 54 }]);
src/js/controller.js
1   -angular.module('focaCrearRemito') .controller('remitoController',
  1 +angular.module('focaCrearRemito').controller('remitoController',
2 2 [
3 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout',
4   - 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService',
  4 + 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService',
5 5 '$localStorage',
6   - function(
  6 + function (
7 7 $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService,
8   - remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage)
9   - {
  8 + remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) {
10 9 config();
11 10  
  11 + var cotizacionPArgentino = {};
  12 +
12 13 function config() {
13 14 $scope.tmpCantidad = Number;
14 15 $scope.tmpPrecio = Number;
... ... @@ -25,31 +26,22 @@ angular.module('focaCrearRemito') .controller('remitoController',
25 26 minDate: new Date(2010, 0, 1)
26 27 };
27 28  
28   - var monedaPorDefecto;
29   - var promiseMoneda = crearRemitoService.getCotizacionByIdMoneda(1);
30   - var promiseProveedor = crearRemitoService.getProveedorById(1);
31 29  
32   - //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
33   - //Trabajo con el proveedo YPF, por eso uso siempre la primera
  30 + crearRemitoService.getParametros().then(function (res) {
  31 + var parametros = JSON.parse(res.data[0].jsonText);
  32 + if ($localStorage.remito) {
  33 + $timeout(function () { getLSRemito(); });
  34 + } else {
  35 + for (var property in parametros) {
  36 + $scope.remito[property] = parametros[property];
  37 + $scope.inicial[property] = parametros[property];
  38 + }
  39 + setearRemito($scope.remito);
  40 + }
  41 + });
34 42  
35   - Promise.all([promiseMoneda, promiseProveedor]).then(function(res) {
36   - var monedaPorDefecto = res[0].data[0];
37   - $scope.remito.cotizacion = Object.assign(
38   - {moneda: monedaPorDefecto},
39   - monedaPorDefecto.cotizaciones[0]
40   - );
41   - $scope.inicial.cotizacion = $scope.remito.cotizacion;
42   - var proveedorPorDefecto = res[1].data[0];
43   - $scope.remito.proveedor = Object.assign(
44   - {proveedor: proveedorPorDefecto}
45   - );
46   - $scope.inicial.proveedor = $scope.remito.proveedor;
47   - $scope.cotizacionPorDefecto = angular.copy($scope.remito.cotizacion);
48   - $scope.proveedor = angular.copy($scope.remito.proveedor);
49   - $timeout(function() {getLSRemito();});
50   - });
51 43 //SETEO BOTONERA LATERAL
52   - $timeout(function() {
  44 + $timeout(function () {
53 45 focaBotoneraLateralService.showSalir(false);
54 46 focaBotoneraLateralService.showPausar(true);
55 47 focaBotoneraLateralService.showGuardar(true, $scope.crearRemito);
... ... @@ -62,17 +54,18 @@ angular.module('focaCrearRemito') .controller('remitoController',
62 54  
63 55 function init() {
64 56 $scope.$broadcast('cleanCabecera');
65   -
  57 + $scope.remitoIsDirty = false;
66 58 $scope.remito = {
67 59 id: 0,
68 60 estado: 0,
69 61 vendedor: {},
70 62 cliente: {},
71 63 proveedor: {},
72   - domicilio: {dom: ''},
  64 + domicilio: { dom: '' },
73 65 moneda: {},
74 66 cotizacion: $scope.cotizacionPorDefecto || {},
75   - articulosRemito: []
  67 + articulosRemito: [],
  68 + remitoPuntoDescarga: []
76 69 };
77 70  
78 71 $scope.notaPedido = {
... ... @@ -83,11 +76,11 @@ angular.module('focaCrearRemito') .controller('remitoController',
83 76 $scope.idLista = undefined;
84 77  
85 78 crearRemitoService.getNumeroRemito().then(
86   - function(res) {
  79 + function (res) {
87 80 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
88 81 $scope.comprobante = rellenar(res.data.numeroRemito, 8);
89 82 },
90   - function(err) {
  83 + function (err) {
91 84 focaModalService.alert('La terminal no esta configurada correctamente');
92 85 console.info(err);
93 86 }
... ... @@ -96,14 +89,14 @@ angular.module('focaCrearRemito') .controller('remitoController',
96 89 $scope.inicial = angular.copy($scope.remito);
97 90 }
98 91  
99   - $scope.$watch('remito', function(newValue) {
  92 + $scope.$watch('remito', function (newValue) {
100 93 focaBotoneraLateralService.setPausarData({
101 94 label: 'remito',
102 95 val: newValue
103 96 });
104 97 }, true);
105 98  
106   - $scope.seleccionarNotaPedido = function() {
  99 + $scope.seleccionarNotaPedido = function () {
107 100 if (varlidarRemitoFacturado()) {
108 101 var modalInstance = $uibModal.open(
109 102 {
... ... @@ -112,19 +105,20 @@ angular.module('focaCrearRemito') .controller('remitoController',
112 105 controller: 'focaModalNotaPedidoController',
113 106 size: 'lg',
114 107 resolve: {
115   - usadoPor: function() { return 'remito'; },
116   - idVendedor: function() { return null; }
  108 + usadoPor: function () { return 'remito'; },
  109 + idVendedor: function () { return null; }
117 110 }
118 111 }
119 112 );
120 113 modalInstance.result.then(
121   - function(notaPedido) {
  114 + function (notaPedido) {
122 115 //añado cabeceras
  116 + $scope.remitoIsDirty = true;
123 117 $scope.notaPedido.id = notaPedido.id;
124 118 $scope.$broadcast('removeCabecera', 'Bomba:');
125 119 $scope.$broadcast('removeCabecera', 'Kilometros:');
126 120 var puntosDescarga = [];
127   - notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedido, idx, arr) {
  121 + notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedido) {
128 122 puntosDescarga.push(notaPedido.puntoDescarga);
129 123 });
130 124 var cabeceras = [
... ... @@ -159,7 +153,7 @@ angular.module('focaCrearRemito') .controller('remitoController',
159 153 },
160 154 {
161 155 label: 'Proveedor:',
162   - valor: $filter('rellenarDigitos')
  156 + valor: $filter('rellenarDigitos')
163 157 (notaPedido.proveedor.COD, 5) + ' - ' +
164 158 notaPedido.proveedor.NOM
165 159 },
... ... @@ -176,10 +170,28 @@ angular.module('focaCrearRemito') .controller('remitoController',
176 170 },
177 171 {
178 172 label: 'Puntos de descarga: ',
179   - valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga))
  173 + valor: $filter('rellenarDigitos')(
  174 + getCabeceraPuntoDescarga(puntosDescarga))
180 175 }
181 176 ];
182 177  
  178 + // Seteo checked en cabeceras
  179 + $filter('filter')($scope.botonera,
  180 + { label: 'Cliente' })[0].checked = true;
  181 + $filter('filter')($scope.botonera,
  182 + { label: 'Proveedor' })[0].checked = true;
  183 + $filter('filter')($scope.botonera,
  184 + { label: 'Moneda' })[0].checked = true;
  185 + $filter('filter')($scope.botonera,
  186 + { label: 'Nota pedido' })[0].checked = true;
  187 + $filter('filter')($scope.botonera,
  188 + { label: 'Precios y condiciones' })[0].checked = true;
  189 +
  190 + if (notaPedido.observaciones) {
  191 + $filter('filter')($scope.botonera,
  192 + { label: 'Observaciones' })[0].checked = true;
  193 + }
  194 +
183 195 function valorPrecioCondicion() {
184 196 if (notaPedido.idPrecioCondicion > 0) {
185 197 return notaPedido.precioCondicion.nombre;
... ... @@ -207,11 +219,14 @@ angular.module('focaCrearRemito') .controller('remitoController',
207 219 $scope.remito = notaPedido;
208 220 $scope.remito.id = 0;
209 221 $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo;
  222 + $scope.remito.remitoPuntoDescarga = notaPedido.notaPedidoPuntoDescarga;
210 223  
211   - for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) {
212   - notaPedido.articulosNotaPedido[i].id = 0;
213   - notaPedido.articulosNotaPedido[i].idRemito = 0;
214   - }
  224 + notaPedido.articulosNotaPedido.forEach(function (articulo) {
  225 + articulo.id = 0;
  226 + articulo.idRemito = 0;
  227 + articulo.precio =
  228 + (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4);
  229 + });
215 230  
216 231 $scope.remito.articulosRemito = notaPedido.articulosNotaPedido;
217 232  
... ... @@ -224,49 +239,58 @@ angular.module('focaCrearRemito') .controller('remitoController',
224 239 enableObservaciones(notaPedido.observaciones ? true : false);
225 240 addArrayCabecera(cabeceras);
226 241  
227   - }, function() {
  242 + }, function () {
228 243 // funcion ejecutada cuando se cancela el modal
229 244 }
230 245 );
231 246 }
232 247 };
233 248  
234   - $scope.seleccionarRemito = function() {
  249 + $scope.seleccionarRemito = function () {
  250 + if ($scope.remitoIsDirty) {
  251 + focaModalService.confirm('¿Desea continuar? Se perderan los cambios')
  252 + .then(function () {
  253 + $scope.getRemitoModal();
  254 + });
  255 + } else {
  256 + $scope.getRemitoModal();
  257 + }
  258 + };
  259 + $scope.getRemitoModal = function () {
235 260 var modalInstance = $uibModal.open(
236 261 {
237 262 ariaLabelledBy: 'Busqueda de Remito',
238 263 templateUrl: 'foca-modal-remito.html',
239 264 controller: 'focaModalRemitoController',
240 265 size: 'lg',
241   - resolve: {usadoPor: function() {return 'remito';}}
  266 + resolve: { usadoPor: function () { return 'remito'; } }
242 267 }
243 268 );
244 269 modalInstance.result.then(
245   - setearRemito, function() {
  270 + setearRemito, function () {
246 271 // funcion ejecutada cuando se cancela el modal
247 272 }
248 273 );
249 274 };
250   -
251 275 //validacion por domicilio y por plazo pago
252   - $scope.crearRemito = function() {
  276 + $scope.crearRemito = function () {
253 277 if (!$scope.remito.vendedor.NUM) {
254 278 focaModalService.alert('Ingrese Vendedor');
255 279 return;
256 280 } else if (!$scope.remito.cliente.COD) {
257 281 focaModalService.alert('Ingrese Cliente');
258 282 return;
259   - } else if (!$scope.remito.proveedor) {
  283 + } else if (!$scope.remito.proveedor.COD) {
260 284 focaModalService.alert('Ingrese Proveedor');
261 285 return;
262 286 } else if (!$scope.remito.cotizacion.moneda.id &&
263   - !$scope.remito.cotizacion.moneda.ID){
  287 + !$scope.remito.cotizacion.moneda.ID) {
264 288 focaModalService.alert('Ingrese Moneda');
265 289 return;
266 290 } else if (!$scope.remito.cotizacion.ID) {
267 291 focaModalService.alert('Ingrese Cotización');
268 292 return;
269   - } else if ($scope.remito.flete === undefined || $scope.remito.flete === null){
  293 + } else if ($scope.remito.flete === undefined || $scope.remito.flete === null) {
270 294 focaModalService.alert('Ingrese Flete');
271 295 return;
272 296 } else if ($scope.articulosFiltro().length === 0) {
... ... @@ -275,39 +299,18 @@ angular.module('focaCrearRemito') .controller('remitoController',
275 299 }
276 300 focaBotoneraLateralService.startGuardar();
277 301 $scope.saveLoading = true;
278   - var save = {
  302 + var save = {
279 303 remito: {
280 304 id: $scope.remito.id,
281 305 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
282 306 idCliente: $scope.remito.cliente.COD,
283 307 nombreCliente: $scope.remito.cliente.NOM,
284 308 cuitCliente: $scope.remito.cliente.CUIT,
285   - responsabilidadIvaCliente: 0,//TODO,
286   - descuento: 0,//TODO,
287   - importeNeto: 0,//TODO
288   - importeExento: 0,//TODO
289   - importeIva: 0,//TODO
290   - importeIvaServicios: 0,//TODO
291   - importeImpuestoInterno: 0,//TODO
292   - importeImpuestoInterno1: 0,//TODO
293   - importeImpuestoInterno2: 0,//TODO
294   - percepcion: 0,//TODO
295   - percepcionIva: 0,//TODO
296   - redondeo: 0,//TODO
297 309 total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR,
298 310 numeroNotaPedido: $scope.remito.numeroNotaPedido,
299   - anulado: false,
300   - planilla: 0,//TODO
301   - lugar: 0,//TODO
302   - cuentaMadre: 0,//
303   - cuentaContable: 0,//TODO
304   - asiento: 0,//TODO
305   - e_hd: '',//TODO
306   - c_hd: '',
307   - numeroLiquidoProducto: 0,//TODO
308 311 idVendedor: $scope.remito.idVendedor,
309   - idProveedor: $scope.remito.idProveedor,
310   - idDomicilio: $scope.remito.idDomicilio,
  312 + idProveedor: $scope.remito.proveedor.COD,
  313 + idDomicilio: $scope.remito.idDomicilio || $scope.remito.domicilio.id,
311 314 idCotizacion: $scope.remito.cotizacion.ID,
312 315 idPrecioCondicion: $scope.remito.idPrecioCondicion,
313 316 flete: $scope.remito.flete,
... ... @@ -315,18 +318,39 @@ angular.module('focaCrearRemito') .controller('remitoController',
315 318 bomba: $scope.remito.bomba,
316 319 kilometros: $scope.remito.kilometros,
317 320 domicilioStamp: $scope.remito.domicilioStamp,
318   - estado: 0,//TODO
319   - destinoVenta: 0,//TODO
320   - operacionTipo: 0, //TODO
321 321 observaciones: $scope.remito.observaciones,
322 322 numeroRemito: parseInt($scope.comprobante),
323   - sucursal: parseInt($scope.puntoVenta)
  323 + sucursal: parseInt($scope.puntoVenta),
  324 + responsabilidadIvaCliente: $scope.remito.cliente.IVA,
  325 + descuento: 0,//TODO,
  326 + importeNeto: getImporte('netoUnitario'),
  327 + importeExento: getImporte('exentoUnitario'),
  328 + importeIva: getImporte('ivaUnitario'),
  329 + importeIvaServicios: 0,//TODO
  330 + importeImpuestoInterno: getImporte('impuestoInternoUnitario'),
  331 + importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'),
  332 + importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'),
  333 + percepcion: 0,//TODO
  334 + percepcionIva: 0,//TODO
  335 + redondeo: 0,//TODO
  336 + anulado: false,
  337 + planilla: $filter('date')($scope.now, 'ddMMyyyy'),
  338 + lugar: parseInt($scope.puntoVenta),
  339 + cuentaMadre: 0,//TODO
  340 + cuentaContable: 0,//TODO
  341 + asiento: 0,//TODO
  342 + e_hd: '',//TODO
  343 + c_hd: '',
  344 + numeroLiquidoProducto: 0,//TODO
  345 + estado: 0,
  346 + destinoVenta: 0,//TODO
  347 + operacionTipo: 0, //TODO
324 348 },
325 349 notaPedido: $scope.notaPedido
326 350 };
327 351  
328 352 crearRemitoService.crearRemito(save).then(
329   - function(data) {
  353 + function (data) {
330 354  
331 355 focaBotoneraLateralService.endGuardar(true);
332 356 $scope.saveLoading = false;
... ... @@ -334,10 +358,15 @@ angular.module('focaCrearRemito') .controller('remitoController',
334 358 $scope.remito.id = data.data.id;
335 359 $scope.remito.numeroRemito = data.data.numero;
336 360  
  361 + if ($scope.remito.remitoPuntoDescarga.length) {
  362 + remitoBusinessService.addPuntosDescarga(data.data.id,
  363 + $scope.remito.remitoPuntoDescarga);
  364 + }
  365 +
337 366 remitoBusinessService.addArticulos($scope.remito.articulosRemito,
338 367 $scope.remito.id, $scope.remito.cotizacion.VENDEDOR);
339 368  
340   - if(data.status === 500) {
  369 + if (data.status === 500) {
341 370 focaModalService.alert(data.data);
342 371 return;
343 372 }
... ... @@ -346,7 +375,7 @@ angular.module('focaCrearRemito') .controller('remitoController',
346 375 if ($scope.remito.id === 0) {
347 376 var plazos = $scope.remito.remitoPlazo;
348 377  
349   - for(var j = 0; j < plazos.length; j++) {
  378 + for (var j = 0; j < plazos.length; j++) {
350 379 var json = {
351 380 idRemito: $scope.remito.id,
352 381 dias: plazos[j].dias
... ... @@ -363,9 +392,9 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
363 392 ])
364 393 );
365 394  
366   - init();
  395 + config();
367 396  
368   - }, function(error) {
  397 + }, function (error) {
369 398 focaModalService.alert(error.data || 'Hubo un error al crear el remito');
370 399 focaBotoneraLateralService.endGuardar();
371 400 $scope.saveLoading = false;
... ... @@ -374,7 +403,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
374 403 );
375 404 };
376 405  
377   - $scope.seleccionarProductos = function() {
  406 + $scope.seleccionarProductos = function () {
378 407 if ($scope.idLista === undefined) {
379 408 focaModalService.alert(
380 409 'Primero seleccione una lista de precio y condicion');
... ... @@ -396,7 +425,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
396 425 }
397 426 );
398 427 modalInstance.result.then(
399   - function(producto) {
  428 + function (producto) {
400 429 var newArt =
401 430 {
402 431 id: 0,
... ... @@ -412,24 +441,29 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
412 441 editCantidad: false,
413 442 editPrecio: false,
414 443 rubro: producto.CodRub,
415   - exentoUnitario: producto.precio,
416 444 ivaUnitario: producto.IMPIVA,
417 445 impuestoInternoUnitario: producto.ImpInt,
418 446 impuestoInterno1Unitario: producto.ImpInt2,
419 447 impuestoInterno2Unitario: producto.ImpInt3,
420 448 precioLista: producto.precio,
421 449 combustible: 1,
422   - facturado: 0
  450 + facturado: 0,
  451 + idArticulo: producto.id,
  452 + tasaIva: producto.tasaIVA
423 453 };
  454 +
  455 + newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto;
  456 + newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0;
  457 +
424 458 $scope.articuloACargar = newArt;
425 459 $scope.cargando = false;
426   - }, function() {
  460 + }, function () {
427 461 // funcion ejecutada cuando se cancela el modal
428 462 }
429 463 );
430 464 };
431 465  
432   - $scope.seleccionarPuntosDeDescarga = function() {
  466 + $scope.seleccionarPuntosDeDescarga = function () {
433 467 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) {
434 468 focaModalService.alert('Primero seleccione un cliente y un domicilio');
435 469 return;
... ... @@ -445,7 +479,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
445 479 idDomicilio: $scope.remito.domicilio.id,
446 480 idCliente: $scope.remito.cliente.COD,
447 481 articulos: $scope.remito.articulosRemito,
448   - puntosDescarga: $scope.remito.domicilio.puntosDescarga,
  482 + puntosDescarga: $scope.remito.remitoPuntoDescarga,
449 483 domicilio: $scope.remito.domicilio
450 484 }
451 485 }
... ... @@ -453,20 +487,27 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
453 487 );
454 488 modalInstance.result.then(
455 489 function(puntosDescarga) {
456   - $scope.remito.domicilio.puntosDescarga = puntosDescarga;
  490 +
  491 + puntosDescarga.forEach(function(punto) {
  492 + $scope.remito.remitoPuntoDescarga.push(
  493 + {
  494 + puntoDescarga: punto
  495 + }
  496 + );
  497 + });
457 498  
458 499 $scope.$broadcast('addCabecera', {
459 500 label: 'Puntos de descarga:',
460   - valor: getCabeceraPuntoDescarga($scope.remito.domicilio.puntosDescarga)
  501 + valor: getCabeceraPuntoDescarga(puntosDescarga)
461 502 });
462   - }, function() {
  503 + }, function () {
463 504 $scope.abrirModalDomicilios($scope.cliente);
464 505 }
465 506 );
466 507 }
467 508 };
468 509  
469   - $scope.seleccionarVendedor = function(callback, ocultarVendedor) {
  510 + $scope.seleccionarVendedor = function (callback, ocultarVendedor) {
470 511 if (ocultarVendedor) {
471 512 callback();
472 513 return;
... ... @@ -493,8 +534,9 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
493 534 size: 'md'
494 535 };
495 536 focaModalService.modal(parametrosModal).then(
496   - function(vendedor) {
497   - $scope.$broadcast('addCabecera',{
  537 + function (vendedor) {
  538 + $scope.remitoIsDirty = true;
  539 + $scope.$broadcast('addCabecera', {
498 540 label: 'Vendedor:',
499 541 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
500 542 vendedor.NOM
... ... @@ -503,16 +545,16 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
503 545 $scope.remito.vendedor = vendedor;
504 546 deleteCliente();
505 547 callback();
506   - }, function() {
  548 + }, function () {
507 549  
508 550 }
509 551 );
510 552 }
511 553 };
512 554  
513   - $scope.seleccionarCliente = function(ocultarVendedor) {
  555 + $scope.seleccionarCliente = function (ocultarVendedor) {
514 556  
515   - $scope.seleccionarVendedor(function() {
  557 + $scope.seleccionarVendedor(function () {
516 558 if (varlidarRemitoFacturado()) {
517 559 var modalInstance = $uibModal.open(
518 560 {
... ... @@ -520,17 +562,17 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
520 562 templateUrl: 'foca-busqueda-cliente-modal.html',
521 563 controller: 'focaBusquedaClienteModalController',
522 564 resolve: {
523   - vendedor: function() { return $scope.remito.vendedor; },
524   - cobrador: function() { return null; }
  565 + vendedor: function () { return $scope.remito.vendedor; },
  566 + cobrador: function () { return null; }
525 567 },
526 568 size: 'lg'
527 569 }
528 570 );
529 571 modalInstance.result.then(
530   - function(cliente) {
  572 + function (cliente) {
531 573 $scope.abrirModalDomicilios(cliente);
532 574 $scope.cliente = cliente;
533   - }, function() {
  575 + }, function () {
534 576 $scope.seleccionarCliente();
535 577 }
536 578 );
... ... @@ -538,7 +580,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
538 580 }, ocultarVendedor);
539 581 };
540 582  
541   - $scope.seleccionarProveedor = function() {
  583 + $scope.seleccionarProveedor = function () {
542 584 if (varlidarRemitoFacturado()) {
543 585 var parametrosModal = {
544 586 titulo: 'Búsqueda de Proveedor',
... ... @@ -562,17 +604,17 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
562 604 }
563 605 ],
564 606 tipo: 'POST',
565   - json: {razonCuitCod: ''}
  607 + json: { razonCuitCod: '' }
566 608 };
567 609 focaModalService.modal(parametrosModal).then(
568   - function(proveedor) {
  610 + function (proveedor) {
569 611 $scope.seleccionarFlete(proveedor);
570   - }, function() { }
  612 + }, function () { }
571 613 );
572 614 }
573 615 };
574 616  
575   - $scope.abrirModalDomicilios = function(cliente) {
  617 + $scope.abrirModalDomicilios = function (cliente) {
576 618 var modalInstanceDomicilio = $uibModal.open(
577 619 {
578 620 ariaLabelledBy: 'Busqueda de Domicilios',
... ... @@ -580,31 +622,33 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
580 622 controller: 'focaModalDomicilioController',
581 623 size: 'lg',
582 624 resolve: {
583   - idCliente: function() { return cliente.cod; },
584   - esNuevo: function() { return cliente.esNuevo; }
  625 + idCliente: function () { return cliente.cod; },
  626 + esNuevo: function () { return cliente.esNuevo; }
585 627 }
586 628 }
587 629 );
588 630 modalInstanceDomicilio.result.then(
589   - function(domicilio) {
  631 + function (domicilio) {
590 632 $scope.remito.domicilio = domicilio;
  633 + console.log(cliente);
591 634 $scope.remito.cliente = {
592 635 COD: cliente.cod,
593 636 CUIT: cliente.cuit,
594 637 NOM: cliente.nom,
595 638 MAIL: cliente.mail,
596   - MOD: cliente.mod
  639 + MOD: cliente.mod,
  640 + IVA: cliente.iva
597 641 };
598 642  
599 643 var domicilioStamp =
600 644 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
601 645 domicilio.Localidad + ', ' + domicilio.Provincia;
602 646 $scope.remito.domicilioStamp = domicilioStamp;
603   - $scope.$broadcast('addCabecera',{
  647 + $scope.$broadcast('addCabecera', {
604 648 label: 'Cliente:',
605 649 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
606 650 });
607   - $scope.$broadcast('addCabecera',{
  651 + $scope.$broadcast('addCabecera', {
608 652 label: 'Domicilio:',
609 653 valor: domicilioStamp
610 654 });
... ... @@ -612,47 +656,44 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
612 656 if (domicilio.verPuntos) {
613 657 delete $scope.remito.domicilio.verPuntos;
614 658 $scope.seleccionarPuntosDeDescarga();
615   - } else {
616   - crearRemitoService
617   - .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
618   - .then(function(res) {
619   - if (res.data.length) $scope.seleccionarPuntosDeDescarga();
620   - });
621 659 }
622   - }, function() {
  660 +
  661 + $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
  662 + }, function () {
623 663 $scope.seleccionarCliente(true);
624 664 return;
625 665 }
626 666 );
627 667 };
628 668  
629   - $scope.getTotal = function() {
  669 + $scope.getTotal = function () {
630 670 var total = 0;
631 671 var arrayTempArticulos = $scope.articulosFiltro();
632   - for(var i = 0; i < arrayTempArticulos.length; i++) {
  672 + for (var i = 0; i < arrayTempArticulos.length; i++) {
633 673 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
634 674 }
635 675 return parseFloat(total.toFixed(2));
636 676 };
637 677  
638   - $scope.getSubTotal = function() {
  678 + $scope.getSubTotal = function () {
639 679 if ($scope.articuloACargar) {
640 680 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
641 681 }
642 682 };
643 683  
644   - $scope.seleccionarPreciosYCondiciones = function() {
  684 + $scope.seleccionarPreciosYCondiciones = function () {
645 685 if (!$scope.remito.cliente.COD) {
646 686 focaModalService.alert('Primero seleccione un cliente');
647 687 return;
648 688 }
649 689  
650 690 if ($scope.remito.articulosRemito.length !== 0) {
651   - focaModalService.confirm('Se perderan los productos ingresados').then(function(data) {
652   - if (data && varlidarRemitoFacturado()) {
653   - abrirModal();
654   - }
655   - });
  691 + focaModalService.confirm('Se perderan los productos ingresados')
  692 + .then(function (data) {
  693 + if (data && varlidarRemitoFacturado()) {
  694 + abrirModal();
  695 + }
  696 + });
656 697 } else {
657 698 abrirModal();
658 699 }
... ... @@ -665,21 +706,21 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
665 706 controller: 'focaModalPrecioCondicionController',
666 707 size: 'lg',
667 708 resolve: {
668   - idListaPrecio: function() {
  709 + idListaPrecio: function () {
669 710 return $scope.remito.cliente.MOD || null;
670 711 }
671 712 }
672 713 }
673 714 );
674 715 modalInstance.result.then(
675   - function(precioCondicion) {
  716 + function (precioCondicion) {
676 717 var cabecera = '';
677 718 var plazosConcat = '';
678 719 if (!Array.isArray(precioCondicion)) {
679 720 $scope.remito.idPrecioCondicion = precioCondicion.id;
680 721 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
681 722 $scope.idLista = precioCondicion.idListaPrecio;
682   - for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
  723 + for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
683 724 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
684 725 }
685 726 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
... ... @@ -689,25 +730,28 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
689 730 //-1, el modal productos busca todos los productos
690 731 $scope.idLista = -1;
691 732 $scope.remito.remitoPlazo = precioCondicion;
692   - for(var j = 0; j < precioCondicion.length; j++) {
  733 + for (var j = 0; j < precioCondicion.length; j++) {
693 734 plazosConcat += precioCondicion[j].dias + ' ';
694 735 }
695 736 cabecera = 'Ingreso manual ' + plazosConcat.trim();
696 737 }
697 738 $scope.remito.articulosRemito = [];
698   - $scope.$broadcast('addCabecera',{
  739 + $scope.$broadcast('addCabecera', {
699 740 label: 'Precios y condiciones:',
700 741 valor: cabecera
701 742 });
702 743 $scope.remito.precioCondicion = precioCondicion;
703   - }, function() {
  744 +
  745 + $filter('filter')($scope.botonera,
  746 + { label: 'Precios y Condiciones' })[0].checked = true;
  747 + }, function () {
704 748  
705 749 }
706 750 );
707 751 }
708 752 };
709 753  
710   - $scope.seleccionarFlete = function(proveedor) {
  754 + $scope.seleccionarFlete = function (proveedor) {
711 755 if (varlidarRemitoFacturado()) {
712 756 var modalInstance = $uibModal.open(
713 757 {
... ... @@ -717,12 +761,12 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
717 761 size: 'lg',
718 762 resolve: {
719 763 parametrosFlete:
720   - function() {
  764 + function () {
721 765 return {
722 766 flete: $scope.remito.flete ? '1' :
723 767 ($scope.remito.fob ? 'FOB' :
724   - ($scope.remito.flete === undefined ?
725   - null : '0')),
  768 + ($scope.remito.flete === undefined ?
  769 + null : '0')),
726 770 bomba: $scope.remito.bomba ? '1' :
727 771 ($scope.remito.bomba === undefined ?
728 772 null : '0'),
... ... @@ -733,11 +777,11 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
733 777 }
734 778 );
735 779 modalInstance.result.then(
736   - function(datos) {
737   -
  780 + function (datos) {
  781 + $scope.remitoIsDirty = true;
738 782 $scope.remito.proveedor = proveedor;
739 783 $scope.remito.idProveedor = proveedor.COD;
740   - $scope.$broadcast('addCabecera',{
  784 + $scope.$broadcast('addCabecera', {
741 785 label: 'Proveedor:',
742 786 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
743 787 proveedor.NOM
... ... @@ -748,16 +792,16 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
748 792 $scope.remito.bomba = datos.bomba;
749 793 $scope.remito.kilometros = datos.kilometros;
750 794  
751   - $scope.$broadcast('addCabecera',{
  795 + $scope.$broadcast('addCabecera', {
752 796 label: 'Flete:',
753 797 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
754 798 });
755 799 if (datos.flete) {
756   - $scope.$broadcast('addCabecera',{
  800 + $scope.$broadcast('addCabecera', {
757 801 label: 'Bomba:',
758 802 valor: datos.bomba ? 'Si' : 'No'
759 803 });
760   - $scope.$broadcast('addCabecera',{
  804 + $scope.$broadcast('addCabecera', {
761 805 label: 'Kilometros:',
762 806 valor: datos.kilometros
763 807 });
... ... @@ -767,14 +811,17 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
767 811 $scope.remito.bomba = false;
768 812 $scope.remito.kilometros = null;
769 813 }
770   - }, function() {
  814 +
  815 + $filter('filter')($scope.botonera,
  816 + { label: 'Proveedor' })[0].checked = true;
  817 + }, function () {
771 818 $scope.seleccionarTransportista();
772 819 }
773 820 );
774 821 }
775 822 };
776 823  
777   - $scope.seleccionarMoneda = function() {
  824 + $scope.seleccionarMoneda = function () {
778 825 if (varlidarRemitoFacturado()) {
779 826 var parametrosModal = {
780 827 titulo: 'Búsqueda de monedas',
... ... @@ -792,16 +839,31 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
792 839 size: 'md'
793 840 };
794 841 focaModalService.modal(parametrosModal).then(
795   - function(moneda) {
796   - $scope.abrirModalCotizacion(moneda);
797   - }, function() {
  842 + function (moneda) {
  843 +
  844 + if (moneda.ID !== 1) {
  845 + $scope.abrirModalCotizacion(moneda);
  846 + return;
  847 + }
  848 +
  849 + crearRemitoService.getCotizacionByIdMoneda(1)
  850 + .then(function (res) {
  851 +
  852 + cotizacionPArgentino = res.data[0].cotizaciones[0];
  853 + cotizacionPArgentino.moneda = moneda;
  854 +
  855 + actualizarCabeceraMoneda(cotizacionPArgentino);
  856 +
  857 + $scope.remito.cotizacion = cotizacionPArgentino;
  858 + });
  859 + }, function () {
798 860  
799 861 }
800 862 );
801 863 }
802 864 };
803 865  
804   - $scope.seleccionarObservaciones = function() {
  866 + $scope.seleccionarObservaciones = function () {
805 867 focaModalService
806 868 .prompt({
807 869 titulo: 'Observaciones',
... ... @@ -809,64 +871,67 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
809 871 textarea: true,
810 872 readonly: true
811 873 })
812   - .then(function(observaciones) {
  874 + .then(function (observaciones) {
813 875 $scope.remito.observaciones = observaciones;
814 876 });
815 877 };
816 878  
817   - $scope.abrirModalCotizacion = function(moneda) {
  879 + $scope.abrirModalCotizacion = function (moneda) {
818 880 var modalInstance = $uibModal.open(
819 881 {
820 882 ariaLabelledBy: 'Busqueda de Cotización',
821 883 templateUrl: 'modal-cotizacion.html',
822 884 controller: 'focaModalCotizacionController',
823 885 size: 'lg',
824   - resolve: {idMoneda: function() {return moneda.ID;}}
  886 + resolve: { idMoneda: function () { return moneda.ID; } }
825 887 }
826 888 );
827 889 modalInstance.result.then(
828   - function(cotizacion) {
829   - var articulosTablaTemp = $scope.remito.articulosRemito;
830   - for(var i = 0; i < articulosTablaTemp.length; i++) {
831   - articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
832   - $scope.remito.cotizacion.VENDEDOR;
833   - articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
834   - cotizacion.VENDEDOR;
835   - }
836   - $scope.remito.articulosRemito = articulosTablaTemp;
  890 + function (cotizacion) {
  891 + cotizacion.moneda = moneda;
  892 + $scope.remitoIsDirty = true;
  893 + actualizarCabeceraMoneda(cotizacion);
837 894 $scope.remito.cotizacion = cotizacion;
838   - $scope.remito.cotizacion.moneda = moneda;
839   - if (moneda.DETALLE === 'PESOS ARGENTINOS') {
840   - $scope.$broadcast('removeCabecera', 'Moneda:');
841   - $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
842   - $scope.$broadcast('removeCabecera', 'Cotizacion:');
843   - } else {
844   - $scope.$broadcast('addCabecera',{
845   - label: 'Moneda:',
846   - valor: moneda.DETALLE
847   - });
848   - $scope.$broadcast('addCabecera',{
849   - label: 'Fecha cotizacion:',
850   - valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
851   - });
852   - $scope.$broadcast('addCabecera',{
853   - label: 'Cotizacion:',
854   - valor: $filter('number')(cotizacion.VENDEDOR, '2')
855   - });
856   - }
857   - }, function() {
  895 + }, function () {
858 896  
859 897 }
860 898 );
861 899 };
862 900  
863   - $scope.agregarATabla = function(key) {
  901 + function actualizarCabeceraMoneda(cotizacion) {
  902 +
  903 + $scope.remito.articulosRemito.forEach(function (art) {
  904 + art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4);
  905 + art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
  906 + });
  907 +
  908 + if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
  909 + $scope.$broadcast('removeCabecera', 'Moneda:');
  910 + $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
  911 + $scope.$broadcast('removeCabecera', 'Cotizacion:');
  912 + } else {
  913 + $scope.$broadcast('addCabecera', {
  914 + label: 'Moneda:',
  915 + valor: cotizacion.moneda.DETALLE
  916 + });
  917 + $scope.$broadcast('addCabecera', {
  918 + label: 'Fecha cotizacion:',
  919 + valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
  920 + });
  921 + $scope.$broadcast('addCabecera', {
  922 + label: 'Cotizacion:',
  923 + valor: $filter('number')(cotizacion.VENDEDOR, '2')
  924 + });
  925 + }
  926 + }
  927 +
  928 + $scope.agregarATabla = function (key) {
864 929 if (key === 13) {
865 930 if ($scope.articuloACargar.cantidad === undefined ||
866 931 $scope.articuloACargar.cantidad === 0 ||
867   - $scope.articuloACargar.cantidad === null ) {
868   - focaModalService.alert('El valor debe ser al menos 1');
869   - return;
  932 + $scope.articuloACargar.cantidad === null) {
  933 + focaModalService.alert('El valor debe ser al menos 1');
  934 + return;
870 935 }
871 936 delete $scope.articuloACargar.sectorCodigo;
872 937 $scope.remito.articulosRemito.push($scope.articuloACargar);
... ... @@ -874,19 +939,26 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
874 939 }
875 940 };
876 941  
877   - $scope.quitarArticulo = function(articulo) {
  942 + $scope.quitarArticulo = function (articulo) {
878 943 articulo.idRemito = -1;
879 944 };
880 945  
881   - $scope.articulosFiltro = function() {
  946 + $scope.articulosFiltro = function () {
882 947  
883   - var result = $scope.remito.articulosRemito.filter(function(articulo) {
  948 + var result = $scope.remito.articulosRemito.filter(function (articulo) {
884 949 return articulo.idRemito >= 0;
885 950 });
  951 +
  952 + // Agrego checked en cabecera si hay datos
  953 + if (result.length) {
  954 + $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true;
  955 + } else {
  956 + $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false;
  957 + }
886 958 return result;
887 959 };
888 960  
889   - $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) {
  961 + $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
890 962 if (key === 13) {
891 963 if (!articulo.cantidad || !articulo.precio) {
892 964 focaModalService.alert('Los valores deben ser al menos 1');
... ... @@ -902,13 +974,13 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
902 974 }
903 975 };
904 976  
905   - $scope.cancelarEditar = function(articulo) {
  977 + $scope.cancelarEditar = function (articulo) {
906 978 $scope.tmpCantidad = articulo.cantidad;
907 979 $scope.tmpPrecio = articulo.precio;
908 980 articulo.editCantidad = articulo.editPrecio = false;
909 981 };
910 982  
911   - $scope.cambioEdit = function(articulo, propiedad) {
  983 + $scope.cambioEdit = function (articulo, propiedad) {
912 984 if (propiedad === 'cantidad') {
913 985 articulo.editCantidad = true;
914 986 } else if (propiedad === 'precio') {
... ... @@ -916,12 +988,12 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
916 988 }
917 989 };
918 990  
919   - $scope.resetFilter = function() {
  991 + $scope.resetFilter = function () {
920 992 $scope.articuloACargar = {};
921 993 $scope.cargando = true;
922 994 };
923 995 //Recibe aviso si el teclado está en uso
924   - $rootScope.$on('usarTeclado', function(event, data) {
  996 + $rootScope.$on('usarTeclado', function (event, data) {
925 997 if (data) {
926 998 $scope.mostrarTeclado = true;
927 999 return;
... ... @@ -929,7 +1001,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
929 1001 $scope.mostrarTeclado = false;
930 1002 });
931 1003  
932   - $scope.selectFocus = function($event) {
  1004 + $scope.selectFocus = function ($event) {
933 1005 // Si el teclado esta en uso no selecciona el valor
934 1006 if ($scope.mostrarTeclado) {
935 1007 return;
... ... @@ -939,7 +1011,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
939 1011  
940 1012 function addArrayCabecera(array) {
941 1013 for (var i = 0; i < array.length; i++) {
942   - $scope.$broadcast('addCabecera',{
  1014 + $scope.$broadcast('addCabecera', {
943 1015 label: array[i].label,
944 1016 valor: array[i].valor
945 1017 });
... ... @@ -973,7 +1045,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
973 1045 if (confirmacion) {
974 1046 focaModalService.confirm(
975 1047 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
976   - ).then(function(data) {
  1048 + ).then(function (data) {
977 1049 if (data) {
978 1050 $location.path('/');
979 1051 }
... ... @@ -984,7 +1056,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
984 1056 }
985 1057  
986 1058 function enableObservaciones(val) {
987   - var boton = $scope.botonera.filter(function(botonObs) {
  1059 + var boton = $scope.botonera.filter(function (botonObs) {
988 1060 return botonObs.label === 'Observaciones';
989 1061 });
990 1062 boton[0].disable = !val;
... ... @@ -1005,7 +1077,7 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1005 1077 });
1006 1078 cabeceras.push({
1007 1079 label: 'Fecha cotizacion:',
1008   - valor: $filter('date')(remito.cotizacion.FECHA,
  1080 + valor: $filter('date')(remito.cotizacion.FECHA,
1009 1081 'dd/MM/yyyy')
1010 1082 });
1011 1083 cabeceras.push({
... ... @@ -1014,6 +1086,11 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1014 1086 '2')
1015 1087 });
1016 1088 }
  1089 +
  1090 + if (remito.cotizacion.moneda) {
  1091 + $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
  1092 + }
  1093 +
1017 1094 if (remito.cliente.COD) {
1018 1095 cabeceras.push({
1019 1096 label: 'Cliente:',
... ... @@ -1024,6 +1101,8 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1024 1101 label: 'Domicilio:',
1025 1102 valor: remito.domicilioStamp
1026 1103 });
  1104 +
  1105 + $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
1027 1106 }
1028 1107 if (remito.vendedor.NUM) {
1029 1108 cabeceras.push({
... ... @@ -1038,6 +1117,8 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1038 1117 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
1039 1118 ' - ' + remito.proveedor.NOM
1040 1119 });
  1120 +
  1121 + $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
1041 1122 }
1042 1123 if (remito.flete !== undefined && remito.fob !== undefined) {
1043 1124 cabeceras.push({
... ... @@ -1052,6 +1133,9 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1052 1133 valor: valorPrecioCondicion() + ' ' +
1053 1134 remitoBusinessService.plazoToString(remito.remitoPlazo)
1054 1135 });
  1136 +
  1137 + $filter('filter')($scope.botonera,
  1138 + { label: 'Precios y condiciones' })[0].checked = true;
1055 1139 }
1056 1140 function valorPrecioCondicion() {
1057 1141 if (remito.idPrecioCondicion > 0) {
... ... @@ -1083,13 +1167,27 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1083 1167 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1084 1168 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1085 1169 $scope.remito = remito;
1086   - if ($scope.remito.puntosDescarga) {
1087   - var puntosDescarga = $scope.remito.puntosDescarga;
  1170 + if ($scope.remito.remitoPuntoDescarga.length) {
  1171 + var puntoDescarga = [];
  1172 +
  1173 + $scope.remito.remitoPuntoDescarga.forEach(function(remitoPuntoDescarga) {
  1174 + puntoDescarga.push(remitoPuntoDescarga.puntoDescarga);
  1175 + });
  1176 +
1088 1177 cabeceras.push({
1089 1178 label: 'Puntos de descarga: ',
1090   - valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntosDescarga))
  1179 + valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga))
1091 1180 });
1092 1181 }
  1182 + $scope.remitoIsDirty = false;
  1183 +
  1184 + if ($scope.remito.articulosRemito.length) {
  1185 + $scope.remito.articulosRemito.forEach(function (articulo) {
  1186 + articulo.precio =
  1187 + (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4);
  1188 + });
  1189 + }
  1190 +
1093 1191 addArrayCabecera(cabeceras);
1094 1192 }
1095 1193  
... ... @@ -1102,18 +1200,19 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1102 1200 }
1103 1201  
1104 1202 function deleteCliente() {
1105   - delete $scope.remito.domicilioStamp;
1106   - delete $scope.remito.puntosDescarga;
1107   - $scope.remito.domicilio = {dom: ''};
  1203 + $scope.remito.domicilioStamp = '';
  1204 + $scope.remito.remitoPuntoDescarga = [];
  1205 + $scope.remito.domicilio = { dom: '' };
1108 1206 $scope.remito.cliente = {};
1109 1207 $scope.$broadcast('removeCabecera', 'Cliente:');
1110 1208 $scope.$broadcast('removeCabecera', 'Domicilio:');
1111 1209 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
  1210 + $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false;
1112 1211 }
1113 1212  
1114 1213 function getCabeceraPuntoDescarga(puntosDescarga) {
1115 1214 var puntosStamp = '';
1116   - puntosDescarga.forEach(function(punto, idx, arr) {
  1215 + puntosDescarga.forEach(function (punto, idx, arr) {
1117 1216 puntosStamp += punto.descripcion;
1118 1217 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1119 1218 });
... ... @@ -1137,13 +1236,28 @@ angular.module(&#39;focaCrearRemito&#39;) .controller(&#39;remitoController&#39;,
1137 1236 }
1138 1237 }
1139 1238 )
1140   - .then(function(res) {
1141   - if (res === false) {
1142   - abrirModalMail(id);
1143   - focaModalService.alert('Descarga o envíe su remito ' +
1144   - 'antes de cerrar esta ventana');
  1239 + .then(function (res) {
  1240 + if (res === false) {
  1241 + abrirModalMail(id);
  1242 + focaModalService.alert('Descarga o envíe su remito ' +
  1243 + 'antes de cerrar esta ventana');
  1244 + }
  1245 + });
  1246 + }
  1247 + //recibo la propiedad por la cual quiero obtener el valor
  1248 + function getImporte(propiedad) {
  1249 + var importe = 0;
  1250 +
  1251 + $scope.articulosFiltro().forEach(function (articulo) {
  1252 +
  1253 + if (articulo[propiedad]) {
  1254 + importe += articulo[propiedad] * articulo.cantidad;
1145 1255 }
  1256 + return;
  1257 +
1146 1258 });
  1259 +
  1260 + return importe;
1147 1261 }
1148 1262 }
1149 1263 ]);
... ... @@ -75,6 +75,13 @@ angular.module(&#39;focaCrearRemito&#39;)
75 75 enviarCorreo: function(options) {
76 76 return $http.post(API_ENDPOINT.URL + '/remito/mail', options);
77 77 },
  78 + getParametros: function() {
  79 + return $http.get(API_ENDPOINT.URL + '/parametros/remito');
  80 + },
  81 + crearPuntosDescarga: function(puntosDescarga) {
  82 + return $http.post(route + '/puntos-descarga/remito',
  83 + {puntosDescarga: puntosDescarga});
  84 + },
78 85 getBotonera: function() {
79 86 return [
80 87 {
src/views/remito.html
... ... @@ -212,7 +212,7 @@
212 212 <td class="text-right no-border-top">
213 213 <button
214 214 type="button"
215   - class="btn btn-default btn-sm"
  215 + class="btn btn-sm"
216 216 >
217 217 Totales
218 218 </button>