Commit a3a220dda5d774fcb6c371f29fb16368efbfc905

Authored by Eric Fernandez
1 parent 9d4f38ad5d
Exists in master and in 1 other branch develop

first version

... ... @@ -0,0 +1,6 @@
  1 +/node_modules
  2 +/dist
  3 +package-lock\.json
  4 +/src/etc/develop.js
  5 +
  6 +tmp/
... ... @@ -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": false,
  54 +
  55 + // Para que funcione en angular
  56 + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe", "L"],
  57 + /*
  58 + * RELAXING OPTIONS
  59 + * =================
  60 + */
  61 +
  62 + // Suppress warnings about == null comparisons.
  63 + "eqnull": true
  64 +}
1   -# foca-modal
  1 +# foca-modal-detalle-cisternas
2 2  
3 3 Modal detalle, carga de cisternas
... ... @@ -0,0 +1,86 @@
  1 +const templateCache = require('gulp-angular-templatecache');
  2 +const clean = require('gulp-clean');
  3 +const concat = require('gulp-concat');
  4 +const htmlmin = require('gulp-htmlmin');
  5 +const rename = require('gulp-rename');
  6 +const uglify = require('gulp-uglify');
  7 +const gulp = require('gulp');
  8 +const pump = require('pump');
  9 +const jshint = require('gulp-jshint');
  10 +const replace = require('gulp-replace');
  11 +const connect = require('gulp-connect');
  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('templates', ['clean'], function() {
  21 + return pump(
  22 + [
  23 + gulp.src(paths.srcViews),
  24 + htmlmin(),
  25 + templateCache('views.js', {
  26 + module: 'focaModalDetalleCisternas',
  27 + root: ''
  28 + }),
  29 + gulp.dest(paths.tmp)
  30 + ]
  31 + );
  32 +});
  33 +
  34 +gulp.task('uglify', ['templates'], function() {
  35 + return pump(
  36 + [
  37 + gulp.src([
  38 + paths.srcJS,
  39 + 'tmp/views.js'
  40 + ]),
  41 + concat('foca-modal-detalle-cisternas.js'),
  42 + replace('src/views/', ''),
  43 + gulp.dest(paths.tmp),
  44 + rename('foca-modal-detalle-cisternas.min.js'),
  45 + uglify(),
  46 + replace('"ui.bootstrap"', ''),
  47 + gulp.dest(paths.dist)
  48 + ]
  49 + );
  50 +});
  51 +
  52 +gulp.task('clean', function(){
  53 + return gulp.src(['tmp', 'dist'], {read: false})
  54 + .pipe(clean());
  55 +});
  56 +
  57 +gulp.task('pre-commit', function() {
  58 + return pump(
  59 + [
  60 + gulp.src(paths.srcJS),
  61 + jshint('.jshintrc'),
  62 + jshint.reporter('default'),
  63 + jshint.reporter('fail')
  64 + ]
  65 + );
  66 +
  67 + gulp.start('uglify');
  68 +});
  69 +
  70 +gulp.task('webserver', function() {
  71 + pump [
  72 + connect.server({port: 3300, host: '0.0.0.0'})
  73 + ]
  74 +});
  75 +
  76 +gulp.task('clean-post-install', function() {
  77 + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
  78 + 'index.html'], {read: false})
  79 + .pipe(clean());
  80 +});
  81 +
  82 +gulp.task('default', ['webserver']);
  83 +
  84 +gulp.task('watch', function() {
  85 + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
  86 +});
