ReceiptExtendController.php 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476
  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 (! empty ( $rinfo ['accountItem'] )){
  2026. $accountType = 2;
  2027. if ($amount>=0){
  2028. $expensesType='EXPENDITURE';
  2029. }else{
  2030. $expensesType='INCOME';
  2031. }
  2032. }else{
  2033. $accountType = 1;
  2034. $expensesType='EXPENDITURE';
  2035. }
  2036. } elseif ($rinfo ['Rtype'] == 2) {
  2037. $accountType = 4;
  2038. $expensesType='EXPENDITURE';
  2039. } elseif ($rinfo ['Rtype'] == 3) {//培训班结算 收支类型
  2040. $accountType = 12;
  2041. Doo::loadClass ( 'authcode.func' );
  2042. $amountTrain=authcode($amountTrain);
  2043. if(!is_numeric ( $amountTrain )) {
  2044. die('illegal request--payType');
  2045. }
  2046. if($amountTrain>=0){
  2047. $expensesType='INCOME';
  2048. }else{
  2049. $expensesType='EXPENDITURE';
  2050. }
  2051. $amount=$amountTrain;
  2052. }
  2053. if (empty ( $accountType )) {
  2054. die ( 'illegal request--accountType' );
  2055. }
  2056. if (empty ( $bank ) || (! ($bank == 'CGBDeposit' || $bank == 'ICBCDeposit' || $bank == 'HUADeposit' || $bank == 'PersonalDeposit'))) {
  2057. die ( 'illegal request--Bank' );
  2058. }
  2059. if($accountType==12){
  2060. $receipt->amount = $amount;
  2061. $receipt->update ( array (
  2062. 'where' => 'rid=' . $rid
  2063. ) );
  2064. }
  2065. /*
  2066. // 更新借款汇款金额
  2067. if ($accountType == 1) {
  2068. Doo::loadModel ( 'loanReceipt' );
  2069. $loanReceipt = new loanReceipt ();
  2070. $loanReceipt->amount = $amount;
  2071. $loanReceipt->update ( array (
  2072. 'where' => ' rid = ' . $rinfo ['loanRid']
  2073. ) );
  2074. }
  2075. */
  2076. //汇款金额正数
  2077. $amount=abs($amount);
  2078. // $accountType = 12;
  2079. $accountBank = $bank;
  2080. if ($expensesType == "INCOME") {
  2081. $expensesTypeWaste = 1;
  2082. $accountPriceShow = $accountPrice = $amount;
  2083. } elseif ($expensesType == "EXPENDITURE") {
  2084. $expensesTypeWaste = 2;
  2085. $accountPriceShow = $amount;
  2086. $accountPrice = - $amount;
  2087. } else {
  2088. die ( 'illegal request--expensesType' );
  2089. }
  2090. // 公司流水记录
  2091. $abDetail = $wasteBook->getAccountBookByAid ( $expensesTypeWaste, $accountType, $rid );
  2092. // 银行
  2093. if (empty ( $abDetail )) {
  2094. $item = array (
  2095. 'dataID' => $rid,
  2096. 'expensesType' => $expensesTypeWaste,
  2097. 'accountType' => $accountType,
  2098. 'accountPriceShow' => $accountPriceShow,
  2099. 'accountPrice' => $accountPrice,
  2100. 'accountBank' => $accountBank,
  2101. 'category' => $rinfo ['category'] [0] ['title'],
  2102. 'cid' => $rinfo ['category'] [0] ['cid'],
  2103. 'name' => $rinfo ['staffDetail'] ['username'],
  2104. 'sid' => $rinfo ['staffDetail'] ['sid'],
  2105. 'inputDate' => $inputDate,
  2106. 'remarks'=>$remarks
  2107. );
  2108. $wasteBook->setAccountBookStatistics ( $item );
  2109. }
  2110. }
  2111. if (empty ( $actionType )) {
  2112. $XDeode = new XDeode ( 7 );
  2113. return '/receiptTrain/implement/' . $XDeode->encode ( $rid ) . '.html?trainEdiType=COLLECT';
  2114. } elseif ($actionType == 'NOTRAIN') {
  2115. $XDeode = new XDeode ( 5 );
  2116. if ($rinfo['Rtype']==1){
  2117. return "/implement/loan/" . $XDeode->encode ( $rid ) . ".html";
  2118. }elseif($rinfo['Rtype']==0){
  2119. return "/implement/receipt/" . $XDeode->encode ( $rid ) . ".html";
  2120. }elseif($rinfo['Rtype']==2){
  2121. return "/implement/public/" . $XDeode->encode ( $rid ) . ".html";
  2122. }
  2123. }
  2124. }
  2125. /**
  2126. * 费用流水
  2127. */
  2128. function receiptWasteBook() {
  2129. Doo::loadClass ( 'XDeode' );
  2130. $XDeode = new XDeode ( 5 );
  2131. Doo::loadModel ( 'receipt' );
  2132. $receipt = new receipt ();
  2133. $receiptList = $receipt->getReceiptByWaste ();
  2134. foreach ($receiptList as $key=>$value){
  2135. $receiptList[$key]['balance']='';
  2136. if($value['Rtype']==1){
  2137. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  2138. $receiptList[$key]['balanceABS']=sprintf("%.2f",abs($receiptList[$key]['balance']));
  2139. }elseif($value['Rtype']==3){
  2140. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  2141. $receiptList[$key]['payment']=$payment;
  2142. $receiptList[$key]['paymentABS']=sprintf("%.2f",abs($payment));
  2143. }
  2144. $receiptList[$key]['amountABS']=sprintf("%.2f",abs($value['amount']));
  2145. }
  2146. $data ['inputDate'] = date ( "Y-m-d H:i:s" );
  2147. $data ['receiptList'] = $receiptList;
  2148. $data ['memu'] = "receipt";
  2149. $data ['staff'] = $this->staff;
  2150. $data ['receiptMemu'] = 'receiptWasteBook';
  2151. $data ['verifyId'] = $this->verifyId;
  2152. $data ['executeId'] = $this->executeId;
  2153. $this->render ( "/receipt/receiptWasteBook", $data );
  2154. }
  2155. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  2156. // 收入合计
  2157. Doo::loadModel ( 'invoiceTraining' );
  2158. $invoiceTraining = new invoiceTraining ();
  2159. Doo::loadModel ( 'receipt' );
  2160. $receipt = new receipt ();
  2161. $invoiceTrainingDetail = array (
  2162. 'invoiceArriveAmount' => '0.00',
  2163. 'RIAmount' => '0.00',
  2164. 'invoiceTotalAmount' => '0.00',
  2165. 'invoiceCompanyAmount' => '0.00',
  2166. 'invoiceArriveAmountM'=>'0.00',
  2167. 'invoiceCompanyAmountM'=>'0.00'
  2168. );
  2169. if ($invoiceTrainId != 0) {
  2170. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  2171. }
  2172. $invoiceArriveAmount = $RIAmount = 0;
  2173. if (! empty ( $invoiceTrainingDetail )) {
  2174. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  2175. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  2176. }
  2177. // 备用金
  2178. $sum = 0;
  2179. if (! empty ( $trainLoanRid )) {
  2180. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  2181. foreach ($receiptLoanList as $key=>$value){
  2182. $sum+=$value['sum'];
  2183. }
  2184. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  2185. // $sum = $receiptLoanDetailBak ['sum'];
  2186. }
  2187. // 支出项金额详情
  2188. // 项目金额合计
  2189. Doo::loadModel ( 'RItem' );
  2190. $RItem = new RItem ();
  2191. Doo::loadModel ( 'accountItem' );
  2192. $accountItem = new accountItem ();
  2193. // 讲师获得
  2194. Doo::loadModel ( 'RILecturer' );
  2195. $RILecturer = new RILecturer ();
  2196. $RItemList = $RItem->getRItemByRid ($rid );
  2197. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2198. // 支出项金额详情
  2199. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  2200. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  2201. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  2202. return $payment;
  2203. }
  2204. /**
  2205. * 费用流水新增
  2206. */
  2207. function receiptWasteBookAddDo() {
  2208. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2209. if (empty ( $ridKey )) {
  2210. die ( 'illegal request--ridKey' );
  2211. }
  2212. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : "";
  2213. $receivedRemarks = $this->get_args ( 'receivedRemarks' ) ? $this->get_args ( 'receivedRemarks' ) : "";
  2214. $receivedInputDate = $this->get_args ( 'receivedInputDate' ) ? $this->get_args ( 'receivedInputDate' ) : date ( "Y-m-d H:i:s" );
  2215. $amountTrain = $this->get_args ( 'paymentAuthCode' ) ? $this->get_args ( 'paymentAuthCode' ) : '';
  2216. if ( empty ( $receivedBank )) {
  2217. die ( 'illegal request--Bank' );
  2218. }
  2219. /*
  2220. $expensesType = $this->get_args ( 'expensesType' ) ? $this->get_args ( 'expensesType' ) : "";
  2221. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : "";
  2222. $expenditurePrice = $this->get_args ( 'expenditurePrice' ) ? $this->get_args ( 'expenditurePrice' ) : "";
  2223. $expenditureRemarks = $this->get_args ( 'expenditureRemarks' ) ? $this->get_args ( 'expenditureRemarks' ) : "";
  2224. $expenditureInputDate = $this->get_args ( 'expenditureInputDate' ) ? $this->get_args ( 'expenditureInputDate' ) : date ( "Y-m-d H:i:s" );
  2225. $receivedPrice = $this->get_args ( 'receivedPrice' ) ? $this->get_args ( 'receivedPrice' ) : "";
  2226. if (empty ( $expenditureBank ) || empty ( $receivedBank )) {
  2227. die ( 'illegal request--Bank' );
  2228. }
  2229. $expenditurePrice=str_replace(',','',$expenditurePrice);
  2230. $receivedPrice=str_replace(',','',$receivedPrice);
  2231. if ($expensesType == "INCOME") {
  2232. if(!is_numeric($receivedPrice)){
  2233. die ( 'illegal request--receivedPrice' );
  2234. }
  2235. } elseif ($expensesType == "EXPENDITURE") {
  2236. if(!is_numeric($expenditurePrice)){
  2237. die ( 'illegal request--expenditurePrice' );
  2238. }
  2239. }
  2240. */
  2241. Doo::loadClass ( 'XDeode' );
  2242. $XDeode = new XDeode ( 5 );
  2243. $rid = $XDeode->decode ( $ridKey );
  2244. Doo::loadModel ( 'receipt' );
  2245. $receipt = new receipt ();
  2246. $detail = $receipt->getReceiptByRid ( $rid );
  2247. if (empty ( $detail )) {
  2248. die ( 'illegal request--noData' );
  2249. }
  2250. $amount=$detail['amount'];
  2251. $accountType = '';
  2252. /*
  2253. if ($detail ['Rtype'] == 1) {
  2254. if (! empty ( $detail ['accountItem'] ))
  2255. $accountType = 2;
  2256. else
  2257. $accountType = 1;
  2258. } elseif ($detail ['Rtype'] == 2) {
  2259. $accountType = 4;
  2260. } elseif ($detail ['Rtype'] == 0) {
  2261. $accountType = 3;
  2262. } elseif ($detail ['Rtype'] == 3) {
  2263. $accountType = 12;
  2264. }
  2265. */
  2266. if ($detail ['Rtype'] == 0) {
  2267. $accountType = 3;
  2268. $expensesType='EXPENDITURE';
  2269. } elseif ($detail ['Rtype'] == 1) {
  2270. if (! empty ( $rinfo ['accountItem'] )){
  2271. $accountType = 2;
  2272. if ($amount>=0){
  2273. $expensesType='EXPENDITURE';
  2274. }else{
  2275. $expensesType='INCOME';
  2276. }
  2277. }else{
  2278. $accountType = 1;
  2279. $expensesType='EXPENDITURE';
  2280. }
  2281. } elseif ($detail ['Rtype'] == 2) {
  2282. $accountType = 4;
  2283. $expensesType='EXPENDITURE';
  2284. } elseif ($detail ['Rtype'] == 3) {//培训班结算 收支类型
  2285. $accountType = 12;
  2286. Doo::loadClass ( 'authcode.func' );
  2287. $amountTrain=authcode($amountTrain);
  2288. if(!is_numeric ( $amountTrain )) {
  2289. die('illegal request--payType');
  2290. }
  2291. if($amountTrain>=0){
  2292. $expensesType='INCOME';
  2293. }else{
  2294. $expensesType='EXPENDITURE';
  2295. }
  2296. $amount=$amountTrain;
  2297. }
  2298. //汇款金额正数
  2299. $amount=abs($amount);
  2300. //$accountType = 12;
  2301. $accountBank = $receivedBank;
  2302. $inputDate = $receivedInputDate;
  2303. if ($expensesType == "INCOME") {
  2304. $expensesTypeWaste = 1;
  2305. $accountPriceShow = $accountPrice = $amount;
  2306. } elseif ($expensesType == "EXPENDITURE") {
  2307. $expensesTypeWaste = 2;
  2308. $accountPriceShow = $amount;
  2309. $accountPrice = - $amount;
  2310. } else {
  2311. die ( 'illegal request--expensesType' );
  2312. }
  2313. /*
  2314. $accountPriceShow = $accountPrice = 0;
  2315. $expensesTypeWaste = 0;
  2316. $accountBank = '';
  2317. $inputDate = date ( "Y-m-d H:i:s" );
  2318. if ($expensesType == "INCOME") {
  2319. $expensesTypeWaste = 1;
  2320. $accountPriceShow = $receivedPrice;
  2321. $accountPrice = $receivedPrice;
  2322. $accountBank = $receivedBank;
  2323. $inputDate = $receivedInputDate;
  2324. } elseif ($expensesType == "EXPENDITURE") {
  2325. $expensesTypeWaste = 2;
  2326. $accountPriceShow = $expenditurePrice;
  2327. $accountPrice = - $expenditurePrice;
  2328. $accountBank = $expenditureBank;
  2329. $inputDate = $expenditureInputDate;
  2330. } else {
  2331. die ( 'illegal request--expensesType' );
  2332. }
  2333. */
  2334. $receipt = new receipt ();
  2335. $receipt->amount = $accountPrice;
  2336. $receipt->update ( array (
  2337. 'where' => 'rid=' . $rid
  2338. ) );
  2339. // 更新借款汇款金额
  2340. if ($accountType == 1) {
  2341. Doo::loadModel ( 'loanReceipt' );
  2342. $loanReceipt = new loanReceipt ();
  2343. $loanReceipt->amount = $accountPrice;
  2344. $loanReceipt->update ( array (
  2345. 'where' => ' rid = ' . $detail ['loanRid']
  2346. ));
  2347. }
  2348. // 公司流水记录
  2349. Doo::loadModel ( 'wasteBook' );
  2350. $wasteBook = new wasteBook ();
  2351. $abDetail = $wasteBook->getAccountBookByAid ( $expensesTypeWaste, $accountType, $rid );
  2352. // 银行
  2353. if (empty ( $abDetail )) {
  2354. $item = array (
  2355. 'dataID' => $rid,
  2356. 'expensesType' => $expensesTypeWaste,
  2357. 'accountType' => $accountType,
  2358. 'accountPriceShow' => $accountPriceShow,
  2359. 'accountPrice' => $accountPrice,
  2360. 'accountBank' => $accountBank,
  2361. 'category' => $detail ['category'] [0] ['title'],
  2362. 'cid' => $detail ['category'] [0] ['cid'],
  2363. 'name' => $detail ['staffDetail'] ['username'],
  2364. 'sid' => $detail ['staffDetail'] ['sid'],
  2365. 'inputDate' => $inputDate
  2366. );
  2367. $wasteBook->setAccountBookStatistics ( $item );
  2368. }
  2369. return '/receiptWasteBook';
  2370. }
  2371. /**
  2372. * 培训班结算营收总计
  2373. */
  2374. function receiptTrainRevenue(){
  2375. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  2376. Doo::loadModel ( 'receipt' );
  2377. $receipt = new receipt ();
  2378. //获得可查看的办事处
  2379. Doo::loadModel ( "receiptTrainManage" );
  2380. $invoiceCategoryManage = new receiptTrainManage ();
  2381. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  2382. if(empty($imcStaff)){
  2383. die ( 'illegal request--Insufficient Permissions' );
  2384. }
  2385. $cidList = array ();
  2386. foreach ( $imcStaff as $key => $value ) {
  2387. array_push ( $cidList, $value ['cid'] );
  2388. }
  2389. $cidString=implode ( ',', $cidList );
  2390. //初始化收款数据
  2391. $where=" where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and paidStatus=0 and invoiceTrainId!=0 ";
  2392. $sql="select invoiceTrainId,rid
  2393. from CLD_receipt as a
  2394. ".$where." and a.cid in (".$cidString.") ";
  2395. $receipt->initReceiptTrainRevenue($sql);
  2396. $unpaid=$receipt->getReceiptTrainByPaid(0,5,$cidString);
  2397. $paid=$receipt->getReceiptTrainByPaid(1,5,$cidString);
  2398. $MonthPriceList=$receipt->getReceiptTrainByYearChart($cidString);
  2399. $income=$month=$pay=$profit=array();
  2400. for ($i=1;$i<=12;$i++){
  2401. $flag=true;
  2402. array_push($month,date("Y").'-'.$i);
  2403. foreach ($MonthPriceList as $key=>$value){
  2404. if($key==$i){
  2405. $flag=false;
  2406. array_push($income,$value['ITprice']);
  2407. array_push($pay,$value['RIprice']);
  2408. array_push($profit,$value['ITprice']-$value['RIprice']);
  2409. }
  2410. }
  2411. if ($flag){
  2412. array_push($income,0);
  2413. array_push($pay,0);
  2414. array_push($profit,0);
  2415. }
  2416. }
  2417. $data ['income'] =json_encode ( $income );
  2418. $data ['pay'] =json_encode ( $pay );
  2419. $data ['profit'] =json_encode ( $profit );
  2420. $data ['month'] =json_encode ( $month );
  2421. $data ['paid'] = $paid;
  2422. $data ['unpaid'] = $unpaid;
  2423. $data ['memu'] = "receipt";
  2424. $data ['staff'] = $this->staff;
  2425. //var_dump( $this->executeId) ;
  2426. //die;
  2427. $data ['receiptMemu'] = 'receiptTrainRevenue';
  2428. $data ['verifyId'] = $this->verifyId;
  2429. $data ['executeId'] = $this->executeId;
  2430. $this->render ( "/receipt/receiptTrainRevenue", $data );
  2431. }
  2432. /**
  2433. * 所有培训班结算
  2434. */
  2435. function receiptTrainRevenueAchieve(){
  2436. //$paid = $this->get_args ( 'paid' ) ? $this->get_args ( 'paid' ) : '';
  2437. $paid =isset ( $this->params ['paid'] ) ? $this->params ['paid'] : 'ALL';
  2438. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  2439. $page_size = 12;
  2440. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2441. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2442. $get='/'.$paid ;//= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2443. Doo::loadModel ( 'receipt' );
  2444. $receipt = new receipt ();
  2445. Doo::loadModel ( 'L_category' );
  2446. $Lcategory = new L_category ();
  2447. Doo::loadClass ( 'XDeode' );
  2448. $XDeode = new XDeode ( 5 );
  2449. $cidSql=$cid='';
  2450. if(!empty($cidKey)){
  2451. $cid = $XDeode->decode ( $cidKey );
  2452. $cidSql=" and a.cid=".$cid." ";
  2453. }
  2454. //获得可查看的办事处
  2455. Doo::loadModel ( "receiptTrainManage" );
  2456. $invoiceCategoryManage = new receiptTrainManage ();
  2457. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  2458. $cidList = array ();
  2459. foreach ( $imcStaff as $key => $value ) {
  2460. array_push ( $cidList, $value ['cid'] );
  2461. }
  2462. if(!empty($cid)&&!in_array($cid, $cidList)){
  2463. die("illegal request-cid");
  2464. }
  2465. $cidString=implode ( ',', $cidList );
  2466. $categoryList = $Lcategory->getCategoryInCid ( $cidString );
  2467. $psSql='';$paidKey='';
  2468. if(!empty($paid)&&$paid!="ALL"){
  2469. if ($paid=='UNPAID'){
  2470. $paidKey='0';
  2471. }elseif($paid=='PAID'){
  2472. $paidKey='1';
  2473. }
  2474. $psSql=" and a.paidStatus=".$paidKey." ";
  2475. }
  2476. $dateArr = explode ( ':', $trainEndDate );
  2477. $D1 = $dateString = '';
  2478. $D2 = '';
  2479. if (! empty ( $trainEndDate )) {
  2480. $D1 = $dateArr [0];
  2481. if (isset ( $dateArr [1] ))
  2482. $D2 = $dateArr [1];
  2483. else
  2484. $D2 = '';
  2485. $dateString = $D1 . ":" . $D2;
  2486. }
  2487. $dateSql='';
  2488. if (! empty ( $D1 ) && ! empty ( $D2 )){
  2489. $dateSql = ' and trainEndDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2490. }elseif (! empty ( $D1 ) && empty ( $D2 )){
  2491. $dateSql = ' and trainEndDate like "%' . $D1 . '%" ';
  2492. }
  2493. $selectCount=" count(*) as count ";
  2494. $where=" where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 ".$psSql;
  2495. $sql = "select ".$selectCount."
  2496. from CLD_receipt as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid)
  2497. ".$where." and a.cid in (".$cidString.") ".$cidSql.$dateSql;
  2498. $action="receiptTrainRevenueAchieve";
  2499. $pageinfo = $this->get_page ( $sql, $page, $page_size, $action, $get, "" );
  2500. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2501. $rtpa=$receipt->getReceiptTrainByPaidAll($paidKey,$cid,$dateSql,$limit,$cidString,$where);
  2502. //金额合计功能
  2503. $sql="select invoiceTrainId,rid
  2504. from CLD_receipt as a
  2505. ".$where." and a.cid in (".$cidString.") ";
  2506. $receiptTrainPriceList=$receipt->getReceiptTrainSumByItid($sql);
  2507. $data ['receiptTrainPriceList']=$receiptTrainPriceList;
  2508. $data ['dateString']=$dateString;
  2509. $data ['cidKey']=$cidKey;
  2510. $data ['categoryList'] =$categoryList;
  2511. $data ['paid'] = $paid;
  2512. $data ['get'] = $get;
  2513. $data ['page'] = $pageinfo;
  2514. $data ['onpage'] = $page;
  2515. $data ['rtpa'] = $rtpa;
  2516. $data ['memu'] = "receipt";
  2517. $data ['staff'] = $this->staff;
  2518. $data ['receiptMemu'] = 'receiptTrainRevenue';
  2519. $data ['verifyId'] = $this->verifyId;
  2520. $data ['executeId'] = $this->executeId;
  2521. $this->render ( "/receipt/receiptTrainRevenueAchieve", $data );
  2522. }
  2523. /*
  2524. * 全年办事处汇总明细
  2525. */
  2526. function receiptSummaryStatisticsByAgency(){
  2527. //$cidIn = $this->get_args ( 'cidIn' ) ? $this->get_args ( 'cidIn' ) : '12,10,9';
  2528. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2529. Doo::loadClass ( 'XDeode' );
  2530. //参数
  2531. $cidKeyIn=file_get_contents( "protected/config/receipt/summary.conf.ini");
  2532. if(!empty($cidKeyIn)){
  2533. $cidKeyIn=explode(',', $cidKeyIn);$cidIn=array();
  2534. foreach ($cidKeyIn as $key=>$value){
  2535. $XDeode = new XDeode ( 5 );
  2536. array_push($cidIn, $XDeode->decode($value));
  2537. }
  2538. $cidIn=implode(',', $cidIn);
  2539. }else{
  2540. $cidKeyIn=array();
  2541. }
  2542. $year= $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date('Y');
  2543. //主体
  2544. Doo::loadModel ( 'L_category' );
  2545. $category = new L_category ();
  2546. $sectionHtml=$sectionItemHtml='';$dataSummary=array();$summaryDateHtml='';
  2547. if(!empty($cidIn)){
  2548. Doo::loadModel ( 'receiptDetail' );
  2549. $receiptDetail = new receiptDetail ();
  2550. Doo::loadModel ( 'accountItem' );
  2551. $accountItem = new accountItem ();
  2552. $aiList=$accountItem->getCategory();
  2553. $aiAllList=$accountItem->getAccountItem();
  2554. $list=$receiptDetail->getReceiptDetailByYear($cidIn,$year);
  2555. $cidArray=explode(',', $cidIn);
  2556. foreach ($cidArray as $cak=>$cav){
  2557. $dataSummary[$cav]=array();
  2558. for($month=1;$month<=12;$month++){
  2559. foreach ($aiList as $aik=>$aiv){
  2560. $dataSummary[$cav][$month][$aiv['category']]=array();
  2561. }
  2562. $dataSummary[$cav][$month]['报销金额调整']=array();
  2563. }
  2564. }
  2565. foreach ($list as $key=>$value){
  2566. array_push($dataSummary[$value['cid']][$value['month']][$value['itemCategory']], $value);
  2567. }
  2568. //print_r($dataSummary);die;
  2569. Doo::loadClass ( 'receipt.func' );
  2570. //构建数据html
  2571. $cglist=$category->getCategoryInCid($cidIn);
  2572. $summaryDateHtml=_getReceiptSummaryHtml($cglist,$aiAllList,$dataSummary,$year);
  2573. //构建栏目展示Html
  2574. foreach ($aiAllList as $key=>$value){
  2575. //栏目
  2576. $sectionCount=count($value)+1;
  2577. $sectionHtml.='<th colspan="'.$sectionCount.'">'.$key.'</th>';
  2578. //栏目细则
  2579. $sectionItemHtml.='<th class="colRed">合计</th>';
  2580. foreach ($value as $k=>$v){
  2581. $sectionItemHtml.='<th>'.$v['name'].'</th>';
  2582. }
  2583. }
  2584. }
  2585. //办事处显示设置
  2586. $categoryList=$category->getCategory();
  2587. $selectedSummary=$cidKeyIn;
  2588. foreach ($categoryList as $key=>$value){
  2589. $categoryList[$key]['checked']='';
  2590. foreach ($selectedSummary as $v){
  2591. if($value['cidKey']==$v){
  2592. $categoryList[$key]['checked']='checked';
  2593. break;
  2594. }
  2595. }
  2596. }
  2597. //年份展示
  2598. Doo::loadClass ( 'date.func' );
  2599. $dateHtml=_getDateHtml($year);
  2600. $summarData=json_encode($dataSummary);
  2601. $data['summarData']=URLEncode($summarData);
  2602. $data['categoryList']=$categoryList;
  2603. $data['dateHtml']=$dateHtml;
  2604. $data['sectionHtml']=$sectionHtml;
  2605. $data['sectionItemHtml']=$sectionItemHtml;
  2606. $data['summaryDateHtml']=$summaryDateHtml;
  2607. $data['year']=$year;
  2608. $data ['memu'] = "receipt";
  2609. $data ['staff'] = $this->staff;
  2610. $data ['receiptMemu'] = 'companyCategoryCollect';
  2611. $data ['verifyId'] = $this->verifyId;
  2612. $data ['executeId'] = $this->executeId;
  2613. $this->render ( "/receipt/receiptSummaryStatisticsByAgency", $data );
  2614. }
  2615. //设置办事处展示明细
  2616. function setSummaryCategory(){
  2617. $cidKey= $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : "";
  2618. $cidKey=implode(',', $cidKey);
  2619. file_put_contents ( "protected/config/receipt/summary.conf.ini", $cidKey);
  2620. return '/receiptSummaryStatisticsByAgency';
  2621. }
  2622. //导出办事处全年费用汇总excel
  2623. function exportReceiptSummaryExcel(){
  2624. $summaryData= $this->get_args ( 'summaryData' ) ? $this->get_args ( 'summaryData' ) : "";
  2625. $year= $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  2626. //$cidIn = $this->get_args ( 'cidIn' ) ? $this->get_args ( 'cidIn' ) : '12,10,9';
  2627. Doo::loadClass ( 'XDeode' );
  2628. $cidKeyIn=file_get_contents( "protected/config/receipt/summary.conf.ini");
  2629. $cidKeyIn=explode(',', $cidKeyIn);$cidIn=array();
  2630. foreach ($cidKeyIn as $key=>$value){
  2631. $XDeode = new XDeode ( 5 );
  2632. array_push($cidIn, $XDeode->decode($value));
  2633. }
  2634. $cidIn=implode(',', $cidIn);
  2635. if(!empty($summaryData)){
  2636. Doo::loadModel ( 'accountItem' );
  2637. $accountItem = new accountItem ();
  2638. Doo::loadModel ( 'L_category' );
  2639. $category = new L_category ();
  2640. $aiAllList=$accountItem->getAccountItem();
  2641. $cglist=$category->getCategoryInCid($cidIn);
  2642. $summaryData=json_decode(urldecode($summaryData), true);
  2643. Doo::loadClass ( 'receipt.func' );
  2644. excelRCData($summaryData,$aiAllList,$cglist,$year);
  2645. }
  2646. die ( 'illegal request--excel Data null' );
  2647. }
  2648. function exportReceiptTrainExcel() {
  2649. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2650. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2651. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2652. $summaryJson = $this->get_args ( 'summaryJson' ) ? $this->get_args ( 'summaryJson' ) : "";
  2653. $aiListJson = $this->get_args ( 'aiListJson' ) ? $this->get_args ( 'aiListJson' ) : "";
  2654. Doo::loadClass ( 'XDeode' );
  2655. $XDeode = new XDeode ( 7 );
  2656. $rid = $XDeode->decode ( $ridKey );
  2657. if (! is_numeric ( $rid ))
  2658. die ( 'illegal request' );
  2659. Doo::loadModel ( 'receipt' );
  2660. $receipt = new receipt ();
  2661. Doo::loadModel ( 'receiptTraining' );
  2662. $receiptTraining = new receiptTraining ();
  2663. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2664. $receiptTrainDetail = $receiptTraining->getReceiptTrainingByRtid ( $rtidKey );
  2665. $summary=json_decode(urldecode($summaryJson), true);
  2666. $aiList=json_decode(urldecode($aiListJson), true);
  2667. //借款相关
  2668. $receiptLoanDetail=array();
  2669. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2670. $receiptLoanDetail = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2671. }
  2672. //收入
  2673. Doo::loadModel ( 'invoice' );
  2674. $invoice = new invoice ();
  2675. Doo::loadModel ( 'invoiceTraining' );
  2676. $invoiceTraining = new invoiceTraining ();
  2677. $invoiceList=array();
  2678. $invoiceTrainingDetail=array();
  2679. if($receiptDetail ['invoiceTrainId']!=0){
  2680. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2681. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2682. }
  2683. //支出
  2684. Doo::loadModel ( 'RItem' );
  2685. $RItem = new RItem ();
  2686. $RItemList = $RItem->getRItemByRid ( $rid );
  2687. //讲师
  2688. Doo::loadModel ( 'RILecturer' );
  2689. $RILecturer = new RILecturer ();
  2690. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2691. Doo::loadClass ( 'receipt.func' );
  2692. excelData ( $receiptTrainDetail, $receiptDetail, $summary, $aiList,$receiptLoanDetail,$invoiceList,$RItemList,$RILecturerList,$invoiceTrainingDetail );
  2693. }
  2694. /**
  2695. * 获得审批流程
  2696. */
  2697. private function fnGetReceiptApprovalProcess($verifyList = array(), $verifyStaff = array()) {
  2698. Doo::loadModel ( 'role' );
  2699. $role = new role ();
  2700. Doo::loadModel ( 'staff' );
  2701. $staff = new staff ();
  2702. $flag = true;
  2703. $roleKey = $button = 0;
  2704. $endStaffArray = array ();
  2705. $roleArrayCopy = array ();
  2706. foreach ( $verifyList as $k => $v ) {
  2707. if ($v [1] == 'ROLE') {
  2708. if (! empty ( $verifyStaff )) {
  2709. $endStaffArray = end ( $verifyStaff );
  2710. if ($v [0] == $endStaffArray ['nextStaff']) {
  2711. $roleId = $v [0];
  2712. }
  2713. }
  2714. $roleVerify = json_decode ( $v [3], true );
  2715. $roleKey = $k;
  2716. $roleArray = array ();
  2717. $rolename = $role->getOne ( array (
  2718. 'where' => 'rid=' . $v [0],
  2719. 'asArray' => true
  2720. ) );
  2721. foreach ( $roleVerify as $o => $p ) {
  2722. $staffID = explode ( '_', $p );
  2723. $staffInfo = $staff->getOne ( array (
  2724. 'where' => 'sid=' . $staffID [0],
  2725. 'asArray' => true
  2726. ) );
  2727. // print_r($staffID);
  2728. $exp = array (
  2729. 0 => $staffInfo ['sid'],
  2730. 1 => $staffID [1],
  2731. 2 => $staffInfo ['avatar'],
  2732. 'date' => '',
  2733. 'date' => '',
  2734. 'opinion' => '',
  2735. 'status' => '',
  2736. 'rolename' => $rolename ['name']
  2737. );
  2738. array_push ( $roleArray, $exp );
  2739. }
  2740. $roleArrayCopy [$v [0]] = $roleArray;
  2741. // $verifyList[$k]['roleArray']=$roleArray;
  2742. }
  2743. // print_r($roleArray);
  2744. $verifyList [$k] ['date'] = "";
  2745. $verifyList [$k] ['opinion'] = "";
  2746. $verifyList [$k] ['status'] = "";
  2747. if (empty ( $verifyStaff )) {
  2748. $verifyList [$k] ['date'] = "";
  2749. $verifyList [$k] ['opinion'] = "";
  2750. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2751. $verifyList [$k] ['status'] = 4;
  2752. $button = 4;
  2753. $flag = false;
  2754. }
  2755. } else {
  2756. foreach ( $verifyStaff as $m => $u ) {
  2757. if ($v [0] == $m) {
  2758. $verifyList [$k] ['date'] = $u ['date'];
  2759. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2760. $verifyList [$k] ['status'] = $u ['status'];
  2761. $flag = false;
  2762. break;
  2763. }
  2764. }
  2765. $endStaffArray = end ( $verifyStaff );
  2766. if (isset ( $endStaffArray ['ROLE'] )) {
  2767. } else {
  2768. $endKey = key ( $verifyStaff );
  2769. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  2770. $button = 4;
  2771. $verifyList [$k] ['status'] = 4;
  2772. }
  2773. }
  2774. }
  2775. }
  2776. $rolename ['name'] = '';
  2777. if (! empty ( $roleId )) {
  2778. Doo::loadModel ( 'role' );
  2779. $role = new role ();
  2780. $rolename = $role->getOne ( array (
  2781. 'where' => 'rid=' . $roleId,
  2782. 'asArray' => true
  2783. ) );
  2784. }
  2785. if (! empty ( $verifyStaff ))
  2786. $endStaffArray = end ( $verifyStaff );
  2787. $KOP = false;
  2788. foreach ( $roleArrayCopy as $P => $A ) {
  2789. foreach ( $A as $MKI => $AVL ) {
  2790. if (! empty ( $verifyStaff )) {
  2791. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2792. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2793. $button = 4;
  2794. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2795. }
  2796. foreach ( $verifyStaff as $m => $u ) {
  2797. $AVLFK = $AVL [0] . '_R';
  2798. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2799. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2800. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2801. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2802. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2803. break;
  2804. }
  2805. }
  2806. } else {
  2807. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2808. $button = 4;
  2809. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2810. }
  2811. }
  2812. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2813. $KOP = true;
  2814. }
  2815. }
  2816. foreach ( $roleArrayCopy as $k => $v ) {
  2817. foreach ( $verifyList as $m => $n ) {
  2818. if ($n [0] == $k) {
  2819. array_splice ( $verifyList, $m, 1, $v );
  2820. }
  2821. }
  2822. }
  2823. return array (
  2824. 'verifyList' => $verifyList,
  2825. 'isApproval' => $button
  2826. );
  2827. }
  2828. function _GetFileEXT($filename) {
  2829. $pics = explode ( '.', $filename );
  2830. $num = count ( $pics );
  2831. return $pics [$num - 1];
  2832. }
  2833. /**
  2834. * 获取get或者POST值
  2835. * @param string $name 属性名称
  2836. * @return fixed 值
  2837. */
  2838. function get_args($name) {
  2839. if (isset ( $_GET [$name] )) {
  2840. if (is_array ( $_GET [$name] ))
  2841. return $_GET [$name];
  2842. else
  2843. return addslashes ( $_GET [$name] );
  2844. } elseif (isset ( $_POST [$name] )) {
  2845. if (is_array ( $_POST [$name] ))
  2846. return $_POST [$name];
  2847. else
  2848. return addslashes ( $_POST [$name] );
  2849. } else
  2850. return false;
  2851. }
  2852. function num_to_rmb($num) {
  2853. $c1 = "零壹贰叁肆伍陆柒捌玖";
  2854. $c2 = "分角元拾佰仟万拾佰仟亿";
  2855. // 精确到分后面就不要了,所以只留两个小数位
  2856. $num = round ( $num, 2 );
  2857. // 将数字转化为整数
  2858. $num = $num * 100;
  2859. if (strlen ( $num ) > 10) {
  2860. return "金额太大,请检查";
  2861. }
  2862. $i = 0;
  2863. $c = "";
  2864. while ( 1 ) {
  2865. if ($i == 0) {
  2866. // 获取最后一位数字
  2867. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  2868. } else {
  2869. $n = $num % 10;
  2870. }
  2871. // 每次将最后一位数字转化为中文
  2872. $p1 = substr ( $c1, 3 * $n, 3 );
  2873. $p2 = substr ( $c2, 3 * $i, 3 );
  2874. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  2875. $c = $p1 . $p2 . $c;
  2876. } else {
  2877. $c = $p1 . $c;
  2878. }
  2879. $i = $i + 1;
  2880. // 去掉数字最后一位了
  2881. $num = $num / 10;
  2882. // echo $num.'</br>';
  2883. $num = ( int ) $num;
  2884. // $num =floor($num);
  2885. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  2886. // echo $num.'</br>';
  2887. // 结束循环
  2888. if ($num == 0) {
  2889. break;
  2890. }
  2891. }
  2892. // echo $c.'</br>';
  2893. $j = 0;
  2894. $slen = strlen ( $c );
  2895. while ( $j < $slen ) {
  2896. // utf8一个汉字相当3个字符
  2897. $m = substr ( $c, $j, 6 );
  2898. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  2899. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  2900. $left = substr ( $c, 0, $j );
  2901. $right = substr ( $c, $j + 3 );
  2902. $c = $left . $right;
  2903. $j = $j - 3;
  2904. $slen = $slen - 3;
  2905. }
  2906. $j = $j + 3;
  2907. }
  2908. // 这个是为了去掉类似23.0中最后一个“零”字
  2909. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  2910. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  2911. }
  2912. // 将处理的汉字加上“整”
  2913. if (empty ( $c )) {
  2914. return "零元整";
  2915. } else {
  2916. return $c . "整";
  2917. }
  2918. }
  2919. /**
  2920. * 获得分页数据
  2921. * @param unknown_type $table
  2922. * @param unknown_type $condition
  2923. * @param unknown_type $on_page
  2924. * @param unknown_type $page_size
  2925. */
  2926. function get_page($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  2927. $page_c = "";
  2928. $page ['previous'] = $this->get_previous ( $on_page );
  2929. $page ['on_page'] = $on_page;
  2930. $total_count = $this->get_table_count ( $sql );
  2931. $total = intval ( $total_count / $page_size );
  2932. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  2933. $page ['total_data'] = $total_count;
  2934. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  2935. $i = 1;
  2936. $page_max = 1;
  2937. $page_width = 3;
  2938. if ($on_page >= $page_width) {
  2939. $page_max = intval ( $on_page / $page_width ) + 1;
  2940. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  2941. }
  2942. for(; $i <= $page ['total_page']; $i ++) {
  2943. if ($i == $on_page)
  2944. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  2945. else
  2946. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  2947. if ($i == ($page_width * $page_max))
  2948. break;
  2949. }
  2950. $page ['page'] = $page_c;
  2951. $page ['lower'] = (-- $on_page) * $page_size;
  2952. return $page;
  2953. }
  2954. /**
  2955. * 获取总页数
  2956. * @param unknown_type $table
  2957. * @param unknown_type $condition
  2958. */
  2959. public function get_table_count($sql="") {
  2960. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  2961. $query = Doo::db ()->query ( $sql );
  2962. $result = $query->fetch ();
  2963. return $result ['count'];
  2964. }
  2965. /**
  2966. * 获取上一页
  2967. * @param unknown_type $on_page
  2968. */
  2969. function get_previous($on_page = 1) {
  2970. return $on_page != 0 ? $on_page - 1 : $on_page;
  2971. }
  2972. }