Commit 749743fbbbf3967b9d2cab2ffdf67349406b6272

Authored by Mauricio Cattafi
Exists in master

Merge branch 'develop' into 'master'

Develop

See merge request !26
src/js/controller.js
1 1 angular.module('focaHojaRuta')
2 2 .controller('listaHojaRutaCtrl',
3 3 [
4   - '$scope',
5   - '$location',
6   - '$filter',
7   - '$uibModal',
8   - 'hojaRutaService',
9   - 'focaLoginService',
10   - 'focaModalService',
11   - '$rootScope',
12   - '$localStorage',
13   - function (
14   - $scope,
15   - $location,
16   - $filter,
17   - $uibModal,
18   - hojaRutaService,
19   - focaLoginService,
20   - focaModalService,
21   - $rootScope,
22   - $localStorage
23   - ) {
  4 + '$scope', '$location', '$filter', '$uibModal', 'hojaRutaService',
  5 + 'focaLoginService', 'focaModalService', '$rootScope', '$localStorage',
  6 + function ($scope, $location, $filter, $uibModal, hojaRutaService,
  7 + focaLoginService, focaModalService, $rootScope, $localStorage) {
24 8  
25 9 var loginData = focaLoginService.getLoginData();
26   -
27 10 config();
28   -
  11 + init();
29 12 function config() {
30   -
31 13 $scope.cabecera = [];
32 14 $scope.showCabecera = true;
33 15 $scope.now = new Date();
34 16 $scope.puntoVenta = '0000';
35 17 $scope.comprobante = '00000000';
36 18 }
37   -
38   - hojaRutaService.getHojaRuta(loginData.chofer).then(function (res) {
39   -
40   - if (res.data) {
41   - var hojaRuta = res.data;
42   - $scope.hojaRuta = hojaRuta;
43   - $scope.puntoVenta = hojaRuta.sucursal;
44   - $scope.comprobante = hojaRuta.numeroHojaRuta;
45   - addCabecera('Transportista:', hojaRuta.transportista.NOM);
46   - addCabecera('Chofer:', hojaRuta.chofer.nombre);
47   - addCabecera('Vehículo:', hojaRuta.vehiculo.tractor);
48   - } else {
49   - focaModalService.alert('Sin hoja de ruta asignada');
50   - $location.path('/');
51   - }
52   -
53   - watch();
54   -
55   - if (!$scope.esatadoRed) {
56   - getLSHojaRuta();
57   - }
58   -
59   - });
60   -
61   - function watch() {
62   -
63   - $scope.$watch('hojaRuta', function (nuevoValor) {
64   - $localStorage.hojaRuta = JSON.stringify(nuevoValor);
65   - }, true);
  19 + function init() {
  20 + hojaRutaService.getHojaRuta(loginData.chofer)
  21 + .then(function (res) {
  22 + abrilModalHojasDeRuta(res.data);
  23 + });
66 24 }
67   -
  25 + function abrilModalHojasDeRuta(hojasDeRuta) {
  26 + hojasDeRuta.forEach(function (hojaRuta) {
  27 + hojaRuta.comprobante = (hojaRuta.abierta ? 'RA ' : '') +
  28 + $filter('comprobante')
  29 + ([hojaRuta.sucursal, hojaRuta.numeroHojaRuta]);
  30 + });
  31 + focaModalService.modal(parametrosModalHojasDeRuta(hojasDeRuta))
  32 + .then(function (hojaRuta) {
  33 + if (hojaRuta) {
  34 + $scope.hojaRuta = hojaRuta;
  35 + $scope.puntoVenta = hojaRuta.sucursal;
  36 + $scope.comprobante = hojaRuta.numeroHojaRuta;
  37 + addCabecera('Transportista:', hojaRuta.transportista.NOM);
  38 + addCabecera('Chofer:', hojaRuta.chofer.nombre);
  39 + addCabecera('Vehículo:', hojaRuta.vehiculo.tractor);
  40 + $localStorage.hojaRuta = JSON.stringify($scope.hojaRuta);
  41 + } else {
  42 + focaModalService.alert('Sin hoja de ruta asignada');
  43 + $location.path('/');
  44 + }
  45 + // if (!$scope.estadoRed) {
  46 + // getLSHojaRuta();
  47 + // }
  48 + })
  49 + .catch(function (e) {
  50 + console.info(e);
  51 + $location.path('/');
  52 + });
  53 + }
  54 + $scope.$watch('hojaRuta', function (nuevoValor) {
  55 + $localStorage.hojaRuta = JSON.stringify(nuevoValor);
  56 + }, true);
68 57 $scope.verDetalle = function (remito) {
69 58 var modalInstance = $uibModal.open(
70 59 {
... ... @@ -79,38 +68,21 @@ angular.module('focaHojaRuta')
79 68 size: 'lg'
80 69 }
81 70 );
82   - modalInstance.result.then(function () {
83   - //funcion se ejecuta cuando se carga pantalla
84   - });
85   - };
86   -
87   - function addCabecera(label, valor) {
88   - var propiedad = $filter('filter')($scope.cabecera, { label: label }, true);
89   - if (propiedad.length === 1) {
90   - propiedad[0].valor = valor;
91   - } else {
92   - $scope.cabecera.push({ label: label, valor: valor });
93   - }
94   - }
95   -
96   - $scope.rellenar = function (relleno, longitud) {
97   - relleno = '' + relleno;
98   - while (relleno.length < longitud) {
99   - relleno = '0' + relleno;
100   - }
101   -
102   - return relleno;
  71 + modalInstance.result
  72 + .then(function () {
  73 + // console.log(data);
  74 + })
  75 + .catch(function (e) { console.info(e); });
103 76 };
104   -
105 77 $scope.salir = function () {
106 78 $location.path('/');
107 79 };
108   -
109 80 $scope.terminarHojaRuta = function () {
110 81 focaModalService
111 82 .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' +
112 83 'otra descarga ni modificación')
113   - .then(function () { $scope.datosExtraCierre(terminar); });
  84 + .then(function () { $scope.datosExtraCierre(terminar); })
  85 + .catch(function (e) { console.info('Modal ', e); });
114 86 function terminar(datosExtraCierre) {
115 87 $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre);
116 88 //limpio objeto para guardar
... ... @@ -135,7 +107,6 @@ angular.module(&#39;focaHojaRuta&#39;)
135 107 );
136 108 }
137 109 };
138   -
139 110 $scope.datosExtraCierre = function (terminar) {
140 111 var modalInstance = $uibModal.open(
141 112 {
... ... @@ -145,38 +116,101 @@ angular.module(&#39;focaHojaRuta&#39;)
145 116 );
146 117 modalInstance.result.then(terminar);
147 118 };
148   -
149 119 $scope.modalDescargas = function () {
150 120 delete $scope.hojaRuta.remitos[0].cliente;
  121 + var remito = $scope.hojaRuta.remitos[0];
  122 + var msg = '';
  123 + var mostrarMensaje = true;
  124 + for (var i = 0; i < remito.cisternas.length; i++) {
  125 + if (remito.cisternas[i].cisternaCarga.cantidad <= 0)
  126 + msg += 'Cisterna ' + remito.cisternas[i].cisternaCarga.articulo.DetArt +
  127 + ' esta vacía.\n';
  128 + else
  129 + mostrarMensaje = false;
  130 + }
  131 + if (mostrarMensaje === true) {
  132 + focaModalService.alert(msg);
  133 + return;
  134 + }
151 135 var modalInstance = $uibModal.open(
152 136 {
153 137 templateUrl: 'foca-modal-descarga.html',
154 138 controller: 'focaModalDescargaCtrl',
155 139 resolve: {
156   - remito: function () { return $scope.hojaRuta.remitos[0]; }
  140 + remito: function () { return remito; }
157 141 },
158 142 }
159 143 );
160   -
161   - modalInstance.result.then(function (data) {
162   -
163   - console.log(data);
  144 + modalInstance.result.then(function () {
  145 + // console.log(data);
164 146 });
165 147 };
166   -
  148 + $scope.articulosDescargados = function (articulosRemito) {
  149 + for (var i = 0; i < articulosRemito.length; i++) {
  150 + if (articulosRemito[i].cantidadDescargada > 0) continue;
  151 + else return false;
  152 + }
  153 + return true;
  154 + };
  155 + $scope.estaPendiente = function () {
  156 + if ($scope.hojaRuta.abierta) {
  157 + $scope.terminarHojaRuta();
  158 + return;
  159 + }
  160 + var pendiente = false;
  161 + $scope.hojaRuta.remitos.forEach(function (remito) {
  162 + if (pendiente === false) {
  163 + var aDescargado = false;
  164 + for (var i = 0; i < remito.articulosRemito.length; i++) {
  165 + if (remito.articulosRemito[i].cantidadDescargada > 0)
  166 + aDescargado = true;
  167 + }
  168 + pendiente = (!aDescargado && remito.rechazado == null) ? true : false;
  169 + }
  170 + });
  171 + if (pendiente) {
  172 + focaModalService.alert('Todavia hay remitos pendientes');
  173 + return;
  174 + }
  175 + $scope.terminarHojaRuta();
  176 + };
167 177 $rootScope.$on('estadoRed', function (event, value) {
168   - $scope.esatadoRed = value;
  178 + $scope.estadoRed = value;
169 179 });
170   -
171   - function getLSHojaRuta() {
172   -
173   - var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
174   -
175   - if (hojaRuta) {
176   - $scope.hojaRuta = hojaRuta;
177   - delete $localStorage.hojaRuta;
178   - }
  180 + function addCabecera(label, valor) {
  181 + var propiedad = $filter('filter')($scope.cabecera, { label: label }, true);
  182 + if (propiedad.length === 1) propiedad[0].valor = valor;
  183 + else $scope.cabecera.push({ label: label, valor: valor });
  184 + }
  185 + // function getLSHojaRuta() {
  186 + // var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
  187 + // if (hojaRuta) {
  188 + // $scope.hojaRuta = hojaRuta;
  189 + // delete $localStorage.hojaRuta;
  190 + // }
  191 + // }
  192 + function parametrosModalHojasDeRuta(datos) {
  193 + var parametrosModal = {
  194 + data: datos,
  195 + columnas: [
  196 + {
  197 + propiedad: 'comprobante',
  198 + nombre: 'Número'
  199 + },
  200 + {
  201 + propiedad: 'fechaReparto',
  202 + nombre: 'Fecha',
  203 + filtro: {
  204 + nombre: 'date',
  205 + parametro: 'yyyy-MM-dd'
  206 + }
  207 + }
  208 + ],
  209 + titulo: 'Selecciona hoja de ruta',
  210 + size: 'md'
  211 + };
  212 + return parametrosModal;
179 213 }
180   -
181 214 }
182   - ]);
  215 + ]
  216 + );
... ... @@ -2,8 +2,8 @@ angular.module(&#39;focaHojaRuta&#39;)
2 2 .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 3 var route = API_ENDPOINT.URL;
4 4 return {
5   - getHojaRuta: function(chofer) {
6   - return $http.get(route + '/hoja-ruta/chofer/' + chofer);
  5 + getHojaRuta: function(id) {
  6 + return $http.get(route + '/hoja-ruta/chofer/' + id);
7 7 },
8 8 terminarHojaRuta: function(hojaRuta) {
9 9 return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta});
src/views/lista-hoja-ruta.html
1   -<div>
  1 +<div class="row mx-0">
2 2 <div class="col-md-10 offset-md-1 col-lg-8 offset-lg-2">
3 3 <div class="row p-1 panel-informativo">
4 4 <div class="col-12">
... ... @@ -59,62 +59,80 @@
59 59 </div>
60 60 </div>
61 61 </div>
62   - <div class="col-12 col-md-10 col-lg-8 offset-md-1 offset-lg-2">
63   - <div class="row grilla-articulo">
64   - <table ng-hide="hojaRuta.abierta" class="table table-responsive table-striped table-sm table-dark">
65   - <thead>
66   - <tr>
67   - <th>#</th>
68   - <th>Número</th>
69   - <th>Razon Social</th>
70   - <th>Domicilio</th>
71   - <th>&nbsp;</th>
72   - </tr>
73   - </thead>
74   - <tbody class="tabla-articulo-body">
75   - <tr
76   - ng-repeat="(key, remito) in hojaRuta.remitos"
77   - >
78   - <td ng-bind="key + 1"></td>
79   - <td
80   - ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"
81   - ></td>
82   - <td ng-bind="remito.nombreCliente"></td>
83   - <td ng-bind="remito.domicilioStamp"></td>
84   - <td>
85   - <button
86   - class="btn btn-secondary"
87   - type="button"
88   - ng-click="verDetalle(remito)"
89   - ><i class="fa fa-search" aria-hidden="true"></i>
90   - </button>
91   - </td>
92   - </tr>
93   - </tbody>
94   - </table>
  62 + <div class="col-12 col-md-10 col-lg-8 offset-md-1 offset-lg-2 mb-5">
  63 + <div ng-hide="hojaRuta.abierta" class="row">
  64 + <div class="col p-0">
  65 + <table class="table table-striped table-sm table-dark">
  66 + <thead>
  67 + <tr>
  68 + <th class="align-middle">#</th>
  69 + <th class="align-middle">Número</th>
  70 + <th class="align-middle">Razon Social</th>
  71 + <th class="align-middle" colspan="2">Domicilio</th>
  72 + </tr>
  73 + </thead>
  74 + <tbody class="tabla-articulo-body">
  75 + <tr
  76 + ng-repeat="(key, remito) in hojaRuta.remitos"
  77 + >
  78 + <td class="align-middle" ng-bind="key + 1"></td>
  79 + <td
  80 + class="align-middle"
  81 + ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"
  82 + ></td>
  83 + <td class="align-middle" ng-bind="remito.nombreCliente"></td>
  84 + <td class="align-middle" ng-bind="remito.domicilioStamp"></td>
  85 + <td class="align-middle">
  86 + <div class="btn-group-vertical">
  87 + <button
  88 + class="btn btn-secondary my-1 rounded"
  89 + type="button"
  90 + ng-click="verDetalle(remito)">
  91 + <i class="fa fa-search" aria-hidden="true"></i>
  92 + </button>
  93 + <button
  94 + ng-show="articulosDescargados(remito.articulosRemito)"
  95 + class="btn btn-secondary my-1 rounded"
  96 + type="button">
  97 + <i class="fa fa-check fa-lg foca-text-success" aria-hidden="true"></i>
  98 + </button>
  99 + <button
  100 + ng-show="remito.rechazado"
  101 + class="btn btn-secondary my-1 rounded"
  102 + type="button">
  103 + <i class="fa fa-remove fa-lg foca-text-danger" aria-hidden="true"></i>
  104 + </button>
  105 + </div>
  106 + </td>
  107 + </tr>
  108 + </tbody>
  109 + </table>
  110 + </div>
95 111 </div>
96 112 <div ng-show="hojaRuta.abierta" class="row grilla-articulo">
97   - <table class="table table-striped table-sm table-dark">
98   - <thead>
99   - <tr>
100   - <th colspan="3" class="text-center">Remito abierto Nº
101   - {{[hojaRuta.remitos[0].sucursal, hojaRuta.remitos[0].numeroRemito] | comprobante}}
102   - </th>
103   - </tr>
104   - <tr>
105   - <th>Cisterna</th>
106   - <th>Producto</th>
107   - <th>Disponibles</th>
108   - </tr>
109   - </thead>
110   - <tbody>
111   - <tr ng-repeat="cisterna in hojaRuta.remitos[0].cisternas">
112   - <td ng-bind="cisterna.codigo"></td>
113   - <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td>
114   - <td ng-bind="cisterna.cisternaCarga.cantidad"></td>
115   - </tr>
116   - </tbody>
117   - </table>
  113 + <div class="col p-0">
  114 + <table class="table table-striped table-sm table-dark">
  115 + <thead>
  116 + <tr>
  117 + <th colspan="3" class="text-center">Remito abierto Nº
  118 + {{[hojaRuta.remitos[0].sucursal, hojaRuta.remitos[0].numeroRemito] | comprobante}}
  119 + </th>
  120 + </tr>
  121 + <tr>
  122 + <th>Cisterna</th>
  123 + <th>Producto</th>
  124 + <th>Disponibles</th>
  125 + </tr>
  126 + </thead>
  127 + <tbody>
  128 + <tr ng-repeat="cisterna in hojaRuta.remitos[0].cisternas">
  129 + <td ng-bind="cisterna.codigo"></td>
  130 + <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td>
  131 + <td ng-bind="cisterna.cisternaCarga.cantidad"></td>
  132 + </tr>
  133 + </tbody>
  134 + </table>
  135 + </div>
118 136 <table class="table table-striped table-sm table-dark">
119 137 <thead>
120 138 <tr>
... ... @@ -138,7 +156,7 @@
138 156 <span class="ml-3 text-muted" ng-click="salir()">Salir</span>
139 157 <span
140 158 class="mr-3 ml-auto"
141   - ng-click="terminarHojaRuta()"
  159 + ng-click="estaPendiente()"
142 160 ladda="saveLoading"
143 161 data-style="expand-left"
144 162 >Terminar</span>