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

$maindb = 'prdmain';
$trandb = 'prdtran';
$trandb2 = 'pumpgrp';

$accdb = 'actran';
$stkdb = 'transacn';

$printfile = "sale_print.php";
$file = 'pumpreading.php';

$trandbexist = 1;
$source = "SLPP";
$keyfld = "vouchno";

$myyear = $_SESSION["tit_" . $dbname];

//date_default_timezone_set('Asia/Kolkata');
$time = date('H:i:s');

$usertype = $_SESSION["usertype"];
$username = $_SESSION["username_" . $dbname];

//browse($username);
$formname = 'Pump Reading';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = substr($zdb, -4);
$zStartDate = getzdates($zyear, 'S');
$zEndDate = getzdates($zyear, 'E');
//browse($zyear);
$keycond = '';

mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;

    $vouchdt = trim($_POST["vouchdt"]);
    $shift = trim($_POST["shift"]);
    $staff = trim($_POST["staff"]);
    $cashamt = trim($_POST["cashamt"]);

    date_default_timezone_set("Asia/Dubai");
    $usertime = date("Y-m-d H:i:sa");

    $oms = $_POST['oms'];

    $count = $_POST["items"];
    $count2 = $_POST["items2"];

    $mvouch = $qvouch;

    $accode = $party;
    $grpcode = '010';
    $purcode = '014';

//    if ($vouchdt == '0000-00-00') {
//        browse("Date Cannot Be Empty");
//        $a = 0;
//    }

    if ($a == 1) {
        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `$trandb2` WRITE,  `$stkdb` WRITE, `$accdb` WRITE, `cashrecp` WRITE, `accmast` WRITE, `product` WRITE")or die(mysqli_error($conn));

        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `$maindb` where vouchno != '' $keycond LIMIT 1 ") or die(mysqli_error($conn));
            if (mysqli_num_rows($gen1) > 0) {
                $vvouch = mysqli_fetch_assoc($gen1);
                $qvouch = $vvouch["maxcode"] + 1;
            } else {
                $qvouch = '1';
            }
            $mvouch = $qvouch;
        }

        //**************************************************        auto cash Entry Start  ***************************************

        $mcashvouch = $_POST["cashvouch"];
        $cashamt = 0;
        if ($cashamt > 0) {

            if ($mcashvouch == '0' || $mcashvouch == '') {
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `cashrecp` where vouchno!=''  LIMIT 1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen1) > 0) {
                    $vvouch = mysqli_fetch_assoc($gen1);
                    $tcashvouch = $vvouch["maxcode"] + 1;
                } else {
                    $tcashvouch = '1';
                }
                $mcashvouch = $tcashvouch;
            }

            $genrecp = mysqli_query($conn, "SELECT vouchno, recpno FROM `cashrecp` where `vouchno` = '$mcashvouch' ") or die(mysqli_error($conn));
            if (mysqli_num_rows($genrecp) > 0) {
                $fetrecp = mysqli_fetch_array($genrecp);
                $mrecpno = $fetrecp['recpno'];
                $mcashvouch = $fetrecp['vouchno'];
            } else {
                $gen2 = mysqli_query($conn, "SELECT MAX(recpno) AS maxcode FROM `cashrecp` where `bankname` = '3' LIMIT 1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen2) > 0) {
                    $gvouch = mysqli_fetch_assoc($gen2);
                    $mrecpno1 = $gvouch["maxcode"] + 1;
                } else {
                    $mrecpno1 = '1';
                }
                $mrecpno = $mrecpno1;
            }
            mysqli_query($conn, "DELETE FROM `cashrecp` WHERE $keyfld ='$mcashvouch' ") or die(mysqli_error($conn));
            mysqli_query($conn, "INSERT INTO `cashrecp`( vouchno ,`vouchdt`, `bankname`, `bankinit`, `recpno`, `party`,`amount`,`remark1`,`remark2`,`trnflag`)
                                             Values ('$mcashvouch', '$vouchdt', '3', 'COH', '$mrecpno','49','$cashamt','Cash Recd. From Pump Reading','Sale No.$mvouch','P') ") or die(mysqli_error($conn));
            // cash part  

            $minus_amt = ($cashamt * -1);

            mysqli_query($conn, "DELETE FROM `$accdb` WHERE `$keyfld`='$mcashvouch' and `source` = 'CR' $keycond") or die(mysqli_error($conn));

            // cash part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, recpno, source, trnno, bankinit, accode, grpcode, amount, trnflag)
                    VALUES ('$vouchdt', '$mcashvouch', '$mrecpno', 'CR', '001', 'COH', '3','002', '$minus_amt', 'P') ") or die(mysqli_error($conn));

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, recpno, source, trnno, bankinit, accode, grpcode, amount, trnflag)
                    VALUES ('$vouchdt', '$mcashvouch', '$mrecpno', 'CR', '002', 'COH', '49', '010', '$cashamt','P') ") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "DELETE FROM `cashrecp` WHERE `$keyfld`='$mcashvouch' ") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM `actran` WHERE `$keyfld`='$mcashvouch' AND `source`='CR' ")or die(mysqli_error($conn));
            $mcashvouch = "";
        }

