Commit 38e36a34011c828b816cff059d712af50b3863f2

Authored by Luigi
1 parent d73a6e985a
Exists in master and in 1 other branch develop

Cambio en el campo MOD del modal de lista precio

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