<?php
header('Content-Type: text/html; charset=utf-8');
header("Content-type: application/vnd.ms-excel");

header("Content-Disposition: attachment; filename=รายงานเก็บเงินปลายทาง.xls");

?>

<?php

function m2t($number){
    $number = number_format($number, 2, '.', '');
    $numberx = $number;
    $txtnum1 = array('ศูนย์','หนึ่ง','สอง','สาม','สี่','ห้า','หก','เจ็ด','แปด','เก้า','สิบ'); 
    $txtnum2 = array('','สิบ','ร้อย','พัน','หมื่น','แสน','ล้าน','สิบ','ร้อย','พัน','หมื่น','แสน','ล้าน'); 
    $number = str_replace(",","",$number); 
    $number = str_replace(" ","",$number); 
    $number = str_replace("บาท","",$number); 
    $number = explode(".",$number); 
    if(sizeof($number)>2){ 
    return 'ทศนิยมหลายตัวนะจ๊ะ'; 
    exit; 
    } 
    $strlen = strlen($number[0]); 
    $convert = ''; 
    for($i=0;$i<$strlen;$i++){ 
    $n = substr($number[0], $i,1); 
    if($n!=0){ 
        if($i==($strlen-1) AND $n==1){ $convert .= 'เอ็ด'; } 
        elseif($i==($strlen-2) AND $n==2){  $convert .= 'ยี่'; } 
        elseif($i==($strlen-2) AND $n==1){ $convert .= ''; } 
        else{ $convert .= $txtnum1[$n]; } 
     $convert .= $txtnum2[$strlen-$i-1]; 
    } 
} 

$convert .= 'บาท'; 
if($number[1]=='0' OR $number[1]=='00' OR 
$number[1]==''){ 
$convert .= 'ถ้วน'; 
}else{ 
$strlen = strlen($number[1]); 
for($i=0;$i<$strlen;$i++){ 
$n = substr($number[1], $i,1); 
if($n!=0){ 
if($i==($strlen-1) AND $n==1){$convert 
.= 'เอ็ด';} 
elseif($i==($strlen-2) AND 
$n==2){$convert .= 'ยี่';} 
elseif($i==($strlen-2) AND 
$n==1){$convert .= '';} 
else{ $convert .= $txtnum1[$n];} 
$convert .= $txtnum2[$strlen-$i-1]; 
} 
} 
$convert .= 'สตางค์'; 
}
//แก้ต่ำกว่า 1 บาท ให้แสดงคำว่าศูนย์ แก้ ศูนย์บาท
if($numberx < 1)
{
	$convert = "ศูนย์" .  $convert;
}

//แก้เอ็ดสตางค์
$len = strlen($numberx);
$lendot1 = $len - 2;
$lendot2 = $len - 1;
if(($numberx[$lendot1] == 0) && ($numberx[$lendot2] == 1))
{
	$convert = substr($convert,0,-10);
	$convert = $convert . "หนึ่งสตางค์";
}

//แก้เอ็ดบาท สำหรับค่า 1-1.99
if($numberx >= 1)
{
	if($numberx < 2)
	{
		$convert = substr($convert,4);
		$convert = "หนึ่ง" .  $convert;
	}
}
return $convert; 
}

function DateThai($strDate)
{
	$strYear = date("Y",strtotime($strDate))+543;
	$strMonth= date("n",strtotime($strDate));
	$strWeek= date("w",strtotime($strDate));
	$strDay= date("j",strtotime($strDate));
	$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
	$thai_day_arr = Array("อา","จ","อ","พ","พฤ","ศ","ส");
	$strMonthThai=$strMonthCut[$strMonth];
	$strWeekThai=$thai_day_arr[$strWeek];
	return "$strDay $strMonthThai $strYear";
}
function Numphon($strNum)
{
	
	$n3 = substr($strNum,6,4);
	$n2 = substr($strNum,3,3);
	$n1 = substr($strNum,0,3);
	$nump = $n1."-".$n2."-".$n3;
	return "$nump";
}



