ReceiptExtendController.php 114 KB

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