... ... @@ -0,0 +1,46 @@
  1 +{
  2 + "name": "foca-modal-detalle-cisternas",
  3 + "version": "0.0.1",
  4 + "description": "Detalle de cisternas",
  5 + "main": "index.js",
  6 + "scripts": {
  7 + "test": "echo \"Error: no test specified\" && exit 1",
  8 + "compile": "gulp uglify",
  9 + "gulp-pre-commit": "gulp pre-commit",
  10 + "postinstall": "npm run compile && gulp clean-post-install",
  11 + "install-dev": "npm install -D jasmine-core pre-commit angular bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump"
  12 + },
  13 + "pre-commit": [
  14 + "gulp-pre-commit"
  15 + ],
  16 + "repository": {
  17 + "type": "git",
  18 + "url": "http://git.focasoftware.com/npm/foca-modal-detalle-cisternas.git"
  19 + },
  20 + "author": "Foca Software",
  21 + "license": "ISC",
  22 + "devDependencies": {
  23 + "angular": "^1.7.5",
  24 + "angular-route": "^1.7.5",
  25 + "bootstrap": "^4.2.1",
  26 + "font-awesome": "^4.7.0",
  27 + "gulp": "^3.9.1",
  28 + "gulp-angular-templatecache": "^2.2.6",
  29 + "gulp-clean": "^0.4.0",
  30 + "gulp-concat": "^2.6.1",
  31 + "gulp-connect": "^5.7.0",
  32 + "gulp-htmlmin": "^5.0.1",
  33 + "gulp-jshint": "^2.1.0",
  34 + "gulp-rename": "^1.4.0",
  35 + "gulp-replace": "^1.0.0",
  36 + "gulp-sequence": "^1.0.0",
  37 + "gulp-uglify": "^3.0.1",
  38 + "gulp-uglify-es": "^1.0.4",
  39 + "jasmine-core": "^3.3.0",
  40 + "jquery": "^3.3.1",
  41 + "jshint": "^2.9.7",
  42 + "pre-commit": "^1.2.2",
  43 + "pump": "^3.0.0",
  44 + "ui-bootstrap4": "^3.0.5"
  45 + }
  46 +}
src/etc/develop.js.ejemplo
... ... @@ -0,0 +1,4 @@
  1 +angular.module('focaModalDetalleCisternas')
  2 + .constant("API_ENDPOINT", {
  3 + 'URL': 'http://127.0.0.1:9000'
  4 + });
... ... @@ -0,0 +1 @@
  1 +angular.module('focaModalDetalleCisternas', ['ui.bootstrap']);
