Commit 3b8c4a9e696e46676f3ab1a94d7e0d6cc720fcb7

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

Revert "Cambio en el campo MOD del modal de lista precio"

This reverts commit 38e36a34011c828b816cff059d712af50b3863f2.
Showing 1 changed file with 0 additions and 1 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;
686 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? 685 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ?
687 parseInt(precioCondicion.listaPrecio.ID) : -1; 686 parseInt(precioCondicion.listaPrecio.ID) : -1;
688 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 687 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
689 plazosConcat += precioCondicion.plazoPago[i].dias + ', '; 688 plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
690 } 689 }
691 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); 690 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
692 cabecera = $filter('rellenarDigitos')($scope.idLista, 4) + 691 cabecera = $filter('rellenarDigitos')($scope.idLista, 4) +
693 ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim(); 692 ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim();
694 } else { //Cuando se ingresan los plazos manualmente 693 } else { //Cuando se ingresan los plazos manualmente
695 $scope.notaPedido.idPrecioCondicion = 0; 694 $scope.notaPedido.idPrecioCondicion = 0;
696 //-1, el modal productos busca todos los productos 695 //-1, el modal productos busca todos los productos
697 $scope.idLista = -1; 696 $scope.idLista = -1;
698 $scope.notaPedido.notaPedidoPlazo = precioCondicion; 697 $scope.notaPedido.notaPedidoPlazo = precioCondicion;
699 for (var j = 0; j < precioCondicion.length; j++) { 698 for (var j = 0; j < precioCondicion.length; j++) {
700 plazosConcat += precioCondicion[j].dias + ' '; 699 plazosConcat += precioCondicion[j].dias + ' ';
701 } 700 }
702 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 701 cabecera = 'Ingreso manual ' + plazosConcat.trim();
703 } 702 }
704 $scope.notaPedido.articulosNotaPedido = []; 703 $scope.notaPedido.articulosNotaPedido = [];
705 $scope.$broadcast('addCabecera', { 704 $scope.$broadcast('addCabecera', {
706 label: 'Precios y condiciones:', 705 label: 'Precios y condiciones:',
707 valor: cabecera 706 valor: cabecera
708 }); 707 });
709 708
710 $filter('filter')($scope.botonera, 709 $filter('filter')($scope.botonera,
711 { label: 'Precios y Condiciones' })[0].checked = true; 710 { label: 'Precios y Condiciones' })[0].checked = true;
712 }) 711 })
713 .catch(function (e) { 712 .catch(function (e) {
714 console.log(e); 713 console.log(e);
715 }) 714 })
716 715
717 } 716 }
718 }; 717 };
719 718
720 $scope.seleccionarMoneda = function () { 719 $scope.seleccionarMoneda = function () {
721 if (validarNotaRemitada()) { 720 if (validarNotaRemitada()) {
722 var parametrosModal = { 721 var parametrosModal = {
723 titulo: 'Búsqueda de monedas', 722 titulo: 'Búsqueda de monedas',
724 query: '/moneda', 723 query: '/moneda',
725 columnas: [ 724 columnas: [
726 { 725 {
727 propiedad: 'DETALLE', 726 propiedad: 'DETALLE',
728 nombre: 'Nombre' 727 nombre: 'Nombre'
729 }, 728 },
730 { 729 {
731 propiedad: 'SIMBOLO', 730 propiedad: 'SIMBOLO',
732 nombre: 'Símbolo' 731 nombre: 'Símbolo'
733 } 732 }
734 ], 733 ],
735 size: 'md' 734 size: 'md'
736 }; 735 };
737 focaModalService.modal(parametrosModal).then( 736 focaModalService.modal(parametrosModal).then(
738 function (moneda) { 737 function (moneda) {
739 738
740 if (moneda.ID !== 1) { 739 if (moneda.ID !== 1) {
741 $scope.abrirModalCotizacion(moneda); 740 $scope.abrirModalCotizacion(moneda);
742 return; 741 return;
743 } 742 }
744 743
745 crearNotaPedidoService.getCotizacionByIdMoneda(1) 744 crearNotaPedidoService.getCotizacionByIdMoneda(1)
746 .then(function (res) { 745 .then(function (res) {
747 746
748 cotizacionPArgentino = res.data[0].cotizaciones[0]; 747 cotizacionPArgentino = res.data[0].cotizaciones[0];
749 cotizacionPArgentino.moneda = moneda; 748 cotizacionPArgentino.moneda = moneda;
750 749
751 actualizarCabeceraMoneda(cotizacionPArgentino); 750 actualizarCabeceraMoneda(cotizacionPArgentino);
752 $scope.notaPedido.cotizacion = cotizacionPArgentino; 751 $scope.notaPedido.cotizacion = cotizacionPArgentino;
753 }); 752 });
754 } 753 }
755 ); 754 );
756 } 755 }
757 }; 756 };
758 757
759 $scope.seleccionarObservaciones = function () { 758 $scope.seleccionarObservaciones = function () {
760 var observacion = { 759 var observacion = {
761 titulo: 'Ingrese Observaciones', 760 titulo: 'Ingrese Observaciones',
762 value: $scope.notaPedido.observaciones, 761 value: $scope.notaPedido.observaciones,
763 maxlength: 155, 762 maxlength: 155,
764 textarea: true 763 textarea: true
765 }; 764 };
766 765
767 focaModalService 766 focaModalService
768 .prompt(observacion) 767 .prompt(observacion)
769 .then(function (observaciones) { 768 .then(function (observaciones) {
770 $scope.notaPedido.observaciones = observaciones; 769 $scope.notaPedido.observaciones = observaciones;
771 }); 770 });
772 }; 771 };
773 772
774 $scope.abrirModalCotizacion = function (moneda) { 773 $scope.abrirModalCotizacion = function (moneda) {
775 var modalInstance = $uibModal.open( 774 var modalInstance = $uibModal.open(
776 { 775 {
777 ariaLabelledBy: 'Busqueda de Cotización', 776 ariaLabelledBy: 'Busqueda de Cotización',
778 templateUrl: 'modal-cotizacion.html', 777 templateUrl: 'modal-cotizacion.html',
779 controller: 'focaModalCotizacionController', 778 controller: 'focaModalCotizacionController',
780 size: 'lg', 779 size: 'lg',
781 resolve: { 780 resolve: {
782 idMoneda: function () { 781 idMoneda: function () {
783 return moneda.ID; 782 return moneda.ID;
784 } 783 }
785 } 784 }
786 } 785 }
787 ); 786 );
788 modalInstance.result.then( 787 modalInstance.result.then(
789 function (cotizacion) { 788 function (cotizacion) {
790 789
791 cotizacion.moneda = moneda; 790 cotizacion.moneda = moneda;
792 actualizarCabeceraMoneda(cotizacion); 791 actualizarCabeceraMoneda(cotizacion);
793 792
794 $scope.notaPedido.cotizacion = cotizacion; 793 $scope.notaPedido.cotizacion = cotizacion;
795 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 794 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
796 }, function () { 795 }, function () {
797 796
798 } 797 }
799 ); 798 );
800 }; 799 };
801 800
802 function actualizarCabeceraMoneda(cotizacion) { 801 function actualizarCabeceraMoneda(cotizacion) {
803 802
804 $scope.notaPedido.articulosNotaPedido.forEach(function (art) { 803 $scope.notaPedido.articulosNotaPedido.forEach(function (art) {
805 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); 804 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4);
806 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); 805 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
807 }); 806 });
808 807
809 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 808 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
810 $scope.$broadcast('removeCabecera', 'Moneda:'); 809 $scope.$broadcast('removeCabecera', 'Moneda:');
811 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 810 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
812 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 811 $scope.$broadcast('removeCabecera', 'Cotizacion:');
813 } else { 812 } else {
814 $scope.$broadcast('addCabecera', { 813 $scope.$broadcast('addCabecera', {
815 label: 'Moneda:', 814 label: 'Moneda:',
816 valor: cotizacion.moneda.DETALLE 815 valor: cotizacion.moneda.DETALLE
817 }); 816 });
818 $scope.$broadcast('addCabecera', { 817 $scope.$broadcast('addCabecera', {
819 label: 'Fecha cotizacion:', 818 label: 'Fecha cotizacion:',
820 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 819 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
821 }); 820 });
822 $scope.$broadcast('addCabecera', { 821 $scope.$broadcast('addCabecera', {
823 label: 'Cotizacion:', 822 label: 'Cotizacion:',
824 valor: $filter('number')(cotizacion.VENDEDOR, '2') 823 valor: $filter('number')(cotizacion.VENDEDOR, '2')
825 }); 824 });
826 } 825 }
827 } 826 }
828 827
829 $scope.agregarATabla = function (key) { 828 $scope.agregarATabla = function (key) {
830 if (key === 13) { 829 if (key === 13) {
831 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { 830 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
832 focaModalService.alert('El valor debe ser al menos 1'); 831 focaModalService.alert('El valor debe ser al menos 1');
833 return; 832 return;
834 } 833 }
835 delete $scope.articuloACargar.sectorCodigo; 834 delete $scope.articuloACargar.sectorCodigo;
836 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); 835 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar);
837 $scope.cargando = true; 836 $scope.cargando = true;
838 } 837 }
839 }; 838 };
840 839
841 $scope.quitarArticulo = function (key) { 840 $scope.quitarArticulo = function (key) {
842 if (validarNotaRemitada()) { 841 if (validarNotaRemitada()) {
843 $scope.notaPedido.articulosNotaPedido.splice(key, 1); 842 $scope.notaPedido.articulosNotaPedido.splice(key, 1);
844 } 843 }
845 }; 844 };
846 845
847 $scope.editarArticulo = function (key, articulo, bandera) { 846 $scope.editarArticulo = function (key, articulo, bandera) {
848 if (key === 13) { 847 if (key === 13) {
849 var valorAEditar = bandera === 'precio' ? articulo.precio : articulo.cantidad; 848 var valorAEditar = bandera === 'precio' ? articulo.precio : articulo.cantidad;
850 var tempValor = bandera === 'precio' ? articulo.tmpPrecio 849 var tempValor = bandera === 'precio' ? articulo.tmpPrecio
851 : articulo.tmpCantidad; 850 : articulo.tmpCantidad;
852 if (tempValor === '') { 851 if (tempValor === '') {
853 focaModalService.alert('Los valores deben ser al menos 1'); 852 focaModalService.alert('Los valores deben ser al menos 1');
854 return; 853 return;
855 } else if (tempValor === '0') { 854 } else if (tempValor === '0') {
856 focaModalService.alert('Esta ingresando un producto con valor 0'); 855 focaModalService.alert('Esta ingresando un producto con valor 0');
857 } else if (valorAEditar < 0) { 856 } else if (valorAEditar < 0) {
858 focaModalService.alert('Los valores no pueden ser negativos'); 857 focaModalService.alert('Los valores no pueden ser negativos');
859 return; 858 return;
860 } 859 }
861 articulo[bandera] = parseFloat(tempValor); 860 articulo[bandera] = parseFloat(tempValor);
862 $scope.getTotal(); 861 $scope.getTotal();
863 var propiedad = 'edit' + bandera.charAt(0).toUpperCase() + bandera.slice(1); 862 var propiedad = 'edit' + bandera.charAt(0).toUpperCase() + bandera.slice(1);
864 articulo[propiedad] = false; 863 articulo[propiedad] = false;
865 } 864 }
866 }; 865 };
867 866
868 $scope.cancelarEditar = function (articulo) { 867 $scope.cancelarEditar = function (articulo) {
869 $scope.tmpCantidad = articulo.cantidad; 868 $scope.tmpCantidad = articulo.cantidad;
870 $scope.tmpPrecio = articulo.precio; 869 $scope.tmpPrecio = articulo.precio;
871 articulo.editCantidad = articulo.editPrecio = false; 870 articulo.editCantidad = articulo.editPrecio = false;
872 }; 871 };
873 872
874 $scope.cambioEdit = function (articulo, propiedad) { 873 $scope.cambioEdit = function (articulo, propiedad) {
875 if (propiedad === 'cantidad') { 874 if (propiedad === 'cantidad') {
876 articulo.editCantidad = true; 875 articulo.editCantidad = true;
877 } else if (propiedad === 'precio') { 876 } else if (propiedad === 'precio') {
878 articulo.editPrecio = true; 877 articulo.editPrecio = true;
879 } 878 }
880 }; 879 };
881 880
882 $scope.resetFilter = function () { 881 $scope.resetFilter = function () {
883 $scope.articuloACargar = {}; 882 $scope.articuloACargar = {};
884 $scope.cargando = true; 883 $scope.cargando = true;
885 }; 884 };
886 //Recibe aviso si el teclado está en uso 885 //Recibe aviso si el teclado está en uso
887 $rootScope.$on('usarTeclado', function (event, data) { 886 $rootScope.$on('usarTeclado', function (event, data) {
888 if (data) { 887 if (data) {
889 $scope.mostrarTeclado = true; 888 $scope.mostrarTeclado = true;
890 return; 889 return;
891 } 890 }
892 $scope.mostrarTeclado = false; 891 $scope.mostrarTeclado = false;
893 }); 892 });
894 893
895 $scope.selectFocus = function ($event) { 894 $scope.selectFocus = function ($event) {
896 // Si el teclado esta en uso no selecciona el valor 895 // Si el teclado esta en uso no selecciona el valor
897 if ($scope.mostrarTeclado) { 896 if ($scope.mostrarTeclado) {
898 return; 897 return;
899 } 898 }
900 $event.target.select(); 899 $event.target.select();
901 }; 900 };
902 901
903 $scope.salir = function () { 902 $scope.salir = function () {
904 $location.path('/'); 903 $location.path('/');
905 }; 904 };
906 905
907 $scope.parsearATexto = function (articulo) { 906 $scope.parsearATexto = function (articulo) {
908 articulo.cantidad = parseFloat(articulo.cantidad); 907 articulo.cantidad = parseFloat(articulo.cantidad);
909 articulo.precio = parseFloat(articulo.precio); 908 articulo.precio = parseFloat(articulo.precio);
910 }; 909 };
911 910
912 // TODO: quitar watch usar función de articulos pedido cuando se haga 911 // TODO: quitar watch usar función de articulos pedido cuando se haga
913 $scope.$watch('notaPedido.articulosNotaPedido', function () { 912 $scope.$watch('notaPedido.articulosNotaPedido', function () {
914 if ($scope.notaPedido.articulosNotaPedido.length) { 913 if ($scope.notaPedido.articulosNotaPedido.length) {
915 $filter('filter')($scope.botonera, 914 $filter('filter')($scope.botonera,
916 { label: 'Productos' })[0].checked = true; 915 { label: 'Productos' })[0].checked = true;
917 } else { 916 } else {
918 $filter('filter')($scope.botonera, 917 $filter('filter')($scope.botonera,
919 { label: 'Productos' })[0].checked = false; 918 { label: 'Productos' })[0].checked = false;
920 } 919 }
921 }, true); 920 }, true);
922 921
923 function setearNotaPedido(notaPedido) { 922 function setearNotaPedido(notaPedido) {
924 //añado cabeceras 923 //añado cabeceras
925 $scope.notaPedido = notaPedido; 924 $scope.notaPedido = notaPedido;
926 if (!$scope.notaPedido.domicilio) { 925 if (!$scope.notaPedido.domicilio) {
927 $scope.notaPedido.domicilio = { 926 $scope.notaPedido.domicilio = {
928 id: $scope.notaPedido.idDomicilio 927 id: $scope.notaPedido.idDomicilio
929 }; 928 };
930 } 929 }
931 $scope.$broadcast('removeCabecera', 'Bomba:'); 930 $scope.$broadcast('removeCabecera', 'Bomba:');
932 $scope.$broadcast('removeCabecera', 'Kilometros:'); 931 $scope.$broadcast('removeCabecera', 'Kilometros:');
933 $scope.$broadcast('cleanCabecera'); 932 $scope.$broadcast('cleanCabecera');
934 933
935 var cabeceras = []; 934 var cabeceras = [];
936 935
937 if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 936 if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
938 cabeceras.push({ 937 cabeceras.push({
939 label: 'Moneda:', 938 label: 'Moneda:',
940 valor: notaPedido.cotizacion.moneda.DETALLE 939 valor: notaPedido.cotizacion.moneda.DETALLE
941 }); 940 });
942 cabeceras.push({ 941 cabeceras.push({
943 label: 'Fecha cotizacion:', 942 label: 'Fecha cotizacion:',
944 valor: $filter('date')(notaPedido.cotizacion.FECHA, 943 valor: $filter('date')(notaPedido.cotizacion.FECHA,
945 'dd/MM/yyyy') 944 'dd/MM/yyyy')
946 }); 945 });
947 cabeceras.push({ 946 cabeceras.push({
948 label: 'Cotizacion:', 947 label: 'Cotizacion:',
949 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 948 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
950 '2') 949 '2')
951 }); 950 });
952 } 951 }
953 952
954 if (notaPedido.cotizacion.moneda) { 953 if (notaPedido.cotizacion.moneda) {
955 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 954 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
956 } 955 }
957 956
958 if (notaPedido.vendedor.NUM) { 957 if (notaPedido.vendedor.NUM) {
959 cabeceras.push({ 958 cabeceras.push({
960 label: 'Vendedor:', 959 label: 'Vendedor:',
961 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + 960 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) +
962 ' - ' + notaPedido.vendedor.NOM 961 ' - ' + notaPedido.vendedor.NOM
963 }); 962 });
964 } 963 }
965 964
966 if (notaPedido.cliente.COD) { 965 if (notaPedido.cliente.COD) {
967 cabeceras.push({ 966 cabeceras.push({
968 label: 'Cliente:', 967 label: 'Cliente:',
969 valor: notaPedido.cliente.NOM 968 valor: notaPedido.cliente.NOM
970 }); 969 });
971 cabeceras.push({ 970 cabeceras.push({
972 label: 'Domicilio:', 971 label: 'Domicilio:',
973 valor: notaPedido.domicilioStamp 972 valor: notaPedido.domicilioStamp
974 }); 973 });
975 974
976 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 975 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
977 } 976 }
978 977
979 if (notaPedido.proveedor.COD) { 978 if (notaPedido.proveedor.COD) {
980 cabeceras.push({ 979 cabeceras.push({
981 label: 'Proveedor:', 980 label: 'Proveedor:',
982 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + 981 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) +
983 ' - ' + notaPedido.proveedor.NOM 982 ' - ' + notaPedido.proveedor.NOM
984 }); 983 });
985 984
986 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; 985 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
987 } 986 }
988 987
989 if (notaPedido.notaPedidoPlazo.length) { 988 if (notaPedido.notaPedidoPlazo.length) {
990 cabeceras.push({ 989 cabeceras.push({
991 label: 'Precios y condiciones:', 990 label: 'Precios y condiciones:',
992 valor: valorPrecioCondicion() + ' ' + 991 valor: valorPrecioCondicion() + ' ' +
993 notaPedidoBusinessService 992 notaPedidoBusinessService
994 .plazoToString(notaPedido.notaPedidoPlazo) 993 .plazoToString(notaPedido.notaPedidoPlazo)
995 }); 994 });
996 995
997 $filter('filter')($scope.botonera, 996 $filter('filter')($scope.botonera,
998 { label: 'Precios y condiciones' })[0].checked = true; 997 { label: 'Precios y condiciones' })[0].checked = true;
999 } 998 }
1000 999
1001 if (notaPedido.flete !== undefined) { 1000 if (notaPedido.flete !== undefined) {
1002 cabeceras.push({ 1001 cabeceras.push({
1003 label: 'Flete:', 1002 label: 'Flete:',
1004 valor: notaPedido.fob === 1 ? 'FOB' : ( 1003 valor: notaPedido.fob === 1 ? 'FOB' : (
1005 notaPedido.flete === 1 ? 'Si' : 'No') 1004 notaPedido.flete === 1 ? 'Si' : 'No')
1006 }); 1005 });
1007 } 1006 }
1008 1007
1009 function valorPrecioCondicion() { 1008 function valorPrecioCondicion() {
1010 if (notaPedido.idPrecioCondicion > 0) { 1009 if (notaPedido.idPrecioCondicion > 0) {
1011 return notaPedido.precioCondicion.nombre; 1010 return notaPedido.precioCondicion.nombre;
1012 } else { 1011 } else {
1013 return 'Ingreso Manual'; 1012 return 'Ingreso Manual';
1014 } 1013 }
1015 } 1014 }
1016 1015
1017 if (notaPedido.flete === 1) { 1016 if (notaPedido.flete === 1) {
1018 var cabeceraBomba = { 1017 var cabeceraBomba = {
1019 label: 'Bomba:', 1018 label: 'Bomba:',
1020 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 1019 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
1021 }; 1020 };
1022 if (notaPedido.kilometros) { 1021 if (notaPedido.kilometros) {
1023 var cabeceraKilometros = { 1022 var cabeceraKilometros = {
1024 label: 'Kilometros:', 1023 label: 'Kilometros:',
1025 valor: notaPedido.kilometros 1024 valor: notaPedido.kilometros
1026 }; 1025 };
1027 cabeceras.push(cabeceraKilometros); 1026 cabeceras.push(cabeceraKilometros);
1028 } 1027 }
1029 cabeceras.push(cabeceraBomba); 1028 cabeceras.push(cabeceraBomba);
1030 } 1029 }
1031 1030
1032 if (notaPedido.idPrecioCondicion > 0) { 1031 if (notaPedido.idPrecioCondicion > 0) {
1033 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 1032 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
1034 } else if (notaPedido.idPrecioCondicion) { 1033 } else if (notaPedido.idPrecioCondicion) {
1035 $scope.idLista = -1; 1034 $scope.idLista = -1;
1036 } 1035 }
1037 1036
1038 $scope.puntoVenta = $filter('rellenarDigitos')( 1037 $scope.puntoVenta = $filter('rellenarDigitos')(
1039 notaPedido.sucursal, 4 1038 notaPedido.sucursal, 4
1040 ); 1039 );
1041 1040
1042 $scope.comprobante = $filter('rellenarDigitos')( 1041 $scope.comprobante = $filter('rellenarDigitos')(
1043 notaPedido.numeroNotaPedido, 8 1042 notaPedido.numeroNotaPedido, 8
1044 ); 1043 );
1045 1044
1046 if (notaPedido.notaPedidoPuntoDescarga.length) { 1045 if (notaPedido.notaPedidoPuntoDescarga.length) {
1047 var puntos = []; 1046 var puntos = [];
1048 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) { 1047 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) {
1049 puntos.push(notaPedidoPuntoDescarga.puntoDescarga); 1048 puntos.push(notaPedidoPuntoDescarga.puntoDescarga);
1050 }); 1049 });
1051 cabeceras.push({ 1050 cabeceras.push({
1052 label: 'Puntos de descarga: ', 1051 label: 'Puntos de descarga: ',
1053 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) 1052 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos))
1054 }); 1053 });
1055 } 1054 }
1056 1055
1057 addArrayCabecera(cabeceras); 1056 addArrayCabecera(cabeceras);
1058 } 1057 }
1059 1058
1060 function getCabeceraPuntoDescarga(puntoDescarga) { 1059 function getCabeceraPuntoDescarga(puntoDescarga) {
1061 var puntosStamp = ''; 1060 var puntosStamp = '';
1062 puntoDescarga.forEach(function (punto, idx, arr) { 1061 puntoDescarga.forEach(function (punto, idx, arr) {
1063 puntosStamp += punto.descripcion; 1062 puntosStamp += punto.descripcion;
1064 if ((idx + 1) !== arr.length) puntosStamp += ', '; 1063 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1065 }); 1064 });
1066 return puntosStamp; 1065 return puntosStamp;
1067 } 1066 }
1068 1067
1069 function addArrayCabecera(array) { 1068 function addArrayCabecera(array) {
1070 for (var i = 0; i < array.length; i++) { 1069 for (var i = 0; i < array.length; i++) {
1071 $scope.$broadcast('addCabecera', { 1070 $scope.$broadcast('addCabecera', {
1072 label: array[i].label, 1071 label: array[i].label,
1073 valor: array[i].valor 1072 valor: array[i].valor
1074 }); 1073 });
1075 } 1074 }
1076 } 1075 }
1077 1076
1078 function validarNotaRemitada() { 1077 function validarNotaRemitada() {
1079 if (!$scope.notaPedido.idRemito) { 1078 if (!$scope.notaPedido.idRemito) {
1080 return true; 1079 return true;
1081 } else { 1080 } else {
1082 focaModalService.alert('No se puede editar una nota de pedido remitada'); 1081 focaModalService.alert('No se puede editar una nota de pedido remitada');
1083 return false; 1082 return false;
1084 } 1083 }
1085 } 1084 }
1086 1085
1087 function salir() { 1086 function salir() {
1088 var confirmacion = false; 1087 var confirmacion = false;
1089 1088
1090 if (!angular.equals($scope.notaPedido, $scope.inicial)) { 1089 if (!angular.equals($scope.notaPedido, $scope.inicial)) {
1091 confirmacion = true; 1090 confirmacion = true;
1092 } 1091 }
1093 1092
1094 if (confirmacion) { 1093 if (confirmacion) {
1095 focaModalService.confirm( 1094 focaModalService.confirm(
1096 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1095 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1097 ).then(function (data) { 1096 ).then(function (data) {
1098 if (data) { 1097 if (data) {
1099 $location.path('/'); 1098 $location.path('/');
1100 } 1099 }
1101 }); 1100 });
1102 } else { 1101 } else {
1103 $location.path('/'); 1102 $location.path('/');
1104 } 1103 }
1105 } 1104 }
1106 1105
1107 function getLSNotaPedido() { 1106 function getLSNotaPedido() {
1108 var notaPedido = JSON.parse($localStorage.notaPedido || null); 1107 var notaPedido = JSON.parse($localStorage.notaPedido || null);
1109 if (notaPedido) { 1108 if (notaPedido) {
1110 delete $localStorage.notaPedido; 1109 delete $localStorage.notaPedido;
1111 setearNotaPedido(notaPedido); 1110 setearNotaPedido(notaPedido);
1112 } 1111 }
1113 } 1112 }
1114 1113
1115 function deleteCliente() { 1114 function deleteCliente() {
1116 $scope.notaPedido.domicilioStamp = ''; 1115 $scope.notaPedido.domicilioStamp = '';
1117 $scope.notaPedido.notaPedidoPuntoDescarga = []; 1116 $scope.notaPedido.notaPedidoPuntoDescarga = [];
1118 $scope.notaPedido.domicilio = { dom: '' }; 1117 $scope.notaPedido.domicilio = { dom: '' };
1119 $scope.notaPedido.cliente = {}; 1118 $scope.notaPedido.cliente = {};
1120 $scope.$broadcast('removeCabecera', 'Cliente:'); 1119 $scope.$broadcast('removeCabecera', 'Cliente:');
1121 $scope.$broadcast('removeCabecera', 'Domicilio:'); 1120 $scope.$broadcast('removeCabecera', 'Domicilio:');
1122 $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); 1121 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1123 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false; 1122 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false;
1124 } 1123 }
1125 } 1124 }
1126 ]); 1125 ]);
1127 1126