Commit 79a4a484d0c518b79f888947605009ff65d64d1f

Authored by Marcelo Puebla
Exists in master

Merge branch 'develop' of git.focasoftware.com:npm/foca-crear-hoja-ruta

src/js/controller.js
... ... @@ -15,11 +15,13 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
15 15 function ($scope, $uibModal, $location, $filter, $timeout,
16 16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService,
17 17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) {
  18 +
18 19 config();
19 20  
20 21 function config() {
21 22  
22   - $scope.botoneraPrincipal = focaCrearHojaRutaService.getBotones();
  23 + $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal =
  24 + focaCrearHojaRutaService.getBotones();
23 25 $scope.botonera = [];
24 26 $scope.datepickerAbierto = false;
25 27 $scope.show = false;
... ... @@ -46,15 +48,25 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
46 48  
47 49 var parametros = JSON.parse(res.data[0].jsonText);
48 50  
49   - if ($localStorage.hojaRuta) {
50   - $timeout(function () { getLSHojaRuta(); });
  51 + $timeout(function () {
  52 + getLSBotoneraPrincipal();
  53 + });
  54 +
  55 + if ($localStorage.data) {
  56 + $timeout(function () {
  57 + getLSHojaRuta();
  58 + });
  59 +
51 60 } else {
52 61 for (var property in parametros) {
53 62 $scope.hojaRuta[property] = parametros[property];
54 63 $scope.inicial[property] = parametros[property];
55 64 }
56 65 //Setear Hoja de Ruta
57   - //setearHojaRuta($scope.hojaRuta);
  66 +
  67 + if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) {
  68 + setearHojaRuta($scope.hojaRuta);
  69 + }
58 70 }
59 71 });
60 72 init();
... ... @@ -84,41 +96,24 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
84 96 console.info(err);
85 97 }
86 98 );
87   - setearFecha(new Date());
88 99 $scope.inicial = angular.copy($scope.hojaRuta);
89 100 }
90 101  
91   - // $scope.$watch('hojaRuta', function(newValue) {
92   -
93   - // // Seteo checked en remitos
94   - // if ($scope.hojaRuta.remitosTabla.length) {
95   - // $filter('filter')($scope.botonera, {
96   - // label: 'Remitos',
97   - // })[0].checked = true;
98   - // } else {
99   - // $filter('filter')($scope.botonera, {
100   - // label: 'Remitos',
101   - // })[0].checked = false;
102   - // }
103   -
104   - // focaBotoneraLateralService.setPausarData({
105   - // label: 'hojaRuta',
106   - // val: newValue
107   - // });
108   - // }, true);
  102 + $scope.$watchGroup(['hojaRuta','precargado','cargaRemito','remitoAbierto'], function(newValues) {
  103 + focaBotoneraLateralService.setPausarData(
  104 + {
  105 + label: 'data',
  106 + val: newValues
  107 + }
  108 + );
  109 + });
