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