Commit 8a51c92b3a28116548c644ed2c58e94816752e73

Authored by Marcelo Puebla
1 parent a085b8d453
Exists in master

Arreglo cambio precio y condicion.

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