receipt.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. class receipt extends DooModel {
  4. public $rid;
  5. public $accountItem;
  6. public $loanItem;
  7. public $staff;
  8. public $sum;
  9. public $date;
  10. public $pastDate;
  11. public $executeDate;
  12. public $loanDate;
  13. public $cid;
  14. public $status;
  15. public $Rtype;
  16. public $isBK;
  17. public $loanSum;
  18. public $loanRid;
  19. public $reviseDetail;
  20. public $revisePrice;
  21. public $receiptOrder;
  22. public $verify;
  23. public $verifyStaff;
  24. public $executeCopy;
  25. public $executeStaff;
  26. public $verifyBreakup;
  27. public $nowStaff;
  28. public $explanation;
  29. public $implementOpinions;
  30. public $notice;
  31. public $amount;
  32. public $remittanceName;
  33. public $bankName;
  34. public $bankNumber;
  35. public $coupletNumber;
  36. public $remittanceBankType;
  37. public $trainId;
  38. public $trainLoanRid;
  39. public $invoiceTrainId;
  40. public $paidStatus;
  41. public $_table = 'CLD_receipt';
  42. public $_primarykey = 'rid';
  43. public $_fields = array (
  44. 'aid',
  45. 'accountItem',
  46. 'staff',
  47. 'sum',
  48. 'date',
  49. 'pastDate',
  50. 'cid',
  51. 'status',
  52. 'reviseDetail',
  53. 'revisePrice',
  54. 'verify',
  55. 'verifyStaff',
  56. 'nowStaff',
  57. 'receiptOrder',
  58. 'explanation',
  59. 'notice',
  60. 'Rtype',
  61. 'loanItem',
  62. 'loanRid',
  63. 'loanSum',
  64. 'implementOpinions',
  65. 'isBK',
  66. 'executeCopy',
  67. 'executeStaff',
  68. 'verifyBreakup',
  69. 'executeDate',
  70. 'amount',
  71. 'loanDate',
  72. 'remittanceName',
  73. 'bankName',
  74. 'bankNumber',
  75. 'coupletNumber',
  76. 'remittanceBankType',
  77. 'trainId',
  78. 'trainLoanRid',
  79. 'invoiceTrainId' ,
  80. 'paidStatus'
  81. );
  82. /**
  83. * 获得培训班结算未收款
  84. */
  85. function getReceiptTrainByPaid($un=0,$limit=5){
  86. $sql = "select b.* ,a.invoiceTrainId,a.rid,a.executeDate
  87. from " . $this->_table . " as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid)
  88. where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 and paidStatus=".$un." limit ".$limit;
  89. $query = Doo::db ()->query ( $sql );
  90. $result = $query->fetchAll ();
  91. Doo::loadModel ( 'invoiceTraining' );
  92. $invoiceTraining = new invoiceTraining ();
  93. Doo::loadClass ( 'XDeode' );
  94. $XDeode = new XDeode ( 7 );
  95. Doo::loadModel ( 'RItem' );
  96. $RItem = new RItem ();
  97. Doo::loadModel ( 'RILecturer' );
  98. $RILecturer = new RILecturer ();
  99. Doo::loadModel ( 'accountItem' );
  100. $accountItem = new accountItem ();
  101. foreach ($result as $key=>$value){
  102. $result[$key]['ridKey']= $XDeode->encode ( $value ['rid'] );
  103. $result[$key]['iTrain']=$invoiceTraining->getInvoiceTrainingByItid ( $value ['invoiceTrainId'] );
  104. $result[$key]['iTrain']['receivablesAmount']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$result[$key]['iTrain']['invoiceArriveAmount']);
  105. $RItemList = $RItem->getRItemByRid ( $value ['rid'] );
  106. $RILecturerList = $RILecturer->getRILecturerByRid ( $value ['rid'] );
  107. // 支出项金额详情
  108. $expendList= $accountItem->getTrainingDetail ( $RItemList, $RILecturerList );
  109. $result[$key]['iTrain']['expendAmount']=sprintf ( "%.2f",$expendList['total']);
  110. $result[$key]['iTrain']['profit']= sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$expendList['total']);
  111. }
  112. return $result;
  113. }
  114. /**
  115. * 获得所有培训班结算
  116. */
  117. function getReceiptTrainByPaidAll($un='',$cid='',$dateSql='',$limit='0,18'){
  118. $psSql='';
  119. if(!empty($un)){
  120. $psSql=" and paidStatus=".$un." ";
  121. }
  122. $cidSql="";
  123. if(!empty($cid)){
  124. $cidSql=" and a.cid=".$cid." ";
  125. }
  126. $sql = "select b.* ,a.invoiceTrainId,a.rid
  127. from " . $this->_table . " as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid)
  128. where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 ".$psSql.$cidSql.$dateSql." limit ".$limit;
  129. $query = Doo::db ()->query ( $sql );
  130. $result = $query->fetchAll ();
  131. Doo::loadModel ( 'invoiceTraining' );
  132. $invoiceTraining = new invoiceTraining ();
  133. Doo::loadClass ( 'XDeode' );
  134. $XDeode = new XDeode ( 7 );
  135. Doo::loadModel ( 'RItem' );
  136. $RItem = new RItem ();
  137. Doo::loadModel ( 'RILecturer' );
  138. $RILecturer = new RILecturer ();
  139. Doo::loadModel ( 'accountItem' );
  140. $accountItem = new accountItem ();
  141. foreach ($result as $key=>$value){
  142. $result[$key]['ridKey']= $XDeode->encode ( $value ['rid'] );
  143. $result[$key]['iTrain']=$invoiceTraining->getInvoiceTrainingByItid ( $value ['invoiceTrainId'] );
  144. $result[$key]['iTrain']['receivablesAmount']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$result[$key]['iTrain']['invoiceArriveAmount']);
  145. $RItemList = $RItem->getRItemByRid ( $value ['rid'] );
  146. $RILecturerList = $RILecturer->getRILecturerByRid ( $value ['rid'] );
  147. // 支出项金额详情
  148. $expendList= $accountItem->getTrainingDetail ( $RItemList, $RILecturerList );
  149. $result[$key]['iTrain']['expendAmount']=sprintf ( "%.2f",$expendList['total']);
  150. $result[$key]['iTrain']['profit']= sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$expendList['total']);
  151. //利润
  152. $result[$key]['iTrain']['companyProfit']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']*0.4);
  153. $result[$key]['iTrain']['categoryProfit']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']*0.6);
  154. }
  155. return $result;
  156. }
  157. /**
  158. * 获得培训班 年营收图表
  159. */
  160. function getReceiptTrainByYearChart($year=''){
  161. if(empty($year)){
  162. $year=date("Y");
  163. }
  164. $sql = "select GROUP_CONCAT(rid) as rid,GROUP_CONCAT(invoiceTrainId) as invoiceTrainId,date_format(date,\"%m\") as month
  165. from " . $this->_table . "
  166. where status not in (3,4,5) and Rtype=3 and trainId!=0 and invoiceTrainId!=0 and paidStatus=1 and Year(date) =".$year."
  167. GROUP BY Month(date)";
  168. //
  169. $query = Doo::db ()->query ( $sql );
  170. $result = $query->fetchAll ();
  171. Doo::loadModel ( 'RItem' );
  172. $RItem = new RItem ();
  173. Doo::loadModel ( 'RILecturer' );
  174. $RILecturer = new RILecturer ();
  175. Doo::loadModel ( 'accountItem' );
  176. $accountItem = new accountItem ();
  177. Doo::loadModel ( 'invoice' );
  178. $invoice = new invoice ();
  179. $MonthPriceList=array();
  180. foreach ($result as $key=>$value){
  181. //获得支出金额总和
  182. $RIprice=$RItem->getRItemPriceByRids($value['rid']);
  183. //收款金额总和
  184. $ITprice=$invoice->getInvoicePriceByIids($value['invoiceTrainId']);
  185. $MonthPriceList[$value['month']]=array(
  186. 'RIprice'=>$RIprice,
  187. 'ITprice'=>$ITprice
  188. );
  189. }
  190. return $MonthPriceList;
  191. }
  192. function receiptByYear($dateCondition, $sid) {
  193. $sql = "select sum(sum) as sum from " . $this->_table . " where staff= '" . $sid . "' " . $dateCondition . " and status=2 ";
  194. // echo '<div style="display:none">'.$sql.'</div>';
  195. $query = Doo::db ()->query ( $sql );
  196. $result = $query->fetch ();
  197. return $result;
  198. }
  199. function getReceiptBySid($sid = '', $year = '', $month = '') {
  200. Doo::loadClass ( 'XDeode' );
  201. $XDeode = new XDeode ( 5 );
  202. if (empty ( $sid ))
  203. return array ();
  204. $sql = 'select a.*
  205. from ' . $this->_table . ' as a left join CLD_receiptDetail as b on b.rid=a.rid
  206. where b.staff =' . $sid . ' and Month(b.pastDate)=' . $month . ' and Year(b.pastDate)=' . $year . ' and b.status=1
  207. GROUP BY b.rid';
  208. $query = Doo::db ()->query ( $sql );
  209. $list = $query->fetchAll ();
  210. foreach ( $list as $key => $value ) {
  211. $list [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  212. }
  213. return $list;
  214. }
  215. function getReceiptByRid($rid = '') {
  216. Doo::loadClass ( 'XDeode' );
  217. $XDeode = new XDeode ( 5 );
  218. Doo::loadModel ( 'L_category' );
  219. $Lcategory = new L_category ();
  220. Doo::loadModel ( 'staff' );
  221. $staff = new staff ();
  222. if (! is_numeric ( $rid ))
  223. $rid = $XDeode->decode ( $rid );
  224. $rinfo = $this->getOne ( array (
  225. 'where' => 'rid=' . $rid,
  226. 'asArray' => true
  227. ) );
  228. $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] );
  229. $rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] );
  230. $XDeode = new XDeode ( 7 );
  231. $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
  232. $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
  233. $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
  234. // $rinfo['sum']=number_format ($rinfo['sum'],2);
  235. return $rinfo;
  236. }
  237. function getReceiptByinvoiceTrainId($invoiceTrainId = 0) {
  238. Doo::loadClass ( 'XDeode' );
  239. $XDeode = new XDeode ( 5 );
  240. Doo::loadModel ( 'L_category' );
  241. $Lcategory = new L_category ();
  242. Doo::loadModel ( 'staff' );
  243. $staff = new staff ();
  244. if (! is_numeric ( $invoiceTrainId ))
  245. $invoiceTrainId = $XDeode->decode ( $invoiceTrainId );
  246. $rinfo = $this->getOne ( array (
  247. 'where' => 'invoiceTrainId=' . $invoiceTrainId,
  248. 'asArray' => true
  249. ) );
  250. if (empty ( $rinfo )) {
  251. return array ();
  252. }
  253. $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] );
  254. $rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] );
  255. $XDeode = new XDeode ( 7 );
  256. $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
  257. $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
  258. $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
  259. return $rinfo;
  260. }
  261. /**
  262. * 默认获得10条
  263. * @param unknown $sid
  264. * @param unknown $cid
  265. * @param unknown $limit
  266. */
  267. function getReceiptLoanByStatus($sid, $cid, $status, $limit = 10) {
  268. $sql = '';
  269. if ($sid !== false && is_numeric ( $sid )) {
  270. $sql .= ' and staff=' . $sid;
  271. }
  272. if ($cid !== false && is_numeric ( $cid )) {
  273. $sql .= ' and cid=' . $cid;
  274. }
  275. $list = $this->find ( array (
  276. 'where' => 'Rtype=1 and status=' . $status . $sql,
  277. 'asArray' => true
  278. ) );
  279. Doo::loadClass ( 'XDeode' );
  280. $XDeode = new XDeode ( 5 );
  281. foreach ( $list as $key => $value ) {
  282. $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] );
  283. }
  284. return $list;
  285. }
  286. /**
  287. * 获得需要记录流水的费用
  288. * @param unknown $status
  289. * @return string
  290. */
  291. function getReceiptByWaste() {
  292. $list = $this->find ( array (
  293. 'where' => 'status=2 or status=6 or status=1',
  294. 'asArray' => true
  295. ) );
  296. Doo::loadClass ( 'XDeode' );
  297. $XDeode = new XDeode ( 5 );
  298. $XDeode7 = new XDeode ( 7 );
  299. Doo::loadModel ( 'wasteBook' );
  300. $wasteBook = new wasteBook ();
  301. $accountType = 0;
  302. foreach ( $list as $key => $value ) {
  303. $list [$key] ['ridKey7'] = $XDeode7->encode ( $list [$key] ['rid'] );
  304. $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] );
  305. if ($list [$key] ['Rtype'] == 0) {
  306. $accountType = 3;
  307. } elseif ($list [$key] ['Rtype'] == 1) {
  308. if (! empty ( $list [$key] ['accountItem'] ))
  309. $accountType = 2;
  310. else
  311. $accountType = 1;
  312. } elseif ($list [$key] ['Rtype'] == 2) {
  313. $accountType = 4;
  314. } elseif ($list [$key] ['Rtype'] == 3) {
  315. $accountType = 12;
  316. }
  317. // 是否已经生成流水
  318. $wbDetail = array ();
  319. if (! empty ( $accountType )) {
  320. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $list [$key] ['rid'] );
  321. if (! empty ( $wbDetail )) {
  322. unset ( $list [$key] );
  323. }
  324. } else {
  325. unset ( $list [$key] );
  326. }
  327. }
  328. return $list;
  329. }
  330. /**
  331. * 根据参数字段更新相应字段(主键ID必须传)
  332. * @param array $item 相关需要更新的字段信息
  333. * @return number 返回发票ID
  334. */
  335. public function setReceiptByCondition($item = array(), $rid = "") {
  336. $lid = 0;
  337. if (is_array ( $item ) && ! empty ( $item )) {
  338. foreach ( $item as $key => $value ) {
  339. $this->$key = $value;
  340. }
  341. if (! empty ( $isid )) {
  342. $condition = array (
  343. 'where' => "rid in (" . $rid . ")",
  344. 'asArray' => TRUE
  345. );
  346. $this->update ( $condition );
  347. } else
  348. $lid = $this->update ();
  349. }
  350. return $lid;
  351. }
  352. }
  353. ?>