Commit 5fefcd803ba481a0d2e4427b42d9f8b41f8be3f3

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

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