Commit 6d049380aa69899b5acc0b6ad2840f2e93eb3604

Authored by Eric Fernandez
1 parent 9e918791b9
Exists in master

Validaciones de ingreso de datos

guarda nota de pedido
... ... @@ -27,6 +27,8 @@
27 27 <script src="node_modules/foca-modal-flete/dist/foca-modal-flete.min.js"></script>
28 28 <script src="node_modules/foca-modal/dist/foca-modal.min.js"></script>
29 29 <script src="node_modules/foca-modal-domicilio/dist/foca-modal-domicilios.min.js"></script>
  30 + <script src="node_modules/foca-modal-moneda/dist/foca-modal-moneda.min.js"></script>
  31 + <script src="node_modules/foca-modal-cotizacion/dist/foca-modal-cotizacion.min.js"></script>
30 32  
31 33 <script src="src/js/app.js"></script>
32 34 <script src="src/js/controller.js"></script>
... ... @@ -8,7 +8,7 @@
8 8 "compile": "gulp uglify",
9 9 "gulp-pre-commit": "gulp pre-commit",
10 10 "postinstall": "npm run compile && gulp clean-post-install",
11   - "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+https://debo.suite.repo/modulos-npm/foca-directivas.git git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git git+https://debo.suite.repo/modulos-npm/foca-modal-flete git+https://debo.suite.repo/modulos-npm/foca-modal.git git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git"
  11 + "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+https://debo.suite.repo/modulos-npm/foca-directivas.git git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git git+https://debo.suite.repo/modulos-npm/foca-modal-flete git+https://debo.suite.repo/modulos-npm/foca-modal.git git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git"
12 12 },
13 13 "pre-commit": [
14 14 "gulp-pre-commit"
... ... @@ -35,8 +35,10 @@
35 35 "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git",
36 36 "foca-modal": "git+https://debo.suite.repo/modulos-npm/foca-modal.git",
37 37 "foca-modal-busqueda-productos": "git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos",
  38 + "foca-modal-cotizacion": "git+https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git",
38 39 "foca-modal-domicilio": "git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git",
39 40 "foca-modal-flete": "git+https://debo.suite.repo/modulos-npm/foca-modal-flete",
  41 + "foca-modal-moneda": "git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git",
40 42 "foca-modal-precio-condiciones": "git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git",
41 43 "foca-modal-proveedor": "git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git",
42 44 "foca-modal-vendedores": "git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git",
... ... @@ -10,5 +10,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;, [
10 10 'focaDirectivas',
11 11 'focaModal',
12 12 'focaModalDomicilio',
13   - 'angular-ladda'
  13 + 'angular-ladda',
  14 + 'focaModalMoneda',
  15 + 'focaModalCotizacion'
14 16 ]);
src/js/controller.js
... ... @@ -25,14 +25,38 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
25 25 maxDate: new Date(),
26 26 minDate: new Date(2010, 0, 1)
27 27 };
  28 + $scope.crearObjetoNotaPedido = function() {
  29 + $scope.notaPedido = {
  30 + vendedor: {},
  31 + cliente: {},
  32 + proveedor: {},
  33 + domicilio: {dom: ''},
  34 + moneda: {},
  35 + cotizacion: {}
  36 + };
  37 + };
28 38  
29   - $scope.notaPedido = {
30   - vendedor: {},
31   - cliente: {},
32   - domicilio: {dom: ''},
33   - moneda: {detalle: ''}
  39 + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
  40 + $scope.obtenerMonedaPorDefecto = function() {
  41 + crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
  42 + monedaPorDefecto = {
  43 + id: res.data[0].ID,
  44 + detalle: res.data[0].DETALLE,
  45 + simbolo: res.data[0].SIMBOLO,
  46 + cotizaciones: res.data[0].cotizaciones
  47 + };
  48 + addCabecera('Moneda:', monedaPorDefecto.detalle);
  49 + addCabecera('Fecha cotizacion:',
  50 + new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString());
  51 + addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION);
  52 + $scope.notaPedido.moneda = monedaPorDefecto;
  53 + $scope.notaPedido.cotizacion.id = monedaPorDefecto.cotizaciones[0].ID;
  54 + });
34 55 };
35 56  
  57 + var monedaPorDefecto;
  58 + $scope.crearObjetoNotaPedido();
  59 + $scope.obtenerMonedaPorDefecto();
