feat: 修正庫存與撥補單邏輯並整合文件
1. 修復倉庫統計數據加總與樣式。 2. 修正可用庫存計算邏輯(排除不可銷售倉庫)。 3. 撥補單商品列表加入批號與效期顯示。 4. 修正撥補單儲存邏輯以支援精確批號轉移。 5. 整合 FEATURES.md 至 README.md。
This commit is contained in:
@@ -4,15 +4,21 @@ namespace App\Modules\Procurement\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Modules\Procurement\Models\Vendor;
|
||||
|
||||
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class VendorController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected InventoryServiceInterface $inventoryService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* 顯示資源列表。
|
||||
*/
|
||||
public function index(\Illuminate\Http\Request $request): \Inertia\Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = Vendor::query();
|
||||
|
||||
@@ -44,28 +50,71 @@ class VendorController extends Controller
|
||||
->paginate($perPage)
|
||||
->withQueryString();
|
||||
|
||||
return \Inertia\Inertia::render('Vendor/Index', [
|
||||
$vendors->getCollection()->transform(function ($vendor) {
|
||||
return (object) [
|
||||
'id' => (string) $vendor->id,
|
||||
'code' => $vendor->code,
|
||||
'name' => $vendor->name,
|
||||
'shortName' => $vendor->short_name,
|
||||
'taxId' => $vendor->tax_id,
|
||||
'owner' => $vendor->owner,
|
||||
'contactName' => $vendor->contact_name,
|
||||
'phone' => $vendor->phone,
|
||||
'tel' => $vendor->tel,
|
||||
'email' => $vendor->email,
|
||||
'address' => $vendor->address,
|
||||
'remark' => $vendor->remark,
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('Vendor/Index', [
|
||||
'vendors' => $vendors,
|
||||
'filters' => $request->only(['search', 'sort_field', 'sort_direction', 'per_page']),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
* 顯示指定資源。
|
||||
*/
|
||||
public function show(Vendor $vendor): \Inertia\Response
|
||||
public function show(Vendor $vendor): Response
|
||||
{
|
||||
$vendor->load(['products.baseUnit', 'products.largeUnit']);
|
||||
return \Inertia\Inertia::render('Vendor/Show', [
|
||||
'vendor' => $vendor,
|
||||
'products' => \App\Modules\Inventory\Models\Product::with('baseUnit')->get(),
|
||||
|
||||
$formattedVendor = (object) [
|
||||
'id' => (string) $vendor->id,
|
||||
'code' => $vendor->code,
|
||||
'name' => $vendor->name,
|
||||
'shortName' => $vendor->short_name,
|
||||
'taxId' => $vendor->tax_id,
|
||||
'owner' => $vendor->owner,
|
||||
'contactName' => $vendor->contact_name,
|
||||
'phone' => $vendor->phone,
|
||||
'tel' => $vendor->tel,
|
||||
'email' => $vendor->email,
|
||||
'address' => $vendor->address,
|
||||
'remark' => $vendor->remark,
|
||||
'supplyProducts' => $vendor->products->map(fn($p) => (object) [
|
||||
'id' => (string) $p->pivot->id,
|
||||
'productId' => (string) $p->id,
|
||||
'productName' => $p->name,
|
||||
'unit' => $p->baseUnit?->name ?? 'N/A',
|
||||
'baseUnit' => $p->baseUnit?->name,
|
||||
'largeUnit' => $p->largeUnit?->name,
|
||||
'conversionRate' => (float) $p->conversion_rate,
|
||||
'lastPrice' => (float) $p->pivot->last_price,
|
||||
]),
|
||||
];
|
||||
|
||||
return Inertia::render('Vendor/Show', [
|
||||
'vendor' => $formattedVendor,
|
||||
'products' => $this->inventoryService->getAllProducts(), // 使用已有的服務獲取所有商品供選取
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* 將新建立的資源儲存到儲存體中。
|
||||
*/
|
||||
public function store(\Illuminate\Http\Request $request)
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
@@ -80,7 +129,7 @@ class VendorController extends Controller
|
||||
'remark' => 'nullable|string',
|
||||
]);
|
||||
|
||||
// Auto-generate code
|
||||
// 自動產生代碼
|
||||
$prefix = 'V';
|
||||
$lastVendor = Vendor::latest('id')->first();
|
||||
$nextId = $lastVendor ? $lastVendor->id + 1 : 1;
|
||||
@@ -94,9 +143,9 @@ class VendorController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* 更新儲存體中的指定資源。
|
||||
*/
|
||||
public function update(\Illuminate\Http\Request $request, Vendor $vendor)
|
||||
public function update(Request $request, Vendor $vendor)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
@@ -117,7 +166,7 @@ class VendorController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* 從儲存體中移除指定資源。
|
||||
*/
|
||||
public function destroy(Vendor $vendor)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user