Commit 6d606aaa56f16b196a5e205cc0947d64d26221c8

Authored by Jose Pinto
1 parent 0e2e6aad50
Exists in master

Primera version

... ... @@ -0,0 +1,6 @@
  1 +/node_modules
  2 +/dist
  3 +/tmp
  4 +package-lock\.json
  5 +
  6 +src/etc/develop\.js
... ... @@ -0,0 +1,64 @@
  1 +{
  2 + /*
  3 + * ENVIRONMENTS
  4 + * =================
  5 + */
  6 +
  7 + // Define globals exposed by modern browsers.
  8 + "browser": true,
  9 +
  10 + // Define globals exposed by jQuery.
  11 + "jquery": true,
  12 +
  13 + // Define globals exposed by Node.js.
  14 + "node": true,
  15 +
  16 + // Allow ES6.
  17 + "esversion": 6,
  18 +
  19 + /*
  20 + * ENFORCING OPTIONS
  21 + * =================
  22 + */
  23 +
  24 + // Force all variable names to use either camelCase style or UPPER_CASE
  25 + // with underscores.
  26 + "camelcase": true,
  27 +
  28 + // Prohibit use of == and != in favor of === and !==.
  29 + "eqeqeq": true,
  30 +
  31 + // Enforce tab width of 2 spaces.
  32 + "indent": 4,
  33 +
  34 + // Prohibit use of a variable before it is defined.
  35 + "latedef": false,
  36 +
  37 + // Enforce line length to 100 characters
  38 + "maxlen": 100,
  39 +
  40 + // Require capitalized names for constructor functions.
  41 + "newcap": true,
  42 +
  43 + // Enforce use of single quotation marks for strings.
  44 + "quotmark": "single",
  45 +
  46 + // Enforce placing 'use strict' at the top function scope
  47 + "strict": false,
  48 +
  49 + // Prohibit use of explicitly undeclared variables.
  50 + "undef": true,
  51 +
  52 + // Warn when variables are defined but never used.
  53 + "unused": true,
  54 +
  55 + // Para que funcione en angular
  56 + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"],
  57 + /*
  58 + * RELAXING OPTIONS
  59 + * =================
  60 + */
  61 +
  62 + // Suppress warnings about == null comparisons.
  63 + "eqnull": true
  64 +}
... ... @@ -0,0 +1,94 @@
  1 +const templateCache = require('gulp-angular-templatecache');
  2 +const concat = require('gulp-concat');
  3 +const htmlmin = require('gulp-htmlmin');
  4 +const rename = require('gulp-rename');
  5 +const uglify = require('gulp-uglify');
  6 +const gulp = require('gulp');
  7 +const pump = require('pump');
  8 +const jshint = require('gulp-jshint');
  9 +const replace = require('gulp-replace');
  10 +const connect = require('gulp-connect');
  11 +const clean = require('gulp-clean');
  12 +
  13 +var paths = {
  14 + srcJS: 'src/js/*.js',
  15 + srcViews: 'src/views/*.html',
  16 + tmp: 'tmp',
  17 + dist: 'dist/'
  18 +};
  19 +
  20 +gulp.task('clean', function() {
  21 + return gulp.src(['tmp', 'dist'], {read: false})
  22 + .pipe(clean());
  23 +});
  24 +
  25 +gulp.task('templates', ['clean'], function() {
  26 + return pump(
  27 + [
  28 + gulp.src(paths.srcViews),
  29 + htmlmin(),
  30 + templateCache('views.js', {
  31 + module: 'focaModalInformeChofer',
  32 + root: ''
  33 + }),
  34 + gulp.dest(paths.tmp)
  35 + ]
  36 + );
  37 +});
  38 +
  39 +gulp.task('uglify', ['templates'], function() {
  40 + return pump(
  41 + [
  42 + gulp.src([
  43 + paths.srcJS,
  44 + 'tmp/views.js'
  45 + ]),
  46 + concat('foca-modal-informe-chofer.js'),
  47 + replace('src/views/', ''),
  48 + gulp.dest(paths.tmp),
  49 + rename('foca-modal-informe-chofer.min.js'),
  50 + uglify(),
  51 + gulp.dest(paths.dist)
  52 + ]
  53 + );
  54 +});
  55 +
  56 +gulp.task('pre-commit', function() {
  57 + return pump(
  58 + [
  59 + gulp.src(paths.srcJS),
  60 + jshint('.jshintrc'),
  61 + jshint.reporter('default'),
  62 + jshint.reporter('fail')
  63 + ]
  64 + );
  65 +
  66 + gulp.start('uglify');
  67 +});
  68 +
  69 +gulp.task('webserver', function() {
  70 + pump [
  71 + connect.server({port: 3000})
  72 + ]
  73 +});
  74 +
  75 +gulp.task('clean-post-install', function() {
  76 + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
  77 + 'index.html'], {read: false})
  78 + .pipe(clean());
  79 +});
  80 +
  81 +gulp.task('default', ['webserver']);
  82 +
  83 +gulp.task('watch', function() {
  84 + gulp.watch([paths.srcJS, paths.srcViews], ['uglify'])
  85 +});
  86 +
  87 +gulp.task('copy', ['uglify'], function() {
  88 + gulp.src('dist/*.js')
  89 + .pipe(gulp.dest('../wrapper-demo/node_modules/foca-informe-hoja-ruta/dist'));
  90 +});
  91 +
  92 +gulp.task('watchAndCopy', function() {
  93 + return gulp.watch([paths.srcJS, paths.srcViews], ['copy']);
  94 +});
