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