Commit bd6424ad36d0a2ca7daab02d473f5b4236ee29c1
Exists in
master
Merge branch 'master' into 'master'
guardado hoja ruta See merge request modulos-npm/foca-crear-hoja-ruta!7
Showing
3 changed files
Show diff stats
src/js/controller.js
1 | 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
2 | 2 | [ |
3 | - '$scope', '$uibModal', '$location', '$filter', 'crearHojaRutaService', | |
4 | - 'focaModalService', 'focaSeguimientoService', 'hojaRutaBusinessService', | |
5 | - function( | |
6 | - $scope, $uibModal, $location, $filter, crearHojaRutaService, focaModalService, | |
7 | - focaSeguimientoService, hojaRutaBusinessService | |
8 | - ) { | |
3 | + '$scope', '$uibModal', '$location', '$filter', 'crearHojaRutaService', 'focaModalService', | |
4 | + function($scope, $uibModal, $location, $filter, crearHojaRutaService, focaModalService) { | |
9 | 5 | $scope.botonera = [ |
10 | 6 | {texto: 'Transportista', accion: function() {$scope.seleccionarProveedor();}}, |
11 | 7 | {texto: 'Chofer', accion: function() {$scope.seleccionarChofer();}}, |
... | ... | @@ -100,90 +96,80 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
100 | 96 | // }; |
101 | 97 | |
102 | 98 | $scope.crearHojaRuta = function() { |
103 | - if(!$scope.hojaRuta.vendedor.codigo) { | |
104 | - focaModalService.alert('Ingrese Vendedor'); | |
99 | + if($scope.hojaRuta.litros <= 0) { | |
100 | + focaModalService.alert('Ingrese Remitos'); | |
105 | 101 | return; |
106 | - } else if(!$scope.hojaRuta.cliente.cod) { | |
107 | - focaModalService.alert('Ingrese Cliente'); | |
108 | - return; | |
109 | - } else if(!$scope.hojaRuta.transportista.codigo) { | |
110 | - focaModalService.alert('Ingrese Transportista'); | |
111 | - return; | |
112 | - } else if(!$scope.hojaRuta.moneda.id) { | |
113 | - focaModalService.alert('Ingrese Moneda'); | |
114 | - return; | |
115 | - } else if(!$scope.hojaRuta.cotizacion.ID) { | |
116 | - focaModalService.alert('Ingrese Cotización'); | |
102 | + } | |
103 | + | |
104 | + if(!$scope.hojaRuta.chofer.id) { | |
105 | + focaModalService.alert('Ingrese Chofer'); | |
117 | 106 | return; |
118 | - } else if(!$scope.plazosPagos) { | |
119 | - focaModalService.alert('Ingrese Precios y Condiciones'); | |
107 | + } | |
108 | + | |
109 | + if(!$scope.hojaRuta.vehiculo.id) { | |
110 | + focaModalService.alert('Ingrese Vehiculo'); | |
120 | 111 | return; |
121 | - } else if( | |
122 | - $scope.hojaRuta.flete === undefined || $scope.hojaRuta.flete === null) | |
123 | - { | |
124 | - focaModalService.alert('Ingrese Flete'); | |
112 | + } | |
113 | + | |
114 | + if(!$scope.hojaRuta.transportista.codigo) { | |
115 | + focaModalService.alert('Ingrese Transportista'); | |
125 | 116 | return; |
126 | - } else if(!$scope.hojaRuta.domicilio.id) { | |
127 | - focaModalService.alert('Ingrese Domicilio'); | |
117 | + } | |
118 | + | |
119 | + if($scope.hojaRuta.vehiculo.capacidad < $scope.hojaRuta.litros) { | |
120 | + focaModalService.alert( | |
121 | + 'La capacidad del Vehiculo es menor a lo ingresado en Remitos' | |
122 | + ); | |
128 | 123 | return; |
129 | - } else if($scope.remitosTabla.length === 0) { | |
130 | - focaModalService.alert('Debe cargar al menos un articulo'); | |
124 | + } | |
125 | + | |
126 | + if(!$scope.hojaRuta.tarifario.costo) { | |
127 | + focaModalService.alert('Ingrese Tarifario'); | |
131 | 128 | return; |
132 | - } | |
129 | + } | |
130 | + | |
133 | 131 | var date = new Date(); |
134 | - var hojaRuta = { | |
135 | - id: 0, | |
136 | - fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | |
137 | - .toISOString().slice(0, 19).replace('T', ' '), | |
138 | - idVendedor: $scope.hojaRuta.vendedor.codigo, | |
139 | - idCliente: $scope.hojaRuta.cliente.cod, | |
140 | - nombreCliente: $scope.hojaRuta.cliente.nom, | |
141 | - cuitCliente: $scope.hojaRuta.cliente.cuit, | |
142 | - idDomicilio: $scope.hojaRuta.domicilio.id, | |
143 | - idProveedor: $scope.hojaRuta.transportista.codigo, | |
144 | - idCotizacion: $scope.hojaRuta.cotizacion.ID, | |
145 | - cotizacion: $scope.hojaRuta.cotizacion.COTIZACION, | |
146 | - flete: $scope.hojaRuta.flete, | |
147 | - fob: $scope.hojaRuta.fob, | |
148 | - bomba: $scope.hojaRuta.bomba, | |
149 | - kilometros: $scope.hojaRuta.kilometros, | |
150 | - estado: 0, | |
151 | - total: $scope.getTotal() | |
132 | + var save = { | |
133 | + hojaRuta: { | |
134 | + id: 0, | |
135 | + fechaCreacion: | |
136 | + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | |
137 | + .toISOString().slice(0, 19) .replace('T', ' '), | |
138 | + idTransportista: $scope.hojaRuta.transportista.codigo, | |
139 | + idChofer: $scope.hojaRuta.chofer.id, | |
140 | + idVehiculo: $scope.hojaRuta.vehiculo.id, | |
141 | + tarifaFlete: $scope.hojaRuta.tarifario.costo | |
142 | + }, | |
143 | + remitos: $scope.remitosTabla | |
152 | 144 | }; |
153 | - crearHojaRutaService.crearHojaRuta(hojaRuta).then( | |
154 | - function(data) { | |
155 | - hojaRutaBusinessService.addArticulos($scope.remitosTabla, | |
156 | - data.data.id, $scope.hojaRuta.cotizacion.COTIZACION); | |
157 | - focaSeguimientoService.guardarPosicion('crear nota pedido', ''); | |
158 | - var plazos = $scope.plazosPagos; | |
159 | - | |
160 | - for(var j = 0; j < plazos.length; j++) { | |
161 | - var json = { | |
162 | - idPedido: data.data.id, | |
163 | - dias: plazos[j].dias | |
164 | - }; | |
165 | - crearHojaRutaService.crearPlazosParaHojaRuta(json); | |
166 | - } | |
167 | - hojaRutaBusinessService.addEstado(data.data.id, | |
168 | - $scope.hojaRuta.vendedor.codigo); | |
169 | 145 | |
170 | - focaModalService.alert('Nota pedido creada'); | |
171 | - $scope.cabecera = []; | |
172 | - addCabecera('Moneda:', $scope.hojaRuta.moneda.detalle); | |
173 | - addCabecera( | |
174 | - 'Fecha cotizacion:', | |
175 | - $filter('date')($scope.hojaRuta.cotizacion.FECHA, 'dd/MM/yyyy') | |
146 | + crearHojaRutaService.crearHojaRuta(save).then( | |
147 | + function(data) { | |
148 | + focaModalService.alert( | |
149 | + 'Hoja ruta creada Nº: ' + | |
150 | + $scope.rellenar(data.sucursal, 4) + | |
151 | + '-' + | |
152 | + $scope.rellenar(data.numeroHojaRuta, 8) | |
176 | 153 | ); |
177 | - addCabecera('Cotizacion:', $scope.hojaRuta.cotizacion.COTIZACION); | |
178 | - $scope.hojaRuta.vendedor = {}; | |
179 | - $scope.hojaRuta.cliente = {}; | |
180 | - $scope.hojaRuta.domicilio = {}; | |
181 | - $scope.hojaRuta.transportista = {}; | |
182 | - $scope.hojaRuta.flete = null; | |
183 | - $scope.hojaRuta.fob = null; | |
184 | - $scope.hojaRuta.bomba = null; | |
185 | - $scope.hojaRuta.kilometros = null; | |
154 | + $scope.hojaRuta = { | |
155 | + fecha: new Date(), | |
156 | + litros: 0, | |
157 | + chofer: {}, | |
158 | + vehiculo: { | |
159 | + capacidad: 0 | |
160 | + }, | |
161 | + transportista: {}, | |
162 | + tarifario: { | |
163 | + costo: null | |
164 | + } | |
165 | + }; | |
166 | + | |
186 | 167 | $scope.remitosTabla = []; |
168 | + $scope.cabecera = []; | |
169 | + | |
170 | + crearHojaRutaService.getNumeroHojaRuta().then(function(res) { | |
171 | + $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); | |
172 | + }); | |
187 | 173 | }, |
188 | 174 | function(error) { |
189 | 175 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
... | ... | @@ -282,7 +268,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
282 | 268 | // funcion ejecutada cuando se cancela el modal |
283 | 269 | } |
284 | 270 | ); |
285 | - } | |
271 | + }; | |
286 | 272 | |
287 | 273 | $scope.seleccionarRemito = function() { |
288 | 274 | var modalInstance = $uibModal.open( |
... | ... | @@ -296,15 +282,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
296 | 282 | modalInstance.result.then( |
297 | 283 | function(remito) { |
298 | 284 | for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { |
299 | - if ($scope.remitosTabla[i].id == remito.id) { | |
285 | + if ($scope.remitosTabla[i].id === remito.id) { | |
300 | 286 | focaModalService.alert('Remito ya incluido'); |
301 | 287 | return; |
302 | 288 | } |
303 | 289 | } |
304 | 290 | |
305 | 291 | var litros = 0; |
306 | - for (var i = remito.articulosRemito.length - 1; i >= 0; i--) { | |
307 | - litros = litros + parseFloat(remito.articulosRemito[i].cantidad); | |
292 | + for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | |
293 | + litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | |
308 | 294 | } |
309 | 295 | |
310 | 296 | if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
... | ... | @@ -393,7 +379,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
393 | 379 | } |
394 | 380 | |
395 | 381 | return relleno; |
396 | - } | |
382 | + }; | |
397 | 383 | |
398 | 384 | $scope.quitarArticulo = function(key) { |
399 | 385 | $scope.remitosTabla.splice(key, 1); |
... | ... | @@ -416,14 +402,12 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
416 | 402 | } |
417 | 403 | } |
418 | 404 | |
419 | - function removeCabecera(label) { | |
405 | + /*function removeCabecera(label) { | |
420 | 406 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
421 | 407 | if(propiedad.length === 1){ |
422 | 408 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
423 | 409 | } |
424 | - } | |
425 | - | |
426 | - | |
410 | + }*/ | |
427 | 411 | } |
428 | 412 | ] |
429 | 413 | ) |
src/js/service.js
... | ... | @@ -3,7 +3,7 @@ angular.module('focaCrearHojaRuta') |
3 | 3 | var route = API_ENDPOINT.URL; |
4 | 4 | return { |
5 | 5 | crearHojaRuta: function(hojaRuta) { |
6 | - return $http.post(route + '/hoja-ruta', {hojaRuta: hojaRuta}); | |
6 | + return $http.post(route + '/hoja-ruta', hojaRuta); | |
7 | 7 | }, |
8 | 8 | obtenerHojaRuta: function() { |
9 | 9 | return $http.get(route +'/hoja-ruta'); |
src/views/hoja-ruta.html
... | ... | @@ -325,7 +325,7 @@ |
325 | 325 | <div class="row align-items-end"> |
326 | 326 | <div class="col-12"> |
327 | 327 | <button |
328 | - ng-click="crearNotaPedido()" | |
328 | + ng-click="crearHojaRuta()" | |
329 | 329 | type="submit" |
330 | 330 | title="Crear nota pedido" |
331 | 331 | class="btn btn-default btn-block mb-2"> |
... | ... | @@ -345,7 +345,7 @@ |
345 | 345 | <div class="row d-md-none fixed-bottom"> |
346 | 346 | <div class="w-100 bg-dark d-flex px-3 acciones-mobile"> |
347 | 347 | <span class="ml-3 text-muted" ng-click="salir()">Salir</span> |
348 | - <span class="mr-3 ml-auto" ng-click="crearNotaPedido()">Guardar</span> | |
348 | + <span class="mr-3 ml-auto" ng-click="crearHojaRuta()">Guardar</span> | |
349 | 349 | </div> |
350 | 350 | </div> |
351 | 351 | </div> |