ReceiptExtendController.php 97 KB

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