Welcome Guest, Not a member yet? Register   Sign In
Is this an efficeient way ti use models?
#1

[eluser]Solarpitch[/eluser]
I'm just wondering if this is best practice or if there is a better way of achieving this. I have a report model that calculates some reports from a sales table. For example, it will calculate the total amount of cash, mastercard, visa, lazer sales etc.

This is what I have...

Code:
function cash_sales()
{  
$this->client->select_sum('price', 'cash_total');
$query = $this->client->get_where('sales', array('type' => 'cash');
$row = $query->row();
return round($row->cash_total, 2);
}

function visa_sales()
{  
$this->client->select_sum('visa', 'visa_total');
$query = $this->client->get_where('sales', array('type' => 'cash');
$row = $query->row();
return round($row->visa_total, 2);
}

function mcard_sales()
{  
$this->client->select_sum('mcard', 'mcard_total');
$query = $this->client->get_where('sales', array('type' => 'cash');
$row = $query->row();
return round($row->mcard_total, 2);
}

.... and so on for the rest

Is there a better way to achieve this or is it pretty much the same. I was worried about page loading due to all the calculations. I would have around 25 functions like this in the report model to be displayed on one page.




Theme © iAndrew 2016 - Forum software by © MyBB