wasteBook.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. class wasteBook extends DooModel {
  4. public $wid;
  5. public $expensesType;
  6. public $accountType;
  7. public $accountMsg;
  8. public $accountPrice;
  9. public $accountBank;
  10. public $category;
  11. public $cid;
  12. public $name;
  13. public $sid;
  14. public $dailyIncomeType;
  15. public $dailyExpenditureType;
  16. public $inputDate;
  17. public $dataID;
  18. public $accountPriceShow;
  19. public $_table = 'CLD_wasteBook';
  20. public $_primarykey = 'wid';
  21. public $_fields = array (
  22. 'wid',
  23. 'expensesType',
  24. 'accountType',
  25. 'accountMsg',
  26. 'accountPrice',
  27. 'accountBank',
  28. 'category',
  29. 'name',
  30. 'cid',
  31. 'sid',
  32. 'dailyIncomeType',
  33. 'dailyExpenditureType',
  34. 'inputDate' ,
  35. 'dataID',
  36. 'accountPriceShow',
  37. );
  38. //
  39. function getWasteBookByStatisticsYear($year=''){
  40. if (empty($year))
  41. $year=date ( "Y" );
  42. $list = $this->find ( array (
  43. 'select' => 'sum(accountPrice) as accountPrice ',
  44. 'where' => " Year(inputDate) <" . $year ,
  45. //'groupby' => 'Month(inputDate)',
  46. 'asArray' => TRUE
  47. ) );
  48. return $list;
  49. }
  50. function getWasteBookByStatisticsDay($year='',$month=''){
  51. $day=cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
  52. if (empty($year)){
  53. $year=date ( "Y" );
  54. $month=date("m");
  55. }
  56. $list = $this->find ( array (
  57. 'select' => 'sum(accountPrice) as accountPrice ',
  58. 'where' => " inputDate <'" . $year."-".$month."-1'" ,
  59. //'groupby' => 'Month(inputDate)',
  60. 'asArray' => TRUE
  61. ) );
  62. return $list;
  63. }
  64. function getWasteBookByStatistics($expensesType=1,$year=''){
  65. if (empty($year))
  66. $year=date ( "Y" );
  67. $list = $this->find ( array (
  68. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow ,Month(inputDate) as month,expensesType,Year(inputDate)',
  69. 'where' => " Year(inputDate) =" . $year . " and expensesType=" . $expensesType,
  70. 'groupby' => 'Month(inputDate),expensesType',
  71. 'asArray' => TRUE
  72. ) );
  73. //print_r($list);
  74. return $list;
  75. }
  76. public function getStatisticsByDay($expensesType=1,$year= '',$month='') {
  77. $list = $this->find ( array (
  78. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow,date_format(inputDate,"%Y-%m") ,Month(inputDate) as month,expensesType,Year(inputDate),Day(inputDate) as day',
  79. 'where' => " date_format(inputDate,'%Y-%m')=date_format('".$year."-".$month."-1','%Y-%m') and expensesType=" . $expensesType,
  80. 'groupby' => 'Day(inputDate),expensesType',
  81. 'asArray' => TRUE
  82. ) );
  83. // $list = $this->find ( array (
  84. // 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,expensesType,Year(date),Day(date) as day',
  85. // 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType.$con,
  86. // 'groupby' => $groupby,
  87. // 'asArray' => TRUE
  88. // ) );
  89. return $list;
  90. }
  91. function getAccountBookByExpensesType($limit=4,$expensesType=1,$con=''){
  92. $where= array (
  93. 'where' => "expensesType=".$expensesType.$con,
  94. 'desc' => 'wid',
  95. 'asArray' => TRUE
  96. );
  97. if($limit!=0){
  98. $where += array (
  99. 'limit' => $limit
  100. );
  101. }
  102. $list = $this->find ( $where );
  103. Doo::loadModel ( "accountBook" );
  104. $accountBook = new accountBook ();
  105. Doo::loadModel ( 'receipt' );
  106. $receipt = new receipt ();
  107. Doo::loadModel ( 'invoiceReceivables' );
  108. $invoiceReceivables = new invoiceReceivables ();
  109. Doo::loadModel ( 'invoice' );
  110. $invoice = new invoice ();
  111. Doo::loadClass ( 'XDeode' );
  112. $XDeode = new XDeode ( 5 );
  113. foreach ($list as $key=>$value){
  114. $list[$key]['widKey']=$XDeode->encode ( $value ['wid'] );
  115. $list[$key]['accountTypeKey']=$XDeode->encode ( $value ['accountType'] );
  116. $list[$key]['accountBankMsg']='';
  117. if($value['accountBank']=='CGBDeposit'){
  118. $list[$key]['accountBankMsg']='纵横广发';
  119. }elseif($value['accountBank']=='ICBCDeposit'){
  120. $list[$key]['accountBankMsg']='纵横工行';
  121. }elseif($value['accountBank']=='HUADeposit'){
  122. $list[$key]['accountBankMsg']='华润银行';
  123. }elseif($value['accountBank']=='PersonalDeposit'){
  124. $list[$key]['accountBankMsg']='个人广发';
  125. }
  126. $list[$key]['data']=array();
  127. if ($value['accountType']==5||$value['accountType']==6||$value['accountType']==9||$value['accountType']==10){
  128. $list[$key]['data']=$accountBook->getAccountBookByAid($value['dataID']);
  129. }elseif($value['accountType']==7||$value['accountType']==11){
  130. $list[$key]['data']=$invoiceReceivables->getInvoiceReceivablesByIrid($value['dataID']);
  131. }elseif($value['accountType']==8){
  132. $list[$key]['data']= $invoice->getInvoiceByIid ( $value['dataID'] );
  133. }elseif($value['accountType']==1||$value['accountType']==2||$value['accountType']==3||$value['accountType']==4||$value['accountType']==12){
  134. $list[$key]['data']=$receipt->getReceiptByRid($value['dataID']);
  135. }
  136. }
  137. //print_r($list);
  138. return $list;
  139. }
  140. /**
  141. */
  142. function getAccountBookByLimit($limit = 3) {
  143. $sql = 'select *
  144. from ' . $this->_table . '
  145. ORDER BY aid desc limit ' . $limit;
  146. $query = Doo::db ()->query ( $sql );
  147. $list = $query->fetchAll ();
  148. Doo::loadClass ( 'XDeode' );
  149. $XDeode = new XDeode ( 5 );
  150. foreach ( $list as $key => $value ) {
  151. $list [$key] ['aidKey'] = $XDeode->encode ( $value ['aid'] );
  152. }
  153. return $list;
  154. }
  155. /**
  156. *
  157. * @param number $limit
  158. * @param string $con
  159. * @param string $desc
  160. * @return boolean
  161. */
  162. function getAccountBookBySql($limit = 0, $con = "", $desc = 'desc') {
  163. // $listCount = $this->count ( array (
  164. // 'where' => $con,
  165. // 'asArray' => TRUE
  166. // ) );
  167. $list = $this->find ( array (
  168. 'where' => '1 ' . $con,
  169. 'limit' => $limit,
  170. $desc => 'aid',
  171. 'asArray' => TRUE
  172. ) ); // echo $con;
  173. Doo::loadClass ( 'XDeode' );
  174. $XDeode = new XDeode ( 5 );
  175. foreach ( $list as $key => $value ) {
  176. // $list [$key] ['count'] = $listCount;
  177. $list [$key] ['aidKey'] = $XDeode->encode ( $value ['aid'] );
  178. }
  179. return $list;
  180. }
  181. /**
  182. *
  183. * @param number $expensesType
  184. * @param number $accountType
  185. * @param number $dataID
  186. * @param string $select
  187. * @return unknown|string[]
  188. */
  189. function getAccountBookByAid($expensesType=1,$accountType=1,$dataID = 0, $select = "") {
  190. Doo::loadClass ( 'XDeode' );
  191. $XDeode = new XDeode ( 5 );
  192. if (! is_numeric ( $dataID ))
  193. $rid=$XDeode->decode( $dataID );
  194. $condition = array (
  195. 'where' => "dataID=" . $dataID.' and expensesType='.$expensesType.' and accountType='.$accountType,
  196. 'asArray' => TRUE
  197. );
  198. if (! empty ( $select ))
  199. $condition += array (
  200. 'select' => $select
  201. );
  202. $Detail = array ();
  203. if (is_numeric ( $dataID ) && ! empty ( $dataID ))
  204. $Detail = $this->getOne ( $condition );
  205. if (empty ( $Detail ))
  206. return $Detail;
  207. $Detail ['widKey'] = $XDeode->encode ( $Detail ['wid'] );
  208. return $Detail;
  209. }
  210. /**
  211. *
  212. */
  213. function getAccountBookByWid(){
  214. }
  215. /**
  216. * 统计存款部分
  217. */
  218. function getWasteBookStatisticsByIncome(){
  219. //and dailyIncomeType!=7
  220. $list['incomeStatistics'] = $this->find ( array (
  221. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyIncomeType',
  222. 'where' => " expensesType=1 and (accountType =6 or accountType =7 or accountType=8 or accountType =1 or accountType =2 or accountType=3 or accountType=4 or accountType=12 ) ",
  223. 'groupby' => 'accountBank',
  224. 'asArray' => TRUE
  225. ) );
  226. $list['expenditureStatistics'] = $this->find ( array (
  227. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType',
  228. 'where' => " expensesType=2 and (accountType =1 or accountType =2 or accountType=3 or accountType=4 or accountType=5 or accountType=11 or accountType=12) ",
  229. 'groupby' => 'accountBank',
  230. 'asArray' => TRUE
  231. ) );
  232. //活期
  233. $list['currentStatistics'] = $this->find ( array (
  234. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType',
  235. 'where' => " accountType =10 ",
  236. 'groupby' => 'accountBank',
  237. 'asArray' => TRUE
  238. ) );
  239. //固期
  240. $list['fixedStatistics'] = $this->find ( array (
  241. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType',
  242. 'where' => " accountType =9 ",
  243. 'groupby' => 'accountBank',
  244. 'asArray' => TRUE
  245. ) );
  246. //月份总计
  247. $list['incomeReport'] = $this->find ( array (
  248. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow,date_format(inputDate,"%Y-%m") as inputDate,expensesType',
  249. 'where' => " YEAR(inputDate)= YEAR( NOW( ) ) and expensesType=1",
  250. 'groupby' => 'date_format(inputDate,"%Y-%m"),expensesType',
  251. 'asArray' => TRUE
  252. ) );
  253. $list['expenditureReport'] = $this->find ( array (
  254. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow,date_format(inputDate,"%Y-%m") as inputDate,expensesType',
  255. 'where' => " YEAR(inputDate)= YEAR( NOW( ) ) and expensesType=2",
  256. 'groupby' => 'date_format(inputDate,"%Y-%m"),expensesType',
  257. 'asArray' => TRUE
  258. ) );
  259. // //合计
  260. // $list['total'] = $this->find ( array (
  261. // 'select' => 'sum(accountPrice) as accountPrice',
  262. // //'where' => " accountType =9 ",
  263. // //'groupby' => 'accountBank',
  264. // 'asArray' => TRUE
  265. // ) );
  266. return $list;
  267. }
  268. /**
  269. * 插入数据
  270. * @param array $item
  271. * @return number
  272. */
  273. function setAccountBookStatistics($item=array()){
  274. $lid = 0;
  275. if (is_array ( $item ) && ! empty ( $item )) {
  276. foreach ( $item as $key => $value ) {
  277. $this->$key = $value;
  278. }
  279. $lid = $this->insert ();
  280. }
  281. return $lid;
  282. }
  283. function getWateBookByAD($accountType='',$dataID=''){
  284. $detail=$this->getOne(array (
  285. 'where' => "accountType=".$accountType.' and dataID='.$dataID,
  286. 'asArray' => TRUE
  287. ));
  288. return $detail;
  289. }
  290. }
  291. ?>