Commit b7f1772add741098225a9650001d56ecd7ba1ca1

Authored by Luigi
1 parent dc8ce4a6c1
Exists in master

Elimino variables temporales

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