ReceiptExtendController.php 98 KB

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