我正在尝试使用codeigniter开发分类帐帐户,现在我发现很难正确地加入表格来制作视图。交易记录在表transaction, transaction_dr, transaction_cr
中。这是我的代码;
function displayLedger() //controller
{
$office_code =$this->office_code;
$data['page_info']="Establishment A/c";
$data['office_code'] = $this->office_code;
$acc_id = 3; // 'acc_id' for 'Establishment A/c'
$data['ledger_type']=$this->lams_finance_model->get_ledger_dr($acc_id);
$this->load->view('test/ledger', $data);
}
型号:
function get_ledger_dr($acc_id)
{ $this->db->select('*');
$this->db->from('transaction_cr');
$this->db->join('transaction_dr', ' transaction_dr.trans_id_dr = transaction_cr.trans_id_cr ');
$this->db->join('transaction', 'transaction.trans_id = transaction_cr.trans_id_cr ');
$this->db->join('trans_account', 'trans_account.acc_id = transaction_dr.dr_acc_id ');
$this->db->where('transaction_cr.cr_acc_id', $acc_id);
$this->db->order_by('transaction.trans_date','ASC');
$query = $this->db->get();
return $query->result();
}
表格结构如下:
CREATE TABLE IF NOT EXISTS `transaction` (
`trans_id` int(11) NOT NULL AUTO_INCREMENT,
`office_code` varchar(5) NOT NULL,
`trans_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`trans_mode` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'specify whether mode is Cheque or DD',
`trans_type` char(1) NOT NULL DEFAULT 'P' COMMENT 'Specify type of transaction, if Receipt or Payment',
`trans_type_Ref` varchar(8) NOT NULL COMMENT 'specify ''trtype_id'' from table ''transaction_type'' based on the type of transaction',
`trans_narration` text NOT NULL,
`entry_by` tinyint(5) DEFAULT NULL,
`auth_by` tinyint(5) DEFAULT NULL,
PRIMARY KEY (`trans_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `transaction_cr` (
`trans_id_cr` int(11) NOT NULL,
`cr_slno` tinyint(2) DEFAULT '1',
`cr_acc_id` tinyint(5) NOT NULL,
`cr_amt` float NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `transaction_dr` (
`trans_id_dr` int(11) NOT NULL,
`dr_slno` tinyint(2) NOT NULL DEFAULT '1',
`dr_acc_id` tinyint(5) NOT NULL,
`dr_amt` float NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
有人可以帮助我获得合适的分类帐加入吗?提前谢谢。