<?php
	$fntrans_no = $paramsx[0]['value'];
      
        //$strSQL = "SELECT * FROM txdelivery_order_hdr WHERE ftdo_no ='$fntrans_no'";
        $strSQL = "CALL spsprint03_delivery_order('{$fntrans_no}')";
	$result = mysqli_query($mysql_link,$strSQL);
        $num_rows = mysqli_num_rows($result);

        $no=1; 
        
        // jika mau di full latter = TRUE / jika tidak = FALSE
        $full_letter = FALSE;

        // Jumlah Baris di baris detail
        if($full_letter){
                $max_baris = 20; 
        }else{
                $max_baris = 8; 
        }
 
        // Header Data
        Function HeaderData ($strSQL) {    
            $mysql_link = mysqli_connect(_SERVER_DB, _USER_DB, _PASS_DB, _NAME_DB) or die(mysqli_error());

            $result = mysqli_query($mysql_link,$strSQL);
            $row = mysqli_fetch_array($result);
	
        
            $element = '<page size="size">    
                        <div id="all-setting">

                        <table border="0" cellpadding="0"  cellspacing="0" style="width:95%">
                        <tr><td><div id="report_title">SURAT JALAN</div></td></tr>    
                        </table>    
                    
                        <table border="0" cellpadding="0" cellspacing="0" style="margin-top:5px; width:95%;">
                            <tr style="vertical-align:top;">
                                <td style="width:15%;">Kepada</td>
                                <td style="width:30%;">: ' . $row["ftcustomer_name"] . '</td>
                                <td style="width:10%;"></td>
                                <td style="width:15%;">No DO</td>
                                <td style="width:30%;">: ' . $row["ftdo_no"] . '</td>
                            </tr>
                            <tr style="vertical-align:top;">
                                <td rowspan="3">Alamat</td>
                                <td rowspan="3">: ' . $row['ftship_address'] . '</td>
                                <td></td>
                                <td>Tanggal</td>
                                <td>: ' . cdaterev($row['fdtrans_date']) . '</td>
                            </tr>
                            <tr style="vertical-align:top;">
                                <td></td>
                                <td>No Order</td>
                                <td>: ' . $row['ftso_no'] . '</td>
                            </tr>
                            <tr style="vertical-align:top;">
                                <td></td>
                                <td>Salesman</td>
                                <td>: ' . $data['ftsales_code'] . '</td>
                            </tr>
                            </table> 
                            
                            <!-- Row Header --> 
                            <table cellpadding="2" style="margin-top:20px;width:95%;border-collapse: collapse;border:1px solid black;" cellspacing="0">
                            <tr style="vertical-align:top;">
                                <th style="border:1px solid black;width:30px;"><div align="left">No</div></th>
                                <th style="border:1px solid black;"><div align="left">Kode</div></th>
                                <th style="border:1px solid black;"><div align="left">Nama Barang</div></th>
                                <th style="border:1px solid black;width:80px;padding-right:10px;"><div align="right">Qty</div></th>
                            </tr> ';
    
            echo $element;
        
        }
       
        // Footer Data        
        Function FooterData($strSQL) { 
            $mysql_link = mysqli_connect(_SERVER_DB, _USER_DB, _PASS_DB, _NAME_DB) or die(mysqli_error());

            $result = mysqli_query($mysql_link,$strSQL);
            $row = mysqli_fetch_array($result);
	
            $element ='     <table border="0" cellpadding="0" cellspacing="0" style="margin-top:10px; width:95%;">
                                <tr style="vertical-align:top;">
                                    <td style=""><div align="left">Keterangan :</td>
                                    <td style=""><div align="left">&nbsp;</div></td>
                                    <td style=""><div align="left">&nbsp;</div></td>
                                    <td style=""><div align="left">&nbsp;</div></td>
                                </tr> 	

                                <tr style="vertical-align:top;">
                                    <td style="width:50%;" colspan="2" rowspan="2"><div align="left">' . $row['ftnotes'] . '</td>
                                    <td style=""><div align="left">Dikirim oleh</div></td>
                                    <td style=""><div align="left">Diterima oleh</div></td>
                                </tr> 	

                                <tr style="vertical-align:top;">
                                    <td style=""><div align="left">&nbsp;</div></td>
                                    <td style=""><div align="left">&nbsp;</div></td>
                                </tr> 	

                                <tr style="vertical-align:top;">
                                    <td style=""><div align="left">&nbsp;</div></td>
                                    <td style=""><div align="left">&nbsp;</div></td>
                                    <td style=""><div align="left"><br>______________</div></td>
                                    <td style=""><div align="left"><br>______________</div></td>
                                </tr> 

                                <tr style="vertical-align:top;">
                                    <td style="padding-top:10px;" colspan="2"><div align="left">Barang Yang Sudah Dibeli tidak Dapat Dikembalikan</div></td>
                                    <td style="padding-top:10px;" colspan="2"><div align="right"><?php echo date("d-M-Y h:i:s A"); ?></div></td>
                                </tr> 
                                </table>

                            </div>
                        </page> ';

            echo $element;
        }    

			
