Commit 3fd18ae414d652f799d62d3cd9691888bf65d2e5

Authored by Marcelo Puebla
1 parent 0bb7798aff
Exists in develop

Cambio en envio de parametros.

Showing 1 changed file with 8 additions and 6 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.cliente); 365 $scope.abrirModalDomicilios($scope.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.cliente); 376 $scope.abrirModalDomicilios($scope.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.cliente ? $scope.cliente.nom : ''; 494 cobrador: null,
495 } 495 searchText: $scope.cliente ? $scope.cliente.nom : ''
496 };
497 },
496 }, 498 },
497 size: 'lg' 499 size: 'lg'
498 } 500 }
499 ); 501 );
500 modalInstance.result.then( 502 modalInstance.result.then(
501 function (cliente) { 503 function (cliente) {
502 cliente.mod = cliente.mod; 504 cliente.mod = cliente.mod;
503 $scope.abrirModalDomicilios(cliente); 505 $scope.abrirModalDomicilios(cliente);
504 $scope.cliente = cliente; 506 $scope.cliente = cliente;
505 }, function () { } 507 }, function () { }
506 ); 508 );
507 } 509 }
508 }; 510 };
509 511
510 $scope.abrirModalProveedores = function (callback) { 512 $scope.abrirModalProveedores = function (callback) {
511 if (validarNotaRemitada()) { 513 if (validarNotaRemitada()) {
512 var parametrosModal = { 514 var parametrosModal = {
513 titulo: 'Búsqueda de Proveedor', 515 titulo: 'Búsqueda de Proveedor',
514 query: '/proveedor', 516 query: '/proveedor',
515 columnas: [ 517 columnas: [
516 { 518 {
517 nombre: 'Código', 519 nombre: 'Código',
518 propiedad: 'COD', 520 propiedad: 'COD',
519 filtro: { 521 filtro: {
520 nombre: 'rellenarDigitos', 522 nombre: 'rellenarDigitos',
521 parametro: 5 523 parametro: 5
522 } 524 }
523 }, 525 },
524 { 526 {
525 nombre: 'Nombre', 527 nombre: 'Nombre',
526 propiedad: 'NOM' 528 propiedad: 'NOM'
527 }, 529 },
528 { 530 {
529 nombre: 'CUIT', 531 nombre: 'CUIT',
530 propiedad: 'CUIT' 532 propiedad: 'CUIT'
531 } 533 }
532 ], 534 ],
533 tipo: 'POST', 535 tipo: 'POST',
534 json: { razonCuitCod: '' } 536 json: { razonCuitCod: '' }
535 }; 537 };
536 focaModalService.modal(parametrosModal).then( 538 focaModalService.modal(parametrosModal).then(
537 function (proveedor) { 539 function (proveedor) {
538 $scope.notaPedido.proveedor = proveedor; 540 $scope.notaPedido.proveedor = proveedor;
539 $scope.$broadcast('addCabecera', { 541 $scope.$broadcast('addCabecera', {
540 label: 'Proveedor:', 542 label: 'Proveedor:',
541 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 543 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
542 proveedor.NOM 544 proveedor.NOM
543 }); 545 });
544 callback(); 546 callback();
545 }, function () { 547 }, function () {
546 548
547 } 549 }
548 ); 550 );
549 } 551 }
550 }; 552 };
551 553
552 $scope.abrirModalDomicilios = function (cliente) { 554 $scope.abrirModalDomicilios = function (cliente) {
553 var modalInstanceDomicilio = $uibModal.open( 555 var modalInstanceDomicilio = $uibModal.open(
554 { 556 {
555 ariaLabelledBy: 'Busqueda de Domicilios', 557 ariaLabelledBy: 'Busqueda de Domicilios',
556 templateUrl: 'modal-domicilio.html', 558 templateUrl: 'modal-domicilio.html',
557 controller: 'focaModalDomicilioController', 559 controller: 'focaModalDomicilioController',
558 resolve: { 560 resolve: {
559 idCliente: function () { return cliente.cod; }, 561 idCliente: function () { return cliente.cod; },
560 esNuevo: function () { return cliente.esNuevo; } 562 esNuevo: function () { return cliente.esNuevo; }
561 }, 563 },
562 size: 'lg', 564 size: 'lg',
563 } 565 }
564 ); 566 );
565 modalInstanceDomicilio.result.then( 567 modalInstanceDomicilio.result.then(
566 function (domicilio) { 568 function (domicilio) {
567 $scope.notaPedido.domicilio = domicilio; 569 $scope.notaPedido.domicilio = domicilio;
568 $scope.notaPedido.cliente = { 570 $scope.notaPedido.cliente = {
569 COD: cliente.cod, 571 COD: cliente.cod,
570 CUIT: cliente.cuit, 572 CUIT: cliente.cuit,
571 NOM: cliente.nom, 573 NOM: cliente.nom,
572 MOD: cliente.mod, 574 MOD: cliente.mod,
573 VEN: cliente.ven 575 VEN: cliente.ven
574 }; 576 };
575 crearNotaPedidoService.getVendedorById($scope.notaPedido.cliente.VEN) 577 crearNotaPedidoService.getVendedorById($scope.notaPedido.cliente.VEN)
576 .then(function (res) { 578 .then(function (res) {
577 if (res.data !== '') { 579 if (res.data !== '') {
578 $scope.notaPedido.vendedor = res.data; 580 $scope.notaPedido.vendedor = res.data;
579 $scope.$broadcast('addCabecera', { 581 $scope.$broadcast('addCabecera', {
580 label: 'Vendedor:', 582 label: 'Vendedor:',
581 valor: $filter('rellenarDigitos') 583 valor: $filter('rellenarDigitos')
582 ($scope.notaPedido.vendedor.NUM, 3) + 584 ($scope.notaPedido.vendedor.NUM, 3) +
583 ' - ' + $scope.notaPedido.vendedor.NOM 585 ' - ' + $scope.notaPedido.vendedor.NOM
584 }); 586 });
585 } 587 }
586 var domicilioStamp = 588 var domicilioStamp =
587 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 589 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
588 domicilio.Localidad + ', ' + domicilio.Provincia; 590 domicilio.Localidad + ', ' + domicilio.Provincia;
589 $scope.notaPedido.domicilioStamp = domicilioStamp; 591 $scope.notaPedido.domicilioStamp = domicilioStamp;
590 592
591 $scope.$broadcast('addCabecera', { 593 $scope.$broadcast('addCabecera', {
592 label: 'Cliente:', 594 label: 'Cliente:',
593 valor: $filter('rellenarDigitos')(cliente.cod, 5) + 595 valor: $filter('rellenarDigitos')(cliente.cod, 5) +
594 ' - ' + cliente.nom 596 ' - ' + cliente.nom
595 }); 597 });
596 598
597 $scope.$broadcast('addCabecera', { 599 $scope.$broadcast('addCabecera', {
598 label: 'Domicilio:', 600 label: 'Domicilio:',
599 valor: domicilioStamp 601 valor: domicilioStamp
600 }); 602 });
601 603
602 if (domicilio.verPuntos) { 604 if (domicilio.verPuntos) {
603 delete $scope.notaPedido.domicilio.verPuntos; 605 delete $scope.notaPedido.domicilio.verPuntos;
604 $scope.seleccionarPuntosDeDescarga(); 606 $scope.seleccionarPuntosDeDescarga();
605 } 607 }
606 608
607 // Seteo checked en botonera 609 // Seteo checked en botonera
608 $filter('filter')($scope.botonera, 610 $filter('filter')($scope.botonera,
609 { label: 'Cliente' })[0].checked = true; 611 { label: 'Cliente' })[0].checked = true;
610 $filter('filter')($scope.botonera, 612 $filter('filter')($scope.botonera,
611 { label: 'Domicilio de Entrega' })[0].checked = true; 613 { label: 'Domicilio de Entrega' })[0].checked = true;
612 }) 614 })
613 .catch(function (e) { console.log(e); }); 615 .catch(function (e) { console.log(e); });
614 }, function () { 616 }, function () {
615 $scope.seleccionarCliente(true); 617 $scope.seleccionarCliente(true);
616 return; 618 return;
617 } 619 }
618 ); 620 );
619 }; 621 };
620 622
621 $scope.getTotal = function () { 623 $scope.getTotal = function () {
622 var total = 0; 624 var total = 0;
623 if ($scope.notaPedido.articulosNotaPedido) { 625 if ($scope.notaPedido.articulosNotaPedido) {
624 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; 626 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido;
625 for (var i = 0; i < arrayTempArticulos.length; i++) { 627 for (var i = 0; i < arrayTempArticulos.length; i++) {
626 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 628 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
627 } 629 }
628 } 630 }
629 return parseFloat(total.toFixed(2)); 631 return parseFloat(total.toFixed(2));
630 }; 632 };
631 633
632 $scope.getSubTotal = function () { 634 $scope.getSubTotal = function () {
633 if ($scope.articuloACargar) { 635 if ($scope.articuloACargar) {
634 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 636 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
635 } 637 }
636 }; 638 };
637 639
638 $scope.seleccionarPreciosYCondiciones = function () { 640 $scope.seleccionarPreciosYCondiciones = function () {
639 641
640 if (!validarNotaRemitada()) return; 642 if (!validarNotaRemitada()) return;
641 643
642 if (!$scope.notaPedido.cliente.COD) { 644 if (!$scope.notaPedido.cliente.COD) {
643 focaModalService.alert('Primero seleccione un cliente'); 645 focaModalService.alert('Primero seleccione un cliente');
644 return; 646 return;
645 } else { 647 } else {
646 abrirModal(); 648 abrirModal();
647 } 649 }
648 650
649 function abrirModal() { 651 function abrirModal() {
650 var parametros = { 652 var parametros = {
651 idCliente: $scope.notaPedido.cliente.COD, 653 idCliente: $scope.notaPedido.cliente.COD,
652 idListaPrecio: $scope.notaPedido.cliente.MOD, 654 idListaPrecio: $scope.notaPedido.cliente.MOD,
653 notaPedido: $scope.notaPedido 655 notaPedido: $scope.notaPedido
654 }; 656 };
655 var modalInstance = $uibModal.open( 657 var modalInstance = $uibModal.open(
656 { 658 {
657 ariaLabelledBy: 'Busqueda de Precio Condición', 659 ariaLabelledBy: 'Busqueda de Precio Condición',
658 templateUrl: 'modal-precio-condicion.html', 660 templateUrl: 'modal-precio-condicion.html',
659 controller: 'focaModalPrecioCondicionController', 661 controller: 'focaModalPrecioCondicionController',
660 size: 'lg', 662 size: 'lg',
661 resolve: { 663 resolve: {
662 parametros: function () { return parametros; }, 664 parametros: function () { return parametros; },
663 } 665 }
664 } 666 }
665 ); 667 );
666 668
667 modalInstance.result.then(function (precioCondicion) { 669 modalInstance.result.then(function (precioCondicion) {
668 var cabecera = ''; 670 var cabecera = '';
669 var plazosConcat = ''; 671 var plazosConcat = '';
670 if (!Array.isArray(precioCondicion)) { 672 if (!Array.isArray(precioCondicion)) {
671 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; 673 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago;
672 $scope.notaPedido.precioCondicion = precioCondicion; 674 $scope.notaPedido.precioCondicion = precioCondicion;
673 $scope.notaPedido.cliente.MOD = precioCondicion.listaPrecio.ID; 675 $scope.notaPedido.cliente.MOD = precioCondicion.listaPrecio.ID;
674 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? 676 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ?
675 parseInt(precioCondicion.listaPrecio.ID) : -1; 677 parseInt(precioCondicion.listaPrecio.ID) : -1;
676 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 678 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
677 plazosConcat += precioCondicion.plazoPago[i].dias + ', '; 679 plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
678 } 680 }
679 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); 681 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
680 cabecera = $filter('rellenarDigitos')($scope.idLista, 4) + 682 cabecera = $filter('rellenarDigitos')($scope.idLista, 4) +
681 ' - ' + precioCondicion.listaPrecio.DES + 683 ' - ' + precioCondicion.listaPrecio.DES +
682 ' ' + plazosConcat.trim(); 684 ' ' + plazosConcat.trim();
683 } else { //Cuando se ingresan los plazos manualmente 685 } else { //Cuando se ingresan los plazos manualmente
684 //-1, el modal productos busca todos los productos 686 //-1, el modal productos busca todos los productos
685 $scope.idLista = -1; 687 $scope.idLista = -1;
686 $scope.notaPedido.notaPedidoPlazo = precioCondicion; 688 $scope.notaPedido.notaPedidoPlazo = precioCondicion;
687 for (var j = 0; j < precioCondicion.length; j++) { 689 for (var j = 0; j < precioCondicion.length; j++) {
688 plazosConcat += precioCondicion[j].dias + ' '; 690 plazosConcat += precioCondicion[j].dias + ' ';
689 } 691 }
690 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 692 cabecera = 'Ingreso manual ' + plazosConcat.trim();
691 } 693 }
692 $scope.cabeceras.push({ 694 $scope.cabeceras.push({
693 label: 'Precios y Condiciones:', 695 label: 'Precios y Condiciones:',
694 valor: $scope.idLista + ' - ' + precioCondicion.listaPrecio.DES + ' ' + 696 valor: $scope.idLista + ' - ' + precioCondicion.listaPrecio.DES + ' ' +
695 notaPedidoBusinessService.plazoToString(precioCondicion.plazoPago) 697 notaPedidoBusinessService.plazoToString(precioCondicion.plazoPago)
696 }); 698 });
697 699
698 $filter('filter')($scope.botonera, 700 $filter('filter')($scope.botonera,
699 { label: 'Precios y Condiciones' })[0].checked = true; 701 { label: 'Precios y Condiciones' })[0].checked = true;
700 702
701 addArrayCabecera($scope.cabeceras); 703 addArrayCabecera($scope.cabeceras);
702 704
703 }) 705 })
704 .catch(function (e) { 706 .catch(function (e) {
705 console.log(e); 707 console.log(e);
706 }); 708 });
707 709
708 } 710 }
709 }; 711 };
710 712
711 $scope.seleccionarMoneda = function () { 713 $scope.seleccionarMoneda = function () {
712 if (validarNotaRemitada()) { 714 if (validarNotaRemitada()) {
713 var parametrosModal = { 715 var parametrosModal = {
714 titulo: 'Búsqueda de monedas', 716 titulo: 'Búsqueda de monedas',
715 query: '/moneda', 717 query: '/moneda',
716 columnas: [ 718 columnas: [
717 { 719 {
718 propiedad: 'DETALLE', 720 propiedad: 'DETALLE',
719 nombre: 'Nombre' 721 nombre: 'Nombre'
720 }, 722 },
721 { 723 {
722 propiedad: 'SIMBOLO', 724 propiedad: 'SIMBOLO',
723 nombre: 'Símbolo' 725 nombre: 'Símbolo'
724 } 726 }
725 ], 727 ],
726 size: 'md' 728 size: 'md'
727 }; 729 };
728 focaModalService.modal(parametrosModal).then( 730 focaModalService.modal(parametrosModal).then(
729 function (moneda) { 731 function (moneda) {
730 732
731 if (moneda.ID !== 1) { 733 if (moneda.ID !== 1) {
732 $scope.abrirModalCotizacion(moneda); 734 $scope.abrirModalCotizacion(moneda);
733 return; 735 return;
734 } 736 }
735 737
736 crearNotaPedidoService.getCotizacionByIdMoneda(1) 738 crearNotaPedidoService.getCotizacionByIdMoneda(1)
737 .then(function (res) { 739 .then(function (res) {
738 740
739 cotizacionPArgentino = res.data[0].cotizaciones[0]; 741 cotizacionPArgentino = res.data[0].cotizaciones[0];
740 cotizacionPArgentino.moneda = moneda; 742 cotizacionPArgentino.moneda = moneda;
741 743
742 actualizarCabeceraMoneda(cotizacionPArgentino); 744 actualizarCabeceraMoneda(cotizacionPArgentino);
743 $scope.notaPedido.cotizacion = cotizacionPArgentino; 745 $scope.notaPedido.cotizacion = cotizacionPArgentino;
744 }); 746 });
745 } 747 }
746 ); 748 );
747 } 749 }
748 }; 750 };
749 751
750 $scope.seleccionarObservaciones = function () { 752 $scope.seleccionarObservaciones = function () {
751 var observacion = { 753 var observacion = {
752 titulo: 'Ingrese Observaciones', 754 titulo: 'Ingrese Observaciones',
753 value: $scope.notaPedido.observaciones, 755 value: $scope.notaPedido.observaciones,
754 maxlength: 155, 756 maxlength: 155,
755 textarea: true 757 textarea: true
756 }; 758 };
757 759
758 focaModalService 760 focaModalService
759 .prompt(observacion) 761 .prompt(observacion)
760 .then(function (observaciones) { 762 .then(function (observaciones) {
761 $scope.notaPedido.observaciones = observaciones; 763 $scope.notaPedido.observaciones = observaciones;
762 }); 764 });
763 }; 765 };
764 766
765 $scope.abrirModalCotizacion = function (moneda) { 767 $scope.abrirModalCotizacion = function (moneda) {
766 var modalInstance = $uibModal.open( 768 var modalInstance = $uibModal.open(
767 { 769 {
768 ariaLabelledBy: 'Busqueda de Cotización', 770 ariaLabelledBy: 'Busqueda de Cotización',
769 templateUrl: 'modal-cotizacion.html', 771 templateUrl: 'modal-cotizacion.html',
770 controller: 'focaModalCotizacionController', 772 controller: 'focaModalCotizacionController',
771 size: 'lg', 773 size: 'lg',
772 resolve: { 774 resolve: {
773 idMoneda: function () { 775 idMoneda: function () {
774 return moneda.ID; 776 return moneda.ID;
775 } 777 }
776 } 778 }
777 } 779 }
778 ); 780 );
779 modalInstance.result.then( 781 modalInstance.result.then(
780 function (cotizacion) { 782 function (cotizacion) {
781 783
782 cotizacion.moneda = moneda; 784 cotizacion.moneda = moneda;
783 actualizarCabeceraMoneda(cotizacion); 785 actualizarCabeceraMoneda(cotizacion);
784 786
785 $scope.notaPedido.cotizacion = cotizacion; 787 $scope.notaPedido.cotizacion = cotizacion;
786 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 788 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
787 }, function () { 789 }, function () {
788 790
789 } 791 }
790 ); 792 );
791 }; 793 };
792 794
793 function actualizarCabeceraMoneda(cotizacion) { 795 function actualizarCabeceraMoneda(cotizacion) {
794 796
795 $scope.notaPedido.articulosNotaPedido.forEach(function (art) { 797 $scope.notaPedido.articulosNotaPedido.forEach(function (art) {
796 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); 798 art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4);
797 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); 799 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
798 }); 800 });
799 801
800 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 802 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
801 $scope.$broadcast('removeCabecera', 'Moneda:'); 803 $scope.$broadcast('removeCabecera', 'Moneda:');
802 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 804 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
803 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 805 $scope.$broadcast('removeCabecera', 'Cotizacion:');
804 } else { 806 } else {
805 $scope.$broadcast('addCabecera', { 807 $scope.$broadcast('addCabecera', {
806 label: 'Moneda:', 808 label: 'Moneda:',
807 valor: cotizacion.moneda.DETALLE 809 valor: cotizacion.moneda.DETALLE
808 }); 810 });
809 $scope.$broadcast('addCabecera', { 811 $scope.$broadcast('addCabecera', {
810 label: 'Fecha cotizacion:', 812 label: 'Fecha cotizacion:',
811 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 813 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
812 }); 814 });
813 $scope.$broadcast('addCabecera', { 815 $scope.$broadcast('addCabecera', {
814 label: 'Cotizacion:', 816 label: 'Cotizacion:',
815 valor: $filter('number')(cotizacion.VENDEDOR, '2') 817 valor: $filter('number')(cotizacion.VENDEDOR, '2')
816 }); 818 });
817 } 819 }
818 } 820 }
819 821
820 $scope.agregarATabla = function (key) { 822 $scope.agregarATabla = function (key) {
821 if (key === 13) { 823 if (key === 13) {
822 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { 824 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
823 focaModalService.alert('El valor debe ser al menos 1'); 825 focaModalService.alert('El valor debe ser al menos 1');
824 return; 826 return;
825 } 827 }
826 delete $scope.articuloACargar.sectorCodigo; 828 delete $scope.articuloACargar.sectorCodigo;
827 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); 829 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar);
828 $scope.cargando = true; 830 $scope.cargando = true;
829 } 831 }
830 }; 832 };
831 833
832 $scope.quitarArticulo = function (key) { 834 $scope.quitarArticulo = function (key) {
833 if (validarNotaRemitada()) { 835 if (validarNotaRemitada()) {
834 $scope.notaPedido.articulosNotaPedido.splice(key, 1); 836 $scope.notaPedido.articulosNotaPedido.splice(key, 1);
835 } 837 }
836 }; 838 };
837 839
838 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { 840 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
839 if (key === 13) { 841 if (key === 13) {
840 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { 842 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) {
841 focaModalService.alert('Los valores deben ser al menos 1'); 843 focaModalService.alert('Los valores deben ser al menos 1');
842 return; 844 return;
843 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 845 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
844 focaModalService.alert('Los valores no pueden ser negativos'); 846 focaModalService.alert('Los valores no pueden ser negativos');
845 return; 847 return;
846 } 848 }
847 articulo.cantidad = tmpCantidad; 849 articulo.cantidad = tmpCantidad;
848 articulo.precio = tmpPrecio; 850 articulo.precio = tmpPrecio;
849 $scope.getTotal(); 851 $scope.getTotal();
850 articulo.editCantidad = articulo.editPrecio = false; 852 articulo.editCantidad = articulo.editPrecio = false;
851 } 853 }
852 }; 854 };
853 855
854 $scope.cancelarEditar = function (articulo) { 856 $scope.cancelarEditar = function (articulo) {
855 $scope.tmpCantidad = articulo.cantidad; 857 $scope.tmpCantidad = articulo.cantidad;
856 $scope.tmpPrecio = articulo.precio; 858 $scope.tmpPrecio = articulo.precio;
857 articulo.editCantidad = articulo.editPrecio = false; 859 articulo.editCantidad = articulo.editPrecio = false;
858 }; 860 };
859 861
860 $scope.cambioEdit = function (articulo, propiedad) { 862 $scope.cambioEdit = function (articulo, propiedad) {
861 if (propiedad === 'cantidad') { 863 if (propiedad === 'cantidad') {
862 articulo.editCantidad = true; 864 articulo.editCantidad = true;
863 } else if (propiedad === 'precio') { 865 } else if (propiedad === 'precio') {
864 articulo.editPrecio = true; 866 articulo.editPrecio = true;
865 } 867 }
866 }; 868 };
867 869
868 $scope.resetFilter = function () { 870 $scope.resetFilter = function () {
869 $scope.articuloACargar = {}; 871 $scope.articuloACargar = {};
870 $scope.cargando = true; 872 $scope.cargando = true;
871 }; 873 };
872 //Recibe aviso si el teclado está en uso 874 //Recibe aviso si el teclado está en uso
873 $rootScope.$on('usarTeclado', function (event, data) { 875 $rootScope.$on('usarTeclado', function (event, data) {
874 if (data) { 876 if (data) {
875 $scope.mostrarTeclado = true; 877 $scope.mostrarTeclado = true;
876 return; 878 return;
877 } 879 }
878 $scope.mostrarTeclado = false; 880 $scope.mostrarTeclado = false;
879 }); 881 });
880 882
881 $scope.selectFocus = function ($event) { 883 $scope.selectFocus = function ($event) {
882 // Si el teclado esta en uso no selecciona el valor 884 // Si el teclado esta en uso no selecciona el valor
883 if ($scope.mostrarTeclado) { 885 if ($scope.mostrarTeclado) {
884 return; 886 return;
885 } 887 }
886 $event.target.select(); 888 $event.target.select();
887 }; 889 };
888 890
889 $scope.salir = function () { 891 $scope.salir = function () {
890 $location.path('/'); 892 $location.path('/');
891 }; 893 };
892 894
893 $scope.parsearATexto = function (articulo) { 895 $scope.parsearATexto = function (articulo) {
894 articulo.cantidad = parseFloat(articulo.cantidad); 896 articulo.cantidad = parseFloat(articulo.cantidad);
895 articulo.precio = parseFloat(articulo.precio); 897 articulo.precio = parseFloat(articulo.precio);
896 }; 898 };
897 899
898 // TODO: quitar watch usar función de articulos pedido cuando se haga 900 // TODO: quitar watch usar función de articulos pedido cuando se haga
899 $scope.$watch('notaPedido.articulosNotaPedido', function () { 901 $scope.$watch('notaPedido.articulosNotaPedido', function () {
900 if ($scope.notaPedido.articulosNotaPedido.length) { 902 if ($scope.notaPedido.articulosNotaPedido.length) {
901 $filter('filter')($scope.botonera, 903 $filter('filter')($scope.botonera,
902 { label: 'Productos' })[0].checked = true; 904 { label: 'Productos' })[0].checked = true;
903 } else { 905 } else {
904 $filter('filter')($scope.botonera, 906 $filter('filter')($scope.botonera,
905 { label: 'Productos' })[0].checked = false; 907 { label: 'Productos' })[0].checked = false;
906 } 908 }
907 }, true); 909 }, true);
908 910
909 function setearNotaPedido(notaPedido) { 911 function setearNotaPedido(notaPedido) {
910 //añado cabeceras 912 //añado cabeceras
911 $scope.notaPedido = notaPedido; 913 $scope.notaPedido = notaPedido;
912 if (!$scope.notaPedido.domicilio) { 914 if (!$scope.notaPedido.domicilio) {
913 $scope.notaPedido.domicilio = { 915 $scope.notaPedido.domicilio = {
914 id: $scope.notaPedido.idDomicilio 916 id: $scope.notaPedido.idDomicilio
915 }; 917 };
916 } 918 }
917 $scope.$broadcast('removeCabecera', 'Bomba:'); 919 $scope.$broadcast('removeCabecera', 'Bomba:');
918 $scope.$broadcast('removeCabecera', 'Kilometros:'); 920 $scope.$broadcast('removeCabecera', 'Kilometros:');
919 $scope.$broadcast('cleanCabecera'); 921 $scope.$broadcast('cleanCabecera');
920 922
921 $scope.cabeceras = []; 923 $scope.cabeceras = [];
922 924
923 if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 925 if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
924 $scope.cabeceras.push({ 926 $scope.cabeceras.push({
925 label: 'Moneda:', 927 label: 'Moneda:',
926 valor: notaPedido.cotizacion.moneda.DETALLE 928 valor: notaPedido.cotizacion.moneda.DETALLE
927 }); 929 });
928 $scope.cabeceras.push({ 930 $scope.cabeceras.push({
929 label: 'Fecha cotizacion:', 931 label: 'Fecha cotizacion:',
930 valor: $filter('date')(notaPedido.cotizacion.FECHA, 932 valor: $filter('date')(notaPedido.cotizacion.FECHA,
931 'dd/MM/yyyy') 933 'dd/MM/yyyy')
932 }); 934 });
933 $scope.cabeceras.push({ 935 $scope.cabeceras.push({
934 label: 'Cotizacion:', 936 label: 'Cotizacion:',
935 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 937 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
936 '2') 938 '2')
937 }); 939 });
938 } 940 }
939 941
940 if (notaPedido.cotizacion.moneda) { 942 if (notaPedido.cotizacion.moneda) {
941 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 943 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
942 } 944 }
943 945
944 if (notaPedido.vendedor.NUM) { 946 if (notaPedido.vendedor.NUM) {
945 $scope.cabeceras.push({ 947 $scope.cabeceras.push({
946 label: 'Vendedor:', 948 label: 'Vendedor:',
947 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + 949 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) +
948 ' - ' + notaPedido.vendedor.NOM 950 ' - ' + notaPedido.vendedor.NOM
949 }); 951 });
950 } 952 }
951 953
952 if (notaPedido.cliente.COD) { 954 if (notaPedido.cliente.COD) {
953 $scope.cabeceras.push({ 955 $scope.cabeceras.push({
954 label: 'Cliente:', 956 label: 'Cliente:',
955 valor: notaPedido.cliente.NOM 957 valor: notaPedido.cliente.NOM
956 }); 958 });
957 $scope.cabeceras.push({ 959 $scope.cabeceras.push({
958 label: 'Domicilio:', 960 label: 'Domicilio:',
959 valor: notaPedido.domicilioStamp 961 valor: notaPedido.domicilioStamp
960 }); 962 });
961 963
962 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 964 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
963 } 965 }
964 966
965 if (notaPedido.proveedor.COD) { 967 if (notaPedido.proveedor.COD) {
966 $scope.cabeceras.push({ 968 $scope.cabeceras.push({
967 label: 'Proveedor:', 969 label: 'Proveedor:',
968 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + 970 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) +
969 ' - ' + notaPedido.proveedor.NOM 971 ' - ' + notaPedido.proveedor.NOM
970 }); 972 });
971 973
972 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; 974 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
973 } 975 }
974 976
975 if (notaPedido.notaPedidoPlazo.length) { 977 if (notaPedido.notaPedidoPlazo.length) {
976 valorPrecioCondicion(); 978 valorPrecioCondicion();
977 $filter('filter')($scope.botonera, 979 $filter('filter')($scope.botonera,
978 { label: 'Precios y condiciones' })[0].checked = true; 980 { label: 'Precios y condiciones' })[0].checked = true;
979 } 981 }
980 982
981 if (notaPedido.flete !== undefined) { 983 if (notaPedido.flete !== undefined) {
982 $scope.cabeceras.push({ 984 $scope.cabeceras.push({
983 label: 'Flete:', 985 label: 'Flete:',
984 valor: notaPedido.fob === 1 ? 'FOB' : ( 986 valor: notaPedido.fob === 1 ? 'FOB' : (
985 notaPedido.flete === 1 ? 'Si' : 'No') 987 notaPedido.flete === 1 ? 'Si' : 'No')
986 }); 988 });
987 } 989 }
988 990
989 function valorPrecioCondicion() { 991 function valorPrecioCondicion() {
990 if (notaPedido.idListaPrecio > 0) { 992 if (notaPedido.idListaPrecio > 0) {
991 crearNotaPedidoService 993 crearNotaPedidoService
992 .getPrecioCondicionById(parseInt(notaPedido.idListaPrecio)) 994 .getPrecioCondicionById(parseInt(notaPedido.idListaPrecio))
993 .then(function (res) { 995 .then(function (res) {
994 $scope.cabeceras.push({ 996 $scope.cabeceras.push({
995 label: 'Precios y Condiciones:', 997 label: 'Precios y Condiciones:',
996 valor: parseInt(res.data[0].ID) + ' - ' + 998 valor: parseInt(res.data[0].ID) + ' - ' +
997 res.data[0].DES + ' ' + 999 res.data[0].DES + ' ' +
998 notaPedidoBusinessService 1000 notaPedidoBusinessService
999 .plazoToString(notaPedido.notaPedidoPlazo) 1001 .plazoToString(notaPedido.notaPedidoPlazo)
1000 }); 1002 });
1001 addArrayCabecera($scope.cabeceras); 1003 addArrayCabecera($scope.cabeceras);
1002 }); 1004 });
1003 } 1005 }
1004 $scope.idLista = parseInt(notaPedido.idListaPrecio); 1006 $scope.idLista = parseInt(notaPedido.idListaPrecio);
1005 } 1007 }
1006 1008
1007 if (notaPedido.flete === 1) { 1009 if (notaPedido.flete === 1) {
1008 var cabeceraBomba = { 1010 var cabeceraBomba = {
1009 label: 'Bomba:', 1011 label: 'Bomba:',
1010 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 1012 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
1011 }; 1013 };
1012 if (notaPedido.kilometros) { 1014 if (notaPedido.kilometros) {
1013 var cabeceraKilometros = { 1015 var cabeceraKilometros = {
1014 label: 'Kilometros:', 1016 label: 'Kilometros:',
1015 valor: notaPedido.kilometros 1017 valor: notaPedido.kilometros
1016 }; 1018 };
1017 $scope.cabeceras.push(cabeceraKilometros); 1019 $scope.cabeceras.push(cabeceraKilometros);
1018 } 1020 }
1019 $scope.cabeceras.push(cabeceraBomba); 1021 $scope.cabeceras.push(cabeceraBomba);
1020 } 1022 }
1021 1023
1022 if (notaPedido.idPrecioCondicion > 0) { 1024 if (notaPedido.idPrecioCondicion > 0) {
1023 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 1025 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
1024 } else if (notaPedido.idPrecioCondicion) { 1026 } else if (notaPedido.idPrecioCondicion) {
1025 $scope.idLista = -1; 1027 $scope.idLista = -1;
1026 } 1028 }
1027 1029
1028 $scope.puntoVenta = $filter('rellenarDigitos')( 1030 $scope.puntoVenta = $filter('rellenarDigitos')(
1029 notaPedido.sucursal, 4 1031 notaPedido.sucursal, 4
1030 ); 1032 );
1031 1033
1032 $scope.comprobante = $filter('rellenarDigitos')( 1034 $scope.comprobante = $filter('rellenarDigitos')(
1033 notaPedido.numeroNotaPedido, 8 1035 notaPedido.numeroNotaPedido, 8
1034 ); 1036 );
1035 1037
1036 if (notaPedido.notaPedidoPuntoDescarga.length) { 1038 if (notaPedido.notaPedidoPuntoDescarga.length) {
1037 var puntos = []; 1039 var puntos = [];
1038 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) { 1040 notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) {
1039 puntos.push(notaPedidoPuntoDescarga.puntoDescarga); 1041 puntos.push(notaPedidoPuntoDescarga.puntoDescarga);
1040 }); 1042 });
1041 $scope.cabeceras.push({ 1043 $scope.cabeceras.push({
1042 label: 'Puntos de descarga: ', 1044 label: 'Puntos de descarga: ',
1043 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) 1045 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos))
1044 }); 1046 });
1045 } 1047 }
1046 1048
1047 addArrayCabecera($scope.cabeceras); 1049 addArrayCabecera($scope.cabeceras);
1048 } 1050 }
1049 1051
1050 function getCabeceraPuntoDescarga(puntoDescarga) { 1052 function getCabeceraPuntoDescarga(puntoDescarga) {
1051 var puntosStamp = ''; 1053 var puntosStamp = '';
1052 puntoDescarga.forEach(function (punto, idx, arr) { 1054 puntoDescarga.forEach(function (punto, idx, arr) {
1053 puntosStamp += punto.descripcion; 1055 puntosStamp += punto.descripcion;
1054 if ((idx + 1) !== arr.length) puntosStamp += ', '; 1056 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1055 }); 1057 });
1056 return puntosStamp; 1058 return puntosStamp;
1057 } 1059 }
1058 1060
1059 function addArrayCabecera(array) { 1061 function addArrayCabecera(array) {
1060 for (var i = 0; i < array.length; i++) { 1062 for (var i = 0; i < array.length; i++) {
1061 $scope.$broadcast('addCabecera', { 1063 $scope.$broadcast('addCabecera', {
1062 label: array[i].label, 1064 label: array[i].label,
1063 valor: array[i].valor 1065 valor: array[i].valor
1064 }); 1066 });
1065 } 1067 }
1066 } 1068 }
1067 1069
1068 function validarNotaRemitada() { 1070 function validarNotaRemitada() {
1069 if (!$scope.notaPedido.idRemito) { 1071 if (!$scope.notaPedido.idRemito) {
1070 return true; 1072 return true;
1071 } else { 1073 } else {
1072 focaModalService.alert('No se puede editar una nota de pedido remitada'); 1074 focaModalService.alert('No se puede editar una nota de pedido remitada');
1073 return false; 1075 return false;
1074 } 1076 }
1075 } 1077 }
1076 1078
1077 function salir() { 1079 function salir() {
1078 var confirmacion = false; 1080 var confirmacion = false;
1079 1081
1080 if (!angular.equals($scope.notaPedido, $scope.inicial)) { 1082 if (!angular.equals($scope.notaPedido, $scope.inicial)) {
1081 confirmacion = true; 1083 confirmacion = true;
1082 } 1084 }
1083 1085
1084 if (confirmacion) { 1086 if (confirmacion) {
1085 focaModalService.confirm( 1087 focaModalService.confirm(
1086 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1088 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1087 ).then(function (data) { 1089 ).then(function (data) {
1088 if (data) { 1090 if (data) {
1089 $location.path('/'); 1091 $location.path('/');
1090 } 1092 }
1091 }); 1093 });
1092 } else { 1094 } else {
1093 $location.path('/'); 1095 $location.path('/');
1094 } 1096 }
1095 } 1097 }
1096 1098
1097 function getLSNotaPedido() { 1099 function getLSNotaPedido() {
1098 var notaPedido = JSON.parse($localStorage.notaPedido || null); 1100 var notaPedido = JSON.parse($localStorage.notaPedido || null);
1099 if (notaPedido) { 1101 if (notaPedido) {
1100 delete $localStorage.notaPedido; 1102 delete $localStorage.notaPedido;
1101 setearNotaPedido(notaPedido); 1103 setearNotaPedido(notaPedido);
1102 } 1104 }
1103 } 1105 }
1104 1106
1105 function deleteCliente() { 1107 function deleteCliente() {
1106 $scope.notaPedido.domicilioStamp = ''; 1108 $scope.notaPedido.domicilioStamp = '';
1107 $scope.notaPedido.notaPedidoPuntoDescarga = []; 1109 $scope.notaPedido.notaPedidoPuntoDescarga = [];
1108 $scope.notaPedido.domicilio = { dom: '' }; 1110 $scope.notaPedido.domicilio = { dom: '' };
1109 $scope.notaPedido.cliente = {}; 1111 $scope.notaPedido.cliente = {};
1110 $scope.$broadcast('removeCabecera', 'Cliente:'); 1112 $scope.$broadcast('removeCabecera', 'Cliente:');
1111 $scope.$broadcast('removeCabecera', 'Domicilio:'); 1113 $scope.$broadcast('removeCabecera', 'Domicilio:');
1112 $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); 1114 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1113 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false; 1115 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false;
1114 } 1116 }
1115 } 1117 }
1116 ]); 1118 ]);
1117 1119