ReceiptExtendController.php 94 KB

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