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

$maindb = "actran";

$file = "ledgerbanya_fr.php";
$pdffile = "cust_ledger_pdf.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$para = $_GET["para"];
$party = $_POST["party"];

$formname = "";
if ($para == "customer") {
    $formname = "Customer Ledger";
    $bgcolor = "#7a4ed9";
} elseif ($para == "supplier") {
    $formname = "Supplier Ledger";
    $bgcolor = "#963634";
} elseif ($para == "expense") {
    $formname = "Expense Ledger";
    $bgcolor = "#A53860";
} elseif ($para == "loan") {
    $formname = "Loan Ledger";
    $bgcolor = "#0b4c78";
}

$dtypecond = "";
$mscopecond = "";

$mfrmdate = $_POST["fdate"];
$mtodate = $_POST["tdate"];

if (!empty($party)) {
    $partycond = " AND `accode`='$party' ";
}

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

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

$mfdt = date("d-m-Y", strtotime($mfrmdate));
$mtdt = date("d-m-Y", strtotime($mtodate));

$maccode = $party;

$getpartyname = mysqli_query($conn, "SELECT `name`, openbal, dc FROM `accmast` WHERE `accode`='$maccode'") or die(mysqli_error($conn));
$zname = mysqli_fetch_object($getpartyname);
$mname = $zname->name;
$mopbal = $zname->openbal;
$mopdc = $zname->dc;

if ($mopdc == "D") {
    $mopbal = $mopbal * -1;
}

$getbal = mysqli_query($conn, "SELECT SUM(amount) as oamt FROM `actran` WHERE accode='$party' AND  date < '$mfrmdate'") or die(mysqli_error($conn));
$getamt = mysqli_fetch_array($getbal);
$oamt = $getamt["oamt"];

$mobal = $mopbal + $oamt;

$getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`date`, '%d-%m-%Y') as mydt FROM `$maindb` WHERE `date` >= '$mfrmdate' 
                                        AND `date` <= '$mtodate' and accode = '$party' order by date, srl ") or die(mysqli_error($conn));

$get = mysqli_num_rows($getpmain);

$prnnarr = 1;

