so im kinda new in codeigniter and web developing in general but is it possible to count Sub Total and Tax, automatically input that value into somekind of input box in codeigniter?
for example :
i have model that join some column and show the data into a table
table model.php
public function getPurchaseOrder()
{
$query =$this->db->query('SELECT dkmno, kodeprod,kodebarang_op,qty_op,unit_op,price,catatan FROM order_product JOIN barang_dkm ON order_product.kodebarang_op = barang_dkm.kodebarang');
return $query->result_array();
}
table view.php
<table class="table table-fixed table-bordered table-hover" style="width:100%;" id="tebal">
<thead>
<tr>
<th scope="col">DKM No </th>
<th scope="col">Kode Produksi </th>
<th scope="col">Kode Barang </th>
<th scope="col">Deskripsi </th>
<th scope="col">Jumlah/Quantity </th>
<th scope="col">Unit </th>
<th scope="col">Unit Price </th>
<th scope="col">Sub Total </th>
</tr>
</thead>
<tbody>
<?php foreach ($dataTabel as $kiki) : ?>
<tr class="table-row">
<td><?php echo $kiki["dkmno"]; ?></td>
<td><?php echo $kiki["kodeprod"]; ?></td>
<td><?php echo $kiki["kodebarang_op"]; ?></td>
<td><?php echo $kiki["catatan"]; ?></td>
<td><?php echo $kiki["qty_op"]; ?></td>
<td><?php echo $kiki["unit_op"]; ?></td>
<td><?php echo $kiki["price"]; ?></td>
<td class="calc"><?php $a=$kiki["qty_op"]*$kiki["price"]; echo $a ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
and i want to count sub total from the table above and show the answer in a textbox or inputbox
subtotal, discount, and tax code if you want to know
<div class="row mt-5">
<div class="col-sm" id="kontol">
<div class="form-group">
<div class="row">
<div class="col-sm-3">
<label for="SubTotal" class="control-label">Sub Total : </label>
</div>
<div class="col-sm-9">
<input type="number" id="subTotal" name="SubTotal" value="" style="text-align: right;" class="form-control" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-3">
<label for="Discount" class="label-control" id="Discount">Discount : </label>
</div>
<div class="col-lg-3">
<div class="input-group">
<input type="number" name="Discount" class="form-control" id="inputDiscount" value="" min="0" max="100" onchange="calculatedSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-lg-6">
<input type="number" name="SubTotalDiscount" value="" style="text-align: right;" class="form-control" id="subTotalDiscount" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-3">
<label for="Tax" class="label-control">Tax : </label>
</div>
<div class="col-lg-3">
<div class="input-group">
<input type="number" name="Tax" value="" min="0" max="100" class="form-control" id="inputTax" onchange="calculatedSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-lg-6">
<input type="number" name="SubTotalTax" style="text-align: right;" class="form-control" id="subTotalTax" value="" disabled>
</div>
</div>
</div>
i have try to look at people who ask the same question but i still need somekind a detail how the model.php, controller.php, view.php, script.js work, if you need more details here's the link the ui that i already made : https://i.imgur.com/LSkrnMH.png
You could get the subtotal using CodeIgniter, but you have to use javascript to calculate the tax because it involves user interaction.
For example you have the subtotal input like this :
<div class="form-group">
<label class="col-sm-3 control-label" for="SubTotal">Sub Total</label>
<div class="col-sm-9">
<input type="number" name="SubTotal" id="subTotal" class="form-control" value="" title="Sub Total" disabled><br/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Discount">Discount</label>
<div class="col-sm-9">
<div class="col-sm-6">
<div class="input-group input-group-md">
<input type="number" name="Discount" id="inputDiscount" class="form-control" value="" title="Discount" min="0" max="100" onchange="calculateSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-sm-6">
<input type="number" name="SubTotalDiscount" id="subTotalDiscount" class="form-control" value="" title="Subtotal After Discount" disabled><br/>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Tax">Tax</label>
<div class="col-sm-9">
<div class="col-sm-6">
<div class="input-group input-group-md">
<input type="number" name="Tax" id="inputTax" class="form-control" value="" title="Tax" min="0" max="100" onchange="calculateSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-sm-6">
<input type="number" name="SubTotalTax" id="subTotalTax" class="form-control" value="" title="Subtotal After Tax" disabled><br/>
</div>
</div>
</div>
Then you could set the subtotal value and also count the subtotals value after discount and after tax like this :
<script>
jQuery(function () {
let sum = 0.0;
jQuery('.calc').each(function() {
sum += parseInt(jQuery(this).text());
});
jQuery("#subTotal").val(sum);
});
function calculateSubTotal() {
let subtotal = jQuery("#subTotal").val();
jQuery("#subTotalDiscount").val(subtotal - (Math.round((jQuery("#inputDiscount").val() / 100) * subtotal)));
let subtotal_discount = jQuery("#subTotalDiscount").val();
jQuery("#subTotalTax").val(+subtotal_discount + (Math.round((jQuery("#inputTax").val() / 100) * subtotal_discount)));
}
</script>
That will set all of the subtotals using javascript instead.
Try this:
$this->db->select_sum('your_column_to_calculate');
$this->db->select('your_column_to_calculate');
$this->db->from('price');
$this->db->get();
or like this:
query = $this->db->query('SELECT sum(your_column_to_calculate) FROM price');
Hope it helps
This is javascript code,This calculate the only the calc row and show the result in subtotal text box and it will load automatically:
<script>
$(document).ready(function(){
var hh2 = 0;
$('#tebal > tbody > tr').each(function() {
var price = $(this).find('.calc').val();
hh2 += parseFloat(price);
});
$('#SubTotal').val(hh2);
});
</script>
you can count all of the sum with php itself
set variable $subtotal with zero, and add $subtotal in every loop
<?php
$subtotal = 0;
foreach ($dataTabel as $kiki) : ?>
<tr class="table-row">
....
</tr> <?php $subtotal = $subtotal+$kiki["qty_op"]*$kiki["price"]; endforeach;?>
Hope you get it.
Related
I have problem with displaying the table when I put 2 Sql queries inside 1 page. I don't have this problem when I only put 1 query.
I wanted to display the list of student from the student table and the the lecturer can add the student to be put under their care which will have the add function. I have done the coding but I encountered problem.
this is my code
<table id=" table" class="table table-bordered">
<thead>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Email</th>
<th>Contact Number</th>
<th>Programme Type</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, "SELECT * FROM `student`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
?>
<tr class="del_student<?php echo $fetch['student_id']?>">
<td><?php echo $fetch['student_id']?></td>
<td><?php echo $fetch['student_name']?></td>
<td><?php echo $fetch['student_email']?></td>
<td><?php echo $fetch['contact_number']?></td>
<td><?php echo $fetch['programme_type']?></td>
<td><?php echo $fetch['status_type']?></td>
<td><center><button class="btn btn-warning" data-toggle="modal" data-target="#edit_modal<?php echo $fetch['student_id']?>"><span class="glyphicon glyphicon-edit"></span> Edit</button> </center>
</td>
</tr>
<div class="modal fade" id="edit_modal<?php echo $fetch['student_id']?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form method="POST" action="update_student.php">
<div class="modal-header">
<h4 class="modal-title">Add Supervisee</h4>
</div>
<div class="modal-body">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group">
<label>Student ID</label>
<input type="hidden" name="id" value="<?php echo $fetch['id']?>" class="form-control"/>
<input type="number" name="student_id" value="<?php echo $fetch['student_id']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Student Name</label>
<input type="text" name="student_name" value="<?php echo $fetch['student_name']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Student Email</label>
<input type="email" name="student_email" value="<?php echo $fetch['student_email']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Contact Number </label>
<input type="text" name="contact_number" value="<?php echo $fetch['contact_number']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Programme Type</label>
<input type="text" name="programme_type" value="<?php echo $fetch['programme_type']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Status</label>
<input type="text" name="status_type" value="<?php echo $fetch['status_type']?>" class="form-control" required="required"/>
</div>
<label>Supervisor Information</label>
<div class="form-group">
<?php
$query = mysqli_query($conn, "SELECT * FROM `supervisor` WHERE `user_id` = '$_SESSION[user]'") or die(mysqli_error());
$fetch = mysqli_fetch_array($query);
$user_id = $fetch['work_id'];
?>
<label>Supervisor ID</label>
<input type="text" name="supervisor_id" value="<?php echo $fetch['work_id']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Supervisor Name</label>
<input type="text" name="supervisor_name" value="<?php echo $fetch['name']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Supervisor Role </label>
<select name="supervisor_role" class="form-control" required="required">
<option value="Chose supervisor role"></option>
<option value="Supervisor">Supervisor</option>
<option value="Co - Supervisor">Co-Supervisor</option>
</select>
</div>
</div>
</div>
<div style="clear:both;"></div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
<button name="update" class="btn btn-warning" ><span class="glyphicon glyphicon-save"></span> Update</button>
</div>
</form>
</div>
</div>
<?php
}
?>
</tbody>
</table>
</div>
</div>
I noticed that the table did not display the full list of student when I put this query
<?php
$query = mysqli_query($conn, "SELECT * FROM `supervisor` WHERE `user_id` = '$_SESSION[user]'") or die(mysqli_error());
$fetch = mysqli_fetch_array($query);
$user_id = $fetch['work_id'];
?>
What I want to achieve is I want to display all the student that have been registered inside the database, and the lecturer can add the student, student information alongside with the lecturer id and name will be saved into the database. How to fix this problem?
You are using $fetch to get results from both queries.
Here's what is happening in your code.
your $fetch gets results from students table.
displays the table content till it reaches the 2nd query.
when your 2nd query gets executed, $fetch values gets changed. Thus only 1 row is displayed for your student's table.
Change the $fetch in 2nd query to something else, like $fetch2
I am working on employee attendance system and the attendance is working perfectly but the issue now is how do I generate the attendance report when I select the employee name and the starting and ending date? am done with the html code all i need now is the php code that would work with my present html code.please i would appreciate your help thanks in advance.
below is the html code.
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<label class="col-sm-3 control-label"> Select Employee Name</label>
<div class="col-sm-4">
<select type="text" name="name" class="form-control" placeholder="Employee Full Name" required>
<option value="">Select Employee Name</option>
<?php
$get = mysql_query("SELECT employee_name FROM employee");
while($row = mysql_fetch_assoc($get)) {
?>
<option value = "<?php echo($row['employee_name'])?>" >
<?php echo($row['employee_name']) ?>
</option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"> Start Date</label>
<div class="col-sm-4">
<input type="text" name="Start_date" class="input-group date form-control" date="" data-date-format="yyyy-mm-dd" placeholder="0000-00-00" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">End Date</label>
<div class="col-sm-4">
<input type="text" name="end_date" class="input-group date form-control" date="" data-date-format="yyyy-mm-dd" placeholder="0000-00-00" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"> </label>
<div class="col-sm-6">
<input type="submit" name="add" class="btn btn-sm btn-primary" value="Generate Report">
<div class="table-responsive">
<table class="table table-striped table-hover">
<tr>
<th>No</th>
<th> Employee Id</th>
<th>Employee Name</th>
<th>Date In</th>
<th>Time In</th>
<th>Late</th>
<th>Tools</th>
</tr>
</table>
</div>
</div>
</form>
Change your query accordingly, like:
"SELECT employee_name FROM employee WHERE '".$date."' BETWEEN (start_date, end_date);"
Or you can also use >= and <= to compare the dates
Just add a print button and give an ID to it. Include JS code:
function printData()
{
var divToPrint=document.getElementById("printTable");
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}
$('button').on('click',function(){
printData();
})
Fiddle: http://jsfiddle.net/dimshik/9DbEP/4/
My view is like i want to show the selected textbox price and code to the controller
how can i do this
<div>
<!--second line start-->
<?php
foreach ($enq_info as $ei) {
echo form_open_multipart("Quotation/prepareQuote2/$ei->eid");
if (!empty($quote_data)) {
?>
<input name="quote_check" value="1" type="text" class="form-control">
<?php
} else {
?>
<input name="quote_check" value="no" type="text" class="form-control">
<?php
}
?>
<div class="form-group">
<div class="col-sm-2">
<label for="firstname">Enquiry Id</label>
<input name="e_id" id="e_id" value="<?php echo $ei->eid;?>" type="text" class="form-control">
</div>
<div class="col-sm-3">
<label for="lastname">Company Name</label>
<input type="text" name="company_name" id="company_name" value="<?php echo $ei->company_name;?>" class="form-control" />
</div>
<div class="col-sm-3">
<label for="lastname">Contact Person</label>
<input type="text" name="c_person" id="c_person" value="<?php echo $ei->c_person;?>" class="form-control"/>
</div>
<div class="col-sm-4">
<label>Address</label>
<textarea class="form-control" id="address" name="address" value="<?php echo $ei->address;?>"><?php echo $ei->address;?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<label for="firstname">Attn Department</label>
<textarea class="form-control" id="dept" name="dept" value="">
<?php
echo $ei->c_person." Tel ";
if(empty($ei->p_contact))
echo $ei->c_contact;
else
echo $ei->p_contact;
?>
</textarea>
</div>
<div class="col-sm-3">
<label for="lastname">Quotation For</label>
<select id="quotation_type" name="quotation_type" class="form-control m-b">
<option value="Q_Manager">Q-Manager Quote</option>
<option value="Q_Master">Q-Master Quote</option>
<option value="Q_Manager_repair">Q-Manager Repair Quote</option>
</select>
</div>
<div class="col-sm-3">
<label for="lastname">Discount</label>
<textarea class="form-control" id="discount" name="discount"></textarea>
</div>
<div class="col-sm-3">
<label for="lastname"></label><br><br>
<input type="submit" class="btn btn-success" id="default_quote" value="Generate Default Quote" onClick="rerurn disable1();"/>
</div>
</div>
<div id="showquote">
<div class="row">
<div class="hpanel">
<div class="panel-body">
<div class="col-md-12">
<table class="table table-bordered table-striped">
<tr>
<td>Product Name</td>
<td>Product Code</td>
<td>Price</td>
<td>Action</td>
</tr>
<?php
// print_r($quote_data);
foreach ($product_data as $qd) {
?>
<tr>
<td><?php echo $qd->cp_name;?></td>
<td><?php echo $qd->cp_code;?></td>
<td>
<input type="text" name="product_price[]" value="<?php echo $qd->p_price;?>">
</td>
<td>
<input type="checkbox" name="product_name[]" value="<?php echo $qd->cp_name;?>" checked/>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
<?php echo form_close(); ?>
<br><br>
<!--for new manual quote-->
<?php
}
?>
<!--third line start-->
how can i send the selected values price and also product code to the controller
just add the product code - product price with comma seperated in a hidden field like below
12-20000,13-30000,14-200 and so on
and once received in controller process it with explode or other way.
hopes you understood.
Any ideas what I'm doing wrong here? I'm getting the getID back fine as it's displaying when I echo on page but nothing else is getting set from database that I'm requesting.
I have tried a few things but cannot seem to crack it; I think maybe it might be bad markup from my side with the actual select query and how I put in the getID but might be wrong.
I've also added a foreach to list products, that might be wrong as well.
PHP / HTML
include('includes/config.php');
include('header.php');
include('functions.php');
$getID = $_GET['id'];
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
// the query
$query = "SELECT i.*
FROM invoices as i
JOIN customers as c ON c.invoice = ".$getID."
JOIN invoice_items as p ON p.invoice = ".$getID."
ORDER BY i.invoice";
// mysqli select query
$results = $mysqli->query($query);
// mysqli select query
if($results) {
$customer_name = $row['customer_name']; // customer name
$customer_email = $row['customer_email']; // customer email
$customer_address_1 = $row['customer_address_1']; // customer address
$customer_address_2 = $row['customer_address_2']; // customer address
$customer_town = $row['customer_town']; // customer town
$customer_county = $row['customer_county']; // customer county
$customer_postcode = $row['customer_postcode']; // customer postcode
$customer_phone = $row['customer_phone']; // customer phone number
//shipping
$customer_name_ship = $row['customer_name_ship']; // customer name (shipping)
$customer_address_1_ship = $row['customer_address_1_ship']; // customer address (shipping)
$customer_address_2_ship = $row['customer_address_2_ship']; // customer address (shipping)
$customer_town_ship = $row['customer_town_ship']; // customer town (shipping)
$customer_county_ship = $row['customer_county_ship']; // customer county (shipping)
$customer_postcode_ship = $row['customer_postcode_ship']; // customer postcode (shipping)
// invoice details
$invoice_number = $row['invoice_id']; // invoice number
$invoice_date = $row['invoice_date']; // invoice date
$invoice_due_date = $row['invoice_due_date']; // invoice due date
$invoice_subtotal = $row['invoice_subtotal']; // invoice sub-total
$invoice_shipping = $row['invoice_shipping']; // invoice shipping amount
$invoice_discount = $row['invoice_discount']; // invoice discount
$invoice_vat = $row['invoice_vat']; // invoice vat
$invoice_total = $row['invoice_total']; // invoice total
$invoice_notes = $row['invoice_notes']; // Invoice notes
$invoice_status = $row['invoice_status']; // Invoice status
}
?>
<h1>Edit Invoice (<?php echo $getID; ?>)</h1>
<hr>
<div id="response" class="alert alert-success" style="display:none;">
×
<div class="message"></div>
</div>
<form method="post" id="create_invoice">
<input type="hidden" name="action" value="create_invoice">
<div class="row">
<div class="col-xs-5">
<h1>
<img src="<?php echo COMPANY_LOGO ?>" class="img-responsive">
</h1>
</div>
<div class="col-xs-7 text-right">
<div class="row">
<div class="col-xs-9">
<h1>INVOICE</h1>
</div>
<div class="col-xs-3">
<select name="invoice_status" id="invoice_status" class="form-control">
<option value="open" <?php if($invoice_status == "open"){?>selected<?php } ?>>Open</option>
<option value="paid" <?php if($invoice_status == "paid"){?>selected<?php } ?>>Paid</option>
</select>
</div>
</div>
<div class="col-xs-4 no-padding-right">
<div class="form-group">
<div class="input-group date" id="invoice_date">
<input type="text" class="form-control required" name="invoice_date" placeholder="Select invoice date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<div class="input-group date" id="invoice_due_date">
<input type="text" class="form-control required" name="invoice_due_date" placeholder="Select due date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_due_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="input-group col-xs-4 float-right">
<span class="input-group-addon">#<?php echo INVOICE_PREFIX ?></span>
<input type="text" name="invoice_id" id="invoice_id" class="form-control required" placeholder="Invoice Number" aria-describedby="sizing-addon1" value="<?php echo $getID; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Customer Information</h4>
<div class="clear"></div>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_name" id="customer_name" placeholder="Enter name" tabindex="1" value="<?php echo $customer_name; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_address_1" id="customer_address_1" placeholder="Address 1" tabindex="3" value="<?php echo $customer_address_1; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_town" id="customer_town" placeholder="Town" tabindex="5" value="<?php echo $customer_town; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control copy-input required" name="customer_postcode" id="customer_postcode" placeholder="Postcode" tabindex="7" value="<?php echo $customer_postcode; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="input-group float-right margin-bottom">
<span class="input-group-addon">#</span>
<input type="email" class="form-control copy-input required" name="customer_email" id="customer_email" placeholder="E-mail address" aria-describedby="sizing-addon1" tabindex="2" value="<?php echo $customer_email; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input" name="customer_address_2" id="customer_address_2" placeholder="Address 2" tabindex="4" value="<?php echo $customer_address_2; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_county" id="customer_county" placeholder="County" tabindex="6" value="<?php echo $customer_county; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_phone" id="invoice_phone" placeholder="Phone number" tabindex="8" value="<?php echo $customer_phone; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 text-right">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Shipping Information</h4>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_name_ship" id="customer_name_ship" placeholder="Enter name" tabindex="9" value="<?php echo $customer_name_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom" name="customer_address_2_ship" id="customer_address_2_ship" placeholder="Address 2" tabindex="11" value="<?php echo $customer_address_2_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_county_ship" id="customer_county_ship" placeholder="County" tabindex="13" value="<?php echo $customer_county_ship; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_address_1_ship" id="customer_address_1_ship" placeholder="Address 1" tabindex="10" value="<?php echo $customer_address_1_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_town_ship" id="customer_town_ship" placeholder="Town" tabindex="12" value="<?php echo $customer_town_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_postcode_ship" id="customer_postcode_ship" placeholder="Postcode" tabindex="14" value="<?php echo $customer_postcode_ship; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / end client details section -->
<table class="table table-bordered" id="invoice_table">
<thead>
<tr>
<th width="500">
<h4><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Item</h4>
</th>
<th>
<h4>Qty</h4>
</th>
<th>
<h4>Price</h4>
</th>
<th width="300">
<h4>Discount</h4>
</th>
<th>
<h4>Sub Total</h4>
</th>
</tr>
</thead>
<tbody>
<?php
foreach($invoice_product as $key => $value) {
$item_product = $value;
// $item_description = $_POST['invoice_product_desc'][$key];
$item_qty = $row['invoice_product_qty'][$key];
$item_price = $row['invoice_product_price'][$key];
$item_discount = $row['invoice_product_discount'][$key];
$item_subtotal = $row['invoice_product_sub'][$key];
?>
<tr>
<td>
<div class="form-group form-group-sm no-margin-bottom">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<input type="text" class="form-control form-group-sm item-input invoice_product" name="invoice_product[]" placeholder="Enter item title and / or description" value="<?php echo $item_product; ?>">
<p class="item-select">or select an item</p>
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_qty[]" value="1" value="<?php echo $item_qty; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm no-margin-bottom">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate invoice_product_price required" name="invoice_product_price[]" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $item_price; ?>">
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_discount[]" placeholder="Enter % or value (ex: 10% or 10.50)" value="<?php echo $item_discount; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate-sub" name="invoice_product_sub[]" id="invoice_product_sub" value="0.00" aria-describedby="sizing-addon1" value="<?php echo $item_subtotal; ?>" disabled>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div id="invoice_totals" class="padding-right row text-right">
<div class="col-xs-6">
<div class="input-group form-group-sm textarea no-margin-bottom">
<textarea class-"form-control" name="invoice_notes" placeholder="Please enter any order notes here." value="<?php echo $invoice_notes; ?>"></textarea>
</div>
</div>
<div class="col-xs-6 no-padding-right">
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Sub Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-sub-total"> <?php echo $invoice_subtotal; ?></span>
<input type="hidden" name="invoice_subtotal" id="invoice_subtotal" value="<?php echo $invoice_subtotal; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Discount:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-discount"> <?php echo $invoice_discount; ?></span>
<input type="hidden" name="invoice_discount" id="invoice_discount" value="<?php echo $invoice_discount; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong class="shipping">Shipping:</strong>
</div>
<div class="col-xs-3">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate shipping" name="invoice_shipping" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $invoice_shipping; ?>">
</div>
</div>
</div>
<?php if (ENABLE_VAT == true) { ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>TAX/VAT:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-vat" data-enable-vat="<?php echo ENABLE_VAT ?>" data-vat-rate="<?php echo VAT_RATE ?>" data-vat-method="<?php echo VAT_INCLUDED ?>">0.00</span>
<input type="hidden" name="invoice_vat" id="invoice_vat">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-total"> <?php echo $invoice_total; ?></span>
<input type="hidden" name="invoice_total" id="invoice_total" value="<?php echo $invoice_total; ?>">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 margin-top btn-group">
<input type="submit" id="action_edit_invoice" class="btn btn-success float-right" value="Update Invoice" data-loading-text="Updating...">
</div>
</div>
</form>
<div id="insert" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Select an item</h4>
</div>
<div class="modal-body">
<?php popProductsList(); ?>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="selected">Add</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
include('footer.php');
?>
The JOINs in your query are a little strange with constants in your ON clauses
...
JOIN customers as c ON c.invoice = ".$getID."
JOIN invoice_items as p ON p.invoice = ".$getID."
...
You want this instead. Your ON clauses need to express a relationship between rows in your three tables. Putting constant values in those clauses defeats that. Instead use a WHERE clause to filter the correct invoice number.
SELECT something, something
FROM invoices as i
JOIN customers as c ON c.invoice = i.invoice
JOIN invoice_items as p ON p.invoice = i.invoice
WHERE i.invoice = ".$getID."
ORDER BY i.invoice
Secondly, are you sure you have a column called invoice in all three of these tables? Your code mentions a column called invoice_id later on. Is that, in fact, the name of your join column?
Thirdly, it looks like your php code expects columns from two of your three tables to appear in your result set. For example.
....
$customer_postcode_ship = $row['customer_postcode_ship'];
....
$invoice_number = $row['invoice_id'];
...
But you did SELECT c.* which only returns the columns from your customers table.
Pro tip: Avoid * in SELECT clauses. Instead, list out the columns you want. Do something like this:
SELECT customer_name, customer_email, customer_address_1, customer_address_2,
customer_town, customer_county, customer_postcode,
customer_phone, customer_name_ship, customer_address_1_ship,
customer_address_2_ship, customer_town_ship, customer_county_ship,
customer_postcode_ship,
invoice_id, invoice_date, invoice_due_date, invoice_subtotal,
invoice_shipping, invoice_discount, invoice_vat, invoice_total,
invoice_notes, invoice_status
FROM ...
I know this seems impossibly verbose. But it's worth the effort because it allows your php code to be resilient to changes in table structure. It also makes it clear to the programmer who debugs this which columns are available in the result set.
Fourthly, keep in mind that you will get a combinatorial explosion of rows here. You're filtering for just one invoice which is fine. Presumably each invoice relates to only one customer. That too is fine. But, your customer and invoice column values will be repeated once for each matching row from your invoice_items table.
Fifth: check for an error return from $mysqli->query($query);.
$results = $mysqli->query($query);
if (!$results) {
printf("Errormessage: %s\n", $mysqli->error);
} else {
/* process the resultset */
}
As you work with SQL, this stuff will eventually become second nature. Don't get overly annoyed at the complexity of doing it right!
i had form that is add some fields via jquery when i click " add new " button it will update a dom , with input fields . Input fields are using a array as a name , when i click submit button , values did not post to php, only static form values are posted but not dynamically generated input values .
My fiddle is http://jsfiddle.net/4L9Rc/
It will demonstrate clearly how is my form working .
HTML
<div class="row">
<div class="col-md-12">
<form method="POST" action="http://fabtech.com/invoices/create" accept-charset="UTF-8" role="form" class="form-horizontal re-form form-inv"><input name="_token" type="hidden" value="aLngVzB1UIlY6cEedbAh55tirXGGkYJl78BL0CRN"> <legend>Invoice Details</legend>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Invoice No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter invoice no" class="form-control" name="inv_no" value=""">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Invoice date</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control date-pic" name="inv_date" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Customer</label>
<div class="col-md-7">
<select class="form-control" name="inv_customer">
<option value="">- Select Customer -</option>
<option value="suresh">suresh</option>
<option value="ABC210">ABC210</option>
<option value="QWERTy123DF">QWERTy123DF</option>
<option value="CUS002">CUS002</option>
<option value="CUS0023">CUS0023</option>
<option value="CUS003">CUS003</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control" name="po_no" value="">
</div> </div>
<div class="form-group">
<label class="col-md-4 control-label">PO date</label>
<div class="col-md-7">
<input type="text" placeholder="DD/MM/YYY" class="form-control date-pic" name="po_date" value="">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Vendor code</label>
<div class="col-md-7">
<input type="text" placeholder="Enter Vendor Code" class="form-control" name="vendor_code" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">75% abatement value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control sf" name="sf">
</div>
<div class="col-md-6 sfbox" style="display:none">
<input type="text" class="form-control sfboxval" readonly="">
</div> </div>
<div class="form-group">
<label class="col-md-4 control-label">25% Taxable Value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control tf" name="tf">
</div>
<div class="col-md-6 tfbox" style="display:none" >
<input type="text" class="form-control tfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tax in %</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control tax" name="tax" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Grand Total</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control grandtotal" readonly="" name="grand_total">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Particulars
<a class="btn btn-xs btn-success" id="apm"><i class="icon-plus"></i> Add new</a>
</legend>
<table id="apmr" width="69%" class="table table-striped table-bordered table-hover invoice">
<thead>
<tr>
<th width="3%">SL No</th>
<th width="25%">Description</th>
<th width="8%">Unit</th>
<th width="8%">Qty</th>
<th width="10%">Unit rate</th>
<th width="9%"> Amount</th>
</tr>
</thead>
<tbody class="roo">
<tr>
<td valign="center"> 1 </td>
<td class="tr_nt"><input type="text" name="parti[1][desc]" class="part"></td>
<td class="tr_nt"><input type="text" name="parti[1][unit]" class="part"></td>
<td class="tr_qty into"><input type="text" name="parti[1][qty]" class="part qty"></td>
<td class="tr_urate into"><input type="text" name="parti[1][urate]" class="part ur"></td>
<td class="tr_amt"><input type="text" name="parti[1][amount]" readonly="" class="part tot"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
<td colspan="2">
Particular's Total: Rs <span class="parttotal"></span>
</td>
</tr>
</tfoot>
</table>
<p style="text-align: center;padding-top: 5px;"><input name="submit" class="btn-lg btn-primary" type="submit" value="View Invoice"></p>
</form> </div>
</div>
</div>
</div>
Javascript
//invoice particulars
var val;
$("#apm").click(function(event) {
//event.preventDefault();
//var preData = $("#apmr tr:last").html();
//console.log(preData);
//
//$("#apmr tr:last").after('<tr>' + preData + '</tr>');
var lasttd = $('.roo tr:last td:first').text();
val = parseInt(lasttd) + 1;
$(".roo tr:last").after(' <tr> <td valign="center"> ' + val + ' </td> <td class="tr_nt"><input type="text" name="parti[' + val + '][desc]" class="part"></td> <td class="tr_nt"><input type="text" name="parti[' + val + '][unit]" class="part"></td> <td class="tr_qty into"><input type="text" name="parti[' + val + '][qty]" class="part qty"></td> <td class="tr_urate into"><input type="text" name="parti[' + val + '][urate]" class="part ur"></td> <td class="tr_amt"><input type="text" name="parti[' + val + '][amount]" readonly class="part tot" ></td></tr>');
// val = val + 1;
return false;
})
var gt;
$("table.invoice").on("change", '.qty, .ur', function(event) {
calculateRow($(this).closest("tr"));
calculateTotal();
});
function calculateRow(row) {
var price = +row.find('.qty').val();
var qty = +row.find('.ur').val();
row.find('.tot').val((price * qty).toFixed(2));
}
function calculateTotal() {
var Total = 0;
$("table.invoice").find('.tot').each(function() {
Total += +$(this).val();
});
$(".parttotal").text(Total.toFixed(2));
calgrand();
}
$(".re-form").on('change', '.tax,.tf,.sf', function(event) {
calgrand();
})
function calgrand() {
var taxVal = $('.tax').val();
var parVal = $(".parttotal").text();
var result = parVal - taxVal * parVal / 100;
$('.grandtotal').val(result.toFixed(2));
if ($('.tf').is(':checked')) {
var resulttf = parVal - 25 * parVal / 100;
$('.tfboxval').val(resulttf.toFixed(2));
var result = result - resulttf;
$('.grandtotal').val(result.toFixed(2));
}
if ($('.sf').is(':checked')) {
//alert('entered');
var resultsf = parVal - 75 * parVal / 100;
$('.sfboxval').val(resultsf.toFixed(2));
var result = result - resultsf;
$('.grandtotal').val(result.toFixed(2));
}
}
$('.tf').click(function() {
$(".tfbox").toggle(this.checked);
});
$('.sf').click(function() {
$(".sfbox").toggle(this.checked);
});
in php i had
print_r($_POST['parti']);
its give out put
Array
(
[1] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
)
but i need
Array
(
[1] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
[2] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
[3] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
....
)
javascript
Please indent your code next time. Too many changes to make in your form. At the line where you have "Enter invoice no." you have left an open quote at value=""" which is a big mistake.
Overwrite your HTML code with this:
<div class="matter">
<div class="container">
<form method="POST" action="http://fabtech.com/invoices/create" accept-charset="UTF-8" role="form" class="form-horizontal re-form form-inv">
<input name="_token" type="hidden" value="aLngVzB1UIlY6cEedbAh55tirXGGkYJl78BL0CRN">
<div class="row">
<div class="col-md-12">
<legend>Invoice Details</legend>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Invoice No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter invoice no" class="form-control" name="inv_no" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Invoice date</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control date-pic" name="inv_date" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Customer</label>
<div class="col-md-7">
<select class="form-control" name="inv_customer">
<option value="">- Select Customer -</option>
<option value="suresh">suresh</option>
<option value="ABC210">ABC210</option>
<option value="QWERTy123DF">QWERTy123DF</option>
<option value="CUS002">CUS002</option>
<option value="CUS0023">CUS0023</option>
<option value="CUS003">CUS003</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control" name="po_no" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO date</label>
<div class="col-md-7">
<input type="text" placeholder="DD/MM/YYY" class="form-control date-pic" name="po_date" value="">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Vendor code</label>
<div class="col-md-7">
<input type="text" placeholder="Enter Vendor Code" class="form-control" name="vendor_code" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">75% abatement value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control sf" name="sf">
</div>
<div class="col-md-6 sfbox" style="display:none">
<input type="text" class="form-control sfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">25% Taxable Value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control tf" name="tf">
</div>
<div class="col-md-6 tfbox" style="display:none">
<input type="text" class="form-control tfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tax in %</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control tax" name="tax" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Grand Total</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control grandtotal" readonly="" name="grand_total">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Particulars <a class="btn btn-xs btn-success" id="apm"><i class="icon-plus"></i> Add new</a>
</legend>
<table id="apmr" width="69%" class="table table-striped table-bordered table-hover invoice">
<thead>
<tr>
<th width="3%">
SL No
</th>
<th width="25%">
Description
</th>
<th width="8%">
Unit
</th>
<th width="8%">
Qty
</th>
<th width="10%">
Unit rate
</th>
<th width="9%">
Amount
</th>
</tr>
</thead>
<tbody class="roo">
<tr>
<td valign="center">
1
</td>
<td class="tr_nt">
<input type="text" name="parti[1][desc]" class="part">
</td>
<td class="tr_nt">
<input type="text" name="parti[1][unit]" class="part">
</td>
<td class="tr_qty into">
<input type="text" name="parti[1][qty]" class="part qty">
</td>
<td class="tr_urate into">
<input type="text" name="parti[1][urate]" class="part ur">
</td>
<td class="tr_amt">
<input type="text" name="parti[1][amount]" readonly="" class="part tot">
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
<td colspan="2">
Particular's Total: Rs <span class="parttotal"></span>
</td>
</tr>
</tfoot>
</table>
<p style="text-align: center;padding-top: 5px;">
<input name="submit" class="btn-lg btn-primary" type="submit" value="View Invoice">
</p>
</div>
</div>
</form>
</div>
</div>
Your mistake was that your <form> tag was closed in the wrong place. Remember to always place tags in such a way that always the inner tags close first.