Commit 638e7c6e59b464b14587424d31a30e31fec66242

Authored by Luigi
1 parent 49f819a76e
Exists in master and in 1 other branch develop

Cambios

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