Commit d9bc6cf24667e15d7421ac0c8ef795c66103d198

Authored by Mauricio Cattafi
Exists in master

Merge branch 'develop' into 'master'

Develop

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