采购单优化
This commit is contained in:
@@ -20,6 +20,7 @@ use Modules\AnnoRoute\Attribute\PutRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Modules\Common\Http\Controllers\BaseController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 采购单管理(C1 汇总生成 / C2-C3 导出 / C4 修改)
|
||||
@@ -213,33 +214,8 @@ class PurchaseOrderController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* C4 门店单元格修改:数量/称重回写订货明细,金额重算并同步订单/采购单汇总
|
||||
*/
|
||||
#[PutRoute(route: '/cell/{id}', authorize: 'update', where: ['id' => '[0-9]+'])]
|
||||
public function updateCell(int $id, PurchaseCellUpdateRequest $request): JsonResponse
|
||||
{
|
||||
$item = StoreOrderItemModel::find($id);
|
||||
if (empty($item)) {
|
||||
throw new RepositoryException('订货明细不存在');
|
||||
}
|
||||
$validated = $request->validated();
|
||||
|
||||
$item = app(PurchaseEditService::class)->updateCell(
|
||||
$item,
|
||||
(int) $validated['quantity'],
|
||||
isset($validated['weight']) ? (float) $validated['weight'] : null,
|
||||
);
|
||||
|
||||
return $this->success([
|
||||
'quantity' => (int) $item->quantity,
|
||||
'weight' => (float) $item->weight,
|
||||
'amount' => (float) $item->amount,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* C4 商品行修改:品名/供应商/包规/单位/成本一键同步该商品全部订货明细;
|
||||
* 实际称重按数量比例分摊(尾差修正守恒)
|
||||
* 商品行修改:品名/供应商/包规/单位/成本一键同步该商品全部订货明细;
|
||||
* @throws Throwable
|
||||
*/
|
||||
#[PutRoute(route: '/{id}/row/{productId}', authorize: 'update', where: ['id' => '[0-9]+', 'productId' => '[0-9]+'])]
|
||||
public function updateRow(int $id, int $productId, PurchaseRowUpdateRequest $request): JsonResponse
|
||||
@@ -256,16 +232,14 @@ class PurchaseOrderController extends BaseController
|
||||
$attrs[$field] = $validated[$field];
|
||||
}
|
||||
}
|
||||
$weight = isset($validated['weight']) ? (float) $validated['weight'] : null;
|
||||
if ($attrs === [] && $weight === null) {
|
||||
throw new RepositoryException('品名/供应商/包规/单位/成本/实际称重至少填写一项');
|
||||
if ($attrs === []) {
|
||||
throw new RepositoryException('品名/供应商/包规/单位/成本至少填写一项');
|
||||
}
|
||||
|
||||
$count = app(PurchaseEditService::class)->updateRow(
|
||||
$purchase,
|
||||
$productId,
|
||||
$attrs,
|
||||
$weight,
|
||||
(bool) ($validated['sync_product'] ?? false),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user