Commit edc2dc474cb21d882da735a69a36675fa8955935

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master (pmarco)

See merge request modulos-npm/foca-crear-remito!4
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",'+ 46 replace('"ngRoute","ui.bootstrap","focaModalVendedores","focaBusquedaProductos",'+
47 '"focaModalProveedor","focaBusquedaCliente","focaModalPrecioCondicion",'+ 47 '"focaModalProveedor","focaBusquedaCliente","focaModalPrecioCondicion",'+
48 '"focaModalFlete","focaDirectivas","focaModal","focaModalDomicilio",'+ 48 '"focaModalFlete","focaDirectivas","focaModal","focaModalDomicilio",'+
49 '"focaModalMoneda","focaModalCotizacion","focaSeguimiento","angular-ladda",'+ 49 '"focaModalMoneda","focaModalCotizacion","focaSeguimiento","angular-ladda",'+
50 '"cordovaGeolocationModule"', ''), 50 '"cordovaGeolocationModule"', ''),
51 gulp.dest(paths.dist) 51 gulp.dest(paths.dist)
52 ] 52 ]
53 ); 53 );
54 }); 54 });
55 55
56 gulp.task('clean', function(){ 56 gulp.task('clean', function() {
57 return gulp.src(['tmp', 'dist'], {read: false}) 57 return gulp.src(['tmp', 'dist'], {read: false})
58 .pipe(clean()); 58 .pipe(clean());
59 }); 59 });
60 60
61 gulp.task('pre-commit', function() { 61 gulp.task('pre-commit', function() {
62 return pump( 62 return pump(
63 [ 63 [
64 gulp.src(paths.srcJS), 64 gulp.src(paths.srcJS),
65 jshint('.jshintrc'), 65 jshint('.jshintrc'),
66 jshint.reporter('default'), 66 jshint.reporter('default'),
67 jshint.reporter('fail') 67 jshint.reporter('fail')
68 ] 68 ]
69 ); 69 );
70 70
71 gulp.start('uglify'); 71 gulp.start('uglify');
72 }); 72 });
73 73
74 gulp.task('webserver', function() { 74 gulp.task('webserver', function() {
75 pump [ 75 pump [
76 connect.server({port: 3300, host: '0.0.0.0'}) 76 connect.server({port: 3300, host: '0.0.0.0'})
77 ] 77 ]
78 }); 78 });
79 79
80 gulp.task('clean-post-install', function() { 80 gulp.task('clean-post-install', function() {
81 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 81 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
82 'index.html'], {read: false}) 82 'index.html'], {read: false})
83 .pipe(clean()); 83 .pipe(clean());
84 }); 84 });
85 85
86 gulp.task('default', ['webserver']); 86 gulp.task('default', ['webserver']);
87 87
88 gulp.task('watch', function() { 88 gulp.task('watch', function() {
89 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 89 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
90 }); 90 });
91 91
92 gulp.task('copy', ['uglify'], function() { 92 gulp.task('copy', ['uglify'], function() {
93 return gulp.src('dist/*.js') 93 return gulp.src('dist/*.js')
94 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-remito/dist/')); 94 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-remito/dist/'));
95 }); 95 });
96 96
97 gulp.task('watchAndCopy', function() { 97 gulp.task('watchAndCopy', function() {
98 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']); 98 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']);
99 }); 99 });
100 100
src/js/controller.js
1 angular.module('focaCrearRemito') .controller('remitoController', 1 angular.module('focaCrearRemito') .controller('remitoController',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService',
4 'focaModalService', 'remitoBusinessService', 4 'focaModalService', 'remitoBusinessService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService, 6 $scope, $uibModal, $location, $filter, crearRemitoService, focaModalService,
7 remitoBusinessService 7 remitoBusinessService
8 ) { 8 ) {
9 $scope.botonera = [ 9 $scope.botonera = [
10 {texto: 'Nota Pedido', accion: function() {$scope.seleccionarNotaPedido();}}, 10 {texto: 'Nota Pedido', accion: function() {$scope.seleccionarNotaPedido();}},
11 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 11 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
12 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 12 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
13 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 13 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
14 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 14 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
15 { 15 {
16 texto: 'Precios y condiciones', 16 texto: 'Precios y condiciones',
17 accion: function() {$scope.abrirModalListaPrecio();}}, 17 accion: function() {$scope.abrirModalListaPrecio();}},
18 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 18 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
19 {texto: '', accion: function() {}} 19 {texto: '', accion: function() {}}
20 ]; 20 ];
21 $scope.datepickerAbierto = false; 21 $scope.datepickerAbierto = false;
22 22
23 $scope.show = false; 23 $scope.show = false;
24 $scope.cargando = true; 24 $scope.cargando = true;
25 $scope.dateOptions = { 25 $scope.dateOptions = {
26 maxDate: new Date(), 26 maxDate: new Date(),
27 minDate: new Date(2010, 0, 1) 27 minDate: new Date(2010, 0, 1)
28 }; 28 };
29 29
30 $scope.remito = { 30 $scope.remito = {
31 vendedor: {}, 31 vendedor: {},
32 cliente: {}, 32 cliente: {},
33 proveedor: {}, 33 proveedor: {},
34 domicilio: {dom: ''}, 34 domicilio: {dom: ''},
35 moneda: {}, 35 moneda: {},
36 cotizacion: {} 36 cotizacion: {}
37 }; 37 };
38 var monedaPorDefecto; 38 var monedaPorDefecto;
39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
40 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { 40 crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) {
41 monedaPorDefecto = { 41 monedaPorDefecto = {
42 id: res.data[0].ID, 42 id: res.data[0].ID,
43 detalle: res.data[0].DETALLE, 43 detalle: res.data[0].DETALLE,
44 simbolo: res.data[0].SIMBOLO, 44 simbolo: res.data[0].SIMBOLO,
45 cotizaciones: res.data[0].cotizaciones 45 cotizaciones: res.data[0].cotizaciones
46 }; 46 };
47 addCabecera('Moneda:', monedaPorDefecto.detalle); 47 addCabecera('Moneda:', monedaPorDefecto.detalle);
48 addCabecera('Fecha cotizacion:', 48 addCabecera('Fecha cotizacion:',
49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); 49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString());
50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); 50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION);
51 $scope.remito.moneda = monedaPorDefecto; 51 $scope.remito.moneda = monedaPorDefecto;
52 $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; 52 $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0];
53 }); 53 });
54 54
55 $scope.cabecera = []; 55 $scope.cabecera = [];
56 $scope.showCabecera = true; 56 $scope.showCabecera = true;
57 57
58 $scope.now = new Date(); 58 $scope.now = new Date();
59 $scope.puntoVenta = Math.round(Math.random() * 10000); 59 $scope.puntoVenta = Math.round(Math.random() * 10000);
60 $scope.comprobante = Math.round(Math.random() * 1000000); 60 $scope.comprobante = Math.round(Math.random() * 1000000);
61 61
62 $scope.articulosTabla = []; 62 $scope.articulosTabla = [];
63 $scope.idLista = undefined; 63 $scope.idLista = undefined;
64 //La pantalla solo se usa para cargar remitos 64 //La pantalla solo se usa para cargar remitos
65 //var remitoTemp = crearRemitoService.getRemito(); 65 //var remitoTemp = crearRemitoService.getRemito();
66 66
67 crearRemitoService.getPrecioCondicion().then( 67 crearRemitoService.getPrecioCondicion().then(
68 function(res) { 68 function(res) {
69 $scope.precioCondiciones = res.data; 69 $scope.precioCondiciones = res.data;
70 } 70 }
71 ); 71 );
72 72
73 crearRemitoService.getNumeroRemito().then( 73 crearRemitoService.getNumeroRemito().then(
74 function(res) { 74 function(res) {
75 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 75 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
76 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); 76 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
77 }, 77 },
78 function(err) { 78 function(err) {
79 focaModalService.alert('La terminal no esta configurada correctamente'); 79 focaModalService.alert('La terminal no esta configurada correctamente');
80 console.info(err); 80 console.info(err);
81 } 81 }
82 ); 82 );
83 83
84 $scope.seleccionarNotaPedido = function() { 84 $scope.seleccionarNotaPedido = function() {
85 var modalInstance = $uibModal.open( 85 var modalInstance = $uibModal.open(
86 { 86 {
87 ariaLabelledBy: 'Busqueda de Nota de Pedido', 87 ariaLabelledBy: 'Busqueda de Nota de Pedido',
88 templateUrl: 'foca-modal-nota-pedido.html', 88 templateUrl: 'foca-modal-nota-pedido.html',
89 controller: 'focaModalNotaPedidoController', 89 controller: 'focaModalNotaPedidoController',
90 resolve: { 90 resolve: {
91 parametroNotaPedido: { 91 parametroNotaPedido: {
92 idLista: $scope.idLista, 92 idLista: $scope.idLista,
93 cotizacion: $scope.remito.cotizacion.COTIZACION, 93 cotizacion: $scope.remito.cotizacion.COTIZACION,
94 simbolo: $scope.remito.moneda.simbolo 94 simbolo: $scope.remito.moneda.simbolo
95 } 95 }
96 }, 96 },
97 size: 'lg' 97 size: 'lg'
98 } 98 }
99 ); 99 );
100 modalInstance.result.then( 100 modalInstance.result.then(
101 function(producto) { 101 function(producto) {
102 var newArt = 102 var newArt =
103 { 103 {
104 id: 0, 104 id: 0,
105 codigo: producto.codigo, 105 codigo: producto.codigo,
106 sector: producto.sector, 106 sector: producto.sector,
107 sectorCodigo: producto.sector + '-' + producto.codigo, 107 sectorCodigo: producto.sector + '-' + producto.codigo,
108 descripcion: producto.descripcion, 108 descripcion: producto.descripcion,
109 item: $scope.articulosTabla.length + 1, 109 item: $scope.articulosTabla.length + 1,
110 nombre: producto.descripcion, 110 nombre: producto.descripcion,
111 precio: parseFloat(producto.precio.toFixed(4)), 111 precio: parseFloat(producto.precio.toFixed(4)),
112 costoUnitario: producto.costo, 112 costoUnitario: producto.costo,
113 editCantidad: false, 113 editCantidad: false,
114 editPrecio: false 114 editPrecio: false
115 }; 115 };
116 $scope.articuloACargar = newArt; 116 $scope.articuloACargar = newArt;
117 $scope.cargando = false; 117 $scope.cargando = false;
118 }, function() { 118 }, function() {
119 // funcion ejecutada cuando se cancela el modal 119 // funcion ejecutada cuando se cancela el modal
120 } 120 }
121 ); 121 );
122 }; 122 };
123 123
124 $scope.seleccionarRemito = function() { 124 $scope.seleccionarRemito = function() {
125 var modalInstance = $uibModal.open( 125 var modalInstance = $uibModal.open(
126 { 126 {
127 ariaLabelledBy: 'Busqueda de Remito', 127 ariaLabelledBy: 'Busqueda de Remito',
128 templateUrl: 'foca-modal-remito.html', 128 templateUrl: 'foca-modal-remito.html',
129 controller: 'focaModalRemitoController', 129 controller: 'focaModalRemitoController',
130 resolve: { 130 resolve: {
131 parametroRemito: { 131 parametroRemito: {
132 idLista: $scope.idLista, 132 idLista: $scope.idLista,
133 cotizacion: $scope.remito.cotizacion.COTIZACION, 133 cotizacion: $scope.remito.cotizacion.COTIZACION,
134 simbolo: $scope.remito.moneda.simbolo 134 simbolo: $scope.remito.moneda.simbolo
135 } 135 }
136 }, 136 },
137 size: 'lg' 137 size: 'lg'
138 } 138 }
139 ); 139 );
140 modalInstance.result.then( 140 modalInstance.result.then(
141 function(producto) { 141 function(producto) {
142 var newArt = 142 var newArt =
143 { 143 {
144 id: 0, 144 id: 0,
145 codigo: producto.codigo, 145 codigo: producto.codigo,
146 sector: producto.sector, 146 sector: producto.sector,
147 sectorCodigo: producto.sector + '-' + producto.codigo, 147 sectorCodigo: producto.sector + '-' + producto.codigo,
148 descripcion: producto.descripcion, 148 descripcion: producto.descripcion,
149 item: $scope.articulosTabla.length + 1, 149 item: $scope.articulosTabla.length + 1,
150 nombre: producto.descripcion, 150 nombre: producto.descripcion,
151 precio: parseFloat(producto.precio.toFixed(4)), 151 precio: parseFloat(producto.precio.toFixed(4)),
152 costoUnitario: producto.costo, 152 costoUnitario: producto.costo,
153 editCantidad: false, 153 editCantidad: false,
154 editPrecio: false 154 editPrecio: false
155 }; 155 };
156 $scope.articuloACargar = newArt; 156 $scope.articuloACargar = newArt;
157 $scope.cargando = false; 157 $scope.cargando = false;
158 }, function() { 158 }, function() {
159 // funcion ejecutada cuando se cancela el modal 159 // funcion ejecutada cuando se cancela el modal
160 } 160 }
161 ); 161 );
162 }; 162 };
163 163
164 //La pantalla solo se usa para cargar remitos 164 //La pantalla solo se usa para cargar remitos
165 // if (remitoTemp !== undefined) { 165 // if (remitoTemp !== undefined) {
166 // remitoTemp.fechaCarga = new Date(remitoTemp.fechaCarga); 166 // remitoTemp.fechaCarga = new Date(remitoTemp.fechaCarga);
167 // $scope.remito = remitoTemp; 167 // $scope.remito = remitoTemp;
168 // $scope.remito.flete = ($scope.remito.flete).toString(); 168 // $scope.remito.flete = ($scope.remito.flete).toString();
169 // $scope.remito.bomba = ($scope.remito.bomba).toString(); 169 // $scope.remito.bomba = ($scope.remito.bomba).toString();
170 // $scope.idLista = $scope.remito.precioCondicion; 170 // $scope.idLista = $scope.remito.precioCondicion;
171 // crearRemitoService 171 // crearRemitoService
172 // .getArticulosByIdRemito($scope.remito.id).then( 172 // .getArticulosByIdRemito($scope.remito.id).then(
173 // function(res) { 173 // function(res) {
174 // $scope.articulosTabla = res.data; 174 // $scope.articulosTabla = res.data;
175 // } 175 // }
176 // ); 176 // );
177 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR REMITO 177 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR REMITO
178 //(NO REQUERIDO EN ESTA VERSION) 178 //(NO REQUERIDO EN ESTA VERSION)
179 // crearRemitoService.getDomiciliosByIdRemito($scope.remito.id).then( 179 // crearRemitoService.getDomiciliosByIdRemito($scope.remito.id).then(
180 // function(res) { 180 // function(res) {
181 // $scope.remito.domicilio = res.data; 181 // $scope.remito.domicilio = res.data;
182 // } 182 // }
183 // ); 183 // );
184 // } else { 184 // } else {
185 // $scope.remito.fechaCarga = new Date(); 185 // $scope.remito.fechaCarga = new Date();
186 // $scope.remito.bomba = '0'; 186 // $scope.remito.bomba = '0';
187 // $scope.remito.flete = '0'; 187 // $scope.remito.flete = '0';
188 // $scope.idLista = undefined; 188 // $scope.idLista = undefined;
189 // } 189 // }
190 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 190 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
191 // $scope.addNewDom = function() { 191 // $scope.addNewDom = function() {
192 // $scope.remito.domicilio.push({ 'id': 0 }); 192 // $scope.remito.domicilio.push({ 'id': 0 });
193 // }; 193 // };
194 // $scope.removeNewChoice = function(choice) { 194 // $scope.removeNewChoice = function(choice) {
195 // if ($scope.remito.domicilio.length > 1) { 195 // if ($scope.remito.domicilio.length > 1) {
196 // $scope.remito.domicilio.splice($scope.remito.domicilio.findIndex( 196 // $scope.remito.domicilio.splice($scope.remito.domicilio.findIndex(
197 // function(c) { 197 // function(c) {
198 // return c.$$hashKey === choice.$$hashKey; 198 // return c.$$hashKey === choice.$$hashKey;
199 // } 199 // }
200 // ), 1); 200 // ), 1);
201 // } 201 // }
202 // }; 202 // };
203 203
204 $scope.crearRemito = function() { 204 $scope.crearRemito = function() {
205 if(!$scope.remito.vendedor.codigo) { 205 if(!$scope.remito.vendedor.codigo) {
206 focaModalService.alert('Ingrese Vendedor'); 206 focaModalService.alert('Ingrese Vendedor');
207 return; 207 return;
208 } else if(!$scope.remito.cliente.cod) { 208 } else if(!$scope.remito.cliente.cod) {
209 focaModalService.alert('Ingrese Cliente'); 209 focaModalService.alert('Ingrese Cliente');
210 return; 210 return;
211 } else if(!$scope.remito.proveedor.codigo) { 211 } else if(!$scope.remito.proveedor.codigo) {
212 focaModalService.alert('Ingrese Proveedor'); 212 focaModalService.alert('Ingrese Proveedor');
213 return; 213 return;
214 } else if(!$scope.remito.moneda.id) { 214 } else if(!$scope.remito.moneda.id) {
215 focaModalService.alert('Ingrese Moneda'); 215 focaModalService.alert('Ingrese Moneda');
216 return; 216 return;
217 } else if(!$scope.remito.cotizacion.ID) { 217 } else if(!$scope.remito.cotizacion.ID) {
218 focaModalService.alert('Ingrese Cotización'); 218 focaModalService.alert('Ingrese Cotización');
219 return; 219 return;
220 } else if(!$scope.plazosPagos) { 220 } else if(!$scope.plazosPagos) {
221 focaModalService.alert('Ingrese Precios y Condiciones'); 221 focaModalService.alert('Ingrese Precios y Condiciones');
222 return; 222 return;
223 } else if( 223 } else if(
224 $scope.remito.flete === undefined || $scope.remito.flete === null) 224 $scope.remito.flete === undefined || $scope.remito.flete === null)
225 { 225 {
226 focaModalService.alert('Ingrese Flete'); 226 focaModalService.alert('Ingrese Flete');
227 return; 227 return;
228 } else if(!$scope.remito.domicilio.id) { 228 } else if(!$scope.remito.domicilio.id) {
229 focaModalService.alert('Ingrese Domicilio'); 229 focaModalService.alert('Ingrese Domicilio');
230 return; 230 return;
231 } else if($scope.articulosTabla.length === 0) { 231 } else if($scope.articulosTabla.length === 0) {
232 focaModalService.alert('Debe cargar al menos un articulo'); 232 focaModalService.alert('Debe cargar al menos un articulo');
233 return; 233 return;
234 } 234 }
235 var date = new Date(); 235 var date = new Date();
236 var remito = { 236 var remito = {
237 id: 0, 237 id: 0,
238 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 238 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
239 .toISOString().slice(0, 19).replace('T', ' '), 239 .toISOString().slice(0, 19).replace('T', ' '),
240 idVendedor: $scope.remito.vendedor.codigo, 240 idVendedor: $scope.remito.vendedor.codigo,
241 idCliente: $scope.remito.cliente.cod, 241 idCliente: $scope.remito.cliente.cod,
242 nombreCliente: $scope.remito.cliente.nom, 242 nombreCliente: $scope.remito.cliente.nom,
243 cuitCliente: $scope.remito.cliente.cuit, 243 cuitCliente: $scope.remito.cliente.cuit,
244 idProveedor: $scope.remito.proveedor.codigo, 244 idProveedor: $scope.remito.proveedor.codigo,
245 idDomicilio: $scope.remito.domicilio.id, 245 idDomicilio: $scope.remito.domicilio.id,
246 idCotizacion: $scope.remito.cotizacion.ID, 246 idCotizacion: $scope.remito.cotizacion.ID,
247 cotizacion: $scope.remito.cotizacion.COTIZACION, 247 cotizacion: $scope.remito.cotizacion.COTIZACION,
248 flete: $scope.remito.flete, 248 flete: $scope.remito.flete,
249 fob: $scope.remito.fob, 249 fob: $scope.remito.fob,
250 bomba: $scope.remito.bomba, 250 bomba: $scope.remito.bomba,
251 kilometros: $scope.remito.kilometros, 251 kilometros: $scope.remito.kilometros,
252 estado: 0, 252 estado: 0,
253 total: $scope.getTotal() 253 total: $scope.getTotal()
254 }; 254 };
255 crearRemitoService.crearRemito(remito).then( 255 crearRemitoService.crearRemito(remito).then(
256 function(data) { 256 function(data) {
257 remitoBusinessService.addArticulos($scope.articulosTabla, 257 remitoBusinessService.addArticulos($scope.articulosTabla,
258 data.data.id, $scope.remito.cotizacion.COTIZACION); 258 data.data.id, $scope.remito.cotizacion.COTIZACION);
259 var plazos = $scope.plazosPagos; 259 var plazos = $scope.plazosPagos;
260 for(var j = 0; j < plazos.length; j++) { 260 for(var j = 0; j < plazos.length; j++) {
261 var json = { 261 var json = {
262 idRemito: data.data.id, 262 idRemito: data.data.id,
263 dias: plazos[j].dias 263 dias: plazos[j].dias
264 }; 264 };
265 crearRemitoService.crearPlazosParaRemito(json); 265 crearRemitoService.crearPlazosParaRemito(json);
266 } 266 }
267 remitoBusinessService.addEstado(data.data.id, 267 remitoBusinessService.addEstado(data.data.id,
268 $scope.remito.vendedor.codigo); 268 $scope.remito.vendedor.codigo);
269 269
270 focaModalService.alert('Nota remito creada'); 270 focaModalService.alert('Nota remito creada');
271 $scope.cabecera = []; 271 $scope.cabecera = [];
272 addCabecera('Moneda:', $scope.remito.moneda.detalle); 272 addCabecera('Moneda:', $scope.remito.moneda.detalle);
273 addCabecera( 273 addCabecera(
274 'Fecha cotizacion:', 274 'Fecha cotizacion:',
275 $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy') 275 $filter('date')($scope.remito.cotizacion.FECHA, 'dd/MM/yyyy')
276 ); 276 );
277 addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION); 277 addCabecera('Cotizacion:', $scope.remito.cotizacion.COTIZACION);
278 $scope.remito.vendedor = {}; 278 $scope.remito.vendedor = {};
279 $scope.remito.cliente = {}; 279 $scope.remito.cliente = {};
280 $scope.remito.proveedor = {}; 280 $scope.remito.proveedor = {};
281 $scope.remito.domicilio = {}; 281 $scope.remito.domicilio = {};
282 $scope.remito.flete = null; 282 $scope.remito.flete = null;
283 $scope.remito.fob = null; 283 $scope.remito.fob = null;
284 $scope.remito.bomba = null; 284 $scope.remito.bomba = null;
285 $scope.remito.kilometros = null; 285 $scope.remito.kilometros = null;
286 $scope.articulosTabla = []; 286 $scope.articulosTabla = [];
287 } 287 }
288 ); 288 );
289 }; 289 };
290 290
291 $scope.seleccionarArticulo = function() { 291 $scope.seleccionarArticulo = function() {
292 if ($scope.idLista === undefined) { 292 if ($scope.idLista === undefined) {
293 focaModalService.alert( 293 focaModalService.alert(
294 'Primero seleccione una lista de precio y condicion'); 294 'Primero seleccione una lista de precio y condicion');
295 return; 295 return;
296 } 296 }
297 var modalInstance = $uibModal.open( 297 var modalInstance = $uibModal.open(
298 { 298 {
299 ariaLabelledBy: 'Busqueda de Productos', 299 ariaLabelledBy: 'Busqueda de Productos',
300 templateUrl: 'modal-busqueda-productos.html', 300 templateUrl: 'modal-busqueda-productos.html',
301 controller: 'modalBusquedaProductosCtrl', 301 controller: 'modalBusquedaProductosCtrl',
302 resolve: { 302 resolve: {
303 parametroProducto: { 303 parametroProducto: {
304 idLista: $scope.idLista, 304 idLista: $scope.idLista,
305 cotizacion: $scope.remito.cotizacion.COTIZACION, 305 cotizacion: $scope.remito.cotizacion.COTIZACION,
306 simbolo: $scope.remito.moneda.simbolo 306 simbolo: $scope.remito.moneda.simbolo
307 } 307 }
308 }, 308 },
309 size: 'lg' 309 size: 'lg'
310 } 310 }
311 ); 311 );
312 modalInstance.result.then( 312 modalInstance.result.then(
313 function(producto) { 313 function(producto) {
314 var newArt = 314 var newArt =
315 { 315 {
316 id: 0, 316 id: 0,
317 codigo: producto.codigo, 317 codigo: producto.codigo,
318 sector: producto.sector, 318 sector: producto.sector,
319 sectorCodigo: producto.sector + '-' + producto.codigo, 319 sectorCodigo: producto.sector + '-' + producto.codigo,
320 descripcion: producto.descripcion, 320 descripcion: producto.descripcion,
321 item: $scope.articulosTabla.length + 1, 321 item: $scope.articulosTabla.length + 1,
322 nombre: producto.descripcion, 322 nombre: producto.descripcion,
323 precio: parseFloat(producto.precio.toFixed(4)), 323 precio: parseFloat(producto.precio.toFixed(4)),
324 costoUnitario: producto.costo, 324 costoUnitario: producto.costo,
325 editCantidad: false, 325 editCantidad: false,
326 editPrecio: false 326 editPrecio: false
327 }; 327 };
328 $scope.articuloACargar = newArt; 328 $scope.articuloACargar = newArt;
329 $scope.cargando = false; 329 $scope.cargando = false;
330 }, function() { 330 }, function() {
331 // funcion ejecutada cuando se cancela el modal 331 // funcion ejecutada cuando se cancela el modal
332 } 332 }
333 ); 333 );
334 }; 334 };
335 335
336 $scope.seleccionarVendedor = function() { 336 $scope.seleccionarVendedor = function() {
337 var modalInstance = $uibModal.open( 337 var modalInstance = $uibModal.open(
338 { 338 {
339 ariaLabelledBy: 'Busqueda de Vendedores', 339 ariaLabelledBy: 'Busqueda de Vendedores',
340 templateUrl: 'modal-vendedores.html', 340 templateUrl: 'modal-vendedores.html',
341 controller: 'modalVendedoresCtrl', 341 controller: 'modalVendedoresCtrl',
342 size: 'lg' 342 size: 'lg'
343 } 343 }
344 ); 344 );
345 modalInstance.result.then( 345 modalInstance.result.then(
346 function(vendedor) { 346 function(vendedor) {
347 addCabecera('Vendedor:', vendedor.NomVen); 347 addCabecera('Vendedor:', vendedor.NomVen);
348 $scope.remito.vendedor.codigo = vendedor.CodVen; 348 $scope.remito.vendedor.codigo = vendedor.CodVen;
349 }, function() { 349 }, function() {
350 350
351 } 351 }
352 ); 352 );
353 }; 353 };
354 354
355 $scope.seleccionarProveedor = function() { 355 $scope.seleccionarProveedor = function() {
356 var modalInstance = $uibModal.open( 356 var modalInstance = $uibModal.open(
357 { 357 {
358 ariaLabelledBy: 'Busqueda de Proveedor', 358 ariaLabelledBy: 'Busqueda de Proveedor',
359 templateUrl: 'modal-proveedor.html', 359 templateUrl: 'modal-proveedor.html',
360 controller: 'focaModalProveedorCtrl', 360 controller: 'focaModalProveedorCtrl',
361 size: 'lg' 361 size: 'lg'
362 } 362 }
363 ); 363 );
364 modalInstance.result.then( 364 modalInstance.result.then(
365 function(proveedor) { 365 function(proveedor) {
366 $scope.remito.proveedor.codigo = proveedor.COD; 366 $scope.remito.proveedor.codigo = proveedor.COD;
367 addCabecera('Proveedor:', proveedor.NOM); 367 addCabecera('Proveedor:', proveedor.NOM);
368 }, function() { 368 }, function() {
369 369
370 } 370 }
371 ); 371 );
372 }; 372 };
373 373
374 $scope.seleccionarCliente = function() { 374 $scope.seleccionarCliente = function() {
375 375
376 var modalInstance = $uibModal.open( 376 var modalInstance = $uibModal.open(
377 { 377 {
378 ariaLabelledBy: 'Busqueda de Cliente', 378 ariaLabelledBy: 'Busqueda de Cliente',
379 templateUrl: 'foca-busqueda-cliente-modal.html', 379 templateUrl: 'foca-busqueda-cliente-modal.html',
380 controller: 'focaBusquedaClienteModalController', 380 controller: 'focaBusquedaClienteModalController',
381 size: 'lg' 381 size: 'lg'
382 } 382 }
383 ); 383 );
384 modalInstance.result.then( 384 modalInstance.result.then(
385 function(cliente) { 385 function(cliente) {
386 $scope.abrirModalDomicilios(cliente); 386 $scope.abrirModalDomicilios(cliente);
387 }, function() { 387 }, function() {
388 388
389 } 389 }
390 ); 390 );
391 }; 391 };
392 392
393 $scope.abrirModalDomicilios = function(cliente) { 393 $scope.abrirModalDomicilios = function(cliente) {
394 var modalInstanceDomicilio = $uibModal.open( 394 var modalInstanceDomicilio = $uibModal.open(
395 { 395 {
396 ariaLabelledBy: 'Busqueda de Domicilios', 396 ariaLabelledBy: 'Busqueda de Domicilios',
397 templateUrl: 'modal-domicilio.html', 397 templateUrl: 'modal-domicilio.html',
398 controller: 'focaModalDomicilioController', 398 controller: 'focaModalDomicilioController',
399 resolve: { idCliente: function() { return cliente.cod; }}, 399 resolve: { idCliente: function() { return cliente.cod; }},
400 size: 'lg', 400 size: 'lg',
401 } 401 }
402 ); 402 );
403 modalInstanceDomicilio.result.then( 403 modalInstanceDomicilio.result.then(
404 function(domicilio) { 404 function(domicilio) {
405 $scope.remito.domicilio.id = domicilio.nivel2; 405 $scope.remito.domicilio.id = domicilio.nivel2;
406 $scope.remito.cliente = cliente; 406 $scope.remito.cliente = cliente;
407 407
408 addCabecera('Cliente:', cliente.nom); 408 addCabecera('Cliente:', cliente.nom);
409 addCabecera('Domicilio:', domicilio.dom); 409 addCabecera('Domicilio:', domicilio.dom);
410 }, function() { 410 }, function() {
411 $scope.seleccionarCliente(); 411 $scope.seleccionarCliente();
412 return; 412 return;
413 } 413 }
414 ); 414 );
415 }; 415 };
416 416
417 $scope.mostrarFichaCliente = function() { 417 $scope.mostrarFichaCliente = function() {
418 $uibModal.open( 418 $uibModal.open(
419 { 419 {
420 ariaLabelledBy: 'Datos del Cliente', 420 ariaLabelledBy: 'Datos del Cliente',
421 templateUrl: 'foca-crear-remito-ficha-cliente.html', 421 templateUrl: 'foca-crear-remito-ficha-cliente.html',
422 controller: 'focaCrearRemitoFichaClienteController', 422 controller: 'focaCrearRemitoFichaClienteController',
423 size: 'lg' 423 size: 'lg'
424 } 424 }
425 ); 425 );
426 }; 426 };
427 427
428 $scope.getTotal = function() { 428 $scope.getTotal = function() {
429 var total = 0; 429 var total = 0;
430 var arrayTempArticulos = $scope.articulosTabla; 430 var arrayTempArticulos = $scope.articulosTabla;
431 for (var i = 0; i < arrayTempArticulos.length; i++) { 431 for (var i = 0; i < arrayTempArticulos.length; i++) {
432 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 432 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
433 } 433 }
434 return parseFloat(total.toFixed(2)); 434 return parseFloat(total.toFixed(2));
435 }; 435 };
436 436
437 $scope.getSubTotal = function() { 437 $scope.getSubTotal = function() {
438 if($scope.articuloACargar) { 438 if($scope.articuloACargar) {
439 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 439 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
440 } 440 }
441 }; 441 };
442 442
443 $scope.abrirModalListaPrecio = function() { 443 $scope.abrirModalListaPrecio = function() {
444 var modalInstance = $uibModal.open( 444 var modalInstance = $uibModal.open(
445 { 445 {
446 ariaLabelledBy: 'Busqueda de Precio Condición', 446 ariaLabelledBy: 'Busqueda de Precio Condición',
447 templateUrl: 'modal-precio-condicion.html', 447 templateUrl: 'modal-precio-condicion.html',
448 controller: 'focaModalPrecioCondicionController', 448 controller: 'focaModalPrecioCondicionController',
449 size: 'lg' 449 size: 'lg'
450 } 450 }
451 ); 451 );
452 modalInstance.result.then( 452 modalInstance.result.then(
453 function(precioCondicion) { 453 function(precioCondicion) {
454 var cabecera = ''; 454 var cabecera = '';
455 var plazosConcat = ''; 455 var plazosConcat = '';
456 if(!Array.isArray(precioCondicion)) { 456 if(!Array.isArray(precioCondicion)) {
457 $scope.plazosPagos = precioCondicion.plazoPago; 457 $scope.plazosPagos = precioCondicion.plazoPago;
458 $scope.idLista = precioCondicion.idListaPrecio; 458 $scope.idLista = precioCondicion.idListaPrecio;
459 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 459 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
460 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 460 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
461 } 461 }
462 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 462 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
463 } else { //Cuando se ingresan los plazos manualmente 463 } else { //Cuando se ingresan los plazos manualmente
464 $scope.idLista = -1; //-1, el modal productos busca todos los productos 464 $scope.idLista = -1; //-1, el modal productos busca todos los productos
465 $scope.plazosPagos = precioCondicion; 465 $scope.plazosPagos = precioCondicion;
466 for(var j = 0; j < precioCondicion.length; j++) { 466 for(var j = 0; j < precioCondicion.length; j++) {
467 plazosConcat += precioCondicion[j].dias + ' '; 467 plazosConcat += precioCondicion[j].dias + ' ';
468 } 468 }
469 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 469 cabecera = 'Ingreso manual ' + plazosConcat.trim();
470 } 470 }
471 $scope.articulosTabla = []; 471 $scope.articulosTabla = [];
472 addCabecera('Precios y condiciones:', cabecera); 472 addCabecera('Precios y condiciones:', cabecera);
473 }, function() { 473 }, function() {
474 474
475 } 475 }
476 ); 476 );
477 }; 477 };
478 478
479 $scope.abrirModalFlete = function() { 479 $scope.abrirModalFlete = function() {
480 var modalInstance = $uibModal.open( 480 var modalInstance = $uibModal.open(
481 { 481 {
482 ariaLabelledBy: 'Busqueda de Flete', 482 ariaLabelledBy: 'Busqueda de Flete',
483 templateUrl: 'modal-flete.html', 483 templateUrl: 'modal-flete.html',
484 controller: 'focaModalFleteController', 484 controller: 'focaModalFleteController',
485 size: 'lg', 485 size: 'lg',
486 resolve: { 486 resolve: {
487 parametrosFlete: 487 parametrosFlete:
488 function() { 488 function() {
489 return { 489 return {
490 flete: $scope.remito.flete ? '1' : 490 flete: $scope.remito.flete ? '1' :
491 ($scope.remito.fob ? 'FOB' : 491 ($scope.remito.fob ? 'FOB' :
492 ($scope.remito.flete === undefined ? null : '0')), 492 ($scope.remito.flete === undefined ? null : '0')),
493 bomba: $scope.remito.bomba ? '1' : 493 bomba: $scope.remito.bomba ? '1' :
494 ($scope.remito.bomba === undefined ? null : '0'), 494 ($scope.remito.bomba === undefined ? null : '0'),
495 kilometros: $scope.remito.kilometros 495 kilometros: $scope.remito.kilometros
496 }; 496 };
497 } 497 }
498 } 498 }
499 } 499 }
500 ); 500 );
501 modalInstance.result.then( 501 modalInstance.result.then(
502 function(datos) { 502 function(datos) {
503 $scope.remito.flete = datos.flete; 503 $scope.remito.flete = datos.flete;
504 $scope.remito.fob = datos.FOB; 504 $scope.remito.fob = datos.FOB;
505 $scope.remito.bomba = datos.bomba; 505 $scope.remito.bomba = datos.bomba;
506 $scope.remito.kilometros = datos.kilometros; 506 $scope.remito.kilometros = datos.kilometros;
507 507
508 addCabecera('Flete:', datos.flete ? 'Si' : 508 addCabecera('Flete:', datos.flete ? 'Si' :
509 ($scope.remito.fob ? 'FOB' : 'No')); 509 ($scope.remito.fob ? 'FOB' : 'No'));
510 if(datos.flete) { 510 if(datos.flete) {
511 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 511 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
512 addCabecera('Kilometros:', datos.kilometros); 512 addCabecera('Kilometros:', datos.kilometros);
513 } else { 513 } else {
514 removeCabecera('Bomba:'); 514 removeCabecera('Bomba:');
515 removeCabecera('Kilometros:'); 515 removeCabecera('Kilometros:');
516 $scope.remito.fob = false; 516 $scope.remito.fob = false;
517 $scope.remito.bomba = false; 517 $scope.remito.bomba = false;
518 $scope.remito.kilometros = null; 518 $scope.remito.kilometros = null;
519 } 519 }
520 }, function() { 520 }, function() {
521 521
522 } 522 }
523 ); 523 );
524 }; 524 };
525 525
526 $scope.abrirModalMoneda = function() { 526 $scope.abrirModalMoneda = function() {
527 var modalInstance = $uibModal.open( 527 var modalInstance = $uibModal.open(
528 { 528 {
529 ariaLabelledBy: 'Busqueda de Moneda', 529 ariaLabelledBy: 'Busqueda de Moneda',
530 templateUrl: 'modal-moneda.html', 530 templateUrl: 'modal-moneda.html',
531 controller: 'focaModalMonedaController', 531 controller: 'focaModalMonedaController',
532 size: 'lg' 532 size: 'lg'
533 } 533 }
534 ); 534 );
535 modalInstance.result.then( 535 modalInstance.result.then(
536 function(moneda) { 536 function(moneda) {
537 $scope.abrirModalCotizacion(moneda); 537 $scope.abrirModalCotizacion(moneda);
538 }, function() { 538 }, function() {
539 539
540 } 540 }
541 ); 541 );
542 }; 542 };
543 543
544 $scope.abrirModalCotizacion = function(moneda) { 544 $scope.abrirModalCotizacion = function(moneda) {
545 var modalInstance = $uibModal.open( 545 var modalInstance = $uibModal.open(
546 { 546 {
547 ariaLabelledBy: 'Busqueda de Cotización', 547 ariaLabelledBy: 'Busqueda de Cotización',
548 templateUrl: 'modal-cotizacion.html', 548 templateUrl: 'modal-cotizacion.html',
549 controller: 'focaModalCotizacionController', 549 controller: 'focaModalCotizacionController',
550 size: 'lg', 550 size: 'lg',
551 resolve: {idMoneda: function() {return moneda.ID;}} 551 resolve: {idMoneda: function() {return moneda.ID;}}
552 } 552 }
553 ); 553 );
554 modalInstance.result.then( 554 modalInstance.result.then(
555 function(cotizacion) { 555 function(cotizacion) {
556 var articulosTablaTemp = $scope.articulosTabla; 556 var articulosTablaTemp = $scope.articulosTabla;
557 for(var i = 0; i < articulosTablaTemp.length; i++) { 557 for(var i = 0; i < articulosTablaTemp.length; i++) {
558 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 558 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
559 $scope.remito.cotizacion.COTIZACION; 559 $scope.remito.cotizacion.COTIZACION;
560 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 560 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
561 cotizacion.COTIZACION; 561 cotizacion.COTIZACION;
562 } 562 }
563 $scope.articulosTabla = articulosTablaTemp; 563 $scope.articulosTabla = articulosTablaTemp;
564 $scope.remito.moneda = { 564 $scope.remito.moneda = {
565 id: moneda.ID, 565 id: moneda.ID,
566 detalle: moneda.DETALLE, 566 detalle: moneda.DETALLE,
567 simbolo: moneda.SIMBOLO 567 simbolo: moneda.SIMBOLO
568 }; 568 };
569 $scope.remito.cotizacion = { 569 $scope.remito.cotizacion = {
570 ID: cotizacion.ID, 570 ID: cotizacion.ID,
571 COTIZACION: cotizacion.COTIZACION, 571 COTIZACION: cotizacion.COTIZACION,
572 FECHA: cotizacion.FECHA 572 FECHA: cotizacion.FECHA
573 }; 573 };
574 addCabecera('Moneda:', moneda.DETALLE); 574 addCabecera('Moneda:', moneda.DETALLE);
575 addCabecera( 575 addCabecera(
576 'Fecha cotizacion:', 576 'Fecha cotizacion:',
577 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 577 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
578 ); 578 );
579 addCabecera('Cotizacion:', cotizacion.COTIZACION); 579 addCabecera('Cotizacion:', cotizacion.COTIZACION);
580 }, function() { 580 }, function() {
581 581
582 } 582 }
583 ); 583 );
584 }; 584 };
585 585
586 $scope.agregarATabla = function(key) { 586 $scope.agregarATabla = function(key) {
587 if(key === 13) { 587 if(key === 13) {
588 if($scope.articuloACargar.cantidad === undefined || 588 if($scope.articuloACargar.cantidad === undefined ||
589 $scope.articuloACargar.cantidad === 0 || 589 $scope.articuloACargar.cantidad === 0 ||
590 $scope.articuloACargar.cantidad === null ){ 590 $scope.articuloACargar.cantidad === null ) {
591 focaModalService.alert('El valor debe ser al menos 1'); 591 focaModalService.alert('El valor debe ser al menos 1');
592 return; 592 return;
593 } 593 }
594 delete $scope.articuloACargar.sectorCodigo; 594 delete $scope.articuloACargar.sectorCodigo;
595 $scope.articulosTabla.push($scope.articuloACargar); 595 $scope.articulosTabla.push($scope.articuloACargar);
596 $scope.cargando = true; 596 $scope.cargando = true;
597 } 597 }
598 }; 598 };
599 599
600 $scope.quitarArticulo = function(key) { 600 $scope.quitarArticulo = function(key) {
601 $scope.articulosTabla.splice(key, 1); 601 $scope.articulosTabla.splice(key, 1);
602 }; 602 };
603 603
604 $scope.editarArticulo = function(key, articulo) { 604 $scope.editarArticulo = function(key, articulo) {
605 if(key === 13) { 605 if(key === 13) {
606 if(articulo.cantidad === null || articulo.cantidad === 0 || 606 if(articulo.cantidad === null || articulo.cantidad === 0 ||
607 articulo.cantidad === undefined){ 607 articulo.cantidad === undefined) {
608 focaModalService.alert('El valor debe ser al menos 1'); 608 focaModalService.alert('El valor debe ser al menos 1');
609 return; 609 return;
610 } 610 }
611 articulo.editCantidad = false; 611 articulo.editCantidad = false;
612 articulo.editPrecio = false; 612 articulo.editPrecio = false;
613 } 613 }
614 }; 614 };
615 615
616 $scope.cambioEdit = function(articulo, propiedad) { 616 $scope.cambioEdit = function(articulo, propiedad) {
617 if(propiedad === 'cantidad') { 617 if(propiedad === 'cantidad') {
618 articulo.editCantidad = true; 618 articulo.editCantidad = true;
619 } else if(propiedad === 'precio') { 619 } else if(propiedad === 'precio') {
620 articulo.editPrecio = true; 620 articulo.editPrecio = true;
621 } 621 }
622 }; 622 };
623 623
624 $scope.limpiarFlete = function() { 624 $scope.limpiarFlete = function() {
625 $scope.remito.fleteNombre = ''; 625 $scope.remito.fleteNombre = '';
626 $scope.remito.chofer = ''; 626 $scope.remito.chofer = '';
627 $scope.remito.vehiculo = ''; 627 $scope.remito.vehiculo = '';
628 $scope.remito.kilometros = ''; 628 $scope.remito.kilometros = '';
629 $scope.remito.costoUnitarioKmFlete = ''; 629 $scope.remito.costoUnitarioKmFlete = '';
630 $scope.choferes = ''; 630 $scope.choferes = '';
631 $scope.vehiculos = ''; 631 $scope.vehiculos = '';
632 }; 632 };
633 633
634 $scope.limpiarPantalla = function() { 634 $scope.limpiarPantalla = function() {
635 $scope.limpiarFlete(); 635 $scope.limpiarFlete();
636 $scope.remito.flete = '0'; 636 $scope.remito.flete = '0';
637 $scope.remito.bomba = '0'; 637 $scope.remito.bomba = '0';
638 $scope.remito.precioCondicion = ''; 638 $scope.remito.precioCondicion = '';
639 $scope.articulosTabla = []; 639 $scope.articulosTabla = [];
640 $scope.remito.vendedor.nombre = ''; 640 $scope.remito.vendedor.nombre = '';
641 $scope.remito.cliente = {nombre: ''}; 641 $scope.remito.cliente = {nombre: ''};
642 $scope.remito.domicilio = {dom: ''}; 642 $scope.remito.domicilio = {dom: ''};
643 $scope.domiciliosCliente = []; 643 $scope.domiciliosCliente = [];
644 }; 644 };
645 645
646 $scope.resetFilter = function() { 646 $scope.resetFilter = function() {
647 $scope.articuloACargar = {}; 647 $scope.articuloACargar = {};
648 $scope.cargando = true; 648 $scope.cargando = true;
649 }; 649 };
650 650
651 $scope.selectFocus = function($event) { 651 $scope.selectFocus = function($event) {
652 $event.target.select(); 652 $event.target.select();
653 }; 653 };
654 654
655 $scope.salir = function() { 655 $scope.salir = function() {
656 $location.path('/'); 656 $location.path('/');
657 }; 657 };
658 658
659 function addCabecera(label, valor) { 659 function addCabecera(label, valor) {
660 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 660 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
661 if(propiedad.length === 1) { 661 if(propiedad.length === 1) {
662 propiedad[0].valor = valor; 662 propiedad[0].valor = valor;
663 } else { 663 } else {
664 $scope.cabecera.push({label: label, valor: valor}); 664 $scope.cabecera.push({label: label, valor: valor});
665 } 665 }
666 } 666 }
667 667
668 function removeCabecera(label) { 668 function removeCabecera(label) {
669 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 669 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
670 if(propiedad.length === 1){ 670 if(propiedad.length === 1) {
671 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 671 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
672 } 672 }
673 } 673 }
674 674
675 function rellenar(relleno, longitud) { 675 function rellenar(relleno, longitud) {
676 relleno = '' + relleno; 676 relleno = '' + relleno;
677 while (relleno.length < longitud) { 677 while (relleno.length < longitud) {
678 relleno = '0' + relleno; 678 relleno = '0' + relleno;
679 } 679 }
680 680
681 return relleno; 681 return relleno;
682 } 682 }
683 } 683 }
684 ] 684 ]
685 ) 685 )
686 .controller('remitoListaCtrl', [ 686 .controller('remitoListaCtrl', [
687 '$scope', 687 '$scope',
688 'crearRemitoService', 688 'crearRemitoService',
689 '$location', 689 '$location',
690 function($scope, crearRemitoService, $location) { 690 function($scope, crearRemitoService, $location) {
691 crearRemitoService.obtenerRemito().then(function(datos) { 691 crearRemitoService.obtenerRemito().then(function(datos) {
692 $scope.remitos = datos.data; 692 $scope.remitos = datos.data;
693 }); 693 });
694 $scope.editar = function(remito) { 694 $scope.editar = function(remito) {
695 crearRemitoService.setRemito(remito); 695 crearRemitoService.setRemito(remito);
696 $location.path('/venta-nota-remito/abm/'); 696 $location.path('/venta-nota-remito/abm/');
697 }; 697 };
698 $scope.crearRemito = function() { 698 $scope.crearRemito = function() {
699 crearRemitoService.clearRemito(); 699 crearRemitoService.clearRemito();
700 $location.path('/venta-nota-remito/abm/'); 700 $location.path('/venta-nota-remito/abm/');
701 }; 701 };
702 } 702 }
703 ]) 703 ])
704 .controller('focaCrearRemitoFichaClienteController', [ 704 .controller('focaCrearRemitoFichaClienteController', [
705 '$scope', 705 '$scope',
706 'crearRemitoService', 706 'crearRemitoService',
707 '$location', 707 '$location',
708 function($scope, crearRemitoService, $location) { 708 function($scope, crearRemitoService, $location) {
709 crearRemitoService.obtenerRemito().then(function(datos) { 709 crearRemitoService.obtenerRemito().then(function(datos) {
710 $scope.remitos = datos.data; 710 $scope.remitos = datos.data;
711 }); 711 });
712 $scope.editar = function(remito) { 712 $scope.editar = function(remito) {
713 crearRemitoService.setRemito(remito); 713 crearRemitoService.setRemito(remito);
714 $location.path('/venta-nota-remito/abm/'); 714 $location.path('/venta-nota-remito/abm/');
715 }; 715 };
716 $scope.crearRemito = function() { 716 $scope.crearRemito = function() {
717 crearRemitoService.clearRemito(); 717 crearRemitoService.clearRemito();
718 $location.path('/venta-nota-remito/abm/'); 718 $location.path('/venta-nota-remito/abm/');
719 }; 719 };
720 } 720 }
721 ]); 721 ]);
722 722