36 60 $scope.cabecera = [];
37 61 $scope.showCabecera = true;
38 62  
... ... @@ -42,24 +66,27 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
42 66  
43 67 $scope.articulosTabla = [];
44 68 $scope.idLista = undefined;
45   - var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
  69 + //La pantalla solo se usa para cargar pedidos
  70 + //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
  71 +
46 72 crearNotaPedidoService.getPrecioCondicion().then(
47 73 function(res) {
48 74 $scope.precioCondiciones = res.data;
49 75 }
50 76 );
51   - if (notaPedidoTemp !== undefined) {
52   - notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
53   - $scope.notaPedido = notaPedidoTemp;
54   - $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
55   - $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
56   - $scope.idLista = $scope.notaPedido.precioCondicion;
57   - crearNotaPedidoService
58   - .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
59   - function(res) {
60   - $scope.articulosTabla = res.data;
61   - }
62   - );
  77 + //La pantalla solo se usa para cargar pedidos
  78 + // if (notaPedidoTemp !== undefined) {
  79 + // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
  80 + // $scope.notaPedido = notaPedidoTemp;
  81 + // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
  82 + // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
  83 + // $scope.idLista = $scope.notaPedido.precioCondicion;
  84 + // crearNotaPedidoService
  85 + // .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
  86 + // function(res) {
  87 + // $scope.articulosTabla = res.data;
  88 + // }
  89 + // );
63 90 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
64 91 //(NO REQUERIDO EN ESTA VERSION)
65 92 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
... ... @@ -67,12 +94,12 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
67 94 // $scope.notaPedido.domicilio = res.data;
68 95 // }
69 96 // );
70   - } else {
71   - $scope.notaPedido.fechaCarga = new Date();
72   - $scope.notaPedido.bomba = '0';
73   - $scope.notaPedido.flete = '0';
74   - $scope.idLista = undefined;
75   - }
  97 + // } else {
  98 + // $scope.notaPedido.fechaCarga = new Date();
  99 + // $scope.notaPedido.bomba = '0';
  100 + // $scope.notaPedido.flete = '0';
  101 + // $scope.idLista = undefined;
  102 + // }
76 103 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
77 104 // $scope.addNewDom = function() {
78 105 // $scope.notaPedido.domicilio.push({ 'id': 0 });
... ... @@ -86,39 +113,55 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
86 113 // ), 1);
87 114 // }
88 115 // };
  116 +
