Commit f776fcedbfb8e8b2ae3898f13247109c750241bd
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !4
Showing
3 changed files
Show diff stats
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 | 'remito', | 7 | 'idRemito', |
| 8 | 'focaModalDetalleHojaRutaService', | 8 | 'focaModalDetalleHojaRutaService', |
| 9 | function($filter, $scope, $uibModalInstance, remito, focaModalDetalleHojaRutaService) { | 9 | 'focaModalService', |
| 10 | $scope.remito = remito; | 10 | 'focaSeguimientoService', |
| 11 | function($filter, $scope, $uibModalInstance, idRemito, focaModalDetalleHojaRutaService, | ||
| 12 | focaModalService, focaSeguimientoService) | ||
| 13 | { | ||
| 14 | //Seteo variables | ||
| 15 | $scope.remito = {}; | ||
| 11 | $scope.cisternas = []; | 16 | $scope.cisternas = []; |
| 12 | $scope.articuloSeleccionado = {}; | 17 | $scope.articuloSeleccionado = {}; |
| 18 | $scope.aDescargar = []; | ||
| 19 | $scope.cargando = true; | ||
| 20 | |||
| 21 | //Datos | ||
| 22 | var promesaRemito = focaModalDetalleHojaRutaService | ||
| 23 | .getRemitoById(idRemito); | ||
| 24 | var promesaCisternas = focaModalDetalleHojaRutaService | ||
| 25 | .getCisternasByIdRemito(idRemito); | ||
| 26 | |||
| 27 | Promise.all([promesaRemito, promesaCisternas]).then(function(res) { | ||
| 28 | $scope.cargando = false; | ||
| 29 | $scope.remito = res[0].data; | ||
| 30 | $scope.cisternas = res[1].data; | ||
| 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 | } | ||
| 41 | $scope.$digest(); | ||
| 42 | }, function() { | ||
| 43 | focaModalService.alert('El servicio no responde intente más tarde'); | ||
| 44 | $uibModalInstance.dismiss(); | ||
| 45 | }); | ||
| 13 | $scope.cambio = function(articulo) { | 46 | $scope.cambio = function(articulo) { |
| 47 | if(!$scope.articuloSeleccionado.descargado) { | ||
| 48 | $scope.articuloSeleccionado.cantidadDescargada = 0; | ||
| 49 | } | ||
| 50 | $scope.aDescargar = []; | ||
| 14 | $scope.articuloSeleccionado = articulo; | 51 | $scope.articuloSeleccionado = articulo; |
| 15 | }; | 52 | }; |
| 16 | focaModalDetalleHojaRutaService.getCisternasByIdRemito($scope.remito.id) | 53 | $scope.descargar = function(key) { |
| 17 | .then(function(res) { | 54 | if(key === 13) { |
| 18 | $scope.cisternas = res.data; | 55 | $scope.cargando = true; |
| 19 | }); | 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 | } | ||
| 63 | focaModalService | ||
| 64 | .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + | ||
| 65 | $scope.articuloSeleccionado.descripcion + '?') | ||
| 66 | .then(descargar); | ||
| 67 | } | ||
| 68 | function descargar() { | ||
| 69 | for(var i = 0; i < $scope.cisternas.length; i++) { | ||
| 70 | var descarga = $scope.aDescargar[i]; | ||
| 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 | } | ||
| 79 | cisternaCarga.cantidad -= descarga; | ||
| 20 | 80 | ||
| 21 | $scope.aceptar = function() { | 81 | //Guardar |
| 22 | var articulos = articulosDescargados(); | 82 | var now = new Date(); |
| 23 | var cisternaMovimientos = []; | 83 | var cisternaMovimiento = { |
| 24 | var hojaRutaMovimientos = []; | 84 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
| 25 | for(var i = 0; i < articulos.length; i++) { | 85 | cantidad: descarga, |
| 26 | var cisternaMovimiento = { | 86 | metodo: 'descarga', |
| 27 | idRemito: $scope.remito.id, | 87 | idCisternaCarga: cisternaCarga.id, |
| 28 | cantidad: articulos[i].aCargar, | 88 | idRemito: $scope.remito.id |
| 29 | metodo: 'descarga' | 89 | }; |
| 30 | }; | 90 | var hojaRutaMovimiento = { |
| 31 | var hojaRutaMovimiento = { | 91 | reciboDescarga: $scope.numeroRecibo, |
| 32 | idRemito: $scope.remito.id, | 92 | idRemito: $scope.remito.id |
| 33 | reciboDescarga: articulos[i].numeroRecibo | 93 | }; |
| 94 | delete cisternaCarga.articulo; | ||
| 95 | cisternaCargas.push(cisternaCarga); | ||
| 96 | cisternaMovimientos.push(cisternaMovimiento); | ||
| 97 | hojaRutaMovimientos.push(hojaRutaMovimiento); | ||
| 98 | } | ||
| 99 | var save = { | ||
| 100 | cisternaCargas: cisternaCargas, | ||
| 101 | cisternaMovimientos: cisternaMovimientos, | ||
| 102 | hojaRutaMovimientos: hojaRutaMovimientos, | ||
| 103 | articulo: $scope.articuloSeleccionado | ||
| 34 | }; | 104 | }; |
| 35 | cisternaMovimientos.push(cisternaMovimiento); | 105 | focaModalDetalleHojaRutaService |
| 36 | hojaRutaMovimientos.push(hojaRutaMovimiento); | 106 | .postMovimientoHojaRuta(save) |
| 107 | .then(guardarSeguimiento) | ||
| 108 | .catch(error); | ||
| 109 | function guardarSeguimiento(res) { | ||
| 110 | focaSeguimientoService | ||
| 111 | .guardarPosicion( | ||
| 112 | 'Entrega de producto', | ||
| 113 | res.data[0].id, | ||
| 114 | $scope.remito.observaciones); | ||
| 115 | $scope.aDescargar = []; | ||
| 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 | } | ||
| 126 | success(); | ||
| 127 | } | ||
| 37 | } | 128 | } |
| 38 | var result = { | ||
| 39 | cisternaMovimientos: cisternaMovimientos, | ||
| 40 | hojaRutaMovimientos: hojaRutaMovimientos, | ||
| 41 | idRemito: $scope.remito.id, | ||
| 42 | observaciones: $scope.remito.observaciones | ||
| 43 | }; | ||
| 44 | $uibModalInstance.close(result); | ||
| 45 | }; | 129 | }; |
| 46 | 130 | ||
| 47 | $scope.cancel = function() { | 131 | $scope.cancel = function() { |
| 48 | $uibModalInstance.dismiss('cancel'); | 132 | $uibModalInstance.dismiss('cancel'); |
| 49 | }; | 133 | }; |
| 50 | 134 | ||
| 51 | $scope.validar = function() { | 135 | $scope.distribucionDisponible = function() { |
| 52 | return !articulosDescargados().length; | 136 | return $scope.articuloSeleccionado.cantidadDescargada === |
| 137 | $scope.articuloSeleccionado.cantidad; | ||
| 53 | }; | 138 | }; |
| 54 | 139 | ||
| 55 | function articulosDescargados() { | 140 | $scope.actualizarArticulo = function() { |
| 56 | var articulosDescargados = $scope.remito.articulosRemito.filter( | 141 | $scope.articuloSeleccionado.cantidadDescargada = 0; |
| 57 | function(articulo) { | 142 | for(var i = 0; i < $scope.aDescargar.length; i++) { |
| 58 | if(articulo.aCargar && articulo.numeroRecibo) { | 143 | $scope.articuloSeleccionado.cantidadDescargada += |
| 59 | return articulo; | 144 | parseFloat($scope.aDescargar[i]) || 0; |
| 60 | } | 145 | } |
| 146 | }; | ||
| 147 | |||
| 148 | $scope.rechazar = function() { | ||
| 149 | focaModalService | ||
| 150 | .prompt('Aclare el motivo de rechazo') | ||
| 151 | .then(function(motivo) { | ||
| 152 | $scope.cargando = true; | ||
| 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; | ||
| 61 | }); | 165 | }); |
| 62 | return articulosDescargados; | 166 | }; |
| 167 | |||
| 168 | //funciones | ||
| 169 | function error(error) { | ||
| 170 | focaModalService.alert('Hubo un error ' + error); | ||
| 171 | } | ||
| 172 | function success() { |
src/js/service.js
| 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 | }, | ||
| 13 | getRemitoById: function(idRemito) { | ||
| 14 | return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito + '/punto'); | ||
| 15 | }, | ||
| 16 | postMovimientoHojaRuta: function(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}); | ||
| 12 | } | 21 | } |
| 13 | }; | 22 | }; |
| 14 | } | 23 | } |
| 15 | ]); | 24 | ]); |
| 16 | 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"> | 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"> | 6 | <div class="form-group row" ng-show="!cargando"> |
| 7 | <div class="col-12 px-0"> | 7 | <div class="col-12 px-0"> |
| 8 | <label class="form-control-sm"> | 8 | <strong>Información Remito</strong> |
| 9 | <b>Remito Nº</b> | ||
| 10 | <span ng-bind="[remito.numeroRemito, remito.sucursal] | comprobante"/> | ||
| 11 | </label> | ||
| 12 | </div> | ||
| 13 | <div class="col-12 px-0"> | ||
| 14 | <label class="form-control-sm"> | ||
| 15 | <b>Cliente</b> | ||
| 16 | </label> | ||
| 17 | <span ng-bind="remito.nombreCliente"/> | ||
| 18 | </div> | ||
| 19 | <div class="col-12 px-0"> | ||
| 20 | <label class="form-control-sm"> | ||
| 21 | <b>Domicilio</b> | ||
| 22 | <span ng-bind="remito.domicilioStamp"/> | ||
| 23 | </label> | ||
| 24 | </div> | ||
| 25 | <div class="col-12 px-0"> | ||
| 26 | <strong>Articulo a descargar</strong> | ||
| 27 | <table class="table table-sm"> | ||
| 28 | <thead> | ||
| 29 | <tr> | ||
| 30 | <th></th> | ||
| 31 | <th>Articulo</th> | ||
| 32 | <th>Total</th> | ||
| 33 | <th>Descargado</th> | ||
| 34 | </tr> | ||
| 35 | </thead> | ||
| 36 | <tbody> | ||
| 37 | <tr ng-repeat="(key, articulo) in remito.articulosRemito"> | ||
| 38 | <td class="pt-2"><input | ||
| 39 | type="radio" | ||
| 40 | name="articuloRadio" | ||
| 41 | id="{{'articulo' + articulo.id}}" | ||
| 42 | ng-click="cambio(articulo)" | ||
| 43 | ng-disabled="articulo.cargado" | ||
| 44 | ></td> | ||
| 45 | <td ng-bind="articulo.descripcion"></td> | ||
| 46 | <td ng-bind="articulo.cantidad"></td> | ||
| 47 | <td ng-bind="articulo.descargado || articulo.cantidad"></td> | ||
| 48 | </tbody> | ||
| 49 | </table> | ||
| 50 | <strong>Cisterna</strong> | ||
| 51 | <table class="table table-sm"> | ||
| 52 | <thead> | ||
| 53 | <tr> | ||
| 54 | <th>Código</th> | ||
| 55 | <th>Articulo</th> | ||
| 56 | <th>Total</th> | ||
| 57 | <th>A descargar</th> | ||
| 58 | </tr> | ||
| 59 | </thead> | ||
| 60 | <tbody> | ||
| 61 | <tr ng-repeat="(key, cisterna) in cisternas"> | ||
| 62 | <td ng-bind="cisterna.codigo"></td> | ||
| 63 | <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td> | ||
| 64 | <td ng-bind="cisterna.cisternaCarga.cantidad"></td> | ||
| 65 | <td><input | ||
| 66 | class="form-control form-control-sm" | ||
| 67 | type="number" | ||
| 68 | ng-model="cisterna.aDescargar" | ||
| 69 | foca-focus="" | ||
| 70 | ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto"/></td> | ||
| 71 | </tr> | ||
| 72 | </tbody> | ||
| 73 | </table> | ||
| 74 | </div> | ||
| 75 | <div class="col-12 px-0"> | ||
| 76 | <label class="form-control-sm px-0"> | ||
| 77 | <b>Observaciones</b> | ||
| 78 | </label> | ||
| 79 | </div> | ||
| 80 | <div class="col-12"> | ||
| 81 | <textarea | ||
| 82 | ng-model="remito.observaciones" | ||
| 83 | class="form-control form-control-sm" | ||
| 84 | rows="1" | ||
| 85 | ></textarea> | ||
| 86 | </div> | ||
| 87 | <div class="col-12 row mt-2"> | ||
| 88 | <label class="form-control-sm px-0 col-3"><b>Nº Recibo</b></label> | ||
| 89 | <input | ||
| 90 | class="form-control form-control-sm col-4" | ||
| 91 | type="number" | ||
| 92 | ng-model="numeroRecibo"> | ||
| 93 | <button | 9 | <button |
| 94 | class="ml-4 form-control-sm btn btn-success col-4" | 10 | class="btn btn-sm btn-outline-light selectable" |
| 95 | ladda="cargando" | 11 | ng-click="verInformacion = !verInformacion" |
| 96 | data-spinner-color="#FF0000" | 12 | ><i |
| 97 | type="button" | 13 | class="fa fa-chevron-down" |
| 98 | ng-disabled="!distribucionDisponible()" | 14 | ng-show="verInformacion"></i> |
| 99 | ng-click="cargarACisternas(vehiculo)" | 15 | <i |
| 100 | foca-focus="distribucionDisponible()"> | 16 | class="fa fa-chevron-up" |
| 101 | Descargar | 17 | ng-hide="verInformacion"> |
| 18 | </i> | ||
| 102 | </button> | 19 | </button> |
| 103 | </div> | 20 | </div> |
| 21 | <div class="row" ng-show="verInformacion"> | ||
| 22 | <div class="col-12"> | ||
| 23 | <label class="form-control-sm"> | ||
| 24 | <b>Remito Nº</b> | ||
| 25 | <span ng-bind="[remito.numeroRemito, remito.sucursal] | comprobante"/> | ||
| 26 | </label> | ||
| 27 | </div> | ||
| 28 | <div class="col-12"> | ||
| 29 | <label class="form-control-sm"> | ||
| 30 | <b>Cliente</b> | ||
| 31 | </label> | ||
| 32 | <span ng-bind="remito.nombreCliente"/> | ||
| 33 | </div> | ||
| 34 | <div class="col-12"> | ||
| 35 | <label class="form-control-sm"> | ||
| 36 | <b>Domicilio</b> | ||
| 37 | <span ng-bind="remito.domicilioStamp"/> | ||
| 38 | </label> | ||
| 39 | </div> | ||
| 40 | <div ng-show="remito.notaPedido.notaPedidoPuntoDescarga.length" class="px-3"> | ||
| 41 | <label class="form-control-sm"> | ||
| 42 | <b>Puntos de descarga</b> | ||
| 43 | </label> | ||
| 44 | <table class="table table-sm"> | ||
| 45 | <thead> | ||
| 46 | <tr> | ||
| 47 | <th>Nombre</th> | ||
| 48 | <th>Articulo</th> | ||
| 49 | <th>Cantidad</th> | ||
| 50 | </tr> | ||
| 51 | </thead> | ||
| 52 | <tbody> | ||
| 53 | <tr ng-repeat="(key, puntoDescarga) in remito.notaPedido.notaPedidoPuntoDescarga"> | ||
| 54 | <td ng-bind="puntoDescarga.puntoDescarga.descripcion"></td> | ||
| 55 | <td ng-bind="puntoDescarga.producto.DetArt"></td> | ||
| 56 | <td ng-bind="puntoDescarga.cantidad"></td> | ||
| 57 | </tbody> | ||
| 58 | </table> | ||
| 59 | </div> | ||
| 60 | </div> | ||
| 61 | <strong>Articulo a descargar</strong> | ||
| 62 | <table class="table table-sm"> | ||
| 63 | <thead> | ||
| 64 | <tr> | ||
| 65 | <th></th> | ||
| 66 | <th>Articulo</th> | ||
| 67 | <th>Total</th> | ||
| 68 | <th>Descargado</th> | ||
| 69 | </tr> | ||
| 70 | </thead> | ||
| 71 | <tbody> | ||
| 72 | <tr ng-repeat="(key, articulo) in remito.articulosRemito"> | ||
| 73 | <td class="pt-2"> | ||
| 74 | <input | ||
| 75 | type="radio" | ||
| 76 | name="articuloRadio" |