diff --git a/package.json b/package.json index 0a4700d..41c94be 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "angular-route": "^1.7.5", "bootstrap": "^4.1.3", "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git", + "foca-modal-chofer": "git+https://debo.suite.repo/modulos-npm/foca-modal-chofer.git", "foca-modal-remito": "git+https://debo.suite.repo/modulos-npm/foca-modal-remito.git", "font-awesome": "^4.7.0", "gulp": "^3.9.1", diff --git a/src/js/controller.js b/src/js/controller.js index 608b4be..6d41f51 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -100,90 +100,80 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', // }; $scope.crearHojaRuta = function() { - if(!$scope.hojaRuta.vendedor.codigo) { - focaModalService.alert('Ingrese Vendedor'); + if($scope.hojaRuta.litros <= 0) { + focaModalService.alert('Ingrese Remitos'); return; - } else if(!$scope.hojaRuta.cliente.cod) { - focaModalService.alert('Ingrese Cliente'); - return; - } else if(!$scope.hojaRuta.transportista.codigo) { - focaModalService.alert('Ingrese Transportista'); - return; - } else if(!$scope.hojaRuta.moneda.id) { - focaModalService.alert('Ingrese Moneda'); - return; - } else if(!$scope.hojaRuta.cotizacion.ID) { - focaModalService.alert('Ingrese Cotización'); + } + + if(!$scope.hojaRuta.chofer.id) { + focaModalService.alert('Ingrese Chofer'); return; - } else if(!$scope.plazosPagos) { - focaModalService.alert('Ingrese Precios y Condiciones'); + } + + if(!$scope.hojaRuta.vehiculo.id) { + focaModalService.alert('Ingrese Vehiculo'); return; - } else if( - $scope.hojaRuta.flete === undefined || $scope.hojaRuta.flete === null) - { - focaModalService.alert('Ingrese Flete'); + } + + if(!$scope.hojaRuta.transportista.codigo) { + focaModalService.alert('Ingrese Transportista'); return; - } else if(!$scope.hojaRuta.domicilio.id) { - focaModalService.alert('Ingrese Domicilio'); + } + + if($scope.hojaRuta.vehiculo.capacidad < $scope.hojaRuta.litros) { + focaModalService.alert( + 'La capacidad del Vehiculo es menor a lo ingresado en Remitos' + ); return; - } else if($scope.remitosTabla.length === 0) { - focaModalService.alert('Debe cargar al menos un articulo'); + } + + if(!$scope.hojaRuta.tarifario.costo) { + focaModalService.alert('Ingrese Tarifario'); return; - } + } + var date = new Date(); - var hojaRuta = { - id: 0, - fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) - .toISOString().slice(0, 19).replace('T', ' '), - idVendedor: $scope.hojaRuta.vendedor.codigo, - idCliente: $scope.hojaRuta.cliente.cod, - nombreCliente: $scope.hojaRuta.cliente.nom, - cuitCliente: $scope.hojaRuta.cliente.cuit, - idDomicilio: $scope.hojaRuta.domicilio.id, - idProveedor: $scope.hojaRuta.transportista.codigo, - idCotizacion: $scope.hojaRuta.cotizacion.ID, - cotizacion: $scope.hojaRuta.cotizacion.COTIZACION, - flete: $scope.hojaRuta.flete, - fob: $scope.hojaRuta.fob, - bomba: $scope.hojaRuta.bomba, - kilometros: $scope.hojaRuta.kilometros, - estado: 0, - total: $scope.getTotal() + var save = { + hojaRuta: { + id: 0, + fechaCreacion: + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) + .toISOString().slice(0, 19) .replace('T', ' '), + idTransportista: $scope.hojaRuta.transportista.codigo, + idChofer: $scope.hojaRuta.chofer.id, + idVehiculo: $scope.hojaRuta.vehiculo.id, + tarifaFlete: $scope.hojaRuta.tarifario.costo + }, + remitos: $scope.remitosTabla }; - crearHojaRutaService.crearHojaRuta(hojaRuta).then( - function(data) { - hojaRutaBusinessService.addArticulos($scope.remitosTabla, - data.data.id, $scope.hojaRuta.cotizacion.COTIZACION); - focaSeguimientoService.guardarPosicion('crear nota pedido', ''); - var plazos = $scope.plazosPagos; - - for(var j = 0; j < plazos.length; j++) { - var json = { - idPedido: data.data.id, - dias: plazos[j].dias - }; - crearHojaRutaService.crearPlazosParaHojaRuta(json); - } - hojaRutaBusinessService.addEstado(data.data.id, - $scope.hojaRuta.vendedor.codigo); - focaModalService.alert('Nota pedido creada'); - $scope.cabecera = []; - addCabecera('Moneda:', $scope.hojaRuta.moneda.detalle); - addCabecera( - 'Fecha cotizacion:', - $filter('date')($scope.hojaRuta.cotizacion.FECHA, 'dd/MM/yyyy') + crearHojaRutaService.crearHojaRuta(save).then( + function(data) { + focaModalService.alert( + 'Hoja ruta creada Nº: ' + + rellenar(data.sucursal, 4) + + '-' + + rellenar(data.numeroHojaRuta, 8) ); - addCabecera('Cotizacion:', $scope.hojaRuta.cotizacion.COTIZACION); - $scope.hojaRuta.vendedor = {}; - $scope.hojaRuta.cliente = {}; - $scope.hojaRuta.domicilio = {}; - $scope.hojaRuta.transportista = {}; - $scope.hojaRuta.flete = null; - $scope.hojaRuta.fob = null; - $scope.hojaRuta.bomba = null; - $scope.hojaRuta.kilometros = null; + $scope.hojaRuta = { + fecha: new Date(), + litros: 0, + chofer: {}, + vehiculo: { + capacidad: 0 + }, + transportista: {}, + tarifario: { + costo: null + } + }; + $scope.remitosTabla = []; + $scope.cabecera = []; + + crearHojaRutaService.getNumeroHojaRuta().then(function(res) { + $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); + }) }, function(error) { focaModalService.alert('Hubo un error al crear la nota de pedido'); diff --git a/src/js/service.js b/src/js/service.js index 23a378a..d239037 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -3,7 +3,7 @@ angular.module('focaCrearHojaRuta') var route = API_ENDPOINT.URL; return { crearHojaRuta: function(hojaRuta) { - return $http.post(route + '/hoja-ruta', {hojaRuta: hojaRuta}); + return $http.post(route + '/hoja-ruta', hojaRuta); }, obtenerHojaRuta: function() { return $http.get(route +'/hoja-ruta'); diff --git a/src/views/hoja-ruta.html b/src/views/hoja-ruta.html index 60cc87c..117490e 100644 --- a/src/views/hoja-ruta.html +++ b/src/views/hoja-ruta.html @@ -325,7 +325,7 @@