ReceiptExtendController.php 101 KB

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