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

$formname = 'Transfer Raw Material';
$maindb = 'tranmatmain';
$trandb = 'tranmattran';
$stkdb = 'rawsacn';


$printfile = "transfermat_print.php";
$file = 'transfermat.php';
$trandbexist = 1;
$keyfld = "vouchno";
$source = "TR";


$fseries = $_SESSION["series_" . $dbname];

$keycond = " and `series`='$fseries'";

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

$stkdb1 = 'tran';
$zroot = $_SESSION["zdir"];
$combstkdb = $stkdb1 . $myyear;

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

$zyear = right($zdb, 4);
$zStartDate = getzdates($zyear, 'S');
$zEndDate = getzdates($zyear, 'E');

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

if (isset($_POST["submit"])) {
    $a = 1;
    $vouchno = $_POST["vouchno"];
    $vouchdt = $_POST["vouchdt"];
    $fromcomp = $_POST["fromcomp"];
    $tocomp = $_POST["tocomp"];
    $qty = $_POST["qty"];
    $total = $_POST["total"];
    $remark = $_POST["remark"];
    $remark2 = $_POST["remark2"];
    $complete = $_POST["complete"];


    $count = $_POST["items"];

    $mvouch = $qvouch;

    $salecode = 11;



    if ($a == 1) {

#################################TRAN PART #################################



        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch' $keycond") or die(mysqli_error($conn));
        // mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$mvouch' and `source`='$source' $keycond") or die(mysqli_error($conn));
//        mysqli_query($conn, "DELETE FROM $zroot.$combstkdb WHERE `$keyfld`='$mvouch' AND `source`='$source' and `compcode`='$compcd'")or die(mysqli_error($conn));

        $chk = mysqli_query($conn, "SELECT vouchno FROM `inwmain` WHERE trnfvouch='$mvouch' and series = '$tocomp'") or die(mysqli_error($conn));
        if (!empty($chk)) {
            $mn = mysqli_num_rows($chk);
        }
//        browse($mn);
        if ($mn > 0) {
            $t = mysqli_fetch_array($chk);
            $trnfvouch = $t['vouchno'];
        } else {


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

        if ($complete != '1') {
            // mysqli_query($conn, "DELETE FROM `inwtran` WHERE `$keyfld`='$mvouch' and `series`='$tocomp'") or die(mysqli_error($conn));
            // mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$trnfvouch' and `source`='IN' and `series`='$tocomp'") or die(mysqli_error($conn));
        }
        $srl = 0;


        for ($i = 0; $i <= $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $barcode = $_POST["barcode_$i"];
            $mitem = $_POST["item_$i"];
            $unit = $_POST["unit_$i"];
            $yard = $_POST["yard_$i"];
            $meters = $_POST["meters_$i"];
            $qty = $_POST["qty_$i"];
            $calby = $_POST["calby_$i"];
            $mrp = $_POST["mrp_$i"];
            $msp = $_POST["msp_$i"];
            $rate = $_POST["rate_$i"];
            $ratebfdisc = $_POST["ratebfdisc_$i"];
            $amount = $_POST["amount_$i"];
            $color = $_POST["color_$i"];

            $discperc = $_POST["discperc_$i"];
            $discamt = $_POST["discamt_$i"];
            $discount2 = $_POST["discount2_$i"];
            $cgstrate = $_POST["cgstrate_$i"];
            $cgstamt = $_POST["cgstamt_$i"];
            $sgstrate = $_POST["sgstrate_$i"];
            $sgstamt = $_POST["sgstamt_$i"];
            $igstrate = $_POST["igstrate_$i"];
            $igstamt = $_POST["igstamt_$i"];
            $total = $_POST["total_$i"];
            $subtot = $_POST["subtot_$i"];

            $otprowsucs = $_POST["otprowsucs_$i"];
            $otpvalue = $_POST["otpvalue_$i"];
            $hsncode = $_POST["hsncode_$i"];

            $purvouch = $_POST["purvouch_$i"];
            $pursrno = $_POST["pursrno_$i"];

            $gstperc = $cgstperc + $sgstperc + $igstperc;

            $stkqty = $qty * -1;
            $stkmtr = $meters * -1;
            $stkyard = $yard * -1;

            if (!empty($mitem)) {
                $srl = $srl + 1;

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, `calby`,
                                `mrp`, `msp`, `rate`, `amount`, `discperc`, `discount`, `discount2`, `otprowsucs`, `otpvalue`,`hsncode`,
                                 `cgstrate` , `cgstamt`, `sgstrate`, `ratebfdisc`,
                                `sgstamt`, `igstrate`, `igstamt`,`total`, `subtot`, `gstperc`,color,meters,yard,series) 
                    VALUES ('$qvouch', '$vouchdt', '$srl', '$barcode', '$mitem', '$qty', '$unit', '$calby',
                            '$mrp', '$msp', '$rate', '$amount', '$discperc', '$discamt', '$discount2', '$otprowsucs', '$otpvalue','$hsncode',
                             '$cgstrate', '$cgstamt', '$sgstrate', '$ratebfdisc',
                            '$sgstamt', '$igstrate', '$igstamt', '$total', '$subtot', '$gstperc','$color','$meters','$yard','$fseries')") or die(mysqli_error($conn));

                ###########Stock Part############
                mysqli_query($conn, "INSERT INTO `$stkdb`(`srno`, series, `compcode`, `yearno`, `vouchno`, `vouchdt`, `source`, `barcode`, `itemcode`,  `qty`, `unit`, `mrp`, `rate`, `amount`,color)
                                        VALUES( '$srl', '$fseries', '$compcd', '$myyear', '$qvouch', '$vouchdt', '$source', '$barcode', '$item', '$sqty', '$unit', '$mrp', '$rate', '$amount','$color')") or die(mysqli_error($conn));
                // if ($complete != '1') {
                //     mysqli_query($conn, "INSERT INTO `inwtran`(`srno`, series,  `vouchno`, `vouchdt`, `barcode`, `itemcode`, `trqty`, `unit`, `mrp`, `msp`, `rate`, `amount`,color)
                //                         VALUES( '$srl', '$tocomp', '$trnfvouch', '$vouchdt', '$barcode', '$item', '$trqty', '$unit', '$mrp', '$msp', '$rate', '$amount','$color')") or die(mysqli_error($conn));

                //     ##########sTOCK pART########
                //     mysqli_query($conn, "INSERT INTO `$stkdb`(`srno`, series, `compcode`, `yearno`, `vouchno`, `vouchdt`, `source`, `barcode`, `itemcode`,  `qty`, `unit`, `mrp`, `rate`, `amount`,color)
                //                         VALUES( '$srl', '$tocomp', '$compcd', '$myyear', '$trnfvouch', '$vouchdt', 'IN', '$barcode', '$item', '$trqty', '$unit', '$mrp', '$rate', '$amount','$color')") or die(mysqli_error($conn));
                // }
//                ##########Combine Stock Part########
//                mysqli_query($conn, "INSERT INTO $zroot.$combstkdb(`srno`, `compcode`, `yearno`, `vouchno`, `vouchdt`, `source`, `barcode`, `itemcode`,  `qty`, `unit`, `mrp`, `rate`, `amount`)
//                                        VALUES( '$srl', '$compcd', '$myyear', '$qvouch', '$vouchdt', '$source', '$barcode', '$item', '$trqty', '$unit', '$mrp', '$rate', '$amount')") or die(mysqli_error($conn));
            }
        }
        

#################################TRAN PART END #################################
############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, series, `vouchdt`, `qty`, `total`, `remark`,`remark2`,`fromcomp`, `tocomp`,`inwvouch`, `adduser`, `adddate`, `addtime`)
                                 VALUES ('$qvouch', '$fseries', '$vouchdt','$qty', '$total','$remark', '$remark2', '$fromcomp', '$tocomp','$trnfvouch','$adduser','$adddate','$addtime')") or die(mysqli_error($conn));

            // if ($complete != '1') {
            //     mysqli_query($conn, "INSERT INTO `inwmain`(`vouchno`, series, `vouchdt`, `qty`, `total`, `remark`,`remark2`, trnfvouch)
            //                          VALUES ('$trnfvouch', '$tocomp', '$vouchdt','$qty', '$total','$remark', '$remark2','$mvouch')") or die(mysqli_error($conn));
            // }
            insmess();
            $mvouch = $qvouch; //1
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&series=$fseries");
        } else {
            $mvouch = $qvouch; //1
            $editdate = date("Y-m-d");
            $edittime = date("h:i:sa");
            mysqli_query($conn, "UPDATE `$maindb` SET `vouchdt`='$vouchdt', inwvouch='$trnfvouch', `qty`='$qty', `total`='$total', `remark`='$remark',
                                `remark2`='$remark2',fromcomp='$fromcomp',tocomp='$tocomp',`edituser`='$adduser',`edittime`='$edittime',`editdate`='$editdate'
                                 WHERE `vouchno`= '$mvouch' $keycond") or die(mysqli_error($conn));
            // if ($complete != '1') {
            //     mysqli_query($conn, "UPDATE `inwmain` SET `vouchdt`='$vouchdt', `qty`='$qty', `total`='$total', `remark`='$remark', `remark2`='$remark2' WHERE `vouchno`= '$trnfvouch' and series='$tocomp'") or die(mysqli_error($conn));
            // }


            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&series=$fseries");
        }
    }
}

if ($addflag != 1) {

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

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


    $getcomp1 = mysqli_query($conn, "SELECT * FROM $zroot.`series` WHERE code='$get[fromcomp]'") or die(mysqli_error($conn));
    $fetcomp1 = mysqli_fetch_array($getcomp1);

    $getcomp2 = mysqli_query($conn, "SELECT * FROM $zroot.`series` WHERE code='$get[tocomp]'") or die(mysqli_error($conn));
    $fetcomp2 = mysqli_fetch_array($getcomp2);
    $comp1 = $get['fromcomp'];
    $comp2 = $get['tocomp'];
    $inwvouch = $get['inwvouch'];
}

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

if (isset($_GET["delete"])) {
//    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
//    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    $delcondns = " vouchno = '$inwvouch' and series = '$comp2'";
    $delconds = " source = 'IN' and vouchno = '$inwvouch' and series = '$comp2'";

    $delcondn = " vouchno = '$_GET[vouchno]' $keycond";
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' $keycond";
    delnew($zdb, "$maindb", "$delcondn", "$file?mode=last&series=$fseries");
    delnew($zdb, "$trandb", "$delcondn", "$file?mode=last&series=$fseries");
    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last&series=$fseries");

    delnew($zdb, "inwmain", "$delcondns", "$file?mode=last&series=$fseries");
    delnew($zdb, "inwtran", "$delcondns", "$file?mode=last&series=$fseries");
    delnew($zdb, "$stkdb", "$delconds", "$file?mode=last&series=$fseries");
}

include("includes/linkshead.php");
?>
<script src="MyScript/transfermat.js" type="text/javascript"></script>
<script src="MyScript/transfermat_search.js" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>

</head>
<body>
    <!--    <div id="preloader" class="col-lg-12 text-center">
            <h3 class="text-center">Loading</h3>
            <div id="status">&nbsp;</div>
        </div>-->
    <form action='' method='POST'>
        <!-- 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">
                        <?php include("includes/usermention.php");
                        ?>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control text-size form" name="vouchno" value="<?php Echo ($addflag != 1) ? $get["vouchno"] : ""; ?>" required readonly>
                                <input type="hidden" class="form-control " name="complete" value="<?php Echo ($addflag != 1) ? $get["complete"] : ""; ?>">
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="date" class="form-control form vouchdt" style="width:70%" name="vouchdt" value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date('Y-m-d'); ?>">
                                <input type="hidden" value="<?= $zStartDate ?>" class="zstdate">
                                <input type="hidden" value="<?= $zEndDate ?>" class="zenddate">
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">From</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <select name="fromcomp" class="form-control form fromcomp">
                                    <option value="<?php Echo ($addflag != 1) ? $fetcomp1["code"] : ""; ?>"><?php Echo ($addflag != 1) ? $fetcomp1["name"] : ""; ?></option>
                                    <?
                                    $getfromcomp = mysqli_query($conn, "SELECT * FROM $zroot.`series` where code = '$fseries' ORDER BY name")or die(mysqli_error($conn));
                                    while ($fetfromcomp = mysqli_fetch_array($getfromcomp)) {
                                        Echo "<option value='$fetfromcomp[code]'>$fetfromcomp[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">To</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <select name="tocomp" class="form-control form tocomp">
                                    <option value="<?php Echo ($addflag != 1) ? $fetcomp2["code"] : ""; ?>"><?php Echo ($addflag != 1) ? $fetcomp2["name"] : ""; ?></option>
                                    <?
                                    $gettocomp = mysqli_query($conn, "SELECT * FROM $zroot.`series` where code != '$fseries' ORDER BY name")or die(mysqli_error($conn));
                                    while ($fettocomp = mysqli_fetch_array($gettocomp)) {
                                        Echo "<option value='$fettocomp[code]'>$fettocomp[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>

                        <div class="table-responsive" style="overflow-y: scroll;height: 350px">
                            <table class="table table-striped table-condensed table-bordered table-padd" width="100%">
                                <thead  style="" class="mySearchTr">
                                <tr>
                                        <th style='width: 1%'></th>
                                        <th style='width: 3%' class='text-right'>Sr.</th>
                                        <th style='width: 13%'>Material</th>
                                        <th style='width: 10%'>Color</th>
                                        <th style='width: 4%' class='text-right'>Yard</th>
                                        <th style='width: 4%' class='text-right'>Meters</th>
                                        <th style='width: 4%' class='text-right'>Qty</th>
                                        <th style='width: 4%' class='text-center'>Cal by</th>
                                        <th style='width: 4%' class='text-right'>Rate</th>
                                        <th style='width: 6%' class='text-right'>Amount</th>
                                    </tr>
                                </thead>
                                <tbody class="tbody" id="saledtltab">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 0;
//                                        $gettran = mysqli_query($conn, "SELECT `vouchno`,`srno`,`barcode`,`item`,`qty`,`unit`,`mrp`,`msp`,`rate`,`amount`,`discperc`,`discount`,`total` FROM `$trandb` WHERE `vouchno`='$get[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$get[vouchno]' $keycond ORDER BY `srno`")or die(mysqli_error($conn));
                                        $rd = '';
                                        while ($tran = mysqli_fetch_array($gettran)) {
                                            
                                            if($tran['calby'] == 'Y'){
                                                $calname = "Yard";
                                            }elseif($tran['calby'] == 'M'){
                                                $calname = "Meters";
                                            }else{
                                                $calname = "Qty";
                                            }
                                            $finditem = mysqli_query($conn, "SELECT `code`,`name` FROM `rawmat` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
                                            $fitem = mysqli_fetch_array($finditem);

                                            $findcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` WHERE `code`='$tran[color]'") or die(mysqli_error($conn));
                                            $fcolor = mysqli_fetch_array($findcolor);

                                            Echo "<tr>";
                                            Echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                            Echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$tran[srno]'>
                                                      <input type='hidden' class='form-control form text-right purvouch' name='purvouch_$sctr' value='$fetquery[purvouch]'>
                                                      <input type='hidden' class='form-control form text-right pursrno' name='pursrno_$sctr' value='$fetquery[pursrno]'></td>";
                                            Echo "<td>";
                                            Echo "<select class='form-control form item select2' name='item_$ctr' style='width:100%'>";
                                            Echo "<option value='$fitem[code]'>$fitem[name]</option>";
                                            $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `rawmat` order by name")or die(mysqli_error($conn));
                                            while ($item = mysqli_fetch_array($gitem)) {
                                                Echo "<option value='$item[code]'>$item[name]</option>";
                                            }
                                            Echo "</select>";
                                            Echo "<input type='hidden' class='msp' name='msp_$ctr' value='$tran[msp]' >";
                                            Echo "<input type='hidden' class='otprowsucs' name='otprowsucs_$ctr' value='$tran[otprowsucs]' >";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<select class='form-control form color select2' name='color_$ctr' style='width:100%'>";
                                            Echo "<option value='$fcolor[code]'>$fcolor[name]</option>";
                                            $gcolor = mysqli_query($conn, 'SELECT `code`,`name` FROM `color` order by name')or die(mysqli_error($conn));
                                            while ($color = mysqli_fetch_array($gcolor)) {
                                                Echo "<option value='$color[code]'>$color[name]</option>";
                                            }
                                            Echo "</select>";
                                            echo "</td>";
                                            Echo "<td><input type='text' class='form-control form text-right yard'   name='yard_$ctr'    value='$tran[yard]'></td>";
                                            Echo "<td><input type='text' class='form-control form text-right meters' name='meters_$ctr'  value='$tran[meters]'></td>";
                                            Echo "<td><input type='text' class='form-control form text-right qty'    name='qty_$ctr'     value='$tran[qty]'></td>";
                                            Echo "<td><select class='form-control form calby ' name='calby_$ctr' style='width:100%'>";
                                            
                                            Echo "<option value='$tran[calby]'>$calname</option>";
                                            Echo "<option value='Q'>Qty</option>";
                                            Echo "<option value='M'>Meters</option>";
                                            Echo "<option value='Y'>Yard</option>";
                                            Echo "</select>";
                                            Echo "</td>";
                                            Echo "<input type='hidden' class='rawtype' name='rawtype_$ctr' value='$tran[rawtype]'>";
                                            Echo "<input type='hidden' class='msp' name='msp_$ctr' >";
                                            Echo "<input type='hidden' class='otpvalue' id='otpvalue_$ctr' name='otpvalue_$ctr' value='$tran[otpvalue]'>";
                                            Echo "<td><input type='text' class='form-control form text-right rate'     name='rate_$ctr'     value='$tran[rate]'></td>";
                                            Echo "<td><input type='text' class='form-control form text-right amount'   name='amount_$ctr'   value='$tran[amount]' readonly  tabindex='-1'>
                                            <input type='hidden' class='form-control form text-right mspamount'   name='mspamount_$ctr'   value='$tran[mspamount]' readonly></td>";
                                            Echo "</tr >";
                                            $ctr++;
                                        }
                                    } else {
                                        $pctr = 0;
                                        ?>
                                        <tr>
                                            <td><i class="fa fa-close remove"></i></td>
                                            <td><input type="text" class="form-control form text-right srno" name="srno_0" value="1">
                                                <input type="hidden" class="form-control form text-right purvouch" name="purvouch_0" value="">
                                                <input type="hidden" class="form-control form text-right pursrno" name="pursrno_0" value="">
                                                <input type="hidden" class="form-control form text-right rawtype" name="rawtype_0" value=""></td>
                                            <!--<td><input type="text" class="form-control form barcode" name="barcode_0" name="barcode"></td>-->
                                            <td>
                                                <select class="form-control form item select2" name="item_0" style='width:100%'>
                                                    <option value=""></option>
                                                    <?php
                                                    $gitem = mysqli_query($conn, "SELECT * FROM `rawmat`")or die(mysqli_error($conn));
                                                    while ($item = mysqli_fetch_array($gitem)) {
                                                        Echo "<option value='$item[code]'>$item[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                                <input type='hidden' class='msp' name='msp_0' >
                                                <input type='hidden' class='otprowsucs' name='otprowsucs_0' >
                                                <input type='hidden' class='otpvalue' name='otpvalue_0' >
                                            </td>
                                            <td>
                                                <select class="form-control form color select2" name="color_0" style='width:100%'>
                                                    <option value=""></option>
                                                    <?php
                                                    $gcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` order by name")or die(mysqli_error($conn));
                                                    while ($color = mysqli_fetch_array($gcolor)) {
                                                        Echo "<option value='$color[code]'>$color[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                            </td>
                                            <!--<td><input type="text" class="form-control form text-left hsncode"  tabindex="15"   name="hsncode_0"      value=""></td>-->
                                            <td><input type="text" class="form-control form text-right yard"      name="yard_0"         value="0"></td>
                                            <td><input type="text" class="form-control form text-right meters"      name="meters_0"         value="0"></td>
                                            <td><input type="text" class="form-control form text-right qty"      name="qty_0"         value="0"></td>
                                            <?php
                                            Echo "<td><select class='form-control form calby ' name='calby_0' style='width:100%'>";
                                            Echo "<option value='Q'>Qty</option>";
                                            Echo "<option value='M'>Meters</option>";
                                            Echo "<option value='Y'>Yard</option>";
                                            Echo "</select>";
                                            Echo "</td>";
                                            ?>
                                            <td><input type="text" class="form-control form text-right rate"  id="rate_<?= $pctr ?>"   name="rate_0"        value="0" ></td>
                                            <td><input type="text" class="form-control form text-right amount"   name="amount_0"      value="0"  tabindex='-1' readonly >
                                                <input type="hidden" class="form-control form text-right mspamount"   name="mspamount_0"      value="0" readonly></td>
    
                                        </tr>  
                                        <?
                                        $pctr++;
                                    }
                                    ?>
                                <!-- <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />   -->

                                </tbody>
                            </table>

                        </div>

                        <div class="row">
                            <div class="col-lg-1" >
                                <button type="button" class="btn btn-square form" style="background-color: #78909C"  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 ($addflag != 1) ? $ctr : $pctr; ?>" />  
                            </div> 
                        </div> 

                        <!-- <div class="row">
                            <div class="col-lg-5 col-md-5 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control text-size marg">Quantity.</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form text-right totqty" name="qty" value="<?php Echo ($addflag != 1) ? $tqty : ""; ?>" readonly>
                            </div>

                            <div class="col-lg-4 col-md-4 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Total</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form text-right totamt" name="total" value="<?php Echo ($addflag != 1) ? $tamt : ""; ?>" readonly>
                            </div>
                        </div> -->
                        <hr>
                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control text-size marg">Remark</label>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form " name="remark" value="<?php Echo ($addflag != 1) ? $get["remark"] : ""; ?>" >
                                <input type="text" class="form-control form " name="remark2" value="<?php Echo ($addflag != 1) ? $get["remark2"] : ""; ?>" >
                            </div>
                        </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"); ?>
                </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="1">Voucher</option>
                            <option value="2">Date</option>
                            <option value="3">Qty</option>
                            <option value="4">Total</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">Voucher</option>
                            <option value="2">Date</option>
                            <option value="3">Qty</option>
                            <option value="4">Total</option>
                        </select> 
                    </div>
                    <div class="col-lg-2">
                        <select class="form-control orderAs">
                            <option value="desc">Desc</option>
                            <option value="asc">Asc</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  class="mySearchTr">
                                <th width="10%">Voucher</th>
                                <th width="10%">Date</th>
                                <th width="10%">Qty</th>
                                <th width="10%">Total</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>
