diff --git a/app/Http/Controllers/App/InventorySerialController.php b/app/Http/Controllers/App/InventorySerialController.php index c485395..18179d0 100644 --- a/app/Http/Controllers/App/InventorySerialController.php +++ b/app/Http/Controllers/App/InventorySerialController.php @@ -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')) { diff --git a/app/Http/Requests/App/BundleStoreRequest.php b/app/Http/Requests/App/BundleStoreRequest.php index d7ecb09..0b6cbb0 100644 --- a/app/Http/Requests/App/BundleStoreRequest.php +++ b/app/Http/Requests/App/BundleStoreRequest.php @@ -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'], diff --git a/app/Http/Requests/App/BundleUpdateRequest.php b/app/Http/Requests/App/BundleUpdateRequest.php index 5794d49..b8c81a4 100644 --- a/app/Http/Requests/App/BundleUpdateRequest.php +++ b/app/Http/Requests/App/BundleUpdateRequest.php @@ -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'], diff --git a/app/Http/Requests/App/CategoryStoreRequest.php b/app/Http/Requests/App/CategoryStoreRequest.php index 59a4a0d..1cd8a9b 100644 --- a/app/Http/Requests/App/CategoryStoreRequest.php +++ b/app/Http/Requests/App/CategoryStoreRequest.php @@ -1,6 +1,7 @@ ['required', 'string', 'max:100'], + 'name' => ['required', 'string', 'max:100', Rule::unique('categories', 'name')->withoutTrashed()], 'description' => ['nullable', 'string', 'max:225'], 'is_active' => ['nullable', 'boolean'], ]; diff --git a/app/Http/Requests/App/CategoryUpdateRequest.php b/app/Http/Requests/App/CategoryUpdateRequest.php index c7e2679..ffc53a7 100644 --- a/app/Http/Requests/App/CategoryUpdateRequest.php +++ b/app/Http/Requests/App/CategoryUpdateRequest.php @@ -1,6 +1,7 @@ ['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'], ]; diff --git a/app/Http/Requests/App/SubcategoryStoreRequest.php b/app/Http/Requests/App/SubcategoryStoreRequest.php index 5a99127..37fb74d 100644 --- a/app/Http/Requests/App/SubcategoryStoreRequest.php +++ b/app/Http/Requests/App/SubcategoryStoreRequest.php @@ -1,6 +1,7 @@ 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'], ]; diff --git a/app/Http/Requests/App/SubcategoryUpdateRequest.php b/app/Http/Requests/App/SubcategoryUpdateRequest.php index 9d8d8fb..85671ee 100644 --- a/app/Http/Requests/App/SubcategoryUpdateRequest.php +++ b/app/Http/Requests/App/SubcategoryUpdateRequest.php @@ -1,6 +1,7 @@ ['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'], ]; diff --git a/app/Services/BundleService.php b/app/Services/BundleService.php index 6b50533..7bdcb05 100644 --- a/app/Services/BundleService.php +++ b/app/Services/BundleService.php @@ -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, ]); }