Usando parametros para transporte
This commit is contained in:
parent
9f4afd1bac
commit
08bdbe0ee1
2 changed files with 39 additions and 5 deletions
|
@ -4,21 +4,29 @@ namespace App\Helpers;
|
|||
|
||||
use App\CanastaLog;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use InvalidArgumentException;
|
||||
use League\Csv\Exception;
|
||||
|
||||
class TransporteHelper
|
||||
{
|
||||
const COSTO_TRANSPORTE = 15;
|
||||
const MONTO_TRANSPORTE = 500;
|
||||
private const COSTO_TRANSPORTE = "bono-transporte";
|
||||
private const MONTO_TRANSPORTE = "monto-transporte";
|
||||
private static ?array $parametros = null;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function cantidadTransporte($monto)
|
||||
{
|
||||
return ceil($monto / self::MONTO_TRANSPORTE);
|
||||
return ceil($monto / self::getParametro(self::MONTO_TRANSPORTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function totalTransporte($monto)
|
||||
{
|
||||
return self::cantidadTransporte($monto) * self::COSTO_TRANSPORTE;
|
||||
return self::cantidadTransporte($monto) * self::getParametro(self::COSTO_TRANSPORTE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,4 +49,28 @@ class TransporteHelper
|
|||
Log::error($error);
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getParametro(string $id): int
|
||||
{
|
||||
if (self::$parametros === null) {
|
||||
$records = CsvHelper::getRecords(resource_path('csv/parametros.csv'), "No se pudo leer el archivo.");
|
||||
self::$parametros = [];
|
||||
foreach ($records as $row) {
|
||||
self::$parametros[$row['id']] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset(self::$parametros[$id])) {
|
||||
throw new InvalidArgumentException("Parámetro '$id' no encontrado.");
|
||||
}
|
||||
|
||||
return (int) self::$parametros[$id]['valor'];
|
||||
}
|
||||
|
||||
public static function resetParametros(): void {
|
||||
self::$parametros = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\GrupoDeCompra;
|
|||
use App\Helpers\CanastaHelper;
|
||||
use App\Helpers\CsvHelper;
|
||||
use App\Helpers\PedidosExportHelper;
|
||||
use App\Helpers\TransporteHelper;
|
||||
use App\Http\Resources\GrupoDeCompraResource;
|
||||
use App\Producto;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
@ -130,7 +131,7 @@ class ComisionesController
|
|||
return response()->json(GrupoDeCompraResource::collection(GrupoDeCompra::all()));
|
||||
}
|
||||
|
||||
public function obtenerParametros()
|
||||
public function obtenerParametros(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$records = self::parametrosRecords();
|
||||
|
@ -151,6 +152,7 @@ class ComisionesController
|
|||
'valor' => ['required', 'numeric', 'gte:0'],
|
||||
]);
|
||||
CsvHelper::cambiarParametro($parametro_id, $valid['valor']);
|
||||
TransporteHelper::resetParametros();
|
||||
return response()->noContent();
|
||||
}
|
||||
return response()->json(['message' => 'Parametro no encontrado.'], 404);
|
||||
|
|
Loading…
Add table
Reference in a new issue