Commit 1f5fb5fb9c0a47e459d952bebd90f131430a4e81
Exists in
master
Merge branch 'master' into 'master'
Master(mpuebla) See merge request !2
Showing
4 changed files
Show diff stats
package.json
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | "description": "foca-modal-descarga", |
5 | 5 | "main": "index.js", |
6 | 6 | "scripts": { |
7 | + "refresh": "gulp uglify && cp tmp/foca-modal-descarga.js ../wrapper-demo/node_modules/foca-modal-descarga/dist/foca-modal-descarga.min.js", | |
7 | 8 | "test": "echo \"Error: no test specified\" && exit 1", |
8 | 9 | "compile": "gulp uglify", |
9 | 10 | "gulp-pre-commit": "gulp pre-commit", |
src/js/controller.js
... | ... | @@ -7,29 +7,50 @@ angular.module('focaModalDescarga') |
7 | 7 | '$timeout', |
8 | 8 | '$uibModalInstance', |
9 | 9 | '$uibModal', |
10 | - function($scope, focaModalDescargasService, $filter, | |
11 | - focaModalService, $timeout, $uibModalInstance, $uibModal) | |
12 | - { | |
10 | + 'remito', | |
11 | + 'focaModalDetalleHojaRutaService', | |
12 | + 'focaSeguimientoService', | |
13 | + function ($scope, focaModalDescargasService, $filter, | |
14 | + focaModalService, $timeout, $uibModalInstance, $uibModal, remito, | |
15 | + focaModalDetalleHojaRutaService, focaSeguimientoService) { | |
13 | 16 | |
14 | 17 | //#region variables |
15 | 18 | $scope.remito = {}; |
16 | - //#endregion | |
19 | + $scope.remito = remito; | |
20 | + $scope.nroRecibo = 0; | |
21 | + $scope.cisternas = remito.cisternas; | |
22 | + $scope.nroRemito = "00" + remito.sucursal + "-000000000" + remito.numeroRemito; | |
17 | 23 | |
18 | - $scope.crearRemito = function() { | |
24 | + console.log(remito); | |
25 | + //#endregion | |
19 | 26 | |
27 | + $scope.crearRemito = function () { | |
28 | + if (!$scope.remito.cliente) { | |
29 | + focaModalService.alert("No has seleccionado cliente"); | |
30 | + return; | |
31 | + } | |
32 | + // if (!validarDescarga()) { | |
33 | + // focaModalService.alert("Cantidad de descarga ingresada erronea"); | |
34 | + // return; | |
35 | + // } | |
36 | + if (!$scope.nroRecibo) { | |
37 | + focaModalService.alert("No ingresaste nro de recibo"); | |
38 | + return; | |
39 | + } | |
40 | + //#region OBJETO REMITO | |
20 | 41 | var remito = { |
21 | - id: $scope.remito.id, | |
22 | - fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | |
23 | - idCliente: $scope.remito.cliente.COD, | |
24 | - nombreCliente: $scope.remito.cliente.NOM, | |
25 | - cuitCliente: $scope.remito.cliente.CUIT, | |
42 | + id: 0, | |
43 | + fechaRemito: new Date().toISOString().slice(0, 19).replace('T', ' '), | |
44 | + idCliente: $scope.remito.cliente.cod, | |
45 | + nombreCliente: $scope.remito.cliente.nom, | |
46 | + cuitCliente: $scope.remito.cliente.cuit, | |
26 | 47 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, |
27 | 48 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
28 | 49 | idVendedor: $scope.remito.vendedor.NUM, |
29 | 50 | idProveedor: $scope.remito.proveedor.COD, |
30 | 51 | idDomicilio: $scope.remito.idDomicilio || $scope.remito.domicilio.id, |
31 | 52 | idCotizacion: $scope.remito.cotizacion.ID, |
32 | - idListaPrecio: $scope.idLista, | |
53 | + idListaPrecio: $scope.remito.cliente.mod, | |
33 | 54 | flete: $scope.remito.flete, |
34 | 55 | fob: $scope.remito.fob, |
35 | 56 | bomba: $scope.remito.bomba, |
... | ... | @@ -38,7 +59,7 @@ angular.module('focaModalDescarga') |
38 | 59 | observaciones: $scope.remito.observaciones, |
39 | 60 | numeroRemito: parseInt($scope.comprobante), |
40 | 61 | sucursal: parseInt($scope.puntoVenta), |
41 | - responsabilidadIvaCliente: $scope.remito.cliente.IVA, | |
62 | + responsabilidadIvaCliente: $scope.remito.cliente.iva, | |
42 | 63 | descuento: 0,//TODO, |
43 | 64 | importeNeto: getImporte('netoUnitario'), |
44 | 65 | importeExento: getImporte('exentoUnitario'), |
... | ... | @@ -62,10 +83,108 @@ angular.module('focaModalDescarga') |
62 | 83 | estado: 0, |
63 | 84 | destinoVenta: 0,//TODO |
64 | 85 | operacionTipo: 0, //TODO |
86 | + idHojaRuta: $scope.remito.idHojaRuta | |
65 | 87 | } |
66 | - } | |
88 | + //#endregionc | |
89 | + focaModalDescargasService.crearRemito({remito: remito, notaPedido: {id:0}}) | |
90 | + .then(function (res) { | |
91 | + console.log(res); | |
92 | + remitoId = res.data.id | |
93 | + descargar(remitoId); | |
94 | + focaModalDescargasService.addArticulos($scope.remito.articulosRemito, remitoId, 1); | |
95 | + focaModalService.alert("Descarga realizada") | |
96 | + .then(function(){ | |
97 | + $uibModalInstance.dismiss(); | |
98 | + }) | |
99 | + }) | |
100 | + .catch(function (e) { console.log(e); }) | |
67 | 101 | |
68 | - $scope.seleccionarCliente = function() { | |
102 | + }; | |
103 | + $scope.getTotal = function () { | |
104 | + var total = 0; | |
105 | + var arrayTempArticulos = $scope.remito.articulosRemito; | |
106 | + for (var i = 0; i < arrayTempArticulos.length; i++) { | |
107 | + total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | |
108 | + } | |
109 | + return parseFloat(total.toFixed(2)); | |
110 | + }; | |
111 | + function descargar(idRemito) { | |
112 | + for (var i = 0; i < $scope.cisternas.length; i++) { | |
113 | + var descarga = $scope.cisternas[i].cisternaCarga.descargar; | |
114 | + var hojaRutaMovimientos = []; | |
115 | + var cisternaMovimientos = []; | |
116 | + var cisternaCargas = []; | |
117 | + var cisternaCarga = $scope.cisternas[i].cisternaCarga; | |
118 | + if (!descarga) continue; | |
119 | + // if (descarga > cisternaCarga.cantidad) { | |
120 | + // focaModalService.alert('La cantidad a descargar no debe ser ' + | |
121 | + // 'mayor a la cantidad de la cisterna'); | |
122 | + // $scope.cargando = false; | |
123 | + // return; | |
124 | + // } | |
125 | + cisternaCarga.cantidad -= descarga; | |
126 | + | |
127 | + //Guardar | |
128 | + var now = new Date(); | |
129 | + var cisternaMovimiento = { | |
130 | + fecha: now.toISOString().slice(0, 19).replace('T', ' '), | |
131 | + cantidad: descarga, | |
132 | + metodo: 'descarga', | |
133 | + idCisternaCarga: cisternaCarga.id, | |
134 | + idRemito: idRemito | |
135 | + }; | |
136 | + var hojaRutaMovimiento = { | |
137 | + reciboDescarga: $scope.nroRecibo, | |
138 | + idRemito: idRemito | |
139 | + }; | |
140 | + delete cisternaCarga.articulo; | |
141 | + delete cisternaCarga.descargar; | |
142 | + cisternaCargas.push(cisternaCarga); | |
143 | + cisternaMovimientos.push(cisternaMovimiento); | |
144 | + hojaRutaMovimientos.push(hojaRutaMovimiento); | |
145 | + } | |
146 | + var save = { | |
147 | + cisternaCargas: cisternaCargas, | |
148 | + cisternaMovimientos: cisternaMovimientos, | |
149 | + hojaRutaMovimientos: hojaRutaMovimientos, | |
150 | + articulo: $scope.articuloSeleccionado | |
151 | + }; | |
152 | + focaModalDetalleHojaRutaService | |
153 | + .postMovimientoHojaRuta(save) | |
154 | + .then(guardarSeguimiento) | |
155 | + .catch(function() {}); | |
156 | + function guardarSeguimiento(res) { | |
157 | + focaSeguimientoService | |
158 | + .guardarPosicion( | |
159 | + 'Entrega de producto', | |
160 | + res.data[0].id, | |
161 | + $scope.remito.observaciones); | |
162 | + $scope.aDescargar = []; | |
163 | + }; | |
164 | + }; | |
165 | + function getImporte(propiedad) { | |
166 | + var importe = 0; | |
167 | + | |
168 | + $scope.remito.articulosRemito.forEach(function (articulo) { | |
169 | + | |
170 | + if (articulo[propiedad]) { | |
171 | + importe += articulo[propiedad] * articulo.cantidad; | |
172 | + } | |
173 | + return; | |
174 | + | |
175 | + }); | |
176 | + | |
177 | + return importe; | |
178 | + }; | |
179 | + function validarDescarga() { | |
180 | + hasDisponible = $scope.cisternas.find(function (cisterna) { | |
181 | + return parseInt(cisterna.cisternaCarga.descargar) > 0 && | |
182 | + parseInt(cisterna.cisternaCarga.descargar) <= | |
183 | + cisterna.cisternaCarga.cantidad | |
184 | + }); | |
185 | + return hasDisponible; | |
186 | + }; | |
187 | + $scope.seleccionarCliente = function () { | |
69 | 188 | |
70 | 189 | var modalInstance = $uibModal.open( |
71 | 190 | { |
... | ... | @@ -79,14 +198,13 @@ angular.module('focaModalDescarga') |
79 | 198 | size: 'lg' |
80 | 199 | } |
81 | 200 | ); |
82 | - modalInstance.result.then(function(cliente) { | |
201 | + modalInstance.result.then(function (cliente) { | |
83 | 202 | $scope.remito.cliente = cliente; |
84 | - }, function() { | |
203 | + }, function () { | |
85 | 204 | //funcion ejecutada al cancelar modal |
86 | 205 | }); |
87 | 206 | }; |
88 | - | |
89 | - $scope.cancelar = function() { | |
207 | + $scope.cancelar = function () { | |
90 | 208 | $uibModalInstance.dismiss(); |
91 | 209 | } |
92 | 210 | } |
src/js/service.js
1 | 1 | angular.module('focaModalDescarga') |
2 | - .factory('focaModalDescargasService', ['$http', 'API_ENDPOINT', function ($http, API_ENDPOINT) { | |
3 | - return { | |
4 | - | |
5 | - }; | |
6 | - }]); | |
2 | + .factory('focaModalDescargasService', ['$http', 'API_ENDPOINT', 'crearRemitoService', | |
3 | + function ($http, API_ENDPOINT, crearRemitoService) { | |
4 | + var route = API_ENDPOINT.URL; | |
5 | + return { | |
6 | + crearRemito: function (remito) { | |
7 | + return $http.post(route + '/remito', remito); | |
8 | + }, | |
9 | + addArticulos: function (articulosRemito, idRemito, cotizacion) { | |
10 | + for (var i = 0; i < articulosRemito.length; i++) { | |
11 | + delete articulosRemito[i].editCantidad; | |
12 | + delete articulosRemito[i].editPrecio; | |
13 | + articulosRemito[i].idRemito = articulosRemito[i].idRemito !== -1 ? | |
14 | + idRemito : articulosRemito[i].idRemito; | |
15 | + articulosRemito[i].precio = articulosRemito[i].precio * cotizacion; | |
16 | + delete articulosRemito[i].idNotaPedido; | |
17 | + crearRemitoService.crearArticulosParaRemito(articulosRemito[i]); | |
18 | + } | |
19 | + } | |
20 | + }; | |
21 | + }]); |
src/views/foca-modal-descarga.html
... | ... | @@ -2,8 +2,8 @@ |
2 | 2 | <h5>Detalle de descarga</h5> |
3 | 3 | </div> |
4 | 4 | <div class="modal-body"> |
5 | - <div class="row"> | |
6 | - <div class="col-3 mt-1 pl-1"> | |
5 | + <div class="row px-1"> | |
6 | + <div class="col-3 align-self-center mt-1 pl-1"> | |
7 | 7 | <strong>Cliente</strong> |
8 | 8 | </div> |
9 | 9 | <div class="col-9"> |
... | ... | @@ -28,25 +28,27 @@ |
28 | 28 | </div> |
29 | 29 | </div> |
30 | 30 | </div> |
31 | - <div class="col-3 pl-1"> | |
31 | + <div class="col-3 align-self-center pl-1 mt-1"> | |
32 | 32 | <strong>Domicilio</strong> |
33 | 33 | </div> |
34 | - <div class="col-9"> | |
35 | - <label ng-bind="remito.cliente.DOM">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Est magni doloribus expedita laudantium veniam ipsum, dicta recusandae natus inventore maiores voluptatum libero, rem obcaecati esse quibusdam quo. Eos, voluptatibus sit.</label> | |
34 | + <div class="col-9 align-self-center mt-1"> | |
35 | + <label ng-bind="remito.cliente.DOM"></label> | |
36 | 36 | </div> |
37 | - <div class="col-3 pl-1"> | |
37 | + <!-- <div class="col-3 pl-1"> | |
38 | 38 | <strong>Punto descarga</strong> |
39 | 39 | </div> |
40 | 40 | <div class="col-9"> |
41 | 41 | <label>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Fugiat facilis commodi dolore aperiam dolor quaerat, sit earum vero iste itaque aspernatur qui nisi id repudiandae error architecto inventore vel temporibus.</label> |
42 | - </div> | |
43 | - <div class="col-3 px-1"> | |
42 | + </div> --> | |
43 | + <div class="col-3 align-self-center px-1 mt-1"> | |
44 | 44 | <strong>Remito Nº</strong> |
45 | 45 | </div> |
46 | - <div class="col-9"> | |
47 | - <input type="text" class="form-control" value="0001-55551111" readonly> | |
46 | + <div class="col-9 mt-1"> | |
47 | + <input | |
48 | + type="text" class="form-control form-control-sm" | |
49 | + ng-model="nroRemito" readonly> | |
48 | 50 | </div> |
49 | - <div class="col-12"> | |
51 | + <div class="col-12 mt-3"> | |
50 | 52 | <table class="table"> |
51 | 53 | <thead> |
52 | 54 | <tr> |
... | ... | @@ -57,22 +59,25 @@ |
57 | 59 | </tr> |
58 | 60 | </thead> |
59 | 61 | <tbody> |
60 | - <tr> | |
61 | - <td>b45</td> | |
62 | - <td>Nafta súper</td> | |
63 | - <td>400</td> | |
62 | + <tr ng-repeat="cisterna in cisternas"> | |
63 | + <td ng-bind="cisterna.codigo"></td> | |
64 | + <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td> | |
65 | + <td ng-bind="cisterna.cisternaCarga.cantidad"></td> | |
64 | 66 | <td> |
65 | - <input type="text" class=" form-control col-12"> | |
67 | + <input | |
68 | + ng-init="cisterna.cisternaCarga.descargar = 0" | |
69 | + ng-model="cisterna.cisternaCarga.descargar" | |
70 | + type="text" class="form-control col-12"> | |
66 | 71 | </td> |
67 | 72 | </tr> |
68 | 73 | </tbody> |
69 | 74 | </table> |
70 | 75 | </div> |
71 | - <div class="col-3 px-1"> | |
76 | + <div class="col-3 align-self-center px-1"> | |
72 | 77 | <strong>Nº Recibo</strong> |
73 | 78 | </div> |
74 | 79 | <div class="col-9"> |
75 | - <input class="form-control" type="text" placeholder="Nº de recibo"> | |
80 | + <input ng-model="nroRecibo" class="form-control" type="text" placeholder="Nº de recibo"> | |
76 | 81 | </div> |
77 | 82 | </div> |
78 | 83 | </div> |
... | ... | @@ -86,7 +91,7 @@ |
86 | 91 | class="btn btn-sm btn-primary" |
87 | 92 | ladda="cargando" |
88 | 93 | type="button" |
89 | - ng-click="aceptar()" | |
94 | + ng-click="crearRemito()" | |
90 | 95 | ng-disabled="tieneArticulosPendientes() || idRemito === -1" |
91 | 96 | foca-focus="!tieneArticulosPendientes() && idRemito !== -1">Descargar</button> |
92 | 97 | </div> |