ReceiptExtendController.php 112 KB

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