if (isset($_POST["view"])) {

    include("includes/linkshead.php");
    ?>
    <style type="text/css">
        #tabital {
            font-style: italic;
        }

        #font1 {
            font-style: italic;
        }

        #boldfont {
            font-weight: bold;
        }

        #loadingIndicator {
            display: flex;
            align-items: center;
            gap: 10px;
            font-family: sans-serif;
            color: #333;
        }

        .spinner {
            width: 24px;
            height: 24px;
            border: 3px solid #ccc;
            border-top: 3px solid #007bff;
            /* Bootstrap blue */
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        /* Spinner Animation */
        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        .buttonsk {
            align-items: center;
            appearance: none;
            background: transparent;
            border: 3px solid
                <?= $bgcolor ?>
            ;
            border-radius: 6px;
            box-sizing: border-box;
            color:
                <?= $bgcolor ?>
            ;
            cursor: pointer;
            display: inline-flex;
            font-family: "JetBrains Mono", monospace;
            height: 38px;
            width: 150px;
            justify-content: center;
            line-height: 1;
            list-style: none;
            overflow: hidden;
            padding-left: 16px;
            padding-right: 16px;
            position: relative;
            text-align: left;
            text-decoration: none;
            transition: box-shadow .15s, transform .15s;
            user-select: none;
            -webkit-user-select: none;
            touch-action: manipulation;
            white-space: nowrap;
            will-change: box-shadow, transform;
            font-size: 18px;
        }

        .buttonsk:active {
            box-shadow:
                <?= $bgcolor ?>
                0 3px 7px inset;
            transform: translateY(2px);
        }

        a:hover {
            color: #cdb4db;
            text-decoration: none;
        }
    </style>
    <script src="MyScript/ledgerbanya.js?a=<?= mt_rand() ?><" type="text/javascript"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>

    <script>
        function saveAsPDF() {
            // Collect all elements with class "noPrint2" (or any other you want)
            const noPrintElements = document.querySelectorAll(".noPrint, .noPrint2");

            // Hide them by adding the "hidden" class
            noPrintElements.forEach(el => el.classList.add("hidden"));

            const element = document.getElementById('content-to-save');
            let showname = document.getElementById('showname')?.textContent || 'NoAccode';
            showname = showname
                .trim()                              // remove start/end spaces
                // .replace(/\s+/g, '_')                // spaces → single underscore
                .replace(/_+/g, '_')                  // collapse multiple underscores
                .replace(/[^a-z0-9_]/gi, '');         // remove other special chars


            // Temporarily scale content to fit A4 landscape width
            const originalWidth = element.style.width;
            element.style.width = "1123px"; // ~A4 landscape in px at 96 DPI

            const opt = {
                margin: [0.2, 0.2, 0.2, 0.2],
                filename: `LEDGERPDF${showname}.pdf`,
                image: { type: 'jpeg', quality: 0.98 },
                html2canvas: {
                    scale: 2,
                    useCORS: true,
                    scrollX: 0,
                    scrollY: 0
                },
                jsPDF: { unit: 'pt', format: 'a4', orientation: 'landscape' },
                pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
            };

            html2pdf().set(opt).from(element).save().then(() => {
                // Restore original width after export
                element.style.width = originalWidth;
                // Show hidden elements again
                noPrintElements.forEach(el => el.classList.remove("hidden"));
            });
        }
    </script>
    </head>

    <body>
        <div class="container" id="content-to-save">

            <?php
            $zroot = $_SESSION["zdir"];

            $getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code`= '1'") or die(mysqli_error($conn));
            $comp = mysqli_fetch_array($getcomp);

            ?>
            <style>
                .HDFont {
                    font-family: "Verdana";
                }

                @media print {
                    .noPrint {
                        display: none;
                    }
                }
            </style>

            <div class="" style="background-color: #98f9f0">
                <table class="" width="100%" id="head">
                    <tr>
                        <td style="font-size:22px" class="HDFont">
                            <?php echo strtoupper($comp['compname']); ?>
                        </td>
                        <td style="text-align:right">
                            <!-- <button
                                onclick="window.open('<?= $pdffile ?>?party=<?= $party ?>&frmdt=<?= $mfrmdate ?>&todt=<?= $mtodate ?>&para=<?= $para ?>', '_blank');"
                                class="btn btn-primary noPrint" style="text-align: right">PDF</button> -->
                            <button class="btn btn-primary noPrint" onclick="saveAsPDF()"
                                style="width: 100px;height:35px;background-color: #4892ff;color:#ffffff;">PDF</button>
                            <button id='cancel' style="background: #26A69A;" type="button" class="btn btn-danger noPrint"
                                onclick="window.close()">
                                Go Back
                            </button>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 12px" class="HDFont">
                            <?php echo $comp['hoadd1']; ?>
                            <?php echo $comp['hoadd2']; ?>
                            <?php echo $comp['hoadd3']; ?>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td></td>
                    </tr>
                    <?php
                    if ($dtype == 1) {
                        $rtype = " - Summary";
                    } elseif ($dtype == 2) {
                        $rtype = " - Detail";
                    } elseif ($dtype == '') {
                        $rtype = '';
                    }
                    ?>
                    <tr>
                        <td style="font-size: 16px;color: red" class="HDFont">
                            <?php echo $formname . ' ' . $rtype; ?>
                        </td>
                        <td style="font-size: 14px" align="right" class="HDFont">
                            Report Date - <?php echo Date("d-m-Y"); ?>
                        </td>
                    </tr>

                    <tr>
                        <td style="font-size: 14px" class="HDFont">
                            <?php if ($mfdt != '') { ?>
                                From Date -
                                <?php echo format_date($mfdt); ?> &nbsp;&nbsp;&nbsp;
                                <?php
                            }
                            if ($mtdt != '') {
                                ?>
                                To Date -
                                <?php
                                echo format_date($mtdt);
                            }
                            ?>
                        </td>
                        <td>
                        </td>
                    </tr>


                    <tr>
                        <td style="font-size: 14px" class="HDFont" colspan="2">
                            <?php echo $rtype2; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 14px" class="HDFont" colspan="2">&nbsp;
                        </td>
                    </tr>
                    <?php

                    if ($getno > 0) {
                        ?>
                        <tr>
                            <td style="font-size: 15px;padding:5px" class="HDFont" colspan="2">
                                Total No. of Record :&nbsp;&nbsp;<b><?php echo $getno; ?></b>
                            </td>
                        </tr>
                    <? }
                    //        elseif ($getno == 0){
//        browse("No Record Found");
//        echo "<script>window.close()</script>";
//        }
                    ?>
                </table>
            </div>


            <input type="hidden" class="printdescrip" value="<?= $_POST["printdescrip"] ?>">
            <input type="hidden" name="accode" id="accode" value="<?= $party ?>" class="form-control text-right accode">

            <?php
            if ($para == "customer") {
                $btnlabel = "Sale";
                $btnval = "S";
                $btnlabel2 = "Receipt";
                $btnval2 = "R";
                $btnlabel3 = "Claim";
                $btnval3 = "SC";

                $divdisplay1 = "";
                $divdisplay2 = "";
                $divdisplay3 = "";
            } elseif ($para == "supplier") {
                $btnlabel = "Purchase";
                $btnval = "PU";
                $btnlabel2 = "Payment";
                $btnval2 = "PY";
                $btnlabel3 = "Claim";
                $btnval3 = "PC";

                $divdisplay1 = "";
                $divdisplay2 = "";
                $divdisplay3 = "";
            } elseif ($para == "expense") {
                $btnlabel2 = "Payment";
                $btnval2 = "PY";

                $divdisplay1 = "display:none";
                $divdisplay2 = "";
                $divdisplay3 = "display:none";
            } elseif ($para == "loan") {
                $btnlabel = "Reciept";
                $btnval = "R";
                $btnlabel2 = "Payment";
                $btnval2 = "PY";

                $divdisplay1 = "";
                $divdisplay2 = "";
                $divdisplay3 = "display:none";
            }
            ?>

            <div class="row noPrint">
                <div class="col-lg-12">
                    <div class="row">
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad text-center" style="<?= $divdisplay1 ?>">
                            <button type="button" class="buttonsk" value="<?= $btnval ?>"><?= $btnlabel ?></button>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 pad text-center" style="<?= $divdisplay2 ?>">
                            <button type="button" class="buttonsk" value="<?= $btnval2 ?>"><?= $btnlabel2 ?></button>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 pad text-center" style="<?= $divdisplay3 ?>">
                            <button type="button" class="buttonsk" value="<?= $btnval3 ?>"><?= $btnlabel3 ?></button>
                        </div>
                        <input type="hidden" id="buttonsAction" value="">
                    </div>
                </div>
            </div>

            <table style="background: white;width: 100%" class="table table-condensed table-hover">
                <thead class="mySearchTr">
                    <tr>
                        <h3
                            style="background-color:<?= $bgcolor; ?>;color:whitesmoke;border: 1px solid black;border-radius:7px;" id="showname" >
                            &nbsp; <?= $mname ?></h3>
                    </tr>
                    <tr style="background-color: #8d99ae;">
                        <th style="width:4%">Sr</th>
                        <th style="width:8%">Date</th>
                        <th style="width:3%">Source</th>
                        <th style="width:6%">Voucher</th>
                        <th style="width:15%">Transaction</th>
                        <th style="width:30%" class="showdescrip">Description</th>
                        <th style="width:26%">Remarks</th>
                        <th style="width:10%" class="text-right">Amount</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $ctr = 0;
                    $totamt = 0;
                    $gtot = 0;

                    $vdate1 = strtotime($mfrmdate);
                    $vdate = date('d-m-Y', $vdate1);

                    $mdescrip = "Opening Balance";

                    $ctr++;
                    echo "<tr id='boldfont'>";
                    echo "<td>$ctr</td>";
                    echo "<td>$vdate</td>";
                    echo "<td></td>";
                    echo "<td></td>";
                    echo "<td>$mdescrip</td>";
                    echo "<td class='showdescrip'></td>";
                    echo "<td></td>";
                    echo "<td class='text-right'>" . number_format($mobal, 2) . "</td>";
                    echo "</tr>";

                    $gtot = $gtot + $mobal;

                    echo "<tr id='boldfont'>";
                    echo "<td></td>";
                    echo "<td></td>";
                    echo "<td></td>";
                    echo "<td></td>";
                    echo "<td></td>";
                    echo "<td class='showdescrip'></td>";
                    echo "<td class='text-right'>Balance</td>";
                    echo "<td style='border-top:1px solid black; background-color:lightyellow' class='text-right'>" . number_format($gtot, 2) . "</td>";
                    echo "</tr>";

                    while ($pmain = mysqli_fetch_array($getpmain)) {
                        $amount = $pmain['amount'];
                        $msource = $pmain['source'];
                        $mvouch = $pmain['vouchno'];

                        $getname = mysqli_query($conn, "SELECT accode,name FROM `accmast` where accode='$pmain[accode]' order by name") or die(mysqli_error($conn));
                        $fetname = mysqli_fetch_array($getname);

                        $mnarr = "";
                        $mchqdtl = "";
                        $desc = "";

                        switch ($msource) {

                            case "PU";
                                $head = "Purchase";
                                $url = "purchase.php?vouchno=$mvouch&mode=edit";
                                $totdiscprov = $totdiscprov + $mamount;

                                if ($prnnarr == 1) {
                                    $nqry1 = mysqli_query($conn, "SELECT vouchno as billno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mbilldate,
                                                                                `remark` FROM `purchase`
                                                                                WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                    $nqry = mysqli_fetch_array($nqry1);
                                    $mbill = $nqry["billno"];
                                    $mbilldt = $nqry["mbilldate"];
                                    $mnarr = trim($nqry["remark1"]) . " " . trim($nqry["remark2"]);
                                    $mchqdtl = "Bill No. : " . trim($mbill) . " &nbsp;&nbsp;Dated : " . $mbilldt;
                                }

                                break;

                            case "SL";
                                $head = "Sale";
                                $url = "sale.php?vouchno=$mvouch&mode=edit";
                                //  if ($prnnarr == 1) {
                                $nqry1 = mysqli_query($conn, "SELECT vouchno as invno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mbilldate,
                                                                            `remark` FROM `sale`
                                                                            WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                $nqry = mysqli_fetch_array($nqry1);
                                $mbill = $nqry["invno"];
                                $mbilldt = $nqry["mbilldate"];

                                $mnarr = trim($nqry["remark"]);
                                $mchqdtl = "Bill No. : " . trim($mbill) . " &nbsp;&nbsp;Dated : " . $mbilldt;
                                // }
                                break;

                            case "SCL";
                                $head = "Sale Claim";
                                $url = "slclaim.php?vouchno=$mvouch&mode=edit";

                                //  if ($prnnarr == 1) {
                                $nqry1 = mysqli_query($conn, "SELECT vouchno as invno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mbilldate,
                                                                            `remark` FROM `slclaim`
                                                                            WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                $nqry = mysqli_fetch_array($nqry1);
                                $mbill = $nqry["invno"];
                                $mbilldt = $nqry["mbilldate"];

                                $mnarr = trim($nqry["remark"]);
                                $mchqdtl = "Bill No. : " . trim($mbill) . " &nbsp;&nbsp;Dated : " . $mbilldt;
                                // }
                                break;

                            case "PCL";
                                $head = "Purchase Claim";
                                $url = "puclaim.php?vouchno=$mvouch&mode=edit";

                                //  if ($prnnarr == 1) {
                                $nqry1 = mysqli_query($conn, "SELECT vouchno as invno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mbilldate,
                                                                            `remark` FROM `puclaim`
                                                                            WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                $nqry = mysqli_fetch_array($nqry1);
                                $mbill = $nqry["invno"];
                                $mbilldt = $nqry["mbilldate"];

                                $mnarr = trim($nqry["remark"]);
                                $mchqdtl = "Bill No. : " . trim($mbill) . " &nbsp;&nbsp;Dated : " . $mbilldt;
                                // }
                                break;

                            case "BR";
                                $head = "Bank Receipt";
                                $url = "bankrecp.php?vouchno=$mvouch&mode=edit";
                                if ($prnnarr == 1) {
                                    $nqry1 = mysqli_query($conn, "SELECT chqno, DATE_FORMAT(`chqdate`, '%d-%m-%Y') as mbilldate, 
                                                                                remark1, remark2  FROM `bankrecp`
                                                                                WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                    $nqry = mysqli_fetch_array($nqry1);
                                    $mbill = $nqry["chqno"];
                                    $mbilldt = $nqry["mbilldate"];
                                    //                                                                        $mnarr = $nqry["narration"];
                
                                    $mchqdtl = "Bill No. : " . trim($mbill) . " &nbsp;&nbsp;Dated : " . $mbilldt;
                                }
                                break;

                            case "BP";
                                $head = "Bank Payment";
                                $url = "bankpay.php?vouchno=$mvouch&mode=edit";
                                if ($prnnarr == 1) {
                                    $nqry1 = mysqli_query($conn, "SELECT chqno, DATE_FORMAT(`chqdate`, '%d-%m-%Y') as mbilldate
                                                                                FROM `bankpay`
                                                                                WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                    $nqry = mysqli_fetch_array($nqry1);
                                    $mbill = $nqry["chqno"];
                                    $mbilldt = $nqry["mbilldate"];
                                    $mnarr = trim($nqry["remark1"]) . " " . trim($nqry["remark2"]);

                                    $mchqdtl = "Bill No. : " . trim($mbill) . " &nbsp;&nbsp;Dated : " . $mbilldt;
                                }
                                break;

                            case "CR";
                                $head = "Receipt";
                                $url = "cashrecp.php?vouchno=$mvouch&mode=edit";
                                if ($prnnarr == 1) {
                                    $nqry1 = mysqli_query($conn, "SELECT a.*, b.name  FROM `cashrecp` a, accmast b
                                                                                WHERE a.vouchno='$mvouch' and a.bankname = b.accode ") or die(mysqli_error($conn));
                                    $nqry = mysqli_fetch_array($nqry1);

                                    $desc = $nqry['name'];
                                    $mnarr = trim($nqry["remark1"]) . " " . trim($nqry["remark2"]);
                                }
                                break;

                            case "CP";
                                $head = "Payment";
                                $url = "cashpay.php?vouchno=$mvouch&mode=edit";
                                if ($prnnarr == 1) {
                                    $nqry1 = mysqli_query($conn, "SELECT a.*,b.name  FROM `cashpay` a, accmast b
                                                                                WHERE a.vouchno='$mvouch' and a.bankname = b.accode ") or die(mysqli_error($conn));
                                    $nqry = mysqli_fetch_array($nqry1);
                                    $desc = $nqry['name'];

                                    $mnarr = trim($nqry["remark1"]) . " " . trim($nqry["remark2"]);
                                }
                                break;

                            case "TR";
                                $head = "Contra / Transfer";
                                $url = "contra.php?vouchno=$mvouch&mode=edit";
                                if ($prnnarr == 1) {
                                    $nqry1 = mysqli_query($conn, "SELECT `narration` FROM `contra`
                                                                                WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
                                    $nqry = mysqli_fetch_array($nqry1);
                                    $mnarr = $nqry["narration"];
                                }
                                break;

                            case "JV";
                                $head = "JV Entry";
                                $url = "jventry.php?vouchno=$mvouch&mode=edit";

                                if ($amount < 0) {
                                    $getcash = mysqli_query($conn, "Select a.remark1 as `narration`, b.name  from `jventry` a, accmast b where 
                                                                                           a.`vouchno`='$mvouch' and a.party = b.accode ") or die(mysqli_error($conn));
                                } else {
                                    $getcash = mysqli_query($conn, "Select a.remark1 as `narration`, b.name from `jventry` a, accmast b where 
                                                                                           a.`vouchno`='$mvouch' and a.bankname = b.accode ") or die(mysqli_error($conn));
                                }
                                $fetcash = mysqli_fetch_array($getcash);
                                $mchqdtl = $fetcash['name'];

                                if ($prnnarr == 1) {
                                    $mnarr = $fetcash["narration"];
                                }
                                break;

                            case "DG";
                                $head = "Discount Given";
                                break;

                            case "DR";
                                $head = "Discount Received";
                                break;

                            default:
                                $head = "Other";
                        }


                        $ctr++;
                        echo "<tr id='boldfont' class='clickable-row2' data-href='$url' data-target='_blank'>";
                        echo "<td>$ctr</td>";
                        echo "<td>$pmain[mydt]</td>";
                        echo "<td>$msource</td>";
                        echo "<td>$pmain[vouchno]</td>";
                        echo "<td>$head</td>";
                        echo "<td class='showdescrip'>$desc $mchqdtl</td>";
                        echo "<td>$mnarr</td>";
                        echo "<td class='text-right'>" . number_format($amount, 2) . "</td>";
                        echo "</tr>";

                        $gtot = $gtot + $amount;

                        echo "<tr id='boldfont'>";
                        echo "<td></td>";
                        echo "<td></td>";
                        echo "<td></td>";
                        echo "<td></td>";
                        echo "<td></td>";
                        echo "<td class='showdescrip'></td>";
                        echo "<td class='text-right'>Balance</td>";
                        echo "<td style='border-top:1px solid black; background-color:lightyellow' class='text-right'>" . number_format($gtot, 2) . "</td>";
                        echo "</tr>";
                    }
                    ?>
                    <tr style="background-color: #8d99ae;">
                        <td colspan="8"></td>
                    </tr>
                </tbody>
            </table>


            <div class="modal fade ModalEntry" 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 Title1">Sale</h4>
                            <h4 class="modal-title Title2">Purchase</h4>
                            <h4 class="modal-title Title3">Receipt</h4>
                            <h4 class="modal-title Title4">Payment</h4>
                            <h4 class="modal-title Title5">Claim</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 marg">Date</label>
                                </div>
                                <div class="col-lg-4 col-md-3 col-sm-6 col-xs-6 pad">
                                    <input type="date" name="vouchdt" value="<?php echo date('Y-m-d'); ?>"
                                        class="form-control vouchdt" autofocus>
                                </div>
                            </div>

                            <div class="row Title1">
                                <div class="col-lg-4 col-md-3 col-sm-3 col-xs-3 text-right">
                                    <label class="control-label marg">Pairs</label>
                                </div>
                                <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 pad">
                                    <input type="number" name="pairs" id="pairs" value=""
                                        class="form-control text-right pairs">
                                </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 marg">Amount</label>
                                </div>
                                <div class="col-lg-4 col-md-3 col-sm-6 col-xs-6 pad">
                                    <input type="number" step="any" name="amount" id="amount" value=""
                                        class="form-control text-right amount">
                                </div>
                            </div>

                            <div class="row showtype1">
                                <div class="col-lg-4 col-md-1 col-sm-4 col-xs-4 text-right">
                                    <label class="label-control marg">Type</label>
                                </div>
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                    <select id="type1" name="type1" class="form-control select type type1"
                                        style="width:100%">
                                        <option value=""></option>
                                        <option value="R">Credit</option>
                                        <option value="U">UPI</option>
                                        <option value="C">Cash</option>
                                    </select>
                                </div>
                            </div>

                            <div class="row showtype2">
                                <div class="col-lg-4 col-md-1 col-sm-4 col-xs-4 text-right">
                                    <label class="label-control marg">Type</label>
                                </div>
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                    <select id="type2" name="type2" class="form-control select type type2"
                                        style="width:100%">
                                        <option value=""></option>
                                        <option value="U">UPI</option>
                                        <option value="C">Cash</option>
                                    </select>
                                </div>
                            </div>

                            <div class="row showcashbank">
                                <div class="col-lg-4 col-md-1 col-sm-3 col-xs-3 text-right">
                                    <label class="label-control marg">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 select bankname"
                                        style="width:100%">
                                        <option value=""></option>
                                        <?php
                                        $mown1 = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` WHERE accode != '3' AND (`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">
                                <div class="col-lg-4 col-md-3 col-sm-3 col-xs-3 text-right">
                                    <label class="control-label marg">Remarks</label>
                                </div>
                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                                    <input type="text" name="remark" id="remark" value="" maxlength="50"
                                        class="form-control remark">
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-xs-12 text-right search-action-bar">
                                    <input type="button" class="btn btn-primary saveent" value="SAVE">
                                </div>
                            </div>

                            <div id="loadingIndicator" style="display: none;">
                                <div class="spinner"></div>
                                <span>Saving data, please wait...</span>
                            </div>

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

        </div>

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

    </html>
    <?php
}
?>