... ... @@ -0,0 +1,62 @@
  1 +{
  2 + "name": "foca-modal-informe-hoja-ruta",
  3 + "version": "0.0.1",
  4 + "description": "Modal para generar informes de correlatividad de hojas de ruta",
  5 + "scripts": {
  6 + "test": "echo \"Error: no test specified\" && exit 1",
  7 + "gulp-pre-commit": "gulp pre-commit",
  8 + "compile": "gulp uglify",
  9 + "postinstall": "npm run compile && gulp clean-post-install",
  10 + "install-dev": "npm install -D angular angular-ladda ladda@1.0.6 bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify gulp-clean jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+http://git.focasoftware.com/npm/foca-directivas.git"
  11 + },
  12 + "pre-commit": [
  13 + "gulp-pre-commit"
  14 + ],
  15 + "repository": {
  16 + "type": "git",
  17 + "url": "http://git.focasoftware.com/npm/foca-modal-informe-hoja-ruta"
  18 + },
  19 + "author": "Nicolรกs Guarnieri",
  20 + "license": "ISC",
  21 + "peerDependencies": {
  22 + "angular": "^1.7.4",
  23 + "bootstrap": "^4.1.3",
  24 + "font-awesome": "^4.7.0",
  25 + "ui-bootstrap4": "^3.0.4",
  26 + "gulp": "^3.9.1",
  27 + "gulp-angular-templatecache": "^2.2.1",
  28 + "gulp-concat": "^2.6.1",
  29 + "gulp-connect": "^5.6.1",
  30 + "gulp-htmlmin": "^5.0.1",
  31 + "gulp-rename": "^1.4.0",
  32 + "gulp-replace": "^1.0.0",
  33 + "gulp-uglify": "^3.0.1",
  34 + "jquery": "^3.3.1",
  35 + "pump": "^3.0.0",
  36 + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git"
  37 + },
  38 + "devDependencies": {
  39 + "angular": "^1.7.5",
  40 + "angular-ladda": "^0.4.3",
  41 + "bootstrap": "^4.1.3",
  42 + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git",
  43 + "font-awesome": "^4.7.0",
  44 + "gulp": "^3.9.1",
  45 + "gulp-angular-templatecache": "^2.2.3",
  46 + "gulp-clean": "^0.4.0",
  47 + "gulp-concat": "^2.6.1",
  48 + "gulp-connect": "^5.6.1",
  49 + "gulp-htmlmin": "^5.0.1",
  50 + "gulp-jshint": "^2.1.0",
  51 + "gulp-rename": "^1.4.0",
  52 + "gulp-replace": "^1.0.0",
  53 + "gulp-uglify": "^3.0.1",
  54 + "jasmine-core": "^3.3.0",
  55 + "jquery": "^3.3.1",
  56 + "jshint": "^2.9.6",
  57 + "ladda": "1.0.6",
  58 + "pre-commit": "^1.2.2",
  59 + "pump": "^3.0.0",
  60 + "ui-bootstrap4": "^3.0.5"
  61 + }
  62 +}
src/etc/develop.js.ejemplo
... ... @@ -0,0 +1,4 @@
  1 +angular.module('focaModalInformeChofer')
  2 + .constant("API_ENDPOINT", {
  3 + 'URL': '//127.0.0.1:9000'
  4 + });
... ... @@ -0,0 +1 @@
  1 +angular.module('focaModalInformeChofer', []);