//**************************************************        auto cash Entry End    *************************************** 

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));

        $cnt = 0;
        $cntamt = 0;

        for ($i = 0; $i <= $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $pumpno = $_POST["pump_$i"];
            $prodcode = $_POST["prodcode_$i"];
            $prodname = $_POST["prodname_$i"];
            $opening = $_POST["opening_$i"];
            $closing = $_POST["closing_$i"];
            $sale = $_POST["sale_$i"];
            $testing = $_POST["testing_$i"];
            $transfer = $_POST["transfer_$i"];
            $evaporate = $_POST["evaporate_$i"];
            $netsale = $_POST["netsale_$i"];

            if (!empty($prodcode)) {
                $cnt++;

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `srno`, `pumpno`, `prodcode`, `prodname`, `opening`, `closing`, 
                                                           `sale`, `testing`, `transfer`, `evaporate`, `netsale`) 
                                                   VALUES ('$mvouch', '$cnt', '$pumpno', '$prodcode', '$prodname', '$opening', '$closing', 
                                                           '$sale', '$testing', '$transfer', '$evaporate', '$netsale') ") or die(mysqli_error($conn));
            }
        }
        
        mysqli_query($conn, "DELETE FROM `$trandb2` WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE vouchno='$mvouch' and source='$source' ") or die(mysqli_error($conn));
        
        $cnt2 = 0;
        for ($j = 0; $j <= $count2; $j++) {
            $msrno = $_POST["srno_$j"];
            $tprodcode = $_POST["tprodcode_$j"];
            $tprodname = $_POST["tprodname_$j"];
            $tsale = $_POST["tsale_$j"];
            $trate = $_POST["trate_$j"];
            $tcredsale = $_POST["credsale_$j"];
            $tcashsale = $_POST["cashsale_$j"];
            $tcredamt = $_POST["credamt_$j"];
            $tcashamt = $_POST["cashamt_$j"];
            $tcost = $_POST["cost_$j"];
            $tparty = 0;

            
            if (!empty($tsale)) {
                $tqty = $tcashsale * -1;
                $group = $source . $mvouch;

                $cnt2++;

                mysqli_query($conn, "INSERT INTO `$trandb2`(`vouchno`, `srno`, `prodcode`,  `sale`, `rate`, `credsale`,  
                                                            `cashsale`, `cost`, `credamt`, `cashamt`)
                                                     VALUES('$mvouch', '$cnt2', '$tprodcode', '$tsale','$trate','$tcredsale', 
                                                            '$tcashsale', '$tcost', '$tcredamt', '$tcashamt')") or die(mysqli_error($conn));

                mysqli_query($conn, "INSERT INTO `$stkdb`(`srno`, `yearno`, `vouchno`, `vouchdt`, `prodcode`,  rate,
                                                          `qty`, `source`, amount, accode, `group` ,  `cost`, `ordno`)
                                                   VALUES('$cnt2', '$myyear', '$mvouch', '$vouchdt', '$tprodcode','$trate',
                                                          '$tqty', '$source', '$tcashamt', '$party', '$group', '$cost', '1')") or die(mysqli_error($conn));
            }
        }
        
