Commit 7965aabb276384b6aaffcd9f25acb6dfc3858fb4
1 parent
8fe8fa36ae
Exists in
master
Validacion precios
Showing
1 changed file
with
16 additions
and
1 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 | |||
| 106 | console.log($scope.precioCondicion); | ||
| 107 | |||
| 108 | if (!$scope.precioCondicion.nombre) { | ||
| 109 | focaModalService.alert('Ingrese nombre'); | ||
| 110 | return; | ||
| 111 | } else if (!$scope.precioCondicion.descripcion) { | ||
| 112 | focaModalService.alert('Ingrese descripcion'); | ||
| 113 | return; | ||
| 114 | } else if (!$scope.precioCondicion.idListaPrecio) { | ||
| 115 | focaModalService.alert('Seleccione precio'); | ||
| 116 | return; | ||
| 117 | } | ||
| 118 | |||
| 105 | var promises = []; | 119 | var promises = []; |
| 106 | var precioCondicion = $scope.precioCondicion; | 120 | var precioCondicion = $scope.precioCondicion; |
| 107 | precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; | 121 | precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; |
| 108 | delete precioCondicion.listaPrecio; | 122 | delete precioCondicion.listaPrecio; |
| 109 | if($scope.mostrarPlazos) { | 123 | if($scope.mostrarPlazos) { |
| 110 | promises.push( | 124 | promises.push( |
| 111 | focaAbmPreciosCondicionesService | 125 | focaAbmPreciosCondicionesService |
| 112 | .guardarPlazosPago($scope.precioCondicion.plazos) | 126 | .guardarPlazosPago($scope.precioCondicion.plazos) |
| 113 | ); | 127 | ); |
| 114 | $scope.plazosAEliminar.forEach(function(id) { | 128 | $scope.plazosAEliminar.forEach(function(id) { |
| 115 | promises.push( | 129 | promises.push( |
| 116 | focaAbmPreciosCondicionesService | 130 | focaAbmPreciosCondicionesService |
| 117 | .borrarPlazoPago(id) | 131 | .borrarPlazoPago(id) |
| 118 | ); | 132 | ); |
| 119 | }); | 133 | }); |
| 120 | } | 134 | } |
| 121 | promises.push( | 135 | promises.push( |
| 122 | focaAbmPreciosCondicionesService | 136 | focaAbmPreciosCondicionesService |
| 123 | .guardarPrecioCondicion(precioCondicion) | 137 | .guardarPrecioCondicion(precioCondicion) |
| 124 | ); | 138 | ); |
| 125 | 139 | ||
| 126 | Promise.all(promises).then(function() { | 140 | Promise.all(promises).then(function() { |
| 127 | $timeout(function() { | 141 | $timeout(function() { |
| 128 | $location.path('/precio-condicion'); | 142 | $location.path('/precio-condicion'); |
| 129 | }, 0); | 143 | }, 0); |
| 130 | }, function(err){ | 144 | }, function(err){ |
| 131 | console.error(err); | 145 | console.error(err); |
| 132 | }); | 146 | }); |
| 133 | }; | 147 | }; |
| 134 | 148 | ||
| 135 | $scope.agregarPlazo = function(key) { | 149 | $scope.agregarPlazo = function(key) { |
| 136 | if(key === 13) { | 150 | if(key === 13) { |
| 137 | if(!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { | 151 | if(!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { |
| 138 | focaModalService.alert('Ingrese cantidad de días'); | 152 | focaModalService.alert('Ingrese cantidad de días'); |
| 139 | return; | 153 | return; |
| 140 | } | 154 | } |
| 141 | var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { | 155 | var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { |
| 142 | return a.dias === $scope.plazoACargar.dias; | 156 | return a.dias === $scope.plazoACargar.dias; |
| 143 | }); | 157 | }); |
| 144 | if(tieneEseDia.length > 0) { | 158 | if(tieneEseDia.length > 0) { |
| 145 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); | 159 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); |
| 146 | return; | 160 | return; |
| 147 | } | 161 | } |
| 148 | $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; | 162 | $scope.plazoACargar.idPreciosCondiciones = $scope.precioCondicion.id; |
| 149 | $scope.plazoACargar.activo = true; | 163 | $scope.plazoACargar.activo = true; |
| 150 | $scope.precioCondicion.plazos.push($scope.plazoACargar); | 164 | $scope.precioCondicion.plazos.push($scope.plazoACargar); |
| 151 | $scope.plazoACargar = | 165 | $scope.plazoACargar = |
| 152 | { | 166 | { |
| 153 | item: $scope.precioCondicion.plazos.length + 1 | 167 | item: $scope.precioCondicion.plazos.length + 1 |
| 154 | }; | 168 | }; |
| 155 | } | 169 | } |
| 156 | }; | 170 | }; |
| 157 | $scope.quitarPlazo = function(key) { | 171 | $scope.quitarPlazo = function(key) { |
| 158 | if($scope.precioCondicion.plazos[key].id) | 172 | if($scope.precioCondicion.plazos[key].id) |
| 159 | $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); | 173 | $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); |
| 160 | 174 | ||
| 161 | $scope.precioCondicion.plazos.splice(key, 1); | 175 | $scope.precioCondicion.plazos.splice(key, 1); |
| 162 | $scope.plazoACargar = | 176 | $scope.plazoACargar = |
| 163 | { | 177 | { |
| 164 | item: $scope.precioCondicion.plazos.length + 1 | 178 | item: $scope.precioCondicion.plazos.length + 1 |
| 165 | }; | 179 | }; |
| 166 | }; | 180 | }; |
| 167 | $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { | 181 | $scope.solicitarConfirmacionPlazoPago = function(plazoPago) { |
| 168 | focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + | 182 | focaModalService.confirm('¿Está seguro que desea borrar el plazo de pago ' + |
| 169 | plazoPago.item + ' ' + plazoPago.dias + ' ?').then( | 183 | plazoPago.item + ' ' + plazoPago.dias + ' ?').then( |
| 170 | function(confirm) { | 184 | function(confirm) { |
| 171 | if (confirm) { | 185 | if (confirm) { |
| 172 | focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); | 186 | focaAbmPreciosCondicionesService.borrarPlazoPago(plazoPago.id); |
| 173 | $scope.precioCondicion.plazos.splice( | 187 | $scope.precioCondicion.plazos.splice( |
| 174 | $scope.precioCondicion.plazos.indexOf(plazoPago), 1 | 188 | $scope.precioCondicion.plazos.indexOf(plazoPago), 1 |
| 175 | ); | 189 | ); |
| 176 | } | 190 | } |
| 177 | } | 191 | } |
| 178 | ); | 192 | ); |
| 179 | }; | 193 | }; |
| 180 | 194 | ||
| 181 | $scope.seleccionarListaPrecio = function(key) { | 195 | $scope.seleccionarListaPrecio = function(key) { |
| 182 | if(key === 13){ | 196 | if(key === 13){ |
| 183 | var modalInstance = $uibModal.open( | 197 | var modalInstance = $uibModal.open( |
| 184 | { | 198 | { |
| 185 | ariaLabelledBy: 'Busqueda de Listas de precio', | 199 | ariaLabelledBy: 'Busqueda de Listas de precio', |
| 186 | templateUrl: 'modal-lista-precio.html', | 200 | templateUrl: 'modal-lista-precio.html', |
| 187 | controller: 'focaModalListaPrecioCtrl', | 201 | controller: 'focaModalListaPrecioCtrl', |
| 188 | size: 'lg' | 202 | size: 'lg' |
| 189 | } | 203 | } |
| 190 | ); | 204 | ); |
| 191 | modalInstance.result.then(function(listaPrecio) { | 205 | modalInstance.result.then(function(listaPrecio) { |
| 206 | $scope.precioCondicion.idListaPrecio = listaPrecio.ID; | ||
| 192 | $scope.precioCondicion.listaPrecio = listaPrecio; | 207 | $scope.precioCondicion.listaPrecio = listaPrecio; |
| 193 | $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; | 208 | $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; |
| 194 | $scope.focused = 4; | 209 | $scope.focused = 4; |
| 195 | }); | 210 | }); |
| 196 | } | 211 | } |
| 197 | }; | 212 | }; |
| 198 | 213 | ||
| 199 | $scope.verProductosListaPrecio = function() { | 214 | $scope.verProductosListaPrecio = function() { |
| 200 | $uibModal.open( | 215 | $uibModal.open( |
| 201 | { | 216 | { |
| 202 | ariaLabelledBy: 'Busqueda de Productos', | 217 | ariaLabelledBy: 'Busqueda de Productos', |
| 203 | templateUrl: 'modal-busqueda-productos.html', | 218 | templateUrl: 'modal-busqueda-productos.html', |
| 204 | controller: 'modalBusquedaProductosCtrl', | 219 | controller: 'modalBusquedaProductosCtrl', |
| 205 | resolve: { | 220 | resolve: { |
| 206 | parametroProducto: { | 221 | parametroProducto: { |
| 207 | idLista: $scope.precioCondicion.listaPrecio.ID, | 222 | idLista: $scope.precioCondicion.listaPrecio.ID, |
| 208 | cotizacion: 1, | 223 | cotizacion: 1, |
| 209 | simbolo: '$', | 224 | simbolo: '$', |
| 210 | soloMostrar: true | 225 | soloMostrar: true |
| 211 | } | 226 | } |
| 212 | }, | 227 | }, |
| 213 | size: 'md' | 228 | size: 'md' |
| 214 | } | 229 | } |
| 215 | ); | 230 | ); |
| 216 | }; | 231 | }; |
| 217 | 232 | ||
| 218 | $scope.next = function(key) { | 233 | $scope.next = function(key) { |
| 219 | if(key === 13) $scope.focused++; | 234 | if(key === 13) $scope.focused++; |
| 220 | }; | 235 | }; |
| 221 | } | 236 | } |
| 222 | ]); | 237 | ]); |
| 223 | 238 |