src/js/controller.js
... ... @@ -0,0 +1,145 @@
  1 +angular.module('focaModalInformeChofer')
  2 + .controller('focaModalInformeChoferController',
  3 + [
  4 + '$filter',
  5 + '$scope',
  6 + '$uibModalInstance',
  7 + 'focaModalInformeChoferService',
  8 + 'i18nService',
  9 + function($filter, $scope, $uibModalInstance,
  10 + focaModalInformeChoferService, i18nService
  11 + ) {
  12 + var fecha = new Date();
  13 + $scope.generando = false;
  14 + $scope.fechaHasta = new Date();
  15 + $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
  16 + $scope.buscar = true;
  17 + $scope.informe = {};
  18 + i18nService.setCurrentLang('es');
  19 + $scope.gridOptions = {
  20 + enableGridMenu: true,
  21 + exporterMenuCsv: false,
  22 + exporterPdfPageSize: 'A4',
  23 + exporterPdfFooter: function (currentPage, pageCount) {
  24 + return {
  25 + columns: [
  26 + {text: $filter('date')(new Date(), 'dd/MM/yyyy'),
  27 + margin: [40, 0]},
  28 + {text: currentPage + ' de ' + pageCount,
  29 + margin: [28, 0], alignment: 'right'}
  30 + ]
  31 + };
  32 + },
  33 +
  34 + };
  35 + $scope.generarInforme = function() {
  36 + $scope.generando = true;
  37 + focaModalInformeChoferService
  38 + .getDescargas(
  39 + $scope.fechaDesde.toISOString().split('.')[0],
  40 + $scope.fechaHasta.toISOString().split('.')[0]
  41 + )
  42 + .then(function(res) {
  43 + var promesas = [];
  44 + $scope.gridOptions.data = orderData(res.data);
  45 +
  46 + res.data.forEach(function(descargas) {
  47 + var idsRemito = descargas.map(function(descarga) {
  48 + return descarga.remito.id;
  49 + });
  50 + idsRemito = eliminarDuplicados(idsRemito);
  51 + promesas.push(
  52 + focaModalInformeChoferService.getDistanciaPorIdRemito(idsRemito));
  53 + });
  54 + return Promise.all(promesas);
  55 + })
  56 + .then(function(res) {
  57 + res.forEach(function(movimiento, idx) {
  58 + //Calculo lts/km y los agrego a la grilla
  59 + var ltsPorKm =
  60 + $scope.gridOptions.data[idx].litros / movimiento.data.totalKms;
  61 + $scope.gridOptions.data[idx].kmRecorridos =
  62 + $filter('number')(movimiento.data.totalKms);
  63 + $scope.gridOptions.data[idx].ltsPorKm =
  64 + $filter('number')(ltsPorKm, 7);
  65 + });
  66 + //TODO: sacar id empresa hardcodeado
  67 + return focaModalInformeChoferService.getEmpresa(1);
  68 + })
  69 + .then(function(res) {
  70 + //Seteo filename para PDF y Excel, y cabecera de PDF
  71 + var filenameStamp = 'Informe choferes - ' +
  72 + $filter('date')(new Date(), 'dd/MM/yyyy');
  73 + $scope.informe.nombreEmpresa = res.data.NOM.trim();
  74 + $scope.informe.direccionEmpresa = res.data.DIR.trim();
  75 + $scope.gridOptions.exporterPdfFilename = filenameStamp + '.pdf';
  76 + $scope.gridOptions.exporterExcelFilename = filenameStamp + '.xlsx';
  77 + $scope.gridOptions.exporterPdfHeader = {
  78 + columns: [
  79 + {
  80 + text: $scope.informe.nombreEmpresa,
  81 + margin: [40, 0],
  82 + fontSize: 9
  83 + },
  84 + {
  85 + text: '\nInforme de choferes',
  86 + margin: [-170, -4, 0, 0],
  87 + fontSize: 12
  88 + },
  89 + {
  90 + text: [
  91 + '\n\nFiltros: ',
  92 + 'Fecha desde: ',
  93 + $filter('date')($scope.fechaDesde, 'dd/MM/yyyy'),
  94 + ' Fecha hasta: ',
  95 + $filter('date')($scope.fechaHasta, 'dd/MM/yyyy')
  96 + ],
  97 + margin: [-380, 2, 0, 0],
  98 + fontSize: 9
  99 + },
  100 + {
  101 + text: $scope.informe.direccionEmpresa,
  102 + margin: [28, 0],
  103 + alignment: 'right',
  104 + fontSize: 9
  105 + }
  106 + ]
  107 + };
  108 + $scope.buscar = false;
  109 + $scope.generando = false;
  110 + });
  111 + };
  112 + $scope.volver = function() {
  113 + $scope.buscar = true;
  114 + };
  115 + $scope.cancel = function() {
  116 + $uibModalInstance.dismiss('Cancelar');
  117 + };
  118 +
  119 + function orderData(data) {
  120 + var result = [];
  121 + data.forEach(function(descargas) {
  122 + var row = {
  123 + chofer: descargas[0].remito.hojaRuta.chofer.nombre,
  124 + litros: 0
  125 + };
  126 + descargas.forEach(function(descarga) {
  127 + row.litros += descarga.cantidad;
  128 + });
  129 + result.push(row);
  130 + });
  131 + return result;
  132 + }
  133 +
  134 + function eliminarDuplicados(datos) {
  135 + var result = [];
  136 + datos.forEach(function(dato) {
  137 + if (result.indexOf(dato) === -1) {
  138 + result.push(dato);
  139 + }
  140 + });
  141 + return result;
  142 + }
  143 + }
  144 + ]
  145 + );