############################### Accounts Part ######################################################

        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source' ") OR die(mysqli_error($conn));

        if ($cashamt > 0) {
            $minus_amt = ($cashamt * -1);

            // sale part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, custcode, grpcode, amount )
                           VALUES ('$vouchdt','$mvouch', '$source', '001', '$purcode', '', '005', '$cashamt' )") or die(mysqli_error($conn));

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, custcode, grpcode, amount )
                               VALUES ('$vouchdt','$mvouch', '$source', '002', '49', '999999', '010', '$minus_amt' )") or die(mysqli_error($conn));
        }

        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(vouchno, `vouchdt`, shift, staffcode , cashamt,cashvouch)
                                      VALUES('$mvouch', '$vouchdt', '$shift', '$staff', '$cashamt', '$mcashvouch')") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt', shift='$shift', staffcode='$staff', `cashvouch`='$mcashvouch', 
                                                       cashamt='$cashamt' WHERE `vouchno` = '$mvouch' ") or die(mysqli_error($conn));
        }

        mysqli_query($conn, "UNLOCK TABLES");

        if ($addflag == 1) {
            insmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form");
        } else {
            updmess();
        }
    }
}

if ($addflag != 1) {
    $getvouch = '';

    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch'  ") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);

    $getstaf = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `accode`= '$get[staffcode]'") or die(mysqli_error($conn));
    $lstaf = mysqli_fetch_array($getstaf);
    $rd = "readonly";

    $delcsh = $get['cashvouch'];
    mysqli_query($conn, "Delete from `save_read_temp` where vouchno = '$getvouch'");
}

if (isset($_GET["delete"])) {
    mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `$trandb2` WRITE,  `$stkdb` WRITE, `$accdb` WRITE, `cashrecp` WRITE, `accmast` WRITE")or die(mysqli_error($conn));

    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    $delcond1 = " source = 'CR' and vouchno = '$delcsh'";
    $delcond3 = " vouchno = '$delcsh' ";
    $delcond2 = " vouchno = '$_GET[vouchno]'";

    delnew($zdb, "$maindb", "$delcond2", "$file?mode=last");
    delnew($zdb, "$trandb", "$delcond2", "$file?mode=last");
    delnew($zdb, "$trandb2", "$delcond2", "$file?mode=last");
    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond1", "$file?mode=last");
    delnew($zdb, "cashrecp", "$delcond3", "$file?mode=last");

    mysqli_query($conn, "UNLOCK TABLES");
}

include("includes/linkshead.php");
?>
<script src="MyScript/pumpreading.js" type="text/javascript"></script>
<script src="MyScript/pumpread_search.js" type="text/javascript"></script>
<!--<script src="MyScript/search_item_sale.js?A=<?= mt_rand(); ?>" type="text/javascript"></script>-->
<!--<script src="MyScript/checkdate.js" type="text/javascript"></script>-->
<!--<script>
    $(document).ready(function () {
      
    })
</script>-->

</head>
<!DOCTYPE html>

<body>
    <form action='' method='post'>
        <div class="col-lg-3 pad text-center" id="overlay_form" style="display:none;z-index:999;">
            <button type="button" id="close_form" style="float: right;font-weight: bold;font-size: 18px;color:red;" ><i class="fa fa-close"></i></button>
            <div style='width:100%;' id='browdata'>
            </div>
        </div>
        <!-- Default box -->
        <div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading" style="height:40px">
                        <div class="col-lg-10 col-md-10 col-sm-10 col-xs-12">
                            <h3 class="panel-title" style="color:black"><a class="myPrint"><?php echo $formname; ?></a></h3>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-12">
                            <input type="date" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                            <input type="date" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                            <h4 class="panel-title" style="float:right"><b><?php echo $get['username'] ?></b></h4>
                        </div>

                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-3 text-right pad">
                                <label class="label-control marg" >Date</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-4 pad">
                                <input type="hidden" class="form-control form addflg" name="addflg"  value="<?php Echo "$addflag"; ?>">
                                <input type="hidden" class="form-control form billflag" name="billflag"  value="">
                                <input type="hidden" class="form-control form chgflag" name="chgflag"  value="">
                                <input type="hidden" class="form-control form vouchno" name="vouchno"  value="<?php Echo "$qvouch"; ?>">
                                <input type="hidden" class="form-control form cashvouch" name="cashvouch"  value="<?php Echo ($addflag != 1) ? $get["cashvouch"] : ""; ?>">
                                <input type="date" class="form-control form vouchdt focusfield" name="vouchdt"  value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" autofocus required <?= $rd ?>>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-3 text-right pad">
                                <label class="label-control marg" >Shift</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-4 pad">
                                <select name="shift" id="shift" class="form-control form shift select2 " required>
                                    <option value="<?php echo ($addflag != 1) ? $get['shift'] : ""; ?>"><?php echo ($addflag != 1) ? $get['shift'] : ""; ?></option>
                                    <?php
