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