Commit 0d8efeb89116a570be4d68e9056dfa3440b94dec

Authored by Eric Fernandez
1 parent c0a40582d1
Exists in develop

?

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