wasteBook.php 13 KB

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