账单总金额
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -55,7 +55,10 @@ class PurchaseOrderController extends BaseController
|
|||||||
{
|
{
|
||||||
$params = $request->all();
|
$params = $request->all();
|
||||||
$pageSize = $params['pageSize'] ?? 10;
|
$pageSize = $params['pageSize'] ?? 10;
|
||||||
$data = $this->buildSearch($params, PurchaseOrderModel::query()->with('operator:id,nickname'))
|
$data = $this->buildSearch($params, PurchaseOrderModel::query()
|
||||||
|
->with('operator:id,nickname')
|
||||||
|
// 应付商品金额 = Σ 已生成门店账单的商品金额(实际口径;未生成账单为 null)
|
||||||
|
->withSum('bills as bill_product_amount', 'product_amount'))
|
||||||
->orderBy('purchase_date', 'desc')
|
->orderBy('purchase_date', 'desc')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($pageSize)
|
->paginate($pageSize)
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ class PurchaseOrderModel extends Model
|
|||||||
'actual_amount' => 'decimal:2',
|
'actual_amount' => 'decimal:2',
|
||||||
'operator_id' => 'integer',
|
'operator_id' => 'integer',
|
||||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||||
|
// 列表 withSum 聚合属性(应付商品金额;无账单时保持 null)
|
||||||
|
'bill_product_amount' => 'decimal:2',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,4 +71,12 @@ class PurchaseOrderModel extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(StoreOrderModel::class, 'purchase_id', 'id');
|
return $this->hasMany(StoreOrderModel::class, 'purchase_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本采购单生成的门店账单
|
||||||
|
*/
|
||||||
|
public function bills(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(BillModel::class, 'purchase_id', 'id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -741,4 +741,28 @@ class PurchaseEditTest extends ProcurementTestCase
|
|||||||
->assertJsonPath('data.count', 0);
|
->assertJsonPath('data.count', 0);
|
||||||
$this->assertSame(0, PurchaseItemCheckModel::count());
|
$this->assertSame(0, PurchaseItemCheckModel::count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 采购单列表「应付商品金额」列 = Σ 已生成门店账单的商品金额(未生成账单为 null) */
|
||||||
|
public function test_list_includes_bill_product_amount(): void
|
||||||
|
{
|
||||||
|
[$purchase, , $stores] = $this->buildPurchase();
|
||||||
|
$this->actingAsSysUser();
|
||||||
|
|
||||||
|
// 未生成账单 → null
|
||||||
|
$this->getJson('/purchase/order')
|
||||||
|
->assertJsonPath('data.data.0.bill_product_amount', null);
|
||||||
|
|
||||||
|
// 完成采购单并生成两店账单(各店商品金额 = 数量 × 等级价 10.00)
|
||||||
|
$purchase->update(['status' => PurchaseOrderModel::STATUS_COMPLETED]);
|
||||||
|
$this->postJson("/purchase/order/{$purchase->id}/bill", [
|
||||||
|
'stores' => [
|
||||||
|
['store_id' => $stores[0]->id, 'delivery_fee' => 0, 'box_num' => 0, 'tray_num' => 0],
|
||||||
|
['store_id' => $stores[1]->id, 'delivery_fee' => 0, 'box_num' => 0, 'tray_num' => 0],
|
||||||
|
],
|
||||||
|
])->assertJsonPath('success', true);
|
||||||
|
|
||||||
|
// 列表回显:2×10.00 + 3×10.00 = 50.00
|
||||||
|
$this->getJson('/purchase/order')
|
||||||
|
->assertJsonPath('data.data.0.bill_product_amount', '50.00');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ export default interface IPurchaseOrder {
|
|||||||
total_weight?: string;
|
total_weight?: string;
|
||||||
estimate_amount?: string;
|
estimate_amount?: string;
|
||||||
actual_amount?: string;
|
actual_amount?: string;
|
||||||
|
/** 应付商品金额 = Σ 已生成门店账单的商品金额(列表接口附;未生成账单为 null) */
|
||||||
|
bill_product_amount?: string | null;
|
||||||
operator_id?: number;
|
operator_id?: number;
|
||||||
operator?: { id: number; nickname: string };
|
operator?: { id: number; nickname: string };
|
||||||
remark?: string;
|
remark?: string;
|
||||||
|
|||||||
@@ -1100,6 +1100,19 @@ const PurchaseOrderPage: React.FC = () => {
|
|||||||
<Text type="secondary">未录入</Text>
|
<Text type="secondary">未录入</Text>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '应付商品金额',
|
||||||
|
dataIndex: 'bill_product_amount',
|
||||||
|
hideInForm: true,
|
||||||
|
hideInSearch: true,
|
||||||
|
align: 'center',
|
||||||
|
render: (_, record) =>
|
||||||
|
record.bill_product_amount != null ? (
|
||||||
|
<Text strong type="danger">¥{Number(record.bill_product_amount).toFixed(2)}</Text>
|
||||||
|
) : (
|
||||||
|
<Text type="secondary">未生成账单</Text>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '总件数',
|
title: '总件数',
|
||||||
dataIndex: 'total_quantity',
|
dataIndex: 'total_quantity',
|
||||||
|
|||||||
Reference in New Issue
Block a user