
PK 
<?php
ob_start();
error_reporting(E_ALL ^ E_NOTICE);
@session_start();
ini_set('allow_url_include',1);
date_default_timezone_set("Asia/Kolkata");
set_time_limit(600);
ini_set('max_execution_time',600);
include '../includes/settings/constant.php';
//include '../includes/settings/db.php';
require_once '../includes/settings/PDODB.php';
include '../includes/modules/functions.php';
$function = new FUNCTIONS();
if(empty($_SESSION['adminId_cheesyBites'])){
header("Location: ../index.php");
exit();
}
$ipAddress = $function->getRealIpAddr();
$pdodb = PDODB::getInstance();
$sql = "SELECT * FROM `inventory` WHERE isActive=1 ORDER BY `id` ASC";
$inventoryData = $pdodb->query($sql);
//print_r($inventoryData); exit;
//item select option
//include "config.php";
$sql="SELECT * FROM `inventory` WHERE isActive=1 ORDER BY `id` ASC";
$products="<option value=''> Select </option>";
$result=$pdodb->query($sql);
if($result>0){
foreach ($result as $key => $value) {
$products.="<option value='{$value["id"]}'>{$value["itemName"]}</option>";
}
}
//end item select option
//print_r($ipaddress); exit;
if(isset($_POST['btnAddPurchase'])){
//print_r($_POST); exit;
$purchase =$_POST;
$customer_contactno= !empty($purchase['customer_contactno'])?trim($purchase['customer_contactno']):"";
$total_amt= !empty($purchase['total_amt'])?trim($purchase['total_amt']):"";
$sql = "INSERT INTO `purchase` SET customer_contactno='".$customer_contactno."', total_amt='".$total_amt."'";
$result = $pdodb->query($sql);
$purchaseId = $pdodb->lastInsertId();
$invoiceId = "INVC/CHEESYBITE/00".$purchaseId;
//print_r($purchaseId); exit;
$sqlupt = "UPDATE `purchase` SET invoiceId='".$invoiceId."' WHERE pId = '".$purchaseId."'";
$resultupt = $pdodb->query($sqlupt);
if(!empty($purchaseId)){
for ($i=0; $i < sizeof($purchase['itemname']); $i++) {
$inventoryId= $purchase['itemname'][$i]; !empty($purchase['itemname'][$i])?trim($purchase['itemname'][$i]):"";
$rateperunit= $purchase['rateperunit'][$i]; !empty($purchase['rateperunit'][$i])?trim($purchase['rateperunit'][$i]):"";
$qty= $purchase['qty'][$i]; !empty($purchase['qty'][$i])?trim($purchase['qty'][$i]):"";
$total= !empty($purchase['total'][$i])?trim($purchase['total'][$i]):"";
$pdodb = PDODB::getInstance();
$sql = "INSERT INTO `purchase_items` SET
purchaseId='$purchaseId',
inventoryId='$inventoryId',
rateperunit='$rateperunit',
qty='$qty',
balStockQty='$qty',
total='$total'";
//exit;
$result = $pdodb->query($sql);
//echo $result; exit;
PDODB::closeInstance();
if (!empty($result)) {
$statusMsg = 'Successfully ADD New Order Entry.';
header("Location: ../invoice.php?id=$purchaseId");
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>INSPINIA | Basic Form</title>
<?php include_once '../layout/style.php'; ?>
<style type="text/css">
/*.inpt-width {width: 60px;}*/
.itemCode {width: 60px;}
.hsnCode {width: 100px;}
.unit {width: 60px;}
.gstRate {width: 25px;}
/*.rateperunit {width: 60%;}*/
.qty {width: 60px;}
/*.total {width: 60%;}*/
.inpt-bgbord { border: none; background: transparent; }
</style>
</head>
<body>
<div id="wrapper">
<?php $currentPage = 'Purchase-create'; include_once '../layout/side-bar.php'; ?>
<div id="page-wrapper" class="gray-bg">
<?php include_once '../layout/header.php'; ?>
<div class="row wrapper border-bottom white-bg page-heading">
<div class="col-lg-10">
<h2></h2>
<h2>New Order Form</h2>
</div>
<div class="col-lg-2">
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="row">
<div class="col-lg-12" style="padding:0px;">
<div class="ibox float-e-margins">
<div class="ibox-title">
<?php if (!empty($statusMsg)) { ?>
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert">x</button>
<?=$statusMsg;?>
</div>
<?php } ?>
</div>
<form method="post" action="" enctype="multipart/form-data" id="formAddPurchase">
<div class="ibox-content">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>Customer Mobile Number</label>
<input class="form-control" type="text" name="customer_contactno" id="customer_contactno">
</div>
</div>
</div>
</div>
<div class="ibox-content">
<div class="table-responsive">
<table class='table table-bordered' >
<thead>
<tr>
<th>Item Name</th>
<th>ItemCode</th>
<th>HSN code</th>
<th>Gst %</th>
<th>Qty</th>
<th>Rate/Amount</th>
<th>Total</th>
<th>Add</th>
<th>Remove</th>
</tr>
</thead>
<tbody class="tbl">
<tr>
<td><select id='itemname' name='itemname[]' class='id select2_demo_3' required style='width: 180px;'><?php echo $products; ?></select></td>
<td class="td-itemCode"><input readonly class='itemCode inpt-bgbord' id='itemCode' type='text' name='itemCode'></td>
<td><input readonly class='hsnCode inpt-bgbord' id='hsnCode' type='text' name='hsnCode'></td>
<td><input readonly class='gstRate inpt-bgbord' id='gstRate' type='text' name='gstRate'></td>
<td><input class='qty' type='text' id="qty" name='qty[]' required></td>
<td><input class='rateperunit' id='rateperunit' type='text' name='rateperunit[]' readonly></td>
<td><input class='total inpt-width' type='text' name='total[]' readonly></td>
<td><input type='button' value='+' class='add btn-success' ></td>
<td></td>
</tr>
</tbody>
<tbody class="tbl2">
</tbody>
<tbody id="orderdetailsItems">
<tr>
<td colspan='6'> </td>
<td><b>Total : </b></td>
<td><input type="text" class="form-control" id="total_amt" name="total_amt"></td>
<td colspan='2'> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="ibox-content">
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-4">
<div class="form-group text-right">
<button class="btn btn-primary" name="btnAddPurchase" id="btnAddPurchase" type="submit">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include_once '../layout/script.php'; ?>
<script>
$(document).ready(function () {
// Add Row
$("body").on("click", ".add", function () {
var products = "<?php echo $products; ?>";
$(".tbl").append(`
<tr>
<td>
<select name='itemname[]' class='id select2_demo_3' required style='width: 180px;'>${products}</select>
</td>
<td><input class='itemCode inpt-width inpt-bgbord' type='text' name='' readonly></td>
<td><input class='hsnCode inpt-width inpt-bgbord' type='text' name='' readonly></td>
<td><input class='gstRate inpt-width inpt-bgbord' type='text' name='' readonly></td>
<td><input class='qty inpt-width' type='text' name='qty[]' required></td>
<td><input class='rateperunit inpt-width' type='text' name='rateperunit[]'></td>
<td><input class='total' type='text' name='total[]' readonly></td>
<td><input type='button' value='+' class='add btn-success'></td>
<td><input type='button' value='-' class='rmv btn-danger'></td>
</tr>
`);
});
// Remove Row
$("body").on("click", ".rmv", function () {
$(this).closest("tr").remove();
calculateGrandTotal(); // Recalculate grand total after row removal
});
// Update Fields on Item Change
$("body").on("change", ".id", function () {
var id = $(this).val();
var row = $(this).closest("tr");
$.ajax({
url: "get_item.php",
type: "POST",
data: { id: id },
success: function (data) {
var item = JSON.parse(data);
row.find(".itemCode").val(item[0]);
row.find(".gstRate").val(item[1]);
row.find(".hsnCode").val(item[2]);
row.find(".rateperunit").val(item[3]);
},
});
});
// Calculate Total per Row
$("body").on("input", ".qty, .rateperunit", function calculateTotalPerRow() {
var row = $(this).closest("tr");
var qty = parseFloat(row.find(".qty").val()) || 0;
var rate = parseFloat(row.find(".rateperunit").val()) || 0;
row.find(".total").val(qty * rate);
calculateGrandTotal();
});
// Calculate Grand Total
function calculateGrandTotal() {
var grandTotal = 0;
$(".tbl .total").each(function () {
var total = parseFloat($(this).val()) || 0;
grandTotal += total;
});
$("#total_amt").val(grandTotal.toFixed(2));
}
});
</script>
<script type="text/javascript">
$("#formAddPurchase").validate({
rules: {
itemName: {
required: true
},
invoiceId: {
required: true
},
invoiceDate: {
required: true
},
customer_contactno: {
required: true,
minlength: 10,
maxlength: 10,
//number: true
digits: true
}
},
messages: {
itemName: {
required: "Please Enter Itme Name"
},
invoiceId: {
required: "Please Enter Invoice Number"
},
invoiceDate: {
required: "Please Enter Invoice Date"
},
customer_contactno: {
required: "Please enter mobile No",
minlength: "Mobile No Must Contain at least 10 digit",
maxlength: "Mobile No Must Not Exceed 10 digit",
digits: "Please enter only digit"
}
},
submitHandler: function(form) {
form.submit();
}
});
</script>
</body>
</html>


PK 99