<?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 ftpurchase_invoice_no FROM txpurchase_invoice_hdr WHERE fnid = '{$_REQUEST['id']}'");

//echo $_REQUEST['id'];
//echo $_REQUEST['form'];
//echo $_REQUEST['mode'];

//$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.ftpurchase_invoice_no
                            FROM (
                                SELECT 1 AS fnurut, `ftpurchase_invoice_no` AS ftTransNo, `fdtrans_date`, fcamount , ftpurchase_invoice_no 
                                FROM `txpurchase_invoice_hdr`
                                WHERE fnstatus = 1 
                                AND ftpurchase_invoice_no='$ftSalesinvoiceNo'
                                UNION ALL
                                SELECT 3 AS urut, ftpurchase_return_no, fdtrans_date, -fcAmount, ftpurchase_invoice_no 
                                FROM `txpurchase_return_hdr`
                                WHERE fnStatus = 1 
                                AND ftpurchase_invoice_no='$ftSalesinvoiceNo'
                                UNION ALL
                                SELECT 2 AS urut, a.ftcvs_no, a.fdtrans_date,  -b.fcPayment_AmountUSD ,b.ftpi_No
                                FROM txrecap_bank_voucher_hdr a
                                LEFT JOIN txrecap_bank_voucher_det b ON a.ftcvs_no=b.ftcvs_no
                                INNER JOIN txpurchase_invoice_hdr c ON b.ftpi_No = c.ftpurchase_invoice_no
                                WHERE a.fnStatus = 1 
                                AND b.ftpi_No='$ftSalesinvoiceNo'
                              ) xx
                              
                             ORDER BY  xx.ftpurchase_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>