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

$formname = 'Pump';
$maindb = 'pump';
$printfile = "pump_print.php";
$file = 'pump.php';
$trandbexist = 0;
$keyfld = "srno";
$focusfield = "name";
//$mgrpcode = '010';
//$keycond = "AND `grpcode`='$mgrpcode'";

////////////////// FB ////////////////////
$adduser = $_SESSION['username_' . $dbname];
date_default_timezone_set("Asia/Kolkata");
$adddate = date("Y-m-d");
$addtime = date("h:i:sa");
//$usertype = $_SESSION["usertype_" . $dbname];
$usertype = $_SESSION["usertype"];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
//include("includes/code_generate.php");
//include("includes/prev&next.php");
// browse($qvouch);


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

    $a = 1;
    
   $count = $_POST["items"];
//    $mvouch = 24;

    
    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLE `$maindb` WRITE");

        
        mysqli_query($conn, "DELETE FROM $maindb  ") or die(mysqli_error($conn));
        
        for ($i = 0; $i <= $count; $i++) {
            $cnt++;
            $msrno = $_POST["srno_$i"];
            $pumpno = $_POST["pumpno_$i"];
            $prodcode = $_POST["prodcode_$i"];
            $product = $_POST["product_$i"];
            $unit = $_POST["unit_$i"];


            if (!empty($pumpno)) {

                mysqli_query($conn, "INSERT INTO `$maindb`(`srno`,pumpno, prodcode, product, `unit`)
                                    VALUES('$cnt', '$pumpno', '$prodcode', '$product', '$unit')") or die(mysqli_error($conn));
            }
        }        
        mysqli_query($conn, "UNLOCK TABLES");
        
        
    }
}

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

    $gettran = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `srno` != '' ORDER BY `srno`") or die(mysqli_error($conn));
    $num=mysqli_num_rows($gettran) ; 
        
    
    $rd="readonly";
}

$senable = "";
$cenable = "";


if (isset($_GET["delete"])) {
    $getcustdtl = mysqli_query($conn, "SELECT * FROM `actran` WHERE `accode` = '$getvouch'") or die(mysqli_error($conn));
    if (mysqli_num_rows($getcustdtl) > 0) {
        browse("Entry Exist in Transaction");
        header("refresh: 1; $file?mode=last");
    } else {
        delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    }
}

include("includes/linkshead.php");
?>
<!--<script src="MyScript/openbal.js"  type="text/javascript"></script>-->   
<script src="MyScript/pump.js" type="text/javascript"></script>
<!--<script src="MyScript/customer_search.js" type="text/javascript"></script>-->

<style>
    .disc{
        width:80px;
    }
    .disc1{
        width:50px;
    }
</style>

</head>
<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-6 pad">
                <div class="panel panel-flat" style="margin-bottom: -11px;">
                    <div class="panel-heading">
                        <?php include("includes/usermention.php");
                        ?>
                        <div class="heading-elements">

                        </div>
                        <a class="heading-elements-toggle"><i class="icon-menu"></i></a>
                    </div>
                    
                <!--<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12 ">-->
                <!--<div class="panel panel-default">-->
