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