this is my code
<?php
//invoice.php
include('database_connection.php');
$statement = $connect->prepare("
SELECT * FROM tbl_order
ORDER BY order_id DESC
");
$statement->execute();
$all_result = $statement->fetchAll();
$total_rows = $statement->rowCount();
if(isset($_POST["create_invoice"]))
{
$order_item_tax1_rate = 0;
$order_item_tax1_amount = 0;
$order_item_tax2_rate = 0;
$order_item_tax2_amount = 0;
$order_item_hc = 0;
$order_item_final_amount = 0;
$statement = $connect->prepare("
INSERT INTO tbl_order
(order_no, order_date, order_receiver_name, order_receiver_gstin, order_item_tax1_rate, order_item_tax1_amount, order_item_tax2_rate, order_item_tax2_amount, order_item_hc_, order_item_final_amount, order_datetime)
VALUES (:order_no, :order_date, :order_receiver_name, :order_receiver_gstin, :order_item_tax1_rate, :order_item_tax1_amount, :order_item_tax2_rate, :order_item_tax2_amount, :order_item_hc, :order_item_final_amount, :order_datetime)
");
$statement->execute(
array(
':order_no' => trim($_POST["order_no"]),
':order_date' => trim($_POST["order_date"]),
':order_receiver_name' => trim($_POST["order_receiver_name"]),
':order_receiver_gstin' => trim($_POST["order_receiver_gstin"]),
':order_item_tax1_rate' => trim($_POST["order_item_tax1_rate"]),
':order_item_tax1_amount' => trim($_POST["order_item_tax1_amount"]),
':order_item_tax2_rate' => trim($_POST["order_item_tax2_rate"]),
':order_item_tax2_amount' => trim($_POST["order_item_tax2_amount"]),
':order_item_hc' => trim($_POST["order_item_hc"]),
':order_item_final_amount' => trim($_POST["order_item_final_amount"]),
':order_datetime' => date("Y-m-d")
)
);
$statement = $connect->query("SELECT LAST_INSERT_ID()");
$order_id = $statement->fetchColumn();
for($count=0; $count<$_POST["total_item"]; $count++)
{
$statement = $connect->prepare("
INSERT INTO tbl_order_item
(order_id, order_item_name, order_item_quantity, order_item_price, order_item_actual_amount)
VALUES (:order_id, :order_item_name, :order_item_quantity, :order_item_price, :order_item_actual_amount)
");
$statement->execute(
array(
':order_id' => $order_id,
':order_item_name' => trim($_POST["order_item_name"][$count]),
':order_item_quantity' => trim($_POST["order_item_quantity"][$count]),
':order_item_price' => trim($_POST["order_item_price"][$count]),
':order_item_actual_amount' => trim($_POST["order_item_actual_amount"][$count])
)
);
}
header("location:invoice.php");
}
if(isset($_POST["update_invoice"]))
{
$order_total_tax1 = 0;
$order_total_tax2 = 0;
$order_hc = 0;
$order_id = $_POST["order_id"];
$statement = $connect->prepare("
DELETE FROM tbl_order_item WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $order_id
)
);
for($count=0; $count<$_POST["total_item"]; $count++)
{
$order_item_hc = floatval(trim($_POST["order_item_hc"][$count]));
$statement = $connect->prepare("
INSERT INTO tbl_order_item
(order_id, order_item_name, order_item_quantity, order_item_price, order_item_actual_amount, order_item_final_amount)
VALUES (:order_id, :order_item_name, :order_item_quantity, :order_item_price, :order_item_actual_amount)
");
$statement->execute(
array(
':order_id' => $order_id,
':order_item_name' => trim($_POST["order_item_name"][$count]),
':order_item_quantity' => trim($_POST["order_item_quantity"][$count]),
':order_item_price' => trim($_POST["order_item_price"][$count]),
':order_item_actual_amount' => trim($_POST["order_item_actual_amount"][$count])
)
);
$result = $statement->fetchAll();
}
$order_total_tax = $order_total_tax1 + $order_total_tax2 + $order_total_tax3;
$statement = $connect->prepare("
UPDATE tbl_order
SET order_no = :order_no,
order_date = :order_date,
order_receiver_name = :order_receiver_name,
order_receiver_gstin = :order_receiver_gstin,
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_no' => trim($_POST["order_no"]),
':order_date' => trim($_POST["order_date"]),
':order_receiver_name' => trim($_POST["order_receiver_name"]),
':order_receiver_gstin' => trim($_POST["order_receiver_gstin"]),
':order_receiver_gstin' => trim($_POST["order_item_hc"]),
':order_id' => $order_id
)
);
$result = $statement->fetchAll();
header("location:invoice.php");
}
if(isset($GET["delete"]) && isset($GET["id"]))
{
$statement = $connect->prepare("DELETE FROM tbl_order WHERE order_id = :id");
$statement->execute(
array(
':id' => $GET["id"]
)
);
$statement = $connect->prepare(
"DELETE FROM tbl_order_item WHERE order_id = :id");
$statement->execute(
array(
':id' => $GET["id"]
)
);
header("location:invoice.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/datepicker.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="css/dataTables.bootstrap.min.css">
<style>
/ Remove the navbar's default margin-bottom and rounded borders /
.navbar {
margin-bottom: 4px;
border-radius: 0;
}
/ Add a gray background color and some padding to the footer /
footer {
background-color: #f2f2f2;
padding: 25px;
}
.carousel-inner img {
width: 100%; / Set width to 100% /
margin: auto;
min-height:200px;
}
.navbar-brand
{
padding:5px 40px;
}
.navbar-brand:hover
{
background-color:#ffffff;
}
/ Hide the carousel text when the screen is less than 600 pixels wide /
@media (max-width: 600px) {
.carousel-caption {
display: none;
}
}
</style>
</head>
<body>
<style>
.box
{
width: 100%;
max-width: 1390px;
border-radius: 5px;
border:1px solid #ccc;
padding: 15px;
margin: 0 auto;
margin-top:50px;
box-sizing:border-box;
}
</style>
<link rel="stylesheet" href="css/datepicker.css">
<script src="js/bootstrap-datepicker1.js"></script>
<script>
$(document).ready(function(){
$('#order_date').datepicker({
format: "yyyy-mm-dd",
autoclose: true
});
});
</script>
<div class="container-fluid">
<?php
if(isset($_GET["add"]))
{
?>
<form method="post" id="invoice_form">
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<td colspan="2" align="center"><h2 style="margin-top:10.5px">Create Invoice</h2></td>
</tr>
<tr>
<td colspan="2">
<div class="row">
<div class="col-md-8">
To,<br />
<b>RECEIVER (BILL TO)</b><br />
<input type="text" name="order_receiver_name" id="order_receiver_name" class="form-control input-sm" placeholder="Name" />
<textarea name="order_receiver_gstin" id="order_receiver_gstin" class="form-control" placeholder="Party's GSTIN"></textarea>
</div>
<div class="col-md-4">
Reverse Charge<br />
Bill No. <input type="text" name="order_no" id="order_no" class="form-control input-sm" readonly value="<?php echo $total_rows+100 ; ?>" placeholder="" />
Date <input type="text" name="order_date" id="order_date" class="form-control input-sm" readonly value="<?php echo date("Y-m-d") ; ?>" placeholder="" />
<?php /*?> <input type="text" name="order_date" id="order_date" class="form-control input-sm" readonly placeholder="<?php echo date("Y-m-d") ?>" /><?php */?>
</div>
</div>
<br />
<table id="invoice-item-table" class="table table-bordered">
<tr>
<th width="7%">Sr No.</th>
<th width="7%">HSN Code</th>
<th width="20%">Item Name</th>
<th width="5%">Quantity</th>
<th width="5%">Rate</th>
<th width="10%">Actual Amt.</th>
</tr>
<tr>
<td><span id="sr_no">1</span></td>
<td><input type="text" name="order_item_hsncode" id="order_item_hsncode" class="form-control input-sm order_item_name_hsncode" /></td>
<td><input type="text" name="order_item_name[]" id="order_item_name1" data-srno="1" class="form-control input-sm order_item_name" /></td>
<td><input type="text" name="order_item_quantity[]" id="order_item_quantity1" data-srno="1" class="form-control input-sm order_item_quantity" /></td>
<td><input type="text" name="order_item_price[]" id="order_item_price1" data-srno="1" class="form-control input-sm number_only order_item_price" /></td>
<td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount1" data-srno="1" class="form-control input-sm order_item_actual_amount" readonly /></td>
</tr>
</table>
<div align="right">
<button type="button" name="add_row" id="add_row" class="btn btn-success btn-xs">+</button>
</div>
<table style="width:25%; margin-left:50%; padding-top:25px;">
<tr>
<th width="15%">Total</th>
<td><input type="text" name="order_item_final_amount" id="order_item_final_amount" data-srno="1" readonly class="form-control input-sm order_item_final_amount" /></td>
</tr>
</table>
<table style="width:40%; margin-left:60%;">
<tr>
<th></th>
<th>Rate</th>
<th>Amt.</th>
</tr>
<tr>
<th width="7%" colspan="1">SGST (%)</th>
<td width="7%"><input type="text" name="order_item_tax1_rate" id="order_item_tax1_rate" data-srno="1" class="form-control input-sm number_only order_item_tax1_rate" /></td>
<td width="7%"><input type="text" name="order_item_tax1_amount" id="order_item_tax1_amount" data-srno="1" readonly class="form-control input-sm order_item_tax1_amount" /></td>
</tr>
<tr>
<th width="7%" colspan="1">CGST (%)</th>
<td>
<input type="text" name="order_item_tax2_rate" id="order_item_tax2_rate" data-srno="1" class="form-control input-sm number_only order_item_tax2_rate" />
</td>
<td>
<input type="text" name="order_item_tax2_amount" id="order_item_tax2_amount" data-srno="1" readonly class="form-control input-sm order_item_tax2_amount" />
</td>
</tr>
<tr>
<th width="7%">Handling Charges</th>
<td>
<input type="text" name="order_item_hc" id="order_item_hc" data-srno="1" class="form-control input-sm number_only order_item_hc" />
</td>
</tr>
</td>
</tr>
<tr>
<td><b>Grand Total</td>
<td align="right" bordercolor="#000000" style="border:medium"><b><span id="final_total_amt"></span></b></td>
<td></td>
</tr>
<br/>
<tr>
</tr>
<tr>
<th>
</th>
<td colspan="2" align="right">
<input type="hidden" name="total_item" id="total_item" value="1" />
<input type="submit" name="create_invoice" id="create_invoice" class="btn btn-info" value="Create" />
</td>
</tr>
</table>
</div>
</form>
<script>
$(document).ready(function(){
var final_total_amt = $('#final_total_amt').text();
var count = 1;
$(document).on('click', '#add_row', function(){
count++;
$('#total_item').val(count);
var html_code = '';
html_code += '<tr id="row_id_'+count+'">';
html_code += '<td><span id="sr_no">'+count+'</span></td>';
html_code += '<td><input type="text" name="item_hsn[]" id="item_name'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="order_item_name[]" id="order_item_name'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="order_item_quantity[]" id="order_item_quantity'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_quantity" /></td>';
html_code += '<td><input type="text" name="order_item_price[]" id="order_item_price'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_price" /></td>';
html_code += '<td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount'+count+'" data-srno="'+count+'" class="form-control input-sm order_item_actual_amount" readonly /></td>';
<?php /*?><!-- html_code += '<td><input type="text" name="order_item_tax1_rate[]" id="order_item_tax1_rate'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_tax1_rate" /></td>';
html_code += '<td><input type="text" name="order_item_tax1_amount[]" id="order_item_tax1_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_tax1_amount" /></td>';
html_code += '<td><input type="text" name="order_item_tax2_rate[]" id="order_item_tax2_rate'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_tax2_rate" /></td>';
html_code += '<td><input type="text" name="order_item_tax2_amount[]" id="order_item_tax2_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_tax2_amount" /></td>';
html_code += '<td><input type="text" name="order_item_hc" id="order_item_hc'+count+'" data-srno="'+count+'" class="form-control input-sm order_item_hc" /></td>'
html_code += '<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_final_amount" /></td>';;--><?php */?>
html_code += '<td><button type="button" name="remove_row" id="'+count+'" class="btn btn-danger btn-xs remove_row">X</button></td>';
html_code += '</tr>';
$('#invoice-item-table').append(html_code);
});
$(document).on('click', '.remove_row', function(){
var row_id = $(this).attr("id");
var total_item_amount = $('#order_item_final_amount'+row_id).val();
var final_amount = $('#final_total_amt').text();
var result_amount = parseFloat(final_amount) - parseFloat(total_item_amount);
$('#final_total_amt').text(result_amount);
$('#row_id_'+row_id).remove();
count--;
$('#total_item').val(count);
});
function cal_final_total(count)
{
var final_item_total = 0;var final_item_subtotal = 0;
for(j=1; j<=count; j++)
{
var quantity = 0;
var price = 0;
var actual_amount = 0;
var tax1_rate = 0;
var tax1_amount = 0;
var tax2_rate = 0;
var tax2_amount = 0;
var hc = 0;
var item_subtotal = 0 ;
var item_total = 0;
quantity = $('#order_item_quantity'+j).val();
<?php /*?>hc = $('#order_item_hc'+j).val();
$('#order_item_hc_amount'+j).val(tax2_amount);<?php */?>
if(quantity > 0)
{
price = $('#order_item_price'+j).val();
if(price > 0)
{
actual_amount = parseFloat(quantity) * parseFloat(price);
}
$('#order_item_actual_amount'+j).val(actual_amount);
}
final_item_subtotal = parseFloat(final_item_subtotal) + parseFloat(actual_amount) ;
$('#order_item_final_amount').val(final_item_subtotal);
}
tax1_rate = $('#order_item_tax1_rate').val();
if(tax1_rate > 0)
{
tax1_amount = $('#order_item_final_amount').val()*parseFloat(tax1_rate)/100;
$('#order_item_tax1_amount').val(tax1_amount);
}
tax2_rate = $('#order_item_tax2_rate').val();
if(tax2_rate > 0)
{
tax2_amount = $('#order_item_final_amount').val()*parseFloat(tax2_rate)/100;
$('#order_item_tax2_amount').val(tax2_amount);
}
hc = $('#order_item_hc').val();
item_subtotal = $('#order_item_final_amount').val();
item_total = parseFloat(item_subtotal) + parseFloat(tax1_amount) + parseFloat(tax2_amount) + parseFloat(hc);
final_item_total = parseFloat(final_item_total) + parseFloat(item_total) ;
$('#final_total_amt').text(final_item_total);
}
$(document).on('blur', '.order_item_price', function(){
cal_final_total(count);
});
$(document).on('blur', '.order_item_tax1_rate', function(){
cal_final_total(count);
});
$(document).on('blur', '.order_item_tax2_rate', function(){
cal_final_total(count);
});
$(document).on('blur', '.order_item_hc', function(){
cal_final_total(count);
});
$('#create_invoice').click(function(){
if($.trim($('#order_receiver_name').val()).length == 0)
{
alert("Please Enter Reciever Name");
return false;
}
if($.trim($('#order_no').val()).length == 0)
{
alert("Please Enter Invoice Number");
return false;
}
if($.trim($('#order_date').val()).length == 0)
{
alert("Please Select Invoice Date");
return false;
}
for(var no=1; no<=count; no++)
{
if($.trim($('#order_item_name'+no).val()).length == 0)
{
alert("Please Enter Item Name");
$('#order_item_name'+no).focus();
return false;
}
if($.trim($('#order_item_quantity'+no).val()).length == 0)
{
alert("Please Enter Quantity");
$('#order_item_quantity'+no).focus();
return false;
}
if($.trim($('#order_item_price'+no).val()).length == 0)
{
alert("Please Enter Price");
$('#order_item_price'+no).focus();
return false;
}
}
$('#invoice_form').submit();
});
});
</script>
<?php
}
elseif(isset($_GET["update"]) && isset($_GET["id"]))
{
$statement = $connect->prepare("
SELECT * FROM tbl_order
WHERE order_id = :order_id
LIMIT 1
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<script>
$(document).ready(function(){
$('#order_no').val("<?php echo $row["order_no"]; ?>");
$('#order_date').val("<?php echo $row["order_date"]; ?>");
$('#order_receiver_name').val("<?php echo $row["order_receiver_name"]; ?>");
$('#order_receiver_gstin').val("<?php echo $row["order_receiver_gstin"]; ?>");
});
</script>
<form method="post" id="invoice_form">
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<td colspan="2" align="center"><h2 style="margin-top:10.5px">Edit Invoice</h2></td>
</tr>
<tr>
<td colspan="2">
<div class="row">
<div class="col-md-8">
To,<br />
<b>RECEIVER (BILL TO)</b><br />
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order_item
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$item_result = $statement->fetchAll();
?>
<input type="text" name="order_receiver_name" id="order_receiver_name" class="form-control input-sm" placeholder="Name" />
<textarea name="order_receiver_gstin" id="order_receiver_gstin" class="form-control" placeholder="PartY's GSTIN"></textarea>
</div>
<div class="col-md-4">
Reverse Charge<br />
<input type="text" name="order_no" id="order_no" class="form-control input-sm" placeholder="Enter Invoice No." />
<input type="text" name="order_date" id="order_date" class="form-control input-sm" readonly placeholder="Select Invoice Date" />
</div>
</div>
<br />
<table id="invoice-item-table" class="table table-bordered">
<tr>
<th width="7%">Sr No.</th>
<th width="7%">HSN Code</th>
<th width="20%">Item Name</th>
<th width="3%">Quantity</th>
<th width="7%">Price</th>
<th width="10%">Actual Amt.</th>
<th width="12.5%" colspan="2">Tax1 (%)</th>
<th width="12.5%" colspan="2">Tax2 (%)</th>
<th width="12.5%" rowspan="2">Total</th>
<th width="3%" rowspan="2"></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>Rate</th>
<th>Amt.</th>
<th>Rate</th>
<th>Amt.</th>
<th>Rate</th>
<th>Amt.</th>
</tr>
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order_item
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$item_result = $statement->fetchAll();
$m = 0;
foreach($item_result as $sub_row)
{
$m = $m + 1;
?>
<tr>
<td><span id="sr_no"><?php echo $m; ?></span></td>
<td><input type="text" name="order_item_name[]" id="order_item_name<?php echo $m; ?>" class="form-control input-sm" value="<?php echo $sub_row["item_name"]; ?>" /></td>
<td><input type="text" name="order_item_quantity[]" id="order_item_quantity<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="form-control input-sm order_item_quantity" value = "<?php echo $sub_row["order_item_quantity"]; ?>"/></td>
<td><input type="text" name="order_item_price[]" id="order_item_price<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="form-control input-sm number_only order_item_price" value="<?php echo $sub_row["order_item_price"]; ?>" /></td>
<td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="form-control input-sm order_item_actual_amount" value="<?php echo $sub_row["order_item_actual_amount"];?>" readonly /></td>
<td><input type="text" name="order_item_tax1_rate[]" id="order_item_tax1_rate<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="form-control input-sm number_only order_item_tax1_rate" value="<?php echo $sub_row["order_item_tax1_rate"]; ?>" /></td>
<td><input type="text" name="order_item_tax1_amount[]" id="order_item_tax1_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" readonly class="form-control input-sm order_item_tax1_amount" value="<?php echo $sub_row["order_item_tax1_amount"];?>" /></td>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" readonly class="form-control input-sm order_item_final_amount" value="<?php echo $sub_row["order_item_final_amount"]; ?>" /></td>
<td></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<tr>
<td align="right"><b>Total</td>
<td align="right"><b><span id="final_total_amt"><?php echo $row["order_total_after_tax"]; ?></span></b></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="total_item" id="total_item" value="<?php echo $m; ?>" />
<input type="hidden" name="order_id" id="order_id" value="<?php echo $row["order_id"]; ?>" />
<input type="submit" name="update_invoice" id="create_invoice" class="btn btn-info" value="Edit" />
</td>
</tr>
</table>
</div>
</form>
<script>
$(document).ready(function(){
var final_total_amt = $('#final_total_amt').text();
var count = "<?php echo $m; ?>";
$(document).on('click', '#add_row', function(){
count++;
$('#total_item').val(count);
var html_code = '';
html_code += '<tr id="row_id_'+count+'">';
html_code += '<td><span id="sr_no">'+count+'</span></td>';
html_code += '<td><input type="text" name="order_item_name[]" id="order_item_name'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="order_item_quantity[]" id="order_item_quantity'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_quantity" /></td>';
html_code += '<td><input type="text" name="order_item_price[]" id="order_item_price'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_price" /></td>';
html_code += '<td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount'+count+'" data-srno="'+count+'" class="form-control input-sm order_item_actual_amount" readonly /></td>';
html_code += '<td><input type="text" name="order_item_tax1_rate[]" id="order_item_tax1_rate'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_tax1_rate" /></td>';
html_code += '<td><input type="text" name="order_item_tax1_amount[]" id="order_item_tax1_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_tax1_amount" /></td>';
<?php /*?> html_code += '<td><input type="text" name="order_item_tax2_rate[]" id="order_item_tax2_rate'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_tax2_rate" /></td>';
html_code += '<td><input type="text" name="order_item_tax2_amount[]" id="order_item_tax2_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_tax2_amount" /></td>';
html_code += '<td><input type="text" name="order_item_tax3_rate[]" id="order_item_tax3_rate'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_tax3_rate" /></td>';
html_code += '<td><input type="text" name="order_item_tax3_amount[]" id="order_item_tax3_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_tax3_amount" /></td>';<?php */?>
html_code += '<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_final_amount" /></td>';
html_code += '<td><button type="button" name="remove_row" id="'+count+'" class="btn btn-danger btn-xs remove_row">X</button></td>';
html_code += '</tr>';
$('#invoice-item-table').append(html_code);
});
$(document).on('click', '.remove_row', function(){
var row_id = $(this).attr("id");
var total_item_amount = $('#order_item_final_amount'+row_id).val();
var final_amount = $('#final_total_amt').text();
var result_amount = parseFloat(final_amount) - parseFloat(total_item_amount);
$('#final_total_amt').text(result_amount);
$('#row_id_'+row_id).remove();
count--;
$('#total_item').val(count);
});
function cal_final_total(count)
{
var final_item_total = 0;
for(j=1; j<=count; j++)
{
var quantity = 0;
var price = 0;
var actual_amount = 0;
var tax1_rate = 0;
var tax1_amount = 0;
var tax2_rate = 0;
var tax2_amount = 0;
var hc_amount = 0;
var item_total = 0;
quantity = $('#order_item_quantity'+j).val();
if(quantity > 0)
{
price = $('#order_item_price'+j).val();
if(price > 0)
{
actual_amount = parseFloat(quantity) * parseFloat(price);
$('#order_item_actual_amount'+j).val(actual_amount);
item_total = parseFloat(actual_amount) ;
$('#order_item_final_amount'+j).val(item_total);
}
}
}
tax1_rate = $('#order_item_tax1_rate'+j).val();
if(tax1_rate > 0)
{
tax1_amount = parseFloat(actual_amount)*parseFloat(tax1_rate)/100;
$('#order_item_tax1_amount'+j).val(tax1_amount);
}
tax2_rate = $('#order_item_tax2_rate'+j).val();
if(tax2_rate > 0)
{
tax2_amount = parseFloat(actual_amount)*parseFloat(tax2_rate)/100;
$('#order_item_tax2_amount'+j).val(tax2_amount);
}
hc_amount = parseFloat('#order_item_hc');
final_item_total = parseFloat(final_item_total) + parseFloat(item_total)+ parseFloat(tax1_amount) + parseFloat(tax2_amount) + parseFloat(hc_amount);
$('#final_total_amt').text(final_item_total);
}
$(document).on('blur', '.order_item_price', function(){
cal_final_total(count);
});
$(document).on('blur', '.order_item_tax1_rate', function(){
cal_final_total(count);
});
$(document).on('blur', '.order_item_tax2_rate', function(){
cal_final_total(count);
});
$(document).on('blur', '.order_item_tax3_rate', function(){
cal_final_total(count);
});
$('#create_invoice').click(function(){
if($.trim($('#order_receiver_name').val()).length == 0)
{
alert("Please Enter Reciever Name");
return false;
}
if($.trim($('#order_no').val()).length == 0)
{
alert("Please Enter Invoice Number");
return false;
}
if($.trim($('#order_date').val()).length == 0)
{
alert("Please Select Invoice Date");
return false;
}
for(var no=1; no<=count; no++)
{
if($.trim($('#order_item_name'+no).val()).length == 0)
{
alert("Please Enter Item Name");
$('#order_item_name'+no).focus();
return false;
}
if($.trim($('#order_item_quantity'+no).val()).length == 0)
{
alert("Please Enter Quantity");
$('#order_item_quantity'+no).focus();
return false;
}
if($.trim($('#order_item_price'+no).val()).length == 0)
{
alert("Please Enter Price");
$('#order_item_price'+no).focus();
return false;
}
}
$('#invoice_form').submit();
});
});
</script>
<?php
}
}
else
{
?>
<h2 align="center">HI-TECH ENGINEERS & FABRICATORS</h2>
<h3 align="center">Invoice System</h3>
<br />
<div align="right">
<a href="invoice.php?add=1" class="btn btn-info btn-xs">Create</a>
</div>
<br />
<table id="data-table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Invoice No.</th>
<th>Invoice Date</th>
<th>Receiver Name</th>
<th>Invoice Total</th>
<th>PDF</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<?php
if($total_rows > 0)
{
foreach($all_result as $row)
{
echo '
<tr>
<td>'.$row["order_no"].'</td>
<td>'.$row["order_date"].'</td>
<td>'.$row["order_receiver_name"].'</td>
<td>'.$row["order_total_after_tax"].'</td>
<td><a href="print_invoice.php?pdf=1&id='.$row["order_id"].'">PDF</a></td>
<td><a href="invoice.php?update=1&id='.$row["order_id"].'"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a href="#" id="'.$row["order_id"].'" class="delete"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
';
}
}
?>
</table>
<?php
}
?>
</div>
<br>
<footer class="container-fluid text-center">
<p>Copyright @ Disbydigital 2019</p>
</footer>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
var table = $('#data-table').DataTable({
"order":[],
"columnDefs":[
{
"targets":[4, 5, 6],
"orderable":false,
},
],
"pageLength": 25
});
$(document).on('click', '.delete', function(){
var id = $(this).attr("id");
if(confirm("Are you sure you want to remove this?"))
{
window.location.href="invoice.php?delete=1&id="+id;
}
else
{
return false;
}
});
});
</script>
<script>
$(document).ready(function(){
$('.number_only').keypress(function(e){
return isNumbers(e, this);
});
function isNumbers(evt, element)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (
(charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
(charCode < 48 || charCode > 57))
return false;
return true;
}
});
</script>