Commit fab780a800c7d1c37a23b0d5e1765f3e37907b98

Authored by Eric Fernandez
0 parents
Exists in master

first commit

File was created 1 /node_modules
2 /dist
3 /tmp
4 package-lock\.json
5 src/etc/develop\.js
6
File was created 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 }
65
File was created 1 Busqueda de Facturas
2 ==========================
3
File was created 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: 'focaModalFactura',
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-factura.js'),
47 replace('src/views/', ''),
48 replace("['ui.bootstrap', 'focaDirectivas', 'angular-ladda']", '[]'),
49 gulp.dest(paths.tmp),
50 rename('foca-modal-factura.min.js'),
51 uglify(),
52 gulp.dest(paths.dist)
53 ]
54 );
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: 3000})
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 });
87
88 gulp.task('copy', ['uglify'], function() {
89 gulp.src('dist/*.js')
90 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-nota-pedido/dist'));
91 });
92
93 gulp.task('watchAndCopy', function() {
94 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']);
95 });
96
File was created 1 <html ng-app="focaModalFactura">
2 <head>
3 <meta charset="UTF-8"/>
4 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5
6 <!--CSS-->
7 <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
8 <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
9 <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet">
10
11 <!--VENDOR JS-->
12 <script src="node_modules/jquery/dist/jquery.min.js"></script>
13 <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
14 <script src="node_modules/angular/angular.min.js"></script>
15 <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script>
16 <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script>
17 <script src="node_modules/ladda/dist/spin.min.js"></script>
18 <script src="node_modules/ladda/dist/ladda.min.js"></script>
19 <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script>
20
21 <!-- BUILD -->
22 <script src="src/js/app.js"></script>
23 <script src="src/js/controller.js"></script>
24 <script src="src/js/service.js"></script>
25
26 <!-- /BUILD -->
27
28 <!-- CONFIG PARA DEVELOP -->
29 <script src="src/etc/develop.js"></script>
30 <script type="text/javascript">
31 angular.module('focaModalFactura')
32 .controller('controller', [
33 '$scope',
34 '$uibModal',
35 '$timeout',
36 function($scope, $uibModal, $timeout) {
37 openModal();
38
39 function openModal() {
40 var modalInstance = $uibModal.open(
41 {
42 ariaLabelledBy: 'Busqueda de Facturas',
43 templateUrl: 'src/views/foca-modal-factura.html',
44 controller: 'focaModalFacturaController',
45 size: 'lg',
46 resolve: {
47 cliente: function() {return 1}
48 }
49 }
50 );
51
52 modalInstance.result.then(
53 function (selectedItem) {
54 console.info(selectedItem);
55 $timeout(openModal, 500);
56 }, function () {
57 console.info('modal-component dismissed at: ' + new Date());
58 $timeout(openModal, 500);
59 }
60 );
61 }
62 }
63 ]);
64 </script>
65 </head>
66 <body ng-controller="controller">
67 </body>
68 </html>
69
File was created 1 {
2 "name": "foca-modal-factura",
3 "version": "0.0.1",
4 "description": "Modal para seleccion facturas",
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-factura.git"
18 },
19 "author": "Foca Software",
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"
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.5",
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 }
63
src/etc/develop.js.ejemplo
File was created 1 angular.module('focaModalFactura')
2 .constant("API_ENDPOINT", {
3 'URL': '//127.0.0.1:9000'
4 });
5
File was created 1 angular.module('focaModalFactura', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda']);
2
src/js/controller.js
File was created 1 angular.module('focaModalFactura')
2 .controller('focaModalFacturaController',
3 [
4 '$filter',
5 '$scope',
6 '$uibModalInstance',
7 'focaModalFacturaService',
8 'cliente',
9 function($filter, $scope, $uibModalInstance,
10 focaModalFacturaService, cliente
11 ) {
12 var fecha = new Date();
13 $scope.fechaHasta = new Date();
14 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
15 $scope.filters = '';
16 $scope.facturas = [];
17 $scope.primerBusqueda = false;
18 $scope.searchLoading = false;
19 // pagination
20 $scope.numPerPage = 10;
21 $scope.currentPage = 1;
22 $scope.filteredFacturas = [];
23 $scope.currentPageFacturas = [];
24 $scope.selectedFactura = -1;
25
26 //METODOS
27 $scope.busquedaPress = function(key) {
28 if (key === 13) {
29 //TODO Validaciones con alertas
30 if(!$scope.fechaDesde) {
31 alert('INGRESE FECHA DESDE');
32 return;
33 }
34 if(!$scope.fechaHasta) {
35 alert('INGRESE FECHA HASTA');
36 return;
37 }
38 if($scope.fechaDesde > $scope.fechaHasta) {
39 alert('La fecha desde no puede ser mayor a la fecha hasta');
40 return;
41 }
42 $scope.searchLoading = true;
43 //TODO hacer filtro de fecha
44 focaModalFacturaService
45 .getFacturasByIdCliente(cliente, $scope.fechaDesde
46 .toISOString().split('.')[0],
47 $scope.fechaHasta.toISOString().split('.')[0])
48 .then(llenarDatos);
49 }
50 };
51 function llenarDatos(res) {
52 $scope.facturas = [];
53 $scope.filteredFacturas = [];
54 $scope.currentPageFacturas = [];
55 $scope.selectedFactura = -1;
56 $scope.searchLoading = false;
57 $scope.primerBusqueda = true;
58 $scope.facturas = res.data;
59 $scope.search();
60 primera();
61 }
62 $scope.search = function() {
63 if($scope.facturas.length > 0) {
64 $scope.filteredFacturas = $filter('filter')(
65 $scope.facturas,
66 {$: $scope.filters}
67 );
68
69 $scope.lastPage = Math.ceil(
70 $scope.filteredFacturas.length / $scope.numPerPage
71 );
72
73 $scope.resetPage();
74 }
75 };
76
77 $scope.resetPage = function() {
78 $scope.currentPage = 1;
79 $scope.selectPage(1);
80 };
81
82 $scope.selectPage = function(page) {
83 var start = (page - 1) * $scope.numPerPage;
84 var end = start + $scope.numPerPage;
85 $scope.paginas = [];
86 $scope.paginas = calcularPages(page);
87 $scope.currentPageFacturas = $scope.filteredFacturas.slice(start, end);
88 $scope.currentPage = page;
89 };
90
91 $scope.select = function(notaPedido) {
92 $uibModalInstance.close(notaPedido);
93 };
94
95 $scope.cancel = function() {
96 $uibModalInstance.dismiss('cancel');
97 };
98
99 $scope.busquedaDown = function(key) {
100 if (key === 40) {
101 primera(key);
102 }
103 };
104
105 $scope.itemNotaPedido = function(key) {
106 if (key === 38) {
107 anterior(key);
108 }
109
110 if (key === 40) {
111 siguiente(key);
112 }
113
114 if (key === 37) {
115 retrocederPagina();
116 }
117
118 if (key === 39) {
119 avanzarPagina();
120 }
121 };
122
123 function calcularPages(paginaActual) {
124 var paginas = [];
125 paginas.push(paginaActual);
126
127 if (paginaActual - 1 > 1) {
128
129 paginas.unshift(paginaActual - 1);
130 if (paginaActual - 2 > 1) {
131 paginas.unshift(paginaActual - 2);
132 }
133 }
134
135 if (paginaActual + 1 < $scope.lastPage) {
136 paginas.push(paginaActual + 1);
137 if (paginaActual + 2 < $scope.lastPage) {
138 paginas.push(paginaActual + 2);
139 }
140 }
141
142 if (paginaActual !== 1) {
143 paginas.unshift(1);
144 }
145
146 if (paginaActual !== $scope.lastPage) {
147 paginas.push($scope.lastPage);
148 }
149
150 return paginas;
151 }
152
153 function primera() {
154 $scope.selectedFactura = 0;
155 }
156
157 function anterior() {
158 if ($scope.selectedFactura === 0 && $scope.currentPage > 1) {
159 retrocederPagina();
160 } else {
161 $scope.selectedFactura--;
162 }
163 }
164
165 function siguiente() {
166 if ($scope.selectedFactura < $scope.currentPageFacturas.length - 1 ) {
167 $scope.selectedFactura++;
168 } else {
169 avanzarPagina();
170 }
171 }
172
173 function retrocederPagina() {
174 if ($scope.currentPage > 1) {
175 $scope.selectPage($scope.currentPage - 1);
176 $scope.selectedFactura = $scope.numPerPage - 1;
177 }
178 }
179
180 function avanzarPagina() {
181 if ($scope.currentPage < $scope.lastPage) {
182 $scope.selectPage($scope.currentPage + 1);
183 $scope.selectedFactura = 0;
184 }
185 }
186 }
187 ]
188 );
189
File was created 1 angular.module('focaModalFactura')
2 .factory('focaModalFacturaService', [
3 '$http',
4 'API_ENDPOINT',
5 function($http, API_ENDPOINT) {
6 return {
7 getFacturasByIdCliente: function(idCliente, fechaDesde, fechaHasta) {
8 return $http.get(API_ENDPOINT.URL + '/factura/cliente/' + idCliente + '/' +
9 fechaDesde + '/' + fechaHasta);
10 }
11 };
12 }
13 ]);
14
src/views/foca-modal-factura.html
File was created 1 <div class="modal-header py-1">
2 <h5 class="modal-title">Busqueda de Facturas</h5>
3 </div>
4 <div class="modal-body" id="modal-body">
5 <div class="input-group row">
6 <small class="col-md-2 col-4 text-left my-1">Fecha Desde</small>
7 <div class="col-md-4 col-8 input-group mb-2">
8 <div class="input-group-prepend">
9 <div class="input-group-text form-control-sm">
10 <i class="fa fa-calendar"></i>
11 </div>
12 </div>
13 <input
14 class="form-control form-control-sm"
15 id="inlineFormInputGroup"
16 ladda="searchLoading"
17 type="date"
18 ng-model="fechaDesde"
19 hasta-hoy
20 ng-required="true"
21 />
22 </div>
23 <small class="col-md-2 col-4 text-left my-1">Fecha Hasta</small>
24 <div class="col-md-4 col-8 input-group mb-2">
25 <div class="input-group-prepend">
26 <div class="input-group-text form-control-sm">
27 <i class="fa fa-calendar"></i>
28 </div>
29 </div>
30 <input
31 class="form-control form-control-sm"
32 id="inlineFormInputGroup"
33 ladda="searchLoading"
34 type="date"
35 ng-model="fechaHasta"
36 ng-required="true"
37 hasta-hoy
38 />
39 </div>
40 </div>
41 <div class="input-group">
42 <input
43 ladda="searchLoading"
44 type="text"
45 class="form-control form-control-sm"
46 placeholder="Busqueda"
47 ng-model="filters"
48 ng-change="search()"
49 ng-keydown="busquedaDown($event.keyCode)"
50 ng-keypress="busquedaPress($event.keyCode)"
51 foca-focus="selectedFactura == -1"
52 ng-focus="selectedFactura = -1"
53 teclado-virtual
54 />
55 <div class="input-group-append">
56 <button
57 ladda="searchLoading"
58 class="btn btn-outline-secondary"
59 type="button"
60 ng-click="busquedaPress(13)"
61 >
62 <i class="fa fa-search" aria-hidden="true"></i>
63 </button>
64 </div>
65 </div>
66 <table ng-show="primerBusqueda" class="table table-striped table-sm">
67 <thead>
68 <tr>
69 <th>Cliente</th>
70 <th>Fecha</th>
71 <th>Nro</th>
72 <th>Importe</th>
73 <th></th>
74 </tr>
75 </thead>
76 <tbody>
77 <tr ng-show="currentPageFacturas.length == 0 && primerBusqueda">
78 <td colspan="5">
79 No se encontraron resultados.
80 </td>
81 </tr>
82 <tr class="selectable"
83 ng-repeat="(key,factura) in currentPageFacturas"
84 ng-click="select(factura)">
85 <td ng-bind="factura.cliente.NOM"></td>
86 <td ng-bind="factura.FEP | date : 'dd/MM/yyyy'"></td>
87 <td ng-bind=
88 "(factura.TCO + '-' + factura.TIP + '-' + factura.SUC + '-' + factura.NCO)">
89 </td>
90 <td ng-bind="factura.IPA"></td>
91 <td>
92 <button
93 type="button"
94 class="btn btn-xs p-1 float-right"
95 ng-class="{
96 'btn-secondary': selectedFactura != key,
97 'btn-primary': selectedFactura == key
98 }"
99 foca-focus="selectedFactura == {{key}}"
100 ng-keydown="itemNotaPedido($event.keyCode)"
101 >
102 <i class="fa fa-arrow-right" aria-hidden="true"></i>
103 </button>
104 </td>
105 </tr>
106 </tbody>
107 </table>
108 <nav ng-show="currentPageFacturas.length > 0 && primerBusqueda">
109 <ul class="pagination pagination-sm justify-content mb-0">
110 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
111 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage - 1)">
112 <span aria-hidden="true">&laquo;</span>
113 <span class="sr-only">Anterior</span>
114 </a>
115 </li>
116 <li
117 class="page-item"
118 ng-repeat="pagina in paginas"
119 ng-class="{'active': pagina == currentPage}"
120 >
121 <a
122 class="page-link"
123 href="javascript:void();"
124 ng-click="selectPage(pagina)"
125 ng-bind="pagina"
126 ></a>
127 </li>
128 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
129 <a class="page-link" href="javascript:void();" ng-click="selectPage(currentPage + 1)">
130 <span aria-hidden="true">&raquo;</span>
131 <span class="sr-only">Siguiente</span>
132 </a>
133 </li>
134 </ul>
135 </nav>
136 </div>
137 <div class="modal-footer py-1">
138 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
139 </div>
140