Commit 1fae4ccbb1aa6b62704e3f97db49e9b73e375506

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'develop' of http://git.focasoftware.com/npm/foca-crear-nota-pedido

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