finaModel.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. class finaClassModel extends Model
  3. {
  4. public function initModel()
  5. {
  6. $this->settable('fininfom');
  7. }
  8. //统计我未还款
  9. public function totaljie($uid, $id=0)
  10. {
  11. $where = 'and id<>'.$id.'';
  12. $to1 = floatval($this->getmou('sum(money)money',"`uid`='$uid' and `type`=2 and `status`=1"));
  13. $to2 = floatval($this->getmou('sum(money)money',"`uid`='$uid' and `type`=3 and `status`<>5 $where"));
  14. $to = $to1-$to2;
  15. return $to;
  16. }
  17. public function getjkdwhere()
  18. {
  19. return '(select `uid` from `[Q]fininfom` where `type`=2 and `status`=1)';
  20. }
  21. //统计
  22. public function totalfkd($rows, $uids)
  23. {
  24. $carr = $barr = array();
  25. //借款
  26. $hkto = $this->db->getall("select uid,sum(money)money from `[Q]fininfom` where `uid` in($uids) and `type`=2 and `status`=1 group by `uid`");
  27. foreach($hkto as $k=>$rs)$carr[$rs['uid']] = $rs['money'];
  28. //还的
  29. $hkto = $this->db->getall("select uid,sum(money)money from `[Q]fininfom` where `uid` in($uids) and `type`=3 and `status`=1 group by `uid`");
  30. foreach($hkto as $k=>$rs)$barr[$rs['uid']] = $rs['money'];
  31. foreach($rows as $k=>$rs){
  32. $uid = $rs['id'];
  33. $moneyjk = floatval(arrvalue($carr, $uid, 0));
  34. $moneyhk = floatval(arrvalue($barr, $uid, 0));
  35. $moneyhx = $moneyjk - $moneyhk;
  36. if($moneyjk==0)$moneyjk='';
  37. if($moneyhk==0)$moneyhk='';
  38. if($moneyhx==0)$moneyhx='';
  39. $rows[$k]['moneyjk'] = $moneyjk;
  40. $rows[$k]['moneyhk'] = $moneyhk;
  41. $rows[$k]['moneyhx'] = $moneyhx;
  42. }
  43. return $rows;
  44. }
  45. //获取当前账套
  46. public function getzhangtao($lx=0)
  47. {
  48. $dt = $this->rock->date;
  49. $where= m('admin')->getcompanywhere(3);
  50. if($lx==0)$where.=" and `startdt`<='$dt' and `enddt`>='$dt'";
  51. $rows = m('finzhang')->getall("status=1 ".$where."",'*','sort, startdt desc');
  52. $arr = array();
  53. foreach($rows as $k=>$rs){
  54. $sarr = array(
  55. 'value' => $rs['id'],
  56. 'name' => $rs['name'],
  57. 'subname' => $rs['startdt'].'→'.$rs['enddt'],
  58. );
  59. if($lx==2){
  60. unset($sarr['subname']);
  61. $sarr['name'].='('.$rs['startdt'].')';
  62. }
  63. $arr[] = $sarr;
  64. }
  65. return $arr;
  66. }
  67. //获取财务帐号
  68. public function getaccount($zhid='')
  69. {
  70. if(!$zhid)$zhid='0';
  71. $where= 'and `zhangid`='.$zhid.'';
  72. $rows = m('finount')->getall("status=1 ".$where."",'*','sort');
  73. $arr = array();
  74. foreach($rows as $k=>$rs){
  75. $name = $rs['name'];
  76. if(!isempt($rs['banknum']))$name.='(**'.mb_substr($rs['banknum'],-4).')';
  77. $arr[] = array(
  78. 'value' => $rs['id'],
  79. 'name' => $name,
  80. );
  81. }
  82. return $arr;
  83. }
  84. //更新财务帐号金额
  85. public function updatemoney($accid='')
  86. {
  87. $where= '';
  88. if(!isempt($accid))$where=' and `accountid`='.$accid.'';
  89. $rows = $this->db->getall('SELECT accountid,SUM(money)money FROM `[Q]finjibook` where `status`=1 '.$where.' group by accountid');
  90. $db = m('finount');
  91. $ids= '0';
  92. foreach($rows as $k=>$rs){
  93. $db->update('`money`='.$rs['money'].'', $rs['accountid']);
  94. $ids.=','.$rs['accountid'].'';
  95. }
  96. if(isempt($accid))$db->update('`money`=0', '`id` not in('.$ids.')');
  97. }
  98. //读取科目数据
  99. private $datarows = array();
  100. public function kemudata()
  101. {
  102. $data = m('finkemu')->getall('`status`=1','*','`sort`');
  103. $this->kemudatas($data, 0,'');
  104. return $this->datarows;
  105. }
  106. private function kemudatas($data,$pid,$nae)
  107. {
  108. foreach($data as $k=>$rs){
  109. if($pid==$rs['pid']){
  110. $this->datarows[] = array(
  111. 'value' => $rs['id'],
  112. 'name' => ''.$rs['num'].' '.$nae.''.$rs['name'].''
  113. );
  114. $this->kemudatas($data, $rs['id'],$nae.$rs['name'].'-');
  115. }
  116. }
  117. }
  118. }
粤ICP备19079148号