Commit 732f4a1b168552160fe6fcb88ad8f8f8073f957a

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Obtener sucursal y numero de pedido

See merge request modulos-npm/foca-crear-nota-pedido!53
1 { 1 {
2 "name": "foca-crear-nota-pedido", 2 "name": "foca-crear-nota-pedido",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "description": "Listado y ABM nota de pedidos", 4 "description": "Listado y ABM nota de pedidos",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {
7 "test": "echo \"Error: no test specified\" && exit 1", 7 "test": "echo \"Error: no test specified\" && exit 1",
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 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+https://debo.suite.repo/modulos-npm/foca-directivas.git git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git git+https://debo.suite.repo/modulos-npm/foca-modal-flete git+https://debo.suite.repo/modulos-npm/foca-modal.git git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git git+https://debo.suite.repo/modulos-npm/foca-seguimiento.git git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git git+https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git" 11 "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route 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+https://debo.suite.repo/modulos-npm/foca-directivas.git git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git git+https://debo.suite.repo/modulos-npm/foca-modal-flete git+https://debo.suite.repo/modulos-npm/foca-modal.git git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git git+https://debo.suite.repo/modulos-npm/foca-seguimiento.git git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git git+https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.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-nota-pedido.git" 18 "url": "https://debo.suite.repo/modulos-npm/foca-crear-nota-pedido.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+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git", 23 "foca-busqueda-cliente": "git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git",
24 "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git", 24 "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git",
25 "foca-modal": "git+https://debo.suite.repo/modulos-npm/foca-modal.git",
25 "foca-modal-busqueda-productos": "git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos", 26 "foca-modal-busqueda-productos": "git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos",
27 "foca-modal-cotizacion": "git+https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git",
28 "foca-modal-domicilio": "git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git",
29 "foca-modal-flete": "git+https://debo.suite.repo/modulos-npm/foca-modal-flete",
30 "foca-modal-moneda": "git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git",
31 "foca-modal-precio-condiciones": "git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git",
26 "foca-modal-proveedor": "git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git", 32 "foca-modal-proveedor": "git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git",
27 "foca-modal-vendedores": "git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git", 33 "foca-modal-vendedores": "git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git",
28 "foca-seguimiento": "git+https://debo.suite.repo/modulos-npm/foca-seguimiento.git" 34 "foca-seguimiento": "git+https://debo.suite.repo/modulos-npm/foca-seguimiento.git"
29 }, 35 },
30 "devDependencies": { 36 "devDependencies": {
31 "angular": "^1.7.5", 37 "angular": "^1.7.5",
32 "angular-ladda": "^0.4.3", 38 "angular-ladda": "^0.4.3",
33 "angular-route": "^1.7.5", 39 "angular-route": "^1.7.5",
34 "bootstrap": "^4.1.3", 40 "bootstrap": "^4.1.3",
35 "foca-busqueda-cliente": "git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git", 41 "foca-busqueda-cliente": "git+https://debo.suite.repo/modulos-npm/foca-busqueda-cliente.git",
36 "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git", 42 "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git",
37 "foca-modal": "git+https://debo.suite.repo/modulos-npm/foca-modal.git", 43 "foca-modal": "git+https://debo.suite.repo/modulos-npm/foca-modal.git",
38 "foca-modal-busqueda-productos": "git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos", 44 "foca-modal-busqueda-productos": "git+https://debo.suite.repo/modulos-npm/foca-modal-busqueda-productos",
39 "foca-modal-cotizacion": "git+https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git", 45 "foca-modal-cotizacion": "git+https://debo.suite.repo/modulos-npm/foca-modal-cotizacion.git",
40 "foca-modal-domicilio": "git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git", 46 "foca-modal-domicilio": "git+https://debo.suite.repo/modulos-npm/foca-modal-domicilio.git",
41 "foca-modal-flete": "git+https://debo.suite.repo/modulos-npm/foca-modal-flete", 47 "foca-modal-flete": "git+https://debo.suite.repo/modulos-npm/foca-modal-flete",
42 "foca-modal-moneda": "git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git", 48 "foca-modal-moneda": "git+https://debo.suite.repo/modulos-npm/foca-modal-moneda.git",
43 "foca-modal-precio-condiciones": "git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git", 49 "foca-modal-precio-condiciones": "git+https://debo.suite.repo/modulos-npm/foca-modal-precio-condiciones.git",
44 "foca-modal-proveedor": "git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git", 50 "foca-modal-proveedor": "git+https://debo.suite.repo/modulos-npm/foca-modal-proveedor.git",
45 "foca-modal-vendedores": "git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git", 51 "foca-modal-vendedores": "git+https://debo.suite.repo/modulos-npm/foca-modal-vendedores.git",
46 "foca-seguimiento": "git+https://debo.suite.repo/modulos-npm/foca-seguimiento.git", 52 "foca-seguimiento": "git+https://debo.suite.repo/modulos-npm/foca-seguimiento.git",
47 "font-awesome": "^4.7.0", 53 "font-awesome": "^4.7.0",
48 "gulp": "^3.9.1", 54 "gulp": "^3.9.1",
49 "gulp-angular-templatecache": "^2.2.2", 55 "gulp-angular-templatecache": "^2.2.3",
50 "gulp-clean": "^0.4.0", 56 "gulp-clean": "^0.4.0",
51 "gulp-concat": "^2.6.1", 57 "gulp-concat": "^2.6.1",
52 "gulp-connect": "^5.6.1", 58 "gulp-connect": "^5.6.1",
53 "gulp-htmlmin": "^5.0.1", 59 "gulp-htmlmin": "^5.0.1",
54 "gulp-jshint": "^2.1.0", 60 "gulp-jshint": "^2.1.0",
55 "gulp-rename": "^1.4.0", 61 "gulp-rename": "^1.4.0",
56 "gulp-replace": "^1.0.0", 62 "gulp-replace": "^1.0.0",
57 "gulp-sequence": "^1.0.0", 63 "gulp-sequence": "^1.0.0",
58 "gulp-uglify": "^3.0.1", 64 "gulp-uglify": "^3.0.1",
59 "gulp-uglify-es": "^1.0.4", 65 "gulp-uglify-es": "^1.0.4",
60 "jasmine-core": "^3.3.0", 66 "jasmine-core": "^3.3.0",
61 "jquery": "^3.3.1", 67 "jquery": "^3.3.1",
62 "jshint": "^2.9.6", 68 "jshint": "^2.9.6",
63 "ladda": "1.0.6", 69 "ladda": "1.0.6",
64 "pre-commit": "^1.2.2", 70 "pre-commit": "^1.2.2",
65 "pump": "^3.0.0", 71 "pump": "^3.0.0",
66 "ui-bootstrap4": "^3.0.5" 72 "ui-bootstrap4": "^3.0.5"
67 } 73 }
68 } 74 }
69 75
src/js/controller.js
1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', 1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', 3 '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService',
4 'focaModalService', 'focaSeguimientoService', 'notaPedidoBusinessService', 4 'focaModalService', 'focaSeguimientoService', 'notaPedidoBusinessService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, 6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService,
7 focaSeguimientoService, notaPedidoBusinessService 7 focaSeguimientoService, notaPedidoBusinessService
8 ) { 8 ) {
9 $scope.botonera = [ 9 $scope.botonera = [
10 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 10 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
11 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 11 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
12 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 12 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
13 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 13 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
14 { 14 {
15 texto: 'Precios y condiciones', 15 texto: 'Precios y condiciones',
16 accion: function() {$scope.abrirModalListaPrecio();}}, 16 accion: function() {$scope.abrirModalListaPrecio();}},
17 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 17 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
18 {texto: '', accion: function() {}}, 18 {texto: '', accion: function() {}},
19 {texto: '', accion: function() {}} 19 {texto: '', accion: function() {}}
20 ]; 20 ];
21 $scope.datepickerAbierto = false; 21 $scope.datepickerAbierto = false;
22 22
23 $scope.show = false; 23 $scope.show = false;
24 $scope.cargando = true; 24 $scope.cargando = true;
25 $scope.dateOptions = { 25 $scope.dateOptions = {
26 maxDate: new Date(), 26 maxDate: new Date(),
27 minDate: new Date(2010, 0, 1) 27 minDate: new Date(2010, 0, 1)
28 }; 28 };
29 29
30 $scope.notaPedido = { 30 $scope.notaPedido = {
31 vendedor: {}, 31 vendedor: {},
32 cliente: {}, 32 cliente: {},
33 proveedor: {}, 33 proveedor: {},
34 domicilio: {dom: ''}, 34 domicilio: {dom: ''},
35 moneda: {}, 35 moneda: {},
36 cotizacion: {} 36 cotizacion: {}
37 }; 37 };
38 var monedaPorDefecto; 38 var monedaPorDefecto;
39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
40 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { 40 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
41 monedaPorDefecto = { 41 monedaPorDefecto = {
42 id: res.data[0].ID, 42 id: res.data[0].ID,
43 detalle: res.data[0].DETALLE, 43 detalle: res.data[0].DETALLE,
44 simbolo: res.data[0].SIMBOLO, 44 simbolo: res.data[0].SIMBOLO,
45 cotizaciones: res.data[0].cotizaciones 45 cotizaciones: res.data[0].cotizaciones
46 }; 46 };
47 addCabecera('Moneda:', monedaPorDefecto.detalle); 47 addCabecera('Moneda:', monedaPorDefecto.detalle);
48 addCabecera('Fecha cotizacion:', 48 addCabecera('Fecha cotizacion:',
49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); 49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString());
50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); 50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION);
51 $scope.notaPedido.moneda = monedaPorDefecto; 51 $scope.notaPedido.moneda = monedaPorDefecto;
52 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; 52 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0];
53 }); 53 });
54 54
55 $scope.cabecera = []; 55 $scope.cabecera = [];
56 $scope.showCabecera = true; 56 $scope.showCabecera = true;
57 57
58 $scope.now = new Date(); 58 $scope.now = new Date();
59 $scope.puntoVenta = Math.round(Math.random() * 10000); 59 $scope.puntoVenta = '0000';
60 $scope.comprobante = Math.round(Math.random() * 1000000); 60 $scope.comprobante = '00000000';
61
62 $scope.articulosTabla = []; 61 $scope.articulosTabla = [];
63 $scope.idLista = undefined; 62 $scope.idLista = undefined;
64 //La pantalla solo se usa para cargar pedidos 63 //La pantalla solo se usa para cargar pedidos
65 //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 64 //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
66 65
67 crearNotaPedidoService.getPrecioCondicion().then( 66 crearNotaPedidoService.getPrecioCondicion().then(
68 function(res) { 67 function(res) {
69 $scope.precioCondiciones = res.data; 68 $scope.precioCondiciones = res.data;
70 } 69 }
71 ); 70 );
71
72 crearNotaPedidoService.getNumeroNotaPedido().then(
73 function(res) {
74 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
75 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
76 },
77 function(err) {
78 focaModalService.alert('La terminal no esta configurada correctamente');
79 console.info(err);
80 }
81 );
72 //La pantalla solo se usa para cargar pedidos 82 //La pantalla solo se usa para cargar pedidos
73 // if (notaPedidoTemp !== undefined) { 83 // if (notaPedidoTemp !== undefined) {
74 // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 84 // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
75 // $scope.notaPedido = notaPedidoTemp; 85 // $scope.notaPedido = notaPedidoTemp;
76 // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 86 // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
77 // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 87 // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
78 // $scope.idLista = $scope.notaPedido.precioCondicion; 88 // $scope.idLista = $scope.notaPedido.precioCondicion;
79 // crearNotaPedidoService 89 // crearNotaPedidoService
80 // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( 90 // .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
81 // function(res) { 91 // function(res) {
82 // $scope.articulosTabla = res.data; 92 // $scope.articulosTabla = res.data;
83 // } 93 // }
84 // ); 94 // );
85 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO 95 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
86 //(NO REQUERIDO EN ESTA VERSION) 96 //(NO REQUERIDO EN ESTA VERSION)
87 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( 97 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
88 // function(res) { 98 // function(res) {
89 // $scope.notaPedido.domicilio = res.data; 99 // $scope.notaPedido.domicilio = res.data;
90 // } 100 // }
91 // ); 101 // );
92 // } else { 102 // } else {
93 // $scope.notaPedido.fechaCarga = new Date(); 103 // $scope.notaPedido.fechaCarga = new Date();
94 // $scope.notaPedido.bomba = '0'; 104 // $scope.notaPedido.bomba = '0';
95 // $scope.notaPedido.flete = '0'; 105 // $scope.notaPedido.flete = '0';
96 // $scope.idLista = undefined; 106 // $scope.idLista = undefined;
97 // } 107 // }
98 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 108 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
99 // $scope.addNewDom = function() { 109 // $scope.addNewDom = function() {
100 // $scope.notaPedido.domicilio.push({ 'id': 0 }); 110 // $scope.notaPedido.domicilio.push({ 'id': 0 });
101 // }; 111 // };
102 // $scope.removeNewChoice = function(choice) { 112 // $scope.removeNewChoice = function(choice) {
103 // if ($scope.notaPedido.domicilio.length > 1) { 113 // if ($scope.notaPedido.domicilio.length > 1) {
104 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( 114 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(
105 // function(c) { 115 // function(c) {
106 // return c.$$hashKey === choice.$$hashKey; 116 // return c.$$hashKey === choice.$$hashKey;
107 // } 117 // }
108 // ), 1); 118 // ), 1);
109 // } 119 // }
110 // }; 120 // };
111 121
112 $scope.crearNotaPedido = function() { 122 $scope.crearNotaPedido = function() {
113 if(!$scope.notaPedido.vendedor.codigo) { 123 if(!$scope.notaPedido.vendedor.codigo) {
114 focaModalService.alert('Ingrese Vendedor'); 124 focaModalService.alert('Ingrese Vendedor');
115 return; 125 return;
116 } else if(!$scope.notaPedido.cliente.cod) { 126 } else if(!$scope.notaPedido.cliente.cod) {
117 focaModalService.alert('Ingrese Cliente'); 127 focaModalService.alert('Ingrese Cliente');
118 return; 128 return;
119 } else if(!$scope.notaPedido.proveedor.codigo) { 129 } else if(!$scope.notaPedido.proveedor.codigo) {
120 focaModalService.alert('Ingrese Proveedor'); 130 focaModalService.alert('Ingrese Proveedor');
121 return; 131 return;
122 } else if(!$scope.notaPedido.moneda.id) { 132 } else if(!$scope.notaPedido.moneda.id) {
123 focaModalService.alert('Ingrese Moneda'); 133 focaModalService.alert('Ingrese Moneda');
124 return; 134 return;
125 } else if(!$scope.notaPedido.cotizacion.ID) { 135 } else if(!$scope.notaPedido.cotizacion.ID) {
126 focaModalService.alert('Ingrese Cotización'); 136 focaModalService.alert('Ingrese Cotización');
127 return; 137 return;
128 } else if(!$scope.plazosPagos) { 138 } else if(!$scope.plazosPagos) {
129 focaModalService.alert('Ingrese Precios y Condiciones'); 139 focaModalService.alert('Ingrese Precios y Condiciones');
130 return; 140 return;
131 } else if( 141 } else if(
132 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) 142 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null)
133 { 143 {
134 focaModalService.alert('Ingrese Flete'); 144 focaModalService.alert('Ingrese Flete');
135 return; 145 return;
136 } else if(!$scope.notaPedido.domicilio.id) { 146 } else if(!$scope.notaPedido.domicilio.id) {
137 focaModalService.aler('Ingrese Domicilio'); 147 focaModalService.aler('Ingrese Domicilio');
138 return; 148 return;
139 } else if($scope.articulosTabla.length === 0) { 149 } else if($scope.articulosTabla.length === 0) {
140 focaModalService.alert('Debe cargar al menos un articulo'); 150 focaModalService.alert('Debe cargar al menos un articulo');
141 return; 151 return;
142 } 152 }
143 var date = new Date(); 153 var date = new Date();
144 var notaPedido = { 154 var notaPedido = {
145 id: 0, 155 id: 0,
146 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 156 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
147 .toISOString().slice(0, 19).replace('T', ' '), 157 .toISOString().slice(0, 19).replace('T', ' '),
148 idVendedor: $scope.notaPedido.vendedor.codigo, 158 idVendedor: $scope.notaPedido.vendedor.codigo,
149 idCliente: $scope.notaPedido.cliente.cod, 159 idCliente: $scope.notaPedido.cliente.cod,
150 nombreCliente: $scope.notaPedido.cliente.nom, 160 nombreCliente: $scope.notaPedido.cliente.nom,
151 cuitCliente: $scope.notaPedido.cliente.cuit, 161 cuitCliente: $scope.notaPedido.cliente.cuit,
152 idProveedor: $scope.notaPedido.proveedor.codigo, 162 idProveedor: $scope.notaPedido.proveedor.codigo,
153 idDomicilio: $scope.notaPedido.domicilio.id, 163 idDomicilio: $scope.notaPedido.domicilio.id,
154 idCotizacion: $scope.notaPedido.cotizacion.ID, 164 idCotizacion: $scope.notaPedido.cotizacion.ID,
155 cotizacion: $scope.notaPedido.cotizacion.COTIZACION, 165 cotizacion: $scope.notaPedido.cotizacion.COTIZACION,
156 flete: $scope.notaPedido.flete, 166 flete: $scope.notaPedido.flete,
157 fob: $scope.notaPedido.fob, 167 fob: $scope.notaPedido.fob,
158 bomba: $scope.notaPedido.bomba, 168 bomba: $scope.notaPedido.bomba,
159 kilometros: $scope.notaPedido.kilometros, 169 kilometros: $scope.notaPedido.kilometros,
160 estado: 0, 170 estado: 0,
161 total: $scope.getTotal() 171 total: $scope.getTotal()
162 }; 172 };
163 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 173 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
164 function(data) { 174 function(data) {
165 notaPedidoBusinessService.addArticulos($scope.articulosTabla, 175 notaPedidoBusinessService.addArticulos($scope.articulosTabla,
166 data.data.id, $scope.notaPedido.cotizacion.COTIZACION); 176 data.data.id, $scope.notaPedido.cotizacion.COTIZACION);
167 focaSeguimientoService.guardarPosicion('crear nota pedido', ''); 177 focaSeguimientoService.guardarPosicion('crear nota pedido', '');
168 var plazos = $scope.plazosPagos; 178 var plazos = $scope.plazosPagos;
179
169 for(var j = 0; j < plazos.length; j++) { 180 for(var j = 0; j < plazos.length; j++) {
170 var json = { 181 var json = {
171 idPedido: data.data.id, 182 idPedido: data.data.id,
172 dias: plazos[j].dias 183 dias: plazos[j].dias
173 }; 184 };
174 crearNotaPedidoService.crearPlazosParaNotaPedido(json); 185 crearNotaPedidoService.crearPlazosParaNotaPedido(json);
175 } 186 }
176 notaPedidoBusinessService.addEstado(data.data.id, 187 notaPedidoBusinessService.addEstado(data.data.id,
177 $scope.notaPedido.vendedor.codigo); 188 $scope.notaPedido.vendedor.codigo);
178 189
179 focaModalService.alert('Nota pedido creada'); 190 focaModalService.alert('Nota pedido creada');
180 $scope.cabecera = []; 191 $scope.cabecera = [];
181 addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); 192 addCabecera('Moneda:', $scope.notaPedido.moneda.detalle);
182 addCabecera( 193 addCabecera(
183 'Fecha cotizacion:', 194 'Fecha cotizacion:',
184 $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') 195 $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy')
185 ); 196 );
186 addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.COTIZACION); 197 addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.COTIZACION);
187 $scope.notaPedido.vendedor = {}; 198 $scope.notaPedido.vendedor = {};
188 $scope.notaPedido.cliente = {}; 199 $scope.notaPedido.cliente = {};
189 $scope.notaPedido.proveedor = {}; 200 $scope.notaPedido.proveedor = {};
190 $scope.notaPedido.domicilio = {}; 201 $scope.notaPedido.domicilio = {};
191 $scope.notaPedido.flete = null; 202 $scope.notaPedido.flete = null;
192 $scope.notaPedido.fob = null; 203 $scope.notaPedido.fob = null;
193 $scope.notaPedido.bomba = null; 204 $scope.notaPedido.bomba = null;
194 $scope.notaPedido.kilometros = null; 205 $scope.notaPedido.kilometros = null;
195 $scope.articulosTabla = []; 206 $scope.articulosTabla = [];
207 },
208 function(error) {
209 focaModalService.alert('Hubo un error al crear la nota de pedido');
210 console.info(error);
196 } 211 }
197 ); 212 );
198 }; 213 };
199 214
200 $scope.seleccionarArticulo = function() { 215 $scope.seleccionarArticulo = function() {
201 if ($scope.idLista === undefined) { 216 if ($scope.idLista === undefined) {
202 focaModalService.alert( 217 focaModalService.alert(
203 'Primero seleccione una lista de precio y condicion'); 218 'Primero seleccione una lista de precio y condicion');
204 return; 219 return;
205 } 220 }
206 var modalInstance = $uibModal.open( 221 var modalInstance = $uibModal.open(
207 { 222 {
208 ariaLabelledBy: 'Busqueda de Productos', 223 ariaLabelledBy: 'Busqueda de Productos',
209 templateUrl: 'modal-busqueda-productos.html', 224 templateUrl: 'modal-busqueda-productos.html',
210 controller: 'modalBusquedaProductosCtrl', 225 controller: 'modalBusquedaProductosCtrl',
211 resolve: { 226 resolve: {
212 parametroProducto: { 227 parametroProducto: {
213 idLista: $scope.idLista, 228 idLista: $scope.idLista,
214 cotizacion: $scope.notaPedido.cotizacion.COTIZACION, 229 cotizacion: $scope.notaPedido.cotizacion.COTIZACION,
215 simbolo: $scope.notaPedido.moneda.simbolo 230 simbolo: $scope.notaPedido.moneda.simbolo
216 } 231 }
217 }, 232 },
218 size: 'lg' 233 size: 'lg'
219 } 234 }
220 ); 235 );
221 modalInstance.result.then( 236 modalInstance.result.then(
222 function(producto) { 237 function(producto) {
223 var newArt = 238 var newArt =
224 { 239 {
225 id: 0, 240 id: 0,
226 codigo: producto.codigo, 241 codigo: producto.codigo,
227 sector: producto.sector, 242 sector: producto.sector,
228 sectorCodigo: producto.sector + '-' + producto.codigo, 243 sectorCodigo: producto.sector + '-' + producto.codigo,
229 descripcion: producto.descripcion, 244 descripcion: producto.descripcion,
230 item: $scope.articulosTabla.length + 1, 245 item: $scope.articulosTabla.length + 1,
231 nombre: producto.descripcion, 246 nombre: producto.descripcion,
232 precio: parseFloat(producto.precio.toFixed(4)), 247 precio: parseFloat(producto.precio.toFixed(4)),
233 costoUnitario: producto.costo, 248 costoUnitario: producto.costo,
234 editCantidad: false, 249 editCantidad: false,
235 editPrecio: false 250 editPrecio: false
236 }; 251 };
237 $scope.articuloACargar = newArt; 252 $scope.articuloACargar = newArt;
238 $scope.cargando = false; 253 $scope.cargando = false;
239 }, function() { 254 }, function() {
240 // funcion ejecutada cuando se cancela el modal 255 // funcion ejecutada cuando se cancela el modal
241 } 256 }
242 ); 257 );
243 }; 258 };
244 259
245 $scope.seleccionarVendedor = function() { 260 $scope.seleccionarVendedor = function() {
246 var modalInstance = $uibModal.open( 261 var modalInstance = $uibModal.open(
247 { 262 {
248 ariaLabelledBy: 'Busqueda de Vendedores', 263 ariaLabelledBy: 'Busqueda de Vendedores',
249 templateUrl: 'modal-vendedores.html', 264 templateUrl: 'modal-vendedores.html',
250 controller: 'modalVendedoresCtrl', 265 controller: 'modalVendedoresCtrl',
251 size: 'lg' 266 size: 'lg'
252 } 267 }
253 ); 268 );
254 modalInstance.result.then( 269 modalInstance.result.then(
255 function(vendedor) { 270 function(vendedor) {
256 addCabecera('Vendedor:', vendedor.NomVen); 271 addCabecera('Vendedor:', vendedor.NomVen);
257 $scope.notaPedido.vendedor.codigo = vendedor.CodVen; 272 $scope.notaPedido.vendedor.codigo = vendedor.CodVen;
258 }, function() { 273 }, function() {
259 274
260 } 275 }
261 ); 276 );
262 }; 277 };
263 278
264 $scope.seleccionarProveedor = function() { 279 $scope.seleccionarProveedor = function() {
265 var modalInstance = $uibModal.open( 280 var modalInstance = $uibModal.open(
266 { 281 {
267 ariaLabelledBy: 'Busqueda de Proveedor', 282 ariaLabelledBy: 'Busqueda de Proveedor',
268 templateUrl: 'modal-proveedor.html', 283 templateUrl: 'modal-proveedor.html',
269 controller: 'focaModalProveedorCtrl', 284 controller: 'focaModalProveedorCtrl',
270 size: 'lg' 285 size: 'lg'
271 } 286 }
272 ); 287 );
273 modalInstance.result.then( 288 modalInstance.result.then(
274 function(proveedor) { 289 function(proveedor) {
275 $scope.notaPedido.proveedor.codigo = proveedor.COD; 290 $scope.notaPedido.proveedor.codigo = proveedor.COD;
276 addCabecera('Proveedor:', proveedor.NOM); 291 addCabecera('Proveedor:', proveedor.NOM);
277 }, function() { 292 }, function() {
278 293
279 } 294 }
280 ); 295 );
281 }; 296 };
282 297
283 $scope.seleccionarCliente = function() { 298 $scope.seleccionarCliente = function() {
284 299
285 var modalInstance = $uibModal.open( 300 var modalInstance = $uibModal.open(
286 { 301 {
287 ariaLabelledBy: 'Busqueda de Cliente', 302 ariaLabelledBy: 'Busqueda de Cliente',
288 templateUrl: 'foca-busqueda-cliente-modal.html', 303 templateUrl: 'foca-busqueda-cliente-modal.html',
289 controller: 'focaBusquedaClienteModalController', 304 controller: 'focaBusquedaClienteModalController',
290 size: 'lg' 305 size: 'lg'
291 } 306 }
292 ); 307 );
293 modalInstance.result.then( 308 modalInstance.result.then(
294 function(cliente) { 309 function(cliente) {
295 $scope.abrirModalDomicilios(cliente); 310 $scope.abrirModalDomicilios(cliente);
296 }, function() { 311 }, function() {
297 312
298 } 313 }
299 ); 314 );
300 }; 315 };
301 316
302 $scope.abrirModalDomicilios = function(cliente) { 317 $scope.abrirModalDomicilios = function(cliente) {
303 var modalInstanceDomicilio = $uibModal.open( 318 var modalInstanceDomicilio = $uibModal.open(
304 { 319 {
305 ariaLabelledBy: 'Busqueda de Domicilios', 320 ariaLabelledBy: 'Busqueda de Domicilios',
306 templateUrl: 'modal-domicilio.html', 321 templateUrl: 'modal-domicilio.html',
307 controller: 'focaModalDomicilioController', 322 controller: 'focaModalDomicilioController',
308 resolve: { idCliente: function() { return cliente.cod; }}, 323 resolve: { idCliente: function() { return cliente.cod; }},
309 size: 'lg', 324 size: 'lg',
310 } 325 }
311 ); 326 );
312 modalInstanceDomicilio.result.then( 327 modalInstanceDomicilio.result.then(
313 function(domicilio) { 328 function(domicilio) {
314 $scope.notaPedido.domicilio.id = domicilio.id; 329 $scope.notaPedido.domicilio.id = domicilio.id;
315 $scope.notaPedido.cliente = cliente; 330 $scope.notaPedido.cliente = cliente;
316 331
317 addCabecera('Cliente:', cliente.nom); 332 addCabecera('Cliente:', cliente.nom);
318 addCabecera('Domicilio:', domicilio.dom); 333 addCabecera('Domicilio:', domicilio.dom);
319 }, function() { 334 }, function() {
320 $scope.seleccionarCliente(); 335 $scope.seleccionarCliente();
321 return; 336 return;
322 } 337 }
323 ); 338 );
324 }; 339 };
325 340
326 $scope.mostrarFichaCliente = function() { 341 $scope.mostrarFichaCliente = function() {
327 $uibModal.open( 342 $uibModal.open(
328 { 343 {
329 ariaLabelledBy: 'Datos del Cliente', 344 ariaLabelledBy: 'Datos del Cliente',
330 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', 345 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html',
331 controller: 'focaCrearNotaPedidoFichaClienteController', 346 controller: 'focaCrearNotaPedidoFichaClienteController',
332 size: 'lg' 347 size: 'lg'
333 } 348 }
334 ); 349 );
335 }; 350 };
336 351
337 $scope.getTotal = function() { 352 $scope.getTotal = function() {
338 var total = 0; 353 var total = 0;
339 var arrayTempArticulos = $scope.articulosTabla; 354 var arrayTempArticulos = $scope.articulosTabla;
340 for (var i = 0; i < arrayTempArticulos.length; i++) { 355 for (var i = 0; i < arrayTempArticulos.length; i++) {
341 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 356 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
342 } 357 }
343 return parseFloat(total.toFixed(2)); 358 return parseFloat(total.toFixed(2));
344 }; 359 };
345 360
346 $scope.getSubTotal = function() { 361 $scope.getSubTotal = function() {
347 if($scope.articuloACargar) { 362 if($scope.articuloACargar) {
348 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 363 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
349 } 364 }
350 }; 365 };
351 366
352 $scope.abrirModalListaPrecio = function() { 367 $scope.abrirModalListaPrecio = function() {
353 var modalInstance = $uibModal.open( 368 var modalInstance = $uibModal.open(
354 { 369 {
355 ariaLabelledBy: 'Busqueda de Precio Condición', 370 ariaLabelledBy: 'Busqueda de Precio Condición',
356 templateUrl: 'modal-precio-condicion.html', 371 templateUrl: 'modal-precio-condicion.html',
357 controller: 'focaModalPrecioCondicionController', 372 controller: 'focaModalPrecioCondicionController',
358 size: 'lg' 373 size: 'lg'
359 } 374 }
360 ); 375 );
361 modalInstance.result.then( 376 modalInstance.result.then(
362 function(precioCondicion) { 377 function(precioCondicion) {
363 var cabecera = ''; 378 var cabecera = '';
364 var plazosConcat = ''; 379 var plazosConcat = '';
365 if(!Array.isArray(precioCondicion)) { 380 if(!Array.isArray(precioCondicion)) {
366 $scope.plazosPagos = precioCondicion.plazoPago; 381 $scope.plazosPagos = precioCondicion.plazoPago;
367 $scope.idLista = precioCondicion.idListaPrecio; 382 $scope.idLista = precioCondicion.idListaPrecio;
368 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 383 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
369 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 384 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
370 } 385 }
371 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 386 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
372 } else { //Cuando se ingresan los plazos manualmente 387 } else { //Cuando se ingresan los plazos manualmente
373 $scope.idLista = -1; //-1, el modal productos busca todos los productos 388 $scope.idLista = -1; //-1, el modal productos busca todos los productos
374 $scope.plazosPagos = precioCondicion; 389 $scope.plazosPagos = precioCondicion;
375 for(var j = 0; j < precioCondicion.length; j++) { 390 for(var j = 0; j < precioCondicion.length; j++) {
376 plazosConcat += precioCondicion[j].dias + ' '; 391 plazosConcat += precioCondicion[j].dias + ' ';
377 } 392 }
378 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 393 cabecera = 'Ingreso manual ' + plazosConcat.trim();
379 } 394 }
380 $scope.articulosTabla = []; 395 $scope.articulosTabla = [];
381 addCabecera('Precios y condiciones:', cabecera); 396 addCabecera('Precios y condiciones:', cabecera);
382 }, function() { 397 }, function() {
383 398
384 } 399 }
385 ); 400 );
386 }; 401 };
387 402
388 $scope.abrirModalFlete = function() { 403 $scope.abrirModalFlete = function() {
389 var modalInstance = $uibModal.open( 404 var modalInstance = $uibModal.open(
390 { 405 {
391 ariaLabelledBy: 'Busqueda de Flete', 406 ariaLabelledBy: 'Busqueda de Flete',
392 templateUrl: 'modal-flete.html', 407 templateUrl: 'modal-flete.html',
393 controller: 'focaModalFleteController', 408 controller: 'focaModalFleteController',
394 size: 'lg', 409 size: 'lg',
395 resolve: { 410 resolve: {
396 parametrosFlete: 411 parametrosFlete:
397 function() { 412 function() {
398 return { 413 return {
399 flete: $scope.notaPedido.flete ? '1' : 414 flete: $scope.notaPedido.flete ? '1' :
400 ($scope.notaPedido.fob ? 'FOB' : 415 ($scope.notaPedido.fob ? 'FOB' :
401 ($scope.notaPedido.flete === undefined ? null : '0')), 416 ($scope.notaPedido.flete === undefined ? null : '0')),
402 bomba: $scope.notaPedido.bomba ? '1' : 417 bomba: $scope.notaPedido.bomba ? '1' :
403 ($scope.notaPedido.bomba === undefined ? null : '0'), 418 ($scope.notaPedido.bomba === undefined ? null : '0'),
404 kilometros: $scope.notaPedido.kilometros 419 kilometros: $scope.notaPedido.kilometros
405 }; 420 };
406 } 421 }
407 } 422 }
408 } 423 }
409 ); 424 );
410 modalInstance.result.then( 425 modalInstance.result.then(
411 function(datos) { 426 function(datos) {
412 $scope.notaPedido.flete = datos.flete; 427 $scope.notaPedido.flete = datos.flete;
413 $scope.notaPedido.fob = datos.FOB; 428 $scope.notaPedido.fob = datos.FOB;
414 $scope.notaPedido.bomba = datos.bomba; 429 $scope.notaPedido.bomba = datos.bomba;
415 $scope.notaPedido.kilometros = datos.kilometros; 430 $scope.notaPedido.kilometros = datos.kilometros;
416 431
417 addCabecera('Flete:', datos.flete ? 'Si' : 432 addCabecera('Flete:', datos.flete ? 'Si' :
418 ($scope.notaPedido.fob ? 'FOB' : 'No')); 433 ($scope.notaPedido.fob ? 'FOB' : 'No'));
419 if(datos.flete) { 434 if(datos.flete) {
420 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 435 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
421 addCabecera('Kilometros:', datos.kilometros); 436 addCabecera('Kilometros:', datos.kilometros);
422 } else { 437 } else {
423 removeCabecera('Bomba:'); 438 removeCabecera('Bomba:');
424 removeCabecera('Kilometros:'); 439 removeCabecera('Kilometros:');
425 $scope.notaPedido.fob = false; 440 $scope.notaPedido.fob = false;
426 $scope.notaPedido.bomba = false; 441 $scope.notaPedido.bomba = false;
427 $scope.notaPedido.kilometros = null; 442 $scope.notaPedido.kilometros = null;
428 } 443 }
429 }, function() { 444 }, function() {
430 445
431 } 446 }
432 ); 447 );
433 }; 448 };
434 449
435 $scope.abrirModalMoneda = function() { 450 $scope.abrirModalMoneda = function() {
436 var modalInstance = $uibModal.open( 451 var modalInstance = $uibModal.open(
437 { 452 {
438 ariaLabelledBy: 'Busqueda de Moneda', 453 ariaLabelledBy: 'Busqueda de Moneda',
439 templateUrl: 'modal-moneda.html', 454 templateUrl: 'modal-moneda.html',
440 controller: 'focaModalMonedaController', 455 controller: 'focaModalMonedaController',
441 size: 'lg' 456 size: 'lg'
442 } 457 }
443 ); 458 );
444 modalInstance.result.then( 459 modalInstance.result.then(
445 function(moneda) { 460 function(moneda) {
446 $scope.abrirModalCotizacion(moneda); 461 $scope.abrirModalCotizacion(moneda);
447 }, function() { 462 }, function() {
448 463
449 } 464 }
450 ); 465 );
451 }; 466 };
452 467
453 $scope.abrirModalCotizacion = function(moneda) { 468 $scope.abrirModalCotizacion = function(moneda) {
454 var modalInstance = $uibModal.open( 469 var modalInstance = $uibModal.open(
455 { 470 {
456 ariaLabelledBy: 'Busqueda de Cotización', 471 ariaLabelledBy: 'Busqueda de Cotización',
457 templateUrl: 'modal-cotizacion.html', 472 templateUrl: 'modal-cotizacion.html',
458 controller: 'focaModalCotizacionController', 473 controller: 'focaModalCotizacionController',
459 size: 'lg', 474 size: 'lg',
460 resolve: {idMoneda: function() {return moneda.ID;}} 475 resolve: {idMoneda: function() {return moneda.ID;}}
461 } 476 }
462 ); 477 );
463 modalInstance.result.then( 478 modalInstance.result.then(
464 function(cotizacion) { 479 function(cotizacion) {
465 var articulosTablaTemp = $scope.articulosTabla; 480 var articulosTablaTemp = $scope.articulosTabla;
466 for(var i = 0; i < articulosTablaTemp.length; i++) { 481 for(var i = 0; i < articulosTablaTemp.length; i++) {
467 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 482 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
468 $scope.notaPedido.cotizacion.COTIZACION; 483 $scope.notaPedido.cotizacion.COTIZACION;
469 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 484 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
470 cotizacion.COTIZACION; 485 cotizacion.COTIZACION;
471 } 486 }
472 $scope.articulosTabla = articulosTablaTemp; 487 $scope.articulosTabla = articulosTablaTemp;
473 $scope.notaPedido.moneda = { 488 $scope.notaPedido.moneda = {
474 id: moneda.ID, 489 id: moneda.ID,
475 detalle: moneda.DETALLE, 490 detalle: moneda.DETALLE,
476 simbolo: moneda.SIMBOLO 491 simbolo: moneda.SIMBOLO
477 }; 492 };
478 $scope.notaPedido.cotizacion = { 493 $scope.notaPedido.cotizacion = {
479 ID: cotizacion.ID, 494 ID: cotizacion.ID,
480 COTIZACION: cotizacion.COTIZACION, 495 COTIZACION: cotizacion.COTIZACION,
481 FECHA: cotizacion.FECHA 496 FECHA: cotizacion.FECHA
482 }; 497 };
483 addCabecera('Moneda:', moneda.DETALLE); 498 addCabecera('Moneda:', moneda.DETALLE);
484 addCabecera( 499 addCabecera(
485 'Fecha cotizacion:', 500 'Fecha cotizacion:',
486 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 501 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
487 ); 502 );
488 addCabecera('Cotizacion:', cotizacion.COTIZACION); 503 addCabecera('Cotizacion:', cotizacion.COTIZACION);
489 }, function() { 504 }, function() {
490 505
491 } 506 }
492 ); 507 );
493 }; 508 };
494 509
495 $scope.agregarATabla = function(key) { 510 $scope.agregarATabla = function(key) {
496 if(key === 13) { 511 if(key === 13) {
497 if($scope.articuloACargar.cantidad === undefined || 512 if($scope.articuloACargar.cantidad === undefined ||
498 $scope.articuloACargar.cantidad === 0 || 513 $scope.articuloACargar.cantidad === 0 ||
499 $scope.articuloACargar.cantidad === null ){ 514 $scope.articuloACargar.cantidad === null ){
500 focaModalService.alert('El valor debe ser al menos 1'); 515 focaModalService.alert('El valor debe ser al menos 1');
501 return; 516 return;
502 } 517 }
503 delete $scope.articuloACargar.sectorCodigo; 518 delete $scope.articuloACargar.sectorCodigo;
504 $scope.articulosTabla.push($scope.articuloACargar); 519 $scope.articulosTabla.push($scope.articuloACargar);
505 $scope.cargando = true; 520 $scope.cargando = true;
506 } 521 }
507 }; 522 };
508 523
509 $scope.quitarArticulo = function(key) { 524 $scope.quitarArticulo = function(key) {
510 $scope.articulosTabla.splice(key, 1); 525 $scope.articulosTabla.splice(key, 1);
511 }; 526 };
512 527
513 $scope.editarArticulo = function(key, articulo) { 528 $scope.editarArticulo = function(key, articulo) {
514 if(key === 13) { 529 if(key === 13) {
515 if(articulo.cantidad === null || articulo.cantidad === 0 || 530 if(articulo.cantidad === null || articulo.cantidad === 0 ||
516 articulo.cantidad === undefined){ 531 articulo.cantidad === undefined){
517 focaModalService.alert('El valor debe ser al menos 1'); 532 focaModalService.alert('El valor debe ser al menos 1');
518 return; 533 return;
519 } 534 }
520 articulo.editCantidad = false; 535 articulo.editCantidad = false;
521 articulo.editPrecio = false; 536 articulo.editPrecio = false;
522 } 537 }
523 }; 538 };
524 539
525 $scope.cambioEdit = function(articulo, propiedad) { 540 $scope.cambioEdit = function(articulo, propiedad) {
526 if(propiedad === 'cantidad') { 541 if(propiedad === 'cantidad') {
527 articulo.editCantidad = true; 542 articulo.editCantidad = true;
528 } else if(propiedad === 'precio') { 543 } else if(propiedad === 'precio') {
529 articulo.editPrecio = true; 544 articulo.editPrecio = true;
530 } 545 }
531 }; 546 };
532 547
533 $scope.limpiarFlete = function() { 548 $scope.limpiarFlete = function() {
534 $scope.notaPedido.fleteNombre = ''; 549 $scope.notaPedido.fleteNombre = '';
535 $scope.notaPedido.chofer = ''; 550 $scope.notaPedido.chofer = '';
536 $scope.notaPedido.vehiculo = ''; 551 $scope.notaPedido.vehiculo = '';
537 $scope.notaPedido.kilometros = ''; 552 $scope.notaPedido.kilometros = '';
538 $scope.notaPedido.costoUnitarioKmFlete = ''; 553 $scope.notaPedido.costoUnitarioKmFlete = '';
539 $scope.choferes = ''; 554 $scope.choferes = '';
540 $scope.vehiculos = ''; 555 $scope.vehiculos = '';
541 }; 556 };
542 557
543 $scope.limpiarPantalla = function() { 558 $scope.limpiarPantalla = function() {
544 $scope.limpiarFlete(); 559 $scope.limpiarFlete();
545 $scope.notaPedido.flete = '0'; 560 $scope.notaPedido.flete = '0';
546 $scope.notaPedido.bomba = '0'; 561 $scope.notaPedido.bomba = '0';
547 $scope.notaPedido.precioCondicion = ''; 562 $scope.notaPedido.precioCondicion = '';
548 $scope.articulosTabla = []; 563 $scope.articulosTabla = [];
549 $scope.notaPedido.vendedor.nombre = ''; 564 $scope.notaPedido.vendedor.nombre = '';
550 $scope.notaPedido.cliente = {nombre: ''}; 565 $scope.notaPedido.cliente = {nombre: ''};
551 $scope.notaPedido.domicilio = {dom: ''}; 566 $scope.notaPedido.domicilio = {dom: ''};
552 $scope.domiciliosCliente = []; 567 $scope.domiciliosCliente = [];
553 }; 568 };
554 569
555 $scope.resetFilter = function() { 570 $scope.resetFilter = function() {
556 $scope.articuloACargar = {}; 571 $scope.articuloACargar = {};
557 $scope.cargando = true; 572 $scope.cargando = true;
558 }; 573 };
559 574
560 $scope.selectFocus = function($event) { 575 $scope.selectFocus = function($event) {
561 $event.target.select(); 576 $event.target.select();
562 }; 577 };
563 578
564 $scope.salir = function() { 579 $scope.salir = function() {
565 $location.path('/'); 580 $location.path('/');
566 }; 581 };
567 582
568 function addCabecera(label, valor) { 583 function addCabecera(label, valor) {
569 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 584 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
570 if(propiedad.length === 1) { 585 if(propiedad.length === 1) {
571 propiedad[0].valor = valor; 586 propiedad[0].valor = valor;
572 } else { 587 } else {
573 $scope.cabecera.push({label: label, valor: valor}); 588 $scope.cabecera.push({label: label, valor: valor});
574 } 589 }
575 } 590 }
576 591
577 function removeCabecera(label) { 592 function removeCabecera(label) {
578 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 593 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
579 if(propiedad.length === 1){ 594 if(propiedad.length === 1){
580 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 595 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
581 } 596 }
582 } 597 }
598
599 function rellenar(relleno, longitud) {
600 relleno = '' + relleno;
601 while (relleno.length < longitud) {
602 relleno = '0' + relleno;
603 }
604
605 return relleno;
606 }
583 } 607 }
584 ] 608 ]
585 ) 609 )
586 .controller('notaPedidoListaCtrl', [ 610 .controller('notaPedidoListaCtrl', [
587 '$scope', 611 '$scope',
588 'crearNotaPedidoService', 612 'crearNotaPedidoService',
589 '$location', 613 '$location',
590 function($scope, crearNotaPedidoService, $location) { 614 function($scope, crearNotaPedidoService, $location) {
591 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 615 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
592 $scope.notaPedidos = datos.data; 616 $scope.notaPedidos = datos.data;
593 }); 617 });
594 $scope.editar = function(notaPedido) { 618 $scope.editar = function(notaPedido) {
595 crearNotaPedidoService.setNotaPedido(notaPedido); 619 crearNotaPedidoService.setNotaPedido(notaPedido);
596 $location.path('/venta-nota-pedido/abm/'); 620 $location.path('/venta-nota-pedido/abm/');
597 }; 621 };
598 $scope.crearPedido = function() { 622 $scope.crearPedido = function() {
599 crearNotaPedidoService.clearNotaPedido(); 623 crearNotaPedidoService.clearNotaPedido();
600 $location.path('/venta-nota-pedido/abm/'); 624 $location.path('/venta-nota-pedido/abm/');
601 }; 625 };
602 } 626 }
603 ]) 627 ])
604 .controller('focaCrearNotaPedidoFichaClienteController', [ 628 .controller('focaCrearNotaPedidoFichaClienteController', [
605 '$scope', 629 '$scope',
606 'crearNotaPedidoService', 630 'crearNotaPedidoService',
607 '$location', 631 '$location',
608 function($scope, crearNotaPedidoService, $location) { 632 function($scope, crearNotaPedidoService, $location) {
609 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 633 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
610 $scope.notaPedidos = datos.data; 634 $scope.notaPedidos = datos.data;
611 }); 635 });
612 $scope.editar = function(notaPedido) { 636 $scope.editar = function(notaPedido) {
613 crearNotaPedidoService.setNotaPedido(notaPedido); 637 crearNotaPedidoService.setNotaPedido(notaPedido);
614 $location.path('/venta-nota-pedido/abm/'); 638 $location.path('/venta-nota-pedido/abm/');
615 }; 639 };
616 $scope.crearPedido = function() { 640 $scope.crearPedido = function() {
617 crearNotaPedidoService.clearNotaPedido(); 641 crearNotaPedidoService.clearNotaPedido();
618 $location.path('/venta-nota-pedido/abm/'); 642 $location.path('/venta-nota-pedido/abm/');
619 }; 643 };
620 } 644 }
621 ]); 645 ]);
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 return { 4 return {
5 crearNotaPedido: function(notaPedido) { 5 crearNotaPedido: function(notaPedido) {
6 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); 6 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido});
7 }, 7 },
8 obtenerNotaPedido: function() { 8 obtenerNotaPedido: function() {
9 return $http.get(route +'/nota-pedido'); 9 return $http.get(route +'/nota-pedido');
10 }, 10 },
11 setNotaPedido: function(notaPedido) { 11 setNotaPedido: function(notaPedido) {
12 this.notaPedido = notaPedido; 12 this.notaPedido = notaPedido;
13 }, 13 },
14 clearNotaPedido: function() { 14 clearNotaPedido: function() {
15 this.notaPedido = undefined; 15 this.notaPedido = undefined;
16 }, 16 },
17 getNotaPedido: function() { 17 getNotaPedido: function() {
18 return this.notaPedido; 18 return this.notaPedido;
19 }, 19 },
20 getArticulosByIdNotaPedido: function(id) { 20 getArticulosByIdNotaPedido: function(id) {
21 return $http.get(route+'/articulos/nota-pedido/'+id); 21 return $http.get(route+'/articulos/nota-pedido/'+id);
22 }, 22 },
23 crearArticulosParaNotaPedido: function(articuloNotaPedido) { 23 crearArticulosParaNotaPedido: function(articuloNotaPedido) {
24 return $http.post(route + '/articulos/nota-pedido', 24 return $http.post(route + '/articulos/nota-pedido',
25 {articuloNotaPedido: articuloNotaPedido}); 25 {articuloNotaPedido: articuloNotaPedido});
26 }, 26 },
27 getDomiciliosByIdNotaPedido: function(id) { 27 getDomiciliosByIdNotaPedido: function(id) {
28 return $http.get(route +'/nota-pedido/'+id+'/domicilios'); 28 return $http.get(route +'/nota-pedido/'+id+'/domicilios');
29 }, 29 },
30 getDomiciliosByIdCliente: function(id) { 30 getDomiciliosByIdCliente: function(id) {
31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
33 }, 33 },
34 getPrecioCondicion: function() { 34 getPrecioCondicion: function() {
35 return $http.get(route + '/precio-condicion'); 35 return $http.get(route + '/precio-condicion');
36 }, 36 },
37 getPrecioCondicionById: function(id) { 37 getPrecioCondicionById: function(id) {
38 return $http.get(route + '/precio-condicion/' + id); 38 return $http.get(route + '/precio-condicion/' + id);
39 }, 39 },
40 getPlazoPagoByPrecioCondicion: function(id) { 40 getPlazoPagoByPrecioCondicion: function(id) {
41 return $http.get(route + '/plazo-pago/precio-condicion/'+ id); 41 return $http.get(route + '/plazo-pago/precio-condicion/'+ id);
42 }, 42 },
43 crearFlete: function(flete) { 43 crearFlete: function(flete) {
44 return $http.post(route + '/flete', {flete : flete}); 44 return $http.post(route + '/flete', {flete : flete});
45 }, 45 },
46 crearPlazosParaNotaPedido: function(plazos) { 46 crearPlazosParaNotaPedido: function(plazos) {
47 return $http.post(route + '/plazo-pago/nota-pedido', plazos); 47 return $http.post(route + '/plazo-pago/nota-pedido', plazos);
48 }, 48 },
49 getCotizacionByIdMoneda: function(id) { 49 getCotizacionByIdMoneda: function(id) {
50 return $http.get(route + '/moneda/' + id); 50 return $http.get(route + '/moneda/' + id);
51 }, 51 },
52 crearEstadoParaNotaPedido: function(estado) { 52 crearEstadoParaNotaPedido: function(estado) {
53 return $http.post(route + '/estado', {estado: estado}); 53 return $http.post(route + '/estado', {estado: estado});
54 },
55 getNumeroNotaPedido: function() {
56 return $http.get(route + '/nota-pedido/numero-siguiente');
54 } 57 }
55 }; 58 };
56 }]); 59 }]);
57 60