From 9b9585d7197beab83a50d029e343c4abc02bcfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s?= Date: Fri, 9 Nov 2018 13:29:15 -0300 Subject: [PATCH] init commit --- .gitignore | 6 + .jshintrc | 64 +++++ gulpfile.js | 90 ++++++ package.json | 40 +++ src/etc/develop.js.ejemplo | 4 + src/js/app.js | 18 ++ src/js/businessService.js | 27 ++ src/js/controller.js | 665 +++++++++++++++++++++++++++++++++++++++++++++ src/js/route.js | 7 + src/js/service.js | 59 ++++ src/views/hoja-ruta.html | 480 ++++++++++++++++++++++++++++++++ 11 files changed, 1460 insertions(+) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/etc/develop.js.ejemplo create mode 100644 src/js/app.js create mode 100644 src/js/businessService.js create mode 100644 src/js/controller.js create mode 100644 src/js/route.js create mode 100644 src/js/service.js create mode 100644 src/views/hoja-ruta.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76a3502 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/dist +package-lock\.json +/src/etc/develop.js + +tmp/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d8cbb07 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,64 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + "browser": true, + + // Define globals exposed by jQuery. + "jquery": true, + + // Define globals exposed by Node.js. + "node": true, + + // Allow ES6. + "esversion": 6, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + "camelcase": true, + + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, + + // Enforce tab width of 2 spaces. + "indent": 4, + + // Prohibit use of a variable before it is defined. + "latedef": false, + + // Enforce line length to 100 characters + "maxlen": 100, + + // Require capitalized names for constructor functions. + "newcap": true, + + // Enforce use of single quotation marks for strings. + "quotmark": "single", + + // Enforce placing 'use strict' at the top function scope + "strict": false, + + // Prohibit use of explicitly undeclared variables. + "undef": true, + + // Warn when variables are defined but never used. + "unused": true, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..bb46a12 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,90 @@ +const templateCache = require('gulp-angular-templatecache'); +const clean = require('gulp-clean'); +const concat = require('gulp-concat'); +const htmlmin = require('gulp-htmlmin'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const gulp = require('gulp'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); +const replace = require('gulp-replace'); +const connect = require('gulp-connect'); + +var paths = { + srcJS: 'src/js/*.js', + srcViews: 'src/views/*.html', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('templates', ['clean'], function() { + return pump( + [ + gulp.src(paths.srcViews), + htmlmin(), + templateCache('views.js', { + module: 'focaCrearHojaRuta', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-crear-hoja-ruta.js'), + replace('src/views/', ''), + gulp.dest(paths.tmp), + rename('foca-crear-hoja-ruta.min.js'), + uglify(), + /*replace('"ngRoute","ui.bootstrap","focaModalVendedores","focaBusquedaProductos",'+ + '"focaModalProveedor","focaBusquedaCliente","focaModalPrecioCondicion",'+ + '"focaModalFlete","focaDirectivas","focaModal","focaModalDomicilio",'+ + '"focaModalMoneda","focaModalCotizacion","focaSeguimiento","angular-ladda",'+ + '"cordovaGeolocationModule"', ''),*/ + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('clean', function(){ + return gulp.src(['tmp', 'dist'], {read: false}) + .pipe(clean()); +}); + +gulp.task('pre-commit', function() { + return pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + + gulp.start('uglify'); +}); + +gulp.task('webserver', function() { + pump [ + connect.server({port: 3300, host: '0.0.0.0'}) + ] +}); + +gulp.task('clean-post-install', function() { + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', + 'index.html'], {read: false}) + .pipe(clean()); +}); + +gulp.task('default', ['webserver']); + +gulp.task('watch', function() { + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..117c3ad --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "foca-crear-hoja-ruta", + "version": "0.0.1", + "description": "foca-crear-hoja-ruta", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git" + }, + "author": "Nicolás Guarnieri", + "license": "ISC", + "devDependencies": { + "angular": "^1.7.5", + "angular-route": "^1.7.5", + "bootstrap": "^4.1.3", + "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git", + "font-awesome": "^4.7.0", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.5", + "gulp-clean": "^0.4.0", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.6.1", + "gulp-htmlmin": "^5.0.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-sequence": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jasmine-core": "^3.3.0", + "jquery": "^3.3.1", + "jshint": "^2.9.6", + "ladda": "^2.0.1", + "pre-commit": "^1.2.2", + "pump": "^3.0.0", + "ui-bootstrap4": "^3.0.5" + } +} diff --git a/src/etc/develop.js.ejemplo b/src/etc/develop.js.ejemplo new file mode 100644 index 0000000..25cd0cd --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaCrearHojaRuta') + .constant("API_ENDPOINT", { + 'URL': '//127.0.0.1:9000' + }); diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..61557b1 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1,18 @@ +angular.module('focaCrearHojaRuta', [ + 'ngRoute', + 'ui.bootstrap'/*, + 'focaModalVendedores', + 'focaBusquedaProductos', + 'focaModalProveedor', + 'focaBusquedaCliente', + 'focaModalPrecioCondicion', + 'focaModalFlete', + 'focaDirectivas', + 'focaModal', + 'focaModalDomicilio', + 'focaModalMoneda', + 'focaModalCotizacion', + 'focaSeguimiento', + 'angular-ladda', + 'cordovaGeolocationModule'*/ +]); diff --git a/src/js/businessService.js b/src/js/businessService.js new file mode 100644 index 0000000..b5632da --- /dev/null +++ b/src/js/businessService.js @@ -0,0 +1,27 @@ +angular.module('focaCrearHojaRuta') + .factory('hojaRutaBusinessService', [ + 'crearHojaRutaService', + function(crearHojaRutaService) { + return { + addArticulos: function(articulosHojaRuta, idHojaRuta, cotizacion) { + for(var i = 0; i < articulosHojaRuta.length; i++) { + delete articulosHojaRuta[i].editCantidad; + delete articulosHojaRuta[i].editPrecio; + articulosHojaRuta[i].idHojaRuta = idHojaRuta; + articulosHojaRuta[i].precio = articulosHojaRuta[i].precio * cotizacion; + crearHojaRutaService.crearArticulosParaHojaRuta(articulosHojaRuta[i]); + } + }, + addEstado: function(idHojaRuta, idVendedor) { + var date = new Date(); + var estado = { + idHojaRuta: idHojaRuta, + fecha: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) + .toISOString().slice(0, 19).replace('T', ' '), + estado: 0, + idVendedor: idVendedor + }; + crearHojaRutaService.crearEstadoParaHojaRuta(estado); + } + }; + }]); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..9c8ad89 --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,665 @@ +angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', + [ + '$scope', '$uibModal', '$location', '$filter', 'crearHojaRutaService', + 'focaModalService', 'focaSeguimientoService', 'hojaRutaBusinessService', + function( + $scope, $uibModal, $location, $filter, crearHojaRutaService, focaModalService, + focaSeguimientoService, hojaRutaBusinessService + ) { + $scope.botonera = [ + {texto: 'Transportista', accion: function() {$scope.seleccionarProveedor();}}, + {texto: 'Chofer', accion: function() {$scope.seleccionarChofer();}}, + {texto: 'Vehiculo', accion: function() {$scope.seleccionarVehiculo();}}, + {texto: 'Tarifario', accion: function() {$scope.seleccionarTarifario();}}, + {texto: 'Remitos', accion: function() {$scope.seleccionarRemito();}}, + {texto: '', accion: function() {}}, + {texto: '', accion: function() {}}, + {texto: '', accion: function() {}} + ]; + $scope.datepickerAbierto = false; + + $scope.show = false; + $scope.cargando = true; + $scope.dateOptions = { + maxDate: new Date(), + minDate: new Date(2010, 0, 1) + }; + + $scope.hojaRuta = { + vendedor: {}, + cliente: {}, + proveedor: {}, + domicilio: {dom: ''}, + moneda: {}, + cotizacion: {} + }; + var monedaPorDefecto; + //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' + crearHojaRutaService.getCotizacionByIdMoneda(1).then(function(res) { + monedaPorDefecto = { + id: res.data[0].ID, + detalle: res.data[0].DETALLE, + simbolo: res.data[0].SIMBOLO, + cotizaciones: res.data[0].cotizaciones + }; + addCabecera('Moneda:', monedaPorDefecto.detalle); + addCabecera('Fecha cotizacion:', + new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); + addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); + $scope.hojaRuta.moneda = monedaPorDefecto; + $scope.hojaRuta.cotizacion = monedaPorDefecto.cotizaciones[0]; + }); + + $scope.cabecera = []; + $scope.showCabecera = true; + + $scope.now = new Date(); + $scope.puntoVenta = '0000'; + $scope.comprobante = '00000000'; + $scope.articulosTabla = []; + $scope.idLista = undefined; + //La pantalla solo se usa para cargar pedidos + //var hojaRutaTemp = crearHojaRutaService.getHojaRuta(); + + crearHojaRutaService.getPrecioCondicion().then( + function(res) { + $scope.precioCondiciones = res.data; + } + ); + + crearHojaRutaService.getNumeroHojaRuta().then( + function(res) { + $scope.puntoVenta = rellenar(res.data.sucursal, 4); + $scope.comprobante = rellenar(res.data.numeroHojaRuta, 8); + }, + function(err) { + focaModalService.alert('La terminal no esta configurada correctamente'); + console.info(err); + } + ); + //La pantalla solo se usa para cargar pedidos + // if (hojaRutaTemp !== undefined) { + // hojaRutaTemp.fechaCarga = new Date(hojaRutaTemp.fechaCarga); + // $scope.hojaRuta = hojaRutaTemp; + // $scope.hojaRuta.flete = ($scope.hojaRuta.flete).toString(); + // $scope.hojaRuta.bomba = ($scope.hojaRuta.bomba).toString(); + // $scope.idLista = $scope.hojaRuta.precioCondicion; + // crearHojaRutaService + // .getArticulosByIdHojaRuta($scope.hojaRuta.id).then( + // function(res) { + // $scope.articulosTabla = res.data; + // } + // ); + //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO + //(NO REQUERIDO EN ESTA VERSION) + // crearHojaRutaService.getDomiciliosByIdHojaRuta($scope.hojaRuta.id).then( + // function(res) { + // $scope.hojaRuta.domicilio = res.data; + // } + // ); + // } else { + // $scope.hojaRuta.fechaCarga = new Date(); + // $scope.hojaRuta.bomba = '0'; + // $scope.hojaRuta.flete = '0'; + // $scope.idLista = undefined; + // } + //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO + // $scope.addNewDom = function() { + // $scope.hojaRuta.domicilio.push({ 'id': 0 }); + // }; + // $scope.removeNewChoice = function(choice) { + // if ($scope.hojaRuta.domicilio.length > 1) { + // $scope.hojaRuta.domicilio.splice($scope.hojaRuta.domicilio.findIndex( + // function(c) { + // return c.$$hashKey === choice.$$hashKey; + // } + // ), 1); + // } + // }; + + $scope.crearHojaRuta = function() { + if(!$scope.hojaRuta.vendedor.codigo) { + focaModalService.alert('Ingrese Vendedor'); + return; + } else if(!$scope.hojaRuta.cliente.cod) { + focaModalService.alert('Ingrese Cliente'); + return; + } else if(!$scope.hojaRuta.proveedor.codigo) { + focaModalService.alert('Ingrese Proveedor'); + return; + } else if(!$scope.hojaRuta.moneda.id) { + focaModalService.alert('Ingrese Moneda'); + return; + } else if(!$scope.hojaRuta.cotizacion.ID) { + focaModalService.alert('Ingrese Cotización'); + return; + } else if(!$scope.plazosPagos) { + focaModalService.alert('Ingrese Precios y Condiciones'); + return; + } else if( + $scope.hojaRuta.flete === undefined || $scope.hojaRuta.flete === null) + { + focaModalService.alert('Ingrese Flete'); + return; + } else if(!$scope.hojaRuta.domicilio.id) { + focaModalService.alert('Ingrese Domicilio'); + return; + } else if($scope.articulosTabla.length === 0) { + focaModalService.alert('Debe cargar al menos un articulo'); + 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, + idProveedor: $scope.hojaRuta.proveedor.codigo, + idDomicilio: $scope.hojaRuta.domicilio.id, + 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() + }; + crearHojaRutaService.crearHojaRuta(hojaRuta).then( + function(data) { + hojaRutaBusinessService.addArticulos($scope.articulosTabla, + 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') + ); + addCabecera('Cotizacion:', $scope.hojaRuta.cotizacion.COTIZACION); + $scope.hojaRuta.vendedor = {}; + $scope.hojaRuta.cliente = {}; + $scope.hojaRuta.proveedor = {}; + $scope.hojaRuta.domicilio = {}; + $scope.hojaRuta.flete = null; + $scope.hojaRuta.fob = null; + $scope.hojaRuta.bomba = null; + $scope.hojaRuta.kilometros = null; + $scope.articulosTabla = []; + }, + function(error) { + focaModalService.alert('Hubo un error al crear la nota de pedido'); + console.info(error); + } + ); + }; + + $scope.seleccionarArticulo = function() { + if ($scope.idLista === undefined) { + focaModalService.alert( + 'Primero seleccione una lista de precio y condicion'); + return; + } + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Productos', + templateUrl: 'modal-busqueda-productos.html', + controller: 'modalBusquedaProductosCtrl', + resolve: { + parametroProducto: { + idLista: $scope.idLista, + cotizacion: $scope.hojaRuta.cotizacion.COTIZACION, + simbolo: $scope.hojaRuta.moneda.simbolo + } + }, + size: 'lg' + } + ); + modalInstance.result.then( + function(producto) { + var newArt = + { + id: 0, + codigo: producto.codigo, + sector: producto.sector, + sectorCodigo: producto.sector + '-' + producto.codigo, + descripcion: producto.descripcion, + item: $scope.articulosTabla.length + 1, + nombre: producto.descripcion, + precio: parseFloat(producto.precio.toFixed(4)), + costoUnitario: producto.costo, + editCantidad: false, + editPrecio: false + }; + $scope.articuloACargar = newArt; + $scope.cargando = false; + }, function() { + // funcion ejecutada cuando se cancela el modal + } + ); + }; + + $scope.seleccionarVendedor = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Vendedores', + templateUrl: 'modal-vendedores.html', + controller: 'modalVendedoresCtrl', + size: 'lg' + } + ); + modalInstance.result.then( + function(vendedor) { + addCabecera('Vendedor:', vendedor.NomVen); + $scope.hojaRuta.vendedor.codigo = vendedor.CodVen; + }, function() { + + } + ); + }; + + $scope.seleccionarProveedor = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Proveedor', + templateUrl: 'modal-proveedor.html', + controller: 'focaModalProveedorCtrl', + size: 'lg', + resolve: { + transportista: function() { + return true; + } + } + } + ); + modalInstance.result.then( + function(proveedor) { + $scope.hojaRuta.proveedor.codigo = proveedor.COD; + addCabecera('Proveedor:', proveedor.NOM); + }, function() { + + } + ); + }; + + $scope.seleccionarCliente = function() { + + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cliente', + templateUrl: 'foca-busqueda-cliente-modal.html', + controller: 'focaBusquedaClienteModalController', + size: 'lg' + } + ); + modalInstance.result.then( + function(cliente) { + $scope.abrirModalDomicilios(cliente); + }, function() { + + } + ); + }; + + $scope.abrirModalDomicilios = function(cliente) { + var modalInstanceDomicilio = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Domicilios', + templateUrl: 'modal-domicilio.html', + controller: 'focaModalDomicilioController', + resolve: { idCliente: function() { return cliente.cod; }}, + size: 'lg', + } + ); + modalInstanceDomicilio.result.then( + function(domicilio) { + $scope.hojaRuta.domicilio.id = domicilio.nivel2; + $scope.hojaRuta.cliente = cliente; + + addCabecera('Cliente:', cliente.nom); + addCabecera('Domicilio:', domicilio.Calle + ' ' + domicilio.Numero); + }, function() { + $scope.seleccionarCliente(); + return; + } + ); + }; + + $scope.mostrarFichaCliente = function() { + $uibModal.open( + { + ariaLabelledBy: 'Datos del Cliente', + templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', + controller: 'focaCrearHojaRutaFichaClienteController', + size: 'lg' + } + ); + }; + + $scope.getTotal = function() { + var total = 0; + var arrayTempArticulos = $scope.articulosTabla; + for (var i = 0; i < arrayTempArticulos.length; i++) { + total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; + } + return parseFloat(total.toFixed(2)); + }; + + $scope.getSubTotal = function() { + if($scope.articuloACargar) { + return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; + } + }; + + $scope.abrirModalListaPrecio = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Precio Condición', + templateUrl: 'modal-precio-condicion.html', + controller: 'focaModalPrecioCondicionController', + size: 'lg' + } + ); + modalInstance.result.then( + function(precioCondicion) { + var cabecera = ''; + var plazosConcat = ''; + if(!Array.isArray(precioCondicion)) { + $scope.plazosPagos = precioCondicion.plazoPago; + $scope.idLista = precioCondicion.idListaPrecio; + for(var i = 0; i < precioCondicion.plazoPago.length; i++) { + plazosConcat += precioCondicion.plazoPago[i].dias + ' '; + } + cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); + } else { //Cuando se ingresan los plazos manualmente + $scope.idLista = -1; //-1, el modal productos busca todos los productos + $scope.plazosPagos = precioCondicion; + for(var j = 0; j < precioCondicion.length; j++) { + plazosConcat += precioCondicion[j].dias + ' '; + } + cabecera = 'Ingreso manual ' + plazosConcat.trim(); + } + $scope.articulosTabla = []; + addCabecera('Precios y condiciones:', cabecera); + }, function() { + + } + ); + }; + + $scope.abrirModalFlete = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Flete', + templateUrl: 'modal-flete.html', + controller: 'focaModalFleteController', + size: 'lg', + resolve: { + parametrosFlete: + function() { + return { + flete: $scope.hojaRuta.flete ? '1' : + ($scope.hojaRuta.fob ? 'FOB' : + ($scope.hojaRuta.flete === undefined ? null : '0')), + bomba: $scope.hojaRuta.bomba ? '1' : + ($scope.hojaRuta.bomba === undefined ? null : '0'), + kilometros: $scope.hojaRuta.kilometros + }; + } + } + } + ); + modalInstance.result.then( + function(datos) { + $scope.hojaRuta.flete = datos.flete; + $scope.hojaRuta.fob = datos.FOB; + $scope.hojaRuta.bomba = datos.bomba; + $scope.hojaRuta.kilometros = datos.kilometros; + + addCabecera('Flete:', datos.flete ? 'Si' : + ($scope.hojaRuta.fob ? 'FOB' : 'No')); + if(datos.flete) { + addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); + addCabecera('Kilometros:', datos.kilometros); + } else { + removeCabecera('Bomba:'); + removeCabecera('Kilometros:'); + $scope.hojaRuta.fob = false; + $scope.hojaRuta.bomba = false; + $scope.hojaRuta.kilometros = null; + } + }, function() { + + } + ); + }; + + $scope.abrirModalMoneda = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Moneda', + templateUrl: 'modal-moneda.html', + controller: 'focaModalMonedaController', + size: 'lg' + } + ); + modalInstance.result.then( + function(moneda) { + $scope.abrirModalCotizacion(moneda); + }, function() { + + } + ); + }; + + $scope.abrirModalCotizacion = function(moneda) { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cotización', + templateUrl: 'modal-cotizacion.html', + controller: 'focaModalCotizacionController', + size: 'lg', + resolve: {idMoneda: function() {return moneda.ID;}} + } + ); + modalInstance.result.then( + function(cotizacion) { + var articulosTablaTemp = $scope.articulosTabla; + for(var i = 0; i < articulosTablaTemp.length; i++) { + articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * + $scope.hojaRuta.cotizacion.COTIZACION; + articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / + cotizacion.COTIZACION; + } + $scope.articulosTabla = articulosTablaTemp; + $scope.hojaRuta.moneda = { + id: moneda.ID, + detalle: moneda.DETALLE, + simbolo: moneda.SIMBOLO + }; + $scope.hojaRuta.cotizacion = { + ID: cotizacion.ID, + COTIZACION: cotizacion.COTIZACION, + FECHA: cotizacion.FECHA + }; + addCabecera('Moneda:', moneda.DETALLE); + addCabecera( + 'Fecha cotizacion:', + $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') + ); + addCabecera('Cotizacion:', cotizacion.COTIZACION); + }, function() { + + } + ); + }; + + $scope.agregarATabla = function(key) { + if(key === 13) { + if($scope.articuloACargar.cantidad === undefined || + $scope.articuloACargar.cantidad === 0 || + $scope.articuloACargar.cantidad === null ){ + focaModalService.alert('El valor debe ser al menos 1'); + return; + } + delete $scope.articuloACargar.sectorCodigo; + console.info($scope.articuloACargar); + $scope.articulosTabla.push($scope.articuloACargar); + $scope.cargando = true; + } + }; + + $scope.quitarArticulo = function(key) { + $scope.articulosTabla.splice(key, 1); + }; + + $scope.editarArticulo = function(key, articulo) { + if(key === 13) { + if(articulo.cantidad === null || articulo.cantidad === 0 || + articulo.cantidad === undefined){ + focaModalService.alert('El valor debe ser al menos 1'); + return; + } + articulo.editCantidad = false; + articulo.editPrecio = false; + } + }; + + $scope.cambioEdit = function(articulo, propiedad) { + if(propiedad === 'cantidad') { + articulo.editCantidad = true; + } else if(propiedad === 'precio') { + articulo.editPrecio = true; + } + }; + + $scope.limpiarFlete = function() { + $scope.hojaRuta.fleteNombre = ''; + $scope.hojaRuta.chofer = ''; + $scope.hojaRuta.vehiculo = ''; + $scope.hojaRuta.kilometros = ''; + $scope.hojaRuta.costoUnitarioKmFlete = ''; + $scope.choferes = ''; + $scope.vehiculos = ''; + }; + + $scope.limpiarPantalla = function() { + $scope.limpiarFlete(); + $scope.hojaRuta.flete = '0'; + $scope.hojaRuta.bomba = '0'; + $scope.hojaRuta.precioCondicion = ''; + $scope.articulosTabla = []; + $scope.hojaRuta.vendedor.nombre = ''; + $scope.hojaRuta.cliente = {nombre: ''}; + $scope.hojaRuta.domicilio = {dom: ''}; + $scope.domiciliosCliente = []; + }; + + $scope.resetFilter = function() { + $scope.articuloACargar = {}; + $scope.cargando = true; + }; + //Recibe aviso si el teclado está en uso + // $rootScope.$on('usarTeclado', function(event, data) { + // if(data) { + // $scope.mostrarTeclado = true; + // return; + // } + // $scope.mostrarTeclado = false; + // }) + $scope.selectFocus = function($event) { + //Si el teclado esta en uso no selecciona el valor + // if($scope.mostrarTeclado) { + // return; + // } + $event.target.select(); + }; + + $scope.salir = function() { + $location.path('/'); + }; + + $scope.parsearATexto = function(articulo) { + articulo.cantidad = parseFloat(articulo.cantidad); + articulo.precio = parseFloat(articulo.precio); + }; + + function addCabecera(label, valor) { + var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); + if(propiedad.length === 1) { + propiedad[0].valor = valor; + } else { + $scope.cabecera.push({label: label, valor: valor}); + } + } + + function removeCabecera(label) { + var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); + if(propiedad.length === 1){ + $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); + } + } + + function rellenar(relleno, longitud) { + relleno = '' + relleno; + while (relleno.length < longitud) { + relleno = '0' + relleno; + } + + return relleno; + } + } + ] +) +.controller('hojaRutaListaCtrl', [ + '$scope', + 'crearHojaRutaService', + '$location', + function($scope, crearHojaRutaService, $location) { + crearHojaRutaService.obtenerHojaRuta().then(function(datos) { + $scope.hojaRutas = datos.data; + }); + $scope.editar = function(hojaRuta) { + crearHojaRutaService.setHojaRuta(hojaRuta); + $location.path('/venta-nota-pedido/abm/'); + }; + $scope.crearPedido = function() { + crearHojaRutaService.clearHojaRuta(); + $location.path('/venta-nota-pedido/abm/'); + }; + } +]) +.controller('focaCrearHojaRutaFichaClienteController', [ + '$scope', + 'crearHojaRutaService', + '$location', + function($scope, crearHojaRutaService, $location) { + crearHojaRutaService.obtenerHojaRuta().then(function(datos) { + $scope.hojaRutas = datos.data; + }); + $scope.editar = function(hojaRuta) { + crearHojaRutaService.setHojaRuta(hojaRuta); + $location.path('/venta-nota-pedido/abm/'); + }; + $scope.crearPedido = function() { + crearHojaRutaService.clearHojaRuta(); + $location.path('/venta-nota-pedido/abm/'); + }; + } +]); diff --git a/src/js/route.js b/src/js/route.js new file mode 100644 index 0000000..b10e109 --- /dev/null +++ b/src/js/route.js @@ -0,0 +1,7 @@ +angular.module('focaCrearHojaRuta') + .config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/venta-hoja-ruta/crear', { + controller: 'hojaRutaCtrl', + templateUrl: 'src/views/hoja-ruta.html' + }); + }]); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..1f2d0a4 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,59 @@ +angular.module('focaCrearHojaRuta') + .service('crearHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { + var route = API_ENDPOINT.URL; + return { + crearHojaRuta: function(hojaRuta) { + return $http.post(route + '/nota-pedido', {hojaRuta: hojaRuta}); + }, + obtenerHojaRuta: function() { + return $http.get(route +'/nota-pedido'); + }, + setHojaRuta: function(hojaRuta) { + this.hojaRuta = hojaRuta; + }, + clearHojaRuta: function() { + this.hojaRuta = undefined; + }, + getHojaRuta: function() { + return this.hojaRuta; + }, + getArticulosByIdHojaRuta: function(id) { + return $http.get(route+'/articulos/nota-pedido/'+id); + }, + crearArticulosParaHojaRuta: function(articuloHojaRuta) { + return $http.post(route + '/articulos/nota-pedido', + {articuloHojaRuta: articuloHojaRuta}); + }, + getDomiciliosByIdHojaRuta: function(id) { + return $http.get(route +'/nota-pedido/'+id+'/domicilios'); + }, + getDomiciliosByIdCliente: function(id) { + var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) + return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); + }, + getPrecioCondicion: function() { + return $http.get(route + '/precio-condicion'); + }, + getPrecioCondicionById: function(id) { + return $http.get(route + '/precio-condicion/' + id); + }, + getPlazoPagoByPrecioCondicion: function(id) { + return $http.get(route + '/plazo-pago/precio-condicion/'+ id); + }, + crearFlete: function(flete) { + return $http.post(route + '/flete', {flete : flete}); + }, + crearPlazosParaHojaRuta: function(plazos) { + return $http.post(route + '/plazo-pago/nota-pedido', plazos); + }, + getCotizacionByIdMoneda: function(id) { + return $http.get(route + '/moneda/' + id); + }, + crearEstadoParaHojaRuta: function(estado) { + return $http.post(route + '/estado', {estado: estado}); + }, + getNumeroHojaRuta: function() { + return $http.get(route + '/nota-pedido/numero-siguiente'); + } + }; + }]); diff --git a/src/views/hoja-ruta.html b/src/views/hoja-ruta.html new file mode 100644 index 0000000..2cb8850 --- /dev/null +++ b/src/views/hoja-ruta.html @@ -0,0 +1,480 @@ +
+
+
+
+
+
+
+
+
HOJA RUTA
+
+
Nº {{puntoVenta}}-{{comprobante}} +
+
+ Fecha: + + + +
+
+
+
+ + +
+ + + + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#CódigoDescripciónCantidadPrecio UnitarioSubTotal + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ +
+ Items: + + +

Total:

+
+

{{getTotal() | currency: hojaRuta.moneda.simbolo}}

+
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
# +
+
Código
+
Descripción
+
+
+
Cantidad
+
P. Uni.
+
Subtotal
+
+
+   +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ + +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ + +
+
+
+ +
+ +
+ +
+ Cantidad Items: + + +

Total:

+
+

{{getTotal() | currency: hojaRuta.moneda.simbolo}}

+
+
+
+
+
+
+ + +
+
+
+
+
+
+ Salir + Guardar +
+
+
-- 1.9.1