109 110  
110 111 $scope.seleccionarRemitoAbierto = function () {
111 112 $scope.remitoAbierto = true;
112 113 $scope.cargaRemito = false;
113 114 $scope.precargado = false;
114 115  
115   - var isBotoneraDirty = $scope.botonera.find(function (boton) {
116   - return boton.checked;
117   - });
118   -
119   - config();
120   -
121   - if (isBotoneraDirty) {
  116 + if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
122 117 $scope.$broadcast('cleanCabecera');
123 118 focaModalService.confirm('Se perderan los cambios')
124 119 .then(function () {
... ... @@ -127,8 +122,10 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
127 122 $filter('filter')($scope.botoneraPrincipal, {
128 123 label: 'Remito Abierto',
129 124 })[0].checked = true;
130   - $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
131   -
  125 +
  126 + config();
  127 +
  128 + $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
132 129 });
133 130 } else {
134 131 $scope.$broadcast('cleanCabecera');
... ... @@ -136,25 +133,19 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
136 133 $filter('filter')($scope.botoneraPrincipal, {
137 134 label: 'Remito Abierto',
138 135 })[0].checked = true;
139   - $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
140   -
  136 +
  137 + config();
  138 +
  139 + $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
141 140 }
142   -
143   - $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
144 141 };
145 142  
146 143 $scope.seleccionarCargarRemitos = function () {
147 144 $scope.cargaRemito = true;
148 145 $scope.remitoAbierto = false;
149 146 $scope.precargado = false;
150   -
151   - var isBotoneraDirty = $scope.botonera.find(function (boton) {
152   - return boton.checked;
153   - });
154   -
155   - config();
156 147  
157   - if (isBotoneraDirty) {
  148 + if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
158 149 $scope.$broadcast('cleanCabecera');
159 150 focaModalService.confirm('Se perderan los cambios')
160 151 .then(function () {
... ... @@ -164,7 +155,10 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
164 155 $filter('filter')($scope.botoneraPrincipal, {
165 156 label: 'Cargar Remitos',
166 157 })[0].checked = true;
167   - $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  158 +
  159 + config();
  160 + // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  161 + $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
168 162 });
169 163 } else {
170 164 $scope.$broadcast('cleanCabecera');
... ... @@ -172,7 +166,9 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
172 166 $filter('filter')($scope.botoneraPrincipal, {
173 167 label: 'Cargar Remitos',
174 168 })[0].checked = true;
175   - $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  169 + config();
  170 + // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  171 + $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
176 172 }
177 173 $scope.precargado = false;
178 174 };
... ... @@ -181,13 +177,8 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
181 177 $scope.precargado = true;
182 178 $scope.cargaRemito = false;
183 179 $scope.remitoAbierto = false;
184   - var isBotoneraDirty = $scope.botonera.find(function (boton) {
185   - return boton.checked;
186   - });
187   -
188   - config();
189 180  
190   - if (isBotoneraDirty) {
  181 + if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
191 182 focaModalService.confirm('Se perderan los cambios')
192 183 .then(function () {
193 184 $scope.$broadcast('cleanCabecera');
... ... @@ -196,7 +187,10 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
196 187 $filter('filter')($scope.botoneraPrincipal, {
197 188 label: 'Precargado',
198 189 })[0].checked = true;
199   - $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  190 +
  191 + config();
  192 +
  193 + $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
200 194 });
201 195 } else {
202 196 $scope.$broadcast('cleanCabecera');
... ... @@ -204,7 +198,10 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
204 198 $filter('filter')($scope.botoneraPrincipal, {
205 199 label: 'Precargado',
206 200 })[0].checked = true;
207   - $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  201 +
  202 + config();
  203 +
  204 + $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
208 205 }
209 206 };
210 207  
... ... @@ -422,25 +419,25 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
422 419 }
423 420  
424 421 $scope.seleccionarCliente = function () {
425   - var modalInstance = $uibModal.open(
426   - {
427   - ariaLabelledBy: 'Busqueda de Cliente',
428   - templateUrl: 'foca-busqueda-cliente-modal.html',
429   - controller: 'focaBusquedaClienteModalController',
430   - resolve: {
431   - vendedor: function () { return null; },
432   - cobrador: function () { return null; }
433   - },
434   - size: 'lg'
435   - }
436   - );
437   - modalInstance.result.then(
438   - function (cliente) {
439   - $scope.abrirModalDomicilios(cliente);
440   - $scope.cliente = cliente;
441   - }, function () {
442   - }
443   - );
  422 + var modalInstance = $uibModal.open(
  423 + {
  424 + ariaLabelledBy: 'Busqueda de Cliente',
  425 + templateUrl: 'foca-busqueda-cliente-modal.html',
  426 + controller: 'focaBusquedaClienteModalController',
  427 + resolve: {
  428 + vendedor: function () { return null; },
  429 + cobrador: function () { return null; }
  430 + },
  431 + size: 'lg'
  432 + }
  433 + );
  434 + modalInstance.result.then(
  435 + function (cliente) {
  436 + $scope.abrirModalDomicilios(cliente);
  437 + $scope.cliente = cliente;
  438 + }, function () {
  439 + }
  440 + );
444 441 };
445 442  
446 443 $scope.abrirModalDomicilios = function (cliente) {
... ... @@ -611,7 +608,9 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
611 608 focaModalService.alert(
612 609 'Hoja ruta creada Nยบ: ' +
613 610 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
614   - $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8)
  611 + $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ' ' +
  612 + $filter('date')($scope.hojaRuta.fechaReparto, 'dd/MM/yyyy') + '-' +
  613 + $scope.hojaRuta.orden
615 614 );
616 615  
617 616 config();
... ... @@ -780,7 +779,9 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
780 779 };
781 780  
782 781 $scope.seleccionarRemitos = function () {
  782 +
783 783 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
  784 +
784 785 var modalInstance = $uibModal.open(
785 786 {
786 787 ariaLabelledBy: 'Busqueda de Remito',
... ... @@ -831,7 +832,7 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
831 832 })[0].checked = true;
832 833  
833 834 }, function (error) {
834   - error.then($scope.seleccionarRemitos);
  835 + $scope.seleccionarRemitos();
835 836 });
836 837 }, function () {
837 838 // funcion ejecutada cuando se cancela el modal
... ... @@ -855,7 +856,8 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
855 856 resolve: {
856 857 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; },
857 858 idRemito: function () { return idRemito; },
858   - fechaReparto: function () { return $scope.hojaRuta.fechaReparto; }
  859 + fechaReparto: function () { return $scope.hojaRuta.fechaReparto;},
  860 + orden: function() { return $scope.hojaRuta.orden }
859 861 }
860 862 }
861 863 );
... ... @@ -966,13 +968,19 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
966 968 };
967 969  
968 970 $scope.mostrarDetalle = function (hojasRutas) {
  971 +
969 972 var modalInstance =$uibModal.open(
970 973 {
971 974 ariaLabelledBy: '',
972 975 templateUrl: 'modal-detalle-carga.html',
973 976 controller: 'focaModalDetalleController',
974 977 resolve: {
975   - hojasRutas: function () { return hojasRutas; }
  978 + parametrosModal: function () {
  979 + return {
  980 + hojasRutas: hojasRutas,
  981 + orden: $scope.hojaRuta.orden
  982 + }
  983 + }
976 984 },
977 985 size: 'lg',
978 986 backdrop: false
... ... @@ -988,7 +996,7 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
988 996 $filter('filter')($scope.botonera, {
989 997 label: 'Detalle de Carga',
990 998 })[0].checked = true;
991   - }, function () {
  999 + }, function () {
992 1000 //se ejecuta cuando se cancela el modal
993 1001 });
994 1002 };
... ... @@ -1006,22 +1014,6 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
1006 1014 label: 'Fecha de entrega: ',
1007 1015 valor: fecha.toLocaleDateString()
1008 1016 });
1009   - //habilitar los otros botones
1010   - var temp = [];
1011   - if ($scope.botonera.length > 1) {
1012   - limpiarBotonera($scope.botonera);
1013   - } else if ($scope.precargado) {
1014   - temp = focaCrearHojaRutaService.getBotoneraPrecargado();
1015   - modalVehiculos(true);
1016   - } else if ($scope.cargaRemito && $scope.precargado === false) {
1017   - temp = focaCrearHojaRutaService.getBotoneraCargarRemito();
1018   - } else {
1019   - temp = focaCrearHojaRutaService.getBotoneraCargarRemito();
1020   - modalVehiculos(true);
1021   - }
1022   - temp.forEach(function (e) {
1023   - $scope.botonera.push(e);
1024   - });
1025 1017  
1026 1018 $filter('filter')($scope.botonera, {
1027 1019 label: 'Fecha Entrega',
... ... @@ -1054,6 +1046,7 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
1054 1046 }
1055 1047  
1056 1048 function modalVehiculos(preCargados) {
  1049 +
1057 1050 var parametrosModal = {};
1058 1051 if (preCargados) {
1059 1052 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
... ... @@ -1077,6 +1070,7 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
1077 1070 nombre: 'Semi'
1078 1071 }
1079 1072 ];
  1073 +
1080 1074 focaModalService.modal(parametrosModal).then(function (vehiculo) {
1081 1075 if (!preCargados && vehiculoEnUso(vehiculo)) return;
1082 1076 $scope.hojaRuta.vehiculo = vehiculo;
... ... @@ -1115,6 +1109,13 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
1115 1109 $scope.hojaRuta.remitosTabla = res.data;
1116 1110 });
1117 1111 }
  1112 +
  1113 + focaCrearHojaRutaService
  1114 + .getNumeroOrden(vehiculo.id, $scope.hojaRuta.fechaReparto)
  1115 + .then(function(res) {
  1116 + $scope.hojaRuta.orden = res.data;
  1117 + });
  1118 +
