wasteBook.php 13 KB

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