fix: [sales,pricing] 매출 0원 + 단가 수정 0원 수정
This commit is contained in:
@@ -180,16 +180,18 @@ public static function createFromOrder(Order $order, string $saleNumber): self
|
||||
*/
|
||||
public static function createFromShipment(Shipment $shipment, string $saleNumber): self
|
||||
{
|
||||
$order = $shipment->order;
|
||||
|
||||
return new self([
|
||||
'tenant_id' => $shipment->tenant_id,
|
||||
'order_id' => $shipment->order_id,
|
||||
'shipment_id' => $shipment->id,
|
||||
'sale_number' => $saleNumber,
|
||||
'sale_date' => $shipment->shipped_date ?? now()->toDateString(),
|
||||
'client_id' => $shipment->order?->client_id,
|
||||
'supply_amount' => $shipment->total_amount / 1.1, // 세전 역산
|
||||
'tax_amount' => $shipment->total_amount - ($shipment->total_amount / 1.1),
|
||||
'total_amount' => $shipment->total_amount,
|
||||
'client_id' => $order?->client_id,
|
||||
'supply_amount' => $order?->supply_amount ?? 0,
|
||||
'tax_amount' => $order?->tax_amount ?? 0,
|
||||
'total_amount' => $order?->total_amount ?? 0,
|
||||
'description' => "출하 {$shipment->shipment_no} 매출",
|
||||
'status' => 'draft',
|
||||
'source_type' => self::SOURCE_SHIPMENT_COMPLETE,
|
||||
|
||||
@@ -188,10 +188,13 @@ public function update(int $id, array $data): Price
|
||||
$data['updated_by'] = $userId;
|
||||
$price->update($data);
|
||||
|
||||
// 판매단가 재계산 (관련 필드가 변경된 경우)
|
||||
// 판매단가 재계산 (관련 필드가 변경된 경우, 계산 가능할 때만)
|
||||
if ($this->shouldRecalculateSalesPrice($data)) {
|
||||
$price->sales_price = $price->calculateSalesPrice();
|
||||
$price->save();
|
||||
$calculated = $price->calculateSalesPrice();
|
||||
if ($calculated !== null) {
|
||||
$price->sales_price = $calculated;
|
||||
$price->save();
|
||||
}
|
||||
}
|
||||
|
||||
$price->refresh();
|
||||
|
||||
Reference in New Issue
Block a user