ติด Fatal error: Call to a member function result_array() on a non-object in C:\AppServ\www\minimart\application\models\reports\detailed_receives.php on line 28
ผมเอาโปรแกรมสำเร็จรูปมาปรับปรุงนะครับ คือ PHP Point Of Sale
<?php
abstract class Report extends Model
{
function __construct()
{
parent::Model();
//Make sure the report is not cached by the browser
$this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
$this->output->set_header("Pragma: no-cache");
//Create our temp table to work with the data in our report
$this->Sale->create_sales_items_temp_table();
//Create our temp table to work with the data in our report // jeng add
$this->Receive->create_receives_items_temp_table(); // jeng add
}
//Returns the column names used for the report
public abstract function getDataColumns();
//Returns all the data to be populated into the report
public abstract function getData(array $inputs);
//Returns key=>value pairing of summary data for the report
public abstract function getSummaryData(array $inputs);
}
?>
<?php
class Receive extends Model
{
public function get_info($receive_id)
{
$this->db->from('receives');
$this->db->where('receive_id',$receive_id);
return $this->db->get();
}
function exists($receive_id)
{
$this->db->from('receives');
$this->db->where('receive_id',$receive_id);
$query = $this->db->get();
return ($query->num_rows()==1);
}
function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receive_id=false)
{
if(count($items)==0)
return -1;
$receives_data = array(
'supplier_id'=> $this->Customer->exists($supplier_id) ? $supplier_id : null,
'employee_id'=>$employee_id,
'payment_type'=>$payment_type,
'comment'=>$comment
);
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
$this->db->insert('receives',$receives_data);
$receive_id = $this->db->insert_id();
foreach($items as $item_id=>$item)
{
$cur_item_info = $this->Item->get_info($item_id);
$receives_items_data = array
(
'receive_id'=>$receive_id,
'item_id'=>$item_id,
'quantity_purchased'=>$item['quantity'],
'discount_percent'=>$item['discount'],
'item_cost_price' => $cur_item_info->cost_price,
'item_unit_price'=>$item['price']
);
$this->db->insert('receives_items',$receives_items_data);
//Update stock quantity
$item_data = array('quantity'=>$cur_item_info->quantity + $item['quantity']);
$this->Item->save($item_data,$item_id);
foreach($this->Item_taxes->get_info($item_id) as $row)
{
$this->db->insert('receives_items_taxes', array(
'receive_id' =>$receive_id,
'item_id' =>$item_id,
'name' =>$row['name'],
'percent' =>$row['percent']
));
}
}
$this->db->trans_complete();
return $receive_id;
}
function get_receive_items($receive_id)
{
$this->db->from('receives_items');
$this->db->where('receive_id',$receive_id);
return $this->db->get();
}
function get_supplier($receive_id)
{
$this->db->from('receives');
$this->db->where('receive_id',$receive_id);
return $this->Customer->get_info($this->db->get()->row()->supplier_id);
}
//We create a temp table that allows us to do easy report/receives queries
public function create_receives_items_temp_table()
{
$this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('receives_items_temp')."
(SELECT date(receive_time) as receive_date, receive_id, comment,payment_type, customer_id, employee_id, item_id, supplier_id, quantity_purchased, item_cost_price, item_unit_price, SUM(percent) as item_tax_percent,
discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal,
ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*(1+(SUM(percent)/100)),2) as total,
ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*(SUM(percent)/100),2) as tax,
(item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) - (item_cost_price*quantity_purchased) as profit
FROM ".$this->db->dbprefix('receives_items')."
INNER JOIN ".$this->db->dbprefix('receives')." USING (receive_id)
INNER JOIN ".$this->db->dbprefix('items')." USING (item_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('receives_items_taxes')." USING (receive_id, item_id)
GROUP BY receive_id, item_id)");
//Update null item_tax_percents to be 0 instead of null
$this->db->where('item_tax_percent IS NULL');
$this->db->update('receives_items_temp', array('item_tax_percent' => 0));
//Update null tax to be 0 instead of null
$this->db->where('tax IS NULL');
$this->db->update('receives_items_temp', array('tax' => 0));
//Update null subtotals to be equal to the total as these don't have tax
$this->db->query('UPDATE '.$this->db->dbprefix('receives_items_temp'). ' SET total=subtotal WHERE total IS NULL');
}
}
?>
ตอนเพิ่มบันทึกก็ทำได้นะครับ แต่ติดตรงออกรายงานครับ ติด error ที่ว่า
Fatal error: Call to a member function result_array() on a non-object in C:\AppServ\www\minimart\application\models\reports\detailed_receives.php on line 28
$this->db->select('receive_date, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit'); $this->db->from('receives_items_temp'); $this->db->group_by('receive_date'); $this->db->having('receive_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); $this->db->order_by('receive_date');
ติด Fatal error: Call to a member function result_array() on a non-object in C:\AppServ\www\minimart\application\models\reports\detailed_receives.php on line 28