ReceiptExtendController.php 95 KB

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