我正在尝试创建一个复式财务会计系统。我已经完成了它的数据库设计,请查看此链接以查看我的数据库图表。http://i39.tinypic.com/juhbv6.png
我已经尝试了很多来开发 mysql 查询以生成总帐,但我没有接近。我所做的只是为一个帐户创建分类帐,我必须为无限帐户创建。
我尝试过的查询如下:
$this->db->select('*');
$this->db->from('credit_side');
$this->db->join('debit_side', ' debit_side.transaction_id_dr = credit_side.transaction_id_cr ');
$this->db->join('transaction_info', 'transaction_info.transaction_id = credit_side.transaction_id_cr ');
$this->db->join('accounts', 'accounts.code = credit_side.account_code ');
$this->db->where('debit_side.account_code', '1001');
$this->db->order_by('voucher_date','ASC');
在未能编写可以为所有帐户生成分类帐的 mysql 查询后,我写下了创建总帐/T 帐户的逻辑。
现在,你能帮我查询一下mysql吗?
请在执行以下操作之前检查数据库。提前致谢 :)
从帐户中获取
accounts.name
AS AccountHeadaccounts.code
。转到表格
debit_side
,get debit_side.account_code
如果debit_side.account_code
=accounts.code
则获取credit_side.account_code
AS AccountName1(但是当我将在 php 中回显时,我想获取名称而不是代码本身)和credit_side.amount
AS Amount1,SUM(credit_side.amount)
AS TotalAmount1 来自credit_side
wheredebit_side.transaction_id_dr
=credit_side.transaction_id_cr
并且transaction_info.voucher_date
在 date1 和 date2 之间transaction_info.transaction_id
=debit_side.transaction_id_dr
完成第二步后,转到表中
credit_side
,get credit_side.account_code
如果
=credit_side.account_code
,accounts.code
则获取debit_side.account_code
AS AccountName2(但是当我将在 php 中回显时,我想获取名称而不是代码本身)和debit_side.amount
AS Amount2,SUM(debit_side.amount)
AS TotalAmount2 从debit_side
wherecredit_side.transaction_id_cr
=debit_side.transaction_id_dr
和transaction_info.voucher_date
在在 date1 和 date2 之间 WHEREtransaction_info.transaction_id
=credit_side.transaction_id_cr
现在在视图文件中,我的目标是:
<table width="200" border="0">
<tr><td colspan="5">Account Head <?echo $AccountHead ; ?> </td> </tr>
<tr>
<td>Dr.</td>
<td>amount.</td>
<td> </td>
<td>Cr</td>
<td>Amount</td>
</tr>
<tr>
<td><?echo $AccountName1 ; ?></td>
<td><?echo $Ammount1 ; ?></td>
<td></td>
<td><?echo $AccountName2 ; ?></td>
<td><?echo $Ammount2 ; ?></td>
</tr>
<tr>
<td>Total</td>
<td><?echo $TotalAmount1 ; ?></td>
<td> </td>
<td>Total </td>
<td><?echo $TotalAmount2 ; ?></td>
</tr>
</table>