Skip to content

Instantly share code, notes, and snippets.

@oritromax
Forked from sarim/bill.php
Last active October 18, 2015 07:16
Show Gist options
  • Save oritromax/3735d1183ffd4ae07a16 to your computer and use it in GitHub Desktop.
Save oritromax/3735d1183ffd4ae07a16 to your computer and use it in GitHub Desktop.
<?php
if(isset($_GET['unit'])) {
$userunit = $_GET['unit'];
$bills = array (
array (
'min' => 1,
'max' => 75,
'price' => 3.8
),
array (
'min' => 76,
'max' => 200,
'price' => 5.14
),
array (
'min' => 201,
'max' => 300,
'price' => 5.36
),
array (
'min' => 301,
'max' => 400,
'price' => 5.63
),
array (
'min' => 401,
'max' => 600,
'price' => 8.7
),
array (
'min' => 601,
'max' => 1000000,
'price' => 9.98
)
);
$billedUnit = $userunit;
$processed = $billedUnit;
$totalCost = 0;
foreach ($bills as &$bill) {
$amount = NULL;
if ($processed == 0) {
break;
}
$maxAmount = $bill['max'] - $bill['min'] + 1;
if ($maxAmount <= $processed) {
$amount = $maxAmount;
} else {
$amount = $processed;
}
$bill['amount'] = $amount;
$bill['cost'] = $amount * $bill['price'];
$totalCost += $bill['cost'];
$processed -= $amount;
}
$totalCost = $totalCost + 55;
$totalCost = ((5 / 100) * $totalCost) + $totalCost;
if(isset($_GET['type'])){
if($_GET['type']=='json'){
header('Content-Type: application/json');
echo json_encode($totalCost);
}
} else {
echo "Total + Vat: \t $totalCost BDT";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment