Commit 410ebbec8de9a7250f8d18fa68ce8ac6fe0e1ba0

Authored by Marcelo
1 parent 03ecc36c1b
Exists in master

Arreglo de cabecera, no mostraba punto de descarga

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