1118 1119 $scope.$broadcast('addCabecera', {
1119 1120 label: 'Tractor:',
1120 1121 valor: vehiculo.tractor
... ... @@ -1244,12 +1245,46 @@ angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
1244 1245 }
1245 1246  
1246 1247 function getLSHojaRuta() {
1247   - var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
  1248 + if ($localStorage.data === undefined) return;
  1249 +
  1250 + var hojaRuta = (JSON.parse($localStorage.data))[0] || null;
1248 1251 if (hojaRuta) {
1249 1252 setearHojaRuta(hojaRuta);
1250   - delete $localStorage.hojaRuta;
  1253 + delete $localStorage.data;
  1254 + }
  1255 + }
  1256 +
  1257 + function getLSBotoneraPrincipal() {
  1258 + if ($localStorage.data === undefined) return;
  1259 +
  1260 + var precargado = (JSON.parse($localStorage.data))[1] || null;
  1261 + var cargaRemito = (JSON.parse($localStorage.data))[2] || null;
  1262 + var remitoAbierto = (JSON.parse($localStorage.data))[3] || null;
  1263 + if (remitoAbierto) {
  1264 + $scope.remitoAbierto = remitoAbierto;
  1265 + $filter('filter')($scope.botoneraPrincipal, {
  1266 + label: 'Remito Abierto'
  1267 + })[0].checked = $scope.remitoAbierto;
  1268 + $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
  1269 + }
  1270 + if (precargado) {
  1271 + $scope.precargado = precargado;
  1272 + $filter('filter')($scope.botoneraPrincipal, {
  1273 + label: 'Precargados'
  1274 + })[0].checked = $scope.precargado;
  1275 + $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  1276 + Array.prototype.push.apply($scope.botonera,focaCrearHojaRutaService.getBotoneraPrecargado());
  1277 + }
  1278 + if (cargaRemito) {
  1279 + $scope.cargaRemito = cargaRemito;
  1280 + $filter('filter')($scope.botoneraPrincipal, {
  1281 + label: 'Cargar Remitos'
  1282 + })[0].checked = $scope.cargaRemito;
  1283 + $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
  1284 + Array.prototype.push.apply($scope.botonera,focaCrearHojaRutaService.getBotoneraCargarRemito());
1251 1285 }
1252 1286 }
  1287 +
1253 1288 function addArrayCabecera(array) {
1254 1289 for (var i = 0; i < array.length; i++) {
1255 1290 $scope.$broadcast('addCabecera', {
src/js/controllerDetalles.js
1 1 angular.module('focaCrearHojaRuta')
2 2 .controller('focaModalDetalleController', [
3 3 '$scope', '$timeout', '$uibModalInstance', 'focaModalService',
4   - 'focaCrearHojaRutaService', 'hojasRutas',
  4 + 'focaCrearHojaRutaService', 'parametrosModal',
5 5 function ($scope, $timeout, $uibModalInstance, focaModalService,
6   - focaCrearHojaRutaService, hojasRutas) {
  6 + focaCrearHojaRutaService, parametrosModal) {
7 7  
8 8 $scope.mostrar = false;
  9 + $scope.orden = parametrosModal.orden;
9 10 $scope.articulos = [];
10 11 $scope.cisternaMovimientos = [];
11 12  
12 13 init();
13 14 function init() {
14   - $scope.hojasRutas = hojasRutas;
  15 + $scope.hojasRutas = parametrosModal.hojasRutas;
15 16  
16 17 $scope.hojasRutas.vehiculo.cisternas = $scope.hojasRutas.vehiculo.cisternas.filter(
17 18 function (cisterna) {
... ... @@ -98,19 +99,20 @@ angular.module(&#39;focaCrearHojaRuta&#39;)
98 99  
99 100 var fechaReparto = $scope.hojasRutas.fechaReparto;
100 101  
101   - var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) {
102   - return carga.fechaReparto === fechaReparto;
103   - });
  102 + // var filtroCisternaCarga = cisterna.cisternasCarga.filter(function(carga) {
  103 + // return carga.fechaReparto === fechaReparto;
  104 + // });
104 105  
105   - if (filtroCisternaCarga.length) {
106   - cisterna.cisternaCarga = filtroCisternaCarga[0];
107   - } else {
  106 + // if (filtroCisternaCarga.length) {
  107 + // cisterna.cisternaCarga = filtroCisternaCarga[0];
  108 + // } else {
108 109 cisterna.cisternaCarga = {
109 110 confirmado: null,
110 111 fechaReparto: fechaReparto,
111 112 idCisterna: cisterna.id,
  113 + orden: $scope.orden
112 114 };
113   - }
  115 + // }
114 116  
115 117 //cargar
116 118 if (cisterna.cisternaCarga.cantidad) {
... ... @@ -175,17 +175,12 @@ angular.module(&#39;focaCrearHojaRuta&#39;)
175 175 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' +
176 176 idDomicilio + '/' + idCliente);
177 177 },
178   - getBotonFecha : function () {
  178 + getBotoneraPrecargado: function () {
179 179 return [
180 180 {
181 181 label: 'Fecha Entrega',
182 182 image: 'FechaEntrega.png'
183 183 },
184   - ];
185   - },
186   - getBotoneraPrecargado: function () {
187   - return [
188   -
189 184 {
190 185 label: 'Transportista',
191 186 image: 'transportista.png'
... ... @@ -195,7 +190,7 @@ angular.module(&#39;focaCrearHojaRuta&#39;)
195 190 image: 'chofer.png'
196 191 },
197 192 {
198   - label: 'Vehiculo',
  193 + label: 'VehiculosPrecargados',
199 194 image: 'vehiculos.png'
200 195 },
201 196 {
... ... @@ -211,6 +206,10 @@ angular.module(&#39;focaCrearHojaRuta&#39;)
211 206 getBotoneraCargarRemito: function () {
212 207 return [
213 208 {
  209 + label: 'Fecha Entrega',
  210 + image: 'FechaEntrega.png'
  211 + },
  212 + {
214 213 label: 'Transportista',
215 214 image: 'transportista.png'
216 215 },
... ... @@ -248,6 +247,10 @@ angular.module(&#39;focaCrearHojaRuta&#39;)
248 247 crearArticulosParaRemito: function(articuloRemito) {
249 248 return $http.post(route + '/articulos/remito',
250 249 {articuloRemito: articuloRemito});
  250 + },
  251 + getNumeroOrden: function(idVehiculo, fecha) {
  252 + return $http.get(route + '/hoja-ruta/obtener/numero-orden/' +
  253 + idVehiculo + '/' + fecha.toISOString().slice(0, 10));
251 254 }
252 255 };
253 256 }]);