<?php          

//$server="localhost"; //lokasi server
//$username="root";  // username mysql
//$password=""; // jika mysql anda tidak diberi password silahkan dikosongkan
//$namadb="isnet-vag"; // Nama database

// Mengkoneksikan file index.php ke server
//$conn=mysql_connect($server,$username,$password);

// Memilih database
//$db=mysql_select_db($namadb);

//echo $_REQUEST['id'];

include "include_custom/config_setting.php";
$ftSalesinvoiceNo = RetRstField("Select ftsales_invoice_no FROM txsales_invoice_hdr WHERE fnid = '{$_REQUEST['id']}'");

//echo $ftSalesinvoiceNo;

//$foo = "105";
//echo number_format((float)$foo, 2, '.', '');  // Outputs -> 105.00

?>



<html>  
            <table border='1' style='margin-left: 10px'>
                <tr>
                    <th width=30>No</th>
                    <th width=150>No Transaksi</th>
                    <th width=100>Tanggal</th>
                    <th width=100>Jumlah</th>

                </tr>
                <?php 
                    $query=mysql_query("SELECT xx.fnurut, xx.ftTransNo, xx.fdtrans_date, xx.fcamount, xx.ftSales_Invoice_No
                            FROM (
                                SELECT 1 AS fnurut, `ftsales_invoice_no` AS ftTransNo, `fdtrans_date`, fcamount , ftsales_invoice_no 
                                FROM `txsales_invoice_hdr`
                                WHERE fnstatus = 1 
                                AND ftsales_invoice_no='$ftSalesinvoiceNo'
                                UNION ALL
                                SELECT 3 AS urut, ftsales_return_no, fdtrans_date, fcAmount, ftsales_invoice_no 
                                FROM `txsales_return_hdr`
                                WHERE fnStatus = 1 
                                AND ftsales_invoice_no='$ftSalesinvoiceNo'
                                UNION ALL
                                SELECT 2 AS urut, a.ftAR_No, a.fdtrans_date,  -b.fcPayment_Amount ,b.ftSales_Invoice_No
                                FROM TXAR_Hdr a
                                LEFT JOIN TXAR_Det b ON a.ftAR_No=b.ftAR_No
                                INNER JOIN TXSales_Invoice_Hdr c ON b.ftSales_Invoice_No = c.ftSales_Invoice_No
                                WHERE a.fnStatus = 1 
                                AND b.ftsales_invoice_no='$ftSalesinvoiceNo'
                              ) xx
                              
                             ORDER BY  xx.ftsales_invoice_no, xx.fnurut");

                    // Perulangan untuk menampilkan data gambar
                    while ($data=mysql_fetch_array($query))
                    { $a++;
                    ?>
                      <tr>
                        <!-- Untuk menampilkan nomor urut -->
                        <td><?=$a;?></td>
                        <!-- untuk menampilkan nama gambar -->
                        <td><?=$data['ftTransNo'];?></td>
                        <td><?=$data['fdtrans_date'];?></td>
                        <td><?=number_format((float)$data['fcamount'], 2, '.', '');?></td>
                        

                      </tr>
                    <?php } ?>

            </table>

</html>