//                                    if ($addflag == 1) {
                                    $mshift = mysqli_query($conn, "SELECT * FROM shift order by shift") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mshift)) {
                                        echo "<option value='$trow[shift]'>$trow[shift]</option>";
                                    }
//                                    }
                                    ?>
                                </select>
                            </div>

                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Staff</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-7 col-xs-9  pad">
                                <select name="staff" id="staff" class="form-control form select2 staff" required>
                                    <option value="<?php echo ($addflag != 1) ? $lstaf['accode'] : ""; ?>"><?php echo ($addflag != 1) ? $lstaf['name'] : ""; ?></option>
                                    <?php
                                    $mstaff = mysqli_query($conn, "SELECT * FROM accmast where grpcode = '040' order by name") or die(mysqli_error($conn));
                                    while ($tsta = mysqli_fetch_array($mstaff)) {
                                        echo "<option value='$tsta[accode]'>$tsta[name]</option>";
                                    }
                                    ?>
                                </select>

                            </div>
                        </div>
                    </div>


                    <div class="sloader3 text-center">
                        <img src="images/search.gif" alt="loading">       
                    </div>
                    <div class="table-responsive readtab">
                        <table class="table-striped table-condensed table-bordered tab" width="100%">
                            <thead  class="mySearchTr">
                                <tr>
                                    <th style="width: 1%">Sr.</th>
                                    <th style="width: 1%" class="text-left">Pump</th>
                                    <th style='width: 4%' class="text-left">Prod Code</th>                                        
                                    <th style='width: 10%' class="text-left">Product</th>                                        
                                    <th style='width: 6%' class="text-right">Opening</th>                                        
                                    <th style='width: 6%' class="text-right">Closing</th>                                        
                                    <th style='width: 6%' class="text-right">Sale</th>
                                    <th style='width: 6%' class="text-right">Testing</th>
