Commit ef70601cce0b6ebc7a3931315fec655be7c7c37f
1 parent
7d68d24ce9
Exists in
master
unit test
Showing
9 changed files
with
1284 additions
and
10 deletions
Show diff stats
gulpfile.js
| 1 | const templateCache = require('gulp-angular-templatecache'); | 1 | const templateCache = require('gulp-angular-templatecache'); |
| 2 | const clean = require('gulp-clean'); | 2 | const clean = require('gulp-clean'); |
| 3 | const concat = require('gulp-concat'); | 3 | const concat = require('gulp-concat'); |
| 4 | const htmlmin = require('gulp-htmlmin'); | 4 | const htmlmin = require('gulp-htmlmin'); |
| 5 | const rename = require('gulp-rename'); | 5 | const rename = require('gulp-rename'); |
| 6 | const uglify = require('gulp-uglify'); | 6 | const uglify = require('gulp-uglify'); |
| 7 | const gulp = require('gulp'); | 7 | const gulp = require('gulp'); |
| 8 | const pump = require('pump'); | 8 | const pump = require('pump'); |
| 9 | const jshint = require('gulp-jshint'); | 9 | const jshint = require('gulp-jshint'); |
| 10 | const replace = require('gulp-replace'); | 10 | const replace = require('gulp-replace'); |
| 11 | const connect = require('gulp-connect'); | 11 | const connect = require('gulp-connect'); |
| 12 | const header = require('gulp-header'); | ||
| 13 | const footer = require('gulp-footer'); | ||
| 12 | 14 | ||
| 13 | var paths = { | 15 | var paths = { |
| 14 | srcJS: 'src/js/*.js', | 16 | srcJS: 'src/js/*.js', |
| 15 | srcViews: 'src/views/*.html', | 17 | srcViews: 'src/views/*.html', |
| 18 | specs: 'spec/*.js', | ||
| 16 | tmp: 'tmp', | 19 | tmp: 'tmp', |
| 17 | dist: 'dist/' | 20 | dist: 'dist/' |
| 18 | }; | 21 | }; |
| 19 | 22 | ||
| 20 | gulp.task('templates', ['clean'], function() { | 23 | gulp.task('templates', ['clean'], function() { |
| 21 | return pump( | 24 | return pump( |
| 22 | [ | 25 | [ |
| 23 | gulp.src(paths.srcViews), | 26 | gulp.src(paths.srcViews), |
| 24 | htmlmin(), | 27 | htmlmin(), |
| 25 | templateCache('views.js', { | 28 | templateCache('views.js', { |
| 26 | module: 'focaCrearHojaRuta', | 29 | module: 'focaCrearHojaRuta', |
| 27 | root: '' | 30 | root: '' |
| 28 | }), | 31 | }), |
| 29 | gulp.dest(paths.tmp) | 32 | gulp.dest(paths.tmp) |
| 30 | ] | 33 | ] |
| 31 | ); | 34 | ); |
| 32 | }); | 35 | }); |
| 33 | 36 | ||
| 34 | gulp.task('uglify', ['templates'], function() { | 37 | gulp.task('uglify', ['templates', 'uglify-spec'], function() { |
| 35 | return pump( | 38 | return pump( |
| 36 | [ | 39 | [ |
| 37 | gulp.src([ | 40 | gulp.src([ |
| 38 | paths.srcJS, | 41 | paths.srcJS, |
| 39 | 'tmp/views.js' | 42 | 'tmp/views.js' |
| 40 | ]), | 43 | ]), |
| 41 | concat('foca-crear-hoja-ruta.js'), | 44 | concat('foca-crear-hoja-ruta.js'), |
| 42 | replace('src/views/', ''), | 45 | replace('src/views/', ''), |
| 43 | gulp.dest(paths.tmp), | 46 | gulp.dest(paths.tmp), |
| 44 | rename('foca-crear-hoja-ruta.min.js'), | 47 | rename('foca-crear-hoja-ruta.min.js'), |
| 45 | uglify(), | 48 | uglify(), |
| 46 | gulp.dest(paths.dist) | 49 | gulp.dest(paths.dist) |
| 47 | ] | 50 | ] |
| 48 | ); | 51 | ); |
| 49 | }); | 52 | }); |
| 50 | 53 | ||
| 54 | gulp.task('uglify-spec', function() { | ||
| 55 | return pump([ | ||
| 56 | gulp.src(paths.specs), | ||
| 57 | concat('foca-crear-hoja-ruta.spec.js'), | ||
| 58 | replace("src/views/", ''), | ||
| 59 | header("describe('Módulo foca-crear-hoja-ruta', function() { \n"), | ||
| 60 | footer("});"), | ||
| 61 | gulp.dest(paths.dist) | ||
| 62 | ]); | ||
| 63 | }); | ||
| 64 | |||
| 51 | gulp.task('clean', function() { | 65 | gulp.task('clean', function() { |
| 52 | return gulp.src(['tmp', 'dist'], {read: false}) | 66 | return gulp.src(['tmp', 'dist'], {read: false}) |
| 53 | .pipe(clean()); | 67 | .pipe(clean()); |
| 54 | }); | 68 | }); |
| 55 | 69 | ||
| 56 | gulp.task('pre-commit', function() { | 70 | gulp.task('pre-commit', function() { |
| 57 | return pump( | 71 | return pump( |
| 58 | [ | 72 | [ |
| 59 | gulp.src(paths.srcJS), | 73 | gulp.src([paths.srcJS, paths.specs]), |
| 60 | jshint('.jshintrc'), | 74 | jshint('.jshintrc'), |
| 61 | jshint.reporter('default'), | 75 | jshint.reporter('default'), |
| 62 | jshint.reporter('fail') | 76 | jshint.reporter('fail') |
| 63 | ] | 77 | ] |
| 64 | ); | 78 | ); |
| 65 | 79 | ||
| 66 | gulp.start('uglify'); | 80 | gulp.start('uglify'); |
| 67 | }); | 81 | }); |
| 68 | 82 | ||
| 69 | gulp.task('webserver', function() { | 83 | gulp.task('webserver', function() { |
| 70 | pump [ | 84 | pump [ |
| 71 | connect.server({port: 3300, host: '0.0.0.0'}) | 85 | connect.server({port: 3300, host: '0.0.0.0'}) |
| 72 | ] | 86 | ] |
| 73 | }); | 87 | }); |
| 74 | 88 | ||
| 75 | gulp.task('clean-post-install', function() { | 89 | gulp.task('clean-post-install', function() { |
| 76 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 90 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
| 77 | 'index.html'], {read: false}) | 91 | 'index.html', 'test.html', 'spec'], {read: false}) |
| 78 | .pipe(clean()); | 92 | .pipe(clean()); |
| 79 | }); | 93 | }); |
| 80 | 94 | ||
| 81 | gulp.task('default', ['webserver']); | 95 | gulp.task('default', ['webserver']); |
| 82 | 96 | ||
| 83 | gulp.task('watch', function() { | 97 | gulp.task('watch', function() { |
| 84 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | 98 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); |
| 85 | }); | 99 | }); |
| 86 | 100 |
package.json
| 1 | { | 1 | { |
| 2 | "name": "foca-crear-hoja-ruta", | 2 | "name": "foca-crear-hoja-ruta", |
| 3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
| 4 | "description": "foca-crear-hoja-ruta", | 4 | "description": "foca-crear-hoja-ruta", |
| 5 | "main": "index.js", | 5 | "main": "index.js", |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | "test": "echo \"Error: no test specified\" && exit 1", | 7 | "test": "test.html", |
| 8 | "compile": "gulp uglify", | 8 | "compile": "gulp uglify", |
| 9 | "gulp-pre-commit": "gulp pre-commit", | 9 | "gulp-pre-commit": "gulp pre-commit", |
| 10 | "postinstall": "npm run compile && gulp clean-post-install", | 10 | "postinstall": "npm run compile && gulp clean-post-install", |
| 11 | "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route 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 git+http://git.focasoftware.com/npm/foca-botonera-facturador.git git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-remito.git" | 11 | "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route 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 git+http://git.focasoftware.com/npm/foca-botonera-facturador.git git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-remito.git" |
| 12 | }, | 12 | }, |
| 13 | "pre-commit": [ | 13 | "pre-commit": [ |
| 14 | "gulp-pre-commit" | 14 | "gulp-pre-commit" |
| 15 | ], | 15 | ], |
| 16 | "repository": { | 16 | "repository": { |
| 17 | "type": "git", | 17 | "type": "git", |
| 18 | "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git" | 18 | "url": "https://debo.suite.repo/modulos-npm/foca-crear-hoja-ruta.git" |
| 19 | }, | 19 | }, |
| 20 | "author": "Foca Software", | 20 | "author": "Foca Software", |
| 21 | "license": "ISC", | 21 | "license": "ISC", |
| 22 | "devDependencies": { | 22 | "devDependencies": { |
| 23 | "angular": "^1.7.5", | 23 | "angular": "^1.7.5", |
| 24 | "angular-ladda": "^0.4.3", | 24 | "angular-ladda": "^0.4.3", |
| 25 | "angular-mocks": "^1.7.7", | ||
| 25 | "angular-route": "^1.7.5", | 26 | "angular-route": "^1.7.5", |
| 26 | "bootstrap": "^4.1.3", | 27 | "bootstrap": "^4.1.3", |
| 27 | "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", | 28 | "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", |
| 28 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", | 29 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", |
| 29 | "foca-modal-remito": "git+http://git.focasoftware.com/npm/foca-modal-remito.git", | 30 | "foca-modal-remito": "git+http://git.focasoftware.com/npm/foca-modal-remito.git", |
| 30 | "font-awesome": "^4.7.0", | 31 | "font-awesome": "^4.7.0", |
| 31 | "gulp": "^3.9.1", | 32 | "gulp": "^3.9.1", |
| 32 | "gulp-angular-templatecache": "^2.2.5", | 33 | "gulp-angular-templatecache": "^2.2.5", |
| 33 | "gulp-clean": "^0.4.0", | 34 | "gulp-clean": "^0.4.0", |
| 34 | "gulp-concat": "^2.6.1", | 35 | "gulp-concat": "^2.6.1", |
| 35 | "gulp-connect": "^5.6.1", | 36 | "gulp-connect": "^5.6.1", |
| 36 | "gulp-htmlmin": "^5.0.1", | 37 | "gulp-htmlmin": "^5.0.1", |
| 37 | "gulp-jshint": "^2.1.0", | 38 | "gulp-jshint": "^2.1.0", |
| 38 | "gulp-rename": "^1.4.0", | 39 | "gulp-rename": "^1.4.0", |
| 39 | "gulp-replace": "^1.0.0", | 40 | "gulp-replace": "^1.0.0", |
| 40 | "gulp-sequence": "^1.0.0", | 41 | "gulp-sequence": "^1.0.0", |
| 41 | "gulp-uglify": "^3.0.1", | 42 | "gulp-uglify": "^3.0.1", |
| 42 | "jasmine-core": "^3.3.0", | 43 | "jasmine-core": "^3.3.0", |
| 43 | "jquery": "^3.3.1", | 44 | "jquery": "^3.3.1", |
| 44 | "jshint": "^2.9.6", | 45 | "jshint": "^2.9.6", |
| 45 | "ladda": "1.0.6", | 46 | "ladda": "1.0.6", |
| 46 | "pre-commit": "^1.2.2", | 47 | "pre-commit": "^1.2.2", |
| 47 | "pump": "^3.0.0", | 48 | "pump": "^3.0.0", |
| 48 | "ui-bootstrap4": "^3.0.5" | 49 | "ui-bootstrap4": "^3.0.5" |
| 49 | } | 50 | } |
| 50 | } | 51 | } |
| 51 | 52 |
spec/controllerSpec.js
| File was created | 1 | describe('Controladores módulo crear hoja de ruta', function() { | |
| 2 | |||
| 3 | var $controller; | ||
| 4 | |||
| 5 | beforeEach(function() { | ||
| 6 | |||
| 7 | module('focaCrearHojaRuta'); | ||
| 8 | inject(function(_$controller_) { | ||
| 9 | $controller = _$controller_; | ||
| 10 | }); | ||
| 11 | }); | ||
| 12 | |||
| 13 | describe('controlador focaModalDatosHojaRutaCtrl', function() { | ||
| 14 | |||
| 15 | it('Existe el controlador focaModalDatosHojaRutaCtrl', function() { | ||
| 16 | |||
| 17 | //act | ||
| 18 | var controlador = $controller('focaModalDatosHojaRutaCtrl', { | ||
| 19 | $filter: {}, | ||
| 20 | $scope: {}, | ||
| 21 | $uibModalInstance: {}, | ||
| 22 | focaModalService: {}, | ||
| 23 | parametrosDatos: {} | ||
| 24 | }); | ||
| 25 | |||
| 26 | //assert | ||
| 27 | expect(typeof controlador).toEqual('object'); | ||
| 28 | }); | ||
| 29 | |||
| 30 | it('función $scope.aceptar muestra alerta cuando el formulario es inválido', function() { | ||
| 31 | |||
| 32 | //arrange | ||
| 33 | var scope = {}; | ||
| 34 | var focaModalService = { | ||
| 35 | alert: function() { } | ||
| 36 | }; | ||
| 37 | |||
| 38 | $controller('focaModalDatosHojaRutaCtrl', { | ||
| 39 | $filter: {}, | ||
| 40 | $scope: scope, | ||
| 41 | $uibModalInstance: {}, | ||
| 42 | focaModalService: focaModalService, | ||
| 43 | parametrosDatos: {} | ||
| 44 | }); | ||
| 45 | |||
| 46 | //act | ||
| 47 | scope.formDatosHojaRuta = { | ||
| 48 | $valid: false | ||
| 49 | }; | ||
| 50 | spyOn(focaModalService, 'alert'); | ||
| 51 | scope.aceptar(13); | ||
| 52 | |||
| 53 | //assert | ||
| 54 | expect(focaModalService.alert).toHaveBeenCalledWith('Formulario inválido'); | ||
| 55 | }); | ||
| 56 | |||
| 57 | it('función $scope.aceptar llama a uibModalInstance.close', function() { | ||
| 58 | |||
| 59 | //arrange | ||
| 60 | var scope = {}; | ||
| 61 | var uibModalInstance = { | ||
| 62 | close: function() { } | ||
| 63 | }; | ||
| 64 | |||
| 65 | $controller('focaModalDatosHojaRutaCtrl', { | ||
| 66 | $filter: {}, | ||
| 67 | $scope: scope, | ||
| 68 | $uibModalInstance: uibModalInstance, | ||
| 69 | focaModalService: {}, | ||
| 70 | parametrosDatos: {} | ||
| 71 | }); | ||
| 72 | |||
| 73 | //act | ||
| 74 | scope.formDatosHojaRuta = { | ||
| 75 | $valid: true | ||
| 76 | }; | ||
| 77 | spyOn(uibModalInstance, 'close'); | ||
| 78 | scope.aceptar(13); | ||
| 79 | |||
| 80 | //assert | ||
| 81 | expect(uibModalInstance.close).toHaveBeenCalled(); | ||
| 82 | }); | ||
| 83 | |||
| 84 | it('función $scope.next suma uno a focused', function() { | ||
| 85 | |||
| 86 | //arrange | ||
| 87 | var scope = {}; | ||
| 88 | |||
| 89 | $controller('focaModalDatosHojaRutaCtrl', { | ||
| 90 | $filter: {}, | ||
| 91 | $scope: scope, | ||
| 92 | $uibModalInstance: {}, | ||
| 93 | focaModalService: {}, | ||
| 94 | parametrosDatos: {} | ||
| 95 | }); | ||
| 96 | scope.focused = 1; | ||
| 97 | |||
| 98 | //act | ||
| 99 | var esperado = scope.focused + 1; | ||
| 100 | scope.next(13); | ||
| 101 | |||
| 102 | //assert | ||
| 103 | expect(scope.focused).toEqual(esperado); | ||
| 104 | }); | ||
| 105 | |||
| 106 | it('función $scope.cancel llama a dismiss', function() { | ||
| 107 | |||
| 108 | //arrange | ||
| 109 | var scope = {}; | ||
| 110 | var uibModalInstance = { | ||
| 111 | dismiss: function() { } | ||
| 112 | }; | ||
| 113 | |||
| 114 | $controller('focaModalDatosHojaRutaCtrl', { | ||
| 115 | $filter: {}, | ||
| 116 | $scope: scope, | ||
| 117 | $uibModalInstance: uibModalInstance, | ||
| 118 | focaModalService: {}, | ||
| 119 | parametrosDatos: {} | ||
| 120 | }); | ||
| 121 | |||
| 122 | //act | ||
| 123 | spyOn(uibModalInstance, 'dismiss'); | ||
| 124 | scope.cancel(); | ||
| 125 | |||
| 126 | //assert | ||
| 127 | expect(uibModalInstance.dismiss).toHaveBeenCalledWith('cancel'); | ||
| 128 | }); | ||
| 129 | }); | ||
| 130 | |||
| 131 | describe('controlador hojaRutaCtrl', function() { | ||
| 132 | |||
| 133 | var $filter = function() { | ||
| 134 | return function() { }; | ||
| 135 | }; | ||
| 136 | |||
| 137 | var $timeout = function() { }; | ||
| 138 | |||
| 139 | it('existe el controlador hojaRutaCtrl', function() { | ||
| 140 | |||
| 141 | //act | ||
| 142 | var controlador = $controller('hojaRutaCtrl', { | ||
| 143 | $scope: { | ||
| 144 | $broadcast: function() { } | ||
| 145 | }, | ||
| 146 | $uibModal: {}, | ||
| 147 | $location: {}, | ||
| 148 | $filter: $filter, | ||
| 149 | $timeout: $timeout, | ||
| 150 | focaCrearHojaRutaService: { | ||
| 151 | getBotonera: function() { }, | ||
| 152 | getNumeroHojaRuta: function() { | ||
| 153 | return { | ||
| 154 | then: function() { } | ||
| 155 | }; | ||
| 156 | } | ||
| 157 | }, | ||
| 158 | focaModalService: {}, | ||
| 159 | focaBotoneraLateralService: {}, | ||
| 160 | focaLoginService: {}, | ||
| 161 | }); | ||
| 162 | |||
| 163 | //assert | ||
| 164 | expect(typeof controlador).toEqual('object'); | ||
| 165 | }); | ||
| 166 | |||
| 167 | it('guardar hoja ruta valida que tenga al menos un remito', function() { | ||
| 168 | |||
| 169 | //arrange | ||
| 170 | var scope = { | ||
| 171 | $broadcast: function() { } | ||
| 172 | }; | ||
| 173 | var focaModalService = { | ||
| 174 | alert: function() { } | ||
| 175 | }; | ||
| 176 | |||
| 177 | $controller('hojaRutaCtrl', { | ||
| 178 | $scope: scope, | ||
| 179 | $uibModal: {}, | ||
| 180 | $location: {}, | ||
| 181 | $filter: $filter, | ||
| 182 | $timeout: $timeout, | ||
| 183 | focaCrearHojaRutaService: { | ||
| 184 | getBotonera: function() { }, | ||
| 185 | getNumeroHojaRuta: function() { | ||
| 186 | return { | ||
| 187 | then: function() { } | ||
| 188 | }; | ||
| 189 | } | ||
| 190 | }, | ||
| 191 | focaModalService: focaModalService, | ||
| 192 | focaBotoneraLateralService: {}, | ||
| 193 | focaLoginService: {}, | ||
| 194 | }); | ||
| 195 | scope.remitosTabla = []; | ||
| 196 | |||
| 197 | //act | ||
| 198 | spyOn(focaModalService, 'alert'); | ||
| 199 | |||
| 200 | scope.crearHojaRuta(); | ||
| 201 | |||
| 202 | //assert | ||
| 203 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Remitos'); | ||
| 204 | }); | ||
| 205 | |||
| 206 | it('guardar hoja ruta valida que tenga chofer', function() { | ||
| 207 | |||
| 208 | //arrange | ||
| 209 | var scope = { | ||
| 210 | $broadcast: function() { } | ||
| 211 | }; | ||
| 212 | var focaModalService = { | ||
| 213 | alert: function() { } | ||
| 214 | }; | ||
| 215 | |||
| 216 | $controller('hojaRutaCtrl', { | ||
| 217 | $scope: scope, | ||
| 218 | $uibModal: {}, | ||
| 219 | $location: {}, | ||
| 220 | $filter: $filter, | ||
| 221 | $timeout: $timeout, | ||
| 222 | focaCrearHojaRutaService: { | ||
| 223 | getBotonera: function() { }, | ||
| 224 | getNumeroHojaRuta: function() { | ||
| 225 | return { | ||
| 226 | then: function() { } | ||
| 227 | }; | ||
| 228 | } | ||
| 229 | }, | ||
| 230 | focaModalService: focaModalService, | ||
| 231 | focaBotoneraLateralService: {}, | ||
| 232 | focaLoginService: {}, | ||
| 233 | }); | ||
| 234 | scope.remitosTabla = [1]; | ||
| 235 | scope.hojaRuta = { | ||
| 236 | chofer: { } | ||
| 237 | }; | ||
| 238 | |||
| 239 | //act | ||
| 240 | spyOn(focaModalService, 'alert'); | ||
| 241 | |||
| 242 | scope.crearHojaRuta(); | ||
| 243 | |||
| 244 | //assert | ||
| 245 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Chofer'); | ||
| 246 | }); | ||
| 247 | |||
| 248 | it('guardar hoja ruta valida que tenga vehiculo', function() { | ||
| 249 | |||
| 250 | //arrange | ||
| 251 | var scope = { | ||
| 252 | $broadcast: function() { } | ||
| 253 | }; | ||
| 254 | var focaModalService = { | ||
| 255 | alert: function() { } | ||
| 256 | }; | ||
| 257 | |||
| 258 | $controller('hojaRutaCtrl', { | ||
| 259 | $scope: scope, | ||
| 260 | $uibModal: {}, | ||
| 261 | $location: {}, | ||
| 262 | $filter: $filter, | ||
| 263 | $timeout: $timeout, | ||
| 264 | focaCrearHojaRutaService: { | ||
| 265 | getBotonera: function() { }, | ||
| 266 | getNumeroHojaRuta: function() { | ||
| 267 | return { | ||
| 268 | then: function() { } | ||
| 269 | }; | ||
| 270 | } | ||
| 271 | }, | ||
| 272 | focaModalService: focaModalService, | ||
| 273 | focaBotoneraLateralService: {}, | ||
| 274 | focaLoginService: {}, | ||
| 275 | }); | ||
| 276 | scope.remitosTabla = [1]; | ||
| 277 | scope.hojaRuta = { | ||
| 278 | chofer: { id: true }, | ||
| 279 | vehiculo: { } | ||
| 280 | }; | ||
| 281 | |||
| 282 | //act | ||
| 283 | spyOn(focaModalService, 'alert'); | ||
| 284 | |||
| 285 | scope.crearHojaRuta(); | ||
| 286 | |||
| 287 | //assert | ||
| 288 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vehiculo'); | ||
| 289 | }); | ||
| 290 | |||
| 291 | it('guardar hoja ruta valida que tenga transportista', function() { | ||
| 292 | |||
| 293 | //arrange | ||
| 294 | var scope = { | ||
| 295 | $broadcast: function() { } | ||
| 296 | }; | ||
| 297 | var focaModalService = { | ||
| 298 | alert: function() { } | ||
| 299 | }; | ||
| 300 | |||
| 301 | $controller('hojaRutaCtrl', { | ||
| 302 | $scope: scope, | ||
| 303 | $uibModal: {}, | ||
| 304 | $location: {}, | ||
| 305 | $filter: $filter, | ||
| 306 | $timeout: $timeout, | ||
| 307 | focaCrearHojaRutaService: { | ||
| 308 | getBotonera: function() { }, | ||
| 309 | getNumeroHojaRuta: function() { | ||
| 310 | return { | ||
| 311 | then: function() { } | ||
| 312 | }; | ||
| 313 | } | ||
| 314 | }, | ||
| 315 | focaModalService: focaModalService, | ||
| 316 | focaBotoneraLateralService: {}, | ||
| 317 | focaLoginService: {}, | ||
| 318 | }); | ||
| 319 | scope.remitosTabla = [1]; | ||
| 320 | scope.hojaRuta = { | ||
| 321 | chofer: { id: true }, | ||
| 322 | vehiculo: { id: true }, | ||
| 323 | transportista: { } | ||
| 324 | }; | ||
| 325 | |||
| 326 | //act | ||
| 327 | spyOn(focaModalService, 'alert'); | ||
| 328 | |||
| 329 | scope.crearHojaRuta(); | ||
| 330 | |||
| 331 | //assert | ||
| 332 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Transportista'); | ||
| 333 | }); | ||
| 334 | |||
| 335 | it('guardar hoja ruta valida que tenga tarifario', function() { | ||
| 336 | |||
| 337 | //arrange | ||
| 338 | var scope = { | ||
| 339 | $broadcast: function() { } | ||
| 340 | }; | ||
| 341 | var focaModalService = { | ||
| 342 | alert: function() { } | ||
| 343 | }; | ||
| 344 | |||
| 345 | $controller('hojaRutaCtrl', { | ||
| 346 | $scope: scope, | ||
| 347 | $uibModal: {}, | ||
| 348 | $location: {}, | ||
| 349 | $filter: $filter, | ||
| 350 | $timeout: $timeout, | ||
| 351 | focaCrearHojaRutaService: { | ||
| 352 | getBotonera: function() { }, | ||
| 353 | getNumeroHojaRuta: function() { | ||
| 354 | return { | ||
| 355 | then: function() { } | ||
| 356 | }; | ||
| 357 | } | ||
| 358 | }, | ||
| 359 | focaModalService: focaModalService, | ||
| 360 | focaBotoneraLateralService: {}, | ||
| 361 | focaLoginService: {}, | ||
| 362 | }); | ||
| 363 | scope.remitosTabla = [1]; | ||
| 364 | scope.hojaRuta = { | ||
| 365 | chofer: { id: true }, | ||
| 366 | vehiculo: { id: true }, | ||
| 367 | transportista: { COD: true }, | ||
| 368 | tarifario: { } | ||
| 369 | }; | ||
| 370 | |||
| 371 | //act | ||
| 372 | spyOn(focaModalService, 'alert'); | ||
| 373 | |||
| 374 | scope.crearHojaRuta(); | ||
| 375 | |||
| 376 | //assert | ||
| 377 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Tarifario'); | ||
| 378 | }); | ||
| 379 | |||
| 380 | it('guardar hoja ruta valida que tenga datosExtra', function() { | ||
| 381 | |||
| 382 | //arrange | ||
| 383 | var scope = { | ||
| 384 | $broadcast: function() { } | ||
| 385 | }; | ||
| 386 | var focaModalService = { | ||
| 387 | alert: function() { } | ||
| 388 | }; | ||
| 389 | |||
| 390 | $controller('hojaRutaCtrl', { | ||
| 391 | $scope: scope, | ||
| 392 | $uibModal: {}, | ||
| 393 | $location: {}, | ||
| 394 | $filter: $filter, | ||
| 395 | $timeout: $timeout, | ||
| 396 | focaCrearHojaRutaService: { | ||
| 397 | getBotonera: function() { }, | ||
| 398 | getNumeroHojaRuta: function() { | ||
| 399 | return { | ||
| 400 | then: function() { } | ||
| 401 | }; | ||
| 402 | } | ||
| 403 | }, | ||
| 404 | focaModalService: focaModalService, | ||
| 405 | focaBotoneraLateralService: {}, | ||
| 406 | focaLoginService: {}, | ||
| 407 | }); | ||
| 408 | scope.remitosTabla = [1]; | ||
| 409 | scope.hojaRuta = { | ||
| 410 | chofer: { id: true }, | ||
| 411 | vehiculo: { id: true }, | ||
| 412 | transportista: { COD: true }, | ||
| 413 | tarifario: { costo: true } | ||
| 414 | }; | ||
| 415 | |||
| 416 | //act | ||
| 417 | spyOn(focaModalService, 'alert'); | ||
| 418 | |||
| 419 | scope.crearHojaRuta(); | ||
| 420 | |||
| 421 | //assert | ||
| 422 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Datos extra'); | ||
| 423 | }); | ||
| 424 | |||
| 425 | it('guardar hoja ruta llama focaCrearHojaRutaService.crearHojaRuta', function() { | ||
| 426 | |||
| 427 | //arrange | ||
| 428 | var scope = { | ||
| 429 | $broadcast: function() { } | ||
| 430 | }; | ||
| 431 | var focaCrearHojaRutaService = { | ||
| 432 | getBotonera: function() { }, | ||
| 433 | getNumeroHojaRuta: function() { | ||
| 434 | return { | ||
| 435 | then: function() { } | ||
| 436 | }; | ||
| 437 | }, | ||
| 438 | crearHojaRuta: function() { } | ||
| 439 | }; | ||
| 440 | |||
| 441 | $controller('hojaRutaCtrl', { | ||
| 442 | $scope: scope, | ||
| 443 | $uibModal: {}, | ||
| 444 | $location: {}, | ||
| 445 | $filter: $filter, | ||
| 446 | $timeout: $timeout, | ||
| 447 | focaCrearHojaRutaService: focaCrearHojaRutaService, | ||
| 448 | focaModalService: {}, | ||
| 449 | focaBotoneraLateralService: {}, | ||
| 450 | focaLoginService: {}, | ||
| 451 | }); | ||
| 452 | scope.remitosTabla = [1]; | ||
| 453 | scope.hojaRuta = { | ||
| 454 | chofer: { id: true }, | ||
| 455 | vehiculo: { id: true }, | ||
| 456 | transportista: { COD: true }, | ||
| 457 | tarifario: { costo: true }, | ||
| 458 | datosExtra: { } | ||
| 459 | }; | ||
| 460 | scope.fechaReparto = new Date(); | ||
| 461 | |||
| 462 | var respuesta = { then: function() { } }; | ||
| 463 | |||
| 464 | //act | ||
| 465 | spyOn(focaCrearHojaRutaService, 'crearHojaRuta').and.returnValue(respuesta); | ||
| 466 | |||
| 467 | scope.crearHojaRuta(); | ||
| 468 | |||
| 469 | //assert | ||
| 470 | expect(focaCrearHojaRutaService.crearHojaRuta).toHaveBeenCalled(); | ||
| 471 | }); | ||
| 472 | |||
| 473 | it('seleccionarTransportista levanta modal y setea datos', function(done) { | ||
| 474 | |||
| 475 | //arrange | ||
| 476 | var scope = { | ||
| 477 | $broadcast: function() { } | ||
| 478 | }; | ||
| 479 | var focaModalService = { | ||
| 480 | modal: function() { } | ||
| 481 | }; | ||
| 482 | |||
| 483 | $controller('hojaRutaCtrl', { | ||
| 484 | $scope: scope, | ||
| 485 | $uibModal: {}, | ||
| 486 | $location: {}, | ||
| 487 | $filter: $filter, | ||
| 488 | $timeout: $timeout, | ||
| 489 | focaCrearHojaRutaService: { | ||
| 490 | getBotonera: function() { }, | ||
| 491 | getNumeroHojaRuta: function() { | ||
| 492 | return { | ||
| 493 | then: function() { } | ||
| 494 | }; | ||
| 495 | } | ||
| 496 | }, | ||
| 497 | focaModalService: focaModalService, | ||
| 498 | focaBotoneraLateralService: {}, | ||
| 499 | focaLoginService: {}, | ||
| 500 | }); | ||
| 501 | |||
| 502 | var respuesta = 1; | ||
| 503 | var promesa = Promise.resolve(respuesta); | ||
| 504 | |||
| 505 | //act | ||
| 506 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | ||
| 507 | spyOn(scope, '$broadcast'); | ||
| 508 | |||
| 509 | scope.seleccionarTransportista(); | ||
| 510 | |||
| 511 | //assert | ||
| 512 | promesa.then(function() { | ||
| 513 | expect(focaModalService.modal).toHaveBeenCalled(); | ||
| 514 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
| 515 | expect(scope.hojaRuta.transportista).toEqual(respuesta); | ||
| 516 | done(); | ||
| 517 | }); | ||
| 518 | |||
| 519 | }); | ||
| 520 | |||
| 521 | it('seleccionarChofer levanta modal y setea datos', function(done) { | ||
| 522 | |||
| 523 | //arrange | ||
| 524 | var scope = { | ||
| 525 | $broadcast: function() { } | ||
| 526 | }; | ||
| 527 | var focaModalService = { | ||
| 528 | modal: function() { } | ||
| 529 | }; | ||
| 530 | |||
| 531 | $controller('hojaRutaCtrl', { | ||
| 532 | $scope: scope, | ||
| 533 | $uibModal: {}, | ||
| 534 | $location: {}, | ||
| 535 | $filter: $filter, | ||
| 536 | $timeout: $timeout, | ||
| 537 | focaCrearHojaRutaService: { | ||
| 538 | getBotonera: function() { }, | ||
| 539 | getNumeroHojaRuta: function() { | ||
| 540 | return { | ||
| 541 | then: function() { } | ||
| 542 | }; | ||
| 543 | } | ||
| 544 | }, | ||
| 545 | focaModalService: focaModalService, | ||
| 546 | focaBotoneraLateralService: {}, | ||
| 547 | focaLoginService: {}, | ||
| 548 | }); | ||
| 549 | |||
| 550 | var respuesta = 1; | ||
| 551 | var promesa = Promise.resolve(respuesta); | ||
| 552 | |||
| 553 | //act | ||
| 554 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | ||
| 555 | spyOn(scope, '$broadcast'); | ||
| 556 | |||
| 557 | scope.seleccionarChofer(); | ||
| 558 | |||
| 559 | //assert | ||
| 560 | promesa.then(function() { | ||
| 561 | expect(focaModalService.modal).toHaveBeenCalled(); | ||
| 562 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
| 563 | expect(scope.hojaRuta.chofer).toEqual(respuesta); | ||
| 564 | done(); | ||
| 565 | }); | ||
| 566 | |||
| 567 | }); | ||
| 568 | |||
| 569 | it('seleccionarTarifario levanta modal y setea datos', function(done) { | ||
| 570 | |||
| 571 | //arrange | ||
| 572 | var scope = { | ||
| 573 | $broadcast: function() { } | ||
| 574 | }; | ||
| 575 | var uibModal = { | ||
| 576 | open: function() { } | ||
| 577 | }; | ||
| 578 | |||
| 579 | $controller('hojaRutaCtrl', { | ||
| 580 | $scope: scope, | ||
| 581 | $uibModal: uibModal, | ||
| 582 | $location: {}, | ||
| 583 | $filter: $filter, | ||
| 584 | $timeout: $timeout, | ||
| 585 | focaCrearHojaRutaService: { | ||
| 586 | getBotonera: function() { }, | ||
| 587 | getNumeroHojaRuta: function() { | ||
| 588 | return { | ||
| 589 | then: function() { } | ||
| 590 | }; | ||
| 591 | } | ||
| 592 | }, | ||
| 593 | focaModalService: {}, | ||
| 594 | focaBotoneraLateralService: {}, | ||
| 595 | focaLoginService: {}, | ||
| 596 | }); | ||
| 597 | |||
| 598 | var respuesta = 1; | ||
| 599 | var promesa = { result: Promise.resolve(respuesta) }; | ||
| 600 | |||
| 601 | //act | ||
| 602 | spyOn(uibModal, 'open').and.returnValue(promesa); | ||
| 603 | spyOn(scope, '$broadcast'); | ||
| 604 | |||
| 605 | scope.seleccionarTarifario(); | ||
| 606 | |||
| 607 | //assert | ||
| 608 | promesa.result.then(function() { | ||
| 609 | expect(uibModal.open).toHaveBeenCalled(); | ||
| 610 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
| 611 | expect(scope.hojaRuta.tarifario).toEqual(respuesta); | ||
| 612 | done(); | ||
| 613 | }); | ||
| 614 | |||
| 615 | }); | ||
| 616 | |||
| 617 | it('seleccionarRemitos levanta modal y setea datos', function(done) { | ||
| 618 | |||
| 619 | //arrange | ||
| 620 | var scope = { | ||
| 621 | $broadcast: function() { } | ||
| 622 | }; | ||
| 623 | var uibModal = { | ||
| 624 | open: function() { } | ||
| 625 | }; | ||
| 626 | |||
| 627 | $controller('hojaRutaCtrl', { | ||
| 628 | $scope: scope, | ||
| 629 | $uibModal: uibModal, | ||
| 630 | $location: {}, | ||
| 631 | $filter: $filter, | ||
| 632 | $timeout: $timeout, | ||
| 633 | focaCrearHojaRutaService: { | ||
| 634 | getBotonera: function() { }, | ||
| 635 | getNumeroHojaRuta: function() { | ||
| 636 | return { | ||
| 637 | then: function() { } | ||
| 638 | }; | ||
| 639 | } | ||
| 640 | }, | ||
| 641 | focaModalService: {}, | ||
| 642 | focaBotoneraLateralService: {}, | ||
| 643 | focaLoginService: {}, | ||
| 644 | }); | ||
| 645 | scope.eligioPreConfirmado = false; | ||
| 646 | scope.fechaReparto = true; | ||
| 647 | scope.hojaRuta = { | ||
| 648 | vehiculo: { | ||
| 649 | id: true | ||
| 650 | } | ||
| 651 | }; | ||
| 652 | |||
| 653 | var respuesta = 1; | ||
| 654 | var promesa = { result: Promise.resolve(respuesta) }; | ||
| 655 | |||
| 656 | //act | ||
| 657 | spyOn(uibModal, 'open').and.returnValue(promesa); | ||
| 658 | |||
| 659 | scope.seleccionarRemitos(); | ||
| 660 | |||
| 661 | //assert | ||
| 662 | promesa.result.then(function() { | ||
| 663 | expect(uibModal.open).toHaveBeenCalled(); | ||
| 664 | done(); | ||
| 665 | }); | ||
| 666 | |||
| 667 | }); | ||
| 668 | |||
| 669 | it('seleccionarVehiculosPrecargados levanta modal y setea datos', function(done) { | ||
| 670 | |||
| 671 | //arrange | ||
| 672 | var scope = { | ||
| 673 | $broadcast: function() { } | ||
| 674 | }; | ||
| 675 | var focaModalService = { | ||
| 676 | modal: function() { } | ||
| 677 | }; | ||
| 678 | var focaCrearHojaRutaService = { | ||
| 679 | getBotonera: function() { }, | ||
| 680 | getNumeroHojaRuta: function() { | ||
| 681 | return { | ||
| 682 | then: function() { } | ||
| 683 | }; | ||
| 684 | }, | ||
| 685 | getRemitosByIdVehiculo: function() { | ||
| 686 | return { | ||
| 687 | then: function() { } | ||
| 688 | }; | ||
| 689 | } | ||
| 690 | }; | ||
| 691 | |||
| 692 | $controller('hojaRutaCtrl', { | ||
| 693 | $scope: scope, | ||
| 694 | $uibModal: {}, | ||
| 695 | $location: {}, | ||
| 696 | $filter: $filter, | ||
| 697 | $timeout: $timeout, | ||
| 698 | focaCrearHojaRutaService: focaCrearHojaRutaService, | ||
| 699 | focaModalService: focaModalService, | ||
| 700 | focaBotoneraLateralService: {}, | ||
| 701 | focaLoginService: {}, | ||
| 702 | }); | ||
| 703 | scope.eligioPreConfirmado = false; | ||
| 704 | scope.fechaReparto = new Date(); | ||
| 705 | |||
| 706 | var respuesta = { transportista: { } }; | ||
| 707 | var promesa = Promise.resolve(respuesta); | ||
| 708 | |||
| 709 | //act | ||
| 710 | spyOn(focaModalService, 'modal') | ||
| 711 | .and.returnValue(promesa); | ||
| 712 | spyOn(focaCrearHojaRutaService, 'getRemitosByIdVehiculo') | ||
| 713 | .and.returnValue( { then: function() { } } ); | ||
| 714 | spyOn(scope, '$broadcast'); | ||
| 715 | |||
| 716 | scope.seleccionarVehiculosPrecargados(); | ||
| 717 | |||
| 718 | //assert | ||
| 719 | promesa.then(function() { | ||
| 720 | expect(focaModalService.modal).toHaveBeenCalled(); | ||
| 721 | expect(focaCrearHojaRutaService.getRemitosByIdVehiculo).toHaveBeenCalled(); | ||
| 722 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
| 723 | done(); | ||
| 724 | }); | ||
| 725 | |||
| 726 | }); | ||
| 727 | |||
| 728 | it('cargarCisterna levanta modal y devuelve promesa', function(done) { | ||
| 729 | |||
| 730 | //arrange | ||
| 731 | var scope = { | ||
| 732 | $broadcast: function() { } | ||
| 733 | }; | ||
| 734 | var uibModal = { | ||
| 735 | open: function() { } | ||
| 736 | }; | ||
| 737 | |||
| 738 | $controller('hojaRutaCtrl', { | ||
| 739 | $scope: scope, | ||
| 740 | $uibModal: uibModal, | ||
| 741 | $location: {}, | ||
| 742 | $filter: $filter, | ||
| 743 | $timeout: $timeout, | ||
| 744 | focaCrearHojaRutaService: { | ||
| 745 | getBotonera: function() { }, | ||
| 746 | getNumeroHojaRuta: function() { | ||
| 747 | return { | ||
| 748 | then: function() { } | ||
| 749 | }; | ||
| 750 | } | ||
| 751 | }, | ||
| 752 | focaModalService: {}, | ||
| 753 | focaBotoneraLateralService: {}, | ||
| 754 | focaLoginService: {}, | ||
| 755 | }); | ||
| 756 | scope.eligioPreConfirmado = false; | ||
| 757 | scope.fechaReparto = true; | ||
| 758 | scope.hojaRuta = { | ||
| 759 | vehiculo: { | ||
| 760 | id: true | ||
| 761 | } | ||
| 762 | }; | ||
| 763 | |||
| 764 | var respuesta = 1; | ||
| 765 | var promesa = { result: Promise.resolve(respuesta) }; | ||
| 766 | |||
| 767 | //act | ||
| 768 | spyOn(uibModal, 'open').and.returnValue(promesa); | ||
| 769 | |||
| 770 | var resultado = scope.cargarCisterna(); | ||
| 771 | |||
| 772 | //assert | ||
| 773 | promesa.result.then(function() { | ||
| 774 | expect(uibModal.open).toHaveBeenCalled(); | ||
| 775 | expect(typeof resultado).toEqual('object'); | ||
| 776 | done(); | ||
| 777 | }); | ||
| 778 | |||
| 779 | }); | ||
| 780 | |||
| 781 | it('seleccionarFechaEntrega levanta modal', function(done) { | ||
| 782 | |||
| 783 | //arrange | ||
| 784 | var scope = { | ||
| 785 | $broadcast: function() { } | ||
| 786 | }; | ||
| 787 | var focaModalService = { | ||
| 788 | modalFecha: function() { } | ||
| 789 | }; | ||
| 790 | |||
| 791 | $controller('hojaRutaCtrl', { | ||
| 792 | $scope: scope, | ||
| 793 | $uibModal: {}, | ||
| 794 | $location: {}, | ||
| 795 | $filter: $filter, | ||
| 796 | $timeout: $timeout, | ||
| 797 | focaCrearHojaRutaService: { | ||
| 798 | getBotonera: function() { }, | ||
| 799 | getNumeroHojaRuta: function() { | ||
| 800 | return { | ||
| 801 | then: function() { } | ||
| 802 | }; | ||
| 803 | } | ||
| 804 | }, | ||
| 805 | focaModalService: focaModalService, | ||
| 806 | focaBotoneraLateralService: {}, | ||
| 807 | focaLoginService: {}, | ||
| 808 | }); | ||
| 809 | |||
| 810 | var respuesta = new Date(); | ||
| 811 | var promesa = Promise.resolve(respuesta); | ||
| 812 | |||
| 813 | //act | ||
| 814 | spyOn(focaModalService, 'modalFecha').and.returnValue(promesa); | ||
| 815 | spyOn(scope, '$broadcast'); | ||
| 816 | |||
| 817 | scope.seleccionarFechaEntrega(); | ||
| 818 | |||
| 819 | //assert | ||
| 820 | promesa.then(function() { | ||
| 821 | expect(focaModalService.modalFecha).toHaveBeenCalled(); | ||
| 822 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
| 823 | done(); | ||
| 824 | }); | ||
| 825 | |||
| 826 | }); | ||
| 827 | |||
| 828 | }); | ||
| 829 | |||
| 830 | }); | ||
| 831 |
spec/routeSpec.js
| File was created | 1 | describe('Rutas de módulo crear hoja de ruta', function() { | |
| 2 | |||
| 3 | var route; | ||
| 4 | |||
| 5 | beforeEach(function() { | ||
| 6 | module('focaCrearHojaRuta'); | ||
| 7 | inject(function($route) { | ||
| 8 | route = $route; | ||
| 9 | }); | ||
| 10 | }); | ||
| 11 | |||
| 12 | it('La ruta /venta-hoja-ruta/crear dirige correctamente', function() { | ||
| 13 | |||
| 14 | //assert | ||
| 15 | expect(route.routes['/venta-hoja-ruta/crear'].controller) | ||
| 16 | .toBe('hojaRutaCtrl'); | ||
| 17 | expect(route.routes['/venta-hoja-ruta/crear'].templateUrl) | ||
| 18 | .toBe('src/views/hoja-ruta.html'); | ||
| 19 | }); | ||
| 20 | }); |
spec/serviceSpec.js
| File was created | 1 | describe('Servicios modulo crear hoja de ruta', function() { | |
| 2 | |||
| 3 | beforeEach(function() { | ||
| 4 | module('focaCrearHojaRuta'); | ||
| 5 | inject(module(function($provide) { | ||
| 6 | $provide.value('API_ENDPOINT', { | ||
| 7 | URL: 'localhost' | ||
| 8 | }); | ||
| 9 | })); | ||
| 10 | }); | ||
| 11 | |||
| 12 | describe('Servicio focaCrearHojaRutaService', function() { | ||
| 13 | |||
| 14 | var servicio; | ||
| 15 | var httpBackend; | ||
| 16 | |||
| 17 | beforeEach(function() { | ||
| 18 | inject(function($httpBackend, _focaCrearHojaRutaService_) { | ||
| 19 | httpBackend = $httpBackend; | ||
| 20 | servicio = _focaCrearHojaRutaService_; | ||
| 21 | }); | ||
| 22 | }); | ||
| 23 | |||
| 24 | it('Existe el servicio focaCrearHojaRutaService', function() { | ||
| 25 | |||
| 26 | //assert | ||
| 27 | expect(typeof servicio).toEqual('object'); | ||
| 28 | }); | ||
| 29 | |||
| 30 | it('función crearHojaRuta llama ruta correcta', function() { | ||
| 31 | |||
| 32 | //arrange | ||
| 33 | var responseFake = 'responseFake'; | ||
| 34 | var result; | ||
| 35 | var paramFake = 'test'; | ||
| 36 | |||
| 37 | httpBackend.expectPOST('localhost/hoja-ruta', paramFake).respond(responseFake); | ||
| 38 | |||
| 39 | //act | ||
| 40 | servicio.crearHojaRuta(paramFake).then(function(data) { | ||
| 41 | result = data.data; | ||
| 42 | }); | ||
| 43 | httpBackend.flush(); | ||
| 44 | |||
| 45 | //assert | ||
| 46 | expect(result).toEqual(responseFake); | ||
| 47 | }); | ||
| 48 | |||
| 49 | it('función obtenerHojaRuta llama ruta correcta', function() { | ||
| 50 | |||
| 51 | //arrange | ||
| 52 | var responseFake = 'responseFake'; | ||
| 53 | var result; | ||
| 54 | |||
| 55 | httpBackend.expectGET('localhost/hoja-ruta').respond(responseFake); | ||
| 56 | |||
| 57 | //act | ||
| 58 | servicio.obtenerHojaRuta().then(function(data) { | ||
| 59 | result = data.data; | ||
| 60 | }); | ||
| 61 | httpBackend.flush(); | ||
| 62 | |||
| 63 | //assert | ||
| 64 | expect(result).toEqual(responseFake); | ||
| 65 | }); | ||
| 66 | |||
| 67 | it('función setHojaRuta llama ruta correcta', function() { | ||
| 68 | |||
| 69 | //arrange | ||
| 70 | var paramFake = 'paramFake'; | ||
| 71 | |||
| 72 | //act | ||
| 73 | servicio.setHojaRuta(paramFake); | ||
| 74 | |||
| 75 | //assert | ||
| 76 | expect(servicio.hojaRuta).toEqual(paramFake); | ||
| 77 | }); | ||
| 78 | |||
| 79 | it('función clearHojaRuta llama ruta correcta', function() { | ||
| 80 | |||
| 81 | //act | ||
| 82 | servicio.clearHojaRuta(); | ||
| 83 | |||
| 84 | //assert | ||
| 85 | expect(servicio.hojaRuta).toEqual(undefined); | ||
| 86 | }); | ||
| 87 | |||
| 88 | it('función getHojaRuta llama ruta correcta', function() { | ||
| 89 | |||
| 90 | //arrange | ||
| 91 | var esperado = 'unit test'; | ||
| 92 | servicio.hojaRuta = esperado; | ||
| 93 | |||
| 94 | //act | ||
| 95 | var resultado = servicio.getHojaRuta(); | ||
| 96 | |||
| 97 | //assert | ||
| 98 | expect(resultado).toEqual(esperado); | ||
| 99 | }); | ||
| 100 | |||
| 101 | it('función getArticulosByIdHojaRuta llama ruta correcta', function() { | ||
| 102 | |||
| 103 | //arrange | ||
| 104 | var responseFake = 'responseFake'; | ||
| 105 | var paramFake = 'param fake'; | ||
| 106 | var result; | ||
| 107 | |||
| 108 | httpBackend.expectGET('localhost/articulos/hoja-ruta/' + paramFake) | ||
| 109 | .respond(responseFake); | ||
| 110 | |||
| 111 | //act | ||
| 112 | servicio.getArticulosByIdHojaRuta(paramFake).then(function(data) { | ||
| 113 | result = data.data; | ||
| 114 | }); | ||
| 115 | httpBackend.flush(); | ||
| 116 | |||
| 117 | //assert | ||
| 118 | expect(result).toEqual(responseFake); | ||
| 119 | }); | ||
| 120 | |||
| 121 | it('función crearArticulosParaHojaRuta llama ruta correcta', function() { | ||
| 122 | |||
| 123 | //arrange | ||
| 124 | var responseFake = 'responseFake'; | ||
| 125 | var paramFake = 'param fake'; | ||
| 126 | var result; | ||
| 127 | |||
| 128 | httpBackend.expectPOST('localhost/articulos/hoja-ruta', | ||
| 129 | { articuloHojaRuta: paramFake }).respond(responseFake); | ||
| 130 | |||
| 131 | //act | ||
| 132 | servicio.crearArticulosParaHojaRuta(paramFake).then(function(data) { | ||
| 133 | result = data.data; | ||
| 134 | }); | ||
| 135 | httpBackend.flush(); | ||
| 136 | |||
| 137 | //assert | ||
| 138 | expect(result).toEqual(responseFake); | ||
| 139 | }); | ||
| 140 | |||
| 141 | it('función getDomiciliosByIdHojaRuta llama ruta correcta', function() { | ||
| 142 | |||
| 143 | //arrange | ||
| 144 | var responseFake = 'responseFake'; | ||
| 145 | var paramFake = 'param-fake'; | ||
| 146 | var result; | ||
| 147 | |||
| 148 | httpBackend.expectGET('localhost/hoja-ruta/' + paramFake + '/domicilios') | ||
| 149 | .respond(responseFake); | ||
| 150 | |||
| 151 | //act | ||
| 152 | servicio.getDomiciliosByIdHojaRuta(paramFake).then(function(data) { | ||
| 153 | result = data.data; | ||
| 154 | }); | ||
| 155 | httpBackend.flush(); | ||
| 156 | |||
| 157 | //assert | ||
| 158 | expect(result).toEqual(responseFake); | ||
| 159 | }); | ||
| 160 | |||
| 161 | it('función getDomiciliosByIdCliente llama ruta correcta', function() { | ||
| 162 | |||
| 163 | //arrange | ||
| 164 | var responseFake = 'responseFake'; | ||
| 165 | var paramFake = 'param-fake'; | ||
| 166 | var result; | ||
| 167 | |||
| 168 | httpBackend.expectGET('localhost/domicilio/tipo/2/cliente/' + paramFake ) | ||
| 169 | .respond(responseFake); | ||
| 170 | |||
| 171 | //act | ||
| 172 | servicio.getDomiciliosByIdCliente(paramFake).then(function(data) { | ||
| 173 | result = data.data; | ||
| 174 | }); | ||
| 175 | httpBackend.flush(); | ||
| 176 | |||
| 177 | //assert | ||
| 178 | expect(result).toEqual(responseFake); | ||
| 179 | }); | ||
| 180 | |||
| 181 | it('función getPrecioCondicion llama ruta correcta', function() { | ||
| 182 | |||
| 183 | //arrange | ||
| 184 | var responseFake = 'responseFake'; | ||
| 185 | var result; | ||
| 186 | |||
| 187 | httpBackend.expectGET('localhost/precio-condicion') | ||
| 188 | .respond(responseFake); | ||
| 189 | |||
| 190 | //act | ||
| 191 | servicio.getPrecioCondicion().then(function(data) { | ||
| 192 | result = data.data; | ||
| 193 | }); | ||
| 194 | httpBackend.flush(); | ||
| 195 | |||
| 196 | //assert | ||
| 197 | expect(result).toEqual(responseFake); | ||
| 198 | }); | ||
| 199 | |||
| 200 | it('función getPrecioCondicionById llama ruta correcta', function() { | ||
| 201 | |||
| 202 | //arrange | ||
| 203 | var responseFake = 'responseFake'; | ||
| 204 | var paramFake = 'param-fake'; | ||
| 205 | var result; | ||
| 206 | |||
| 207 | httpBackend.expectGET('localhost/precio-condicion/' + paramFake) | ||
| 208 | .respond(responseFake); | ||
| 209 | |||
| 210 | //act | ||
| 211 | servicio.getPrecioCondicionById(paramFake).then(function(data) { | ||
| 212 | result = data.data; | ||
| 213 | }); | ||
| 214 | httpBackend.flush(); | ||
| 215 | |||
| 216 | //assert | ||
| 217 | expect(result).toEqual(responseFake); | ||
| 218 | }); | ||
| 219 | |||
| 220 | it('función getPlazoPagoByPrecioCondicion llama ruta correcta', function() { | ||
| 221 | |||
| 222 | //arrange | ||
| 223 | var responseFake = 'responseFake'; | ||
| 224 | var paramFake = 'param-fake'; | ||
| 225 | var result; | ||
| 226 | |||
| 227 | httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + paramFake) | ||
| 228 | .respond(responseFake); | ||
| 229 | |||
| 230 | //act | ||
| 231 | servicio.getPlazoPagoByPrecioCondicion(paramFake).then(function(data) { | ||
| 232 | result = data.data; | ||
| 233 | }); | ||
| 234 | httpBackend.flush(); | ||
| 235 | |||
| 236 | //assert | ||
| 237 | expect(result).toEqual(responseFake); | ||
| 238 | }); | ||
| 239 | |||
| 240 | it('función crearFlete llama ruta correcta', function() { | ||
| 241 | |||
| 242 | //arrange | ||
| 243 | var responseFake = 'responseFake'; | ||
| 244 | var paramFake = 'param-fake'; | ||
| 245 | var result; | ||
| 246 | |||
| 247 | httpBackend.expectPOST('localhost/flete', { flete: paramFake }) | ||
| 248 | .respond(responseFake); | ||
| 249 | |||
| 250 | //act | ||
| 251 | servicio.crearFlete(paramFake).then(function(data) { | ||
| 252 | result = data.data; | ||
| 253 | }); | ||
| 254 | httpBackend.flush(); | ||
| 255 | |||
| 256 | //assert | ||
| 257 | expect(result).toEqual(responseFake); | ||
| 258 | }); | ||
| 259 | |||
| 260 | it('función crearPlazosParaHojaRuta llama ruta correcta', function() { | ||
| 261 | |||
| 262 | //arrange | ||
| 263 | var responseFake = 'responseFake'; | ||
| 264 | var paramFake = 'param-fake'; | ||
| 265 | var result; | ||
| 266 | |||
| 267 | httpBackend.expectPOST('localhost/plazo-pago/hoja-ruta', paramFake) | ||
| 268 | .respond(responseFake); | ||
| 269 | |||
| 270 | //act | ||
| 271 | servicio.crearPlazosParaHojaRuta(paramFake).then(function(data) { | ||
| 272 | result = data.data; | ||
| 273 | }); | ||
| 274 | httpBackend.flush(); | ||
| 275 | |||
| 276 | //assert | ||
| 277 | expect(result).toEqual(responseFake); | ||
| 278 | }); | ||
| 279 | |||
| 280 | it('función getCotizacionByIdMoneda llama ruta correcta', function() { | ||
| 281 | |||
| 282 | //arrange | ||
| 283 | var responseFake = 'responseFake'; | ||
| 284 | var paramFake = 'param-fake'; | ||
| 285 | var result; | ||
| 286 | |||
| 287 | httpBackend.expectGET('localhost/moneda/' + paramFake) | ||
| 288 | .respond(responseFake); | ||
| 289 | |||
| 290 | //act | ||
| 291 | servicio.getCotizacionByIdMoneda(paramFake).then(function(data) { | ||
| 292 | result = data.data; | ||
| 293 | }); | ||
| 294 | httpBackend.flush(); | ||
| 295 | |||
| 296 | //assert | ||
| 297 | expect(result).toEqual(responseFake); | ||
| 298 | }); | ||
| 299 | |||
| 300 | it('función crearEstadoParaHojaRuta llama ruta correcta', function() { | ||
| 301 | |||
| 302 | //arrange | ||
| 303 | var responseFake = 'responseFake'; | ||
| 304 | var paramFake = 'param-fake'; | ||
| 305 | var result; | ||
| 306 | |||
| 307 | httpBackend.expectPOST('localhost/estado', { estado: paramFake}) | ||
| 308 | .respond(responseFake); | ||
| 309 | |||
| 310 | //act | ||
| 311 | servicio.crearEstadoParaHojaRuta(paramFake).then(function(data) { | ||
| 312 | result = data.data; | ||
| 313 | }); | ||
| 314 | httpBackend.flush(); | ||
| 315 | |||
| 316 | //assert | ||
| 317 | expect(result).toEqual(responseFake); | ||
| 318 | }); | ||
| 319 | |||
| 320 | it('función getNumeroHojaRuta llama ruta correcta', function() { | ||
| 321 | |||
| 322 | //arrange | ||
| 323 | var responseFake = 'responseFake'; | ||
| 324 | var result; | ||
| 325 | |||
| 326 | httpBackend.expectGET('localhost/hoja-ruta/numero-siguiente') | ||
| 327 | .respond(responseFake); | ||
| 328 | |||
| 329 | //act | ||
| 330 | servicio.getNumeroHojaRuta().then(function(data) { | ||
| 331 | result = data.data; | ||
| 332 | }); | ||
| 333 | httpBackend.flush(); | ||
| 334 | |||
| 335 | //assert | ||
| 336 | expect(result).toEqual(responseFake); | ||
| 337 | }); | ||
| 338 | |||
| 339 | it('función getRemitosByIdVehiculo llama ruta correcta', function() { | ||
| 340 | |||
| 341 | //arrange | ||
| 342 | var responseFake = 'responseFake'; | ||
| 343 | var paramFake = 'param fake'; | ||
| 344 | var dateFake = new Date(); | ||
| 345 | var result; | ||
| 346 | |||
| 347 | httpBackend.expectGET('localhost/vehiculo/obtener/remitos/' + paramFake + '/' + | ||
| 348 | dateFake.toISOString().substring(0, 10)) | ||
| 349 | .respond(responseFake); | ||
| 350 | |||
| 351 | //act | ||
| 352 | servicio.getRemitosByIdVehiculo(paramFake, dateFake).then(function(data) { | ||
| 353 | result = data.data; | ||
| 354 | }); | ||
| 355 | httpBackend.flush(); | ||
| 356 | |||
| 357 | //assert | ||
| 358 | expect(result).toEqual(responseFake); | ||
| 359 | }); | ||
| 360 | |||
| 361 | it('función desasociarRemitos llama ruta correcta', function() { | ||
| 362 | |||
| 363 | //arrange | ||
| 364 | var responseFake = 'responseFake'; | ||
| 365 | var paramFake = 'param fake'; | ||
| 366 | var paramFake2 = 'param fake 2'; | ||
| 367 | var paramFake3 = 'param fake 3'; | ||
| 368 | var result; | ||
| 369 | |||
| 370 | httpBackend.expectPOST('localhost/vehiculo/desasociar-remitos', | ||
| 371 | { | ||
| 372 | idsRemitos: paramFake, | ||
| 373 | idVehiculo: paramFake2, | ||
| 374 | vehiculoSinRemitos: paramFake3 | ||
| 375 | }).respond(responseFake); | ||
| 376 | |||
| 377 | //act | ||
| 378 | servicio.desasociarRemitos(paramFake, paramFake2, paramFake3).then(function(data) { | ||
| 379 | result = data.data; | ||
| 380 | }); | ||
| 381 | httpBackend.flush(); | ||
| 382 | |||
| 383 | //assert | ||
| 384 | expect(result).toEqual(responseFake); | ||
| 385 | }); | ||
| 386 | }); | ||
| 387 | }); | ||
| 388 |
src/js/app.js
| 1 | angular.module('focaCrearHojaRuta', []); | 1 | angular.module('focaCrearHojaRuta', ['ngRoute']); |
| 2 | 2 |
src/js/controller.js
| 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', | 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'focaCrearHojaRutaService', | 8 | 'focaCrearHojaRutaService', |
| 9 | 'focaModalService', | 9 | 'focaModalService', |
| 10 | 'focaBotoneraLateralService', | 10 | 'focaBotoneraLateralService', |
| 11 | 'focaLoginService', | 11 | 'focaLoginService', |
| 12 | function($scope, $uibModal, $location, $filter, $timeout, | 12 | function($scope, $uibModal, $location, $filter, $timeout, |
| 13 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, | 13 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, |
| 14 | focaLoginSrv) | 14 | focaLoginSrv) |
| 15 | { | 15 | { |
| 16 | config(); | 16 | config(); |
| 17 | 17 | ||
| 18 | function config() { | 18 | function config() { |
| 19 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); | 19 | $scope.botonera = focaCrearHojaRutaService.getBotonera(); |
| 20 | $scope.datepickerAbierto = false; | 20 | $scope.datepickerAbierto = false; |
| 21 | $scope.show = false; | 21 | $scope.show = false; |
| 22 | $scope.cargando = true; | 22 | $scope.cargando = true; |
| 23 | $scope.now = new Date(); | 23 | $scope.now = new Date(); |
| 24 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 24 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 25 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 25 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 26 | 26 | ||
| 27 | //SETEO BOTONERA LATERAL | 27 | //SETEO BOTONERA LATERAL |
| 28 | $timeout(function() { | 28 | $timeout(function() { |
| 29 | focaBotoneraLateralService.showSalir(false); | 29 | focaBotoneraLateralService.showSalir(false); |
| 30 | focaBotoneraLateralService.showPausar(true); | 30 | focaBotoneraLateralService.showPausar(true); |
| 31 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); | 31 | focaBotoneraLateralService.showGuardar(true, $scope.crearHojaRuta); |
| 32 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 32 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 33 | }); | 33 | }); |
| 34 | 34 | ||
| 35 | init(); | 35 | init(); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | function init() { | 38 | function init() { |
| 39 | $scope.$broadcast('cleanCabecera'); | 39 | $scope.$broadcast('cleanCabecera'); |
| 40 | 40 | ||
| 41 | $scope.hojaRuta = { | 41 | $scope.hojaRuta = { |
| 42 | fecha: new Date(), | 42 | fecha: new Date(), |
| 43 | litros: 0, | 43 | litros: 0, |
| 44 | chofer: {}, | 44 | chofer: {}, |
| 45 | vehiculo: { | 45 | vehiculo: { |
| 46 | capacidad: 0 | 46 | capacidad: 0 |
| 47 | }, | 47 | }, |
| 48 | transportista: {}, | 48 | transportista: {}, |
| 49 | tarifario: { | 49 | tarifario: { |
| 50 | costo: null | 50 | costo: null |
| 51 | } | 51 | } |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | $scope.remitosTabla = []; | 54 | $scope.remitosTabla = []; |
| 55 | $scope.idLista = undefined; | 55 | $scope.idLista = undefined; |
| 56 | 56 | ||
| 57 | focaCrearHojaRutaService.getNumeroHojaRuta().then( | 57 | focaCrearHojaRutaService.getNumeroHojaRuta().then( |
| 58 | function(res) { | 58 | function(res) { |
| 59 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); | 59 | $scope.puntoVenta = $filter('rellenarDigitos')(res.data.sucursal, 4); |
| 60 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); | 60 | $scope.comprobante = $filter('rellenarDigitos')(res.data.numeroHojaRuta, 8); |
| 61 | }, | 61 | }, |
| 62 | function(err) { | 62 | function(err) { |
| 63 | focaModalService.alert('La terminal no esta configurada correctamente'); | 63 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 64 | console.info(err); | 64 | console.info(err); |
| 65 | } | 65 | } |
| 66 | ); | 66 | ); |
| 67 | 67 | ||
| 68 | $scope.inicial = { | 68 | $scope.inicial = { |
| 69 | hojaRuta: angular.copy($scope.hojaRuta), | 69 | hojaRuta: angular.copy($scope.hojaRuta), |
| 70 | remitosTabla: angular.copy($scope.remitosTabla), | 70 | remitosTabla: angular.copy($scope.remitosTabla), |
| 71 | idLista: angular.copy($scope.idLista) | 71 | idLista: angular.copy($scope.idLista) |
| 72 | }; | 72 | }; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | $scope.crearHojaRuta = function() { | 75 | $scope.crearHojaRuta = function() { |
| 76 | if(!$scope.remitosTabla.length) { | 76 | if(!$scope.remitosTabla.length) { |
| 77 | focaModalService.alert('Ingrese Remitos'); | 77 | focaModalService.alert('Ingrese Remitos'); |
| 78 | return; | 78 | return; |
| 79 | } | 79 | } |
| 80 | if(!$scope.hojaRuta.chofer.id) { | 80 | if(!$scope.hojaRuta.chofer.id) { |
| 81 | focaModalService.alert('Ingrese Chofer'); | 81 | focaModalService.alert('Ingrese Chofer'); |
| 82 | return; | 82 | return; |
| 83 | } | 83 | } |
| 84 | if(!$scope.hojaRuta.vehiculo.id) { | 84 | if(!$scope.hojaRuta.vehiculo.id) { |
| 85 | focaModalService.alert('Ingrese Vehiculo'); | 85 | focaModalService.alert('Ingrese Vehiculo'); |
| 86 | return; | 86 | return; |
| 87 | } | 87 | } |
| 88 | if(!$scope.hojaRuta.transportista.COD) { | 88 | if(!$scope.hojaRuta.transportista.COD) { |
| 89 | focaModalService.alert('Ingrese Transportista'); | 89 | focaModalService.alert('Ingrese Transportista'); |
| 90 | return; | 90 | return; |
| 91 | } | 91 | } |
| 92 | if(!$scope.hojaRuta.tarifario.costo) { | 92 | if(!$scope.hojaRuta.tarifario.costo) { |
| 93 | focaModalService.alert('Ingrese Tarifario'); | 93 | focaModalService.alert('Ingrese Tarifario'); |
| 94 | return; | 94 | return; |
| 95 | } | 95 | } |
| 96 | if(!$scope.hojaRuta.datosExtra) { | 96 | if(!$scope.hojaRuta.datosExtra) { |
| 97 | focaModalService.alert('Ingrese Datos extra'); | 97 | focaModalService.alert('Ingrese Datos extra'); |
| 98 | return; | 98 | return; |
| 99 | } | 99 | } |
| 100 | var date = new Date(); | 100 | var date = new Date(); |
| 101 | var save = { | 101 | var save = { |
| 102 | hojaRuta: { | 102 | hojaRuta: { |
| 103 | id: 0, | 103 | id: 0, |
| 104 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) | 104 | fechaCreacion: new Date(date.getTime()).toISOString().slice(0, 19) |
| 105 | .replace('T', ' '), | 105 | .replace('T', ' '), |
| 106 | idTransportista: $scope.hojaRuta.transportista.COD, | 106 | idTransportista: $scope.hojaRuta.transportista.COD, |
| 107 | idChofer: $scope.hojaRuta.chofer.id, | 107 | idChofer: $scope.hojaRuta.chofer.id, |
| 108 | idVehiculo: $scope.hojaRuta.vehiculo.id, | 108 | idVehiculo: $scope.hojaRuta.vehiculo.id, |
| 109 | tarifaFlete: $scope.hojaRuta.tarifario.costo, | 109 | tarifaFlete: $scope.hojaRuta.tarifario.costo, |
| 110 | fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), | 110 | fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), |
| 111 | estado: 0 | 111 | estado: 0 |
| 112 | }, | 112 | }, |
| 113 | remitos: $scope.remitosTabla | 113 | remitos: $scope.remitosTabla |
| 114 | }; | 114 | }; |
| 115 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); | 115 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); |
| 116 | focaCrearHojaRutaService.crearHojaRuta(save).then( | 116 | focaCrearHojaRutaService.crearHojaRuta(save).then( |
| 117 | function(data) { | 117 | function(data) { |
| 118 | focaModalService.alert( | 118 | focaModalService.alert( |
| 119 | 'Hoja ruta creada Nº: ' + | 119 | 'Hoja ruta creada Nº: ' + |
| 120 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + | 120 | $filter('rellenarDigitos')(data.data.sucursal, 4) + '-' + |
| 121 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) | 121 | $filter('rellenarDigitos')(data.data.numeroHojaRuta, 8) |
| 122 | ); | 122 | ); |
| 123 | 123 | ||
| 124 | init(); | 124 | init(); |
| 125 | }, | 125 | }, |
| 126 | function(error) { | 126 | function(error) { |
| 127 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); | 127 | focaModalService.alert('Hubo un error al crear la hoja de ruta'); |
| 128 | console.info(error); | 128 | console.info(error); |
| 129 | } | 129 | } |
| 130 | ); | 130 | ); |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | $scope.seleccionarTransportista = function() { | 133 | $scope.seleccionarTransportista = function() { |
| 134 | if(eligioPreConfirmado()) return; | 134 | if(eligioPreConfirmado()) return; |
| 135 | var parametrosModal = { | 135 | var parametrosModal = { |
| 136 | titulo: 'Búsqueda de transportista', | 136 | titulo: 'Búsqueda de transportista', |
| 137 | query: '/transportista', | 137 | query: '/transportista', |
| 138 | columnas: [ | 138 | columnas: [ |
| 139 | { | 139 | { |
| 140 | nombre: 'Código', | 140 | nombre: 'Código', |
| 141 | propiedad: 'COD' | 141 | propiedad: 'COD' |
| 142 | }, | 142 | }, |
| 143 | { | 143 | { |
| 144 | nombre: 'Nombre', | 144 | nombre: 'Nombre', |
| 145 | propiedad: 'NOM' | 145 | propiedad: 'NOM' |
| 146 | }, | 146 | }, |
| 147 | { | 147 | { |
| 148 | nombre: 'CUIT', | 148 | nombre: 'CUIT', |
| 149 | propiedad: 'CUIT' | 149 | propiedad: 'CUIT' |
| 150 | } | 150 | } |
| 151 | ] | 151 | ] |
| 152 | }; | 152 | }; |
| 153 | focaModalService.modal(parametrosModal).then( | 153 | focaModalService.modal(parametrosModal).then( |
| 154 | function(proveedor) { | 154 | function(proveedor) { |
| 155 | $scope.hojaRuta.transportista = proveedor; | 155 | $scope.hojaRuta.transportista = proveedor; |
| 156 | $scope.$broadcast('addCabecera', { | 156 | $scope.$broadcast('addCabecera', { |
| 157 | label: 'Transportista:', | 157 | label: 'Transportista:', |
| 158 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 158 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 159 | proveedor.NOM | 159 | proveedor.NOM |
| 160 | }); | 160 | }); |
| 161 | }, function() { | 161 | }, function() { |
| 162 | 162 | ||
| 163 | } | 163 | } |
| 164 | ); | 164 | ); |
| 165 | }; | 165 | }; |
| 166 | 166 | ||
| 167 | $scope.seleccionarChofer = function() { | 167 | $scope.seleccionarChofer = function() { |
| 168 | var parametrosModal = { | 168 | var parametrosModal = { |
| 169 | titulo: 'Búsqueda de Chofer', | 169 | titulo: 'Búsqueda de Chofer', |
| 170 | query: '/chofer', | 170 | query: '/chofer', |
| 171 | columnas: [ | 171 | columnas: [ |
| 172 | { | 172 | { |
| 173 | propiedad: 'id', | 173 | propiedad: 'id', |
| 174 | nombre: 'Código', | 174 | nombre: 'Código', |
| 175 | filtro: { | 175 | filtro: { |
| 176 | nombre: 'rellenarDigitos', | 176 | nombre: 'rellenarDigitos', |
| 177 | parametro: 3 | 177 | parametro: 3 |
| 178 | } | 178 | } |
| 179 | }, | 179 | }, |
| 180 | { | 180 | { |
| 181 | propiedad: 'nombre', | 181 | propiedad: 'nombre', |
| 182 | nombre: 'Nombre' | 182 | nombre: 'Nombre' |
| 183 | }, | 183 | }, |
| 184 | { | 184 | { |
| 185 | propiedad: 'dni', | 185 | propiedad: 'dni', |
| 186 | nombre: 'DNI' | 186 | nombre: 'DNI' |
| 187 | }, | 187 | }, |
| 188 | { | 188 | { |
| 189 | propiedad: 'telefono', | 189 | propiedad: 'telefono', |
| 190 | nombre: 'Teléfono' | 190 | nombre: 'Teléfono' |
| 191 | } | 191 | } |
| 192 | ] | 192 | ] |
| 193 | }; | 193 | }; |
| 194 | focaModalService.modal(parametrosModal).then( | 194 | focaModalService.modal(parametrosModal).then( |
| 195 | function(chofer) { | 195 | function(chofer) { |
| 196 | $scope.hojaRuta.chofer = chofer; | 196 | $scope.hojaRuta.chofer = chofer; |
| 197 | $scope.$broadcast('addCabecera', { | 197 | $scope.$broadcast('addCabecera', { |
| 198 | label: 'Chofer:', | 198 | label: 'Chofer:', |
| 199 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre | 199 | valor: $filter('rellenarDigitos')(chofer.id, 3) + ' - ' +chofer.nombre |
| 200 | }); | 200 | }); |
| 201 | }, function() { | 201 | }, function() { |
| 202 | // funcion ejecutada cuando se cancela el modal | 202 | // funcion ejecutada cuando se cancela el modal |
| 203 | } | 203 | } |
| 204 | ); | 204 | ); |
| 205 | }; | 205 | }; |
| 206 | 206 | ||
| 207 | $scope.seleccionarVehiculo = function() { | 207 | $scope.seleccionarVehiculo = function() { |
| 208 | if(!eligioFecha() || eligioPreConfirmado()) return; | 208 | if(!eligioFecha() || eligioPreConfirmado()) return; |
| 209 | modalVehiculos(); | 209 | modalVehiculos(); |
| 210 | }; | 210 | }; |
| 211 | 211 | ||
| 212 | $scope.seleccionarTarifario = function() { | 212 | $scope.seleccionarTarifario = function() { |
| 213 | var modalInstance = $uibModal.open( | 213 | var modalInstance = $uibModal.open( |
| 214 | { | 214 | { |
| 215 | ariaLabelledBy: 'Busqueda de Tarifario', | 215 | ariaLabelledBy: 'Busqueda de Tarifario', |
| 216 | templateUrl: 'modal-tarifa-flete.html', | 216 | templateUrl: 'modal-tarifa-flete.html', |
| 217 | controller: 'focaModalTarifaFleteController', | 217 | controller: 'focaModalTarifaFleteController', |
| 218 | size: 'lg', | 218 | size: 'lg', |
| 219 | resolve: { | 219 | resolve: { |
| 220 | parametrosTarifaFlete: function() { | 220 | parametrosTarifaFlete: function() { |
| 221 | return $scope.hojaRuta.tarifario.costo; | 221 | return $scope.hojaRuta.tarifario.costo; |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | } | 224 | } |
| 225 | ); | 225 | ); |
| 226 | 226 | ||
| 227 | modalInstance.result.then( | 227 | modalInstance.result.then( |
| 228 | function(tarifario) { | 228 | function(tarifario) { |
| 229 | $scope.hojaRuta.tarifario = tarifario; | 229 | $scope.hojaRuta.tarifario = tarifario; |
| 230 | $scope.$broadcast('addCabecera', { | 230 | $scope.$broadcast('addCabecera', { |
| 231 | label: 'Tarifario:', | 231 | label: 'Tarifario:', |
| 232 | valor: tarifario.costo | 232 | valor: tarifario.costo |
| 233 | }); | 233 | }); |
| 234 | }, function() { | 234 | }, function() { |
| 235 | // funcion ejecutada cuando se cancela el modal | 235 | // funcion ejecutada cuando se cancela el modal |
| 236 | } | 236 | } |
| 237 | ); | 237 | ); |
| 238 | }; | 238 | }; |
| 239 | 239 | ||
| 240 | $scope.seleccionarRemitos = function() { | 240 | $scope.seleccionarRemitos = function() { |
| 241 | if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; | 241 | if(eligioPreConfirmado() || !eligioFecha() || !eligioVehiculo()) return; |
| 242 | var modalInstance = $uibModal.open( | 242 | var modalInstance = $uibModal.open( |
| 243 | { | 243 | { |
| 244 | ariaLabelledBy: 'Busqueda de Remito', | 244 | ariaLabelledBy: 'Busqueda de Remito', |
| 245 | templateUrl: 'foca-modal-remito.html', | 245 | templateUrl: 'foca-modal-remito.html', |
| 246 | controller: 'focaModalRemitoController', | 246 | controller: 'focaModalRemitoController', |
| 247 | size: 'lg', | 247 | size: 'lg', |
| 248 | resolve: {usadoPor: function() {return 'hojaRuta';}} | 248 | resolve: {usadoPor: function() {return 'hojaRuta';}} |
| 249 | } | 249 | } |
| 250 | ); | 250 | ); |
| 251 | modalInstance.result.then( | 251 | modalInstance.result.then( |
| 252 | function(remito) { | 252 | function(remito) { |
| 253 | // TODO: borrar cuando no se use definitivamente | 253 | // TODO: borrar cuando no se use definitivamente |
| 254 | // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { | 254 | // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { |
| 255 | // if ($scope.remitosTabla[i].id === remito.id) { | 255 | // if ($scope.remitosTabla[i].id === remito.id) { |
| 256 | // focaModalService.alert('Remito ya incluido'); | 256 | // focaModalService.alert('Remito ya incluido'); |
| 257 | // return; | 257 | // return; |
| 258 | // } | 258 | // } |
| 259 | // } | 259 | // } |
| 260 | 260 | ||
| 261 | // var litros = 0; | 261 | // var litros = 0; |
| 262 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | 262 | // for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { |
| 263 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | 263 | // litros = litros + parseFloat(remito.articulosRemito[j].cantidad); |
| 264 | // } | 264 | // } |
| 265 | 265 | ||
| 266 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { | 266 | // if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
| 267 | // focaModalService.alert( | 267 | // focaModalService.alert( |
| 268 | // 'Debe ingresar toda la información para el transporte' | 268 | // 'Debe ingresar toda la información para el transporte' |
| 269 | // ); | 269 | // ); |
| 270 | // return; | 270 | // return; |
| 271 | // } | 271 | // } |
| 272 | 272 | ||
| 273 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) | 273 | //if($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) |
| 274 | // { | 274 | // { |
| 275 | // var litrostotales = litros; | 275 | // var litrostotales = litros; |
| 276 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; | 276 | // litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; |
| 277 | // focaModalService.alert( | 277 | // focaModalService.alert( |
| 278 | // 'La carga excede la capacidad disponible del vehiculo. ' + | 278 | // 'La carga excede la capacidad disponible del vehiculo. ' + |
| 279 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' | 279 | // 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' |
| 280 | // ); | 280 | // ); |
| 281 | // } | 281 | // } |
| 282 | 282 | ||
| 283 | // remito.litros = litros; | 283 | // remito.litros = litros; |
| 284 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; | 284 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
| 285 | $scope.cargarCisterna(remito.id).then(function() { | 285 | $scope.cargarCisterna(remito.id).then(function() { |
| 286 | $scope.remitosTabla.push(remito); | 286 | $scope.remitosTabla.push(remito); |
| 287 | $scope.seleccionarRemitos(); | 287 | $scope.seleccionarRemitos(); |
| 288 | }, function() { | 288 | }, function() { |
| 289 | $scope.seleccionarRemitos(); | 289 | $scope.seleccionarRemitos(); |
| 290 | }); | 290 | }); |
| 291 | }, function() { | 291 | }, function() { |
| 292 | // funcion ejecutada cuando se cancela el modal | 292 | // funcion ejecutada cuando se cancela el modal |
| 293 | } | 293 | } |
| 294 | ); | 294 | ); |
| 295 | }; | 295 | }; |
| 296 | 296 | ||
| 297 | $scope.seleccionarVehiculosPrecargados = function() { | 297 | $scope.seleccionarVehiculosPrecargados = function() { |
| 298 | if(!eligioFecha()) return; | 298 | if(!eligioFecha()) return; |
| 299 | modalVehiculos(true); | 299 | modalVehiculos(true); |
| 300 | }; | 300 | }; |
| 301 | 301 | ||
| 302 | $scope.cargarCisterna = function(idRemito) { | 302 | $scope.cargarCisterna = function(idRemito) { |
| 303 | if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; | 303 | if(!eligioFecha() || !$scope.hojaRuta.vehiculo.id) return; |
| 304 | var modalInstance = $uibModal.open( | 304 | var modalInstance = $uibModal.open( |
| 305 | { | 305 | { |
| 306 | ariaLabelledBy: 'Busqueda de Vehiculo', | 306 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 307 | templateUrl: 'foca-detalle-vehiculo.html', | 307 | templateUrl: 'foca-detalle-vehiculo.html', |
| 308 | controller: 'focaDetalleVehiculo', | 308 | controller: 'focaDetalleVehiculo', |
| 309 | size: 'lg', | 309 | size: 'lg', |
| 310 | resolve: { | 310 | resolve: { |
| 311 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, | 311 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, |
| 312 | idRemito: function() {return idRemito;}, | 312 | idRemito: function() {return idRemito;}, |
| 313 | fechaReparto: function() {return $scope.fechaReparto;} | 313 | fechaReparto: function() {return $scope.fechaReparto;} |
| 314 | } | 314 | } |
| 315 | } | 315 | } |
| 316 | ); | 316 | ); |
| 317 | return modalInstance.result; | 317 | return modalInstance.result; |
| 318 | }; | 318 | }; |
| 319 | 319 | ||
| 320 | $scope.seleccionarFechaEntrega = function() { | 320 | $scope.seleccionarFechaEntrega = function() { |
| 321 | if(!$scope.fechaReparto) { | 321 | if(!$scope.fechaReparto) { |
| 322 | elegirFecha(); | 322 | elegirFecha(); |
| 323 | return; | 323 | return; |
| 324 | } | 324 | } |
| 325 | focaModalService | 325 | focaModalService |
| 326 | .confirm('Si cambia la fecha se perderán los datos actuales') | 326 | .confirm('Si cambia la fecha se perderán los datos actuales') |
| 327 | .then(function() { | 327 | .then(function() { |
| 328 | elegirFecha(); | 328 | elegirFecha(); |
| 329 | }, function() { | 329 | }, function() { |
| 330 | return ; | 330 | return ; |
| 331 | }); | 331 | }); |
| 332 | }; | 332 | }; |
| 333 | 333 | ||
| 334 | $scope.seleccionarDatosExtra = function() { | 334 | $scope.seleccionarDatosExtra = function() { |
| 335 | var datosHojaRuta = $scope.hojaRuta.datosExtra; | 335 | var datosHojaRuta = $scope.hojaRuta.datosExtra; |
| 336 | var modalInstance = $uibModal.open( | 336 | var modalInstance = $uibModal.open( |
| 337 | { | 337 | { |
| 338 | templateUrl: 'foca-modal-datos-hoja-ruta.html', | 338 | templateUrl: 'foca-modal-datos-hoja-ruta.html', |
| 339 | controller: 'focaModalDatosHojaRutaCtrl', | 339 | controller: 'focaModalDatosHojaRutaCtrl', |
| 340 | size: 'lg', | 340 | size: 'lg', |
| 341 | resolve: { | 341 | resolve: { |
| 342 | parametrosDatos: function() { | 342 | parametrosDatos: function() { |
| 343 | return { | 343 | return { |
| 344 | datosHojaRuta: datosHojaRuta | 344 | datosHojaRuta: datosHojaRuta |
| 345 | }; | 345 | }; |
| 346 | } | 346 | } |
| 347 | } | 347 | } |
| 348 | } | 348 | } |
| 349 | ); | 349 | ); |
| 350 | return modalInstance.result.then(function(datosExtra) { | 350 | return modalInstance.result.then(function(datosExtra) { |
| 351 | $scope.hojaRuta.datosExtra = datosExtra; | 351 | $scope.hojaRuta.datosExtra = datosExtra; |
| 352 | }, function() { | 352 | }, function() { |
| 353 | //se ejecuta cuando se cancela el modal | 353 | //se ejecuta cuando se cancela el modal |
| 354 | }); | 354 | }); |
| 355 | }; | 355 | }; |
| 356 | 356 | ||
| 357 | $scope.desasociarRemito = function(key, idRemito) { | 357 | $scope.desasociarRemito = function(key, idRemito) { |
| 358 | var idsRemito = [idRemito]; | 358 | var idsRemito = [idRemito]; |
| 359 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + | 359 | focaModalService.confirm('¿Está seguro que desea desasociar este remito del' + |
| 360 | ' vehículo?').then(function() { | 360 | ' vehículo?').then(function() { |
| 361 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, | 361 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, |
| 362 | $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( | 362 | $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( |
| 363 | function() { | 363 | function() { |
| 364 | $scope.remitosTabla.splice(key, 1); | 364 | $scope.remitosTabla.splice(key, 1); |
| 365 | focaModalService.alert('Remito desasociado con éxito'); | 365 | focaModalService.alert('Remito desasociado con éxito'); |
| 366 | } | 366 | } |
| 367 | ); | 367 | ); |
| 368 | }); | 368 | }); |
| 369 | }; | 369 | }; |
| 370 | 370 | ||
| 371 | function elegirFecha() { | 371 | function elegirFecha() { |
| 372 | focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { | 372 | focaModalService.modalFecha('Fecha de entrega').then(function(fecha) { |
| 373 | $scope.$broadcast('addCabecera', { | 373 | $scope.$broadcast('addCabecera', { |
| 374 | label: 'Fecha de entrega:', | 374 | label: 'Fecha de entrega:', |
| 375 | valor: fecha.toLocaleDateString() | 375 | valor: fecha.toLocaleDateString() |
| 376 | }); | 376 | }); |
| 377 | $scope.fechaReparto = fecha; | 377 | $scope.fechaReparto = fecha; |
| 378 | }); | 378 | }); |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | function eligioPreConfirmado() { | 381 | function eligioPreConfirmado() { |
| 382 | if($scope.eligioPreConfirmado) { | 382 | if($scope.eligioPreConfirmado) { |
| 383 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); | 383 | focaModalService.alert('No puede elegir si eligió un vehiculo pre cargado'); |
| 384 | return true; | 384 | return true; |
| 385 | } | 385 | } |
| 386 | return false; | 386 | return false; |
| 387 | } | 387 | } |
| 388 | 388 | ||
| 389 | function eligioFecha() { | 389 | function eligioFecha() { |
| 390 | if(!$scope.fechaReparto) { | 390 | if(!$scope.fechaReparto) { |
| 391 | focaModalService.alert('Primero seleccione fecha de reparto'); | 391 | focaModalService.alert('Primero seleccione fecha de reparto'); |
| 392 | return false; | 392 | return false; |
| 393 | } | 393 | } |
| 394 | return true; | 394 | return true; |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | function eligioVehiculo() { | 397 | function eligioVehiculo() { |
| 398 | if(!$scope.hojaRuta.vehiculo.id) { | 398 | if(!$scope.hojaRuta.vehiculo.id) { |
| 399 | focaModalService.alert('Primero seleccione vehiculo'); | 399 | focaModalService.alert('Primero seleccione vehiculo'); |
| 400 | return false; | 400 | return false; |
| 401 | } | 401 | } |
| 402 | return true; | 402 | return true; |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | function modalVehiculos(preCargados) { | 405 | function modalVehiculos(preCargados) { |
| 406 | var parametrosModal = {}; | 406 | var parametrosModal = {}; |
| 407 | if(preCargados) { | 407 | if(preCargados) { |
| 408 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + | 408 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + |
| 409 | $scope.fechaReparto.toISOString().substring(0, 10); | 409 | $scope.fechaReparto.toISOString().substring(0, 10); |
| 410 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; | 410 | parametrosModal.titulo = 'Búsqueda de vehiculos pre confirmados'; |
| 411 | }else { | 411 | }else { |
| 412 | parametrosModal.query = '/vehiculo'; | 412 | parametrosModal.query = '/vehiculo'; |
| 413 | parametrosModal.titulo = 'Búsqueda de vehículos'; | 413 | parametrosModal.titulo = 'Búsqueda de vehículos'; |
| 414 | } | 414 | } |
| 415 | parametrosModal.columnas = [ | 415 | parametrosModal.columnas = [ |
| 416 | { | 416 | { |
| 417 | propiedad: 'codigo', | 417 | propiedad: 'codigo', |
| 418 | nombre: 'Código' | 418 | nombre: 'Código' |
| 419 | }, | 419 | }, |
| 420 | { | 420 | { |
| 421 | propiedad: 'tractor', | 421 | propiedad: 'tractor', |
| 422 | nombre: 'tractor' | 422 | nombre: 'tractor' |
| 423 | }, | 423 | }, |
| 424 | { | 424 | { |
| 425 | propiedad: 'semi', | 425 | propiedad: 'semi', |
| 426 | nombre: 'Semi' | 426 | nombre: 'Semi' |
| 427 | } | 427 | } |
| 428 | ]; | 428 | ]; |
| 429 | focaModalService.modal(parametrosModal).then(function(vehiculo) { | 429 | focaModalService.modal(parametrosModal).then(function(vehiculo) { |
| 430 | if(!preCargados && vehiculoEnUso(vehiculo)) return; | 430 | if(!preCargados && vehiculoEnUso(vehiculo)) return; |
| 431 | $scope.hojaRuta.vehiculo = vehiculo; | 431 | $scope.hojaRuta.vehiculo = vehiculo; |
| 432 | $scope.hojaRuta.transportista = vehiculo.transportista; | 432 | $scope.hojaRuta.transportista = vehiculo.transportista; |
| 433 | if(preCargados) { | 433 | if(preCargados) { |
| 434 | $scope.eligioPreConfirmado = true; | 434 | $scope.eligioPreConfirmado = true; |
| 435 | $scope.hojaRuta.vehiculo = vehiculo; | 435 | $scope.hojaRuta.vehiculo = vehiculo; |
| 436 | $scope.$broadcast('addCabecera', { | 436 | $scope.$broadcast('addCabecera', { |
| 437 | label: 'Transportista:', | 437 | label: 'Transportista:', |
| 438 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + | 438 | valor: $filter('rellenarDigitos')(vehiculo.transportista.COD, 5) + |
| 439 | ' - ' + vehiculo.transportista.NOM | 439 | ' - ' + vehiculo.transportista.NOM |
| 440 | }); | 440 | }); |
| 441 | focaCrearHojaRutaService | 441 | focaCrearHojaRutaService |
| 442 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) | 442 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) |
| 443 | .then(function(res) { | 443 | .then(function(res) { |
| 444 | $scope.remitosTabla = res.data; | 444 | $scope.remitosTabla = res.data; |
| 445 | }); | 445 | }); |
| 446 | }else { | 446 | }else { |
| 447 | focaCrearHojaRutaService | 447 | focaCrearHojaRutaService |
| 448 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) | 448 | .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) |
| 449 | .then(function(res) { | 449 | .then(function(res) { |
| 450 | $scope.remitosTabla = res.data; | 450 | $scope.remitosTabla = res.data; |
| 451 | }); | 451 | }); |
| 452 | } | 452 | } |
| 453 | $scope.$broadcast('addCabecera', { | 453 | $scope.$broadcast('addCabecera', { |
| 454 | label: 'Tractor:', | 454 | label: 'Tractor:', |
| 455 | valor: vehiculo.tractor | 455 | valor: vehiculo.tractor |
| 456 | }); | 456 | }); |
| 457 | $scope.$broadcast('addCabecera', { | 457 | $scope.$broadcast('addCabecera', { |
| 458 | label: 'Semi:', | 458 | label: 'Semi:', |
| 459 | valor: vehiculo.semi | 459 | valor: vehiculo.semi |
| 460 | }); | 460 | }); |
| 461 | $scope.$broadcast('addCabecera', { | 461 | $scope.$broadcast('addCabecera', { |
| 462 | label: 'Capacidad:', | 462 | label: 'Capacidad:', |
| 463 | valor: vehiculo.capacidad | 463 | valor: vehiculo.capacidad |
| 464 | }); | 464 | }); |
| 465 | }); | 465 | }); |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | function vehiculoEnUso(vehiculo) { | 468 | function vehiculoEnUso(vehiculo) { |
| 469 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; | 469 | var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; |
| 470 | for(var i = 0; i < vehiculo.cisternas.length; i++) { | 470 | for(var i = 0; i < vehiculo.cisternas.length; i++) { |
| 471 | for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { | 471 | for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
| 472 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; | 472 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
| 473 | if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto | 473 | if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto |
| 474 | .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && | 474 | .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && |
| 475 | cisternaCarga.idUsuarioProceso !== idUsuario) | 475 | cisternaCarga.idUsuarioProceso !== idUsuario) |
| 476 | { | 476 | { |
| 477 | focaModalService.alert('El vehículo está siendo usado por otro' + | 477 | focaModalService.alert('El vehículo está siendo usado por otro' + |
| 478 | ' usuario'); | 478 | ' usuario'); |
| 479 | return true; | 479 | return true; |
| 480 | } | 480 | } |
| 481 | } | 481 | } |
| 482 | } | 482 | } |
| 483 | return false; | 483 | return false; |
| 484 | } | 484 | } |
| 485 | 485 | ||
| 486 | function salir() { | 486 | function salir() { |
| 487 | var confirmacion = false; | 487 | var confirmacion = false; |
| 488 | 488 | ||
| 489 | angular.forEach($scope.inicial, function(valor, key) { | 489 | angular.forEach($scope.inicial, function(valor, key) { |
| 490 | if (!angular.equals($scope[key], $scope.inicial[key])) { | 490 | if (!angular.equals($scope[key], $scope.inicial[key])) { |
| 491 | confirmacion = true; | 491 | confirmacion = true; |
| 492 | } | 492 | } |
| 493 | }); | 493 | }); |
| 494 | 494 | ||
| 495 | if (confirmacion) { | 495 | if (confirmacion) { |
| 496 | focaModalService.confirm( | 496 | focaModalService.confirm( |
| 497 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 497 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 498 | ).then(function(data) { | 498 | ).then(function(data) { |
| 499 | if (data) { | 499 | if (data) { |
| 500 | $location.path('/'); | 500 | $location.path('/'); |
| 501 | } | 501 | } |
| 502 | }); | 502 | }); |
| 503 | } else { | 503 | } else { |
| 504 | $location.path('/'); | 504 | $location.path('/'); |
| 505 | } | 505 | } |
| 506 | } | 506 | } |
| 507 | } | 507 | } |
| 508 | ]); | 508 | ]); |
| 509 | 509 |
src/js/controllerDatosHojaRuta.js
| 1 | angular.module('focaCrearHojaRuta') | 1 | angular.module('focaCrearHojaRuta') |
| 2 | .controller('focaModalDatosHojaRutaCtrl', | 2 | .controller('focaModalDatosHojaRutaCtrl', |
| 3 | [ | 3 | [ |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaModalService', | 7 | 'focaModalService', |
| 8 | 'parametrosDatos', | 8 | 'parametrosDatos', |
| 9 | function($filter, $scope, $uibModalInstance, focaModalService, parametrosDatos) { | 9 | function($filter, $scope, $uibModalInstance, focaModalService, parametrosDatos) { |
| 10 | $scope.datosHojaRuta = parametrosDatos.datosHojaRuta; | 10 | $scope.datosHojaRuta = parametrosDatos.datosHojaRuta; |
| 11 | $scope.focused = 0; | 11 | $scope.focused = 0; |
| 12 | 12 | ||
| 13 | $scope.aceptar = function(key) { | 13 | $scope.aceptar = function(key) { |
| 14 | if(key === 13) { | 14 | if(key === 13) { |
| 15 | if(!$scope.formDatosHojaRuta.$valid) { | 15 | if(!$scope.formDatosHojaRuta.$valid) { |
| 16 | focaModalService.alert('Formulario inválido'); | 16 | focaModalService.alert('Formulario inválido'); |
| 17 | return; | 17 | return; |
| 18 | } | 18 | } |
| 19 | $uibModalInstance.close($scope.datosHojaRuta); | 19 | $uibModalInstance.close($scope.datosHojaRuta); |
| 20 | } | 20 | } |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | $scope.next = function(key) { | 23 | $scope.next = function(key) { |
| 24 | if(key === 13) $scope.focused++; | 24 | if(key === 13) $scope.focused++; |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | $scope.cancel = function() { | 27 | $scope.cancel = function() { |
| 28 | $uibModalInstance.dismiss('cancel'); | 28 | $uibModalInstance.dismiss('cancel'); |
| 29 | }; | 29 | }; |
| 30 | } | 30 | } |
| 31 | ] | 31 | ] |
| 32 | ); | 32 | ); |
| 33 | 33 |
test.html
| File was created | 1 | <html> | |
| 2 | <head> | ||
| 3 | <link rel="stylesheet" type="text/css" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> | ||
| 4 | <meta charset="UTF-8" /> | ||
| 5 | </head> | ||
| 6 | <body> | ||
| 7 | <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> | ||
| 8 | <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> | ||
| 9 | <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script> | ||
| 10 | <script type="text/javascript" src="node_modules/angular/angular.min.js"></script> | ||
| 11 | <script type="text/javascript" src="node_modules/angular-route/angular-route.min.js"></script> | ||
| 12 | <script type="text/javascript" src="node_modules/angular-mocks/angular-mocks.js"></script> | ||
| 13 | <script type="text/javascript" src="src/js/app.js"></script> | ||
| 14 | <script type="text/javascript" src="src/js/controller.js"></script> | ||
| 15 | <script type="text/javascript" src="src/js/controllerDatosHojaRuta.js"></script> | ||
| 16 | <script type="text/javascript" src="src/js/service.js"></script> | ||
| 17 | <script type="text/javascript" src="src/js/route.js"></script> | ||
| 18 | <script type="text/javascript" src="spec/controllerSpec.js"></script> | ||
| 19 | <script type="text/javascript" src="spec/serviceSpec.js"></script> | ||
| 20 | <script type="text/javascript" src="spec/routeSpec.js"></script> | ||
| 21 | </body> | ||
| 22 | </html> | ||
| 23 |