feat: actualizar validaciones de SKU y código de barras en solicitudes de bundles y categorías, y ajustar cálculo de impuestos en el servicio de bundles
This commit is contained in:
parent
3d5198a65a
commit
ec33cf2c0e
@ -6,6 +6,7 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Inventory;
|
||||
use App\Models\InventorySerial;
|
||||
use App\Models\Warehouse;
|
||||
use App\Services\InventoryMovementService;
|
||||
use Illuminate\Http\Request;
|
||||
use Notsoweb\ApiResponse\Enums\ApiResponse;
|
||||
@ -31,6 +32,11 @@ public function index(Inventory $inventario, Request $request)
|
||||
|
||||
if ($request->has('warehouse_id')) {
|
||||
$query->where('warehouse_id', $request->warehouse_id);
|
||||
} else {
|
||||
$mainWarehouse = Warehouse::where('is_main', true)->first();
|
||||
if ($mainWarehouse) {
|
||||
$query->where('warehouse_id', $mainWarehouse->id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->has('q')) {
|
||||
|
||||
@ -22,7 +22,7 @@ public function rules(): array
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'sku' => ['required', 'string', 'max:50', 'unique:bundles,sku'],
|
||||
'barcode' => ['nullable', 'string', 'max:50'],
|
||||
'barcode' => ['nullable', 'string', 'unique:bundles,barcode'],
|
||||
|
||||
// Componentes del kit (mínimo 2 productos)
|
||||
'items' => ['required', 'array', 'min:2'],
|
||||
|
||||
@ -24,7 +24,7 @@ public function rules(): array
|
||||
return [
|
||||
'name' => ['nullable', 'string', 'max:255'],
|
||||
'sku' => ['nullable', 'string', 'max:50', 'unique:bundles,sku,' . $bundleId],
|
||||
'barcode' => ['nullable', 'string', 'max:50'],
|
||||
'barcode' => ['nullable', 'string', 'unique:bundles,barcode,' . $bundleId],
|
||||
|
||||
// Componentes del kit (opcional en update)
|
||||
'items' => ['nullable', 'array', 'min:2'],
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace App\Http\Requests\App;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CategoryStoreRequest extends FormRequest
|
||||
{
|
||||
@ -19,7 +20,7 @@ public function authorize(): bool
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'name' => ['required', 'string', 'max:100', Rule::unique('categories', 'name')->withoutTrashed()],
|
||||
'description' => ['nullable', 'string', 'max:225'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace App\Http\Requests\App;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CategoryUpdateRequest extends FormRequest
|
||||
{
|
||||
@ -19,7 +20,7 @@ public function authorize(): bool
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['nullable', 'string', 'max:100'],
|
||||
'name' => ['nullable', 'string', 'max:100', Rule::unique('categories', 'name')->ignore($this->route('categoria'))->withoutTrashed()],
|
||||
'description' => ['nullable', 'string', 'max:225'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace App\Http\Requests\App;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SubcategoryStoreRequest extends FormRequest
|
||||
{
|
||||
@ -11,15 +12,19 @@ public function authorize(): bool
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$uniqueRule = Rule::unique('subcategories', 'name')
|
||||
->where('category_id', $this->route('category')->id)
|
||||
->withoutTrashed();
|
||||
|
||||
if($this->isBulk()) {
|
||||
return [
|
||||
'*.name' => ['required', 'string', 'max:100'],
|
||||
'*.name' => ['required', 'string', 'max:100', $uniqueRule],
|
||||
'*.description' => ['nullable', 'string', 'max:255'],
|
||||
'*.is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'name' => ['required', 'string', 'max:100', $uniqueRule],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace App\Http\Requests\App;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SubcategoryUpdateRequest extends FormRequest
|
||||
{
|
||||
@ -12,7 +13,7 @@ public function authorize(): bool
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['nullable', 'string', 'max:100'],
|
||||
'name' => ['nullable', 'string', 'max:100', Rule::unique('subcategories', 'name')->where('category_id', $this->route('category')->id)->ignore($this->route('subcategory'))->withoutTrashed()],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
|
||||
@ -44,7 +44,7 @@ public function createBundle(array $data): Bundle
|
||||
|
||||
// Permitir override de precio (para promociones)
|
||||
$finalRetailPrice = $data['retail_price'] ?? $totalRetailPrice;
|
||||
$tax = $data['tax'] ?? ($finalRetailPrice * 0.16); // 16% por defecto
|
||||
$tax = $data['tax'] ?? 16.00;
|
||||
|
||||
BundlePrice::create([
|
||||
'bundle_id' => $bundle->id,
|
||||
@ -99,7 +99,7 @@ public function updateBundle(Bundle $bundle, array $data): Bundle
|
||||
}
|
||||
|
||||
$finalRetailPrice = $data['retail_price'] ?? $totalRetailPrice;
|
||||
$tax = $data['tax'] ?? ($finalRetailPrice * 0.16);
|
||||
$tax = $data['tax'] ?? 16.00;
|
||||
|
||||
$bundle->price->update([
|
||||
'cost' => $totalCost,
|
||||
@ -110,7 +110,7 @@ public function updateBundle(Bundle $bundle, array $data): Bundle
|
||||
// Solo actualizar precio sin recalcular componentes
|
||||
$bundle->price->update([
|
||||
'retail_price' => $data['retail_price'],
|
||||
'tax' => $data['tax'] ?? ($data['retail_price'] * 0.16),
|
||||
'tax' => $data['tax'] ?? 16.00,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user