Commit 9e4386a38516864954f42ac5b2bab637c01e15a0

Authored by Marcelo Puebla
1 parent e3b7de210d
Exists in master and in 1 other branch develop

Codigo identado.

Showing 1 changed file with 51 additions and 46 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', 1 angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'crearNotaPedidoService', 8 'crearNotaPedidoService',
9 'focaBotoneraLateralService', 9 'focaBotoneraLateralService',
10 'focaModalService', 10 'focaModalService',
11 'notaPedidoBusinessService', 11 'notaPedidoBusinessService',
12 '$rootScope', 12 '$rootScope',
13 'focaSeguimientoService', 13 'focaSeguimientoService',
14 'APP', 14 'APP',
15 'focaLoginService', 15 'focaLoginService',
16 '$localStorage', 16 '$localStorage',
17 function ( 17 function (
18 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, 18 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService,
19 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, 19 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService,
20 $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) { 20 $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) {
21 config(); 21 config();
22 var cotizacionPArgentino = {}; 22 var cotizacionPArgentino = {};
23 23
24 function config() { 24 function config() {
25 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA 25 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA
26 $scope.tmpCantidad = Number; 26 $scope.tmpCantidad = Number;
27 $scope.tmpPrecio = Number; 27 $scope.tmpPrecio = Number;
28 $scope.notaPedido = {}; 28 $scope.notaPedido = {};
29 $scope.isNumber = angular.isNumber; 29 $scope.isNumber = angular.isNumber;
30 $scope.datepickerAbierto = false; 30 $scope.datepickerAbierto = false;
31 $scope.show = false; 31 $scope.show = false;
32 $scope.cargando = true; 32 $scope.cargando = true;
33 $scope.cabeceras = []; 33 $scope.cabeceras = [];
34 $scope.botonera = crearNotaPedidoService.getBotonera(); 34 $scope.botonera = crearNotaPedidoService.getBotonera();
35 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 35 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
36 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 36 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
37 $scope.dateOptions = { 37 $scope.dateOptions = {
38 maxDate: new Date(), 38 maxDate: new Date(),
39 minDate: new Date(2010, 0, 1) 39 minDate: new Date(2010, 0, 1)
40 }; 40 };
41 41
42 //SETEO BOTONERA LATERAL 42 //SETEO BOTONERA LATERAL
43 $timeout(function () { 43 $timeout(function () {
44 focaBotoneraLateralService.showSalir(false); 44 focaBotoneraLateralService.showSalir(false);
45 focaBotoneraLateralService.showPausar(true); 45 focaBotoneraLateralService.showPausar(true);
46 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); 46 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
47 focaBotoneraLateralService.addCustomButton('Salir', salir); 47 focaBotoneraLateralService.addCustomButton('Salir', salir);
48 }); 48 });
49 49
50 // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR 50 // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR
51 if (APP === 'distribuidor') { 51 if (APP === 'distribuidor') {
52 $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; 52 $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador;
53 } 53 }
54 54
55 crearNotaPedidoService.getParametros().then(function (res) { 55 crearNotaPedidoService.getParametros().then(function (res) {
56 var parametros = JSON.parse(res.data[0].jsonText); 56 var parametros = JSON.parse(res.data[0].jsonText);
57 if ($localStorage.notaPedido) { 57 if ($localStorage.notaPedido) {
58 $timeout(function () { getLSNotaPedido(); }); 58 $timeout(function () { getLSNotaPedido(); });
59 } else { 59 } else {
60 for (var property in parametros) { 60 for (var property in parametros) {
61 $scope.notaPedido[property] = parametros[property]; 61 $scope.notaPedido[property] = parametros[property];
62 $scope.inicial[property] = parametros[property]; 62 $scope.inicial[property] = parametros[property];
63 } 63 }
64 setearNotaPedido($scope.notaPedido); 64 setearNotaPedido($scope.notaPedido);
65 } 65 }
66 }); 66 });
67 67
68 init(); 68 init();
69 69
70 } 70 }
71 71
72 function init() { 72 function init() {
73 $scope.$broadcast('cleanCabecera'); 73 $scope.$broadcast('cleanCabecera');
74 74
75 $scope.notaPedido = { 75 $scope.notaPedido = {
76 id: 0, 76 id: 0,
77 cliente: {}, 77 cliente: {},
78 proveedor: {}, 78 proveedor: {},
79 domicilio: { dom: '' }, 79 domicilio: { dom: '' },
80 vendedor: {}, 80 vendedor: {},
81 fechaCarga: new Date(), 81 fechaCarga: new Date(),
82 cotizacion: {}, 82 cotizacion: {},
83 articulosNotaPedido: [], 83 articulosNotaPedido: [],
84 notaPedidoPlazo: [], 84 notaPedidoPlazo: [],
85 notaPedidoPuntoDescarga: [] 85 notaPedidoPuntoDescarga: []
86 }; 86 };
87 $scope.idLista = undefined; 87 $scope.idLista = undefined;
88 88
89 crearNotaPedidoService.getNumeroNotaPedido().then( 89 crearNotaPedidoService.getNumeroNotaPedido().then(
90 function (res) { 90 function (res) {
91 $scope.puntoVenta = $filter('rellenarDigitos')( 91 $scope.puntoVenta = $filter('rellenarDigitos')(
92 res.data.sucursal, 4 92 res.data.sucursal, 4
93 ); 93 );
94 94
95 $scope.comprobante = $filter('rellenarDigitos')( 95 $scope.comprobante = $filter('rellenarDigitos')(
96 res.data.numeroNotaPedido, 8 96 res.data.numeroNotaPedido, 8
97 ); 97 );
98 }, 98 },
99 function (err) { 99 function (err) {
100 focaModalService.alert('La terminal no esta configurada correctamente'); 100 focaModalService.alert('La terminal no esta configurada correctamente');
101 console.info(err); 101 console.info(err);
102 } 102 }
103 ); 103 );
104 104
105 if (APP === 'distribuidor') { 105 if (APP === 'distribuidor') {
106 crearNotaPedidoService.getVendedorById($scope.idVendedor).then( 106 crearNotaPedidoService.getVendedorById($scope.idVendedor).then(
107 function (res) { 107 function (res) {
108 var vendedor = res.data; 108 var vendedor = res.data;
109 $scope.$broadcast('addCabecera', { 109 $scope.$broadcast('addCabecera', {
110 label: 'Vendedor:', 110 label: 'Vendedor:',
111 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 111 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
112 vendedor.NOM 112 vendedor.NOM
113 }); 113 });
114 114
115 $scope.notaPedido.vendedor = vendedor; 115 $scope.notaPedido.vendedor = vendedor;
116 $scope.inicial.vendedor = $scope.notaPedido.vendedor; 116 $scope.inicial.vendedor = $scope.notaPedido.vendedor;
117 } 117 }
118 ); 118 );
119 } 119 }
120 120
121 $scope.inicial = angular.copy($scope.notaPedido); 121 $scope.inicial = angular.copy($scope.notaPedido);
122 } 122 }
123 123
124 $scope.$watch('notaPedido', function (newValue) { 124 $scope.$watch('notaPedido', function (newValue) {
125 focaBotoneraLateralService.setPausarData({ 125 focaBotoneraLateralService.setPausarData({
126 label: 'notaPedido', 126 label: 'notaPedido',
127 val: newValue 127 val: newValue
128 }); 128 });
129 }, true); 129 }, true);
130 130
131 $scope.crearNotaPedido = function () { 131 $scope.crearNotaPedido = function () {
132 if (!$scope.notaPedido.cliente.COD) { 132 if (!$scope.notaPedido.cliente.COD) {
133 focaModalService.alert('Ingrese Cliente'); 133 focaModalService.alert('Ingrese Cliente');
134 return; 134 return;
135 } else if ($scope.notaPedido.idRemito === -1) { 135 } else if ($scope.notaPedido.idRemito === -1) {
136 focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); 136 focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido');
137 return; 137 return;
138 } else if (!$scope.notaPedido.proveedor.COD) { 138 } else if (!$scope.notaPedido.proveedor.COD) {
139 focaModalService.alert('Ingrese Proveedor'); 139 focaModalService.alert('Ingrese Proveedor');
140 return; 140 return;
141 } else if (!$scope.notaPedido.cotizacion.ID) { 141 } else if (!$scope.notaPedido.cotizacion.ID) {
142 focaModalService.alert('Ingrese Cotización'); 142 focaModalService.alert('Ingrese Cotización');
143 return; 143 return;
144 } else if (!$scope.notaPedido.cotizacion.moneda.ID) { 144 } else if (!$scope.notaPedido.cotizacion.moneda.ID) {
145 focaModalService.alert('Ingrese Moneda'); 145 focaModalService.alert('Ingrese Moneda');
146 return; 146 return;
147 } else if (!$scope.notaPedido.notaPedidoPlazo) { 147 } else if (!$scope.notaPedido.notaPedidoPlazo) {
148 focaModalService.alert('Ingrese Precios y Condiciones'); 148 focaModalService.alert('Ingrese Precios y Condiciones');
149 return; 149 return;
150 } else if ( 150 } else if (
151 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) { 151 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) {
152 focaModalService.alert('Ingrese Flete'); 152 focaModalService.alert('Ingrese Flete');
153 return; 153 return;
154 } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto 154 } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto
155 focaModalService.alert('Ingrese Domicilio'); 155 focaModalService.alert('Ingrese Domicilio');
156 return; 156 return;
157 } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { 157 } else if ($scope.notaPedido.articulosNotaPedido.length === 0) {
158 focaModalService.alert('Debe cargar al menos un articulo'); 158 focaModalService.alert('Debe cargar al menos un articulo');
159 return; 159 return;
160 } 160 }
161 161
162 focaBotoneraLateralService.startGuardar(); 162 focaBotoneraLateralService.startGuardar();
163 $scope.saveLoading = true; 163 $scope.saveLoading = true;
164 var notaPedido = { 164 var notaPedido = {
165 id: $scope.notaPedido.id, 165 id: $scope.notaPedido.id,
166 fechaCarga: new Date($scope.notaPedido.fechaCarga) 166 fechaCarga: new Date($scope.notaPedido.fechaCarga)
167 .toISOString().slice(0, 19).replace('T', ' '), 167 .toISOString().slice(0, 19).replace('T', ' '),
168 idVendedor: $scope.notaPedido.vendedor.id, 168 idVendedor: $scope.notaPedido.vendedor.id,
169 idCliente: $scope.notaPedido.cliente.COD, 169 idCliente: $scope.notaPedido.cliente.COD,
170 nombreCliente: $scope.notaPedido.cliente.NOM, 170 nombreCliente: $scope.notaPedido.cliente.NOM,
171 cuitCliente: $scope.notaPedido.cliente.CUIT, 171 cuitCliente: $scope.notaPedido.cliente.CUIT,
172 idProveedor: $scope.notaPedido.proveedor.COD, 172 idProveedor: $scope.notaPedido.proveedor.COD,
173 idDomicilio: $scope.notaPedido.domicilio.id, 173 idDomicilio: $scope.notaPedido.domicilio.id,
174 idCotizacion: $scope.notaPedido.cotizacion.ID, 174 idCotizacion: $scope.notaPedido.cotizacion.ID,
175 idListaPrecio: $scope.notaPedido.idPrecioCondicion, 175 idListaPrecio: $scope.notaPedido.idPrecioCondicion,
176 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 176 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
177 flete: $scope.notaPedido.flete, 177 flete: $scope.notaPedido.flete,
178 fob: $scope.notaPedido.fob, 178 fob: $scope.notaPedido.fob,
179 bomba: $scope.notaPedido.bomba, 179 bomba: $scope.notaPedido.bomba,
180 kilometros: $scope.notaPedido.kilometros, 180 kilometros: $scope.notaPedido.kilometros,
181 domicilioStamp: $scope.notaPedido.domicilioStamp, 181 domicilioStamp: $scope.notaPedido.domicilioStamp,
182 observaciones: $scope.notaPedido.observaciones, 182 observaciones: $scope.notaPedido.observaciones,
183 estado: 0, 183 estado: 0,
184 total: $scope.getTotal() 184 total: $scope.getTotal()
185 }; 185 };
186 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 186 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
187 function (data) { 187 function (data) {
188 // Al guardar los datos de la nota de pedido logueamos la 188 // Al guardar los datos de la nota de pedido logueamos la
189 // actividad para su seguimiento. 189 // actividad para su seguimiento.
190 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? 190 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR?
191 focaSeguimientoService.guardarPosicion( 191 focaSeguimientoService.guardarPosicion(
192 'Nota de pedido', 192 'Nota de pedido',
193 data.data.id, 193 data.data.id,
194 '' 194 ''
195 ); 195 );
196 notaPedidoBusinessService.addArticulos( 196 notaPedidoBusinessService.addArticulos(
197 $scope.notaPedido.articulosNotaPedido, 197 $scope.notaPedido.articulosNotaPedido,
198 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); 198 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR);
199 199
200 if ($scope.notaPedido.notaPedidoPuntoDescarga.length > 0) { 200 if ($scope.notaPedido.notaPedidoPuntoDescarga.length > 0) {
201 notaPedidoBusinessService.addPuntosDescarga(data.data.id, 201 notaPedidoBusinessService.addPuntosDescarga(data.data.id,
202 $scope.notaPedido.notaPedidoPuntoDescarga); 202 $scope.notaPedido.notaPedidoPuntoDescarga);
203 } 203 }
204 204
205 var plazos = $scope.notaPedido.notaPedidoPlazo; 205 var plazos = $scope.notaPedido.notaPedidoPlazo;
206 var plazosACrear = []; 206 var plazosACrear = [];
207 plazos.forEach(function (plazo) { 207 plazos.forEach(function (plazo) {
208 plazosACrear.push({ 208 plazosACrear.push({
209 idNotaPedido: data.data.id, 209 idNotaPedido: data.data.id,
210 dias: plazo.dias 210 dias: plazo.dias
211 }); 211 });
212 }); 212 });
213 213
214 if (plazosACrear.length) { 214 if (plazosACrear.length) {
215 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); 215 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear);
216 } 216 }
217 217
218 notaPedidoBusinessService.addEstado(data.data.id, 218 notaPedidoBusinessService.addEstado(data.data.id,
219 $scope.notaPedido.vendedor.id); 219 $scope.notaPedido.vendedor.id);
220 220
221 focaBotoneraLateralService.endGuardar(true); 221 focaBotoneraLateralService.endGuardar(true);
222 $scope.saveLoading = false; 222 $scope.saveLoading = false;
223 223
224 config(); 224 config();
225 }, function (error) { 225 }, function (error) {
226 focaModalService.alert('Hubo un error al crear la nota de pedido'); 226 focaModalService.alert('Hubo un error al crear la nota de pedido');
227 focaBotoneraLateralService.endGuardar(); 227 focaBotoneraLateralService.endGuardar();
228 $scope.saveLoading = false; 228 $scope.saveLoading = false;
229 console.info(error); 229 console.info(error);
230 }); 230 });
231 }; 231 };
232 232
233 $scope.seleccionarNotaPedido = function () { 233 $scope.seleccionarNotaPedido = function () {
234 var modalInstance = $uibModal.open( 234 var modalInstance = $uibModal.open(
235 { 235 {
236 ariaLabelledBy: 'Busqueda de Nota de Pedido', 236 ariaLabelledBy: 'Busqueda de Nota de Pedido',
237 templateUrl: 'foca-modal-nota-pedido.html', 237 templateUrl: 'foca-modal-nota-pedido.html',
238 controller: 'focaModalNotaPedidoController', 238 controller: 'focaModalNotaPedidoController',
239 size: 'lg', 239 size: 'lg',
240 resolve: { 240 resolve: {
241 usadoPor: function () { return 'notaPedido'; }, 241 usadoPor: function () { return 'notaPedido'; },
242 idVendedor: function () { 242 idVendedor: function () {
243 if (APP === 'distribuidor') 243 if (APP === 'distribuidor')
244 return $scope.notaPedido.vendedor.id; 244 return $scope.notaPedido.vendedor.id;
245 else 245 else
246 return null; 246 return null;
247 } 247 }
248 } 248 }
249 } 249 }
250 ); 250 );
251 modalInstance.result.then(function(notaPedido) { 251 modalInstance.result.then(function (notaPedido) {
252 252
253 notaPedido.articulosNotaPedido.forEach(function (articulo) { 253 notaPedido.articulosNotaPedido.forEach(function (articulo) {
254 articulo.precio = 254 articulo.precio =
255 (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); 255 (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4);
256 }); 256 });
257 257
258 setearNotaPedido(notaPedido); 258 setearNotaPedido(notaPedido);
259 }); 259 });
260 }; 260 };
261 261
262 $scope.seleccionarProductos = function () { 262 $scope.seleccionarProductos = function () {
263 if ($scope.idLista === undefined) { 263 if ($scope.idLista === undefined) {
264 focaModalService.alert('Primero seleccione una lista de precio y condición'); 264 focaModalService.alert('Primero seleccione una lista de precio y condición');
265 return; 265 return;
266 } else if (!validarNotaRemitada()) { 266 } else if (!validarNotaRemitada()) {
267 return; 267 return;
268 } 268 }
269 269
270 var modalInstance = $uibModal.open( 270 var modalInstance = $uibModal.open(
271 { 271 {
272 ariaLabelledBy: 'Busqueda de Productos', 272 ariaLabelledBy: 'Busqueda de Productos',
273 templateUrl: 'modal-busqueda-productos.html', 273 templateUrl: 'modal-busqueda-productos.html',
274 controller: 'modalBusquedaProductosCtrl', 274 controller: 'modalBusquedaProductosCtrl',
275 resolve: { 275 resolve: {
276 parametroProducto: { 276 parametroProducto: {
277 idLista: $scope.idLista, 277 idLista: $scope.idLista,
278 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 278 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
279 simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO 279 simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO
280 } 280 }
281 }, 281 },
282 size: 'lg' 282 size: 'lg'
283 } 283 }
284 ); 284 );
285 modalInstance.result.then( 285 modalInstance.result.then(
286 function (producto) { 286 function (producto) {
287 var newArt = 287 var newArt =
288 { 288 {
289 id: 0, 289 id: 0,
290 codigo: producto.codigo, 290 codigo: producto.codigo,
291 sector: producto.sector, 291 sector: producto.sector,
292 sectorCodigo: producto.sector + '-' + producto.codigo, 292 sectorCodigo: producto.sector + '-' + producto.codigo,
293 descripcion: producto.descripcionLarga, 293 descripcion: producto.descripcionLarga,
294 item: $scope.notaPedido.articulosNotaPedido.length + 1, 294 item: $scope.notaPedido.articulosNotaPedido.length + 1,
295 nombre: producto.descripcion, 295 nombre: producto.descripcion,
296 precio: parseFloat(producto.precio.toFixed(4)), 296 precio: parseFloat(producto.precio.toFixed(4)),
297 costoUnitario: producto.costo, 297 costoUnitario: producto.costo,
298 editCantidad: false, 298 editCantidad: false,
299 editPrecio: false, 299 editPrecio: false,
300 rubro: producto.CodRub, 300 rubro: producto.CodRub,
301 ivaUnitario: producto.IMPIVA, 301 ivaUnitario: producto.IMPIVA,
302 impuestoInternoUnitario: producto.ImpInt, 302 impuestoInternoUnitario: producto.ImpInt,
303 impuestoInterno1Unitario: producto.ImpInt2, 303 impuestoInterno1Unitario: producto.ImpInt2,
304 impuestoInterno2Unitario: producto.ImpInt3, 304 impuestoInterno2Unitario: producto.ImpInt3,
305 precioLista: producto.precio, 305 precioLista: producto.precio,
306 combustible: 1, 306 combustible: 1,
307 facturado: 0, 307 facturado: 0,
308 idArticulo: producto.id, 308 idArticulo: producto.id,
309 tasaIva: producto.tasaIVA 309 tasaIva: producto.tasaIVA
310 }; 310 };
311 311
312 newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; 312 newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto;
313 newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; 313 newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0;
314 314
315 $scope.articuloACargar = newArt; 315 $scope.articuloACargar = newArt;
316 $scope.cargando = false; 316 $scope.cargando = false;
317 }, function () { 317 }, function () {
318 // funcion ejecutada cuando se cancela el modal 318 // funcion ejecutada cuando se cancela el modal
319 } 319 }
320 ); 320 );
321 }; 321 };
322 322
323 $scope.seleccionarPuntosDeDescarga = function () { 323 $scope.seleccionarPuntosDeDescarga = function () {
324 if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { 324 if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) {
325 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 325 focaModalService.alert('Primero seleccione un cliente y un domicilio');
326 return; 326 return;
327 } else { 327 } else {
328 var modalInstance = $uibModal.open( 328 var modalInstance = $uibModal.open(
329 { 329 {
330 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 330 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
331 templateUrl: 'modal-punto-descarga.html', 331 templateUrl: 'modal-punto-descarga.html',
332 controller: 'focaModalPuntoDescargaController', 332 controller: 'focaModalPuntoDescargaController',
333 size: 'lg', 333 size: 'lg',
334 resolve: { 334 resolve: {
335 filters: { 335 filters: {
336 idDomicilio: $scope.notaPedido.domicilio.id, 336 idDomicilio: $scope.notaPedido.domicilio.id,
337 idCliente: $scope.notaPedido.cliente.COD, 337 idCliente: $scope.notaPedido.cliente.COD,
338 articulos: $scope.notaPedido.articulosNotaPedido, 338 articulos: $scope.notaPedido.articulosNotaPedido,
339 puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, 339 puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga,
340 domicilio: $scope.notaPedido.domicilio 340 domicilio: $scope.notaPedido.domicilio
341 } 341 }
342 } 342 }
343 } 343 }
344 ); 344 );
345 modalInstance.result.then( 345 modalInstance.result.then(
346 function (puntoDescarga) { 346 function (puntoDescarga) {
347 347
348 puntoDescarga.forEach(function (punto) { 348 puntoDescarga.forEach(function (punto) {
349 $scope.notaPedido.notaPedidoPuntoDescarga.push( 349 $scope.notaPedido.notaPedidoPuntoDescarga.push(
350 { 350 {
351 puntoDescarga: punto 351 puntoDescarga: punto
352 } 352 }
353 ); 353 );
354 }); 354 });
355 355
356 $scope.$broadcast('addCabecera', { 356 $scope.$broadcast('addCabecera', {
357 label: 'Puntos de descarga:', 357 label: 'Puntos de descarga:',
358 valor: getCabeceraPuntoDescarga(puntoDescarga) 358 valor: getCabeceraPuntoDescarga(puntoDescarga)
359 }); 359 });
360 }, function () { 360 }, function () {
361 $scope.abrirModalDomicilios($scope.cliente); 361 $scope.abrirModalDomicilios($scope.cliente);
362 } 362 }
363 ); 363 );
364 } 364 }
365 }; 365 };
366 366
367 $scope.seleccionarDomicilioDeEntrega = function () { 367 $scope.seleccionarDomicilioDeEntrega = function () {
368 if (!$scope.notaPedido.cliente.COD) { 368 if (!$scope.notaPedido.cliente.COD) {
369 focaModalService.alert('Seleccione un Cliente'); 369 focaModalService.alert('Seleccione un Cliente');
370 return; 370 return;
371 } else { 371 } else {
372 $scope.abrirModalDomicilios($scope.cliente); 372 $scope.abrirModalDomicilios($scope.cliente);
373 } 373 }
374 }; 374 };
375 $scope.seleccionarProveedor = function () { 375 $scope.seleccionarProveedor = function () {
376 $scope.abrirModalProveedores(function () { 376 $scope.abrirModalProveedores(function () {
377 if (validarNotaRemitada()) { 377 if (validarNotaRemitada()) {
378 var modalInstance = $uibModal.open( 378 var modalInstance = $uibModal.open(
379 { 379 {
380 ariaLabelledBy: 'Busqueda de Flete', 380 ariaLabelledBy: 'Busqueda de Flete',
381 templateUrl: 'modal-flete.html', 381 templateUrl: 'modal-flete.html',
382 controller: 'focaModalFleteController', 382 controller: 'focaModalFleteController',
383 size: 'lg', 383 size: 'lg',
384 resolve: { 384 resolve: {
385 parametrosFlete: 385 parametrosFlete:
386 function () { 386 function () {
387 return { 387 return {
388 flete: $scope.notaPedido.fob ? 'FOB' : 388 flete: $scope.notaPedido.fob ? 'FOB' :
389 ($scope.notaPedido.flete ? '1' : 389 ($scope.notaPedido.flete ? '1' :
390 ($scope.notaPedido.flete === undefined ? 390 ($scope.notaPedido.flete === undefined ?
391 null : '0')), 391 null : '0')),
392 bomba: $scope.notaPedido.bomba ? '1' : 392 bomba: $scope.notaPedido.bomba ? '1' :
393 ($scope.notaPedido.bomba === undefined ? 393 ($scope.notaPedido.bomba === undefined ?
394 null : '0'), 394 null : '0'),
395 kilometros: $scope.notaPedido.kilometros 395 kilometros: $scope.notaPedido.kilometros
396 }; 396 };
397 } 397 }
398 } 398 }
399 } 399 }
400 ); 400 );
401 modalInstance.result.then( 401 modalInstance.result.then(
402 function (datos) { 402 function (datos) {
403 $scope.notaPedido.flete = datos.flete; 403 $scope.notaPedido.flete = datos.flete;
404 $scope.notaPedido.fob = datos.FOB; 404 $scope.notaPedido.fob = datos.FOB;
405 $scope.notaPedido.bomba = datos.bomba; 405 $scope.notaPedido.bomba = datos.bomba;
406 $scope.notaPedido.kilometros = datos.kilometros; 406 $scope.notaPedido.kilometros = datos.kilometros;
407 $scope.$broadcast('addCabecera', { 407 $scope.$broadcast('addCabecera', {
408 label: 'Flete:', 408 label: 'Flete:',
409 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') 409 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')
410 }); 410 });
411 if (datos.flete) { 411 if (datos.flete) {
412 $scope.$broadcast('addCabecera', { 412 $scope.$broadcast('addCabecera', {
413 label: 'Bomba:', 413 label: 'Bomba:',
414 valor: datos.bomba ? 'Si' : 'No' 414 valor: datos.bomba ? 'Si' : 'No'
415 }); 415 });
416 $scope.$broadcast('addCabecera', { 416 $scope.$broadcast('addCabecera', {
417 label: 'Kilometros:', 417 label: 'Kilometros:',
418 valor: datos.kilometros 418 valor: datos.kilometros
419 }); 419 });
420 } else { 420 } else {
421 $scope.$broadcast('removeCabecera', 'Bomba:'); 421 $scope.$broadcast('removeCabecera', 'Bomba:');
422 $scope.$broadcast('removeCabecera', 'Kilometros:'); 422 $scope.$broadcast('removeCabecera', 'Kilometros:');
423 $scope.notaPedido.bomba = false; 423 $scope.notaPedido.bomba = false;
424 $scope.notaPedido.kilometros = null; 424 $scope.notaPedido.kilometros = null;
425 } 425 }
426 426
427 $filter('filter')($scope.botonera, 427 $filter('filter')($scope.botonera,
428 { label: 'Proveedor' })[0].checked = true; 428 { label: 'Proveedor' })[0].checked = true;
429 }, function () { 429 }, function () {
430 $scope.seleccionarTransportista(); 430 $scope.seleccionarTransportista();
431 } 431 }
432 ); 432 );
433 } 433 }
434 }); 434 });
435 }; 435 };
436 436
437 $scope.seleccionarVendedor = function (callback, ocultarVendedor) { 437 $scope.seleccionarVendedor = function (callback, ocultarVendedor) {
438 if (APP === 'distribuidor' || ocultarVendedor) { 438 if (APP === 'distribuidor' || ocultarVendedor) {
439 callback(); 439 callback();
440 return; 440 return;
441 } 441 }
442 442
443 if (validarNotaRemitada()) { 443 if (validarNotaRemitada()) {
444 var parametrosModal = { 444 var parametrosModal = {
445 titulo: 'Búsqueda vendedores', 445 titulo: 'Búsqueda vendedores',
446 query: '/vendedor', 446 query: '/vendedor',
447 columnas: [ 447 columnas: [
448 { 448 {
449 propiedad: 'NUM', 449 propiedad: 'NUM',
450 nombre: 'Código', 450 nombre: 'Código',
451 filtro: { 451 filtro: {
452 nombre: 'rellenarDigitos', 452 nombre: 'rellenarDigitos',
453 parametro: 3 453 parametro: 3
454 } 454 }
455 }, 455 },
456 { 456 {
457 propiedad: 'NOM', 457 propiedad: 'NOM',
458 nombre: 'Nombre' 458 nombre: 'Nombre'
459 } 459 }
460 ], 460 ],
461 size: 'md' 461 size: 'md'
462 }; 462 };
463 focaModalService.modal(parametrosModal).then( 463 focaModalService.modal(parametrosModal).then(
464 function (vendedor) { 464 function (vendedor) {
465 $scope.$broadcast('addCabecera', { 465 $scope.$broadcast('addCabecera', {
466 label: 'Vendedor:', 466 label: 'Vendedor:',
467 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 467 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
468 vendedor.NOM 468 vendedor.NOM
469 }); 469 });
470 $scope.notaPedido.vendedor = vendedor; 470 $scope.notaPedido.vendedor = vendedor;
471 deleteCliente(); 471 deleteCliente();
472 callback(); 472 callback();
473 }, function () { } 473 }, function () { }
474 ); 474 );
475 } 475 }
476 }; 476 };
477 477
478 $scope.seleccionarCliente = function () { 478 $scope.seleccionarCliente = function () {
479 if (validarNotaRemitada()) { 479 if (validarNotaRemitada()) {
480 480
481 var modalInstance = $uibModal.open( 481 var modalInstance = $uibModal.open(
482 { 482 {
483 ariaLabelledBy: 'Busqueda de Cliente', 483 ariaLabelledBy: 'Busqueda de Cliente',
484 templateUrl: 'foca-busqueda-cliente-modal.html', 484 templateUrl: 'foca-busqueda-cliente-modal.html',
485 controller: 'focaBusquedaClienteModalController', 485 controller: 'focaBusquedaClienteModalController',
486 resolve: { 486 resolve: {
487 vendedor: function () { return { id: $scope.idVendedor} }, 487 vendedor: function () { return { id: $scope.idVendedor }; },
488 cobrador: function () { return null; } 488 cobrador: function () { return null; }
489 }, 489 },
490 size: 'lg' 490 size: 'lg'
491 } 491 }
492 ); 492 );
493 modalInstance.result.then( 493 modalInstance.result.then(
494 function (cliente) { 494 function (cliente) {
495 cliente.mod = cliente.mod; 495 cliente.mod = cliente.mod;
496 $scope.abrirModalDomicilios(cliente); 496 $scope.abrirModalDomicilios(cliente);
497 $scope.cliente = cliente; 497 $scope.cliente = cliente;
498 }, function () { } 498 }, function () { }
499 ); 499 );
500 } 500 }
501 }; 501 };
502 502
503 $scope.abrirModalProveedores = function (callback) { 503 $scope.abrirModalProveedores = function (callback) {
504 if (validarNotaRemitada()) { 504 if (validarNotaRemitada()) {
505 var parametrosModal = { 505 var parametrosModal = {
506 titulo: 'Búsqueda de Proveedor', 506 titulo: 'Búsqueda de Proveedor',
507 query: '/proveedor', 507 query: '/proveedor',
508 columnas: [ 508 columnas: [
509 { 509 {
510 nombre: 'Código', 510 nombre: 'Código',
511 propiedad: 'COD', 511 propiedad: 'COD',
512 filtro: { 512 filtro: {
513 nombre: 'rellenarDigitos', 513 nombre: 'rellenarDigitos',
514 parametro: 5 514 parametro: 5
515 } 515 }
516 }, 516 },
517 { 517 {
518 nombre: 'Nombre', 518 nombre: 'Nombre',
519 propiedad: 'NOM' 519 propiedad: 'NOM'
520 }, 520 },
521 { 521 {
522 nombre: 'CUIT', 522 nombre: 'CUIT',
523 propiedad: 'CUIT' 523 propiedad: 'CUIT'
524 } 524 }
525 ], 525 ],
526 tipo: 'POST', 526 tipo: 'POST',
527 json: { razonCuitCod: '' } 527 json: { razonCuitCod: '' }
528 }; 528 };
529 focaModalService.modal(parametrosModal).then( 529 focaModalService.modal(parametrosModal).then(
530 function (proveedor) { 530 function (proveedor) {
531 $scope.notaPedido.proveedor = proveedor; 531 $scope.notaPedido.proveedor = proveedor;
532 $scope.$broadcast('addCabecera', { 532 $scope.$broadcast('addCabecera', {
533 label: 'Proveedor:', 533 label: 'Proveedor:',
534 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 534 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
535 proveedor.NOM 535 proveedor.NOM
536 }); 536 });
537 callback(); 537 callback();
538 }, function () { 538 }, function () {
539 539
540 } 540 }
541 ); 541 );
542 } 542 }
543 }; 543 };
544 544
545 $scope.abrirModalDomicilios = function (cliente) { 545 $scope.abrirModalDomicilios = function (cliente) {
546 var modalInstanceDomicilio = $uibModal.open( 546 var modalInstanceDomicilio = $uibModal.open(
547 { 547 {
548 ariaLabelledBy: 'Busqueda de Domicilios', 548 ariaLabelledBy: 'Busqueda de Domicilios',
549 templateUrl: 'modal-domicilio.html', 549 templateUrl: 'modal-domicilio.html',
550 controller: 'focaModalDomicilioController', 550 controller: 'focaModalDomicilioController',
551 resolve: { 551 resolve: {
552 idCliente: function () { return cliente.cod; }, 552 idCliente: function () { return cliente.cod; },
553 esNuevo: function () { return cliente.esNuevo; } 553 esNuevo: function () { return cliente.esNuevo; }
554 }, 554 },
555 size: 'lg', 555 size: 'lg',
556 } 556 }
557 ); 557 );
558 modalInstanceDomicilio.result.then( 558 modalInstanceDomicilio.result.then(
559 function (domicilio) { 559 function (domicilio) {
560 $scope.notaPedido.domicilio = domicilio; 560 $scope.notaPedido.domicilio = domicilio;
561 $scope.notaPedido.cliente = { 561 $scope.notaPedido.cliente = {
562 COD: cliente.cod, 562 COD: cliente.cod,
563 CUIT: cliente.cuit, 563 CUIT: cliente.cuit,
564 NOM: cliente.nom, 564 NOM: cliente.nom,
565 MOD: cliente.mod, 565 MOD: cliente.mod,
566 VEN: cliente.ven 566 VEN: cliente.ven
567 }; 567 };
568 crearNotaPedidoService.getVendedorById($scope.notaPedido.cliente.VEN) 568 crearNotaPedidoService.getVendedorById($scope.notaPedido.cliente.VEN)
569 .then(function (res) { 569 .then(function (res) {
570 if (res.data !== '') { 570 if (res.data !== '') {
571 $scope.notaPedido.vendedor = res.data; 571 $scope.notaPedido.vendedor = res.data;
572 $scope.$broadcast('addCabecera', { 572 $scope.$broadcast('addCabecera', {
573 label: 'Vendedor:', 573 label: 'Vendedor:',
574 valor: $filter('rellenarDigitos') 574 valor: $filter('rellenarDigitos')
575 ($scope.notaPedido.vendedor.NUM, 3) + 575 ($scope.notaPedido.vendedor.NUM, 3) +
576 ' - ' + $scope.notaPedido.vendedor.NOM 576 ' - ' + $scope.notaPedido.vendedor.NOM
577 }); 577 });
578 } 578 }
579 var domicilioStamp = 579 var domicilioStamp =
580 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 580 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
581 domicilio.Localidad + ', ' + domicilio.Provincia; 581 domicilio.Localidad + ', ' + domicilio.Provincia;
582 $scope.notaPedido.domicilioStamp = domicilioStamp; 582 $scope.notaPedido.domicilioStamp = domicilioStamp;
583 583
584 $scope.$broadcast('addCabecera', { 584 $scope.$broadcast('addCabecera', {
585 label: 'Cliente:', 585 label: 'Cliente:',
586 valor: $filter('rellenarDigitos')(cliente.cod, 5) + 586 valor: $filter('rellenarDigitos')(cliente.cod, 5) +
587 ' - ' + cliente.nom 587 ' - ' + cliente.nom
588 }); 588 });
589 589
590 $scope.$broadcast('addCabecera', { 590 $scope.$broadcast('addCabecera', {
591 label: 'Domicilio:', 591 label: 'Domicilio:',
592 valor: domicilioStamp 592 valor: domicilioStamp
593 }); 593 });
594 594
595 if (domicilio.verPuntos) { 595 if (domicilio.verPuntos) {
596 delete $scope.notaPedido.domicilio.verPuntos; 596 delete $scope.notaPedido.domicilio.verPuntos;
597 $scope.seleccionarPuntosDeDescarga(); 597 $scope.seleccionarPuntosDeDescarga();
598 } 598 }
599 599
600 // Seteo checked en botonera 600 // Seteo checked en botonera
601 $filter('filter')($scope.botonera, 601 $filter('filter')($scope.botonera,
602 { label: 'Cliente' })[0].checked = true; 602 { label: 'Cliente' })[0].checked = true;
603 $filter('filter')($scope.botonera, 603 $filter('filter')($scope.botonera,
604 { label: 'Domicilio de Entrega' })[0].checked = true; 604 { label: 'Domicilio de Entrega' })[0].checked = true;
605 }) 605 })
606 .catch(function (e) { console.log(e); }); 606 .catch(function (e) { console.log(e); });
607 }, function () { 607 }, function () {
608 $scope.seleccionarCliente(true); 608 $scope.seleccionarCliente(true);
609 return; 609 return;
610 } 610 }
611 ); 611 );
612 }; 612 };
613 613
614 $scope.getTotal = function () { 614 $scope.getTotal = function () {
615 var total = 0; 615 var total = 0;
616 if ($scope.notaPedido.articulosNotaPedido) { 616 if ($scope.notaPedido.articulosNotaPedido) {
617 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; 617 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido;
618 for (var i = 0; i < arrayTempArticulos.length; i++) { 618 for (var i = 0; i < arrayTempArticulos.length; i++) {
619 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 619 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
620 } 620 }
621 } 621 }
622 return parseFloat(total.toFixed(2)); 622 return parseFloat(total.toFixed(2));
623 }; 623 };
624 624
625 $scope.getSubTotal = function () { 625 $scope.getSubTotal = function () {
626 if ($scope.articuloACargar) { 626 if ($scope.articuloACargar) {
627 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 627 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
628 } 628 }
629 }; 629 };
630 630
631 $scope.seleccionarPreciosYCondiciones = function () { 631 $scope.seleccionarPreciosYCondiciones = function () {
632 632
633 if (!validarNotaRemitada()) { 633 if (!validarNotaRemitada()) {
634 return; 634 return;
635 } 635 }
636 636
637 if (!$scope.notaPedido.cliente.COD) { 637 if (!$scope.notaPedido.cliente.COD) {
638 focaModalService.alert('Primero seleccione un cliente'); 638 focaModalService.alert('Primero seleccione un cliente');
639 return; 639 return;
640 } else { 640 } else {
641 abrirModal(); 641 abrirModal();
642 } 642 }
643 643
644 function abrirModal() { 644 function abrirModal() {
645 var parametros = { idCliente: $scope.notaPedido.cliente.COD, idListaPrecio : $scope.notaPedido.cliente.MOD, 645 var parametros = {
646 notaPedido: $scope.notaPedido }; 646 idCliente: $scope.notaPedido.cliente.COD,
647 idListaPrecio: $scope.notaPedido.cliente.MOD,
648 notaPedido: $scope.notaPedido
649 };
647 var modalInstance = $uibModal.open( 650 var modalInstance = $uibModal.open(
648 { 651 {
649 ariaLabelledBy: 'Busqueda de Precio Condición', 652 ariaLabelledBy: 'Busqueda de Precio Condición',
650 templateUrl: 'modal-precio-condicion.html', 653 templateUrl: 'modal-precio-condicion.html',
651 controller: 'focaModalPrecioCondicionController', 654 controller: 'focaModalPrecioCondicionController',
652 size: 'lg', 655 size: 'lg',
653 resolve: { 656 resolve: {
654 parametros: function () { return parametros; }, 657 parametros: function () { return parametros; },
655 } 658 }
656 } 659 }
657 ); 660 );
658 661
659 modalInstance.result 662 modalInstance.result.then(function (precioCondicion) {
660 .then(function (precioCondicion) { 663 var cabecera = '';
661 var cabecera = ''; 664 var plazosConcat = '';
662 var plazosConcat = ''; 665 if (!Array.isArray(precioCondicion)) {
663 if (!Array.isArray(precioCondicion)) { 666 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago;
664 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; 667 $scope.notaPedido.precioCondicion = precioCondicion;
665 $scope.notaPedido.precioCondicion = precioCondicion; 668 $scope.notaPedido.idPrecioCondicion = precioCondicion.listaPrecio.ID;
666 $scope.notaPedido.idPrecioCondicion = precioCondicion.listaPrecio.ID; 669 $scope.notaPedido.cliente.MOD = precioCondicion.listaPrecio.ID;
667 $scope.notaPedido.cliente.MOD = precioCondicion.listaPrecio.ID; 670 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ?
668 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? 671 parseInt(precioCondicion.listaPrecio.ID) : -1;
669 parseInt(precioCondicion.listaPrecio.ID) : -1; 672 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
670 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 673 plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
671 plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
672 }
673 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
674 cabecera = $filter('rellenarDigitos')($scope.idLista, 4) +
675 ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim();
676 } else { //Cuando se ingresan los plazos manualmente
677 $scope.notaPedido.idPrecioCondicion = 0;
678 //-1, el modal productos busca todos los productos
679 $scope.idLista = -1;
680 $scope.notaPedido.notaPedidoPlazo = precioCondicion;
681 for (var j = 0; j < precioCondicion.length; j++) {
682 plazosConcat += precioCondicion[j].dias + ' ';
683 }
684 cabecera = 'Ingreso manual ' + plazosConcat.trim();
685 } 674 }
686 $scope.cabeceras.push({ 675 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
687 label: 'Precios y Condiciones:', 676 cabecera = $filter('rellenarDigitos')($scope.idLista, 4) +
688 valor: $scope.idLista + ' - ' + precioCondicion.listaPrecio.DES + ' ' + 677 ' - ' + precioCondicion.listaPrecio.DES +
689 notaPedidoBusinessService.plazoToString(precioCondicion.plazoPago) 678 ' ' + plazosConcat.trim();
690 }); 679 } else { //Cuando se ingresan los plazos manualmente
680 $scope.notaPedido.idPrecioCondicion = 0;
681 //-1, el modal productos busca todos los productos
682 $scope.idLista = -1;
683 $scope.notaPedido.notaPedidoPlazo = precioCondicion;
684 for (var j = 0; j < precioCondicion.length; j++) {
685 plazosConcat += precioCondicion[j].dias + ' ';
686 }
687 cabecera = 'Ingreso manual ' + plazosConcat.trim();
688 }
689 $scope.cabeceras.push({
690 label: 'Precios y Condiciones:',
691 valor: $scope.idLista + ' - ' + precioCondicion.listaPrecio.DES + ' ' +
692 notaPedidoBusinessService.plazoToString(precioCondicion.plazoPago)
693 });
691 694
692 $filter('filter')($scope.botonera, 695 $filter('filter')($scope.botonera,
693 { label: 'Precios y Condiciones' })[0].checked = true; 696 { label: 'Precios y Condiciones' })[0].checked = true;
694
695 addArrayCabecera($scope.cabeceras);
696 697
697 }) 698 addArrayCabecera($scope.cabeceras);
699
700 })
698 .catch(function (e) { 701 .catch(function (e) {
699 console.log(e); 702 console.log(e);
700 }) 703 });
701 704
702 } 705 }
703 }; 706 };
704 707
705 $scope.seleccionarMoneda = function () { 708 $scope.seleccionarMoneda = function () {
706 if (validarNotaRemitada()) { 709 if (validarNotaRemitada()) {
707 var parametrosModal = { 710 var parametrosModal = {
708 titulo: 'Búsqueda de monedas', 711 titulo: 'Búsqueda de monedas',
709 query: '/moneda', 712 query: '/moneda',
710 columnas: [ 713 columnas: [
711 { 714 {
712 propiedad: 'DETALLE', 715 propiedad: 'DETALLE',
713 nombre: 'Nombre' 716 nombre: 'Nombre'
714 }, 717 },
715 { 718 {
716 propiedad: 'SIMBOLO', 719 propiedad: 'SIMBOLO',
717 nombre: 'Símbolo' 720 nombre: 'Símbolo'
718 } 721 }
719 ], 722 ],
720 size: 'md' 723 size: 'md'
721 }; 724 };
722 focaModalService.modal(parametrosModal).then( 725 focaModalService.modal(parametrosModal).then(
723 function (moneda) { 726 function (moneda) {
724 727
725 if (moneda.ID !== 1) { 728 if (moneda.ID !== 1) {
726 $scope.abrirModalCotizacion(moneda); 729 $scope.abrirModalCotizacion(moneda);
727 return; 730 return;
728 } 731 }
729 732
730 crearNotaPedidoService.getCotizacionByIdMoneda(1) 733 crearNotaPedidoService.getCotizacionByIdMoneda(1)
731 .then(function (res) { 734 .then(function (res) {
732 735
733 cotizacionPArgentino = res.data[0].cotizaciones[0]; 736 cotizacionPArgentino = res.data[0].cotizaciones[0];
734 cotizacionPArgentino.moneda = moneda; 737 cotizacionPArgentino.moneda = moneda;
735 738
736 actualizarCabeceraMoneda(cotizacionPArgentino); 739 actualizarCabeceraMoneda(cotizacionPArgentino);
737 $scope.notaPedido.cotizacion = cotizacionPArgentino; 740 $scope.notaPedido.cotizacion = cotizacionPArgentino;
738 }); 741 });
739 } 742 }
740 ); 743 );
741 } 744 }
742 }; 745 };
743 746
744 $scope.seleccionarObservaciones = function () { 747 $scope.seleccionarObservaciones = function () {
745 var observacion = { 748 var observacion = {
746 titulo: 'Ingrese Observaciones', 749 titulo: 'Ingrese Observaciones',
747 value: $scope.notaPedido.observaciones, 750 value: $scope.notaPedido.observaciones,
748 maxlength: 155, 751 maxlength: 155,
749 textarea: true 752 textarea: true
750 }; 753 };
751 754
752 focaModalService 755 focaModalService
753 .prompt(observacion) 756 .prompt(observacion)
754 .then(function (observaciones) { 757 .then(function (observaciones) {
755 $scope.notaPedido.observaciones = observaciones; 758 $scope.notaPedido.observaciones = observaciones;
756 }); 759 });
757 }; 760 };
758 761
759 $scope.abrirModalCotizacion = function (moneda) { 762 $scope.abrirModalCotizacion = function (moneda) {
760 var modalInstance = $uibModal.open( 763 var modalInstance = $uibModal.open(
761 { 764 {
762 ariaLabelledBy: 'Busqueda de Cotización', 765 ariaLabelledBy: 'Busqueda de Cotización',
763 templateUrl: 'modal-cotizacion.html', 766 templateUrl: 'modal-cotizacion.html',
764 controller: 'focaModalCotizacionController', 767 controller: 'focaModalCotizacionController',
765 size: 'lg', 768 size: 'lg',
766 resolve: { 769 resolve: {
767 idMoneda: function () { 770 idMoneda: function () {
768 return moneda.ID; 771 return moneda.ID;
769 } 772 }
770 } 773 }
771 } 774 }
772 ); 775 );
773 modalInstance.result.then( 776 modalInstance.result.then(
774 function (cotizacion) { 777 function (cotizacion) {
775 778
776 cotizacion.moneda = moneda; 779 cotizacion.moneda = moneda;
777 actualizarCabeceraMoneda(cotizacion); 780 actualizarCabeceraMoneda(cotizacion);
778 781
779 $scope.notaPedido.cotizacion = cotizacion; 782 $scope.notaPedido.cotizacion = cotizacion;
780 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 783 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
781 }, function () { 784 }, function () {
782 785
783 } 786 }
784 ); 787 );
785 }; 788 };
786 789
787 function actualizarCabeceraMoneda(cotizacion) { 790 function actualizarCabeceraMoneda(cotizacion) {
788 791
789 $scope.notaPedido.articulosNotaPedido.forEach(function (art) { 792 $scope.notaPedido.articulosNotaPedido.forEach(function (art) {
790 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); 793 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4);
791 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); 794 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
792 }); 795 });
793 796
794 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 797 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
795 $scope.$broadcast('removeCabecera', 'Moneda:'); 798 $scope.$broadcast('removeCabecera', 'Moneda:');
796 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 799 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
797 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 800 $scope.$broadcast('removeCabecera', 'Cotizacion:');
798 } else { 801 } else {
799 $scope.$broadcast('addCabecera', { 802 $scope.$broadcast('addCabecera', {
800 label: 'Moneda:', 803 label: 'Moneda:',
801 valor: cotizacion.moneda.DETALLE 804 valor: cotizacion.moneda.DETALLE
802 }); 805 });
803 $scope.$broadcast('addCabecera', { 806 $scope.$broadcast('addCabecera', {
804 label: 'Fecha cotizacion:', 807 label: 'Fecha cotizacion:',
805 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 808 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
806 }); 809 });
807 $scope.$broadcast('addCabecera', { 810 $scope.$broadcast('addCabecera', {
808 label: 'Cotizacion:', 811 label: 'Cotizacion:',
809 valor: $filter('number')(cotizacion.VENDEDOR, '2') 812 valor: $filter('number')(cotizacion.VENDEDOR, '2')
810 }); 813 });
811 } 814 }
812 } 815 }
813 816
814 $scope.agregarATabla = function (key) { 817 $scope.agregarATabla = function (key) {
815 if (key === 13) { 818 if (key === 13) {
816 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { 819 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
817 focaModalService.alert('El valor debe ser al menos 1'); 820 focaModalService.alert('El valor debe ser al menos 1');
818 return; 821 return;
819 } 822 }
820 delete $scope.articuloACargar.sectorCodigo; 823 delete $scope.articuloACargar.sectorCodigo;
821 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); 824 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar);
822 $scope.cargando = true; 825 $scope.cargando = true;
823 } 826 }
824 }; 827 };
825 828
826 $scope.quitarArticulo = function (key) { 829 $scope.quitarArticulo = function (key) {
827 if (validarNotaRemitada()) { 830 if (validarNotaRemitada()) {
828 $scope.notaPedido.articulosNotaPedido.splice(key, 1); 831 $scope.notaPedido.articulosNotaPedido.splice(key, 1);
829 } 832 }
830 }; 833 };
831 834
832 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { 835 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
833 if (key === 13) { 836 if (key === 13) {
834 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { 837 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) {
835 focaModalService.alert('Los valores deben ser al menos 1'); 838 focaModalService.alert('Los valores deben ser al menos 1');
836 return; 839 return;
837 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 840 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
838 focaModalService.alert('Los valores no pueden ser negativos'); 841 focaModalService.alert('Los valores no pueden ser negativos');
839 return; 842 return;
840 } 843 }
841 articulo.cantidad = tmpCantidad; 844 articulo.cantidad = tmpCantidad;
842 articulo.precio = tmpPrecio; 845 articulo.precio = tmpPrecio;
843 $scope.getTotal(); 846 $scope.getTotal();
844 articulo.editCantidad = articulo.editPrecio = false; 847 articulo.editCantidad = articulo.editPrecio = false;
845 } 848 }
846 }; 849 };
847 850
848 $scope.cancelarEditar = function (articulo) { 851 $scope.cancelarEditar = function (articulo) {
849 $scope.tmpCantidad = articulo.cantidad; 852 $scope.tmpCantidad = articulo.cantidad;
850 $scope.tmpPrecio = articulo.precio; 853 $scope.tmpPrecio = articulo.precio;
851 articulo.editCantidad = articulo.editPrecio = false; 854 articulo.editCantidad = articulo.editPrecio = false;
852 }; 855 };
853 856
854 $scope.cambioEdit = function (articulo, propiedad) { 857 $scope.cambioEdit = function (articulo, propiedad) {
855 if (propiedad === 'cantidad') { 858 if (propiedad === 'cantidad') {
856 articulo.editCantidad = true; 859 articulo.editCantidad = true;
857 } else if (propiedad === 'precio') { 860 } else if (propiedad === 'precio') {
858 articulo.editPrecio = true; 861 articulo.editPrecio = true;
859 } 862 }
860 }; 863 };
861 864
862 $scope.resetFilter = function () { 865 $scope.resetFilter = function () {
863 $scope.articuloACargar = {}; 866 $scope.articuloACargar = {};
864 $scope.cargando = true; 867 $scope.cargando = true;
865 }; 868 };
866 //Recibe aviso si el teclado está en uso 869 //Recibe aviso si el teclado está en uso
867 $rootScope.$on('usarTeclado', function (event, data) { 870 $rootScope.$on('usarTeclado', function (event, data) {
868 if (data) { 871 if (data) {
869 $scope.mostrarTeclado = true; 872 $scope.mostrarTeclado = true;
870 return; 873 return;
871 } 874 }
872 $scope.mostrarTeclado = false; 875 $scope.mostrarTeclado = false;
873 }); 876 });
874 877
875 $scope.selectFocus = function ($event) { 878 $scope.selectFocus = function ($event) {
876 // Si el teclado esta en uso no selecciona el valor 879 // Si el teclado esta en uso no selecciona el valor
877 if ($scope.mostrarTeclado) { 880 if ($scope.mostrarTeclado) {
878 return; 881 return;
879 } 882 }
880 $event.target.select(); 883 $event.target.select();
881 }; 884 };
882 885
883 $scope.salir = function () { 886 $scope.salir = function () {
884 $location.path('/'); 887 $location.path('/');
885 }; 888 };
886 889
887 $scope.parsearATexto = function (articulo) { 890 $scope.parsearATexto = function (articulo) {
888 articulo.cantidad = parseFloat(articulo.cantidad); 891 articulo.cantidad = parseFloat(articulo.cantidad);
889 articulo.precio = parseFloat(articulo.precio); 892 articulo.precio = parseFloat(articulo.precio);
890 }; 893 };
891 894
892 // TODO: quitar watch usar función de articulos pedido cuando se haga 895 // TODO: quitar watch usar función de articulos pedido cuando se haga
893 $scope.$watch('notaPedido.articulosNotaPedido', function () { 896 $scope.$watch('notaPedido.articulosNotaPedido', function () {
894 if ($scope.notaPedido.articulosNotaPedido.length) { 897 if ($scope.notaPedido.articulosNotaPedido.length) {
895 $filter('filter')($scope.botonera, 898 $filter('filter')($scope.botonera,
896 { label: 'Productos' })[0].checked = true; 899 { label: 'Productos' })[0].checked = true;
897 } else { 900 } else {
898 $filter('filter')($scope.botonera, 901 $filter('filter')($scope.botonera,
899 { label: 'Productos' })[0].checked = false; 902 { label: 'Productos' })[0].checked = false;
900 } 903 }
901 }, true); 904 }, true);
902 905
903 function setearNotaPedido(notaPedido) { 906 function setearNotaPedido(notaPedido) {
904 //añado cabeceras 907 //añado cabeceras
905 $scope.notaPedido = notaPedido; 908 $scope.notaPedido = notaPedido;
906 if (!$scope.notaPedido.domicilio) { 909 if (!$scope.notaPedido.domicilio) {
907 $scope.notaPedido.domicilio = { 910 $scope.notaPedido.domicilio = {
908 id: $scope.notaPedido.idDomicilio 911 id: $scope.notaPedido.idDomicilio
909 }; 912 };
910 } 913 }
911 $scope.$broadcast('removeCabecera', 'Bomba:'); 914 $scope.$broadcast('removeCabecera', 'Bomba:');
912 $scope.$broadcast('removeCabecera', 'Kilometros:'); 915 $scope.$broadcast('removeCabecera', 'Kilometros:');
913 $scope.$broadcast('cleanCabecera'); 916 $scope.$broadcast('cleanCabecera');
914 917
915 $scope.cabeceras = []; 918 $scope.cabeceras = [];
916 919
917 if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 920 if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
918 $scope.cabeceras.push({ 921 $scope.cabeceras.push({
919 label: 'Moneda:', 922 label: 'Moneda:',
920 valor: notaPedido.cotizacion.moneda.DETALLE 923 valor: notaPedido.cotizacion.moneda.DETALLE
921 }); 924 });
922 $scope.cabeceras.push({ 925 $scope.cabeceras.push({
923 label: 'Fecha cotizacion:', 926 label: 'Fecha cotizacion:',
924 valor: $filter('date')(notaPedido.cotizacion.FECHA, 927 valor: $filter('date')(notaPedido.cotizacion.FECHA,
925 'dd/MM/yyyy') 928 'dd/MM/yyyy')
926 }); 929 });
927 $scope.cabeceras.push({ 930 $scope.cabeceras.push({
928 label: 'Cotizacion:', 931 label: 'Cotizacion:',
929 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 932 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
930 '2') 933 '2')
931 }); 934 });
932 } 935 }
933 936
934 if (notaPedido.cotizacion.moneda) { 937 if (notaPedido.cotizacion.moneda) {
935 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 938 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
936 } 939 }
937 940
938 if (notaPedido.vendedor.NUM) { 941 if (notaPedido.vendedor.NUM) {
939 $scope.cabeceras.push({ 942 $scope.cabeceras.push({
940 label: 'Vendedor:', 943 label: 'Vendedor:',
941 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + 944 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) +
942 ' - ' + notaPedido.vendedor.NOM 945 ' - ' + notaPedido.vendedor.NOM
943 }); 946 });
944 } 947 }
945 948
946 if (notaPedido.cliente.COD) { 949 if (notaPedido.cliente.COD) {
947 $scope.cabeceras.push({ 950 $scope.cabeceras.push({
948 label: 'Cliente:', 951 label: 'Cliente:',
949 valor: notaPedido.cliente.NOM 952 valor: notaPedido.cliente.NOM
950 }); 953 });
951 $scope.cabeceras.push({ 954 $scope.cabeceras.push({
952 label: 'Domicilio:', 955 label: 'Domicilio:',
953 valor: notaPedido.domicilioStamp 956 valor: notaPedido.domicilioStamp
954 }); 957 });
955 958
956 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 959 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
957 } 960 }
958 961
959 if (notaPedido.proveedor.COD) { 962 if (notaPedido.proveedor.COD) {
960 $scope.cabeceras.push({ 963 $scope.cabeceras.push({
961 label: 'Proveedor:', 964 label: 'Proveedor:',
962 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + 965 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) +
963 ' - ' + notaPedido.proveedor.NOM 966 ' - ' + notaPedido.proveedor.NOM
964 }); 967 });
965 968
966 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; 969 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
967 } 970 }
968 971
969 if (notaPedido.notaPedidoPlazo.length) { 972 if (notaPedido.notaPedidoPlazo.length) {
970 valorPrecioCondicion(); 973 valorPrecioCondicion();
971 $filter('filter')($scope.botonera, 974 $filter('filter')($scope.botonera,
972 { label: 'Precios y condiciones' })[0].checked = true; 975 { label: 'Precios y condiciones' })[0].checked = true;
973 } 976 }
974 977
975 if (notaPedido.flete !== undefined) { 978 if (notaPedido.flete !== undefined) {
976 $scope.cabeceras.push({ 979 $scope.cabeceras.push({
977 label: 'Flete:', 980 label: 'Flete:',
978 valor: notaPedido.fob === 1 ? 'FOB' : ( 981 valor: notaPedido.fob === 1 ? 'FOB' : (
979 notaPedido.flete === 1 ? 'Si' : 'No') 982 notaPedido.flete === 1 ? 'Si' : 'No')
980 }); 983 });
981 } 984 }
982 985
983 function valorPrecioCondicion() { 986 function valorPrecioCondicion() {
984 if (notaPedido.idListaPrecio > 0) { 987 if (notaPedido.idListaPrecio > 0) {
985 crearNotaPedidoService.getPrecioCondicionById(parseInt(notaPedido.idListaPrecio)) 988 crearNotaPedidoService
989 .getPrecioCondicionById(parseInt(notaPedido.idListaPrecio))
986 .then(function (res) { 990 .then(function (res) {
987 $scope.cabeceras.push({ 991 $scope.cabeceras.push({
988 label: 'Precios y Condiciones:', 992 label: 'Precios y Condiciones:',
989 valor: parseInt(res.data[0].ID) + ' - ' + res.data[0].DES + ' ' + 993 valor: parseInt(res.data[0].ID) + ' - ' +
990 notaPedidoBusinessService 994 res.data[0].DES + ' ' +
995 notaPedidoBusinessService
991 .plazoToString(notaPedido.notaPedidoPlazo) 996 .plazoToString(notaPedido.notaPedidoPlazo)
992 }); 997 });
993 addArrayCabecera($scope.cabeceras); 998 addArrayCabecera($scope.cabeceras);
994 }); 999 });
995 } 1000 }
996 $scope.idLista = parseInt(notaPedido.idListaPrecio); 1001 $scope.idLista = parseInt(notaPedido.idListaPrecio);
997 } 1002 }
998 1003
999 if (notaPedido.flete === 1) { 1004 if (notaPedido.flete === 1) {
1000 var cabeceraBomba = { 1005 var cabeceraBomba = {
1001 label: 'Bomba:', 1006 label: 'Bomba:',
1002 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 1007 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
1003 }; 1008 };
1004 if (notaPedido.kilometros) { 1009 if (notaPedido.kilometros) {
1005 var cabeceraKilometros = { 1010 var cabeceraKilometros = {
1006 label: 'Kilometros:', 1011 label: 'Kilometros:',
1007 valor: notaPedido.kilometros 1012 valor: notaPedido.kilometros
1008 }; 1013 };
1009 $scope.cabeceras.push(cabeceraKilometros); 1014 $scope.cabeceras.push(cabeceraKilometros);
1010 } 1015 }
1011 $scope.cabeceras.push(cabeceraBomba); 1016 $scope.cabeceras.push(cabeceraBomba);
1012 } 1017 }
1013 1018
1014 if (notaPedido.idPrecioCondicion > 0) { 1019 if (notaPedido.idPrecioCondicion > 0) {
1015 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 1020 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
1016 } else if (notaPedido.idPrecioCondicion) { 1021 } else if (notaPedido.idPrecioCondicion) {
1017 $scope.idLista = -1; 1022 $scope.idLista = -1;
1018 } 1023 }
1019 1024
1020 $scope.puntoVenta = $filter('rellenarDigitos')( 1025 $scope.puntoVenta = $filter('rellenarDigitos')(
1021 notaPedido.sucursal, 4 1026 notaPedido.sucursal, 4
1022 ); 1027 );
1023 1028
1024 $scope.comprobante = $filter('rellenarDigitos')( 1029 $scope.comprobante = $filter('rellenarDigitos')(
1025 notaPedido.numeroNotaPedido, 8 1030 notaPedido.numeroNotaPedido, 8
1026 ); 1031 );
1027 1032
1028 if (notaPedido.notaPedidoPuntoDescarga.length) { 1033 if (notaPedido.notaPedidoPuntoDescarga.length) {
1029 var puntos = []; 1034 var puntos = [];
1030 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) { 1035 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) {
1031 puntos.push(notaPedidoPuntoDescarga.puntoDescarga); 1036 puntos.push(notaPedidoPuntoDescarga.puntoDescarga);
1032 }); 1037 });
1033 $scope.cabeceras.push({ 1038 $scope.cabeceras.push({
1034 label: 'Puntos de descarga: ', 1039 label: 'Puntos de descarga: ',
1035 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) 1040 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos))
1036 }); 1041 });
1037 } 1042 }
1038 1043
1039 addArrayCabecera($scope.cabeceras); 1044 addArrayCabecera($scope.cabeceras);
1040 } 1045 }
1041 1046
1042 function getCabeceraPuntoDescarga(puntoDescarga) { 1047 function getCabeceraPuntoDescarga(puntoDescarga) {
1043 var puntosStamp = ''; 1048 var puntosStamp = '';
1044 puntoDescarga.forEach(function (punto, idx, arr) { 1049 puntoDescarga.forEach(function (punto, idx, arr) {
1045 puntosStamp += punto.descripcion; 1050 puntosStamp += punto.descripcion;
1046 if ((idx + 1) !== arr.length) puntosStamp += ', '; 1051 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1047 }); 1052 });
1048 return puntosStamp; 1053 return puntosStamp;
1049 } 1054 }
1050 1055
1051 function addArrayCabecera(array) { 1056 function addArrayCabecera(array) {
1052 for (var i = 0; i < array.length; i++) { 1057 for (var i = 0; i < array.length; i++) {
1053 $scope.$broadcast('addCabecera', { 1058 $scope.$broadcast('addCabecera', {
1054 label: array[i].label, 1059 label: array[i].label,
1055 valor: array[i].valor 1060 valor: array[i].valor
1056 }); 1061 });
1057 } 1062 }
1058 } 1063 }
1059 1064
1060 function validarNotaRemitada() { 1065 function validarNotaRemitada() {
1061 if (!$scope.notaPedido.idRemito) { 1066 if (!$scope.notaPedido.idRemito) {
1062 return true; 1067 return true;
1063 } else { 1068 } else {
1064 focaModalService.alert('No se puede editar una nota de pedido remitada'); 1069 focaModalService.alert('No se puede editar una nota de pedido remitada');
1065 return false; 1070 return false;
1066 } 1071 }
1067 } 1072 }
1068 1073
1069 function salir() { 1074 function salir() {
1070 var confirmacion = false; 1075 var confirmacion = false;
1071 1076
1072 if (!angular.equals($scope.notaPedido, $scope.inicial)) { 1077 if (!angular.equals($scope.notaPedido, $scope.inicial)) {
1073 confirmacion = true; 1078 confirmacion = true;
1074 } 1079 }
1075 1080
1076 if (confirmacion) { 1081 if (confirmacion) {
1077 focaModalService.confirm( 1082 focaModalService.confirm(
1078 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1083 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1079 ).then(function (data) { 1084 ).then(function (data) {
1080 if (data) { 1085 if (data) {
1081 $location.path('/'); 1086 $location.path('/');
1082 } 1087 }
1083 }); 1088 });
1084 } else { 1089 } else {
1085 $location.path('/'); 1090 $location.path('/');
1086 } 1091 }
1087 } 1092 }
1088 1093
1089 function getLSNotaPedido() { 1094 function getLSNotaPedido() {
1090 var notaPedido = JSON.parse($localStorage.notaPedido || null); 1095 var notaPedido = JSON.parse($localStorage.notaPedido || null);
1091 if (notaPedido) { 1096 if (notaPedido) {
1092 delete $localStorage.notaPedido; 1097 delete $localStorage.notaPedido;
1093 setearNotaPedido(notaPedido); 1098 setearNotaPedido(notaPedido);