Your IP : 216.73.216.26


Current Path : /home2/wtmwscom/public_html/admin/
Upload File :
Current File : /home2/wtmwscom/public_html/admin/product_sale_admin.php

<?php
$title = "Product Sale";
include 'header.php';
?>
<!--<h3>Product Sale</h3>
<form action="product_sale_admin.php" method="post" >
    <table border="1">
        <tr>
            <td>Franchise ID</td>
            <td colspan="3"><select name="fid" required="required">
                    <option value="">--------Select franchise-------</option>
                    <?php
                    $rs = mysqli_query($connection, "select fid, store_name from franchise order by store_name");
                    while ($row = mysqli_fetch_object($rs)) {
                        echo "<option value='" . $row->fid . "'>$row->store_name</option>";
                    }
                    ?>
                </select>
            </td>
        </tr>

        <tr>
            <td>Product Name</td>
            <td colspan="3"><select name="pid" id="pid"  onchange="get_product_details(this.value)" required="required">
                    <option value="" >--------Select Product-----------</option><?php
                    $rs77 = mysqli_query($connection, "select pid, pcode, pname from product where quantity > 0 order by pname");
                    while ($row77 = mysqli_fetch_array($rs77)) {
                        echo '<option value="' . $row77['pid'] . '">' . $row77['pcode'] . ' ' . $row77['pname'] . '</option>';
                    }
                    ?></select></td>
        </tr>


        <td>Product details</td>
        <td id="product_detail_html"></td>
        </tr>

        <tr>

            <td>Quantity</td>
            <td><input type="text" name="quantity" onchange="validate_qty(this.value)" id="quantity" size="5" required="required" ></td>
        </tr>


        <tr>

            <td colspan="2" align="center"><input type="submit" name="submit" id="submit"/></td>
        </tr>
    </table>
</form>-->

<?php
if (isset($_POST['submit'])) {
    $is_success = FALSE;
    $date = date('Y-m-d');
    $qty = $_POST['quantity'];
    $pid = $_POST['pid'];
    $rs = mysqli_query($connection, "select rec_id from product_franchise where pid='" . $_POST['pid'] . "' and fid='" . $_POST['fid'] . "'");
    if (mysqli_num_rows($rs)) {
        $row = mysqli_fetch_object($rs);

        $is_success = mysqli_query($connection, "update product_franchise set quantity = quantity +  $qty, last_date = '" . $date . "' where rec_id = $row->rec_id");
        mysqli_query($connection, "update product set quantity = quantity - $qty where pid = $pid ");
    } else {
        $fid = $_POST['fid'];
        $is_success = mysqli_query($connection, "insert into product_franchise (pid, fid, quantity, last_date) values(
        $pid, $fid, $qty, '" . $date . "'
        )");
        mysqli_query($connection, "update product set quantity = quantity - $qty where pid = $pid ");
    }
    $msg = $is_success ? 'Created successfully' : 'Try again';
    echo $msg;
}
?>

<div class="container-fluid">
    <?php getMessage();
    ?>
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <h4 class="page-title">Product Sale</h4>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                    <li class="breadcrumb-item"><a href="#">Inventory</a></li>
                    <li class="breadcrumb-item active">Product Sale</li>
                </ol>
            </div>
        </div>
    </div>
    <!-- end row -->
    <div class="row">
        <div class="col-12">
            <div class="card m-b-20">
                <div class="card-body">
                    <form action="product_sale_admin.php" method="post">
                        <div class="form-group row">
                            <!--                                            <label for="example-text-input" class="col-sm-2 col-form-label">Text</label>-->
                            <label class="col-sm-2 col-form-label" for="franchise_id">Franchise ID <span>*</span></label>
<!--                                            <label class="col-sm-2 col-form-label" for="dob"> Name<span>*</span></label>-->
                            <div class="col-sm-10">

                                <select class="custom-select" name="fid" required="required">
                                    <option value="" disabled="disabled" selected="selected">--------Select franchise-------</option>
                                    <option <?php
                                    $rs = mysqli_query($connection,"select fid, store_name from franchise order by store_name");
                                    while ($row = mysqli_fetch_object($rs)) {
                                        echo "<option value='" . $row->fid . "'>$row->store_name</option>";
                                    }
                                    ?></option>
                                </select> 
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label" for="pname">Product Name </label>
                            <div class="col-sm-10">
                                <select class="custom-select" name="pid" id="pid"  onchange="get_product_details(this.value)" required="required">
                                    <option value="" disabled="disabled" selected="selected">--------Select Product-----------</option>
                                    <option <?php
                                    $rs77 = mysqli_query($connection,"select pid, pcode, pname from product where quantity > 0 order by pname");
                                    while ($row77 = mysqli_fetch_array($rs77)) {
                                        echo '<option value="' . $row77['pid'] . '">' . $row77['pcode'] . ' ' . $row77['pname'] . '</option>';
                                    }
                                    ?></option>
                                </select>     </div>
                        </div>
                        
                        <div class="form-group row">
                            <!--                                            <label for="example-text-input" class="col-sm-2 col-form-label">Text</label>-->
                            <label class="col-sm-2 col-form-label" for="amount">Help Amount  <span>*</span></label>
<!--                                            <label class="col-sm-2 col-form-label" for="dob"> Name<span>*</span></label>-->
                            <div class="col-sm-10" id = "product_detail_html">

                              
                            </div>
                        </div>
                        <div class="form-group row">
                            <!--                                            <label for="example-text-input" class="col-sm-2 col-form-label">Text</label>-->
                            <label class="col-sm-2 col-form-label" for="quantity">Quantity  <span>*</span></label>
<!--                                            <label class="col-sm-2 col-form-label" for="dob"> Name<span>*</span></label>-->
                            <div class="col-sm-10">

                                <input class="form-control" type="text" name="quantity" onchange="validate_qty(this.value)" id="quantity" size="5" required="required" >
                            </div>
                        </div>

                        <div class="form-group">
                            <div>
                                <button type="submit" name="submit" id="submit" class="btn btn-primary waves-effect waves-light">
                                    Submit
                                </button>
                            </div>
                        </div>

                    </form>
                </div>

            </div>
        </div> <!-- end col -->
    </div> <!-- end row -->


</div> <!-- container-fluid -->
<script>
    var quantity = 0;
    function validate_qty(qty) {
        if ((parseInt(qty) > quantity) || (parseInt(qty) < 1)) {
            // qty1 = quantity + parseInt(qty);
            //alert('tttt'+parseInt(qty)+' '+quantity+' '+qty1);
            $("#quantity").val("")
        }
        ;
    }


    function get_product_details(pid)
    {
        $.get("get_product_detail.php", {pid: pid}, function (data, status) {
            $('#product_detail_html').html(data.html);
            quantity = parseInt(data.quantity);
        }, "json");
    }
</script>
<?php
include('footer.php');
?>