Commit 78c7dd382b83e63a5b6595b03d122d9b2230e561

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master(efernandez)

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