diff --git a/app/Models/Tenants/Sale.php b/app/Models/Tenants/Sale.php index ac1ecd36..d6c01dcd 100644 --- a/app/Models/Tenants/Sale.php +++ b/app/Models/Tenants/Sale.php @@ -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, diff --git a/app/Services/PricingService.php b/app/Services/PricingService.php index 16d022df..914d7052 100644 --- a/app/Services/PricingService.php +++ b/app/Services/PricingService.php @@ -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();