ReceiptExtendController.php 112 KB

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