Commit 9e6f3c0c1c13cc7b18be155f8177e14f698a4612

Authored by Eric Fernandez
1 parent 9ff0854bf4
Exists in master

quito modal vendedores

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