mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-10-19 23:11:44 -04:00
Sale Overview change
- Refactor and optimise payments part (added now amount to detail sale report too) - fix some </tr> that should have been </td> - minor indentation fixes NOTE: The only_invoices checkbox is not responsive
This commit is contained in:
1 parent
c88f37f8e7
commit
75fa706299
6 files changed
+51
-78
No files matched your search
@@ -39,15 +39,10 @@ class Sales extends Secure_area
|
||||
$report_data = $model->get_data(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id,
|
||||
'only_invoices' => $only_invoices, 'lines_per_page' => $lines_per_page, 'limit_from' => $limit_from));
|
||||
|
||||
$sales = $report_data['summary'];
|
||||
$payments = $report_data['payments'];
|
||||
$details = $report_data['details'];
|
||||
$payments_summary = $report_data['payments_summary'];
|
||||
|
||||
$data['only_invoices'] = $only_invoices;
|
||||
$data['links'] = $this->_initialize_pagination($model, $lines_per_page, $limit_from, -1, 'manage', $only_invoices);
|
||||
$data['manage_table'] = get_sales_manage_table($sales, $payments, $details, $this);
|
||||
$data['payments_summary_data'] = get_sales_manage_payments_summary($payments_summary, $this);
|
||||
$data['manage_table'] = get_sales_manage_table($report_data['sales'], $this);
|
||||
$data['payments_summary'] = get_sales_manage_payments_summary($report_data['payments'], $report_data['sales'], $this);
|
||||
$this->load->view($data['controller_name'] . '/manage', $data);
|
||||
$this->_remove_duplicate_cookies();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
function get_sales_manage_table($sales, $payments, $details, $controller)
|
||||
function get_sales_manage_table($sales, $controller)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$table='<table class="tablesorter" id="sortable_table">';
|
||||
@@ -22,7 +22,7 @@ function get_sales_manage_table($sales, $payments, $details, $controller)
|
||||
$table.="<th>$header</th>";
|
||||
}
|
||||
$table.='</tr></thead><tbody>';
|
||||
$table.=get_sales_manage_table_data_rows($sales, $payments, $details, $controller);
|
||||
$table.=get_sales_manage_table_data_rows($sales, $controller);
|
||||
$table.='</tbody></table>';
|
||||
|
||||
return $table;
|
||||
@@ -31,17 +31,17 @@ function get_sales_manage_table($sales, $payments, $details, $controller)
|
||||
/*
|
||||
Gets the html data rows for the sales.
|
||||
*/
|
||||
function get_sales_manage_table_data_rows($sales, $payments, $details, $controller)
|
||||
function get_sales_manage_table_data_rows($sales, $controller)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$table_data_rows='';
|
||||
$table_data_rows = '';
|
||||
$sum_amount_tendered = 0;
|
||||
$sum_amount_due = 0;
|
||||
$sum_change_due = 0;
|
||||
|
||||
foreach($sales as $key=>$sale)
|
||||
{
|
||||
$table_data_rows.=get_sales_manage_sale_data_row($sale, $payments[$key], $controller);
|
||||
$table_data_rows .= get_sales_manage_sale_data_row($sale, $controller);
|
||||
|
||||
$sum_amount_tendered += $sale['amount_tendered'];
|
||||
$sum_amount_due += $sale['amount_due'];
|
||||
@@ -50,66 +50,41 @@ function get_sales_manage_table_data_rows($sales, $payments, $details, $controll
|
||||
|
||||
if($table_data_rows == '')
|
||||
{
|
||||
$table_data_rows.="<tr><td colspan='8'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('sales_no_sales_to_display')."</div></tr></tr>";
|
||||
$table_data_rows .= "<tr><td colspan='8'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('sales_no_sales_to_display')."</div></td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
// empty line
|
||||
//$table_data_rows .= "<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>";
|
||||
// show a line in bold with the totals
|
||||
$table_data_rows.="<tr><th> </th><th>".$CI->lang->line('sales_total')."</th><th> </th><th> </th><th>".to_currency($sum_amount_tendered)."</th><th>".to_currency($sum_amount_due)."</th><th>".to_currency($sum_change_due)."</th></tr>";
|
||||
$table_data_rows .= "<tr><th> </th><th>".$CI->lang->line('sales_total')."</th><th> </th><th> </th><th>".to_currency($sum_amount_tendered)."</th><th>".to_currency($sum_amount_due)."</th><th>".to_currency($sum_change_due)."</th></tr>";
|
||||
}
|
||||
|
||||
return $table_data_rows;
|
||||
}
|
||||
|
||||
function get_sales_manage_sale_data_row($sale, $payments, $controller)
|
||||
function get_sales_manage_sale_data_row($sale, $controller)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$controller_name = $CI->uri->segment(1);
|
||||
$width = $controller->get_form_width();
|
||||
|
||||
$payment = '';
|
||||
|
||||
// set in one string all the payments type and amount
|
||||
foreach( $payments as $key=>$row )
|
||||
{
|
||||
$payment.= $row['payment_type'] . " ";
|
||||
|
||||
// the assumption here is that any change due is deducted from the cash amount paid, not from any other form of payment
|
||||
if( $row['payment_type'] == $CI->lang->line('sales_cash') )
|
||||
{
|
||||
$payment.= to_currency($row['payment_amount'] - $sale['change_due']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$payment.= to_currency($row['payment_amount']);
|
||||
}
|
||||
|
||||
$payment.= ", ";
|
||||
}
|
||||
|
||||
// make sure we have something in the string
|
||||
if( $payment != '' )
|
||||
{
|
||||
// remove the last ", " from the string
|
||||
$payment = substr($payment, 0, strlen($payment) - 2 );
|
||||
}
|
||||
|
||||
$table_data_row='<tr>';
|
||||
$table_data_row.='<td width="3%"><input type="checkbox" id="sale_"' . $sale[ 'sale_id' ] . ' value="' . $sale[ 'sale_id' ]. '" /></td>';
|
||||
$table_data_row.='<td width="15%">'.'POS ' . $sale[ 'sale_id' ]. '</td>';
|
||||
$table_data_row.='<td width="17%">'.date($CI->config->item('dateformat').' '.$CI->config->item('timeformat'), strtotime($sale[ 'sale_time' ])).'</td>';
|
||||
$table_data_row.='<td width="23%">'.character_limiter( $sale[ 'customer_name' ], 25).'</td>';
|
||||
$table_data_row.='<td width="10%">'.to_currency( $sale[ 'amount_tendered' ] ).'</td>';
|
||||
$table_data_row.='<td width="10%">'.to_currency( $sale[ 'amount_due' ] ).'</td>';
|
||||
$table_data_row.='<td width="10%">'.to_currency( $sale[ 'change_due' ] ).'</td>';
|
||||
$table_data_row.='<td width="20%">'.$payment.'</td>';
|
||||
$table_data_row.='<td width="10%">'.$sale[ 'invoice_number' ].'</td>';
|
||||
$table_data_row.='<td width="3%"><input type="checkbox" id="sale_"' . $sale['sale_id'] . ' value="' . $sale['sale_id']. '" /></td>';
|
||||
$table_data_row.='<td width="15%">'.'POS ' . $sale['sale_id'] . '</td>';
|
||||
$table_data_row.='<td width="17%">'.date( $CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($sale['sale_time']) ).'</td>';
|
||||
$table_data_row.='<td width="23%">'.character_limiter( $sale['customer_name'], 25).'</td>';
|
||||
$table_data_row.='<td width="10%">'.to_currency( $sale['amount_tendered'] ).'</td>';
|
||||
$table_data_row.='<td width="10%">'.to_currency( $sale['amount_due'] ).'</td>';
|
||||
$table_data_row.='<td width="10%">'.to_currency( $sale['change_due'] ).'</td>';
|
||||
$table_data_row.='<td width="20%">'.$sale['payment_type'].'</td>';
|
||||
$table_data_row.='<td width="10%">'.$sale['invoice_number'].'</td>';
|
||||
$table_data_row.='<td width="12%">';
|
||||
$table_data_row.=anchor($controller_name."/edit/" . $sale[ 'sale_id' ] . "/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update')));
|
||||
$table_data_row.=anchor($controller_name."/edit/" . $sale['sale_id'] . "/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update')));
|
||||
$table_data_row.=' ';
|
||||
$table_data_row.='<a href="'.site_url($controller_name. "/receipt/" . $sale[ 'sale_id' ]) . '">' . $CI->lang->line('sales_show_receipt') . '</a>';
|
||||
$table_data_row.='<a href="'.site_url($controller_name. "/receipt/" . $sale['sale_id']) . '">' . $CI->lang->line('sales_show_receipt') . '</a>';
|
||||
$table_data_row.=' ';
|
||||
$table_data_row.='<a href="'.site_url($controller_name. "/invoice/" . $sale[ 'sale_id' ]) . '">' . $CI->lang->line('sales_show_invoice') . '</a>';
|
||||
$table_data_row.='<a href="'.site_url($controller_name. "/invoice/" . $sale['sale_id']) . '">' . $CI->lang->line('sales_show_invoice') . '</a>';
|
||||
$table_data_row.='</td>';
|
||||
$table_data_row.='</tr>';
|
||||
|
||||
@@ -119,11 +94,11 @@ function get_sales_manage_sale_data_row($sale, $payments, $controller)
|
||||
/*
|
||||
Get the sales payments summary
|
||||
*/
|
||||
function get_sales_manage_payments_summary($payments_summary, $controller)
|
||||
function get_sales_manage_payments_summary($payments_summary, $sales, $controller)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$table='<table class="tablesorter" id="sortable_table">';
|
||||
|
||||
|
||||
$table.='<thead><tr>';
|
||||
$table.='<th> </th>';
|
||||
foreach($payments_summary as $key=>$summary)
|
||||
@@ -134,7 +109,19 @@ function get_sales_manage_payments_summary($payments_summary, $controller)
|
||||
$table.='<th>'.$CI->lang->line('sales_total').'</th>';
|
||||
foreach($payments_summary as $key=>$summary)
|
||||
{
|
||||
$table.='<td>'.to_currency( $summary['payment_amount'] ).'</td>';
|
||||
$amount = $summary['payment_amount'];
|
||||
|
||||
// WARNING: the strong assumption here is that if a change is due it was a cash transaction always
|
||||
// therefore we remove from the total cash amount any change due
|
||||
if( $summary['payment_type'] == $CI->lang->line('sales_cash') )
|
||||
{
|
||||
foreach($sales as $key=>$sale)
|
||||
{
|
||||
$amount -= $sale['change_due'];
|
||||
}
|
||||
}
|
||||
|
||||
$table.='<td>'.to_currency( $amount ).'</td>';
|
||||
}
|
||||
$table.='</tr></tbody></table>';
|
||||
|
||||
@@ -267,7 +254,7 @@ function get_supplier_manage_table_data_rows($suppliers,$controller)
|
||||
|
||||
if($suppliers->num_rows()==0)
|
||||
{
|
||||
$table_data_rows.="<tr><td colspan='8'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('common_no_persons_to_display')."</div></tr></tr>";
|
||||
$table_data_rows.="<tr><td colspan='8'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('common_no_persons_to_display')."</div></td></tr>";
|
||||
}
|
||||
|
||||
return $table_data_rows;
|
||||
@@ -343,7 +330,7 @@ function get_items_manage_table_data_rows($items,$controller)
|
||||
|
||||
if($items->num_rows()==0)
|
||||
{
|
||||
$table_data_rows.="<tr><td colspan='12'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('items_no_items_to_display')."</div></tr></tr>";
|
||||
$table_data_rows.="<tr><td colspan='12'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('items_no_items_to_display')."</div></td></tr>";
|
||||
}
|
||||
|
||||
return $table_data_rows;
|
||||
@@ -438,7 +425,7 @@ function get_giftcards_manage_table_data_rows( $giftcards, $controller )
|
||||
|
||||
if($giftcards->num_rows()==0)
|
||||
{
|
||||
$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('giftcards_no_giftcards_to_display')."</div></tr></tr>";
|
||||
$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('giftcards_no_giftcards_to_display')."</div></td></tr>";
|
||||
}
|
||||
|
||||
return $table_data_rows;
|
||||
@@ -505,7 +492,7 @@ function get_item_kits_manage_table_data_rows( $item_kits, $controller )
|
||||
|
||||
if($item_kits->num_rows()==0)
|
||||
{
|
||||
$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('item_kits_no_item_kits_to_display')."</div></tr></tr>";
|
||||
$table_data_rows.="<tr><td colspan='11'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('item_kits_no_item_kits_to_display')."</div></td></tr>";
|
||||
}
|
||||
|
||||
return $table_data_rows;
|
||||
|
||||
@@ -23,11 +23,11 @@ class Sale extends CI_Model
|
||||
}
|
||||
|
||||
// get the sales data for the takings table
|
||||
function get_data($inputs)
|
||||
public function get_data($inputs)
|
||||
{
|
||||
$this->db->select('sale_id, sale_date, sale_time, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name,
|
||||
CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit,
|
||||
sale_payment_amount as amount_tendered, total as amount_due, (sale_payment_amount - total) as change_due, invoice_number', false);
|
||||
sale_payment_amount as amount_tendered, total as amount_due, (sale_payment_amount - total) as change_due, payment_type, invoice_number', false);
|
||||
$this->db->from('sales_items_temp');
|
||||
$this->db->join('people as employee', 'sales_items_temp.employee_id = employee.person_id');
|
||||
$this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left');
|
||||
@@ -61,14 +61,7 @@ class Sale extends CI_Model
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['summary'] = $this->db->get()->result_array();
|
||||
$data['details'] = array();
|
||||
$data['payments'] = array();
|
||||
|
||||
foreach($data['summary'] as $key=>$value)
|
||||
{
|
||||
$data['payments'][$key] = $this->get_sale_payments($value['sale_id'])->result_array();
|
||||
}
|
||||
$data['sales'] = $this->db->get()->result_array();
|
||||
|
||||
// get payment summary
|
||||
$this->db->select('sales_payments.payment_type, count(*) as count, sum(payment_amount) as payment_amount', false);
|
||||
@@ -92,7 +85,7 @@ class Sale extends CI_Model
|
||||
|
||||
$this->db->group_by("payment_type");
|
||||
|
||||
$data['payments_summary'] = $this->db->get()->result_array();
|
||||
$data['payments'] = $this->db->get()->result_array();
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -117,7 +110,7 @@ class Sale extends CI_Model
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
function get_invoice_number_for_year($year='', $start_from = 0)
|
||||
function get_invoice_number_for_year($year = '', $start_from = 0)
|
||||
{
|
||||
$year = $year == '' ? date('Y') : $year;
|
||||
$this->db->select("COUNT( 1 ) AS invoice_number_year", FALSE);
|
||||
@@ -369,7 +362,7 @@ class Sale extends CI_Model
|
||||
INNER JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales').'.sale_id'."
|
||||
INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('sales_items').'.item_id='.$this->db->dbprefix('items').'.item_id'."
|
||||
INNER JOIN (SELECT sale_id, SUM(payment_amount) AS sale_payment_amount,
|
||||
GROUP_CONCAT(payment_type SEPARATOR ', ') AS payment_type FROM " .$this->db->dbprefix('sales_payments') . " GROUP BY sale_id) AS payments
|
||||
GROUP_CONCAT(concat(payment_type,' ',payment_amount) SEPARATOR ', ') AS payment_type FROM " .$this->db->dbprefix('sales_payments') . " GROUP BY sale_id) AS payments
|
||||
ON " . $this->db->dbprefix('sales_items') . '.sale_id'. "=" . "payments.sale_id
|
||||
LEFT OUTER JOIN ".$this->db->dbprefix('suppliers')." ON ".$this->db->dbprefix('items').'.supplier_id='.$this->db->dbprefix('suppliers').'.person_id'."
|
||||
LEFT OUTER JOIN ".$this->db->dbprefix('sales_items_taxes')." ON "
|
||||
|
||||
@@ -78,7 +78,7 @@ if(count($cart)==0)
|
||||
?>
|
||||
<tr><td colspan='8'>
|
||||
<div class='warning_message' style='padding:7px;'><?php echo $this->lang->line('sales_no_items_in_cart'); ?></div>
|
||||
</tr></tr>
|
||||
</td></tr>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
|
||||
@@ -40,7 +40,6 @@ if($export_excel == 1){
|
||||
|
||||
<tbody>
|
||||
<?php foreach ($details_data[$key] as $row2) { ?>
|
||||
|
||||
<tr>
|
||||
<?php foreach ($row2 as $cell) { ?>
|
||||
<td><?php echo $cell; ?></td>
|
||||
@@ -49,7 +48,6 @@ if($export_excel == 1){
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
@@ -166,7 +166,7 @@ function init_table_sorting()
|
||||
</div>
|
||||
|
||||
<div id="table_summary">
|
||||
<?php echo $payments_summary_data; ?>
|
||||
<?php echo $payments_summary; ?>
|
||||
</div>
|
||||
|
||||
<div id="feedback_bar"></div>
|
||||
|
||||
Reference in new issue
Block a user