src/js/controller.js
... ... @@ -0,0 +1,222 @@
  1 +angular.module('focaModalDetalleCisternas')
  2 + .controller('focaDetalleVehiculo',
  3 + ['$scope',
  4 + '$uibModalInstance',
  5 + 'idVehiculo',
  6 + 'idRemito',
  7 + 'focaModalService',
  8 + '$filter',
  9 + 'focaLogisticaPedidoRutaService',
  10 + function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter,
  11 + focaLogisticaPedidoRutaService
  12 + ) {
  13 + //seteo variables
  14 + $scope.cargandoDatos = true;
  15 + $scope.idRemito = idRemito;
  16 + $scope.articulos = [];
  17 + $scope.vehiculo = {};
  18 + $scope.cisternas = [];
  19 + $scope.cisternasCarga = [];
  20 + $scope.remito = {};
  21 + $scope.aCargar = [];
  22 + var cisternaMovimientos = [];
  23 + var promesaRemito;
  24 + var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo);
  25 + var promesaCisternas = focaLogisticaPedidoRutaService
  26 + .obtenerCisternasPorFecha(idVehiculo);
  27 + if(idRemito !== -1) {
  28 + promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito);
  29 + }
  30 + Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) {
  31 + $scope.cargandoDatos = false;
  32 + $scope.vehiculo = res[0].data;
  33 + $scope.cisternas = res[1].data;
  34 + if(!res[2]) {
  35 + $scope.$digest();
  36 + return;
  37 + }
  38 + $scope.remito = res[2].data;
  39 + if($scope.remito.idUsuarioProceso) {
  40 + focaModalService.alert('Remito ya asignado');
  41 + $uibModalInstance.close();
  42 + }
  43 + $scope.articulos = $scope.remito.articulosRemito;
  44 + $scope.seleccionarArticulo($scope.articulos[0]);
  45 + var tieneUsuario = $scope.cisternas.filter(function(cisterna) {
  46 + if(cisterna.cisternaCarga && cisterna.cisternaCarga.idUsuarioProceso) {
  47 + return cisterna.cisternaCarga.idUsuarioProceso !==
  48 + focaLogisticaPedidoRutaService.idUsuario;
  49 + }
  50 + });
  51 + if(tieneUsuario.length) {
  52 + focaModalService.alert('Otro usario esta usando este vehículo');
  53 + $uibModalInstance.close();
  54 + }
  55 + $scope.$digest();
  56 + });
  57 + $scope.aceptar = function() {
  58 + $scope.cargando = true;
  59 + for(var i = 0; i < $scope.cisternasCarga.length; i++) {
  60 + $scope.cisternasCarga[i].idUsuarioProceso =
  61 + focaLogisticaPedidoRutaService.idUsuario;
  62 + delete $scope.cisternasCarga[i].articulo;
  63 + }
  64 + var cisterna = {
  65 + cisternaMovimientos: cisternaMovimientos,
  66 + cisternaCargas: $scope.cisternasCarga,
  67 + idVehiculo: $scope.vehiculo.id,
  68 + fechaReparto: focaLogisticaPedidoRutaService.fecha
  69 + };
  70 + focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id)
  71 + .then(function() {
  72 + focaModalService.alert('Cisternas cargadas con éxito').then(function() {
  73 + $scope.cargando = false;
  74 + $uibModalInstance.close();
  75 + });
  76 + }).catch(function(error) {
  77 + $scope.cargando = false;
  78 + $uibModalInstance.close();
  79 + if (error.status === 403) {
  80 + focaModalService.alert('ERROR: ' + error.data);
  81 + return;
  82 + }
  83 + focaModalService.alert('Hubo un error al cargar las cisternas');
  84 + });
  85 + };
  86 + $scope.cancelar = function() {
  87 + $uibModalInstance.close();
  88 + };
  89 + $scope.cargarACisternas = function() {
  90 + for(var i = 0; i < $scope.cisternas.length; i++) {
  91 + var cisterna = $scope.cisternas[i];
  92 + var aCargar = parseFloat($scope.aCargar[i]);
  93 + var fechaReparto = focaLogisticaPedidoRutaService.fecha;
  94 + //validaciones
  95 + if(!aCargar) {
  96 + continue;
  97 + }
  98 + //cargar
  99 + if(cisterna.cisternaCarga.cantidad) {
  100 + cisterna.cisternaCarga.cantidad += aCargar;
  101 + }else {
  102 + cisterna.cisternaCarga.cantidad = aCargar;
  103 + cisterna.cisternaCarga.idProducto = $scope.articuloSeleccionado.idArticulo;
  104 + }
  105 + cisterna.disponible = cisterna.capacidad - cisterna.cisternaCarga.cantidad;
  106 +
  107 + cisterna.cisternaCarga.articulo = {
  108 + DetArt: $scope.articuloSeleccionado.descripcion
  109 + };
  110 + $filter('filter')($scope.articulos, {id: $scope.articuloSeleccionado.id})[0]
  111 + .cargado = true;
  112 +
  113 + $scope.calcularPorcentaje(cisterna);
  114 + //Guardar
  115 + var now = new Date();
  116 + var cisternaMovimiento = {
  117 + fecha: now.toISOString().slice(0, 19).replace('T', ' '),
  118 + cantidad: aCargar,
  119 + metodo: 'carga',
  120 + idCisternaCarga: cisterna.cisternaCarga.id,
  121 + idRemito: $scope.remito.id
  122 + };
  123 + cisterna.cisternaCarga.fechaReparto = fechaReparto;
  124 + cisterna.cisternaCarga.idCisterna = cisterna.id;
  125 + $scope.cisternasCarga.push(cisterna.cisternaCarga);
  126 + cisternaMovimientos.push(cisternaMovimiento);
  127 + }
  128 + var articuloSiguiente = $scope.articulos.filter(
  129 + function(filter) {
  130 + return filter.cargado !== true;
  131 + }
  132 + );
  133 + if(articuloSiguiente.length > 0) {
  134 + $scope.seleccionarArticulo(articuloSiguiente[0]);
  135 + }
  136 + };
  137 + $scope.calcularPorcentaje = function(cisterna) {
  138 + if(!cisterna.cisternaCarga) {
  139 + cisterna.cisternaCarga = {
  140 + cantidad: 0
  141 + };
  142 + }
  143 + var porcentaje = (cisterna.cisternaCarga.cantidad * 100 /
  144 + cisterna.capacidad) + '%';
  145 + var elementHtml = document.getElementById(cisterna.id);
  146 + if(elementHtml) {
  147 + elementHtml.style.width = porcentaje;
  148 + }
  149 + };
  150 + $scope.seleccionarArticulo = function(articulo) {
  151 + $scope.articuloSeleccionado = articulo;
  152 + $scope.cisternaDisponible();
  153 + $scope.autoCompletar();
  154 + $scope.actualizarArticulo();
  155 + };
  156 + $scope.actualizarArticulo = function () {
  157 + $scope.articuloSeleccionado.cantidadCargada = 0;
  158 + for (var i = 0; i < $scope.aCargar.length; i++) {
  159 + $scope.articuloSeleccionado.cantidadCargada +=
  160 + parseFloat($scope.aCargar[i]) || 0;
  161 + }
  162 + };
  163 + $scope.autoCompletar = function() {
  164 + $scope.aCargar = [];
  165 + var disponible = $filter('filter')($scope.cisternas, {disabled: false});
  166 + var index = $scope.cisternas.indexOf(disponible[0]);
  167 + $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad;
  168 + };
  169 + $scope.cisternaDisponible = function() {
  170 + for(var i = 0; i < $scope.cisternas.length; i++) {
  171 + if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) {
  172 + $scope.cisternas[i].disabled = true;
  173 + continue;
  174 + }
  175 + if($scope.cisternas[i].cisternaCarga &&
  176 + $scope.cisternas[i].cisternaCarga.idProducto &&
  177 + $scope.articuloSeleccionado.idArticulo !==
  178 + $scope.cisternas[i].cisternaCarga.idProducto)
  179 + {
  180 + $scope.cisternas[i].disabled = true;
  181 + continue;
  182 + }
  183 + $scope.cisternas[i].disabled = false;
  184 + }
  185 + };
  186 + $scope.rellenarInput = function(input) {
  187 + if(!$scope.articuloSeleccionado) return;
  188 + if($scope.articuloSeleccionado.cantidad -
  189 + $scope.articuloSeleccionado.cantidadCargada === 0) {
  190 + return input;
  191 + }
  192 + if(!input) input = 0;
  193 + input = parseFloat(input);
  194 + input += parseFloat($scope.articuloSeleccionado.cantidad -
  195 + $scope.articuloSeleccionado.cantidadCargada);
  196 + return input;
  197 + };
  198 + $scope.distribucionDisponible = function() {
  199 + if(!$scope.articuloSeleccionado || $scope.articuloSeleccionado.cantidad -
  200 + $scope.articuloSeleccionado.cantidadCargada !== 0 ||
  201 + !$scope.tieneArticulosPendientes()) {
  202 + return false;
  203 + }
  204 + return true;
  205 + };
  206 + $scope.tieneArticulosPendientes = function() {
  207 + var algunValorNegativo = $scope.aCargar.filter(function(p) {
  208 + return p < 0;
  209 + });
  210 + if(algunValorNegativo.length) {
  211 + return false;
  212 + }
  213 + var articulosDescargados = $scope.articulos.filter(function(filter) {
  214 + return filter.cargado === true;
  215 + });
  216 + if(articulosDescargados.length === $scope.articulos.length) {
  217 + $scope.aCargar = [];
  218 + return false;
  219 + }
  220 + return true;
  221 + };
  222 + }]);
