View/Invoice/View.ctp
<?php
if ( $payments == NULL ) {
echo '<tr><td> -- No Payments Are Associated With This Invoice -- </td>
<td></td>
<td></td></tr>';
}
?>
<? foreach ($payments as $payment): ?>
<tr id="payment_row_<?= $payment['id'] ?>">
<td class="responsive_cell"><?php echo $payment['method']?></td>
<td class="date_cell responsive_cell"><?php echo $payment['date']?></td>
<td class="right responsive_cell"><?php echo number_format($payment['amount'], 2, '.', ',')?></td>
</tr>
<?php $paymentsTotal += $payment['amount'] ?>
<? endforeach; ?>
View/Invoice/email.ctp
$bedrag = $settings['Setting']['currency'].$thisInvoice['Payment'];
This echo's €Array in EMail.ctp and in View.ctp show the right amount.
How do i get the right amount in Email.ctp ?
Related
I have a table with weeks of a year and some data adjacent to each week, and i can't seem to merge the values correctly. Week rows with no data should stay empty
This is where i list the weeks
foreach ($getLeadCountDMm as $index => $leadCount) { ?>
<tr>
<td><?php echo $leadCount->theweek ?>
/ <?php echo $leadCount->theyear ?></td>
</tr>
<?php }
And this is where i try to merge
foreach ($getLeadCountDMm as $index => $leadCount) { ?>
<tr>
<td style="text-align: center">
<?php if ($getFtdCountDMm[$index]->theweek == $leadCount->theweek && !empty($getFtdCountDMm[$index]->ftdcount)) {
echo $getFtdCountDMm[$index]->ftdcount;
} else {
echo '0';
} ?>
</td>
</tr>
<?php } ?>
it should look like this
but it looks like this
Instead of running two loops run one loop like this.
foreach ($getLeadCountDMm as $index => $leadCount) { ?>
<tr>
<td><?php echo $leadCount->theweek ?>
/ <?php echo $leadCount->theyear ?>
</td>
<td style="text-align: center">
<?php if ($getFtdCountDMm[$index]->theweek == $leadCount->theweek && !empty($getFtdCountDMm[$index]->ftdcount)) {
echo $getFtdCountDMm[$index]->ftdcount;
} else {
echo '0';
} ?>
</td>
</tr>
<?php }
I am working on a point of sale for a hardware shop developed using codeigniter framework.
I want to come up with a detailed statement of account like in the picture below
I have two tables which are sales and payment, I want to get data from this two tables so that I can generate a statement of account of a specific customer.
This will help since the customer can be able to see all the items he/she bought on cash basis or credit basis and also show how much they has paid grouped by date.
It will also be possible to calculate the amount due.
I can be able to list separately (sales and payment) by using the below code and thereby calculate the amount due.
Sales
<?php
$salestotal = 0;
if (is_array($sales) || is_object($sales))
{
foreach ($sales as $key=>$sale): {?>
<tr>
<td>
<?php echo $sale->date; ?>
</td>
<td>
<?php echo $sale->id; ?>
</td>
<td>
<?php echo $sale->grand_total; ?>
</td>
<td>
<?php echo $sale->paid; ?>
</td>
<td></td>
</tr>
<?php
if(isset($sale->grand_total))
$salestotal += $sale->grand_total;
} endforeach ; }?>
Payments
<?php
$paymentstotal = 0;
if (is_array($payments) || is_object($payments))
{
foreach ($payments as $key=>$payment): {?>
<tr>
<td>
<?php echo $payment->date; ?>
</td>
<td class="text-center">
<?php echo $payment->sale_id; ?>
</td>
<td class="text-center">
<?php echo $payment->paid_by; ?>
</td>
<td class="text-center">
<?php echo $payment->cheque_no; ?>
</td>
<td class="text-center">
<?php echo $payment->amount; ?>
</td>
<td class="text-center">
<?php echo $this->customers_model->getUserna($payment->created_by); ?>
</td>
<td class="text-center">
<?php echo $payment->pos_paid; ?>
</td>
<td class="text-center">
<?php echo $payment->pos_balance; ?>
</td>
<td class="text-right">
<?php echo $this->customers_model->getStorename($payment->store_id); ?>
</td>
</tr>
<?php
if(isset($payment->amount))
$paymentstotal += $payment->amount;
} endforeach ;}?>
My controller
function statement($id = NULL)
{
if (!$this->Admin) {
$this->session->set_flashdata('error', $this->lang->line('access_denied'));
redirect('pos');
}
if($this->input->get('id')) { $id = $this->input->get('id', TRUE); }
$this->data['sales'] = $this->customers_model->getSales($id);
$this->data['payments'] = $this->customers_model->getPayments($id);
$this->data['customer'] = $this->customers_model->getCustomername($id);
$this->data['customer_id'] = $id;
$this->page_cons('customers/statement', $this->data);
}
My Model
public function getSales($id)
{
$q = $this->db->get_where('sales', array('customer_id' => $id));
if( $q->num_rows() > 0 ) {
return $q->result();
}
return FALSE;
}
public function getPayments($id)
{
$q = $this->db->get_where('payments', array('customer_id' => $id));
if( $q->num_rows() > 0 ) {
return $q->result();
}
return FALSE;
}
How do I combine this two tables?
I hope I am clear enough on this question, I have been trying to Google but I have no luck.
I will appreciate any help. Thanks
Edit
MYSQL tables
Sales
Payments
You can reuse the given methods getSales() and getPayments() in a new method getSalesWithPayments() to combine the two results:
public function getSalesWithPayments($customerId) {
$sales = [];
foreach ($this->getSales($customerId) as $sale) {
$sale->payment = null;
$sales[$sale->id] = $sale;
}
foreach ($this->getPayments($customerId) as $payment) {
$sales[$payment->sale_id]->payment = $payment;
}
return $sales;
}
In the first loop you initialize $sale->payment (for the case that a sale has no payment yet) and populate the $sales array, which is indexed by the id column. This way you can easily access any sale by its id without an expensive search.
In the second loop you assign the payments to the corresponding sales.
Note that you might need to add logic to handle empty results (which wouldn't be necessary if you would just return an empty array instead of FALSE).
You can now use it like..
Controller:
$this->data['sales'] = $this->customers_model->getSalesWithPayments($id);
View:
<?php foreach ($sales as $sale): ?>
<tr>
<td><?php echo $sale->date; ?></td>
<td><?php echo $sale->id; ?></td>
...
<?php if($sale->payment !== null): ?>
<td><?php echo $sale->payment->date; ?></td>
<td><?php echo $sale->payment->amount; ?></td>
...
<?php else: // empty cells if no payment ?>
<td></td>
<td></td>
...
<?php endif; ?>
</tr>
<?php endforeach; ?>
If you post the sales and payments table the answer will be better and exact. You can use MySQL Join to get combined data from 2 tables.
Try this:
$this->db->select('*')
->from('sales')
->join('payments', 'payments.sales_id = sales.id', 'right')
->where(array('sales.customer_id' => $id));
$results = $this->db->get();
I want to prevent amaun_caj , amaun_pelbagai , amaun_penalti , amaun_tunggakan from being repeated so if the id_akaun is the same the data will not appear, my code only works on amaun_caj, and for the rest, not a single data appear, what's the problem?
<?php
$i = 0; $id_akaun_old ="";
while($output = mysql_fetch_array($result)) {
$i++;
$id_akaun = $output["id_akaun"];
$lokasi = $output["lokasi"];
$amaun_caj = $output["amaun_caj"];
$amaun_tunggakan = $output["amaun_tunggakan"];
$amaun_penalti = $output["amaun_penalti"];
$amaun_pelbagai = $output["amaun_pelbagai"];
$jumlah_bayaran = $output["jumlah_bayaran"];
?>
<tr>
<td>
<?php echo $i; ?>
</td>
<td>
<?php echo $jenis; ?>
</td>
<td>
<?php echo $id_akaun;
?>
</td>
<td>
<?php echo $no_telefon; ?>
</td>
<td>
<?php echo $lokasi; ?>
</td>
<td align="center">
<?php
if($id_akaun != $id_akaun_old):
echo $amaun_caj;
$id_akaun_old = $id_akaun;
else: echo '';
endif;?>
</td>
<td align="center">
<?php
if($id_akaun != $id_akaun_old):
echo $amaun_pelbagai;
$id_akaun_old = $id_akaun;
else: echo '';
endif;?>
</td>
<td align="center">
<?php
if($id_akaun != $id_akaun_old):
echo $amaun_penalti;
$id_akaun_old = $id_akaun;
else: echo '';
endif;?>
</td>
<td align="center">
<?php
if($id_akaun != $id_akaun_old):
echo $amaun_tunggakan;
$id_akaun_old = $id_akaun;
else: echo '';
endif;?>
</td>
<td align="center">
<?php
if($id_akaun != $id_akaun_old):
echo $jumlah_bayaran;
$id_akaun_old = $id_akaun;
else: echo '';
endif;?>
</td>
<?php
}
?>
Using temporary variable $old_id_akaun might not be the best practice. If you still want to do it like that, i suggest you user ORDER BY id_akaun in your SQL syntax.
In my oppinion, you might get rid of temporary variable and follow these steps,
1. Create empty array outside your while loop. For the sake of easy
understanding, let's called it $list_id_akaun.
2. Inside your while loop, after you get $id_akaun, check whether $id_akaun
is inside $list_id_akaun
3. If not exists, insert it to $list_id_akaun and continue echoing your
table row
4. If exists, skip to the next row.
I don't know why you don't want to use a select distinct clause in this case, but just put them inside a container then check inside the loop:
<?php
$temp = array();
$i = 1;
while($output = mysql_fetch_array($result)):
$id_akaun = $output["id_akaun"];
$lokasi = $output["lokasi"];
$amaun_caj = $output["amaun_caj"];
$amaun_tunggakan = $output["amaun_tunggakan"];
$amaun_penalti = $output["amaun_penalti"];
$amaun_pelbagai = $output["amaun_pelbagai"];
$jumlah_bayaran = $output["jumlah_bayaran"];
?>
<tr>
<td><?php echo $i; $i++; ?></td>
<td><?php echo $jenis; ?></td>
<td><?php echo $id_akaun; ?></td>
<td><?php echo $no_telefon; ?></td>
<td><?php echo $lokasi; ?></td>
<?php if(!in_array($id_akaun, $temp)): ?>
<td><?php echo $amaun_penalti; ?></td>
<td><?php echo $amaun_tunggakan; ?></td>
<td><?php echo $jumlah_bayaran; ?></td>
<?php $temp[] = $id_akaun; ?>
<?php else : ?>
<td></td><td></td><td></td>
<?php endif; ?>
</tr>
<?php endhile; ?>
I'm currently learning cart system with CI and got some problems
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: models/main_model.php
Line Number: 241
here's the code:
Controller:
function update_cart(){
$this->main_model->validate_update_cart();
redirect('cart');
}
Model:
function validate_update_cart(){
// Get the total number of items in cart
$total = $this->cart->total_items();
// Retrieve the posted information
$item = $this->input->post('rowid');
$qty = $this->input->post('qty');
// Cycle true all items and update them
for($i=0;$i < $total;$i++)
{
// Create an array with the products rowid's and quantities.
$data = array(
'rowid' => $item[$i], //this is line 241
'qty' => $qty[$i]
);
// Update the cart with the new information
$this->cart->update($data);
}
}
view:
<div id="main">
<?php if(!$this->cart->contents()):
echo 'You don\'t have any items yet.';
else:
?>
<?php echo form_open('cart/update_cart'); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td style="background-color:yellow;">Qty</td>
<td style="background-color:yellow;">Item No/td>
<td style="background-color:yellow;">Description</td>
<td style="background-color:yellow;">Color</td>
<td style="background-color:yellow;">Price</td>
<td style="background-color:yellow;">Sub-Total</td>
<td style="background-color:yellow;">Delete</td>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden('rowid[]', $items['rowid']); ?>
<tr <?php if($i&1){ echo 'class="alt"'; }?>>
<td>
<?php echo form_input(array('name' => 'qty[]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?>
</td>
<td><a style="font-size:11px;"><?php echo $items['id']?></a></td>
<td><a style="font-size:11px;"><?php echo $items['name']; ?></a></td>
<td><a style="font-size:11px;"><?php echo $items['warna']?></a></td>
<td><a style="font-size:11px;">Rp. <?php echo number_format($items['price'],0,",",".");?></a></td>
<td><a style="font-size:11px;">Rp. <?php echo number_format($items['subtotal'],0,",",".");?></a></td>
<td><img src="<?= base_url();?>assets/image/hapus.png"></img></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="5"><strong>Total</strong></td>
<td colspan="2"><a align="right"><?php echo $this->cart->format_number($this->cart->total()); ?></a></td>
</tr>
</tbody>
</table>
<p><?php echo "<input type='submit' class='Button' value='Update'>";?></p>
<?php
echo form_close();
endif;
?>
edited the view, complete code.
when i click the update button it returned error live above.
thanks.
It seems that $this->cart->total_items() returns something different from the total items in the $item and $qty arrays. Later on, you are using this result to iterate these arrays, and the loop variable ($i) exceeds the arrays' boundaries.
Change your loop to:
for($i=0;$i < count($item);$i++)
You can choose count($qty) if you prefer, provided that the two arrays contain the same number of elements (which has to be true anyway, in order for the whole algorithm to work).
when you receive the post you should use
rowid[] instead of rowid
I have been on this for a day now and still cant solve it though it should be quite simple. I have a php code.
foreach($cart as $line=>$item)
{
echo form_open("sales/edit_item/$line");
?>
<td style="align:center;"><?php echo $item['name']; ?></td>
<?php if ($items_module_allowed)
{
?>
<td><?php echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6'));?></td>
<?php
}
else
{
?>
<td><?php echo $item['price']; ?></td>
<?php echo form_hidden('price',$item['price']); ?>
<?php
}
?>
<td>
<?php
if($item['is_serialized']==1)
{
echo $item['quantity'];
echo form_hidden('quantity',$item['quantity']);
}
else
{
echo form_input(array('name'=>'quantity','value'=>$item['quantity'],'size'=>'2'));
}
?>
</td>
</div></div>
<td><?php echo to_currency($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100); ?></td>
<?php
if($item['allow_alt_description']==1)
{
}
else
{
if ($item['description']!='')
{
}
else
{
}
}
?>
</td>
<td> </td>
<td style="color:#2F4F4F";>
<?php
if($item['is_serialized']==1)
{
}
?>
</td>
<td colspan=3 style="text-align:left;">
<?php
if($item['is_serialized']==1)
{
}
?>
</td>
</tr>
<tr style="height:3px">
<td colspan=8 style="background-color:white"> </td>
</tr> </form>
<?php
}
}
?>
This creates fields with relevant data and works ok. I just need to get the last field and echo it, I have tried everything and it still loops through the array, or does not work. This might be simple to someone else but it has confused me for a day now.
When you use a loop, such as for or foreach or while, it will iterate over every single child element of the array until it reaches the end. You don't need to loop, you simply need to access the last member of the array, like so:
$lastLine = end( array_keys($cart) );
echo form_open("sales/edit_item/{$lastLine}");
Edit: Now that I understand a bit better:
$lastItem = array_slice($cart, -1, null, true);
$line = key($lastItem);
$item = reset($lastItem);
echo form_open("sales/edit_item/{$line}");
?>
<!-- do all your html-ish stuff here. -->