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

$zdb = $_SESSION["zdbyear_" . $dbname];
$admin = $_SESSION["admin_" . $dbname];

$formname = "Kaigar Report";
$grid = "karigrep.php";
$file = "karigrep.php";
$maindb = "accmast";

mysqli_select_db($conn, $zdb);

$trandb = "actran";

if (isset($_POST["view"])) {
    $gcond = "";
    $accond = "";
    $stcond = "";
    $ctcond = "";

    $dtype = $_POST["dtype"];


    $custcond = '';
    if (!empty($_POST['acnamemul'])) {
        foreach ($_POST['acnamemul'] as $check2) {
            $mycheck2[$count2++] .= "OR `accode` = '" . $check2 . "' ";
        }

        foreach ($mycheck2 as $g => $values2) {
            $mcheck2 .= $values2;
        }

        $custcond = " AND (`accode` = '' " . $mcheck2 . " )";
    }
    $accode = trim($_POST["acname"]);

    if ($accode == '' && $custcond == '') {
        browse("Atleast select one A/c.");
        echo "<script>"
        . "window.close();"
        . "</script>";
    }
    if (!empty($_POST["acname"])) {

        $accond = "and accode = '$accode'";
    }


    $mfrmdate = trim($_POST["frmdt"]);

    $mtodate = trim($_POST["todt"]);

    if (empty($mfrmdate)) {
        browse("From Date Cannot Be Empty");
        echo "<script>"
        . "window.close();"
        . "</script>";
    }

    if (empty($mtodate)) {
        browse("To Date Cannot Be Empty");
        echo "<script>"
        . "window.close();"
        . "</script>";
    }



    if ($mfrmdate > $mtodate) {

        browse("To Date Cannot Be Less Than From Date");

        header("refresh: 1; karigrep.php");

        exit();
    }



    $getacc = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE accode != '' and active = '1'  $accond $custcond   order by name") or die(mysqli_error($conn));

    include("includes/linkshead.php");
    $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));
    ?>
    <style>
        table th{
            background-color: #337AB7;
        }
    </style>
    <?php
    if ($dtype == 1) {
        ?>
        <script type="text/javascript">
            $(document).ready(function () {
                //        left side
                $(".dtlsale").hide();
                $(".dtlsale2").hide();
                $("body").on('dblclick', '.getdtl', getDetails);
                $("body").on('dblclick', '.getdtl2', getDetails2);
                $("body").on('dblclick', '.dtlhide1', hideDetails);
                $("body").on('dblclick', '.dtlhide2', hideDetails2);
                function getDetails() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#dtlsale_" + idval).show();
                }
                function getDetails2() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#dtlsale2_" + idval).show();
                }
                function hideDetails() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#dtlsale_" + idval).hide();
                }
                function hideDetails2() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#dtlsale2_" + idval).hide();
                }

                //        right side
                $(".rdtlsale").hide();
                $(".rdtlsale2").hide();
                $("body").on('dblclick', '.rgetdtl', getDetailsr);
                $("body").on('dblclick', '.rgetdtl2', getDetailsr2);
                $("body").on('dblclick', '.rdtlhide1', hideDetailsr);
                $("body").on('dblclick', '.rdtlhide2', hideDetailsr2);
                function getDetailsr() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#rdtlsale_" + idval).show();
                }
                function getDetailsr2() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#rdtlsale2_" + idval).show();
                }
                function hideDetailsr() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#rdtlsale_" + idval).hide();
                }
                function hideDetailsr2() {
                    var trid = $(this).closest('tr').attr('id');
                    var idval = trid.split('_')[1];
                    $("#rdtlsale2_" + idval).hide();
                }
            });

        </script>
        <?php
    }
    ?>


    </head>

    <body id="ledger">   
        <div class="row" style="padding : 1%">
            <div class="col-lg-1"></div>
            <div class="col-lg-10">
                <?php include ("includes/head_rep.php"); ?>
                <!--            </div>
                            <div class="col-lg-8">-->

                <div class="box">


                    <div id="sortableTable" class="body collapse in">

                        <table class="table table-bordered sortableTable responsive-table">
                            <thead>
                                <?php
                                while ($getac = mysqli_fetch_array($getacc)) {
                                    ?>
                                    <tr>
                                        <th align="left" colspan="2">Account Name :- <b><?php echo $getac['name']; ?></b></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td style="width:50%">
                                            <table style="width:100%" class="table table-bordered">
                                                <thead>
                                                    <?php
                                                    $getopen = mysqli_query($conn, "Select sum(amount) as tamt from $trandb where accode = '$getac[accode]' and date < '$mfrmdate'") or die(mysqli_error($conn));
                                                    $fetopen = mysqli_fetch_array($getopen);
                                                    $open = $getac['openbal'];
                                                    $dc = $getac['dc'];
                                                    if ($dc == 'D') {
                                                        $mopen = $open * -1;
                                                    } else {
                                                        $mopen = $open;
                                                    }
                                                    $tamt = $fetopen['tamt'];
                                                    $openamt = $mopen + $tamt;

                                                    if ($openamt < 0) {
                                                        ?>
                                                        <tr>
                                                            <td class="text-right" colspan="3"><b style='font-size:15px;'>Advance&nbsp;</b></td>
                                                            <td class="text-right"><b style='font-size:15px;'><?= number_format(abs($openamt), 2); ?></b></td>
                                                        </tr>
                                                    <?php } else { ?>
                                                        <tr>
                                                            <td class="text-right" colspan="3"><b style='font-size:15px;'></b></td>
                                                            <td class="text-right"><b style='font-size:15px;'>&nbsp;</b></td>
                                                        </tr>
                                                    <?php }
                                                    ?>

                                                    <tr>
                                                        <th style="width:25%">Date</th>
                                                        <th style="width:10%">Voucher</th>
                                                        <th style="width:50%">Description</th>
                                                        <th  style="width:20%" class='text-right'>Amount</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="tbody">

                                                    <?php
                                                    $getopen = mysqli_query($conn, "Select sum(amount) as tamt from $trandb where accode = '$getac[accode]' and date < '$mfrmdate'") or die(mysqli_error($conn));
                                                    $fetopen = mysqli_fetch_array($getopen);
                                                    $open = $getac['openbal'];
                                                    $dc = $getac['dc'];
                                                    if ($dc == 'D') {
                                                        $mopen = $open * -1;
                                                    } else {
                                                        $mopen = $open;
                                                    }
                                                    $tamt = $fetopen['tamt'];
                                                    $openamt = $mopen + $tamt;

                                                    $totright = $totleft = $mnctr = $mnctr2 = $rnctr = $rnctr2 = 0;
                                                    $getleft = mysqli_query($conn, "Select *,date_format(date,'%d-%m-%Y') as mydt from `$trandb` 
                                                                        where accode = '$getac[accode]' and date >= '$mfrmdate' and date <= '$mtodate' 
                                                                        and amount < 0 order by date,vouchno") or die(mysqli_error($conn));
                                                    
                                                    $ldescrip = $custname = $acnum =  $url = '';
                                                    while ($rowleft = mysqli_fetch_array($getleft)) {
                                                        $mnctr++;
                                                        $lsource = $rowleft['source'];
                                                        switch ($lsource) {
                                                            case "SLM":
                                                                $ldescrip = 'Material Given to Karigar';
                                                                $indb = 'rawtran';
                                                                $url = "salematmulti.php?mode=edit&vouchno=$rowleft[vouchno]";
                                                                break;
                                                            case "REPG":
                                                                $ldescrip = 'Repair Given to Karigar';
                                                                $indb = 'repgivtran';
                                                                $url = "repairgiven.php?mode=edit&para=G&vouchno=$rowleft[vouchno]";

                                                                break;
                                                            case "BP":
                                                                $ldescrip = 'Bank Payment';
                                                                $url = "bankpay.php?mode=edit&vouchno=$rowleft[vouchno]";

                                                                $indb = '';

                                                                break;
                                                            case "CP":
                                                                $ldescrip = 'Cash Payment';
                                                                $url = "cashpay.php?mode=edit&vouchno=$rowleft[vouchno]";

                                                                $indb = '';

                                                                break;
                                                            case "JV":
                                                                $ldescrip = 'Journal Entry';
                                                                $indb = '';

                                                                break;
                                                            case "BRBP":
                                                                $indb = '';

                                                                $get2 = mysqli_query($conn, "Select a.name,b.acnum from accmast a, custtokari b where a.accode = b.karigar  
                                                                                 and b.vouchno = '$rowleft[vouchno]' order by b.vouchdt,b.vouchno") or die(mysqli_error($conn));
                                                                $fet2 = mysqli_fetch_array($get2);
                                                                $custname = $fet2['name'];
                                                                $acnum = $fet2['acnum'];
                                                                $ldescrip = 'TR - ' . $acnum . '  ( ' . $custname . ' ) ';
                                                                $url = "custtokari.php?mode=edit&vouchno=$rowleft[vouchno]";

                                                                break;

                                                            default:
                                                                break;
                                                        }

                                                        echo "<tr class='clickable-row getdtl' id='getdtl_$mnctr' data-href='$url' data-target='_blank' >";
                                                        
                                                        echo "<td>$rowleft[mydt]</td>";
//                                                        echo "<td><a href='$url' target='_blank'>$rowleft[vouchno]</a></td>";
                                                        echo "<td>$rowleft[vouchno]</td>";
                                                        echo "<td>$ldescrip</td>";
                                                        echo "<td class='text-right'>" . number_format(abs($rowleft['amount']), 2) . "</td>";
                                                        echo "</tr>";
                                                        $totleft = $totleft + abs($rowleft['amount']);

                                                        if ($lsource == 'SLM') {
//                                                    detail part start
                                                            Echo "<tr style='height:10px;' class='dtlsale' id='dtlsale_$mnctr'>";
                                                            Echo "<td colspan='6'>";
                                                            Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-bordered'>";
                                                            echo "<tr class='dtlhide1' id='dtlsale_$mnctr' style='background-color: #3E065F;'>";
                                                            Echo "<th style='background-color: #3E065F;width:5%;'>Sr.</th>";
                                                            Echo "<th style='background-color: #3E065F;width:35%;'>Item</th>";
                                                            Echo "<th style='background-color: #3E065F;width:8%;' class='numeric'>Yard</th>";
                                                            Echo "<th style='background-color: #3E065F;width:8%;' class='numeric'>Meters</th>";
                                                            Echo "<th style='background-color: #3E065F;width:8%;' class='numeric'>Qty.</th>";
                                                            Echo "<th style='background-color: #3E065F;width:8%;' class='numeric'>Rate</th>";
                                                            Echo "<th style='background-color: #3E065F;width:12%;' class='numeric'>Amount</th>";
                                                            Echo "</tr>";


                                                            $ctr2 = 0;
                                                            $tqty = 0;
                                                            $tamt = 0;

                                                            $gettran = mysqli_query($conn, "SELECT * FROM `$indb` WHERE vouchno = '$rowleft[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
//                                                        print table($gettran);
                                                            while ($tran = mysqli_fetch_array($gettran)) {
                                                                $getit = mysqli_query($conn, "Select name from rawmat where code='$tran[item]'") or die(mysqli_error($conn));
                                                                $fetit = mysqli_fetch_array($getit);
                                                                $mnctr2++;

                                                                $ctr2++;

                                                                Echo "<tr class='getdtl2' style='font-size:8px;' id='getdtl2_$mnctr2'>";
                                                                Echo "<td  style='font-size:10px;'>$ctr2</td>";
                                                                Echo "<td  style='font-size:10px;'>$fetit[name]</td>";
                                                                Echo "<td class='numeric'  style='font-size:10px;'>$tran[yard]</td>";
                                                                Echo "<td class='numeric'  style='font-size:10px;'>$tran[meters]</td>";
                                                                Echo "<td class='numeric'  style='font-size:10px;'>$tran[qty]</td>";
                                                                Echo "<td class='numeric'  style='font-size:10px;'>$tran[rate]</td>";
                                                                Echo "<td class='numeric'  style='font-size:10px;'>" . number_format($tran['amount'], 0) . "</td>";
                                                                Echo "</tr>";
                                                            }
                                                            echo "</table>";

                                                            echo "</td>";
                                                            echo "</tr>";
                                                        }

                                                        if ($lsource == 'REPG') {
//                                                    detail part start
                                                            Echo "<tr style='height:10px;' class='dtlsale' id='dtlsale_$mnctr'>";
                                                            Echo "<td colspan='6'>";
                                                            Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-bordered'>";
                                                            echo "<tr class='dtlhide1' id='dtlsale_$mnctr' style='background-color: #3E065F;'>";
                                                            Echo "<th style='background-color: #3E065F;width:3%;'>Sr.</th>";
                                                            Echo "<th style='background-color: #3E065F;width:25%;'>Item</th>";
                                                            Echo "<th style='background-color: #3E065F;width:10%;'>Color</th>";
                                                            Echo "<th style='background-color: #3E065F;width:5%;' class='numeric'>Qty.</th>";
                                                            Echo "<th style='background-color: #3E065F;width:7%;' class='numeric'>Rate</th>";
                                                            Echo "<th style='background-color: #3E065F;width:10%;' class='numeric'>Amount</th>";
                                                            Echo "</tr>";


                                                            $ctr2 = 0;
                                                            $tqty = 0;
                                                            $tamt = 0;

                                                            $getktran = mysqli_query($conn, "SELECT * FROM `$indb` WHERE vouchno = '$rowleft[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
//                                                        print table($gettran);
                                                            while ($ktran = mysqli_fetch_array($getktran)) {

                                                                $getkit = mysqli_query($conn, "Select name from item where code='$ktran[itemcode]'") or die(mysqli_error($conn));
                                                                $fetkit = mysqli_fetch_array($getkit);

                                                                $getkcol = mysqli_query($conn, "Select name from color where code='$ktran[color]'") or die(mysqli_error($conn));
                                                                $fetkcol = mysqli_fetch_array($getkcol);
                                                                $mnctr2++;

                                                                $ctr2++;

                                                                Echo "<tr class='getdtl2' style='font-size:8px;' id='getdtl2_$mnctr2'>";
                                                                Echo "<td style='font-size:10px;'>$ctr2</td>";
                                                                Echo "<td style='font-size:10px;'>$fetkit[name]</td>";
                                                                Echo "<td style='font-size:10px;'>$fetkcol[name]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$ktran[qty]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$ktran[rate]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$ktran[amount]</td>";
                                                                Echo "</tr>";
                                                            }
                                                            echo "</table>";

                                                            echo "</td>";
                                                            echo "</tr>";
                                                        }
//                                                    detail part end
                                                    }
                                                    echo "<tr>";
                                                    echo "<td></td>";
                                                    echo "<td></td>";
                                                    echo "<td class='text-right'><b style='font-size:15px;'>Total</b></td>";
                                                    echo "<td class='text-right'><b style='font-size:15px;'>" . number_format($totleft, 2) . "</b></td>";
                                                    echo "</tr>";
                                                    ?>

                                                </tbody>
                                            </table>    
                                        </td>
                                        <td style="width:50%">
                                            <table style="width:100%" class="table table-bordered">
                                                <thead>
                                                    <?php if ($openamt > 0) { ?>
                                                        <tr>
                                                            <td class="text-right" colspan="3"><b style='font-size:15px;'>Opening Balance</b></td>
                                                            <td class="text-right"><b style='font-size:15px;'><?= number_format(abs($openamt), 2); ?></b></td>
                                                        </tr>
                                                    <?php } else { ?>
                                                        <tr>
                                                            <td class="text-right" colspan="3"><b style='font-size:15px;'>&nbsp;</b></td>
                                                            <td class="text-right"><b style='font-size:15px;'>&nbsp;</b></td>
                                                        </tr>
                                                    <?php }
                                                    ?>
                                                    <tr>
                                                        <th style="width:25%">Date</th>
                                                        <th style="width:10%">Voucher</th>
                                                        <th style="width:50%">Description</th>
                                                        <th  style="width:10%" class='text-right'>Amount</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="tbody">
                                                    <?php
                                                    $getright = mysqli_query($conn, "Select *,date_format(date,'%d-%m-%Y') as mydt from `$trandb` 
                                                                        where accode = '$getac[accode]' and date >= '$mfrmdate' and date <= '$mtodate' 
                                                                        and amount > 0 order by date,vouchno") or die(mysqli_error($conn));

                                                    $rdescrip = '';
                                                    $url = '';
                                                    while ($rowright = mysqli_fetch_array($getright)) {
                                                        $rnctr++;
                                                        $rsource = $rowright['source'];
                                                        switch ($rsource) {
                                                            case "PU":
                                                                $rdescrip = 'Goods Received from Karigar';
                                                                $outdb = 'purtran';
                                                                $url = "purchase.php?mode=edit&vouchno=$rowright[vouchno]";

                                                                break;

                                                            case "REPG":
                                                                $rdescrip = 'Repair Given To Karigar';
                                                                $outdb = 'repgivtran';
                                                                $url = "repairgiven.php?mode=edit&vouchno=$rowright[vouchno]&para=G";

                                                                break;
                                                            case "REPT":
                                                                $rdescrip = 'Repair Recd. From Karigar';
                                                                $outdb = 'reprectran';
                                                                $url = "repairgiven.php?mode=edit&vouchno=$rowright[vouchno]&para=T";


                                                                break;
                                                            case "PUTX":
                                                                $rdescrip = 'Goods Received from Karigar - GST';
                                                                $outdb = 'pgsttran';
                                                                $url = "purchgstmulti.php?mode=edit&vouchno=$rowright[vouchno]";

                                                                break;
                                                            case "BR":
                                                                $rdescrip = 'Bank Receipt';
                                                                $url = "bankrecp.php?mode=edit&vouchno=$rowright[vouchno]";

                                                                $outdb = '';

                                                                break;
                                                            case "CR":
                                                                $rdescrip = 'Cash Receipt';
                                                                $url = "cashrecp.php?mode=edit&vouchno=$rowright[vouchno]";

                                                                $outdb = '';

                                                                break;
                                                            case "JV":
                                                                $rdescrip = 'Journal Entry';
                                                                $outdb = '';

                                                                break;
                                                            default:
                                                                break;
                                                        }
//                                                        echo "<tr class='rgetdtl' id='rgetdtl_$rnctr'>";
                                                        echo "<tr class='clickable-row rgetdtl' id='rgetdtl_$rnctr' data-href='$url' data-target='_blank' >";
                                                        
                                                        echo "<td>$rowright[mydt]</td>";
//                                                        echo "<td><a href='$url' target='_blank'>$rowright[vouchno]</a></td>";
                                                        echo "<td>$rowright[vouchno]</td>";
                                                        echo "<td>$rdescrip</td>";
                                                        echo "<td class='text-right'>" . number_format(abs($rowright['amount']), 2) . "</td>";
                                                        echo "</tr>";
                                                        $totright = $totright + abs($rowright['amount']);

                                                        if ($rsource == 'PU' || $rsource == 'PUTX') {
//                                                    detail part start
                                                            Echo "<tr style='height:10px;' class='rdtlsale' id='rdtlsale_$rnctr'>";
                                                            Echo "<td colspan='6'>";
                                                            Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-hover table-bordered'>";
                                                            echo "<tr class='rdtlhide1' id='rdtlsale_$rnctr' style='background-color: #7f708e;'>";
                                                            Echo "<th style='background-color: #7f708e;width:3%;'>Sr.</th>";
                                                            Echo "<th style='background-color: #7f708e;width:25%;'>Item</th>";
                                                            Echo "<th style='background-color: #7f708e;width:10%;'>Color</th>";
                                                            Echo "<th style='background-color: #7f708e;width:5%;' class='numeric'>Qty.</th>";
                                                            Echo "<th style='background-color: #7f708e;width:7%;' class='numeric'>Rate</th>";
                                                            Echo "<th style='background-color: #7f708e;width:10%;' class='numeric'>Amount</th>";
                                                            Echo "</tr>";

                                                            $ctr2 = 0;
                                                            $tqty = 0;
                                                            $tamt = 0;
//                                $gettran = mysqli_query($conn, "SELECT vouchno,series,party,sum(netamt) as netamt,sum(totqty) as totqty, date_format(`vouchdt`,'%d/%m/%Y') as mydt FROM `$maindb` WHERE `series`='$pmain[series]' and vouchdt >= '$mfrmdate' and `vouchdt`<='$mtodate' ORDER BY `vouchno` desc ")or die(mysqli_error($conn));
                                                            $gettran2 = mysqli_query($conn, "SELECT * FROM `$outdb` WHERE vouchno = '$rowright[vouchno]' ORDER BY `srno` ")or die(mysqli_error($conn));
//                                                        print table($gettran);
                                                            while ($tran2 = mysqli_fetch_array($gettran2)) {
                                                                $getit2 = mysqli_query($conn, "Select name from item where code='$tran2[itemcode]'") or die(mysqli_error($conn));
                                                                $fetit2 = mysqli_fetch_array($getit2);
                                                                $getcl = mysqli_query($conn, "Select name from color where code='$tran2[color]'") or die(mysqli_error($conn));
                                                                $fetcl = mysqli_fetch_array($getcl);
                                                                $rnctr2++;


                                                                $ctr2++;
                                                                Echo "<tr class='getdtl2' id='rgetdtl2_$rnctr2'>";
                                                                Echo "<td style='font-size:10px;'>$ctr2</td>";
                                                                Echo "<td style='font-size:10px;'>$fetit2[name]</td>";
                                                                Echo "<td style='font-size:10px;'>$fetcl[name]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$tran2[qty]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$tran2[rate]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$tran2[amount]</td>";
                                                                Echo "</tr>";
                                                            }
                                                            echo "</table>";

                                                            echo "</td>";
                                                            echo "</tr>";
                                                        }
//                                                    detail part end

                                                        if ($rsource == 'REPT') {
//                                                    detail part start
                                                            Echo "<tr style='height:10px;' class='dtlsale' id='dtlsale_$mnctr'>";
                                                            Echo "<td colspan='6'>";
                                                            Echo "<table style='width:100%;' id='tabital' class='table table-condensed table-bordered'>";
                                                            echo "<tr class='dtlhide1' id='dtlsale_$mnctr' style='background-color: #7f708e;'>";
                                                            Echo "<th style='background-color: #7f708e;width:3%;'>Sr.</th>";
                                                            Echo "<th style='background-color: #7f708e;width:25%;'>Item</th>";
                                                            Echo "<th style='background-color: #7f708e;width:10%;'>Color</th>";
                                                            Echo "<th style='background-color: #7f708e;width:5%;' class='numeric'>Qty.</th>";
                                                            Echo "<th style='background-color: #7f708e;width:7%;' class='numeric'>Rate</th>";
                                                            Echo "<th style='background-color: #7f708e;width:10%;' class='numeric'>Amount</th>";
                                                            Echo "</tr>";


                                                            $ctr2 = 0;
                                                            $tqty = 0;
                                                            $tamt = 0;

                                                            $getktran = mysqli_query($conn, "SELECT * FROM `$outdb` WHERE vouchno = '$rowright[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
//                                                        print table($gettran);
                                                            while ($ktran = mysqli_fetch_array($getktran)) {

                                                                $getkit = mysqli_query($conn, "Select name from item where code='$ktran[itemcode]'") or die(mysqli_error($conn));
                                                                $fetkit = mysqli_fetch_array($getkit);

                                                                $getkcol = mysqli_query($conn, "Select name from color where code='$ktran[color]'") or die(mysqli_error($conn));
                                                                $fetkcol = mysqli_fetch_array($getkcol);
                                                                $mnctr2++;

                                                                $ctr2++;

                                                                Echo "<tr class='getdtl2' style='font-size:8px;' id='getdtl2_$mnctr2'>";
                                                                Echo "<td style='font-size:10px;'>$ctr2</td>";
                                                                Echo "<td style='font-size:10px;'>$fetkit[name]</td>";
                                                                Echo "<td style='font-size:10px;'>$fetkcol[name]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$ktran[qty]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$ktran[rate]</td>";
                                                                Echo "<td style='font-size:10px;' class='numeric'>$ktran[amount]</td>";
                                                                Echo "</tr>";
                                                            }
                                                            echo "</table>";

                                                            echo "</td>";
                                                            echo "</tr>";
                                                        }
//                                                    DETAIL PART END
                                                    }
                                                    echo "<tr >";
                                                    echo "<td></td>";
                                                    echo "<td></td>";
                                                    echo "<td class='text-right' ><b style='font-size:15px;'>Total</b></td>";
                                                    echo "<td class='text-right'><b style='font-size:15px;'>" . number_format($totright, 2) . "</b></td>";
                                                    echo "</tr>";
                                                    $balamt = $openamt - $totleft + $totright;

//                                                browse($openamt);
//                                                browse($totleft);
//                                                browse($totright);
//                                                browse($balamt);
                                                    ?>

                                                </tbody>
                                            </table> 
                                        </td>
                                    </tr>
                                    <tr>

                                        <td class="text-right">
                                            &nbsp;&nbsp;
                                            <?php
                                            if ($balamt < 0) {
                                                echo "<b style='color:red;font-size:20px'>Advance  &nbsp;&nbsp;&nbsp; " . number_format(abs($balamt), 2) . "</b>";
                                            }
                                            ?>

                                        </td>
                                        <td class="text-right">
                                            &nbsp;&nbsp;
                                            <?php
                                            if ($balamt > 0) {
                                                echo "<b style='color:blue;font-size:20px'>Balance  &nbsp;&nbsp;&nbsp; " . number_format(abs($balamt), 2) . "</b>";
                                            }
                                            ?>

                                        </td>
                                    </tr>
                                </tbody>
                            <?php } ?>
                            <tfoot>
                                <tr>
                                    <td colspan="9">
                                    </td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <?php include("includes/linksfoot.php"); ?>
    </body>
    </html>
    <?php
}
?>

