ReceiptExtendController.php 108 KB

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