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