ReceiptExtendController.php 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptExtendController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  18. private function showCache($path) {
  19. if (file_exists ( $path )) {
  20. echo "<!DOCTYPE html>";
  21. include $path;
  22. die ();
  23. }
  24. }
  25. private function cacheFile($path) {
  26. $content = ob_get_contents ();
  27. $fp = fopen ( $path, "w" );
  28. fwrite ( $fp, $content );
  29. fclose ( $fp );
  30. }
  31. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  32. $collectHtml = "";
  33. $sumPrice = 0.00;
  34. for($i = 1; $i <= 12; $i ++) {
  35. $falg = true;
  36. foreach ( $receiptCollectList as $key => $value ) {
  37. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  38. $sumPrice += $value ['price'];
  39. if ($classType == "b") {
  40. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  41. $falg = false;
  42. break;
  43. } else {
  44. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  45. $falg = false;
  46. break;
  47. }
  48. }
  49. }
  50. if ($falg)
  51. $collectHtml .= '<td class="taR">-</td>';
  52. }
  53. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  54. return $collectHtml;
  55. }
  56. public function beforeRun($resource, $action) {
  57. Doo::loadClass ( 'XDeode' );
  58. $XDeode = new XDeode ( 5 );
  59. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  60. // 单独判断公司汇总的访问权限
  61. if ($action == 'companyCategoryCollect') {
  62. Doo::loadModel ( "receiptAuthorityManage" );
  63. $invoiceCompanyManage = new receiptAuthorityManage ();
  64. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  65. if (empty ( $icm ))
  66. die ( 'illegal request' );
  67. }
  68. Doo::loadModel ( 'staff' );
  69. $staff = new staff ();
  70. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  71. $accessModular = 'RECEIPTSEXTEND'; // 是否已经开放的方法
  72. $accessAuthority = 'RECEIPTS';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. die ( 'illegal request' );
  75. else {
  76. if (in_array ( $accessAuthority, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. die ( 'illegal request' );
  84. }
  85. }
  86. if (! $flag)
  87. die ( 'illegal request' );
  88. }
  89. function __construct() {
  90. if (isset ( $_COOKIE ["staff"] )) {
  91. if (! empty ( $_COOKIE ["staff"] )) {
  92. Doo::loadModel ( 'staff' );
  93. Doo::loadModel ( 'verify' );
  94. $verify = new verify ();
  95. $staff = new staff ();
  96. Doo::loadModel ( "execute" );
  97. $execute = new execute ();
  98. $verifyList = $verify->find ( array (
  99. 'select' => 'staff',
  100. 'asArray' => true
  101. ) );
  102. $list = array ();
  103. // 判断角色的审批权限
  104. foreach ( $verifyList as $key => $value ) {
  105. $ver = json_decode ( $value ['staff'] );
  106. foreach ( $ver as $k => $v ) {
  107. if ($v [1] == 'ROLE') {
  108. $roleList = json_decode ( $v [3] );
  109. foreach ( $roleList as $t => $g ) {
  110. $gList = explode ( "_", $g );
  111. array_push ( $list, $gList [0] );
  112. // print_r($list);
  113. }
  114. } else
  115. array_push ( $list, $v [0] );
  116. }
  117. }
  118. // 判断执行人的审批权限
  119. $executeList = $execute->find ( array (
  120. 'select' => 'staff',
  121. 'asArray' => true
  122. ) );
  123. $list2 = array ();
  124. foreach ( $executeList as $key => $value ) {
  125. $ver = json_decode ( $value ['staff'] );
  126. foreach ( $ver as $k => $v ) {
  127. array_push ( $list2, $v [0] );
  128. }
  129. }
  130. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  131. $eidList = array_filter ( explode ( ",", $eidList ) );
  132. $this->executeId = array_merge ( $list2, $eidList );
  133. $this->verifyId = $list;
  134. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  135. // 检测用户信息完成
  136. $this->data ['isStaffCompleteMsg'] = false;
  137. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  138. if (! empty ( $detail ))
  139. $this->data ['isStaffCompleteMsg'] = true;
  140. return "/";
  141. }
  142. }
  143. Doo::loadCore ( 'uri/DooUriRouter' );
  144. $router = new DooUriRouter ();
  145. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  146. if ($routeRs ['1'] != "login") {
  147. header ( 'Content-Type:text/html;charset=utf-8' );
  148. @header ( "Location: /login" );
  149. }
  150. }
  151. /**
  152. * 查看审批培训班结算
  153. */
  154. function receiptTrain() {
  155. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
  156. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  157. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  158. Doo::loadClass ( 'XDeode' );
  159. $XDeode = new XDeode ( 7 );
  160. $rid = $XDeode->decode ( $ridKey );
  161. if (! is_numeric ( $rid ))
  162. die ( 'illegal request' );
  163. Doo::loadModel ( 'receipt' );
  164. $receipt = new receipt ();
  165. Doo::loadModel ( 'receiptTraining' );
  166. $receiptTraining = new receiptTraining ();
  167. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  168. // 如有已入账已收款的发票,自动取消办事处已收款
  169. // Doo::loadModel ( 'RIExtend' );
  170. // $RIExtend = new RIExtend ();
  171. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  172. // if (!empty($RIExtendList)){
  173. // foreach ($RIExtenreceiptTrainRevenuedList as $key=>$value){
  174. // $RIExtend = new RIExtend ();
  175. // $RIExtend->delete(array (
  176. // 'where' => 'iid=' . $value['iid'],
  177. // 'limit' => 1
  178. // ));
  179. // }
  180. // }
  181. $data ['receiptMemu'] = 'expenses';
  182. if ($showType == 'approval') {
  183. $data ['receiptMemu'] = 'approvalExpenses';
  184. // if ($receiptDetail ['status'] != 2)
  185. // die ();
  186. } elseif ($showType == 'implement') {
  187. $data ['receiptMemu'] = 'implement';
  188. // if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
  189. // die ();
  190. }
  191. $data ['showType'] = $showType;
  192. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  193. // 汇总表合计
  194. // 收入合计
  195. Doo::loadModel ( 'invoiceTraining' );
  196. $invoiceTraining = new invoiceTraining ();
  197. $invoiceTrainingDetail = array (
  198. 'invoiceArriveAmount' => '0.00',
  199. 'RIAmount' => '0.00',
  200. 'invoiceTotalAmount' => '0.00',
  201. 'invoiceCompanyAmount' => '0.00'
  202. );
  203. if ($receiptDetail ['invoiceTrainId'] != 0) {
  204. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  205. }
  206. // print_r($invoiceTrainingDetail);
  207. $invoiceArriveAmount = $RIAmount = 0;
  208. if (! empty ( $invoiceTrainingDetail )) {
  209. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  210. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  211. }
  212. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  213. // 支出项目
  214. Doo::loadModel ( 'accountItem' );
  215. $accountItem = new accountItem ();
  216. // 项目金额合计
  217. Doo::loadModel ( 'RItem' );
  218. $RItem = new RItem ();
  219. // 讲师获得
  220. Doo::loadModel ( 'RILecturer' );
  221. $RILecturer = new RILecturer ();
  222. $RItemList = $RItem->getRItemByRid ( $rid );
  223. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  224. // 支出项金额详情
  225. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  226. // 利润
  227. $profit = $invoiceArriveAmount - $aiData ['total'];
  228. $companyProfit = $profit * 0.6;
  229. $categoryProfit = $profit * 0.4;
  230. $data ['profit'] = sprintf ( "%.2f", $profit );
  231. $data ['companyProfit'] = sprintf ( "%.2f", $companyProfit );
  232. $data ['categoryProfit'] = sprintf ( "%.2f", $categoryProfit );
  233. // 发票利润
  234. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  235. // 发票公司利润
  236. $invoiceCompanyProfit = $data ['invoiceProfit'] * 0.6;
  237. $data ['invoiceCompanyProfit'] = sprintf ( "%.2f", $invoiceCompanyProfit );
  238. // 办事处利润
  239. $invoiceCategoryProfit = $data ['invoiceProfit'] * 0.4;
  240. $data ['invoiceCategoryProfit'] = sprintf ( "%.2f", $invoiceCategoryProfit );
  241. // print_r($aiData['dataList']);
  242. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  243. $data ['categoryActualExpenditure'] = sprintf ( "%.2f", $categoryActualExpenditure );
  244. // 备用金
  245. $sum = 0;
  246. $data ['receiptLoanDetail'] = array (
  247. 'sum' => '0.00'
  248. );
  249. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  250. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  251. $sum = $data ['receiptLoanDetail'] ['sum'];
  252. }
  253. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  254. $data ['payment'] = sprintf ( "%.2f", $payment );
  255. $data ['total'] = sprintf ( "%.2f", $aiData ['total'] );
  256. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  257. $data ['aiList'] = $aiData ['dataList'];
  258. // 占比计算
  259. if ($invoiceArriveAmount != 0) {
  260. $data ['totalProportion'] = sprintf ( "%.2f", $aiData ['total'] / $invoiceArriveAmount * 100 );
  261. $data ['profitProportion'] = sprintf ( "%.2f", $profit / $invoiceArriveAmount * 100 ); // number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  262. $data ['sumProportion'] = sprintf ( "%.2f", $sum / $invoiceArriveAmount * 100 ); // number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  263. $data ['invoiceTotalAmountProportion'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount * 100 );
  264. $data ['RIAmountProportion'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount * 100 );
  265. $data ['companyProfitProportion'] = sprintf ( "%.2f", $companyProfit / $invoiceArriveAmount * 100 );
  266. $data ['categoryProportion'] = sprintf ( "%.2f", $categoryProfit / $invoiceArriveAmount * 100 );
  267. $data ['categoryActualExpenditureProportion'] = sprintf ( "%.2f", $categoryActualExpenditure / $invoiceArriveAmount * 100 );
  268. $data ['paymentProportion'] = sprintf ( "%.2f", $payment / $invoiceArriveAmount * 100 );
  269. } else {
  270. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  271. }
  272. // 发票金额占比计算
  273. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  274. // 支出
  275. $data ['invoicetotalProportion'] = sprintf ( "%.2f", $aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  276. // 利润
  277. $data ['invoiceprofitProportion'] = sprintf ( "%.2f", $data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  278. // 公司利润
  279. $data ['invoicecompanyProfitProportion'] = sprintf ( "%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  280. // 办事处利润
  281. $data ['invoicecategoryProportion'] = sprintf ( "%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  282. // 公司收款
  283. $data ['invoiceTotalAmountProportionB'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  284. // 备用金
  285. $data ['invoicesumProportion'] = sprintf ( "%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  286. // 办事处收款
  287. $data ['invoiceRIAmountProportion'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  288. // 办事处实际支出
  289. $data ['ICAEP'] = sprintf ( "%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  290. // 付总部款
  291. $data ['invoicepaymentProportion'] = sprintf ( "%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
  292. } else {
  293. $data ['invoiceprofitProportion'] = $data ['invoiceRIAmountProportion'] = $data ['invoicetotalProportion'] = $data ['invoiceTotalAmountProportionB'] = $data ['invoicesumProportion'] = $data ['ICAEP'] = $data ['invoicepaymentProportion'] = $data ['invoicecompanyProfitProportion'] = $data ['invoicecategoryProportion'] = 0;
  294. }
  295. // 是否写入过流水
  296. $accountType = 0;
  297. if ($receiptDetail ['Rtype'] == 0) {
  298. $accountType = 3;
  299. } elseif ($receiptDetail ['Rtype'] == 1) {
  300. if ($receiptDetail ['Rtype'] == 0) {
  301. $accountType = 1;
  302. } elseif ($receiptDetail ['Rtype'] == 1) {
  303. $accountType = 2;
  304. }
  305. } elseif ($receiptDetail ['Rtype'] == 2) {
  306. $accountType = 4;
  307. } elseif ($receiptDetail ['Rtype'] == 3) {
  308. $accountType = 12;
  309. }
  310. Doo::loadModel ( 'wasteBook' );
  311. $wasteBook = new wasteBook ();
  312. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptDetail ['rid'] );
  313. $data ['wbDetail'] = $wbDetail;
  314. // 讲师人数
  315. Doo::loadModel ( 'RILecturer' );
  316. $RILecturer = new RILecturer ();
  317. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  318. $data ['lectureCount'] = count ( $RILecturerList );
  319. // 审批组
  320. Doo::loadModel ( 'verify' );
  321. $verify = new verify ();
  322. $veList = $verify->getVerifyByAll ();
  323. // 办事处
  324. Doo::loadModel ( 'L_category' );
  325. $lCategory = new L_category ();
  326. $data ['category'] = $lCategory->getCategory ();
  327. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  328. $data ['receiptDetail'] = $receiptDetail;
  329. $data ['veList'] = $veList;
  330. $data ['trainEdiType'] = $trainEdiType;
  331. $data ['ridKey'] = $ridKey;
  332. $summaryJson = array (
  333. 0 => array (
  334. 'invoiceTotalAmount' => $data ['invoiceTrainingDetail'] ['invoiceTotalAmount'],
  335. 'invoiceArriveAmount' => $data ['invoiceTrainingDetail'] ['invoiceArriveAmount']
  336. ),
  337. 1 => array (
  338. '1' => $data ['total'],
  339. '2' => $data ['invoicetotalProportion'] . '%',
  340. '3' => $data ['total'],
  341. '4' => $data ['totalProportion'] . '%'
  342. ),
  343. 2 => array (
  344. '1' => $data ['invoiceProfit'],
  345. '2' => $data ['invoiceprofitProportion'] . '%',
  346. '3' => $data ['profit'],
  347. '4' => $data ['profitProportion'] . '%'
  348. ),
  349. 3 => array (
  350. '1' => $data ['invoiceCompanyProfit'],
  351. '2' => $data ['invoicecompanyProfitProportion'] . '%',
  352. '3' => $data ['companyProfit'],
  353. '4' => $data ['companyProfitProportion'] . '%'
  354. ),
  355. 4 => array (
  356. '1' => $data ['invoiceCategoryProfit'],
  357. '2' => $data ['invoicecategoryProportion'] . '%',
  358. '3' => $data ['categoryProfit'],
  359. '4' => $data ['categoryProportion'] . '%'
  360. ),
  361. 5 => array (
  362. '1' =>$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'],
  363. '2' => $data ['invoiceTotalAmountProportionB'] . '%',
  364. '3' => $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'],
  365. '4' => $data ['invoiceTotalAmountProportion'] . '%'
  366. ),
  367. 6 => array (
  368. '1' =>$data ['receiptLoanDetail'] ['sum'],
  369. '2' => $data ['invoicesumProportion'] . '%',
  370. '3' => $data ['receiptLoanDetail'] ['sum'],
  371. '4' => $data ['sumProportion'] . '%'
  372. ),
  373. 7 => array (
  374. '1' =>$data ['invoiceTrainingDetail'] ['RIAmount'],
  375. '2' => $data ['invoiceRIAmountProportion'] . '%',
  376. '3' => $data ['invoiceTrainingDetail'] ['RIAmount'],
  377. '4' => $data ['RIAmountProportion'] . '%'
  378. ),
  379. 8 => array (
  380. '1' =>$data ['categoryActualExpenditure'],
  381. '2' => $data ['ICAEP'] . '%',
  382. '3' => $data ['categoryActualExpenditure'] ,
  383. '4' => $data ['categoryActualExpenditureProportion'] . '%'
  384. ),
  385. 9 => array (
  386. '1' =>$data ['payment'],
  387. '2' => $data ['invoicepaymentProportion'] . '%',
  388. '3' => $data ['payment'] ,
  389. '4' => $data ['paymentProportion'] . '%'
  390. ),
  391. 10 => array (
  392. 'participants' =>$data ['receiptTrainingDetail'] ['participants'],
  393. 'lectureCount' => $data ['lectureCount'] ,
  394. ),
  395. 11=>array(
  396. 'total'=>$data ['total'],
  397. 'totalProportion'=>$data ['totalProportion']
  398. ),
  399. );
  400. $data ['summaryJson'] =URLEncode(json_encode($summaryJson));
  401. $data ['aiListJson'] =URLEncode(json_encode($data ['aiList']));
  402. $data ['memu'] = "receipt";
  403. $data ['staff'] = $this->staff;
  404. $data ['verifyId'] = $this->verifyId;
  405. $data ['executeId'] = $this->executeId;
  406. $this->render ( "/receipt/receiptTrain", $data );
  407. }
  408. /**
  409. * 培训班借款
  410. */
  411. function receiptTrainLoan() {
  412. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
  413. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  414. Doo::loadClass ( 'XDeode' );
  415. $XDeode = new XDeode ( 7 );
  416. $rid = $XDeode->decode ( $ridKey );
  417. if (! is_numeric ( $rid ))
  418. die ( 'illegal request' );
  419. Doo::loadModel ( 'receipt' );
  420. $receipt = new receipt ();
  421. Doo::loadModel ( 'receiptTraining' );
  422. $receiptTraining = new receiptTraining ();
  423. Doo::loadModel ( 'verify' );
  424. $verify = new verify ();
  425. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  426. $data ['receiptMemu'] = 'expenses';
  427. if ($showType == 'approval') {
  428. $data ['receiptMemu'] = 'approvalExpenses';
  429. // if ($receiptDetail ['status'] != 2)
  430. // die ();
  431. } elseif ($showType == 'implement') {
  432. $data ['receiptMemu'] = 'implement';
  433. // if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
  434. // die ();
  435. }
  436. $data ['showType'] = $showType;
  437. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  438. // 借款详情HTML
  439. // 获得借款信息
  440. $receiptLoanHtml = '';
  441. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  442. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  443. // 获得某费用单审批信息
  444. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  445. Doo::loadClass ( 'receipt.func' );
  446. $extendHtml = '';
  447. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  448. }
  449. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  450. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  451. $data ['receiptDetail'] = $receiptDetail;
  452. $data ['trainEdiType'] = "LOAN";
  453. $data ['ridKey'] = $ridKey;
  454. $data ['memu'] = "receipt";
  455. $data ['staff'] = $this->staff;
  456. $data ['verifyId'] = $this->verifyId;
  457. $data ['executeId'] = $this->executeId;
  458. $this->render ( "/receipt/receiptTrainLoan", $data );
  459. }
  460. /**
  461. * 培训班结算 ---开票
  462. */
  463. function receiptTrainInvoice() {
  464. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
  465. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  466. Doo::loadClass ( 'XDeode' );
  467. $XDeode = new XDeode ( 7 );
  468. $rid = $XDeode->decode ( $ridKey );
  469. if (! is_numeric ( $rid ))
  470. die ( 'illegal request' );
  471. Doo::loadModel ( 'receipt' );
  472. $receipt = new receipt ();
  473. Doo::loadModel ( 'receiptTraining' );
  474. $receiptTraining = new receiptTraining ();
  475. Doo::loadModel ( 'invoice' );
  476. $invoice = new invoice ();
  477. Doo::loadModel ( 'invoiceTraining' );
  478. $invoiceTraining = new invoiceTraining ();
  479. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  480. $data ['receiptMemu'] = 'expenses';
  481. if ($showType == 'approval') {
  482. $data ['receiptMemu'] = 'approvalExpenses';
  483. // if ($receiptDetail ['status'] != 2)
  484. // die ();
  485. } elseif ($showType == 'implement') {
  486. $data ['receiptMemu'] = 'implement';
  487. // if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
  488. // die ();
  489. }
  490. $data ['showType'] = $showType;
  491. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  492. $invoiceList = $invoiceTrainingDetail = array ();
  493. if ($receiptDetail ['invoiceTrainId'] != 0) {
  494. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  495. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  496. }
  497. //收款是否完成更新状态
  498. //$RIC=$invoiceTrainingDetail['RIAmount']+$invoiceTrainingDetail['invoiceCompanyAmount'];
  499. if ($invoiceTrainingDetail['invoiceTotalAmount']<=$invoiceTrainingDetail['invoiceArriveAmount']&&$receiptDetail['paidStatus']==0){
  500. $receipt = new receipt ();
  501. $itemData = array (
  502. 'rid' => $rid,
  503. 'paidStatus' => 1,
  504. );
  505. $receipt->setReceiptByCondition($itemData);
  506. }
  507. // print_r($invoiceList);
  508. $data ['invoiceList'] = $invoiceList;
  509. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  510. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  511. $data ['receiptDetail'] = $receiptDetail;
  512. $data ['trainEdiType'] = "INVOICE";
  513. $data ['ridKey'] = $ridKey;
  514. $data ['memu'] = "receipt";
  515. $data ['staff'] = $this->staff;
  516. $data ['verifyId'] = $this->verifyId;
  517. $data ['executeId'] = $this->executeId;
  518. $this->render ( "/receipt/receiptTrainInvoice", $data );
  519. }
  520. /**
  521. * 培训班结算
  522. */
  523. function receiptTrainItem() {
  524. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
  525. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  526. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  527. Doo::loadClass ( 'XDeode' );
  528. $XDeode = new XDeode ( 7 );
  529. $rid = $XDeode->decode ( $ridKey );
  530. if (! is_numeric ( $rid ))
  531. die ( 'illegal request' );
  532. Doo::loadModel ( 'receipt' );
  533. $receipt = new receipt ();
  534. Doo::loadModel ( 'receiptTraining' );
  535. $receiptTraining = new receiptTraining ();
  536. Doo::loadModel ( 'RItem' );
  537. $RItem = new RItem ();
  538. Doo::loadModel ( 'accountItem' );
  539. $accountItem = new accountItem ();
  540. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  541. $data ['receiptMemu'] = 'expenses';
  542. if ($showType == 'approval') {
  543. $data ['receiptMemu'] = 'approvalExpenses';
  544. // if ($receiptDetail ['status'] != 2)
  545. // die ();
  546. } elseif ($showType == 'implement') {
  547. $data ['receiptMemu'] = 'implement';
  548. // if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
  549. // die ();
  550. }
  551. $data ['showType'] = $showType;
  552. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  553. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  554. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );
  555. // print_r($RItemList);
  556. $data ['name'] = $name;
  557. $data ['RItemList'] = $RItemList;
  558. $data ['aiList'] = $aiList;
  559. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  560. $data ['receiptDetail'] = $receiptDetail;
  561. $data ['trainEdiType'] = "ITEM";
  562. $data ['ridKey'] = $ridKey;
  563. $data ['memu'] = "receipt";
  564. $data ['staff'] = $this->staff;
  565. $data ['verifyId'] = $this->verifyId;
  566. $data ['executeId'] = $this->executeId;
  567. $this->render ( "/receipt/receiptTrainItem", $data );
  568. }
  569. /**
  570. * 培训班结算-讲师
  571. */
  572. function receiptTrainLecturer() {
  573. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
  574. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  575. Doo::loadClass ( 'XDeode' );
  576. $XDeode = new XDeode ( 7 );
  577. $rid = $XDeode->decode ( $ridKey );
  578. if (! is_numeric ( $rid ))
  579. die ( 'illegal request' );
  580. Doo::loadModel ( 'receipt' );
  581. $receipt = new receipt ();
  582. Doo::loadModel ( 'receiptTraining' );
  583. $receiptTraining = new receiptTraining ();
  584. Doo::loadModel ( 'RILecturer' );
  585. $RILecturer = new RILecturer ();
  586. Doo::loadModel ( 'lecturer' );
  587. $lecturer = new lecturer ();
  588. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  589. $data ['receiptMemu'] = 'expenses';
  590. if ($showType == 'approval') {
  591. $data ['receiptMemu'] = 'approvalExpenses';
  592. // if ($receiptDetail ['status'] != 2)
  593. // die ();
  594. } elseif ($showType == 'implement') {
  595. $data ['receiptMemu'] = 'implement';
  596. // if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
  597. // die ();
  598. }
  599. $data ['showType'] = $showType;
  600. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  601. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  602. $lecturerList = $lecturer->getLecturerAll ();
  603. $INSIDEhtml = $OUTSIDEhtml = '';
  604. foreach ( $lecturerList as $key => $value ) {
  605. if ($value ['ltype'] == 'INSIDE') {
  606. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  607. } elseif ($value ['ltype'] == 'OUTSIDE') {
  608. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  609. }
  610. }
  611. $data ['INSIDEhtml'] = $INSIDEhtml;
  612. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  613. // print_r($RItemList);
  614. $data ['RILecturerList'] = $RILecturerList;
  615. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  616. $data ['receiptDetail'] = $receiptDetail;
  617. $data ['trainEdiType'] = "LECTURER";
  618. $data ['ridKey'] = $ridKey;
  619. $data ['memu'] = "receipt";
  620. $data ['staff'] = $this->staff;
  621. $data ['verifyId'] = $this->verifyId;
  622. $data ['executeId'] = $this->executeId;
  623. $this->render ( "/receipt/receiptTrainLecturer", $data );
  624. }
  625. /**
  626. * 培训班结算编辑-协助
  627. */
  628. function receiptTrainAssistEdi() {
  629. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  630. Doo::loadClass ( 'XDeode' );
  631. $XDeode = new XDeode ( 7 );
  632. $rid = $XDeode->decode ( $ridKey );
  633. if (! is_numeric ( $rid ))
  634. die ( 'illegal request' );
  635. Doo::loadModel ( 'receipt' );
  636. $receipt = new receipt ();
  637. Doo::loadModel ( 'receiptTraining' );
  638. $receiptTraining = new receiptTraining ();
  639. Doo::loadModel ( 'RAssist' );
  640. $RAssist = new RAssist ();
  641. Doo::loadModel ( 'staff' );
  642. $staff = new staff ();
  643. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  644. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  645. die ();
  646. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  647. $RAssistList = $RAssist->getRAssistByRid ( $rid );
  648. $assistStaffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  649. // print_r($RAssistList);
  650. $data ['$assistStaffList'] = $assistStaffList;
  651. $data ['RAssistList'] = $RAssistList;
  652. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  653. $data ['receiptDetail'] = $receiptDetail;
  654. $data ['trainEdiType'] = "ASSIST";
  655. $data ['ridKey'] = $ridKey;
  656. $data ['memu'] = "receipt";
  657. $data ['staff'] = $this->staff;
  658. $data ['receiptMemu'] = 'saeaBorad';
  659. $data ['verifyId'] = $this->verifyId;
  660. $data ['executeId'] = $this->executeId;
  661. $this->render ( "/receipt/receiptTrainAssistEdi", $data );
  662. }
  663. /**
  664. * 添加协助人
  665. */
  666. function receiptTrainAssistAddDo() {
  667. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  668. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : "";
  669. if (! empty ( $ridKey ) && ! empty ( $sidKey )) {
  670. Doo::loadClass ( 'XDeode' );
  671. $XDeode = new XDeode ( 5 );
  672. Doo::loadModel ( 'RAssist' );
  673. $RAssist = new RAssist ();
  674. $rid = $XDeode->decode ( $ridKey );
  675. $sid = $XDeode->decode ( $sidKey );
  676. if (! is_numeric ( $rid ) || ! is_numeric ( $sid )) {
  677. die ( 'illegal request' );
  678. }
  679. $RAssist->rid = $rid;
  680. $RAssist->sid = $sid;
  681. $RAssist->date = date ( "Y-m-d" );
  682. $RAssist->insert ();
  683. $XDeode = new XDeode ( 7 );
  684. return '/receiptTrainAssistEdi/' . $XDeode->encode ( $rid ) . '.html';
  685. } else
  686. die ( 'illegal request' );
  687. }
  688. /**
  689. * 删除协作人
  690. */
  691. function receiptTrainAssistDelDo() {
  692. $aidKey = isset ( $this->params ['aidKey'] ) ? $this->params ['aidKey'] : '';
  693. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  694. Doo::loadClass ( 'XDeode' );
  695. $XDeode = new XDeode ( 5 );
  696. $aid = $XDeode->decode ( $aidKey );
  697. $rid = $XDeode->decode ( $ridKey );
  698. if (! is_numeric ( $aid )) {
  699. die ( 'illegal request--id' );
  700. }
  701. Doo::loadModel ( 'RAssist' );
  702. $RAssist = new RAssist ();
  703. $RAssist->delete ( array (
  704. 'where' => 'aid=' . $aid
  705. ) );
  706. $XDeode = new XDeode ( 7 );
  707. return '/receiptTrainAssistEdi/' . $XDeode->encode ( $rid ) . '.html';
  708. }
  709. /*
  710. * 培训班结算-审批
  711. */
  712. function receiptTrainApproval() {
  713. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
  714. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  715. Doo::loadClass ( 'XDeode' );
  716. $XDeode = new XDeode ( 7 );
  717. $rid = $XDeode->decode ( $ridKey );
  718. if (! is_numeric ( $rid ))
  719. die ( 'illegal request' );
  720. Doo::loadModel ( 'receipt' );
  721. $receipt = new receipt ();
  722. Doo::loadModel ( 'receiptTraining' );
  723. $receiptTraining = new receiptTraining ();
  724. Doo::loadModel ( 'lecturer' );
  725. $lecturer = new lecturer ();
  726. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  727. // 是否有权访问
  728. if ($showType != 'info') {
  729. if (! in_array ( $this->staff [0] ['sid'], $this->verifyId )) {
  730. die ( 'illegal request-verifyId' );
  731. }
  732. }
  733. // 用户的访问页面类型
  734. $data ['receiptMemu'] = 'expenses';
  735. if ($showType == 'approval') {
  736. $data ['receiptMemu'] = 'approvalExpenses';
  737. // if ($receiptDetail ['status'] != 2)
  738. // die ();
  739. }
  740. $data ['showType'] = $showType;
  741. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  742. // 获取审批日志
  743. Doo::loadModel ( 'receiptLog' );
  744. $receiptLog = new receiptLog ();
  745. // echo $rid;
  746. $rlList = $receiptLog->find ( array (
  747. 'where' => 'rid=' . $rid,
  748. 'asc' => 'rlid',
  749. 'asArray' => true
  750. ) );
  751. $data ['rlList'] = $rlList;
  752. // 审批组
  753. Doo::loadModel ( 'verify' );
  754. $verify = new verify ();
  755. $verifyList = $verify->getOne ( array (
  756. 'where' => 'vid=' . $receiptDetail ['verify'],
  757. 'asArray' => true
  758. ) );
  759. $verifyList = json_decode ( $verifyList ['staff'], true );
  760. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  761. $verifyList = $this->fnGetReceiptApprovalProcess ( $verifyList, $verifyStaff );
  762. $data ['verifyList'] = $verifyList ['verifyList'];
  763. // print_r($verifyList['verifyList']);
  764. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  765. $data ['receiptDetail'] = $receiptDetail;
  766. $data ['trainEdiType'] = "APPROVAL";
  767. $data ['ridKey'] = $ridKey;
  768. $data ['memu'] = "receipt";
  769. $data ['staff'] = $this->staff;
  770. $data ['verifyId'] = $this->verifyId;
  771. $data ['executeId'] = $this->executeId;
  772. if ($showType == 'approval') {
  773. $this->render ( "/receipt/receiptTrainApproval", $data );
  774. } else {
  775. $this->render ( "/receipt/receiptTrainApprovalInfo", $data );
  776. }
  777. }
  778. /**
  779. * 培训班结算--执行
  780. */
  781. function receiptTrainImplement() {
  782. $showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : 'implement';
  783. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  784. Doo::loadClass ( 'XDeode' );
  785. $XDeode = new XDeode ( 7 );
  786. $rid = $XDeode->decode ( $ridKey );
  787. if (! is_numeric ( $rid ))
  788. die ( 'illegal request' );
  789. Doo::loadModel ( 'receipt' );
  790. $receipt = new receipt ();
  791. Doo::loadModel ( 'receiptTraining' );
  792. $receiptTraining = new receiptTraining ();
  793. Doo::loadModel ( 'lecturer' );
  794. $lecturer = new lecturer ();
  795. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  796. // 是否有权访问
  797. if (! in_array ( $this->staff [0] ['sid'], $this->executeId )) {
  798. die ( 'illegal request' );
  799. }
  800. // 用户的访问页面类型
  801. $data ['receiptMemu'] = 'implement';
  802. // if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6)) {
  803. // die ();
  804. // }
  805. $data ['showType'] = $showType;
  806. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  807. // 获取审批日志
  808. Doo::loadModel ( 'receiptLog' );
  809. $receiptLog = new receiptLog ();
  810. // echo $rid;
  811. $rlList = $receiptLog->find ( array (
  812. 'where' => 'rid=' . $rid,
  813. 'asc' => 'rlid',
  814. 'asArray' => true
  815. ) );
  816. $data ['rlList'] = $rlList;
  817. // 审批组
  818. Doo::loadModel ( 'verify' );
  819. $verify = new verify ();
  820. $verifyList = $verify->getOne ( array (
  821. 'where' => 'vid=' . $receiptDetail ['verify'],
  822. 'asArray' => true
  823. ) );
  824. $verifyList = json_decode ( $verifyList ['staff'], true );
  825. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  826. $verifyList = $this->fnGetReceiptApprovalProcess ( $verifyList, $verifyStaff );
  827. $data ['verifyList'] = $verifyList ['verifyList'];
  828. // print_r($verifyList['verifyList']);
  829. // 执行组
  830. $executeList = json_decode ( $receiptDetail ['executeCopy'], true );
  831. $executeStaff = array ();
  832. if (! empty ( $receiptDetail ['executeStaff'] )) {
  833. $executeStaff = json_decode ( $receiptDetail ['executeStaff'], true );
  834. }
  835. $button2 = 0;
  836. if (isset ( $executeList )) {
  837. foreach ( $executeList as $op => $lo ) {
  838. $executeList [$op] ['date'] = "";
  839. $executeList [$op] ['opinion'] = "";
  840. $executeList [$op] ['status'] = "";
  841. foreach ( $executeStaff as $m => $u ) {
  842. if ($lo [0] == $m) {
  843. $executeList [$op] ['date'] = $u ['date'];
  844. $executeList [$op] ['opinion'] = $u ['opinion'];
  845. $executeList [$op] ['status'] = $u ['status'];
  846. break;
  847. }
  848. }
  849. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  850. $button2 = 1;
  851. $executeList [$op] ['status'] = 4;
  852. }
  853. }
  854. }
  855. $data ['button2'] = $button2;
  856. $data ['executeList'] = $executeList;
  857. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  858. $data ['receiptDetail'] = $receiptDetail;
  859. $data ['trainEdiType'] = "implement";
  860. $data ['ridKey'] = $ridKey;
  861. $data ['memu'] = "receipt";
  862. $data ['staff'] = $this->staff;
  863. $data ['verifyId'] = $this->verifyId;
  864. $data ['executeId'] = $this->executeId;
  865. $this->render ( "/receipt/receiptTrainImplement", $data );
  866. }
  867. function receiptTrainApprovalDo() {
  868. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  869. $statusKey = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : '';
  870. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  871. if (! empty ( $ridKey ) && ! empty ( $statusKey )) {
  872. Doo::loadClass ( 'XDeode' );
  873. $XDeode = new XDeode ( 5 );
  874. $rid = $XDeode->decode ( $ridKey );
  875. if ($statusKey == 'AGREE') {
  876. $status = 1;
  877. } elseif ($statusKey == 'END') {
  878. $status = 3;
  879. } else {
  880. die ( 'illegal request--status' );
  881. }
  882. Doo::loadModel ( "verify" );
  883. $verify = new verify ();
  884. Doo::loadModel ( "receiptDetail" );
  885. $receiptDetailObj = new receiptDetail ();
  886. Doo::loadModel ( "itemStatistics" );
  887. Doo::loadModel ( "statistics" );
  888. $statistics = new statistics ();
  889. $itemStatistics = new itemStatistics ();
  890. Doo::loadModel ( "receipt" );
  891. $receipt = new receipt ();
  892. $receiptDetail = $receipt->getOne ( array (
  893. 'where' => 'rid=' . $rid . ' and status=2 ',
  894. 'asArray' => true
  895. ) );
  896. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  897. $nsflag = true;
  898. foreach ( $nslist as $value ) {
  899. if ($value == $this->staff ['0'] ['sid']) {
  900. $nsflag = false;
  901. break;
  902. }
  903. }
  904. // 该用户是否能审批
  905. if (empty ( $receiptDetail ) || $nsflag)
  906. return "/approvalExpenses/pendApproval";
  907. $verifyDetail = $verify->getOne ( array (
  908. 'where' => ' vid =' . $receiptDetail ['verify'],
  909. 'asArray' => true
  910. ) );
  911. $verifyString = $verifyDetail ['staff'];
  912. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  913. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  914. if (empty ( $opinion )) {
  915. if ($status == 3)
  916. $opinion = "终止";
  917. else
  918. $opinion = "同意支付";
  919. }
  920. $nowStaff = 0;
  921. $nowStaffList = array ();
  922. if (empty ( $verifyStaff )) {
  923. // 还需加入是否已经进入角色审批
  924. if ($verifyDetail [0] [1] == 'ROLE') {
  925. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  926. foreach ( $vStaffString as $key => $value ) {
  927. $staffK = explode ( "_", $value );
  928. if ($staffK [0] != $this->staff [0] ['sid'])
  929. array_push ( $nowStaffList, $staffK [0] );
  930. }
  931. // print_r($verifyDetail);
  932. // die;
  933. if (! empty ( $nowStaffList )) {
  934. $nowStaff = implode ( ',', $nowStaffList );
  935. $verifyStaff = array (
  936. $this->staff [0] ['sid'] . "_R" => array (
  937. 'date' => date ( 'Y-m-d' ),
  938. 'opinion' => $opinion,
  939. 'status' => $status,
  940. 'nextStaff' => $verifyDetail [0] [0],
  941. 'ROLE' => 1
  942. )
  943. );
  944. } else {
  945. $nowStaff = $verifyDetail [1] [0];
  946. $verifyStaff = array (
  947. $this->staff [0] ['sid'] . "_R" => array (
  948. 'date' => date ( 'Y-m-d' ),
  949. 'opinion' => $opinion,
  950. 'status' => $status,
  951. 'nextStaff' => $verifyDetail [1] [0]
  952. )
  953. );
  954. }
  955. } else {
  956. if ($verifyDetail [1] [1] == 'ROLE') {
  957. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  958. // echo "dd";
  959. foreach ( $vStaffString as $key => $value ) {
  960. $staffK = explode ( "_", $value );
  961. array_push ( $nowStaffList, $staffK [0] );
  962. }
  963. $nowStaff = implode ( ',', $nowStaffList );
  964. $verifyStaff = array (
  965. $this->staff [0] ['sid'] => array (
  966. 'date' => date ( 'Y-m-d' ),
  967. 'opinion' => $opinion,
  968. 'status' => $status,
  969. 'nextStaff' => $verifyDetail [1] [0],
  970. 'ROLE' => 1
  971. )
  972. );
  973. } else {
  974. $nowStaff = $verifyDetail [1] [0];
  975. $verifyStaff = array (
  976. $this->staff [0] ['sid'] => array (
  977. 'date' => date ( 'Y-m-d' ),
  978. 'opinion' => $opinion,
  979. 'status' => $status,
  980. 'nextStaff' => $verifyDetail [1] [0]
  981. )
  982. );
  983. }
  984. }
  985. if ($status == 3)
  986. $verifyStaff = array (
  987. 'final' => $status,
  988. $this->staff [0] ['sid'] => array (
  989. 'date' => date ( 'Y-m-d' ),
  990. 'opinion' => $opinion,
  991. 'status' => $status
  992. )
  993. );
  994. $vStaffString = json_encode ( $verifyStaff );
  995. $receipt->nowStaff = $nowStaff;
  996. $receipt->verifyStaff = $vStaffString;
  997. } else {
  998. $VS = end ( $verifyStaff );
  999. // 非角色审批
  1000. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  1001. $nextStaff = 0;
  1002. $roleSTF = false;
  1003. foreach ( $verifyDetail as $key => $value ) {
  1004. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  1005. if (isset ( $verifyDetail [$key + 1] )) {
  1006. $nextStaff = $verifyDetail [$key + 1] [0];
  1007. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  1008. $roleSTF = true;
  1009. }
  1010. break;
  1011. }
  1012. }
  1013. if (! $roleSTF) {
  1014. $nowStaff = $nextStaff;
  1015. $verifyStaff [$this->staff [0] ['sid']] = array (
  1016. 'date' => date ( 'Y-m-d' ),
  1017. 'opinion' => $opinion,
  1018. 'status' => $status,
  1019. 'nextStaff' => $nextStaff
  1020. );
  1021. } else {
  1022. // 获取角色下的所有用户ID
  1023. $nowStaffList = array ();
  1024. foreach ( $verifyDetail as $vfk ) {
  1025. if ($vfk [1] == 'ROLE') {
  1026. $vStaffString = json_decode ( $vfk [3] );
  1027. foreach ( $vStaffString as $key => $value ) {
  1028. $staffK = explode ( "_", $value );
  1029. array_push ( $nowStaffList, $staffK [0] );
  1030. }
  1031. }
  1032. }
  1033. $nowStaff = implode ( ',', $nowStaffList );
  1034. $verifyStaff [$this->staff [0] ['sid']] = array (
  1035. 'date' => date ( 'Y-m-d' ),
  1036. 'opinion' => $opinion,
  1037. 'status' => $status,
  1038. 'nextStaff' => $nextStaff,
  1039. 'ROLE' => 0
  1040. );
  1041. }
  1042. if ($status == 3) {
  1043. $verifyStaff ['final'] = $status;
  1044. $verifyStaff [$this->staff [0] ['sid']] = array (
  1045. 'date' => date ( 'Y-m-d' ),
  1046. 'opinion' => $opinion,
  1047. 'status' => $status
  1048. );
  1049. }
  1050. $vStaffString = json_encode ( $verifyStaff );
  1051. $receipt->nowStaff = $nowStaff;
  1052. $receipt->verifyStaff = $vStaffString;
  1053. }
  1054. // 角色审批
  1055. if (isset ( $VS ['ROLE'] )) {
  1056. // 找出角色人 当前审批角色组
  1057. $verifyJSStaff = array ();
  1058. $nowStaffList2 = array ();
  1059. foreach ( $verifyDetail as $key => $value ) {
  1060. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  1061. $verifyJSStaff = json_decode ( $value [3] );
  1062. foreach ( $verifyJSStaff as $m ) {
  1063. $staffK = explode ( "_", $m );
  1064. array_push ( $nowStaffList2, $staffK [0] );
  1065. }
  1066. // print_r($nowStaffList2);
  1067. }
  1068. }
  1069. $RoleVerifyStaff = array ();
  1070. foreach ( $verifyStaff as $key => $value ) {
  1071. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  1072. foreach ( $nowStaffList2 as $m ) {
  1073. if ($key == $m . "_R")
  1074. $RoleVerifyStaff [$key] = $value;
  1075. }
  1076. }
  1077. }
  1078. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  1079. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  1080. // 下一个审批人ID
  1081. $nextStaff = 0;
  1082. $falg = false;
  1083. foreach ( $verifyDetail as $key => $value ) {
  1084. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  1085. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  1086. $falg = true;
  1087. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  1088. $nowStaffList = array ();
  1089. foreach ( $vStaffString as $v ) {
  1090. $staffK = explode ( "_", $v );
  1091. array_push ( $nowStaffList, $staffK [0] );
  1092. }
  1093. $nowStaff = implode ( ',', $nowStaffList );
  1094. $nextStaff = $verifyDetail [$key + 1] [0];
  1095. } elseif (isset ( $verifyDetail [$key + 1] )) {
  1096. $nextStaff = $verifyDetail [$key + 1] [0];
  1097. $nowStaff = $nextStaff;
  1098. } else
  1099. $nowStaff = '';
  1100. break;
  1101. }
  1102. }
  1103. if ($falg)
  1104. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  1105. 'date' => date ( 'Y-m-d' ),
  1106. 'opinion' => $opinion,
  1107. 'status' => $status,
  1108. 'nextStaff' => $nextStaff,
  1109. 'ROLE' => 1
  1110. );
  1111. else
  1112. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  1113. 'date' => date ( 'Y-m-d' ),
  1114. 'opinion' => $opinion,
  1115. 'status' => $status,
  1116. 'nextStaff' => $nextStaff
  1117. );
  1118. // print_r($verifyStaff);
  1119. // echo $nowStaff;die;
  1120. } else { // 进入下一个角色或者审批人
  1121. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  1122. //
  1123. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  1124. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  1125. 'date' => date ( 'Y-m-d' ),
  1126. 'opinion' => $opinion,
  1127. 'status' => $status,
  1128. 'nextStaff' => $VS ['nextStaff'],
  1129. 'ROLE' => 1
  1130. );
  1131. // print_r($verifyStaff);
  1132. // die;
  1133. }
  1134. if ($status == 3) {
  1135. $verifyStaff ['final'] = $status;
  1136. $verifyStaff [$this->staff [0] ['sid']] = array (
  1137. 'date' => date ( 'Y-m-d' ),
  1138. 'opinion' => $opinion,
  1139. 'status' => $status
  1140. );
  1141. }
  1142. $vStaffString = json_encode ( $verifyStaff );
  1143. $receipt->verifyStaff = $vStaffString;
  1144. $receipt->nowStaff = $nowStaff;
  1145. }
  1146. // print_r($verifyStaff);die;
  1147. }
  1148. // print_r($verifyDetail);
  1149. $roleKey = 0;
  1150. $roleId = 0;
  1151. $verifyDetailCopy = array ();
  1152. foreach ( $verifyDetail as $k => $v ) {
  1153. if ($v [1] == 'ROLE') {
  1154. $roleId = $v [0];
  1155. $roleVerify = json_decode ( $v [3], true );
  1156. $roleKey = $k;
  1157. $roleArray = array ();
  1158. foreach ( $roleVerify as $o => $p ) {
  1159. $staffID = explode ( '_', $p );
  1160. $exp = array (
  1161. 0 => $staffID [0],
  1162. 1 => $staffID [1]
  1163. );
  1164. array_push ( $roleArray, $exp );
  1165. }
  1166. $verifyDetailCopy [$v [0]] = $roleArray;
  1167. }
  1168. }
  1169. // print_r($verifyDetail);
  1170. foreach ( $verifyDetailCopy as $k => $v ) {
  1171. foreach ( $verifyDetail as $m => $n ) {
  1172. if ($n [0] == $k) {
  1173. array_splice ( $verifyDetail, $m, 1, $v );
  1174. }
  1175. }
  1176. }
  1177. Doo::loadModel ( "receiptLog" );
  1178. $receiptLog = new receiptLog ();
  1179. // 审批日志
  1180. if (! isset ( $verifyStaff ['final'] )) {
  1181. if (! empty ( $roleId )) {
  1182. Doo::loadModel ( "role" );
  1183. $role = new role ();
  1184. $roleInfo = $role->getOne ( array (
  1185. 'where' => 'rid=' . $roleId,
  1186. 'asArray' => true
  1187. ) );
  1188. $receiptLog->rolename = $roleInfo ['name'];
  1189. }
  1190. $receiptLog->username = $this->staff [0] ['username'];
  1191. $receiptLog->uid = $this->staff [0] ['sid'];
  1192. $receiptLog->date = date ( "Y-m-d" );
  1193. $receiptLog->opinion = $opinion;
  1194. $receiptLog->img = $this->staff [0] ['avatar'];
  1195. $receiptLog->status = 1;
  1196. $receiptLog->rid = $rid;
  1197. $receiptLog->insert ();
  1198. }
  1199. if (isset ( $verifyStaff ['final'] )) { // rDetail
  1200. $receipt->verifyBreakup = $verifyString;
  1201. $receipt->status = 3;
  1202. $receiptDetailObj->status = 3;
  1203. $receiptDetailObj->update ( array (
  1204. 'where' => 'rid=' . $rid
  1205. ) );
  1206. if (! empty ( $roleId )) {
  1207. Doo::loadModel ( "role" );
  1208. $role = new role ();
  1209. $roleInfo = $role->getOne ( array (
  1210. 'where' => 'rid=' . $roleId,
  1211. 'asArray' => true
  1212. ) );
  1213. $receiptLog->rolename = $roleInfo ['name'];
  1214. }
  1215. $receiptLog->username = $this->staff [0] ['username'];
  1216. $receiptLog->uid = $this->staff [0] ['sid'];
  1217. $receiptLog->date = date ( "Y-m-d" );
  1218. $receiptLog->opinion = $opinion;
  1219. $receiptLog->img = $this->staff [0] ['avatar'];
  1220. $receiptLog->status = 3;
  1221. $receiptLog->rid = $rid;
  1222. $receiptLog->insert ();
  1223. // 微信企业号通知
  1224. // $this->setWXMsg ( $rid, 3 );
  1225. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  1226. $receipt->status = 1;
  1227. $reviseSum = 0;
  1228. $receipt->verifyBreakup = $verifyString;
  1229. $receiptDetailObj = new receiptDetail ();
  1230. $receiptDetailObj->status = 1;
  1231. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  1232. $receiptDetailObj->update ( array (
  1233. 'where' => 'rid=' . $rid
  1234. ) );
  1235. $dateArray = explode ( "-", $receiptDetail ['date'] );
  1236. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  1237. $stat = $statistics->getOne ( array (
  1238. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  1239. 'asArray' => true
  1240. ) );
  1241. if (empty ( $stat )) {
  1242. $statistics->date = $receiptDetail ['date'];
  1243. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  1244. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  1245. $statistics->agPrice = $receiptDetail ['sum'];
  1246. $statistics->rePrice = $reviseSum;
  1247. $statistics->insert ();
  1248. } else {
  1249. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  1250. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  1251. $statistics->update ( array (
  1252. 'where' => 'sid=' . $stat ['sid']
  1253. ) );
  1254. }
  1255. $dateArray = explode ( "-", $receiptDetail ['date'] );
  1256. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  1257. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  1258. foreach ( $accountItem ['cSum'] as $key => $value ) {
  1259. if ($key == "trainSum") {
  1260. $iStatistics = $itemStatistics->getOne ( array (
  1261. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  1262. 'asArray' => true
  1263. ) );
  1264. if (empty ( $iStatistics )) {
  1265. $itemStatistics->cid = $receiptDetail ['cid'];
  1266. $itemStatistics->staff = $receiptDetail ['staff'];
  1267. $itemStatistics->price = $receiptDetail ['sum'];
  1268. $itemStatistics->itemCategory = $this->TRAIN;
  1269. $itemStatistics->date = $receiptDetail ['date'];
  1270. $itemStatistics->insert ();
  1271. } else {
  1272. if (! empty ( $value )) {
  1273. $itemStatistics->price = $receiptDetail ['sum'] + $iStatistics ['price'];
  1274. $itemStatistics->update ( array (
  1275. 'where' => 'sid=' . $iStatistics ['sid']
  1276. ) );
  1277. }
  1278. }
  1279. }
  1280. }
  1281. $receipt->pastDate = date ( "Y-m-d" );
  1282. // 微信企业号通知
  1283. // $this->setWXMsg ( $rid, 1 );
  1284. }
  1285. $receipt->update ( array (
  1286. 'where' => ' rid = ' . $rid
  1287. ) );
  1288. }
  1289. return "/approvalExpenses/pendApproval";
  1290. }
  1291. /**
  1292. * 培训班结算--撤回
  1293. */
  1294. function receiptTrainApprovalBackDo() {
  1295. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  1296. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1297. if (! empty ( $ridKey )) {
  1298. Doo::loadClass ( 'XDeode' );
  1299. $XDeode = new XDeode ( 5 );
  1300. $rid = $XDeode->decode ( $ridKey );
  1301. // 操作记录
  1302. Doo::loadModel ( "receipt" );
  1303. $receipt = new receipt ();
  1304. Doo::loadModel ( "receiptLog" );
  1305. $receiptLog = new receiptLog ();
  1306. Doo::loadModel ( "verify" );
  1307. $verify = new verify ();
  1308. $receiptInfo = $receipt->getOne ( array (
  1309. 'where' => 'rid=' . $rid . ' and status=2',
  1310. 'asArray' => true
  1311. ) );
  1312. if (empty ( $receiptInfo )) {
  1313. echo json_encode ( array (
  1314. 'status' => 2
  1315. ) );
  1316. die ();
  1317. }
  1318. $vr = $verify->getOne ( array (
  1319. 'where' => 'vid=' . $receiptInfo ['verify'],
  1320. 'asArray' => true
  1321. ) );
  1322. $jd = json_decode ( $vr ['staff'] );
  1323. $roleId = 0;
  1324. foreach ( $jd as $key => $value ) {
  1325. if ($value [1] == 'ROLE') {
  1326. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  1327. if ($pos !== false) {
  1328. $roleId = $value [0];
  1329. }
  1330. }
  1331. }
  1332. // 审批日志
  1333. // echo $roleId;die;
  1334. if (! empty ( $roleId )) {
  1335. Doo::loadModel ( "role" );
  1336. $role = new role ();
  1337. $roleInfo = $role->getOne ( array (
  1338. 'where' => 'rid=' . $roleId,
  1339. 'asArray' => true
  1340. ) );
  1341. $receiptLog->rolename = $roleInfo ['name'];
  1342. }
  1343. $receiptLog->username = $this->staff [0] ['username'];
  1344. $receiptLog->uid = $this->staff [0] ['sid'];
  1345. $receiptLog->date = date ( "Y-m-d" );
  1346. $receiptLog->opinion = $opinion;
  1347. $receiptLog->img = $this->staff [0] ['avatar'];
  1348. $receiptLog->status = 4;
  1349. $receiptLog->rid = $rid;
  1350. $receiptLog->insert ();
  1351. $receipt->status = 4;
  1352. $receipt->update ( array (
  1353. 'where' => 'rid=' . $rid
  1354. ) );
  1355. // 微信企业号通知
  1356. $this->setWXMsg ( $rid, 2 );
  1357. echo json_encode ( array (
  1358. 'status' => 1
  1359. ) );
  1360. die ();
  1361. }
  1362. echo json_encode ( array (
  1363. 'status' => 2
  1364. ) );
  1365. die ();
  1366. }
  1367. function receiptTrainItemEdiDo(){
  1368. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  1369. $riidKey = $this->get_args ( 'riidKey' ) ? $this->get_args ( 'riidKey' ) : "";
  1370. // 支出项信息
  1371. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  1372. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  1373. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1374. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  1375. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  1376. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  1377. Doo::loadClass ( 'XDeode' );
  1378. $XDeode = new XDeode ( 5 );
  1379. $rid = $XDeode->decode ( $ridKey );
  1380. $riid = $XDeode->decode ( $riidKey );
  1381. if (! is_numeric ( $rid ) || ! is_numeric ( $riid )) {
  1382. die ( 'illegal request--id' );
  1383. }
  1384. Doo::loadModel ( 'receipt' );
  1385. $receipt = new receipt ();
  1386. Doo::loadModel ( 'RItem' );
  1387. $RItem = new RItem ();
  1388. Doo::loadModel ( 'receiptDetail' );
  1389. $rDetail = $receipt->getReceiptByRid ( $rid );
  1390. if (! ($rDetail ['status'] == 5 || $rDetail ['status'] == 4 || $rDetail ['status'] == 2)) {
  1391. die ( 'illegal request-status' );
  1392. }
  1393. $detail = $RItem->getRItemByRiid ( $riid );
  1394. if (empty ( $detail )) {
  1395. die ( 'illegal request-dataError' );
  1396. }
  1397. //创建人可以删除协助人
  1398. if(!($rDetail['staff']==$this->staff [0] ['sid'])){
  1399. if (! ($this->staff [0] ['sid'] == $detail ['createrId'] || $this->staff [0] ['username'] == $detail ['creater'])) {
  1400. die ( 'illegal request-sidError' );
  1401. }
  1402. }
  1403. if ( ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  1404. //--------------------移除支出信息
  1405. $this->_receiptTrainItemDel($RItem, $rDetail, $riid, $rid, $detail, $receipt);
  1406. //---------------------添加支出信息
  1407. $receiptDetail = new receiptDetail ();
  1408. $receipt = new receipt ();
  1409. $RItem = new RItem ();
  1410. $order = array (
  1411. "\r\n",
  1412. "\n",
  1413. "\r"
  1414. );
  1415. $replace = '<br/>';
  1416. $describe = str_replace ( $order, $replace, $describe );
  1417. $itemData = array (
  1418. 'rid' => $rid,
  1419. 'item' => $item,
  1420. 'price' => $price,
  1421. 'date' => $date,
  1422. 'inputer' => $inputer,
  1423. 'identifying'=>$detail['identifying'],
  1424. 'describe' => $describe,
  1425. 'creater' => $this->staff['0']['username'],
  1426. 'createrId' => $this->staff['0']['sid'],
  1427. 'creatDate' => date ( "Y-m-d H:i:s" )
  1428. );
  1429. if($payType=='company'){
  1430. $itemData += array (
  1431. 'payType' => 1
  1432. );
  1433. }
  1434. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  1435. $XDeode = new XDeode ( 7 );
  1436. if($payType=='company'){
  1437. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  1438. }else{
  1439. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  1440. }
  1441. }else
  1442. die ( 'illegal request-dataError' );
  1443. }
  1444. //移除培训班结算-支出列
  1445. private function _receiptTrainItemDel($RItem,$rDetail,$riid,$rid,$detail,$receipt){
  1446. $RItem->delete ( array (
  1447. 'where' => 'riid=' . $riid
  1448. ) );
  1449. // 更新费用合计金额
  1450. $rInfo = $receipt->getReceiptByRid ( $rid );
  1451. $receipt = new receipt ();
  1452. $receipt->sum = $rDetail ['sum'] - $detail ['price'];
  1453. $receipt->update ( array (
  1454. 'where' => 'rid=' . $rid
  1455. ) );
  1456. Doo::loadModel ( 'receiptDetail' );
  1457. $receiptDetail = new receiptDetail ();
  1458. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, $detail ['item'], '培训班费用' );
  1459. $receiptDetail = new receiptDetail ();
  1460. $rdInfo ['price'] -= $detail ['price'];
  1461. $receiptDetail->price = $rdInfo ['price'];
  1462. $receiptDetail->update ( array (
  1463. 'where' => 'rid=' . $rid . ' and item like "' . $detail ['item'] . '" and itemCategory like "培训班费用"'
  1464. ) );
  1465. //汇总金额--提交审批之后有 支出项时 需要更新汇总
  1466. if($detail['payType']==1){
  1467. Doo::loadModel ( "statistics" );
  1468. $statistics = new statistics ();
  1469. $dateArray = explode ( "-", $rInfo ['date'] );
  1470. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  1471. $stat = $statistics->getOne ( array (
  1472. 'where' => 'staff=' . $rInfo ['staff'] . $dateCondition,
  1473. 'asArray' => true
  1474. ) );
  1475. if (!empty($stat)){
  1476. $statistics->rePrice = $stat ['rePrice'] - $detail['price'];
  1477. $statistics->update ( array (
  1478. 'where' => 'sid=' . $stat ['sid']
  1479. ) );
  1480. }
  1481. }
  1482. }
  1483. /**
  1484. * 移除培训班结算-支出列
  1485. */
  1486. function receiptTrainItemDelDo() {
  1487. $riidKey = isset ( $this->params ['riidKey'] ) ? $this->params ['riidKey'] : '';
  1488. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  1489. Doo::loadClass ( 'XDeode' );
  1490. $XDeode = new XDeode ( 5 );
  1491. $rid = $XDeode->decode ( $ridKey );
  1492. $riid = $XDeode->decode ( $riidKey );
  1493. if (! is_numeric ( $rid ) || ! is_numeric ( $riid )) {
  1494. die ( 'illegal request--id' );
  1495. }
  1496. Doo::loadModel ( 'receipt' );
  1497. $receipt = new receipt ();
  1498. Doo::loadModel ( 'RItem' );
  1499. $RItem = new RItem ();
  1500. $rDetail = $receipt->getReceiptByRid ( $rid );
  1501. if (! ($rDetail ['status'] == 5 || $rDetail ['status'] == 4 || $rDetail ['status'] == 2)) {
  1502. die ( 'illegal request-status' );
  1503. }
  1504. $detail = $RItem->getRItemByRiid ( $riid );
  1505. if (empty ( $detail )) {
  1506. die ( 'illegal request-dataError' );
  1507. }
  1508. if (! ($this->staff [0] ['sid'] == $detail ['createrId'] || $this->staff [0] ['username'] == $detail ['creater'])) {
  1509. die ( 'illegal request-sidError' );
  1510. }
  1511. $this->_receiptTrainItemDel($RItem, $rDetail, $riid, $rid, $detail, $receipt);
  1512. $XDeode = new XDeode ( 7 );
  1513. if ($rDetail ['status'] == 2) {
  1514. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  1515. } else {
  1516. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  1517. }
  1518. }
  1519. /**
  1520. * 生成对冲收款
  1521. */
  1522. function invoiceReceivablesStrikeAddDo() {
  1523. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  1524. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  1525. if (empty ( $iidKey ) || empty ( $ridKey )) {
  1526. die ( 'illegal request--idKey' );
  1527. }
  1528. Doo::loadClass ( 'XDeode' );
  1529. $XDeode = new XDeode ( 5 );
  1530. $XDeode7 = new XDeode ( 7 );
  1531. $iid = $XDeode->decode ( $iidKey );
  1532. $rid = $XDeode7->decode ( $ridKey );
  1533. Doo::loadModel ( 'invoiceReceivables' );
  1534. $invoiceReceivables = new invoiceReceivables ();
  1535. Doo::loadModel ( 'invoice' );
  1536. $invoice = new invoice ();
  1537. Doo::loadModel ( 'invoiceTraining' );
  1538. $invoiceTraining = new invoiceTraining ();
  1539. Doo::loadModel ( 'invoiceOperationLog' );
  1540. $invoiceOperationLog = new invoiceOperationLog ();
  1541. Doo::loadModel ( 'receipt' );
  1542. $receipt = new receipt ();
  1543. Doo::loadModel ( 'receiptTraining' );
  1544. $receiptTraining = new receiptTraining ();
  1545. $detail = $invoice->getInvoiceByIid ( $iid );
  1546. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $detail ['trainId'] );
  1547. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1548. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1549. if (empty ( $invoiceTrainingDetail ) || empty ( $detail ) || $detail ['untreadStatus'] == 3 || ! empty ( $detail ['irid'] )) {
  1550. die ( 'illegal request--trainId-status-irid' );
  1551. }
  1552. // 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  1553. // 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  1554. // 添加收款
  1555. $item = array (
  1556. 'iid' => $detail ['iid'],
  1557. 'bindStatus' => 1,
  1558. 'bindPrice' => $detail ['invoicePrice'],
  1559. 'inputStaff' => $this->staff [0] ['username'],
  1560. 'source' => 2,
  1561. 'bindDate' => date ( "Y-m-d" ),
  1562. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1563. 'receivablesPrice' => $detail ['invoicePrice'],
  1564. 'OriginalPrice' => $detail ['invoicePrice'],
  1565. 'receivablesMessage' => $receiptTrainingDetail ['trainName'] . '冲账',
  1566. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1567. 'receivablesBank' => '财务录入',
  1568. 'receivablesDate' => date ( "Y-m-d" ),
  1569. 'inputStaff' => $this->staff [0] ['username'],
  1570. 'date' => date ( "Y-m-d" ),
  1571. 'receivablesCategory' => $detail ['cid'] . ":" . $detail ['categoryName'],
  1572. 'receivablesStaff' => $detail ['sid'] . "-" . $detail ['userName']
  1573. );
  1574. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1575. // 更新发票绑定收款
  1576. $iridString = "";
  1577. if (empty ( $detail ['irid'] ))
  1578. $iridString = $irid;
  1579. else
  1580. $iridString = $detail ['irid'] . ',' . $irid;
  1581. $item = array (
  1582. 'iid' => $detail ['iid'],
  1583. 'irid' => $iridString,
  1584. 'untreadStatus' => 3,
  1585. 'bindTime' => date ( "Y-m-d H:i:s" )
  1586. );
  1587. $invoice->setInvoiceByCondition ( $item );
  1588. // 在是对冲收款 确保已收款不被删除
  1589. // Doo::loadModel ( 'RIExtend' );
  1590. // $RIExtend = new RIExtend ();
  1591. // 操作日志
  1592. $item = array (
  1593. 'date' => date ( "Y-m-d H:i:s" ),
  1594. 'operation' => "收款" . $invoiceTrainingDetail ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  1595. 'status' => 8,
  1596. 'img' => $this->staff [0] ['avatar'],
  1597. 'username' => $this->staff [0] ['username'],
  1598. 'uid' => $this->staff [0] ['sid'],
  1599. 'category' => $this->staff [0] ['category'],
  1600. 'iid' => $detail ['iid']
  1601. );
  1602. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1603. // 是否加入统计--冲账不需要加入汇总
  1604. return '/receiptTrainInvoice/approval/' . $ridKey . '.html';
  1605. }
  1606. /**
  1607. * 培训班结算--执行
  1608. */
  1609. function receiptTrainImplementDo() {
  1610. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  1611. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1612. if (! empty ( $ridKey )) {
  1613. Doo::loadModel ( 'receipt' );
  1614. $receipt = new receipt ();
  1615. Doo::loadModel ( 'wasteBook' );
  1616. $wasteBook = new wasteBook ();
  1617. Doo::loadClass ( 'XDeode' );
  1618. $XDeode = new XDeode ( 5 );
  1619. $rid = $XDeode->decode ( $ridKey );
  1620. $rinfo = $receipt->getReceiptByRid ( $rid );
  1621. if (empty ( $rinfo )) {
  1622. die ( 'illegal request--rid' );
  1623. }
  1624. $accountType = '';
  1625. if ($rinfo ['Rtype'] == 1) {
  1626. if ($rinfo ['loanRid'] != 0)
  1627. $accountType = 2;
  1628. else
  1629. $accountType = 1;
  1630. } elseif ($rinfo ['Rtype'] == 2) {
  1631. $accountType = 4;
  1632. } elseif ($rinfo ['Rtype'] == 0) {
  1633. $accountType = 3;
  1634. } elseif ($rinfo ['Rtype'] == 3) {
  1635. $accountType = 12;
  1636. }
  1637. if (empty ( $accountType ))
  1638. die ( 'illegal request' );
  1639. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  1640. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  1641. if (empty ( $executeStaff )) {
  1642. $executeStaff = array (
  1643. $this->staff [0] ['sid'] => array (
  1644. 'date' => date ( 'Y-m-d' ),
  1645. 'opinion' => $implementOpinions,
  1646. 'status' => 1
  1647. )
  1648. );
  1649. } else {
  1650. $executeStaff [$this->staff [0] ['sid']] = array (
  1651. 'date' => date ( 'Y-m-d' ),
  1652. 'opinion' => $implementOpinions,
  1653. 'status' => 1
  1654. );
  1655. }
  1656. if (count ( $executeStaff ) == count ( $executeCopy )) {
  1657. // 费用执行没有
  1658. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rinfo ['rid'] );
  1659. if (empty ( $wbDetail )) {
  1660. die ( 'illegal request--wate' );
  1661. }
  1662. $receipt->executeStaff = json_encode ( $executeStaff );
  1663. $receipt->status = 8;
  1664. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  1665. $receipt->status = 9;
  1666. if ($rinfo ['status'] == 6) {
  1667. $receipt->loanDate = date ( "Y-m-d" );
  1668. }
  1669. $receipt->executeDate = date ( "Y-m-d" );
  1670. } else {
  1671. $receipt->executeStaff = json_encode ( $executeStaff );
  1672. }
  1673. $receipt->update ( array (
  1674. 'where' => 'rid=' . $rid
  1675. ) );
  1676. return '/hisImplement/train';
  1677. }
  1678. die ( 'illegal request-dataError' );
  1679. }
  1680. /**
  1681. * 生成执行流水
  1682. */
  1683. function receiptTrainImplementWateDo() {
  1684. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  1685. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1686. $amountTrain = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  1687. $expensesType = $this->get_args ( 'expensesType' ) ? $this->get_args ( 'expensesType' ) : "";
  1688. $actionType = $this->get_args ( 'actionType' ) ? $this->get_args ( 'actionType' ) : "";
  1689. if (! empty ( $actionType )) {
  1690. if ($actionType != 'NOTRAIN')
  1691. die ( 'illegal request--errorActionType' );
  1692. }
  1693. if (! empty ( $ridKey )) {
  1694. Doo::loadModel ( 'receipt' );
  1695. $receipt = new receipt ();
  1696. Doo::loadModel ( 'wasteBook' );
  1697. $wasteBook = new wasteBook ();
  1698. Doo::loadClass ( 'XDeode' );
  1699. $XDeode = new XDeode ( 5 );
  1700. $rid = $XDeode->decode ( $ridKey );
  1701. $rinfo = $receipt->getReceiptByRid ( $rid );
  1702. $amount=$rinfo['amount'];
  1703. if (empty ( $rinfo )) {
  1704. die ( 'illegal request--noData' );
  1705. }
  1706. $accountType = '';
  1707. if ($rinfo ['Rtype'] == 0) {
  1708. $accountType = 3;
  1709. $expensesType='EXPENDITURE';
  1710. } elseif ($rinfo ['Rtype'] == 1) {
  1711. if (! empty ( $rinfo ['accountItem'] )){
  1712. $accountType = 2;
  1713. if ($amount>=0){
  1714. $expensesType='EXPENDITURE';
  1715. }else{
  1716. $expensesType='INCOME';
  1717. }
  1718. }else{
  1719. $accountType = 1;
  1720. $expensesType='EXPENDITURE';
  1721. }
  1722. } elseif ($rinfo ['Rtype'] == 2) {
  1723. $accountType = 4;
  1724. $expensesType='EXPENDITURE';
  1725. } elseif ($rinfo ['Rtype'] == 3) {
  1726. $accountType = 12;
  1727. $amount=$amountTrain;
  1728. }
  1729. if (empty ( $accountType )) {
  1730. die ( 'illegal request--accountType' );
  1731. }
  1732. if (empty ( $bank ) || (! ($bank == 'CGBDeposit' || $bank == 'ICBCDeposit' || $bank == 'HUADeposit' || $bank == 'PersonalDeposit'))) {
  1733. die ( 'illegal request--Bank' );
  1734. }
  1735. if($accountType==12){
  1736. $receipt->amount = $amount;
  1737. $receipt->update ( array (
  1738. 'where' => 'rid=' . $rid
  1739. ) );
  1740. }
  1741. /*
  1742. // 更新借款汇款金额
  1743. if ($accountType == 1) {
  1744. Doo::loadModel ( 'loanReceipt' );
  1745. $loanReceipt = new loanReceipt ();
  1746. $loanReceipt->amount = $amount;
  1747. $loanReceipt->update ( array (
  1748. 'where' => ' rid = ' . $rinfo ['loanRid']
  1749. ) );
  1750. }
  1751. */
  1752. //汇款金额正数
  1753. $amount=abs($amount);
  1754. // $accountType = 12;
  1755. $accountBank = $bank;
  1756. if ($expensesType == "INCOME") {
  1757. $expensesTypeWaste = 1;
  1758. $accountPriceShow = $accountPrice = $amount;
  1759. } elseif ($expensesType == "EXPENDITURE") {
  1760. $expensesTypeWaste = 2;
  1761. $accountPriceShow = $amount;
  1762. $accountPrice = - $amount;
  1763. } else {
  1764. die ( 'illegal request--expensesType' );
  1765. }
  1766. // 公司流水记录
  1767. $abDetail = $wasteBook->getAccountBookByAid ( $expensesTypeWaste, $accountType, $rid );
  1768. // 银行
  1769. if (empty ( $abDetail )) {
  1770. $item = array (
  1771. 'dataID' => $rid,
  1772. 'expensesType' => $expensesTypeWaste,
  1773. 'accountType' => $accountType,
  1774. 'accountPriceShow' => $accountPriceShow,
  1775. 'accountPrice' => $accountPrice,
  1776. 'accountBank' => $accountBank,
  1777. 'category' => $rinfo ['category'] [0] ['title'],
  1778. 'cid' => $rinfo ['category'] [0] ['cid'],
  1779. 'name' => $rinfo ['staffDetail'] ['username'],
  1780. 'sid' => $rinfo ['staffDetail'] ['sid'],
  1781. 'inputDate' => date ( "Y-m-d H:i:s" )
  1782. );
  1783. $wasteBook->setAccountBookStatistics ( $item );
  1784. }
  1785. }
  1786. if (empty ( $actionType )) {
  1787. $XDeode = new XDeode ( 7 );
  1788. return '/receiptTrain/implement/' . $XDeode->encode ( $rid ) . '.html?trainEdiType=COLLECT';
  1789. } elseif ($actionType == 'NOTRAIN') {
  1790. $XDeode = new XDeode ( 5 );
  1791. return "/implement/" . $XDeode->encode ( $rid ) . ".html";
  1792. }
  1793. }
  1794. /**
  1795. * 费用流水
  1796. */
  1797. function receiptWasteBook() {
  1798. Doo::loadClass ( 'XDeode' );
  1799. $XDeode = new XDeode ( 5 );
  1800. Doo::loadModel ( 'receipt' );
  1801. $receipt = new receipt ();
  1802. $receiptList = $receipt->getReceiptByWaste ();
  1803. foreach ($receiptList as $key=>$value){
  1804. $receiptList[$key]['balance']='';
  1805. if($value['Rtype']==1){
  1806. if($value['isBK']==1){
  1807. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  1808. }
  1809. }
  1810. }
  1811. $data ['inputDate'] = date ( "Y-m-d H:i:s" );
  1812. $data ['receiptList'] = $receiptList;
  1813. $data ['memu'] = "receipt";
  1814. $data ['staff'] = $this->staff;
  1815. $data ['receiptMemu'] = 'receiptWasteBook';
  1816. $data ['verifyId'] = $this->verifyId;
  1817. $data ['executeId'] = $this->executeId;
  1818. $this->render ( "/receipt/receiptWasteBook", $data );
  1819. }
  1820. /**
  1821. * 费用流水新增
  1822. */
  1823. function receiptWasteBookAddDo() {
  1824. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  1825. if (empty ( $ridKey )) {
  1826. die ( 'illegal request--ridKey' );
  1827. }
  1828. $expensesType = $this->get_args ( 'expensesType' ) ? $this->get_args ( 'expensesType' ) : "";
  1829. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : "";
  1830. $expenditurePrice = $this->get_args ( 'expenditurePrice' ) ? $this->get_args ( 'expenditurePrice' ) : "";
  1831. $expenditureRemarks = $this->get_args ( 'expenditureRemarks' ) ? $this->get_args ( 'expenditureRemarks' ) : "";
  1832. $expenditureInputDate = $this->get_args ( 'expenditureInputDate' ) ? $this->get_args ( 'expenditureInputDate' ) : date ( "Y-m-d H:i:s" );
  1833. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : "";
  1834. $receivedPrice = $this->get_args ( 'receivedPrice' ) ? $this->get_args ( 'receivedPrice' ) : "";
  1835. $receivedRemarks = $this->get_args ( 'receivedRemarks' ) ? $this->get_args ( 'receivedRemarks' ) : "";
  1836. $receivedInputDate = $this->get_args ( 'receivedInputDate' ) ? $this->get_args ( 'receivedInputDate' ) : date ( "Y-m-d H:i:s" );
  1837. $expenditurePrice=str_replace(',','',$expenditurePrice);
  1838. $receivedPrice=str_replace(',','',$receivedPrice);
  1839. if (empty ( $expenditureBank ) || empty ( $receivedBank )) {
  1840. die ( 'illegal request--Bank' );
  1841. }
  1842. if ($expensesType == "INCOME") {
  1843. if(!is_numeric($receivedPrice)){
  1844. die ( 'illegal request--receivedPrice' );
  1845. }
  1846. } elseif ($expensesType == "EXPENDITURE") {
  1847. if(!is_numeric($expenditurePrice)){
  1848. die ( 'illegal request--expenditurePrice' );
  1849. }
  1850. }
  1851. Doo::loadClass ( 'XDeode' );
  1852. $XDeode = new XDeode ( 5 );
  1853. $rid = $XDeode->decode ( $ridKey );
  1854. Doo::loadModel ( 'receipt' );
  1855. $receipt = new receipt ();
  1856. $detail = $receipt->getReceiptByRid ( $rid );
  1857. if (empty ( $detail )) {
  1858. die ( 'illegal request--noData' );
  1859. }
  1860. $accountType = '';
  1861. if ($detail ['Rtype'] == 1) {
  1862. if (! empty ( $detail ['accountItem'] ))
  1863. $accountType = 2;
  1864. else
  1865. $accountType = 1;
  1866. } elseif ($detail ['Rtype'] == 2) {
  1867. $accountType = 4;
  1868. } elseif ($detail ['Rtype'] == 0) {
  1869. $accountType = 3;
  1870. } elseif ($detail ['Rtype'] == 3) {
  1871. $accountType = 12;
  1872. }
  1873. $accountPriceShow = $accountPrice = 0;
  1874. $expensesTypeWaste = 0;
  1875. $accountBank = '';
  1876. $inputDate = date ( "Y-m-d H:i:s" );
  1877. if ($expensesType == "INCOME") {
  1878. $expensesTypeWaste = 1;
  1879. $accountPriceShow = $receivedPrice;
  1880. $accountPrice = $receivedPrice;
  1881. $accountBank = $receivedBank;
  1882. $inputDate = $receivedInputDate;
  1883. } elseif ($expensesType == "EXPENDITURE") {
  1884. $expensesTypeWaste = 2;
  1885. $accountPriceShow = $expenditurePrice;
  1886. $accountPrice = - $expenditurePrice;
  1887. $accountBank = $expenditureBank;
  1888. $inputDate = $expenditureInputDate;
  1889. } else {
  1890. die ( 'illegal request--expensesType' );
  1891. }
  1892. $receipt = new receipt ();
  1893. $receipt->amount = $accountPriceShow;
  1894. $receipt->update ( array (
  1895. 'where' => 'rid=' . $rid
  1896. ) );
  1897. // 更新借款汇款金额
  1898. if ($accountType == 1) {
  1899. Doo::loadModel ( 'loanReceipt' );
  1900. $loanReceipt = new loanReceipt ();
  1901. $loanReceipt->amount = $accountPriceShow;
  1902. $loanReceipt->update ( array (
  1903. 'where' => ' rid = ' . $detail ['loanRid']
  1904. ) );
  1905. }
  1906. // 公司流水记录
  1907. Doo::loadModel ( 'wasteBook' );
  1908. $wasteBook = new wasteBook ();
  1909. $abDetail = $wasteBook->getAccountBookByAid ( $expensesTypeWaste, $accountType, $rid );
  1910. // 银行
  1911. if (empty ( $abDetail )) {
  1912. $item = array (
  1913. 'dataID' => $rid,
  1914. 'expensesType' => $expensesTypeWaste,
  1915. 'accountType' => $accountType,
  1916. 'accountPriceShow' => $accountPriceShow,
  1917. 'accountPrice' => $accountPrice,
  1918. 'accountBank' => $accountBank,
  1919. 'category' => $detail ['category'] [0] ['title'],
  1920. 'cid' => $detail ['category'] [0] ['cid'],
  1921. 'name' => $detail ['staffDetail'] ['username'],
  1922. 'sid' => $detail ['staffDetail'] ['sid'],
  1923. 'inputDate' => $inputDate
  1924. );
  1925. $wasteBook->setAccountBookStatistics ( $item );
  1926. }
  1927. return '/receiptWasteBook';
  1928. }
  1929. /**
  1930. * 培训班结算营收总计
  1931. */
  1932. function receiptTrainRevenue(){
  1933. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1934. Doo::loadModel ( 'receipt' );
  1935. $receipt = new receipt ();
  1936. //获得可查看的办事处
  1937. Doo::loadModel ( "receiptTrainManage" );
  1938. $invoiceCategoryManage = new receiptTrainManage ();
  1939. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  1940. if(empty($imcStaff)){
  1941. die ( 'illegal request--Insufficient Permissions' );
  1942. }
  1943. $cidList = array ();
  1944. foreach ( $imcStaff as $key => $value ) {
  1945. array_push ( $cidList, $value ['cid'] );
  1946. }
  1947. $cidString=implode ( ',', $cidList );
  1948. //初始化收款数据
  1949. $where=" where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and paidStatus=0 and invoiceTrainId!=0 ";
  1950. $sql="select invoiceTrainId,rid
  1951. from CLD_receipt as a
  1952. ".$where." and a.cid in (".$cidString.") ";
  1953. $receipt->initReceiptTrainRevenue($sql);
  1954. $unpaid=$receipt->getReceiptTrainByPaid(0,5,$cidString);
  1955. $paid=$receipt->getReceiptTrainByPaid(1,5,$cidString);
  1956. $MonthPriceList=$receipt->getReceiptTrainByYearChart($cidString);
  1957. $income=$month=$pay=$profit=array();
  1958. for ($i=1;$i<=12;$i++){
  1959. $flag=true;
  1960. array_push($month,date("Y").'-'.$i);
  1961. foreach ($MonthPriceList as $key=>$value){
  1962. if($key==$i){
  1963. $flag=false;
  1964. array_push($income,$value['ITprice']);
  1965. array_push($pay,$value['RIprice']);
  1966. array_push($profit,$value['ITprice']-$value['RIprice']);
  1967. }
  1968. }
  1969. if ($flag){
  1970. array_push($income,0);
  1971. array_push($pay,0);
  1972. array_push($profit,0);
  1973. }
  1974. }
  1975. $data ['income'] =json_encode ( $income );
  1976. $data ['pay'] =json_encode ( $pay );
  1977. $data ['profit'] =json_encode ( $profit );
  1978. $data ['month'] =json_encode ( $month );
  1979. $data ['paid'] = $paid;
  1980. $data ['unpaid'] = $unpaid;
  1981. $data ['memu'] = "receipt";
  1982. $data ['staff'] = $this->staff;
  1983. $data ['receiptMemu'] = 'receiptTrainRevenue';
  1984. $data ['verifyId'] = $this->verifyId;
  1985. $data ['executeId'] = $this->executeId;
  1986. $this->render ( "/receipt/receiptTrainRevenue", $data );
  1987. }
  1988. /**
  1989. * 所有培训班结算
  1990. */
  1991. function receiptTrainRevenueAchieve(){
  1992. //$paid = $this->get_args ( 'paid' ) ? $this->get_args ( 'paid' ) : '';
  1993. $paid =isset ( $this->params ['paid'] ) ? $this->params ['paid'] : 'ALL';
  1994. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  1995. $page_size = 12;
  1996. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1997. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1998. $get='/'.$paid ;//= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1999. Doo::loadModel ( 'receipt' );
  2000. $receipt = new receipt ();
  2001. Doo::loadModel ( 'L_category' );
  2002. $Lcategory = new L_category ();
  2003. Doo::loadClass ( 'XDeode' );
  2004. $XDeode = new XDeode ( 5 );
  2005. $cidSql=$cid='';
  2006. if(!empty($cidKey)){
  2007. $cid = $XDeode->decode ( $cidKey );
  2008. $cidSql=" and a.cid=".$cid." ";
  2009. }
  2010. //获得可查看的办事处
  2011. Doo::loadModel ( "receiptTrainManage" );
  2012. $invoiceCategoryManage = new receiptTrainManage ();
  2013. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  2014. $cidList = array ();
  2015. foreach ( $imcStaff as $key => $value ) {
  2016. array_push ( $cidList, $value ['cid'] );
  2017. }
  2018. if(!empty($cid)&&!in_array($cid, $cidList)){
  2019. die("illegal request-cid");
  2020. }
  2021. $cidString=implode ( ',', $cidList );
  2022. $categoryList = $Lcategory->getCategoryInCid ( $cidString );
  2023. $psSql='';$paidKey='';
  2024. if(!empty($paid)&&$paid!="ALL"){
  2025. if ($paid=='UNPAID'){
  2026. $paidKey='0';
  2027. }elseif($paid=='PAID'){
  2028. $paidKey='1';
  2029. }
  2030. $psSql=" and a.paidStatus=".$paidKey." ";
  2031. }
  2032. $dateArr = explode ( ':', $trainEndDate );
  2033. $D1 = $dateString = '';
  2034. $D2 = '';
  2035. if (! empty ( $trainEndDate )) {
  2036. $D1 = $dateArr [0];
  2037. if (isset ( $dateArr [1] ))
  2038. $D2 = $dateArr [1];
  2039. else
  2040. $D2 = '';
  2041. $dateString = $D1 . ":" . $D2;
  2042. }
  2043. $dateSql='';
  2044. if (! empty ( $D1 ) && ! empty ( $D2 )){
  2045. $dateSql = ' and trainEndDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2046. }elseif (! empty ( $D1 ) && empty ( $D2 )){
  2047. $dateSql = ' and trainEndDate like "%' . $D1 . '%" ';
  2048. }
  2049. $selectCount=" count(*) as count ";
  2050. $where=" where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 ".$psSql;
  2051. $sql = "select ".$selectCount."
  2052. from CLD_receipt as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid)
  2053. ".$where." and a.cid in (".$cidString.") ".$cidSql.$dateSql;
  2054. $action="receiptTrainRevenueAchieve";
  2055. $pageinfo = $this->get_page ( $sql, $page, $page_size, $action, $get, "" );
  2056. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2057. $rtpa=$receipt->getReceiptTrainByPaidAll($paidKey,$cid,$dateSql,$limit,$cidString,$where);
  2058. //金额合计功能
  2059. $sql="select invoiceTrainId,rid
  2060. from CLD_receipt as a
  2061. ".$where." and a.cid in (".$cidString.") ";
  2062. $receiptTrainPriceList=$receipt->getReceiptTrainSumByItid($sql);
  2063. $data ['receiptTrainPriceList']=$receiptTrainPriceList;
  2064. $data ['dateString']=$dateString;
  2065. $data ['cidKey']=$cidKey;
  2066. $data ['categoryList'] =$categoryList;
  2067. $data ['paid'] = $paid;
  2068. $data ['get'] = $get;
  2069. $data ['page'] = $pageinfo;
  2070. $data ['onpage'] = $page;
  2071. $data ['rtpa'] = $rtpa;
  2072. $data ['memu'] = "receipt";
  2073. $data ['staff'] = $this->staff;
  2074. $data ['receiptMemu'] = 'receiptTrainRevenue';
  2075. $data ['verifyId'] = $this->verifyId;
  2076. $data ['executeId'] = $this->executeId;
  2077. $this->render ( "/receipt/receiptTrainRevenueAchieve", $data );
  2078. }
  2079. function exportReceiptTrainExcel() {
  2080. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2081. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2082. $summaryJson = $this->get_args ( 'summaryJson' ) ? $this->get_args ( 'summaryJson' ) : "";
  2083. $aiListJson = $this->get_args ( 'aiListJson' ) ? $this->get_args ( 'aiListJson' ) : "";
  2084. Doo::loadClass ( 'XDeode' );
  2085. $XDeode = new XDeode ( 7 );
  2086. $rid = $XDeode->decode ( $ridKey );
  2087. if (! is_numeric ( $rid ))
  2088. die ( 'illegal request' );
  2089. Doo::loadModel ( 'receipt' );
  2090. $receipt = new receipt ();
  2091. Doo::loadModel ( 'receiptTraining' );
  2092. $receiptTraining = new receiptTraining ();
  2093. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2094. $receiptTrainDetail = $receiptTraining->getReceiptTrainingByRtid ( $rtidKey );
  2095. $summary=json_decode(urldecode($summaryJson), true);
  2096. $aiList=json_decode(urldecode($aiListJson), true);
  2097. $receiptLoanDetail=array();
  2098. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2099. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2100. }
  2101. //收入
  2102. Doo::loadModel ( 'invoice' );
  2103. $invoice = new invoice ();
  2104. Doo::loadModel ( 'invoiceTraining' );
  2105. $invoiceTraining = new invoiceTraining ();
  2106. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2107. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2108. //支出
  2109. Doo::loadModel ( 'RItem' );
  2110. $RItem = new RItem ();
  2111. $RItemList = $RItem->getRItemByRid ( $rid );
  2112. //讲师
  2113. Doo::loadModel ( 'RILecturer' );
  2114. $RILecturer = new RILecturer ();
  2115. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2116. Doo::loadClass ( 'receipt.func' );
  2117. excelData ( $receiptTrainDetail, $receiptDetail, $summary, $aiList,$receiptLoanDetail,$invoiceList,$RItemList,$RILecturerList,$invoiceTrainingDetail );
  2118. }
  2119. /**
  2120. * 获得审批流程
  2121. */
  2122. private function fnGetReceiptApprovalProcess($verifyList = array(), $verifyStaff = array()) {
  2123. Doo::loadModel ( 'role' );
  2124. $role = new role ();
  2125. Doo::loadModel ( 'staff' );
  2126. $staff = new staff ();
  2127. $flag = true;
  2128. $roleKey = $button = 0;
  2129. $endStaffArray = array ();
  2130. $roleArrayCopy = array ();
  2131. foreach ( $verifyList as $k => $v ) {
  2132. if ($v [1] == 'ROLE') {
  2133. if (! empty ( $verifyStaff )) {
  2134. $endStaffArray = end ( $verifyStaff );
  2135. if ($v [0] == $endStaffArray ['nextStaff']) {
  2136. $roleId = $v [0];
  2137. }
  2138. }
  2139. $roleVerify = json_decode ( $v [3], true );
  2140. $roleKey = $k;
  2141. $roleArray = array ();
  2142. $rolename = $role->getOne ( array (
  2143. 'where' => 'rid=' . $v [0],
  2144. 'asArray' => true
  2145. ) );
  2146. foreach ( $roleVerify as $o => $p ) {
  2147. $staffID = explode ( '_', $p );
  2148. $staffInfo = $staff->getOne ( array (
  2149. 'where' => 'sid=' . $staffID [0],
  2150. 'asArray' => true
  2151. ) );
  2152. // print_r($staffID);
  2153. $exp = array (
  2154. 0 => $staffInfo ['sid'],
  2155. 1 => $staffID [1],
  2156. 2 => $staffInfo ['avatar'],
  2157. 'date' => '',
  2158. 'date' => '',
  2159. 'opinion' => '',
  2160. 'status' => '',
  2161. 'rolename' => $rolename ['name']
  2162. );
  2163. array_push ( $roleArray, $exp );
  2164. }
  2165. $roleArrayCopy [$v [0]] = $roleArray;
  2166. // $verifyList[$k]['roleArray']=$roleArray;
  2167. }
  2168. // print_r($roleArray);
  2169. $verifyList [$k] ['date'] = "";
  2170. $verifyList [$k] ['opinion'] = "";
  2171. $verifyList [$k] ['status'] = "";
  2172. if (empty ( $verifyStaff )) {
  2173. $verifyList [$k] ['date'] = "";
  2174. $verifyList [$k] ['opinion'] = "";
  2175. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2176. $verifyList [$k] ['status'] = 4;
  2177. $button = 4;
  2178. $flag = false;
  2179. }
  2180. } else {
  2181. foreach ( $verifyStaff as $m => $u ) {
  2182. if ($v [0] == $m) {
  2183. $verifyList [$k] ['date'] = $u ['date'];
  2184. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2185. $verifyList [$k] ['status'] = $u ['status'];
  2186. $flag = false;
  2187. break;
  2188. }
  2189. }
  2190. $endStaffArray = end ( $verifyStaff );
  2191. if (isset ( $endStaffArray ['ROLE'] )) {
  2192. } else {
  2193. $endKey = key ( $verifyStaff );
  2194. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  2195. $button = 4;
  2196. $verifyList [$k] ['status'] = 4;
  2197. }
  2198. }
  2199. }
  2200. }
  2201. $rolename ['name'] = '';
  2202. if (! empty ( $roleId )) {
  2203. Doo::loadModel ( 'role' );
  2204. $role = new role ();
  2205. $rolename = $role->getOne ( array (
  2206. 'where' => 'rid=' . $roleId,
  2207. 'asArray' => true
  2208. ) );
  2209. }
  2210. if (! empty ( $verifyStaff ))
  2211. $endStaffArray = end ( $verifyStaff );
  2212. $KOP = false;
  2213. foreach ( $roleArrayCopy as $P => $A ) {
  2214. foreach ( $A as $MKI => $AVL ) {
  2215. if (! empty ( $verifyStaff )) {
  2216. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2217. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2218. $button = 4;
  2219. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2220. }
  2221. foreach ( $verifyStaff as $m => $u ) {
  2222. $AVLFK = $AVL [0] . '_R';
  2223. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2224. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2225. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2226. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2227. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2228. break;
  2229. }
  2230. }
  2231. } else {
  2232. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2233. $button = 4;
  2234. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2235. }
  2236. }
  2237. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2238. $KOP = true;
  2239. }
  2240. }
  2241. foreach ( $roleArrayCopy as $k => $v ) {
  2242. foreach ( $verifyList as $m => $n ) {
  2243. if ($n [0] == $k) {
  2244. array_splice ( $verifyList, $m, 1, $v );
  2245. }
  2246. }
  2247. }
  2248. return array (
  2249. 'verifyList' => $verifyList,
  2250. 'isApproval' => $button
  2251. );
  2252. }
  2253. function _GetFileEXT($filename) {
  2254. $pics = explode ( '.', $filename );
  2255. $num = count ( $pics );
  2256. return $pics [$num - 1];
  2257. }
  2258. /**
  2259. * 获取get或者POST值
  2260. * @param string $name 属性名称
  2261. * @return fixed 值
  2262. */
  2263. function get_args($name) {
  2264. if (isset ( $_GET [$name] )) {
  2265. if (is_array ( $_GET [$name] ))
  2266. return $_GET [$name];
  2267. else
  2268. return addslashes ( $_GET [$name] );
  2269. } elseif (isset ( $_POST [$name] )) {
  2270. if (is_array ( $_POST [$name] ))
  2271. return $_POST [$name];
  2272. else
  2273. return addslashes ( $_POST [$name] );
  2274. } else
  2275. return false;
  2276. }
  2277. function num_to_rmb($num) {
  2278. $c1 = "零壹贰叁肆伍陆柒捌玖";
  2279. $c2 = "分角元拾佰仟万拾佰仟亿";
  2280. // 精确到分后面就不要了,所以只留两个小数位
  2281. $num = round ( $num, 2 );
  2282. // 将数字转化为整数
  2283. $num = $num * 100;
  2284. if (strlen ( $num ) > 10) {
  2285. return "金额太大,请检查";
  2286. }
  2287. $i = 0;
  2288. $c = "";
  2289. while ( 1 ) {
  2290. if ($i == 0) {
  2291. // 获取最后一位数字
  2292. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  2293. } else {
  2294. $n = $num % 10;
  2295. }
  2296. // 每次将最后一位数字转化为中文
  2297. $p1 = substr ( $c1, 3 * $n, 3 );
  2298. $p2 = substr ( $c2, 3 * $i, 3 );
  2299. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  2300. $c = $p1 . $p2 . $c;
  2301. } else {
  2302. $c = $p1 . $c;
  2303. }
  2304. $i = $i + 1;
  2305. // 去掉数字最后一位了
  2306. $num = $num / 10;
  2307. // echo $num.'</br>';
  2308. $num = ( int ) $num;
  2309. // $num =floor($num);
  2310. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  2311. // echo $num.'</br>';
  2312. // 结束循环
  2313. if ($num == 0) {
  2314. break;
  2315. }
  2316. }
  2317. // echo $c.'</br>';
  2318. $j = 0;
  2319. $slen = strlen ( $c );
  2320. while ( $j < $slen ) {
  2321. // utf8一个汉字相当3个字符
  2322. $m = substr ( $c, $j, 6 );
  2323. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  2324. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  2325. $left = substr ( $c, 0, $j );
  2326. $right = substr ( $c, $j + 3 );
  2327. $c = $left . $right;
  2328. $j = $j - 3;
  2329. $slen = $slen - 3;
  2330. }
  2331. $j = $j + 3;
  2332. }
  2333. // 这个是为了去掉类似23.0中最后一个“零”字
  2334. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  2335. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  2336. }
  2337. // 将处理的汉字加上“整”
  2338. if (empty ( $c )) {
  2339. return "零元整";
  2340. } else {
  2341. return $c . "整";
  2342. }
  2343. }
  2344. /**
  2345. * 获得分页数据
  2346. * @param unknown_type $table
  2347. * @param unknown_type $condition
  2348. * @param unknown_type $on_page
  2349. * @param unknown_type $page_size
  2350. */
  2351. function get_page($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  2352. $page_c = "";
  2353. $page ['previous'] = $this->get_previous ( $on_page );
  2354. $page ['on_page'] = $on_page;
  2355. $total_count = $this->get_table_count ( $sql );
  2356. $total = intval ( $total_count / $page_size );
  2357. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  2358. $page ['total_data'] = $total_count;
  2359. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  2360. $i = 1;
  2361. $page_max = 1;
  2362. $page_width = 3;
  2363. if ($on_page >= $page_width) {
  2364. $page_max = intval ( $on_page / $page_width ) + 1;
  2365. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  2366. }
  2367. for(; $i <= $page ['total_page']; $i ++) {
  2368. if ($i == $on_page)
  2369. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  2370. else
  2371. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  2372. if ($i == ($page_width * $page_max))
  2373. break;
  2374. }
  2375. $page ['page'] = $page_c;
  2376. $page ['lower'] = (-- $on_page) * $page_size;
  2377. return $page;
  2378. }
  2379. /**
  2380. * 获取总页数
  2381. * @param unknown_type $table
  2382. * @param unknown_type $condition
  2383. */
  2384. public function get_table_count($sql="") {
  2385. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  2386. $query = Doo::db ()->query ( $sql );
  2387. $result = $query->fetch ();
  2388. return $result ['count'];
  2389. }
  2390. /**
  2391. * 获取上一页
  2392. * @param unknown_type $on_page
  2393. */
  2394. function get_previous($on_page = 1) {
  2395. return $on_page != 0 ? $on_page - 1 : $on_page;
  2396. }
  2397. }
  2398. ?>