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

$zdb = $_SESSION["zdbyear_$dbname"];
$ztit = $_SESSION["tit"];
$file = "order.php";
$grid = "ordermain.php";

$maindb = 'ordmain';
$trandb = 'ordtran';
$stkdb  = 'transacn';

mysqli_select_db($conn, $zdb);

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

if ($qvouch <= 9) {
    $dvouch = "00" . $qvouch;
} elseif ($qvouch <= 99) {
    $dvouch = "0" . $qvouch;
} else {
    $dvouch = $qvouch;
}

if (isset($_POST["submit"])) {
    $a = 1;
    $vouchdt = trim($_POST["vouchdt"]);
//    $ordno = trim($_POST["ordno"]);
    $invno = trim($_POST["invno"]);
    $party = trim($_POST["cmbparty"]);
    $lot = trim($_POST["lot"]);
    $billamt = trim($_POST["total"]);
    $totcarton = trim($_POST["totcarton"]);
    
    $source = "ORD";
    $count = $_POST["items"];
    
    if ($party == " ") {
        $a = 0;
        browse("Party Cannot Be Empty");
        if ($addflag == 1) {
            header("location:javascript://history.go(-1)");
        } else {
            header("refresh: ; $file?vouchno=$_GET[vouchno]");
        }
    }


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

     $ordno = $mvouch ;
     for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $article = $_POST["article_$i"];
        $size = $_POST["size_$i"];
        $color = $_POST["color_$i"];
        $descrip = $_POST["descrip_$i"];
        $packing = $_POST["packing_$i"];
        $carton = $_POST["carton_$i"];
        $pair = $_POST["pair_$i"];
        $rate = $_POST["rate_$i"];
        $id = $_POST["id_$i"];
        $mamt = $_POST["amount_$i"];

        if (!empty($article)) {
            mysqli_query($conn, "INSERT INTO `$trandb`(vouchno, srno, `article`, `size`, `color`, `descrip`, `packing`, `cartons`, `pairs`, `rate`, `amount`, `ordno`)
                          VALUES('$mvouch', '$msrno', '$article', '$size', '$color', '$descrip', '$packing', '$carton', '$pair', '$rate', '$mamt', '$ordno')") or die(mysqli_error($conn));
        }
     }

    ######################## STOCK PART ######################################

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

    $cnt = 1;
    for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $article = $_POST["article_$i"];
        $size = $_POST["size_$i"];
        $descrip = $_POST["descrip_$i"];
        $color = $_POST["color_$i"];
        $packing = $_POST["packing_$i"];
        $carton = $_POST["carton_$i"];
        $pair = $_POST["pair_$i"];
        $rate = $_POST["rate_$i"];
        $mamt = $_POST["amount_$i"];
        
        if (!empty($article)) {
            mysqli_query($conn, "INSERT INTO `$stkdb`(vouchno, `vouchdt`, srno, `article`, `size`, `color`, `packing`, `cartons`, 
                                              `pairs`, `rate`, `amount`, `source`, accode, `ordno`, `descrip`)
                         VALUES('$mvouch',  '$vouchdt', '$cnt', '$article', '$size', '$color', '$packing', '$carton', 
                                '$pair', '$rate', '$mamt', '$source', '$party', '$mvouch', '$descrip')") or die(mysqli_error($conn));
            $cnt++;
        }
    }

    ######################## END STOCK PART ######################################

        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(vouchno, `vouchdt`, `party`, `ordno`, `lot`, `totcarton`, `billamt`)
                         VALUES($qvouch, '$vouchdt', '$party', '$ordno', '$lot', '$totcarton', '$billamt')") or die(mysqli_error($conn));
            insmess();

            header("refresh: 1; $file?mode=true");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn, "UPDATE `$maindb` SET `vouchdt`='$vouchdt', `party`='$party', `ordno` = '$ordno', `lot`='$lot', `totcarton`='$totcarton',
                        `billamt`='$billamt' WHERE vouchno = '$mvouch' ") or die(mysqli_error($conn));
            updmess();
            header("refresh: 1; $file?vouchno=$mvouch");
        }
    }
}

