wasteBook.php 9.9 KB

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