Commit 69a544160579c05558906a4bebcdd2b1b449b370

Authored by Eric Fernandez
1 parent 1fae4ccbb1
Exists in develop

no $scope.clientes

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