Commit af23c9133666b4a1f52b8ea6ebaffed37dd4e8e5

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !21
src/js/controller.js
... ... @@ -14,7 +14,7 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo
14 14 };
15 15 var fecha = {
16 16 label: 'Fecha Reparto',
17   - image: 'abmChofer.png'
  17 + image: 'fechaDeReparto.png'
18 18 };
19 19 $scope.botonera = [fecha, transportista];
20 20 var cabecera = '';
... ... @@ -76,6 +76,21 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo
76 76 };
77 77  
78 78 $scope.quitarVehiculo = function(vehiculo) {
  79 + //TODO: Pasar validación a función
  80 + $scope.fechaReparto.setHours(0, 0, 0, 0);
  81 + var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
  82 + for(var i = 0; i < vehiculo.cisternas.length; i++) {
  83 + for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
  84 + var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
  85 + if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
  86 + .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
  87 + idUsuario)
  88 + {
  89 + focaModalService.alert('El vehículo está siendo usado por otro usuario');
  90 + return;
  91 + }
  92 + }
  93 + }
79 94 focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' +
80 95 vehiculo.codigo + '?').then(function() {
81 96 eliminarVehiculo(vehiculo);
... ... @@ -87,6 +102,21 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;) .controller(&#39;focaLogisticaPedidoRutaCo
87 102 focaModalService.alert('Primero seleccione fecha de reparto');
88 103 return;
89 104 }
  105 + //TODO: Pasar validación a función
  106 + $scope.fechaReparto.setHours(0, 0, 0, 0);
  107 + var idUsuario = focaLogisticaPedidoRutaService.idUsuario;
  108 + for(var i = 0; i < vehiculo.cisternas.length; i++) {
  109 + for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
  110 + var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
  111 + if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
  112 + .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso !==
  113 + idUsuario)
  114 + {
  115 + focaModalService.alert('El vehículo está siendo usado por otro usuario');
  116 + return;
  117 + }
  118 + }
  119 + }
