<?php

namespace App\Helpers;

use App\Models\CustomerPricing;
use App\Models\Product;

class PriceHelper
{
    public static function getCustomerSalePrice($customerNo, $productCode)
    {
        $product = Product::where('ProductCode', $productCode)->first();

        if (!$product) {
            return null;
        }

        $basePrice = round((float) $product->SalePrice, 2);

        $pricing = CustomerPricing::where('CustomerNo', $customerNo)
            ->where('ProductNo', $productCode)
            ->first();

        if ($pricing) {
            return round((float) $pricing->SalePrice, 2);
        }

        return $basePrice;
    }
}