<!--                                    <th style='width: 6%' class="text-right">Transfer</th>
                                    <th style='width: 6%' class="text-right">Evaporate</th>                                        -->
                                    <th style='width: 6%' class="text-right">Net Sale</th>                                        

                                </tr>
                            </thead>
                            <tbody class="tbody">
                                <?php
                                if ($addflag != 1) {
                                    $qry = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$getvouch' ORDER BY srno") or die(mysqli_error($conn));
                                    $ctr = 0;
                                    while ($row = mysqli_fetch_array($qry)) {
                                        $getpd = mysqli_query($conn, "SELECT name FROM `product` WHERE `prodcode`= '$row[prodcode]'") or die(mysqli_error($conn));
                                        $lpd = mysqli_fetch_array($getpd);
                                        Echo "<tr>";
                                        Echo "<td><input type='text' class='srno text-right form-control  form'     name='srno_$ctr'  value='$row[srno]' readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='pump text-right form-control  form'     name='pump_$ctr'  value='$row[pumpno]' readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form prodcode'             name='prodcode_$ctr'  value='$row[prodcode]' readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form product'              name='product_$ctr' value='$lpd[name]' readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right opening'   name='opening_$ctr'  value='$row[opening]' readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right closing'   name='closing_$ctr'  value='$row[closing]'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right sale'      name='sale_$ctr'       value='$row[sale]' tabindex='-1'readonly></td>";
                                        Echo "<td><input type='text' class='form-control form text-right testing'   name='testing_$ctr'      value='$row[testing]'></td>";
//                                        Echo "<td><input type='text' class='form-control form text-right transfer'  name='transfer_$ctr'      value='$row[transfer]'></td>";
//                                        Echo "<td><input type='text' class='form-control form text-right evaporate' name='evaporate_$ctr'    value='$row[evaporate]' ></td>";
                                        Echo "<td><input type='text' class='form-control form text-right netsale'   name='netsale_$ctr'    value='$row[netsale]'  tabindex='-1'readonly></td>";
                                        Echo "</tr>";
                                        $ctr++;
                                    }
                                }
                                ?>
                            <input type="hidden" id="items" name="items" value="<?php Echo ($addflag != 1) ? $ctr : 1; ?>">  

                            </tbody>
                        </table>
                        <br>
                        <button type="button" class="form btn btn-default pumpnext" style="width: 150px;float: right">Next</button>
                    </div>


                    <div class="table-responsive saletab tbody2">
                        <?php
                        if ($addflag != 1) {
                            ?>
                            <table class="table-striped table-condensed table-bordered tab" width="100%">
                                <thead  class="mySearchTr">
                                    <tr>
                                        <th style='width: 10%' class="text-left">Product</th>                                        
                                        <th style='width: 7%' class="text-center">Sale</th>
                                        <th style='width: 7%' class="text-center">Rate</th>
                                        <th style='width: 8%' class="text-center">Credit Sale</th>
                                        <th style='width: 8%' class="text-center">Credit Amt.</th>
                                        <th style='width: 8%' class="text-left">Cash Sale</th>                                        
                                        <th style='width: 8%' class="text-left">Cash Amt.</th>                                        
                                    </tr>
                                </thead>
                                <tbody class="">
                                    <?php
//                                if ($addflag != 1) {
                                    $qry2 = mysqli_query($conn, "SELECT * FROM  `$trandb2` WHERE vouchno='$get[vouchno]'") or die(mysqli_error($conn));
//                                    print table($qry2);
                                    $ctr2 = 0;
                                    while ($row2 = mysqli_fetch_array($qry2)) {
                                        $getpd = mysqli_query($conn, "SELECT code,name,rate FROM `product` WHERE `prodcode`= '$row2[prodcode]'") or die(mysqli_error($conn));
                                        $lpd = mysqli_fetch_array($getpd);
                                        $code = $lpd['code'];

                                        Echo "<tr>";
                                        Echo "<td><input type='hidden' class='form-control form tprodcode'          name='tprodcode_$ctr2' value='$row2[prodcode]' readonly tabindex='-1'>"
                                        . "<input type='text' class='form-control form tproduct'                    name='tproduct_$ctr2' value='$lpd[name]'  readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right tsale'     name='tsale_$ctr2'  value='$row2[sale]'   readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right trate'     name='trate_$ctr2'  value='$row2[rate]'   readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right credsale'  name='credsale_$ctr2'  value='$row2[credsale]'   readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right credamt'   name='credamt_$ctr2'       value='$row2[credamt]'   readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right cashsale'  name='cashsale_$ctr2'  value='$row2[cashsale]'   readonly tabindex='-1'></td>";
                                        Echo "<td><input type='text' class='form-control form text-right cashamt'   name='cashamt_$ctr2'       value='$row2[cashamt]'   readonly tabindex='-1'></td>";
                                        Echo "</tr>";


                                        $ctr2++;
                                    }
                                    ?>
                                <input type="hidden" id="items2" name="items2" value="<?php Echo ($addflag != 1) ? $ctr2 : 1; ?>">  
                                </tbody>
                            </table>
                            <div class="row">

                                <div class="col-lg-10 col-xs-8 pad text-right">
                                    <label class="label-control marg">Cash Amount(Rs.)</label>
                                </div>
                                <div class="col-lg-2 col-xs-3 pad">
                                    <input type="number" step="any" style='color:blue' name="cashamt" class="form-control form text-right cashamt" readonly value="<?php Echo $get['cashamt']; ?>">    
                                </div>
                            </div>
                        <?php }
                        ?>
                    </div>
                    <div class="row">
                        <div class="col-lg-9">
                        </div>
                        <div class="col-lg-1">
                            <button type="button" class="form btn btn-default pumpprev" style="background-color: #F2AA3E;width: 150px;color: white;font-size: 15px;">Previous</button>
                        </div>
                        <!--                        <div class="col-lg-1">
                                                </div>-->
                        <div class="col-lg-1" style="padding-left: 4%;">

                            <button type="button" class="form btn btn-default finishtab" style="background-color: #26A69A;color: white;font-size: 15px;width: 150px;">Check & Finish</button>
                        </div>
                    </div>
                </div>

                <div class="col-lg-12 col-xs-12 pad">
                    <div class="col-lg-9 pad">
                        <?php
                        if ($get['canc_flag'] != '') {
                            ?>
                            <img src="images/cancel.jpg" alt="Cancelled Bill" style="width:100%;height:100%">
                        <?php } ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
        <div class="panel panel-default">
            <div class="panel-body">
                <?php include("includes/buttons.php"); ?>
                <script>
                    $(document).ready(function () {

                        var usertype = <?= $usertype ?>;
                        if (usertype == 3) {
                            $("#hedit").hide();
                        }
                    });
                </script>
            </div>
        </div>
    </div>
