Commit 4abfac3b147a454f91b48762b5133254ddd61e1d

Authored by Eric Fernandez
1 parent d7c76f29c4
Exists in master

unit test servicios y rutas

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 12
13 var paths = { 13 var paths = {
14 srcJS: 'src/js/*.js', 14 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 15 srcViews: 'src/views/*.html',
16 specs: 'spec/*.js',
16 tmp: 'tmp', 17 tmp: 'tmp',
17 dist: 'dist/' 18 dist: 'dist/'
18 }; 19 };
19 20
20 gulp.task('templates', ['clean'], function() { 21 gulp.task('templates', ['clean'], function() {
21 return pump( 22 return pump(
22 [ 23 [
23 gulp.src(paths.srcViews), 24 gulp.src(paths.srcViews),
24 htmlmin(), 25 htmlmin(),
25 templateCache('views.js', { 26 templateCache('views.js', {
26 module: 'focaCrearNotaPedido', 27 module: 'focaCrearNotaPedido',
27 root: '' 28 root: ''
28 }), 29 }),
29 gulp.dest(paths.tmp) 30 gulp.dest(paths.tmp)
30 ] 31 ]
31 ); 32 );
32 }); 33 });
33 34
34 gulp.task('uglify', ['templates'], function() { 35 gulp.task('uglify', ['templates'], function() {
35 return pump( 36 return pump(
36 [ 37 [
37 gulp.src([ 38 gulp.src([
38 paths.srcJS, 39 paths.srcJS,
39 'tmp/views.js' 40 'tmp/views.js'
40 ]), 41 ]),
41 concat('foca-crear-nota-pedido.js'), 42 concat('foca-crear-nota-pedido.js'),
42 replace('src/views/', ''), 43 replace('src/views/', ''),
43 gulp.dest(paths.tmp), 44 gulp.dest(paths.tmp),
44 rename('foca-crear-nota-pedido.min.js'), 45 rename('foca-crear-nota-pedido.min.js'),
45 uglify(), 46 uglify(),
46 gulp.dest(paths.dist) 47 gulp.dest(paths.dist)
47 ] 48 ]
48 ); 49 );
49 }); 50 });
50 51
51 gulp.task('clean', function() { 52 gulp.task('clean', function() {
52 return gulp.src(['tmp', 'dist'], {read: false}) 53 return gulp.src(['tmp', 'dist'], {read: false})
53 .pipe(clean()); 54 .pipe(clean());
54 }); 55 });
55 56
56 gulp.task('pre-commit', function() { 57 gulp.task('pre-commit', function() {
57 return pump( 58 return pump(
58 [ 59 [
59 gulp.src(paths.srcJS), 60 gulp.src([paths.srcJS, paths.specs]),
60 jshint('.jshintrc'), 61 jshint('.jshintrc'),
61 jshint.reporter('default'), 62 jshint.reporter('default'),
62 jshint.reporter('fail') 63 jshint.reporter('fail')
63 ] 64 ]
64 ); 65 );
65 66
66 gulp.start('uglify'); 67 gulp.start('uglify');
67 }); 68 });
68 69
69 gulp.task('webserver', function() { 70 gulp.task('webserver', function() {
70 pump [ 71 pump [
71 connect.server({port: 3300, host: '0.0.0.0'}) 72 connect.server({port: 3300, host: '0.0.0.0'})
72 ] 73 ]
73 }); 74 });
74 75
75 gulp.task('clean-post-install', function() { 76 gulp.task('clean-post-install', function() {
76 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 77 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
77 'index.html'], {read: false}) 78 'index.html'], {read: false})
78 .pipe(clean()); 79 .pipe(clean());
79 }); 80 });
80 81
81 gulp.task('default', ['webserver']); 82 gulp.task('default', ['webserver']);
82 83
83 gulp.task('watch', function() { 84 gulp.task('watch', function() {
84 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 85 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
85 }); 86 });
86 87
87 gulp.task('copy', ['uglify'], function() { 88 gulp.task('copy', ['uglify'], function() {
88 return gulp.src('dist/*.js') 89 return gulp.src('dist/*.js')
89 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/')); 90 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/'));
90 }); 91 });
91 92
92 gulp.task('watchAndCopy', function() { 93 gulp.task('watchAndCopy', function() {
93 return gulp.watch([paths.srcJS], ['copy']); 94 return gulp.watch([paths.srcJS], ['copy']);
94 }); 95 });
95 96
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": "echo \"Error: no test specified\" && exit 1", 7 "test": "test.html",
8 "compile": "gulp uglify", 8 "compile": "gulp uglify",
9 "gulp-pre-commit": "gulp pre-commit", 9 "gulp-pre-commit": "gulp pre-commit",
10 "postinstall": "npm run compile && gulp clean-post-install", 10 "postinstall": "npm run compile && gulp clean-post-install",
11 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+http://git.focasoftware.com/npm/foca-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-route": "^1.7.5", 41 "angular-route": "^1.7.5",
41 "bootstrap": "^4.1.3", 42 "bootstrap": "^4.1.3",
42 "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",
43 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", 44 "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git",
44 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", 45 "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git",
45 "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",
46 "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",
47 "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",
48 "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",
49 "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",
50 "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",
51 "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",
52 "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",
53 "foca-seguimiento": "git+http://git.focasoftware.com/npm/foca-seguimiento.git", 54 "foca-seguimiento": "git+http://git.focasoftware.com/npm/foca-seguimiento.git",
54 "font-awesome": "^4.7.0", 55 "font-awesome": "^4.7.0",
55 "gulp": "^3.9.1", 56 "gulp": "^3.9.1",
56 "gulp-angular-templatecache": "^2.2.5", 57 "gulp-angular-templatecache": "^2.2.5",
57 "gulp-clean": "^0.4.0", 58 "gulp-clean": "^0.4.0",
58 "gulp-concat": "^2.6.1", 59 "gulp-concat": "^2.6.1",
59 "gulp-connect": "^5.6.1", 60 "gulp-connect": "^5.6.1",
60 "gulp-htmlmin": "^5.0.1", 61 "gulp-htmlmin": "^5.0.1",
61 "gulp-jshint": "^2.1.0", 62 "gulp-jshint": "^2.1.0",
62 "gulp-rename": "^1.4.0", 63 "gulp-rename": "^1.4.0",
63 "gulp-replace": "^1.0.0", 64 "gulp-replace": "^1.0.0",
64 "gulp-sequence": "^1.0.0", 65 "gulp-sequence": "^1.0.0",
65 "gulp-uglify": "^3.0.1", 66 "gulp-uglify": "^3.0.1",
66 "gulp-uglify-es": "^1.0.4", 67 "gulp-uglify-es": "^1.0.4",
67 "jasmine-core": "^3.3.0", 68 "jasmine-core": "^3.3.0",
68 "jquery": "^3.3.1", 69 "jquery": "^3.3.1",
69 "jshint": "^2.9.6", 70 "jshint": "^2.9.6",
70 "ladda": "1.0.6", 71 "ladda": "1.0.6",
71 "pre-commit": "^1.2.2", 72 "pre-commit": "^1.2.2",
72 "pump": "^3.0.0", 73 "pump": "^3.0.0",
73 "ui-bootstrap4": "^3.0.5" 74 "ui-bootstrap4": "^3.0.5"
74 } 75 }
75 } 76 }
76 77
File was created 1 describe('Rutas del módulo crear nota de pedido', function() {
2
3 var route;
4
5 beforeEach(function() {
6 module('focaCrearNotaPedido');
7 inject(function($route) {
8 route = $route;
9 });
10 });
11
12 it('la ruta /venta-nota-pedido/crear dirige correctamente', function() {
13 //expect
14 expect(route.routes['/venta-nota-pedido/crear'].controller)
15 .toBe('notaPedidoCtrl');
16 expect(route.routes['/venta-nota-pedido/crear'].templateUrl)
17 .toBe('src/views/nota-pedido.html');
18 });
19 });
20
File was created 1 describe('Servicios módulo crear nota de pedido', function() {
2
3 beforeEach(function() {
4 module('focaCrearNotaPedido');
5 });
6
7 describe('servicios crearNotaPedidoService', function() {
8
9 var servicio, httpBackend;
10
11 beforeEach(function() {
12
13 inject(module(function($provide) {
14 $provide.value('API_ENDPOINT', {
15 URL: 'localhost'
16 });
17 }));
18
19 inject(function(_crearNotaPedidoService_, $httpBackend) {
20 servicio = _crearNotaPedidoService_;
21 httpBackend = $httpBackend;
22 });
23 });
24
25 it('Existe el servicio crearNotaPedidoService', function() {
26 //assert
27 expect(typeof servicio).toEqual('object');
28 });
29
30 it('la función crearNotaPedido lleva la ruta correcta', function() {
31 //arrange
32 var responseFake = { data: 'test'};
33 var result;
34 var bodyFake = 1;
35 httpBackend.expectPOST('localhost/nota-pedido', { notaPedido: bodyFake })
36 .respond(responseFake);
37
38 //act
39 servicio.crearNotaPedido(bodyFake).then(function(data) {
40 result = data.data;
41 });
42 httpBackend.flush();
43
44 //assert
45 expect(result).toEqual(responseFake);
46 });
47
48 it('la función obtenerNotaPedido lleva la ruta correcta', function() {
49 //arrange
50 var responseFake = { data: 'test'};
51 var result;
52 httpBackend.expectGET('localhost/nota-pedido').respond(responseFake);
53
54 //act
55 servicio.obtenerNotaPedido().then(function(data) {
56 result = data.data;
57 });
58 httpBackend.flush();
59
60 //assert
61 expect(result).toEqual(responseFake);
62 });
63
64 it('la función setNotaPedido setea nota pedido', function() {
65 //arrange
66 var paramFake = 1;
67
68 //act
69 servicio.setNotaPedido(paramFake);
70
71 //assert
72 expect(servicio.notaPedido).toEqual(paramFake);
73 });
74
75 it('la función clearNotaPedido setea nota pedido undefined', function() {
76
77 //act
78 servicio.clearNotaPedido();
79
80 //assert
81 expect(servicio.notaPedido).toEqual(undefined);
82 });
83
84 it('la función clearNotaPedido setea nota pedido undefined', function() {
85 //arrange
86 var paramFake = 1;
87
88 //act
89 servicio.setNotaPedido(paramFake);
90 var result = servicio.getNotaPedido();
91
92 //assert
93 expect(result).toEqual(paramFake);
94 });
95
96 it('la funcion getArticulosByIdNotaPedido llama a la ruta correcta', function() {
97
98 //arrange
99 var responseFake = { data: 'test'};
100 var result;
101 var paramFake = 1;
102 httpBackend.expectGET('localhost/articulos/nota-pedido/' + paramFake)
103 .respond(responseFake);
104
105 //act
106 servicio.getArticulosByIdNotaPedido(paramFake).then(function(data) {
107 result = data.data;
108 });
109 httpBackend.flush();
110
111 //assert
112 expect(result).toEqual(responseFake);
113 });
114
115 it('la funcion crearArticulosParaNotaPedido llama a la ruta correcta', function() {
116
117 //arrange
118 var responseFake = { data: 'test'};
119 var result;
120 var paramFake = 1;
121 httpBackend.expectPOST('localhost/articulos/nota-pedido',
122 {articuloNotaPedido: paramFake}).respond(responseFake);
123
124 //act
125 servicio.crearArticulosParaNotaPedido(paramFake).then(function(data) {
126 result = data.data;
127 });
128 httpBackend.flush();
129
130 //assert
131 expect(result).toEqual(responseFake);
132 });
133
134 it('la funcion getDomiciliosByIdNotaPedido llama a la ruta correcta', function() {
135
136 //arrange
137 var responseFake = { data: 'test'};
138 var result;
139 var paramFake = 1;
140 httpBackend.expectGET('localhost/nota-pedido/' + paramFake + '/domicilios')
141 .respond(responseFake);
142
143 //act
144 servicio.getDomiciliosByIdNotaPedido(paramFake).then(function(data) {
145 result = data.data;
146 });
147 httpBackend.flush();
148
149 //assert
150 expect(result).toEqual(responseFake);
151 });
152
153 it('la funcion getDomiciliosByIdCliente llama a la ruta correcta', function() {
154
155 //arrange
156 var responseFake = { data: 'test'};
157 var result;
158 var paramFake = 1;
159 httpBackend.expectGET('localhost/domicilio/tipo/2/cliente/' + paramFake )
160 .respond(responseFake);
161
162 //act
163 servicio.getDomiciliosByIdCliente(paramFake).then(function(data) {
164 result = data.data;
165 });
166 httpBackend.flush();
167
168 //assert
169 expect(result).toEqual(responseFake);
170 });
171
172 it('la funcion getPrecioCondicion llama a la ruta correcta', function() {
173
174 //arrange
175 var responseFake = { data: 'test'};
176 var result;
177 httpBackend.expectGET('localhost/precio-condicion').respond(responseFake);
178
179 //act
180 servicio.getPrecioCondicion().then(function(data) {
181 result = data.data;
182 });
183 httpBackend.flush();
184
185 //assert
186 expect(result).toEqual(responseFake);
187 });
188
189 it('la funcion getPrecioCondicionById llama a la ruta correcta', function() {
190
191 //arrange
192 var responseFake = { data: 'test'};
193 var result;
194 var paramFake = 1;
195 httpBackend.expectGET('localhost/precio-condicion/' + paramFake).respond(responseFake);
196
197 //act
198 servicio.getPrecioCondicionById(paramFake).then(function(data) {
199 result = data.data;
200 });
201 httpBackend.flush();
202
203 //assert
204 expect(result).toEqual(responseFake);
205 });
206
207 it('la funcion getPlazoPagoByPrecioCondicion llama a la ruta correcta', function() {
208
209 //arrange
210 var responseFake = { data: 'test'};
211 var result;
212 var paramFake = 1;
213 httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + paramFake)
214 .respond(responseFake);
215
216 //act
217 servicio.getPlazoPagoByPrecioCondicion(paramFake).then(function(data) {
218 result = data.data;
219 });
220 httpBackend.flush();
221
222 //assert
223 expect(result).toEqual(responseFake);
224 });
225
226 it('la funcion crearFlete llama a la ruta correcta', function() {
227
228 //arrange
229 var responseFake = { data: 'test'};
230 var result;
231 var paramFake = 1;
232 httpBackend.expectPOST('localhost/flete', { flete: paramFake })
233 .respond(responseFake);
234
235 //act
236 servicio.crearFlete(paramFake).then(function(data) {
237 result = data.data;
238 });
239 httpBackend.flush();
240
241 //assert
242 expect(result).toEqual(responseFake);
243 });
244
245 it('la funcion crearPlazosParaNotaPedido llama a la ruta correcta', function() {
246
247 //arrange
248 var responseFake = { data: 'test'};
249 var result;
250 var paramFake = 1;
251 httpBackend.expectPOST('localhost/plazo-pago/nota-pedido', { plazos: paramFake })
252 .respond(responseFake);
253
254 //act
255 servicio.crearPlazosParaNotaPedido(paramFake).then(function(data) {
256 result = data.data;
257 });
258 httpBackend.flush();
259
260 //assert
261 expect(result).toEqual(responseFake);
262 });
263
264 it('la funcion getCotizacionByIdMoneda llama a la ruta correcta', function() {
265
266 //arrange
267 var responseFake = { data: 'test'};
268 var result;
269 var paramFake = 1;
270 httpBackend.expectGET('localhost/moneda/' + paramFake).respond(responseFake);
271
272 //act
273 servicio.getCotizacionByIdMoneda(paramFake).then(function(data) {
274 result = data.data;
275 });
276 httpBackend.flush();
277
278 //assert
279 expect(result).toEqual(responseFake);
280 });
281
282 it('la funcion crearEstadoParaNotaPedido llama a la ruta correcta', function() {
283
284 //arrange
285 var responseFake = { data: 'test'};
286 var result;
287 var paramFake = 1;
288 httpBackend.expectPOST('localhost/estado', { estado: paramFake })
289 .respond(responseFake);
290
291 //act
292 servicio.crearEstadoParaNotaPedido(paramFake).then(function(data) {
293 result = data.data;
294 });
295 httpBackend.flush();
296
297 //assert
298 expect(result).toEqual(responseFake);
299 });
300
301 it('la funcion getNumeroNotaPedido llama a la ruta correcta', function() {
302
303 //arrange
304 var responseFake = { data: 'test'};
305 var result;
306 httpBackend.expectGET('localhost/nota-pedido/numero-siguiente').respond(responseFake);
307
308 //act
309 servicio.getNumeroNotaPedido().then(function(data) {
310 result = data.data;
311 });
312 httpBackend.flush();
313
314 //assert
315 expect(result).toEqual(responseFake);
316 });
317
318 it('la funcion crearPuntosDescarga llama a la ruta correcta', function() {
319
320 //arrange
321 var responseFake = { data: 'test'};
322 var result;
323 var paramFake = 1;
324 httpBackend.expectPOST('localhost/puntos-descarga/nota-pedido',
325 { puntosDescarga: paramFake }).respond(responseFake);
326
327 //act
328 servicio.crearPuntosDescarga(paramFake).then(function(data) {
329 result = data.data;
330 });
331 httpBackend.flush();
332
333 //assert
334 expect(result).toEqual(responseFake);
335 });
336
337 it('la funcion getPuntosDescargaByClienDom llama a la ruta correcta', function() {
338
339 //arrange
340 var responseFake = { data: 'test'};
341 var result;
342 var paramFake = 1;
343 var paramFake2 = 1;
344 httpBackend.expectGET('localhost/punto-descarga/' + paramFake + '/' + paramFake2)
345 .respond(responseFake);
346
347 //act
348 servicio.getPuntosDescargaByClienDom(paramFake, paramFake2).then(function(data) {
349 result = data.data;
350 });
351 httpBackend.flush();
352
353 //assert
354 expect(result).toEqual(responseFake);
355 });
356
357 it('la funcion getVendedorById llama a la ruta correcta', function() {
358
359 //arrange
360 var responseFake = { data: 'test'};
361 var result;
362 var paramFake = 1;
363 httpBackend.expectGET('localhost/vendedor-cobrador/' + paramFake)
364 .respond(responseFake);
365
366 //act
367 servicio.getVendedorById(paramFake).then(function(data) {
368 result = data.data;
369 });
370 httpBackend.flush();
371
372 //assert
373 expect(result).toEqual(responseFake);
374 });
375
376 });
377 });
378
1 angular.module('focaCrearNotaPedido', []); 1 angular.module('focaCrearNotaPedido', ['ngRoute']);
2 2
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 function( 16 function(
17 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, 17 $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService,
18 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, 18 focaBotoneraLateralService, focaModalService, notaPedidoBusinessService,
19 $rootScope, focaSeguimientoService, APP, focaLoginService) 19 $rootScope, focaSeguimientoService, APP, focaLoginService)
20 { 20 {
21 config(); 21 config();
22 22
23 function config() { 23 function config() {
24 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA 24 // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA
25 $scope.isNumber = angular.isNumber; 25 $scope.isNumber = angular.isNumber;
26 $scope.datepickerAbierto = false; 26 $scope.datepickerAbierto = false;
27 $scope.show = false; 27 $scope.show = false;
28 $scope.cargando = true; 28 $scope.cargando = true;
29 $scope.now = new Date(); 29 $scope.now = new Date();
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 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { 54 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
55 $scope.monedaDefecto = res.data[0]; 55 $scope.monedaDefecto = res.data[0];
56 $scope.cotizacionDefecto = $scope.monedaDefecto.cotizaciones[0]; 56 $scope.cotizacionDefecto = $scope.monedaDefecto.cotizaciones[0];
57 57
58 init(); 58 init();
59 }); 59 });
60 } 60 }
61 61
62 function init() { 62 function init() {
63 $scope.$broadcast('cleanCabecera'); 63 $scope.$broadcast('cleanCabecera');
64 64
65 $scope.notaPedido = { 65 $scope.notaPedido = {
66 id: 0, 66 id: 0,
67 cliente: {}, 67 cliente: {},
68 proveedor: {}, 68 proveedor: {},
69 domicilio: {dom: ''}, 69 domicilio: {dom: ''},
70 vendedor: {}, 70 vendedor: {},
71 moneda: $scope.monedaDefecto, 71 moneda: $scope.monedaDefecto,
72 cotizacion: $scope.cotizacionDefecto 72 cotizacion: $scope.cotizacionDefecto
73 }; 73 };
74 74
75 $scope.articulosTabla = []; 75 $scope.articulosTabla = [];
76 $scope.idLista = undefined; 76 $scope.idLista = undefined;
77 77
78 crearNotaPedidoService.getNumeroNotaPedido().then( 78 crearNotaPedidoService.getNumeroNotaPedido().then(
79 function(res) { 79 function(res) {
80 $scope.puntoVenta = $filter('rellenarDigitos')( 80 $scope.puntoVenta = $filter('rellenarDigitos')(
81 res.data.sucursal, 4 81 res.data.sucursal, 4
82 ); 82 );
83 83
84 $scope.comprobante = $filter('rellenarDigitos')( 84 $scope.comprobante = $filter('rellenarDigitos')(
85 res.data.numeroNotaPedido, 8 85 res.data.numeroNotaPedido, 8
86 ); 86 );
87 }, 87 },
88 function(err) { 88 function(err) {
89 focaModalService.alert('La terminal no esta configurada correctamente'); 89 focaModalService.alert('La terminal no esta configurada correctamente');
90 console.info(err); 90 console.info(err);
91 } 91 }
92 ); 92 );
93 93
94 if (APP === 'distribuidor') { 94 if (APP === 'distribuidor') {
95 crearNotaPedidoService.getVendedorById($scope.idVendedor).then( 95 crearNotaPedidoService.getVendedorById($scope.idVendedor).then(
96 function(res) { 96 function(res) {
97 var vendedor = res.data; 97 var vendedor = res.data;
98 $scope.$broadcast('addCabecera', { 98 $scope.$broadcast('addCabecera', {
99 label: 'Vendedor:', 99 label: 'Vendedor:',
100 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 100 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
101 vendedor.NOM 101 vendedor.NOM
102 }); 102 });
103 103
104 $scope.notaPedido.vendedor = vendedor; 104 $scope.notaPedido.vendedor = vendedor;
105 $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; 105 $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor;
106 } 106 }
107 ); 107 );
108 } 108 }
109 109
110 $scope.inicial = { 110 $scope.inicial = {
111 notaPedido: angular.copy($scope.notaPedido), 111 notaPedido: angular.copy($scope.notaPedido),
112 articulosTabla: angular.copy($scope.articulosTabla), 112 articulosTabla: angular.copy($scope.articulosTabla),
113 idLista: angular.copy($scope.idLista) 113 idLista: angular.copy($scope.idLista)
114 }; 114 };
115 } 115 }
116 116
117 $scope.crearNotaPedido = function() { 117 $scope.crearNotaPedido = function() {
118 if(!$scope.notaPedido.vendedor.id) { 118 if(!$scope.notaPedido.vendedor.id) {
119 focaModalService.alert('Ingrese Vendedor'); 119 focaModalService.alert('Ingrese Vendedor');
120 return; 120 return;
121 } else if(!$scope.notaPedido.cliente.COD) { 121 } else if(!$scope.notaPedido.cliente.COD) {
122 focaModalService.alert('Ingrese Cliente'); 122 focaModalService.alert('Ingrese Cliente');
123 return; 123 return;
124 } else if(!$scope.notaPedido.proveedor.COD) { 124 } else if(!$scope.notaPedido.proveedor.COD) {
125 focaModalService.alert('Ingrese Proveedor'); 125 focaModalService.alert('Ingrese Proveedor');
126 return; 126 return;
127 } else if(!$scope.notaPedido.moneda.ID) { 127 } else if(!$scope.notaPedido.moneda.ID) {
128 focaModalService.alert('Ingrese Moneda'); 128 focaModalService.alert('Ingrese Moneda');
129 return; 129 return;
130 } else if(!$scope.notaPedido.cotizacion.ID) { 130 } else if(!$scope.notaPedido.cotizacion.ID) {
131 focaModalService.alert('Ingrese Cotización'); 131 focaModalService.alert('Ingrese Cotización');
132 return; 132 return;
133 } else if(!$scope.plazosPagos) { 133 } else if(!$scope.plazosPagos) {
134 focaModalService.alert('Ingrese Precios y Condiciones'); 134 focaModalService.alert('Ingrese Precios y Condiciones');
135 return; 135 return;
136 } else if( 136 } else if(
137 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) 137 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null)
138 { 138 {
139 focaModalService.alert('Ingrese Flete'); 139 focaModalService.alert('Ingrese Flete');
140 return; 140 return;
141 } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto 141 } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto
142 focaModalService.alert('Ingrese Domicilio'); 142 focaModalService.alert('Ingrese Domicilio');
143 return; 143 return;
144 } else if($scope.articulosTabla.length === 0) { 144 } else if($scope.articulosTabla.length === 0) {
145 focaModalService.alert('Debe cargar al menos un articulo'); 145 focaModalService.alert('Debe cargar al menos un articulo');
146 return; 146 return;
147 } 147 }
148 focaBotoneraLateralService.startGuardar(); 148 focaBotoneraLateralService.startGuardar();
149 $scope.saveLoading = true; 149 $scope.saveLoading = true;
150 var notaPedido = { 150 var notaPedido = {
151 id: $scope.notaPedido.id, 151 id: $scope.notaPedido.id,
152 fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 152 fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
153 idVendedor: $scope.notaPedido.vendedor.id, 153 idVendedor: $scope.notaPedido.vendedor.id,
154 idCliente: $scope.notaPedido.cliente.COD, 154 idCliente: $scope.notaPedido.cliente.COD,
155 nombreCliente: $scope.notaPedido.cliente.NOM, 155 nombreCliente: $scope.notaPedido.cliente.NOM,
156 cuitCliente: $scope.notaPedido.cliente.CUIT, 156 cuitCliente: $scope.notaPedido.cliente.CUIT,
157 idProveedor: $scope.notaPedido.proveedor.COD, 157 idProveedor: $scope.notaPedido.proveedor.COD,
158 idDomicilio: $scope.notaPedido.domicilio.id, 158 idDomicilio: $scope.notaPedido.domicilio.id,
159 idCotizacion: $scope.notaPedido.cotizacion.ID, 159 idCotizacion: $scope.notaPedido.cotizacion.ID,
160 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, 160 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion,
161 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 161 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
162 flete: $scope.notaPedido.flete, 162 flete: $scope.notaPedido.flete,
163 fob: $scope.notaPedido.fob, 163 fob: $scope.notaPedido.fob,
164 bomba: $scope.notaPedido.bomba, 164 bomba: $scope.notaPedido.bomba,
165 kilometros: $scope.notaPedido.kilometros, 165 kilometros: $scope.notaPedido.kilometros,
166 domicilioStamp: $scope.notaPedido.domicilioStamp, 166 domicilioStamp: $scope.notaPedido.domicilioStamp,
167 observaciones: $scope.notaPedido.observaciones, 167 observaciones: $scope.notaPedido.observaciones,
168 estado: 0, 168 estado: 0,
169 total: $scope.getTotal() 169 total: $scope.getTotal()
170 }; 170 };
171 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 171 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
172 function(data) { 172 function(data) {
173 // Al guardar los datos de la nota de pedido logueamos la 173 // Al guardar los datos de la nota de pedido logueamos la
174 // actividad para su seguimiento. 174 // actividad para su seguimiento.
175 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? 175 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR?
176 focaSeguimientoService.guardarPosicion( 176 focaSeguimientoService.guardarPosicion(
177 'Nota de pedido', 177 'Nota de pedido',
178 data.data.id, 178 data.data.id,
179 '' 179 ''
180 ); 180 );
181 notaPedidoBusinessService.addArticulos($scope.articulosTabla, 181 notaPedidoBusinessService.addArticulos($scope.articulosTabla,
182 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); 182 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR);
183 183
184 if($scope.notaPedido.puntosDescarga) { 184 if($scope.notaPedido.puntosDescarga) {
185 notaPedidoBusinessService.addPuntosDescarga(data.data.id, 185 notaPedidoBusinessService.addPuntosDescarga(data.data.id,
186 $scope.notaPedido.puntosDescarga); 186 $scope.notaPedido.puntosDescarga);
187 } 187 }
188 188
189 var plazos = $scope.plazosPagos; 189 var plazos = $scope.plazosPagos;
190 var plazosACrear = []; 190 var plazosACrear = [];
191 plazos.forEach(function(plazo) { 191 plazos.forEach(function(plazo) {
192 plazosACrear.push({ 192 plazosACrear.push({
193 idNotaPedido: data.data.id, 193 idNotaPedido: data.data.id,
194 dias: plazo.dias 194 dias: plazo.dias
195 }); 195 });
196 }); 196 });
197 197
198 if (plazosACrear.length) { 198 if (plazosACrear.length) {
199 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); 199 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear);
200 } 200 }
201 201
202 notaPedidoBusinessService.addEstado(data.data.id, 202 notaPedidoBusinessService.addEstado(data.data.id,
203 $scope.notaPedido.vendedor.id); 203 $scope.notaPedido.vendedor.id);
204 204
205 focaBotoneraLateralService.endGuardar(true); 205 focaBotoneraLateralService.endGuardar(true);
206 $scope.saveLoading = false; 206 $scope.saveLoading = false;
207 207
208 init(); 208 init();
209 }, function(error) { 209 }, function(error) {
210 focaModalService.alert('Hubo un error al crear la nota de pedido'); 210 focaModalService.alert('Hubo un error al crear la nota de pedido');
211 focaBotoneraLateralService.endGuardar(); 211 focaBotoneraLateralService.endGuardar();
212 $scope.saveLoading = false; 212 $scope.saveLoading = false;
213 console.info(error); 213 console.info(error);
214 } 214 }
215 ); 215 );
216 }; 216 };
217 217
218 $scope.seleccionarNotaPedido = function() { 218 $scope.seleccionarNotaPedido = function() {
219 var modalInstance = $uibModal.open( 219 var modalInstance = $uibModal.open(
220 { 220 {
221 ariaLabelledBy: 'Busqueda de Nota de Pedido', 221 ariaLabelledBy: 'Busqueda de Nota de Pedido',
222 templateUrl: 'foca-modal-nota-pedido.html', 222 templateUrl: 'foca-modal-nota-pedido.html',
223 controller: 'focaModalNotaPedidoController', 223 controller: 'focaModalNotaPedidoController',
224 size: 'lg', 224 size: 'lg',
225 resolve: { 225 resolve: {
226 usadoPor: function() {return 'notaPedido';}, 226 usadoPor: function() {return 'notaPedido';},
227 idVendedor: function() { 227 idVendedor: function() {
228 if(APP === 'distribuidor') 228 if(APP === 'distribuidor')
229 return $scope.notaPedido.vendedor.id; 229 return $scope.notaPedido.vendedor.id;
230 else 230 else
231 return null; 231 return null;
232 } 232 }
233 } 233 }
234 } 234 }
235 ); 235 );
236 modalInstance.result.then( 236 modalInstance.result.then(
237 function(notaPedido) { 237 function(notaPedido) {
238 $scope.now = new Date(notaPedido.fechaCarga); 238 $scope.now = new Date(notaPedido.fechaCarga);
239 //añado cabeceras 239 //añado cabeceras
240 $scope.notaPedido.id = notaPedido.id; 240 $scope.notaPedido.id = notaPedido.id;
241 $scope.$broadcast('removeCabecera', 'Bomba:'); 241 $scope.$broadcast('removeCabecera', 'Bomba:');
242 $scope.$broadcast('removeCabecera', 'Kilometros:'); 242 $scope.$broadcast('removeCabecera', 'Kilometros:');
243 var cabeceras = [ 243 var cabeceras = [
244 { 244 {
245 label: 'Moneda:', 245 label: 'Moneda:',
246 valor: notaPedido.cotizacion.moneda.DETALLE 246 valor: notaPedido.cotizacion.moneda.DETALLE
247 }, 247 },
248 { 248 {
249 label: 'Fecha cotizacion:', 249 label: 'Fecha cotizacion:',
250 valor: $filter('date')(notaPedido.cotizacion.FECHA, 250 valor: $filter('date')(notaPedido.cotizacion.FECHA,
251 'dd/MM/yyyy') 251 'dd/MM/yyyy')
252 }, 252 },
253 { 253 {
254 label: 'Cotizacion:', 254 label: 'Cotizacion:',
255 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 255 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
256 '2') 256 '2')
257 }, 257 },
258 { 258 {
259 label: 'Cliente:', 259 label: 'Cliente:',
260 valor: notaPedido.cliente.NOM 260 valor: notaPedido.cliente.NOM
261 }, 261 },
262 { 262 {
263 label: 'Domicilio:', 263 label: 'Domicilio:',
264 valor: notaPedido.domicilioStamp 264 valor: notaPedido.domicilioStamp
265 }, 265 },
266 { 266 {
267 label: 'Vendedor:', 267 label: 'Vendedor:',
268 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + 268 valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) +
269 ' - ' + notaPedido.vendedor.NOM 269 ' - ' + notaPedido.vendedor.NOM
270 }, 270 },
271 { 271 {
272 label: 'Proveedor:', 272 label: 'Proveedor:',
273 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + 273 valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) +
274 ' - ' + notaPedido.proveedor.NOM 274 ' - ' + notaPedido.proveedor.NOM
275 }, 275 },
276 { 276 {
277 label: 'Precios y condiciones:', 277 label: 'Precios y condiciones:',
278 valor: valorPrecioCondicion() + ' ' + 278 valor: valorPrecioCondicion() + ' ' +
279 notaPedidoBusinessService 279 notaPedidoBusinessService
280 .plazoToString(notaPedido.notaPedidoPlazo) 280 .plazoToString(notaPedido.notaPedidoPlazo)
281 }, 281 },
282 { 282 {
283 label: 'Flete:', 283 label: 'Flete:',
284 valor: notaPedido.fob === 1 ? 'FOB' : ( 284 valor: notaPedido.fob === 1 ? 'FOB' : (
285 notaPedido.flete === 1 ? 'Si' : 'No') 285 notaPedido.flete === 1 ? 'Si' : 'No')
286 } 286 }
287 ]; 287 ];
288 288
289 function valorPrecioCondicion() { 289 function valorPrecioCondicion() {
290 if(notaPedido.idPrecioCondicion > 0) { 290 if(notaPedido.idPrecioCondicion > 0) {
291 return notaPedido.precioCondicion.nombre; 291 return notaPedido.precioCondicion.nombre;
292 } else { 292 } else {
293 return 'Ingreso Manual'; 293 return 'Ingreso Manual';
294 } 294 }
295 } 295 }
296 296
297 if(notaPedido.flete === 1) { 297 if(notaPedido.flete === 1) {
298 var cabeceraBomba = { 298 var cabeceraBomba = {
299 label: 'Bomba:', 299 label: 'Bomba:',
300 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 300 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
301 }; 301 };
302 if(notaPedido.kilometros) { 302 if(notaPedido.kilometros) {
303 var cabeceraKilometros = { 303 var cabeceraKilometros = {
304 label: 'Kilometros:', 304 label: 'Kilometros:',
305 valor: notaPedido.kilometros 305 valor: notaPedido.kilometros
306 }; 306 };
307 cabeceras.push(cabeceraKilometros); 307 cabeceras.push(cabeceraKilometros);
308 } 308 }
309 cabeceras.push(cabeceraBomba); 309 cabeceras.push(cabeceraBomba);
310 } 310 }
311 311
312 $scope.articulosTabla = notaPedido.articulosNotaPedido; 312 $scope.articulosTabla = notaPedido.articulosNotaPedido;
313 notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, 313 notaPedidoBusinessService.calcularArticulos($scope.articulosTabla,
314 notaPedido.cotizacion.VENDEDOR); 314 notaPedido.cotizacion.VENDEDOR);
315 315
316 if(notaPedido.idPrecioCondicion > 0) { 316 if(notaPedido.idPrecioCondicion > 0) {
317 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 317 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
318 } else { 318 } else {
319 $scope.idLista = -1; 319 $scope.idLista = -1;
320 } 320 }
321 321
322 $scope.puntoVenta = $filter('rellenarDigitos')( 322 $scope.puntoVenta = $filter('rellenarDigitos')(
323 notaPedido.sucursal, 4 323 notaPedido.sucursal, 4
324 ); 324 );
325 325
326 $scope.comprobante = $filter('rellenarDigitos')( 326 $scope.comprobante = $filter('rellenarDigitos')(
327 notaPedido.numeroNotaPedido, 8 327 notaPedido.numeroNotaPedido, 8
328 ); 328 );
329 329
330 $scope.notaPedido = notaPedido; 330 $scope.notaPedido = notaPedido;
331 $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; 331 $scope.notaPedido.moneda = notaPedido.cotizacion.moneda;
332 $scope.plazosPagos = notaPedido.notaPedidoPlazo; 332 $scope.plazosPagos = notaPedido.notaPedidoPlazo;
333 $scope.notaPedido.puntosDescarga = 333 $scope.notaPedido.puntosDescarga =
334 formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); 334 formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga);
335 addArrayCabecera(cabeceras); 335 addArrayCabecera(cabeceras);
336 336
337 }, function() { 337 }, function() {
338 // funcion ejecutada cuando se cancela el modal 338 // funcion ejecutada cuando se cancela el modal
339 } 339 }
340 ); 340 );
341 }; 341 };
342 342
343 $scope.seleccionarProductos = function() { 343 $scope.seleccionarProductos = function() {
344 if ($scope.idLista === undefined) { 344 if ($scope.idLista === undefined) {
345 focaModalService.alert( 345 focaModalService.alert(
346 'Primero seleccione una lista de precio y condicion'); 346 'Primero seleccione una lista de precio y condicion');
347 return; 347 return;
348 } 348 }
349 var modalInstance = $uibModal.open( 349 var modalInstance = $uibModal.open(
350 { 350 {
351 ariaLabelledBy: 'Busqueda de Productos', 351 ariaLabelledBy: 'Busqueda de Productos',
352 templateUrl: 'modal-busqueda-productos.html', 352 templateUrl: 'modal-busqueda-productos.html',
353 controller: 'modalBusquedaProductosCtrl', 353 controller: 'modalBusquedaProductosCtrl',
354 resolve: { 354 resolve: {
355 parametroProducto: { 355 parametroProducto: {
356 idLista: $scope.idLista, 356 idLista: $scope.idLista,
357 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 357 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
358 simbolo: $scope.notaPedido.moneda.SIMBOLO 358 simbolo: $scope.notaPedido.moneda.SIMBOLO
359 } 359 }
360 }, 360 },
361 size: 'lg' 361 size: 'lg'
362 } 362 }
363 ); 363 );
364 modalInstance.result.then( 364 modalInstance.result.then(
365 function(producto) { 365 function(producto) {
366 var newArt = 366 var newArt =
367 { 367 {
368 id: 0, 368 id: 0,
369 codigo: producto.codigo, 369 codigo: producto.codigo,
370 sector: producto.sector, 370 sector: producto.sector,
371 sectorCodigo: producto.sector + '-' + producto.codigo, 371 sectorCodigo: producto.sector + '-' + producto.codigo,
372 descripcion: producto.descripcion, 372 descripcion: producto.descripcion,
373 item: $scope.articulosTabla.length + 1, 373 item: $scope.articulosTabla.length + 1,
374 nombre: producto.descripcion, 374 nombre: producto.descripcion,
375 precio: parseFloat(producto.precio.toFixed(4)), 375 precio: parseFloat(producto.precio.toFixed(4)),
376 costoUnitario: producto.costo, 376 costoUnitario: producto.costo,
377 editCantidad: false, 377 editCantidad: false,
378 editPrecio: false, 378 editPrecio: false,
379 rubro: producto.CodRub, 379 rubro: producto.CodRub,
380 exentoUnitario: producto.precio, 380 exentoUnitario: producto.precio,
381 ivaUnitario: producto.IMPIVA, 381 ivaUnitario: producto.IMPIVA,
382 impuestoInternoUnitario: producto.ImpInt, 382 impuestoInternoUnitario: producto.ImpInt,
383 impuestoInterno1Unitario: producto.ImpInt2, 383 impuestoInterno1Unitario: producto.ImpInt2,
384 impuestoInterno2Unitario: producto.ImpInt3, 384 impuestoInterno2Unitario: producto.ImpInt3,
385 precioLista: producto.precio, 385 precioLista: producto.precio,
386 combustible: 1, 386 combustible: 1,
387 facturado: 0, 387 facturado: 0,
388 idArticulo: producto.id 388 idArticulo: producto.id
389 }; 389 };
390 $scope.articuloACargar = newArt; 390 $scope.articuloACargar = newArt;
391 $scope.cargando = false; 391 $scope.cargando = false;
392 }, function() { 392 }, function() {
393 // funcion ejecutada cuando se cancela el modal 393 // funcion ejecutada cuando se cancela el modal
394 } 394 }
395 ); 395 );
396 }; 396 };
397 397
398 $scope.seleccionarPuntosDeDescarga = function() { 398 $scope.seleccionarPuntosDeDescarga = function() {
399 if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { 399 if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) {
400 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 400 focaModalService.alert('Primero seleccione un cliente y un domicilio');
401 return; 401 return;
402 }else { 402 }else {
403 var modalInstance = $uibModal.open( 403 var modalInstance = $uibModal.open(
404 { 404 {
405 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 405 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
406 templateUrl: 'modal-punto-descarga.html', 406 templateUrl: 'modal-punto-descarga.html',
407 controller: 'focaModalPuntoDescargaController', 407 controller: 'focaModalPuntoDescargaController',
408 size: 'lg', 408 size: 'lg',
409 resolve: { 409 resolve: {
410 filters: { 410 filters: {
411 idDomicilio: $scope.notaPedido.domicilio.id, 411 idDomicilio: $scope.notaPedido.domicilio.id,
412 idCliente: $scope.notaPedido.cliente.COD, 412 idCliente: $scope.notaPedido.cliente.COD,
413 articulos: $scope.articulosTabla, 413 articulos: $scope.articulosTabla,
414 puntosDescarga: $scope.notaPedido.puntosDescarga 414 puntosDescarga: $scope.notaPedido.puntosDescarga
415 } 415 }
416 } 416 }
417 } 417 }
418 ); 418 );
419 modalInstance.result.then( 419 modalInstance.result.then(
420 function(puntosDescarga) { 420 function(puntosDescarga) {
421 $scope.notaPedido.puntosDescarga = puntosDescarga; 421 $scope.notaPedido.puntosDescarga = puntosDescarga;
422 422
423 //AGREGO PUNTOS DE DESCARGA A CABECERA 423 //AGREGO PUNTOS DE DESCARGA A CABECERA
424 var puntosStamp = ''; 424 var puntosStamp = '';
425 puntosDescarga.forEach(function(punto, idx, arr) { 425 puntosDescarga.forEach(function(punto, idx, arr) {
426 puntosStamp += punto.descripcion; 426 puntosStamp += punto.descripcion;
427 if((idx + 1) !== arr.length) puntosStamp += ', '; 427 if((idx + 1) !== arr.length) puntosStamp += ', ';
428 }); 428 });
429 429
430 $scope.$broadcast('addCabecera', { 430 $scope.$broadcast('addCabecera', {
431 label: 'Puntos de descarga:', 431 label: 'Puntos de descarga:',
432 valor: puntosStamp 432 valor: puntosStamp
433 }); 433 });
434 }, function() { 434 }, function() {
435 $scope.abrirModalDomicilios($scope.cliente); 435 $scope.abrirModalDomicilios($scope.cliente);
436 } 436 }
437 ); 437 );
438 } 438 }
439 }; 439 };
440 440
441 $scope.seleccionarVendedor = function() { 441 $scope.seleccionarVendedor = function() {
442 if(validarNotaRemitada()) { 442 if(validarNotaRemitada()) {
443 var parametrosModal = { 443 var parametrosModal = {
444 titulo: 'Búsqueda vendedores', 444 titulo: 'Búsqueda vendedores',
445 query: '/vendedor', 445 query: '/vendedor',
446 columnas: [ 446 columnas: [
447 { 447 {
448 propiedad: 'NUM', 448 propiedad: 'NUM',
449 nombre: 'Código', 449 nombre: 'Código',
450 filtro: { 450 filtro: {
451 nombre: 'rellenarDigitos', 451 nombre: 'rellenarDigitos',
452 parametro: 3 452 parametro: 3
453 } 453 }
454 }, 454 },
455 { 455 {
456 propiedad: 'NOM', 456 propiedad: 'NOM',
457 nombre: 'Nombre' 457 nombre: 'Nombre'
458 } 458 }
459 ], 459 ],
460 size: 'md' 460 size: 'md'
461 }; 461 };
462 focaModalService.modal(parametrosModal).then( 462 focaModalService.modal(parametrosModal).then(
463 function(vendedor) { 463 function(vendedor) {
464 $scope.$broadcast('addCabecera', { 464 $scope.$broadcast('addCabecera', {
465 label: 'Vendedor:', 465 label: 'Vendedor:',
466 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 466 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
467 vendedor.NOM 467 vendedor.NOM
468 }); 468 });
469 $scope.notaPedido.vendedor = vendedor; 469 $scope.notaPedido.vendedor = vendedor;
470 }, function() { 470 }, function() {
471 471
472 } 472 }
473 ); 473 );
474 } 474 }
475 }; 475 };
476 476
477 $scope.seleccionarProveedor = function() { 477 $scope.seleccionarProveedor = function() {
478 if(validarNotaRemitada()) { 478 if(validarNotaRemitada()) {
479 var parametrosModal = { 479 var parametrosModal = {
480 titulo: 'Búsqueda de Proveedor', 480 titulo: 'Búsqueda de Proveedor',
481 query: '/proveedor', 481 query: '/proveedor',
482 columnas: [ 482 columnas: [
483 { 483 {
484 nombre: 'Código', 484 nombre: 'Código',
485 propiedad: 'COD', 485 propiedad: 'COD',
486 filtro: { 486 filtro: {
487 nombre: 'rellenarDigitos', 487 nombre: 'rellenarDigitos',
488 parametro: 5 488 parametro: 5
489 } 489 }
490 }, 490 },
491 { 491 {
492 nombre: 'Nombre', 492 nombre: 'Nombre',
493 propiedad: 'NOM' 493 propiedad: 'NOM'
494 }, 494 },
495 { 495 {
496 nombre: 'CUIT', 496 nombre: 'CUIT',
497 propiedad: 'CUIT' 497 propiedad: 'CUIT'
498 } 498 }
499 ], 499 ],
500 tipo: 'POST', 500 tipo: 'POST',
501 json: {razonCuitCod: ''} 501 json: {razonCuitCod: ''}
502 }; 502 };
503 focaModalService.modal(parametrosModal).then( 503 focaModalService.modal(parametrosModal).then(
504 function(proveedor) { 504 function(proveedor) {
505 $scope.notaPedido.proveedor = proveedor; 505 $scope.notaPedido.proveedor = proveedor;
506 $scope.$broadcast('addCabecera', { 506 $scope.$broadcast('addCabecera', {
507 label: 'Proveedor:', 507 label: 'Proveedor:',
508 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 508 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
509 proveedor.NOM 509 proveedor.NOM
510 }); 510 });
511 }, function() { 511 }, function() {
512 512
513 } 513 }
514 ); 514 );
515 } 515 }
516 }; 516 };
517 517
518 $scope.seleccionarCliente = function() { 518 $scope.seleccionarCliente = function() {
519 if(!$scope.notaPedido.vendedor.NUM) { 519 if(!$scope.notaPedido.vendedor.NUM) {
520 focaModalService.alert('Primero seleccione un vendedor'); 520 focaModalService.alert('Primero seleccione un vendedor');
521 return; 521 return;
522 } 522 }
523 if(validarNotaRemitada()) { 523 if(validarNotaRemitada()) {
524 var modalInstance = $uibModal.open( 524 var modalInstance = $uibModal.open(
525 { 525 {
526 ariaLabelledBy: 'Busqueda de Cliente', 526 ariaLabelledBy: 'Busqueda de Cliente',
527 templateUrl: 'foca-busqueda-cliente-modal.html', 527 templateUrl: 'foca-busqueda-cliente-modal.html',
528 controller: 'focaBusquedaClienteModalController', 528 controller: 'focaBusquedaClienteModalController',
529 resolve: { 529 resolve: {
530 vendedor: function() { return $scope.notaPedido.vendedor; } 530 vendedor: function() { return $scope.notaPedido.vendedor; }
531 }, 531 },
532 size: 'lg' 532 size: 'lg'
533 } 533 }
534 ); 534 );
535 modalInstance.result.then( 535 modalInstance.result.then(
536 function(cliente) { 536 function(cliente) {
537 $scope.abrirModalDomicilios(cliente); 537 $scope.abrirModalDomicilios(cliente);
538 $scope.cliente = cliente; 538 $scope.cliente = cliente;
539 }, function() {} 539 }, function() {}
540 ); 540 );
541 } 541 }
542 }; 542 };
543 543
544 $scope.abrirModalDomicilios = function(cliente) { 544 $scope.abrirModalDomicilios = function(cliente) {
545 var modalInstanceDomicilio = $uibModal.open( 545 var modalInstanceDomicilio = $uibModal.open(
546 { 546 {
547 ariaLabelledBy: 'Busqueda de Domicilios', 547 ariaLabelledBy: 'Busqueda de Domicilios',
548 templateUrl: 'modal-domicilio.html', 548 templateUrl: 'modal-domicilio.html',
549 controller: 'focaModalDomicilioController', 549 controller: 'focaModalDomicilioController',
550 resolve: { 550 resolve: {
551 idCliente: function() { return cliente.cod; }, 551 idCliente: function() { return cliente.cod; },
552 esNuevo: function() { return cliente.esNuevo; } 552 esNuevo: function() { return cliente.esNuevo; }
553 }, 553 },
554 size: 'lg', 554 size: 'lg',
555 } 555 }
556 ); 556 );
557 modalInstanceDomicilio.result.then( 557 modalInstanceDomicilio.result.then(
558 function(domicilio) { 558 function(domicilio) {
559 $scope.notaPedido.domicilio = domicilio; 559 $scope.notaPedido.domicilio = domicilio;
560 $scope.notaPedido.cliente = { 560 $scope.notaPedido.cliente = {
561 COD: cliente.cod, 561 COD: cliente.cod,
562 CUIT: cliente.cuit, 562 CUIT: cliente.cuit,
563 NOM: cliente.nom 563 NOM: cliente.nom
564 }; 564 };
565 var domicilioStamp = 565 var domicilioStamp =
566 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 566 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
567 domicilio.Localidad + ', ' + domicilio.Provincia; 567 domicilio.Localidad + ', ' + domicilio.Provincia;
568 $scope.notaPedido.domicilioStamp = domicilioStamp; 568 $scope.notaPedido.domicilioStamp = domicilioStamp;
569 569
570 $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; 570 $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga;
571 571
572 $scope.$broadcast('addCabecera', { 572 $scope.$broadcast('addCabecera', {
573 label: 'Cliente:', 573 label: 'Cliente:',
574 valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom 574 valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom
575 }); 575 });
576 $scope.$broadcast('addCabecera', { 576 $scope.$broadcast('addCabecera', {
577 label: 'Domicilio:', 577 label: 'Domicilio:',
578 valor: domicilioStamp 578 valor: domicilioStamp
579 }); 579 });
580 if(domicilio.verPuntos) { 580 if(domicilio.verPuntos) {
581 delete $scope.notaPedido.domicilio.verPuntos; 581 delete $scope.notaPedido.domicilio.verPuntos;
582 $scope.seleccionarPuntosDeDescarga(); 582 $scope.seleccionarPuntosDeDescarga();
583 }else { 583 }else {
584 crearNotaPedidoService 584 crearNotaPedidoService
585 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 585 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
586 .then(function(res) { 586 .then(function(res) {
587 if(res.data.length) $scope.seleccionarPuntosDeDescarga(); 587 if(res.data.length) $scope.seleccionarPuntosDeDescarga();
588 }); 588 });
589 } 589 }
590 }, function() { 590 }, function() {
591 $scope.seleccionarCliente(); 591 $scope.seleccionarCliente();
592 return; 592 return;
593 } 593 }
594 ); 594 );
595 }; 595 };
596 596
597 $scope.getTotal = function() { 597 $scope.getTotal = function() {
598 var total = 0; 598 var total = 0;
599 599
600 if ($scope.articulosTabla) { 600 if ($scope.articulosTabla) {
601 var arrayTempArticulos = $scope.articulosTabla; 601 var arrayTempArticulos = $scope.articulosTabla;
602 for (var i = 0; i < arrayTempArticulos.length; i++) { 602 for (var i = 0; i < arrayTempArticulos.length; i++) {
603 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 603 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
604 } 604 }
605 } 605 }
606 606
607 return parseFloat(total.toFixed(2)); 607 return parseFloat(total.toFixed(2));
608 }; 608 };
609 609
610 $scope.getSubTotal = function() { 610 $scope.getSubTotal = function() {
611 if($scope.articuloACargar) { 611 if($scope.articuloACargar) {
612 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 612 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
613 } 613 }
614 }; 614 };
615 615
616 $scope.seleccionarPreciosYCondiciones = function() { 616 $scope.seleccionarPreciosYCondiciones = function() {
617 if(validarNotaRemitada()) { 617 if(validarNotaRemitada()) {
618 var modalInstance = $uibModal.open( 618 var modalInstance = $uibModal.open(
619 { 619 {
620 ariaLabelledBy: 'Busqueda de Precio Condición', 620 ariaLabelledBy: 'Busqueda de Precio Condición',
621 templateUrl: 'modal-precio-condicion.html', 621 templateUrl: 'modal-precio-condicion.html',
622 controller: 'focaModalPrecioCondicionController', 622 controller: 'focaModalPrecioCondicionController',
623 size: 'lg' 623 size: 'lg'
624 } 624 }
625 ); 625 );
626 modalInstance.result.then( 626 modalInstance.result.then(
627 function(precioCondicion) { 627 function(precioCondicion) {
628 var cabecera = ''; 628 var cabecera = '';
629 var plazosConcat = ''; 629 var plazosConcat = '';
630 if(!Array.isArray(precioCondicion)) { 630 if(!Array.isArray(precioCondicion)) {
631 $scope.notaPedido.idPrecioCondicion = precioCondicion.id; 631 $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
632 $scope.plazosPagos = precioCondicion.plazoPago; 632 $scope.plazosPagos = precioCondicion.plazoPago;
633 $scope.idLista = precioCondicion.idListaPrecio; 633 $scope.idLista = precioCondicion.idListaPrecio;
634 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 634 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
635 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 635 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
636 } 636 }
637 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 637 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
638 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 638 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
639 } else { //Cuando se ingresan los plazos manualmente 639 } else { //Cuando se ingresan los plazos manualmente
640 $scope.notaPedido.idPrecioCondicion = 0; 640 $scope.notaPedido.idPrecioCondicion = 0;
641 //-1, el modal productos busca todos los productos 641 //-1, el modal productos busca todos los productos
642 $scope.idLista = -1; 642 $scope.idLista = -1;
643 $scope.plazosPagos = precioCondicion; 643 $scope.plazosPagos = precioCondicion;
644 for(var j = 0; j < precioCondicion.length; j++) { 644 for(var j = 0; j < precioCondicion.length; j++) {
645 plazosConcat += precioCondicion[j].dias + ' '; 645 plazosConcat += precioCondicion[j].dias + ' ';
646 } 646 }
647 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 647 cabecera = 'Ingreso manual ' + plazosConcat.trim();
648 } 648 }
649 $scope.articulosTabla = []; 649 $scope.articulosTabla = [];
650 $scope.$broadcast('addCabecera', { 650 $scope.$broadcast('addCabecera', {
651 label: 'Precios y condiciones:', 651 label: 'Precios y condiciones:',
652 valor: cabecera 652 valor: cabecera
653 }); 653 });
654 }, function() { 654 }, function() {
655 655
656 } 656 }
657 ); 657 );
658 } 658 }
659 }; 659 };
660 660
661 $scope.seleccionarFlete = function() { 661 $scope.seleccionarFlete = function() {
662 if(validarNotaRemitada()) { 662 if(validarNotaRemitada()) {
663 var modalInstance = $uibModal.open( 663 var modalInstance = $uibModal.open(
664 { 664 {
665 ariaLabelledBy: 'Busqueda de Flete', 665 ariaLabelledBy: 'Busqueda de Flete',
666 templateUrl: 'modal-flete.html', 666 templateUrl: 'modal-flete.html',
667 controller: 'focaModalFleteController', 667 controller: 'focaModalFleteController',
668 size: 'lg', 668 size: 'lg',
669 resolve: { 669 resolve: {
670 parametrosFlete: 670 parametrosFlete:
671 function() { 671 function() {
672 return { 672 return {
673 flete: $scope.notaPedido.fob ? 'FOB' : 673 flete: $scope.notaPedido.fob ? 'FOB' :
674 ( $scope.notaPedido.flete ? '1' : 674 ( $scope.notaPedido.flete ? '1' :
675 ($scope.notaPedido.flete === undefined ? 675 ($scope.notaPedido.flete === undefined ?
676 null : '0')), 676 null : '0')),
677 bomba: $scope.notaPedido.bomba ? '1' : 677 bomba: $scope.notaPedido.bomba ? '1' :
678 ($scope.notaPedido.bomba === undefined ? 678 ($scope.notaPedido.bomba === undefined ?
679 null : '0'), 679 null : '0'),
680 kilometros: $scope.notaPedido.kilometros 680 kilometros: $scope.notaPedido.kilometros
681 }; 681 };
682 } 682 }
683 } 683 }
684 } 684 }
685 ); 685 );
686 modalInstance.result.then( 686 modalInstance.result.then(
687 function(datos) { 687 function(datos) {
688 $scope.notaPedido.flete = datos.flete; 688 $scope.notaPedido.flete = datos.flete;
689 $scope.notaPedido.fob = datos.FOB; 689 $scope.notaPedido.fob = datos.FOB;
690 $scope.notaPedido.bomba = datos.bomba; 690 $scope.notaPedido.bomba = datos.bomba;
691 $scope.notaPedido.kilometros = datos.kilometros; 691 $scope.notaPedido.kilometros = datos.kilometros;
692 $scope.$broadcast('addCabecera', { 692 $scope.$broadcast('addCabecera', {
693 label: 'Flete:', 693 label: 'Flete:',
694 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') 694 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')
695 }); 695 });
696 if(datos.flete) { 696 if(datos.flete) {
697 $scope.$broadcast('addCabecera', { 697 $scope.$broadcast('addCabecera', {
698 label: 'Bomba:', 698 label: 'Bomba:',
699 valor: datos.bomba ? 'Si' : 'No' 699 valor: datos.bomba ? 'Si' : 'No'
700 }); 700 });
701 $scope.$broadcast('addCabecera', { 701 $scope.$broadcast('addCabecera', {
702 label: 'Kilometros:', 702 label: 'Kilometros:',
703 valor: datos.kilometros 703 valor: datos.kilometros
704 }); 704 });
705 } else { 705 } else {
706 $scope.$broadcast('removeCabecera', 'Bomba:'); 706 $scope.$broadcast('removeCabecera', 'Bomba:');
707 $scope.$broadcast('removeCabecera', 'Kilometros:'); 707 $scope.$broadcast('removeCabecera', 'Kilometros:');
708 $scope.notaPedido.bomba = false; 708 $scope.notaPedido.bomba = false;
709 $scope.notaPedido.kilometros = null; 709 $scope.notaPedido.kilometros = null;
710 } 710 }
711 }, function() { 711 }, function() {
712 712
713 } 713 }
714 ); 714 );
715 } 715 }
716 }; 716 };
717 717
718 $scope.seleccionarMoneda = function() { 718 $scope.seleccionarMoneda = function() {
719 if(validarNotaRemitada()) { 719 if(validarNotaRemitada()) {
720 var parametrosModal = { 720 var parametrosModal = {
721 titulo: 'Búsqueda de monedas', 721 titulo: 'Búsqueda de monedas',
722 query: '/moneda', 722 query: '/moneda',
723 columnas: [ 723 columnas: [
724 { 724 {
725 propiedad: 'DETALLE', 725 propiedad: 'DETALLE',
726 nombre: 'Nombre' 726 nombre: 'Nombre'
727 }, 727 },
728 { 728 {
729 propiedad: 'SIMBOLO', 729 propiedad: 'SIMBOLO',
730 nombre: 'Símbolo' 730 nombre: 'Símbolo'
731 } 731 }
732 ], 732 ],
733 size: 'md' 733 size: 'md'
734 }; 734 };
735 focaModalService.modal(parametrosModal).then( 735 focaModalService.modal(parametrosModal).then(
736 function(moneda) { 736 function(moneda) {
737 $scope.abrirModalCotizacion(moneda); 737 $scope.abrirModalCotizacion(moneda);
738 }, function() { 738 }, function() {
739 739
740 } 740 }
741 ); 741 );
742 } 742 }
743 }; 743 };
744 744
745 $scope.seleccionarObservaciones = function() { 745 $scope.seleccionarObservaciones = function() {
746 focaModalService 746 focaModalService
747 .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true) 747 .prompt('Ingrese observaciones', $scope.notaPedido.observaciones, true)
748 .then(function(observaciones) { 748 .then(function(observaciones) {
749 $scope.notaPedido.observaciones = observaciones; 749 $scope.notaPedido.observaciones = observaciones;
750 }); 750 });
751 }; 751 };
752 752
753 $scope.abrirModalCotizacion = function(moneda) { 753 $scope.abrirModalCotizacion = function(moneda) {
754 var modalInstance = $uibModal.open( 754 var modalInstance = $uibModal.open(
755 { 755 {
756 ariaLabelledBy: 'Busqueda de Cotización', 756 ariaLabelledBy: 'Busqueda de Cotización',
757 templateUrl: 'modal-cotizacion.html', 757 templateUrl: 'modal-cotizacion.html',
758 controller: 'focaModalCotizacionController', 758 controller: 'focaModalCotizacionController',
759 size: 'lg', 759 size: 'lg',
760 resolve: { 760 resolve: {
761 idMoneda: function() { 761 idMoneda: function() {
762 return moneda.ID; 762 return moneda.ID;
763 } 763 }
764 } 764 }
765 } 765 }
766 ); 766 );
767 modalInstance.result.then( 767 modalInstance.result.then(
768 function(cotizacion) { 768 function(cotizacion) {
769 var articulosTablaTemp = $scope.articulosTabla; 769 var articulosTablaTemp = $scope.articulosTabla;
770 770
771 for(var i = 0; i < articulosTablaTemp.length; i++) { 771 for(var i = 0; i < articulosTablaTemp.length; i++) {
772 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 772 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
773 $scope.notaPedido.cotizacion.VENDEDOR; 773 $scope.notaPedido.cotizacion.VENDEDOR;
774 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 774 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
775 cotizacion.VENDEDOR; 775 cotizacion.VENDEDOR;
776 } 776 }
777 777
778 $scope.articulosTabla = articulosTablaTemp; 778 $scope.articulosTabla = articulosTablaTemp;
779 $scope.notaPedido.moneda = moneda; 779 $scope.notaPedido.moneda = moneda;
780 $scope.monedaDefecto = moneda; 780 $scope.monedaDefecto = moneda;
781 $scope.cotizacionDefecto = cotizacion; 781 $scope.cotizacionDefecto = cotizacion;
782 $scope.notaPedido.cotizacion = cotizacion; 782 $scope.notaPedido.cotizacion = cotizacion;
783 783
784 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 784 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
785 $scope.$broadcast('removeCabecera', 'Moneda:'); 785 $scope.$broadcast('removeCabecera', 'Moneda:');
786 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 786 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
787 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 787 $scope.$broadcast('removeCabecera', 'Cotizacion:');
788 } else { 788 } else {
789 $scope.$broadcast('addCabecera', { 789 $scope.$broadcast('addCabecera', {
790 label: 'Moneda:', 790 label: 'Moneda:',
791 valor: moneda.DETALLE 791 valor: moneda.DETALLE
792 }); 792 });
793 $scope.$broadcast('addCabecera', { 793 $scope.$broadcast('addCabecera', {
794 label: 'Fecha cotizacion:', 794 label: 'Fecha cotizacion:',
795 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 795 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
796 }); 796 });
797 $scope.$broadcast('addCabecera', { 797 $scope.$broadcast('addCabecera', {
798 label: 'Cotizacion:', 798 label: 'Cotizacion:',
799 valor: $filter('number')(cotizacion.VENDEDOR, '2') 799 valor: $filter('number')(cotizacion.VENDEDOR, '2')
800 }); 800 });
801 } 801 }
802 }, function() { 802 }, function() {
803 803
804 } 804 }
805 ); 805 );
806 }; 806 };
807 807
808 $scope.agregarATabla = function(key) { 808 $scope.agregarATabla = function(key) {
809 if(key === 13) { 809 if(key === 13) {
810 if($scope.articuloACargar.cantidad === undefined || 810 if($scope.articuloACargar.cantidad === undefined ||
811 $scope.articuloACargar.cantidad === 0 || 811 $scope.articuloACargar.cantidad === 0 ||
812 $scope.articuloACargar.cantidad === null ) { 812 $scope.articuloACargar.cantidad === null ) {
813 focaModalService.alert('El valor debe ser al menos 1'); 813 focaModalService.alert('El valor debe ser al menos 1');
814 return; 814 return;
815 } 815 }
816 delete $scope.articuloACargar.sectorCodigo; 816 delete $scope.articuloACargar.sectorCodigo;
817 $scope.articulosTabla.push($scope.articuloACargar); 817 $scope.articulosTabla.push($scope.articuloACargar);
818 $scope.cargando = true; 818 $scope.cargando = true;
819 } 819 }
820 }; 820 };
821 821
822 $scope.quitarArticulo = function(key) { 822 $scope.quitarArticulo = function(key) {
823 $scope.articulosTabla.splice(key, 1); 823 $scope.articulosTabla.splice(key, 1);
824 }; 824 };
825 825
826 $scope.editarArticulo = function(key, articulo) { 826 $scope.editarArticulo = function(key, articulo) {
827 if(key === 13) { 827 if(key === 13) {
828 if(articulo.cantidad === null || articulo.cantidad === 0 || 828 if(articulo.cantidad === null || articulo.cantidad === 0 ||
829 articulo.cantidad === undefined) { 829 articulo.cantidad === undefined) {
830 focaModalService.alert('El valor debe ser al menos 1'); 830 focaModalService.alert('El valor debe ser al menos 1');
831 return; 831 return;
832 } 832 }
833 articulo.editCantidad = false; 833 articulo.editCantidad = false;
834 articulo.editPrecio = false; 834 articulo.editPrecio = false;
835 } 835 }
836 }; 836 };
837 837
838 $scope.cambioEdit = function(articulo, propiedad) { 838 $scope.cambioEdit = function(articulo, propiedad) {
839 if(propiedad === 'cantidad') { 839 if(propiedad === 'cantidad') {
840 articulo.editCantidad = true; 840 articulo.editCantidad = true;
841 } else if(propiedad === 'precio') { 841 } else if(propiedad === 'precio') {
842 articulo.editPrecio = true; 842 articulo.editPrecio = true;
843 } 843 }
844 }; 844 };
845 845
846 $scope.resetFilter = function() { 846 $scope.resetFilter = function() {
847 $scope.articuloACargar = {}; 847 $scope.articuloACargar = {};
848 $scope.cargando = true; 848 $scope.cargando = true;
849 }; 849 };
850 //Recibe aviso si el teclado está en uso 850 //Recibe aviso si el teclado está en uso
851 $rootScope.$on('usarTeclado', function(event, data) { 851 $rootScope.$on('usarTeclado', function(event, data) {
852 if(data) { 852 if(data) {
853 $scope.mostrarTeclado = true; 853 $scope.mostrarTeclado = true;
854 return; 854 return;
855 } 855 }
856 $scope.mostrarTeclado = false; 856 $scope.mostrarTeclado = false;
857 }); 857 });
858 858
859 $scope.selectFocus = function($event) { 859 $scope.selectFocus = function($event) {
860 // Si el teclado esta en uso no selecciona el valor 860 // Si el teclado esta en uso no selecciona el valor
861 if($scope.mostrarTeclado) { 861 if($scope.mostrarTeclado) {
862 return; 862 return;
863 } 863 }
864 $event.target.select(); 864 $event.target.select();
865 }; 865 };
866 866
867 $scope.salir = function() { 867 $scope.salir = function() {
868 $location.path('/'); 868 $location.path('/');
869 }; 869 };
870 870
871 $scope.parsearATexto = function(articulo) { 871 $scope.parsearATexto = function(articulo) {
872 articulo.cantidad = parseFloat(articulo.cantidad); 872 articulo.cantidad = parseFloat(articulo.cantidad);
873 articulo.precio = parseFloat(articulo.precio); 873 articulo.precio = parseFloat(articulo.precio);
874 }; 874 };
875 875
876 function addArrayCabecera(array) { 876 function addArrayCabecera(array) {
877 for(var i = 0; i < array.length; i++) { 877 for(var i = 0; i < array.length; i++) {
878 $scope.$broadcast('addCabecera', { 878 $scope.$broadcast('addCabecera', {
879 label: array[i].label, 879 label: array[i].label,
880 valor: array[i].valor 880 valor: array[i].valor
881 }); 881 });
882 } 882 }
883 } 883 }
884 884
885 function validarNotaRemitada() { 885 function validarNotaRemitada() {
886 if(!$scope.notaPedido.idRemito) { 886 if(!$scope.notaPedido.idRemito) {
887 return true; 887 return true;
888 }else{ 888 }else{
889 focaModalService.alert('No se puede editar una nota de pedido remitada'); 889 focaModalService.alert('No se puede editar una nota de pedido remitada');
890 return false; 890 return false;
891 } 891 }
892 } 892 }
893 893
894 function formatearPuntosDescarga(puntosDescarga) { 894 function formatearPuntosDescarga(puntosDescarga) {
895 var result = []; 895 var result = [];
896 896
897 puntosDescarga.forEach(function(el) { 897 puntosDescarga.forEach(function(el) {
898 var puntoDescarga = result.filter(function(resultPunto) { 898 var puntoDescarga = result.filter(function(resultPunto) {
899 return resultPunto.id === el.idPuntoDescarga; 899 return resultPunto.id === el.idPuntoDescarga;
900 }); 900 });
901 901
902 if(puntoDescarga.length) { 902 if(puntoDescarga.length) {
903 puntoDescarga[0].articulosAgregados.push({ 903 puntoDescarga[0].articulosAgregados.push({
904 cantidad: el.cantidad, 904 cantidad: el.cantidad,
905 descripcion: el.producto.descripcion, 905 descripcion: el.producto.descripcion,
906 id: el.producto.id 906 id: el.producto.id
907 }); 907 });
908 }else { 908 }else {
909 result.push({ 909 result.push({
910 id: el.puntoDescarga.id, 910 id: el.puntoDescarga.id,
911 id_cliente: el.puntoDescarga.id_cliente, 911 id_cliente: el.puntoDescarga.id_cliente,
912 id_da_config_0: el.puntoDescarga.id_da_config_0, 912 id_da_config_0: el.puntoDescarga.id_da_config_0,
913 latitud: el.puntoDescarga.latitud, 913 latitud: el.puntoDescarga.latitud,
914 longitud: el.puntoDescarga.longitud, 914 longitud: el.puntoDescarga.longitud,
915 descripcion: el.puntoDescarga.descripcion, 915 descripcion: el.puntoDescarga.descripcion,
916 articulosAgregados: [ 916 articulosAgregados: [
917 { 917 {
918 cantidad: el.cantidad, 918 cantidad: el.cantidad,
919 descripcion: el.producto.descripcion, 919 descripcion: el.producto.descripcion,
920 id: el.producto.id 920 id: el.producto.id
921 } 921 }
922 ] 922 ]
923 }); 923 });
924 } 924 }
925 }); 925 });
926 return result; 926 return result;
927 } 927 }
928 928
929 function salir() { 929 function salir() {
930 var confirmacion = false; 930 var confirmacion = false;
931 931
932 angular.forEach($scope.inicial, function(valor, key) { 932 angular.forEach($scope.inicial, function(valor, key) {
933 if (!angular.equals($scope[key], $scope.inicial[key])) { 933 if (!angular.equals($scope[key], $scope.inicial[key])) {
934 confirmacion = true; 934 confirmacion = true;
935 } 935 }
936 }); 936 });
937 937
938 if (confirmacion) { 938 if (confirmacion) {
939 focaModalService.confirm( 939 focaModalService.confirm(
940 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 940 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
941 ).then(function(data) { 941 ).then(function(data) {
942 if (data) { 942 if (data) {
943 $location.path('/'); 943 $location.path('/');
944 } 944 }
945 }); 945 });
946 } else { 946 } else {
947 $location.path('/'); 947 $location.path('/');
948 } 948 }
949 } 949 }
950 } 950 }
951 ]); 951 ]);
952 952
File was created 1 <html>
2 <head>
3 <link rel="stylesheet" type="text/css" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
4 <meta charset="UTF-8" />
5 </head>
6 <body>
7 <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
8 <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
9 <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
10 <script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
11 <script type="text/javascript" src="node_modules/angular-route/angular-route.min.js"></script>
12 <script type="text/javascript" src="node_modules/angular-mocks/angular-mocks.js"></script>
13 <script type="text/javascript" src="src/js/app.js"></script>
14 <script type="text/javascript" src="src/js/controller.js"></script>
15 <script type="text/javascript" src="src/js/service.js"></script>
16 <script type="text/javascript" src="src/js/route.js"></script>
17 <script type="text/javascript" src="spec/controllerSpec.js"></script>
18 <script type="text/javascript" src="spec/serviceSpec.js"></script>
19 <script type="text/javascript" src="spec/routeSpec.js"></script>
20 </body>
21 </html>
22