<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$formname = "Traders Position";
$file = "tradeposn_fr.php";
$grid = "";
$zroot = $_SESSION["zdbroot"];
$accdb = "actran";
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$zyear = right($zdb, 4);
$mfrmdate = getzdates($zyear, 'S', $conn);
$mtodate = getzdates($zyear, 'E', $conn);
mysqli_select_db($conn, $zdb);

$accode = $_REQUEST['accode'];
$getname = mysqli_query($conn, "Select * from accmast where accode='$accode'") or die(mysqli_error($conn));
$fetname = mysqli_fetch_array($getname);
$partyname = $fetname['name'];
$seriescond = "";
include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" type="text/css">
<style type="text/css">
    #tabital {
        font-style: italic;
    }

    #font1 {
        font-style: italic;
    }

    #boldfont {
        font-weight: bold;
    }

    .mtotclr {
        color: #0098DA;
    }

    .ttotclr {
        color: #ed3237;
    }

    .totdwn {
        font-size: 20px;
    }

    .depbtn {
        color: #585858;
        text-transform: uppercase;
        text-decoration: none;
        border: 2px solid purple;
        border-radius: 5px;
        padding: 10px 20px;
        font-size: 17px;
        font-weight: bold;
        background: transparent;
        position: relative;
        transition: all 1s;
        overflow: hidden;
    }

    .depbtn:hover {
        color: white;
    }

    .depbtn::before {
        content: '';
        position: absolute;
        height: 100%;
        width: 0%;
        top: 0;
        left: -40px;
        transform: skewX(45deg);
        background-color: #585858;
        z-index: -1;
        transition: all 1s;
    }

    .depbtn:hover::before {
        width: 160%;
    }

    .withbtn {
        color: black;
        text-transform: uppercase;
        text-decoration: none;
        border: 2px solid green;
        border-radius: 5px;
        padding: 10px 20px;
        font-size: 17px;
        font-weight: bold;
        background: transparent;
        position: relative;
        transition: all 1s;
        overflow: hidden;
    }

    .withbtn:hover {
        color: white;
    }

    .withbtn::before {
        content: '';
        position: absolute;
        height: 100%;
        width: 0%;
        top: 0;
        left: -40px;
        transform: skewX(45deg);
        background-color: #D6BD60;
        z-index: -1;
        transition: all 1s;
    }

    .withbtn:hover::before {
        width: 160%;
    }

    .tradbtn {
        color: #963634;
        text-transform: uppercase;
        text-decoration: none;
        border: 2px solid #963634;
        border-radius: 5px;
        padding: 10px 20px;
        font-size: 17px;
        font-weight: bold;
        background: transparent;
        position: relative;
        transition: all 1s;
        overflow: hidden;
    }

    .tradbtn:hover {
        color: white;
    }


    .tradbtn::before {
        content: '';
        position: absolute;
        height: 100%;
        width: 0%;
        top: 0;
        left: -40px;
        transform: skewX(45deg);
        background-color: #963634;
        z-index: -1;
        transition: all 1s;
    }

    .tradbtn:hover::before {

        width: 160%;

    }

</style>

