Commit 8a4d6cf29c72dfedfee1445ede4663ca9a363c56

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master(mpuebla)

See merge request !68
1 { 1 {
2 "name": "foca-crear-hoja-ruta", 2 "name": "foca-crear-hoja-ruta",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "foca-crear-hoja-ruta", 4 "description": "foca-crear-hoja-ruta",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {
7 "refresh" : "gulp uglify && cp tmp/foca-crear-hoja-ruta.js ../wrapper-demo/node_modules/foca-crear-hoja-ruta/dist/foca-crear-hoja-ruta.min.js",
7 "test": "test.html", 8 "test": "test.html",
8 "compile": "gulp uglify", 9 "compile": "gulp uglify",
9 "gulp-pre-commit": "gulp pre-commit", 10 "gulp-pre-commit": "gulp pre-commit",
10 "postinstall": "npm run compile && gulp clean-post-install", 11 "postinstall": "npm run compile && gulp clean-post-install",
11 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-botonera-facturador.git git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-remito.git" 12 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-botonera-facturador.git git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-remito.git"
12 }, 13 },
13 "pre-commit": [ 14 "pre-commit": [
14 "gulp-pre-commit" 15 "gulp-pre-commit"
15 ], 16 ],
16 "repository": { 17 "repository": {
17 "type": "git", 18 "type": "git",
18 "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git" 19 "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git"
19 }, 20 },
20 "author": "Foca Software", 21 "author": "Foca Software",
21 "license": "ISC", 22 "license": "ISC",
22 "devDependencies": { 23 "devDependencies": {
23 "angular": "^1.7.5", 24 "angular": "^1.7.5",
24 "angular-ladda": "^0.4.3", 25 "angular-ladda": "^0.4.3",
25 "angular-mocks": "^1.7.7", 26 "angular-mocks": "^1.7.7",
26 "angular-route": "^1.7.5", 27 "angular-route": "^1.7.5",
27 "bootstrap": "^4.1.3", 28 "bootstrap": "^4.1.3",
28 "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", 29 "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git",
29 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", 30 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git",
30 "foca-modal-remito": "git+http://git.focasoftware.com/npm/foca-modal-remito.git", 31 "foca-modal-remito": "git+http://git.focasoftware.com/npm/foca-modal-remito.git",
31 "font-awesome": "^4.7.0", 32 "font-awesome": "^4.7.0",
32 "gulp": "^3.9.1", 33 "gulp": "^3.9.1",
33 "gulp-angular-templatecache": "^2.2.5", 34 "gulp-angular-templatecache": "^2.2.5",
34 "gulp-clean": "^0.4.0", 35 "gulp-clean": "^0.4.0",
35 "gulp-concat": "^2.6.1", 36 "gulp-concat": "^2.6.1",
36 "gulp-connect": "^5.6.1", 37 "gulp-connect": "^5.6.1",
37 "gulp-htmlmin": "^5.0.1", 38 "gulp-htmlmin": "^5.0.1",
38 "gulp-jshint": "^2.1.0", 39 "gulp-jshint": "^2.1.0",
39 "gulp-rename": "^1.4.0", 40 "gulp-rename": "^1.4.0",
40 "gulp-replace": "^1.0.0", 41 "gulp-replace": "^1.0.0",
41 "gulp-sequence": "^1.0.0", 42 "gulp-sequence": "^1.0.0",
42 "gulp-uglify": "^3.0.1", 43 "gulp-uglify": "^3.0.1",
43 "jasmine-core": "^3.3.0", 44 "jasmine-core": "^3.3.0",
44 "jquery": "^3.3.1", 45 "jquery": "^3.3.1",
45 "jshint": "^2.9.6", 46 "jshint": "^2.9.6",
46 "ladda": "1.0.6", 47 "ladda": "1.0.6",
47 "pre-commit": "^1.2.2", 48 "pre-commit": "^1.2.2",
48 "pump": "^3.0.0", 49 "pump": "^3.0.0",
49 "ui-bootstrap4": "^3.0.5" 50 "ui-bootstrap4": "^3.0.5"
50 } 51 }
51 } 52 }
52 53
src/js/controller.js
1 angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl', 1 angular.module('focaCrearHojaRuta').controller('hojaRutaCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'focaCrearHojaRutaService', 8 'focaCrearHojaRutaService',
9 'focaModalService', 9 'focaModalService',
10 'focaBotoneraLateralService', 10 'focaBotoneraLateralService',
11 'focaLoginService', 11 'focaLoginService',
12 '$localStorage', 12 '$localStorage',
13 'hojaRutaBusinessService', 13 'hojaRutaBusinessService',
14 '$cookies', 14 '$cookies',
15 function ($scope, $uibModal, $location, $filter, $timeout, 15 function ($scope, $uibModal, $location, $filter, $timeout,
16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, 16 focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService,
17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) { 17 focaLoginSrv, $localStorage, hojaRutaBusinessService, $cookies) {
18 18
19 config(); 19 config();
20 20
21 function config() { 21 function config() {
22 22
23 $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal = 23 $scope.botoneraPrincipal ? false : $scope.botoneraPrincipal =
24 focaCrearHojaRutaService.getBotones(); 24 focaCrearHojaRutaService.getBotones();
25 $scope.botonera = []; 25 $scope.botonera = [];
26 $scope.datepickerAbierto = false; 26 $scope.datepickerAbierto = false;
27 $scope.show = false; 27 $scope.show = false;
28 $scope.cisternaCargas = []; 28 $scope.cisternaCargas = [];
29 $scope.cargando = true; 29 $scope.cargando = true;
30 $scope.articulos = []; 30 $scope.articulos = [];
31 $scope.remito = { 31 $scope.remito = {
32 id: '', 32 id: '',
33 numeroRemito: '' 33 numeroRemito: ''
34 }; 34 };
35 $scope.now = new Date(); 35 $scope.now = new Date();
36 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 36 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
37 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 37 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
38 38
39 //SETEO BOTONERA LATERAL 39 //SETEO BOTONERA LATERAL
40 $timeout(function () { 40 $timeout(function () {
41 focaBotoneraLateralService.showSalir(false); 41 focaBotoneraLateralService.showSalir(false);
42 focaBotoneraLateralService.showPausar(true); 42 focaBotoneraLateralService.showPausar(true);
43 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); 43 focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta);
44 focaBotoneraLateralService.addCustomButton('Salir', salir); 44 focaBotoneraLateralService.addCustomButton('Salir', salir);
45 }); 45 });
46 46
47 focaCrearHojaRutaService.getParametros().then(function (res) { 47 focaCrearHojaRutaService.getParametros().then(function (res) {
48 48
49 var parametros = JSON.parse(res.data[0].jsonText); 49 var parametros = JSON.parse(res.data[0].jsonText);
50 50
51 $timeout(function () { 51 $timeout(function () {
52 getLSBotoneraPrincipal(); 52 getLSBotoneraPrincipal();
53 }); 53 });
54 54
55 if ($localStorage.data) { 55 if ($localStorage.data) {
56 $timeout(function () { 56 $timeout(function () {
57 getLSHojaRuta(); 57 getLSHojaRuta();
58 }); 58 });
59 59
60 } else { 60 } else {
61 for (var property in parametros) { 61 for (var property in parametros) {
62 $scope.hojaRuta[property] = parametros[property]; 62 $scope.hojaRuta[property] = parametros[property];
63 $scope.inicial[property] = parametros[property]; 63 $scope.inicial[property] = parametros[property];
64 } 64 }
65 //Setear Hoja de Ruta 65 //Setear Hoja de Ruta
66 66
67 if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) { 67 if ($scope.remitoAbierto || $scope.cargaRemito || $scope.precargado) {
68 setearHojaRuta($scope.hojaRuta); 68 setearHojaRuta($scope.hojaRuta);
69 } 69 }
70 } 70 }
71 }); 71 });
72 init(); 72 init();
73 } 73 }
74 function init() { 74 function init() {
75 $scope.$broadcast('cleanCabecera'); 75 $scope.$broadcast('cleanCabecera');
76 76
77 $scope.hojaRuta = { 77 $scope.hojaRuta = {
78 fecha: new Date(), 78 fecha: new Date(),
79 litros: 0, 79 litros: 0,
80 chofer: {}, 80 chofer: {},
81 vehiculo: { 81 vehiculo: {
82 capacidad: 0 82 capacidad: 0
83 }, 83 },
84 transportista: {}, 84 transportista: {},
85 remitosTabla: [] 85 remitosTabla: []
86 }; 86 };
87 $scope.idLista = undefined; 87 $scope.idLista = undefined;
88 88
89 focaCrearHojaRutaService.getNumeroHojaRuta().then( 89 focaCrearHojaRutaService.getNumeroHojaRuta().then(
90 function (res) { 90 function (res) {
91 $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); 91 $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4);
92 $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); 92 $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8);
93 }, 93 },
94 function (err) { 94 function (err) {
95 focaModalService.alert('La terminal no esta configurada correctamente'); 95 focaModalService.alert('La terminal no esta configurada correctamente');
96 console.info(err); 96 console.info(err);
97 } 97 }
98 ); 98 );
99 $scope.inicial = angular.copy($scope.hojaRuta); 99 $scope.inicial = angular.copy($scope.hojaRuta);
100 } 100 }
101 101
102 $scope.$watchGroup(['hojaRuta','precargado','cargaRemito','remitoAbierto'], function(newValues) { 102 $scope.$watchGroup(['hojaRuta', 'precargado', 'cargaRemito', 'remitoAbierto'],
103 focaBotoneraLateralService.setPausarData( 103 function (newValues) {
104 { 104 focaBotoneraLateralService.setPausarData(
105 label: 'data', 105 {
106 val: newValues 106 label: 'data',
107 } 107 val: newValues
108 ); 108 }
109 }); 109 );
110 });
110 111
111 $scope.seleccionarRemitoAbierto = function () { 112 $scope.seleccionarRemitoAbierto = function () {
112 $scope.remitoAbierto = true; 113 $scope.remitoAbierto = true;
113 $scope.cargaRemito = false; 114 $scope.cargaRemito = false;
114 $scope.precargado = false; 115 $scope.precargado = false;
115 116
116 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 117 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
117 $scope.$broadcast('cleanCabecera'); 118 $scope.$broadcast('cleanCabecera');
118 focaModalService.confirm('Se perderan los cambios') 119 focaModalService.confirm('Se perderan los cambios')
119 .then(function () { 120 .then(function () {
120 limpiarBotonera($scope.botonera); 121 limpiarBotonera($scope.botonera);
121 limpiarBotonera($scope.botoneraPrincipal); 122 limpiarBotonera($scope.botoneraPrincipal);
122 $filter('filter')($scope.botoneraPrincipal, { 123 $filter('filter')($scope.botoneraPrincipal, {
123 label: 'Remito Abierto', 124 label: 'Remito Abierto',
124 })[0].checked = true; 125 })[0].checked = true;
125 126
126 config(); 127 config();
127 128
128 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 129 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
129 }); 130 });
130 } else { 131 } else {
131 $scope.$broadcast('cleanCabecera'); 132 $scope.$broadcast('cleanCabecera');
132 limpiarBotonera($scope.botoneraPrincipal); 133 limpiarBotonera($scope.botoneraPrincipal);
133 $filter('filter')($scope.botoneraPrincipal, { 134 $filter('filter')($scope.botoneraPrincipal, {
134 label: 'Remito Abierto', 135 label: 'Remito Abierto',
135 })[0].checked = true; 136 })[0].checked = true;
136 137
137 config(); 138 config();
138 139
139 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 140 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
140 } 141 }
141 }; 142 };
142 143
143 $scope.seleccionarCargarRemitos = function () { 144 $scope.seleccionarCargarRemitos = function () {
144 $scope.cargaRemito = true; 145 $scope.cargaRemito = true;
145 $scope.remitoAbierto = false; 146 $scope.remitoAbierto = false;
146 $scope.precargado = false; 147 $scope.precargado = false;
147 148
148 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 149 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
149 $scope.$broadcast('cleanCabecera'); 150 $scope.$broadcast('cleanCabecera');
150 focaModalService.confirm('Se perderan los cambios') 151 focaModalService.confirm('Se perderan los cambios')
151 .then(function () { 152 .then(function () {
152 limpiarBotonera($scope.botonera); 153 limpiarBotonera($scope.botonera);
153 limpiarBotonera($scope.botoneraPrincipal); 154 limpiarBotonera($scope.botoneraPrincipal);
154 $scope.preCargados = false; 155 $scope.preCargados = false;
155 $filter('filter')($scope.botoneraPrincipal, { 156 $filter('filter')($scope.botoneraPrincipal, {
156 label: 'Cargar Remitos', 157 label: 'Cargar Remitos',
157 })[0].checked = true; 158 })[0].checked = true;
158 159
159 config(); 160 config();
160 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 161 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
161 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito(); 162 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
162 }); 163 });
163 } else { 164 } else {
164 $scope.$broadcast('cleanCabecera'); 165 $scope.$broadcast('cleanCabecera');
165 limpiarBotonera($scope.botoneraPrincipal); 166 limpiarBotonera($scope.botoneraPrincipal);
166 $filter('filter')($scope.botoneraPrincipal, { 167 $filter('filter')($scope.botoneraPrincipal, {
167 label: 'Cargar Remitos', 168 label: 'Cargar Remitos',
168 })[0].checked = true; 169 })[0].checked = true;
169 config(); 170 config();
170 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 171 // $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
171 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito(); 172 $scope.botonera = focaCrearHojaRutaService.getBotoneraCargarRemito();
172 } 173 }
173 $scope.precargado = false; 174 $scope.precargado = false;
174 }; 175 };
175 176
176 $scope.seleccionarPrecargados = function () { 177 $scope.seleccionarPrecargados = function () {
177 $scope.precargado = true; 178 $scope.precargado = true;
178 $scope.cargaRemito = false; 179 $scope.cargaRemito = false;
179 $scope.remitoAbierto = false; 180 $scope.remitoAbierto = false;
180 181
181 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 182 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
182 focaModalService.confirm('Se perderan los cambios') 183 focaModalService.confirm('Se perderan los cambios')
183 .then(function () { 184 .then(function () {
184 $scope.$broadcast('cleanCabecera'); 185 $scope.$broadcast('cleanCabecera');
185 limpiarBotonera($scope.botonera); 186 limpiarBotonera($scope.botonera);
186 limpiarBotonera($scope.botoneraPrincipal); 187 limpiarBotonera($scope.botoneraPrincipal);
187 $filter('filter')($scope.botoneraPrincipal, { 188 $filter('filter')($scope.botoneraPrincipal, {
188 label: 'Precargado', 189 label: 'Precargado',
189 })[0].checked = true; 190 })[0].checked = true;
190 191
191 config(); 192 config();
192 193
193 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado(); 194 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
194 }); 195 });
195 } else { 196 } else {
196 $scope.$broadcast('cleanCabecera'); 197 $scope.$broadcast('cleanCabecera');
197 limpiarBotonera($scope.botoneraPrincipal); 198 limpiarBotonera($scope.botoneraPrincipal);
198 $filter('filter')($scope.botoneraPrincipal, { 199 $filter('filter')($scope.botoneraPrincipal, {
199 label: 'Precargado', 200 label: 'Precargado',
200 })[0].checked = true; 201 })[0].checked = true;
201 202
202 config(); 203 config();
203 204
204 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado(); 205 $scope.botonera = focaCrearHojaRutaService.getBotoneraPrecargado();
205 } 206 }
206 }; 207 };
207 208
208 $scope.quitarArticulo = function (key) { 209 $scope.quitarArticulo = function (key) {
209 $scope.articulos.splice(key, 1); 210 $scope.articulos.splice(key, 1);
210 }; 211 };
211 212
212 function validarHojaRuta() { 213 function validarHojaRuta() {
213 if ($scope.precargado) { 214 if ($scope.precargado) {
214 if (!$scope.hojaRuta.chofer.id) { 215 if (!$scope.hojaRuta.chofer.id) {
215 focaModalService.alert('Ingrese Chofer'); 216 focaModalService.alert('Ingrese Chofer');
216 return false; 217 return false;
217 } 218 }
218 if (!$scope.hojaRuta.vehiculo.id) { 219 if (!$scope.hojaRuta.vehiculo.id) {
219 focaModalService.alert('Ingrese Vehiculo'); 220 focaModalService.alert('Ingrese Vehiculo');
220 return false; 221 return false;
221 } 222 }
222 if (!$scope.hojaRuta.transportista.COD) { 223 if (!$scope.hojaRuta.transportista.COD) {
223 focaModalService.alert('Ingrese Transportista'); 224 focaModalService.alert('Ingrese Transportista');
224 return false; 225 return false;
225 } 226 }
226 if (!$scope.hojaRuta.datosExtra) { 227 if (!$scope.hojaRuta.datosExtra) {
227 focaModalService.alert('Ingrese Datos extra'); 228 focaModalService.alert('Ingrese Datos extra');
228 return false; 229 return false;
229 } 230 }
230 } else if ($scope.cargaRemito) { 231 } else if ($scope.cargaRemito) {
231 if (!$scope.hojaRuta.remitosTabla.length) { 232 if (!$scope.hojaRuta.remitosTabla.length) {
232 focaModalService.alert('Ingrese Remitos'); 233 focaModalService.alert('Ingrese Remitos');
233 return false; 234 return false;
234 } else if (!$scope.hojaRuta.chofer.id) { 235 } else if (!$scope.hojaRuta.chofer.id) {
235 focaModalService.alert('Ingrese Chofer'); 236 focaModalService.alert('Ingrese Chofer');
236 return false; 237 return false;
237 } 238 }
238 if (!$scope.hojaRuta.vehiculo.id) { 239 if (!$scope.hojaRuta.vehiculo.id) {
239 focaModalService.alert('Ingrese Vehiculo'); 240 focaModalService.alert('Ingrese Vehiculo');
240 return false; 241 return false;
241 } 242 }
242 if (!$scope.hojaRuta.transportista.COD) { 243 if (!$scope.hojaRuta.transportista.COD) {
243 focaModalService.alert('Ingrese Transportista'); 244 focaModalService.alert('Ingrese Transportista');
244 return false; 245 return false;
245 } 246 }
246 if (!$scope.hojaRuta.datosExtra) { 247 if (!$scope.hojaRuta.datosExtra) {
247 focaModalService.alert('Ingrese Datos extra'); 248 focaModalService.alert('Ingrese Datos extra');
248 return false; 249 return false;
249 } 250 }
250 } else if ($scope.remitoAbierto) { 251 } else if ($scope.remitoAbierto) {
251 if (!$scope.hojaRuta.transportista.COD) { 252 if (!$scope.hojaRuta.transportista.COD) {
252 focaModalService.alert('Ingrese Transportista'); 253 focaModalService.alert('Ingrese Transportista');
253 return false; 254 return false;
254 } else if (!$scope.hojaRuta.vehiculo.id) { 255 } else if (!$scope.hojaRuta.vehiculo.id) {
255 focaModalService.alert('Ingrese Vehiculo'); 256 focaModalService.alert('Ingrese Vehiculo');
256 return false; 257 return false;
257 } else if (!$scope.hojaRuta.chofer.id) { 258 } else if (!$scope.hojaRuta.chofer.id) {
258 focaModalService.alert('Ingrese Chofer'); 259 focaModalService.alert('Ingrese Chofer');
259 return false; 260 return false;
260 } else if (!$scope.hojaRuta.proveedor.COD) { 261 } else if (!$scope.hojaRuta.proveedor.COD) {
261 focaModalService.alert('Ingrese Proveedor'); 262 focaModalService.alert('Ingrese Proveedor');
262 return false; 263 return false;
263 } else if (!$scope.hojaRuta.cliente.COD) { 264 } else if (!$scope.hojaRuta.cliente.COD) {
264 focaModalService.alert('Ingrese un Cliente'); 265 focaModalService.alert('Ingrese un Cliente');
265 return; 266 return;
266 } 267 }
267 } 268 }
268 return true; 269 return true;
269 270
270 } 271 }
271 272
272 function getImporte(propiedad) { 273 function getImporte(propiedad) {
273 var importe = 0; 274 var importe = 0;
274 275
275 $scope.articulos.forEach(function (articulo) { 276 $scope.articulos.forEach(function (articulo) {
276 277
277 if (articulo[propiedad]) { 278 if (articulo[propiedad]) {
278 importe += articulo[propiedad] * articulo.cantidad; 279 importe += articulo[propiedad] * articulo.cantidad;
279 } 280 }
280 return; 281 return;
281 282
282 }); 283 });
283 284
284 return importe; 285 return importe;
285 } 286 }
286 287
287 function guardarRemitoAbierto() { 288 function guardarRemitoAbierto() {
288 //guardar nuevo objeto (?) 289 //guardar nuevo objeto (?)
289 var date = new Date(); 290 var date = new Date();
290 if ($scope.hojaRuta !== null) { 291 if ($scope.hojaRuta !== null) {
291 focaBotoneraLateralService.startGuardar(); 292 focaBotoneraLateralService.startGuardar();
292 var save = { 293 var save = {
293 remito: { 294 remito: {
294 id: 0, 295 id: 0,
295 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 296 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
296 idCliente: $scope.hojaRuta.cliente.COD, 297 idCliente: $scope.hojaRuta.cliente.COD,
297 nombreCliente: $scope.hojaRuta.cliente.NOM, 298 nombreCliente: $scope.hojaRuta.cliente.NOM,
298 cuitCliente: $scope.hojaRuta.cliente.CUIT, 299 cuitCliente: $scope.hojaRuta.cliente.CUIT,
299 idVendedor: $cookies.get('vendedorCobrador'), 300 idVendedor: $cookies.get('vendedorCobrador'),
300 idProveedor: $scope.hojaRuta.proveedor.COD, 301 idProveedor: $scope.hojaRuta.proveedor.COD,
301 idDomicilio: $scope.hojaRuta.idDomicilio || 302 idDomicilio: $scope.hojaRuta.idDomicilio ||
302 $scope.hojaRuta.domicilio.id, 303 $scope.hojaRuta.domicilio.id,
303 idCotizacion: $scope.hojaRuta.cotizacion.ID, 304 idCotizacion: $scope.hojaRuta.cotizacion.ID,
304 domicilioStamp: $scope.hojaRuta.domicilioStamp, 305 domicilioStamp: $scope.hojaRuta.domicilioStamp,
305 observaciones: $scope.hojaRuta.observaciones, 306 observaciones: $scope.hojaRuta.observaciones,
306 idListaPrecio: $scope.hojaRuta.cliente.MOD.trim(), 307 idListaPrecio: $scope.hojaRuta.cliente.MOD.trim(),
307 total: getImporte('total') || 0, 308 total: getImporte('total') || 0,
308 descuento: 0,//TODO, 309 descuento: 0,//TODO,
309 importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar, 310 importeNeto: getImporte('netoUnitario') || 0, //TODO: arreglar,
310 importeExento: getImporte('exentoUnitario'), 311 importeExento: getImporte('exentoUnitario'),
311 importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar 312 importeIva: getImporte('ivaUnitario') || 0, //TODO: arreglar
312 importeIvaServicios: 0,//TODO 313 importeIvaServicios: 0,//TODO
313 importeImpuestoInterno: getImporte('impuestoInternoUnitario'), 314 importeImpuestoInterno: getImporte('impuestoInternoUnitario'),
314 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'), 315 importeImpuestoInterno1: getImporte('impuestoInterno1Unitario'),
315 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'), 316 importeImpuestoInterno2: getImporte('impuestoInterno2Unitario'),
316 percepcion: 0,//TODO 317 percepcion: 0,//TODO
317 percepcionIva: 0,//TODO 318 percepcionIva: 0,//TODO
318 redondeo: 0,//TODO 319 redondeo: 0,//TODO
319 anulado: false, 320 anulado: false,
320 planilla: $filter('date')($scope.now, 'ddMMyyyy'), 321 planilla: $filter('date')($scope.now, 'ddMMyyyy'),
321 lugar: parseInt($scope.puntoVenta), 322 lugar: parseInt($scope.puntoVenta),
322 cuentaMadre: 0,//TODO 323 cuentaMadre: 0,//TODO
323 cuentaContable: 0,//TODO 324 cuentaContable: 0,//TODO
324 asiento: 0,//TODO 325 asiento: 0,//TODO
325 e_hd: '',//TODO 326 e_hd: '',//TODO
326 c_hd: '', 327 c_hd: '',
327 numeroLiquidoProducto: 0,//TODO 328 numeroLiquidoProducto: 0,//TODO
328 estado: 0, 329 estado: 0,
329 destinoVenta: 0,//TODO 330 destinoVenta: 0,//TODO
330 operacionTipo: 0, //TODO 331 operacionTipo: 0, //TODO
332 flete: false,
333 fob: false,
334 bomba: false,
331 }, 335 },
332 notaPedido: { 336 notaPedido: {
333 id: 0 337 id: 0
334 } 338 }
335 }; 339 };
336 focaCrearHojaRutaService.crearRemito(save).then( 340 focaCrearHojaRutaService.crearRemito(save).then(
337 function (data) { 341 function (data) {
338 focaBotoneraLateralService.endGuardar(true); 342 focaBotoneraLateralService.endGuardar(true);
339 $scope.saveLoading = false; 343 $scope.saveLoading = false;
340 344
341 $scope.remito.id = data.data.id; 345 $scope.remito.id = data.data.id;
342 346
343 focaCrearHojaRutaService.guardarCisternas({ 347 focaCrearHojaRutaService.guardarCisternas({
344 cisternaCargas: $scope.cisternaCargas, 348 cisternaCargas: $scope.cisternaCargas,
345 cisternaMovimientos: $scope.cisternaMovimientos, 349 cisternaMovimientos: $scope.cisternaMovimientos,
346 fechaReparto: $scope.hojaRuta.fechaReparto, 350 fechaReparto: $scope.hojaRuta.fechaReparto,
347 idVehiculo: $scope.hojaRuta.vehiculo.id 351 idVehiculo: $scope.hojaRuta.vehiculo.id
348 }, data.data.id); 352 }, data.data.id);
349 $scope.remito.numeroRemito = data.data.numero; 353 $scope.remito.numeroRemito = data.data.numero;
350 354
351 // if ($scope.remito.remitoPuntoDescarga.length > 0) { 355 // if ($scope.remito.remitoPuntoDescarga.length > 0) {
352 // remitoBusinessService.addPuntosDescarga(data.data.id, 356 // remitoBusinessService.addPuntosDescarga(data.data.id,
353 // $scope.remito.remitoPuntoDescarga); 357 // $scope.remito.remitoPuntoDescarga);
354 // } 358 // }
355 359
356 hojaRutaBusinessService.addArticulos($scope.articulosRecibidos, 360 hojaRutaBusinessService.addArticulos($scope.articulosRecibidos,
357 data.data.id, $scope.hojaRuta.cotizacion.VENDEDOR); 361 data.data.id, $scope.hojaRuta.cotizacion.VENDEDOR);
358 362
359 guardarHojaRuta(data.data.id); 363 guardarHojaRuta(data.data.id);
360 364
361 }, function (error) { 365 }, function (error) {
362 focaModalService.alert( 366 focaModalService.alert(
363 error.data || 'Hubo un error al crear el remito'); 367 error.data || 'Hubo un error al crear el remito');
364 focaBotoneraLateralService.endGuardar(); 368 focaBotoneraLateralService.endGuardar();
365 $scope.saveLoading = false; 369 $scope.saveLoading = false;
366 console.info(error); 370 console.info(error);
367 } 371 }
368 ); 372 );
369 373
370 function guardarHojaRuta(idRemito) { 374 function guardarHojaRuta(idRemito) {
371 375
372 var save2 = { 376 var save2 = {
373 hojaRuta: { 377 hojaRuta: {
374 id: 0, 378 id: 0,
375 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 379 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
376 .replace('T', ' '), 380 .replace('T', ' '),
377 idTransportista: $scope.hojaRuta.transportista.COD, 381 idTransportista: $scope.hojaRuta.transportista.COD,
378 idChofer: $scope.hojaRuta.chofer.id, 382 idChofer: $scope.hojaRuta.chofer.id,
379 idVehiculo: $scope.hojaRuta.vehiculo.id, 383 idVehiculo: $scope.hojaRuta.vehiculo.id,
380 proveedor: $scope.hojaRuta.proveedor.id, 384 proveedor: $scope.hojaRuta.proveedor.id,
381 fechaReparto: new Date($scope.hojaRuta.fechaReparto) 385 fechaReparto: new Date($scope.hojaRuta.fechaReparto)
382 .toISOString() 386 .toISOString()
383 .substring(0, 10), 387 .substring(0, 10),
384 estado: 0, 388 estado: 0,
385 abierta: 1 389 abierta: 1
386 }, 390 },
387 remitos: [{id: idRemito}] 391 remitos: [{ id: idRemito }]
388 }; 392 };
389 393
390 save2.hojaRuta = angular 394 save2.hojaRuta = angular
391 .extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra); 395 .extend({}, save2.hojaRuta, $scope.hojaRuta.datosExtra);
392 focaCrearHojaRutaService.crearHojaRuta(save2).then( 396 focaCrearHojaRutaService.crearHojaRuta(save2).then(
393 function (data) { 397 function (data) {
394 var remitoNumero; 398 var remitoNumero;
395 data.data.remitos.forEach(function(idRemitos) { 399 data.data.remitos.forEach(function (idRemitos) {
396 remitoNumero = idRemitos; 400 remitoNumero = idRemitos;
397 }); 401 });
398 focaModalService.alert( 402 focaModalService.alert(
399 'Hoja ruta creada Nº: ' + 403 'Hoja ruta creada Nº: ' +
400 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 404 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
401 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + 405 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) +
402 '\nRemito Abierto Nº: ' + 406 '\nRemito Abierto Nº: ' +
403 $filter('rellenarDigitos')(remitoNumero.sucursal, 4) + '-' + 407 $filter('rellenarDigitos')(remitoNumero.sucursal, 4) + '-' +
404 $filter('rellenarDigitos')(remitoNumero.numeroRemito,8) 408 $filter('rellenarDigitos')(remitoNumero.numeroRemito, 8)
405 ); 409 );
406 410
407 config(); 411 config();
408 }, 412 },
409 function (error) { 413 function (error) {
410 414
411 focaModalService 415 focaModalService
412 .alert('Hubo un error al crear la hoja de ruta'); 416 .alert('Hubo un error al crear la hoja de ruta');
413 417
414 console.info(error); 418 console.info(error);
415 } 419 }
416 ); 420 );
417 } 421 }
418 } 422 }
419 } 423 }
420 424
421 $scope.seleccionarCliente = function () { 425 $scope.seleccionarCliente = function () {
422 var modalInstance = $uibModal.open( 426 var modalInstance = $uibModal.open(
423 { 427 {
424 ariaLabelledBy: 'Busqueda de Cliente', 428 ariaLabelledBy: 'Busqueda de Cliente',
425 templateUrl: 'foca-busqueda-cliente-modal.html', 429 templateUrl: 'foca-busqueda-cliente-modal.html',
426 controller: 'focaBusquedaClienteModalController', 430 controller: 'focaBusquedaClienteModalController',
427 resolve: { 431 resolve: {
428 vendedor: function () { return null; }, 432 vendedor: function () { return null; },
429 cobrador: function () { return null; } 433 cobrador: function () { return null; }
430 }, 434 },
431 size: 'lg' 435 size: 'lg'
432 } 436 }
433 ); 437 );
434 modalInstance.result.then( 438 modalInstance.result.then(
435 function (cliente) { 439 function (cliente) {
436 $scope.abrirModalDomicilios(cliente); 440 $scope.abrirModalDomicilios(cliente);
437 $scope.cliente = cliente; 441 $scope.cliente = cliente;
438 }, function () { 442 }, function () {
439 } 443 }
440 ); 444 );
441 }; 445 };
442 446
443 $scope.abrirModalDomicilios = function (cliente) { 447 $scope.abrirModalDomicilios = function (cliente) {
444 var modalInstanceDomicilio = $uibModal.open( 448 var modalInstanceDomicilio = $uibModal.open(
445 { 449 {
446 ariaLabelledBy: 'Busqueda de Domicilios', 450 ariaLabelledBy: 'Busqueda de Domicilios',
447 templateUrl: 'modal-domicilio.html', 451 templateUrl: 'modal-domicilio.html',
448 controller: 'focaModalDomicilioController', 452 controller: 'focaModalDomicilioController',
449 size: 'lg', 453 size: 'lg',
450 resolve: { 454 resolve: {
451 idCliente: function () { return cliente.cod; }, 455 idCliente: function () { return cliente.cod; },
452 esNuevo: function () { return cliente.esNuevo; } 456 esNuevo: function () { return cliente.esNuevo; }
453 } 457 }
454 } 458 }
455 ); 459 );
456 modalInstanceDomicilio.result.then( 460 modalInstanceDomicilio.result.then(
457 function (domicilio) { 461 function (domicilio) {
458 $scope.hojaRuta.domicilio = domicilio; 462 $scope.hojaRuta.domicilio = domicilio;
459 $scope.hojaRuta.cliente = { 463 $scope.hojaRuta.cliente = {
460 COD: cliente.cod, 464 COD: cliente.cod,
461 CUIT: cliente.cuit, 465 CUIT: cliente.cuit,
462 NOM: cliente.nom, 466 NOM: cliente.nom,
463 MAIL: cliente.mail, 467 MAIL: cliente.mail,
464 MOD: cliente.mod, 468 MOD: cliente.mod,
465 IVA: cliente.iva, 469 IVA: cliente.iva,
466 VEN: cliente.ven 470 VEN: cliente.ven
467 }; 471 };
468 focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN) 472 focaCrearHojaRutaService.getVendedorById($scope.hojaRuta.cliente.VEN)
469 .then(function (res) { 473 .then(function (res) {
470 if (res.data !== '') { 474 if (res.data !== '') {
471 $scope.hojaRuta.vendedor = res.data; 475 $scope.hojaRuta.vendedor = res.data;
472 $scope.$broadcast('addCabecera', { 476 $scope.$broadcast('addCabecera', {
473 label: 'Vendedor:', 477 label: 'Vendedor:',
474 valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor 478 valor: $filter('rellenarDigitos')($scope.hojaRuta.vendedor
475 .NUM, 3) +' - ' + $scope.hojaRuta.vendedor.NOM 479 .NUM, 3) + ' - ' + $scope.hojaRuta.vendedor.NOM
476 }); 480 });
477 } 481 }
478 var domicilioStamp = 482 var domicilioStamp =
479 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 483 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
480 domicilio.Localidad + ', ' + domicilio.Provincia; 484 domicilio.Localidad + ', ' + domicilio.Provincia;
481 $scope.hojaRuta.domicilioStamp = domicilioStamp; 485 $scope.hojaRuta.domicilioStamp = domicilioStamp;
482 $scope.$broadcast('addCabecera', { 486 $scope.$broadcast('addCabecera', {
483 label: 'Cliente:', 487 label: 'Cliente:',
484 valor: $filter('rellenarDigitos')(cliente.cod, 3) + 488 valor: $filter('rellenarDigitos')(cliente.cod, 3) +
485 ' - ' + cliente.nom 489 ' - ' + cliente.nom
486 }); 490 });
487 $scope.$broadcast('addCabecera', { 491 $scope.$broadcast('addCabecera', {
488 label: 'Domicilio:', 492 label: 'Domicilio:',
489 valor: domicilioStamp 493 valor: domicilioStamp
490 }); 494 });
491 495
492 if (domicilio.verPuntos) { 496 if (domicilio.verPuntos) {
493 delete $scope.hojaRuta.domicilio.verPuntos; 497 delete $scope.hojaRuta.domicilio.verPuntos;
494 $scope.seleccionarPuntosDeDescarga(); 498 $scope.seleccionarPuntosDeDescarga();
495 } else { 499 } else {
496 focaCrearHojaRutaService 500 focaCrearHojaRutaService
497 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 501 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
498 .then(function (res) { 502 .then(function (res) {
499 if (res.data.length) { 503 if (res.data.length) {
500 $scope.seleccionarPuntosDeDescarga(); 504 $scope.seleccionarPuntosDeDescarga();
501 } 505 }
502 }); 506 });
503 } 507 }
504 508
505 $filter('filter')($scope.botonera, { 509 $filter('filter')($scope.botonera, {
506 label: 'Cliente', 510 label: 'Cliente',
507 })[0].checked = true; 511 })[0].checked = true;
508 }) 512 })
509 .catch(function (e) { console.log(e); }); 513 .catch(function (e) { console.log(e); });
510 }, function () { 514 }, function () {
511 $scope.seleccionarCliente(true); 515 $scope.seleccionarCliente(true);
512 return; 516 return;
513 } 517 }
514 ); 518 );
515 }; 519 };
516 520
517 $scope.seleccionarPuntosDeDescarga = function () { 521 $scope.seleccionarPuntosDeDescarga = function () {
518 if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) { 522 if (!$scope.hojaRuta.cliente.COD || !$scope.hojaRuta.domicilio.id) {
519 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 523 focaModalService.alert('Primero seleccione un cliente y un domicilio');
520 return; 524 return;
521 } else { 525 } else {
522 var modalInstance = $uibModal.open( 526 var modalInstance = $uibModal.open(
523 { 527 {
524 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 528 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
525 templateUrl: 'modal-punto-descarga.html', 529 templateUrl: 'modal-punto-descarga.html',
526 controller: 'focaModalPuntoDescargaController', 530 controller: 'focaModalPuntoDescargaController',
527 size: 'lg', 531 size: 'lg',
528 resolve: { 532 resolve: {
529 filters: { 533 filters: {
530 idDomicilio: $scope.remito.domicilio.id, 534 idDomicilio: $scope.remito.domicilio.id,
531 idCliente: $scope.remito.cliente.COD, 535 idCliente: $scope.remito.cliente.COD,
532 articulos: $scope.remito.articulosRemito, 536 articulos: $scope.remito.articulosRemito,
533 puntosDescarga: $scope.remito.remitoPuntoDescarga, 537 puntosDescarga: $scope.remito.remitoPuntoDescarga,
534 domicilio: $scope.remito.domicilio 538 domicilio: $scope.remito.domicilio
535 } 539 }
536 } 540 }
537 } 541 }
538 ); 542 );
539 modalInstance.result.then( 543 modalInstance.result.then(
540 function(puntosDescarga) { 544 function (puntosDescarga) {
541 545
542 puntosDescarga.forEach(function(punto) { 546 puntosDescarga.forEach(function (punto) {
543 $scope.hojaRuta.remitoPuntoDescarga.push( 547 $scope.hojaRuta.remitoPuntoDescarga.push(
544 { 548 {
545 puntoDescarga: punto 549 puntoDescarga: punto
546 } 550 }
547 ); 551 );
548 }); 552 });
549 553
550 $scope.$broadcast('addCabecera', { 554 $scope.$broadcast('addCabecera', {
551 label: 'Puntos de descarga:', 555 label: 'Puntos de descarga:',
552 valor: getCabeceraPuntoDescarga(puntosDescarga) 556 valor: getCabeceraPuntoDescarga(puntosDescarga)
553 }); 557 });
554 }, function () { 558 }, function () {
555 $scope.abrirModalDomicilios($scope.cliente); 559 $scope.abrirModalDomicilios($scope.cliente);
556 } 560 }
557 ); 561 );
558 } 562 }
559 }; 563 };
560 564
561 $scope.seleccionarDetalleDeCarga = function () { 565 $scope.seleccionarDetalleDeCarga = function () {
562 if ($scope.hojaRuta.vehiculo.capacidad === 0) { 566 if ($scope.hojaRuta.vehiculo.capacidad === 0) {
563 focaModalService.alert('Debe ingresar vehiculo'); 567 focaModalService.alert('Debe ingresar vehiculo');
564 return; 568 return;
565 } else { 569 } else {
566 $scope.mostrarDetalle($scope.hojaRuta); 570 $scope.mostrarDetalle($scope.hojaRuta);
567 } 571 }
568 }; 572 };
569 573
570 function getCabeceraPuntoDescarga(puntosDescarga) { 574 function getCabeceraPuntoDescarga(puntosDescarga) {
571 var puntosStamp = ''; 575 var puntosStamp = '';
572 puntosDescarga.forEach(function (punto, idx, arr) { 576 puntosDescarga.forEach(function (punto, idx, arr) {
573 puntosStamp += punto.descripcion; 577 puntosStamp += punto.descripcion;
574 if ((idx + 1) !== arr.length) puntosStamp += ', '; 578 if ((idx + 1) !== arr.length) puntosStamp += ', ';
575 }); 579 });
576 return puntosStamp; 580 return puntosStamp;
577 } 581 }
578 582
579 $scope.crearHojaRuta = function () { 583 $scope.crearHojaRuta = function () {
580 584
581 var continuar = validarHojaRuta(); 585 var continuar = validarHojaRuta();
582 if (!continuar) { 586 if (!continuar) {
583 return; 587 return;
584 } else if ($scope.remitoAbierto) { 588 } else if ($scope.remitoAbierto) {
585 guardarRemitoAbierto(); 589 guardarRemitoAbierto();
586 return; 590 return;
587 } 591 }
588 var date = new Date(); 592 var date = new Date();
589 var save = { 593 var save = {
590 hojaRuta: { 594 hojaRuta: {
591 id: 0, 595 id: 0,
592 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) 596 fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19)
593 .replace('T', ' '), 597 .replace('T', ' '),
594 idTransportista: $scope.hojaRuta.transportista.COD, 598 idTransportista: $scope.hojaRuta.transportista.COD,
595 idChofer: $scope.hojaRuta.chofer.id, 599 idChofer: $scope.hojaRuta.chofer.id,
596 idVehiculo: $scope.hojaRuta.vehiculo.id, 600 idVehiculo: $scope.hojaRuta.vehiculo.id,
597 tarifaFlete: $scope.hojaRuta.tarifario, 601 tarifaFlete: $scope.hojaRuta.tarifario,
598 fechaReparto: 602 fechaReparto:
599 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), 603 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10),
600 estado: 0 604 estado: 0
601 }, 605 },
602 remitos: $scope.hojaRuta.remitosTabla 606 remitos: $scope.hojaRuta.remitosTabla
603 }; 607 };
604 608
605 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); 609 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
606 focaCrearHojaRutaService.crearHojaRuta(save).then( 610 focaCrearHojaRutaService.crearHojaRuta(save).then(
607 function (data) { 611 function (data) {
608 focaModalService.alert( 612 focaModalService.alert(
609 'Hoja ruta creada Nº: ' + 613 'Hoja ruta creada Nº: ' +
610 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + 614 $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' +
611 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ' ' + 615 $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) + ' ' +
612 $filter('date')($scope.hojaRuta.fechaReparto, 'dd/MM/yyyy') + '-' + 616 $filter('date')($scope.hojaRuta.fechaReparto, 'dd/MM/yyyy') + '-' +
613 $scope.hojaRuta.orden 617 $scope.hojaRuta.orden
614 ); 618 );
615 619
616 config(); 620 config();
617 }, 621 },
618 function (error) { 622 function (error) {
619 focaModalService.alert('Hubo un error al crear la hoja de ruta'); 623 focaModalService.alert('Hubo un error al crear la hoja de ruta');
620 console.info(error); 624 console.info(error);
621 } 625 }
622 ); 626 );
623 }; 627 };
624 628
625 $scope.seleccionarProveedor = function () { 629 $scope.seleccionarProveedor = function () {
626 var parametrosModal = { 630 var parametrosModal = {
627 titulo: 'Búsqueda de Proveedor', 631 titulo: 'Búsqueda de Proveedor',
628 query: '/proveedor', 632 query: '/proveedor',
629 columnas: [ 633 columnas: [
630 { 634 {
631 nombre: 'Código', 635 nombre: 'Código',
632 propiedad: 'COD', 636 propiedad: 'COD',
633 filtro: { 637 filtro: {
634 nombre: 'rellenarDigitos', 638 nombre: 'rellenarDigitos',
635 parametro: 5 639 parametro: 5
636 }
637 },
638 {
639 nombre: 'Nombre',
640 propiedad: 'NOM'
641 },
642 {
643 nombre: 'CUIT',
644 propiedad: 'CUIT'
645 } 640 }
646 ], 641 },
647 tipo: 'POST', 642 {
648 json: { razonCuitCod: '' } 643 nombre: 'Nombre',
649 }; 644 propiedad: 'NOM'
650 focaModalService.modal(parametrosModal).then( 645 },
651 function (proveedor) { 646 {
652 $filter('filter')($scope.botonera, { 647 nombre: 'CUIT',
653 label: 'Proveedor', 648 propiedad: 'CUIT'
654 })[0].checked = true; 649 }
650 ],
651 tipo: 'POST',
652 json: { razonCuitCod: '' }
653 };
654 focaModalService.modal(parametrosModal).then(
655 function (proveedor) {
656 $filter('filter')($scope.botonera, {
657 label: 'Proveedor',
658 })[0].checked = true;
655 659
656 $scope.$broadcast('addCabecera', { 660 $scope.$broadcast('addCabecera', {
657 label: 'Proveedor:', 661 label: 'Proveedor:',
658 valor: proveedor.COD + ' - ' + proveedor.NOM 662 valor: proveedor.COD + ' - ' + proveedor.NOM
659 }); 663 });
660 $scope.hojaRuta.proveedor = proveedor; 664 $scope.hojaRuta.proveedor = proveedor;
661 }, function () { } 665 }, function () { }
662 ); 666 );
663 }; 667 };
664 668
665 $scope.seleccionarTransportista = function () { 669 $scope.seleccionarTransportista = function () {
666 if (eligioPreConfirmado()) return; 670 if (eligioPreConfirmado()) return;
667 var parametrosModal = { 671 var parametrosModal = {
668 titulo: 'Búsqueda de transportista', 672 titulo: 'Búsqueda de transportista',
669 query: '/transportista', 673 query: '/transportista',
670 columnas: [ 674 columnas: [
671 { 675 {
672 nombre: 'Código', 676 nombre: 'Código',
673 propiedad: 'COD' 677 propiedad: 'COD'
674 }, 678 },
675 { 679 {
676 nombre: 'Nombre', 680 nombre: 'Nombre',
677 propiedad: 'NOM' 681 propiedad: 'NOM'
678 }, 682 },
679 { 683 {
680 nombre: 'CUIT', 684 nombre: 'CUIT',
681 propiedad: 'CUIT' 685 propiedad: 'CUIT'
682 } 686 }
683 ] 687 ]
684 }; 688 };
685 focaModalService.modal(parametrosModal).then( 689 focaModalService.modal(parametrosModal).then(
686 function (proveedor) { 690 function (proveedor) {
687 $scope.hojaRuta.transportista = proveedor; 691 $scope.hojaRuta.transportista = proveedor;
688 $scope.$broadcast('addCabecera', { 692 $scope.$broadcast('addCabecera', {
689 label: 'Transportista:', 693 label: 'Transportista:',
690 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 694 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
691 proveedor.NOM 695 proveedor.NOM
692 }); 696 });
693 697
694 $filter('filter')($scope.botonera, { 698 $filter('filter')($scope.botonera, {
695 label: 'Transportista', 699 label: 'Transportista',
696 })[0].checked = true; 700 })[0].checked = true;
697 }, function () { 701 }, function () {
698 702
699 } 703 }
700 ); 704 );
701 }; 705 };
702 706
703 $scope.seleccionarChofer = function () { 707 $scope.seleccionarChofer = function () {
704 var parametrosModal = { 708 var parametrosModal = {
705 titulo: 'Búsqueda de Chofer', 709 titulo: 'Búsqueda de Chofer',
706 query: '/chofer', 710 query: '/chofer',
707 columnas: [ 711 columnas: [
708 { 712 {
709 propiedad: 'id', 713 propiedad: 'id',
710 nombre: 'Código', 714 nombre: 'Código',
711 filtro: { 715 filtro: {
712 nombre: 'rellenarDigitos', 716 nombre: 'rellenarDigitos',
713 parametro: 3 717 parametro: 3
714 } 718 }
715 }, 719 },
716 { 720 {
717 propiedad: 'nombre', 721 propiedad: 'nombre',
718 nombre: 'Nombre' 722 nombre: 'Nombre'
719 }, 723 },
720 { 724 {
721 propiedad: 'dni', 725 propiedad: 'dni',
722 nombre: 'DNI' 726 nombre: 'DNI'
723 }, 727 },
724 { 728 {
725 propiedad: 'telefono', 729 propiedad: 'telefono',
726 nombre: 'Teléfono' 730 nombre: 'Teléfono'
727 } 731 }
728 ] 732 ]
729 }; 733 };
730 focaModalService.modal(parametrosModal).then( 734 focaModalService.modal(parametrosModal).then(
731 function (chofer) { 735 function (chofer) {
732 $scope.hojaRuta.chofer = chofer; 736 $scope.hojaRuta.chofer = chofer;
733 $scope.$broadcast('addCabecera', { 737 $scope.$broadcast('addCabecera', {
734 label: 'Chofer:', 738 label: 'Chofer:',
735 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre 739 valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' + chofer.nombre
736 }); 740 });
737 741
738 $filter('filter')($scope.botonera, { 742 $filter('filter')($scope.botonera, {
739 label: 'Chofer', 743 label: 'Chofer',
740 })[0].checked = true; 744 })[0].checked = true;
741 }, function () { 745 }, function () {
742 // funcion ejecutada cuando se cancela el modal 746 // funcion ejecutada cuando se cancela el modal
743 } 747 }
744 ); 748 );
745 }; 749 };
746 750
747 $scope.seleccionarVehiculo = function () { 751 $scope.seleccionarVehiculo = function () {
748 if (!eligioFecha() || eligioPreConfirmado()) return; 752 if (!eligioFecha() || eligioPreConfirmado()) return;
749 modalVehiculos(); 753 modalVehiculos();
750 }; 754 };
751 755
752 $scope.seleccionarTarifario = function () { 756 $scope.seleccionarTarifario = function () {
753 focaModalService 757 focaModalService
754 .prompt({ 758 .prompt({
755 titulo: 'Tarifa flete', 759 titulo: 'Tarifa flete',
756 value: $scope.hojaRuta.tarifario 760 value: $scope.hojaRuta.tarifario
757 }) 761 })
758 .then(function (costo) { 762 .then(function (costo) {
759 if (isNaN(costo)) { 763 if (isNaN(costo)) {
760 focaModalService 764 focaModalService
761 .alert('Ingrese un valor válido') 765 .alert('Ingrese un valor válido')
762 .then(function () { 766 .then(function () {
763 $scope.seleccionarTarifario(); 767 $scope.seleccionarTarifario();
764 }); 768 });
765 769
766 return; 770 return;
767 } 771 }
768 772
769 $scope.hojaRuta.tarifario = costo; 773 $scope.hojaRuta.tarifario = costo;
770 $scope.$broadcast('addCabecera', { 774 $scope.$broadcast('addCabecera', {
771 label: 'Tarifario:', 775 label: 'Tarifario:',
772 valor: costo 776 valor: costo
773 }); 777 });
774 778
775 $filter('filter')($scope.botonera, { 779 $filter('filter')($scope.botonera, {
776 label: 'Tarifario', 780 label: 'Tarifario',
777 })[0].checked = true; 781 })[0].checked = true;
778 }); 782 });
779 }; 783 };
780 784
781 $scope.seleccionarRemitos = function () { 785 $scope.seleccionarRemitos = function () {
782 786
783 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; 787 if (eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return;
784 788
785 var modalInstance = $uibModal.open( 789 var modalInstance = $uibModal.open(
786 { 790 {
787 ariaLabelledBy: 'Busqueda de Remito', 791 ariaLabelledBy: 'Busqueda de Remito',
788 templateUrl: 'foca-modal-remito.html', 792 templateUrl: 'foca-modal-remito.html',
789 controller: 'focaModalRemitoController', 793 controller: 'focaModalRemitoController',
790 size: 'lg', 794 size: 'lg',
791 resolve: { usadoPor: function () { return 'hojaRuta'; } } 795 resolve: { usadoPor: function () { return 'hojaRuta'; } }
792 } 796 }
793 ); 797 );
794 modalInstance.result.then( 798 modalInstance.result
795 function (remito) { 799 .then(function (remito) {
796 // TODO: borrar cuando no se use definitivamente 800 // TODO: borrar cuando no se use definitivamente
797 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { 801 // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) {
798 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { 802 // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) {
799 // focaModalService.alert('Remito ya incluido'); 803 // focaModalService.alert('Remito ya incluido');
800 // return; 804 // return;
801 // } 805 // }
802 // } 806 // }
803 807
804 // var litros = 0; 808 // var litros = 0;
805 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { 809 // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) {
806 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); 810 // litros = litros + parseFloat(remito.articulosRemito[j].cantidad);
807 // } 811 // }
808 812
809 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { 813 // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) {
810 // focaModalService.alert( 814 // focaModalService.alert(
811 // 'Debe ingresar toda la información para el transporte' 815 // 'Debe ingresar toda la información para el transporte'
812 // ); 816 // );
813 // return; 817 // return;
814 // } 818 // }
815 819
816 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) 820 //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad)
817 // { 821 // {
818 // var litrostotales = litros; 822 // var litrostotales = litros;
819 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; 823 // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros;
820 // focaModalService.alert( 824 // focaModalService.alert(
821 // 'La carga excede la capacidad disponible del vehiculo. ' + 825 // 'La carga excede la capacidad disponible del vehiculo. ' +
822 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' 826 // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros'
823 // ); 827 // );
824 // } 828 // }
825 829
826 // remito.litros = litros; 830 // remito.litros = litros;
827 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; 831 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
828 $scope.cargarCisterna(remito.id).then(function () { 832 $scope.cargarCisterna(remito.id)
829 $scope.hojaRuta.remitosTabla.push(remito); 833 .then(function () {
830 $filter('filter')($scope.botonera, { 834 $scope.hojaRuta.remitosTabla.push(remito);
831 label: 'Remitos', 835 $filter('filter')($scope.botonera, {
832 })[0].checked = true; 836 label: 'Remitos',
837 })[0].checked = true;
833 838
834 }, function (error) { 839 })
835 $scope.seleccionarRemitos(); 840 .catch(function (error) {
836 }); 841 console.error(error);
837 }, function () { 842 $scope.seleccionarRemitos();
838 // funcion ejecutada cuando se cancela el modal 843 });
839 } 844 })
840 ); 845 .catch(function (e) { console.error(e); });
841 }; 846 };
842 847
843 $scope.seleccionarVehiculosPrecargados = function () { 848 $scope.seleccionarVehiculosPrecargados = function () {
844 if (!eligioFecha()) return; 849 if (!eligioFecha()) return;
845 modalVehiculos(true); 850 modalVehiculos(true);
846 }; 851 };
847 852
848 $scope.cargarCisterna = function (idRemito) { 853 $scope.cargarCisterna = function (idRemito) {
849 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; 854 if (!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return;
850 var modalInstance = $uibModal.open( 855 var modalInstance = $uibModal.open(
851 { 856 {
852 ariaLabelledBy: 'Busqueda de Vehiculo', 857 ariaLabelledBy: 'Busqueda de Vehiculo',
853 templateUrl: 'foca-detalle-vehiculo.html', 858 templateUrl: 'foca-detalle-vehiculo.html',
854 controller: 'focaDetalleVehiculo', 859 controller: 'focaDetalleVehiculo',
855 size: 'lg', 860 size: 'lg',
856 resolve: { 861 resolve: {
857 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; }, 862 idVehiculo: function () { return $scope.hojaRuta.vehiculo.id; },
858 idRemito: function () { return idRemito; }, 863 idRemito: function () { return idRemito; },
859 fechaReparto: function () { return $scope.hojaRuta.fechaReparto;}, 864 fechaReparto: function () { return $scope.hojaRuta.fechaReparto; },
860 orden: function() { return $scope.hojaRuta.orden } 865 orden: function () { return $scope.hojaRuta.orden; }
861 } 866 }
862 } 867 }
863 ); 868 );
864 return modalInstance.result; 869 return modalInstance.result;
865 }; 870 };
866 871
867 $scope.seleccionarFechaEntrega = function () { 872 $scope.seleccionarFechaEntrega = function () {
868 873
869 var confirmacion = false; 874 var confirmacion = false;
870 875
871 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 876 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
872 confirmacion = true; 877 confirmacion = true;
873 } 878 }
874 879
875 if (confirmacion) { 880 if (confirmacion) {
876 focaModalService 881 focaModalService
877 .confirm('Si cambia la fecha se perderán los datos actuales') 882 .confirm('Si cambia la fecha se perderán los datos actuales')
878 .then(function (data) { 883 .then(function (data) {
879 if (data) { 884 if (data) {
880 $scope.hojaRuta.vehiculo.id = undefined; 885 $scope.hojaRuta.vehiculo.id = undefined;
881 $scope.hojaRuta.tarifario = null; 886 $scope.hojaRuta.tarifario = null;
882 $scope.hojaRuta.transportista = {}; 887 $scope.hojaRuta.transportista = {};
883 $scope.hojaRuta.chofer = {}; 888 $scope.hojaRuta.chofer = {};
884 $scope.hojaRuta.datosExtra = undefined; 889 $scope.hojaRuta.datosExtra = undefined;
885 elegirFecha(); 890 elegirFecha();
886 } 891 }
887 }, function () { 892 }, function () {
888 return; 893 return;
889 }); 894 });
890 } else { 895 } else {
891 elegirFecha(); 896 elegirFecha();
892 } 897 }
893 }; 898 };
894 899
895 function setearFecha(fecha) { 900 function setearFecha(fecha) {
896 $timeout(function () { 901 $timeout(function () {
897 $scope.$broadcast('addCabecera', { 902 $scope.$broadcast('addCabecera', {
898 label: 'Fecha de entrega: ', 903 label: 'Fecha de entrega: ',
899 valor: fecha.toLocaleDateString() 904 valor: fecha.toLocaleDateString()
900 }); 905 });
901 $scope.hojaRuta.fechaReparto = fecha; 906 $scope.hojaRuta.fechaReparto = fecha;
902 $scope.inicial.fechaReparto = fecha; 907 $scope.inicial.fechaReparto = fecha;
903 }); 908 });
904 } 909 }
905 910
906 $scope.seleccionarDatosExtra = function () { 911 $scope.seleccionarDatosExtra = function () {
907 var datosHojaRuta = $scope.hojaRuta.datosExtra; 912 var datosHojaRuta = $scope.hojaRuta.datosExtra;
908 var modalInstance = $uibModal.open( 913 var modalInstance = $uibModal.open(
909 { 914 {
910 templateUrl: 'foca-modal-datos-hoja-ruta.html', 915 templateUrl: 'foca-modal-datos-hoja-ruta.html',
911 controller: 'focaModalDatosHojaRutaCtrl', 916 controller: 'focaModalDatosHojaRutaCtrl',
912 size: 'lg', 917 size: 'lg',
913 resolve: { 918 resolve: {
914 parametrosDatos: function () { 919 parametrosDatos: function () {
915 return { 920 return {
916 datosHojaRuta: datosHojaRuta 921 datosHojaRuta: datosHojaRuta
917 }; 922 };
918 } 923 }
919 } 924 }
920 } 925 }
921 ); 926 );
922 return modalInstance.result.then(function (datosExtra) { 927 return modalInstance.result.then(function (datosExtra) {
923 928
924 $filter('filter')($scope.botonera, { 929 $filter('filter')($scope.botonera, {
925 label: 'Datos extra', 930 label: 'Datos extra',
926 })[0].checked = true; 931 })[0].checked = true;
927 932
928 $scope.hojaRuta.datosExtra = datosExtra; 933 $scope.hojaRuta.datosExtra = datosExtra;
929 }, function () { 934 }, function () {
930 //se ejecuta cuando se cancela el modal 935 //se ejecuta cuando se cancela el modal
931 }); 936 });
932 }; 937 };
933 938
934 $scope.desasociarRemito = function (key, idRemito) { 939 $scope.desasociarRemito = function (key, idRemito) {
935 var idsRemito = [idRemito]; 940 var idsRemito = [idRemito];
936 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + 941 focaModalService.confirm('¿Está seguro que desea desasociar este remito del' +
937 ' vehículo?').then(function () { 942 ' vehículo?').then(function () {
938 focaCrearHojaRutaService.desasociarRemitos(idsRemito, 943 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
939 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1) 944 $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1)
940 .then(function () { 945 .then(function () {
941 $scope.hojaRuta.remitosTabla.splice(key, 1); 946 $scope.hojaRuta.remitosTabla.splice(key, 1);
942 focaModalService.alert('Remito desasociado con éxito'); 947 focaModalService.alert('Remito desasociado con éxito');
943 }); 948 });
944 }); 949 });
945 }; 950 };
946 951
947 $scope.verProductosRemito = function (idRemito) { 952 $scope.verProductosRemito = function (idRemito) {
948 var parametrosModal = { 953 var parametrosModal = {
949 titulo: 'Articulos remito', 954 titulo: 'Articulos remito',
950 query: '/articulos/remito/' + idRemito, 955 query: '/articulos/remito/' + idRemito,
951 soloMostrar: true, 956 soloMostrar: true,
952 columnas: [ 957 columnas: [
953 { 958 {
954 nombre: 'Código', 959 nombre: 'Código',
955 propiedad: 'codigo' 960 propiedad: 'codigo'
956 }, 961 },
957 { 962 {
958 nombre: 'Descripción', 963 nombre: 'Descripción',
959 propiedad: 'descripcion' 964 propiedad: 'descripcion'
960 }, 965 },
961 { 966 {
962 nombre: 'Cantidad', 967 nombre: 'Cantidad',
963 propiedad: 'cantidad' 968 propiedad: 'cantidad'
964 } 969 }
965 ] 970 ]
966 }; 971 };
967 focaModalService.modal(parametrosModal).then(); 972 focaModalService.modal(parametrosModal).then();
968 }; 973 };
969 974
970 $scope.mostrarDetalle = function (hojasRutas) { 975 $scope.mostrarDetalle = function (hojasRutas) {
971 976 var modalInstance = $uibModal.open(
972 var modalInstance =$uibModal.open(
973 { 977 {
974 ariaLabelledBy: '', 978 ariaLabelledBy: '',
975 templateUrl: 'modal-detalle-carga.html', 979 templateUrl: 'modal-detalle-carga.html',
976 controller: 'focaModalDetalleController', 980 controller: 'focaModalDetalleController',
977 resolve: { 981 resolve: {
978 parametrosModal: function () { 982 parametrosModal: function () {
979 return { 983 return {
980 hojasRutas: hojasRutas, 984 hojasRutas: hojasRutas,
981 orden: $scope.hojaRuta.orden 985 orden: $scope.hojaRuta.orden
982 } 986 };
983 } 987 }
984 }, 988 },
985 size: 'lg', 989 size: 'lg',
986 backdrop: false 990 backdrop: false
987 } 991 }
988 ); 992 );
989 return modalInstance.result.then(function (res) { 993 return modalInstance.result
990 res.cisternas.forEach( function (cisterna) { 994 .then(function (res) {
991 $scope.cisternaCargas.push(cisterna.cisternaCarga); 995 res.cisternas.forEach(function (cisterna) {
992 }); 996 $scope.cisternaCargas.push(cisterna.cisternaCarga);
993 $scope.cisternaMovimientos = res.movimientos; 997 });
994 $scope.articulosRecibidos = res.articulos; 998 $scope.cisternaMovimientos = res.movimientos;
995 $scope.articulos = res.articulos; 999 $scope.articulosRecibidos = res.articulos;
996 $filter('filter')($scope.botonera, { 1000 $scope.articulos = res.articulos;
997 label: 'Detalle de Carga', 1001 $filter('filter')($scope.botonera, {
998 })[0].checked = true; 1002 label: 'Detalle de Carga',
999 }, function () { 1003 })[0].checked = true;
1000 //se ejecuta cuando se cancela el modal 1004 })
1001 }); 1005 .catch(function (e) { console.error(e); });
1002 }; 1006 };
1003 1007
1004 function elegirFecha() { 1008 function elegirFecha() {
1005 var fechaEntrega = { 1009 var fechaEntrega = {
1006 titulo: 'Fecha de entrega', 1010 titulo: 'Fecha de entrega',
1007 minDate: new Date() 1011 minDate: new Date()
1008 }; 1012 };
1009 focaModalService.modalFecha(fechaEntrega).then(function (fecha) { 1013 focaModalService.modalFecha(fechaEntrega).then(function (fecha) {
1010 1014
1011 $scope.hojaRuta.fechaReparto = fecha; 1015 $scope.hojaRuta.fechaReparto = fecha;
1012 1016
1013 $scope.$broadcast('addCabecera', { 1017 $scope.$broadcast('addCabecera', {
1014 label: 'Fecha de entrega: ', 1018 label: 'Fecha de entrega: ',
1015 valor: fecha.toLocaleDateString() 1019 valor: fecha.toLocaleDateString()
1016 }); 1020 });
1017 1021
1018 $filter('filter')($scope.botonera, { 1022 $filter('filter')($scope.botonera, {
1019 label: 'Fecha Entrega', 1023 label: 'Fecha Entrega',
1020 })[0].checked = true; 1024 })[0].checked = true;
1021 }); 1025 });
1022 } 1026 }
1023 1027
1024 function eligioPreConfirmado() { 1028 function eligioPreConfirmado() {
1025 if ($scope.eligioPreConfirmado) { 1029 if ($scope.eligioPreConfirmado) {
1026 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); 1030 focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado');
1027 return true; 1031 return true;
1028 } 1032 }
1029 return false; 1033 return false;
1030 } 1034 }
1031 1035
1032 function eligioFecha() { 1036 function eligioFecha() {
1033 if (!$scope.hojaRuta.fechaReparto) { 1037 if (!$scope.hojaRuta.fechaReparto) {
1034 focaModalService.alert('Primero seleccione fecha de reparto'); 1038 focaModalService.alert('Primero seleccione fecha de reparto');
1035 return false; 1039 return false;
1036 } 1040 }
1037 return true; 1041 return true;
1038 } 1042 }
1039 1043
1040 function eligioVehiculo() { 1044 function eligioVehiculo() {
1041 if (!$scope.hojaRuta.vehiculo.id) { 1045 if (!$scope.hojaRuta.vehiculo.id) {
1042 focaModalService.alert('Primero seleccione vehiculo'); 1046 focaModalService.alert('Primero seleccione vehiculo');
1043 return false; 1047 return false;
1044 } 1048 }
1045 return true; 1049 return true;
1046 } 1050 }
1047 1051
1048 function modalVehiculos(preCargados) { 1052 function modalVehiculos(preCargados) {
1049 1053
1050 var parametrosModal = {}; 1054 var parametrosModal = {};
1051 if (preCargados) { 1055 if (preCargados) {
1052 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + 1056 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
1053 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); 1057 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10);
1054 parametrosModal.titulo = 'Búsqueda de vehiculos precargados'; 1058 parametrosModal.titulo = 'Búsqueda de vehiculos precargados';
1055 } else { 1059 } else {
1056 parametrosModal.query = '/vehiculo'; 1060 parametrosModal.query = '/vehiculo';
1057 parametrosModal.titulo = 'Búsqueda de vehículos'; 1061 parametrosModal.titulo = 'Búsqueda de vehículos';
1058 } 1062 }
1059 parametrosModal.columnas = [ 1063 parametrosModal.columnas = [
1060 { 1064 {
1061 propiedad: 'codigo', 1065 propiedad: 'codigo',
1062 nombre: 'Código' 1066 nombre: 'Código'
1063 }, 1067 },
1064 { 1068 {
1065 propiedad: 'tractor', 1069 propiedad: 'tractor',
1066 nombre: 'tractor' 1070 nombre: 'tractor'
1067 }, 1071 },
1068 { 1072 {
1069 propiedad: 'semi', 1073 propiedad: 'semi',
1070 nombre: 'Semi' 1074 nombre: 'Semi'
1071 } 1075 }
1072 ]; 1076 ];
1073 1077
1074 focaModalService.modal(parametrosModal).then(function (vehiculo) { 1078 focaModalService.modal(parametrosModal).then(function (vehiculo) {
1075 if (!preCargados && vehiculoEnUso(vehiculo)) return; 1079 if (!preCargados && vehiculoEnUso(vehiculo)) return;
1076 $scope.hojaRuta.vehiculo = vehiculo; 1080 $scope.hojaRuta.vehiculo = vehiculo;
1077 $scope.hojaRuta.transportista = vehiculo.transportista; 1081 $scope.hojaRuta.transportista = vehiculo.transportista;
1078 // mostrarDetalle(vehiculo); 1082 // mostrarDetalle(vehiculo);
1079 if (preCargados) { 1083 if (preCargados) {
1080 $scope.eligioPreConfirmado = true; 1084 $scope.eligioPreConfirmado = true;
1081 $scope.hojaRuta.vehiculo = vehiculo; 1085 $scope.hojaRuta.vehiculo = vehiculo;
1082 $scope.$broadcast('addCabecera', { 1086 $scope.$broadcast('addCabecera', {
1083 label: 'Transportista:', 1087 label: 'Transportista:',
1084 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + 1088 valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) +
1085 ' - ' + vehiculo.transportista.NOM 1089 ' - ' + vehiculo.transportista.NOM
1086 }); 1090 });
1087 focaCrearHojaRutaService 1091 focaCrearHojaRutaService
1088 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) 1092 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto)
1089 .then(function (res) { 1093 .then(function (res) {
1090 $filter('filter')($scope.botonera, { 1094 $filter('filter')($scope.botonera, {
1091 label: 'Transportista', 1095 label: 'Transportista',
1092 })[0].checked = true; 1096 })[0].checked = true;
1093 1097
1094 $filter('filter')($scope.botonera, { 1098 $filter('filter')($scope.botonera, {
1095 label: 'Vehiculo', 1099 label: 'Vehiculo',
1096 })[0].checked = true; 1100 })[0].checked = true;
1097 1101
1098 $scope.hojaRuta.remitosTabla = res.data; 1102 $scope.hojaRuta.remitosTabla = res.data;
1099 }); 1103 });
1100 } else { 1104 } else {
1101 focaCrearHojaRutaService 1105 focaCrearHojaRutaService
1102 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) 1106 .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true)
1103 .then(function (res) { 1107 .then(function (res) {
1104 1108
1105 $filter('filter')($scope.botonera, { 1109 $filter('filter')($scope.botonera, {
1106 label: 'Vehiculo', 1110 label: 'Vehiculo',
1107 })[0].checked = true; 1111 })[0].checked = true;
1108 1112
1109 $scope.hojaRuta.remitosTabla = res.data; 1113 $scope.hojaRuta.remitosTabla = res.data;
1110 }); 1114 });
1111 } 1115 }
1112 1116
1113 focaCrearHojaRutaService 1117 focaCrearHojaRutaService
1114 .getNumeroOrden(vehiculo.id, $scope.hojaRuta.fechaReparto) 1118 .getNumeroOrden(vehiculo.id, $scope.hojaRuta.fechaReparto)
1115 .then(function(res) { 1119 .then(function (res) {
1116 $scope.hojaRuta.orden = res.data; 1120 $scope.hojaRuta.orden = res.data;
1117 }); 1121 });
1118 1122
1119 $scope.$broadcast('addCabecera', { 1123 $scope.$broadcast('addCabecera', {
1120 label: 'Tractor:', 1124 label: 'Tractor:',
1121 valor: vehiculo.tractor 1125 valor: vehiculo.tractor
1122 }); 1126 });
1123 $scope.$broadcast('addCabecera', { 1127 $scope.$broadcast('addCabecera', {
1124 label: 'Semi:', 1128 label: 'Semi:',
1125 valor: vehiculo.semi 1129 valor: vehiculo.semi
1126 }); 1130 });
1127 $scope.$broadcast('addCabecera', { 1131 $scope.$broadcast('addCabecera', {
1128 label: 'Capacidad:', 1132 label: 'Capacidad:',
1129 valor: vehiculo.capacidad 1133 valor: vehiculo.capacidad
1130 }); 1134 });
1131 1135
1132 }); 1136 });
1133 } 1137 }
1134 1138
1135 function vehiculoEnUso(vehiculo) { 1139 function vehiculoEnUso(vehiculo) {
1136 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; 1140 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
1137 for (var i = 0; i < vehiculo.cisternas.length; i++) { 1141 for (var i = 0; i < vehiculo.cisternas.length; i++) {
1138 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { 1142 for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
1139 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; 1143 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
1140 if (cisternaCarga.fechaReparto.substring(0, 10) === 1144 if (cisternaCarga.fechaReparto.substring(0, 10) ===
1141 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && 1145 new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) &&
1142 cisternaCarga.idUsuarioProceso && 1146 cisternaCarga.idUsuarioProceso &&
1143 cisternaCarga.idUsuarioProceso !== idUsuario) { 1147 cisternaCarga.idUsuarioProceso !== idUsuario) {
1144 focaModalService.alert('El vehículo está siendo usado por otro' + 1148 focaModalService.alert('El vehículo está siendo usado por otro' +
1145 ' usuario'); 1149 ' usuario');
1146 return true; 1150 return true;
1147 } 1151 }
1148 } 1152 }
1149 } 1153 }
1150 return false; 1154 return false;
1151 } 1155 }
1152 1156
1153 function salir() { 1157 function salir() {
1154 var confirmacion = false; 1158 var confirmacion = false;
1155 1159
1156 if (!angular.equals($scope.hojaRuta, $scope.inicial)) { 1160 if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
1157 confirmacion = true; 1161 confirmacion = true;
1158 } 1162 }
1159 1163
1160 if (confirmacion) { 1164 if (confirmacion) {
1161 focaModalService.confirm( 1165 focaModalService.confirm(
1162 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1166 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1163 ).then(function (data) { 1167 ).then(function (data) {
1164 if (data) { 1168 if (data) {
1165 $location.path('/'); 1169 $location.path('/');
1166 } 1170 }
1167 }); 1171 });
1168 } else { 1172 } else {
1169 $location.path('/'); 1173 $location.path('/');
1170 } 1174 }
1171 } 1175 }
1172 1176
1173 function limpiarBotonera(botonera) { 1177 function limpiarBotonera(botonera) {
1174 botonera.forEach(function (boton) { 1178 botonera.forEach(function (boton) {
1175 boton.checked = false; 1179 boton.checked = false;
1176 }); 1180 });
1177 } 1181 }
1178 function setearHojaRuta(hojaRuta) { 1182 function setearHojaRuta(hojaRuta) {
1179 $scope.$broadcast('cleanCabecera'); 1183 $scope.$broadcast('cleanCabecera');
1180 1184
1181 var cabeceras = []; 1185 var cabeceras = [];
1182 if (hojaRuta.fechaReparto) { 1186 if (hojaRuta.fechaReparto) {
1183 cabeceras.push({ 1187 cabeceras.push({
1184 label: 'Fecha de entrega:', 1188 label: 'Fecha de entrega:',
1185 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') 1189 valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
1186 }); 1190 });
1187 1191
1188 $filter('filter')($scope.botonera, { 1192 $filter('filter')($scope.botonera, {
1189 label: 'Fecha Entrega' 1193 label: 'Fecha Entrega'
1190 })[0].checked = true; 1194 })[0].checked = true;
1191 } 1195 }
1192 if (hojaRuta.transportista.COD) { 1196 if (hojaRuta.transportista.COD) {
1193 cabeceras.push({ 1197 cabeceras.push({
1194 label: 'Transportista:', 1198 label: 'Transportista:',
1195 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + 1199 valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' +
1196 hojaRuta.transportista.NOM 1200 hojaRuta.transportista.NOM
1197 }); 1201 });
1198 1202
1199 $filter('filter')($scope.botonera, { 1203 $filter('filter')($scope.botonera, {
1200 label: 'Transportista' 1204 label: 'Transportista'
1201 })[0].checked = true; 1205 })[0].checked = true;
1202 } 1206 }
1203 if (hojaRuta.chofer.id) { 1207 if (hojaRuta.chofer.id) {
1204 cabeceras.push({ 1208 cabeceras.push({
1205 label: 'Chofer:', 1209 label: 'Chofer:',
1206 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + 1210 valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) +
1207 ' - ' + hojaRuta.chofer.nombre 1211 ' - ' + hojaRuta.chofer.nombre
1208 }); 1212 });
1209 1213
1210 $filter('filter')($scope.botonera, { 1214 $filter('filter')($scope.botonera, {
1211 label: 'Chofer' 1215 label: 'Chofer'
1212 })[0].checked = true; 1216 })[0].checked = true;
1213 } 1217 }
1214 if (hojaRuta.vehiculo.id) { 1218 if (hojaRuta.vehiculo.id) {
1215 cabeceras.push({ 1219 cabeceras.push({
1216 label: 'Tractor:', 1220 label: 'Tractor:',
1217 valor: hojaRuta.vehiculo.tractor 1221 valor: hojaRuta.vehiculo.tractor
1218 }); 1222 });
1219 cabeceras.push({ 1223 cabeceras.push({
1220 label: 'Semi:', 1224 label: 'Semi:',
1221 valor: hojaRuta.vehiculo.semi 1225 valor: hojaRuta.vehiculo.semi
1222 }); 1226 });
1223 cabeceras.push({ 1227 cabeceras.push({
1224 label: 'Capacidad:', 1228 label: 'Capacidad:',
1225 valor: hojaRuta.vehiculo.capacidad 1229 valor: hojaRuta.vehiculo.capacidad
1226 }); 1230 });
1227 1231
1228 $filter('filter')($scope.botonera, { 1232 $filter('filter')($scope.botonera, {
1229 label: 'Vehiculo' 1233 label: 'Vehiculo'
1230 })[0].checked = true; 1234 })[0].checked = true;
1231 } 1235 }
1232 if (hojaRuta.tarifario) { 1236 if (hojaRuta.tarifario) {
1233 cabeceras.push({ 1237 cabeceras.push({
1234 label: 'Tarifario:', 1238 label: 'Tarifario:',
1235 valor: hojaRuta.tarifario 1239 valor: hojaRuta.tarifario
1236 }); 1240 });
1237 1241
1238 $filter('filter')($scope.botonera, { 1242 $filter('filter')($scope.botonera, {
1239 label: 'Tarifario' 1243 label: 'Tarifario'
1240 })[0].checked = true; 1244 })[0].checked = true;
1241 } 1245 }
1242 1246
1243 addArrayCabecera(cabeceras); 1247 addArrayCabecera(cabeceras);
1244 $scope.hojaRuta = hojaRuta; 1248 $scope.hojaRuta = hojaRuta;
1245 } 1249 }
1246 1250
1247 function getLSHojaRuta() { 1251 function getLSHojaRuta() {
1248 if ($localStorage.data === undefined) return; 1252 if ($localStorage.data === undefined) return;
1249 1253
1250 var hojaRuta = (JSON.parse($localStorage.data))[0] || null; 1254 var hojaRuta = (JSON.parse($localStorage.data))[0] || null;
1251 if (hojaRuta) { 1255 if (hojaRuta) {
1252 setearHojaRuta(hojaRuta); 1256 setearHojaRuta(hojaRuta);
1253 delete $localStorage.data; 1257 delete $localStorage.data;
1254 } 1258 }
1255 } 1259 }
1256 1260
1257 function getLSBotoneraPrincipal() { 1261 function getLSBotoneraPrincipal() {
1258 if ($localStorage.data === undefined) return; 1262 if ($localStorage.data === undefined) return;
1259 1263
1260 var precargado = (JSON.parse($localStorage.data))[1] || null; 1264 var precargado = (JSON.parse($localStorage.data))[1] || null;
1261 var cargaRemito = (JSON.parse($localStorage.data))[2] || null; 1265 var cargaRemito = (JSON.parse($localStorage.data))[2] || null;
1262 var remitoAbierto = (JSON.parse($localStorage.data))[3] || null; 1266 var remitoAbierto = (JSON.parse($localStorage.data))[3] || null;
1263 if (remitoAbierto) { 1267 if (remitoAbierto) {
1264 $scope.remitoAbierto = remitoAbierto; 1268 $scope.remitoAbierto = remitoAbierto;
1265 $filter('filter')($scope.botoneraPrincipal, { 1269 $filter('filter')($scope.botoneraPrincipal, {
1266 label: 'Remito Abierto' 1270 label: 'Remito Abierto'
1267 })[0].checked = $scope.remitoAbierto; 1271 })[0].checked = $scope.remitoAbierto;
1268 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto(); 1272 $scope.botonera = focaCrearHojaRutaService.getRemitoAbierto();
1269 } 1273 }
1270 if (precargado) { 1274 if (precargado) {
1271 $scope.precargado = precargado; 1275 $scope.precargado = precargado;
1272 $filter('filter')($scope.botoneraPrincipal, { 1276 $filter('filter')($scope.botoneraPrincipal, {
1273 label: 'Precargados' 1277 label: 'Precargados'
1274 })[0].checked = $scope.precargado; 1278 })[0].checked = $scope.precargado;
1275 $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 1279 $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
1276 Array.prototype.push.apply($scope.botonera,focaCrearHojaRutaService.getBotoneraPrecargado()); 1280 Array.prototype.push.apply($scope.botonera,
1281 focaCrearHojaRutaService.getBotoneraPrecargado());
1277 } 1282 }
1278 if (cargaRemito) { 1283 if (cargaRemito) {
1279 $scope.cargaRemito = cargaRemito; 1284 $scope.cargaRemito = cargaRemito;
1280 $filter('filter')($scope.botoneraPrincipal, { 1285 $filter('filter')($scope.botoneraPrincipal, {
1281 label: 'Cargar Remitos' 1286 label: 'Cargar Remitos'
1282 })[0].checked = $scope.cargaRemito; 1287 })[0].checked = $scope.cargaRemito;
1283 $scope.botonera = focaCrearHojaRutaService.getBotonFecha(); 1288 $scope.botonera = focaCrearHojaRutaService.getBotonFecha();
1284 Array.prototype.push.apply($scope.botonera,focaCrearHojaRutaService.getBotoneraCargarRemito()); 1289 Array.prototype.push.apply($scope.botonera,
1290 focaCrearHojaRutaService.getBotoneraCargarRemito());
1285 } 1291 }
1286 } 1292 }
1287 1293
1288 function addArrayCabecera(array) { 1294 function addArrayCabecera(array) {