Commit 0bb7798affa0c22f35c4ef6aecda846585d13dd2

Authored by Eric Fernandez
Exists in develop

Merge branch 'master' into 'develop'

Master(mpuebla)

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