?>

<html>
<head>
<style>
/* setting semua element */
*{	
    /* font-weight: bold; */
    font-family:Verdana, Geneva, Tahoma, sans-serif;
    font-size: 10pt; 
    letter-spacing: 2px;
    color:black;
}

body {
  background: rgb(204,204,204); 
}

tr {
  height: 20px;
}  
    
page[size="size"] {
  background: white;
  width: 8.5in;
  height: <?php if($full_letter){?> 11in <?php }else{ ?> 5.30in <?php } ?>;
  display: block;
  overflow: hidden;
  margin: 0 auto;
  margin-bottom: 1.0cm;
  /* mengatur jarak kertas */
  /* margin-bottom: 1.8cm; */
  /* margin: 0 auto;
   */
  /* border-style:solid;  */
  /* box-shadow: 0 0 0.5cm rgba(0,0,0,0.5); */
}

@media screen {
    html, body {
        width: 8.5in;
        height: <?php if($full_letter){?> 11in <?php }else{ ?> 5.30in <?php } ?>;
    }    
}

@media print {
    html, body {
	width: 8.5in;
	height: <?php if($full_letter){?> 11in <?php }else{ ?> 5.30in <?php } ?>;
    }
   
} 

table {
	/* untuk mengubah kanan kiri semua element */
	margin-left:10px; 
}

/* header settings  */
#report_title{
	/* setting judul text */
	font-size:18px; 
	font-weight:bold; 
	margin-bottom:10px; 
	margin-top: 10px;
        text-align: center;
}
</style>
</head>
<body>

	<!-- Table Data -->
        <?php 
               
        HeaderData($strSQL); 

        while($row = mysqli_fetch_array($result)){ 
	    echo "  <tr style='vertical-align:top;'>
			<td style='border-right:1px solid black;'>" . $no . "</td>
			<td style='border-right:1px solid black;'>" . $row['ftitem_code'] . "</td>
			<td style='border-right:1px solid black;'>" .$row['ftitem_name'] . "</td>
                        <td style='padding-right:10px;'><div align='right'>" . $row['fnqty'] . "</div></td>
                    </tr>";
            
            // Total 
            $total_qty = $total_qty + $row["fnqty"];
            
            // Apabila Jumlah Baris lebih dari satu halaman
            if($no % $max_baris == 0) { 
                // Display Total Layout 
                echo "  <tr style='vertical-align:top;'>
                            <td style='border:1px solid black;padding-right:10px;' colspan='3'><div align='right'>&nbsp;</div></td>
                            <td style='border:1px solid black;padding-right:10px;'><div align='right'>&nbsp;</div></td>
                        </tr> 	
                    </table>";
                FooterData($strSQL);
                
                if ($num_rows != $no) {
                    HeaderData($strSQL); 
                }
            } else {
                // Apabila di posisi halaman terakhir   
                if ($num_rows == $no){
                    // Membuat isi baris yg kurang                  
                    $sisa_baris = $max_baris - ($no % $max_baris);
                    for($baris=1; $baris <= $sisa_baris; $baris++) {
                        echo "  <tr style='vertical-align:top;'>
                                        <td style='border-right:1px solid black;'>&nbsp;</td>
                                        <td style='border-right:1px solid black;'>&nbsp;</td>
                                        <td style='border-right:1px solid black;'>&nbsp;</td>
                                        <td style='border-right:1px solid black;'>&nbsp;</td>
                                </tr>	";
                    }    
                    // Display Total
                    echo "  <tr style='vertical-align:top;'>
                                <td style='border:1px solid black;padding-right:10px;' colspan='3'><div align='right'>Total Qty</div></td>
                                <td style='border:1px solid black;padding-right:10px;'><div align='right'>" . number_format($total_qty,0) . "</div></td>
                            </tr> 	
                        </table>";
                    FooterData($strSQL);
		}
                
            }    

            $no++;  
                    
        }    
                      
     
 
?>
        
</body>
</html>