<script type="text/javascript">

    $(document).ready(function () {

        $("body").on("click", ".depbtn", Deposit);

        $("body").on("click", ".withbtn", Deposit);

        $("body").on("click", ".tradbtn", Trading);

        $("body").on("click", ".savdep", savDeposit);

        $("body").on("click", ".savetrade", savTrade);



        $("body").on("change", "#type", showrmb);





        $(".rmbshow").hide();



        function showrmb() {



            var type = $("#type").val();



            if (type == "R") {

                $(".rmbshow").show();

            } else {

                $(".rmbshow").hide();

            }



        }







        function Deposit() {

            $(".depModal").modal("show");

            var depwit = $(this).val();


            $(".para").val(depwit);
            if (depwit == "D") {

                $("#myLargeModalLabel1").show();

                $("#myLargeModalLabel2").hide();

                $(".wittrd").hide();

                $(".deptrd").show();

            } else {

                $(".wittrd").show();

                $(".deptrd").hide();

                $("#myLargeModalLabel1").hide();

                $("#myLargeModalLabel2").show();

            }

        }

        function Trading() {

            $(".tradeModal").modal("show");

            //            var depwit = $(this).val();

            //            $(".para").val(depwit);

        }

        function savDeposit() {

            var accode = <?= $accode ?>,
                    para = $(".para").val(),
                    depdate = $(".withdate").val(),
//                    bankname = $(".bankname").val(),
                    bankname = 3,
                    depamt = $(".depamt").val(),
                    type = $(".type").val(),
                    roe = $(".roe").val();

            $.post("saveDeposit.php", {depamt: depamt, bankname: bankname, depdate: depdate, accode: accode, para: para, type: type, roe: roe}, function (data) {

                if (data > 0) {

                    location.reload(true);

                }

            });

        }



        function savTrade() {

            var accode = <?= $accode ?>,
                    para = $(".para").val(),
                    depdate = $(".depdate").val(),
                    //                    depamt = $(".depamt").val(),

                    qty = $(".qty").val(),
                    ounzval = $(".ounzval").val(),
                    totgm = $(".totgm").val(),
                    roe = $(".roe").val(),
                    rateusd = $(".rateusd").val(),
                    itemtype = $(".itemtype").val(),
                    tradetype = $(".tradetype").val(),
                    ratepergm = rateusd / ounzval,
                    ratedirhgm = ratepergm * roe,
                    amount = ratedirhgm * totgm;

            $.post("saveTrade.php", {

                amount: amount, depdate: depdate, accode: accode, qty: qty, ounzval: ounzval, tradetype: tradetype,

                totgm: totgm, roe: roe, rateusd: rateusd, itemtype: itemtype, ratepergm: ratepergm, ratedirhgm: ratedirhgm

            }, function (data) {

                if (data > 0) {

                    location.reload(true);

                }

            });

        }





        $("body").on("change keyup blur", ".qty, .rateusd", calAmt);

        $("body").on("change blur", ".itemtype, .qty", calGm);



        function calGm() {

            var itemtype = $(".itemtype").val(),
                    qty = $(".qty").val();

            $.post("calGm.php", {itemtype: itemtype, qty: qty}, function (data) {

                $(".totgm").val(data);

            });

        }

        function calAmt() {

            var qty = $(".qty").val(),
                    ounzval = $(".ounzval").val(),
                    totgm = $(".totgm").val(),
                    roe = $(".roe").val(),
                    rateusd = $(".rateusd").val(),
                    ratepergm = rateusd / ounzval,
                    ratedirhgm = ratepergm * roe,
                    amount = ratedirhgm * totgm;



            $(".ratepergm").val(ratepergm);

            $(".ratedirhgm").val(ratedirhgm);

            $(".amount").val(amount.toFixed(2));


        }


    })

</script>

<style>

    @media print {

        a {

            text-decoration: none;

            /* Remove the underline */

            color: black;

            /* Change the color to black */

        }



        a[href]:after {

            content: none;

            /* Hide the href */

        }



        table td {

            font-size: 10px;

        }

    }

</style>





</head>



