Commit 02bd2f0b6d213dfb2db1fb3efb1944a987869aa2

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

Envio de data a modal busqueda de cliente.

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