Commit af8cfbe551086619beffbf5d632b2869f02966f5

Authored by Jose Pinto
1 parent 9b31d344c5
Exists in master

boton pausar funcionando, arreglo error gulp

1 /node_modules 1 /node_modules
2 /dist 2 /dist
3 package-lock\.json 3 package-lock\.json
4 /src/etc/develop.js 4 /src/etc/develop.js
5 5
6 tmp/ 6 tmp/
7 debug.log
7 8
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 15
15 var paths = { 16 var paths = {
16 srcJS: 'src/js/*.js', 17 srcJS: 'src/js/*.js',
17 srcViews: 'src/views/*.html', 18 srcViews: 'src/views/*.html',
18 specs: 'spec/*.js', 19 specs: 'spec/*.js',
19 tmp: 'tmp', 20 tmp: 'tmp',
20 dist: 'dist/' 21 dist: 'dist/'
21 }; 22 };
22 23
23 gulp.task('templates', ['clean'], function() { 24 gulp.task('uglify', gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app'));
25
26 gulp.task('templates', function() {
24 return pump( 27 return pump(
25 [ 28 [
26 gulp.src(paths.srcViews), 29 gulp.src(paths.srcViews),
27 htmlmin(), 30 htmlmin(),
28 templateCache('views.js', { 31 templateCache('views.js', {
29 module: 'focaCrearNotaPedido', 32 module: 'focaCrearNotaPedido',
30 root: '' 33 root: ''
31 }), 34 }),
32 gulp.dest(paths.tmp) 35 gulp.dest(paths.tmp)
33 ] 36 ]
34 ); 37 );
35 }); 38 });
36 39
37 gulp.task('uglify', ['templates', 'uglify-spec'], function() { 40 gulp.task('uglify-app', function() {
38 return pump( 41 return pump(
39 [ 42 [
40 gulp.src([ 43 gulp.src([
41 paths.srcJS, 44 paths.srcJS,
42 'tmp/views.js' 45 'tmp/views.js'
43 ]), 46 ]),
44 concat('foca-crear-nota-pedido.js'), 47 concat('foca-crear-nota-pedido.js'),
45 replace('src/views/', ''), 48 replace('src/views/', ''),
46 gulp.dest(paths.tmp), 49 gulp.dest(paths.tmp),
47 rename('foca-crear-nota-pedido.min.js'), 50 rename('foca-crear-nota-pedido.min.js'),
48 uglify(), 51 uglify(),
49 gulp.dest(paths.dist) 52 gulp.dest(paths.dist)
50 ] 53 ]
51 ); 54 );
52 }); 55 });
53 56
54 gulp.task('uglify-spec', function() { 57 gulp.task('uglify-spec', function() {
55 return pump([ 58 return pump([
56 gulp.src(paths.specs), 59 gulp.src(paths.specs),
57 concat('foca-crear-nota-pedido.spec.js'), 60 concat('foca-crear-nota-pedido.spec.js'),
58 replace("src/views/", ''), 61 replace("src/views/", ''),
59 header("describe('Módulo foca-crear-nota-pedido', function() { \n"), 62 header("describe('Módulo foca-crear-nota-pedido', function() { \n"),
60 footer("});"), 63 footer("});"),
61 gulp.dest(paths.dist) 64 gulp.dest(paths.dist)
62 ]); 65 ]);
63 }); 66 });
64 67
65 gulp.task('clean', function() { 68 gulp.task('clean', function() {
66 return gulp.src(['tmp', 'dist'], {read: false}) 69 return gulp.src(['tmp', 'dist'], {read: false})
67 .pipe(clean()); 70 .pipe(clean());
68 }); 71 });
69 72
70 gulp.task('pre-commit', function() { 73 gulp.task('pre-commit', function() {
71 return pump( 74 return pump(
72 [ 75 [
73 gulp.src([paths.srcJS, paths.specs]), 76 gulp.src([paths.srcJS, paths.specs]),
74 jshint('.jshintrc'), 77 jshint('.jshintrc'),
75 jshint.reporter('default'), 78 jshint.reporter('default'),
76 jshint.reporter('fail') 79 jshint.reporter('fail')
77 ] 80 ]
78 ); 81 );
79 82
80 gulp.start('uglify'); 83 gulp.start('uglify');
81 }); 84 });
82 85
83 gulp.task('webserver', function() { 86 gulp.task('webserver', function() {
84 pump [ 87 pump [
85 connect.server({port: 3300, host: '0.0.0.0'}) 88 connect.server({port: 3300, host: '0.0.0.0'})
86 ] 89 ]
87 }); 90 });
88 91
89 gulp.task('clean-post-install', function() { 92 gulp.task('clean-post-install', function() {
90 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 93 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
91 'index.html', 'test.html', 'spec'], {read: false}) 94 'index.html', 'test.html', 'spec'], {read: false})
92 .pipe(clean()); 95 .pipe(clean());
93 }); 96 });
94 97
95 gulp.task('default', ['webserver']); 98 gulp.task('default', ['webserver']);
96 99
97 gulp.task('watch', function() { 100 gulp.task('watch', function() {
98 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 101 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
99 }); 102 });
100 103
101 gulp.task('copy', ['uglify'], function() { 104 gulp.task('copy', ['uglify'], function() {
102 return gulp.src('dist/*.js') 105 return gulp.src('dist/*.js')
103 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/')); 106 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/'));
104 }); 107 });
105 108
106 gulp.task('watchAndCopy', function() { 109 gulp.task('watchAndCopy', function() {
107 return gulp.watch([paths.srcJS], ['copy']); 110 return gulp.watch([paths.srcJS], ['copy']);
108 }); 111 });
109 112
1 { 1 {
2 "name": "foca-crear-nota-pedido", 2 "name": "foca-crear-nota-pedido",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "Listado y ABM nota de pedidos", 4 "description": "Listado y ABM nota de pedidos",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {
7 "test": "test.html", 7 "test": "test.html",
8 "compile": "gulp uglify", 8 "compile": "gulp uglify",
9 "gulp-pre-commit": "gulp pre-commit", 9 "gulp-pre-commit": "gulp pre-commit",
10 "postinstall": "npm run compile && gulp clean-post-install", 10 "postinstall": "npm run compile && gulp clean-post-install",
11 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-vendedores.git git+http://git.focasoftware.com/npm/foca-modal-proveedor.git git+http://git.focasoftware.com/npm/foca-modal-busqueda-productos.git git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git git+http://git.focasoftware.com/npm/foca-modal-precio-condiciones.git git+http://git.focasoftware.com/npm/foca-modal-flete.git git+http://git.focasoftware.com/npm/foca-modal.git git+http://git.focasoftware.com/npm/foca-modal-domicilio.git git+http://git.focasoftware.com/npm/foca-seguimiento.git git+http://git.focasoftware.com/npm/foca-modal-moneda.git git+http://git.focasoftware.com/npm/foca-modal-cotizacion.git" 11 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-directivas.git git+http://git.focasoftware.com/npm/foca-modal-vendedores.git git+http://git.focasoftware.com/npm/foca-modal-proveedor.git git+http://git.focasoftware.com/npm/foca-modal-busqueda-productos.git git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git git+http://git.focasoftware.com/npm/foca-modal-precio-condiciones.git git+http://git.focasoftware.com/npm/foca-modal-flete.git git+http://git.focasoftware.com/npm/foca-modal.git git+http://git.focasoftware.com/npm/foca-modal-domicilio.git git+http://git.focasoftware.com/npm/foca-seguimiento.git git+http://git.focasoftware.com/npm/foca-modal-moneda.git git+http://git.focasoftware.com/npm/foca-modal-cotizacion.git"
12 }, 12 },
13 "pre-commit": [ 13 "pre-commit": [
14 "gulp-pre-commit" 14 "gulp-pre-commit"
15 ], 15 ],
16 "repository": { 16 "repository": {
17 "type": "git", 17 "type": "git",
18 "url": "https://debo.suite.repo/modulos-npm/foca-crear-nota-pedido.git" 18 "url": "https://debo.suite.repo/modulos-npm/foca-crear-nota-pedido.git"
19 }, 19 },
20 "author": "Foca Software", 20 "author": "Foca Software",
21 "license": "ISC", 21 "license": "ISC",
22 "peerDependencies": { 22 "peerDependencies": {
23 "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", 23 "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git",
24 "foca-busqueda-cliente": "git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git", 24 "foca-busqueda-cliente": "git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git",
25 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", 25 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git",
26 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", 26 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git",
27 "foca-modal-busqueda-productos": "git+http://git.focasoftware.com/npm/foca-modal-busqueda-productos.git", 27 "foca-modal-busqueda-productos": "git+http://git.focasoftware.com/npm/foca-modal-busqueda-productos.git",
28 "foca-modal-cotizacion": "git+http://git.focasoftware.com/npm/foca-modal-cotizacion.git", 28 "foca-modal-cotizacion": "git+http://git.focasoftware.com/npm/foca-modal-cotizacion.git",
29 "foca-modal-domicilio": "git+http://git.focasoftware.com/npm/foca-modal-domicilio.git", 29 "foca-modal-domicilio": "git+http://git.focasoftware.com/npm/foca-modal-domicilio.git",
30 "foca-modal-flete": "git+http://git.focasoftware.com/npm/foca-modal-flete.git", 30 "foca-modal-flete": "git+http://git.focasoftware.com/npm/foca-modal-flete.git",
31 "foca-modal-moneda": "git+http://git.focasoftware.com/npm/foca-modal-moneda.git", 31 "foca-modal-moneda": "git+http://git.focasoftware.com/npm/foca-modal-moneda.git",
32 "foca-modal-precio-condiciones": "git+http://git.focasoftware.com/npm/foca-modal-precio-condiciones.git", 32 "foca-modal-precio-condiciones": "git+http://git.focasoftware.com/npm/foca-modal-precio-condiciones.git",
33 "foca-modal-proveedor": "git+http://git.focasoftware.com/npm/foca-modal-proveedor.git", 33 "foca-modal-proveedor": "git+http://git.focasoftware.com/npm/foca-modal-proveedor.git",
34 "foca-modal-vendedores": "git+http://git.focasoftware.com/npm/foca-modal-vendedores.git", 34 "foca-modal-vendedores": "git+http://git.focasoftware.com/npm/foca-modal-vendedores.git",
35 "foca-seguimiento": "git+http://git.focasoftware.com/npm/foca-seguimiento.git" 35 "foca-seguimiento": "git+http://git.focasoftware.com/npm/foca-seguimiento.git"
36 }, 36 },
37 "devDependencies": { 37 "devDependencies": {
38 "angular": "^1.7.5", 38 "angular": "^1.7.5",
39 "angular-ladda": "^0.4.3", 39 "angular-ladda": "^0.4.3",
40 "angular-mocks": "^1.7.7", 40 "angular-mocks": "^1.7.7",
41 "angular-route": "^1.7.5", 41 "angular-route": "^1.7.5",
42 "bootstrap": "^4.1.3", 42 "bootstrap": "^4.1.3",
43 "foca-busqueda-cliente": "git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git", 43 "foca-busqueda-cliente": "git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git",
44 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", 44 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git",
45 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", 45 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git",
46 "foca-modal-busqueda-productos": "git+http://git.focasoftware.com/npm/foca-modal-busqueda-productos.git", 46 "foca-modal-busqueda-productos": "git+http://git.focasoftware.com/npm/foca-modal-busqueda-productos.git",
47 "foca-modal-cotizacion": "git+http://git.focasoftware.com/npm/foca-modal-cotizacion.git", 47 "foca-modal-cotizacion": "git+http://git.focasoftware.com/npm/foca-modal-cotizacion.git",
48 "foca-modal-domicilio": "git+http://git.focasoftware.com/npm/foca-modal-domicilio.git", 48 "foca-modal-domicilio": "git+http://git.focasoftware.com/npm/foca-modal-domicilio.git",
49 "foca-modal-flete": "git+http://git.focasoftware.com/npm/foca-modal-flete.git", 49 "foca-modal-flete": "git+http://git.focasoftware.com/npm/foca-modal-flete.git",
50 "foca-modal-moneda": "git+http://git.focasoftware.com/npm/foca-modal-moneda.git", 50 "foca-modal-moneda": "git+http://git.focasoftware.com/npm/foca-modal-moneda.git",
51 "foca-modal-precio-condiciones": "git+http://git.focasoftware.com/npm/foca-modal-precio-condiciones.git", 51 "foca-modal-precio-condiciones": "git+http://git.focasoftware.com/npm/foca-modal-precio-condiciones.git",
52 "foca-modal-proveedor": "git+http://git.focasoftware.com/npm/foca-modal-proveedor.git", 52 "foca-modal-proveedor": "git+http://git.focasoftware.com/npm/foca-modal-proveedor.git",
53 "foca-modal-vendedores": "git+http://git.focasoftware.com/npm/foca-modal-vendedores.git", 53 "foca-modal-vendedores": "git+http://git.focasoftware.com/npm/foca-modal-vendedores.git",
54 "foca-seguimiento": "git+http://git.focasoftware.com/npm/foca-seguimiento.git", 54 "foca-seguimiento": "git+http://git.focasoftware.com/npm/foca-seguimiento.git",
55 "font-awesome": "^4.7.0", 55 "font-awesome": "^4.7.0",
56 "gulp": "^3.9.1", 56 "gulp": "^3.9.1",
57 "gulp-angular-templatecache": "^2.2.5", 57 "gulp-angular-templatecache": "^2.2.5",
58 "gulp-clean": "^0.4.0", 58 "gulp-clean": "^0.4.0",
59 "gulp-concat": "^2.6.1", 59 "gulp-concat": "^2.6.1",
60 "gulp-connect": "^5.6.1", 60 "gulp-connect": "^5.6.1",
61 "gulp-htmlmin": "^5.0.1", 61 "gulp-htmlmin": "^5.0.1",
62 "gulp-jshint": "^2.1.0", 62 "gulp-jshint": "^2.1.0",
63 "gulp-rename": "^1.4.0", 63 "gulp-rename": "^1.4.0",
64 "gulp-replace": "^1.0.0", 64 "gulp-replace": "^1.0.0",
65 "gulp-sequence": "^1.0.0", 65 "gulp-sequence": "^1.0.0",
66 "gulp-uglify": "^3.0.1", 66 "gulp-uglify": "^3.0.1",
67 "gulp-uglify-es": "^1.0.4", 67 "gulp-uglify-es": "^1.0.4",
68 "jasmine-core": "^3.3.0", 68 "jasmine-core": "^3.3.0",
69 "jquery": "^3.3.1", 69 "jquery": "^3.3.1",
70 "jshint": "^2.9.6", 70 "jshint": "^2.9.6",
71 "ladda": "1.0.6", 71 "ladda": "1.0.6",
72 "ngstorage": "^0.3.11",
72 "pre-commit": "^1.2.2", 73 "pre-commit": "^1.2.2",
73 "pump": "^3.0.0", 74 "pump": "^3.0.0",
74 "ui-bootstrap4": "^3.0.5" 75 "ui-bootstrap4": "^3.0.5"
75 } 76 }
76 } 77 }
77 78
spec/controllerSpec.js
1 describe('Controladores módulo crear nota de pedido', function() { 1 describe('Controladores módulo crear nota de pedido', function() {
2 2
3 var $controler; 3 var $controler;
4 4
5 beforeEach(function() { 5 beforeEach(function() {
6 module('focaCrearNotaPedido'); 6 module('focaCrearNotaPedido');
7 inject(function(_$controller_) { 7 inject(function(_$controller_) {
8 $controler = _$controller_; 8 $controler = _$controller_;
9 }); 9 });
10 }); 10 });
11 11
12 describe('Controlador notaPedidoCtrl', function() { 12 describe('Controlador notaPedidoCtrl', function() {
13 13
14 var filter = function() { 14 var filter = function() {
15 return function() { }; 15 return function() { };
16 }; 16 };
17 var timeout; 17 var timeout;
18 18
19 beforeEach(function() { 19 beforeEach(function() {
20 20
21 inject(function($timeout) { 21 inject(function($timeout) {
22 timeout = $timeout; 22 timeout = $timeout;
23 }); 23 });
24 }); 24 });
25 25
26 it('La función seleccionarNotaPedido levanta modal', function() { 26 it('La función seleccionarNotaPedido levanta modal', function() {
27 //arrange 27 //arrange
28 var scope = {}; 28 var scope = {};
29 var uibModal = { 29 var uibModal = {
30 open: function() { } 30 open: function() { }
31 }; 31 };
32 32
33 $controler('notaPedidoCtrl', { 33 $controler('notaPedidoCtrl', {
34 $scope: scope, 34 $scope: scope,
35 $uibModal: uibModal, 35 $uibModal: uibModal,
36 $location: {}, 36 $location: {},
37 $filter: filter, 37 $filter: filter,
38 $timeout: timeout, 38 $timeout: timeout,
39 crearNotaPedidoService: { 39 crearNotaPedidoService: {
40 getBotonera: function() { }, 40 getBotonera: function() { },
41 getCotizacionByIdMoneda: function() { 41 getCotizacionByIdMoneda: function() {
42 return { 42 return {
43 then: function() { } 43 then: function() { }
44 }; 44 };
45 } 45 }
46 }, 46 },
47 focaBotoneraLateralService: {}, 47 focaBotoneraLateralService: {},
48 focaModalService: {}, 48 focaModalService: {},
49 notaPedidoBusinessService: {}, 49 notaPedidoBusinessService: {},
50 $rootScope: { 50 $rootScope: {
51 $on: function() { } 51 $on: function() { }
52 }, 52 },
53 focaSeguimientoService: {}, 53 focaSeguimientoService: {},
54 APP: {}, 54 APP: {},
55 focaLoginService: {} 55 focaLoginService: {},
56 $localStorage: {},
57 $watch: function() { }
56 }); 58 });
57 var respuesta = { result: { then: function() { } } }; 59 var respuesta = { result: { then: function() { } } };
58 60
59 //act 61 //act
60 spyOn(uibModal, 'open').and.returnValue(respuesta); 62 spyOn(uibModal, 'open').and.returnValue(respuesta);
61 scope.seleccionarNotaPedido(); 63 scope.seleccionarNotaPedido();
62 64
63 //assert 65 //assert
64 expect(uibModal.open).toHaveBeenCalled(); 66 expect(uibModal.open).toHaveBeenCalled();
65 }); 67 });
66 68
67 it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { 69 it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) {
68 //arrange 70 //arrange
69 var scope = {}; 71 var scope = {};
70 var uibModal = { 72 var uibModal = {
71 open: function() { } 73 open: function() { }
72 }; 74 };
73 75
74 $controler('notaPedidoCtrl', { 76 $controler('notaPedidoCtrl', {
75 $scope: scope, 77 $scope: scope,
76 $uibModal: uibModal, 78 $uibModal: uibModal,
77 $location: {}, 79 $location: {},
78 $filter: filter, 80 $filter: filter,
79 $timeout: timeout, 81 $timeout: timeout,
80 crearNotaPedidoService: { 82 crearNotaPedidoService: {
81 getBotonera: function() { }, 83 getBotonera: function() { },
82 getCotizacionByIdMoneda: function() { 84 getCotizacionByIdMoneda: function() {
83 return { 85 return {
84 then: function() { } 86 then: function() { }
85 }; 87 };
86 } 88 }
87 }, 89 },
88 focaBotoneraLateralService: {}, 90 focaBotoneraLateralService: {},
89 focaModalService: {}, 91 focaModalService: {},
90 notaPedidoBusinessService: { 92 notaPedidoBusinessService: {
91 plazoToString: function() { }, 93 plazoToString: function() { },
92 calcularArticulos: function() { } 94 calcularArticulos: function() { }
93 }, 95 },
94 $rootScope: { 96 $rootScope: {
95 $on: function() { } 97 $on: function() { }
96 }, 98 },
97 focaSeguimientoService: {}, 99 focaSeguimientoService: {},
98 APP: {}, 100 APP: {},
99 focaLoginService: {} 101 focaLoginService: {},
102 $localStorage: {},
103 $watch: function() { }
100 }); 104 });
101 var notaPedido = { 105 var notaPedido = {
102 cotizacion: { 106 cotizacion: {
103 moneda: {} 107 moneda: {}
104 }, 108 },
105 cliente: {}, 109 cliente: {},
106 vendedor: {}, 110 vendedor: {},
107 proveedor: {}, 111 proveedor: {},
108 notaPedidoPlazo: {}, 112 notaPedidoPlazo: {},
109 notaPedidoPuntoDescarga: [] 113 notaPedidoPuntoDescarga: []
110 }; 114 };
111 var respuesta = { result: Promise.resolve(notaPedido) }; 115 var respuesta = { result: Promise.resolve(notaPedido) };
112 116
113 //act 117 //act
114 scope.notaPedido = {}; 118 scope.notaPedido = {};
115 scope.$broadcast = function() { }; 119 scope.$broadcast = function() { };
116 spyOn(uibModal, 'open').and.returnValue(respuesta); 120 spyOn(uibModal, 'open').and.returnValue(respuesta);
117 spyOn(scope, '$broadcast'); 121 spyOn(scope, '$broadcast');
118 scope.seleccionarNotaPedido(); 122 scope.seleccionarNotaPedido();
119 123
120 //assert 124 //assert
121 respuesta.result.then(function() { 125 respuesta.result.then(function() {
122 expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:'); 126 expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:');
123 expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:'); 127 expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:');
124 done(); 128 done();
125 }); 129 });
126 }); 130 });
127 131
128 it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { 132 it('función seleccionarProductos muestra alerta cuando idLista undefined', function() {
129 //arrange 133 //arrange
130 var scope = {}; 134 var scope = {};
131 var focaModalService = { 135 var focaModalService = {
132 alert: function() { } 136 alert: function() { }
133 }; 137 };
134 138
135 $controler('notaPedidoCtrl', { 139 $controler('notaPedidoCtrl', {
136 $scope: scope, 140 $scope: scope,
137 $uibModal: {}, 141 $uibModal: {},
138 $location: {}, 142 $location: {},
139 $filter: filter, 143 $filter: filter,
140 $timeout: timeout, 144 $timeout: timeout,
141 crearNotaPedidoService: { 145 crearNotaPedidoService: {
142 getBotonera: function() { }, 146 getBotonera: function() { },
143 getCotizacionByIdMoneda: function() { 147 getCotizacionByIdMoneda: function() {
144 return { 148 return {
145 then: function() { } 149 then: function() { }
146 }; 150 };
147 } 151 }
148 }, 152 },
149 focaBotoneraLateralService: {}, 153 focaBotoneraLateralService: {},
150 focaModalService: focaModalService, 154 focaModalService: focaModalService,
151 notaPedidoBusinessService: {}, 155 notaPedidoBusinessService: {},
152 $rootScope: { 156 $rootScope: {
153 $on: function() { } 157 $on: function() { }
154 }, 158 },
155 focaSeguimientoService: {}, 159 focaSeguimientoService: {},
156 APP: {}, 160 APP: {},
157 focaLoginService: {} 161 focaLoginService: {},
162 $localStorage: {},
163 $watch: function() { }
158 }); 164 });
159 165
160 //act 166 //act
161 spyOn(focaModalService, 'alert'); 167 spyOn(focaModalService, 'alert');
162 scope.idLista = undefined; 168 scope.idLista = undefined;
163 scope.seleccionarProductos(); 169 scope.seleccionarProductos();
164 170
165 //assert 171 //assert
166 expect(focaModalService.alert) 172 expect(focaModalService.alert)
167 .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion'); 173 .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion');
168 }); 174 });
169 175
170 it('función seleccionarProductos abre modal', function() { 176 it('función seleccionarProductos abre modal', function() {
171 //arrange 177 //arrange
172 var scope = {}; 178 var scope = {};
173 var uibModal = { 179 var uibModal = {
174 open: function() { } 180 open: function() { }
175 }; 181 };
176 182
177 $controler('notaPedidoCtrl', { 183 $controler('notaPedidoCtrl', {
178 $scope: scope, 184 $scope: scope,
179 $uibModal: uibModal, 185 $uibModal: uibModal,
180 $location: {}, 186 $location: {},
181 $filter: filter, 187 $filter: filter,
182 $timeout: timeout, 188 $timeout: timeout,
183 crearNotaPedidoService: { 189 crearNotaPedidoService: {
184 getBotonera: function() { }, 190 getBotonera: function() { },
185 getCotizacionByIdMoneda: function() { 191 getCotizacionByIdMoneda: function() {
186 return { 192 return {
187 then: function() { } 193 then: function() { }
188 }; 194 };
189 } 195 }
190 }, 196 },
191 focaBotoneraLateralService: {}, 197 focaBotoneraLateralService: {},
192 focaModalService: {}, 198 focaModalService: {},
193 notaPedidoBusinessService: {}, 199 notaPedidoBusinessService: {},
194 $rootScope: { 200 $rootScope: {
195 $on: function() { } 201 $on: function() { }
196 }, 202 },
197 focaSeguimientoService: {}, 203 focaSeguimientoService: {},
198 APP: {}, 204 APP: {},
199 focaLoginService: {} 205 focaLoginService: {},
206 $localStorage: {},
207 $watch: function() { }
200 }); 208 });
201 scope.idLista = true; 209 scope.idLista = true;
202 scope.notaPedido = { 210 scope.notaPedido = {
203 cotizacion: {}, 211 cotizacion: {},
204 moneda: {} 212 moneda: {}
205 }; 213 };
206 var respuesta = { result: {then: function() { } } }; 214 var respuesta = { result: {then: function() { } } };
207 215
208 //act 216 //act
209 spyOn(uibModal, 'open').and.returnValue(respuesta); 217 spyOn(uibModal, 'open').and.returnValue(respuesta);
210 scope.seleccionarProductos(); 218 scope.seleccionarProductos();
211 219
212 //assert 220 //assert
213 expect(uibModal.open).toHaveBeenCalled(); 221 expect(uibModal.open).toHaveBeenCalled();
214 }); 222 });
215 223
216 it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' + 224 it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' +
217 'undefined', function() 225 'undefined', function()
218 { 226 {
219 //arrange 227 //arrange
220 var scope = {}; 228 var scope = {};
221 var focaModalService = { 229 var focaModalService = {
222 alert: function() { } 230 alert: function() { }
223 }; 231 };
224 232
225 $controler('notaPedidoCtrl', { 233 $controler('notaPedidoCtrl', {
226 $scope: scope, 234 $scope: scope,
227 $uibModal: {}, 235 $uibModal: {},
228 $location: {}, 236 $location: {},
229 $filter: filter, 237 $filter: filter,
230 $timeout: timeout, 238 $timeout: timeout,
231 crearNotaPedidoService: { 239 crearNotaPedidoService: {
232 getBotonera: function() { }, 240 getBotonera: function() { },
233 getCotizacionByIdMoneda: function() { 241 getCotizacionByIdMoneda: function() {
234 return { 242 return {
235 then: function() { } 243 then: function() { }
236 }; 244 };
237 } 245 }
238 }, 246 },
239 focaBotoneraLateralService: {}, 247 focaBotoneraLateralService: {},
240 focaModalService: focaModalService, 248 focaModalService: focaModalService,
241 notaPedidoBusinessService: {}, 249 notaPedidoBusinessService: {},
242 $rootScope: { 250 $rootScope: {
243 $on: function() { } 251 $on: function() { }
244 }, 252 },
245 focaSeguimientoService: {}, 253 focaSeguimientoService: {},
246 APP: {}, 254 APP: {},
247 focaLoginService: {} 255 focaLoginService: {},
256 $localStorage: {},
257 $watch: function() { }
248 }); 258 });
249 scope.idLista = true; 259 scope.idLista = true;
250 scope.notaPedido = { 260 scope.notaPedido = {
251 cliente: { COD: false }, 261 cliente: { COD: false },
252 domicilio: { id: false} 262 domicilio: { id: false}
253 }; 263 };
254 264
255 //act 265 //act
256 spyOn(focaModalService, 'alert'); 266 spyOn(focaModalService, 'alert');
257 scope.seleccionarPuntosDeDescarga(); 267 scope.seleccionarPuntosDeDescarga();
258 268
259 //assert 269 //assert
260 expect(focaModalService.alert).toHaveBeenCalled(); 270 expect(focaModalService.alert).toHaveBeenCalled();
261 }); 271 });
262 272
263 it('función seleccionarPuntosDeDescarga abre modal', function() { 273 it('función seleccionarPuntosDeDescarga abre modal', function() {
264 //arrange 274 //arrange
265 var scope = {}; 275 var scope = {};
266 var uibModal = { 276 var uibModal = {
267 open: function() { } 277 open: function() { }
268 }; 278 };
269 279
270 $controler('notaPedidoCtrl', { 280 $controler('notaPedidoCtrl', {
271 $scope: scope, 281 $scope: scope,
272 $uibModal: uibModal, 282 $uibModal: uibModal,
273 $location: {}, 283 $location: {},
274 $filter: filter, 284 $filter: filter,
275 $timeout: timeout, 285 $timeout: timeout,
276 crearNotaPedidoService: { 286 crearNotaPedidoService: {
277 getBotonera: function() { }, 287 getBotonera: function() { },
278 getCotizacionByIdMoneda: function() { 288 getCotizacionByIdMoneda: function() {
279 return { 289 return {
280 then: function() { } 290 then: function() { }
281 }; 291 };
282 } 292 }
283 }, 293 },
284 focaBotoneraLateralService: {}, 294 focaBotoneraLateralService: {},
285 focaModalService: {}, 295 focaModalService: {},
286 notaPedidoBusinessService: {}, 296 notaPedidoBusinessService: {},
287 $rootScope: { 297 $rootScope: {
288 $on: function() { } 298 $on: function() { }
289 }, 299 },
290 focaSeguimientoService: {}, 300 focaSeguimientoService: {},
291 APP: {}, 301 APP: {},
292 focaLoginService: {} 302 focaLoginService: {},
303 $localStorage: {},
304 $watch: function() { }
293 }); 305 });
294 scope.idLista = true; 306 scope.idLista = true;
295 scope.notaPedido = { 307 scope.notaPedido = {
296 cliente: { COD: true }, 308 cliente: { COD: true },
297 domicilio: { id: true } 309 domicilio: { id: true }
298 }; 310 };
299 var respuesta = { result: { then: function() { } } }; 311 var respuesta = { result: { then: function() { } } };
300 312
301 //act 313 //act
302 spyOn(uibModal, 'open').and.returnValue(respuesta); 314 spyOn(uibModal, 'open').and.returnValue(respuesta);
303 scope.seleccionarPuntosDeDescarga(); 315 scope.seleccionarPuntosDeDescarga();
304 316
305 //assert 317 //assert
306 expect(uibModal.open).toHaveBeenCalled(); 318 expect(uibModal.open).toHaveBeenCalled();
307 }); 319 });
308 320
309 it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { 321 it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) {
310 //arrange 322 //arrange
311 var scope = {}; 323 var scope = {};
312 var uibModal = { 324 var uibModal = {
313 open: function() { } 325 open: function() { }
314 }; 326 };
315 327
316 $controler('notaPedidoCtrl', { 328 $controler('notaPedidoCtrl', {
317 $scope: scope, 329 $scope: scope,
318 $uibModal: uibModal, 330 $uibModal: uibModal,
319 $location: {}, 331 $location: {},
320 $filter: filter, 332 $filter: filter,
321 $timeout: timeout, 333 $timeout: timeout,
322 crearNotaPedidoService: { 334 crearNotaPedidoService: {
323 getBotonera: function() { }, 335 getBotonera: function() { },
324 getCotizacionByIdMoneda: function() { 336 getCotizacionByIdMoneda: function() {
325 return { 337 return {
326 then: function() { } 338 then: function() { }
327 }; 339 };
328 } 340 }
329 }, 341 },
330 focaBotoneraLateralService: {}, 342 focaBotoneraLateralService: {},
331 focaModalService: {}, 343 focaModalService: {},
332 notaPedidoBusinessService: {}, 344 notaPedidoBusinessService: {},
333 $rootScope: { 345 $rootScope: {
334 $on: function() { } 346 $on: function() { }
335 }, 347 },
336 focaSeguimientoService: {}, 348 focaSeguimientoService: {},
337 APP: {}, 349 APP: {},
338 focaLoginService: {} 350 focaLoginService: {},
351 $localStorage: {},
352 $watch: function() { }
339 }); 353 });
340 scope.idLista = true; 354 scope.idLista = true;
341 scope.notaPedido = { 355 scope.notaPedido = {
342 cliente: { COD: true }, 356 cliente: { COD: true },
343 domicilio: { id: true } 357 domicilio: { id: true }
344 }; 358 };
345 var respuesta = []; 359 var respuesta = [];
346 var promiseRespuesta = { result: Promise.resolve(respuesta) }; 360 var promiseRespuesta = { result: Promise.resolve(respuesta) };
347 scope.$broadcast = function() { }; 361 scope.$broadcast = function() { };
348 362
349 //act 363 //act
350 spyOn(uibModal, 'open').and.returnValue(promiseRespuesta); 364 spyOn(uibModal, 'open').and.returnValue(promiseRespuesta);
351 scope.seleccionarPuntosDeDescarga(); 365 scope.seleccionarPuntosDeDescarga();
352 366
353 //assert 367 //assert
354 promiseRespuesta.result.then(function() { 368 promiseRespuesta.result.then(function() {
355 expect(scope.notaPedido.puntosDescarga).toEqual(respuesta); 369 expect(scope.notaPedido.puntosDescarga).toEqual(respuesta);
356 done(); 370 done();
357 }); 371 });
358 }); 372 });
359 373
360 it('función seleccionarVendedor abre modal', function() { 374 it('función seleccionarVendedor abre modal', function() {
361 //arrange 375 //arrange
362 var scope = {}; 376 var scope = {};
363 var focaModalService = { 377 var focaModalService = {
364 modal: function() { } 378 modal: function() { }
365 }; 379 };
366 380
367 $controler('notaPedidoCtrl', { 381 $controler('notaPedidoCtrl', {
368 $scope: scope, 382 $scope: scope,
369 $uibModal: {}, 383 $uibModal: {},
370 $location: {}, 384 $location: {},
371 $filter: filter, 385 $filter: filter,
372 $timeout: timeout, 386 $timeout: timeout,
373 crearNotaPedidoService: { 387 crearNotaPedidoService: {
374 getBotonera: function() { }, 388 getBotonera: function() { },
375 getCotizacionByIdMoneda: function() { 389 getCotizacionByIdMoneda: function() {
376 return { 390 return {
377 then: function() { } 391 then: function() { }
378 }; 392 };
379 } 393 }
380 }, 394 },
381 focaBotoneraLateralService: {}, 395 focaBotoneraLateralService: {},
382 focaModalService: focaModalService, 396 focaModalService: focaModalService,
383 notaPedidoBusinessService: {}, 397 notaPedidoBusinessService: {},
384 $rootScope: { 398 $rootScope: {
385 $on: function() { } 399 $on: function() { }
386 }, 400 },
387 focaSeguimientoService: {}, 401 focaSeguimientoService: {},
388 APP: {}, 402 APP: {},
389 focaLoginService: {} 403 focaLoginService: {},
404 $localStorage: {},
405 $watch: function() { }
390 }); 406 });
391 scope.idLista = true; 407 scope.idLista = true;
392 scope.notaPedido = { 408 scope.notaPedido = {
393 cliente: { COD: true }, 409 cliente: { COD: true },
394 domicilio: { id: true } 410 domicilio: { id: true }
395 }; 411 };
396 412
397 var respuesta = { then: function() { } }; 413 var respuesta = { then: function() { } };
398 414
399 //act 415 //act
400 spyOn(focaModalService, 'modal').and.returnValue(respuesta); 416 spyOn(focaModalService, 'modal').and.returnValue(respuesta);
401 scope.seleccionarVendedor(); 417 scope.seleccionarVendedor();
402 418
403 //assert 419 //assert
404 expect(focaModalService.modal).toHaveBeenCalled(); 420 expect(focaModalService.modal).toHaveBeenCalled();
405 }); 421 });
406 422
407 it('función seleccionarVendedor setea vendedor y cabecera', function(done) { 423 it('función seleccionarVendedor setea vendedor y cabecera', function(done) {
408 //arrange 424 //arrange
409 var scope = {}; 425 var scope = {};
410 var focaModalService = { 426 var focaModalService = {
411 modal: function() { } 427 modal: function() { }
412 }; 428 };
413 429
414 $controler('notaPedidoCtrl', { 430 $controler('notaPedidoCtrl', {
415 $scope: scope, 431 $scope: scope,
416 $uibModal: {}, 432 $uibModal: {},
417 $location: {}, 433 $location: {},
418 $filter: filter, 434 $filter: filter,
419 $timeout: timeout, 435 $timeout: timeout,
420 crearNotaPedidoService: { 436 crearNotaPedidoService: {
421 getBotonera: function() { }, 437 getBotonera: function() { },
422 getCotizacionByIdMoneda: function() { 438 getCotizacionByIdMoneda: function() {
423 return { 439 return {
424 then: function() { } 440 then: function() { }
425 }; 441 };
426 } 442 }
427 }, 443 },
428 focaBotoneraLateralService: {}, 444 focaBotoneraLateralService: {},
429 focaModalService: focaModalService, 445 focaModalService: focaModalService,
430 notaPedidoBusinessService: {}, 446 notaPedidoBusinessService: {},
431 $rootScope: { 447 $rootScope: {
432 $on: function() { } 448 $on: function() { }
433 }, 449 },
434 focaSeguimientoService: {}, 450 focaSeguimientoService: {},
435 APP: {}, 451 APP: {},
436 focaLoginService: {} 452 focaLoginService: {},
453 $localStorage: {},
454 $watch: function() { }
437 }); 455 });
438 scope.idLista = true; 456 scope.idLista = true;
439 scope.notaPedido = { 457 scope.notaPedido = {
440 cliente: { COD: true }, 458 cliente: { COD: true },
441 domicilio: { id: true } 459 domicilio: { id: true }
442 }; 460 };
443 var respuesta = {}; 461 var respuesta = {};
444 var promesaRespuesta = Promise.resolve(respuesta); 462 var promesaRespuesta = Promise.resolve(respuesta);
445 scope.$broadcast = function() { }; 463 scope.$broadcast = function() { };
446 464
447 //act 465 //act
448 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); 466 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta);
449 spyOn(scope, '$broadcast'); 467 spyOn(scope, '$broadcast');
450 scope.seleccionarVendedor(); 468 scope.seleccionarVendedor();
451 469
452 //assert 470 //assert
453 promesaRespuesta.then(function() { 471 promesaRespuesta.then(function() {
454 expect(scope.notaPedido.vendedor).toEqual(respuesta); 472 expect(scope.notaPedido.vendedor).toEqual(respuesta);
455 expect(scope.$broadcast).toHaveBeenCalled(); 473 expect(scope.$broadcast).toHaveBeenCalled();
456 done(); 474 done();
457 }); 475 });
458 }); 476 });
459 477
460 it('función seleccionarProveedor abre modal', function() { 478 it('función seleccionarProveedor abre modal', function() {
461 //arrange 479 //arrange
462 var scope = {}; 480 var scope = {};
463 var focaModalService = { 481 var focaModalService = {
464 modal: function() { } 482 modal: function() { }
465 }; 483 };
466 484
467 $controler('notaPedidoCtrl', { 485 $controler('notaPedidoCtrl', {
468 $scope: scope, 486 $scope: scope,
469 $uibModal: {}, 487 $uibModal: {},
470 $location: {}, 488 $location: {},
471 $filter: filter, 489 $filter: filter,
472 $timeout: timeout, 490 $timeout: timeout,
473 crearNotaPedidoService: { 491 crearNotaPedidoService: {
474 getBotonera: function() { }, 492 getBotonera: function() { },
475 getCotizacionByIdMoneda: function() { 493 getCotizacionByIdMoneda: function() {
476 return { 494 return {
477 then: function() { } 495 then: function() { }
478 }; 496 };
479 } 497 }
480 }, 498 },
481 focaBotoneraLateralService: {}, 499 focaBotoneraLateralService: {},
482 focaModalService: focaModalService, 500 focaModalService: focaModalService,
483 notaPedidoBusinessService: {}, 501 notaPedidoBusinessService: {},
484 $rootScope: { 502 $rootScope: {
485 $on: function() { } 503 $on: function() { }
486 }, 504 },
487 focaSeguimientoService: {}, 505 focaSeguimientoService: {},
488 APP: {}, 506 APP: {},
489 focaLoginService: {} 507 focaLoginService: {},
508 $localStorage: {},
509 $watch: function() { }
490 }); 510 });
491 scope.notaPedido = {}; 511 scope.notaPedido = {};
492 512
493 var respuesta = { then: function() { } }; 513 var respuesta = { then: function() { } };
494 514
495 //act 515 //act
496 spyOn(focaModalService, 'modal').and.returnValue(respuesta); 516 spyOn(focaModalService, 'modal').and.returnValue(respuesta);
497 scope.seleccionarProveedor(); 517 scope.seleccionarProveedor();
498 518
499 //assert 519 //assert
500 expect(focaModalService.modal).toHaveBeenCalled(); 520 expect(focaModalService.modal).toHaveBeenCalled();
501 }); 521 });
502 522
503 it('función seleccionarProveedor setea vendedor y cabecera', function(done) { 523 it('función seleccionarProveedor setea vendedor y cabecera', function(done) {
504 //arrange 524 //arrange
505 var scope = {}; 525 var scope = {};
506 var focaModalService = { 526 var focaModalService = {
507 modal: function() { } 527 modal: function() { }
508 }; 528 };
509 529
510 $controler('notaPedidoCtrl', { 530 $controler('notaPedidoCtrl', {
511 $scope: scope, 531 $scope: scope,
512 $uibModal: {}, 532 $uibModal: {},
513 $location: {}, 533 $location: {},
514 $filter: filter, 534 $filter: filter,
515 $timeout: timeout, 535 $timeout: timeout,
516 crearNotaPedidoService: { 536 crearNotaPedidoService: {
517 getBotonera: function() { }, 537 getBotonera: function() { },
518 getCotizacionByIdMoneda: function() { 538 getCotizacionByIdMoneda: function() {
519 return { 539 return {
520 then: function() { } 540 then: function() { }
521 }; 541 };
522 } 542 }
523 }, 543 },
524 focaBotoneraLateralService: {}, 544 focaBotoneraLateralService: {},
525 focaModalService: focaModalService, 545 focaModalService: focaModalService,
526 notaPedidoBusinessService: {}, 546 notaPedidoBusinessService: {},
527 $rootScope: { 547 $rootScope: {
528 $on: function() { } 548 $on: function() { }
529 }, 549 },
530 focaSeguimientoService: {}, 550 focaSeguimientoService: {},
531 APP: {}, 551 APP: {},
532 focaLoginService: {} 552 focaLoginService: {},
553 $localStorage: {},
554 $watch: function() { }
533 }); 555 });
534 556
535 scope.notaPedido = {}; 557 scope.notaPedido = {};
536 var respuesta = {}; 558 var respuesta = {};
537 var promesaRespuesta = Promise.resolve(respuesta); 559 var promesaRespuesta = Promise.resolve(respuesta);
538 scope.$broadcast = function() { }; 560 scope.$broadcast = function() { };
539 561
540 //act 562 //act
541 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); 563 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta);
542 spyOn(scope, '$broadcast'); 564 spyOn(scope, '$broadcast');
543 scope.seleccionarProveedor(); 565 scope.seleccionarProveedor();
544 566
545 //assert 567 //assert
546 promesaRespuesta.then(function() { 568 promesaRespuesta.then(function() {
547 expect(scope.notaPedido.proveedor).toEqual(respuesta); 569 expect(scope.notaPedido.proveedor).toEqual(respuesta);
548 expect(scope.$broadcast).toHaveBeenCalled(); 570 expect(scope.$broadcast).toHaveBeenCalled();
549 done(); 571 done();
550 }); 572 });
551 }); 573 });
552 574
553 it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() { 575 it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() {
554 //arrange 576 //arrange
555 var scope = {}; 577 var scope = {};
556 var focaModalService = { 578 var focaModalService = {
557 alert: function() { } 579 alert: function() { }
558 }; 580 };
559 581
560 $controler('notaPedidoCtrl', { 582 $controler('notaPedidoCtrl', {
561 $scope: scope, 583 $scope: scope,
562 $uibModal: {}, 584 $uibModal: {},
563 $location: {}, 585 $location: {},
564 $filter: filter, 586 $filter: filter,
565 $timeout: timeout, 587 $timeout: timeout,
566 crearNotaPedidoService: { 588 crearNotaPedidoService: {
567 getBotonera: function() { }, 589 getBotonera: function() { },
568 getCotizacionByIdMoneda: function() { 590 getCotizacionByIdMoneda: function() {
569 return { 591 return {
570 then: function() { } 592 then: function() { }
571 }; 593 };
572 } 594 }
573 }, 595 },
574 focaBotoneraLateralService: {}, 596 focaBotoneraLateralService: {},
575 focaModalService: focaModalService, 597 focaModalService: focaModalService,
576 notaPedidoBusinessService: {}, 598 notaPedidoBusinessService: {},
577 $rootScope: { 599 $rootScope: {
578 $on: function() { } 600 $on: function() { }
579 }, 601 },
580 focaSeguimientoService: {}, 602 focaSeguimientoService: {},
581 APP: {}, 603 APP: {},
582 focaLoginService: {} 604 focaLoginService: {},
605 $localStorage: {},
606 $watch: function() { }
583 }); 607 });
584 scope.notaPedido = { 608 scope.notaPedido = {
585 vendedor: { NUM: false } 609 vendedor: { NUM: false }
586 }; 610 };
587 611
588 //act 612 //act
589 spyOn(focaModalService, 'alert'); 613 spyOn(focaModalService, 'alert');
590 scope.seleccionarCliente(); 614 scope.seleccionarCliente();
591 615
592 //assert 616 //assert
593 expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor'); 617 expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor');
594 }); 618 });
595 619
596 it('función seleccionarCliente abre modal', function() { 620 it('función seleccionarCliente abre modal', function() {
597 //arrange 621 //arrange
598 var scope = {}; 622 var scope = {};
599 var uibModal = { 623 var uibModal = {
600 open: function() { } 624 open: function() { }
601 }; 625 };
602 626
603 $controler('notaPedidoCtrl', { 627 $controler('notaPedidoCtrl', {
604 $scope: scope, 628 $scope: scope,
605 $uibModal: uibModal, 629 $uibModal: uibModal,
606 $location: {}, 630 $location: {},
607 $filter: filter, 631 $filter: filter,
608 $timeout: timeout, 632 $timeout: timeout,
609 crearNotaPedidoService: { 633 crearNotaPedidoService: {
610 getBotonera: function() { }, 634 getBotonera: function() { },
611 getCotizacionByIdMoneda: function() { 635 getCotizacionByIdMoneda: function() {
612 return { 636 return {
613 then: function() { } 637 then: function() { }
614 }; 638 };
615 } 639 }
616 }, 640 },
617 focaBotoneraLateralService: {}, 641 focaBotoneraLateralService: {},
618 focaModalService: {}, 642 focaModalService: {},
619 notaPedidoBusinessService: {}, 643 notaPedidoBusinessService: {},
620 $rootScope: { 644 $rootScope: {
621 $on: function() { } 645 $on: function() { }
622 }, 646 },
623 focaSeguimientoService: {}, 647 focaSeguimientoService: {},
624 APP: {}, 648 APP: {},
625 focaLoginService: {} 649 focaLoginService: {},
650 $localStorage: {},
651 $watch: function() { }
626 }); 652 });
627 scope.notaPedido = { 653 scope.notaPedido = {
628 vendedor: { NUM: true } 654 vendedor: { NUM: true }
629 }; 655 };
630 656
631 var respuesta = { result: {then: function() { } } }; 657 var respuesta = { result: {then: function() { } } };
632 658
633 //act 659 //act
634 spyOn(uibModal, 'open').and.returnValue(respuesta); 660 spyOn(uibModal, 'open').and.returnValue(respuesta);
635 scope.seleccionarCliente(); 661 scope.seleccionarCliente();
636 662
637 //assert 663 //assert
638 expect(uibModal.open).toHaveBeenCalled(); 664 expect(uibModal.open).toHaveBeenCalled();
639 }); 665 });
640 666
641 it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { 667 it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) {
642 668
643 //arrange 669 //arrange
644 var scope = {}; 670 var scope = {};
645 var uibModal = { 671 var uibModal = {
646 open: function() { } 672 open: function() { }
647 }; 673 };
648 674
649 $controler('notaPedidoCtrl', { 675 $controler('notaPedidoCtrl', {
650 $scope: scope, 676 $scope: scope,
651 $uibModal: uibModal, 677 $uibModal: uibModal,
652 $location: {}, 678 $location: {},
653 $filter: filter, 679 $filter: filter,
654 $timeout: timeout, 680 $timeout: timeout,
655 crearNotaPedidoService: { 681 crearNotaPedidoService: {
656 getBotonera: function() { }, 682 getBotonera: function() { },
657 getCotizacionByIdMoneda: function() { 683 getCotizacionByIdMoneda: function() {
658 return { 684 return {
659 then: function() { } 685 then: function() { }
660 }; 686 };
661 } 687 }
662 }, 688 },
663 focaBotoneraLateralService: {}, 689 focaBotoneraLateralService: {},
664 focaModalService: {}, 690 focaModalService: {},
665 notaPedidoBusinessService: {}, 691 notaPedidoBusinessService: {},
666 $rootScope: { 692 $rootScope: {
667 $on: function() { } 693 $on: function() { }
668 }, 694 },
669 focaSeguimientoService: {}, 695 focaSeguimientoService: {},
670 APP: {}, 696 APP: {},
671 focaLoginService: {} 697 focaLoginService: {},
698 $localStorage: {},
699 $watch: function() { }
672 }); 700 });
673 scope.idLista = true; 701 scope.idLista = true;
674 scope.notaPedido = { 702 scope.notaPedido = {
675 vendedor: { NUM: true } 703 vendedor: { NUM: true }
676 }; 704 };
677 var respuesta = {}; 705 var respuesta = {};
678 var promesaRespuesta = { result: Promise.resolve(respuesta) }; 706 var promesaRespuesta = { result: Promise.resolve(respuesta) };
679 707
680 //act 708 //act
681 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); 709 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
682 spyOn(scope, 'abrirModalDomicilios'); 710 spyOn(scope, 'abrirModalDomicilios');
683 scope.seleccionarCliente(); 711 scope.seleccionarCliente();
684 712
685 //assert 713 //assert
686 promesaRespuesta.result.then(function() { 714 promesaRespuesta.result.then(function() {
687 expect(scope.cliente).toEqual(respuesta); 715 expect(scope.cliente).toEqual(respuesta);
688 expect(scope.abrirModalDomicilios).toHaveBeenCalled(); 716 expect(scope.abrirModalDomicilios).toHaveBeenCalled();
689 done(); 717 done();
690 }); 718 });
691 }); 719 });
692 720
693 it('función abrirModalDomicilios abre modal', function() { 721 it('función abrirModalDomicilios abre modal', function() {
694 //arrange 722 //arrange
695 var scope = {}; 723 var scope = {};
696 var uibModal = { 724 var uibModal = {
697 open: function() { } 725 open: function() { }
698 }; 726 };
699 727
700 $controler('notaPedidoCtrl', { 728 $controler('notaPedidoCtrl', {
701 $scope: scope, 729 $scope: scope,
702 $uibModal: uibModal, 730 $uibModal: uibModal,
703 $location: {}, 731 $location: {},
704 $filter: filter, 732 $filter: filter,
705 $timeout: timeout, 733 $timeout: timeout,
706 crearNotaPedidoService: { 734 crearNotaPedidoService: {
707 getBotonera: function() { }, 735 getBotonera: function() { },
708 getCotizacionByIdMoneda: function() { 736 getCotizacionByIdMoneda: function() {
709 return { 737 return {
710 then: function() { } 738 then: function() { }
711 }; 739 };
712 } 740 }
713 }, 741 },
714 focaBotoneraLateralService: {}, 742 focaBotoneraLateralService: {},
715 focaModalService: {}, 743 focaModalService: {},
716 notaPedidoBusinessService: {}, 744 notaPedidoBusinessService: {},
717 $rootScope: { 745 $rootScope: {
718 $on: function() { } 746 $on: function() { }
719 }, 747 },
720 focaSeguimientoService: {}, 748 focaSeguimientoService: {},
721 APP: {}, 749 APP: {},
722 focaLoginService: {} 750 focaLoginService: {},
751 $localStorage: {},
752 $watch: function() { }
723 }); 753 });
724 754
725 var respuesta = { result: {then: function() { } } }; 755 var respuesta = { result: {then: function() { } } };
726 756
727 //act 757 //act
728 spyOn(uibModal, 'open').and.returnValue(respuesta); 758 spyOn(uibModal, 'open').and.returnValue(respuesta);
729 scope.abrirModalDomicilios(); 759 scope.abrirModalDomicilios();
730 760
731 //assert 761 //assert
732 expect(uibModal.open).toHaveBeenCalled(); 762 expect(uibModal.open).toHaveBeenCalled();
733 }); 763 });
734 764
735 it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { 765 it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) {
736 766
737 //arrange 767 //arrange
738 var scope = {}; 768 var scope = {};
739 var uibModal = { 769 var uibModal = {
740 open: function() { } 770 open: function() { }
741 }; 771 };
742 772
743 $controler('notaPedidoCtrl', { 773 $controler('notaPedidoCtrl', {
744 $scope: scope, 774 $scope: scope,
745 $uibModal: uibModal, 775 $uibModal: uibModal,
746 $location: {}, 776 $location: {},
747 $filter: filter, 777 $filter: filter,
748 $timeout: timeout, 778 $timeout: timeout,
749 crearNotaPedidoService: { 779 crearNotaPedidoService: {
750 getBotonera: function() { }, 780 getBotonera: function() { },
751 getCotizacionByIdMoneda: function() { 781 getCotizacionByIdMoneda: function() {
752 return { 782 return {
753 then: function() { } 783 then: function() { }
754 }; 784 };
755 }, 785 },
756 getPuntosDescargaByClienDom: function() { 786 getPuntosDescargaByClienDom: function() {
757 return { 787 return {
758 then: function() { } 788 then: function() { }
759 }; 789 };
760 } 790 }
761 }, 791 },
762 focaBotoneraLateralService: {}, 792 focaBotoneraLateralService: {},
763 focaModalService: {}, 793 focaModalService: {},
764 notaPedidoBusinessService: {}, 794 notaPedidoBusinessService: {},
765 $rootScope: { 795 $rootScope: {
766 $on: function() { } 796 $on: function() { }
767 }, 797 },
768 focaSeguimientoService: {}, 798 focaSeguimientoService: {},
769 APP: {}, 799 APP: {},
770 focaLoginService: {} 800 focaLoginService: {},
801 $localStorage: {},
802 $watch: function() { }
771 }); 803 });
772 scope.idLista = true; 804 scope.idLista = true;
773 scope.notaPedido = { 805 scope.notaPedido = {
774 vendedor: { NUM: true } 806 vendedor: { NUM: true }
775 }; 807 };
776 var respuesta = {}; 808 var respuesta = {};
777 var promesaRespuesta = { result: Promise.resolve(respuesta) }; 809 var promesaRespuesta = { result: Promise.resolve(respuesta) };
778 scope.$broadcast = function() { }; 810 scope.$broadcast = function() { };
779 var cliente = { 811 var cliente = {
780 COD: undefined, 812 COD: undefined,
781 CUIT: undefined, 813 CUIT: undefined,
782 NOM: undefined 814 NOM: undefined
783 }; 815 };
784 816
785 //act 817 //act
786 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); 818 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
787 spyOn(scope, '$broadcast'); 819 spyOn(scope, '$broadcast');
788 scope.abrirModalDomicilios({ }); 820 scope.abrirModalDomicilios({ });
789 821
790 //assert 822 //assert
791 promesaRespuesta.result.then(function() { 823 promesaRespuesta.result.then(function() {
792 expect(scope.notaPedido.domicilio).toEqual(respuesta); 824 expect(scope.notaPedido.domicilio).toEqual(respuesta);
793 expect(scope.notaPedido.cliente).toEqual(cliente); 825 expect(scope.notaPedido.cliente).toEqual(cliente);
794 expect(scope.$broadcast).toHaveBeenCalled(); 826 expect(scope.$broadcast).toHaveBeenCalled();
795 done(); 827 done();
796 }); 828 });
797 }); 829 });
798 830
799 it('función getTotal devulve correctamente', function() { 831 it('función getTotal devulve correctamente', function() {
800 832
801 //arrange 833 //arrange
802 var scope = {}; 834 var scope = {};
803 835
804 $controler('notaPedidoCtrl', { 836 $controler('notaPedidoCtrl', {
805 $scope: scope, 837 $scope: scope,
806 $uibModal: {}, 838 $uibModal: {},
807 $location: {}, 839 $location: {},
808 $filter: filter, 840 $filter: filter,
809 $timeout: timeout, 841 $timeout: timeout,
810 crearNotaPedidoService: { 842 crearNotaPedidoService: {
811 getBotonera: function() { }, 843 getBotonera: function() { },
812 getCotizacionByIdMoneda: function() { 844 getCotizacionByIdMoneda: function() {
813 return { 845 return {
814 then: function() { } 846 then: function() { }
815 }; 847 };
816 } 848 }
817 }, 849 },
818 focaBotoneraLateralService: {}, 850 focaBotoneraLateralService: {},
819 focaModalService: {}, 851 focaModalService: {},
820 notaPedidoBusinessService: {}, 852 notaPedidoBusinessService: {},
821 $rootScope: { 853 $rootScope: {
822 $on: function() { } 854 $on: function() { }
823 }, 855 },
824 focaSeguimientoService: {}, 856 focaSeguimientoService: {},
825 APP: {}, 857 APP: {},
826 focaLoginService: {} 858 focaLoginService: {},
859 $localStorage: {},
860 $watch: function() { }
827 }); 861 });
828 scope.idLista = true; 862 scope.idLista = true;
829 scope.notaPedido = { 863 scope.notaPedido = {
830 vendedor: { NUM: true } 864 vendedor: { NUM: true }
831 }; 865 };
832 866
833 //act 867 //act
834 scope.articulosTabla = [{ precio: 2, cantidad: 1}]; 868 scope.articulosTabla = [{ precio: 2, cantidad: 1}];
835 var esperado = 2; 869 var esperado = 2;
836 var resultado = scope.getTotal(); 870 var resultado = scope.getTotal();
837 871
838 //assert 872 //assert
839 expect(resultado).toEqual(esperado); 873 expect(resultado).toEqual(esperado);
840 }); 874 });
841 875
842 it('función getSubTotal devulve correctamente', function() { 876 it('función getSubTotal devulve correctamente', function() {
843 877
844 //arrange 878 //arrange
845 var scope = {}; 879 var scope = {};
846 880
847 $controler('notaPedidoCtrl', { 881 $controler('notaPedidoCtrl', {
848 $scope: scope, 882 $scope: scope,
849 $uibModal: {}, 883 $uibModal: {},
850 $location: {}, 884 $location: {},
851 $filter: filter, 885 $filter: filter,
852 $timeout: timeout, 886 $timeout: timeout,
853 crearNotaPedidoService: { 887 crearNotaPedidoService: {
854 getBotonera: function() { }, 888 getBotonera: function() { },
855 getCotizacionByIdMoneda: function() { 889 getCotizacionByIdMoneda: function() {
856 return { 890 return {
857 then: function() { } 891 then: function() { }
858 }; 892 };
859 } 893 }
860 }, 894 },
861 focaBotoneraLateralService: {}, 895 focaBotoneraLateralService: {},
862 focaModalService: {}, 896 focaModalService: {},
863 notaPedidoBusinessService: {}, 897 notaPedidoBusinessService: {},
864 $rootScope: { 898 $rootScope: {
865 $on: function() { } 899 $on: function() { }
866 }, 900 },
867 focaSeguimientoService: {}, 901 focaSeguimientoService: {},
868 APP: {}, 902 APP: {},
869 focaLoginService: {} 903 focaLoginService: {},
904 $localStorage: {},
905 $watch: function() { }
870 }); 906 });
871 scope.idLista = true; 907 scope.idLista = true;
872 scope.notaPedido = { 908 scope.notaPedido = {
873 vendedor: { NUM: true } 909 vendedor: { NUM: true }
874 }; 910 };
875 911
876 //act 912 //act
877 scope.articuloACargar = { precio: 2, cantidad: 1}; 913 scope.articuloACargar = { precio: 2, cantidad: 1};
878 var esperado = 2; 914 var esperado = 2;
879 var resultado = scope.getSubTotal(); 915 var resultado = scope.getSubTotal();
880 916
881 //assert 917 //assert
882 expect(resultado).toEqual(esperado); 918 expect(resultado).toEqual(esperado);
883 }); 919 });
884 920
885 it('función seleccionarPreciosYCondiciones abre modal', function() { 921 it('función seleccionarPreciosYCondiciones abre modal', function() {
886 922
887 //arrange 923 //arrange
888 var scope = {}; 924 var scope = {};
889 var uibModal = { 925 var uibModal = {
890 open: function() { } 926 open: function() { }
891 }; 927 };
892 928
893 $controler('notaPedidoCtrl', { 929 $controler('notaPedidoCtrl', {
894 $scope: scope, 930 $scope: scope,
895 $uibModal: uibModal, 931 $uibModal: uibModal,
896 $location: {}, 932 $location: {},
897 $filter: filter, 933 $filter: filter,
898 $timeout: timeout, 934 $timeout: timeout,
899 crearNotaPedidoService: { 935 crearNotaPedidoService: {
900 getBotonera: function() { }, 936 getBotonera: function() { },
901 getCotizacionByIdMoneda: function() { 937 getCotizacionByIdMoneda: function() {
902 return { 938 return {
903 then: function() { } 939 then: function() { }
904 }; 940 };
905 } 941 }
906 }, 942 },
907 focaBotoneraLateralService: {}, 943 focaBotoneraLateralService: {},
908 focaModalService: {}, 944 focaModalService: {},
909 notaPedidoBusinessService: {}, 945 notaPedidoBusinessService: {},
910 $rootScope: { 946 $rootScope: {
911 $on: function() { } 947 $on: function() { }
912 }, 948 },
913 focaSeguimientoService: {}, 949 focaSeguimientoService: {},
914 APP: {}, 950 APP: {},
915 focaLoginService: {} 951 focaLoginService: {},
952 $localStorage: {},
953 $watch: function() { }
916 }); 954 });
917 955
918 scope.notaPedido = {}; 956 scope.notaPedido = {};
919 957
920 var respuesta = { result: {then: function() { } } }; 958 var respuesta = { result: {then: function() { } } };
921 959
922 //act 960 //act
923 spyOn(uibModal, 'open').and.returnValue(respuesta); 961 spyOn(uibModal, 'open').and.returnValue(respuesta);
924 scope.seleccionarPreciosYCondiciones(); 962 scope.seleccionarPreciosYCondiciones();
925 963
926 //assert 964 //assert
927 expect(uibModal.open).toHaveBeenCalled(); 965 expect(uibModal.open).toHaveBeenCalled();
928 }); 966 });
929 967
930 it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { 968 it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) {
931 969
932 //arrange 970 //arrange
933 var scope = {}; 971 var scope = {};
934 var uibModal = { 972 var uibModal = {
935 open: function() { } 973 open: function() { }
936 }; 974 };
937 975
938 $controler('notaPedidoCtrl', { 976 $controler('notaPedidoCtrl', {
939 $scope: scope, 977 $scope: scope,
940 $uibModal: uibModal, 978 $uibModal: uibModal,
941 $location: {}, 979 $location: {},
942 $filter: filter, 980 $filter: filter,
943 $timeout: timeout, 981 $timeout: timeout,
944 crearNotaPedidoService: { 982 crearNotaPedidoService: {
945 getBotonera: function() { }, 983 getBotonera: function() { },
946 getCotizacionByIdMoneda: function() { 984 getCotizacionByIdMoneda: function() {
947 return { 985 return {
948 then: function() { } 986 then: function() { }
949 }; 987 };
950 } 988 }
951 }, 989 },
952 focaBotoneraLateralService: {}, 990 focaBotoneraLateralService: {},
953 focaModalService: {}, 991 focaModalService: {},
954 notaPedidoBusinessService: {}, 992 notaPedidoBusinessService: {},
955 $rootScope: { 993 $rootScope: {
956 $on: function() { } 994 $on: function() { }
957 }, 995 },
958 focaSeguimientoService: {}, 996 focaSeguimientoService: {},
959 APP: {}, 997 APP: {},
960 focaLoginService: {} 998 focaLoginService: {},
999 $localStorage: {},
1000 $watch: function() { }
961 }); 1001 });
962 scope.idLista = true; 1002 scope.idLista = true;
963 scope.notaPedido = { 1003 scope.notaPedido = {
964 vendedor: { NUM: true } 1004 vendedor: { NUM: true }
965 }; 1005 };
966 var respuesta = { plazoPago: { } }; 1006 var respuesta = { plazoPago: { } };
967 var promesaRespuesta = { result: Promise.resolve(respuesta) }; 1007 var promesaRespuesta = { result: Promise.resolve(respuesta) };
968 scope.$broadcast = function() { }; 1008 scope.$broadcast = function() { };
969 1009
970 //act 1010 //act
971 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); 1011 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
972 spyOn(scope, '$broadcast'); 1012 spyOn(scope, '$broadcast');
973 scope.seleccionarPreciosYCondiciones(); 1013 scope.seleccionarPreciosYCondiciones();
974 1014
975 //assert 1015 //assert
976 promesaRespuesta.result.then(function() { 1016 promesaRespuesta.result.then(function() {
977 expect(scope.articulosTabla.length).toEqual(0); 1017 expect(scope.articulosTabla.length).toEqual(0);
978 expect(scope.$broadcast).toHaveBeenCalled(); 1018 expect(scope.$broadcast).toHaveBeenCalled();
979 done(); 1019 done();
980 }); 1020 });
981 }); 1021 });
982 1022
983 it('función seleccionarFlete abre modal', function() { 1023 it('función seleccionarFlete abre modal', function() {
984 1024
985 //arrange 1025 //arrange
986 var scope = {}; 1026 var scope = {};
987 var uibModal = { 1027 var uibModal = {
988 open: function() { } 1028 open: function() { }
989 }; 1029 };
990 1030
991 $controler('notaPedidoCtrl', { 1031 $controler('notaPedidoCtrl', {
992 $scope: scope, 1032 $scope: scope,
993 $uibModal: uibModal, 1033 $uibModal: uibModal,
994 $location: {}, 1034 $location: {},
995 $filter: filter, 1035 $filter: filter,
996 $timeout: timeout, 1036 $timeout: timeout,
997 crearNotaPedidoService: { 1037 crearNotaPedidoService: {
998 getBotonera: function() { }, 1038 getBotonera: function() { },
999 getCotizacionByIdMoneda: function() { 1039 getCotizacionByIdMoneda: function() {
1000 return { 1040 return {
1001 then: function() { } 1041 then: function() { }
1002 }; 1042 };
1003 } 1043 }
1004 }, 1044 },
1005 focaBotoneraLateralService: {}, 1045 focaBotoneraLateralService: {},
1006 focaModalService: {}, 1046 focaModalService: {},
1007 notaPedidoBusinessService: {}, 1047 notaPedidoBusinessService: {},
1008 $rootScope: { 1048 $rootScope: {
1009 $on: function() { } 1049 $on: function() { }
1010 }, 1050 },
1011 focaSeguimientoService: {}, 1051 focaSeguimientoService: {},
1012 APP: {}, 1052 APP: {},
1013 focaLoginService: {} 1053 focaLoginService: {},
1054 $localStorage: {},
1055 $watch: function() { }
1014 }); 1056 });
1015 1057
1016 scope.notaPedido = {}; 1058 scope.notaPedido = {};
1017 1059
1018 var respuesta = { result: {then: function() { } } }; 1060 var respuesta = { result: {then: function() { } } };
1019 1061
1020 //act 1062 //act
1021 spyOn(uibModal, 'open').and.returnValue(respuesta); 1063 spyOn(uibModal, 'open').and.returnValue(respuesta);
1022 scope.seleccionarFlete(); 1064 scope.seleccionarFlete();
1023 1065
1024 //assert 1066 //assert
1025 expect(uibModal.open).toHaveBeenCalled(); 1067 expect(uibModal.open).toHaveBeenCalled();
1026 }); 1068 });
1027 1069
1028 it('función seleccionarFlete setea flete y cabecera', function(done) { 1070 it('función seleccionarFlete setea flete y cabecera', function(done) {
1029 1071
1030 //arrange 1072 //arrange
1031 var scope = {}; 1073 var scope = {};
1032 var uibModal = { 1074 var uibModal = {
1033 open: function() { } 1075 open: function() { }
1034 }; 1076 };
1035 1077
1036 $controler('notaPedidoCtrl', { 1078 $controler('notaPedidoCtrl', {
1037 $scope: scope, 1079 $scope: scope,
1038 $uibModal: uibModal, 1080 $uibModal: uibModal,
1039 $location: {}, 1081 $location: {},
1040 $filter: filter, 1082 $filter: filter,
1041 $timeout: timeout, 1083 $timeout: timeout,
1042 crearNotaPedidoService: { 1084 crearNotaPedidoService: {
1043 getBotonera: function() { }, 1085 getBotonera: function() { },
1044 getCotizacionByIdMoneda: function() { 1086 getCotizacionByIdMoneda: function() {
1045 return { 1087 return {
1046 then: function() { } 1088 then: function() { }
1047 }; 1089 };
1048 } 1090 }
1049 }, 1091 },
1050 focaBotoneraLateralService: {}, 1092 focaBotoneraLateralService: {},
1051 focaModalService: {}, 1093 focaModalService: {},
1052 notaPedidoBusinessService: {}, 1094 notaPedidoBusinessService: {},
1053 $rootScope: { 1095 $rootScope: {
1054 $on: function() { } 1096 $on: function() { }
1055 }, 1097 },
1056 focaSeguimientoService: {}, 1098 focaSeguimientoService: {},
1057 APP: {}, 1099 APP: {},
1058 focaLoginService: {} 1100 focaLoginService: {},
1101 $localStorage: {},
1102 $watch: function() { }
1059 }); 1103 });
1060 scope.idLista = true; 1104 scope.idLista = true;
1061 scope.notaPedido = { 1105 scope.notaPedido = {
1062 vendedor: { NUM: true } 1106 vendedor: { NUM: true }
1063 }; 1107 };
1064 var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 }; 1108 var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 };
1065 var promesaRespuesta = { result: Promise.resolve(respuesta) }; 1109 var promesaRespuesta = { result: Promise.resolve(respuesta) };
1066 scope.$broadcast = function() { }; 1110 scope.$broadcast = function() { };
1067 1111
1068 //act 1112 //act
1069 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); 1113 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
1070 spyOn(scope, '$broadcast'); 1114 spyOn(scope, '$broadcast');
1071 scope.seleccionarFlete(); 1115 scope.seleccionarFlete();
1072 1116
1073 //assert 1117 //assert
1074 1118
1075 promesaRespuesta.result.then(function() { 1119 promesaRespuesta.result.then(function() {
1076 expect(scope.notaPedido.flete).toEqual(respuesta.flete); 1120 expect(scope.notaPedido.flete).toEqual(respuesta.flete);
1077 expect(scope.notaPedido.fob).toEqual(respuesta.FOB); 1121 expect(scope.notaPedido.fob).toEqual(respuesta.FOB);
1078 expect(scope.notaPedido.bomba).toEqual(respuesta.bomba); 1122 expect(scope.notaPedido.bomba).toEqual(respuesta.bomba);
1079 expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros); 1123 expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros);
1080 expect(scope.$broadcast).toHaveBeenCalled(); 1124 expect(scope.$broadcast).toHaveBeenCalled();
1081 done(); 1125 done();
1082 }); 1126 });
1083 }); 1127 });
1084 1128
1085 it('función seleccionarMoneda abre modal', function() { 1129 it('función seleccionarMoneda abre modal', function() {
1086 //arrange 1130 //arrange
1087 var scope = {}; 1131 var scope = {};
1088 var focaModalService = { 1132 var focaModalService = {
1089 modal: function() { } 1133 modal: function() { }
1090 }; 1134 };
1091 1135
1092 $controler('notaPedidoCtrl', { 1136 $controler('notaPedidoCtrl', {
1093 $scope: scope, 1137 $scope: scope,
1094 $uibModal: {}, 1138 $uibModal: {},
1095 $location: {}, 1139 $location: {},
1096 $filter: filter, 1140 $filter: filter,
1097 $timeout: timeout, 1141 $timeout: timeout,
1098 crearNotaPedidoService: { 1142 crearNotaPedidoService: {
1099 getBotonera: function() { }, 1143 getBotonera: function() { },
1100 getCotizacionByIdMoneda: function() { 1144 getCotizacionByIdMoneda: function() {
1101 return { 1145 return {
1102 then: function() { } 1146 then: function() { }
1103 }; 1147 };
1104 } 1148 }
1105 }, 1149 },
1106 focaBotoneraLateralService: {}, 1150 focaBotoneraLateralService: {},
1107 focaModalService: focaModalService, 1151 focaModalService: focaModalService,
1108 notaPedidoBusinessService: {}, 1152 notaPedidoBusinessService: {},
1109 $rootScope: { 1153 $rootScope: {
1110 $on: function() { } 1154 $on: function() { }
1111 }, 1155 },
1112 focaSeguimientoService: {}, 1156 focaSeguimientoService: {},
1113 APP: {}, 1157 APP: {},
1114 focaLoginService: {} 1158 focaLoginService: {},
1159 $localStorage: {},
1160 $watch: function() { }
1115 }); 1161 });
1116 scope.notaPedido = {}; 1162 scope.notaPedido = {};
1117 1163
1118 var respuesta = { then: function() { } }; 1164 var respuesta = { then: function() { } };
1119 1165
1120 //act 1166 //act
1121 spyOn(focaModalService, 'modal').and.returnValue(respuesta); 1167 spyOn(focaModalService, 'modal').and.returnValue(respuesta);
1122 scope.seleccionarMoneda(); 1168 scope.seleccionarMoneda();
1123 1169
1124 //assert 1170 //assert
1125 expect(focaModalService.modal).toHaveBeenCalled(); 1171 expect(focaModalService.modal).toHaveBeenCalled();
1126 }); 1172 });
1127 1173
1128 it('función seleccionarMoneda llama Modal Cotizacion', function(done) { 1174 it('función seleccionarMoneda llama Modal Cotizacion', function(done) {
1129 //arrange 1175 //arrange
1130 var scope = {}; 1176 var scope = {};
1131 var focaModalService = { 1177 var focaModalService = {
1132 modal: function() { } 1178 modal: function() { }
1133 }; 1179 };
1134 1180
1135 $controler('notaPedidoCtrl', { 1181 $controler('notaPedidoCtrl', {
1136 $scope: scope, 1182 $scope: scope,
1137 $uibModal: {}, 1183 $uibModal: {},
1138 $location: {}, 1184 $location: {},
1139 $filter: filter, 1185 $filter: filter,
1140 $timeout: timeout, 1186 $timeout: timeout,
1141 crearNotaPedidoService: { 1187 crearNotaPedidoService: {
1142 getBotonera: function() { }, 1188 getBotonera: function() { },
1143 getCotizacionByIdMoneda: function() { 1189 getCotizacionByIdMoneda: function() {
1144 return { 1190 return {
1145 then: function() { } 1191 then: function() { }
1146 }; 1192 };
1147 } 1193 }
1148 }, 1194 },
1149 focaBotoneraLateralService: {}, 1195 focaBotoneraLateralService: {},
1150 focaModalService: focaModalService, 1196 focaModalService: focaModalService,
1151 notaPedidoBusinessService: {}, 1197 notaPedidoBusinessService: {},
1152 $rootScope: { 1198 $rootScope: {
1153 $on: function() { } 1199 $on: function() { }
1154 }, 1200 },
1155 focaSeguimientoService: {}, 1201 focaSeguimientoService: {},
1156 APP: {}, 1202 APP: {},
1157 focaLoginService: {} 1203 focaLoginService: {},
1204 $localStorage: {},
1205 $watch: function() { }
1158 }); 1206 });
1159 1207
1160 scope.notaPedido = {}; 1208 scope.notaPedido = {};
1161 var respuesta = 'test'; 1209 var respuesta = 'test';
1162 var promesaRespuesta = Promise.resolve(respuesta); 1210 var promesaRespuesta = Promise.resolve(respuesta);
1163 1211
1164 //act 1212 //act
1165 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); 1213 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta);
1166 spyOn(scope, 'abrirModalCotizacion'); 1214 spyOn(scope, 'abrirModalCotizacion');
1167 scope.seleccionarMoneda(); 1215 scope.seleccionarMoneda();
1168 1216
1169 //assert 1217 //assert
1170 promesaRespuesta.then(function() { 1218 promesaRespuesta.then(function() {
1171 expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test'); 1219 expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test');
1172 done(); 1220 done();
1173 }); 1221 });
1174 }); 1222 });
1175 1223
1176 it('función seleccionarObservaciones llama a prompt', function() { 1224 it('función seleccionarObservaciones llama a prompt', function() {
1177 1225
1178 //arrange 1226 //arrange
1179 var scope = {}; 1227 var scope = {};
1180 var focaModalService = { 1228 var focaModalService = {
1181 prompt: function() { } 1229 prompt: function() { }
1182 }; 1230 };
1183 1231
1184 $controler('notaPedidoCtrl', { 1232 $controler('notaPedidoCtrl', {
1185 $scope: scope, 1233 $scope: scope,
1186 $uibModal: {}, 1234 $uibModal: {},
1187 $location: {}, 1235 $location: {},
1188 $filter: filter, 1236 $filter: filter,
1189 $timeout: timeout, 1237 $timeout: timeout,
1190 crearNotaPedidoService: { 1238 crearNotaPedidoService: {
1191 getBotonera: function() { }, 1239 getBotonera: function() { },
1192 getCotizacionByIdMoneda: function() { 1240 getCotizacionByIdMoneda: function() {
1193 return { 1241 return {
1194 then: function() { } 1242 then: function() { }
1195 }; 1243 };
1196 } 1244 }
1197 }, 1245 },
1198 focaBotoneraLateralService: {}, 1246 focaBotoneraLateralService: {},
1199 focaModalService: focaModalService, 1247 focaModalService: focaModalService,
1200 notaPedidoBusinessService: {}, 1248 notaPedidoBusinessService: {},
1201 $rootScope: { 1249 $rootScope: {
1202 $on: function() { } 1250 $on: function() { }
1203 }, 1251 },
1204 focaSeguimientoService: {}, 1252 focaSeguimientoService: {},
1205 APP: {}, 1253 APP: {},
1206 focaLoginService: {} 1254 focaLoginService: {},
1255 $localStorage: {},
1256 $watch: function() { }
1207 }); 1257 });
1208 var respuesta = { then: function() { } }; 1258 var respuesta = { then: function() { } };
1209 scope.notaPedido = {}; 1259 scope.notaPedido = {};
1210 1260
1211 //act 1261 //act
1212 spyOn(focaModalService, 'prompt').and.returnValue(respuesta); 1262 spyOn(focaModalService, 'prompt').and.returnValue(respuesta);
1213 scope.seleccionarObservaciones(); 1263 scope.seleccionarObservaciones();
1214 1264
1215 //assert 1265 //assert
1216 expect(focaModalService.prompt).toHaveBeenCalled(); 1266 expect(focaModalService.prompt).toHaveBeenCalled();
1217 }); 1267 });
1218 1268
1219 it('función seleccionarObservaciones setea observaciones', function(done) { 1269 it('función seleccionarObservaciones setea observaciones', function(done) {
1220 1270
1221 //arrange 1271 //arrange
1222 var scope = {}; 1272 var scope = {};
1223 var focaModalService = { 1273 var focaModalService = {
1224 prompt: function() { } 1274 prompt: function() { }
1225 }; 1275 };
1226 1276
1227 $controler('notaPedidoCtrl', { 1277 $controler('notaPedidoCtrl', {
1228 $scope: scope, 1278 $scope: scope,
1229 $uibModal: {}, 1279 $uibModal: {},
1230 $location: {}, 1280 $location: {},
1231 $filter: filter, 1281 $filter: filter,
1232 $timeout: timeout, 1282 $timeout: timeout,
1233 crearNotaPedidoService: { 1283 crearNotaPedidoService: {
1234 getBotonera: function() { }, 1284 getBotonera: function() { },
1235 getCotizacionByIdMoneda: function() { 1285 getCotizacionByIdMoneda: function() {
1236 return { 1286 return {
1237 then: function() { } 1287 then: function() { }
1238 }; 1288 };
1239 } 1289 }
1240 }, 1290 },
1241 focaBotoneraLateralService: {}, 1291 focaBotoneraLateralService: {},
1242 focaModalService: focaModalService, 1292 focaModalService: focaModalService,
1243 notaPedidoBusinessService: {}, 1293 notaPedidoBusinessService: {},
1244 $rootScope: { 1294 $rootScope: {
1245 $on: function() { } 1295 $on: function() { }
1246 }, 1296 },
1247 focaSeguimientoService: {}, 1297 focaSeguimientoService: {},
1248 APP: {}, 1298 APP: {},
1249 focaLoginService: {} 1299 focaLoginService: {},
1300 $localStorage: {},
1301 $watch: function() { }
1250 }); 1302 });
1251 var respuesta = 'unit test'; 1303 var respuesta = 'unit test';
1252 var promesa = Promise.resolve(respuesta); 1304 var promesa = Promise.resolve(respuesta);
1253 scope.notaPedido = {}; 1305 scope.notaPedido = {};
1254 1306
1255 //act 1307 //act
1256 spyOn(focaModalService, 'prompt').and.returnValue(promesa); 1308 spyOn(focaModalService, 'prompt').and.returnValue(promesa);
1257 scope.seleccionarObservaciones(); 1309 scope.seleccionarObservaciones();
1258 1310
1259 //assert 1311 //assert
1260 promesa.then(function() { 1312 promesa.then(function() {
1261 expect(scope.notaPedido.observaciones).toEqual(respuesta); 1313 expect(scope.notaPedido.observaciones).toEqual(respuesta);
1262 done(); 1314 done();
1263 }); 1315 });
1264 }); 1316 });
1265 1317
1266 it('función abrirModalCotizacion abre modal', function() { 1318 it('función abrirModalCotizacion abre modal', function() {
1267 1319
1268 //arrange 1320 //arrange
1269 var scope = {}; 1321 var scope = {};
1270 var uibModal = { 1322 var uibModal = {
1271 open: function() { } 1323 open: function() { }
1272 }; 1324 };
1273 1325
1274 $controler('notaPedidoCtrl', { 1326 $controler('notaPedidoCtrl', {
1275 $scope: scope, 1327 $scope: scope,
1276 $uibModal: uibModal, 1328 $uibModal: uibModal,
1277 $location: {}, 1329 $location: {},
1278 $filter: filter, 1330 $filter: filter,
1279 $timeout: timeout, 1331 $timeout: timeout,
1280 crearNotaPedidoService: { 1332 crearNotaPedidoService: {
1281 getBotonera: function() { }, 1333 getBotonera: function() { },
1282 getCotizacionByIdMoneda: function() { 1334 getCotizacionByIdMoneda: function() {
1283 return { 1335 return {
1284 then: function() { } 1336 then: function() { }
1285 }; 1337 };
1286 } 1338 }
1287 }, 1339 },
1288 focaBotoneraLateralService: {}, 1340 focaBotoneraLateralService: {},
1289 focaModalService: {}, 1341 focaModalService: {},
1290 notaPedidoBusinessService: {}, 1342 notaPedidoBusinessService: {},
1291 $rootScope: { 1343 $rootScope: {
1292 $on: function() { } 1344 $on: function() { }
1293 }, 1345 },
1294 focaSeguimientoService: {}, 1346 focaSeguimientoService: {},
1295 APP: {}, 1347 APP: {},
1296 focaLoginService: {} 1348 focaLoginService: {},
1349 $localStorage: {},
1350 $watch: function() { }
1297 }); 1351 });
1298 1352
1299 scope.notaPedido = {}; 1353 scope.notaPedido = {};
1300 1354
1301 var respuesta = { result: {then: function() { } } }; 1355 var respuesta = { result: {then: function() { } } };
1302 1356
1303 //act 1357 //act
1304 spyOn(uibModal, 'open').and.returnValue(respuesta); 1358 spyOn(uibModal, 'open').and.returnValue(respuesta);
1305 scope.abrirModalCotizacion(); 1359 scope.abrirModalCotizacion();
1306 1360
1307 //assert 1361 //assert
1308 expect(uibModal.open).toHaveBeenCalled(); 1362 expect(uibModal.open).toHaveBeenCalled();
1309 }); 1363 });
1310 1364
1311 it('función abrirModalCotizacion setea datos y cabecera', function(done) { 1365 it('función abrirModalCotizacion setea datos y cabecera', function(done) {
1312 //arrange 1366 //arrange
1313 var scope = {}; 1367 var scope = {};
1314 var uibModal = { 1368 var uibModal = {
1315 open: function() { } 1369 open: function() { }
1316 }; 1370 };
1317 1371
1318 $controler('notaPedidoCtrl', { 1372 $controler('notaPedidoCtrl', {
1319 $scope: scope, 1373 $scope: scope,
1320 $uibModal: uibModal, 1374 $uibModal: uibModal,
1321 $location: {}, 1375 $location: {},
1322 $filter: filter, 1376 $filter: filter,
1323 $timeout: timeout, 1377 $timeout: timeout,
1324 crearNotaPedidoService: { 1378 crearNotaPedidoService: {
1325 getBotonera: function() { }, 1379 getBotonera: function() { },
1326 getCotizacionByIdMoneda: function() { 1380 getCotizacionByIdMoneda: function() {
1327 return { 1381 return {
1328 then: function() { } 1382 then: function() { }
1329 }; 1383 };
1330 } 1384 }
1331 }, 1385 },
1332 focaBotoneraLateralService: {}, 1386 focaBotoneraLateralService: {},
1333 focaModalService: {}, 1387 focaModalService: {},
1334 notaPedidoBusinessService: {}, 1388 notaPedidoBusinessService: {},
1335 $rootScope: { 1389 $rootScope: {
1336 $on: function() { } 1390 $on: function() { }
1337 }, 1391 },
1338 focaSeguimientoService: {}, 1392 focaSeguimientoService: {},
1339 APP: {}, 1393 APP: {},
1340 focaLoginService: {} 1394 focaLoginService: {},
1395 $localStorage: {},
1396 $watch: function() { }
1341 }); 1397 });
1342 1398
1343 scope.notaPedido = {}; 1399 scope.notaPedido = {};
1344 scope.articulosTabla = []; 1400 scope.articulosTabla = [];
1345 scope.$broadcast = function() { }; 1401 scope.$broadcast = function() { };
1346 var moneda = 'moneda'; 1402 var moneda = 'moneda';
1347 var cotizacion = 'test'; 1403 var cotizacion = 'test';
1348 var promesaRespuesta = { result: Promise.resolve(cotizacion) }; 1404 var promesaRespuesta = { result: Promise.resolve(cotizacion) };
1349 1405
1350 //act 1406 //act
1351 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); 1407 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
1352 spyOn(scope, '$broadcast'); 1408 spyOn(scope, '$broadcast');
1353 scope.abrirModalCotizacion(moneda); 1409 scope.abrirModalCotizacion(moneda);
1354 1410
1355 //assert 1411 //assert
1356 promesaRespuesta.result.then(function() { 1412 promesaRespuesta.result.then(function() {
1357 1413
1358 expect(scope.$broadcast).toHaveBeenCalled(); 1414 expect(scope.$broadcast).toHaveBeenCalled();
1359 expect(scope.notaPedido.moneda).toEqual(moneda); 1415 expect(scope.notaPedido.moneda).toEqual(moneda);
1360 expect(scope.monedaDefecto).toEqual(moneda); 1416 expect(scope.monedaDefecto).toEqual(moneda);
1361 expect(scope.cotizacionDefecto).toEqual(cotizacion); 1417 expect(scope.cotizacionDefecto).toEqual(cotizacion);
1362 expect(scope.notaPedido.cotizacion).toEqual(cotizacion); 1418 expect(scope.notaPedido.cotizacion).toEqual(cotizacion);
1363 done(); 1419 done();
1364 }); 1420 });
1365 }); 1421 });
1366 1422
1367 it('función agregarATabla muestra alerta cuando a cargar undefined', function() { 1423 it('función agregarATabla muestra alerta cuando a cargar undefined', function() {
1368 1424
1369 //arrange 1425 //arrange
1370 var scope = {}; 1426 var scope = {};
1371 var focaModalService = { 1427 var focaModalService = {
1372 alert: function() { } 1428 alert: function() { }
1373 }; 1429 };
1374 1430
1375 $controler('notaPedidoCtrl', { 1431 $controler('notaPedidoCtrl', {
1376 $scope: scope, 1432 $scope: scope,
1377 $uibModal: {}, 1433 $uibModal: {},
1378 $location: {}, 1434 $location: {},
1379 $filter: filter, 1435 $filter: filter,
1380 $timeout: timeout, 1436 $timeout: timeout,
1381 crearNotaPedidoService: { 1437 crearNotaPedidoService: {
1382 getBotonera: function() { }, 1438 getBotonera: function() { },
1383 getCotizacionByIdMoneda: function() { 1439 getCotizacionByIdMoneda: function() {
1384 return { 1440 return {
1385 then: function() { } 1441 then: function() { }
1386 }; 1442 };
1387 } 1443 }
1388 }, 1444 },
1389 focaBotoneraLateralService: {}, 1445 focaBotoneraLateralService: {},
1390 focaModalService: focaModalService, 1446 focaModalService: focaModalService,
1391 notaPedidoBusinessService: {}, 1447 notaPedidoBusinessService: {},
1392 $rootScope: { 1448 $rootScope: {
1393 $on: function() { } 1449 $on: function() { }
1394 }, 1450 },
1395 focaSeguimientoService: {}, 1451 focaSeguimientoService: {},
1396 APP: {}, 1452 APP: {},
1397 focaLoginService: {} 1453 focaLoginService: {},
1454 $localStorage: {},
1455 $watch: function() { }
1398 }); 1456 });
1399 scope.articuloACargar = {}; 1457 scope.articuloACargar = {};
1400 1458
1401 //act 1459 //act
1402 spyOn(focaModalService, 'alert'); 1460 spyOn(focaModalService, 'alert');
1403 scope.agregarATabla(13); 1461 scope.agregarATabla(13);
1404 1462
1405 //assert 1463 //assert
1406 expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); 1464 expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1');
1407 }); 1465 });
1408 1466
1409 it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { 1467 it('función editarArticulo muestra alerta cuando a cargar es undefined', function() {
1410 1468
1411 //arrange 1469 //arrange
1412 var scope = {}; 1470 var scope = {};
1413 var focaModalService = { 1471 var focaModalService = {
1414 alert: function() { } 1472 alert: function() { }
1415 }; 1473 };
1416 1474
1417 $controler('notaPedidoCtrl', { 1475 $controler('notaPedidoCtrl', {
1418 $scope: scope, 1476 $scope: scope,
1419 $uibModal: {}, 1477 $uibModal: {},
1420 $location: {}, 1478 $location: {},
1421 $filter: filter, 1479 $filter: filter,
1422 $timeout: timeout, 1480 $timeout: timeout,
1423 crearNotaPedidoService: { 1481 crearNotaPedidoService: {
1424 getBotonera: function() { }, 1482 getBotonera: function() { },
1425 getCotizacionByIdMoneda: function() { 1483 getCotizacionByIdMoneda: function() {
1426 return { 1484 return {
1427 then: function() { } 1485 then: function() { }
1428 }; 1486 };
1429 } 1487 }
1430 }, 1488 },
1431 focaBotoneraLateralService: {}, 1489 focaBotoneraLateralService: {},
1432 focaModalService: focaModalService, 1490 focaModalService: focaModalService,
1433 notaPedidoBusinessService: {}, 1491 notaPedidoBusinessService: {},
1434 $rootScope: { 1492 $rootScope: {
1435 $on: function() { } 1493 $on: function() { }
1436 }, 1494 },
1437 focaSeguimientoService: {}, 1495 focaSeguimientoService: {},
1438 APP: {}, 1496 APP: {},
1439 focaLoginService: {} 1497 focaLoginService: {},
1498 $localStorage: {},
1499 $watch: function() { }
1440 }); 1500 });
1441 scope.articuloACargar = {}; 1501 scope.articuloACargar = {};
1442 1502
1443 //act 1503 //act
1444 spyOn(focaModalService, 'alert'); 1504 spyOn(focaModalService, 'alert');
1445 scope.agregarATabla(13); 1505 scope.agregarATabla(13);
1446 1506
1447 //assert 1507 //assert
1448 expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); 1508 expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1');
1449 }); 1509 });
1450 1510
1451 it('función salir lleva a ruta correcta', function() { 1511 it('función salir lleva a ruta correcta', function() {
1452 1512
1453 inject(function($location) { 1513 inject(function($location) {
1454 1514
1455 //arrange 1515 //arrange
1456 var scope = {}; 1516 var scope = {};
1457 1517
1458 $controler('notaPedidoCtrl', { 1518 $controler('notaPedidoCtrl', {
1459 $scope: scope, 1519 $scope: scope,
1460 $uibModal: {}, 1520 $uibModal: {},
1461 $location: $location, 1521 $location: $location,
1462 $filter: filter, 1522 $filter: filter,
1463 $timeout: timeout, 1523 $timeout: timeout,
1464 crearNotaPedidoService: { 1524 crearNotaPedidoService: {
1465 getBotonera: function() { }, 1525 getBotonera: function() { },
1466 getCotizacionByIdMoneda: function() { 1526 getCotizacionByIdMoneda: function() {
1467 return { 1527 return {
1468 then: function() { } 1528 then: function() { }
1469 }; 1529 };
1470 } 1530 }
1471 }, 1531 },
1472 focaBotoneraLateralService: {}, 1532 focaBotoneraLateralService: {},
1473 focaModalService: {}, 1533 focaModalService: {},
1474 notaPedidoBusinessService: {}, 1534 notaPedidoBusinessService: {},
1475 $rootScope: { 1535 $rootScope: {
1476 $on: function() { } 1536 $on: function() { }
1477 }, 1537 },
1478 focaSeguimientoService: {}, 1538 focaSeguimientoService: {},
1479 APP: {}, 1539 APP: {},
1480 focaLoginService: {} 1540 focaLoginService: {},
1541 $localStorage: {},
1542 $watch: function() { }
1481 }); 1543 });
1482 1544
1483 //act 1545 //act
1484 scope.salir(); 1546 scope.salir();
1485 1547
1486 //assert 1548 //assert
1487 expect($location.url()).toEqual('/'); 1549 expect($location.url()).toEqual('/');
1488 }); 1550 });
1489 }); 1551 });
1490 }); 1552 });
1491 }); 1553 });
1492 1554
spec/controllerSpecCrearPedido.js
1 describe('Controladores módulo crear nota de pedido', function() { 1 describe('Controladores módulo crear nota de pedido', function() {
2 2
3 var $controler; 3 var $controler;
4 4
5 beforeEach(function() { 5 beforeEach(function() {
6 module('focaCrearNotaPedido'); 6 module('focaCrearNotaPedido');
7 inject(function(_$controller_) { 7 inject(function(_$controller_) {
8 $controler = _$controller_; 8 $controler = _$controller_;
9 }); 9 });
10 }); 10 });
11 11
12 describe('Controlador notaPedidoCtrl crear nota de pedido', function() { 12 describe('Controlador notaPedidoCtrl crear nota de pedido', function() {
13 13
14 var filter = function() { 14 var filter = function() {
15 return function() { }; 15 return function() { };
16 }; 16 };
17 var timeout; 17 var timeout;
18 18
19 beforeEach(function() { 19 beforeEach(function() {
20 20
21 inject(function($timeout) { 21 inject(function($timeout) {
22 timeout = $timeout; 22 timeout = $timeout;
23 }); 23 });
24 }); 24 });
25 25
26 it('Existe el controlador notaPedidoCtrl', function() { 26 it('Existe el controlador notaPedidoCtrl', function() {
27 27
28 //act 28 //act
29 var controlador = $controler('notaPedidoCtrl', { 29 var controlador = $controler('notaPedidoCtrl', {
30 $scope: {}, 30 $scope: {},
31 $uibModal: {}, 31 $uibModal: {},
32 $location: {}, 32 $location: {},
33 $filter: filter, 33 $filter: filter,
34 $timeout: timeout, 34 $timeout: timeout,
35 crearNotaPedidoService: { 35 crearNotaPedidoService: {
36 getBotonera: function() { }, 36 getBotonera: function() { },
37 getCotizacionByIdMoneda: function() { 37 getCotizacionByIdMoneda: function() {
38 return { 38 return {
39 then: function() {} 39 then: function() {}
40 }; 40 };
41 } 41 }
42 }, 42 },
43 focaBotoneraLateralService: {}, 43 focaBotoneraLateralService: {},
44 focaModalService: {}, 44 focaModalService: {},
45 notaPedidoBusinessService: {}, 45 notaPedidoBusinessService: {},
46 $rootScope: { 46 $rootScope: {
47 $on: function() { } 47 $on: function() { }
48 }, 48 },
49 focaSeguimientoService: {}, 49 focaSeguimientoService: {},
50 APP: {}, 50 APP: {},
51 focaLoginService: {} 51 focaLoginService: {},
52 $localStorage: {},
53 $watch: function() { }
52 }); 54 });
53 55
54 //expect 56 //expect
55 expect(typeof controlador).toEqual('object'); 57 expect(typeof controlador).toEqual('object');
56 }); 58 });
57 59
58 it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() { 60 it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() {
59 61
60 //arrange 62 //arrange
61 var scope = {}; 63 var scope = {};
62 var focaModalService = { 64 var focaModalService = {
63 alert: function() { } 65 alert: function() { }
64 }; 66 };
65 67
66 $controler('notaPedidoCtrl', { 68 $controler('notaPedidoCtrl', {
67 $scope: scope, 69 $scope: scope,
68 $uibModal: {}, 70 $uibModal: {},
69 $location: {}, 71 $location: {},
70 $filter: filter, 72 $filter: filter,
71 $timeout: timeout, 73 $timeout: timeout,
72 crearNotaPedidoService: { 74 crearNotaPedidoService: {
73 getBotonera: function() { }, 75 getBotonera: function() { },
74 getCotizacionByIdMoneda: function() { 76 getCotizacionByIdMoneda: function() {
75 return { 77 return {
76 then: function() {} 78 then: function() {}
77 }; 79 };
78 } 80 }
79 }, 81 },
80 focaBotoneraLateralService: {}, 82 focaBotoneraLateralService: {},
81 focaModalService: focaModalService, 83 focaModalService: focaModalService,
82 notaPedidoBusinessService: {}, 84 notaPedidoBusinessService: {},
83 $rootScope: { 85 $rootScope: {
84 $on: function() { } 86 $on: function() { }
85 }, 87 },
86 focaSeguimientoService: {}, 88 focaSeguimientoService: {},
87 APP: {}, 89 APP: {},
88 focaLoginService: {} 90 focaLoginService: {},
91 $localStorage: {},
92 $watch: function() { }
89 }); 93 });
90 94
91 //act 95 //act
92 scope.notaPedido = { 96 scope.notaPedido = {
93 vendedor: { 97 vendedor: {
94 id: null 98 id: null
95 } 99 }
96 }; 100 };
97 spyOn(focaModalService, 'alert'); 101 spyOn(focaModalService, 'alert');
98 scope.crearNotaPedido(); 102 scope.crearNotaPedido();
99 103
100 //expect 104 //expect
101 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor'); 105 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor');
102 }); 106 });
103 107
104 it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() { 108 it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() {
105 109
106 //arrange 110 //arrange
107 var scope = {}; 111 var scope = {};
108 var focaModalService = { 112 var focaModalService = {
109 alert: function() { } 113 alert: function() { }
110 }; 114 };
111 115
112 $controler('notaPedidoCtrl', { 116 $controler('notaPedidoCtrl', {
113 $scope: scope, 117 $scope: scope,
114 $uibModal: {}, 118 $uibModal: {},
115 $location: {}, 119 $location: {},
116 $filter: filter, 120 $filter: filter,
117 $timeout: timeout, 121 $timeout: timeout,
118 crearNotaPedidoService: { 122 crearNotaPedidoService: {
119 getBotonera: function() { }, 123 getBotonera: function() { },
120 getCotizacionByIdMoneda: function() { 124 getCotizacionByIdMoneda: function() {
121 return { 125 return {
122 then: function() {} 126 then: function() {}
123 }; 127 };
124 } 128 }
125 }, 129 },
126 focaBotoneraLateralService: {}, 130 focaBotoneraLateralService: {},
127 focaModalService: focaModalService, 131 focaModalService: focaModalService,
128 notaPedidoBusinessService: {}, 132 notaPedidoBusinessService: {},
129 $rootScope: { 133 $rootScope: {
130 $on: function() { } 134 $on: function() { }
131 }, 135 },
132 focaSeguimientoService: {}, 136 focaSeguimientoService: {},
133 APP: {}, 137 APP: {},
134 focaLoginService: {} 138 focaLoginService: {},
139 $localStorage: {},
140 $watch: function() { }
135 }); 141 });
136 142
137 scope.notaPedido = { 143 scope.notaPedido = {
138 vendedor: { 144 vendedor: {
139 id: true 145 id: true
140 }, 146 },
141 cliente:{ 147 cliente:{
142 COD: false 148 COD: false
143 } 149 }
144 }; 150 };
145 151
146 //act 152 //act
147 spyOn(focaModalService, 'alert'); 153 spyOn(focaModalService, 'alert');
148 scope.crearNotaPedido(); 154 scope.crearNotaPedido();
149 155
150 //expect 156 //expect
151 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); 157 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente');
152 }); 158 });
153 159
154 it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() { 160 it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() {
155 161
156 //arrange 162 //arrange
157 var scope = {}; 163 var scope = {};
158 var focaModalService = { 164 var focaModalService = {
159 alert: function() { } 165 alert: function() { }
160 }; 166 };
161 167
162 $controler('notaPedidoCtrl', { 168 $controler('notaPedidoCtrl', {
163 $scope: scope, 169 $scope: scope,
164 $uibModal: {}, 170 $uibModal: {},
165 $location: {}, 171 $location: {},
166 $filter: filter, 172 $filter: filter,
167 $timeout: timeout, 173 $timeout: timeout,
168 crearNotaPedidoService: { 174 crearNotaPedidoService: {
169 getBotonera: function() { }, 175 getBotonera: function() { },
170 getCotizacionByIdMoneda: function() { 176 getCotizacionByIdMoneda: function() {
171 return { 177 return {
172 then: function() {} 178 then: function() {}
173 }; 179 };
174 } 180 }
175 }, 181 },
176 focaBotoneraLateralService: {}, 182 focaBotoneraLateralService: {},
177 focaModalService: focaModalService, 183 focaModalService: focaModalService,
178 notaPedidoBusinessService: {}, 184 notaPedidoBusinessService: {},
179 $rootScope: { 185 $rootScope: {
180 $on: function() { } 186 $on: function() { }
181 }, 187 },
182 focaSeguimientoService: {}, 188 focaSeguimientoService: {},
183 APP: {}, 189 APP: {},
184 focaLoginService: {} 190 focaLoginService: {},
191 $localStorage: {},
192 $watch: function() { }
185 }); 193 });
186 194
187 scope.notaPedido = { 195 scope.notaPedido = {
188 vendedor: { 196 vendedor: {
189 id: true 197 id: true
190 }, 198 },
191 cliente:{ 199 cliente:{
192 COD: true 200 COD: true
193 }, 201 },
194 proveedor:{ 202 proveedor:{
195 COD: null 203 COD: null
196 } 204 }
197 }; 205 };
198 206
199 //act 207 //act
200 spyOn(focaModalService, 'alert'); 208 spyOn(focaModalService, 'alert');
201 scope.crearNotaPedido(); 209 scope.crearNotaPedido();
202 210
203 //expect 211 //expect
204 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor'); 212 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor');
205 }); 213 });
206 214
207 it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() { 215 it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() {
208 216
209 //arrange 217 //arrange
210 var scope = {}; 218 var scope = {};
211 var focaModalService = { 219 var focaModalService = {
212 alert: function() { } 220 alert: function() { }
213 }; 221 };
214 222
215 $controler('notaPedidoCtrl', { 223 $controler('notaPedidoCtrl', {
216 $scope: scope, 224 $scope: scope,
217 $uibModal: {}, 225 $uibModal: {},
218 $location: {}, 226 $location: {},
219 $filter: filter, 227 $filter: filter,
220 $timeout: timeout, 228 $timeout: timeout,
221 crearNotaPedidoService: { 229 crearNotaPedidoService: {
222 getBotonera: function() { }, 230 getBotonera: function() { },
223 getCotizacionByIdMoneda: function() { 231 getCotizacionByIdMoneda: function() {
224 return { 232 return {
225 then: function() {} 233 then: function() {}
226 }; 234 };
227 } 235 }
228 }, 236 },
229 focaBotoneraLateralService: {}, 237 focaBotoneraLateralService: {},
230 focaModalService: focaModalService, 238 focaModalService: focaModalService,
231 notaPedidoBusinessService: {}, 239 notaPedidoBusinessService: {},
232 $rootScope: { 240 $rootScope: {
233 $on: function() { } 241 $on: function() { }
234 }, 242 },
235 focaSeguimientoService: {}, 243 focaSeguimientoService: {},
236 APP: {}, 244 APP: {},
237 focaLoginService: {} 245 focaLoginService: {},
246 $localStorage: {},
247 $watch: function() { }
238 }); 248 });
239 249
240 scope.notaPedido = { 250 scope.notaPedido = {
241 vendedor: { 251 vendedor: {
242 id: true 252 id: true
243 }, 253 },
244 cliente:{ 254 cliente:{
245 COD: true 255 COD: true
246 }, 256 },
247 proveedor:{ 257 proveedor:{
248 COD: true 258 COD: true
249 }, 259 },
250 moneda:{ 260 moneda:{
251 ID: null 261 ID: null
252 } 262 }
253 }; 263 };
254 264
255 //act 265 //act
256 spyOn(focaModalService, 'alert'); 266 spyOn(focaModalService, 'alert');
257 scope.crearNotaPedido(); 267 scope.crearNotaPedido();
258 268
259 //expect 269 //expect
260 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda'); 270 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda');
261 }); 271 });
262 272
263 it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() { 273 it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() {
264 274
265 //arrange 275 //arrange
266 var scope = {}; 276 var scope = {};
267 var focaModalService = { 277 var focaModalService = {
268 alert: function() { } 278 alert: function() { }
269 }; 279 };
270 280
271 $controler('notaPedidoCtrl', { 281 $controler('notaPedidoCtrl', {
272 $scope: scope, 282 $scope: scope,
273 $uibModal: {}, 283 $uibModal: {},
274 $location: {}, 284 $location: {},
275 $filter: filter, 285 $filter: filter,
276 $timeout: timeout, 286 $timeout: timeout,
277 crearNotaPedidoService: { 287 crearNotaPedidoService: {
278 getBotonera: function() { }, 288 getBotonera: function() { },
279 getCotizacionByIdMoneda: function() { 289 getCotizacionByIdMoneda: function() {
280 return { 290 return {
281 then: function() {} 291 then: function() {}
282 }; 292 };
283 } 293 }
284 }, 294 },
285 focaBotoneraLateralService: {}, 295 focaBotoneraLateralService: {},
286 focaModalService: focaModalService, 296 focaModalService: focaModalService,
287 notaPedidoBusinessService: {}, 297 notaPedidoBusinessService: {},
288 $rootScope: { 298 $rootScope: {
289 $on: function() { } 299 $on: function() { }
290 }, 300 },
291 focaSeguimientoService: {}, 301 focaSeguimientoService: {},
292 APP: {}, 302 APP: {},
293 focaLoginService: {} 303 focaLoginService: {},
304 $localStorage: {},
305 $watch: function() { }
294 }); 306 });
295 307
296 scope.notaPedido = { 308 scope.notaPedido = {
297 vendedor: { 309 vendedor: {
298 id: true 310 id: true
299 }, 311 },
300 cliente:{ 312 cliente:{
301 COD: true 313 COD: true
302 }, 314 },
303 proveedor:{ 315 proveedor:{
304 COD: true 316 COD: true
305 }, 317 },
306 moneda:{ 318 moneda:{
307 ID: true 319 ID: true
308 }, 320 },
309 cotizacion:{ 321 cotizacion:{
310 ID: null 322 ID: null
311 } 323 }
312 }; 324 };
313 325
314 //act 326 //act
315 spyOn(focaModalService, 'alert'); 327 spyOn(focaModalService, 'alert');
316 scope.crearNotaPedido(); 328 scope.crearNotaPedido();
317 329
318 //expect 330 //expect
319 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización'); 331 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización');
320 }); 332 });
321 333
322 it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() { 334 it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() {
323 335
324 //arrange 336 //arrange
325 var scope = {}; 337 var scope = {};
326 var focaModalService = { 338 var focaModalService = {
327 alert: function() { } 339 alert: function() { }
328 }; 340 };
329 341
330 $controler('notaPedidoCtrl', { 342 $controler('notaPedidoCtrl', {
331 $scope: scope, 343 $scope: scope,
332 $uibModal: {}, 344 $uibModal: {},
333 $location: {}, 345 $location: {},
334 $filter: filter, 346 $filter: filter,
335 $timeout: timeout, 347 $timeout: timeout,
336 crearNotaPedidoService: { 348 crearNotaPedidoService: {
337 getBotonera: function() { }, 349 getBotonera: function() { },
338 getCotizacionByIdMoneda: function() { 350 getCotizacionByIdMoneda: function() {
339 return { 351 return {
340 then: function() {} 352 then: function() {}
341 }; 353 };
342 } 354 }
343 }, 355 },
344 focaBotoneraLateralService: {}, 356 focaBotoneraLateralService: {},
345 focaModalService: focaModalService, 357 focaModalService: focaModalService,
346 notaPedidoBusinessService: {}, 358 notaPedidoBusinessService: {},
347 $rootScope: { 359 $rootScope: {
348 $on: function() { } 360 $on: function() { }
349 }, 361 },
350 focaSeguimientoService: {}, 362 focaSeguimientoService: {},
351 APP: {}, 363 APP: {},
352 focaLoginService: {} 364 focaLoginService: {},
365 $localStorage: {},
366 $watch: function() { }
353 }); 367 });
354 368
355 scope.notaPedido = { 369 scope.notaPedido = {
356 vendedor: { 370 vendedor: {
357 id: true 371 id: true
358 }, 372 },
359 cliente:{ 373 cliente:{
360 COD: true 374 COD: true
361 }, 375 },
362 proveedor:{ 376 proveedor:{
363 COD: true 377 COD: true
364 }, 378 },
365 moneda:{ 379 moneda:{
366 ID: true 380 ID: true
367 }, 381 },
368 cotizacion:{ 382 cotizacion:{
369 ID: true 383 ID: true
370 } 384 }
371 }; 385 };
372 386
373 scope.plazosPagos = null; 387 scope.plazosPagos = null;
374 388
375 //act 389 //act
376 spyOn(focaModalService, 'alert'); 390 spyOn(focaModalService, 'alert');
377 scope.crearNotaPedido(); 391 scope.crearNotaPedido();
378 392
379 //expect 393 //expect
380 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones'); 394 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones');
381 }); 395 });
382 396
383 it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() { 397 it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() {
384 398
385 //arrange 399 //arrange
386 var scope = {}; 400 var scope = {};
387 var focaModalService = { 401 var focaModalService = {
388 alert: function() { } 402 alert: function() { }
389 }; 403 };
390 404
391 $controler('notaPedidoCtrl', { 405 $controler('notaPedidoCtrl', {
392 $scope: scope, 406 $scope: scope,
393 $uibModal: {}, 407 $uibModal: {},
394 $location: {}, 408 $location: {},
395 $filter: filter, 409 $filter: filter,
396 $timeout: timeout, 410 $timeout: timeout,
397 crearNotaPedidoService: { 411 crearNotaPedidoService: {
398 getBotonera: function() { }, 412 getBotonera: function() { },
399 getCotizacionByIdMoneda: function() { 413 getCotizacionByIdMoneda: function() {
400 return { 414 return {
401 then: function() {} 415 then: function() {}
402 }; 416 };
403 } 417 }
404 }, 418 },
405 focaBotoneraLateralService: {}, 419 focaBotoneraLateralService: {},
406 focaModalService: focaModalService, 420 focaModalService: focaModalService,
407 notaPedidoBusinessService: {}, 421 notaPedidoBusinessService: {},
408 $rootScope: { 422 $rootScope: {
409 $on: function() { } 423 $on: function() { }
410 }, 424 },
411 focaSeguimientoService: {}, 425 focaSeguimientoService: {},
412 APP: {}, 426 APP: {},
413 focaLoginService: {} 427 focaLoginService: {},
428 $localStorage: {},
429 $watch: function() { }
414 }); 430 });
415 431
416 scope.notaPedido = { 432 scope.notaPedido = {
417 vendedor: { 433 vendedor: {
418 id: true 434 id: true
419 }, 435 },
420 cliente:{ 436 cliente:{
421 COD: true 437 COD: true
422 }, 438 },
423 proveedor:{ 439 proveedor:{
424 COD: true 440 COD: true
425 }, 441 },
426 moneda:{ 442 moneda:{
427 ID: true 443 ID: true
428 }, 444 },
429 cotizacion:{ 445 cotizacion:{
430 ID: true 446 ID: true
431 }, 447 },
432 flete: null 448 flete: null
433 }; 449 };
434 450
435 scope.plazosPagos = true; 451 scope.plazosPagos = true;
436 452
437 //act 453 //act
438 spyOn(focaModalService, 'alert'); 454 spyOn(focaModalService, 'alert');
439 scope.crearNotaPedido(); 455 scope.crearNotaPedido();
440 456
441 //expect 457 //expect
442 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete'); 458 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete');
443 }); 459 });
444 460
445 it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() { 461 it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() {
446 462
447 //arrange 463 //arrange
448 var scope = {}; 464 var scope = {};
449 var focaModalService = { 465 var focaModalService = {
450 alert: function() { } 466 alert: function() { }
451 }; 467 };
452 468
453 $controler('notaPedidoCtrl', { 469 $controler('notaPedidoCtrl', {
454 $scope: scope, 470 $scope: scope,
455 $uibModal: {}, 471 $uibModal: {},
456 $location: {}, 472 $location: {},
457 $filter: filter, 473 $filter: filter,
458 $timeout: timeout, 474 $timeout: timeout,
459 crearNotaPedidoService: { 475 crearNotaPedidoService: {
460 getBotonera: function() { }, 476 getBotonera: function() { },
461 getCotizacionByIdMoneda: function() { 477 getCotizacionByIdMoneda: function() {
462 return { 478 return {
463 then: function() {} 479 then: function() {}
464 }; 480 };
465 } 481 }
466 }, 482 },
467 focaBotoneraLateralService: {}, 483 focaBotoneraLateralService: {},
468 focaModalService: focaModalService, 484 focaModalService: focaModalService,
469 notaPedidoBusinessService: {}, 485 notaPedidoBusinessService: {},
470 $rootScope: { 486 $rootScope: {
471 $on: function() { } 487 $on: function() { }
472 }, 488 },
473 focaSeguimientoService: {}, 489 focaSeguimientoService: {},
474 APP: {}, 490 APP: {},
475 focaLoginService: {} 491 focaLoginService: {},
492 $localStorage: {},
493 $watch: function() { }
476 }); 494 });
477 495
478 scope.notaPedido = { 496 scope.notaPedido = {
479 vendedor: { 497 vendedor: {
480 id: true 498 id: true
481 }, 499 },
482 cliente:{ 500 cliente:{
483 COD: true 501 COD: true
484 }, 502 },
485 proveedor:{ 503 proveedor:{
486 COD: true 504 COD: true
487 }, 505 },
488 moneda:{ 506 moneda:{
489 ID: true 507 ID: true
490 }, 508 },
491 cotizacion:{ 509 cotizacion:{
492 ID: true 510 ID: true
493 }, 511 },
494 flete: true, 512 flete: true,
495 domicilioStamp: null 513 domicilioStamp: null
496 }; 514 };
497 515
498 scope.plazosPagos = true; 516 scope.plazosPagos = true;
499 517
500 //act 518 //act
501 spyOn(focaModalService, 'alert'); 519 spyOn(focaModalService, 'alert');
502 scope.crearNotaPedido(); 520 scope.crearNotaPedido();
503 521
504 //expect 522 //expect
505 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio'); 523 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio');
506 }); 524 });
507 525
508 it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos', 526 it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos',
509 function() 527 function()
510 { 528 {
511 529
512 //arrange 530 //arrange
513 var scope = {}; 531 var scope = {};
514 var focaModalService = { 532 var focaModalService = {
515 alert: function() { } 533 alert: function() { }
516 }; 534 };
517 535
518 $controler('notaPedidoCtrl', { 536 $controler('notaPedidoCtrl', {
519 $scope: scope, 537 $scope: scope,
520 $uibModal: {}, 538 $uibModal: {},
521 $location: {}, 539 $location: {},
522 $filter: filter, 540 $filter: filter,
523 $timeout: timeout, 541 $timeout: timeout,
524 crearNotaPedidoService: { 542 crearNotaPedidoService: {
525 getBotonera: function() { }, 543 getBotonera: function() { },
526 getCotizacionByIdMoneda: function() { 544 getCotizacionByIdMoneda: function() {
527 return { 545 return {
528 then: function() {} 546 then: function() {}
529 }; 547 };
530 } 548 }
531 }, 549 },
532 focaBotoneraLateralService: {}, 550 focaBotoneraLateralService: {},
533 focaModalService: focaModalService, 551 focaModalService: focaModalService,
534 notaPedidoBusinessService: {}, 552 notaPedidoBusinessService: {},
535 $rootScope: { 553 $rootScope: {
536 $on: function() { } 554 $on: function() { }
537 }, 555 },
538 focaSeguimientoService: {}, 556 focaSeguimientoService: {},
539 APP: {}, 557 APP: {},
540 focaLoginService: {} 558 focaLoginService: {},
559 $localStorage: {},
560 $watch: function() { }
541 }); 561 });
542 562
543 scope.notaPedido = { 563 scope.notaPedido = {
544 vendedor: { 564 vendedor: {
545 id: true 565 id: true
546 }, 566 },
547 cliente:{ 567 cliente:{
548 COD: true 568 COD: true
549 }, 569 },
550 proveedor:{ 570 proveedor:{
551 COD: true 571 COD: true
552 }, 572 },
553 moneda:{ 573 moneda:{
554 ID: true 574 ID: true
555 }, 575 },
556 cotizacion:{ 576 cotizacion:{
557 ID: true 577 ID: true
558 }, 578 },
559 flete: true, 579 flete: true,
560 domicilioStamp: true, 580 domicilioStamp: true,
561 }; 581 };
562 582
563 scope.plazosPagos = true; 583 scope.plazosPagos = true;
564 scope.articulosTabla = []; 584 scope.articulosTabla = [];
565 585
566 //act 586 //act
567 spyOn(focaModalService, 'alert'); 587 spyOn(focaModalService, 'alert');
568 scope.crearNotaPedido(); 588 scope.crearNotaPedido();
569 589
570 //expect 590 //expect
571 expect(focaModalService.alert) 591 expect(focaModalService.alert)
572 .toHaveBeenCalledWith('Debe cargar al menos un articulo'); 592 .toHaveBeenCalledWith('Debe cargar al menos un articulo');
573 }); 593 });
574 594
575 it('funcion $scope.crearNotaPedido llama startGuardar', function() { 595 it('funcion $scope.crearNotaPedido llama startGuardar', function() {
576 596
577 //arrange 597 //arrange
578 var scope = {}; 598 var scope = {};
579 var focaBotoneraLateralService = { 599 var focaBotoneraLateralService = {
580 startGuardar: function() { } 600 startGuardar: function() { }
581 }; 601 };
582 602
583 $controler('notaPedidoCtrl', { 603 $controler('notaPedidoCtrl', {
584 $scope: scope, 604 $scope: scope,
585 $uibModal: {}, 605 $uibModal: {},
586 $location: {}, 606 $location: {},
587 $filter: filter, 607 $filter: filter,
588 $timeout: timeout, 608 $timeout: timeout,
589 crearNotaPedidoService: { 609 crearNotaPedidoService: {
590 getBotonera: function() { }, 610 getBotonera: function() { },
591 getCotizacionByIdMoneda: function() { 611 getCotizacionByIdMoneda: function() {
592 return { 612 return {
593 then: function() {} 613 then: function() {}
594 }; 614 };
595 }, 615 },
596 crearNotaPedido: function() { 616 crearNotaPedido: function() {
597 return { 617 return {
598 then: function() { } 618 then: function() { }
599 }; 619 };
600 } 620 }
601 }, 621 },
602 focaBotoneraLateralService: focaBotoneraLateralService, 622 focaBotoneraLateralService: focaBotoneraLateralService,
603 focaModalService: {}, 623 focaModalService: {},
604 notaPedidoBusinessService: {}, 624 notaPedidoBusinessService: {},
605 $rootScope: { 625 $rootScope: {
606 $on: function() { } 626 $on: function() { }
607 }, 627 },
608 focaSeguimientoService: {}, 628 focaSeguimientoService: {},
609 APP: {}, 629 APP: {},
610 focaLoginService: {} 630 focaLoginService: {},
631 $localStorage: {},
632 $watch: function() { }
611 }); 633 });
612 634
613 scope.notaPedido = { 635 scope.notaPedido = {
614 vendedor: { 636 vendedor: {
615 id: true 637 id: true
616 }, 638 },
617 cliente:{ 639 cliente:{
618 COD: true 640 COD: true
619 }, 641 },
620 proveedor:{ 642 proveedor:{
621 COD: true 643 COD: true
622 }, 644 },
623 moneda:{ 645 moneda:{
624 ID: true 646 ID: true
625 }, 647 },
626 cotizacion:{ 648 cotizacion:{
627 ID: true 649 ID: true
628 }, 650 },
629 flete: true, 651 flete: true,
630 domicilioStamp: true, 652 domicilioStamp: true,
631 domicilio: { 653 domicilio: {
632 id: true 654 id: true
633 } 655 }
634 }; 656 };
635 657
636 scope.plazosPagos = true; 658 scope.plazosPagos = true;
637 scope.articulosTabla = [1]; 659 scope.articulosTabla = [1];
638 660
639 //act 661 //act
640 spyOn(focaBotoneraLateralService, 'startGuardar'); 662 spyOn(focaBotoneraLateralService, 'startGuardar');
641 scope.crearNotaPedido(); 663 scope.crearNotaPedido();
642 664
643 //expect 665 //expect
644 expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); 666 expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled();
645 }); 667 });
646 668
647 it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { 669 it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) {
648 670
649 //arrange 671 //arrange
650 var scope = {}; 672 var scope = {};
651 var focaBotoneraLateralService = { 673 var focaBotoneraLateralService = {
652 startGuardar: function() { }, 674 startGuardar: function() { },
653 endGuardar: function() { } 675 endGuardar: function() { }
654 }; 676 };
655 var focaSeguimientoService = { 677 var focaSeguimientoService = {
656 guardarPosicion: function() { } 678 guardarPosicion: function() { }
657 }; 679 };
658 var notaPedidoBusinessService = { 680 var notaPedidoBusinessService = {
659 addArticulos: function() { }, 681 addArticulos: function() { },
660 addEstado: function() { } 682 addEstado: function() { }
661 }; 683 };
662 var crearNotaPedidoService = { 684 var crearNotaPedidoService = {
663 getBotonera: function() { }, 685 getBotonera: function() { },
664 getCotizacionByIdMoneda: function() { 686 getCotizacionByIdMoneda: function() {
665 return { 687 return {
666 then: function() {} 688 then: function() {}
667 }; 689 };
668 }, 690 },
669 crearNotaPedido: function() { }, 691 crearNotaPedido: function() { },
670 getNumeroNotaPedido: function() { 692 getNumeroNotaPedido: function() {
671 return { 693 return {
672 then: function() { } 694 then: function() { }
673 }; 695 };
674 } 696 }
675 }; 697 };
676 698
677 $controler('notaPedidoCtrl', { 699 $controler('notaPedidoCtrl', {
678 $scope: scope, 700 $scope: scope,
679 $uibModal: {}, 701 $uibModal: {},
680 $location: {}, 702 $location: {},
681 $filter: filter, 703 $filter: filter,
682 $timeout: timeout, 704 $timeout: timeout,
683 crearNotaPedidoService: crearNotaPedidoService, 705 crearNotaPedidoService: crearNotaPedidoService,
684 focaBotoneraLateralService: focaBotoneraLateralService, 706 focaBotoneraLateralService: focaBotoneraLateralService,
685 focaModalService: {}, 707 focaModalService: {},
686 notaPedidoBusinessService: notaPedidoBusinessService, 708 notaPedidoBusinessService: notaPedidoBusinessService,
687 $rootScope: { 709 $rootScope: {
688 $on: function() { } 710 $on: function() { }
689 }, 711 },
690 focaSeguimientoService: focaSeguimientoService, 712 focaSeguimientoService: focaSeguimientoService,
691 APP: {}, 713 APP: {},
692 focaLoginService: {} 714 focaLoginService: {},
715 $localStorage: {},
716 $watch: function() { }
693 }); 717 });
694 718
695 scope.notaPedido = { 719 scope.notaPedido = {
696 vendedor: { 720 vendedor: {
697 id: true 721 id: true
698 }, 722 },
699 cliente:{ 723 cliente:{
700 COD: true 724 COD: true
701 }, 725 },
702 proveedor:{ 726 proveedor:{
703 COD: true 727 COD: true
704 }, 728 },
705 moneda:{ 729 moneda:{
706 ID: true 730 ID: true
707 }, 731 },
708 cotizacion:{ 732 cotizacion:{
709 ID: true 733 ID: true
710 }, 734 },
711 flete: true, 735 flete: true,
712 domicilioStamp: true, 736 domicilioStamp: true,
713 domicilio: { 737 domicilio: {
714 id: true 738 id: true
715 } 739 }
716 }; 740 };
717 741
718 scope.plazosPagos = []; 742 scope.plazosPagos = [];
719 scope.articulosTabla = [1]; 743 scope.articulosTabla = [1];
720 744
721 var promesa = Promise.resolve({ data: 1 }); 745 var promesa = Promise.resolve({ data: 1 });
722 scope.$broadcast = function() { }; 746 scope.$broadcast = function() { };
723 747
724 //act 748 //act
725 spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa); 749 spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa);
726 spyOn(focaSeguimientoService, 'guardarPosicion'); 750 spyOn(focaSeguimientoService, 'guardarPosicion');
727 spyOn(notaPedidoBusinessService, 'addArticulos'); 751 spyOn(notaPedidoBusinessService, 'addArticulos');
728 scope.crearNotaPedido(); 752 scope.crearNotaPedido();
729 753
730 //expect 754 //expect
731 promesa.then(function() { 755 promesa.then(function() {
732 expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); 756 expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled();
733 expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); 757 expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled();
734 done(); 758 done();
735 }); 759 });
736 }); 760 });
737 }); 761 });
738 }); 762 });
739 763
src/js/controller.js
1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', 1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'crearNotaPedidoService', 8 'crearNotaPedidoService',
9 'focaBotoneraLateralService', 9 'focaBotoneraLateralService',
10 'focaModalService', 10 'focaModalService',
11 'notaPedidoBusinessService', 11 'notaPedidoBusinessService',
12 '$rootScope', 12 '$rootScope',
13 'focaSeguimientoService', 13 'focaSeguimientoService',
14 'APP', 14 'APP',
15 'focaLoginService', 15 'focaLoginService',
16 '$localStorage', 16 '$localStorage',
17 function( 17 function(
18 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, 18 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService,
19 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, 19 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService,
20 $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) 20 $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage)
21 { 21 {
22 config(); 22 config();
23 23
24 function config() { 24 function config() {
25 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA 25 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA
26 $scope.isNumber = angular.isNumber; 26 $scope.isNumber = angular.isNumber;
27 $scope.datepickerAbierto = false; 27 $scope.datepickerAbierto = false;
28 $scope.show = false; 28 $scope.show = false;
29 $scope.cargando = true; 29 $scope.cargando = true;
30 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); 30 $scope.puntoVenta = $filter('rellenarDigitos')(0, 4);
31 $scope.comprobante = $filter('rellenarDigitos')(0, 8); 31 $scope.comprobante = $filter('rellenarDigitos')(0, 8);
32 $scope.dateOptions = { 32 $scope.dateOptions = {
33 maxDate: new Date(), 33 maxDate: new Date(),
34 minDate: new Date(2010, 0, 1) 34 minDate: new Date(2010, 0, 1)
35 }; 35 };
36 36
37 //SETEO BOTONERA LATERAL 37 //SETEO BOTONERA LATERAL
38 $timeout(function() { 38 $timeout(function() {
39 focaBotoneraLateralService.showSalir(false); 39 focaBotoneraLateralService.showSalir(false);
40 focaBotoneraLateralService.showPausar(true); 40 focaBotoneraLateralService.showPausar(true);
41 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); 41 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
42 focaBotoneraLateralService.addCustomButton('Salir', salir); 42 focaBotoneraLateralService.addCustomButton('Salir', salir);
43 }); 43 });
44 44
45 // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR 45 // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR
46 if (APP === 'distribuidor') { 46 if (APP === 'distribuidor') {
47 $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; 47 $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador;
48 $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor); 48 $scope.botonera = crearNotaPedidoService.getBotonera($scope.idVendedor);
49 } else { 49 } else {
50 $scope.botonera = crearNotaPedidoService.getBotonera(); 50 $scope.botonera = crearNotaPedidoService.getBotonera();
51 } 51 }
52 52
53 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 53 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
54 var monedaPorDefecto;
55 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { 54 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
56 monedaPorDefecto = res.data[0]; 55 var monedaPorDefecto = res.data[0];
57 56
58 $scope.notaPedido.cotizacion = Object.assign( 57 $scope.cotizacionPorDefecto = Object.assign(
59 {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] 58 {moneda: monedaPorDefecto},
59 monedaPorDefecto.cotizaciones[0]
60 ); 60 );
61 $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; 61
62 init();
63 getLSNotaPedido();
62 }); 64 });
63 65
64 init();
65 $timeout(function() {getLSNotaPedido();});
66 66
67 } 67 }
68 68
69 function init() { 69 function init() {
70 $scope.$broadcast('cleanCabecera'); 70 $scope.$broadcast('cleanCabecera');
71 71
72 $scope.notaPedido = { 72 $scope.notaPedido = {
73 id: 0, 73 id: 0,
74 cliente: {}, 74 cliente: {},
75 proveedor: {}, 75 proveedor: {},
76 domicilio: {dom: ''}, 76 domicilio: {dom: ''},
77 vendedor: {}, 77 vendedor: {},
78 fechaCarga: new Date(), 78 fechaCarga: new Date(),
79 cotizacion: {} 79 cotizacion: $scope.cotizacionPorDefecto
80 }; 80 };
81 81
82 $scope.notaPedido.articulosNotaPedido = []; 82 $scope.notaPedido.articulosNotaPedido = [];
83 $scope.idLista = undefined; 83 $scope.idLista = undefined;
84 84
85 crearNotaPedidoService.getNumeroNotaPedido().then( 85 crearNotaPedidoService.getNumeroNotaPedido().then(
86 function(res) { 86 function(res) {
87 $scope.puntoVenta = $filter('rellenarDigitos')( 87 $scope.puntoVenta = $filter('rellenarDigitos')(
88 res.data.sucursal, 4 88 res.data.sucursal, 4
89 ); 89 );
90 90
91 $scope.comprobante = $filter('rellenarDigitos')( 91 $scope.comprobante = $filter('rellenarDigitos')(
92 res.data.numeroNotaPedido, 8 92 res.data.numeroNotaPedido, 8
93 ); 93 );
94 }, 94 },
95 function(err) { 95 function(err) {
96 focaModalService.alert('La terminal no esta configurada correctamente'); 96 focaModalService.alert('La terminal no esta configurada correctamente');
97 console.info(err); 97 console.info(err);
98 } 98 }
99 ); 99 );
100 100
101 if (APP === 'distribuidor') { 101 if (APP === 'distribuidor') {
102 crearNotaPedidoService.getVendedorById($scope.idVendedor).then( 102 crearNotaPedidoService.getVendedorById($scope.idVendedor).then(
103 function(res) { 103 function(res) {
104 var vendedor = res.data; 104 var vendedor = res.data;
105 $scope.$broadcast('addCabecera', { 105 $scope.$broadcast('addCabecera', {
106 label: 'Vendedor:', 106 label: 'Vendedor:',
107 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 107 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
108 vendedor.NOM 108 vendedor.NOM
109 }); 109 });
110 110
111 $scope.notaPedido.vendedor = vendedor; 111 $scope.notaPedido.vendedor = vendedor;
112 $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; 112 $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor;
113 } 113 }
114 ); 114 );
115 } 115 }
116 116
117 $scope.inicial = angular.copy($scope.notaPedido); 117 $scope.inicial = angular.copy($scope.notaPedido);
118 } 118 }
119 119
120 $scope.$watch('notaPedido', function(newValue, oldValue) { 120 $scope.$watch('notaPedido', function(newValue, oldValue) {
121 focaBotoneraLateralService.setPausarData({ 121 focaBotoneraLateralService.setPausarData({
122 label: 'notaPedido', 122 label: 'notaPedido',
123 val: newValue 123 val: newValue
124 }); 124 });
125 }, true); 125 }, true);
126 126
127 $scope.crearNotaPedido = function() { 127 $scope.crearNotaPedido = function() {
128 if(!$scope.notaPedido.vendedor.id) { 128 if(!$scope.notaPedido.vendedor.id) {
129 focaModalService.alert('Ingrese Vendedor'); 129 focaModalService.alert('Ingrese Vendedor');
130 return; 130 return;
131 } else if(!$scope.notaPedido.cliente.COD) { 131 } else if(!$scope.notaPedido.cliente.COD) {
132 focaModalService.alert('Ingrese Cliente'); 132 focaModalService.alert('Ingrese Cliente');
133 return; 133 return;
134 } else if(!$scope.notaPedido.proveedor.COD) { 134 } else if(!$scope.notaPedido.proveedor.COD) {
135 focaModalService.alert('Ingrese Proveedor'); 135 focaModalService.alert('Ingrese Proveedor');
136 return; 136 return;
137 } else if(!$scope.notaPedido.cotizacion.moneda.ID) { 137 } else if(!$scope.notaPedido.cotizacion.moneda.ID) {
138 focaModalService.alert('Ingrese Moneda'); 138 focaModalService.alert('Ingrese Moneda');
139 return; 139 return;
140 } else if(!$scope.notaPedido.cotizacion.ID) { 140 } else if(!$scope.notaPedido.cotizacion.ID) {
141 focaModalService.alert('Ingrese Cotización'); 141 focaModalService.alert('Ingrese Cotización');
142 return; 142 return;
143 } else if(!$scope.notaPedido.notaPedidoPlazo) { 143 } else if(!$scope.notaPedido.notaPedidoPlazo) {
144 focaModalService.alert('Ingrese Precios y Condiciones'); 144 focaModalService.alert('Ingrese Precios y Condiciones');
145 return; 145 return;
146 } else if( 146 } else if(
147 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) 147 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null)
148 { 148 {
149 focaModalService.alert('Ingrese Flete'); 149 focaModalService.alert('Ingrese Flete');
150 return; 150 return;
151 } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto 151 } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto
152 focaModalService.alert('Ingrese Domicilio'); 152 focaModalService.alert('Ingrese Domicilio');
153 return; 153 return;
154 } else if($scope.notaPedido.articulosNotaPedido.length === 0) { 154 } else if($scope.notaPedido.articulosNotaPedido.length === 0) {
155 focaModalService.alert('Debe cargar al menos un articulo'); 155 focaModalService.alert('Debe cargar al menos un articulo');
156 return; 156 return;
157 } 157 }
158 focaBotoneraLateralService.startGuardar(); 158 focaBotoneraLateralService.startGuardar();
159 $scope.saveLoading = true; 159 $scope.saveLoading = true;
160 var notaPedido = { 160 var notaPedido = {
161 id: $scope.notaPedido.id, 161 id: $scope.notaPedido.id,
162 fechaCarga: new Date($scope.notaPedido.fechaCarga).toISOString().slice(0, 19).replace('T', ' '), 162 fechaCarga: new Date($scope.notaPedido.fechaCarga).toISOString().slice(0, 19).replace('T', ' '),
163 idVendedor: $scope.notaPedido.vendedor.id, 163 idVendedor: $scope.notaPedido.vendedor.id,
164 idCliente: $scope.notaPedido.cliente.COD, 164 idCliente: $scope.notaPedido.cliente.COD,
165 nombreCliente: $scope.notaPedido.cliente.NOM, 165 nombreCliente: $scope.notaPedido.cliente.NOM,
166 cuitCliente: $scope.notaPedido.cliente.CUIT, 166 cuitCliente: $scope.notaPedido.cliente.CUIT,
167 idProveedor: $scope.notaPedido.proveedor.COD, 167 idProveedor: $scope.notaPedido.proveedor.COD,
168 idDomicilio: $scope.notaPedido.idDomicilio || $scope.notaPedido.domicilio.id, 168 idDomicilio: $scope.notaPedido.idDomicilio || $scope.notaPedido.domicilio.id,
169 idCotizacion: $scope.notaPedido.cotizacion.ID, 169 idCotizacion: $scope.notaPedido.cotizacion.ID,
170 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, 170 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion,
171 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 171 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
172 flete: $scope.notaPedido.flete, 172 flete: $scope.notaPedido.flete,
173 fob: $scope.notaPedido.fob, 173 fob: $scope.notaPedido.fob,
174 bomba: $scope.notaPedido.bomba, 174 bomba: $scope.notaPedido.bomba,
175 kilometros: $scope.notaPedido.kilometros, 175 kilometros: $scope.notaPedido.kilometros,
176 domicilioStamp: $scope.notaPedido.domicilioStamp, 176 domicilioStamp: $scope.notaPedido.domicilioStamp,
177 observaciones: $scope.notaPedido.observaciones, 177 observaciones: $scope.notaPedido.observaciones,
178 estado: 0, 178 estado: 0,
179 total: $scope.getTotal() 179 total: $scope.getTotal()
180 }; 180 };
181 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 181 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
182 function(data) { 182 function(data) {
183 // Al guardar los datos de la nota de pedido logueamos la 183 // Al guardar los datos de la nota de pedido logueamos la
184 // actividad para su seguimiento. 184 // actividad para su seguimiento.
185 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? 185 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR?
186 focaSeguimientoService.guardarPosicion( 186 focaSeguimientoService.guardarPosicion(
187 'Nota de pedido', 187 'Nota de pedido',
188 data.data.id, 188 data.data.id,
189 '' 189 ''
190 ); 190 );
191 notaPedidoBusinessService.addArticulos($scope.notaPedido.articulosNotaPedido, 191 notaPedidoBusinessService.addArticulos($scope.notaPedido.articulosNotaPedido,
192 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); 192 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR);
193 193
194 if($scope.notaPedido.notaPedidoPuntoDescarga) { 194 if($scope.notaPedido.notaPedidoPuntoDescarga) {
195 notaPedidoBusinessService.addPuntosDescarga(data.data.id, 195 notaPedidoBusinessService.addPuntosDescarga(data.data.id,
196 $scope.notaPedido.notaPedidoPuntoDescarga); 196 $scope.notaPedido.notaPedidoPuntoDescarga);
197 } 197 }
198 198
199 var plazos = $scope.notaPedido.notaPedidoPlazo; 199 var plazos = $scope.notaPedido.notaPedidoPlazo;
200 var plazosACrear = []; 200 var plazosACrear = [];
201 plazos.forEach(function(plazo) { 201 plazos.forEach(function(plazo) {
202 plazosACrear.push({ 202 plazosACrear.push({
203 idNotaPedido: data.data.id, 203 idNotaPedido: data.data.id,
204 dias: plazo.dias 204 dias: plazo.dias
205 }); 205 });
206 }); 206 });
207 207
208 if (plazosACrear.length) { 208 if (plazosACrear.length) {
209 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); 209 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear);
210 } 210 }
211 211
212 notaPedidoBusinessService.addEstado(data.data.id, 212 notaPedidoBusinessService.addEstado(data.data.id,
213 $scope.notaPedido.vendedor.id); 213 $scope.notaPedido.vendedor.id);
214 214
215 focaBotoneraLateralService.endGuardar(true); 215 focaBotoneraLateralService.endGuardar(true);
216 $scope.saveLoading = false; 216 $scope.saveLoading = false;
217 217
218 init(); 218 init();
219 }, function(error) { 219 }, function(error) {
220 focaModalService.alert('Hubo un error al crear la nota de pedido'); 220 focaModalService.alert('Hubo un error al crear la nota de pedido');
221 focaBotoneraLateralService.endGuardar(); 221 focaBotoneraLateralService.endGuardar();
222 $scope.saveLoading = false; 222 $scope.saveLoading = false;
223 console.info(error); 223 console.info(error);
224 } 224 }
225 ); 225 );
226 }; 226 };
227 227
228 $scope.seleccionarNotaPedido = function() { 228 $scope.seleccionarNotaPedido = function() {
229 var modalInstance = $uibModal.open( 229 var modalInstance = $uibModal.open(
230 { 230 {
231 ariaLabelledBy: 'Busqueda de Nota de Pedido', 231 ariaLabelledBy: 'Busqueda de Nota de Pedido',
232 templateUrl: 'foca-modal-nota-pedido.html', 232 templateUrl: 'foca-modal-nota-pedido.html',
233 controller: 'focaModalNotaPedidoController', 233 controller: 'focaModalNotaPedidoController',
234 size: 'lg', 234 size: 'lg',
235 resolve: { 235 resolve: {
236 usadoPor: function() {return 'notaPedido';}, 236 usadoPor: function() {return 'notaPedido';},
237 idVendedor: function() { 237 idVendedor: function() {
238 if(APP === 'distribuidor') 238 if(APP === 'distribuidor')
239 return $scope.notaPedido.vendedor.id; 239 return $scope.notaPedido.vendedor.id;
240 else 240 else
241 return null; 241 return null;
242 } 242 }
243 } 243 }
244 } 244 }
245 ); 245 );
246 modalInstance.result.then(setearNotaPedido); 246 modalInstance.result.then(setearNotaPedido);
247 }; 247 };
248 248
249 $scope.seleccionarProductos = function() { 249 $scope.seleccionarProductos = function() {
250 if ($scope.idLista === undefined) { 250 if ($scope.idLista === undefined) {
251 focaModalService.alert( 251 focaModalService.alert(
252 'Primero seleccione una lista de precio y condicion'); 252 'Primero seleccione una lista de precio y condicion');
253 return; 253 return;
254 } 254 }
255 var modalInstance = $uibModal.open( 255 var modalInstance = $uibModal.open(
256 { 256 {
257 ariaLabelledBy: 'Busqueda de Productos', 257 ariaLabelledBy: 'Busqueda de Productos',
258 templateUrl: 'modal-busqueda-productos.html', 258 templateUrl: 'modal-busqueda-productos.html',
259 controller: 'modalBusquedaProductosCtrl', 259 controller: 'modalBusquedaProductosCtrl',
260 resolve: { 260 resolve: {
261 parametroProducto: { 261 parametroProducto: {
262 idLista: $scope.idLista, 262 idLista: $scope.idLista,
263 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 263 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
264 simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO 264 simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO
265 } 265 }
266 }, 266 },
267 size: 'lg' 267 size: 'lg'
268 } 268 }
269 ); 269 );
270 modalInstance.result.then( 270 modalInstance.result.then(
271 function(producto) { 271 function(producto) {
272 var newArt = 272 var newArt =
273 { 273 {
274 id: 0, 274 id: 0,
275 codigo: producto.codigo, 275 codigo: producto.codigo,
276 sector: producto.sector, 276 sector: producto.sector,
277 sectorCodigo: producto.sector + '-' + producto.codigo, 277 sectorCodigo: producto.sector + '-' + producto.codigo,
278 descripcion: producto.descripcion, 278 descripcion: producto.descripcion,
279 item: $scope.notaPedido.articulosNotaPedido.length + 1, 279 item: $scope.notaPedido.articulosNotaPedido.length + 1,
280 nombre: producto.descripcion, 280 nombre: producto.descripcion,
281 precio: parseFloat(producto.precio.toFixed(4)), 281 precio: parseFloat(producto.precio.toFixed(4)),
282 costoUnitario: producto.costo, 282 costoUnitario: producto.costo,
283 editCantidad: false, 283 editCantidad: false,
284 editPrecio: false, 284 editPrecio: false,
285 rubro: producto.CodRub, 285 rubro: producto.CodRub,
286 exentoUnitario: producto.precio, 286 exentoUnitario: producto.precio,
287 ivaUnitario: producto.IMPIVA, 287 ivaUnitario: producto.IMPIVA,
288 impuestoInternoUnitario: producto.ImpInt, 288 impuestoInternoUnitario: producto.ImpInt,
289 impuestoInterno1Unitario: producto.ImpInt2, 289 impuestoInterno1Unitario: producto.ImpInt2,
290 impuestoInterno2Unitario: producto.ImpInt3, 290 impuestoInterno2Unitario: producto.ImpInt3,
291 precioLista: producto.precio, 291 precioLista: producto.precio,
292 combustible: 1, 292 combustible: 1,
293 facturado: 0, 293 facturado: 0,
294 idArticulo: producto.id 294 idArticulo: producto.id
295 }; 295 };
296 $scope.articuloACargar = newArt; 296 $scope.articuloACargar = newArt;
297 $scope.cargando = false; 297 $scope.cargando = false;
298 }, function() { 298 }, function() {
299 // funcion ejecutada cuando se cancela el modal 299 // funcion ejecutada cuando se cancela el modal
300 } 300 }
301 ); 301 );
302 }; 302 };
303 303
304 $scope.seleccionarPuntosDeDescarga = function() { 304 $scope.seleccionarPuntosDeDescarga = function() {
305 if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { 305 if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) {
306 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 306 focaModalService.alert('Primero seleccione un cliente y un domicilio');
307 return; 307 return;
308 }else { 308 }else {
309 var modalInstance = $uibModal.open( 309 var modalInstance = $uibModal.open(
310 { 310 {
311 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 311 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
312 templateUrl: 'modal-punto-descarga.html', 312 templateUrl: 'modal-punto-descarga.html',
313 controller: 'focaModalPuntoDescargaController', 313 controller: 'focaModalPuntoDescargaController',
314 size: 'lg', 314 size: 'lg',
315 resolve: { 315 resolve: {
316 filters: { 316 filters: {
317 idDomicilio: $scope.notaPedido.domicilio.id, 317 idDomicilio: $scope.notaPedido.domicilio.id,
318 idCliente: $scope.notaPedido.cliente.COD, 318 idCliente: $scope.notaPedido.cliente.COD,
319 articulos: $scope.notaPedido.articulosNotaPedido, 319 articulos: $scope.notaPedido.articulosNotaPedido,
320 puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga 320 puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga
321 } 321 }
322 } 322 }
323 } 323 }
324 ); 324 );
325 modalInstance.result.then( 325 modalInstance.result.then(
326 function(puntosDescarga) { 326 function(puntosDescarga) {
327 $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; 327 $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga;
328 328
329 //AGREGO PUNTOS DE DESCARGA A CABECERA 329 //AGREGO PUNTOS DE DESCARGA A CABECERA
330 var puntosStamp = ''; 330 var puntosStamp = '';
331 puntosDescarga.forEach(function(punto, idx, arr) { 331 puntosDescarga.forEach(function(punto, idx, arr) {
332 puntosStamp += punto.descripcion; 332 puntosStamp += punto.descripcion;
333 if((idx + 1) !== arr.length) puntosStamp += ', '; 333 if((idx + 1) !== arr.length) puntosStamp += ', ';
334 }); 334 });
335 335
336 $scope.$broadcast('addCabecera', { 336 $scope.$broadcast('addCabecera', {
337 label: 'Puntos de descarga:', 337 label: 'Puntos de descarga:',
338 valor: puntosStamp 338 valor: puntosStamp
339 }); 339 });
340 }, function() { 340 }, function() {
341 $scope.abrirModalDomicilios($scope.cliente); 341 $scope.abrirModalDomicilios($scope.cliente);
342 } 342 }
343 ); 343 );
344 } 344 }
345 }; 345 };
346 346
347 $scope.seleccionarVendedor = function() { 347 $scope.seleccionarVendedor = function() {
348 if(validarNotaRemitada()) { 348 if(validarNotaRemitada()) {
349 var parametrosModal = { 349 var parametrosModal = {
350 titulo: 'Búsqueda vendedores', 350 titulo: 'Búsqueda vendedores',
351 query: '/vendedor', 351 query: '/vendedor',
352 columnas: [ 352 columnas: [
353 { 353 {
354 propiedad: 'NUM', 354 propiedad: 'NUM',
355 nombre: 'Código', 355 nombre: 'Código',
356 filtro: { 356 filtro: {
357 nombre: 'rellenarDigitos', 357 nombre: 'rellenarDigitos',
358 parametro: 3 358 parametro: 3
359 } 359 }
360 }, 360 },
361 { 361 {
362 propiedad: 'NOM', 362 propiedad: 'NOM',
363 nombre: 'Nombre' 363 nombre: 'Nombre'
364 } 364 }
365 ], 365 ],
366 size: 'md' 366 size: 'md'
367 }; 367 };
368 focaModalService.modal(parametrosModal).then( 368 focaModalService.modal(parametrosModal).then(
369 function(vendedor) { 369 function(vendedor) {
370 $scope.$broadcast('addCabecera', { 370 $scope.$broadcast('addCabecera', {
371 label: 'Vendedor:', 371 label: 'Vendedor:',
372 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 372 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
373 vendedor.NOM 373 vendedor.NOM
374 }); 374 });
375 $scope.notaPedido.vendedor = vendedor; 375 $scope.notaPedido.vendedor = vendedor;
376 }, function() { 376 }, function() {
377 377
378 } 378 }
379 ); 379 );
380 } 380 }
381 }; 381 };
382 382
383 $scope.seleccionarProveedor = function() { 383 $scope.seleccionarProveedor = function() {
384 if(validarNotaRemitada()) { 384 if(validarNotaRemitada()) {
385 var parametrosModal = { 385 var parametrosModal = {
386 titulo: 'Búsqueda de Proveedor', 386 titulo: 'Búsqueda de Proveedor',
387 query: '/proveedor', 387 query: '/proveedor',
388 columnas: [ 388 columnas: [
389 { 389 {
390 nombre: 'Código', 390 nombre: 'Código',
391 propiedad: 'COD', 391 propiedad: 'COD',
392 filtro: { 392 filtro: {
393 nombre: 'rellenarDigitos', 393 nombre: 'rellenarDigitos',
394 parametro: 5 394 parametro: 5
395 } 395 }
396 }, 396 },
397 { 397 {
398 nombre: 'Nombre', 398 nombre: 'Nombre',
399 propiedad: 'NOM' 399 propiedad: 'NOM'
400 }, 400 },
401 { 401 {
402 nombre: 'CUIT', 402 nombre: 'CUIT',
403 propiedad: 'CUIT' 403 propiedad: 'CUIT'
404 } 404 }
405 ], 405 ],
406 tipo: 'POST', 406 tipo: 'POST',
407 json: {razonCuitCod: ''} 407 json: {razonCuitCod: ''}
408 }; 408 };
409 focaModalService.modal(parametrosModal).then( 409 focaModalService.modal(parametrosModal).then(
410 function(proveedor) { 410 function(proveedor) {
411 $scope.notaPedido.proveedor = proveedor; 411 $scope.notaPedido.proveedor = proveedor;
412 $scope.$broadcast('addCabecera', { 412 $scope.$broadcast('addCabecera', {
413 label: 'Proveedor:', 413 label: 'Proveedor:',
414 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 414 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
415 proveedor.NOM 415 proveedor.NOM
416 }); 416 });
417 }, function() { 417 }, function() {
418 418
419 } 419 }
420 ); 420 );
421 } 421 }
422 }; 422 };
423 423
424 $scope.seleccionarCliente = function() { 424 $scope.seleccionarCliente = function() {
425 if(!$scope.notaPedido.vendedor.NUM) { 425 if(!$scope.notaPedido.vendedor.NUM) {
426 focaModalService.alert('Primero seleccione un vendedor'); 426 focaModalService.alert('Primero seleccione un vendedor');
427 return; 427 return;
428 } 428 }
429 if(validarNotaRemitada()) { 429 if(validarNotaRemitada()) {
430 var modalInstance = $uibModal.open( 430 var modalInstance = $uibModal.open(
431 { 431 {
432 ariaLabelledBy: 'Busqueda de Cliente', 432 ariaLabelledBy: 'Busqueda de Cliente',
433 templateUrl: 'foca-busqueda-cliente-modal.html', 433 templateUrl: 'foca-busqueda-cliente-modal.html',
434 controller: 'focaBusquedaClienteModalController', 434 controller: 'focaBusquedaClienteModalController',
435 resolve: { 435 resolve: {
436 vendedor: function() { return $scope.notaPedido.vendedor; } 436 vendedor: function() { return $scope.notaPedido.vendedor; }
437 }, 437 },
438 size: 'lg' 438 size: 'lg'
439 } 439 }
440 ); 440 );
441 modalInstance.result.then( 441 modalInstance.result.then(
442 function(cliente) { 442 function(cliente) {
443 $scope.abrirModalDomicilios(cliente); 443 $scope.abrirModalDomicilios(cliente);
444 $scope.cliente = cliente; 444 $scope.cliente = cliente;
445 }, function() {} 445 }, function() {}
446 ); 446 );
447 } 447 }
448 }; 448 };
449 449
450 $scope.abrirModalDomicilios = function(cliente) { 450 $scope.abrirModalDomicilios = function(cliente) {
451 var modalInstanceDomicilio = $uibModal.open( 451 var modalInstanceDomicilio = $uibModal.open(
452 { 452 {
453 ariaLabelledBy: 'Busqueda de Domicilios', 453 ariaLabelledBy: 'Busqueda de Domicilios',
454 templateUrl: 'modal-domicilio.html', 454 templateUrl: 'modal-domicilio.html',
455 controller: 'focaModalDomicilioController', 455 controller: 'focaModalDomicilioController',
456 resolve: { 456 resolve: {
457 idCliente: function() { return cliente.cod; }, 457 idCliente: function() { return cliente.cod; },
458 esNuevo: function() { return cliente.esNuevo; } 458 esNuevo: function() { return cliente.esNuevo; }
459 }, 459 },
460 size: 'lg', 460 size: 'lg',
461 } 461 }
462 ); 462 );
463 modalInstanceDomicilio.result.then( 463 modalInstanceDomicilio.result.then(
464 function(domicilio) { 464 function(domicilio) {
465 $scope.notaPedido.domicilio = domicilio; 465 $scope.notaPedido.domicilio = domicilio;
466 $scope.notaPedido.cliente = { 466 $scope.notaPedido.cliente = {
467 COD: cliente.cod, 467 COD: cliente.cod,
468 CUIT: cliente.cuit, 468 CUIT: cliente.cuit,
469 NOM: cliente.nom 469 NOM: cliente.nom
470 }; 470 };
471 var domicilioStamp = 471 var domicilioStamp =
472 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 472 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
473 domicilio.Localidad + ', ' + domicilio.Provincia; 473 domicilio.Localidad + ', ' + domicilio.Provincia;
474 $scope.notaPedido.domicilioStamp = domicilioStamp; 474 $scope.notaPedido.domicilioStamp = domicilioStamp;
475 475
476 $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; 476 $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga;
477 477
478 $scope.$broadcast('addCabecera', { 478 $scope.$broadcast('addCabecera', {
479 label: 'Cliente:', 479 label: 'Cliente:',
480 valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom 480 valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom
481 }); 481 });
482 $scope.$broadcast('addCabecera', { 482 $scope.$broadcast('addCabecera', {
483 label: 'Domicilio:', 483 label: 'Domicilio:',
484 valor: domicilioStamp 484 valor: domicilioStamp
485 }); 485 });
486 if(domicilio.verPuntos) { 486 if(domicilio.verPuntos) {
487 delete $scope.notaPedido.domicilio.verPuntos; 487 delete $scope.notaPedido.domicilio.verPuntos;
488 $scope.seleccionarPuntosDeDescarga(); 488 $scope.seleccionarPuntosDeDescarga();
489 }else { 489 }else {
490 crearNotaPedidoService 490 crearNotaPedidoService
491 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 491 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
492 .then(function(res) { 492 .then(function(res) {
493 if(res.data.length) $scope.seleccionarPuntosDeDescarga(); 493 if(res.data.length) $scope.seleccionarPuntosDeDescarga();
494 }); 494 });
495 } 495 }
496 }, function() { 496 }, function() {
497 $scope.seleccionarCliente(); 497 $scope.seleccionarCliente();
498 return; 498 return;
499 } 499 }
500 ); 500 );
501 }; 501 };
502 502
503 $scope.getTotal = function() { 503 $scope.getTotal = function() {
504 var total = 0; 504 var total = 0;
505 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; 505 if ($scope.notaPedido.articulosNotaPedido) {
506 for (var i = 0; i < arrayTempArticulos.length; i++) { 506 var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido;
507 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 507 for (var i = 0; i < arrayTempArticulos.length; i++) {
508 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
509 }
508 } 510 }
509 511
510 return parseFloat(total.toFixed(2)); 512 return parseFloat(total.toFixed(2));
511 }; 513 };
512 514
513 $scope.getSubTotal = function() { 515 $scope.getSubTotal = function() {
514 if($scope.articuloACargar) { 516 if($scope.articuloACargar) {
515 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 517 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
516 } 518 }
517 }; 519 };
518 520
519 $scope.seleccionarPreciosYCondiciones = function() { 521 $scope.seleccionarPreciosYCondiciones = function() {
520 if(validarNotaRemitada()) { 522 if(validarNotaRemitada()) {
521 var modalInstance = $uibModal.open( 523 var modalInstance = $uibModal.open(
522 { 524 {
523 ariaLabelledBy: 'Busqueda de Precio Condición', 525 ariaLabelledBy: 'Busqueda de Precio Condición',
524 templateUrl: 'modal-precio-condicion.html', 526 templateUrl: 'modal-precio-condicion.html',
525 controller: 'focaModalPrecioCondicionController', 527 controller: 'focaModalPrecioCondicionController',
526 size: 'lg' 528 size: 'lg'
527 } 529 }
528 ); 530 );
529 modalInstance.result.then( 531 modalInstance.result.then(
530 function(precioCondicion) { 532 function(precioCondicion) {
531 var cabecera = ''; 533 var cabecera = '';
532 var plazosConcat = ''; 534 var plazosConcat = '';
533 if(!Array.isArray(precioCondicion)) { 535 if(!Array.isArray(precioCondicion)) {
534 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; 536 $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago;
535 $scope.notaPedido.precioCondicion = precioCondicion; 537 $scope.notaPedido.precioCondicion = precioCondicion;
536 $scope.notaPedido.idPrecioCondicion = precioCondicion.id; 538 $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
537 $scope.idLista = precioCondicion.idListaPrecio; 539 $scope.idLista = precioCondicion.idListaPrecio;
538 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 540 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
539 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 541 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
540 } 542 }
541 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 543 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
542 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 544 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
543 } else { //Cuando se ingresan los plazos manualmente 545 } else { //Cuando se ingresan los plazos manualmente
544 $scope.notaPedido.idPrecioCondicion = 0; 546 $scope.notaPedido.idPrecioCondicion = 0;
545 //-1, el modal productos busca todos los productos 547 //-1, el modal productos busca todos los productos
546 $scope.idLista = -1; 548 $scope.idLista = -1;
547 $scope.notaPedido.notaPedidoPlazo = precioCondicion; 549 $scope.notaPedido.notaPedidoPlazo = precioCondicion;
548 for(var j = 0; j < precioCondicion.length; j++) { 550 for(var j = 0; j < precioCondicion.length; j++) {
549 plazosConcat += precioCondicion[j].dias + ' '; 551 plazosConcat += precioCondicion[j].dias + ' ';
550 } 552 }
551 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 553 cabecera = 'Ingreso manual ' + plazosConcat.trim();
552 } 554 }
553 $scope.notaPedido.articulosNotaPedido = []; 555 $scope.notaPedido.articulosNotaPedido = [];
554 $scope.$broadcast('addCabecera', { 556 $scope.$broadcast('addCabecera', {
555 label: 'Precios y condiciones:', 557 label: 'Precios y condiciones:',
556 valor: cabecera 558 valor: cabecera
557 }); 559 });
558 }, function() { 560 }, function() {
559 561
560 } 562 }
561 ); 563 );
562 } 564 }
563 }; 565 };
564 566
565 $scope.seleccionarFlete = function() { 567 $scope.seleccionarFlete = function() {
566 if(validarNotaRemitada()) { 568 if(validarNotaRemitada()) {
567 var modalInstance = $uibModal.open( 569 var modalInstance = $uibModal.open(
568 { 570 {
569 ariaLabelledBy: 'Busqueda de Flete', 571 ariaLabelledBy: 'Busqueda de Flete',
570 templateUrl: 'modal-flete.html', 572 templateUrl: 'modal-flete.html',
571 controller: 'focaModalFleteController', 573 controller: 'focaModalFleteController',
572 size: 'lg', 574 size: 'lg',
573 resolve: { 575 resolve: {
574 parametrosFlete: 576 parametrosFlete:
575 function() { 577 function() {
576 return { 578 return {
577 flete: $scope.notaPedido.fob ? 'FOB' : 579 flete: $scope.notaPedido.fob ? 'FOB' :
578 ( $scope.notaPedido.flete ? '1' : 580 ( $scope.notaPedido.flete ? '1' :
579 ($scope.notaPedido.flete === undefined ? 581 ($scope.notaPedido.flete === undefined ?
580 null : '0')), 582 null : '0')),
581 bomba: $scope.notaPedido.bomba ? '1' : 583 bomba: $scope.notaPedido.bomba ? '1' :
582 ($scope.notaPedido.bomba === undefined ? 584 ($scope.notaPedido.bomba === undefined ?
583 null : '0'), 585 null : '0'),
584 kilometros: $scope.notaPedido.kilometros 586 kilometros: $scope.notaPedido.kilometros
585 }; 587 };
586 } 588 }
587 } 589 }
588 } 590 }
589 ); 591 );
590 modalInstance.result.then( 592 modalInstance.result.then(
591 function(datos) { 593 function(datos) {
592 $scope.notaPedido.flete = datos.flete; 594 $scope.notaPedido.flete = datos.flete;
593 $scope.notaPedido.fob = datos.FOB; 595 $scope.notaPedido.fob = datos.FOB;
594 $scope.notaPedido.bomba = datos.bomba; 596 $scope.notaPedido.bomba = datos.bomba;
595 $scope.notaPedido.kilometros = datos.kilometros; 597 $scope.notaPedido.kilometros = datos.kilometros;
596 $scope.$broadcast('addCabecera', { 598 $scope.$broadcast('addCabecera', {
597 label: 'Flete:', 599 label: 'Flete:',
598 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') 600 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')
599 }); 601 });
600 if(datos.flete) { 602 if(datos.flete) {
601 $scope.$broadcast('addCabecera', { 603 $scope.$broadcast('addCabecera', {
602 label: 'Bomba:', 604 label: 'Bomba:',
603 valor: datos.bomba ? 'Si' : 'No' 605 valor: datos.bomba ? 'Si' : 'No'
604 }); 606 });
605 $scope.$broadcast('addCabecera', { 607 $scope.$broadcast('addCabecera', {
606 label: 'Kilometros:', 608 label: 'Kilometros:',
607 valor: datos.kilometros 609 valor: datos.kilometros
608 }); 610 });
609 } else { 611 } else {
610 $scope.$broadcast('removeCabecera', 'Bomba:'); 612 $scope.$broadcast('removeCabecera', 'Bomba:');
611 $scope.$broadcast('removeCabecera', 'Kilometros:'); 613 $scope.$broadcast('removeCabecera', 'Kilometros:');
612 $scope.notaPedido.bomba = false; 614 $scope.notaPedido.bomba = false;
613 $scope.notaPedido.kilometros = null; 615 $scope.notaPedido.kilometros = null;
614 } 616 }
615 }, function() { 617 }, function() {
616 618
617 } 619 }
618 ); 620 );
619 } 621 }
620 }; 622 };
621 623
622 $scope.seleccionarMoneda = function() { 624 $scope.seleccionarMoneda = function() {
623 if(validarNotaRemitada()) { 625 if(validarNotaRemitada()) {
624 var parametrosModal = { 626 var parametrosModal = {
625 titulo: 'Búsqueda de monedas', 627 titulo: 'Búsqueda de monedas',
626 query: '/moneda', 628 query: '/moneda',
627 columnas: [ 629 columnas: [
628 { 630 {
629 propiedad: 'DETALLE', 631 propiedad: 'DETALLE',
630 nombre: 'Nombre' 632 nombre: 'Nombre'
631 }, 633 },
632 { 634 {
633 propiedad: 'SIMBOLO', 635 propiedad: 'SIMBOLO',
634 nombre: 'Símbolo' 636 nombre: 'Símbolo'
635 } 637 }
636 ], 638 ],
637 size: 'md' 639 size: 'md'
638 }; 640 };
639 focaModalService.modal(parametrosModal).then( 641 focaModalService.modal(parametrosModal).then(
640 function(moneda) { 642 function(moneda) {
641 $scope.abrirModalCotizacion(moneda); 643 $scope.abrirModalCotizacion(moneda);
642 }, function() { 644 }, function() {
643 645
644 } 646 }
645 ); 647 );
646 } 648 }
647 }; 649 };
648 650
649 $scope.seleccionarObservaciones = function() { 651 $scope.seleccionarObservaciones = function() {
650 focaModalService 652 focaModalService
651 .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true) 653 .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true)
652 .then(function(observaciones) { 654 .then(function(observaciones) {
653 $scope.notaPedido.observaciones = observaciones; 655 $scope.notaPedido.observaciones = observaciones;
654 }); 656 });
655 }; 657 };
656 658
657 $scope.abrirModalCotizacion = function(moneda) { 659 $scope.abrirModalCotizacion = function(moneda) {
658 var modalInstance = $uibModal.open( 660 var modalInstance = $uibModal.open(
659 { 661 {
660 ariaLabelledBy: 'Busqueda de Cotización', 662 ariaLabelledBy: 'Busqueda de Cotización',
661 templateUrl: 'modal-cotizacion.html', 663 templateUrl: 'modal-cotizacion.html',
662 controller: 'focaModalCotizacionController', 664 controller: 'focaModalCotizacionController',
663 size: 'lg', 665 size: 'lg',
664 resolve: { 666 resolve: {
665 idMoneda: function() { 667 idMoneda: function() {
666 return moneda.ID; 668 return moneda.ID;
667 } 669 }
668 } 670 }
669 } 671 }
670 ); 672 );
671 modalInstance.result.then( 673 modalInstance.result.then(
672 function(cotizacion) { 674 function(cotizacion) {
673 var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido; 675 var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido;
674 for(var i = 0; i < articulosTablaTemp.length; i++) { 676 for(var i = 0; i < articulosTablaTemp.length; i++) {
675 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 677 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
676 $scope.notaPedido.cotizacion.VENDEDOR; 678 $scope.notaPedido.cotizacion.VENDEDOR;
677 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 679 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
678 cotizacion.VENDEDOR; 680 cotizacion.VENDEDOR;
679 } 681 }
680 $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; 682 $scope.notaPedido.articulosNotaPedido = articulosTablaTemp;
681 $scope.notaPedido.cotizacion = cotizacion; 683 $scope.notaPedido.cotizacion = cotizacion;
682 $scope.notaPedido.cotizacion.moneda = moneda; 684 $scope.notaPedido.cotizacion.moneda = moneda;
683 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 685 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
684 $scope.$broadcast('removeCabecera', 'Moneda:'); 686 $scope.$broadcast('removeCabecera', 'Moneda:');
685 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 687 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
686 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 688 $scope.$broadcast('removeCabecera', 'Cotizacion:');
687 } else { 689 } else {
688 $scope.$broadcast('addCabecera', { 690 $scope.$broadcast('addCabecera', {
689 label: 'Moneda:', 691 label: 'Moneda:',
690 valor: moneda.DETALLE 692 valor: moneda.DETALLE
691 }); 693 });
692 $scope.$broadcast('addCabecera', { 694 $scope.$broadcast('addCabecera', {
693 label: 'Fecha cotizacion:', 695 label: 'Fecha cotizacion:',
694 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 696 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
695 }); 697 });
696 $scope.$broadcast('addCabecera', { 698 $scope.$broadcast('addCabecera', {
697 label: 'Cotizacion:', 699 label: 'Cotizacion:',
698 valor: $filter('number')(cotizacion.VENDEDOR, '2') 700 valor: $filter('number')(cotizacion.VENDEDOR, '2')
699 }); 701 });
700 } 702 }
701 }, function() { 703 }, function() {
702 704
703 } 705 }
704 ); 706 );
705 }; 707 };
706 708
707 $scope.agregarATabla = function(key) { 709 $scope.agregarATabla = function(key) {
708 if(key === 13) { 710 if(key === 13) {
709 if($scope.articuloACargar.cantidad === undefined || 711 if($scope.articuloACargar.cantidad === undefined ||
710 $scope.articuloACargar.cantidad === 0 || 712 $scope.articuloACargar.cantidad === 0 ||
711 $scope.articuloACargar.cantidad === null ) { 713 $scope.articuloACargar.cantidad === null ) {
712 focaModalService.alert('El valor debe ser al menos 1'); 714 focaModalService.alert('El valor debe ser al menos 1');
713 return; 715 return;
714 } 716 }
715 delete $scope.articuloACargar.sectorCodigo; 717 delete $scope.articuloACargar.sectorCodigo;
716 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); 718 $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar);
717 $scope.cargando = true; 719 $scope.cargando = true;
718 } 720 }
719 }; 721 };
720 722
721 $scope.quitarArticulo = function(key) { 723 $scope.quitarArticulo = function(key) {
722 $scope.notaPedido.articulosNotaPedido.splice(key, 1); 724 $scope.notaPedido.articulosNotaPedido.splice(key, 1);
723 }; 725 };
724 726
725 $scope.editarArticulo = function(key, articulo) { 727 $scope.editarArticulo = function(key, articulo) {
726 if(key === 13) { 728 if(key === 13) {
727 if(articulo.cantidad === null || articulo.cantidad === 0 || 729 if(articulo.cantidad === null || articulo.cantidad === 0 ||
728 articulo.cantidad === undefined) { 730 articulo.cantidad === undefined) {
729 focaModalService.alert('El valor debe ser al menos 1'); 731 focaModalService.alert('El valor debe ser al menos 1');
730 return; 732 return;
731 } 733 }
732 articulo.editCantidad = false; 734 articulo.editCantidad = false;
733 articulo.editPrecio = false; 735 articulo.editPrecio = false;
734 } 736 }
735 }; 737 };
736 738
737 $scope.cambioEdit = function(articulo, propiedad) { 739 $scope.cambioEdit = function(articulo, propiedad) {
738 if(propiedad === 'cantidad') { 740 if(propiedad === 'cantidad') {
739 articulo.editCantidad = true; 741 articulo.editCantidad = true;
740 } else if(propiedad === 'precio') { 742 } else if(propiedad === 'precio') {
741 articulo.editPrecio = true; 743 articulo.editPrecio = true;
742 } 744 }
743 }; 745 };
744 746
745 $scope.resetFilter = function() { 747 $scope.resetFilter = function() {
746 $scope.articuloACargar = {}; 748 $scope.articuloACargar = {};
747 $scope.cargando = true; 749 $scope.cargando = true;
748 }; 750 };
749 //Recibe aviso si el teclado está en uso 751 //Recibe aviso si el teclado está en uso
750 $rootScope.$on('usarTeclado', function(event, data) { 752 $rootScope.$on('usarTeclado', function(event, data) {
751 if(data) { 753 if(data) {
752 $scope.mostrarTeclado = true; 754 $scope.mostrarTeclado = true;
753 return; 755 return;
754 } 756 }
755 $scope.mostrarTeclado = false; 757 $scope.mostrarTeclado = false;
756 }); 758 });
757 759
758 $scope.selectFocus = function($event) { 760 $scope.selectFocus = function($event) {
759 // Si el teclado esta en uso no selecciona el valor 761 // Si el teclado esta en uso no selecciona el valor
760 if($scope.mostrarTeclado) { 762 if($scope.mostrarTeclado) {
761 return; 763 return;
762 } 764 }
763 $event.target.select(); 765 $event.target.select();
764 }; 766 };
765 767
766 $scope.salir = function() { 768 $scope.salir = function() {
767 $location.path('/'); 769 $location.path('/');
768 }; 770 };
769 771
770 $scope.parsearATexto = function(articulo) { 772 $scope.parsearATexto = function(articulo) {
771 articulo.cantidad = parseFloat(articulo.cantidad); 773 articulo.cantidad = parseFloat(articulo.cantidad);
772 articulo.precio = parseFloat(articulo.precio); 774 articulo.precio = parseFloat(articulo.precio);
773 }; 775 };
774 776
775 function setearNotaPedido(notaPedido) { 777 function setearNotaPedido(notaPedido) {
776 //añado cabeceras 778 //añado cabeceras
777 $scope.notaPedido = notaPedido; 779 $scope.notaPedido = notaPedido;
778 $scope.$broadcast('removeCabecera', 'Bomba:'); 780 $scope.$broadcast('removeCabecera', 'Bomba:');
779 $scope.$broadcast('removeCabecera', 'Kilometros:'); 781 $scope.$broadcast('removeCabecera', 'Kilometros:');
780 782
781 var cabeceras = []; 783 var cabeceras = [];
782 784
783 if (notaPedido.cotizacion) { 785 if (notaPedido.cotizacion) {
784 cabeceras.push({ 786 cabeceras.push({
785 label: 'Moneda:', 787 label: 'Moneda:',
786 valor: notaPedido.cotizacion.moneda.DETALLE 788 valor: notaPedido.cotizacion.moneda.DETALLE
787 }); 789 });
788 cabeceras.push({ 790 cabeceras.push({
789 label: 'Fecha cotizacion:', 791 label: 'Fecha cotizacion:',
790 valor: $filter('date')(notaPedido.cotizacion.FECHA, 792 valor: $filter('date')(notaPedido.cotizacion.FECHA,
791 'dd/MM/yyyy') 793 'dd/MM/yyyy')
792 }); 794 });
793 cabeceras.push({ 795 cabeceras.push({
794 label: 'Cotizacion:', 796 label: 'Cotizacion:',
795 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 797 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
796 '2') 798 '2')
797 }); 799 });
798 } 800 }
799 if (notaPedido.cliente.COD) { 801 if (notaPedido.cliente.COD) {
800 cabeceras.push({ 802 cabeceras.push({
801 label: 'Cliente:', 803 label: 'Cliente:',
802 valor: notaPedido.cliente.NOM 804 valor: notaPedido.cliente.NOM
803 }); 805 });
804 cabeceras.push({ 806 cabeceras.push({
805 label: 'Domicilio:', 807 label: 'Domicilio:',
806 valor: notaPedido.domicilioStamp 808 valor: notaPedido.domicilioStamp
807 }); 809 });
808 } 810 }
809 if (notaPedido.vendedor.NUM) { 811 if (notaPedido.vendedor.NUM) {
810 cabeceras.push({ 812 cabeceras.push({
811 label: 'Vendedor:', 813 label: 'Vendedor:',
812 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + 814 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) +
813 ' - ' + notaPedido.vendedor.NOM 815 ' - ' + notaPedido.vendedor.NOM
814 }); 816 });
815 } 817 }
816 if (notaPedido.proveedor.COD) { 818 if (notaPedido.proveedor.COD) {
817 cabeceras.push({ 819 cabeceras.push({
818 label: 'Proveedor:', 820 label: 'Proveedor:',
819 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + 821 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) +
820 ' - ' + notaPedido.proveedor.NOM 822 ' - ' + notaPedido.proveedor.NOM
821 }); 823 });
822 } 824 }
823 if (notaPedido.notaPedidoPlazo) { 825 if (notaPedido.notaPedidoPlazo) {
824 cabeceras.push({ 826 cabeceras.push({
825 label: 'Precios y condiciones:', 827 label: 'Precios y condiciones:',
826 valor: valorPrecioCondicion() + ' ' + 828 valor: valorPrecioCondicion() + ' ' +
827 notaPedidoBusinessService 829 notaPedidoBusinessService
828 .plazoToString(notaPedido.notaPedidoPlazo) 830 .plazoToString(notaPedido.notaPedidoPlazo)
829 }); 831 });
830 } 832 }
831 if (notaPedido.flete !== undefined) { 833 if (notaPedido.flete !== undefined) {
832 cabeceras.push({ 834 cabeceras.push({
833 label: 'Flete:', 835 label: 'Flete:',
834 valor: notaPedido.fob === 1 ? 'FOB' : ( 836 valor: notaPedido.fob === 1 ? 'FOB' : (
835 notaPedido.flete === 1 ? 'Si' : 'No') 837 notaPedido.flete === 1 ? 'Si' : 'No')
836 }); 838 });
837 } 839 }
838 840
839 841
840 function valorPrecioCondicion() { 842 function valorPrecioCondicion() {
841 if(notaPedido.idPrecioCondicion > 0) { 843 if(notaPedido.idPrecioCondicion > 0) {
842 return notaPedido.precioCondicion.nombre; 844 return notaPedido.precioCondicion.nombre;
843 } else { 845 } else {
844 return 'Ingreso Manual'; 846 return 'Ingreso Manual';
845 } 847 }
846 } 848 }
847 849
848 if(notaPedido.flete === 1) { 850 if(notaPedido.flete === 1) {
849 var cabeceraBomba = { 851 var cabeceraBomba = {
850 label: 'Bomba:', 852 label: 'Bomba:',
851 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 853 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
852 }; 854 };
853 if(notaPedido.kilometros) { 855 if(notaPedido.kilometros) {
854 var cabeceraKilometros = { 856 var cabeceraKilometros = {
855 label: 'Kilometros:', 857 label: 'Kilometros:',
856 valor: notaPedido.kilometros 858 valor: notaPedido.kilometros
857 }; 859 };
858 cabeceras.push(cabeceraKilometros); 860 cabeceras.push(cabeceraKilometros);
859 } 861 }
860 cabeceras.push(cabeceraBomba); 862 cabeceras.push(cabeceraBomba);
861 } 863 }
862 864
863 notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, 865 notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido,
864 notaPedido.cotizacion.VENDEDOR); 866 notaPedido.cotizacion.VENDEDOR);
865 867
866 if(notaPedido.idPrecioCondicion > 0) { 868 if(notaPedido.idPrecioCondicion > 0) {
867 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 869 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
868 } else { 870 } else {
869 $scope.idLista = -1; 871 $scope.idLista = -1;
870 } 872 }
871 873
872 $scope.puntoVenta = $filter('rellenarDigitos')( 874 $scope.puntoVenta = $filter('rellenarDigitos')(
873 notaPedido.sucursal, 4 875 notaPedido.sucursal, 4
874 ); 876 );
875 877
876 $scope.comprobante = $filter('rellenarDigitos')( 878 $scope.comprobante = $filter('rellenarDigitos')(
877 notaPedido.numeroNotaPedido, 8 879 notaPedido.numeroNotaPedido, 8
878 ); 880 );
879 881
880 $scope.notaPedido.notaPedidoPuntoDescarga = 882 $scope.notaPedido.notaPedidoPuntoDescarga =
881 formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); 883 formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []);
882 addArrayCabecera(cabeceras); 884 addArrayCabecera(cabeceras);
883 } 885 }
884 886
885 function addArrayCabecera(array) { 887 function addArrayCabecera(array) {
886 for(var i = 0; i < array.length; i++) { 888 for(var i = 0; i < array.length; i++) {
887 $scope.$broadcast('addCabecera', { 889 $scope.$broadcast('addCabecera', {
888 label: array[i].label, 890 label: array[i].label,
889 valor: array[i].valor 891 valor: array[i].valor
890 }); 892 });
891 } 893 }
892 } 894 }
893 895
894 function validarNotaRemitada() { 896 function validarNotaRemitada() {
895 if(!$scope.notaPedido.idRemito) { 897 if(!$scope.notaPedido.idRemito) {
896 return true; 898 return true;
897 }else{ 899 }else{
898 focaModalService.alert('No se puede editar una nota de pedido remitada'); 900 focaModalService.alert('No se puede editar una nota de pedido remitada');
899 return false; 901 return false;
900 } 902 }
901 } 903 }
902 904
903 function formatearPuntosDescarga(puntosDescarga) { 905 function formatearPuntosDescarga(puntosDescarga) {
904 var result = []; 906 var result = [];
905 907
906 puntosDescarga.forEach(function(el) { 908 puntosDescarga.forEach(function(el) {
907 var puntoDescarga = result.filter(function(resultPunto) { 909 var puntoDescarga = result.filter(function(resultPunto) {
908 return resultPunto.id === el.idPuntoDescarga; 910 return resultPunto.id === el.idPuntoDescarga;
909 }); 911 });
910 912
911 if (puntoDescarga.length) { 913 if (puntoDescarga.length) {
912 puntoDescarga[0].articulosAgregados.push({ 914 puntoDescarga[0].articulosAgregados.push({
913 cantidad: el.cantidad, 915 cantidad: el.cantidad,
914 descripcion: el.producto.descripcion, 916 descripcion: el.producto.descripcion,
915 id: el.producto.id 917 id: el.producto.id
916 }); 918 });
917 } else { 919 } else {
918 result.push({ 920 result.push({
919 id: el.puntoDescarga.id, 921 id: el.puntoDescarga.id,
920 id_cliente: el.puntoDescarga.id_cliente, 922 id_cliente: el.puntoDescarga.id_cliente,
921 id_da_config_0: el.puntoDescarga.id_da_config_0, 923 id_da_config_0: el.puntoDescarga.id_da_config_0,
922 latitud: el.puntoDescarga.latitud, 924 latitud: el.puntoDescarga.latitud,
923 longitud: el.puntoDescarga.longitud, 925 longitud: el.puntoDescarga.longitud,
924 descripcion: el.puntoDescarga.descripcion, 926 descripcion: el.puntoDescarga.descripcion,
925 articulosAgregados: [ 927 articulosAgregados: [
926 { 928 {
927 cantidad: el.cantidad, 929 cantidad: el.cantidad,
928 descripcion: el.producto.descripcion, 930 descripcion: el.producto.descripcion,
929 id: el.producto.id 931 id: el.producto.id
930 } 932 }
931 ] 933 ]
932 }); 934 });
933 } 935 }
934 }); 936 });
935 return result; 937 return result;
936 } 938 }
937 939
938 function salir() { 940 function salir() {
939 var confirmacion = false; 941 var confirmacion = false;
940 942
941 if (!angular.equals($scope.notaPedido, $scope.inicial)) { 943 if (!angular.equals($scope.notaPedido, $scope.inicial)) {
942 confirmacion = true; 944 confirmacion = true;
943 } 945 }
944 946
945 if (confirmacion) { 947 if (confirmacion) {
946 focaModalService.confirm( 948 focaModalService.confirm(
947 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 949 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
948 ).then(function(data) { 950 ).then(function(data) {
949 if (data) { 951 if (data) {
950 $location.path('/'); 952 $location.path('/');
951 } 953 }
952 }); 954 });
953 } else { 955 } else {
954 $location.path('/'); 956 $location.path('/');
955 } 957 }
956 } 958 }
957 959
958 function getLSNotaPedido() { 960 function getLSNotaPedido() {
959 var notaPedido = JSON.parse($localStorage.notaPedido || null); 961 var notaPedido = JSON.parse($localStorage.notaPedido || null);
960 if (notaPedido) { 962 if (notaPedido) {
961 setearNotaPedido(notaPedido); 963 setearNotaPedido(notaPedido);
962 delete $localStorage.notaPedido; 964 delete $localStorage.notaPedido;
963 } 965 }
964 } 966 }