... ... @@ -0,0 +1,19 @@
  1 +angular.module('focaModalInformeChofer')
  2 + .factory('focaModalInformeChoferService', [
  3 + '$http',
  4 + 'API_ENDPOINT',
  5 + function($http, API_ENDPOINT) {
  6 + return {
  7 + getDescargas: function(fechaDesde, fechaHasta) {
  8 + return $http.get(API_ENDPOINT.URL + '/cisterna-movimiento/groupedBy/chofer/' +
  9 + fechaDesde + '/' + fechaHasta);
  10 + },
  11 + getEmpresa: function(id) {
  12 + return $http.get(API_ENDPOINT.URL + '/empresa/' + id);
  13 + },
  14 + getDistanciaPorIdRemito: function(ids) {
  15 + return $http.post(API_ENDPOINT.URL + '/remito/distancia', {ids: ids});
  16 + }
  17 + };
  18 + }
  19 + ]);
src/views/modal-informe-chofer.html
... ... @@ -0,0 +1,85 @@
  1 +<div class="modal-header py-1">
  2 + <div class="row w-100">
  3 + <div class="col-6" ng-bind="informe.nombreEmpresa" ng-hide="buscar"></div>
  4 + <div class="col-6 text-right" ng-bind="informe.direccionEmpresa" ng-hide="buscar"></div>
  5 + <div class="col-12"><h5 class="modal-title">Informe de choferes</h5></div>
  6 + <div class="col-12" ng-hide="buscar">Filtros: Fecha desde: {{fechaDesde | date: 'dd/MM/yyyy'}} Fecha hasta: {{fechaHasta | date: 'dd/MM/yyyy'}}</div>
  7 + </div>
  8 +</div>
  9 +<div class="modal-body" id="modal-body">
  10 +
  11 + <div class="input-group row"
  12 + ng-show="buscar">
  13 + <small class="col-md-2 col-4 text-left my-1">Fecha Desde</small>
  14 + <div class="col-md-4 col-8 input-group mb-2">
  15 + <div class="input-group-prepend">
  16 + <div class="input-group-text form-control-sm">
  17 + <i class="fa fa-calendar"></i>
  18 + </div>
  19 + </div>
  20 + <input
  21 + class="form-control form-control-sm"
  22 + id="inlineFormInputGroup"
  23 + type="text"
  24 + ng-model="fechaDesde"
  25 + ng-required="true"
  26 + uib-datepicker-popup="dd/MM/yyyy"
  27 + show-button-bar="false"
  28 + is-open="datepickerOpen"
  29 + on-open-focus="false"
  30 + ng-focus="datepickerOpen = true"
  31 + datepicker-options="dateOptions"
  32 + />
  33 + </div>
  34 + <small class="col-md-2 col-4 text-left my-1">Fecha Hasta</small>
  35 + <div class="col-md-4 col-8 input-group mb-2">
  36 + <div class="input-group-prepend">
  37 + <div class="input-group-text form-control-sm">
  38 + <i class="fa fa-calendar"></i>
  39 + </div>
  40 + </div>
  41 + <input
  42 + class="form-control form-control-sm"
  43 + id="inlineFormInputGroup"
  44 + type="text"
  45 + ng-model="fechaHasta"
  46 + ng-required="true"
  47 + uib-datepicker-popup="dd/MM/yyyy"
  48 + show-button-bar="false"
  49 + is-open="datepicker2Open"
  50 + on-open-focus="false"
  51 + ng-focus="datepicker2Open = true"
  52 + />
  53 + </div>
  54 + </div>
  55 + <div
  56 + ng-if="!buscar"
  57 + class="row">
  58 + <div class="col-12">
  59 + <div
  60 + class="gridInforme"
  61 + ui-grid="gridOptions"
  62 + ui-grid-exporter
  63 + ui-grid-resize-columns
  64 + ></div>
  65 + </div>
  66 + </div>
  67 +</div>
  68 +<div class="modal-footer py-1">
  69 + <button
  70 + class="btn btn-sm btn-secondary"
  71 + type="button"
  72 + ng-click="cancel()"
  73 + ng-show="buscar">Cancelar</button>
  74 + <button
  75 + ladda="generando"
  76 + class="btn btn-sm btn-secondary"
  77 + type="button"
  78 + ng-click="generarInforme()"
  79 + ng-show="buscar">Generar</button>
  80 + <button
  81 + class="btn btn-sm btn-secondary"
  82 + type="button"
  83 + ng-click="volver()"
  84 + ng-hide="buscar">Volver</button>
  85 +</div>