/** * Function: convert_number * * Description: * Converts a given integer (in range [0..1T-1], inclusive) into * alphabetical format ("one", "two", etc.) * * @int * * @return string * */ function convert_number($number) { if ($number < 0 || $number > 999999999) { throw new Exception("Number is out of range"); } $Cn = floor($number / 10000000); /* Millions (giga) */ $number -= $Cn * 10000000; $Ln = floor($number / 100000); /* Millions (giga) */ $number -= $Ln * 100000; $kn = floor($number / 1000); /* Thousands (kilo) */ $number -= $kn * 1000; $Hn = floor($number / 100); /* Hundreds (hecto) */ $number -= $Hn * 100; $Dn = floor($number / 10); /* Tens (deca) */ $n = $number % 10; /* Ones */ $res = ""; if ($Cn) { $res .= convert_number($Cn) . " Crore"; } if ($Ln) { $res .= convert_number($Ln) . " Lac"; } if ($kn) { $res .= (empty($res) ? "" : " ") . convert_number($kn) . " Thousand"; } if ($Hn) { $res .= (empty($res) ? "" : " ") . convert_number($Hn) . " Hundred"; } $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen"); $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eigthy", "Ninety"); if ($Dn || $n) { if (!empty($res)) { $res .= " and "; } if ($Dn < 2) { $res .= $ones[$Dn * 10 + $n]; } else { $res .= $tens[$Dn]; if ($n) { $res .= "-" . $ones[$n]; } } } if (empty($res)) { $res = "zero"; } return $res; }
function getTexCommandName($txt) { //var_dump($txt); for ($i = 1000; $i >= 0; $i--) { $str = (string) $i; if (strlen(strstr($txt, $str)) > 0) { $word = convert_number($i); $txt = str_replace($str, $word, $txt); //break; } } $txt = str_replace(".", "dot", $txt); $txt = str_replace("-", "", $txt); $txt = str_replace("/", "", $txt); $txt = str_replace("ä", "ae", $txt); $txt = str_replace("ü", "ou", $txt); $txt = str_replace("ö", "oe", $txt); $txt = str_replace("è", "e", $txt); $txt = str_replace(":", "", $txt); $res = str_replace(' ', '', $txt); return $res; }
function generateSalesReport() { $dao = new DAO(); $invoiceNo = $_REQUEST['invoiceNo']; $invoiceDetails = $dao->getSalesInvoiceByInvoiceNo($invoiceNo); $salesDetails = $dao->getSalesEntryByInvoiceNo($invoiceNo); $totalWeight = 0; $totalLitres = 0; foreach ($salesDetails as $key => $data) { $totalWeight = $totalWeight + $data['totalWeight']; $totalLitres = $totalLitres + $data['totalLitres']; } $invoiceDetails['partyName'] = $dao->getDistributorByID($invoiceDetails['partyName']); $invoiceDetails['salesmanID'] = $dao->getEmployeeNameByID($invoiceDetails['salesmanID']); $invoiceDetails['transporterID'] = $dao->getTransporterNameByID($invoiceDetails['transporterID']); //echo convert_number(1263000); $totalAmountInWords = convert_number($invoiceDetails['totalAmountAfterTax']); //echo "<pre>"; //print_r($invoiceDetails); //print_r($salesDetails); include "../view/generatedSalesReport.php"; }
</tr> <tr> <td > Total Fees: </td> <td > <?php echo sprintf('%0.2f', $total_fee); ?> </td> </tr> <tr> <td > Amount: <?php echo $wrd = convert_number($total_fee) . " Only"; ?> </td> </tr> </tr> <tr> <td colspan="2"> <center> <button class="btn btn-primary" type="button"> Make payment</button> </center> </td> </tr>
function convert_number($number) { if ($number < 0 || $number > 999999999) { throw new Exception("Nombor diluar dari julat"); } $Gn = floor($number / 1000000); /* Millions (giga) */ $number -= $Gn * 1000000; $kn = floor($number / 1000); /* Thousands (kilo) */ $number -= $kn * 1000; $Hn = floor($number / 100); /* Hundreds (hecto) */ $number -= $Hn * 100; $Dn = floor($number / 10); /* Tens (deca) */ $n = $number % 10; /* Ones */ $res = ""; if ($Gn) { $res .= convert_number($Gn) . " Juta"; } if ($kn) { $res .= (empty($res) ? "" : " ") . convert_number($kn) . " Ribu"; } if ($Hn) { $res .= (empty($res) ? "" : " ") . convert_number($Hn) . " Ratus"; } $ones = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Lapan", "Sembilan", "Sepuluh", "Sebelas", "Dua Belas", "Tiga Belas", "Empat Belas", "Lima Belas", "Enam Belas", "Tujuh Belas", "Lapan Belas", "Sembilan Belas"); $tens = array("", "", "Dua Puluh", "Tiga Puluh", "Empat Puluh", "Lima Puluh", "Enam Puluh", "Tujuh Puluh", "Lapan Puluh", "Sembilan Puluh"); if ($Dn || $n) { if (!empty($res)) { $res .= " "; //$res .= " dan "; } if ($Dn < 2) { $res .= $ones[$Dn * 10 + $n]; } else { $res .= $tens[$Dn]; if ($n) { $res .= " " . $ones[$n]; //$res .= "-" . $ones[$n]; } } } if (empty($res)) { $res = "kosong"; } return $res; }