Commit 893f1d249cc4d13411fc5e360302984839e83205

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !6
src/js/controller.js
1 angular.module('focaEstadoCisternas') 1 angular.module('focaEstadoCisternas')
2 .controller('focaEstadoCisternasController', [ 2 .controller('focaEstadoCisternasController', [
3 '$scope', 'focaEstadoCisternasService', 'focaModalService', 3 '$scope', 'focaEstadoCisternasService', 'focaModalService',
4 '$uibModal', 'focaBotoneraLateralService', '$timeout', 4 '$uibModal', 'focaBotoneraLateralService', '$timeout',
5 function($scope, focaEstadoCisternasService, focaModalService, 5 function($scope, focaEstadoCisternasService, focaModalService,
6 $uibModal, focaBotoneraLateralService, $timeout) { 6 $uibModal, focaBotoneraLateralService, $timeout) {
7 7
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.fecha = new Date(); 9 $scope.fecha = new Date();
10 $scope.cisternas = []; 10 $scope.cisternas = [];
11 $scope.botonera = focaEstadoCisternasService.getBotonera(); 11 $scope.botonera = focaEstadoCisternasService.getBotonera();
12 12
13 //SETEO BOTONERA LATERAL 13 //SETEO BOTONERA LATERAL
14 focaBotoneraLateralService.showSalir(true); 14 focaBotoneraLateralService.showSalir(true);
15 focaBotoneraLateralService.showPausar(false); 15 focaBotoneraLateralService.showPausar(false);
16 focaBotoneraLateralService.showCancelar(false); 16 focaBotoneraLateralService.showCancelar(false);
17 focaBotoneraLateralService.showGuardar(false); 17 focaBotoneraLateralService.showGuardar(false);
18 18
19 $timeout(function() { 19 $timeout(function() {
20 $scope.$broadcast('addCabecera', { 20 $scope.$broadcast('addCabecera', {
21 label: 'Fecha:', 21 label: 'Fecha:',
22 valor: $scope.fecha.toLocaleDateString() 22 valor: $scope.fecha.toLocaleDateString()
23 }); 23 });
24 }); 24 });
25 25
26 $scope.seleccionarTransportista = function() { 26 $scope.seleccionarTransportista = function() {
27 var modalInstance = $uibModal.open( 27 var modalInstance = $uibModal.open(
28 { 28 {
29 ariaLabelledBy: 'Busqueda de Transportista', 29 ariaLabelledBy: 'Busqueda de Transportista',
30 templateUrl: 'modal-proveedor.html', 30 templateUrl: 'modal-proveedor.html',
31 controller: 'focaModalProveedorCtrl', 31 controller: 'focaModalProveedorCtrl',
32 size: 'lg', 32 size: 'lg',
33 resolve: { 33 resolve: {
34 transportista: function() { 34 transportista: function() {
35 return true; 35 return true;
36 } 36 }
37 } 37 }
38 } 38 }
39 ); 39 );
40 return modalInstance.result; 40 return modalInstance.result;
41 }; 41 };
42 42
43 $scope.seleccionarVehiculo = function() { 43 $scope.seleccionarVehiculo = function() {
44 $scope.seleccionarTransportista().then( 44 $scope.seleccionarTransportista().then(
45 function(transportista) { 45 function(transportista) {
46 elegirTransportista(transportista); 46 elegirTransportista(transportista);
47 47
48 var query = '/vehiculo/transportista/' + $scope.idTransportista; 48 var parametrosModal = {
49 var columnas = { 49 columnas: [
50 nombre: ['Código', 'tractor', 'Semi', 'Capacidad'], 50 {
51 propiedad: ['codigo', 'tractor', 'semi', 'capacidadTotalCisternas'] 51 propiedad: 'codigo',
52 nombre: 'Código'
53 },
54 {
55 propiedad: 'tractor',
56 nombre: 'tractor'
57 },
58 {
59 propiedad: 'semi',
60 nombre: 'Semi'
61 },
62 {
63 propiedad: 'capacidadTotalCisternas',
64 nombre: 'Capacidad'
65 }
66 ],
67 query: '/vehiculo/transportista/' + transportista.COD,
68 titulo: 'Búsqueda de vehiculos',
69 subTitulo: transportista.COD + '-' + transportista.NOM
52 }; 70 };
53 var titulo = 'Búsqueda de vehículos';
54 71
55 focaModalService.modal(columnas, query, titulo).then( 72 focaModalService.modal(parametrosModal).then(
56 function(vehiculo) { 73 function(vehiculo) {
57 $scope.$broadcast('addCabecera', { 74 $scope.$broadcast('addCabecera', {
58 label: 'Vehículo:', 75 label: 'Vehículo:',
59 valor: vehiculo.codigo 76 valor: vehiculo.codigo
60 }); 77 });
61 $scope.cisternas = vehiculo.cisternas; 78 $scope.cisternas = vehiculo.cisternas;
62 getEstadosCisternas($scope.cisternas); 79 getEstadosCisternas($scope.cisternas);
63 }, function() { 80 }, function() {
64 $scope.seleccionarTransportista(); 81 $scope.seleccionarTransportista();
65 }); 82 });
66 }); 83 });
67 }; 84 };
68 85
69 $scope.seleccionarFechaEntrega = function() { 86 $scope.seleccionarFechaEntrega = function() {
70 focaModalService.modalFecha('Fecha').then(function(fecha) { 87 focaModalService.modalFecha('Fecha').then(function(fecha) {
71 $scope.$broadcast('addCabecera', { 88 $scope.$broadcast('addCabecera', {
72 label: 'Fecha:', 89 label: 'Fecha:',
73 valor: fecha.toLocaleDateString() 90 valor: fecha.toLocaleDateString()
74 }); 91 });
75 $scope.fecha = fecha; 92 $scope.fecha = fecha;
76 if($scope.cisternas) 93 if($scope.cisternas)
77 getEstadosCisternas($scope.cisternas); 94 getEstadosCisternas($scope.cisternas);
78 }); 95 });
79 }; 96 };
80 97
81 $scope.seleccionarGrafico = function() { 98 $scope.seleccionarGrafico = function() {
82 if(!$scope.cisternas.length){ 99 if(!$scope.cisternas.length){
83 focaModalService.alert('Primero seleccione un vehículo con cisternas'); 100 focaModalService.alert('Primero seleccione un vehículo con cisternas');
84 return; 101 return;
85 } 102 }
86 $uibModal.open( 103 $uibModal.open(
87 { 104 {
88 ariaLabelledBy: 'Grafico de cisternas', 105 ariaLabelledBy: 'Grafico de cisternas',
89 templateUrl: 'modal-grafico-cisternas.html', 106 templateUrl: 'modal-grafico-cisternas.html',
90 controller: 'focaModalGraficoCisternasController', 107 controller: 'focaModalGraficoCisternasController',
91 size: 'md', 108 size: 'md',
92 resolve:{ 109 resolve:{
93 filters: { 110 filters: {
94 cisternas: $scope.cisternas 111 cisternas: $scope.cisternas
95 } 112 }
96 } 113 }
97 } 114 }
98 ); 115 );
99 }; 116 };
100 117
101 function elegirTransportista(transportista) { 118 function elegirTransportista(transportista) {
102 var codigo = ('00000' + transportista.COD).slice(-5); 119 var codigo = ('00000' + transportista.COD).slice(-5);
103 $scope.idTransportista = transportista.COD; 120 $scope.idTransportista = transportista.COD;
104 $scope.filtros = transportista.NOM.trim(); 121 $scope.filtros = transportista.NOM.trim();
105 $scope.$broadcast('addCabecera', { 122 $scope.$broadcast('addCabecera', {
106 label: 'Transportista:', 123 label: 'Transportista:',
107 valor: codigo + ' - ' + transportista.NOM 124 valor: codigo + ' - ' + transportista.NOM
108 }); 125 });
109 } 126 }
110 127
111 function getEstadosCisternas(cisternas) { 128 function getEstadosCisternas(cisternas) {
112 cisternas.forEach(function(cisterna) { 129 cisternas.forEach(function(cisterna) {
113 focaEstadoCisternasService 130 focaEstadoCisternasService
114 .getEstadoCisterna(cisterna.id, $scope.fecha) 131 .getEstadoCisterna(cisterna.id, $scope.fecha)
115 .then(function(res) { 132 .then(function(res) {
116 cisterna.estado = res.data; 133 cisterna.estado = res.data;
117 }); 134 });
118 }); 135 });
119 } 136 }
120 } 137 }
121 ]); 138 ]);