<meta charset="utf-8">
<?php
    require('conn/conn_mssql.php');
    $VCID =$_GET['VCID'];
	
 function moneytotext($m){
    If ($m == ""){
        return "";
	}
	$m=str_replace(",", "", $m);
	if(! is_numeric($m)){
		return "";
	}
    $mtext = number_format($m, 2, '.', '');
    $totdigit = strlen($mtext) - 3;
    $outtext = "";
    //หน้าทศนิยม
    for ($i=$totdigit;$i>=1;$i--){
        $c = substr($mtext, $i-1, 1);
        $cdigit = $totdigit + 1 - $i;
        //ตัวเลข
        switch ($c){
        case "0":
            if ($cdigit == 7 and $totdigit > 7 ){
                $t = "ศูนย์";
			}else{
                $t = "";
			}
			break;
        case "1":
            if ($cdigit == 1 and $totdigit > 1 or $cdigit == 7 and $totdigit > 7 ){
                $t = "เอ็ด";
			}else{
                $t = "หนึ่ง";
            }
			break;
        case "2":
            if ($cdigit == 2 or $cdigit == 8){
                $t = "ยี่";
			}else{
                $t = "สอง";
			}
			break;
		case "3":
            $t = "สาม";
			break;
        case "4":
            $t = "สี่";
			break;
        case "5":
            $t = "ห้า";
			break;
        case "6":
            $t = "หก";
			break;
        case "7":
            $t = "เจ็ด";
			break;
        case "8":
            $t = "แปด";
			break;
        case "9":
            $t = "เก้า";
			break;
        default :
            $t = "";
        }
        //หลัก
        if ($t <> ""){
            switch ($cdigit){
            case 1:  //หน่วย
                $d = "";
				break;
            case 2:  //สิบ
                if ($t == "หนึ่ง"){
                    $t = "";
				}
                $d = "สิบ";
				break;
            case 3:  //ร้อย
                $d = "ร้อย";
				break;
            case 4:  //พัน
                $d = "พัน";
				break;
            case 5:  //หมื่น
                $d = "หมื่น";
				break;
            case 6:  //แสน
                $d = "แสน";
				break;
            case 7:  //ล้าน
                if ($t == "ศูนย์"){
                    $t = "";
				}
                $d = "ล้าน";
				break;
            case 8:  //สิบล้าน
                if ($t == "หนึ่ง"){
                    $t = "";
				}
                $d = "สิบ";
				break;
            case 9: //ร้อยล้าน
                $d = "ร้อย";
				break;
            case 10: //พันล้าน
                $d = "พัน";
				break;
            default :
                $d = "";
            }
        }
		else{
            $d = "";
		}	
        $outtext = $t.$d.$outtext;
	}
    if ($outtext <> ""){
        $outtext = $outtext ."บาท";
	}
    
    //หลัง ทศนิยม ตำแหน่งที่ 1
    switch (substr($mtext, strlen($mtext) - 2, 1)){
        case "1":
            $d01 = "สิบ";
			break;
        case "2":
            $d01 = "ยี่สิบ";
			break;
        case "3":
            $d01 = "สามสิบ";
			break;
        case "4":
            $d01 = "สี่สิบ";
			break;
        case "5";
            $d01 = "ห้าสิบ";
			break;
        case "6":
            $d01 = "หกสิบ";
			break;
        case "7":
            $d01 = "เจ็ดสิบ";
			break;
        case "8":
            $d01 = "แปดสิบ";
			break;
        case "9":
            $d01 = "เก้าสิบ";
			break;
        default:
            $d01 = "";
    }
    //ทศนิยม ตำแหน่งที่ 2
    switch (substr($mtext, strlen($mtext)-1, 1)){
        case "1":
            if ($d01 <> ""){
                $d02 = "เอ็ด";
			}else{
                $d02 = "หนึ่ง";
            }
			break;
        case "2":
            $d02 = "สอง";
			break;
        case "3":
            $d02 = "สาม";
			break;
        case "4":
            $d02 = "สี่";
			break;
        case "5":
            $d02 = "ห้า";
			break;
        case "6":
            $d02 = "หก";
			break;
        case "7":
            $d02 = "เจ็ด";
			break;
        case "8":
            $d02 = "แปด";
			break;
        case "9":
            $d02 = "เก้า";
			break;
        default:
            $d02 = "";
    }
    if ($d01.$d02 <> ""){
        $d02 = $d02 ."สตางค์";
    }
    
    if ($d01.$d02 <> ""){
        $outtext = $outtext.$d01.$d02;
	}
    else{
        $outtext = $outtext."ถ้วน";
    }
    return $outtext;
 }
	
	
	
