D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
salvation.incrediblebengal.com
/
admin
/
Filename :
purchase-products.php
back
Copy
<?php include'config.php'; include'get_session_access.php'; $page_title = "Purchase Entry"; ?> <!DOCTYPE html> <html lang="en"> <head> <title>Encode Restaurent - Admin Dashboard </title> <?php include'style.php'; ?> </head> <body> <div id="main-wrapper"> <?php include'header.php'; ?> <?php include'sidebar.php'; ?> <div class="content-body"> <div class="container-fluid"> <div class="row"> <div class="col-xl-12"> <div class="inventory_div"> <h4>Add Purchaed Items In inventory</h4> <form action="" method="POST" name="cart" id="cart"> <div class="clearfix"></div> <div class="row"> <div class="col-lg-12 col-sm-12 col-lg-offset-2"> <div class="add_purchasedItems"> <table class="Store_details"> <tr> <td> <label>Date:</label> </td> <td> <input class="form-control" name="purchase_date" type="datetime-local" placeholder="Purchasing Date"> </td> </tr> <tr> <td> <label>Store Name:</label> </td> <td> <input class="form-control" name="store_name" type="text" placeholder="Store Name" required> </td> <td> <label>Store Contact No.:</label> </td> <td> <input class="form-control" name="store_phone" maxlength="10" type="tel" placeholder="Store Contact No." required> </td> <td> <label>Store Address:</label> </td> <td> <input class="form-control" name="store_address" type="text" placeholder="Store Address"> </td> </tr> <tr> <td> <label>Dealer Name:</label> </td> <td> <input class="form-control" name="dealer_name" type="text" placeholder="Dealer Name" required> </td> <td> <label>Dealer Contact no.:</label> </td> <td> <input class="form-control" name="dealer_phone" maxlength="10" type="text" placeholder="Dealer Contact no." required> </td> <td> <label>Dealer Email:</label> </td> <td> <input class="form-control" name="dealer_email" type="email" placeholder="Dealer Email" required> </td> </tr> </table> <table class="purchased_itemList" id="dynamicItem_field"> <tr> <th>Item Id.</th> <th>Item Name</th> <th>Rate</th> <th>Qty</th> <th>Item Total Price</th> <th>Action</th> </tr> <tr> <td>1.</td> <td> <div class="form-group"> <input class="form-control" id="itemname_1" name="item_name[]" type="text" placeholder="Item Name"> </div> </td> <td> <div class="form-group"> <input class="form-control" id="itemrate_1" name="item_rate[]" type="text" placeholder="Item Rate" autocomplete="off"> </div> </td> <td> <div class="form-group"> <input class="form-control" id="itemqty_1" name="item_qty[]" type="text" placeholder="Item Qty" autocomplete="off"> </div> </td> <td> <div class="form-group"> <input class="form-control" id="itemamount_1" name="item_amount[]" type="text" placeholder="Item Amount"> </div> </td> <td> <button type="button" id="addItem" name="add_item" class="btn btn-success">+</button> </td> </tr> </table> <table class="purchased_amountList"> <tr> <td>Sub Total Price:</td> <td> <input class="form-control sub_total" id="subTotal" name="sub_total" type="text" placeholder="Sub Total" autocomplete="off"> </td> <td>Tax (%):</td> <td><input type="text" id="taxRate" class="form-control" name="tax_rate" placeholder="Tax Percent (%)" autocomplete="off"></td> <td>Tax Amount: </td> <td><input type="text" id="taxAmount" class="form-control" name="tax_amount" placeholder="Tax Amount" autocomplete="off" readonly></td> </tr> <tr> <td>Total Amount:</td> <td><input type="text" id="amountTotal" class="form-control" name="total_amount" placeholder="Total Amount" autocomplete="off"></td> <td>Paid Price:</td> <td> <input class="form-control" id="amountPaid" name="paid_amount" type="text" placeholder="Paid Price" autocomplete="off"> </td> <td>Due Price:</td> <td> <input class="form-control" id="amountDue" name="due_amount" type="text" placeholder="Due Price" autocomplete="off"> </td> </tr> </table> <div class="form-group float-right"> <input class="bttn bttn-submit" type="submit" name="purchase_submit"> </div> </div> </div> </div> </form> </div> </div> </div> </div> </div> <?php include'footer.php'; ?> <script type="text/javascript"> $(document).ready(function(){ var count = 1; $(document).on('click', '.bttn_remove', function(){ var button_id = $(this).attr("id"); $('#row'+button_id+'').remove(); count--; }); $('#addItem').click(function(){ count++; var htrows = ''; htrows +='<tr id="row'+count+'">'; htrows += '<td>'+count+'.</td>'; htrows += '<td> <input type="text" name="item_name[]" id="itemname_'+count+'" class="itemname form-control" placeholder="Item Name"></td>'; htrows += '<td> <input type="text" name="item_rate[]" id="itemrate_'+count+'" class="itemrate form-control" placeholder="Item Rate"></td>'; htrows += '<td> <input type="text" name="item_qty[]" id="itemqty_'+count+'" class="itemqty form-control" placeholder="Item Qty"></td>'; htrows += '<td> <input type="text" name="item_amount[]" id="itemamount_'+count+'" class="itemamount form-control" placeholder="Item Amount"></td>'; htrows += '<td><button id="'+count+'" name="remove_item" class="btn btn-danger bttn_remove"><i class="fa fa-trash"></i> </button></td></tr>'; $('#dynamicItem_field').append(htrows); }); $(document).on('blur', "[id^=itemqty_]", function(){ calculateTotal(); }); $(document).on('blur', "[id^=itemrate_]", function(){ calculateTotal(); }); $(document).on('blur', "#taxRate", function(){ calculateTotal(); }); $(document).on('blur', "#amountPaid", function(){ var amountPaid = $(this).val(); var amountTotal = $('#amountTotal').val(); if(amountPaid && amountTotal) { amountTotal = amountTotal-amountPaid; $('#amountDue').val(amountTotal); } else { $('#amountDue').val(amountTotal); } }); }); function calculateTotal(){ var totalAmount = 0; $("[id^='itemrate_']").each(function() { var id = $(this).attr('id'); id = id.replace("itemrate_",''); var price = $('#itemrate_'+id).val(); var quantity = $('#itemqty_'+id).val(); if(!quantity) { quantity = 1; } var total = price*quantity; $('#itemamount_'+id).val(parseFloat(total)); totalAmount += total; }); $('#subTotal').val(parseFloat(totalAmount)); var taxRate = $("#taxRate").val(); var subTotal = $('#subTotal').val(); if(subTotal) { var taxAmount = subTotal*taxRate/100; $('#taxAmount').val(taxAmount); subTotal = parseFloat(subTotal)+parseFloat(taxAmount); $('#amountTotal').val(subTotal); var amountPaid = $('#amountPaid').val(); var amountTotal = $('#amountTotal').val(); if(amountPaid && amountTotal) { amountTotal = amountTotal-amountPaid; $('#amountDue').val(amountTotal); } else { $('#amountDue').val(subTotal); } } } </script> </body> </html> <?php if (isset($_POST['purchase_submit'])) { $dealer_name = $_POST['dealer_name']; $dealer_phone = $_POST['dealer_phone']; $dealer_email = $_POST['dealer_email']; $store_name = $_POST['store_name']; $store_phone = $_POST['store_phone']; $store_address = $_POST['store_address']; $purchase_date = $_POST['purchase_date']; $total_price = $_POST['total_amount']; $paid_price = $_POST['paid_amount']; $due_price = $_POST['due_amount']; $item_name = $_POST['item_name']; $item_rate = $_POST['item_rate']; $item_qty = $_POST['item_qty']; $item_total = $_POST['item_total']; $insert_data = "INSERT INTO `purchase_dealer`(`dealer_id`, `dealer_name`, `dealer_phone`, `dealer_email`, `store_name`, `store_phone`, `store_address`, `purchase_date`, `total_price`, `paid_price`, `due_price`) VALUES ('','$dealer_name','$dealer_phone','$dealer_email','$store_name','$store_phone','$store_address','$purchase_date','$total_price','$paid_price','$due_price')"; $run_query = mysqli_query($conn, $insert_data); if ($run_query) { echo '<script>alert("Data inserted.")</script>'; } else{ echo '<script>alert("Oops! Data not inserted.")</script>'; } $get_data = "SELECT `dealer_id` FROM `purchase_dealer` WHERE `dealer_name` = '$dealer_name' AND `dealer_phone` = '$dealer_phone' AND `purchase_date` = '$purchase_date'"; $run_data = mysqli_query($conn, $get_data); while($row = mysqli_fetch_array($run_data)) { $dealer_id = $row['dealer_id']; echo $dealer_id; foreach ($item_name as $key => $value) { $i_name = $value; $i_rate = $item_rate[$key]; $i_qty = $item_qty[$key]; $i_total = $item_total[$key]; $insert_items = "INSERT INTO `purchase_items`(`item_id`, `item_name`, `item_rate`, `item_qty`, `item_total`, `dealer_id`, `purchase_date`) VALUES ('','$i_name','$i_rate','$i_qty','$i_total','$dealer_id', '$purchase_date')"; $run_itemData = mysqli_query($conn, $insert_items); } if ($run_query) { echo '<script>alert("Items inserted.")</script>'; } else{ echo '<script>alert("Oops! Items not inserted.")</script>'; } } } ?>