Commit a0c7dfb720e8febc35003f8888a25205332a510c

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

conflicts

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