wasteBook.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. class wasteBook extends DooModel {
  4. public $wid;
  5. public $expensesType;
  6. public $accountType;
  7. public $dailyType;
  8. public $operatingBankType;
  9. public $depositMethod;
  10. public $accountMsg;
  11. public $accountPrice;
  12. public $accountBank;
  13. public $category;
  14. public $cid;
  15. public $name;
  16. public $sid;
  17. public $dailyIncomeType;
  18. public $dailyExpenditureType;
  19. public $inputDate;
  20. public $dataID;
  21. public $remarks;
  22. public $accountPriceShow;
  23. public $createAt;
  24. public $updateAt;
  25. public $synPaymentDate;
  26. public $_table = 'CLD_wasteBook';
  27. public $_primarykey = 'wid';
  28. public $_fields = array (
  29. 'wid',
  30. 'expensesType',
  31. 'accountType',
  32. 'dailyType',
  33. 'operatingBankType',
  34. 'depositMethod',
  35. 'accountMsg',
  36. 'accountPrice',
  37. 'accountBank',
  38. 'category',
  39. 'name',
  40. 'cid',
  41. 'sid',
  42. 'dailyIncomeType',
  43. 'dailyExpenditureType',
  44. 'inputDate' ,
  45. 'dataID',
  46. 'remarks',
  47. 'accountPriceShow',
  48. 'createAt',
  49. 'updateAt',
  50. 'synPaymentDate',
  51. );
  52. //
  53. function getWasteBookByStatisticsYear($year=''){
  54. if (empty($year))
  55. $year=date ( "Y" );
  56. $list = $this->find ( array (
  57. 'select' => 'sum(accountPrice) as accountPrice ',
  58. 'where' => " Year(inputDate) <" . $year ,
  59. //'groupby' => 'Month(inputDate)',
  60. 'asArray' => TRUE
  61. ) );
  62. return $list;
  63. }
  64. function getWasteBookByStatisticsDay($year='',$month=''){
  65. $day=cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
  66. if (empty($year)){
  67. $year=date ( "Y" );
  68. $month=date("m");
  69. }
  70. $list = $this->find ( array (
  71. 'select' => 'sum(accountPrice) as accountPrice ',
  72. 'where' => " inputDate <'" . $year."-".$month."-1'" ,
  73. //'groupby' => 'Month(inputDate)',
  74. 'asArray' => TRUE
  75. ) );
  76. return $list;
  77. }
  78. function getWasteBookByStatistics($expensesType=1,$year=''){
  79. if (empty($year))
  80. $year=date ( "Y" );
  81. $list = $this->find ( array (
  82. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow ,Month(inputDate) as month,expensesType,Year(inputDate)',
  83. 'where' => " Year(inputDate) =" . $year . " and expensesType=" . $expensesType,
  84. 'groupby' => 'Month(inputDate),expensesType',
  85. 'asArray' => TRUE
  86. ) );
  87. //print_r($list);
  88. return $list;
  89. }
  90. function getStatisticsByMonthAll($year= '',$month=''){
  91. $startYear=$year."-".$month."-01:00.00.00";
  92. // $endYear=$data['year']."-".$data['month']."-31:23.59.59";
  93. // date_format(inputDate,'%Y-%m')<date_format('".$year."-".$month."-1','%Y-%m')
  94. $list = $this->find ( array (
  95. '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',
  96. 'where' => " inputDate< ? and (expensesType=1 or expensesType=2)",
  97. 'param' =>array($startYear),
  98. //'groupby' => 'Day(inputDate)',
  99. 'asArray' => TRUE
  100. ) );
  101. return $list;
  102. }
  103. public function getStatisticsByDay($expensesType=1,$year= '',$month='') {
  104. $list = $this->find ( array (
  105. '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',
  106. 'where' => " date_format(inputDate,'%Y-%m')=date_format('".$year."-".$month."-1','%Y-%m') and expensesType=" . $expensesType,
  107. 'groupby' => 'Day(inputDate),expensesType',
  108. 'asArray' => TRUE
  109. ) );
  110. // $list = $this->find ( array (
  111. // 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,expensesType,Year(date),Day(date) as day',
  112. // 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType.$con,
  113. // 'groupby' => $groupby,
  114. // 'asArray' => TRUE
  115. // ) );
  116. return $list;
  117. }
  118. function getAccountBookByExpensesType($limit=4,$expensesType=1,$con=''){
  119. $where= array (
  120. 'where' => "expensesType=".$expensesType.$con,
  121. 'desc' => 'inputDate',
  122. 'asArray' => TRUE
  123. );
  124. if($limit!=0){
  125. $where += array (
  126. 'limit' => $limit
  127. );
  128. }
  129. $list= $this->find ( $where );
  130. //print_r($list);
  131. Doo::loadModel ( "accountBook" );
  132. $accountBook = new accountBook ();
  133. Doo::loadModel ( 'receipt' );
  134. $receipt = new receipt ();
  135. Doo::loadModel ( 'invoiceReceivables' );
  136. $invoiceReceivables = new invoiceReceivables ();
  137. Doo::loadModel ( 'invoice' );
  138. $invoice = new invoice ();
  139. Doo::loadClass ( 'XDeode' );
  140. $XDeode = new XDeode ( 5 );
  141. //print_r($list);
  142. foreach ($list as $key=>$value){
  143. $list[$key]['widKey']=$XDeode->encode ( $value ['wid'] );
  144. $list[$key]['accountTypeKey']=$XDeode->encode ( $value ['accountType'] );
  145. $list[$key]['accountBankMsg']='';
  146. if($value['accountBank']=='CGBDeposit'){
  147. $list[$key]['accountBankMsg']='纵横广发';
  148. }elseif($value['accountBank']=='ICBCDeposit'){
  149. $list[$key]['accountBankMsg']='纵横工行';
  150. }elseif($value['accountBank']=='HUADeposit'){
  151. $list[$key]['accountBankMsg']='广发纵横知道';
  152. }elseif($value['accountBank']=='PersonalDeposit'||$value['accountBank']=='CGBPersonalDeposit'){
  153. $list[$key]['accountBankMsg']='个人广发';
  154. }
  155. $list[$key]['data']=array();
  156. if ($value['accountType']==5||$value['accountType']==6||$value['accountType']==9||$value['accountType']==10){
  157. $list[$key]['data']=$accountBook->getAccountBookByAid($value['dataID']);
  158. }elseif($value['accountType']==7||$value['accountType']==11){
  159. $ir=$invoiceReceivables->getInvoiceReceivablesByIrid($value['dataID']);
  160. $idetail=$invoice->getInvoiceByIid ( $ir['iid'] );
  161. //$ir['settlementType']=0;
  162. if(!empty($idetail)){
  163. $ir['settlementType']=$idetail['settlementType'];
  164. }
  165. $list[$key]['data']=$ir;//$invoiceReceivables->getInvoiceReceivablesByIrid($value['dataID']);
  166. }elseif($value['accountType']==8){
  167. $list[$key]['data']= $invoice->getInvoiceByIid ( $value['dataID'] );
  168. }elseif($value['accountType']==1||$value['accountType']==2||$value['accountType']==3||$value['accountType']==4||$value['accountType']==12){
  169. $list[$key]['data']=$receipt->getReceiptByRid($value['dataID']);
  170. }
  171. }
  172. //print_r($list);
  173. return $list;
  174. }
  175. /**
  176. */
  177. function getAccountBookByLimit($limit = 3) {
  178. $sql = 'select *
  179. from ' . $this->_table . '
  180. ORDER BY aid desc limit ' . $limit;
  181. $query = Doo::db ()->query ( $sql );
  182. $list = $query->fetchAll ();
  183. Doo::loadClass ( 'XDeode' );
  184. $XDeode = new XDeode ( 5 );
  185. foreach ( $list as $key => $value ) {
  186. $list [$key] ['aidKey'] = $XDeode->encode ( $value ['aid'] );
  187. }
  188. return $list;
  189. }
  190. /**
  191. *
  192. * @param number $limit
  193. * @param string $con
  194. * @param string $desc
  195. * @return boolean
  196. */
  197. function getAccountBookBySql($limit = 0, $con = "", $desc = 'desc') {
  198. // $listCount = $this->count ( array (
  199. // 'where' => $con,
  200. // 'asArray' => TRUE
  201. // ) );
  202. $list = $this->find ( array (
  203. 'where' => '1 ' . $con,
  204. 'limit' => $limit,
  205. $desc => 'aid',
  206. 'asArray' => TRUE
  207. ) ); // echo $con;
  208. Doo::loadClass ( 'XDeode' );
  209. $XDeode = new XDeode ( 5 );
  210. foreach ( $list as $key => $value ) {
  211. // $list [$key] ['count'] = $listCount;
  212. $list [$key] ['aidKey'] = $XDeode->encode ( $value ['aid'] );
  213. }
  214. return $list;
  215. }
  216. function _getAccountBankEN($receivablesBank){
  217. $accountBank = '';
  218. if ($receivablesBank == '纵横广发') {
  219. $accountBank = 'CGBDeposit';
  220. } elseif ($receivablesBank == '纵横工行') {
  221. $accountBank = 'ICBCDeposit';
  222. } elseif ($receivablesBank == '华润银行') {
  223. $accountBank = 'HUADeposit';
  224. } elseif ($receivablesBank == '个人广发') {
  225. $accountBank = 'PersonalDeposit';
  226. }
  227. return $accountBank;
  228. }
  229. /**
  230. *
  231. * @param number $expensesType
  232. * @param number $accountType
  233. * @param number $dataID
  234. * @param string $select
  235. * @return unknown|string[]
  236. */
  237. function getAccountBookByAid($expensesType=1,$accountType=1,$dataID = 0, $select = "") {
  238. Doo::loadClass ( 'XDeode' );
  239. $XDeode = new XDeode ( 5 );
  240. if (! is_numeric ( $dataID ))
  241. $rid=$XDeode->decode( $dataID );
  242. $condition = array (
  243. 'where' => "dataID=" . $dataID.' and expensesType='.$expensesType.' and accountType='.$accountType,
  244. 'asArray' => TRUE
  245. );
  246. if (! empty ( $select ))
  247. $condition += array (
  248. 'select' => $select
  249. );
  250. $Detail = array ();
  251. if (is_numeric ( $dataID ) && ! empty ( $dataID ))
  252. $Detail = $this->getOne ( $condition );
  253. if (empty ( $Detail ))
  254. return $Detail;
  255. $Detail ['widKey'] = $XDeode->encode ( $Detail ['wid'] );
  256. return $Detail;
  257. }
  258. function getReportData(){
  259. $list = $this->find ( array (
  260. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType,depositMethod,operatingBankType',
  261. 'where' => " dailyType =3 and operatingBankType=2 and (accountType =5 or accountType =6) ",
  262. 'groupby' => 'accountBank',
  263. 'asArray' => TRUE
  264. ) );
  265. return $list;
  266. }
  267. //日常收支改变后的金额汇总
  268. function getBankSavingsStatistics(){
  269. $list = $this->find ( array (
  270. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType,depositMethod,operatingBankType',
  271. 'where' => " dailyType =3 and operatingBankType=2 and (accountType =5 or accountType =6) ",
  272. 'groupby' => 'accountBank',
  273. 'asArray' => TRUE
  274. ) );
  275. return $list;
  276. }
  277. /**
  278. * 理财部分的面板总计
  279. *
  280. * @return void
  281. */
  282. function getFinancesStatistics(){
  283. //理财-理财账号
  284. $list['financesAccount'] = $this->find ( array (
  285. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType,depositMethod,operatingBankType',
  286. 'where' => " dailyType =2 and operatingBankType=1 and (accountType =5 or accountType =6) ",
  287. 'groupby' => 'accountBank,depositMethod',
  288. 'asArray' => TRUE
  289. ) );
  290. //理财-公司账号
  291. $list['companyAccount'] = $this->find ( array (
  292. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType,depositMethod,operatingBankType',
  293. 'where' => " dailyType =2 and operatingBankType=2 and (accountType =5 or accountType =6) ",
  294. 'groupby' => 'accountBank',
  295. 'asArray' => TRUE
  296. ) );
  297. return $list;
  298. }
  299. /**
  300. * 统计存款部分
  301. */
  302. function getWasteBookStatisticsByIncome(){
  303. //and dailyIncomeType!=7
  304. $list['incomeStatistics'] = $this->find ( array (
  305. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyIncomeType',
  306. 'where' => " expensesType=1 and dailyType=0 and (accountType =6 or accountType =7 or accountType=8 or accountType =1 or accountType =2 or accountType=3 or accountType=4 or accountType=12 ) ",
  307. 'groupby' => 'accountBank',
  308. 'asArray' => TRUE
  309. ) );
  310. $list['expenditureStatistics'] = $this->find ( array (
  311. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType',
  312. 'where' => " expensesType=2 and dailyType=0 and (accountType =1 or accountType =2 or accountType=3 or accountType=4 or accountType=5 or accountType=11 or accountType=12) ",
  313. 'groupby' => 'accountBank',
  314. 'asArray' => TRUE
  315. ) );
  316. //活期
  317. $list['currentStatistics'] = $this->find ( array (
  318. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType',
  319. 'where' => " accountType =10 ",
  320. 'groupby' => 'accountBank',
  321. 'asArray' => TRUE
  322. ) );
  323. //固期
  324. $list['fixedStatistics'] = $this->find ( array (
  325. 'select' => 'sum(accountPrice) as accountPrice,expensesType,accountType,accountBank,dailyExpenditureType',
  326. 'where' => " accountType =9 ",
  327. 'groupby' => 'accountBank',
  328. 'asArray' => TRUE
  329. ) );
  330. //月份总计
  331. $list['incomeReport'] = $this->find ( array (
  332. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow,date_format(inputDate,"%Y-%m") as inputDate,expensesType',
  333. 'where' => " YEAR(inputDate)= YEAR( NOW( ) ) and expensesType=1",
  334. 'groupby' => 'date_format(inputDate,"%Y-%m"),expensesType',
  335. 'asArray' => TRUE
  336. ) );
  337. $list['expenditureReport'] = $this->find ( array (
  338. 'select' => 'sum(accountPrice) as accountPrice,sum(accountPriceShow) as accountPriceShow,date_format(inputDate,"%Y-%m") as inputDate,expensesType',
  339. 'where' => " YEAR(inputDate)= YEAR( NOW( ) ) and expensesType=2",
  340. 'groupby' => 'date_format(inputDate,"%Y-%m"),expensesType',
  341. 'asArray' => TRUE
  342. ) );
  343. //print_r($list);
  344. // //合计
  345. // $list['total'] = $this->find ( array (
  346. // 'select' => 'sum(accountPrice) as accountPrice',
  347. // //'where' => " accountType =9 ",
  348. // //'groupby' => 'accountBank',
  349. // 'asArray' => TRUE
  350. // ) );
  351. return $list;
  352. }
  353. /**
  354. * 插入数据
  355. * @param array $item
  356. * @return number
  357. */
  358. function setAccountBookStatistics($item=array()){
  359. $lid = 0;
  360. if (is_array ( $item ) && ! empty ( $item )) {
  361. foreach ( $item as $key => $value ) {
  362. $this->$key = $value;
  363. }
  364. $lid = $this->insert ();
  365. }
  366. return $lid;
  367. }
  368. function getWateBookByAD($accountType='',$dataID=''){
  369. $detail=$this->getOne(array (
  370. 'where' => "accountType=".$accountType.' and dataID='.$dataID,
  371. 'asArray' => TRUE
  372. ));
  373. return $detail;
  374. }
  375. }
  376. ?>