Commit 7888b4110a7204287717eca6d9acd27fd9bcc20d

Authored by Eric Fernandez
1 parent b7ba244196
Exists in master

validaciones, rechazo remito

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 $scope.cambio($scope.remito.articulosRemito[0]); 31 var articuloAChequear = $scope.remito.articulosRemito.filter(
32 function(articulo) {
33 return !articulo.descargado;
34 });
35 if(!articuloAChequear.length || $scope.remito.rechazado) {
36 $scope.readonly = true;
37 $scope.cambio($scope.remito.articulosRemito[0]);
38 }else {
39 $scope.cambio(articuloAChequear[0]);
40 }
32 $scope.$digest(); 41 $scope.$digest();
33 }, function() { 42 }, function() {
34 focaModalService.alert('El servicio no responde intente más tarde'); 43 focaModalService.alert('El servicio no responde intente más tarde');
35 $uibModalInstance.dismiss(); 44 $uibModalInstance.dismiss();
36 }); 45 });
37 $scope.cambio = function(articulo) { 46 $scope.cambio = function(articulo) {
47 if(!$scope.articuloSeleccionado.descargado) {
48 $scope.articuloSeleccionado.cantidadDescargada = 0;
49 }
38 $scope.aDescargar = []; 50 $scope.aDescargar = [];
39 $scope.articuloSeleccionado = articulo; 51 $scope.articuloSeleccionado = articulo;
40 }; 52 };
41 $scope.descargar = function(key) { 53 $scope.descargar = function(key) {
42 var hojaRutaMovimientos = [];
43 var cisternaMovimientos = [];
44 var cisternaCargas = [];
45 var totalADescargar = 0;
46 for (var i = 0; i < $scope.aDescargar.length; i++) {
47 totalADescargar += $scope.aDescargar[i] || 0;
48 }
49 if(key === 13) { 54 if(key === 13) {
55 $scope.cargando = true;
56 var hojaRutaMovimientos = [];
57 var cisternaMovimientos = [];
58 var cisternaCargas = [];
59 var totalADescargar = 0;
60 for(var i = 0; i < $scope.aDescargar.length; i++) {
61 totalADescargar += $scope.aDescargar[i] || 0;
62 }
50 focaModalService 63 focaModalService
51 .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + 64 .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' +
52 $scope.articuloSeleccionado.descripcion + '?') 65 $scope.articuloSeleccionado.descripcion + '?')
53 .then(descargar); 66 .then(descargar);
54 } 67 }
55 function descargar() { 68 function descargar() {
56 for (var i = 0; i < $scope.cisternas.length; i++) { 69 for(var i = 0; i < $scope.cisternas.length; i++) {
57 var descarga = $scope.aDescargar[i]; 70 var descarga = $scope.aDescargar[i];
58 if(!descarga) continue;
59 var cisternaCarga = $scope.cisternas[i].cisternaCarga; 71 var cisternaCarga = $scope.cisternas[i].cisternaCarga;
72 if(!descarga) continue;
73 if(descarga > cisternaCarga.cantidad) {
74 focaModalService.alert('La cantidad a descargar no debe ser ' +
75 'mayor a la cantidad de la cisterna');
76 $scope.cargando = false;
77 return;
78 }
60 cisternaCarga.cantidad -= descarga; 79 cisternaCarga.cantidad -= descarga;
61 80
62 //Guardar 81 //Guardar
63 var now = new Date(); 82 var now = new Date();
64 var cisternaMovimiento = { 83 var cisternaMovimiento = {
65 fecha: now.toISOString().slice(0, 19).replace('T', ' '), 84 fecha: now.toISOString().slice(0, 19).replace('T', ' '),
66 cantidad: descarga, 85 cantidad: descarga,
67 metodo: 'descarga', 86 metodo: 'descarga',
68 idCisternaCarga: cisternaCarga.id, 87 idCisternaCarga: cisternaCarga.id,
69 idRemito: $scope.remito.id 88 idRemito: $scope.remito.id
70 }; 89 };
71 var hojaRutaMovimiento = { 90 var hojaRutaMovimiento = {
72 reciboDescarga: $scope.numeroRecibo, 91 reciboDescarga: $scope.numeroRecibo,
73 idRemito: $scope.remito.id 92 idRemito: $scope.remito.id
74 }; 93 };
75 delete cisternaCarga.articulo; 94 delete cisternaCarga.articulo;
76 cisternaCargas.push(cisternaCarga); 95 cisternaCargas.push(cisternaCarga);
77 cisternaMovimientos.push(cisternaMovimiento); 96 cisternaMovimientos.push(cisternaMovimiento);
78 hojaRutaMovimientos.push(hojaRutaMovimiento); 97 hojaRutaMovimientos.push(hojaRutaMovimiento);
79 } 98 }
80 var save = { 99 var save = {
81 cisternaCargas: cisternaCargas, 100 cisternaCargas: cisternaCargas,
82 cisternaMovimientos: cisternaMovimientos, 101 cisternaMovimientos: cisternaMovimientos,
83 hojaRutaMovimientos: hojaRutaMovimientos 102 hojaRutaMovimientos: hojaRutaMovimientos,
103 articulo: $scope.articuloSeleccionado
84 }; 104 };
85 focaModalDetalleHojaRutaService 105 focaModalDetalleHojaRutaService
86 .postMovimientoHojaRuta(save) 106 .postMovimientoHojaRuta(save)
87 .then(guardarSeguimiento) 107 .then(guardarSeguimiento)
88 .catch(error); 108 .catch(error);
89 function guardarSeguimiento(res) { 109 function guardarSeguimiento(res) {
90 focaSeguimientoService 110 focaSeguimientoService
91 .guardarPosicion( 111 .guardarPosicion(
92 'Entrega de producto', 112 'Entrega de producto',
93 res.data[0].id, 113 res.data[0].id,
94 $scope.remito.observaciones); 114 $scope.remito.observaciones);
95 $scope.aDescargar = []; 115 $scope.aDescargar = [];
96 $scope.remito.observaciones = ''; 116 $scope.remito.observaciones = '';
117 $scope.articuloSeleccionado.descargado = true;
118 var siguienteArticulo = $scope.remito.articulosRemito.filter(
119 function(articulo) {
120 return articulo.id != $scope.articuloSeleccionado.id;
121 }
122 );
123 if(siguienteArticulo.length) {
124 $scope.cambio(siguienteArticulo[0]);
125 }
97 success(); 126 success();
98 } 127 }
99 } 128 }
100 }; 129 };
101 130
102 $scope.cancel = function() { 131 $scope.cancel = function() {
103 $uibModalInstance.dismiss('cancel'); 132 $uibModalInstance.dismiss('cancel');
104 }; 133 };
105 134
106 $scope.distribucionDisponible = function() { 135 $scope.distribucionDisponible = function() {
107 return $scope.articuloSeleccionado.cantidadDescargada === 136 return $scope.articuloSeleccionado.cantidadDescargada ===
108 $scope.articuloSeleccionado.cantidad; 137 $scope.articuloSeleccionado.cantidad;
109 }; 138 };
110 139
111 $scope.actualizarArticulo = function() { 140 $scope.actualizarArticulo = function() {
112 $scope.articuloSeleccionado.cantidadDescargada = 0; 141 $scope.articuloSeleccionado.cantidadDescargada = 0;
113 for(var i = 0; i < $scope.aDescargar.length; i++) { 142 for(var i = 0; i < $scope.aDescargar.length; i++) {
114 $scope.articuloSeleccionado.cantidadDescargada += 143 $scope.articuloSeleccionado.cantidadDescargada +=
115 parseFloat($scope.aDescargar[i]) || 0; 144 parseFloat($scope.aDescargar[i]) || 0;
116 } 145 }
117 }; 146 };
118 147
119 $scope.rechazar = function() { 148 $scope.rechazar = function() {
120 focaModalService 149 focaModalService
121 .prompt('Aclare el motivo de rechazo') 150 .prompt('Aclare el motivo de rechazo')
122 .then(function() { 151 .then(function(motivo) {
123 focaModalService.alert('desarrollo'); 152 $scope.cargando = true;
124 $uibModalInstance.dismiss(); 153 var remitoRechazado = $.extend(true, {}, $scope.remito);
154 delete remitoRechazado.articulosRemito;
155 delete remitoRechazado.notaPedido;
156 remitoRechazado.rechazado = true;
157 remitoRechazado.motivoRechazo = motivo;
158 remitoRechazado.fechaRemito =
159 remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' ');
160 focaModalDetalleHojaRutaService
161 .rechazarRemito(remitoRechazado)
162 .then(success)
163 .catch(error)
164 $scope.readonly = true;
125 }); 165 });
126 }; 166 };
127 167
128 //funciones 168 //funciones
129 function error(error) { 169 function error(error) {
130 focaModalService.alert('Hubo un error ' + error); 170 focaModalService.alert('Hubo un error ' + error);
131 } 171 }
1 angular.module('focaModalDetalleHojaRuta') 1 angular.module('focaModalDetalleHojaRuta')
2 .service('focaModalDetalleHojaRutaService', [ 2 .service('focaModalDetalleHojaRutaService', [
3 '$http', 3 '$http',
4 'API_ENDPOINT', 4 'API_ENDPOINT',
5 function($http, API_ENDPOINT) { 5 function($http, API_ENDPOINT) {
6 return { 6 return {
7 getDetallesHojaRuta: function() { 7 getDetallesHojaRuta: function() {
8 return $http.get(API_ENDPOINT.URL + '/transportista'); 8 return $http.get(API_ENDPOINT.URL + '/transportista');
9 }, 9 },
10 getCisternasByIdRemito: function(idRemito) { 10 getCisternasByIdRemito: function(idRemito) {
11 return $http.get(API_ENDPOINT.URL + '/cisternas/obtener/remito/' + idRemito); 11 return $http.get(API_ENDPOINT.URL + '/cisternas/obtener/remito/' + idRemito);
12 }, 12 },
13 getRemitoById: function(idRemito) { 13 getRemitoById: function(idRemito) {
14 return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito + '/punto'); 14 return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito + '/punto');
15 }, 15 },
16 postMovimientoHojaRuta: function(datos) { 16 postMovimientoHojaRuta: function(datos) {
17 return $http.post(API_ENDPOINT.URL + '/hoja-ruta/movimiento', datos); 17 return $http.post(API_ENDPOINT.URL + '/hoja-ruta/movimiento', datos);
18 },
19 rechazarRemito: function(remito) {
20 return $http.post(API_ENDPOINT.URL + '/remito/update', {remito: remito});
18 } 21 }
19 }; 22 };
20 } 23 }
21 ]); 24 ]);
22 25
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-outline-light selectable" 10 class="btn btn-sm btn-outline-light selectable"
11 ng-click="verInformacion = !verInformacion" 11 ng-click="verInformacion = !verInformacion"
12 ><i 12 ><i
13 class="fa fa-chevron-down" 13 class="fa fa-chevron-down"
14 ng-show="verInformacion"></i> 14 ng-show="verInformacion"></i>
15 <i 15 <i
16 class="fa fa-chevron-up" 16 class="fa fa-chevron-up"
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.cargado" 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.cantidad - articulo.cantidadDescargada"></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"/></td> 108 ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto
109 || readonly"/></td>
109 </tr> 110 </tr>
110 </tbody> 111 </tbody>
111 </table> 112 </table>
112 <div class="col-12 px-0"> 113 <div class="col-12 px-0">
113 <label class="form-control-sm px-0"> 114 <label class="form-control-sm px-0">
114 <b>Observaciones</b> 115 <b>Observaciones</b>
115 </label> 116 </label>
116 </div> 117 </div>
117 <div class="col-12"> 118 <div class="col-12">
118 <textarea 119 <textarea
119 ng-model="remito.observaciones" 120 ng-model="remito.observaciones"
121 ng-disabled="readonly"
120 class="form-control form-control-sm" 122 class="form-control form-control-sm"
121 rows="1" 123 rows="1"
122 ></textarea> 124 ></textarea>
123 </div> 125 </div>
124 <div class="col-12 row mt-2"> 126 <div class="col-12 row mt-2">
125 <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>
126 <input 128 <input
127 class="form-control form-control-sm col-4" 129 class="form-control form-control-sm col-4"
128 type="number" 130 type="number"
131 ng-disabled="readonly"
129 ng-model="numeroRecibo" 132 ng-model="numeroRecibo"
130 ng-keypress="descargar($event.keyCode)" 133 ng-keypress="descargar($event.keyCode)"
131 foca-focus="distribucionDisponible()"> 134 foca-focus="distribucionDisponible()">
132 <button 135 <button
133 class="ml-4 form-control-sm btn btn-success col-4" 136 class="ml-4 form-control-sm btn btn-success col-4"
134 ladda="cargando" 137 ladda="cargando"
135 data-spinner-color="#FF0000" 138 data-spinner-color="#FF0000"
136 type="button" 139 type="button"
137 ng-disabled="!distribucionDisponible() || !numeroRecibo" 140 ng-disabled="!distribucionDisponible() || !numeroRecibo"
138 ng-click="descargar(13)"> 141 ng-click="descargar(13)">
139 Descargar 142 Descargar
140 </button> 143 </button>
141 </div> 144 </div>
142 </form> 145 </form>
143 </div> 146 </div>
144 <div class="modal-footer py-2"> 147 <div class="modal-footer py-2">
145 <button 148 <button
146 class="btn btn-danger btn-sm" 149 class="btn btn-danger btn-sm"
147 type="button" 150 type="button"
148 ng-click="rechazar()" 151 ng-click="rechazar()"
149 ng-disabled="" 152 ng-disabled="readonly"
150 >Rechazar</button> 153 >Rechazar</button>
151 <button 154 <button
152 class="btn btn-secondary btn-sm" 155 class="btn btn-secondary btn-sm"
153 type="button" 156 type="button"
154 ng-click="cancel()" 157 ng-click="cancel()"
155 >Salir</button> 158 >Salir</button>
156 </div> 159 </div>
157 160