Commit 8b76f7d0e80a79131f7e8920529fa90c60c5cb26

Authored by Marcelo Puebla
Exists in master

Merge branch 'develop' of git.focasoftware.com:npm/foca-crear-remito

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