wasteBook.php 9.7 KB

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