วันพฤหัสบดีที่ 9 กุมภาพันธ์ พ.ศ. 2555

PHP - ใบเสร็จรับเงิน


วันนี้ขอแนะนำตัวอย่างโค้ด PHP + Java เกี่ยวกับการออกใบเสร็จรับเงินที่สามารถสั่งพริ้นออกมาผ่านเครื่องพริ้นได้ทันที และโปรแกรมนี้ยังสามารถสั่งพริ้นใบเสร็จจำนวนกี่ใบก็ได้ตามต้องการ (แค่ต้องมานั่งปรับหน้ากันนิดหน่อยเท่านั้น)
<?php session_start(); ?>
<?php require_once('../include/connect.php'); ?>
<?php require_once('../include/function.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
/*$("#date1").glDatePicker(
{
onChange: function(target, newDate)
{
target.val
(
newDate.getFullYear() + "-" +
(newDate.getMonth() + 1) + "-" +
newDate.getDate()
);
}
});
*/

});
</script>

<body>
<?php

  for ($i=0;$i<count($_POST["show"]);$i++)
  {
 if(trim($_POST["show"][$i]) !="")
 {
  $sql = "select * from offer
inner join member on offer.mem_id=member.mem_id
inner join district on member.dis_id=district.dis_id
inner join province on member.prov_id=province.prov_id
where ido = '".$_POST["show"][$i]."'";
$query = mysql_query($sql);

$result = mysql_query($sql) or exit($sql);

$row = mysql_fetch_array($result);

$id = $row["ido"];
$account          = $row["account"];
$date = $row[".changedate($date)."];
$offerby          = $row["offerby"];
$bank = $row["bank"];
$cheque_bank  = $row["cheque_bank"];
$cheque_no = $row["cheque_no"];
$cheque_date = $row["cheque_date"];
$amount   = $row["amount"];
$purpose = $row["purpose"];
$name = $row["name"];
$address = $row["address"];
$dis_id = $row["dis_id"];
$prov_id = $row["prov_id"];
$postcode = $row["postcode"];
$idm = $row["mem_id"];
$distirct    = $row["dis_name"];
$province = $row["prov_name"];

//  echo "show $i = ".$_POST["show"][$i]."<br>";
?>
<table width="650" border="0" align="center">
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center"><strong>ใบเสร็จรับเงิน</strong>
      <input name="id" type="hidden" id="id" value="<?php echo $_GET["ido"] ?>" />
      <input name="idm" type="hidden" id="idm" value="<?php echo $idm ?>" />
    </td>
  </tr>
  <tr>
    <td height="15" colspan="3" align="right">เลขที่ : <?php echo $row["account"] ?></td>
  </tr>
  <tr>
    <td height="15" colspan="3" align="right">วันที่ : <?php echo date("d/m/Y") ?></td>
  </tr>
  <tr>
    <td height="15" colspan="3">ได้รับเงินจาก : <?php echo $row["name"] ?></td>
  </tr>
  <tr>
    <td height="15" colspan="3">ที่อยู่ : <?php echo $row["address"] ?> <?php echo $row["dis_name"] ?> <?php echo $row["prov_name"] ?> <?php echo $row["postcode"] ?></td>
  </tr>
  <tr>
    <td height="15" colspan="3">เพื่อ : ตามวัตถุประสงค์มูลนิธิฯ</td>
  </tr>
  <tr>
    <td height="15" colspan="3">จำนวน : <?php echo number_format($row["amount"],2, '.', ','); ?> บาท (<?php echo num2string($amount) ?>)</td>
  </tr>
  <tr>
    <td height="15" colspan="3">โดย : <?php echo $row["offerby"] ?> <?php echo $row["bank"] ?> <?php echo $row["cheque_bank"] ?> <?php echo $row["cheque_no"] ?> <?php echo $row["cheque_date"] ?></td>
  </tr>
  <tr>
    <td height="15" colspan="3">ไว้เป็นที่เรียบร้อยด้วยความขอบพระคุณยิ่ง</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td width="368">&nbsp;</td>
    <td width="145" align="center">&nbsp;</td>
    <td width="123" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="368">&nbsp;</td>
    <td align="center">&nbsp;</td>
    <td align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="368">&nbsp;</td>
    <td align="center">ผู้รับเงิน</td>
    <td align="center">เหรัญญิก</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <?php
 }
  }

?>

</table>

<?php
function num2string($amount)
{
$digit=Array("หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า");
$unit=Array("สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน");
if($amount==0)
return "ศูนย์บาทถ้วน";

if(strpos($amount,".")==0)
$amount.=".00";

$tmp=substr($amount,0,strpos($amount,"."));
while(strlen($tmp)>6)
{
$cut=strlen($tmp)%6;
if($cut==0)$cut=6;
$data=substr($tmp,0,$cut);
for($i=0;$i<strlen($data)-2;$i++)
{
    if($data[$i]==0)
      continue;

    $ans.=$digit[$data[$i]-1].$unit[strlen($data)-$i-2];
    }
    $ans.=num2string_2digit(substr($data,strlen($data)-2))."ล้าน";
    $tmp=substr($tmp,$cut);
  }

  for($i=0;$i<strlen($tmp)-2;$i++)
  {
    if($tmp[$i]==0)
    continue;

    $ans.=$digit[$tmp[$i]-1].$unit[strlen($tmp)-$i-2];
  }

  $ans.=num2string_2digit(substr($tmp,strlen($tmp)-2))."บาท";

  $tmp=substr($amount,strpos($amount,".")+1);
  if(substr($tmp,0,2)=="00")
    return $ans."ถ้วน";

  return $ans.num2string_2digit($tmp)."สตางค์";
}
function num2string_2digit($amount)
{
$digit=Array("ศูนย์","หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า");

  $ans="";
  $amount=sprintf("%d",$amount);

  if(strlen($amount)==1)
    return $digit[$amount];

if($amount[0]==2)
    $ans.="ยี่";
  else if($amount[0]>2)
    $ans.=$digit[$amount[0]];

  if($amount[0]>0)
    $ans.="สิบ";

  if($amount[1]>1)
    $ans.=$digit[$amount[1]];
  else if($amount[1]==1)
    $ans.="เอ็ด";

  return $ans;
}

?>

</p>
</body>
</html>
อ้อ ถ้าอยากจะให้ font สวยกว่านี้ก็คงต้องใช้ css ช่วยอีกหน่อย รับรองแจ่มค่ะ

ไม่มีความคิดเห็น:

แสดงความคิดเห็น