Commit 9ada384d5cf8f608e0f27a49c1c4b12dcd39c936

Authored by Eric Fernandez
1 parent 3ff3ddf4fe
Exists in master

permite descargar menos de lo indicado

src/js/controller.js
1 angular.module('focaModalDetalleHojaRuta') 1 angular.module('focaModalDetalleHojaRuta')
2 .controller('focaModalDetalleHojaRutaController', 2 .controller('focaModalDetalleHojaRutaController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'idRemito', 7 'idRemito',
8 'focaModalDetalleHojaRutaService', 8 'focaModalDetalleHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaSeguimientoService', 10 'focaSeguimientoService',
11 function($filter, $scope, $uibModalInstance, idRemito, focaModalDetalleHojaRutaService, 11 function($filter, $scope, $uibModalInstance, idRemito, focaModalDetalleHojaRutaService,
12 focaModalService, focaSeguimientoService) 12 focaModalService, focaSeguimientoService)
13 { 13 {
14 //Seteo variables 14 //Seteo variables
15 $scope.remito = {}; 15 $scope.remito = {};
16 $scope.cisternas = []; 16 $scope.cisternas = [];
17 $scope.articuloSeleccionado = {}; 17 $scope.articuloSeleccionado = {};
18 $scope.aDescargar = []; 18 $scope.aDescargar = [];
19 $scope.cargando = true; 19 $scope.cargando = true;
20 20
21 //Datos 21 //Datos
22 var promesaRemito = focaModalDetalleHojaRutaService 22 var promesaRemito = focaModalDetalleHojaRutaService
23 .getRemitoById(idRemito); 23 .getRemitoById(idRemito);
24 var promesaCisternas = focaModalDetalleHojaRutaService 24 var promesaCisternas = focaModalDetalleHojaRutaService
25 .getCisternasByIdRemito(idRemito); 25 .getCisternasByIdRemito(idRemito);
26 26
27 Promise.all([promesaRemito, promesaCisternas]).then(function(res) { 27 Promise.all([promesaRemito, promesaCisternas]).then(function(res) {
28 $scope.cargando = false; 28 $scope.cargando = false;
29 $scope.remito = res[0].data; 29 $scope.remito = res[0].data;
30 $scope.cisternas = res[1].data; 30 $scope.cisternas = res[1].data;
31 var articuloAChequear = $scope.remito.articulosRemito.filter( 31 var articuloAChequear = $scope.remito.articulosRemito.filter(
32 function(articulo) { 32 function(articulo) {
33 return !articulo.descargado; 33 return !articulo.descargado;
34 }); 34 });
35 if(!articuloAChequear.length || $scope.remito.rechazado) { 35 if(!articuloAChequear.length || $scope.remito.rechazado) {
36 $scope.readonly = true; 36 $scope.readonly = true;
37 $scope.cambio($scope.remito.articulosRemito[0]); 37 $scope.cambio($scope.remito.articulosRemito[0]);
38 }else { 38 }else {
39 $scope.cambio(articuloAChequear[0]); 39 $scope.cambio(articuloAChequear[0]);
40 } 40 }
41 $scope.$digest(); 41 $scope.$digest();
42 }, function() { 42 }, function() {
43 focaModalService.alert('El servicio no responde intente más tarde'); 43 focaModalService.alert('El servicio no responde intente más tarde');
44 $uibModalInstance.dismiss(); 44 $uibModalInstance.dismiss();
45 }); 45 });
46 $scope.cambio = function(articulo) { 46 $scope.cambio = function(articulo) {
47 if(!$scope.articuloSeleccionado.descargado) { 47 if(!$scope.articuloSeleccionado.descargado) {
48 $scope.articuloSeleccionado.cantidadDescargada = 0; 48 $scope.articuloSeleccionado.cantidadDescargada = 0;
49 } 49 }
50 $scope.aDescargar = []; 50 $scope.aDescargar = [];
51 $scope.articuloSeleccionado = articulo; 51 $scope.articuloSeleccionado = articulo;
52 }; 52 };
53 $scope.descargar = function(key) { 53 $scope.descargar = function(key) {
54 if(key === 13) { 54 if(key === 13) {
55 $scope.cargando = true; 55 $scope.cargando = true;
56 var hojaRutaMovimientos = []; 56 var hojaRutaMovimientos = [];
57 var cisternaMovimientos = []; 57 var cisternaMovimientos = [];
58 var cisternaCargas = []; 58 var cisternaCargas = [];
59 var totalADescargar = 0; 59 var totalADescargar = 0;
60 for(var i = 0; i < $scope.aDescargar.length; i++) { 60 for(var i = 0; i < $scope.aDescargar.length; i++) {
61 totalADescargar += $scope.aDescargar[i] || 0; 61 totalADescargar += $scope.aDescargar[i] || 0;
62 } 62 }
63 focaModalService 63 focaModalService
64 .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + 64 .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' +
65 $scope.articuloSeleccionado.descripcion + '?') 65 $scope.articuloSeleccionado.descripcion + '?')
66 .then(descargar, function() { 66 .then(descargar, function() {
67 $scope.cargando = false; 67 $scope.cargando = false;
68 }); 68 });
69 } 69 }
70 function descargar() { 70 function descargar() {
71 for(var i = 0; i < $scope.cisternas.length; i++) { 71 for(var i = 0; i < $scope.cisternas.length; i++) {
72 var descarga = $scope.aDescargar[i]; 72 var descarga = $scope.aDescargar[i];
73 var cisternaCarga = $scope.cisternas[i].cisternaCarga; 73 var cisternaCarga = $scope.cisternas[i].cisternaCarga;
74 if(!descarga) continue; 74 if(!descarga) continue;
75 if(descarga > cisternaCarga.cantidad) { 75 if(descarga > cisternaCarga.cantidad) {
76 focaModalService.alert('La cantidad a descargar no debe ser ' + 76 focaModalService.alert('La cantidad a descargar no debe ser ' +
77 'mayor a la cantidad de la cisterna'); 77 'mayor a la cantidad de la cisterna');
78 $scope.cargando = false; 78 $scope.cargando = false;
79 return; 79 return;
80 } 80 }
81 cisternaCarga.cantidad -= descarga; 81 cisternaCarga.cantidad -= descarga;
82 82
83 //Guardar 83 //Guardar
84 var now = new Date(); 84 var now = new Date();
85 var cisternaMovimiento = { 85 var cisternaMovimiento = {
86 fecha: now.toISOString().slice(0, 19).replace('T', ' '), 86 fecha: now.toISOString().slice(0, 19).replace('T', ' '),
87 cantidad: descarga, 87 cantidad: descarga,
88 metodo: 'descarga', 88 metodo: 'descarga',
89 idCisternaCarga: cisternaCarga.id, 89 idCisternaCarga: cisternaCarga.id,
90 idRemito: $scope.remito.id 90 idRemito: $scope.remito.id
91 }; 91 };
92 var hojaRutaMovimiento = { 92 var hojaRutaMovimiento = {
93 reciboDescarga: $scope.numeroRecibo, 93 reciboDescarga: $scope.numeroRecibo,
94 idRemito: $scope.remito.id 94 idRemito: $scope.remito.id
95 }; 95 };
96 delete cisternaCarga.articulo; 96 delete cisternaCarga.articulo;
97 cisternaCargas.push(cisternaCarga); 97 cisternaCargas.push(cisternaCarga);
98 cisternaMovimientos.push(cisternaMovimiento); 98 cisternaMovimientos.push(cisternaMovimiento);
99 hojaRutaMovimientos.push(hojaRutaMovimiento); 99 hojaRutaMovimientos.push(hojaRutaMovimiento);
100 } 100 }
101 var save = { 101 var save = {
102 cisternaCargas: cisternaCargas, 102 cisternaCargas: cisternaCargas,
103 cisternaMovimientos: cisternaMovimientos, 103 cisternaMovimientos: cisternaMovimientos,
104 hojaRutaMovimientos: hojaRutaMovimientos, 104 hojaRutaMovimientos: hojaRutaMovimientos,
105 articulo: $scope.articuloSeleccionado 105 articulo: $scope.articuloSeleccionado
106 }; 106 };
107 focaModalDetalleHojaRutaService 107 focaModalDetalleHojaRutaService
108 .postMovimientoHojaRuta(save) 108 .postMovimientoHojaRuta(save)
109 .then(guardarSeguimiento) 109 .then(guardarSeguimiento)
110 .catch(error); 110 .catch(error);
111 function guardarSeguimiento(res) { 111 function guardarSeguimiento(res) {
112 focaSeguimientoService 112 focaSeguimientoService
113 .guardarPosicion( 113 .guardarPosicion(
114 'Entrega de producto', 114 'Entrega de producto',
115 res.data[0].id, 115 res.data[0].id,
116 $scope.remito.observaciones); 116 $scope.remito.observaciones);
117 $scope.aDescargar = []; 117 $scope.aDescargar = [];
118 $scope.remito.observaciones = ''; 118 $scope.remito.observaciones = '';
119 $scope.articuloSeleccionado.descargado = true; 119 $scope.articuloSeleccionado.descargado = true;
120 var siguienteArticulo = $scope.remito.articulosRemito.filter( 120 var siguienteArticulo = $scope.remito.articulosRemito.filter(
121 function(articulo) { 121 function(articulo) {
122 return articulo.id != $scope.articuloSeleccionado.id; 122 return articulo.id != $scope.articuloSeleccionado.id;
123 } 123 }
124 ); 124 );
125 if(siguienteArticulo.length) { 125 if(siguienteArticulo.length) {
126 $scope.cambio(siguienteArticulo[0]); 126 $scope.cambio(siguienteArticulo[0]);
127 } 127 }
128 success(); 128 success();
129 } 129 }
130 } 130 }
131 }; 131 };
132 132
133 $scope.cancel = function() { 133 $scope.cancel = function() {
134 $uibModalInstance.dismiss('cancel'); 134 $uibModalInstance.dismiss('cancel');
135 }; 135 };
136 136
137 $scope.distribucionDisponible = function() { 137 $scope.distribucionDisponible = function() {
138 return $scope.articuloSeleccionado.cantidadDescargada === 138 return $scope.articuloSeleccionado.cantidadDescargada &&
139 $scope.articuloSeleccionado.cantidadDescargada <=
139 $scope.articuloSeleccionado.cantidad; 140 $scope.articuloSeleccionado.cantidad;
140 }; 141 };
141 142
142 $scope.actualizarArticulo = function() { 143 $scope.actualizarArticulo = function() {
143 $scope.articuloSeleccionado.cantidadDescargada = 0; 144 $scope.articuloSeleccionado.cantidadDescargada = 0;
144 for(var i = 0; i < $scope.aDescargar.length; i++) { 145 for(var i = 0; i < $scope.aDescargar.length; i++) {
145 $scope.articuloSeleccionado.cantidadDescargada += 146 $scope.articuloSeleccionado.cantidadDescargada +=
146 parseFloat($scope.aDescargar[i]) || 0; 147 parseFloat($scope.aDescargar[i]) || 0;
147 } 148 }
148 }; 149 };
149 150
150 $scope.rechazar = function() { 151 $scope.rechazar = function() {
151 focaModalService 152 focaModalService
152 .prompt('Aclare el motivo de rechazo') 153 .prompt('Aclare el motivo de rechazo')
153 .then(function(motivo) { 154 .then(function(motivo) {
154 $scope.cargando = true; 155 $scope.cargando = true;
155 var remitoRechazado = $.extend(true, {}, $scope.remito); 156 var remitoRechazado = $.extend(true, {}, $scope.remito);
156 delete remitoRechazado.articulosRemito; 157 delete remitoRechazado.articulosRemito;
157 delete remitoRechazado.notaPedido; 158 delete remitoRechazado.notaPedido;
158 remitoRechazado.rechazado = true; 159 remitoRechazado.rechazado = true;
159 remitoRechazado.motivoRechazo = motivo; 160 remitoRechazado.motivoRechazo = motivo;
160 remitoRechazado.fechaRemito = 161 remitoRechazado.fechaRemito =
161 remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' '); 162 remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' ');
162 focaModalDetalleHojaRutaService 163 focaModalDetalleHojaRutaService
163 .rechazarRemito(remitoRechazado) 164 .rechazarRemito(remitoRechazado)
164 .then(success) 165 .then(success)
165 .catch(error) 166 .catch(error)
166 $scope.readonly = true; 167 $scope.readonly = true;
167 }); 168 });
168 }; 169 };
169 170
170 //funciones 171 //funciones
171 function error(error) { 172 function error(error) {
172 focaModalService.alert('Hubo un error ' + error); 173 focaModalService.alert('Hubo un error ' + error);
173 } 174 }
174 function success() { 175 function success() {
175 focaModalService.alert('Operación realizada con éxito'); 176 focaModalService.alert('Operación realizada con éxito');
176 $scope.cargando = false; 177 $scope.cargando = false;
177 } 178 }
178 } 179 }
179 ] 180 ]
180 ); 181 );
181 182
src/views/modal-detalle-hoja-ruta.html
1 <div class="modal-header py-1"> 1 <div class="modal-header py-1">
2 <h5 class="modal-title">Detalle de descarga</h5> 2 <h5 class="modal-title">Detalle de descarga</h5>
3 </div> 3 </div>
4 <div class="modal-body" id="modal-body" ladda="cargando" data-spinner-color="#FF0000" data-spinner-size="5"> 4 <div class="modal-body" id="modal-body" ladda="cargando" data-spinner-color="#FF0000" data-spinner-size="5">
5 <form name="formDetalleHojaRuta"> 5 <form name="formDetalleHojaRuta">
6 <div class="form-group row" ng-show="!cargando"> 6 <div class="form-group row" ng-show="!cargando">
7 <div class="col-12 px-0"> 7 <div class="col-12 px-0">
8 <strong>Información Remito</strong> 8 <strong>Información Remito</strong>
9 <button 9 <button
10 class="btn btn-sm btn-light selectable" 10 class="btn btn-sm btn-light selectable"
11 ng-click="verInformacion = !verInformacion" 11 ng-click="verInformacion = !verInformacion"
12 ><i 12 ><i
13 class="fa fa-chevron-up" 13 class="fa fa-chevron-up"
14 ng-show="verInformacion"></i> 14 ng-show="verInformacion"></i>
15 <i 15 <i
16 class="fa fa-chevron-down" 16 class="fa fa-chevron-down"
17 ng-hide="verInformacion"> 17 ng-hide="verInformacion">
18 </i> 18 </i>
19 </button> 19 </button>
20 </div> 20 </div>
21 <div class="row" ng-show="verInformacion"> 21 <div class="row" ng-show="verInformacion">
22 <div class="col-12"> 22 <div class="col-12">
23 <label class="form-control-sm"> 23 <label class="form-control-sm">
24 <b>Remito Nº</b> 24 <b>Remito Nº</b>
25 <span ng-bind="[remito.numeroRemito, remito.sucursal] | comprobante"/> 25 <span ng-bind="[remito.numeroRemito, remito.sucursal] | comprobante"/>
26 </label> 26 </label>
27 </div> 27 </div>
28 <div class="col-12"> 28 <div class="col-12">
29 <label class="form-control-sm"> 29 <label class="form-control-sm">
30 <b>Cliente</b> 30 <b>Cliente</b>
31 </label> 31 </label>
32 <span ng-bind="remito.nombreCliente"/> 32 <span ng-bind="remito.nombreCliente"/>
33 </div> 33 </div>
34 <div class="col-12"> 34 <div class="col-12">
35 <label class="form-control-sm"> 35 <label class="form-control-sm">
36 <b>Domicilio</b> 36 <b>Domicilio</b>
37 <span ng-bind="remito.domicilioStamp"/> 37 <span ng-bind="remito.domicilioStamp"/>
38 </label> 38 </label>
39 </div> 39 </div>
40 <div ng-show="remito.notaPedido.notaPedidoPuntoDescarga.length" class="px-3"> 40 <div ng-show="remito.notaPedido.notaPedidoPuntoDescarga.length" class="px-3">
41 <label class="form-control-sm"> 41 <label class="form-control-sm">
42 <b>Puntos de descarga</b> 42 <b>Puntos de descarga</b>
43 </label> 43 </label>
44 <table class="table table-sm"> 44 <table class="table table-sm">
45 <thead> 45 <thead>
46 <tr> 46 <tr>
47 <th>Nombre</th> 47 <th>Nombre</th>
48 <th>Articulo</th> 48 <th>Articulo</th>
49 <th>Cantidad</th> 49 <th>Cantidad</th>
50 </tr> 50 </tr>
51 </thead> 51 </thead>
52 <tbody> 52 <tbody>
53 <tr ng-repeat="(key, puntoDescarga) in remito.notaPedido.notaPedidoPuntoDescarga"> 53 <tr ng-repeat="(key, puntoDescarga) in remito.notaPedido.notaPedidoPuntoDescarga">
54 <td ng-bind="puntoDescarga.puntoDescarga.descripcion"></td> 54 <td ng-bind="puntoDescarga.puntoDescarga.descripcion"></td>
55 <td ng-bind="puntoDescarga.producto.DetArt"></td> 55 <td ng-bind="puntoDescarga.producto.DetArt"></td>
56 <td ng-bind="puntoDescarga.cantidad"></td> 56 <td ng-bind="puntoDescarga.cantidad"></td>
57 </tbody> 57 </tbody>
58 </table> 58 </table>
59 </div> 59 </div>
60 </div> 60 </div>
61 <strong>Articulo a descargar</strong> 61 <strong>Articulo a descargar</strong>
62 <table class="table table-sm"> 62 <table class="table table-sm">
63 <thead> 63 <thead>
64 <tr> 64 <tr>
65 <th></th> 65 <th></th>
66 <th>Articulo</th> 66 <th>Articulo</th>
67 <th>Total</th> 67 <th>Total</th>
68 <th>Descargado</th> 68 <th>Descargado</th>
69 </tr> 69 </tr>
70 </thead> 70 </thead>
71 <tbody> 71 <tbody>
72 <tr ng-repeat="(key, articulo) in remito.articulosRemito"> 72 <tr ng-repeat="(key, articulo) in remito.articulosRemito">
73 <td class="pt-2"> 73 <td class="pt-2">
74 <input 74 <input
75 type="radio" 75 type="radio"
76 name="articuloRadio" 76 name="articuloRadio"
77 id="{{'articulo' + articulo.id}}" 77 id="{{'articulo' + articulo.id}}"
78 ng-click="cambio(articulo)" 78 ng-click="cambio(articulo)"
79 ng-disabled="articulo.descargado || readonly" 79 ng-disabled="articulo.descargado || readonly"
80 ng-checked="articuloSeleccionado.id === articulo.id" 80 ng-checked="articuloSeleccionado.id === articulo.id"
81 ></td> 81 ></td>
82 <td ng-bind="articulo.descripcion"></td> 82 <td ng-bind="articulo.descripcion"></td>
83 <td ng-bind="articulo.cantidad"></td> 83 <td ng-bind="articulo.cantidad"></td>
84 <td ng-bind="articulo.cantidadDescargada || 0"></td> 84 <td ng-bind="articulo.cantidadDescargada || 0"></td>
85 </tbody> 85 </tbody>
86 </table> 86 </table>
87 <strong>Cisterna</strong> 87 <strong>Cisterna</strong>
88 <table class="table table-sm"> 88 <table class="table table-sm">
89 <thead> 89 <thead>
90 <tr> 90 <tr>
91 <th>Código</th> 91 <th>Código</th>
92 <th>Articulo</th> 92 <th>Articulo</th>
93 <th>Total</th> 93 <th>Total</th>
94 <th>A descargar</th> 94 <th>A descargar</th>
95 </tr> 95 </tr>
96 </thead> 96 </thead>
97 <tbody> 97 <tbody>
98 <tr ng-repeat="(key, cisterna) in cisternas"> 98 <tr ng-repeat="(key, cisterna) in cisternas">
99 <td ng-bind="cisterna.codigo"></td> 99 <td ng-bind="cisterna.codigo"></td>
100 <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td> 100 <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td>
101 <td ng-bind="cisterna.cisternaCarga.cantidad"></td> 101 <td ng-bind="cisterna.cisternaCarga.cantidad"></td>
102 <td><input 102 <td><input
103 class="form-control form-control-sm" 103 class="form-control form-control-sm"
104 type="number" 104 type="number"
105 ng-model="aDescargar[key]" 105 ng-model="aDescargar[key]"
106 ng-change="actualizarArticulo()" 106 ng-change="actualizarArticulo()"
107 foca-focus="articuloSeleccionado.idArticulo == cisterna.cisternaCarga.idProducto" 107 foca-focus="articuloSeleccionado.idArticulo == cisterna.cisternaCarga.idProducto"
108 ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto 108 ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto
109 || readonly"/></td> 109 || readonly"/></td>
110 </tr> 110 </tr>
111 </tbody> 111 </tbody>
112 </table> 112 </table>
113 <div class="col-12 px-0"> 113 <div class="col-12 px-0">
114 <label class="form-control-sm px-0"> 114 <label class="form-control-sm px-0">
115 <b>Observaciones</b> 115 <b>Observaciones</b>
116 </label> 116 </label>
117 </div> 117 </div>
118 <div class="col-12"> 118 <div class="col-12">
119 <textarea 119 <textarea
120 ng-model="remito.observaciones" 120 ng-model="remito.observaciones"
121 ng-disabled="readonly" 121 ng-disabled="readonly"
122 class="form-control form-control-sm" 122 class="form-control form-control-sm"
123 rows="1" 123 rows="1"
124 ></textarea> 124 ></textarea>
125 </div> 125 </div>
126 <div class="col-12 row mt-2"> 126 <div class="col-12 row mt-2">
127 <label class="form-control-sm px-0 col-3"><b>Nº Recibo</b></label> 127 <label class="form-control-sm px-0 col-3"><b>Nº Recibo</b></label>
128 <input 128 <input
129 class="form-control form-control-sm col-4" 129 class="form-control form-control-sm col-4"
130 type="number" 130 type="number"
131 ng-disabled="readonly" 131 ng-disabled="readonly"
132 ng-model="numeroRecibo" 132 ng-model="numeroRecibo"
133 ng-keypress="descargar($event.keyCode)" 133 ng-keypress="descargar($event.keyCode)"
134 foca-focus="distribucionDisponible()"> 134 foca-focus="articuloSeleccionado.cantidadDescargada === articuloSeleccionado.cantidad">
135 <button 135 <button
136 class="ml-4 form-control-sm btn btn-success col-4" 136 class="ml-4 form-control-sm btn btn-success col-4"
137 ladda="cargando" 137 ladda="cargando"
138 data-spinner-color="#FF0000" 138 data-spinner-color="#FF0000"
139 type="button" 139 type="button"
140 ng-disabled="!distribucionDisponible() || !numeroRecibo" 140 ng-disabled="!distribucionDisponible() || !numeroRecibo"
141 ng-click="descargar(13)"> 141 ng-click="descargar(13)">
142 Descargar 142 Descargar
143 </button> 143 </button>
144 </div> 144 </div>
145 </form> 145 </form>
146 </div> 146 </div>
147 <div class="modal-footer py-2"> 147 <div class="modal-footer py-2">
148 <button 148 <button
149 class="btn btn-danger btn-sm" 149 class="btn btn-danger btn-sm"
150 type="button" 150 type="button"
151 ng-click="rechazar()" 151 ng-click="rechazar()"
152 ng-disabled="readonly" 152 ng-disabled="readonly"
153 >Rechazar</button> 153 >Rechazar</button>
154 <button 154 <button
155 class="btn btn-secondary btn-sm" 155 class="btn btn-secondary btn-sm"
156 type="button" 156 type="button"
157 ng-click="cancel()" 157 ng-click="cancel()"
158 >Salir</button> 158 >Salir</button>
159 </div> 159 </div>
160 160