89 117 $scope.crearNotaPedido = function() {
90   - if($scope.articulosTabla.length === 0) {
  118 + if(!$scope.notaPedido.vendedor.codigo) {
  119 + focaModalService.alert('Ingrese Vendedor');
  120 + return;
  121 + } else if(!$scope.notaPedido.cliente.id) {
  122 + focaModalService.alert('Ingrese Cliente');
  123 + return;
  124 + } else if(!$scope.notaPedido.proveedor.codigo) {
  125 + focaModalService.alert('Ingrese Proveedor');
  126 + return;
  127 + } else if(!$scope.notaPedido.moneda.id) {
  128 + focaModalService.alert('Ingrese Moneda');
  129 + return;
  130 + } else if(!$scope.notaPedido.cotizacion.id) {
  131 + focaModalService.alert('Ingrese Cotización');
  132 + return;
  133 + } else if(!$scope.plazosPagos) {
  134 + focaModalService.alert('Ingrese Precios y Condiciones');
  135 + return;
  136 + } else if(!$scope.notaPedido.flete) {
  137 + focaModalService.alert('Ingrese Flete');
  138 + return;
  139 + } else if(!$scope.notaPedido.domicilio.id) {
  140 + focaModalService.aler('Ingrese Domicilio');
  141 + return;
  142 + } else if($scope.articulosTabla.length === 0) {
91 143 focaModalService.alert('Debe cargar almenos un articulo');
92 144 return;
93 145 }
94   - if($scope.notaPedido.domicilio.id === undefined) {
95   - $scope.notaPedido.domicilio.id = 0;
96   - }
97 146 var date = new Date();
98 147 var notaPedido = {
99 148 id: 0,
100 149 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
101 150 .toISOString().slice(0, 19).replace('T', ' '),
102   - vendedor: $scope.notaPedido.vendedor.nombre,
  151 + idVendedor: $scope.notaPedido.vendedor.codigo,
103 152 idCliente: $scope.notaPedido.cliente.id,
104   - domicilio: $scope.notaPedido.domicilio,
105   - bomba: $scope.notaPedido.bomba,
106   - flete: $scope.notaPedido.flete,
  153 + idProveedor: $scope.notaPedido.proveedor.codigo,
  154 + idDomicilio: $scope.notaPedido.domicilio.id,
  155 + idCotizacion: $scope.notaPedido.cotizacion.id,
  156 + flete: parseInt($scope.notaPedido.flete),
  157 + fob: parseInt($scope.notaPedido.fob),
  158 + bomba: parseInt($scope.notaPedido.bomba),
  159 + kilometros: $scope.notaPedido.kilometros,
107 160 total: $scope.getTotal()
108 161 };
109 162 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
110 163 function(data) {
111   - if($scope.notaPedido.flete === 1) {
112   - var flete = {
113   - idNotaPedido: data.data.id,
114   - idTransportista: $scope.notaPedido.fleteId,
115   - idChofer: $scope.notaPedido.chofer.id,
116   - idVehiculo: $scope.notaPedido.vehiculo.id,
117   - kilometros: $scope.notaPedido.kilometros,
118   - costoKilometro: $scope.notaPedido.costoUnitarioKmFlete
119   - };
120   - crearNotaPedidoService.crearFlete(flete);
121   - }
  164 +
122 165 var articulosNotaPedido = $scope.articulosTabla;
123 166 for(var i = 0; i < articulosNotaPedido.length; i++) {
124 167 delete articulosNotaPedido[i].editCantidad;
... ... @@ -136,7 +179,10 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
136 179 crearNotaPedidoService.crearPlazosParaNotaPedido(json);
137 180 }
138 181 focaModalService.alert('Nota pedido creada');
139   - $scope.limpiarPantalla();
  182 + $scope.obtenerMonedaPorDefecto();
  183 + $scope.crearObjetoNotaPedido();
  184 + $scope.cabecera = [];
  185 + $scope.articulosTabla = [];
140 186 }
141 187 );
142 188 };
... ... @@ -192,7 +238,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
192 238 modalInstance.result.then(
193 239 function(vendedor) {
194 240 addCabecera('Vendedor:', vendedor.NomVen);
195   - $scope.notaPedido.vendedor.nombre = vendedor.NomVen;
  241 + $scope.notaPedido.vendedor.codigo = vendedor.CodVen;
196 242 }, function() {
197 243  
198 244 }
... ... @@ -210,7 +256,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
210 256 );
211 257 modalInstance.result.then(
212 258 function(proveedor) {
213   - $scope.notaPedido.proveedor = proveedor.NOM;
  259 + $scope.notaPedido.proveedor.codigo = proveedor.COD;
214 260 addCabecera('Proveedor:', proveedor.NOM);
215 261 }, function() {
216 262  
... ... @@ -219,6 +265,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
219 265 };
220 266  
221 267 $scope.seleccionarCliente = function() {
  268 +
222 269 var modalInstance = $uibModal.open(
223 270 {
224 271 ariaLabelledBy: 'Busqueda de Cliente',
... ... @@ -229,8 +276,6 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
229 276 );
230 277 modalInstance.result.then(
231 278 function(cliente) {
232   - $scope.notaPedido.cliente.nombre = cliente.nom;
233   - $scope.notaPedido.cliente.id = cliente.cod;
234 279 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then(
235 280 function(data) {
236 281 if(data.data.length === 0){
... ... @@ -239,37 +284,38 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
239 284 .then(
240 285 function() {
241 286 $scope.seleccionarCliente();
242   - $scope.notaPedido.cliente = {nombre: ''};
243 287 }
244 288 );
245 289 return;
246 290 }
247   - var modalInstanceDomicilio = $uibModal.open(
248   - {
249   - ariaLabelledBy: 'Busqueda de Domicilios',
250   - templateUrl: 'modal-domicilio.html',
251   - controller: 'focaModalDomicilioController',
252   - resolve: { idCliente: function() { return cliente.cod; }},
253   - size: 'lg',
254   - backdrop: 'static',
255   - }
256   - );
257   - modalInstanceDomicilio.result.then(
258   - function(domicilio) {
259   - focaModalService.alert('Domicilio elegido' + domicilio.dom);
260   - }, function() {
261   - $scope.notaPedido.cliente.nombre = '';
262   - $scope.notaPedido.cliente.id = '';
263   - removeCabecera('Cliente:');
264   - $scope.seleccionarCliente();
265   - return;
266   - }
267   - );
  291 + $scope.abrirModalDomicilios(cliente);
268 292 }
269 293 );
270   - addCabecera('Cliente:', cliente.nom);
271 294 }, function() {
  295 +
  296 + }
  297 + );
  298 + };
272 299  
  300 + $scope.abrirModalDomicilios = function(cliente) {
  301 + var modalInstanceDomicilio = $uibModal.open(
  302 + {
  303 + ariaLabelledBy: 'Busqueda de Domicilios',
  304 + templateUrl: 'modal-domicilio.html',
  305 + controller: 'focaModalDomicilioController',
  306 + resolve: { idCliente: function() { return cliente.cod; }},
  307 + size: 'lg',
  308 + }
  309 + );
  310 + modalInstanceDomicilio.result.then(
  311 + function(domicilio) {
  312 + $scope.notaPedido.domicilio.id = domicilio.id;
  313 + $scope.notaPedido.cliente.id = cliente.cod;
  314 + addCabecera('Cliente:', cliente.nom);
  315 + addCabecera('Domicilio:', domicilio.dom);
  316 + }, function() {
  317 + $scope.seleccionarCliente();
  318 + return;
273 319 }
274 320 );
275 321 };
... ... @@ -291,7 +337,7 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
291 337 for (var i = 0; i < arrayTempArticulos.length; i++) {
292 338 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
293 339 }
294   - return total.toFixed(2);
  340 + return parseFloat(total.toFixed(2));
295 341 };
296 342  
297 343 $scope.getSubTotal = function() {
... ... @@ -358,11 +404,12 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
358 404 modalInstance.result.then(
359 405 function(datos) {
360 406 $scope.notaPedido.flete = datos.flete;
  407 + $scope.notaPedido.fob = datos.FOB;
361 408 $scope.notaPedido.bomba = datos.bomba;
362 409 $scope.notaPedido.kilometros = datos.kilometros;
363 410  
364 411 addCabecera('Flete:', datos.flete);
365   - if(datos.flete === 'si') {
  412 + if(datos.flete === '1') {
366 413 addCabecera('Bomba:', datos.bomba);
367 414 addCabecera('Kilometros:', datos.kilometros);
368 415 } else {
... ... @@ -386,37 +433,36 @@ angular.module(&#39;focaCrearNotaPedido&#39;) .controller(&#39;notaPedidoCtrl&#39;,
386 433 );
387 434 modalInstance.result.then(
388 435 function(moneda) {
389   - $scope.notaPedido.moneda = {
390   - id: moneda.ID,
391   - detalle: moneda.DETALLE,
392   - simbolo: moneda.SIMBOLO
393   - };
394 436  
395   - addCabecera('Moneda:', moneda.DETALLE);
396   - $scope.abrirModalCotizacion(moneda.ID);
  437 + $scope.abrirModalCotizacion(moneda);
397 438 }, function() {
398 439  
399 440 }
400 441 );
401 442 };
402 443  
403   - $scope.abrirModalCotizacion = function(idMoneda) {
  444 + $scope.abrirModalCotizacion = function(moneda) {
404 445 var modalInstance = $uibModal.open(
405 446 {
406 447 ariaLabelledBy: 'Busqueda de Cotización',
407 448 templateUrl: 'modal-cotizacion.html',
408 449 controller: 'focaModalCotizacionController',
409 450 size: 'lg',
410   - resolve: {idMoneda: function() {return idMoneda;}}
  451 + resolve: {idMoneda: function() {return moneda.ID;}}
411 452 }
412 453 );
413 454 modalInstance.result.then(
414 455 function(cotizacion) {
  456 + $scope.notaPedido.moneda = {
  457 + id: moneda.ID,
  458 + detalle: moneda.DETALLE,
  459 + simbolo: moneda.SIMBOLO
  460 + };
415 461 $scope.notaPedido.cotizacion = {
416 462 id: cotizacion.ID,
417 463 cotizacion: cotizacion.COTIZACION
418 464 };
419   -
  465 + addCabecera('Moneda:', moneda.DETALLE);
420 466 addCabecera(
421 467 'Fecha cotizacion:',
422 468 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
... ... @@ -45,6 +45,9 @@ angular.module(&#39;focaCrearNotaPedido&#39;)
45 45 },
46 46 crearPlazosParaNotaPedido: function(plazos) {
47 47 return $http.post(route + '/plazo-pago/nota-pedido', plazos);
  48 + },
  49 + getCotizacionByIdMoneda: function(id) {
  50 + return $http.get(route + '/moneda/' + id);
48 51 }
49 52 };
50 53 }]);