90 120 var modalInstance = $uibModal.open(
91 121 {
92 122 ariaLabelledBy: 'Creación hoja ruta',
src/js/controllerCerrarVehiculo.js
... ... @@ -13,13 +13,11 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
13 13 $scope.remitos = [];
14 14 $scope.now = new Date();
15 15 focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) {
16   - $scope.vehiculo = res.data;
  16 + $scope.vehiculo = res.data;
17 17 });
18   - //TODO: refactor código esta rre feo
19 18 focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) {
20 19 $scope.remitos = focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data);
21 20 });
22   -
23 21 focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) {
24 22 $scope.sucursal = res.data.sucursal;
25 23 $scope.numero = res.data.numeroHojaRuta;
... ... @@ -28,22 +26,19 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
28 26 $uibModalInstance.close();
29 27 };
30 28 $scope.aceptar = function() {
31   - var save = {
32   - hojaRuta: {
33   - id: 0,
34   - fechaCreacion: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
35   - idTransportista: $scope.vehiculo.idTransportista,
36   - idChofer: $scope.chofer.id,
37   - idVehiculo: $scope.vehiculo.id,
38   - tarifaFlete: $scope.tarifaFlete
39   - },
40   - remitos: $scope.remitos,
41   - idVehiculo: $scope.vehiculo.id
42   - };
43   - focaLogisticaPedidoRutaService.crearHojaRuta(save).then(function() {
44   - $uibModalInstance.close();
45   - focaModalService.alert('Hoja de ruta guardada con éxito');
  29 + var idsRemito = [];
  30 + $scope.remitos.forEach(function(remito) {
  31 + idsRemito.push(remito.id);
46 32 });
  33 + var cierreDistribuicion = {
  34 + idsRemito: idsRemito,
  35 + fechaReparto: focaLogisticaPedidoRutaService.fecha
  36 + };
  37 + focaLogisticaPedidoRutaService.cerrarDistribuicion(cierreDistribuicion)
  38 + .then(function() {
  39 + focaModalService.alert('Vehículo cerrado con éxito');
  40 + }
  41 + );
47 42 };
48 43 $scope.seleccionarChofer = function() {
49 44 var modalInstance = $uibModal.open(
src/js/controllerDetalleVehiculo.js
... ... @@ -39,16 +39,30 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
39 39 }
40 40 $scope.articulos = $scope.remito.articulosRemito;
41 41 $scope.seleccionarArticulo($scope.articulos[0]);
  42 + var tieneUsuario = $scope.cisternas.filter(function(cisterna) {
  43 + if(cisterna.cisternaCarga) {
  44 + return cisterna.cisternaCarga.idUsuarioProceso !==
  45 + focaLogisticaPedidoRutaService.idUsuario;
  46 + }
  47 + });
  48 + if(tieneUsuario.length) {
  49 + focaModalService.alert('Otro usario esta usando este vehículo');
  50 + $uibModalInstance.close();
  51 + return;
  52 + }
42 53 });
43 54 $scope.aceptar = function() {
44 55 $scope.cargando = true;
45 56 for(var i = 0; i < $scope.cisternasCarga.length; i++) {
  57 + $scope.cisternasCarga[i].idUsuarioProceso =
  58 + focaLogisticaPedidoRutaService.idUsuario;
46 59 delete $scope.cisternasCarga[i].articulo;
47 60 }
48 61 var cisterna = {
49 62 cisternaMovimientos: cisternaMovimientos,
50 63 cisternaCargas: $scope.cisternasCarga,
51   - idVehiculo: $scope.vehiculo.id
  64 + idVehiculo: $scope.vehiculo.id,
  65 + fechaReparto: focaLogisticaPedidoRutaService.fecha
52 66 };
53 67 focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id)
54 68 .then(function() {
... ... @@ -59,11 +73,8 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
59 73 }).catch(function(error) {
60 74 $scope.cargando = false;
61 75 $uibModalInstance.close();
62   - if (error.status === 403.1) {
63   - focaModalService.alert('ERROR: El vehículo esta en uso');
64   - }
65   - if(error.status === 403.2) {
66   - focaModalService.alert('ERROR: Otro usario ya cargó este remito');
  76 + if (error.status === 403) {
  77 + focaModalService.alert('ERROR: ' + error.data);
67 78 return;
68 79 }
69 80 focaModalService.alert('Hubo un error al cargar las cisternas');
... ... @@ -6,36 +6,37 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
6 6 'API_ENDPOINT',
7 7 '$filter',
8 8 function($http, $cookies, API_ENDPOINT, $filter) {
  9 + var url = API_ENDPOINT.URL;
9 10 return {
10 11 idUsuario: $cookies.get('idUsuario'),
11 12 obtenerActividad: function(parametros) {
12   - return $http.post(API_ENDPOINT.URL + '/seguimiento/filtros', parametros);
  13 + return $http.post(url + '/seguimiento/filtros', parametros);
13 14 },
14 15 obtenerVehiculoById: function(idVehiculo) {
15   - return $http.get(API_ENDPOINT.URL + '/vehiculo/' + idVehiculo);
  16 + return $http.get(url + '/vehiculo/' + idVehiculo);
16 17 },
17 18 obtenerRemitoById: function(idRemito) {
18   - return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito);
  19 + return $http.get(url + '/remito/obtener/' + idRemito);
19 20 },
20 21 guardarCisternas: function(cisterna, idRemito) {
21   - return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' +
  22 + return $http.post(url + '/cisterna/guardar/cargar/' +
22 23 this.idUsuario + '/' + idRemito,cisterna);
23 24 },
24 25 numeroHojaRuta: function() {
25   - return $http.get(API_ENDPOINT.URL + '/hoja-ruta/numero-siguiente');
  26 + return $http.get(url + '/hoja-ruta/numero-siguiente');
26 27 },
27 28 getRemitos: function(idVehiculo) {
28   - return $http.get(API_ENDPOINT.URL + '/remito/sin-hoja-ruta/' +idVehiculo);
  29 + return $http.get(url + '/remito/sin-hoja-ruta/' +idVehiculo);
29 30 },
30   - crearHojaRuta: function(hojaRuta) {
31   - return $http.post(API_ENDPOINT.URL + '/hoja-ruta', hojaRuta);
  31 + cerrarDistribuicion: function(remitos) {
  32 + return $http.post(url + '/vehiculo/cierre-distribuicion', remitos);
32 33 },
33 34 desasociarRemitos: function(remitos, idVehiculo, sinRemitos) {
34 35 var idsRemitos = [];
35 36 for (var i = 0; i < remitos.length; i++) {
36 37 idsRemitos.push(remitos[i].id);
37 38 }
38   - return $http.post(API_ENDPOINT.URL + '/vehiculo/desasociar-remitos',
  39 + return $http.post(url + '/vehiculo/desasociar-remitos',
39 40 {
40 41 idsRemitos: idsRemitos,
41 42 idVehiculo: idVehiculo,
... ... @@ -53,7 +54,8 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
53 54 .length; k++)
54 55 {
55 56 if(cisterna.cisternasCarga[j].fechaReparto.substring(0, 10) ===
56   - fecha.substring(0, 10))
  57 + fecha.substring(0, 10) && !cisterna.cisternasCarga[j]
  58 + .confirmado)
57 59 {
58 60 procesoMovimiento(cisterna.cisternasCarga[j]
59 61 .cisternaMovimientos[k]);
... ... @@ -74,18 +76,18 @@ angular.module(&#39;focaLogisticaPedidoRuta&#39;)
74 76 return remitosRes;
75 77 },
76 78 getVehiculosByIdUsuario: function() {
77   - return $http.get(API_ENDPOINT.URL + '/vehiculo/usuario/' + this.idUsuario);
  79 + return $http.get(url + '/vehiculo/usuario/' + this.idUsuario);
78 80 },
79 81 obtenerCisternasPorFecha: function(idVehiculo) {
80   - return $http.post(API_ENDPOINT.URL + '/cisterna/listar/fecha',
  82 + return $http.post(url + '/cisterna/listar/fecha',
81 83 {idVehiculo: idVehiculo, fechaReparto: this.fecha});
82 84 },
83 85 getUnidadesByFecha: function() {
84   - return $http.post(API_ENDPOINT.URL + '/vehiculo/listar/fecha',
  86 + return $http.post(url + '/vehiculo/listar/fecha',
85 87 {fecha: this.fecha});
86 88 },
87 89 setFechaReparto: function(fechaReparto) {
88 90 this.fecha = fechaReparto;
89   - }
  91 + },
90 92 };
91 93 }]);
src/views/foca-logistica-pedido-ruta.html
... ... @@ -50,29 +50,6 @@
50 50 ng-focus="fechaHastaOpen = true"
51 51 ng-change="search()"
52 52 />
53   - <!-- TODO: descomentar cuando se quite definitivamente -->
54   - <!-- <button
55   - type="button"
56   - ng-class="{'active': idVendedor == 0}"
57   - class="btn col-12 my-1"
58   - ng-click="general()"
59   - >General</button>
60   - <button
61   - type="button"
62   - ng-class="{'active': idVendedor != 0}"
63   - class="btn col-12 my-1"
64   - ng-click="individual()"
65   - >Individual</button>
66   - <div class="form-group" ng-show="idVendedor == -1">
67   - <input
68   - type="text"
69   - placeholder="Vendedor"
70   - class="form-control"
71   - ng-model="idVendedorInput"
72   - ng-keypress="search($event.keyCode)"
73   - foca-focus="idVendedor == -1"
74   - >
75   - </div> -->
76 53 <div class="custom-control custom-radio">
77 54 <input
78 55 type="radio"
src/views/foca-modal-cerrar-vehiculo.html
... ... @@ -48,6 +48,7 @@
48 48 <th>Remito Nº</th>
49 49 <th>Cliente</th>
50 50 <th>Domicilio de entrega</th>
  51 + <th>Eliminar</th>
51 52 </tr>
52 53 </thead>
53 54 <tbody>
... ... @@ -89,6 +90,6 @@
89 90 class="btn btn-sm btn-primary"
90 91 ladda="cargando"
91 92 type="button"
92   - ng-disabled="!formHojaRuta.$valid || !remitos.length || true"
  93 + ng-disabled="!formHojaRuta.$valid || !remitos.length"
93 94 ng-click="aceptar()">Cerrar distribución</button>
94 95 </div>