function format_dateD($fulldate1){
    $day = substr($fulldate1,-2,2);
   // $month = substr($fulldate1,-5,2);
   // $year = substr($fulldate1,-10,4);
   //$fulldate1 = $day ."/".$month."/".$year ;
    $fulldate1 = $day  ;
    return $fulldate1;
}
function format_dateM($fulldate1){
   // $day = substr($fulldate1,-2,2);
     $month = substr($fulldate1,-5,2);
   // $year = substr($fulldate1,-10,4);
   //$fulldate1 = $day ."/".$month."/".$year ;
    $fulldate1 = $month  ;
    return $fulldate1;
}

function format_dateY($fulldate1){
   // $day = substr($fulldate1,-2,2);
   //  $month = substr($fulldate1,-5,2);
    $year = substr($fulldate1,-10,4);
   //$fulldate1 = $day ."/".$month."/".$year ;
    $fulldate1 = $year  ;
    return $fulldate1;
}
	
function format_dateDMY($fulldate1){
    $day = substr($fulldate1,-2,2);
    $month = substr($fulldate1,-5,2);
    $year = substr($fulldate1,-10,4);
    $fulldate1 = $day ."/".$month."/".$year ;
   // $fulldate1 = $year  ;
    return $fulldate1;
}	
	
	
 $sql_code="select   *    from   vw_VCPrint    where   VCID    like  '$VCID'     order by  VCID Desc ";
 $query_code=$conn->prepare($sql_code);
 $query_code->execute();
 $result_code = $query_code->fetch( PDO::FETCH_ASSOC);
	
$VCID =   $result_code['VCID'] ;
$VCDate  = $result_code['VCDate'] ;	
$VCDealerName = $result_code['VCDealerName'] ;	
$VCAddr   = $result_code['DealerAddr1']." ".$result_code['DealerAddr2']."  โทร.".$result_code['DealerPhone'] ;	
$VCDealerBranchName = 	$result_code['VCDealerBranchName'] ;	
	

	
//$txtDRepTax   = "ภาษีหัก ณ ที่จ่าย  ".number_format($TaxPercent,2)."% เป็นเงิน  ".number_format($dat['TotalTaxBath'],2)                                   ;	
	
	
	
	
	
	
	
	
	
//$sql_code="select   *    from   vw_VCPrint    where   VCID    like  '$VCID'     order by  VCID Desc ";
//$query_code=$conn->prepare($sql_code);
//$query_code->execute();
//while($result_code = $query_code->fetch( PDO::FETCH_ASSOC)){


//$VCID =   $result_code['VCID'] ;
//$VCDate  = $result_code['VCDate'] ;


//}	
	

	
	?>
	
	
<?php
$header = '

  <table width="100%" border="0" cellpadding="1" cellspacing="1" >
    <tr>
    <td colspan="2" align = "right">หน้าที่   {PAGENO} จาก  {nb} </td>
  </tr>
  <tr>
    <td colspan="2" align="center" ><h2>'.$VCDealerName.'</h2></td>
  </tr>
  <tr>
    <td colspan="2"  align="center"><div align="center">'.$VCAddr.'</div></td>
  </tr>
  
  
  <tr>
    <td colspan="2"height="40"  >&nbsp;</td>
  </tr>
  
  
  <tr>
    <td colspan="2" align="center"><h3>ใบสำคัญจ่ายเงินสดย่อย   ('.$VCDealerBranchName.')</h3></td>
  </tr>
  <tr>
    <td >&nbsp;</td>
    <td >เลขที่  &nbsp;&nbsp; '.$VCID.'</td>
  </tr>
  <tr>
    <td width="75%" >&nbsp;</td>
    <td width="25%" >วันที่ &nbsp;&nbsp; '.format_dateDMY($VCDate).'</td>
  </tr>
  
 
  
  <tr>
    <td colspan="2" >ชื่อบัญชี____________________________________________________________________________________________</td>
  </tr>
</table>
		
';	

?>	
	
	
	
	
	
<?php

$htmlele = '
<meta charset="utf-8">

