Commit b967c9d3ca62c85478440f34d7a2f4eb0508547a
1 parent
f2b06cf510
Exists in
master
ok identacion
Showing
1 changed file
with
7 additions
and
7 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaAbmPreciosCondiciones') | 1 | angular.module('focaAbmPreciosCondiciones') |
| 2 | .controller('focaAbmPreciosCondicionesController', [ | 2 | .controller('focaAbmPreciosCondicionesController', [ |
| 3 | '$scope', 'focaAbmPreciosCondicionesService', '$location', | 3 | '$scope', 'focaAbmPreciosCondicionesService', '$location', |
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', |
| 5 | function($scope, focaAbmPreciosCondicionesService, $location, | 5 | function($scope, focaAbmPreciosCondicionesService, $location, |
| 6 | focaModalService, focaBotoneraLateralService, $timeout) { | 6 | focaModalService, focaBotoneraLateralService, $timeout) { |
| 7 | 7 | ||
| 8 | $timeout(function() { | 8 | $timeout(function() { |
| 9 | focaBotoneraLateralService.showSalir(true); | 9 | focaBotoneraLateralService.showSalir(true); |
| 10 | focaBotoneraLateralService.showPausar(false); | 10 | focaBotoneraLateralService.showPausar(false); |
| 11 | focaBotoneraLateralService.showCancelar(false); | 11 | focaBotoneraLateralService.showCancelar(false); |
| 12 | focaBotoneraLateralService.showGuardar(false); | 12 | focaBotoneraLateralService.showGuardar(false); |
| 13 | }); | 13 | }); |
| 14 | $scope.filters = ''; | 14 | $scope.filters = ''; |
| 15 | $scope.now = new Date(); | 15 | $scope.now = new Date(); |
| 16 | $scope.editar = function(id) { | 16 | $scope.editar = function(id) { |
| 17 | $location.path('/precio-condicion/' + id); | 17 | $location.path('/precio-condicion/' + id); |
| 18 | }; | 18 | }; |
| 19 | $scope.solicitarConfirmacion = function(precioCondicion) { | 19 | $scope.solicitarConfirmacion = function(precioCondicion) { |
| 20 | focaModalService.confirm('¿Está seguro que desea borrar el precio condición' + | 20 | focaModalService.confirm('¿Está seguro que desea borrar el precio condición' + |
| 21 | precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then( | 21 | precioCondicion.codigo + ' ' + precioCondicion.nombre + ' ?').then( |
| 22 | function(data) { | 22 | function(data) { |
| 23 | if (data) { | 23 | if (data) { |
| 24 | focaAbmPreciosCondicionesService | 24 | focaAbmPreciosCondicionesService |
| 25 | .borrarPrecioCondicion(precioCondicion.id); | 25 | .borrarPrecioCondicion(precioCondicion.id); |
| 26 | $scope.preciosCondiciones.splice( | 26 | $scope.preciosCondiciones.splice( |
| 27 | $scope.preciosCondiciones.indexOf(precioCondicion), 1 | 27 | $scope.preciosCondiciones.indexOf(precioCondicion), 1 |
| 28 | ); | 28 | ); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | ); | 31 | ); |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | $scope.buscar = function(key) { | 34 | $scope.buscar = function(key) { |
| 35 | if(key === 13){ | 35 | if(key === 13){ |
| 36 | focaAbmPreciosCondicionesService | 36 | focaAbmPreciosCondicionesService |
| 37 | .obtenerPreciosCondiciones($scope.filters) | 37 | .obtenerPreciosCondiciones($scope.filters) |
| 38 | .then(function(datos) { | 38 | .then(function(datos) { |
| 39 | $scope.preciosCondiciones = datos.data; | 39 | $scope.preciosCondiciones = datos.data; |
| 40 | $scope.preciosCondiciones.forEach(function(precioCondicion) { | 40 | $scope.preciosCondiciones.forEach(function(precioCondicion) { |
| 41 | precioCondicion.plazoPago.sort(function(a, b) { | 41 | precioCondicion.plazoPago.sort(function(a, b) { |
| 42 | return a.dias- b.dias; | 42 | return a.dias- b.dias; |
| 43 | }); | ||
| 43 | }); | 44 | }); |
| 44 | }); | 45 | }); |
| 45 | }); | ||
| 46 | } | 46 | } |
| 47 | }; | 47 | }; |
| 48 | } | 48 | } |
| 49 | ]) | 49 | ]) |
| 50 | .controller('focaAbmPrecioCondicionController', [ | 50 | .controller('focaAbmPrecioCondicionController', [ |
| 51 | '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', | 51 | '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', |
| 52 | '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', | 52 | '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', |
| 53 | function( | 53 | function( |
| 54 | $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, | 54 | $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, |
| 55 | $routeParams, $location, focaModalService, $timeout, $uibModal, $window | 55 | $routeParams, $location, focaModalService, $timeout, $uibModal, $window |
| 56 | ) { | 56 | ) { |
| 57 | $scope.focused = 1; | 57 | $scope.focused = 1; |
| 58 | $scope.plazosAEliminar = []; | 58 | $scope.plazosAEliminar = []; |
| 59 | $scope.mostrarPlazos = $routeParams.id > 0; | 59 | $scope.mostrarPlazos = $routeParams.id > 0; |
| 60 | $scope.now = new Date(); | 60 | $scope.now = new Date(); |
| 61 | $scope.listaPrecioLabel = ''; | 61 | $scope.listaPrecioLabel = ''; |
| 62 | focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) | 62 | focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id) |
| 63 | .then(function(datos) { | 63 | .then(function(datos) { |
| 64 | $scope.precioCondicion = { | 64 | $scope.precioCondicion = { |
| 65 | id: 0, | 65 | id: 0, |
| 66 | codigo: '', | 66 | codigo: '', |
| 67 | nombre: '', | 67 | nombre: '', |
| 68 | descripcion: '', | 68 | descripcion: '', |
| 69 | idListaPrecio: 0, | 69 | idListaPrecio: 0, |
| 70 | vigencia: new Date() | 70 | vigencia: new Date() |
| 71 | }; | 71 | }; |
| 72 | if(datos.data.id) { | 72 | if(datos.data.id) { |
| 73 | $scope.precioCondicion = datos.data; | 73 | $scope.precioCondicion = datos.data; |
| 74 | $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + | 74 | $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + |
| 75 | ' - ' + datos.data.listaPrecio.DES; | 75 | ' - ' + datos.data.listaPrecio.DES; |
| 76 | $scope.$broadcast('addCabecera', { | 76 | $scope.$broadcast('addCabecera', { |
| 77 | label: 'Precio y condición:', | 77 | label: 'Precio y condición:', |
| 78 | valor: datos.data.nombre | 78 | valor: datos.data.nombre |
| 79 | }); | 79 | }); |
| 80 | focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) | 80 | focaAbmPreciosCondicionesService.obtenerPlazoPago(datos.data.id) |
| 81 | .then(function(datos) { | 81 | .then(function(datos) { |
| 82 | $scope.precioCondicion.plazos = datos.data; | 82 | $scope.precioCondicion.plazos = datos.data; |
| 83 | $scope.precioCondicion.plazos.sort(function(a, b) { | 83 | $scope.precioCondicion.plazos.sort(function(a, b) { |
| 84 | return a.dias- b.dias; | 84 | return a.dias- b.dias; |
| 85 | }); | 85 | }); |
| 86 | $scope.plazoACargar = | 86 | $scope.plazoACargar = |
| 87 | { | 87 | { |
| 88 | item: datos.data.length + 1 | 88 | item: datos.data.length + 1 |
| 89 | }; | 89 | }; |
| 90 | }); | 90 | }); |
| 91 | } | 91 | } |
| 92 | }); | 92 | }); |
| 93 | 93 | ||
| 94 | $timeout(function() { | 94 | $timeout(function() { |
| 95 | focaBotoneraLateralService.showSalir(false); | 95 | focaBotoneraLateralService.showSalir(false); |
| 96 | focaBotoneraLateralService.showPausar(true); | 96 | focaBotoneraLateralService.showPausar(true); |
| 97 | focaBotoneraLateralService.showCancelar(true); | 97 | focaBotoneraLateralService.showCancelar(true); |
| 98 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 98 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 99 | }); | 99 | }); |
| 100 | 100 | ||
| 101 | $scope.cancelar = function() { | 101 | $scope.cancelar = function() { |
| 102 | $location.path('/precio-condicion'); | 102 | $location.path('/precio-condicion'); |
| 103 | }; | 103 | }; |
| 104 | $scope.guardar = function() { | 104 | $scope.guardar = function() { |
| 105 | var promises = []; | 105 | var promises = []; |
| 106 | var precioCondicion = $scope.precioCondicion; | 106 | var precioCondicion = $scope.precioCondicion; |
| 107 | precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; | 107 | precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; |
| 108 | delete precioCondicion.listaPrecio; | 108 | delete precioCondicion.listaPrecio; |
| 109 | if($scope.mostrarPlazos) { | 109 | if($scope.mostrarPlazos) { |
| 110 | promises.push( | 110 | promises.push( |
| 111 | focaAbmPreciosCondicionesService | 111 | focaAbmPreciosCondicionesService |
| 112 | .guardarPlazosPago($scope.precioCondicion.plazos) | 112 | .guardarPlazosPago($scope.precioCondicion.plazos) |
| 113 | ); | 113 | ); |
| 114 | $scope.plazosAEliminar.forEach(function(id) { | 114 | $scope.plazosAEliminar.forEach(function(id) { |
| 115 | promises.push( | 115 | promises.push( |
| 116 | focaAbmPreciosCondicionesService | 116 | focaAbmPreciosCondicionesService |
| 117 | .borrarPlazoPago(id) | 117 | .borrarPlazoPago(id) |
| 118 | ); | 118 | ); |
| 119 | }); | 119 | }); |
| 120 | } | 120 | } |
| 121 | promises.push( | 121 | promises.push( |
| 122 | focaAbmPreciosCondicionesService | 122 | focaAbmPreciosCondicionesService |
| 123 | .guardarPrecioCondicion(precioCondicion) | 123 | .guardarPrecioCondicion(precioCondicion) |
| 124 | ); | 124 | ); |
| 125 | 125 | ||
| 126 | Promise.all(promises).then(function() { | 126 | Promise.all(promises).then(function() { |
| 127 | $window.location.assign('/#!/precio-condicion'); | 127 | $window.location.assign('/#!/precio-condicion'); |
| 128 | }, function(err){ | 128 | }, function(err){ |
| 129 | console.error(err); | 129 | console.error(err); |
| 130 | }); | 130 | }); |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | $scope.agregarPlazo = function(key) { | 133 | $scope.agregarPlazo = function(key) { |
| 134 | if(key === 13) { | 134 | if(key === 13) { |
| 135 | if(!$scope.plazoACargar.dias) { | 135 | if(!$scope.plazoACargar.dias) { |
| 136 | focaModalService.alert('Ingrese cantidad de días'); | 136 | focaModalService.alert('Ingrese cantidad de días'); |
| 137 | return; | 137 | return; |
| 138 | } | 138 | } |
| 139 | var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { | 139 | var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { |
| 140 | return a.dias === $scope.plazoACargar.dias; | 140 | return a.dias === $scope.plazoACargar.dias; |
| 141 | }); | 141 | }); |
| 142 | if(tieneEseDia.length > 0) { | 142 | if(tieneEseDia.length > 0) { |
| 143 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); | 143 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); |
| 144 | return; | 144 | return; |
| 145 | } | 145 | } |
| 146 | $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; | 146 | $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; |
| 147 | $scope.plazoACargar.activo = true; | 147 | $scope.plazoACargar.activo = true; |
| 148 | $scope.precioCondicion.plazos.push($scope.plazoACargar); | 148 | $scope.precioCondicion.plazos.push($scope.plazoACargar); |
| 149 | $scope.plazoACargar = | 149 | $scope.plazoACargar = |
| 150 | { | 150 | { |
| 151 | item: $scope.precioCondicion.plazos.length + 1 | 151 | item: $scope.precioCondicion.plazos.length + 1 |
| 152 | }; | 152 | }; |
| 153 | } | 153 | } |
| 154 | }; | 154 | }; |
| 155 | $scope.quitarPlazo = function(key) { | 155 | $scope.quitarPlazo = function(key) { |
| 156 | if($scope.precioCondicion.plazos[key].id) | 156 | if($scope.precioCondicion.plazos[key].id) |
| 157 | $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); | 157 | $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); |
| 158 | 158 | ||
| 159 | $scope.precioCondicion.plazos.splice(key, 1); | 159 | $scope.precioCondicion.plazos.splice(key, 1); |
| 160 | $scope.plazoACargar = | 160 | $scope.plazoACargar = |
| 161 | { | 161 | { |
| 162 | item: $scope.precioCondicion.plazos.length + 1 | 162 | item: $scope.precioCondicion.plazos.length + 1 |
| 163 | }; | 163 | }; |
| 164 | }; | 164 | }; |
| 165 | $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { | 165 | $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { |
| 166 | focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + | 166 | focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + |
| 167 | plazoPago.item + ' ' + plazoPago.dias + ' ?').then( | 167 | plazoPago.item + ' ' + plazoPago.dias + ' ?').then( |
| 168 | function(confirm) { | 168 | function(confirm) { |
| 169 | if (confirm) { | 169 | if (confirm) { |
| 170 | focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); | 170 | focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); |
| 171 | $scope.precioCondicion.plazos.splice( | 171 | $scope.precioCondicion.plazos.splice( |
| 172 | $scope.precioCondicion.plazos.indexOf(plazoPago), 1 | 172 | $scope.precioCondicion.plazos.indexOf(plazoPago), 1 |
| 173 | ); | 173 | ); |
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| 176 | ); | 176 | ); |
| 177 | }; | 177 | }; |
| 178 | 178 | ||
| 179 | $scope.seleccionarListaPrecio = function(key) { | 179 | $scope.seleccionarListaPrecio = function(key) { |
| 180 | if(key === 13){ | 180 | if(key === 13){ |
| 181 | var modalInstance = $uibModal.open( | 181 | var modalInstance = $uibModal.open( |
| 182 | { | 182 | { |
| 183 | ariaLabelledBy: 'Busqueda de Listas de precio', | 183 | ariaLabelledBy: 'Busqueda de Listas de precio', |
| 184 | templateUrl: 'modal-lista-precio.html', | 184 | templateUrl: 'modal-lista-precio.html', |
| 185 | controller: 'focaModalListaPrecioCtrl', | 185 | controller: 'focaModalListaPrecioCtrl', |
| 186 | size: 'lg' | 186 | size: 'lg' |
| 187 | } | 187 | } |
| 188 | ); | 188 | ); |
| 189 | modalInstance.result.then(function(listaPrecio) { | 189 | modalInstance.result.then(function(listaPrecio) { |
| 190 | $scope.precioCondicion.listaPrecio = listaPrecio; | 190 | $scope.precioCondicion.listaPrecio = listaPrecio; |
| 191 | $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; | 191 | $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; |
| 192 | $scope.focused = 4; | 192 | $scope.focused = 4; |
| 193 | }); | 193 | }); |
| 194 | } | 194 | } |
| 195 | }; | 195 | }; |
| 196 | 196 | ||
| 197 | $scope.next = function(key) { | 197 | $scope.next = function(key) { |
| 198 | if(key === 13) $scope.focused++; | 198 | if(key === 13) $scope.focused++; |
| 199 | }; | 199 | }; |
| 200 | } | 200 | } |
| 201 | ]); | 201 | ]); |