Commit 5a5b6f973c12a792cd32152ea23c2eef90b959d0

Authored by Jose Pinto
Exists in master

Merge remote-tracking branch 'upstream/develop'

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