receipt.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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
  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 getReceiptTrainByYearChart($year=''){
  118. if(empty($year)){
  119. $year=date("Y");
  120. }
  121. $sql = "select GROUP_CONCAT(rid) as rid,GROUP_CONCAT(invoiceTrainId) as invoiceTrainId,date_format(date,\"%m\") as month
  122. from " . $this->_table . "
  123. where status not in (3,4,5) and Rtype=3 and trainId!=0 and invoiceTrainId!=0 and Year(date) =".$year."
  124. GROUP BY Month(date)";
  125. //and paidStatus=1
  126. $query = Doo::db ()->query ( $sql );
  127. $result = $query->fetchAll ();
  128. Doo::loadModel ( 'RItem' );
  129. $RItem = new RItem ();
  130. Doo::loadModel ( 'RILecturer' );
  131. $RILecturer = new RILecturer ();
  132. Doo::loadModel ( 'accountItem' );
  133. $accountItem = new accountItem ();
  134. Doo::loadModel ( 'invoice' );
  135. $invoice = new invoice ();
  136. $MonthPriceList=array();
  137. foreach ($result as $key=>$value){
  138. //获得支出金额总和
  139. $RIprice=$RItem->getRItemPriceByRids($value['rid']);
  140. //收款金额总和
  141. $ITprice=$invoice->getInvoicePriceByIids($value['invoiceTrainId']);
  142. $MonthPriceList[$value['month']]=array(
  143. 'RIprice'=>$RIprice,
  144. 'ITprice'=>$ITprice
  145. );
  146. }
  147. return $MonthPriceList;
  148. }
  149. function receiptByYear($dateCondition, $sid) {
  150. $sql = "select sum(sum) as sum from " . $this->_table . " where staff= '" . $sid . "' " . $dateCondition . " and status=2 ";
  151. // echo '<div style="display:none">'.$sql.'</div>';
  152. $query = Doo::db ()->query ( $sql );
  153. $result = $query->fetch ();
  154. return $result;
  155. }
  156. function getReceiptBySid($sid = '', $year = '', $month = '') {
  157. Doo::loadClass ( 'XDeode' );
  158. $XDeode = new XDeode ( 5 );
  159. if (empty ( $sid ))
  160. return array ();
  161. $sql = 'select a.*
  162. from ' . $this->_table . ' as a left join CLD_receiptDetail as b on b.rid=a.rid
  163. where b.staff =' . $sid . ' and Month(b.pastDate)=' . $month . ' and Year(b.pastDate)=' . $year . ' and b.status=1
  164. GROUP BY b.rid';
  165. $query = Doo::db ()->query ( $sql );
  166. $list = $query->fetchAll ();
  167. foreach ( $list as $key => $value ) {
  168. $list [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  169. }
  170. return $list;
  171. }
  172. function getReceiptByRid($rid = '') {
  173. Doo::loadClass ( 'XDeode' );
  174. $XDeode = new XDeode ( 5 );
  175. Doo::loadModel ( 'L_category' );
  176. $Lcategory = new L_category ();
  177. Doo::loadModel ( 'staff' );
  178. $staff = new staff ();
  179. if (! is_numeric ( $rid ))
  180. $rid = $XDeode->decode ( $rid );
  181. $rinfo = $this->getOne ( array (
  182. 'where' => 'rid=' . $rid,
  183. 'asArray' => true
  184. ) );
  185. $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] );
  186. $rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] );
  187. $XDeode = new XDeode ( 7 );
  188. $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
  189. $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
  190. $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
  191. // $rinfo['sum']=number_format ($rinfo['sum'],2);
  192. return $rinfo;
  193. }
  194. function getReceiptByinvoiceTrainId($invoiceTrainId = 0) {
  195. Doo::loadClass ( 'XDeode' );
  196. $XDeode = new XDeode ( 5 );
  197. Doo::loadModel ( 'L_category' );
  198. $Lcategory = new L_category ();
  199. Doo::loadModel ( 'staff' );
  200. $staff = new staff ();
  201. if (! is_numeric ( $invoiceTrainId ))
  202. $invoiceTrainId = $XDeode->decode ( $invoiceTrainId );
  203. $rinfo = $this->getOne ( array (
  204. 'where' => 'invoiceTrainId=' . $invoiceTrainId,
  205. 'asArray' => true
  206. ) );
  207. if (empty ( $rinfo )) {
  208. return array ();
  209. }
  210. $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] );
  211. $rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] );
  212. $XDeode = new XDeode ( 7 );
  213. $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
  214. $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] );
  215. $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] );
  216. return $rinfo;
  217. }
  218. /**
  219. * 默认获得10条
  220. * @param unknown $sid
  221. * @param unknown $cid
  222. * @param unknown $limit
  223. */
  224. function getReceiptLoanByStatus($sid, $cid, $status, $limit = 10) {
  225. $sql = '';
  226. if ($sid !== false && is_numeric ( $sid )) {
  227. $sql .= ' and staff=' . $sid;
  228. }
  229. if ($cid !== false && is_numeric ( $cid )) {
  230. $sql .= ' and cid=' . $cid;
  231. }
  232. $list = $this->find ( array (
  233. 'where' => 'Rtype=1 and status=' . $status . $sql,
  234. 'asArray' => true
  235. ) );
  236. Doo::loadClass ( 'XDeode' );
  237. $XDeode = new XDeode ( 5 );
  238. foreach ( $list as $key => $value ) {
  239. $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] );
  240. }
  241. return $list;
  242. }
  243. /**
  244. * 获得需要记录流水的费用
  245. * @param unknown $status
  246. * @return string
  247. */
  248. function getReceiptByWaste() {
  249. $list = $this->find ( array (
  250. 'where' => 'status=2 or status=6 or status=1',
  251. 'asArray' => true
  252. ) );
  253. Doo::loadClass ( 'XDeode' );
  254. $XDeode = new XDeode ( 5 );
  255. $XDeode7 = new XDeode ( 7 );
  256. Doo::loadModel ( 'wasteBook' );
  257. $wasteBook = new wasteBook ();
  258. $accountType = 0;
  259. foreach ( $list as $key => $value ) {
  260. $list [$key] ['ridKey7'] = $XDeode7->encode ( $list [$key] ['rid'] );
  261. $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] );
  262. if ($list [$key] ['Rtype'] == 0) {
  263. $accountType = 3;
  264. } elseif ($list [$key] ['Rtype'] == 1) {
  265. if (! empty ( $list [$key] ['accountItem'] ))
  266. $accountType = 2;
  267. else
  268. $accountType = 1;
  269. } elseif ($list [$key] ['Rtype'] == 2) {
  270. $accountType = 4;
  271. } elseif ($list [$key] ['Rtype'] == 3) {
  272. $accountType = 12;
  273. }
  274. // 是否已经生成流水
  275. $wbDetail = array ();
  276. if (! empty ( $accountType )) {
  277. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $list [$key] ['rid'] );
  278. if (! empty ( $wbDetail )) {
  279. unset ( $list [$key] );
  280. }
  281. } else {
  282. unset ( $list [$key] );
  283. }
  284. }
  285. return $list;
  286. }
  287. /**
  288. * 根据参数字段更新相应字段(主键ID必须传)
  289. * @param array $item 相关需要更新的字段信息
  290. * @return number 返回发票ID
  291. */
  292. public function setReceiptByCondition($item = array(), $rid = "") {
  293. $lid = 0;
  294. if (is_array ( $item ) && ! empty ( $item )) {
  295. foreach ( $item as $key => $value ) {
  296. $this->$key = $value;
  297. }
  298. if (! empty ( $isid )) {
  299. $condition = array (
  300. 'where' => "rid in (" . $rid . ")",
  301. 'asArray' => TRUE
  302. );
  303. $this->update ( $condition );
  304. } else
  305. $lid = $this->update ();
  306. }
  307. return $lid;
  308. }
  309. }
  310. ?>