Commit 6eccd5edf7441d272c0ec60b2999fde0ea8a7f51

Authored by Eric
1 parent 78c7dd382b
Exists in master and in 1 other branch develop

inicial

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