<body>

    <div class="container">

        <input type="hidden" name="accode" class="accode" value="<?= $accode ?>">

        <?php // include("includes/head_rep.php");  ?>

        <br>

        <div class="row">

            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad text-right">

                <button type="button" class="depbtn" value="D">You Received</button>

            </div>
            <div class="col-lg-2 col-md-2 col-sm-1 col-xs-1 pad text-right">
            </div>
            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad text-right">

                <button type="button" class="withbtn" value="W">You Paid</button>

            </div>



        </div>



        <div class="row">

            <div class="col-lg-12 col-md-12 col-sm-12 text-center col-xs-12 pad">

                <h1 style="background-color:#963634;color:whitesmoke;border: 1px solid black;"><?= $fetname['name'] ?>

                </h1>

            </div>

        </div>



        <div class="row">

            <?php
            $maccode = $accode;

            $recqry = mysqli_query($conn, " SELECT *, DATE_FORMAT(`date`, '%d-%m-%Y') AS vouchdt  FROM `$accdb`

                                            where amount < 0 and accode = '$maccode' and chqret != 'Y' and type != 'R'

                                            and date >= '$mfrmdate' and date <= '$mtodate' 

                                            order by date, source, vouchno ") or die(mysqli_error($conn));

            $rcount = mysqli_num_rows($recqry);

            $payqry = mysqli_query($conn, " SELECT *, DATE_FORMAT(`date`, '%d-%m-%Y') AS vouchdt  FROM `$accdb`

                                            where amount > 0 and accode = '$maccode' and chqret != 'Y' and type != 'R'

                                            and date >= '$mfrmdate' and date <= '$mtodate'     

                                            order by date, source, vouchno ") or die(mysqli_error($conn));

            $lcount = mysqli_num_rows($payqry);

//            $getopen = mysqli_query($conn, "SELECT grpcode, accode, name, openbal, dc  FROM `accmast` WHERE `accode` = '$maccode'  ")or die(mysqli_error($conn));



            $ctr = 0;

            $totrecp = 0;

//            $fetopen = mysqli_fetch_array($getopen);
//            $mname = $fetopen['name'];



            $opdc = $fetname["dc"];

            if ($opdc == 'D') {

                $opb = $fetname["openbal"] * -1;
            } else {

                $opb = $fetname["openbal"];
            }



            $opbt = $opb;

            $mopen = $opbt;

            $getacc = mysqli_query($conn, "SELECT SUM(amount) AS `openamt` FROM `$accdb` WHERE `accode` = '$maccode' and `date` < '$mfrmdate' and chqret != 'Y' and type !='R' ") or die(mysqli_error($conn));

            $fetacc = mysqli_fetch_array($getacc);

            $openacc = $fetacc['openamt'];

            $finopen = $mopen + $openacc;

            $finop = abs($finopen);

            $getacc2 = mysqli_query($conn, "SELECT SUM(amount) AS `openamt` FROM `$accdb` WHERE `accode` = '$maccode' and `date` <= '$mtodate' and chqret != 'Y'  and type !='R' ") or die(mysqli_error($conn));

            $fetacc2 = mysqli_fetch_array($getacc2);

            $openacc2 = $fetacc2['openamt'];

            $finclos = $mopen + $openacc2;

            $fincl = abs($finclos);

            require("includes/dbconnect.php");

            mysqli_select_db($conn, $zdb);
            ?>



            <div class="container">

                <div class="row">

                    <div class="col-lg-6">

                        <div class="box">

                            <table width="100%">

<!--                                <tr style="border:2px">

                                <h4 style="color:blue;" colspan="2"><b>INR</b></h4>

                                </tr>-->

                                <tr>

                                    <td width="50%">

                                        <table style="background: white;float:right" class="table  table-bordered"

                                               style="width:100%">

                                            <thead class="mySearchTr">

                                                <tr style="border:2px">

                                                    <th colspan="5" style="font-size: 16px;color:#963634">Received</th>

                                                </tr>



                                                <tr style="border:2px;background:#93aebc">

                                                    <th width="28%">Date</th>

                                                    <th width="4%">Source</th>

                                                    <th width="8%">Voucher</th>

                                                    <th width="40%">Description</th>

                                                    <th width="18%" class="text-right">Amount</th>

                                                </tr>

                                            </thead>



                                            <tbody>

                                                <?php
                                                $openflag = 0;

                                                if ($finopen >= 0) {

                                                    $ctr++;

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td>Opening</td>";

                                                    echo "<td></td>";

                                                    echo "<td class='text-right'>$finopen</td>";

                                                    echo "</tr>";

                                                    $totrecp = $totrecp + $finopen;

                                                    $openflag = 1;
                                                } else {

                                                    if ($lop == 1) {

                                                        echo "<tr>";

                                                        echo "<td></td>";

                                                        echo "<td></td>";

                                                        echo "<td></td>";

                                                        echo "<td>&nbsp;</td>";

                                                        echo "<td></td>";

                                                        echo "</tr>";
                                                    }
                                                }

                                                $ctr = 0;

                                                while ($receipt = mysqli_fetch_array($recqry)) {

                                                    $source = $receipt['source'];

                                                    $vouchno = $receipt['vouchno'];

                                                    $vouchdt = $receipt['vouchdt'];

                                                    $grpcode = $receipt['grpcode'];

                                                    $contno = $receipt['contno'];

                                                    $rmbfeamt = abs($receipt['feamt']);

                                                    $recamt = abs($receipt['amount']);

                                                    $colr = "";

                                                    $acname = '';

                                                    if ($source == 'BR') {

                                                        $url = "bankrecp.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "bankrecp_fr.php?vouchno=$vouchno";

                                                        $getbank = mysqli_query($conn, "Select date_format(vouchdt, '%d-%m-%Y') as recvdate,chqno from `bankrecp` where `vouchno`='$vouchno' $compcond $keycond") or die(mysqli_error($conn));

                                                        $fetbank = mysqli_fetch_array($getbank);

                                                        $vouchdt = $fetbank['recvdate'];

                                                        $getclr = mysqli_query($conn, "SELECT `clrdate` FROM `$accdb` WHERE `vouchno` = '$vouchno' and `source`='BR' $keycond") or die(mysqli_error($conn));

                                                        $fetclr = mysqli_fetch_array($getclr);

                                                        $clrdate = $fetclr['clrdate'];

                                                        if ($clrdate == '0000-00-00') {

                                                            $colr = 'color:red';
                                                        }
                                                    }


                                                    if ($source == 'PYIN') {

                                                        $url = "payin.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "payin_fr.php?vouchno=$vouchno";

                                                        $desc = "Payment In";

                                                        if ($grpcode == '002') {

                                                            $getcash = mysqli_query($conn, "SELECT party as accode FROM `cashrecp` WHERE `vouchno`='$vouchno' ") or die(mysqli_error($conn));
                                                        } else {

                                                            $getcash = mysqli_query($conn, "SELECT bankname as accode FROM `cashrecp` WHERE `vouchno`='$vouchno' ") or die(mysqli_error($conn));
                                                        }

                                                        $fetcash = mysqli_fetch_array($getcash);

                                                        $accode = $fetcash['accode'];

                                                        $getacc = mysqli_query($conn, "Select name from `accmast` where `accode`='$accode' ") or die(mysqli_error($conn));

                                                        $fetacc = mysqli_fetch_array($getacc);

                                                        $desc = $fetacc['name'];
                                                    }



                                                    if ($source == 'PUSL') {

                                                        $url = "purchsale.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "";

                                                        $desc = "Entry";

//                                                        $getcash = mysqli_query($conn, "SELECT party as accode FROM `cashrecp` WHERE `vouchno`='$vouchno' ") or die(mysqli_error($conn));
//
//                                                        $fetcash = mysqli_fetch_array($getcash);
//
//                                                        $accode = $fetcash['accode'];
//
//                                                        $getacc = mysqli_query($conn, "Select name from `accmast` where `accode`='$accode' ") or die(mysqli_error($conn));
//
//                                                        $fetacc = mysqli_fetch_array($getacc);

//                                                        $desc = ;
                                                    }





                                                    if ($source == 'FRAG') {

                                                        $url = "agentout.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "agentout_fr.php?vouchno=$vouchno";

                                                        $desc = "Payment From Agent";

                                                        $getcash = mysqli_query($conn, "Select party as accode from `agentout` where `vouchno`='$vouchno' ") or die(mysqli_error($conn));

                                                        $fetcash = mysqli_fetch_array($getcash);

                                                        $accode = $fetcash['accode'];

                                                        $getacc = mysqli_query($conn, "Select name from `accmast` where `accode`='$accode' ") or die(mysqli_error($conn));

                                                        $fetacc = mysqli_fetch_array($getacc);

                                                        $desc = $fetacc['name'];
                                                    }





                                                    if ($source == 'INV') {

                                                        $url = "invoiceent.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "invoiceent_pdf.php?vouchno=$vouchno";

                                                        $desc = "Invoice";

                                                        $desc = " CNo.: " . trim($contno) . "&nbsp;&nbsp;&nbsp;&nbsp; RMB : " . $rmbfeamt;
                                                    }





                                                    $ctr++;

                                                    echo "<tr style='$colr' class='clickable-row2' data-href='$url' data-target='_blank'>";

                                                    echo "<td>$vouchdt</td>";

                                                    echo "<td>$source</td>";

                                                    echo "<td><a href='$url2' target='_blank'>$vouchno</a></td>";

                                                    echo "<td>$desc</td>";

                                                    echo "<td class='text-right'>$recamt</td>";

                                                    echo "</tr>";

                                                    $totrecp = $totrecp + $recamt;
                                                }



                                                if ($rcount < $lcount) {

                                                    $ext = $lcount - $rcount;

                                                    for ($i = 0; $i < $ext; $i++) {

                                                        echo "<tr>";

                                                        echo "<td></td>";

                                                        echo "<td></td>";

                                                        echo "<td></td>";

                                                        echo "<td>&nbsp;</td>";

                                                        echo "<td></td>";

                                                        echo "</tr>";
                                                    }
                                                }



                                                echo "<tr style='background:#b3d4e5'>";

                                                echo "<td></td>";

                                                echo "<td></td>";

                                                echo "<td></td>";

                                                echo "<td class='text-right'>Total</td>";

                                                echo "<td class='text-right'><b>$totrecp</b></td>";

                                                echo "</tr>";

                                                if ($finclos > 0) {

                                                    $ctr2++;

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td style='color:red' class='text-right'><b>Closing</b></td>";

                                                    echo "<td style='color:red' class='text-right'><b>$fincl</b></td>";

                                                    echo "</tr>";
                                                } else {

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td>&nbsp;</td>";

                                                    echo "<td></td>";

                                                    echo "</tr>";
                                                }
                                                ?>

                                            </tbody>

                                        </table>

                                    </td>



                                    <td width="50%">

                                        <table style="background:white; width: 100%;" class="table table-bordered">

                                            <thead class="mySearchTr">



                                                <tr style="border:2px">

                                                    <th colspan="6" style="font-size: 16px;color:#963634">Paid</th>

                                                </tr>



                                                <tr style="border:2px;background:#93aebc">

                                                    <th width="28%">Date</th>

                                                    <th width="4%">Source</th>

                                                    <th width="8%">Voucher</th>

                                                    <th width="40%">Description</th>

                                                    <th width="18%" class="text-right">Amount</th>

                                                </tr>

                                            </thead>

                                            <tbody>

                                                <?php
                                                $lop = 0;

                                                if ($finopen < 0) {

                                                    $ctr++;

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td>Opening</td>";

                                                    echo "<td></td>";

                                                    echo "<td class='text-right'>$finop</td>";

                                                    echo "</tr>";

                                                    $lop = 1;

                                                    $totpay = $totpay + $finop;
                                                }



                                                if ($openflag > 0) {

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td>&nbsp;</td>";

                                                    echo "<td></td>";

                                                    echo "</tr>";
                                                }
                                                ?>

                                                <?php
                                                $ctr2 = 0;

                                                $totpay = 0;

                                                while ($payment = mysqli_fetch_array($payqry)) {

                                                    $source = $payment['source'];

                                                    $vouchno = $payment['vouchno'];

                                                    $vouchdt = $payment['vouchdt'];

                                                    $contno = $payment['contno'];

                                                    $rmbfeamt = abs($payment['feamt']);

                                                    $payamt = abs($payment['amount']);

                                                    $trcolr = "";

                                                    if ($source == 'SL') {

                                                        $url = "sale.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "sale_print.php?vouchno=$vouchno&mode=edit";

                                                        $mtransacdb = 'salemain';

                                                        $gdetail = mysqli_query($conn, "SELECT * FROM `$mtransacdb` WHERE vouchno='$vouchno' $keycond") or die(mysqli_error($conn));

                                                        $gdtl = mysqli_fetch_array($gdetail);

                                                        $manualno = $gdtl['manualno'];

                                                        $lotno = $gdtl['totalqty'];

                                                        //                                                        browse($lotno);

                                                        $trn2 = mysqli_query($conn, "SELECT SUM(`setoff`) AS `totadj`, nodays FROM `billsett` WHERE 

                                                                                    `billno` = '$gdtl[vouchno]' AND 

                                                                                    `party` = '$gdtl[party]' LIMIT 0,1 ") or die(mysqli_error($conn));

                                                        $tranqry2 = mysqli_fetch_assoc($trn2);

                                                        $totadj = $tranqry2["totadj"];

                                                        if ($totadj != $gdtl['netamt']) {

                                                            $trcolr = "color:red";
                                                        }
                                                    }


                                                    if ($source == 'PUSL') {

                                                        $url = "purchsale.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "";

                                                        $desc = "Entry";

//                                                        $getcash = mysqli_query($conn, "SELECT party as accode FROM `cashrecp` WHERE `vouchno`='$vouchno' ") or die(mysqli_error($conn));
//
//                                                        $fetcash = mysqli_fetch_array($getcash);
//
//                                                        $accode = $fetcash['accode'];
//
//                                                        $getacc = mysqli_query($conn, "Select name from `accmast` where `accode`='$accode' ") or die(mysqli_error($conn));
//
//                                                        $fetacc = mysqli_fetch_array($getacc);

//                                                        $desc = ;
                                                    }



                                                    if ($source == 'PYOU') {

                                                        $url = "payout.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "payout_fr.php?vouchno=$vouchno";

                                                        $desc = "Payment Out";

                                                        $mtransacdb = 'cashpay';

                                                        if ($grpcode == '002') {

                                                            $getcash = mysqli_query($conn, "Select party as accode from `cashpay` where `vouchno`='$vouchno' $compcond $keycond") or die(mysqli_error($conn));
                                                        } else {

                                                            $getcash = mysqli_query($conn, "Select bankname as accode from `cashpay` where `vouchno`='$vouchno' $compcond $keycond") or die(mysqli_error($conn));
                                                        }

                                                        $fetcash = mysqli_fetch_array($getcash);

                                                        $accode = $fetcash['accode'];

                                                        $getacc = mysqli_query($conn, "Select name from `accmast` where `accode`='$accode' ") or die(mysqli_error($conn));

                                                        $fetacc = mysqli_fetch_array($getacc);

                                                        $desc = $fetacc['name'];
                                                    }



                                                    if ($source == 'FRAG') {

                                                        $url = "agentout.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "agentout_fr.php?vouchno=$vouchno";

                                                        $desc = "Agent Out";

                                                        $mtransacdb = 'agentout';

                                                        //                                                        if ($grpcode == '002') {
//                                                            $getcash = mysqli_query($conn, "Select party as accode from `cashpay` where `vouchno`='$vouchno' $compcond $keycond") or die(mysqli_error($conn));
//                                                        } else {

                                                        $getcash = mysqli_query($conn, "Select b.name from `agentout` a, accmast b where a.`vouchno`='$vouchno' and a.agent = b.accode ") or die(mysqli_error($conn));

                                                        //                                                        }

                                                        $fetcash = mysqli_fetch_array($getcash);

                                                        $desc = $fetcash['name'];
                                                    }



                                                    if ($source == 'CARR') {

                                                        $url = "carrierfees.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "";

                                                        $desc = "Carries Fees ";

                                                        $contno = '';

                                                        $mtransacdb = 'carrierfees';

                                                        $getcash = mysqli_query($conn, "Select containerno from `carrierfees` where `vouchno`='$vouchno' ") or die(mysqli_error($conn));

                                                        $fetcash = mysqli_fetch_array($getcash);

                                                        $contno = $fetcash['containerno'];

                                                        if ($contno != '') {

                                                            $desc = "Carries Fees - Container No. - " . trim($contno);
                                                        }
                                                    }





                                                    if ($source == 'INV') {

                                                        $url = "invoiceent.php?vouchno=$vouchno&mode=edit";

                                                        $url2 = "invoiceent_pdf.php?vouchno=$vouchno";

                                                        $desc = "Invoice";

                                                        $desc = " CNo.: " . trim($contno) . "&nbsp;&nbsp;&nbsp;&nbsp;  RMB : " . $rmbfeamt;
                                                    }



                                                    $ctr2++;

                                                    echo "<tr style='$trcolr' class='clickable-row2' data-href='$url' data-target='_blank'>";

                                                    echo "<td>$vouchdt</td>";

                                                    echo "<td>$source</td>";

                                                    echo "<td><a href='$url2' target='_blank'>$vouchno</a></td>";

                                                    echo "<td>$desc</td>";

                                                    echo "<td class='text-right'>$payamt</td>";

                                                    echo "</tr>";

                                                    $totpay = $totpay + $payamt;
                                                }



                                                if ($lcount < $rcount) {

                                                    $ext = $rcount - $lcount;

                                                    for ($i = 0; $i < $ext; $i++) {

                                                        echo "<tr>";

                                                        echo "<td></td>";

                                                        echo "<td></td>";

                                                        echo "<td></td>";

                                                        echo "<td>&nbsp;</td>";

                                                        echo "<td></td>";

                                                        echo "</tr>";
                                                    }
                                                }



                                                echo "<tr style='background:#b3d4e5'>";

                                                echo "<td></td>";

                                                echo "<td></td>";

                                                echo "<td></td>";

                                                echo "<td class='text-right'>Total</td>";

                                                echo "<td class='text-right'><b>$totpay</b></td>";

                                                echo "</tr>";

                                                if ($finclos <= 0) {

                                                    $ctr2++;

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td style='color:blue' class='text-right'><b>Closing</b></td>";

                                                    echo "<td style='color:blue' class='text-right'><b>$fincl</b></td>";

                                                    echo "</tr>";
                                                } else {

                                                    echo "<tr>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td></td>";

                                                    echo "<td>&nbsp;</td>";

                                                    echo "<td></td>";

                                                    echo "</tr>";
                                                }
                                                ?>

                                            </tbody>

                                        </table>

                                    </td>

                                </tr>



                            </table>

                        </div>

                    </div>

                </div>


            </div>

        </div>

    </div>





    <?php include("includes/linksfoot.php");
    ?>

    <div class="modal fade tradeModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">

        <div class="modal-dialog modal-lg">

            <div class="modal-content" style="width:50%">

                <div class="modal-header">

                    <button class="close" data-dismiss="modal"><span>&times;</span></button>

                    <h4 class="modal-title">TRADING ENTRY</h4>

                </div>

                <div class="modal-body">



                </div>

                <div class="modal-footer"></div>

            </div>

        </div>

    </div>

    <input type="hidden" name="para" class="para">

    <div class="modal fade depModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">

        <div class="modal-dialog modal-lg">

            <div class="modal-content" style="width:50%">

                <div class="modal-header">

                    <button class="close" data-dismiss="modal"><span>&times;</span></button>

                    <h4 class="modal-title" id="myLargeModalLabel1">You Received</h4>

                    <h4 class="modal-title" id="myLargeModalLabel2">You Paid</h4>

                </div>

                <div class="modal-body">

                    <div class="row">

                        <div class="col-lg-4 col-md-1 col-sm-3 col-xs-3 text-right">

                            <label class="label-control">Date</label>

                        </div>

                        <div class="col-lg-4 col-md-3 col-sm-6 col-xs-6 pad">

                            <input type="date" name="withdate" placeholder="date" value="<?php echo date('Y-m-d'); ?>"

                                   class="form-control withdate" style="height: 30px;" autofocus="autofocus">

                        </div>

                    </div>



                    <!--                    <div class="row deptrd">
                    
                                            <div class="col-lg-4 col-md-1 col-sm-3 col-xs-3 text-right">
                    
                                                <label class="label-control">Cash / Bank</label>
                    
                                            </div>
                    
                                            <div class="col-lg-6 col-md-6 col-sm-7 col-xs-7 pad">
                    
                                                <select id="bankname" name="bankname" class="form-control select2 bankname"
                    
                                                        style="width:100%">
                    
                                                    <option value=""></option>
                    
                    <?php
                    $mown1 = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` where `grpcode` = '002' or grpcode = '001'") or die(mysqli_error($conn));

                    while ($trow1 = mysqli_fetch_array($mown1)) {

                        echo "<option value='$trow1[accode]'>$trow1[name]</option>";
                    }
                    ?>
                    
                                                </select>
                    
                                            </div>
                    
                                        </div>-->

                    <!--                    <div class="row wittrd">
                    
                                            <div class="col-lg-4 col-md-1 col-sm-4 col-xs-4 text-right">
                    
                                                <label class="label-control">Agent</label>
                    
                                            </div>
                    
                                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                    
                                                <select id="agentname" name="agentname" class="form-control select2 agentname"
                    
                                                        style="width:100%">
                    
                                                    <option value=""></option>
                    
                    <?php
                    $mown2 = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` where `grpcode` = '044'") or die(mysqli_error($conn));

                    while ($trow2 = mysqli_fetch_array($mown2)) {

                        echo "<option value='$trow2[accode]'>$trow2[name]</option>";
                    }
                    ?>
                    
                                                </select>
                    
                                            </div>
                    
                                        </div>
                    
                                        <div class="row wittrd">
                    
                                            <div class="col-lg-4 col-md-3 col-sm-4 col-xs-4 text-right">
                    
                                                <label class="control-label">RMB</label>
                    
                                            </div>
                    
                                            <div class="col-lg-4 col-md-3 col-sm-6 col-xs-6 pad">
                    
                                                <input type="text" name="rmbamt" id="rmbamt" placeholder="RMB" value="0"
                    
                                                       class="form-control text-right numeric rmbamt">
                    
                                            </div>
                    
                                        </div>-->



                    <div class="row">

                        <div class="col-lg-4 col-md-3 col-sm-3 col-xs-3 text-right">

                            <label class="control-label">Amount</label>

                        </div>

                        <div class="col-lg-4 col-md-3 col-sm-6 col-xs-6 pad">

                            <input type="text" name="depamt" id="depamt" placeholder="Amount" value="0"

                                   class="form-control text-right numeric depamt">

                        </div>

                    </div>



                    <!--                    <div class="row deptrd">
                    
                                            <div class="col-lg-4 col-md-1 col-sm-4 col-xs-4 text-right">
                    
                                                <label class="label-control">Type</label>
                    
                                            </div>
                    
                                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                    
                                                <select id="type" name="type" class="form-control select2 type" style="width:100%">
                    
                                                    <option value="I">INR</option>
                    
                                                    <option value="R">RMB</option>
                    
                                                </select>
                    
                                            </div>
                    
                                        </div>-->



                    <div class="row deptrd">

                        <div class="col-lg-4 col-md-3 col-sm-4 col-xs-4 text-right">

                            <label class="control-label rmbshow">ROE</label>

                        </div>

                        <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">

                            <input type="text" name="roe" id="roe" placeholder="ROE" value="0"

                                   class="form-control text-right numeric roe rmbshow">

                        </div>

                    </div>



                    <div class="row">

                        <div class="col-xs-12 text-right search-action-bar">

                            <input type="button" class="btn btn-primary savdep" value="SAVE">

                            <!--<input type="button"  class="btn btn-primary snext" value="Next">-->

                        </div>

                    </div>

                </div>

                <div class="modal-footer"></div>

            </div>

        </div>

    </div>

</body>



</html>