Commit 10f053b7894ce7263e5a0e672fc89c36b43169c4

Authored by Jose Pinto
1 parent af8cfbe551
Exists in master and in 1 other branch develop

fix error notaPedido undefined

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