Commit 9e1dec3ae514f975ef32ab320de0ce487e389323

Authored by Eric Fernandez
1 parent 85936cdd7e
Exists in master

error en enviar variable idLista

Showing 1 changed file with 2 additions and 1 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .controller('notaPedidoCtrl', 2 .controller('notaPedidoCtrl',
3 [ 3 [
4 '$scope', 4 '$scope',
5 '$uibModal', 5 '$uibModal',
6 'crearNotaPedidoService', 6 'crearNotaPedidoService',
7 function ($scope, $uibModal, crearNotaPedidoService) { 7 function ($scope, $uibModal, crearNotaPedidoService) {
8 $scope.notaPedido = {}; 8 $scope.notaPedido = {};
9 $scope.articulosTabla = []; 9 $scope.articulosTabla = [];
10 var idLista; 10 var idLista;
11 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 11 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
12 $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1); 12 $scope.domiciliosCliente = crearNotaPedidoService.getDomicilios(1);
13 crearNotaPedidoService.getPrecioCondicion().then( 13 crearNotaPedidoService.getPrecioCondicion().then(
14 function (res) { 14 function (res) {
15 $scope.precioCondiciones = res.data; 15 $scope.precioCondiciones = res.data;
16 } 16 }
17 ); 17 );
18 if (notaPedidoTemp != undefined) { 18 if (notaPedidoTemp != undefined) {
19 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 19 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
20 $scope.notaPedido = notaPedidoTemp; 20 $scope.notaPedido = notaPedidoTemp;
21 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 21 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
22 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 22 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
23 $scope.notaPedido.precioCondicion = 2; 23 idLista= $scope.notaPedido.precioCondicion;
24 24
25 } else { 25 } else {
26 $scope.notaPedido.fechaCarga = new Date(); 26 $scope.notaPedido.fechaCarga = new Date();
27 $scope.notaPedido.domicilio = [{ id: 0 }] 27 $scope.notaPedido.domicilio = [{ id: 0 }]
28 $scope.notaPedido.bomba = '1'; 28 $scope.notaPedido.bomba = '1';
29 $scope.notaPedido.flete = '1'; 29 $scope.notaPedido.flete = '1';
30 idLista = undefined;
30 } 31 }
31 $scope.addNewDom = function () { 32 $scope.addNewDom = function () {
32 $scope.notaPedido.domicilio.push({ 'id': 0 }); 33 $scope.notaPedido.domicilio.push({ 'id': 0 });
33 } 34 }
34 $scope.removeNewChoice = function (choice) { 35 $scope.removeNewChoice = function (choice) {
35 if ($scope.notaPedido.domicilio.length > 1) { 36 if ($scope.notaPedido.domicilio.length > 1) {
36 $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1) 37 $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(c => c.$$hashKey == choice.$$hashKey), 1)
37 } 38 }
38 } 39 }
39 $scope.crearNotaPedido = function () { 40 $scope.crearNotaPedido = function () {
40 var notaPedido = { 41 var notaPedido = {
41 idNotaPedido: 0, 42 idNotaPedido: 0,
42 precioCondicion: $scope.notaPedido.precioCondicion, 43 precioCondicion: $scope.notaPedido.precioCondicion,
43 fechaCarga: $scope.notaPedido.fechaCarga, 44 fechaCarga: $scope.notaPedido.fechaCarga,
44 vendedor: $scope.notaPedido.vendedor, 45 vendedor: $scope.notaPedido.vendedor,
45 cliente: $scope.notaPedido.cliente, 46 cliente: $scope.notaPedido.cliente,
46 producto: $scope.notaPedido.producto, 47 producto: $scope.notaPedido.producto,
47 bomba: $scope.notaPedido.bomba, 48 bomba: $scope.notaPedido.bomba,
48 petrolera: $scope.notaPedido.petrolera, 49 petrolera: $scope.notaPedido.petrolera,
49 domicilio: $scope.notaPedido.domicilio, 50 domicilio: $scope.notaPedido.domicilio,
50 kilometros: $scope.notaPedido.kilometros, 51 kilometros: $scope.notaPedido.kilometros,
51 jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB, 52 jurisdiccionIIBB: $scope.notaPedido.jurisdiccionIIBB,
52 costoFinanciacion: $scope.notaPedido.costoFinanciacion, 53 costoFinanciacion: $scope.notaPedido.costoFinanciacion,
53 flete: $scope.notaPedido.flete, 54 flete: $scope.notaPedido.flete,
54 costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete, 55 costoUnitarioKmFlete: $scope.notaPedido.costoUnitarioKmFlete,
55 articulosTabla: $scope.articulosTabla 56 articulosTabla: $scope.articulosTabla
56 } 57 }
57 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 58 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
58 function (res) { 59 function (res) {
59 alert('Nota pedido creada') 60 alert('Nota pedido creada')
60 } 61 }
61 ) 62 )
62 } 63 }
63 $scope.siguienteTab = function () { 64 $scope.siguienteTab = function () {
64 $scope.active = 1; 65 $scope.active = 1;
65 } 66 }
66 $scope.seleccionarArticulo = function () { 67 $scope.seleccionarArticulo = function () {
67 if(idLista==undefined){ 68 if(idLista==undefined){
68 alert('primero seleccione una lista de precio y condicion'); 69 alert('primero seleccione una lista de precio y condicion');
69 return; 70 return;
70 } 71 }
71 var modalInstance = $uibModal.open( 72 var modalInstance = $uibModal.open(
72 { 73 {
73 ariaLabelledBy: 'Busqueda de Productos', 74 ariaLabelledBy: 'Busqueda de Productos',
74 templateUrl: 'modal-busqueda-productos.html', 75 templateUrl: 'modal-busqueda-productos.html',
75 controller: 'modalBusquedaProductosCtrl', 76 controller: 'modalBusquedaProductosCtrl',
76 resolve: {idLista: function() {return idLista}}, 77 resolve: {idLista: function() {return idLista}},
77 size: 'lg' 78 size: 'lg'
78 } 79 }
79 ) 80 )
80 modalInstance.result.then( 81 modalInstance.result.then(
81 function (producto) { 82 function (producto) {
82 var newArt = 83 var newArt =
83 { 84 {
84 codigo: producto.FiltroSectorCodigo, 85 codigo: producto.FiltroSectorCodigo,
85 item: $scope.articulosTabla.length + 1, 86 item: $scope.articulosTabla.length + 1,
86 nombre: producto.descripcion, 87 nombre: producto.descripcion,
87 precio: producto.precio, 88 precio: producto.precio,
88 costoUnitario: producto.costo, 89 costoUnitario: producto.costo,
89 cantidad: 1 90 cantidad: 1
90 } 91 }
91 $scope.articulosTabla.unshift(newArt); 92 $scope.articulosTabla.unshift(newArt);
92 }, function () { 93 }, function () {
93 // funcion ejecutada cuando se cancela el modal 94 // funcion ejecutada cuando se cancela el modal
94 } 95 }
95 ); 96 );
96 } 97 }
97 $scope.seleccionarVendedor = function () { 98 $scope.seleccionarVendedor = function () {
98 var modalInstance = $uibModal.open( 99 var modalInstance = $uibModal.open(
99 { 100 {
100 ariaLabelledBy: 'Busqueda de Vendedores', 101 ariaLabelledBy: 'Busqueda de Vendedores',
101 templateUrl: 'modal-vendedores.html', 102 templateUrl: 'modal-vendedores.html',
102 controller: 'modalVendedoresCtrl', 103 controller: 'modalVendedoresCtrl',
103 size: 'lg' 104 size: 'lg'
104 } 105 }
105 ) 106 )
106 modalInstance.result.then( 107 modalInstance.result.then(
107 function (vendedor) { 108 function (vendedor) {
108 $scope.notaPedido.vendedor = vendedor.NomVen; 109 $scope.notaPedido.vendedor = vendedor.NomVen;
109 }, function () { 110 }, function () {
110 111
111 } 112 }
112 ); 113 );
113 } 114 }
114 $scope.seleccionarPetrolera = function() { 115 $scope.seleccionarPetrolera = function() {
115 var modalInstance = $uibModal.open( 116 var modalInstance = $uibModal.open(
116 { 117 {
117 ariaLabelledBy: 'Busqueda de Petrolera', 118 ariaLabelledBy: 'Busqueda de Petrolera',
118 templateUrl: 'modal-petroleras.html', 119 templateUrl: 'modal-petroleras.html',
119 controller: 'modalPetrolerasCtrl', 120 controller: 'modalPetrolerasCtrl',
120 size: 'lg' 121 size: 'lg'
121 } 122 }
122 ) 123 )
123 modalInstance.result.then( 124 modalInstance.result.then(
124 function (petrolera) { 125 function (petrolera) {
125 $scope.notaPedido.petrolera = petrolera.NOM; 126 $scope.notaPedido.petrolera = petrolera.NOM;
126 }, function () { 127 }, function () {
127 128
128 } 129 }
129 ); 130 );
130 } 131 }
131 $scope.seleccionarCliente = function() { 132 $scope.seleccionarCliente = function() {
132 var modalInstance = $uibModal.open( 133 var modalInstance = $uibModal.open(
133 { 134 {
134 ariaLabelledBy: 'Busqueda de Cliente', 135 ariaLabelledBy: 'Busqueda de Cliente',
135 templateUrl: 'foca-busqueda-cliente-modal.html', 136 templateUrl: 'foca-busqueda-cliente-modal.html',
136 controller: 'focaBusquedaClienteModalController', 137 controller: 'focaBusquedaClienteModalController',
137 size: 'lg' 138 size: 'lg'
138 } 139 }
139 ) 140 )
140 modalInstance.result.then( 141 modalInstance.result.then(
141 function (cliente) { 142 function (cliente) {
142 $scope.notaPedido.cliente = cliente.nom; 143 $scope.notaPedido.cliente = cliente.nom;
143 }, function () { 144 }, function () {
144 145
145 } 146 }
146 ); 147 );
147 } 148 }
148 $scope.obtenerDomicilios = function (id) { 149 $scope.obtenerDomicilios = function (id) {
149 crearNotaPedidoService.getDomicilios(id).then( 150 crearNotaPedidoService.getDomicilios(id).then(
150 function (res) { 151 function (res) {
151 $scope.notaPedido.domicilio = res.data; 152 $scope.notaPedido.domicilio = res.data;
152 } 153 }
153 ) 154 )
154 } 155 }
155 $scope.getSubTotal = function(item) { 156 $scope.getSubTotal = function(item) {
156 var subTotal=0; 157 var subTotal=0;
157 var array = $scope.articulosTabla.filter(a=>a.item<=item); 158 var array = $scope.articulosTabla.filter(a=>a.item<=item);
158 for(var i = 0; i< array.length; i++) { 159 for(var i = 0; i< array.length; i++) {
159 subTotal+=array[i].precio*array[i].cantidad 160 subTotal+=array[i].precio*array[i].cantidad
160 } 161 }
161 return subTotal.toFixed(2); 162 return subTotal.toFixed(2);
162 } 163 }
163 $scope.cargarArticulos = function() { 164 $scope.cargarArticulos = function() {
164 idLista=$scope.notaPedido.precioCondicion; 165 idLista=$scope.notaPedido.precioCondicion;
165 } 166 }
166 } 167 }
167 ] 168 ]
168 ) 169 )
169 .controller('notaPedidoListaCtrl', [ 170 .controller('notaPedidoListaCtrl', [
170 '$scope', 171 '$scope',
171 'crearNotaPedidoService', 172 'crearNotaPedidoService',
172 '$location', 173 '$location',
173 function ($scope, crearNotaPedidoService, $location) { 174 function ($scope, crearNotaPedidoService, $location) {
174 crearNotaPedidoService.obtenerNotaPedido().then(function (datos) { 175 crearNotaPedidoService.obtenerNotaPedido().then(function (datos) {
175 $scope.notaPedidos = datos.data; 176 $scope.notaPedidos = datos.data;
176 }); 177 });
177 $scope.editar = function (notaPedido) { 178 $scope.editar = function (notaPedido) {
178 crearNotaPedidoService.setNotaPedido(notaPedido); 179 crearNotaPedidoService.setNotaPedido(notaPedido);
179 $location.path('/venta-nota-pedido/abm/'); 180 $location.path('/venta-nota-pedido/abm/');
180 } 181 }
181 $scope.crearPedido = function () { 182 $scope.crearPedido = function () {
182 $location.path('/venta-nota-pedido/abm/'); 183 $location.path('/venta-nota-pedido/abm/');
183 } 184 }
184 } 185 }
185 ]) 186 ])
186 187