Commit 99532cb1a9119ceb07a18b0e990bf6a50e85b646

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !48
1 const templateCache = require('gulp-angular-templatecache'); 1 const templateCache = require('gulp-angular-templatecache');
2 const clean = require('gulp-clean'); 2 const clean = require('gulp-clean');
3 const concat = require('gulp-concat'); 3 const concat = require('gulp-concat');
4 const htmlmin = require('gulp-htmlmin'); 4 const htmlmin = require('gulp-htmlmin');
5 const rename = require('gulp-rename'); 5 const rename = require('gulp-rename');
6 const uglify = require('gulp-uglify'); 6 const uglify = require('gulp-uglify');
7 const gulp = require('gulp'); 7 const gulp = require('gulp');
8 const pump = require('pump'); 8 const pump = require('pump');
9 const jshint = require('gulp-jshint'); 9 const jshint = require('gulp-jshint');
10 const replace = require('gulp-replace'); 10 const replace = require('gulp-replace');
11 const connect = require('gulp-connect'); 11 const connect = require('gulp-connect');
12 const header = require('gulp-header');
13 const footer = require('gulp-footer');
12 14
13 var paths = { 15 var paths = {
14 srcJS: 'src/js/*.js', 16 srcJS: 'src/js/*.js',
15 srcViews: 'src/views/*.html', 17 srcViews: 'src/views/*.html',
18 specs: 'spec/*.js',
16 tmp: 'tmp', 19 tmp: 'tmp',
17 dist: 'dist/' 20 dist: 'dist/'
18 }; 21 };
19 22
20 gulp.task('templates', ['clean'], function() { 23 gulp.task('templates', ['clean'], function() {
21 return pump( 24 return pump(
22 [ 25 [
23 gulp.src(paths.srcViews), 26 gulp.src(paths.srcViews),
24 htmlmin(), 27 htmlmin(),
25 templateCache('views.js', { 28 templateCache('views.js', {
26 module: 'focaCrearNotaPedido', 29 module: 'focaCrearNotaPedido',
27 root: '' 30 root: ''
28 }), 31 }),
29 gulp.dest(paths.tmp) 32 gulp.dest(paths.tmp)
30 ] 33 ]
31 ); 34 );
32 }); 35 });
33 36
34 gulp.task('uglify', ['templates'], function() { 37 gulp.task('uglify', ['templates', 'uglify-spec'], function() {
35 return pump( 38 return pump(
36 [ 39 [
37 gulp.src([ 40 gulp.src([
38 paths.srcJS, 41 paths.srcJS,
39 'tmp/views.js' 42 'tmp/views.js'
40 ]), 43 ]),
41 concat('foca-crear-nota-pedido.js'), 44 concat('foca-crear-nota-pedido.js'),
42 replace('src/views/', ''), 45 replace('src/views/', ''),
43 gulp.dest(paths.tmp), 46 gulp.dest(paths.tmp),
44 rename('foca-crear-nota-pedido.min.js'), 47 rename('foca-crear-nota-pedido.min.js'),
45 uglify(), 48 uglify(),
46 gulp.dest(paths.dist) 49 gulp.dest(paths.dist)
47 ] 50 ]
48 ); 51 );
49 }); 52 });
50 53
54 gulp.task('uglify-spec', function() {
55 return pump([
56 gulp.src(paths.specs),
57 concat('foca-crear-nota-pedido.spec.js'),
58 replace("src/views/", ''),
59 header("describe('Módulo foca-crear-nota-pedido', function() { \n"),
60 footer("});"),
61 gulp.dest(paths.dist)
62 ]);
63 });
64
51 gulp.task('clean', function() { 65 gulp.task('clean', function() {
52 return gulp.src(['tmp', 'dist'], {read: false}) 66 return gulp.src(['tmp', 'dist'], {read: false})
53 .pipe(clean()); 67 .pipe(clean());
54 }); 68 });
55 69
56 gulp.task('pre-commit', function() { 70 gulp.task('pre-commit', function() {
57 return pump( 71 return pump(
58 [ 72 [
59 gulp.src(paths.srcJS), 73 gulp.src([paths.srcJS, paths.specs]),
60 jshint('.jshintrc'), 74 jshint('.jshintrc'),
61 jshint.reporter('default'), 75 jshint.reporter('default'),
62 jshint.reporter('fail') 76 jshint.reporter('fail')
63 ] 77 ]
64 ); 78 );
65 79
66 gulp.start('uglify'); 80 gulp.start('uglify');
67 }); 81 });
68 82
69 gulp.task('webserver', function() { 83 gulp.task('webserver', function() {
70 pump [ 84 pump [
71 connect.server({port: 3300, host: '0.0.0.0'}) 85 connect.server({port: 3300, host: '0.0.0.0'})
72 ] 86 ]
73 }); 87 });
74 88
75 gulp.task('clean-post-install', function() { 89 gulp.task('clean-post-install', function() {
76 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 90 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
77 'index.html'], {read: false}) 91 'index.html', 'test.html', 'spec'], {read: false})
78 .pipe(clean()); 92 .pipe(clean());
79 }); 93 });
80 94
81 gulp.task('default', ['webserver']); 95 gulp.task('default', ['webserver']);
82 96
83 gulp.task('watch', function() { 97 gulp.task('watch', function() {
84 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 98 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
85 }); 99 });
86 100
87 gulp.task('copy', ['uglify'], function() { 101 gulp.task('copy', ['uglify'], function() {
88 return gulp.src('dist/*.js') 102 return gulp.src('dist/*.js')
89 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/')); 103 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-nota-pedido/dist/'));
90 }); 104 });
91 105
92 gulp.task('watchAndCopy', function() { 106 gulp.task('watchAndCopy', function() {
93 return gulp.watch([paths.srcJS], ['copy']); 107 return gulp.watch([paths.srcJS], ['copy']);
94 }); 108 });
95 109
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
spec/controllerSpec.js
File was created 1 describe('Controladores módulo crear nota de pedido', function() {
2
3 var $controler;
4
5 beforeEach(function() {
6 module('focaCrearNotaPedido');
7 inject(function(_$controller_) {
8 $controler = _$controller_;
9 });
10 });
11
12 describe('Controlador notaPedidoCtrl', function() {
13
14 var filter = function() {
15 return function() { };
16 };
17 var timeout;
18
19 beforeEach(function() {
20
21 inject(function($timeout) {
22 timeout = $timeout;
23 });
24 });
25
26 it('La función seleccionarNotaPedido levanta modal', function() {
27 //arrange
28 var scope = {};
29 var uibModal = {
30 open: function() { }
31 };
32
33 $controler('notaPedidoCtrl', {
34 $scope: scope,
35 $uibModal: uibModal,
36 $location: {},
37 $filter: filter,
38 $timeout: timeout,
39 crearNotaPedidoService: {
40 getBotonera: function() { },
41 getCotizacionByIdMoneda: function() {
42 return {
43 then: function() { }
44 };
45 }
46 },
47 focaBotoneraLateralService: {},
48 focaModalService: {},
49 notaPedidoBusinessService: {},
50 $rootScope: {
51 $on: function() { }
52 },
53 focaSeguimientoService: {},
54 APP: {},
55 focaLoginService: {}
56 });
57 var respuesta = { result: { then: function() { } } };
58
59 //act
60 spyOn(uibModal, 'open').and.returnValue(respuesta);
61 scope.seleccionarNotaPedido();
62
63 //assert
64 expect(uibModal.open).toHaveBeenCalled();
65 });
66
67 it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) {
68 //arrange
69 var scope = {};
70 var uibModal = {
71 open: function() { }
72 };
73
74 $controler('notaPedidoCtrl', {
75 $scope: scope,
76 $uibModal: uibModal,
77 $location: {},
78 $filter: filter,
79 $timeout: timeout,
80 crearNotaPedidoService: {
81 getBotonera: function() { },
82 getCotizacionByIdMoneda: function() {
83 return {
84 then: function() { }
85 };
86 }
87 },
88 focaBotoneraLateralService: {},
89 focaModalService: {},
90 notaPedidoBusinessService: {
91 plazoToString: function() { },
92 calcularArticulos: function() { }
93 },
94 $rootScope: {
95 $on: function() { }
96 },
97 focaSeguimientoService: {},
98 APP: {},
99 focaLoginService: {}
100 });
101 var notaPedido = {
102 cotizacion: {
103 moneda: {}
104 },
105 cliente: {},
106 vendedor: {},
107 proveedor: {},
108 notaPedidoPlazo: {},
109 notaPedidoPuntoDescarga: []
110 };
111 var respuesta = { result: Promise.resolve(notaPedido) };
112
113 //act
114 scope.notaPedido = {};
115 scope.$broadcast = function() { };
116 spyOn(uibModal, 'open').and.returnValue(respuesta);
117 spyOn(scope, '$broadcast');
118 scope.seleccionarNotaPedido();
119
120 //assert
121 respuesta.result.then(function() {
122 expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:');
123 expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:');
124 done();
125 });
126 });
127
128 it('función seleccionarProductos muestra alerta cuando idLista undefined', function() {
129 //arrange
130 var scope = {};
131 var focaModalService = {
132 alert: function() { }
133 };
134
135 $controler('notaPedidoCtrl', {
136 $scope: scope,
137 $uibModal: {},
138 $location: {},
139 $filter: filter,
140 $timeout: timeout,
141 crearNotaPedidoService: {
142 getBotonera: function() { },
143 getCotizacionByIdMoneda: function() {
144 return {
145 then: function() { }
146 };
147 }
148 },
149 focaBotoneraLateralService: {},
150 focaModalService: focaModalService,
151 notaPedidoBusinessService: {},
152 $rootScope: {
153 $on: function() { }
154 },
155 focaSeguimientoService: {},
156 APP: {},
157 focaLoginService: {}
158 });
159
160 //act
161 spyOn(focaModalService, 'alert');
162 scope.idLista = undefined;
163 scope.seleccionarProductos();
164
165 //assert
166 expect(focaModalService.alert)
167 .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion');
168 });
169
170 it('función seleccionarProductos abre modal', function() {
171 //arrange
172 var scope = {};
173 var uibModal = {
174 open: function() { }
175 };
176
177 $controler('notaPedidoCtrl', {
178 $scope: scope,
179 $uibModal: uibModal,
180 $location: {},
181 $filter: filter,
182 $timeout: timeout,
183 crearNotaPedidoService: {
184 getBotonera: function() { },
185 getCotizacionByIdMoneda: function() {
186 return {
187 then: function() { }
188 };
189 }
190 },
191 focaBotoneraLateralService: {},
192 focaModalService: {},
193 notaPedidoBusinessService: {},
194 $rootScope: {
195 $on: function() { }
196 },
197 focaSeguimientoService: {},
198 APP: {},
199 focaLoginService: {}
200 });
201 scope.idLista = true;
202 scope.notaPedido = {
203 cotizacion: {},
204 moneda: {}
205 };
206 var respuesta = { result: {then: function() { } } };
207
208 //act
209 spyOn(uibModal, 'open').and.returnValue(respuesta);
210 scope.seleccionarProductos();
211
212 //assert
213 expect(uibModal.open).toHaveBeenCalled();
214 });
215
216 it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' +
217 'undefined', function()
218 {
219 //arrange
220 var scope = {};
221 var focaModalService = {
222 alert: function() { }
223 };
224
225 $controler('notaPedidoCtrl', {
226 $scope: scope,
227 $uibModal: {},
228 $location: {},
229 $filter: filter,
230 $timeout: timeout,
231 crearNotaPedidoService: {
232 getBotonera: function() { },
233 getCotizacionByIdMoneda: function() {
234 return {
235 then: function() { }
236 };
237 }
238 },
239 focaBotoneraLateralService: {},
240 focaModalService: focaModalService,
241 notaPedidoBusinessService: {},
242 $rootScope: {
243 $on: function() { }
244 },
245 focaSeguimientoService: {},
246 APP: {},
247 focaLoginService: {}
248 });
249 scope.idLista = true;
250 scope.notaPedido = {
251 cliente: { COD: false },
252 domicilio: { id: false}
253 };
254
255 //act
256 spyOn(focaModalService, 'alert');
257 scope.seleccionarPuntosDeDescarga();
258
259 //assert
260 expect(focaModalService.alert).toHaveBeenCalled();
261 });
262
263 it('función seleccionarPuntosDeDescarga abre modal', function() {
264 //arrange
265 var scope = {};
266 var uibModal = {
267 open: function() { }
268 };
269
270 $controler('notaPedidoCtrl', {
271 $scope: scope,
272 $uibModal: uibModal,
273 $location: {},
274 $filter: filter,
275 $timeout: timeout,
276 crearNotaPedidoService: {
277 getBotonera: function() { },
278 getCotizacionByIdMoneda: function() {
279 return {
280 then: function() { }
281 };
282 }
283 },
284 focaBotoneraLateralService: {},
285 focaModalService: {},
286 notaPedidoBusinessService: {},
287 $rootScope: {
288 $on: function() { }
289 },
290 focaSeguimientoService: {},
291 APP: {},
292 focaLoginService: {}
293 });
294 scope.idLista = true;
295 scope.notaPedido = {
296 cliente: { COD: true },
297 domicilio: { id: true }
298 };
299 var respuesta = { result: { then: function() { } } };
300
301 //act
302 spyOn(uibModal, 'open').and.returnValue(respuesta);
303 scope.seleccionarPuntosDeDescarga();
304
305 //assert
306 expect(uibModal.open).toHaveBeenCalled();
307 });
308
309 it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) {
310 //arrange
311 var scope = {};
312 var uibModal = {
313 open: function() { }
314 };
315
316 $controler('notaPedidoCtrl', {
317 $scope: scope,
318 $uibModal: uibModal,
319 $location: {},
320 $filter: filter,
321 $timeout: timeout,
322 crearNotaPedidoService: {
323 getBotonera: function() { },
324 getCotizacionByIdMoneda: function() {
325 return {
326 then: function() { }
327 };
328 }
329 },
330 focaBotoneraLateralService: {},
331 focaModalService: {},
332 notaPedidoBusinessService: {},
333 $rootScope: {
334 $on: function() { }
335 },
336 focaSeguimientoService: {},
337 APP: {},
338 focaLoginService: {}
339 });
340 scope.idLista = true;
341 scope.notaPedido = {
342 cliente: { COD: true },
343 domicilio: { id: true }
344 };
345 var respuesta = [];
346 var promiseRespuesta = { result: Promise.resolve(respuesta) };
347 scope.$broadcast = function() { };
348
349 //act
350 spyOn(uibModal, 'open').and.returnValue(promiseRespuesta);
351 scope.seleccionarPuntosDeDescarga();
352
353 //assert
354 promiseRespuesta.result.then(function() {
355 expect(scope.notaPedido.puntosDescarga).toEqual(respuesta);
356 done();
357 });
358 });
359
360 it('función seleccionarVendedor abre modal', function() {
361 //arrange
362 var scope = {};
363 var focaModalService = {
364 modal: function() { }
365 };
366
367 $controler('notaPedidoCtrl', {
368 $scope: scope,
369 $uibModal: {},
370 $location: {},
371 $filter: filter,
372 $timeout: timeout,
373 crearNotaPedidoService: {
374 getBotonera: function() { },
375 getCotizacionByIdMoneda: function() {
376 return {
377 then: function() { }
378 };
379 }
380 },
381 focaBotoneraLateralService: {},
382 focaModalService: focaModalService,
383 notaPedidoBusinessService: {},
384 $rootScope: {
385 $on: function() { }
386 },
387 focaSeguimientoService: {},
388 APP: {},
389 focaLoginService: {}
390 });
391 scope.idLista = true;
392 scope.notaPedido = {
393 cliente: { COD: true },
394 domicilio: { id: true }
395 };
396
397 var respuesta = { then: function() { } };
398
399 //act
400 spyOn(focaModalService, 'modal').and.returnValue(respuesta);
401 scope.seleccionarVendedor();
402
403 //assert
404 expect(focaModalService.modal).toHaveBeenCalled();
405 });
406
407 it('función seleccionarVendedor setea vendedor y cabecera', function(done) {
408 //arrange
409 var scope = {};
410 var focaModalService = {
411 modal: function() { }
412 };
413
414 $controler('notaPedidoCtrl', {
415 $scope: scope,
416 $uibModal: {},
417 $location: {},
418 $filter: filter,
419 $timeout: timeout,
420 crearNotaPedidoService: {
421 getBotonera: function() { },
422 getCotizacionByIdMoneda: function() {
423 return {
424 then: function() { }
425 };
426 }
427 },
428 focaBotoneraLateralService: {},
429 focaModalService: focaModalService,
430 notaPedidoBusinessService: {},
431 $rootScope: {
432 $on: function() { }
433 },
434 focaSeguimientoService: {},
435 APP: {},
436 focaLoginService: {}
437 });
438 scope.idLista = true;
439 scope.notaPedido = {
440 cliente: { COD: true },
441 domicilio: { id: true }
442 };
443 var respuesta = {};
444 var promesaRespuesta = Promise.resolve(respuesta);
445 scope.$broadcast = function() { };
446
447 //act
448 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta);
449 spyOn(scope, '$broadcast');
450 scope.seleccionarVendedor();
451
452 //assert
453 promesaRespuesta.then(function() {
454 expect(scope.notaPedido.vendedor).toEqual(respuesta);
455 expect(scope.$broadcast).toHaveBeenCalled();
456 done();
457 });
458 });
459
460 it('función seleccionarProveedor abre modal', function() {
461 //arrange
462 var scope = {};
463 var focaModalService = {
464 modal: function() { }
465 };
466
467 $controler('notaPedidoCtrl', {
468 $scope: scope,
469 $uibModal: {},
470 $location: {},
471 $filter: filter,
472 $timeout: timeout,
473 crearNotaPedidoService: {
474 getBotonera: function() { },
475 getCotizacionByIdMoneda: function() {
476 return {
477 then: function() { }
478 };
479 }
480 },
481 focaBotoneraLateralService: {},
482 focaModalService: focaModalService,
483 notaPedidoBusinessService: {},
484 $rootScope: {
485 $on: function() { }
486 },
487 focaSeguimientoService: {},
488 APP: {},
489 focaLoginService: {}
490 });
491 scope.notaPedido = {};
492
493 var respuesta = { then: function() { } };
494
495 //act
496 spyOn(focaModalService, 'modal').and.returnValue(respuesta);
497 scope.seleccionarProveedor();
498
499 //assert
500 expect(focaModalService.modal).toHaveBeenCalled();
501 });
502
503 it('función seleccionarProveedor setea vendedor y cabecera', function(done) {
504 //arrange
505 var scope = {};
506 var focaModalService = {
507 modal: function() { }
508 };
509
510 $controler('notaPedidoCtrl', {
511 $scope: scope,
512 $uibModal: {},
513 $location: {},
514 $filter: filter,
515 $timeout: timeout,
516 crearNotaPedidoService: {
517 getBotonera: function() { },
518 getCotizacionByIdMoneda: function() {
519 return {
520 then: function() { }
521 };
522 }
523 },
524 focaBotoneraLateralService: {},
525 focaModalService: focaModalService,
526 notaPedidoBusinessService: {},
527 $rootScope: {
528 $on: function() { }
529 },
530 focaSeguimientoService: {},
531 APP: {},
532 focaLoginService: {}
533 });
534
535 scope.notaPedido = {};
536 var respuesta = {};
537 var promesaRespuesta = Promise.resolve(respuesta);
538 scope.$broadcast = function() { };
539
540 //act
541 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta);
542 spyOn(scope, '$broadcast');
543 scope.seleccionarProveedor();
544
545 //assert
546 promesaRespuesta.then(function() {
547 expect(scope.notaPedido.proveedor).toEqual(respuesta);
548 expect(scope.$broadcast).toHaveBeenCalled();
549 done();
550 });
551 });
552
553 it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() {
554 //arrange
555 var scope = {};
556 var focaModalService = {
557 alert: function() { }
558 };
559
560 $controler('notaPedidoCtrl', {
561 $scope: scope,
562 $uibModal: {},
563 $location: {},
564 $filter: filter,
565 $timeout: timeout,
566 crearNotaPedidoService: {
567 getBotonera: function() { },
568 getCotizacionByIdMoneda: function() {
569 return {
570 then: function() { }
571 };
572 }
573 },
574 focaBotoneraLateralService: {},
575 focaModalService: focaModalService,
576 notaPedidoBusinessService: {},
577 $rootScope: {
578 $on: function() { }
579 },
580 focaSeguimientoService: {},
581 APP: {},
582 focaLoginService: {}
583 });
584 scope.notaPedido = {
585 vendedor: { NUM: false }
586 };
587
588 //act
589 spyOn(focaModalService, 'alert');
590 scope.seleccionarCliente();
591
592 //assert
593 expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor');
594 });
595
596 it('función seleccionarCliente abre modal', function() {
597 //arrange
598 var scope = {};
599 var uibModal = {
600 open: function() { }
601 };
602
603 $controler('notaPedidoCtrl', {
604 $scope: scope,
605 $uibModal: uibModal,
606 $location: {},
607 $filter: filter,
608 $timeout: timeout,
609 crearNotaPedidoService: {
610 getBotonera: function() { },
611 getCotizacionByIdMoneda: function() {
612 return {
613 then: function() { }
614 };
615 }
616 },
617 focaBotoneraLateralService: {},
618 focaModalService: {},
619 notaPedidoBusinessService: {},
620 $rootScope: {
621 $on: function() { }
622 },
623 focaSeguimientoService: {},
624 APP: {},
625 focaLoginService: {}
626 });
627 scope.notaPedido = {
628 vendedor: { NUM: true }
629 };
630
631 var respuesta = { result: {then: function() { } } };
632
633 //act
634 spyOn(uibModal, 'open').and.returnValue(respuesta);
635 scope.seleccionarCliente();
636
637 //assert
638 expect(uibModal.open).toHaveBeenCalled();
639 });
640
641 it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) {
642
643 //arrange
644 var scope = {};
645 var uibModal = {
646 open: function() { }
647 };
648
649 $controler('notaPedidoCtrl', {
650 $scope: scope,
651 $uibModal: uibModal,
652 $location: {},
653 $filter: filter,
654 $timeout: timeout,
655 crearNotaPedidoService: {
656 getBotonera: function() { },
657 getCotizacionByIdMoneda: function() {
658 return {
659 then: function() { }
660 };
661 }
662 },
663 focaBotoneraLateralService: {},
664 focaModalService: {},
665 notaPedidoBusinessService: {},
666 $rootScope: {
667 $on: function() { }
668 },
669 focaSeguimientoService: {},
670 APP: {},
671 focaLoginService: {}
672 });
673 scope.idLista = true;
674 scope.notaPedido = {
675 vendedor: { NUM: true }
676 };
677 var respuesta = {};
678 var promesaRespuesta = { result: Promise.resolve(respuesta) };
679
680 //act
681 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
682 spyOn(scope, 'abrirModalDomicilios');
683 scope.seleccionarCliente();
684
685 //assert
686 promesaRespuesta.result.then(function() {
687 expect(scope.cliente).toEqual(respuesta);
688 expect(scope.abrirModalDomicilios).toHaveBeenCalled();
689 done();
690 });
691 });
692
693 it('función abrirModalDomicilios abre modal', function() {
694 //arrange
695 var scope = {};
696 var uibModal = {
697 open: function() { }
698 };
699
700 $controler('notaPedidoCtrl', {
701 $scope: scope,
702 $uibModal: uibModal,
703 $location: {},
704 $filter: filter,
705 $timeout: timeout,
706 crearNotaPedidoService: {
707 getBotonera: function() { },
708 getCotizacionByIdMoneda: function() {
709 return {
710 then: function() { }
711 };
712 }
713 },
714 focaBotoneraLateralService: {},
715 focaModalService: {},
716 notaPedidoBusinessService: {},
717 $rootScope: {
718 $on: function() { }
719 },
720 focaSeguimientoService: {},
721 APP: {},
722 focaLoginService: {}
723 });
724
725 var respuesta = { result: {then: function() { } } };
726
727 //act
728 spyOn(uibModal, 'open').and.returnValue(respuesta);
729 scope.abrirModalDomicilios();
730
731 //assert
732 expect(uibModal.open).toHaveBeenCalled();
733 });
734
735 it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) {
736
737 //arrange
738 var scope = {};
739 var uibModal = {
740 open: function() { }
741 };
742
743 $controler('notaPedidoCtrl', {
744 $scope: scope,
745 $uibModal: uibModal,
746 $location: {},
747 $filter: filter,
748 $timeout: timeout,
749 crearNotaPedidoService: {
750 getBotonera: function() { },
751 getCotizacionByIdMoneda: function() {
752 return {
753 then: function() { }
754 };
755 },
756 getPuntosDescargaByClienDom: function() {
757 return {
758 then: function() { }
759 };
760 }
761 },
762 focaBotoneraLateralService: {},
763 focaModalService: {},
764 notaPedidoBusinessService: {},
765 $rootScope: {
766 $on: function() { }
767 },
768 focaSeguimientoService: {},
769 APP: {},
770 focaLoginService: {}
771 });
772 scope.idLista = true;
773 scope.notaPedido = {
774 vendedor: { NUM: true }
775 };
776 var respuesta = {};
777 var promesaRespuesta = { result: Promise.resolve(respuesta) };
778 scope.$broadcast = function() { };
779 var cliente = {
780 COD: undefined,
781 CUIT: undefined,
782 NOM: undefined
783 };
784
785 //act
786 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
787 spyOn(scope, '$broadcast');
788 scope.abrirModalDomicilios({ });
789
790 //assert
791 promesaRespuesta.result.then(function() {
792 expect(scope.notaPedido.domicilio).toEqual(respuesta);
793 expect(scope.notaPedido.cliente).toEqual(cliente);
794 expect(scope.$broadcast).toHaveBeenCalled();
795 done();
796 });
797 });
798
799 it('función getTotal devulve correctamente', function() {
800
801 //arrange
802 var scope = {};
803
804 $controler('notaPedidoCtrl', {
805 $scope: scope,
806 $uibModal: {},
807 $location: {},
808 $filter: filter,
809 $timeout: timeout,
810 crearNotaPedidoService: {
811 getBotonera: function() { },
812 getCotizacionByIdMoneda: function() {
813 return {
814 then: function() { }
815 };
816 }
817 },
818 focaBotoneraLateralService: {},
819 focaModalService: {},
820 notaPedidoBusinessService: {},
821 $rootScope: {
822 $on: function() { }
823 },
824 focaSeguimientoService: {},
825 APP: {},
826 focaLoginService: {}
827 });
828 scope.idLista = true;
829 scope.notaPedido = {
830 vendedor: { NUM: true }
831 };
832
833 //act
834 scope.articulosTabla = [{ precio: 2, cantidad: 1}];
835 var esperado = 2;
836 var resultado = scope.getTotal();
837
838 //assert
839 expect(resultado).toEqual(esperado);
840 });
841
842 it('función getSubTotal devulve correctamente', function() {
843
844 //arrange
845 var scope = {};
846
847 $controler('notaPedidoCtrl', {
848 $scope: scope,
849 $uibModal: {},
850 $location: {},
851 $filter: filter,
852 $timeout: timeout,
853 crearNotaPedidoService: {
854 getBotonera: function() { },
855 getCotizacionByIdMoneda: function() {
856 return {
857 then: function() { }
858 };
859 }
860 },
861 focaBotoneraLateralService: {},
862 focaModalService: {},
863 notaPedidoBusinessService: {},
864 $rootScope: {
865 $on: function() { }
866 },
867 focaSeguimientoService: {},
868 APP: {},
869 focaLoginService: {}
870 });
871 scope.idLista = true;
872 scope.notaPedido = {
873 vendedor: { NUM: true }
874 };
875
876 //act
877 scope.articuloACargar = { precio: 2, cantidad: 1};
878 var esperado = 2;
879 var resultado = scope.getSubTotal();
880
881 //assert
882 expect(resultado).toEqual(esperado);
883 });
884
885 it('función seleccionarPreciosYCondiciones abre modal', function() {
886
887 //arrange
888 var scope = {};
889 var uibModal = {
890 open: function() { }
891 };
892
893 $controler('notaPedidoCtrl', {
894 $scope: scope,
895 $uibModal: uibModal,
896 $location: {},
897 $filter: filter,
898 $timeout: timeout,
899 crearNotaPedidoService: {
900 getBotonera: function() { },
901 getCotizacionByIdMoneda: function() {
902 return {
903 then: function() { }
904 };
905 }
906 },
907 focaBotoneraLateralService: {},
908 focaModalService: {},
909 notaPedidoBusinessService: {},
910 $rootScope: {
911 $on: function() { }
912 },
913 focaSeguimientoService: {},
914 APP: {},
915 focaLoginService: {}
916 });
917
918 scope.notaPedido = {};
919
920 var respuesta = { result: {then: function() { } } };
921
922 //act
923 spyOn(uibModal, 'open').and.returnValue(respuesta);
924 scope.seleccionarPreciosYCondiciones();
925
926 //assert
927 expect(uibModal.open).toHaveBeenCalled();
928 });
929
930 it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) {
931
932 //arrange
933 var scope = {};
934 var uibModal = {
935 open: function() { }
936 };
937
938 $controler('notaPedidoCtrl', {
939 $scope: scope,
940 $uibModal: uibModal,
941 $location: {},
942 $filter: filter,
943 $timeout: timeout,
944 crearNotaPedidoService: {
945 getBotonera: function() { },
946 getCotizacionByIdMoneda: function() {
947 return {
948 then: function() { }
949 };
950 }
951 },
952 focaBotoneraLateralService: {},
953 focaModalService: {},
954 notaPedidoBusinessService: {},
955 $rootScope: {
956 $on: function() { }
957 },
958 focaSeguimientoService: {},
959 APP: {},
960 focaLoginService: {}
961 });
962 scope.idLista = true;
963 scope.notaPedido = {
964 vendedor: { NUM: true }
965 };
966 var respuesta = { plazoPago: { } };
967 var promesaRespuesta = { result: Promise.resolve(respuesta) };
968 scope.$broadcast = function() { };
969
970 //act
971 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
972 spyOn(scope, '$broadcast');
973 scope.seleccionarPreciosYCondiciones();
974
975 //assert
976 promesaRespuesta.result.then(function() {
977 expect(scope.articulosTabla.length).toEqual(0);
978 expect(scope.$broadcast).toHaveBeenCalled();
979 done();
980 });
981 });
982
983 it('función seleccionarFlete abre modal', function() {
984
985 //arrange
986 var scope = {};
987 var uibModal = {
988 open: function() { }
989 };
990
991 $controler('notaPedidoCtrl', {
992 $scope: scope,
993 $uibModal: uibModal,
994 $location: {},
995 $filter: filter,
996 $timeout: timeout,
997 crearNotaPedidoService: {
998 getBotonera: function() { },
999 getCotizacionByIdMoneda: function() {
1000 return {
1001 then: function() { }
1002 };
1003 }
1004 },
1005 focaBotoneraLateralService: {},
1006 focaModalService: {},
1007 notaPedidoBusinessService: {},
1008 $rootScope: {
1009 $on: function() { }
1010 },
1011 focaSeguimientoService: {},
1012 APP: {},
1013 focaLoginService: {}
1014 });
1015
1016 scope.notaPedido = {};
1017
1018 var respuesta = { result: {then: function() { } } };
1019
1020 //act
1021 spyOn(uibModal, 'open').and.returnValue(respuesta);
1022 scope.seleccionarFlete();
1023
1024 //assert
1025 expect(uibModal.open).toHaveBeenCalled();
1026 });
1027
1028 it('función seleccionarFlete setea flete y cabecera', function(done) {
1029
1030 //arrange
1031 var scope = {};
1032 var uibModal = {
1033 open: function() { }
1034 };
1035
1036 $controler('notaPedidoCtrl', {
1037 $scope: scope,
1038 $uibModal: uibModal,
1039 $location: {},
1040 $filter: filter,
1041 $timeout: timeout,
1042 crearNotaPedidoService: {
1043 getBotonera: function() { },
1044 getCotizacionByIdMoneda: function() {
1045 return {
1046 then: function() { }
1047 };
1048 }
1049 },
1050 focaBotoneraLateralService: {},
1051 focaModalService: {},
1052 notaPedidoBusinessService: {},
1053 $rootScope: {
1054 $on: function() { }
1055 },
1056 focaSeguimientoService: {},
1057 APP: {},
1058 focaLoginService: {}
1059 });
1060 scope.idLista = true;
1061 scope.notaPedido = {
1062 vendedor: { NUM: true }
1063 };
1064 var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 };
1065 var promesaRespuesta = { result: Promise.resolve(respuesta) };
1066 scope.$broadcast = function() { };
1067
1068 //act
1069 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
1070 spyOn(scope, '$broadcast');
1071 scope.seleccionarFlete();
1072
1073 //assert
1074
1075 promesaRespuesta.result.then(function() {
1076 expect(scope.notaPedido.flete).toEqual(respuesta.flete);
1077 expect(scope.notaPedido.fob).toEqual(respuesta.FOB);
1078 expect(scope.notaPedido.bomba).toEqual(respuesta.bomba);
1079 expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros);
1080 expect(scope.$broadcast).toHaveBeenCalled();
1081 done();
1082 });
1083 });
1084
1085 it('función seleccionarMoneda abre modal', function() {
1086 //arrange
1087 var scope = {};
1088 var focaModalService = {
1089 modal: function() { }
1090 };
1091
1092 $controler('notaPedidoCtrl', {
1093 $scope: scope,
1094 $uibModal: {},
1095 $location: {},
1096 $filter: filter,
1097 $timeout: timeout,
1098 crearNotaPedidoService: {
1099 getBotonera: function() { },
1100 getCotizacionByIdMoneda: function() {
1101 return {
1102 then: function() { }
1103 };
1104 }
1105 },
1106 focaBotoneraLateralService: {},
1107 focaModalService: focaModalService,
1108 notaPedidoBusinessService: {},
1109 $rootScope: {
1110 $on: function() { }
1111 },
1112 focaSeguimientoService: {},
1113 APP: {},
1114 focaLoginService: {}
1115 });
1116 scope.notaPedido = {};
1117
1118 var respuesta = { then: function() { } };
1119
1120 //act
1121 spyOn(focaModalService, 'modal').and.returnValue(respuesta);
1122 scope.seleccionarMoneda();
1123
1124 //assert
1125 expect(focaModalService.modal).toHaveBeenCalled();
1126 });
1127
1128 it('función seleccionarMoneda llama Modal Cotizacion', function(done) {
1129 //arrange
1130 var scope = {};
1131 var focaModalService = {
1132 modal: function() { }
1133 };
1134
1135 $controler('notaPedidoCtrl', {
1136 $scope: scope,
1137 $uibModal: {},
1138 $location: {},
1139 $filter: filter,
1140 $timeout: timeout,
1141 crearNotaPedidoService: {
1142 getBotonera: function() { },
1143 getCotizacionByIdMoneda: function() {
1144 return {
1145 then: function() { }
1146 };
1147 }
1148 },
1149 focaBotoneraLateralService: {},
1150 focaModalService: focaModalService,
1151 notaPedidoBusinessService: {},
1152 $rootScope: {
1153 $on: function() { }
1154 },
1155 focaSeguimientoService: {},
1156 APP: {},
1157 focaLoginService: {}
1158 });
1159
1160 scope.notaPedido = {};
1161 var respuesta = 'test';
1162 var promesaRespuesta = Promise.resolve(respuesta);
1163
1164 //act
1165 spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta);
1166 spyOn(scope, 'abrirModalCotizacion');
1167 scope.seleccionarMoneda();
1168
1169 //assert
1170 promesaRespuesta.then(function() {
1171 expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test');
1172 done();
1173 });
1174 });
1175
1176 it('función seleccionarObservaciones llama a prompt', function() {
1177
1178 //arrange
1179 var scope = {};
1180 var focaModalService = {
1181 prompt: function() { }
1182 };
1183
1184 $controler('notaPedidoCtrl', {
1185 $scope: scope,
1186 $uibModal: {},
1187 $location: {},
1188 $filter: filter,
1189 $timeout: timeout,
1190 crearNotaPedidoService: {
1191 getBotonera: function() { },
1192 getCotizacionByIdMoneda: function() {
1193 return {
1194 then: function() { }
1195 };
1196 }
1197 },
1198 focaBotoneraLateralService: {},
1199 focaModalService: focaModalService,
1200 notaPedidoBusinessService: {},
1201 $rootScope: {
1202 $on: function() { }
1203 },
1204 focaSeguimientoService: {},
1205 APP: {},
1206 focaLoginService: {}
1207 });
1208 var respuesta = { then: function() { } };
1209 scope.notaPedido = {};
1210
1211 //act
1212 spyOn(focaModalService, 'prompt').and.returnValue(respuesta);
1213 scope.seleccionarObservaciones();
1214
1215 //assert
1216 expect(focaModalService.prompt).toHaveBeenCalled();
1217 });
1218
1219 it('función seleccionarObservaciones setea observaciones', function(done) {
1220
1221 //arrange
1222 var scope = {};
1223 var focaModalService = {
1224 prompt: function() { }
1225 };
1226
1227 $controler('notaPedidoCtrl', {
1228 $scope: scope,
1229 $uibModal: {},
1230 $location: {},
1231 $filter: filter,
1232 $timeout: timeout,
1233 crearNotaPedidoService: {
1234 getBotonera: function() { },
1235 getCotizacionByIdMoneda: function() {
1236 return {
1237 then: function() { }
1238 };
1239 }
1240 },
1241 focaBotoneraLateralService: {},
1242 focaModalService: focaModalService,
1243 notaPedidoBusinessService: {},
1244 $rootScope: {
1245 $on: function() { }
1246 },
1247 focaSeguimientoService: {},
1248 APP: {},
1249 focaLoginService: {}
1250 });
1251 var respuesta = 'unit test';
1252 var promesa = Promise.resolve(respuesta);
1253 scope.notaPedido = {};
1254
1255 //act
1256 spyOn(focaModalService, 'prompt').and.returnValue(promesa);
1257 scope.seleccionarObservaciones();
1258
1259 //assert
1260 promesa.then(function() {
1261 expect(scope.notaPedido.observaciones).toEqual(respuesta);
1262 done();
1263 });
1264 });
1265
1266 it('función abrirModalCotizacion abre modal', function() {
1267
1268 //arrange
1269 var scope = {};
1270 var uibModal = {
1271 open: function() { }
1272 };
1273
1274 $controler('notaPedidoCtrl', {
1275 $scope: scope,
1276 $uibModal: uibModal,
1277 $location: {},
1278 $filter: filter,
1279 $timeout: timeout,
1280 crearNotaPedidoService: {
1281 getBotonera: function() { },
1282 getCotizacionByIdMoneda: function() {
1283 return {
1284 then: function() { }
1285 };
1286 }
1287 },
1288 focaBotoneraLateralService: {},
1289 focaModalService: {},
1290 notaPedidoBusinessService: {},
1291 $rootScope: {
1292 $on: function() { }
1293 },
1294 focaSeguimientoService: {},
1295 APP: {},
1296 focaLoginService: {}
1297 });
1298
1299 scope.notaPedido = {};
1300
1301 var respuesta = { result: {then: function() { } } };
1302
1303 //act
1304 spyOn(uibModal, 'open').and.returnValue(respuesta);
1305 scope.abrirModalCotizacion();
1306
1307 //assert
1308 expect(uibModal.open).toHaveBeenCalled();
1309 });
1310
1311 it('función abrirModalCotizacion setea datos y cabecera', function(done) {
1312 //arrange
1313 var scope = {};
1314 var uibModal = {
1315 open: function() { }
1316 };
1317
1318 $controler('notaPedidoCtrl', {
1319 $scope: scope,
1320 $uibModal: uibModal,
1321 $location: {},
1322 $filter: filter,
1323 $timeout: timeout,
1324 crearNotaPedidoService: {
1325 getBotonera: function() { },
1326 getCotizacionByIdMoneda: function() {
1327 return {
1328 then: function() { }
1329 };
1330 }
1331 },
1332 focaBotoneraLateralService: {},
1333 focaModalService: {},
1334 notaPedidoBusinessService: {},
1335 $rootScope: {
1336 $on: function() { }
1337 },
1338 focaSeguimientoService: {},
1339 APP: {},
1340 focaLoginService: {}
1341 });
1342
1343 scope.notaPedido = {};
1344 scope.articulosTabla = [];
1345 scope.$broadcast = function() { };
1346 var moneda = 'moneda';
1347 var cotizacion = 'test';
1348 var promesaRespuesta = { result: Promise.resolve(cotizacion) };
1349
1350 //act
1351 spyOn(uibModal, 'open').and.returnValue(promesaRespuesta);
1352 spyOn(scope, '$broadcast');
1353 scope.abrirModalCotizacion(moneda);
1354
1355 //assert
1356 promesaRespuesta.result.then(function() {
1357
1358 expect(scope.$broadcast).toHaveBeenCalled();
1359 expect(scope.notaPedido.moneda).toEqual(moneda);
1360 expect(scope.monedaDefecto).toEqual(moneda);
1361 expect(scope.cotizacionDefecto).toEqual(cotizacion);
1362 expect(scope.notaPedido.cotizacion).toEqual(cotizacion);
1363 done();
1364 });
1365 });
1366
1367 it('función agregarATabla muestra alerta cuando a cargar undefined', function() {
1368
1369 //arrange
1370 var scope = {};
1371 var focaModalService = {
1372 alert: function() { }
1373 };
1374
1375 $controler('notaPedidoCtrl', {
1376 $scope: scope,
1377 $uibModal: {},
1378 $location: {},
1379 $filter: filter,
1380 $timeout: timeout,
1381 crearNotaPedidoService: {
1382 getBotonera: function() { },
1383 getCotizacionByIdMoneda: function() {
1384 return {
1385 then: function() { }
1386 };
1387 }
1388 },
1389 focaBotoneraLateralService: {},
1390 focaModalService: focaModalService,
1391 notaPedidoBusinessService: {},
1392 $rootScope: {
1393 $on: function() { }
1394 },
1395 focaSeguimientoService: {},
1396 APP: {},
1397 focaLoginService: {}
1398 });
1399 scope.articuloACargar = {};
1400
1401 //act
1402 spyOn(focaModalService, 'alert');
1403 scope.agregarATabla(13);
1404
1405 //assert
1406 expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1');
1407 });
1408
1409 it('función editarArticulo muestra alerta cuando a cargar es undefined', function() {
1410
1411 //arrange
1412 var scope = {};
1413 var focaModalService = {
1414 alert: function() { }
1415 };
1416
1417 $controler('notaPedidoCtrl', {
1418 $scope: scope,
1419 $uibModal: {},
1420 $location: {},
1421 $filter: filter,
1422 $timeout: timeout,
1423 crearNotaPedidoService: {
1424 getBotonera: function() { },
1425 getCotizacionByIdMoneda: function() {
1426 return {
1427 then: function() { }
1428 };
1429 }
1430 },
1431 focaBotoneraLateralService: {},
1432 focaModalService: focaModalService,
1433 notaPedidoBusinessService: {},
1434 $rootScope: {
1435 $on: function() { }
1436 },
1437 focaSeguimientoService: {},
1438 APP: {},
1439 focaLoginService: {}
1440 });
1441 scope.articuloACargar = {};
1442
1443 //act
1444 spyOn(focaModalService, 'alert');
1445 scope.agregarATabla(13);
1446
1447 //assert
1448 expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1');
1449 });
1450
1451 it('función salir lleva a ruta correcta', function() {
1452
1453 inject(function($location) {
1454
1455 //arrange
1456 var scope = {};
1457
1458 $controler('notaPedidoCtrl', {
1459 $scope: scope,
1460 $uibModal: {},
1461 $location: $location,
1462 $filter: filter,
1463 $timeout: timeout,
1464 crearNotaPedidoService: {
1465 getBotonera: function() { },
1466 getCotizacionByIdMoneda: function() {
1467 return {
1468 then: function() { }
1469 };
1470 }
1471 },
1472 focaBotoneraLateralService: {},
1473 focaModalService: {},
1474 notaPedidoBusinessService: {},
1475 $rootScope: {
1476 $on: function() { }
1477 },
1478 focaSeguimientoService: {},
1479 APP: {},
1480 focaLoginService: {}
1481 });
1482
1483 //act
1484 scope.salir();
1485
1486 //assert
1487 expect($location.url()).toEqual('/');
1488 });
1489 });
1490 });
1491 });
1492
spec/controllerSpecCrearPedido.js
File was created 1 describe('Controladores módulo crear nota de pedido', function() {
2
3 var $controler;
4
5 beforeEach(function() {
6 module('focaCrearNotaPedido');
7 inject(function(_$controller_) {
8 $controler = _$controller_;
9 });
10 });
11
12 describe('Controlador notaPedidoCtrl crear nota de pedido', function() {
13
14 var filter = function() {
15 return function() { };
16 };
17 var timeout;
18
19 beforeEach(function() {
20
21 inject(function($timeout) {
22 timeout = $timeout;
23 });
24 });
25
26 it('Existe el controlador notaPedidoCtrl', function() {
27
28 //act
29 var controlador = $controler('notaPedidoCtrl', {
30 $scope: {},
31 $uibModal: {},
32 $location: {},
33 $filter: filter,
34 $timeout: timeout,
35 crearNotaPedidoService: {
36 getBotonera: function() { },
37 getCotizacionByIdMoneda: function() {
38 return {
39 then: function() {}
40 };
41 }
42 },
43 focaBotoneraLateralService: {},
44 focaModalService: {},
45 notaPedidoBusinessService: {},
46 $rootScope: {
47 $on: function() { }
48 },
49 focaSeguimientoService: {},
50 APP: {},
51 focaLoginService: {}
52 });
53
54 //expect
55 expect(typeof controlador).toEqual('object');
56 });
57
58 it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() {
59
60 //arrange
61 var scope = {};
62 var focaModalService = {
63 alert: function() { }
64 };
65
66 $controler('notaPedidoCtrl', {
67 $scope: scope,
68 $uibModal: {},
69 $location: {},
70 $filter: filter,
71 $timeout: timeout,
72 crearNotaPedidoService: {
73 getBotonera: function() { },
74 getCotizacionByIdMoneda: function() {
75 return {
76 then: function() {}
77 };
78 }
79 },
80 focaBotoneraLateralService: {},
81 focaModalService: focaModalService,
82 notaPedidoBusinessService: {},
83 $rootScope: {
84 $on: function() { }
85 },
86 focaSeguimientoService: {},
87 APP: {},
88 focaLoginService: {}
89 });
90
91 //act
92 scope.notaPedido = {
93 vendedor: {
94 id: null
95 }
96 };
97 spyOn(focaModalService, 'alert');
98 scope.crearNotaPedido();
99
100 //expect
101 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor');
102 });
103
104 it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() {
105
106 //arrange
107 var scope = {};
108 var focaModalService = {
109 alert: function() { }
110 };
111
112 $controler('notaPedidoCtrl', {
113 $scope: scope,
114 $uibModal: {},
115 $location: {},
116 $filter: filter,
117 $timeout: timeout,
118 crearNotaPedidoService: {
119 getBotonera: function() { },
120 getCotizacionByIdMoneda: function() {
121 return {
122 then: function() {}
123 };
124 }
125 },
126 focaBotoneraLateralService: {},
127 focaModalService: focaModalService,
128 notaPedidoBusinessService: {},
129 $rootScope: {
130 $on: function() { }
131 },
132 focaSeguimientoService: {},
133 APP: {},
134 focaLoginService: {}
135 });
136
137 scope.notaPedido = {
138 vendedor: {
139 id: true
140 },
141 cliente:{
142 COD: false
143 }
144 };
145
146 //act
147 spyOn(focaModalService, 'alert');
148 scope.crearNotaPedido();
149
150 //expect
151 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente');
152 });
153
154 it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() {
155
156 //arrange
157 var scope = {};
158 var focaModalService = {
159 alert: function() { }
160 };
161
162 $controler('notaPedidoCtrl', {
163 $scope: scope,
164 $uibModal: {},
165 $location: {},
166 $filter: filter,
167 $timeout: timeout,
168 crearNotaPedidoService: {
169 getBotonera: function() { },
170 getCotizacionByIdMoneda: function() {
171 return {
172 then: function() {}
173 };
174 }
175 },
176 focaBotoneraLateralService: {},
177 focaModalService: focaModalService,
178 notaPedidoBusinessService: {},
179 $rootScope: {
180 $on: function() { }
181 },
182 focaSeguimientoService: {},
183 APP: {},
184 focaLoginService: {}
185 });
186
187 scope.notaPedido = {
188 vendedor: {
189 id: true
190 },
191 cliente:{
192 COD: true
193 },
194 proveedor:{
195 COD: null
196 }
197 };
198
199 //act
200 spyOn(focaModalService, 'alert');
201 scope.crearNotaPedido();
202
203 //expect
204 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor');
205 });
206
207 it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() {
208
209 //arrange
210 var scope = {};
211 var focaModalService = {
212 alert: function() { }
213 };
214
215 $controler('notaPedidoCtrl', {
216 $scope: scope,
217 $uibModal: {},
218 $location: {},
219 $filter: filter,
220 $timeout: timeout,
221 crearNotaPedidoService: {
222 getBotonera: function() { },
223 getCotizacionByIdMoneda: function() {
224 return {
225 then: function() {}
226 };
227 }
228 },
229 focaBotoneraLateralService: {},
230 focaModalService: focaModalService,
231 notaPedidoBusinessService: {},
232 $rootScope: {
233 $on: function() { }
234 },
235 focaSeguimientoService: {},
236 APP: {},
237 focaLoginService: {}
238 });
239
240 scope.notaPedido = {
241 vendedor: {
242 id: true
243 },
244 cliente:{
245 COD: true
246 },
247 proveedor:{
248 COD: true
249 },
250 moneda:{
251 ID: null
252 }
253 };
254
255 //act
256 spyOn(focaModalService, 'alert');
257 scope.crearNotaPedido();
258
259 //expect
260 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda');
261 });
262
263 it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() {
264
265 //arrange
266 var scope = {};
267 var focaModalService = {
268 alert: function() { }
269 };
270
271 $controler('notaPedidoCtrl', {
272 $scope: scope,
273 $uibModal: {},
274 $location: {},
275 $filter: filter,
276 $timeout: timeout,
277 crearNotaPedidoService: {
278 getBotonera: function() { },
279 getCotizacionByIdMoneda: function() {
280 return {
281 then: function() {}
282 };
283 }
284 },
285 focaBotoneraLateralService: {},
286 focaModalService: focaModalService,
287 notaPedidoBusinessService: {},
288 $rootScope: {
289 $on: function() { }
290 },
291 focaSeguimientoService: {},
292 APP: {},
293 focaLoginService: {}
294 });
295
296 scope.notaPedido = {
297 vendedor: {
298 id: true
299 },
300 cliente:{
301 COD: true
302 },
303 proveedor:{
304 COD: true
305 },
306 moneda:{
307 ID: true
308 },
309 cotizacion:{
310 ID: null
311 }
312 };
313
314 //act
315 spyOn(focaModalService, 'alert');
316 scope.crearNotaPedido();
317
318 //expect
319 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización');
320 });
321
322 it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() {
323
324 //arrange
325 var scope = {};
326 var focaModalService = {
327 alert: function() { }
328 };
329
330 $controler('notaPedidoCtrl', {
331 $scope: scope,
332 $uibModal: {},
333 $location: {},
334 $filter: filter,
335 $timeout: timeout,
336 crearNotaPedidoService: {
337 getBotonera: function() { },
338 getCotizacionByIdMoneda: function() {
339 return {
340 then: function() {}
341 };
342 }
343 },
344 focaBotoneraLateralService: {},
345 focaModalService: focaModalService,
346 notaPedidoBusinessService: {},
347 $rootScope: {
348 $on: function() { }
349 },
350 focaSeguimientoService: {},
351 APP: {},
352 focaLoginService: {}
353 });
354
355 scope.notaPedido = {
356 vendedor: {
357 id: true
358 },
359 cliente:{
360 COD: true
361 },
362 proveedor:{
363 COD: true
364 },
365 moneda:{
366 ID: true
367 },
368 cotizacion:{
369 ID: true
370 }
371 };
372
373 scope.plazosPagos = null;
374
375 //act
376 spyOn(focaModalService, 'alert');
377 scope.crearNotaPedido();
378
379 //expect
380 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones');
381 });
382
383 it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() {
384
385 //arrange
386 var scope = {};
387 var focaModalService = {
388 alert: function() { }
389 };
390
391 $controler('notaPedidoCtrl', {
392 $scope: scope,
393 $uibModal: {},
394 $location: {},
395 $filter: filter,
396 $timeout: timeout,
397 crearNotaPedidoService: {
398 getBotonera: function() { },
399 getCotizacionByIdMoneda: function() {
400 return {
401 then: function() {}
402 };
403 }
404 },
405 focaBotoneraLateralService: {},
406 focaModalService: focaModalService,
407 notaPedidoBusinessService: {},
408 $rootScope: {
409 $on: function() { }
410 },
411 focaSeguimientoService: {},
412 APP: {},
413 focaLoginService: {}
414 });
415
416 scope.notaPedido = {
417 vendedor: {
418 id: true
419 },
420 cliente:{
421 COD: true
422 },
423 proveedor:{
424 COD: true
425 },
426 moneda:{
427 ID: true
428 },
429 cotizacion:{
430 ID: true
431 },
432 flete: null
433 };
434
435 scope.plazosPagos = true;
436
437 //act
438 spyOn(focaModalService, 'alert');
439 scope.crearNotaPedido();
440
441 //expect
442 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete');
443 });
444
445 it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() {
446
447 //arrange
448 var scope = {};
449 var focaModalService = {
450 alert: function() { }
451 };
452
453 $controler('notaPedidoCtrl', {
454 $scope: scope,
455 $uibModal: {},
456 $location: {},
457 $filter: filter,
458 $timeout: timeout,
459 crearNotaPedidoService: {
460 getBotonera: function() { },
461 getCotizacionByIdMoneda: function() {
462 return {
463 then: function() {}
464 };
465 }
466 },
467 focaBotoneraLateralService: {},
468 focaModalService: focaModalService,
469 notaPedidoBusinessService: {},
470 $rootScope: {
471 $on: function() { }
472 },
473 focaSeguimientoService: {},
474 APP: {},
475 focaLoginService: {}
476 });
477
478 scope.notaPedido = {
479 vendedor: {
480 id: true
481 },
482 cliente:{
483 COD: true
484 },
485 proveedor:{
486 COD: true
487 },
488 moneda:{
489 ID: true
490 },
491 cotizacion:{
492 ID: true
493 },
494 flete: true,
495 domicilioStamp: null
496 };
497
498 scope.plazosPagos = true;
499
500 //act
501 spyOn(focaModalService, 'alert');
502 scope.crearNotaPedido();
503
504 //expect
505 expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio');
506 });
507
508 it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos',
509 function()
510 {
511
512 //arrange
513 var scope = {};
514 var focaModalService = {
515 alert: function() { }
516 };
517
518 $controler('notaPedidoCtrl', {
519 $scope: scope,
520 $uibModal: {},
521 $location: {},
522 $filter: filter,
523 $timeout: timeout,
524 crearNotaPedidoService: {
525 getBotonera: function() { },
526 getCotizacionByIdMoneda: function() {
527 return {
528 then: function() {}
529 };
530 }
531 },
532 focaBotoneraLateralService: {},
533 focaModalService: focaModalService,
534 notaPedidoBusinessService: {},
535 $rootScope: {
536 $on: function() { }
537 },
538 focaSeguimientoService: {},
539 APP: {},
540 focaLoginService: {}
541 });
542
543 scope.notaPedido = {
544 vendedor: {
545 id: true
546 },
547 cliente:{
548 COD: true
549 },
550 proveedor:{
551 COD: true
552 },
553 moneda:{
554 ID: true
555 },
556 cotizacion:{
557 ID: true
558 },
559 flete: true,
560 domicilioStamp: true,
561 };
562
563 scope.plazosPagos = true;
564 scope.articulosTabla = [];
565
566 //act
567 spyOn(focaModalService, 'alert');
568 scope.crearNotaPedido();
569
570 //expect
571 expect(focaModalService.alert)
572 .toHaveBeenCalledWith('Debe cargar al menos un articulo');
573 });
574
575 it('funcion $scope.crearNotaPedido llama startGuardar', function() {
576
577 //arrange
578 var scope = {};
579 var focaBotoneraLateralService = {
580 startGuardar: function() { }
581 };
582
583 $controler('notaPedidoCtrl', {
584 $scope: scope,
585 $uibModal: {},
586 $location: {},
587 $filter: filter,
588 $timeout: timeout,
589 crearNotaPedidoService: {
590 getBotonera: function() { },
591 getCotizacionByIdMoneda: function() {
592 return {
593 then: function() {}
594 };
595 },
596 crearNotaPedido: function() {
597 return {
598 then: function() { }
599 };
600 }
601 },
602 focaBotoneraLateralService: focaBotoneraLateralService,
603 focaModalService: {},
604 notaPedidoBusinessService: {},
605 $rootScope: {
606 $on: function() { }
607 },
608 focaSeguimientoService: {},
609 APP: {},
610 focaLoginService: {}
611 });
612
613 scope.notaPedido = {
614 vendedor: {
615 id: true
616 },
617 cliente:{
618 COD: true
619 },
620 proveedor:{
621 COD: true
622 },
623 moneda:{
624 ID: true
625 },
626 cotizacion:{
627 ID: true
628 },
629 flete: true,
630 domicilioStamp: true,
631 domicilio: {
632 id: true
633 }
634 };
635
636 scope.plazosPagos = true;
637 scope.articulosTabla = [1];
638
639 //act
640 spyOn(focaBotoneraLateralService, 'startGuardar');
641 scope.crearNotaPedido();
642
643 //expect
644 expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled();
645 });
646
647 it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) {
648
649 //arrange
650 var scope = {};
651 var focaBotoneraLateralService = {
652 startGuardar: function() { },
653 endGuardar: function() { }
654 };
655 var focaSeguimientoService = {
656 guardarPosicion: function() { }
657 };
658 var notaPedidoBusinessService = {
659 addArticulos: function() { },
660 addEstado: function() { }
661 };
662 var crearNotaPedidoService = {
663 getBotonera: function() { },
664 getCotizacionByIdMoneda: function() {
665 return {
666 then: function() {}
667 };
668 },
669 crearNotaPedido: function() { },
670 getNumeroNotaPedido: function() {
671 return {
672 then: function() { }
673 };
674 }
675 };
676
677 $controler('notaPedidoCtrl', {
678 $scope: scope,
679 $uibModal: {},
680 $location: {},
681 $filter: filter,
682 $timeout: timeout,
683 crearNotaPedidoService: crearNotaPedidoService,
684 focaBotoneraLateralService: focaBotoneraLateralService,
685 focaModalService: {},
686 notaPedidoBusinessService: notaPedidoBusinessService,
687 $rootScope: {
688 $on: function() { }
689 },
690 focaSeguimientoService: focaSeguimientoService,
691 APP: {},
692 focaLoginService: {}
693 });
694
695 scope.notaPedido = {
696 vendedor: {
697 id: true
698 },
699 cliente:{
700 COD: true
701 },
702 proveedor:{
703 COD: true
704 },
705 moneda:{
706 ID: true
707 },
708 cotizacion:{
709 ID: true
710 },
711 flete: true,
712 domicilioStamp: true,
713 domicilio: {
714 id: true
715 }
716 };
717
718 scope.plazosPagos = [];
719 scope.articulosTabla = [1];
720
721 var promesa = Promise.resolve({ data: 1 });
722 scope.$broadcast = function() { };
723
724 //act
725 spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa);
726 spyOn(focaSeguimientoService, 'guardarPosicion');
727 spyOn(notaPedidoBusinessService, 'addArticulos');
728 scope.crearNotaPedido();
729
730 //expect
731 promesa.then(function() {
732 expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled();
733 expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled();
734 done();
735 });
736 });
737 });
738 });
739
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
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .factory('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 return { 4 return {
5 crearNotaPedido: function(notaPedido) { 5 crearNotaPedido: function(notaPedido) {
6 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); 6 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido});
7 }, 7 },
8 obtenerNotaPedido: function() { 8 obtenerNotaPedido: function() {
9 return $http.get(route +'/nota-pedido'); 9 return $http.get(route +'/nota-pedido');
10 }, 10 },
11 setNotaPedido: function(notaPedido) { 11 setNotaPedido: function(notaPedido) {
12 this.notaPedido = notaPedido; 12 this.notaPedido = notaPedido;
13 }, 13 },
14 clearNotaPedido: function() { 14 clearNotaPedido: function() {
15 this.notaPedido = undefined; 15 this.notaPedido = undefined;
16 }, 16 },
17 getNotaPedido: function() { 17 getNotaPedido: function() {
18 return this.notaPedido; 18 return this.notaPedido;
19 }, 19 },
20 getArticulosByIdNotaPedido: function(id) { 20 getArticulosByIdNotaPedido: function(id) {
21 return $http.get(route+'/articulos/nota-pedido/'+id); 21 return $http.get(route+'/articulos/nota-pedido/'+id);
22 }, 22 },
23 crearArticulosParaNotaPedido: function(articuloNotaPedido) { 23 crearArticulosParaNotaPedido: function(articuloNotaPedido) {
24 return $http.post(route + '/articulos/nota-pedido', 24 return $http.post(route + '/articulos/nota-pedido',
25 {articuloNotaPedido: articuloNotaPedido}); 25 {articuloNotaPedido: articuloNotaPedido});
26 }, 26 },
27 getDomiciliosByIdNotaPedido: function(id) { 27 getDomiciliosByIdNotaPedido: function(id) {
28 return $http.get(route +'/nota-pedido/'+id+'/domicilios'); 28 return $http.get(route +'/nota-pedido/'+id+'/domicilios');
29 }, 29 },
30 getDomiciliosByIdCliente: function(id) { 30 getDomiciliosByIdCliente: function(id) {
31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
33 }, 33 },
34 getPrecioCondicion: function() { 34 getPrecioCondicion: function() {
35 return $http.get(route + '/precio-condicion'); 35 return $http.get(route + '/precio-condicion');
36 }, 36 },
37 getPrecioCondicionById: function(id) { 37 getPrecioCondicionById: function(id) {
38 return $http.get(route + '/precio-condicion/' + id); 38 return $http.get(route + '/precio-condicion/' + id);
39 }, 39 },
40 getPlazoPagoByPrecioCondicion: function(id) { 40 getPlazoPagoByPrecioCondicion: function(id) {
41 return $http.get(route + '/plazo-pago/precio-condicion/'+ id); 41 return $http.get(route + '/plazo-pago/precio-condicion/'+ id);
42 }, 42 },
43 crearFlete: function(flete) { 43 crearFlete: function(flete) {
44 return $http.post(route + '/flete', {flete : flete}); 44 return $http.post(route + '/flete', {flete : flete});
45 }, 45 },
46 crearPlazosParaNotaPedido: function(plazos) { 46 crearPlazosParaNotaPedido: function(plazos) {
47 return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos}); 47 return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos});
48 }, 48 },
49 getCotizacionByIdMoneda: function(id) { 49 getCotizacionByIdMoneda: function(id) {
50 return $http.get(route + '/moneda/' + id); 50 return $http.get(route + '/moneda/' + id);
51 }, 51 },
52 crearEstadoParaNotaPedido: function(estado) { 52 crearEstadoParaNotaPedido: function(estado) {
53 return $http.post(route + '/estado', {estado: estado}); 53 return $http.post(route + '/estado', {estado: estado});
54 }, 54 },
55 getNumeroNotaPedido: function() { 55 getNumeroNotaPedido: function() {
56 return $http.get(route + '/nota-pedido/numero-siguiente'); 56 return $http.get(route + '/nota-pedido/numero-siguiente');
57 }, 57 },
58 getBotonera: function(vendedor) { 58 getBotonera: function(vendedor) {
59 var result = [ 59 var result = [
60 { 60 {
61 label: 'Cliente', 61 label: 'Cliente',
62 image: 'cliente.png' 62 image: 'cliente.png'
63 }, 63 },
64 { 64 {
65 label: 'Proveedor', 65 label: 'Proveedor',
66 image: 'proveedor.png' 66 image: 'proveedor.png'
67 }, 67 },
68 { 68 {
69 label: 'Moneda', 69 label: 'Moneda',
70 image: 'moneda.png' 70 image: 'moneda.png'
71 }, 71 },
72 { 72 {
73 label: 'Precios y condiciones', 73 label: 'Precios y condiciones',
74 image: 'precios-condiciones.png' 74 image: 'precios-condiciones.png'
75 }, 75 },
76 { 76 {
77 label: 'Flete', 77 label: 'Flete',
78 image: 'flete.png' 78 image: 'flete.png'
79 }, 79 },
80 { 80 {
81 label: 'Productos', 81 label: 'Productos',
82 image: 'productos.png' 82 image: 'productos.png'
83 }, 83 },
84 { 84 {
85 label: 'Observaciones', 85 label: 'Observaciones',
86 image: 'productos.png' 86 image: 'productos.png'
87 } 87 }
88 ]; 88 ];
89 89
90 if(!vendedor) { 90 if(!vendedor) {
91 var botonVendedor = { 91 var botonVendedor = {
92 label: 'Vendedor', 92 label: 'Vendedor',
93 image: 'vendedor.png' 93 image: 'vendedor.png'
94 }; 94 };
95 95
96 result.unshift(botonVendedor); 96 result.unshift(botonVendedor);
97 } 97 }
98 98
99 return result; 99 return result;
100 }, 100 },
101 crearPuntosDescarga: function(puntosDescarga) { 101 crearPuntosDescarga: function(puntosDescarga) {
102 return $http.post(route + '/puntos-descarga/nota-pedido', 102 return $http.post(route + '/puntos-descarga/nota-pedido',
103 {puntosDescarga: puntosDescarga}); 103 {puntosDescarga: puntosDescarga});
104 }, 104 },
105 getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { 105 getPuntosDescargaByClienDom: function(idDomicilio, idCliente) {
106 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + 106 return $http.get(API_ENDPOINT.URL + '/punto-descarga/' +
107 idDomicilio + '/' + idCliente); 107 idDomicilio + '/' + idCliente);
108 }, 108 },
109 getVendedorById: function(id) { 109 getVendedorById: function(id) {
110 return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); 110 return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id);
111 } 111 }
112 }; 112 };
113 }]); 113 }]);
114 114
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/controllerSpecCrearPedido.js"></script>
19 <script type="text/javascript" src="spec/serviceSpec.js"></script>
20 <script type="text/javascript" src="spec/routeSpec.js"></script>
21 </body>
22 </html>
23