?>
<html>
<meta charset="utf-8">
<head>
    <style>
    table, th, td {
      border: 1px solid black;
    }
    </style>
    </head>
<body>

	<?php
	$totalqt = 0;
	$qq1 = "";
	$qq2 = "";
	$first = true;
	$numnewpage = 0;
	$AmountRec = 0;
	$AmountRecAll =0;
	$idlot  = null;
	$row = 1;
  $idtranmt = null;
  $DocCode = null;
  $priceTarn = null;
  $NameUser = null;
  $price_tarn = null;
  $nameSocial = null;
  $notets = null;
  $tracking = null;
  $name_transport = null;
  $date_to = null;
  $AddressText = null;
  $Mobile1 = null;
  $date = null;
  $date_to = null;
  


	?>

<table style="width:100% ;margin: 0 auto; border:1px solid;text-align:center">
    <tr>
      <th colspan="16">JOBS ORDER <?php echo e($date); ?> - <?php echo e($text); ?> </th>
    </tr>
    <tr>
      <th>Jobs No.</th>
      <th>ชื่อบิล</th> 
      <th>ที่อยู่</th>
      <th>เบอร์โทร</th> 
      <th>รายการสินค้า</th> 
      <th>จำนวน</th>
      <th>ราคา</th> 
      <th>วันที่สั่งซื้อ</th>
      <th>วันที่ส่งออก</th> 
      <th>สั่งซื้อทาง</th>
      <th>ส่งทาง</th> 
      <th>ราคาค่าขนส่ง</th>
      <th>แทร็คกิ๊ง</th> 
    
    </tr>
    <?php $__currentLoopData = $m; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php
    if($idtranmt != $x->id_transport_mt){

     
        $DocCode = $x->DocCode;
        $priceTarn = number_format($x->priceTarn);
        $NameUser = $x->NameUser;
        $price_tarn = number_format($x->price_tarn);
        $nameSocial = $x->nameSocial;
        $notets = $x->notets;
        $tracking = $x->tracking;
        $name_transport = $x->name_transport;
        $date_to = DateThai($x->date_to);
        $AddressText = $x->AddressText;
        $Mobile1 = Numphon($x->Mobile1);
        $date = DateThai($x->date);
        $date_to = DateThai($x->date_to);
  
      }else{
        $DocCode = " '' ";
        $priceTarn = " '' ";
        $NameUser = " '' ";
        $price_tarn = " '' ";
        $nameSocial = " '' ";
        $notets = " '' ";
        $tracking = " ''";
        $name_transport = " '' ";
        $date_to = " '' ";
        $AddressText = " '' ";
        $Mobile1 = " '' ";
        $date = " '' ";
        $date_to = " '' ";
       
      } 
      $idtranmt = $x->id_transport_mt;
      ?>
    <tr>
        <td><?php echo e($DocCode); ?></td>
        <td><?php echo e($NameUser); ?></td>
        <td><?php echo e($AddressText); ?></td>
        <td><?php echo e($Mobile1); ?></td>
        <td><?php echo e($x->PdName); ?></td>
        <td><?php echo e(number_format($x->quantity)); ?></td>
        <td><?php echo e(number_format($x->Price)); ?></td>
        <td style="text-align:center"><?php echo e($date); ?></td>
        <td style="text-align:center"><?php echo e($date_to); ?></td>
        <td style="text-align:center"><?php echo e($nameSocial); ?></td>
        <td style="text-align:center"><?php echo e($name_transport); ?></td>
        <td><?php echo e($priceTarn); ?></td>
        <td style="text-align:center"><?php echo e($tracking); ?></td>
    </tr>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
  </table>
  

	</body>
	</html><?php /**PATH /home/cp325668/public_html/except/resources/views/stock/reExcelSCG.blade.php ENDPATH**/ ?>