</div>
</div>
</form>


<div class="modal fade" id="cancmodel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="col-lg-11">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Cancel Bill</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-12 upload">
                            <form id="upload_form" method="post">

                                <div class="row pad">
                                    <input type="hidden" name="cancvouch" id="cancvouch" value='<?php Echo ($addflag != 1) ? $get['vouchno'] : "$qvouch"; ?>'>
                                    <input type="hidden" name="cashvouch2" id="cashvouch2" value='<?php Echo ($addflag != 1) ? $get['cashvouch'] : ""; ?>'>
                                    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-5 text-right">
                                        <label class="label-control marg">Cancel Date</label>
                                    </div>
                                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-7">

                                        <input type="date" name="cancdate" value="<?php Echo ($addflag != 1) ? $get['cancdate'] : ""; ?>" class="form-control cancdate">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-6 col-md-6 col-sm-7 col-xs-8 text-right">
                                        <input type="submit" value="Cancel"  name="cancbtn" class="btn btn-square" style="background-color: #C0CA33; color: white">
                                    </div>
                                </div>

                            </form>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal"><span>&times;</span></button>
                <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-lg-2">
                        <select class="form-control sfield">
                            <option value="1">Date</option>
                            <option value="2">Staff</option>
                            <option value="3">Shift</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control soperator">
                            <option value="">Type of Search</option>
                            <option value="%">Like</option>
                            <option value="=">Exactly</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control sortBy">
                            <option value="">Sort By</option>
                            <option value="1">Date</option>
                            <option value="2">Staff</option>
                            <option value="3">Shift</option>
                        </select> 
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control orderAs">
                            <option value="asc">Asc</option>
                            <option value="desc">Desc</option>
                        </select>
                    </div>
                    <div class="col-lg-2">
                        <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                    </div>
                    <div class="col-lg-2">
                        <input type="button" class="btn btn-primary sload"  value="Search" >
                    </div>
                </div>
                <div class="col-lg-12 sloaders text-center">
                    <!--<img src="images/search.gif" alt="loading">-->       
                </div>
                <div class="col-lg-12 snoRecord text-center">
                    <h3>NO RECORDS FOUND</h3>
                </div>
                <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                    <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                        <thead>
                            <tr style="background-color:#1ABC9C;">
                                <th width="20%">Date</th>
                                <th width="50%">Staff</th>
                                <th width="25%">Shift</th>
                                <th width="5%">Action</th>
                            </tr>
                        </thead>
                        <tbody class="sTbody">
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right search-action-bar">
                        <input type="button"  class="btn btn-primary sprev" value="Previous">
                        <input type="button"  class="btn btn-primary snext" value="Next">
                    </div>
                </div>
            </div>
            <div class="modal-footer"></div>
        </div>
    </div>
</div>
<?php include("includes/linksfoot.php"); ?>
</body>
</html>