if ($addflag == 0) {
    $getvouch = $_GET["vouchno"];
    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE vouchno='$getvouch'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);

    $getpname = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$get[party]'") or die(mysqli_error($conn));
    $getp = mysqli_fetch_array($getpname);

    $getpdest = mysqli_query($conn, "SELECT * FROM `country` WHERE `code`= '$get[destcode]'") or die(mysqli_error($conn));
    $getdest = mysqli_fetch_array($getpdest);
}
?>

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title>Export Order</title>
        <meta name="msapplication-TileColor" content="#5bc0de"/>
        <meta name="msapplication-TileImage" content="assets/img/metis-tile.png"/>

        <link rel="stylesheet" href="assets/lib/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="assets/css/main.css"/>
        <link rel="stylesheet" href="assets/lib/Font-Awesome/css/font-awesome.css"/>

        <link rel="stylesheet" href="assets/css/theme.css">


        <link rel="stylesheet" href="assets/lib/uniform/themes/default/css/uniform.default.css">
        <link rel="stylesheet" href="assets/lib/inputlimiter/jquery.inputlimiter.1.0.css">
        <link rel="stylesheet" href="assets/lib/chosen/chosen.min.css">
        <link rel="stylesheet" href="assets/lib/colorpicker/css/colorpicker.css">
        <link rel="stylesheet" href="assets/lib/tagsinput/jquery.tagsinput.css">
        <link rel="stylesheet" href="assets/lib/daterangepicker/daterangepicker-bs3.css">
        <link rel="stylesheet" href="assets/lib/datepicker/css/datepicker.css">
        <link rel="stylesheet" href="assets/lib/timepicker/css/bootstrap-timepicker.min.css">
        <link rel="stylesheet" href="assets/lib/switch/static/stylesheets/bootstrap-switch.css">
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/flick/jquery-ui.css">


        <script>
            (function(i, s, o, g, r, a, m) {
                i['GoogleAnalyticsObject'] = r;
                i[r] = i[r] || function() {
                    (i[r].q = i[r].q || []).push(arguments)
                }, i[r].l = 1 * new Date();
                a = s.createElement(o),
                        m = s.getElementsByTagName(o)[0];
                a.async = 1;
                a.src = g;
                m.parentNode.insertBefore(a, m)
            })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

            ga('create', 'UA-1669764-16', 'onokumus.com');
            ga('send', 'pageview');

        </script>

        <script src="assets/lib/modernizr-build.min.js"></script>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript">
            function keyPressed(evt)
            {
                var theEvent = evt || window.event;
                var k = theEvent.keyCode || theEvent.which;
                if (k == 89 || k == 78 || k == 8 || k == 46)
                    return true;
                else {
                    $.msgbox("Invalid Key. Press Y / N ");
                    // alert("Your Message");
                    evt.preventDefault();
                    return false;
                }
            }
        </script>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/jquery.bpopup.min.js"></script>
        <script type='text/javascript'>
            $(document).ready(function() {
                $('#data').on('keyup', '.packing, .carton, .rate ', calculateRow);
                $('#data').on('blur', '.size', showprevious);
                $('#data').on('blur', '.size', addrows2());

                function showprevious() {
                    $('#browdata').empty();
                    var $row = $(this).closest("tr");
                    var article = $row.find(".article").val();
                    var size = $row.find(".size").val();
                    var party = $('#party').val();

                    $.get('show_previous_orders.php', {party: party, article: article, size: size}, function(data) {


                        $('#browdata').append(data);
                    });
                    $("#overlay_form").fadeIn(1000);
                    positionPopup();

                }

                function addrows2() {
                    if ($('#data tr:last')) {


                    }

                }

                function addrows() {
                    var ctr = $('#items').val();
                    $.post('invoice_add.php', {ctr: ctr, xcode: 1}, function(data) {
                        $(data).appendTo('#data');
                        ctr++;
                        $('#items').val(ctr);
                    });
                }

                $('#addnew').click(function() {
                    addrows();
                });

                $("#discount").keyup(function() {
                    var value = parseFloat($("#total").val());
                    var disc = parseFloat($("#discount").val());
                    var taxes = parseFloat($("#taxes").val());
                    var frgt = parseFloat($("#freight").val());
                    var mtot = value - disc + taxes + frgt;
                    $('#billamt').val(mtot.toFixed(2));
                });
                
                $("#freight").keyup(function() {
                    var value = parseFloat($("#total").val());
                    var value2 = parseFloat($("#freight").val());
                    var mtax = parseFloat($("#taxes").val());
                    var mdisc = parseFloat($("#discount").val());
                    var tot = value + value2 - mdisc + mtax;
                    $('#billamt').val(tot.toFixed(2));
                });
                
                $("#taxes").keyup(function() {
                    var value = parseFloat($("#total").val());
                    var value2 = parseFloat($("#taxes").val());
                    var value3 = parseFloat($("#freight").val());
                    var value4 = parseFloat($("#discount").val());

                    var tot = value + value2 + value3 - value4;
                    $('#billamt').val(tot.toFixed(2));
                });

                function calculateTot() {
                    var amt = 0;
                    var ctntot = 0;
                    var tdisc = 0;
                    var tvat = 0;
                    var tst = 0;
                    var bill = 0;
                    var val = 0;
                    var cval = 0;
                    /*********Total Part************/

                    $(".amount").each(function() {
                        if (!isNaN(this.value) && this.value.length != 0) {
                            val += parseFloat(this.value);
                        }
                    });
                    amt = val.toFixed(2);
                    $("#total").val(amt);

                    $(".carton").each(function() {
                        if (!isNaN(this.value) && this.value.length != 0) {
                            cval += parseFloat(this.value);
                        }
                    });
                    ctntot = cval.toFixed(2);
                    $("#totcarton").val(ctntot);



                }
                function calculateRow() {
                    var cost = 0;
                    var $row = $(this).closest("tr");

                    var packing = $row.find('.packing').val();
                    var carton = parseFloat($row.find('.carton').val());
                    var rate = parseFloat($row.find('.rate').val());

                    var pair = packing * carton;
                    $row.find('.pair').val(pair.toFixed(2));
                    var amt = pair * rate;


                    if (isNaN(amt)) {
                        $row.find('.amount').val("0");
                    } else {
                        $row.find('.amount').val(amt);
                    }
                    calculateTot();
                }


                $("#consignee").change(function() {
                    var code = $("#consignee").val();
                    $.post('get_add.php', {code: code}, function(data) {
                        //   alert(data);
                        $('#conadd').html("");
                        $('#conadd').append("SHIP STORES IN TRANSIT");
                        $('#conadd').append(data);

                    });
                });

                $("#party").change(function() {
                    var code = $("#party").val();
                    $.post('party_orders.php', {code: code}, function(data) {
                        $('#ordno').val(data);

                    });
                });

            });


        </script>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#lessamt").keyup(function() {
                    var value = parseFloat($("#billamt").val());
                    var value2 = parseFloat($("#lessamt").val());
                    //var newValue = parseInt(value) - parseInt(value2);
                    //alert('newValue');
                    $('#finamt').val(value - value2).toFixed(2);
                });

            });
        </script>
        <style>
            /*  input[type='text']{
                  border-radius: 5px;
                  height: 20px;
                  border: 1px solid #ccc;
              }
              #data td{
                  height:10px;
              }*/
        </style>
        <script type="text/javascript" src="jquery-1.6.1.min.js"></script>
        <script type="text/javascript">

            $(document).ready(function() {
                //open popup
                $("#pop").click(function() {
                    $("#overlay_form").fadeIn(1000);
                    positionPopup();
                });

                //close popup
                $("#close").click(function() {
                    $("#overlay_form").fadeOut(500);
                });
            });

            //position the popup at the center of the page
            function positionPopup() {
                if (!$("#overlay_form").is(':visible')) {
                    return;
                }
                $("#overlay_form").css({
                    left: '200px',
                    top: ($(window).width() - $('#overlay_form').width()) / 7,
                    position: 'absolute'
                });
            }

            //maintain the popup at center of the page when browser resized
            $(window).bind('resize', positionPopup);

        </script>
        <style>
            #overlay_form{
                position: absolute;
                border: 1px solid #428BCA;
                padding: 10px;
                background: white;
                width: 900px;
                max-height: 400px;
                overflow: auto;
            }
            #pop{
                display: block;
                border: 1px solid gray;
                width: 65px;
                text-align: center;
                padding: 6px;
                border-radius: 5px;
                text-decoration: none;
                margin: 0 auto;
            }
        </style>

    </head>
    <!--<a href="#" id="pop" >PopUp</a>
    <br />-->
    <body>
        <div id="overlay_form" style="display:none;z-index:999;">
            <a href="#" id="close" style="float: right;font-weight: bold;font-size: 18px;color:red;" >X</a>
            <div style='width:100%;' id='browdata'>

            </div>
        </div>

        <form action=''  name="invoice" method="POST">

            <div class="row">
                <div class="col-lg-6" style='width:100%;float:left;'>
                    <div class="box dark">
                        <header>
                            <div class="icons"><i class="fa fa-edit"></i></div>
                            <h5>Order Form</h5>
                            <!-- .toolbar -->
                            <div class="toolbar">
                                <ul class="nav">
                                    <li><a href="#"></a></li>
                                    <li>
                                        <a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-1">
                                            <i class="fa fa-chevron-up"></i>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                            <!-- /.toolbar -->
                        </header>
                        <div id="div-1" class="accordion-body collapse in body">
                            <div class="form-horizontal">
                                <table border="0">
                                    <tr>
                                        <td style ="width:140px;text-align:right;">
                                            <label class="">Voucher No.&nbsp;&nbsp;</label>
                                        </td>
                                        <td>
                                            <input type="text" size="6" maxlength="6" id="vouchno" name="vouchno" value="<?php echo ($addflag == 0) ? $get['vouchno'] : $qvouch; ?>"  class="form-control" disabled />
                                        </td>

                                        <td style ="width:100px;text-align:right;">
                                            <label class="control-label">Date.&nbsp;&nbsp;</label>
                                        </td>
                                        <td>
                                            <input type="date"  name="vouchdt" value="<?php echo ($addflag == 0) ? $get['vouchdt'] : date("Y-m-d"); ?>" class="form-control" />
                                        </td>


                                        <td style ="width:120px;text-align:right;">
                                            <label class="control-label">Party&nbsp;&nbsp;</label>
                                        </td>
                                        <td>
                                            <select style="width:280px" data-placeholder="Party" id="party" name="cmbparty" class="form-control">
                                                <?php
                                                if ($addflag == 0) {
                                                    ?>
                                                    <option value="<?php echo ($addflag == 0) ? $getp['accode'] : " "; ?>"><?php echo ($addflag == 0) ? $getp['name'] : " "; ?></option>
                                                    <?php
                                                } else {
                                                    $mown = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` WHERE grpcode='010' ORDER BY `name`") or die(mysqli_error($conn));
                                                    echo "<option></option>";
                                                    while ($trow = mysqli_fetch_array($mown)) {
                                                        echo "<option value=$trow[accode]>$trow[name]</option>";
                                                    }
                                                }
                                                ?>
                                            </select>

                                        <td style ="width:100px;text-align:right;">
                                            <label class="">Lot.&nbsp;&nbsp;</label>
                                        </td> 
                                        <td>
                                            <input type="text" size="6" maxlength="40" id="exporter" name="lot" value="<?php echo ($addflag == 0) ?  $get['lot'] : " "; ?>"  class="form-control" />
                                        </td>

                                    </tr>

<!--                                    <tr>
                                        <td style ="text-align:right;">
                                            <label class="">Party Order No.&nbsp;&nbsp;</label>
                                        </td> 
                                        <td>
                                            <input type="text" size="6" maxlength="20" id="ordno" name="ordno" value="<?php echo ($addflag == 0) ? $get['ordno'] : " "; ?>"  class="form-control" readonly />
                                        </td> 
                                    </tr>-->

                                </table>  

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

            <div class="col-lg-6" style='width:100%;float:left;'>
                <div class="box dark">
                    <header>
                        <div class="icons"><i class="fa fa-edit"></i></div>
                            <h5>Order Detail.</h5>
                            <!-- .toolbar -->
                            <div class="toolbar">
                                <ul class="nav">
                                    <li>
                                        <?php
                                        if ($addflag == 0) {
                                            echo '<input class="btn btn-primary" type="button" id="submit" name="print" value="Order Form Print" onclick="window.open(\'order_print.php?vouchno=' . $getvouch . '\',\'popUpWindow\',\'height=800,width=950,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes\');" style="width:130px;"/>';
                                        }
                                        ?>

                                    </li>
                                    <li><input type='submit' name='submit' value='Save' class="btn btn-primary"></li>
                                    <li><input type='button' name='exit' value='Exit' class="btn btn-danger" onClick="window.location.href = '<?= $grid ?>'"></li>

                                    <li>
                                        <a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-2">
                                            <i class="fa fa-chevron-up"></i>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                            <!-- /.toolbar -->
                        </header>
                        <div id="div-2" class="accordion-body collapse in body">
                            <table id="data" border="1px" width="100%">
                                <tr>
                                    <td width="50px" align="center"> <label class="control-label">Sr.</label></td>
                                    <td width="190px" align="center"><label class="control-label">Article</label></td>
                                    <td width="80px" align="center"><label class="control-label">Size</label></td>
                                    <td width="60px" align="center"><label class="control-label">Colour</label></td>
                                    <td width="230px" align="center"><label class="control-label">Description</label></td>
                                    <td width="40px" align="center"><label class="control-label">Pkg.</label></td>
                                    <td width="60px" align="center"><label class="control-label">Cartons</label></td>
                                    <td width="60px" align="center"><label class="control-label">Pairs</label></td>
                                    <td width="70px" align="center"><label class="control-label">Rate</label></td>
                                    <td width="110px" align="center"><label class="control-label">Amount</label></td>
                                </tr>
                                <?php
                                if ($addflag == 0) {
                                    $qry = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$getvouch' ORDER BY vouchdt") or die(mysqli_error($conn));
//                                    $qdes = mysqli_query($conn, "SELECT * FROM  itemdesc WHERE id='$id' ORDER BY srno") or die(mysqli_error($conn));
                                    $ctr = 0;
                                    while ($row = mysqli_fetch_array($qry)) {

                                        echo "<tr>";
                                        echo "<td align='left'><input type='text'   name='srno_$ctr' class='sno form-control' value='$row[srno]'/></td>";
                                        echo "<td align='left'><input type='text'   name='article_$ctr' class='article form-control' value='$row[article]' /></td>";
                                        echo "<td align='left'><input type='text'   name='size_$ctr' class='size form-control' value='$row[size]'/></td>";
                                        echo "<td align='center'><input type='text' name='color_$ctr' class='color form-control' value='$row[color]'/></td>";

                                        echo "<td align='left'>";
                                            echo "<input list='descrip_$ctr' name='descrip_$ctr' class='descrip form-control'  value='$row[descrip]' >";
                                            echo "<datalist id='descrip_$ctr'>";
                                            echo "<option value='$row->descrip'>";
                                            $mitem = mysqli_query($conn, "SELECT `name` FROM `itemdesc` ORDER BY `name`") or die(mysqli_error($conn));
                                            while ($trow1 = mysqli_fetch_array($mitem)) {
                                                echo "<option value='$trow1[name]'>";
                                            }
                                            echo "</datalist>";
                                        echo "</td>";
                                        
                                        echo "<td align='center'><input type='text' name='packing_$ctr' class='packing form-control' style='text-align:right' value='$row[packing]'/></td>";
                                        echo "<td align='center'><input type='text' name='carton_$ctr'  class='carton form-control' style='text-align:right' value='$row[cartons]'/></td>";
                                        echo "<td align='center'><input type='text' name='pair_$ctr'  class='pair form-control' style='text-align:right' value='$row[pairs]' readonly/></td>";
                                        echo "<td align='center'><input type='text' name='rate_$ctr' class='rate form-control' style='text-align:right' value='$row[rate]'></td>";
                                        echo "<td align='center'><input type='text' name='amount_$ctr' class='amount form-control' style='text-align:right' value='$row[amount]' readonly></td>";
                                        echo "</tr>";
                                        $ctr++;
                                    }
                                    //browse($ctr);
                                } else {
                                    ?>
                                    <?php
                                    $pctr = 0;
                                    $zctr = 0;
                                    for ($i = 0; $i <= 30; $i++) {
                                        $zctr++;
                                        ?>
                                        <tr>
                                            <td align="right"><input type="text"  maxlength="6" name="srno_<?= $pctr ?>" class="sno form-control" value="<?= $zctr ?>" readonly/></td>
                                            <td align="left"><input type="text"   name="article_<?= $pctr ?>" class="article form-control" /></td>
                                            <td align="left"><input type="text"   name="size_<?= $pctr ?>" class="size form-control"/></td>
                                            <td align="center"><input type="text" name="color_<?= $pctr ?>" class="color form-control"/></td>
                                
                                            <td align="left">
                                                <input list="descrip_<?= $pctr ?>" name="descrip_<?= $pctr ?>"  class="descrip form-control">
                                                <datalist id="descrip_<?= $pctr ?>"> 
                                                    <option value=""></option>
                                                    <?php
                                                    $mitem = mysqli_query($conn, "SELECT `name` FROM `itemdesc` ORDER BY `name`") or die(mysqli_error($conn));
                                                    while ($trow1 = mysqli_fetch_array($mitem)) {
                                                        echo "<option value='$trow1[name]'>";
                                                    }
                                                    ?>
                                                </datalist>
                                            </td>
                                            
                                            
<!--                                            <td align="center"><input type="text" name="descrip_<?= $pctr ?>" class="color form-control"/></td>-->
                                            <td align="center"><input type="text" name="packing_<?= $pctr ?>" class="packing form-control" style='text-align:right' value='0'/></td>               
                                            <td align="center"><input type="text" name="carton_<?= $pctr ?>"  class="carton form-control" style='text-align:right' value='0'/></td>
                                            <td align="center"><input type="text" name="pair_<?= $pctr ?>"  class="pair form-control" style='text-align:right' value='0' readonly/></td>
                                            <td align="center"><input type='text' name="rate_<?= $pctr ?>" class="rate form-control" style='text-align:right' value='0'></td>
                                            <td align="center"><input type='text' name="amount_<?= $pctr ?>" class="amount form-control" style='text-align:right' value='0' readonly></td>
                                        </tr>
                                        <?php
                                        $pctr++;
                                    }
                                }
                                ?>
                            </table>
                        </div>  

                    </div>
                    <table border='0' width='100%'>

                        <tr>
                            <td width="150px">
                                <input type="button" id="addnew" class="btn btn-success btn-lg" name="addnew" value="+" />
                                <input type="hidden" id="items" name="items" value="<?php echo ($addflag == 0) ? $ctr : $pctr; ?>" />  
                            </td>
                            <td width="240px"></td>
                            <td width="180px" align="right"><label for=""><font color="black" size="3px">Total&nbsp;&nbsp;&nbsp;&nbsp;</font><span></span></label></td>
                            <td width="160px"><input id="totcarton" type="text" name="totcarton" class="form-control"  value="<?php echo ($addflag == 0) ? $get['totcarton'] : "0.00"; ?>" readonly style='text-align:right'></td>
                            <td width="80px"></td>
                            <td width="200px"><input id="total" type="text" name="total" class="form-control"  value="<?php echo ($addflag == 0) ? $get['billamt'] : "0.00"; ?>" readonly style='text-align:right'></td>
                        </tr>

                    </table>
                </div>
            </div>
        </form>



        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="assets/lib/jquery.min.js"><\/script>')</script> 

        <script src="assets/lib/bootstrap/js/bootstrap.js"></script>

        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

        <script src="assets/lib/uniform/jquery.uniform.min.js"></script>
        <script src="assets/lib/jquery.dualListbox-1.3/jquery.dualListBox-1.3.min.js"></script>
        <script src="assets/lib/autosize/jquery.autosize.min.js"></script>
        <script src="assets/lib/jasny/js/bootstrap-inputmask.js"></script>

        <script src="assets/js/main.js"></script>

        <script>
            $(function() {
                formGeneral();
            });
        </script>

    </body>
</html>