<!DOCTYPE html>
<html> 
<head>
<title>ใบสำคัญจ่ายเงินสดย่อย</title>
</head>   
<body>
<style>
body{
    font-family: "Garuda";
    font-size: 9pt;
}
.thai2{
    font-family: "Garuda";
}


.coltablerbso{
BORDER-RIGHT: #000000 1px solid ; BORDER-BOTTOM: #000000 1px solid;
}


.coltableroundso{
BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid ;BORDER-TOP: #000000 1px solid;
}


.colBottomso{
BORDER-BOTTOM: #000000 1px solid;
}

.colrso{
BORDER-RIGHT: #000000 1px solid ; 

}

.collso{
BORDER-Left: #000000 1px solid ; 
}

.coltoprso{
BORDER-RIGHT: #000000 1px solid ; BORDER-TOP: #000000 1px solid;
}

.coltopso{
BORDER-TOP: #000000 1px solid;
}

</style>

';





?>

<?php







$htmlele .='
<table width="100%" style="font-size: 10pt; border-collapse: collapse; " cellpadding="2" cellspacing="4" class = "coltableroundso">
<thead>
<tr >
<td width="12%"  align ="center" class = "colrso"  >วัน.เดือน.ปี</td>
<td width="24%" align ="center" class = "colrso" >จ่ายให้</td>
<td width="40%"  align ="center"  class = "colrso">รายการ</td>
<td width="12%" align ="center" class = "colrso">ยอดเงิน</td>
<td width="12%" align ="center">ผู้อนุมัติ</td>
</tr>
</thead>
<tbody>
';

?>
<?php



// $sql_paycash="SELECT *  FROM vw_VCDet  WHERE VCID like  '$VCID' order by PayCashID , PayCashDetID    ";
    //            $query_paycash=$conn->prepare($sql_paycash);
              //  $query_paycash->execute();
      //          while($result_paycash = $query_paycash->fetch( PDO::FETCH_ASSOC)){
					

	 $sql_paycash="SELECT *  FROM tbvw_VCDet_Temp  WHERE VCID like  '$VCID' order by PayCashID , PayCashDetID    ";
                $query_paycash=$conn->prepare($sql_paycash);
                $query_paycash->execute();
              while($result_paycash = $query_paycash->fetch( PDO::FETCH_ASSOC)){				
					
					

 if($result_paycash['PayCashID']== $PayCashID  ) { 
 
 
 //---------------------------------------------------               
$htmlele .='


<!-- ITEMS HERE -->
<tr>
<td   align="center"  class="colrso"></td>
<td  align="center" class="colrso"></td>
<td  align="left" class="colrso">'.$result_paycash['PayCashDetDetail'].'</td>
<td  align="right" class="colrso" >'.number_format($result_paycash['PayCashDetAmt'],2).'&nbsp;</td>
<td  align="center" class = "colrso" >&nbsp;</td>
</tr>








					
';						
//--------------------------------------------------- 
 
}else{ 
//---------------------------------------------------               
$htmlele .='


<!-- ITEMS HERE -->
<tr>
<td   align="center"  class="coltoprso">'.format_dateDMY($result_paycash['PayCashDate']).'</td>
<td  align="" class="coltoprso">'.$result_paycash['PayCashto'].'</td>
<td  align="left" class="coltoprso">'.$result_paycash['PayCashDetDetail'].'</td>
<td  align="right" class="coltoprso" >'.number_format($result_paycash['PayCashDetAmt'],2).'&nbsp;</td>
<td  align="center" class = "coltoprso" ></td>
</tr>
					
';						
//---------------------------------------------------  
}	// จบ if ซ้ำ

$PayCashID = $result_paycash['PayCashID'];
$TotalVCAmt = $TotalVCAmt+ $result_paycash['PayCashDetAmtCal'];





}   //จบ while วนลูป
?>




<?php



?>







<?php



