Commit f776fcedbfb8e8b2ae3898f13247109c750241bd

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !4
src/js/controller.js
... ... @@ -4,62 +4,174 @@ angular.module('focaModalDetalleHojaRuta')
4 4 '$filter',
5 5 '$scope',
6 6 '$uibModalInstance',
7   - 'remito',
  7 + 'idRemito',
8 8 'focaModalDetalleHojaRutaService',
9   - function($filter, $scope, $uibModalInstance, remito, focaModalDetalleHojaRutaService) {
10   - $scope.remito = remito;
  9 + 'focaModalService',
  10 + 'focaSeguimientoService',
  11 + function($filter, $scope, $uibModalInstance, idRemito, focaModalDetalleHojaRutaService,
  12 + focaModalService, focaSeguimientoService)
  13 + {
  14 + //Seteo variables
  15 + $scope.remito = {};
11 16 $scope.cisternas = [];
12 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 46 $scope.cambio = function(articulo) {
  47 + if(!$scope.articuloSeleccionado.descargado) {
  48 + $scope.articuloSeleccionado.cantidadDescargada = 0;
  49 + }
  50 + $scope.aDescargar = [];
14 51 $scope.articuloSeleccionado = articulo;
15 52 };
16   - focaModalDetalleHojaRutaService.getCisternasByIdRemito($scope.remito.id)
17   - .then(function(res) {
18   - $scope.cisternas = res.data;
19   - });
  53 + $scope.descargar = function(key) {
  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 + }
  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() {
22   - var articulos = articulosDescargados();
23   - var cisternaMovimientos = [];
24   - var hojaRutaMovimientos = [];
25   - for(var i = 0; i < articulos.length; i++) {
26   - var cisternaMovimiento = {
27   - idRemito: $scope.remito.id,
28   - cantidad: articulos[i].aCargar,
29   - metodo: 'descarga'
30   - };
31   - var hojaRutaMovimiento = {
32   - idRemito: $scope.remito.id,
33   - reciboDescarga: articulos[i].numeroRecibo
  81 + //Guardar
  82 + var now = new Date();
  83 + var cisternaMovimiento = {
  84 + fecha: now.toISOString().slice(0, 19).replace('T', ' '),
  85 + cantidad: descarga,
  86 + metodo: 'descarga',
  87 + idCisternaCarga: cisternaCarga.id,
  88 + idRemito: $scope.remito.id
  89 + };
  90 + var hojaRutaMovimiento = {
  91 + reciboDescarga: $scope.numeroRecibo,
  92 + idRemito: $scope.remito.id
  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);
36   - hojaRutaMovimientos.push(hojaRutaMovimiento);
  105 + focaModalDetalleHojaRutaService
  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 131 $scope.cancel = function() {
48 132 $uibModalInstance.dismiss('cancel');
49 133 };
50 134  
51   - $scope.validar = function() {
52   - return !articulosDescargados().length;
  135 + $scope.distribucionDisponible = function() {
  136 + return $scope.articuloSeleccionado.cantidadDescargada ===
  137 + $scope.articuloSeleccionado.cantidad;
53 138 };
54 139  
55   - function articulosDescargados() {
56   - var articulosDescargados = $scope.remito.articulosRemito.filter(
57   - function(articulo) {
58   - if(articulo.aCargar && articulo.numeroRecibo) {
59   - return articulo;
60   - }
  140 + $scope.actualizarArticulo = function() {
  141 + $scope.articuloSeleccionado.cantidadDescargada = 0;
  142 + for(var i = 0; i < $scope.aDescargar.length; i++) {
  143 + $scope.articuloSeleccionado.cantidadDescargada +=
  144 + parseFloat($scope.aDescargar[i]) || 0;
  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() {
  173 + focaModalService.alert('Operación realizada con éxito');
  174 + $scope.cargando = false;
63 175 }
64 176 }
65 177 ]
... ... @@ -9,6 +9,15 @@ angular.module(&#39;focaModalDetalleHojaRuta&#39;)
9 9 },
10 10 getCisternasByIdRemito: function(idRemito) {
11 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 }
src/views/modal-detalle-hoja-ruta.html
1 1 <div class="modal-header py-1">
2 2 <h5 class="modal-title">Detalle de descarga</h5>
3 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 5 <form name="formDetalleHojaRuta">
6   - <div class="form-group row">
  6 + <div class="form-group row" ng-show="!cargando">
7 7 <div class="col-12 px-0">
8   - <label class="form-control-sm">
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">
  8 + <strong>Información Remito</strong>
93 9 <button
94   - class="ml-4 form-control-sm btn btn-success col-4"
95   - ladda="cargando"
96   - data-spinner-color="#FF0000"
97   - type="button"
98   - ng-disabled="!distribucionDisponible()"
99   - ng-click="cargarACisternas(vehiculo)"
100   - foca-focus="distribucionDisponible()">
101   - Descargar
  10 + class="btn btn-sm btn-outline-light selectable"
  11 + ng-click="verInformacion = !verInformacion"
  12 + ><i
  13 + class="fa fa-chevron-down"
  14 + ng-show="verInformacion"></i>
  15 + <i
  16 + class="fa fa-chevron-up"
  17 + ng-hide="verInformacion">
  18 + </i>
102 19 </button>
103 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"
  77 + id="{{'articulo' + articulo.id}}"
  78 + ng-click="cambio(articulo)"
  79 + ng-disabled="articulo.descargado || readonly"
  80 + ng-checked="articuloSeleccionado.id === articulo.id"
  81 + ></td>
  82 + <td ng-bind="articulo.descripcion"></td>
  83 + <td ng-bind="articulo.cantidad"></td>
  84 + <td ng-bind="articulo.cantidadDescargada || 0"></td>
  85 + </tbody>
  86 + </table>
  87 + <strong>Cisterna</strong>
  88 + <table class="table table-sm">
  89 + <thead>
  90 + <tr>
  91 + <th>Código</th>
  92 + <th>Articulo</th>
  93 + <th>Total</th>
  94 + <th>A descargar</th>
  95 + </tr>
  96 + </thead>
  97 + <tbody>
  98 + <tr ng-repeat="(key, cisterna) in cisternas">
  99 + <td ng-bind="cisterna.codigo"></td>
  100 + <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td>
  101 + <td ng-bind="cisterna.cisternaCarga.cantidad"></td>
  102 + <td><input
  103 + class="form-control form-control-sm"
  104 + type="number"
  105 + ng-model="aDescargar[key]"
  106 + ng-change="actualizarArticulo()"
  107 + foca-focus="articuloSeleccionado.idArticulo == cisterna.cisternaCarga.idProducto"
  108 + ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto
  109 + || readonly"/></td>
  110 + </tr>
  111 + </tbody>
  112 + </table>
  113 + <div class="col-12 px-0">
  114 + <label class="form-control-sm px-0">
  115 + <b>Observaciones</b>
  116 + </label>
  117 + </div>
  118 + <div class="col-12">
  119 + <textarea
  120 + ng-model="remito.observaciones"
  121 + ng-disabled="readonly"
  122 + class="form-control form-control-sm"
  123 + rows="1"
  124 + ></textarea>
  125 + </div>
  126 + <div class="col-12 row mt-2">
  127 + <label class="form-control-sm px-0 col-3"><b>Nº Recibo</b></label>
  128 + <input
  129 + class="form-control form-control-sm col-4"
  130 + type="number"
  131 + ng-disabled="readonly"
  132 + ng-model="numeroRecibo"
  133 + ng-keypress="descargar($event.keyCode)"
  134 + foca-focus="distribucionDisponible()">
  135 + <button
  136 + class="ml-4 form-control-sm btn btn-success col-4"
  137 + ladda="cargando"
  138 + data-spinner-color="#FF0000"
  139 + type="button"
  140 + ng-disabled="!distribucionDisponible() || !numeroRecibo"
  141 + ng-click="descargar(13)">
  142 + Descargar
  143 + </button>
104 144 </div>
105 145 </form>
106 146 </div>
... ... @@ -108,18 +148,12 @@
108 148 <button
109 149 class="btn btn-danger btn-sm"
110 150 type="button"
111   - ng-click=""
112   - ng-disabled=""
113   - >Anular</button>
  151 + ng-click="rechazar()"
  152 + ng-disabled="readonly"
  153 + >Rechazar</button>
114 154 <button
115 155 class="btn btn-secondary btn-sm"
116 156 type="button"
117 157 ng-click="cancel()"
118   - >Cancelar</button>
119   - <button
120   - class="btn btn-primary btn-sm"
121   - type="button"
122   - ng-click="aceptar()"
123   - ng-disabled="validar()"
124   - >Aceptar</button>
  158 + >Salir</button>
125 159 </div>