<?php
// Mocking the math from js/purchase.js
function calculatePurchase($gross, $bori, $tara, $kat, $rate, $basis) {
    echo "Inputs: Gross=$gross, Bori=$bori, Tara=$tara, Kat=$kat, Rate=$rate, Basis=$basis\n";
    
    $totalTara = $bori * $tara;
    $netWeight = $gross - $totalTara - $kat;
    $netWeightDisplay = $netWeight > 0 ? number_format($netWeight, 2) : "0.00";
    
    echo "Total Tara: $totalTara\n";
    echo "Net Weight: $netWeightDisplay\n";
    
    $grossAmount = 0;
    if ($netWeight > 0 && $rate > 0) {
        $grossAmount = ($netWeight / $basis) * $rate;
    }
    
    echo "Gross Amount: " . number_format($grossAmount, 2) . "\n";
    return $grossAmount;
}

echo "--- Test 1 (User's values) ---\n";
// User's values: Gross 100, Bori 100, Tara 1.00, Kat 10, Rate 10, Basis 40
calculatePurchase(100, 100, 1.00, 10, 10, 40);

echo "\n--- Test 2 (Normal values) ---\n";
// Normal values: Gross 4000, Bori 100, Tara 1.00, Kat 10, Rate 4500, Basis 40
calculatePurchase(4000, 100, 1.00, 10, 4500, 40);
