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