<!--                    <div class="panel-heading">
                        <h3 class="panel-title">Vehicle Details</h3>
                    </div>-->
                    <div class="panel-body">
                        <div class='table-responsive' style="overflow-y:scroll; height: 300px">
                            <table class="table table-striped table-condensed table-bordered myTable" width="100%">
                                <thead  class="mySearchTr">
                                <tr>
                                    <th style="width: 5%"></th>
                                    <th style="width: 10%;text-align: right;">Sr.</th>
                                    <th style="width: 20%;" >Pump No.</th>
                                    <th style="width: 25%;">Product Code</th>
                                    <th style="width: 20%;">Product</th>
                                    <th style="width: 20%;">Unit</th>
                                </tr>
                                </thead>
                                <tbody id="tabledata">
                                    <?php
                                    if ($num > 0 ) {
                                        $ctr = 0;
                                        while ($tran = mysqli_fetch_array($gettran)) {
                                            Echo "<tr>";
                                            Echo "<td align='center' valign='top'><span class='remove fa fa-times ' name='remove' value='remove' ></span></td>";
                                            Echo "<td><input type='text' value='$tran[srno]'  name='srno_$ctr'  class='form-control text-right' style='text-align:right;' readonly></td>";
                                            Echo "<td>";
                                            Echo "<input type='text' value='$tran[pumpno]' name='pumpno_$ctr' class='form-control pumpno'>";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<input type='text' value='$tran[prodcode]' name='prodcode_$ctr' class='form-control prodcode'>";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<input type='text' value='$tran[product]' name='product_$ctr' class='form-control product' readonly>";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<input type='text' value='$tran[unit]' name='unit_$ctr' class='form-control unit' readonly>";
                                            Echo "</td>";
                                            Echo "</tr>";
                                            $ctr++;
                                        }
                                    } else {
                                        $ctr = 0;
                                        $yctr = 0;
//                                        for ($i = $ctr; $i < 10; $i++) {
                                            $yctr++;
                                            echo "<tr>";
                                            Echo "<td align='center'><span class='remove fa fa-times ' name='remove' value='remove'></span></td>";
                                            echo "<td  align='left'><input type='text' size='6' maxlength='6' name='srno_$ctr' class='sno form-control' style='text-align:right' value='$yctr' readonly></td>";

                                            echo "<td align='center'><input type='text' size=''  name='pumpno_$ctr' class='pumpno form-control' style='text-align:left;' value='' /></td>";
                                            echo "<td align='center'><input type='text' size=''  name='prodcode_$ctr' class='prodcode form-control' style='text-align:left;' value='' /></td>";
                                            echo "<td align='center'><input type='text' size=''  name='product_$ctr' class='product form-control form' readonly style='text-align:left;' value='' /></td>";
                                            echo "<td align='center'><input type='text' size=''  name='unit_$ctr' class='unit form-control form' readonly style='text-align:left;' value='' /></td>";
                                            echo "</tr>";
                                            $ctr++;
//                                        }
                                    }
                                    ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="row">
                            <button type="button" class="btn btn-success btn-square"  id="addnew">
                                <i class="fa fa-plus" style="color:#ffffff" data-toggle='tooltip' title='Add Row'></i>    
                            </button>
                            <input type="hidden" id="items" name="items" value="<?php echo $ctr  ; ?>" />  
                        </div>
                    </div>
                <!--</div>-->
            <!--</div>-->

                    <div class="panel-footer">
                        <div style="overflow: auto;">
    <table class="table-condensed" style="margin: 0 auto;">
        <tr>
            
            <td class=" buttonform tooltip-bottom" id="ssubmit" style="display: <? Echo $savedisabled ?>" data-toggle="tooltip" data-placement="top" title="" data-original-title="Save Record">
                <button id='submit' type='submit' name='submit' value='<?php echo ($addflag == 0) ? "Update" : "Save"; ?>' class="btn btn-pad btn-square " style="background-color:#008D4C; ">
                    <i class="fa fa-check" style="color:#ffffff"></i>
                </button>
            </td>
            <td class=" buttonform tooltip-bottom" id="scancel" style="display: <? Echo $canceldisabled ?>" data-toggle="tooltip" data-placement="top" title="" data-original-title="Cancel Record">
                <button id='cancel' type="button" class="btn btn-pad btn-square " style="background-color:#39CCCC; "  onClick="window.location.href = '<?= $file ?>'">
                    <i class="fa fa-times" style="color:#ffffff"></i>
                </button>
            </td>
        </tr>
    </table>
</div>
    <script>
        $(document).ready(function () {
            $("#submit").click(function () {
                alert("Changes Saved!");
            });
        });
    </script>                        
                    </div>
                </div>
            </div>

                        


        </div>


    </form>
    <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="6">Accode</option>
                                <option value="1">Name</option>
                                <option value="2">Address</option>
                                <option value="3">City</option>
                                <option value="4">Pin</option>
                                <option value="5">Telephone</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="6">Accode</option>
                                <option value="1">Name</option>
                                <option value="2">Address</option>
                                <option value="3">City</option>
                                <option value="4">Pin</option>
                                <option value="5">Telephone</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 sloader 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="10%">Accode</th>
                                    <th width="25%">Name</th>
                                    <th width="20%">Address</th>
                                    <th width="10%">City</th>
                                    <th width="10%">Pin</th>
                                    <th width="10%">Telephone</th>
                                    <th width="10%">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>
