Commit 749743fbbbf3967b9d2cab2ffdf67349406b6272

Authored by Mauricio Cattafi
Exists in master

Merge branch 'develop' into 'master'

Develop

See merge request !26
src/js/controller.js
1 angular.module('focaHojaRuta') 1 angular.module('focaHojaRuta')
2 .controller('listaHojaRutaCtrl', 2 .controller('listaHojaRutaCtrl',
3 [ 3 [
4 '$scope', 4 '$scope', '$location', '$filter', '$uibModal', 'hojaRutaService',
5 '$location', 5 'focaLoginService', 'focaModalService', '$rootScope', '$localStorage',
6 '$filter', 6 function ($scope, $location, $filter, $uibModal, hojaRutaService,
7 '$uibModal', 7 focaLoginService, focaModalService, $rootScope, $localStorage) {
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 ) {
24 8
25 var loginData = focaLoginService.getLoginData(); 9 var loginData = focaLoginService.getLoginData();
26
27 config(); 10 config();
28 11 init();
29 function config() { 12 function config() {
30
31 $scope.cabecera = []; 13 $scope.cabecera = [];
32 $scope.showCabecera = true; 14 $scope.showCabecera = true;
33 $scope.now = new Date(); 15 $scope.now = new Date();
34 $scope.puntoVenta = '0000'; 16 $scope.puntoVenta = '0000';
35 $scope.comprobante = '00000000'; 17 $scope.comprobante = '00000000';
36 } 18 }
37 19 function init() {
38 hojaRutaService.getHojaRuta(loginData.chofer).then(function (res) { 20 hojaRutaService.getHojaRuta(loginData.chofer)
39 21 .then(function (res) {
40 if (res.data) { 22 abrilModalHojasDeRuta(res.data);
41 var hojaRuta = res.data; 23 });
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);
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 $scope.verDetalle = function (remito) { 57 $scope.verDetalle = function (remito) {
69 var modalInstance = $uibModal.open( 58 var modalInstance = $uibModal.open(
70 { 59 {
71 ariaLabelledBy: 'Detalle hoja ruta', 60 ariaLabelledBy: 'Detalle hoja ruta',
72 templateUrl: 'modal-detalle-hoja-ruta.html', 61 templateUrl: 'modal-detalle-hoja-ruta.html',
73 controller: 'focaModalDetalleHojaRutaController', 62 controller: 'focaModalDetalleHojaRutaController',
74 resolve: { 63 resolve: {
75 parametros: { 64 parametros: {
76 remito: remito, 65 remito: remito,
77 } 66 }
78 }, 67 },
79 size: 'lg' 68 size: 'lg'
80 } 69 }
81 ); 70 );
82 modalInstance.result.then(function () { 71 modalInstance.result
83 //funcion se ejecuta cuando se carga pantalla 72 .then(function () {
84 }); 73 // console.log(data);
85 }; 74 })
86 75 .catch(function (e) { console.info(e); });
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;
103 }; 76 };
104
105 $scope.salir = function () { 77 $scope.salir = function () {
106 $location.path('/'); 78 $location.path('/');
107 }; 79 };
108
109 $scope.terminarHojaRuta = function () { 80 $scope.terminarHojaRuta = function () {
110 focaModalService 81 focaModalService
111 .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' + 82 .confirm('¿Desea terminar la hoja de ruta? No podra realizar ninguna ' +
112 'otra descarga ni modificación') 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 function terminar(datosExtraCierre) { 86 function terminar(datosExtraCierre) {
115 $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre); 87 $scope.hojaRuta = angular.extend({}, $scope.hojaRuta, datosExtraCierre);
116 //limpio objeto para guardar 88 //limpio objeto para guardar
117 delete $scope.hojaRuta.chofer; 89 delete $scope.hojaRuta.chofer;
118 delete $scope.hojaRuta.remitos; 90 delete $scope.hojaRuta.remitos;
119 delete $scope.hojaRuta.transportista; 91 delete $scope.hojaRuta.transportista;
120 delete $scope.hojaRuta.vehiculo; 92 delete $scope.hojaRuta.vehiculo;
121 93
122 $scope.hojaRuta.fechaCreacion = 94 $scope.hojaRuta.fechaCreacion =
123 $scope.hojaRuta.fechaCreacion.slice(0, 19).replace('T', ' '); 95 $scope.hojaRuta.fechaCreacion.slice(0, 19).replace('T', ' ');
124 $scope.hojaRuta.fechaReparto = 96 $scope.hojaRuta.fechaReparto =
125 $scope.hojaRuta.fechaReparto.slice(0, 19).replace('T', ' '); 97 $scope.hojaRuta.fechaReparto.slice(0, 19).replace('T', ' ');
126 $scope.hojaRuta.estado = 2; 98 $scope.hojaRuta.estado = 2;
127 hojaRutaService.terminarHojaRuta($scope.hojaRuta).then( 99 hojaRutaService.terminarHojaRuta($scope.hojaRuta).then(
128 function () { 100 function () {
129 focaModalService.alert( 101 focaModalService.alert(
130 'Hoja de ruta ' + 102 'Hoja de ruta ' +
131 $filter('comprobante')([$scope.puntoVenta, 103 $filter('comprobante')([$scope.puntoVenta,
132 $scope.comprobante]) + ' cerrada con éxito'); 104 $scope.comprobante]) + ' cerrada con éxito');
133 $location.path('/'); 105 $location.path('/');
134 } 106 }
135 ); 107 );
136 } 108 }
137 }; 109 };
138
139 $scope.datosExtraCierre = function (terminar) { 110 $scope.datosExtraCierre = function (terminar) {
140 var modalInstance = $uibModal.open( 111 var modalInstance = $uibModal.open(
141 { 112 {
142 templateUrl: 'focaDatosExtra.html', 113 templateUrl: 'focaDatosExtra.html',
143 controller: 'focaModalDatosExtraCierre', 114 controller: 'focaModalDatosExtraCierre',
144 } 115 }
145 ); 116 );
146 modalInstance.result.then(terminar); 117 modalInstance.result.then(terminar);
147 }; 118 };
148
149 $scope.modalDescargas = function () { 119 $scope.modalDescargas = function () {
150 delete $scope.hojaRuta.remitos[0].cliente; 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 var modalInstance = $uibModal.open( 135 var modalInstance = $uibModal.open(
152 { 136 {
153 templateUrl: 'foca-modal-descarga.html', 137 templateUrl: 'foca-modal-descarga.html',
154 controller: 'focaModalDescargaCtrl', 138 controller: 'focaModalDescargaCtrl',
155 resolve: { 139 resolve: {
156 remito: function () { return $scope.hojaRuta.remitos[0]; } 140 remito: function () { return remito; }
157 }, 141 },
158 } 142 }
159 ); 143 );
160 144 modalInstance.result.then(function () {
161 modalInstance.result.then(function (data) { 145 // console.log(data);
162
163 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;
1 angular.module('focaHojaRuta') 1 angular.module('focaHojaRuta')
2 .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .factory('hojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 return { 4 return {
5 getHojaRuta: function(chofer) { 5 getHojaRuta: function(id) {
6 return $http.get(route + '/hoja-ruta/chofer/' + chofer); 6 return $http.get(route + '/hoja-ruta/chofer/' + id);
7 }, 7 },
8 terminarHojaRuta: function(hojaRuta) { 8 terminarHojaRuta: function(hojaRuta) {
9 return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta}); 9 return $http.post(route + '/hoja-ruta/terminar', {hojaRuta: hojaRuta});
10 } 10 }
11 }; 11 };
12 }]); 12 }]);
13 13
src/views/lista-hoja-ruta.html
1 <div> 1 <div class="row mx-0">
2 <div class="col-md-10 offset-md-1 col-lg-8 offset-lg-2"> 2 <div class="col-md-10 offset-md-1 col-lg-8 offset-lg-2">
3 <div class="row p-1 panel-informativo"> 3 <div class="row p-1 panel-informativo">
4 <div class="col-12"> 4 <div class="col-12">
5 <div class="row"> 5 <div class="row">
6 <div class="col-12 col-sm-4 nota-pedido"> 6 <div class="col-12 col-sm-4 nota-pedido">
7 <h5>Hojas de ruta</h5> 7 <h5>Hojas de ruta</h5>
8 </div> 8 </div>
9 <div class="col-5 col-sm-4 numero-pedido"> 9 <div class="col-5 col-sm-4 numero-pedido">
10 Nº <span ng-bind="[puntoVenta, comprobante] | comprobante"></span> 10 Nº <span ng-bind="[puntoVenta, comprobante] | comprobante"></span>
11 </div> 11 </div>
12 <div class="col-7 col-sm-4 text-right"> 12 <div class="col-7 col-sm-4 text-right">
13 Fecha: 13 Fecha:
14 <span 14 <span
15 ng-show="!datepickerAbierto" 15 ng-show="!datepickerAbierto"
16 ng-bind="now | date:'dd/MM/yyyy HH:mm'" 16 ng-bind="now | date:'dd/MM/yyyy HH:mm'"
17 ng-click="datepickerAbierto = true" 17 ng-click="datepickerAbierto = true"
18 > 18 >
19 </span> 19 </span>
20 <input 20 <input
21 ng-show="datepickerAbierto" 21 ng-show="datepickerAbierto"
22 type="date" 22 type="date"
23 ng-model="now" 23 ng-model="now"
24 ng-change="datepickerAbierto = false" 24 ng-change="datepickerAbierto = false"
25 ng-blur="datepickerAbierto = false" 25 ng-blur="datepickerAbierto = false"
26 class="form-control form-control-sm col-8 float-right" 26 class="form-control form-control-sm col-8 float-right"
27 foca-focus="datepickerAbierto" 27 foca-focus="datepickerAbierto"
28 hasta-hoy 28 hasta-hoy
29 /> 29 />
30 </div> 30 </div>
31 </div> 31 </div>
32 <div class="row"> 32 <div class="row">
33 <div class="col-auto" ng-repeat="cab in cabecera" ng-show="showCabecera"> 33 <div class="col-auto" ng-repeat="cab in cabecera" ng-show="showCabecera">
34 <span class="label" ng-bind="cab.label"></span> 34 <span class="label" ng-bind="cab.label"></span>
35 <span class="valor" ng-bind="cab.valor"></span> 35 <span class="valor" ng-bind="cab.valor"></span>
36 </div> 36 </div>
37 </div> 37 </div>
38 </div> 38 </div>
39 </div> 39 </div>
40 <div class="row p-1 botonera-secundaria"> 40 <div class="row p-1 botonera-secundaria">
41 <div class="col-12"> 41 <div class="col-12">
42 <div class="row"> 42 <div class="row">
43 <div class="col-6 col-sm-3 px-0 py-0" ng-repeat="boton in botonera"> 43 <div class="col-6 col-sm-3 px-0 py-0" ng-repeat="boton in botonera">
44 <button 44 <button
45 type="button" 45 type="button"
46 class="btn btn-default btn-block btn-xs text-left py-2" 46 class="btn btn-default btn-block btn-xs text-left py-2"
47 ng-click="boton.accion()" 47 ng-click="boton.accion()"
48 ng-class="{'d-none d-sm-block': boton.texto == ''}" 48 ng-class="{'d-none d-sm-block': boton.texto == ''}"
49 > 49 >
50 <i 50 <i
51 class="fa fa-arrow-circle-right" 51 class="fa fa-arrow-circle-right"
52 ng-show="boton.texto != ''" 52 ng-show="boton.texto != ''"
53 ></i> 53 ></i>
54 &nbsp; 54 &nbsp;
55 {{boton.texto}} 55 {{boton.texto}}
56 </button> 56 </button>
57 </div> 57 </div>
58 </div> 58 </div>
59 </div> 59 </div>
60 </div> 60 </div>
61 </div> 61 </div>
62 <div class="col-12 col-md-10 col-lg-8 offset-md-1 offset-lg-2"> 62 <div class="col-12 col-md-10 col-lg-8 offset-md-1 offset-lg-2 mb-5">
63 <div class="row grilla-articulo"> 63 <div ng-hide="hojaRuta.abierta" class="row">
64 <table ng-hide="hojaRuta.abierta" class="table table-responsive table-striped table-sm table-dark"> 64 <div class="col p-0">
65 <thead> 65 <table class="table table-striped table-sm table-dark">
66 <tr> 66 <thead>
67 <th>#</th> 67 <tr>
68 <th>Número</th> 68 <th class="align-middle">#</th>
69 <th>Razon Social</th> 69 <th class="align-middle">Número</th>
70 <th>Domicilio</th> 70 <th class="align-middle">Razon Social</th>
71 <th>&nbsp;</th> 71 <th class="align-middle" colspan="2">Domicilio</th>
72 </tr> 72 </tr>
73 </thead> 73 </thead>
74 <tbody class="tabla-articulo-body"> 74 <tbody class="tabla-articulo-body">
75 <tr 75 <tr
76 ng-repeat="(key, remito) in hojaRuta.remitos" 76 ng-repeat="(key, remito) in hojaRuta.remitos"
77 > 77 >
78 <td ng-bind="key + 1"></td> 78 <td class="align-middle" ng-bind="key + 1"></td>
79 <td 79 <td
80 ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante" 80 class="align-middle"
81 ></td> 81 ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"
82 <td ng-bind="remito.nombreCliente"></td> 82 ></td>
83 <td ng-bind="remito.domicilioStamp"></td> 83 <td class="align-middle" ng-bind="remito.nombreCliente"></td>
84 <td> 84 <td class="align-middle" ng-bind="remito.domicilioStamp"></td>
85 <button 85 <td class="align-middle">
86 class="btn btn-secondary" 86 <div class="btn-group-vertical">
87 type="button" 87 <button
88 ng-click="verDetalle(remito)" 88 class="btn btn-secondary my-1 rounded"
89 ><i class="fa fa-search" aria-hidden="true"></i> 89 type="button"
90 </button> 90 ng-click="verDetalle(remito)">
91 </td> 91 <i class="fa fa-search" aria-hidden="true"></i>
92 </tr> 92 </button>
93 </tbody> 93 <button
94 </table> 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 </div> 111 </div>
96 <div ng-show="hojaRuta.abierta" class="row grilla-articulo"> 112 <div ng-show="hojaRuta.abierta" class="row grilla-articulo">
97 <table class="table table-striped table-sm table-dark"> 113 <div class="col p-0">
98 <thead> 114 <table class="table table-striped table-sm table-dark">
99 <tr> 115 <thead>
100 <th colspan="3" class="text-center">Remito abierto Nº 116 <tr>
101 {{[hojaRuta.remitos[0].sucursal, hojaRuta.remitos[0].numeroRemito] | comprobante}} 117 <th colspan="3" class="text-center">Remito abierto Nº
102 </th> 118 {{[hojaRuta.remitos[0].sucursal, hojaRuta.remitos[0].numeroRemito] | comprobante}}
103 </tr> 119 </th>
104 <tr> 120 </tr>
105 <th>Cisterna</th> 121 <tr>
106 <th>Producto</th> 122 <th>Cisterna</th>
107 <th>Disponibles</th> 123 <th>Producto</th>
108 </tr> 124 <th>Disponibles</th>
109 </thead> 125 </tr>
110 <tbody> 126 </thead>
111 <tr ng-repeat="cisterna in hojaRuta.remitos[0].cisternas"> 127 <tbody>
112 <td ng-bind="cisterna.codigo"></td> 128 <tr ng-repeat="cisterna in hojaRuta.remitos[0].cisternas">
113 <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td> 129 <td ng-bind="cisterna.codigo"></td>
114 <td ng-bind="cisterna.cisternaCarga.cantidad"></td> 130 <td ng-bind="cisterna.cisternaCarga.articulo.DetArt"></td>
115 </tr> 131 <td ng-bind="cisterna.cisternaCarga.cantidad"></td>
116 </tbody> 132 </tr>
117 </table> 133 </tbody>
134 </table>
135 </div>
118 <table class="table table-striped table-sm table-dark"> 136 <table class="table table-striped table-sm table-dark">
119 <thead> 137 <thead>
120 <tr> 138 <tr>
121 <th>Descarga en cliente</th> 139 <th>Descarga en cliente</th>
122 <th> 140 <th>
123 <button class="btn btn-outline-debo" ng-click="modalDescargas()"> 141 <button class="btn btn-outline-debo" ng-click="modalDescargas()">
124 <i class="fa fa-plus"></i> 142 <i class="fa fa-plus"></i>
125 </button> 143 </button>
126 </th> 144 </th>
127 </tr> 145 </tr>
128 <tr></tr> 146 <tr></tr>
129 </thead> 147 </thead>
130 <tbody> 148 <tbody>
131 <tr ng-repeat="remito in remitos"></tr> 149 <tr ng-repeat="remito in remitos"></tr>
132 </tbody> 150 </tbody>
133 </table> 151 </table>
134 </div> 152 </div>
135 </div> 153 </div>
136 <div class="row d-md-none fixed-bottom"> 154 <div class="row d-md-none fixed-bottom">
137 <div class="w-100 bg-dark d-flex px-3 acciones-mobile"> 155 <div class="w-100 bg-dark d-flex px-3 acciones-mobile">
138 <span class="ml-3 text-muted" ng-click="salir()">Salir</span> 156 <span class="ml-3 text-muted" ng-click="salir()">Salir</span>
139 <span 157 <span
140 class="mr-3 ml-auto" 158 class="mr-3 ml-auto"
141 ng-click="terminarHojaRuta()" 159 ng-click="estaPendiente()"
142 ladda="saveLoading" 160 ladda="saveLoading"
143 data-style="expand-left" 161 data-style="expand-left"
144 >Terminar</span> 162 >Terminar</span>
145 </div> 163 </div>
146 </div> 164 </div>
147 </div> 165 </div>
148 166