Commit 07e0d7c7b1594141e9eeca5345448e681ed93866

Authored by Luigi
1 parent dca6a3afd6
Exists in master

Auto stash before revert of "Validar id remito"

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