Commit 6b9369a8dcd62de300e92cc6b4036abd6487117a

Authored by Eric Fernandez
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'develop'

Master(mpuebla)

See merge request !23
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.estadoRed) {
56   - getLSHojaRuta();
57   - }
58   -
59   -
60   - });
61   -
  19 + function init() {
  20 + hojaRutaService.getHojaRuta(loginData.chofer)
  21 + .then(function (res) {
  22 + if (res.data) {
  23 + var hojaRuta = res.data;
  24 + $scope.hojaRuta = hojaRuta;
  25 + $scope.puntoVenta = hojaRuta.sucursal;
  26 + $scope.comprobante = hojaRuta.numeroHojaRuta;
  27 + addCabecera('Transportista:', hojaRuta.transportista.NOM);
  28 + addCabecera('Chofer:', hojaRuta.chofer.nombre);
  29 + addCabecera('Vehículo:', hojaRuta.vehiculo.tractor);
  30 + } else {
  31 + focaModalService.alert('Sin hoja de ruta asignada');
  32 + $location.path('/');
  33 + }
  34 + watch();
  35 + if (!$scope.estadoRed) {
  36 + getLSHojaRuta();
  37 + }
  38 + });
  39 + }
62 40 function watch() {
63   -
64 41 $scope.$watch('hojaRuta', function (nuevoValor) {
65 42 $localStorage.hojaRuta = JSON.stringify(nuevoValor);
66 43 }, true);
67 44 }
68   -
69 45 $scope.verDetalle = function (remito) {
70 46 var modalInstance = $uibModal.open(
71 47 {
... ... @@ -80,20 +56,13 @@ angular.module('focaHojaRuta')
80 56 size: 'lg'
81 57 }
82 58 );
83   - modalInstance.result.then(function () {
84   - //funcion se ejecuta cuando se carga pantalla
85   - });
  59 + modalInstance.result
  60 + .then(function (data) {
  61 + //funcion se ejecuta cuando se carga pantalla
  62 + console.log(data);
  63 + })
  64 + .catch(function (e) { console.info(e); });
86 65 };
87   -
88   - function addCabecera(label, valor) {
89   - var propiedad = $filter('filter')($scope.cabecera, { label: label }, true);
90   - if (propiedad.length === 1) {
91   - propiedad[0].valor = valor;
92   - } else {
93   - $scope.cabecera.push({ label: label, valor: valor });
94   - }
95   - }
96   -
97 66 $scope.rellenar = function (relleno, longitud) {
98 67 relleno = '' + relleno;
99 68 while (relleno.length < longitud) {
... ... @@ -102,11 +71,9 @@ angular.module(&#39;focaHojaRuta&#39;)
102 71  
103 72 return relleno;
104 73 };
105   -
106 74 $scope.salir = function () {
107 75 $location.path('/');
108 76 };
109   -
110 77 $scope.terminarHojaRuta = function () {
111 78 focaModalService
112 79 .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' +
... ... @@ -136,7 +103,6 @@ angular.module(&#39;focaHojaRuta&#39;)
136 103 );
137 104 }
138 105 };
139   -
140 106 $scope.datosExtraCierre = function (terminar) {
141 107 var modalInstance = $uibModal.open(
142 108 {
... ... @@ -146,7 +112,6 @@ angular.module(&#39;focaHojaRuta&#39;)
146 112 );
147 113 modalInstance.result.then(terminar);
148 114 };
149   -
150 115 $scope.modalDescargas = function () {
151 116 delete $scope.hojaRuta.remitos[0].cliente;
152 117 var remito = $scope.hojaRuta.remitos[0];
... ... @@ -158,7 +123,6 @@ angular.module(&#39;focaHojaRuta&#39;)
158 123 ' esta vacía.\n';
159 124 else
160 125 mostrarMensaje = false;
161   -
162 126 }
163 127 if (mostrarMensaje === true) {
164 128 focaModalService.alert(msg);
... ... @@ -173,26 +137,57 @@ angular.module(&#39;focaHojaRuta&#39;)
173 137 },
174 138 }
175 139 );
176   -
177 140 modalInstance.result.then(function (data) {
178   -
179 141 console.log(data);
180 142 });
181 143 };
182   -
  144 + $scope.articulosDescargados = function (articulosRemito) {
  145 + for (var i = 0; i < articulosRemito.length; i++) {
  146 + if (articulosRemito[i].cantidadDescargada > 0) continue;
  147 + else return false;
  148 + }
  149 + return true;
  150 + };
  151 + $scope.estaPendiente = function () {
  152 + var pendiente = false;
  153 + $scope.hojaRuta.remitos.forEach(function (remito) {
  154 + if (pendiente === false) {
  155 + var aDescargado = false;
  156 + for (var i = 0; i < remito.articulosRemito.length; i++) {
  157 + if (remito.articulosRemito[i].cantidadDescargada > 0)
  158 + aDescargado = true;
  159 + }
  160 + pendiente = (!aDescargado && remito.rechazado == null) ? true : false;
  161 + }
  162 + });
  163 + if (pendiente) {
  164 + focaModalService.alert('Todavia hay remitos pendientes');
  165 + return;
  166 + }
  167 + $scope.terminarHojaRuta();
  168 + };
183 169 $rootScope.$on('estadoRed', function (event, value) {
184 170 $scope.estadoRed = value;
185 171 });
186   -
  172 + function addCabecera(label, valor) {
  173 + var propiedad = $filter('filter')($scope.cabecera, { label: label }, true);
  174 + if (propiedad.length === 1) {
  175 + propiedad[0].valor = valor;
  176 + } else {
  177 + $scope.cabecera.push({ label: label, valor: valor });
  178 + }
  179 + }
187 180 function getLSHojaRuta() {
188 181  
189 182 var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
190 183  
191 184 if (hojaRuta) {
  185 + console.log('getLSHojaRuta() => ', hojaRuta);
192 186 $scope.hojaRuta = hojaRuta;
193 187 delete $localStorage.hojaRuta;
194 188 }
195 189 }
196 190  
197 191 }
198   - ]);
  192 + ]
  193 + );
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>