/*
$htmlele .='

<tbody>
<!-- ITEMS HERE -->
<tr>
<td   align="center"  class="coltoprso">24/01/2564</td>
<td  align="center" class="coltoprso">หจก.พงศ์พันธุ์ สหกิจ</td>
<td  align="left" class="coltoprso">xxxxxxxxxxxxxxxxx</td>
<td  align="right" class="coltoprso" >1000.00&nbsp;</td>
<td  align="center" class = "coltoprso" >&nbsp;</td>
</tr>

<tr>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="left"  class="colrso">ภาษีมูลค่าเพิ่ม 7 %</td>
  <td  align="right"  class="colrso">12.71&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
</tr>

<tr>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="left"  class="colrso">หัก ภาษีหัก ณ ที่จ่าย  3 %</td>
  <td  align="right"  class="colrso">11.71&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
</tr>

<tr>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="left"  class="colrso">ยอดเงินรวม</td>
  <td  align="right"  class="colrso">11.71&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
</tr>



<tr>
<td   align="center"  class="coltoprso">24/01/2564</td>
<td  align="center" class="coltoprso">หจก.พงศ์พันธุ์ สหกิจ</td>
<td  align="left" class="coltoprso">xxxxxxxxxxxxxxxxx</td>
<td  align="right" class="coltoprso" >1000.00&nbsp;</td>
<td  align="center" class = "coltoprso" >&nbsp;</td>
</tr>



<tr>
<td   align="center"  class="coltoprso">24/01/2564</td>
<td  align="center" class="coltoprso">หจก.พงศ์พันธุ์ สหกิจ</td>
<td  align="left" class="coltoprso">xxxxxxxxxxxxxxxxx</td>
<td  align="right" class="coltoprso" >1000.00&nbsp;</td>
<td  align="center" class = "coltoprso" >&nbsp;</td>
</tr>

<tr>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="left"  class="colrso">ภาษีมูลค่าเพิ่ม 7 %</td>
  <td  align="right"  class="colrso">12.71&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
</tr>

<tr>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
  <td  align="left"  class="colrso">ยอดเงินรวม</td>
  <td  align="right"  class="colrso">11.71&nbsp;</td>
  <td  align="center"  class="colrso">&nbsp;</td>
</tr>


<tr>
<td   align="center"  class="coltoprso">24/01/2564</td>
<td  align="center" class="coltoprso">หจก.พงศ์พันธุ์ สหกิจ</td>
<td  align="left" class="coltoprso">xxxxxxxxxxxxxxxxx</td>
<td  align="right" class="coltoprso" >1000.00&nbsp;</td>
<td  align="center" class = "coltoprso" >&nbsp;</td>
</tr>

';



*/



?>






<?php
$htmlele .='
<!-- END ITEMS HERE -->
<tr>
<td colspan="3"  class="coltoprso"  align="center"><span style="text-align: center; font-style: italic;">('.moneytotext($TotalVCAmt).')</span></td>

<td  class="coltoprso"  align="right">'.number_format($TotalVCAmt,2).'&nbsp;</td>
<td  class="coltoprso">&nbsp;</td>
</tr>
</tbody>
</table>


<div style="text-align: center ; font-style: italic;">***********************************</div>




</body>
</html>

';


 //$htmlele .='';

?>


<?php

?>





<?php
		include_once 'mpdf/vendor/autoload.php';
		
		
		include("mpdf/mpdf.php");
		
		
		/*
		 $mpdf = new mPDF(   '',    // mode - default ''
                '',    // format - A4, for example, default ''
                0,     // font size - default 0
                '',    // default font family
                15,    // margin_left       7
                15,    // margin right      6
                58,     // margin top       5
                60,    // margin bottom     4
                6,     // margin header     3
                0,     // margin footer     2
                'L' );  // L - landscape, P - portrait            1
		*/
		//$mpdf = new mPDF('c');
		//$mpdf=new mPDF(''); 
		//$mpdf = new mPDF('c','A4','','',20,15,48,25,10,10);
		$mpdf=new mPDF('','A4-P','','' , 10 , 10 , 55 , 25 , 10 , 10 ,'P'); 
		//$stylesheet = file_get_contents('vendor/bootstrap/css/bootstrap.css');
		$stylesheet = file_get_contents('css/css.css');
		
		$mpdf->SetDisplayMode('fullpage');
	//	$mpdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list
		
		
		
	  // $stylesheet = file_get_contents('css/mpdfstyleA4.css');
     //  $mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text
		
		
		
		
     	
    //    $mpdf->SetHTMLFooter();
	//	$mpdf->allow_charset_conversion=true;
	//	$mpdf->charset_in='UTF-8';
		//$mpdf->WriteHTML($stylesheet,1);
		$mpdf->SetHTMLHeader($header);
	//	$mpdf->SetHTMLFooter($footer);
		$mpdf->WriteHTML($htmlele);  
	
		$mpdf->Output(); 
		/* $mpdf->Output('doc/PDF/Quotation_'.$order_id.'_'.$tele.'.pdf','F'); */
?>