src/views/foca-detalle-vehiculo.html
... ... @@ -0,0 +1,129 @@
  1 +<div class="modal-header">
  2 + <h4>Detalle de carga</h4>
  3 + Transportista
  4 + <strong ng-bind="vehiculo.transportista.COD"></strong>
  5 + <strong ng-bind="vehiculo.transportista.NOM"></strong>
  6 + Unidad <strong ng-bind="vehiculo.codigo"></strong>
  7 + Tractor <strong ng-bind="vehiculo.tractor"></strong>
  8 + <br>
  9 + <div ng-show="idRemito !== -1">
  10 + <span>Remito Nº</span>
  11 + <strong ng-bind="[remito.sucursal, remito.numeroRemito] | comprobante"></strong>
  12 + <span>, Fecha</span>
  13 + <strong ng-bind="remito.fechaRemito | date: 'dd/MM/yyyy HH:mm'"></strong>
  14 + <span>, Cliente</span>
  15 + <strong ng-bind="remito.nombreCliente"></strong>
  16 + <span>, Domicilio entrega</span>
  17 + <strong ng-bind="remito.domicilioStamp"></strong>
  18 + </div>
  19 +</div>
  20 +<div class="modal-body">
  21 + <div>
  22 + <table class="table table-sm" ng-show="idRemito !== -1">
  23 + <thead>
  24 + <tr>
  25 + <th></th>
  26 + <th>Articulo</th>
  27 + <th>Cantidad</th>
  28 + <th>Cargado</th>
  29 + <th>Resta asignar</th>
  30 + </tr>
  31 + </thead>
  32 + <tbody>
  33 + <tr ng-repeat="(key, articulo) in articulos">
  34 + <td><input
  35 + type="radio"
  36 + name="articuloRadio"
  37 + id="{{'articulo' + articulo.id}}"
  38 + ng-checked="articuloSeleccionado.id === articulo.id"
  39 + ng-disabled="articulo.cargado"
  40 + ng-click="seleccionarArticulo(articulo)"
  41 + ></td>
  42 + <td ng-bind="articulo.descripcion"></td>
  43 + <td ng-bind="articulo.cantidad"></td>
  44 + <td ng-bind="articulo.cantidadCargada || 0"></td>
  45 + <td ng-bind="articulo.cantidad - articulo.cantidadCargada"></td>
  46 + </tr>
  47 + </tbody>
  48 + </table>
  49 + <table class="table table-sm" ladda="cargandoDatos" data-spinner-color="#FF0000">
  50 + <thead>
  51 + <tr>
  52 + <th width="10%">Cisterna</th>
  53 + <th>Capacidad</th>
  54 + <th>Articulo cargado</th>
  55 + <th width="20%">Asignado</th>
  56 + <th>Cargado / Capacidad Disponible</th>
  57 + </tr>
  58 + </thead>
  59 + <tbody>
  60 + <tr ng-repeat="(key, cisterna) in cisternas">
  61 + <td class="py-3" ng-bind="cisterna.codigo"></td>
  62 + <td class="py-3" ng-bind="cisterna.capacidad"></td>
  63 + <td class="py-3" ng-bind="cisterna.cisternaCarga.articulo.DetArt || 'Sin asignar'"></td>
  64 + <td ng-if="idRemito != -1">
  65 + <input
  66 + class="form-control"
  67 + foca-tipo-input
  68 + foca-teclado
  69 + placeholder="A cargar..."
  70 + ng-model="aCargar[key]"
  71 + ng-disabled="cisterna.disabled || !tieneArticulosPendientes()"
  72 + ng-focus="aCargar[key] = rellenarInput(aCargar[key]); actualizarArticulo()"
  73 + ng-change="actualizarArticulo()"
  74 + >
  75 + </td>
  76 + <td ng-if="idRemito == -1">
  77 + <input
  78 + class="form-control"
  79 + placeholder="A cargar..."
  80 + readonly>
  81 + </td>
  82 + <td><div class="progress foca-alto-progress pl-0 pr-0 mt-1">
  83 + <strong
  84 + class="mt-2 col-4 text-center position-absolute"
  85 + ng-bind="(cisterna.cisternaCarga.cantidad || 0) + '/' +
  86 + (cisterna.capacidad - cisterna.cisternaCarga.cantidad)">
  87 + </strong>
  88 + <div
  89 + id="{{cisterna.id}}"
  90 + class="progress-bar"
  91 + role="progressbar"
  92 + aria-valuemin="0"
  93 + aria-valuemax="{{cisterna.capacidad}}"
  94 + ng-style="{'width':'{{calcularPorcentaje(cisterna)}}'}">
  95 + </div>
  96 + </div>
  97 + </td>
  98 + </tr>
  99 + </tbody>
  100 + </table>
  101 + <div class="col-12">
  102 + <button
  103 + class="form-control btn btn-success"
  104 + ladda="cargando"
  105 + data-spinner-color="#FF0000"
  106 + type="button"
  107 + ng-disabled="!distribucionDisponible()"
  108 + ng-class="{'btn-light': !distribucionDisponible()}"
  109 + ng-click="cargarACisternas(vehiculo)"
  110 + foca-focus="distribucionDisponible()">
  111 + Aplicar distribución de cargas
  112 + </button>
  113 + </div>
  114 + </div>
  115 +</div>
  116 +<div class="modal-footer py-1">
  117 + <button
  118 + class="btn btn-sm btn-secondary"
  119 + ladda="cargando"
  120 + type="button"
  121 + ng-click="cancelar()">Cancelar</button>
  122 + <button
  123 + class="btn btn-sm btn-primary"
  124 + ladda="cargando"
  125 + type="button"
  126 + ng-click="aceptar()"
  127 + ng-disabled="tieneArticulosPendientes() || idRemito === -1"
  128 + foca-focus="!tieneArticulosPendientes() && idRemito !== -1">Cargar</button>
  129 +</div>