InvoiceController.php 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o';//awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. // $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. // $fiML=json_decode($fileInvoice,true);
  40. // foreach ($fiML as $key=>$value){
  41. // $sidList=explode(',',$value);
  42. // foreach ($sidList as $k=>$v){
  43. // if ($v==$sid){
  44. // array_push ( $moldList, array (
  45. // 'mold' => $key
  46. // ) );
  47. // break;
  48. // }
  49. // }
  50. // }
  51. foreach ( $moldList as $value ) {
  52. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  53. $flag = true;
  54. break;
  55. }
  56. }
  57. }
  58. /*
  59. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  60. */
  61. // var_dump($flag) ;
  62. if (! $flag)
  63. die ( 'illegal request' );
  64. }
  65. function __construct() {
  66. if (isset ( $_COOKIE ["staff"] )) {
  67. if (! empty ( $_COOKIE ["staff"] )) {
  68. Doo::loadModel ( 'staff' );
  69. $staff = new staff ();
  70. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  71. $this->ACTION = $uriPartsOrig [1];
  72. $this->data ['new'] = $this->isInvoiceNew ();
  73. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  74. return "/";
  75. }
  76. }
  77. Doo::loadCore ( 'uri/DooUriRouter' );
  78. $router = new DooUriRouter ();
  79. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  80. if ($routeRs ['1'] != "login") {
  81. header ( 'Content-Type:text/html;charset=utf-8' );
  82. @header ( "Location: /login" );
  83. }
  84. }
  85. function testSend(){
  86. $title2 = '[结果]您的发票333完成打印';
  87. $msg = '';
  88. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  89. $hfreult = $this->msgSend ( $msg, $title2, $url, 'caipin' );
  90. }
  91. function invoice() {
  92. Doo::loadModel ( 'invoice' );
  93. $invoice = new invoice ();
  94. Doo::loadModel ( 'express' );
  95. $express = new express ();
  96. $expressList = $express->getExpressByAll ();
  97. $this->data ['expressList'] = $expressList;
  98. // Doo::loadModel ( 'invoiceReceivables' );
  99. // $invoiceReceivables = new invoiceReceivables ();
  100. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  101. Doo::loadModel ( 'invoiceStatistics' );
  102. $invoiceStatistics = new invoiceStatistics ();
  103. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  104. $year = date ( "Y" );
  105. $tmp_date = date ( "Ym" );
  106. $tmp_year = substr ( $tmp_date, 0, 4 );
  107. $tmp_mon = substr ( $tmp_date, 4, 2 );
  108. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  109. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  110. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  111. $htm = $this->showCache ( $path );
  112. Doo::loadClass ( 'XDeode' );
  113. $XDeode = new XDeode ( 5 );
  114. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  115. $invoiceList = $invoice->getMyInvoice ( $sid );
  116. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  117. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  118. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  119. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  120. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  121. // print_r($myInvoiceUnAccount);
  122. $this->data ['isMonth'] = $isMonth;
  123. $this->data ['htm'] = $htm;
  124. $this->data ['invoiceList'] = $invoiceList;
  125. $this->data ['receivablesList'] = $list;
  126. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  127. $this->data ['memu'] = "invoice";
  128. $this->data ['staff'] = $this->staff;
  129. $this->data ['receiptMemu'] = 'invoice';
  130. $this->render ( "/admin/invoice", $this->data );
  131. }
  132. function invoiceAdd() {
  133. Doo::loadModel ( 'L_category' );
  134. $lCategory = new L_category ();
  135. $category = $lCategory->find ( array (
  136. 'asArray' => true
  137. ) );
  138. $this->data ['category'] = $category;
  139. $this->data ['memu'] = "invoice";
  140. $this->data ['staff'] = $this->staff;
  141. $this->data ['receiptMemu'] = 'invoice';
  142. $this->render ( "/admin/invoiceAdd", $this->data );
  143. }
  144. /**
  145. * 提交一份开票申请,并记录下操作日志
  146. *
  147. * @since 1.0.0
  148. * @var integer cid 办事处ID
  149. * @var integer invoiceType 发票类型
  150. * @var integer doPost 是否邮寄
  151. * @var integer invoicePrice 开票金额
  152. * @var string invoiceElement 开票内容
  153. * @var string invoiceTitle 发票抬头
  154. * @var string invoiceCompany 单位名称
  155. * @var string TIN 纳税人识别码
  156. * @var string address 注册地址
  157. * @var string phone 注册电话
  158. * @var string bank 开户银行
  159. * @var string bankAccount 银行账户
  160. * @var string recipients 收件人
  161. * @var string recipientsPhone 收件人手机/电话
  162. * @var string recipientsAddress 收件地址
  163. * @var string mailItems 邮寄物品
  164. * @var string remark 备注
  165. * @return string 返回跳转开票主页路径
  166. */
  167. function invoiceAddDo() {
  168. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  169. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  170. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  171. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  172. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  173. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  174. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  175. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  176. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  177. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  178. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  179. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  180. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  181. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  182. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  183. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  184. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  185. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  186. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  187. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  188. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  189. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  190. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  191. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  192. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  193. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  194. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  195. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  196. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  197. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  198. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  199. /*
  200. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  201. */
  202. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  203. Doo::loadModel ( 'invoice' );
  204. $invoice = new invoice ();
  205. Doo::loadModel ( 'L_category' );
  206. $lCategory = new L_category ();
  207. Doo::loadModel ( 'invoiceManage' );
  208. $invoiceManage = new invoiceManage ();
  209. Doo::loadModel ( 'invoiceOperationLog' );
  210. $invoiceOperationLog = new invoiceOperationLog ();
  211. $categoryDetil = $lCategory->getOne ( array (
  212. 'SELECT' => 'title',
  213. 'where' => 'cid=' . $cid,
  214. 'asArray' => true
  215. ) );
  216. $invoicePrice=$invoiceQuantity*$invoiceUnitPrice;
  217. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  218. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  219. // print_r(current($invoiceManageDetail ['staffList']));
  220. // die;
  221. $moldManage = array ();
  222. foreach ( $invoiceManageList as $key => $value ) {
  223. if ($value ['mold'] == '发票打印')
  224. $moldManage [$value ['mold']] = $value ['staffList'];
  225. elseif ($value ['mold'] == '发票邮寄')
  226. $moldManage [$value ['mold']] = $value ['staffList'];
  227. elseif ($value ['mold'] == '发票退票')
  228. $moldManage [$value ['mold']] = $value ['staffList'];
  229. }
  230. $item = array (
  231. 'cid' => $cid,
  232. 'categoryName' => $categoryDetil ['title'],
  233. 'invoiceElement' => $invoiceElement,
  234. 'invoiceQuantity' => $invoiceQuantity,
  235. 'invoiceUnitPrice' => $invoiceUnitPrice,
  236. 'invoicePrice' => $invoicePrice,
  237. 'invoiceType' => $invoiceType,
  238. 'doPost' => $doPost,
  239. 'status' => 1,
  240. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  241. 'date' => date ( "Y-m-d H:i:s" ),
  242. 'updateTime' => date ( "Y-m-d H:i:s" ),
  243. 'sid' => $this->staff [0] ['sid'],
  244. 'userName' => $this->staff [0] ['username'],
  245. 'invoiceManage' => $invoiceManageDetail ['staff'],
  246. 'pendingApprovals' => current ( $invoiceManageDetail ['staffList'] ) [0],
  247. 'moldManage' => json_encode ( $moldManage ),
  248. 'remark' => $remark
  249. );
  250. if ($invoiceType == 0)
  251. $item += array (
  252. 'invoiceTitle' => $invoiceTitle,
  253. 'TIN' => $TINT,
  254. 'address' => $addressT,
  255. 'phone' => $phoneT,
  256. 'bank' => $bankT,
  257. 'bankAccount' => $bankAccountT
  258. );
  259. else {
  260. $item += array (
  261. 'invoiceCompany' => $invoiceCompany,
  262. 'TIN' => $TIN,
  263. 'address' => $address,
  264. 'phone' => $phone,
  265. 'bank' => $bank,
  266. 'bankAccount' => $bankAccount
  267. );
  268. }
  269. if ($doPost == 1) {
  270. $mailList = array (
  271. 'invoice' => 1,
  272. 'mailItems' => $mailItems
  273. );
  274. if (! empty ( $softLock ))
  275. $mailList += array (
  276. 'softLock' => $softLockNum
  277. );
  278. else
  279. $mailList += array (
  280. 'softLock' => 0
  281. );
  282. if (! empty ( $contract ))
  283. $mailList += array (
  284. 'contract' => $contractNum
  285. );
  286. else
  287. $mailList += array (
  288. 'contract' => 0
  289. );
  290. if (! empty ( $instructions ))
  291. $mailList += array (
  292. 'instructions' => $instructionsNum
  293. );
  294. else
  295. $mailList += array (
  296. 'instructions' => 0
  297. );
  298. if (! empty ( $remittance ))
  299. $mailList += array (
  300. 'remittance' => $remittance
  301. );
  302. else
  303. $mailList += array (
  304. 'remittance' => ''
  305. );
  306. $mailString = '发票x1,备注:' . $mailItems;
  307. if (! empty ( $softLock ))
  308. $mailString .= ',软件锁x' . $softLockNum;
  309. if (! empty ( $contract ))
  310. $mailString .= ',合同x' . $contractNum;
  311. if (! empty ( $instructions ))
  312. $mailString .= ',说明书x' . $instructionsNum;
  313. if (! empty ( $remittance ))
  314. $mailString .= ',汇款账号单';
  315. $item += array (
  316. 'recipients' => $recipients,
  317. 'recipientsPhone' => $recipientsPhone,
  318. 'recipientsAddress' => $recipientsAddress,
  319. 'mailItems' => $mailString,
  320. 'mailItemsJson' => json_encode ( $mailList )
  321. );
  322. }
  323. $iid = $invoice->addInvoice ( $item );
  324. $item = array (
  325. 'date' => date ( "Y-m-d H:i:s" ),
  326. 'operation' => "创建",
  327. 'status' => 1,
  328. 'img' => $this->staff [0] ['avatar'],
  329. 'username' => $this->staff [0] ['username'],
  330. 'uid' => $this->staff [0] ['sid'],
  331. 'category' => $this->staff [0] ['category'],
  332. 'iid' => $iid
  333. );
  334. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  335. $item = array (
  336. 'date' => date ( "Y-m-d H:i:s" ),
  337. 'operation' => "提交审批",
  338. 'status' => 1,
  339. 'img' => $this->staff [0] ['avatar'],
  340. 'username' => $this->staff [0] ['username'],
  341. 'uid' => $this->staff [0] ['sid'],
  342. 'category' => $this->staff [0] ['category'],
  343. 'iid' => $iid
  344. );
  345. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  346. }
  347. return "/invoice";
  348. }
  349. function invoiceEdit() {
  350. Doo::loadClass ( 'XDeode' );
  351. $XDeode = new XDeode ( 5 );
  352. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  353. $iid = $XDeode->decode ( $iid );
  354. if (! is_numeric ( $iid ))
  355. die ( 'illegal request' );
  356. Doo::loadModel ( 'invoice' );
  357. $invoice = new invoice ();
  358. Doo::loadModel ( 'invoiceOperationLog' );
  359. $invoiceOperationLog = new invoiceOperationLog ();
  360. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  361. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  362. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  363. $this->data ['operation'] = $operation;
  364. $this->data ['invoiceDetail'] = $invoiceDetail;
  365. $this->data ['memu'] = "invoice";
  366. $this->data ['staff'] = $this->staff;
  367. $this->data ['receiptMemu'] = 'invoice';
  368. $this->render ( "/admin/invoiceEdit", $this->data );
  369. }
  370. /**
  371. * 重新编辑退回的发票
  372. * @return string
  373. */
  374. function invoiceEditDo() {
  375. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  376. Doo::loadModel ( 'invoice' );
  377. $invoice = new invoice ();
  378. $iid = $invoice->authcode ( $iidKey );
  379. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  380. die ( 'illegal request' );
  381. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  382. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  383. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  384. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  385. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  386. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  387. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  388. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  389. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  390. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  391. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  392. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  393. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  394. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  395. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  396. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  397. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  398. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  399. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  400. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  401. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  402. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  403. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  404. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  405. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  406. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  407. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  408. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  409. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  410. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  411. Doo::loadModel ( 'invoiceManage' );
  412. $invoiceManage = new invoiceManage ();
  413. Doo::loadModel ( 'invoiceOperationLog' );
  414. $invoiceOperationLog = new invoiceOperationLog ();
  415. $cid = explode ( ':', $cid );
  416. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  417. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  418. $moldManage = array ();
  419. foreach ( $invoiceManageList as $key => $value ) {
  420. if ($value ['mold'] == '发票打印')
  421. $moldManage [$value ['mold']] = $value ['staffList'];
  422. elseif ($value ['mold'] == '发票邮寄')
  423. $moldManage [$value ['mold']] = $value ['staffList'];
  424. elseif ($value ['mold'] == '发票打印')
  425. $moldManage [$value ['mold']] = $value ['staffList'];
  426. }
  427. $item = array (
  428. 'iid' => $iid,
  429. 'cid' => $cid [0],
  430. 'categoryName' => $cid [1],
  431. 'invoiceElement' => $invoiceElement,
  432. 'invoicePrice' => $invoicePrice,
  433. 'invoiceType' => $invoiceType,
  434. 'doPost' => $doPost,
  435. 'status' => 1,
  436. 'updateTime' => date ( "Y-m-d H:i:s" ),
  437. 'remark' => $remark
  438. );
  439. if ($invoiceType == 0)
  440. $item += array (
  441. 'invoiceTitle' => $invoiceTitle,
  442. 'TIN' => $TINT,
  443. 'address' => $addressT,
  444. 'phone' => $phoneT,
  445. 'bank' => $bankT,
  446. 'bankAccount' => $bankAccountT
  447. );
  448. else {
  449. $item += array (
  450. 'invoiceCompany' => $invoiceCompany,
  451. 'TIN' => $TIN,
  452. 'address' => $address,
  453. 'phone' => $phone,
  454. 'bank' => $bank,
  455. 'bankAccount' => $bankAccount
  456. );
  457. }
  458. if ($doPost == 1) {
  459. $mailList = array (
  460. 'invoice' => 1,
  461. 'mailItems' => $mailItems
  462. );
  463. if (! empty ( $softLock ))
  464. $mailList += array (
  465. 'softLock' => $softLockNum
  466. );
  467. else
  468. $mailList += array (
  469. 'softLock' => '0'
  470. );
  471. if (! empty ( $contract ))
  472. $mailList += array (
  473. 'contract' => $contractNum
  474. );
  475. else
  476. $mailList += array (
  477. 'contract' => '0'
  478. );
  479. if (! empty ( $instructions ))
  480. $mailList += array (
  481. 'instructions' => $instructionsNum
  482. );
  483. else
  484. $mailList += array (
  485. 'instructions' => '0'
  486. );
  487. if (! empty ( $remittance ))
  488. $mailList += array (
  489. 'remittance' => $remittance
  490. );
  491. else
  492. $mailList += array (
  493. 'remittance' => ''
  494. );
  495. $mailString = '发票x1,备注:' . $mailItems;
  496. if (! empty ( $softLock ))
  497. $mailString .= ',软件锁x' . $softLockNum;
  498. if (! empty ( $contract ))
  499. $mailString .= ',合同x' . $contractNum;
  500. if (! empty ( $instructions ))
  501. $mailString .= ',说明书x' . $instructionsNum;
  502. if (! empty ( $remittance ))
  503. $mailString .= ',汇款账号单';
  504. $item += array (
  505. 'recipients' => $recipients,
  506. 'recipientsPhone' => $recipientsPhone,
  507. 'recipientsAddress' => $recipientsAddress,
  508. 'mailItems' => $mailString,
  509. 'mailItemsJson' => json_encode ( $mailList )
  510. );
  511. }
  512. $invoice->setInvoiceByCondition ( $item );
  513. $item = array (
  514. 'date' => date ( "Y-m-d H:i:s" ),
  515. 'operation' => "重新提交审批",
  516. 'status' => 1,
  517. 'img' => $this->staff [0] ['avatar'],
  518. 'username' => $this->staff [0] ['username'],
  519. 'uid' => $this->staff [0] ['sid'],
  520. 'category' => $this->staff [0] ['category'],
  521. 'iid' => $iid
  522. );
  523. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  524. }
  525. return "/invoice";
  526. }
  527. /**
  528. * 终止开票
  529. */
  530. function invoiceDroppedDo() {
  531. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  532. Doo::loadModel ( 'invoice' );
  533. $invoice = new invoice ();
  534. Doo::loadModel ( 'invoiceOperationLog' );
  535. $invoiceOperationLog = new invoiceOperationLog ();
  536. $iid = $invoice->authcode ( $droppedIidKey );
  537. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  538. die ( 'illegal request' );
  539. $item = array (
  540. 'iid' => $iid,
  541. 'status' => 4,
  542. 'updateTime' => date ( "Y-m-d H:i:s" )
  543. );
  544. $invoice->setInvoiceByCondition ( $item );
  545. $item = array (
  546. 'date' => date ( "Y-m-d H:i:s" ),
  547. 'operation' => '终止了开票',
  548. 'status' => 4,
  549. 'img' => $this->staff [0] ['avatar'],
  550. 'username' => $this->staff [0] ['username'],
  551. 'uid' => $this->staff [0] ['sid'],
  552. 'category' => $this->staff [0] ['category'],
  553. 'iid' => $iid
  554. );
  555. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  556. return "/invoice";
  557. }
  558. /**
  559. * 更新退票的邮寄信息
  560. */
  561. function invoiceUntreadMailDo() {
  562. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  563. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  564. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  565. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  566. Doo::loadModel ( 'invoice' );
  567. $invoice = new invoice ();
  568. $iid = $invoice->authcode ( $untreadIidKey );
  569. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  570. die ( 'illegal request' );
  571. $item = array (
  572. 'iid' => $iid,
  573. 'untreadCompany' => $untreadCompany,
  574. 'untreadNumber' => $untreadNumber,
  575. 'untreadItems' => $untreadItems
  576. );
  577. $invoice->setInvoiceByCondition ( $item );
  578. return "/invoice";
  579. }
  580. /**
  581. * 申请退票 --
  582. */
  583. function invoiceUntreadDo() {
  584. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  585. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  586. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  587. Doo::loadModel ( 'invoice' );
  588. $invoice = new invoice ();
  589. Doo::loadModel ( 'invoiceOperationLog' );
  590. $invoiceOperationLog = new invoiceOperationLog ();
  591. Doo::loadModel ( 'invoiceReceivables' );
  592. $invoiceReceivables = new invoiceReceivables ();
  593. $iid = $invoice->authcode ( $untreadIidKey );
  594. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  595. die ( 'illegal request' );
  596. /*
  597. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  598. */
  599. $item = array (
  600. 'iid' => $iid,
  601. 'untreadStatus' => 1,
  602. 'untreadReason' => $untreadReason,
  603. 'untreadPost' => $untreadPost,
  604. 'updateTime' => date ( "Y-m-d H:i:s" )
  605. );
  606. $invoice->setInvoiceByCondition ( $item );
  607. $item = array (
  608. 'date' => date ( "Y-m-d H:i:s" ),
  609. 'operation' => '申请退票',
  610. 'status' => 7,
  611. 'img' => $this->staff [0] ['avatar'],
  612. 'username' => $this->staff [0] ['username'],
  613. 'uid' => $this->staff [0] ['sid'],
  614. 'category' => $this->staff [0] ['category'],
  615. 'iid' => $iid
  616. );
  617. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  618. return "/invoice";
  619. }
  620. /**
  621. * 删除已终止的开票
  622. */
  623. function invoiceDelDo() {
  624. Doo::loadClass ( 'XDeode' );
  625. $XDeode = new XDeode ( 5 );
  626. Doo::loadModel ( 'invoice' );
  627. $invoice = new invoice ();
  628. Doo::loadModel ( 'invoiceOperationLog' );
  629. $invoiceOperationLog = new invoiceOperationLog ();
  630. Doo::loadClass ( 'XDeode' );
  631. $XDeode = new XDeode ( 5 );
  632. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  633. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  634. $iid = $XDeode->decode ( $iid );
  635. if (! is_numeric ( $iid ))
  636. die ( 'illegal request' );
  637. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  638. if (empty ( $invoiceDetail ))
  639. die ( 'illegal request' );
  640. $item = array (
  641. 'iid' => $iid,
  642. 'isDelete' => 1,
  643. 'updateTime' => date ( "Y-m-d H:i:s" )
  644. );
  645. $invoice->setInvoiceByCondition ( $item );
  646. $item = array (
  647. 'date' => date ( "Y-m-d H:i:s" ),
  648. 'operation' => '删除了已终止的发票',
  649. 'status' => 4,
  650. 'img' => $this->staff [0] ['avatar'],
  651. 'username' => $this->staff [0] ['username'],
  652. 'uid' => $this->staff [0] ['sid'],
  653. 'category' => $this->staff [0] ['category'],
  654. 'iid' => $iid
  655. );
  656. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  657. return "/invoice";
  658. }
  659. function invoiceApproval() {
  660. Doo::loadModel ( 'invoice' );
  661. $invoice = new invoice ();
  662. Doo::loadClass ( 'XDeode' );
  663. $XDeode = new XDeode ( 5 );
  664. Doo::loadModel ( 'staff' );
  665. $staff = new staff ();
  666. $invoiceList = $invoice->find ( array (
  667. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  668. 'desc' => 'iid',
  669. 'asArray' => true
  670. ) );
  671. foreach ( $invoiceList as $key => $value ) {
  672. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  673. $lastApprover = json_decode ( $value ['processApprovals'], true );
  674. if (! empty ( $lastApprover )) {
  675. $lastApproverKey = array_keys ( $lastApprover );
  676. $lastApprover = end ( $lastApprover );
  677. $staffDetail = $staff->getOne ( array (
  678. 'where' => 'sid=' . end ( $lastApproverKey ),
  679. 'asArray' => true
  680. ) );
  681. $lastApprover ['username'] = $staffDetail ['username'];
  682. }
  683. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  684. }
  685. $ilist = $invoice->getInvoiceByProcessStatus ();
  686. // print_r($ilist);
  687. $this->data ['invoiceList'] = $invoiceList;
  688. $this->data ['ilist'] = $ilist;
  689. $this->data ['memu'] = "invoice";
  690. $this->data ['staff'] = $this->staff;
  691. $this->data ['receiptMemu'] = 'invoiceApproval';
  692. $this->render ( "/admin/invoiceApproval", $this->data );
  693. }
  694. function invoiceDetail() {
  695. Doo::loadClass ( 'XDeode' );
  696. $XDeode = new XDeode ( 5 );
  697. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  698. $iid = $XDeode->decode ( $iid );
  699. if (! is_numeric ( $iid ))
  700. die ( 'illegal request' );
  701. Doo::loadModel ( 'invoice' );
  702. $invoice = new invoice ();
  703. Doo::loadModel ( 'invoiceOperationLog' );
  704. $invoiceOperationLog = new invoiceOperationLog ();
  705. $invoiceDetail = $invoice->getOne ( array (
  706. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  707. 'asArray' => true
  708. ) );
  709. if (empty ( $invoiceDetail ))
  710. die ( 'illegal request' );
  711. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  712. $this->data ['invoiceDetail'] = $invoiceDetail;
  713. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  714. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  715. $this->data ['memu'] = "invoice";
  716. $this->data ['staff'] = $this->staff;
  717. $this->data ['receiptMemu'] = 'invoiceApproval';
  718. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  719. }
  720. /**
  721. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  722. *
  723. * @since 1.0.0
  724. * @var integer iid 开票ID 已加密
  725. * @var integer status 发票审批状态
  726. * @var integer opintion 审批发票的意见
  727. * @return string 如操作成功返回审批首页
  728. */
  729. function invoiceApprovalDo() {
  730. Doo::loadModel ( 'invoice' );
  731. $invoice = new invoice ();
  732. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  733. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  734. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  735. $iid = $invoice->authcode ( $iid );
  736. if (! is_numeric ( $iid ))
  737. die ( 'illegal request' );
  738. // && ! empty ( $opinion )
  739. if (! empty ( $iid ) && ! empty ( $status )) {
  740. if (! ($status == 2 || $status == 3 || $status == 4))
  741. die ( 'illegal request' );
  742. Doo::loadModel ( 'invoiceOperationLog' );
  743. $invoiceOperationLog = new invoiceOperationLog ();
  744. $invoiceDetail = $invoice->getOne ( array (
  745. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  746. 'asArray' => true
  747. ) );
  748. if (empty ( $invoiceDetail ))
  749. die ( 'illegal request' );
  750. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  751. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  752. if ($status == 3) {
  753. $invoice->status = $status;
  754. $item = array (
  755. 'operation' => $opinion
  756. );
  757. } else {
  758. if (empty ( $processApprovals )) {
  759. $processApprovals = array (
  760. $this->staff [0] ['sid'] => array (
  761. 'date' => date ( "Y-m-d H:i:s" ),
  762. 'opinion' => $opinion,
  763. 'status' => $status
  764. )
  765. );
  766. // var_dump(next($invoiceManage));
  767. $nextInvoiceManage = next ( $invoiceManage );
  768. // print_r($nextInvoiceManage);
  769. if ($status != 4 && $nextInvoiceManage !== false)
  770. $invoice->pendingApprovals = $nextInvoiceManage [0];
  771. $invoice->processApprovals = json_encode ( $processApprovals );
  772. // var_dump($invoice);
  773. // print_r($invoiceManage);
  774. } else {
  775. $processApprovals [$this->staff [0] ['sid']] = array (
  776. 'date' => date ( "Y-m-d H:i:s" ),
  777. 'opinion' => $opinion,
  778. 'status' => $status
  779. );
  780. $pendingApprovals = 0;
  781. foreach ( $invoiceManage as $key => $value ) {
  782. if ($value [0] == $this->staff [0] ['sid']) {
  783. if (isset ( $invoiceManage [$key + 1] ))
  784. $pendingApprovals = $invoiceManage [$key + 1] [0];
  785. break;
  786. }
  787. }
  788. if ($status != 4 && ! empty ( $pendingApprovals ))
  789. $invoice->pendingApprovals = $pendingApprovals;
  790. $invoice->processApprovals = json_encode ( $processApprovals );
  791. }
  792. $item = array (
  793. 'operation' => $opinion
  794. );
  795. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  796. $invoice->status = $status;
  797. $invoice->pendingApprovals = 0;
  798. } elseif ($status == 4) {
  799. $invoice->status = $status;
  800. $item = array (
  801. 'operation' => $opinion
  802. );
  803. }
  804. }
  805. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  806. $invoice->update ( array (
  807. 'where' => 'iid=' . $iid
  808. ) );
  809. $item += array (
  810. 'date' => date ( "Y-m-d H:i:s" ),
  811. 'img' => $this->staff [0] ['avatar'],
  812. 'username' => $this->staff [0] ['username'],
  813. 'uid' => $this->staff [0] ['sid'],
  814. 'category' => $this->staff [0] ['category'],
  815. 'status' => $status,
  816. 'iid' => $iid
  817. );
  818. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  819. return '/invoiceApproval';
  820. }
  821. die ( 'illegal request' );
  822. }
  823. /**
  824. * 展示需要打印的发票数据
  825. *
  826. * @since 1.0.0
  827. */
  828. function invoicePrint() {
  829. Doo::loadModel ( 'invoice' );
  830. $invoice = new invoice ();
  831. Doo::loadClass ( 'XDeode' );
  832. $XDeode = new XDeode ( 5 );
  833. Doo::loadModel ( 'staff' );
  834. $staff = new staff ();
  835. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  836. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  837. foreach ( $toPrint as $key => $value ) {
  838. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  839. $lastApprover = json_decode ( $value ['processApprovals'], true );
  840. if (! empty ( $lastApprover )) {
  841. $lastApproverKey = array_keys ( $lastApprover );
  842. $lastApprover = end ( $lastApprover );
  843. $staffDetail = $staff->getOne ( array (
  844. 'where' => 'sid=' . end ( $lastApproverKey ),
  845. 'asArray' => true
  846. ) );
  847. $lastApprover ['username'] = $staffDetail ['username'];
  848. }
  849. $toPrint [$key] ['lastApprover'] = $lastApprover;
  850. }
  851. foreach ( $printed as $key => $value ) {
  852. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  853. $lastApprover = json_decode ( $value ['processApprovals'], true );
  854. if (! empty ( $lastApprover )) {
  855. $lastApproverKey = array_keys ( $lastApprover );
  856. $lastApprover = end ( $lastApprover );
  857. $staffDetail = $staff->getOne ( array (
  858. 'where' => 'sid=' . end ( $lastApproverKey ),
  859. 'asArray' => true
  860. ) );
  861. $lastApprover ['username'] = $staffDetail ['username'];
  862. }
  863. $printed [$key] ['lastApprover'] = $lastApprover;
  864. }
  865. $this->data ['printed'] = $printed;
  866. $this->data ['toPrint'] = $toPrint;
  867. $this->data ['memu'] = "invoice";
  868. $this->data ['staff'] = $this->staff;
  869. $this->data ['receiptMemu'] = 'invoicePrint';
  870. $this->render ( "/admin/invoicePrint", $this->data );
  871. }
  872. /**
  873. * 展示发票打印的详情页面
  874. *
  875. * @since 1.0.0
  876. */
  877. function invoicePrintDetail() {
  878. Doo::loadClass ( 'XDeode' );
  879. $XDeode = new XDeode ( 5 );
  880. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  881. $iid = $XDeode->decode ( $iid );
  882. if (! is_numeric ( $iid ))
  883. die ( 'illegal request' );
  884. Doo::loadModel ( 'invoice' );
  885. $invoice = new invoice ();
  886. Doo::loadModel ( 'invoiceOperationLog' );
  887. $invoiceOperationLog = new invoiceOperationLog ();
  888. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  889. if (empty ( $invoiceDetail ))
  890. die ( 'illegal request' );
  891. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  892. $this->data ['invoiceDetail'] = $invoiceDetail;
  893. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  894. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  895. $this->data ['memu'] = "invoice";
  896. $this->data ['staff'] = $this->staff;
  897. $this->data ['receiptMemu'] = 'invoicePrint';
  898. $this->render ( "/admin/invoicePrintDetail", $this->data );
  899. }
  900. /**
  901. * 填写票号并完成打印
  902. * @since 1.0.0
  903. */
  904. function invoicePrintDo() {
  905. Doo::loadModel ( 'invoice' );
  906. $invoice = new invoice ();
  907. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  908. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  909. $iid = $invoice->authcode ( $iid );
  910. if (! is_numeric ( $iid ))
  911. die ( 'illegal request' );
  912. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  913. Doo::loadModel ( 'invoiceOperationLog' );
  914. $invoiceOperationLog = new invoiceOperationLog ();
  915. Doo::loadModel ( 'invoiceStatistics' );
  916. $invoiceStatistics = new invoiceStatistics ();
  917. // $info=$invoice->getOne(array('where'=>"invoiceNo = '".$invoiceNo."'",'asArray' => TRUE));
  918. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  919. if (empty ( $invoicePrintDetail ))
  920. die ( 'illegal request' );
  921. $item = array (
  922. 'iid' => $iid,
  923. 'printStatus' => 1,
  924. 'updateTime' => date ( "Y-m-d H:i:s" ),
  925. 'printer' => $this->staff [0] ['username'],
  926. 'printTime' => date ( "Y-m-d H:i:s" ),
  927. 'invoiceNo' => $invoiceNo
  928. );
  929. $invoice->setInvoiceByCondition ( $item );
  930. $item = array (
  931. 'date' => date ( "Y-m-d H:i:s" ),
  932. 'operation' => $invoiceNo,
  933. 'status' => 5,
  934. 'img' => $this->staff [0] ['avatar'],
  935. 'username' => $this->staff [0] ['username'],
  936. 'uid' => $this->staff [0] ['sid'],
  937. 'category' => $this->staff [0] ['category'],
  938. 'iid' => $iid
  939. );
  940. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  941. // 去统计--负票不汇总
  942. $item = array (
  943. 'date' => date ( "Y-m-d H:i:s" ),
  944. 'priceClass' => 1,
  945. 'cid' => $invoicePrintDetail ['cid'],
  946. 'staff' => $invoicePrintDetail ['sid'],
  947. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  948. );
  949. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  950. // 发送通知信息到微信-去除
  951. // $this->setWXMsg($iid,'PRINT');
  952. // 申请人获取微信通知
  953. Doo::loadModel ( 'staff' );
  954. $staff = new staff ();
  955. Doo::loadClass ( 'XDeode' );
  956. $XDeode = new XDeode ( 5 );
  957. $username2 = $staff->getOne ( array (
  958. 'select' => 'wxid',
  959. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  960. 'asArray' => TRUE
  961. ) );
  962. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  963. $msg = '';
  964. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  965. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'] );
  966. return "/invoicePrint";
  967. }
  968. }
  969. /**
  970. * 需要邮寄的发票
  971. * @since 1.0.0
  972. */
  973. function invoicePost() {
  974. Doo::loadModel ( 'invoice' );
  975. $invoice = new invoice ();
  976. Doo::loadModel ( 'express' );
  977. $express = new express ();
  978. $invoicePost = $invoice->getPostByInvoice ();
  979. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  980. $expressList = $express->getExpressByAll ();
  981. $this->data ['expressList'] = $expressList;
  982. $this->data ['invoicePost'] = $invoicePost;
  983. $this->data ['invoicePosted'] = $invoicePosted;
  984. $this->data ['memu'] = "invoice";
  985. $this->data ['staff'] = $this->staff;
  986. $this->data ['receiptMemu'] = 'invoicePost';
  987. $this->render ( "/admin/invoicePost", $this->data );
  988. }
  989. /**
  990. * 添加发票邮寄信息
  991. */
  992. function invoiceExpressAddDo() {
  993. Doo::loadModel ( 'invoice' );
  994. $invoice = new invoice ();
  995. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  996. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  997. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  998. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  999. $iid = $iid = $invoice->authcode ( $iid );
  1000. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  1001. die ( 'illegal request' );
  1002. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  1003. $item = array (
  1004. 'iid' => $iid,
  1005. 'postStatus' => 1,
  1006. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1007. 'postTime' => date ( "Y-m-d H:i:s" ),
  1008. 'expressCompany' => $expressCompany,
  1009. 'expressNumber' => $expressNumber,
  1010. 'actualItems' => $actualItems,
  1011. 'poster' => $this->staff [0] ['username']
  1012. );
  1013. $invoice->setInvoiceByCondition ( $item );
  1014. // 微信通知-去掉
  1015. // $this->setWXMsg ( $iid );
  1016. Doo::loadModel ( 'staff' );
  1017. $staff = new staff ();
  1018. Doo::loadClass ( 'XDeode' );
  1019. $XDeode = new XDeode ( 5 );
  1020. $username2 = $staff->getOne ( array (
  1021. 'select' => 'wxid',
  1022. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  1023. 'asArray' => TRUE
  1024. ) );
  1025. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  1026. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  1027. if (empty ( $expCom ))
  1028. $expCom [0] = '';
  1029. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  1030. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  1031. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'] );
  1032. return '/invoicePost';
  1033. }
  1034. function invoiceExpressUpdateDo() {
  1035. Doo::loadModel ( 'invoice' );
  1036. $invoice = new invoice ();
  1037. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  1038. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1039. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  1040. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  1041. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  1042. $iid = $invoice->authcode ( $iid );
  1043. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  1044. die ( 'illegal request' );
  1045. $item = array (
  1046. 'iid' => $iid,
  1047. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1048. 'expressCompany' => $expressCompany,
  1049. 'expressNumber' => $expressNumber,
  1050. 'actualItems' => $actualItems,
  1051. 'poster' => $this->staff [0] ['username']
  1052. );
  1053. $invoice->setInvoiceByCondition ( $item );
  1054. return $action;
  1055. }
  1056. /**
  1057. * 可退票管理
  1058. */
  1059. function invoiceUntreadIsAchieve() {
  1060. Doo::loadModel ( 'invoice' );
  1061. $invoice = new invoice ();
  1062. Doo::loadClass ( 'XDeode' );
  1063. $XDeode = new XDeode ( 5 );
  1064. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  1065. $page_size = 18;
  1066. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1067. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1068. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1069. $dateArr = explode ( ':', $date );
  1070. $D1 = '';
  1071. $D2 = '';
  1072. if (! empty ( $date )) {
  1073. $D1 = $dateArr [0];
  1074. $D2 = $dateArr [1];
  1075. }
  1076. $con = '';
  1077. if (! empty ( $D1 ) && ! empty ( $D2 ))
  1078. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1079. // if ($date == 'MONTHO')
  1080. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1081. // elseif ($date == 'MONTHT')
  1082. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1083. // elseif ($date == 'MONTHY')
  1084. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1085. if (! empty ( $MebSea )) {
  1086. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1087. }
  1088. $pageinfo ['page'] = array (
  1089. 'previous' => ''
  1090. );
  1091. // printStatus=1 and
  1092. $sql = " untreadStatus=0 and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  1093. $action = "invoiceUntreadIsAchieve";
  1094. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1095. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1096. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1097. // print_r($list);
  1098. $this->data ['MebSeaEn'] = $MebSea;
  1099. // $this->data ['MebSea'] = urlencode ( $MebSea );
  1100. $this->data ['get'] = $get;
  1101. $this->data ['page'] = $pageinfo;
  1102. $this->data ['date'] = $date;
  1103. $this->data ['list'] = $list;
  1104. $this->data ['memu'] = "invoice";
  1105. $this->data ['staff'] = $this->staff;
  1106. $this->data ['receiptMemu'] = 'invoice';
  1107. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  1108. }
  1109. /**
  1110. * 退票处理页面
  1111. */
  1112. function invoiceUntread() {
  1113. Doo::loadModel ( 'invoice' );
  1114. $invoice = new invoice ();
  1115. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  1116. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  1117. foreach ( $establishedInvoice as $key => $value ) {
  1118. // months
  1119. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  1120. $nowDate = strtotime ( 'now' );
  1121. $establishedInvoice [$key] ['lossShow'] = false;
  1122. if ($lossDate < $nowDate)
  1123. $establishedInvoice [$key] ['lossShow'] = true;
  1124. }
  1125. $this->data ['untreadInvoice'] = $untreadInvoice;
  1126. $this->data ['establishedInvoice'] = $establishedInvoice;
  1127. $this->data ['memu'] = "invoice";
  1128. $this->data ['staff'] = $this->staff;
  1129. $this->data ['receiptMemu'] = 'invoiceUntread';
  1130. $this->render ( "/admin/invoiceUntread", $this->data );
  1131. }
  1132. /**
  1133. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  1134. */
  1135. function invoiceUntreadEstablishedDo() {
  1136. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1137. Doo::loadModel ( 'invoice' );
  1138. $invoice = new invoice ();
  1139. Doo::loadModel ( 'invoiceOperationLog' );
  1140. $invoiceOperationLog = new invoiceOperationLog ();
  1141. Doo::loadModel ( 'invoiceReceivables' );
  1142. $invoiceReceivables = new invoiceReceivables ();
  1143. Doo::loadModel ( 'invoiceStatistics' );
  1144. $invoiceStatistics = new invoiceStatistics ();
  1145. $iid = $invoice->authcode ( $untreadIidKey );
  1146. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1147. die ( 'illegal request' );
  1148. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  1149. if ($invoiceDetails ['untreadStatus'] != 1)
  1150. die ( 'illegal request' );
  1151. $item = array (
  1152. 'iid' => $iid,
  1153. // 'irid'=>'',
  1154. 'untreadStatus' => 2,
  1155. 'updateTime' => date ( "Y-m-d H:i:s" )
  1156. );
  1157. $invoice->setInvoiceByCondition ( $item );
  1158. $item = array (
  1159. 'date' => date ( "Y-m-d H:i:s" ),
  1160. 'operation' => '已确认退票',
  1161. 'status' => 6,
  1162. 'img' => $this->staff [0] ['avatar'],
  1163. 'username' => $this->staff [0] ['username'],
  1164. 'uid' => $this->staff [0] ['sid'],
  1165. 'category' => $this->staff [0] ['category'],
  1166. 'iid' => $iid
  1167. );
  1168. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1169. // 收款解绑以及入账扣除
  1170. if (! empty ( $invoiceDetails ['irid'] )) {
  1171. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  1172. foreach ( $iridList as $value ) {
  1173. $irDetails = $invoiceReceivables->getOne ( array (
  1174. 'where' => " irid=" . $value . ' and bindStatus=1',
  1175. 'asArray' => TRUE
  1176. ) );
  1177. $item = array (
  1178. 'irid' => $value,
  1179. 'bindStatus' => 0,
  1180. 'untreadStatus' => 1,
  1181. 'untreadStaff' => $invoiceDetails ['userName'],
  1182. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  1183. 'iid' => 0
  1184. );
  1185. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1186. if (! empty ( $irDetails )) {
  1187. $item = array (
  1188. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['bindDate'] ) ),
  1189. 'priceClass' => 3,
  1190. 'cid' => $invoiceDetails ['cid'],
  1191. 'staff' => $invoiceDetails ['sid'],
  1192. 'accountPrice' => - $irDetails ['receivablesPrice']
  1193. );
  1194. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1195. }
  1196. }
  1197. }
  1198. return "/invoiceUntread";
  1199. }
  1200. /**
  1201. * 建立负票,关联原来发票
  1202. */
  1203. function invoiceLossDo() {
  1204. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1205. if ( ! empty ( $iidKey )) {
  1206. Doo::loadClass ( 'XDeode' );
  1207. $XDeode = new XDeode ( 5 );
  1208. Doo::loadModel ( 'invoice' );
  1209. $invoice = new invoice ();
  1210. Doo::loadModel ( 'invoiceOperationLog' );
  1211. $invoiceOperationLog = new invoiceOperationLog ();
  1212. $iidKey = $XDeode->decode ( $iidKey );
  1213. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  1214. //拷贝插入一条发票数据
  1215. $iid=$invoice->setInvoiceLoss($iidKey);
  1216. //更新负票
  1217. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1218. $invoice = new invoice ();
  1219. $item = array (
  1220. 'iid' => $iid,
  1221. 'sid' => $this->staff [0] ['sid'],
  1222. 'userName' => $this->staff [0] ['username'],
  1223. 'cid' => $this->staff [0] ['cid'],
  1224. 'categoryName' => $this->staff [0] ['category'],
  1225. 'invoicePrice' => -$invoiceDetail['invoicePrice'],
  1226. 'invoiceSerial' => $invoiceSerial,
  1227. 'invoiceNo'=>'',
  1228. 'printStatus' => 0,
  1229. 'untreadStatus' => 4,
  1230. //关联发票号
  1231. 'lossIid'=>$invoiceDetail['iid'],
  1232. );
  1233. $invoice->setInvoiceByCondition ( $item );
  1234. //更新原发票
  1235. $invoice = new invoice ();
  1236. $item = array (
  1237. 'iid' => $invoiceDetail['iid'],
  1238. 'lossIid'=>$iid,
  1239. );
  1240. $invoice->setInvoiceByCondition ( $item );
  1241. // 操作日志
  1242. $item = array (
  1243. 'date' => date ( "Y-m-d H:i:s" ),
  1244. 'operation' => "创建负票" . $invoiceSerial ,
  1245. 'status' => 12,
  1246. 'img' => $this->staff [0] ['avatar'],
  1247. 'username' => $this->staff [0] ['username'],
  1248. 'uid' => $this->staff [0] ['sid'],
  1249. 'category' => $this->staff [0] ['category'],
  1250. 'iid' => $iid
  1251. );
  1252. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1253. //print_r($invoiceDetail);
  1254. //echo $iid;die;
  1255. }
  1256. return '/invoiceUntread';
  1257. }
  1258. function invoiceReceivables() {
  1259. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  1260. Doo::loadModel ( 'L_category' );
  1261. $lCategory = new L_category ();
  1262. Doo::loadModel ( 'staff' );
  1263. $staff = new staff ();
  1264. Doo::loadModel ( 'invoiceReceivables' );
  1265. $invoiceReceivables = new invoiceReceivables ();
  1266. Doo::loadModel ( 'invoice' );
  1267. $invoice = new invoice ();
  1268. Doo::loadClass ( 'XDeode' );
  1269. $XDeode = new XDeode ( 5 );
  1270. $category = $lCategory->getCategory ();
  1271. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  1272. $sql = 'bindStatus=1 and iid!=0';
  1273. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  1274. // 获取未入账发票
  1275. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ();
  1276. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  1277. foreach ( $invoiceUnAccount as $key => $value ) {
  1278. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1279. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1280. if (! empty ( $lastApprover )) {
  1281. $lastApproverKey = array_keys ( $lastApprover );
  1282. $lastApprover = end ( $lastApprover );
  1283. $staffDetail = $staff->getOne ( array (
  1284. 'where' => 'sid=' . end ( $lastApproverKey ),
  1285. 'asArray' => true
  1286. ) );
  1287. $lastApprover ['username'] = $staffDetail ['username'];
  1288. }
  1289. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  1290. }
  1291. foreach ( $invoiceExistAccount as $key => $value ) {
  1292. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  1293. if (empty ( $irList ))
  1294. $irList [0] ['sumPrice'] = 0;
  1295. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  1296. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  1297. $invoiceExistAccount [$key] ['balance'] = $balance;
  1298. }
  1299. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  1300. // print_r($receivablesList);
  1301. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  1302. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  1303. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  1304. $this->data ['receivablesInput'] = $receivablesInput;
  1305. $this->data ['year'] = date ( 'Y' );
  1306. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  1307. $this->data ['receivablesList'] = $receivablesList;
  1308. $this->data ['staffList'] = $staffList;
  1309. $this->data ['category'] = $category;
  1310. $this->data ['memu'] = "invoice";
  1311. $this->data ['staff'] = $this->staff;
  1312. $this->data ['receiptMemu'] = 'invoiceReceivables';
  1313. $this->render ( "/admin/invoiceReceivables", $this->data );
  1314. }
  1315. /**
  1316. * 新添加收款直接入账发票
  1317. */
  1318. function invoiceCompareClaimPrice() {
  1319. // 收款录入
  1320. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1321. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1322. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1323. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1324. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1325. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  1326. Doo::loadModel ( 'invoiceReceivables' );
  1327. $invoiceReceivables = new invoiceReceivables ();
  1328. Doo::loadModel ( 'invoiceROLog' );
  1329. $invoiceROLog = new invoiceROLog ();
  1330. Doo::loadModel ( 'invoiceStatistics' );
  1331. $invoiceStatistics = new invoiceStatistics ();
  1332. Doo::loadModel ( 'invoice' );
  1333. $invoice = new invoice ();
  1334. Doo::loadClass ( 'XDeode' );
  1335. $XDeode = new XDeode ( 5 );
  1336. Doo::loadModel ( 'invoiceOperationLog' );
  1337. $invoiceOperationLog = new invoiceOperationLog ();
  1338. $iidKey = $XDeode->decode ( $iidKey );
  1339. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  1340. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1341. // 收款录入 并绑定发票
  1342. Doo::db ()->beginTransaction ();
  1343. $item = array (
  1344. 'bindStatus' => 1,
  1345. 'iid' => $invoiceDetail ['iid'],
  1346. 'bindDate' => date ( "Y-m-d H:i:s" ),
  1347. 'receivablesPrice' => $receivablesPrice,
  1348. 'receivablesMessage' => $receivablesMessage,
  1349. 'receivablesSerial' => $receivablesSerial,
  1350. 'receivablesBank' => $receivablesBank,
  1351. 'receivablesDate' => $receivablesDate,
  1352. 'inputStaff' => $this->staff [0] ['username'],
  1353. 'accountClerk' => $this->staff [0] ['username'],
  1354. 'date' => date ( "Y-m-d" ),
  1355. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  1356. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  1357. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1358. );
  1359. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1360. $item = array ();
  1361. // 收款操作日志
  1362. $item = array (
  1363. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  1364. );
  1365. $item += array (
  1366. 'date' => date ( "Y-m-d" ),
  1367. 'status' => 1,
  1368. 'img' => $this->staff [0] ['avatar'],
  1369. 'username' => $this->staff [0] ['username'],
  1370. 'uid' => $this->staff [0] ['sid'],
  1371. 'category' => $this->staff [0] ['category'],
  1372. 'irid' => $irid
  1373. );
  1374. $invoiceROLog->setInvoiceROLog ( $item );
  1375. // 收款统计
  1376. $item = array (
  1377. 'date' => date ( "Y-m-d H:i:s" ),
  1378. 'priceClass' => 2,
  1379. 'irid' => $irid,
  1380. 'cid' => $invoiceDetail ['cid'],
  1381. 'staff' => $invoiceDetail ['sid'],
  1382. 'receivablesPrice' => $receivablesPrice
  1383. );
  1384. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1385. // 收款 入 发票
  1386. $detail = $invoiceDetail;
  1387. $iridString = "";
  1388. if (empty ( $detail ['irid'] ))
  1389. $iridString = $irid;
  1390. else
  1391. $iridString = $detail ['irid'] . ',' . $irid;
  1392. $item = array (
  1393. 'irid' => $iridString,
  1394. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1395. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1396. 'iid' => $detail ['iid']
  1397. );
  1398. $invoiceReceivables = new invoiceReceivables ();
  1399. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  1400. if ($detail ['invoicePrice'] <= $sum)
  1401. $item += array (
  1402. 'untreadStatus' => 3
  1403. );
  1404. $invoice->setInvoiceByCondition ( $item );
  1405. // 操作日志
  1406. $item = array (
  1407. 'date' => date ( "Y-m-d H:i:s" ),
  1408. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  1409. 'status' => 8,
  1410. 'img' => $this->staff [0] ['avatar'],
  1411. 'username' => $this->staff [0] ['username'],
  1412. 'uid' => $this->staff [0] ['sid'],
  1413. 'category' => $this->staff [0] ['category'],
  1414. 'iid' => $detail ['iid']
  1415. );
  1416. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1417. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1418. $accountPrice = 0;
  1419. foreach ( $list as $key => $value ) {
  1420. $accountPrice += $value ['receivablesPrice'];
  1421. }
  1422. $item = array (
  1423. 'date' => date ( "Y-m-d H:i:s" ),
  1424. 'priceClass' => 3,
  1425. 'cid' => $invoiceDetail ['cid'],
  1426. 'staff' => $invoiceDetail ['sid'],
  1427. 'accountPrice' => $accountPrice
  1428. );
  1429. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1430. Doo::db ()->commit ();
  1431. }
  1432. return '/invoiceReceivables';
  1433. }
  1434. /**
  1435. * 检索未入账发票数据 function sir() { }
  1436. */
  1437. /**
  1438. * 录入收款数据
  1439. * @return string
  1440. */
  1441. function invoiceReceivablesDo() {
  1442. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1443. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1444. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1445. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1446. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1447. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1448. Doo::loadModel ( 'invoiceReceivables' );
  1449. $invoiceReceivables = new invoiceReceivables ();
  1450. Doo::loadModel ( 'invoiceROLog' );
  1451. $invoiceROLog = new invoiceROLog ();
  1452. Doo::loadModel ( 'invoiceStatistics' );
  1453. $invoiceStatistics = new invoiceStatistics ();
  1454. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  1455. $item = array (
  1456. 'receivablesPrice' => $receivablesPrice,
  1457. 'receivablesMessage' => $receivablesMessage,
  1458. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1459. 'receivablesBank' => $receivablesBank,
  1460. 'receivablesDate' => $receivablesDate,
  1461. 'inputStaff' => $this->staff [0] ['username'],
  1462. 'date' => date ( "Y-m-d" ),
  1463. 'receivablesCategory' => $receivablesCategory,
  1464. 'receivablesStaff' => $receivablesStaff
  1465. );
  1466. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1467. $item += array (
  1468. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1469. 'inputType' => 1
  1470. );
  1471. }
  1472. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1473. $item = array ();
  1474. // 收款操作日志
  1475. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1476. $item = array (
  1477. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1478. );
  1479. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1480. $item = array (
  1481. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1482. );
  1483. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1484. $receivablesStaff = explode ( '-', $receivablesStaff );
  1485. $item = array (
  1486. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1487. );
  1488. }
  1489. $item += array (
  1490. 'date' => date ( "Y-m-d" ),
  1491. 'status' => 1,
  1492. 'img' => $this->staff [0] ['avatar'],
  1493. 'username' => $this->staff [0] ['username'],
  1494. 'uid' => $this->staff [0] ['sid'],
  1495. 'category' => $this->staff [0] ['category'],
  1496. 'irid' => $irid
  1497. );
  1498. $invoiceROLog->setInvoiceROLog ( $item );
  1499. $item = array (
  1500. 'date' => date ( "Y-m-d H:i:s" ),
  1501. 'priceClass' => 2,
  1502. 'irid' => $irid,
  1503. 'receivablesPrice' => $receivablesPrice
  1504. );
  1505. if ($receivablesCategory != 'PUBLIC') {
  1506. $receivablesCategory = explode ( ":", $receivablesCategory );
  1507. $item += array (
  1508. 'cid' => $receivablesCategory [0]
  1509. );
  1510. }
  1511. if ($receivablesStaff2 != 'PUBLIC') {
  1512. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  1513. $item += array (
  1514. 'staff' => $receivablesStaff [0]
  1515. );
  1516. }
  1517. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1518. }
  1519. return "/invoiceReceivables";
  1520. }
  1521. /**
  1522. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  1523. */
  1524. function invoiceReceivablesClaim() {
  1525. Doo::loadModel ( 'invoiceReceivables' );
  1526. $invoiceReceivables = new invoiceReceivables ();
  1527. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1528. $this->data ['receivablesList'] = $receivablesList;
  1529. $this->data ['memu'] = "invoice";
  1530. $this->data ['staff'] = $this->staff;
  1531. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  1532. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  1533. }
  1534. /**
  1535. * 更新收款相关数据
  1536. */
  1537. function invoiceReceivablesUpdateClaim() {
  1538. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1539. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1540. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1541. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1542. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1543. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1544. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1545. if (empty ( $claimKey ))
  1546. die ( 'illegal request' );
  1547. Doo::loadModel ( 'invoiceReceivables' );
  1548. $invoiceReceivables = new invoiceReceivables ();
  1549. Doo::loadModel ( 'invoiceROLog' );
  1550. $invoiceROLog = new invoiceROLog ();
  1551. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  1552. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1553. if (empty ( $detail ))
  1554. die ( 'illegal request' );
  1555. $invoiceReceivables = new invoiceReceivables ();
  1556. $item = array (
  1557. 'irid' => $detail ['irid']
  1558. );
  1559. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1560. $item += array (
  1561. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1562. );
  1563. }
  1564. if (! empty ( $receivablesCategory ))
  1565. $item += array (
  1566. 'receivablesCategory' => $receivablesCategory
  1567. );
  1568. if (! empty ( $receivablesStaff ))
  1569. $item += array (
  1570. 'receivablesStaff' => $receivablesStaff
  1571. );
  1572. if (! empty ( $receivablesPrice ))
  1573. $item += array (
  1574. 'receivablesPrice' => $receivablesPrice
  1575. );
  1576. if (! empty ( $receivablesMessage ))
  1577. $item += array (
  1578. 'receivablesMessage' => $receivablesMessage
  1579. );
  1580. if (! empty ( $receivablesBank ))
  1581. $item += array (
  1582. 'receivablesBank' => $receivablesBank
  1583. );
  1584. if (! empty ( $receivablesDate ))
  1585. $item += array (
  1586. 'receivablesDate' => $receivablesDate
  1587. );
  1588. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1589. // 收款操作日志
  1590. $item = array ();
  1591. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1592. $item = array (
  1593. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1594. );
  1595. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1596. $item = array (
  1597. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1598. );
  1599. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1600. $receivablesStaff = explode ( '-', $receivablesStaff );
  1601. $item = array (
  1602. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1603. );
  1604. }
  1605. $item += array (
  1606. 'date' => date ( "Y-m-d" ),
  1607. 'status' => 1,
  1608. 'img' => $this->staff [0] ['avatar'],
  1609. 'username' => $this->staff [0] ['username'],
  1610. 'uid' => $this->staff [0] ['sid'],
  1611. 'category' => $this->staff [0] ['category'],
  1612. 'irid' => $detail ['irid']
  1613. );
  1614. $invoiceROLog->setInvoiceROLog ( $item );
  1615. return '/invoiceReceivablesAS';
  1616. }
  1617. function invoiceReceivablesDelete() {
  1618. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1619. if (empty ( $claimKey ))
  1620. die ( 'illegal request' );
  1621. Doo::loadModel ( 'invoiceReceivables' );
  1622. $invoiceReceivables = new invoiceReceivables ();
  1623. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  1624. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1625. if (empty ( $detail ))
  1626. die ( 'illegal request' );
  1627. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  1628. return '/invoiceReceivablesAS';
  1629. }
  1630. /**
  1631. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  1632. */
  1633. function invoiceReceivablesAscription() {
  1634. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1635. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  1636. Doo::loadModel ( 'invoiceReceivables' );
  1637. $invoiceReceivables = new invoiceReceivables ();
  1638. Doo::loadModel ( 'invoiceROLog' );
  1639. $invoiceROLog = new invoiceROLog ();
  1640. Doo::loadModel ( 'invoiceStatistics' );
  1641. $invoiceStatistics = new invoiceStatistics ();
  1642. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1643. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  1644. $item = array (
  1645. 'irid' => $detail ['irid'],
  1646. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  1647. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  1648. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1649. 'recepitTitleMark' => $recepitTitleMark,
  1650. 'source' => 1
  1651. );
  1652. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1653. $item = array (
  1654. 'date' => date ( "Y-m-d" ),
  1655. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  1656. 'status' => 2,
  1657. 'img' => $this->staff [0] ['avatar'],
  1658. 'username' => $this->staff [0] ['username'],
  1659. 'uid' => $this->staff [0] ['sid'],
  1660. 'category' => $this->staff [0] ['category'],
  1661. 'irid' => $irid
  1662. );
  1663. $invoiceROLog->setInvoiceROLog ( $item );
  1664. $item = array (
  1665. 'cid' => $this->staff [0] ['cid'],
  1666. 'staff' => $this->staff [0] ['sid']
  1667. );
  1668. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'] );
  1669. }
  1670. return "/invoiceReceivablesClaim";
  1671. }
  1672. /**
  1673. */
  1674. function invoiceMyReceivables() {
  1675. Doo::loadModel ( 'invoiceReceivables' );
  1676. $invoiceReceivables = new invoiceReceivables ();
  1677. Doo::loadModel ( 'invoiceStatistics' );
  1678. $invoiceStatistics = new invoiceStatistics ();
  1679. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  1680. $year = date ( "Y" );
  1681. $tmp_date = date ( "Ym" );
  1682. $tmp_year = substr ( $tmp_date, 0, 4 );
  1683. $tmp_mon = substr ( $tmp_date, 4, 2 );
  1684. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  1685. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  1686. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  1687. $htm = $this->showCache ( $path );
  1688. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1689. $this->data ['isMonth'] = $isMonth;
  1690. $this->data ['htm'] = $htm;
  1691. $this->data ['list'] = $list;
  1692. $this->data ['memu'] = "invoice";
  1693. $this->data ['staff'] = $this->staff;
  1694. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1695. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  1696. }
  1697. /**
  1698. * 收款绑定发票 ,一个收款只能绑定一个发票
  1699. */
  1700. function invoiceBindReceivables() {
  1701. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1702. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1703. Doo::loadModel ( 'invoice' );
  1704. $invoice = new invoice ();
  1705. Doo::loadModel ( 'invoiceReceivables' );
  1706. $invoiceReceivables = new invoiceReceivables ();
  1707. Doo::loadModel ( 'invoiceOperationLog' );
  1708. $invoiceOperationLog = new invoiceOperationLog ();
  1709. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  1710. die ( 'illegal request' );
  1711. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1712. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  1713. if (empty ( $detail ) && empty ( $detailM ))
  1714. die ( 'illegal request' );
  1715. if ($detail ['untreadStatus'] == 3)
  1716. die ( 'illegal request' );
  1717. // if ($detailM ['receivablesPrice'] >= $detail ['invoicePrice']) {
  1718. // $price = $detailM ['receivablesPrice'] - $detail ['invoicePrice'];
  1719. // die ( '<p>收款金额超出开票金额 ¥' . $price . '元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>' );
  1720. // }
  1721. $item = array (
  1722. 'irid' => $detailM ['irid'],
  1723. 'bindStatus' => 1,
  1724. 'iid' => $detail ['iid'],
  1725. 'accountClerk' => $this->staff [0] ['username'],
  1726. 'bindDate' => date ( "Y-m-d H:i:s" )
  1727. );
  1728. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1729. $iridString = "";
  1730. if (empty ( $detail ['irid'] ))
  1731. $iridString = $detailM ['irid'];
  1732. else
  1733. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1734. $item = array (
  1735. 'iid' => $detail ['iid'],
  1736. 'irid' => $iridString
  1737. );
  1738. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  1739. if ($detail ['invoicePrice'] <= $sum)
  1740. $item += array (
  1741. 'untreadStatus' => 3
  1742. );
  1743. $invoice->setInvoiceByCondition ( $item );
  1744. // 操作日志
  1745. $item = array (
  1746. 'date' => date ( "Y-m-d H:i:s" ),
  1747. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  1748. 'status' => 8,
  1749. 'img' => $this->staff [0] ['avatar'],
  1750. 'username' => $this->staff [0] ['username'],
  1751. 'uid' => $this->staff [0] ['sid'],
  1752. 'category' => $this->staff [0] ['category'],
  1753. 'iid' => $detail ['iid']
  1754. );
  1755. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1756. Doo::loadModel ( 'invoiceStatistics' );
  1757. $invoiceStatistics = new invoiceStatistics ();
  1758. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1759. $accountPrice = 0;
  1760. foreach ( $list as $key => $value ) {
  1761. $accountPrice += $value ['receivablesPrice'];
  1762. }
  1763. $item = array (
  1764. 'date' => date ( "Y-m-d H:i:s" ),
  1765. 'priceClass' => 3,
  1766. 'cid' => $detail ['cid'],
  1767. 'staff' => $detail ['sid'],
  1768. 'accountPrice' => $accountPrice
  1769. );
  1770. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1771. return "/invoiceReceivables";
  1772. }
  1773. /**
  1774. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 function invoiceEnterReceivables() { $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; // $invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); Doo::loadModel ( 'invoiceStatistics' ); $invoiceStatistics = new invoiceStatistics (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); if (empty ( $detail )) die ( 'illegal request' ); if (empty ( $detail ['irid'] )) die ( 'illegal request' ); $item = array ( 'untreadStatus' => 3, 'updateTime' => date ( "Y-m-d H:i:s" ), 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "发票" . $detail ['invoiceSerial'] . "收款完成", 'status' => 9, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] ); $accountPrice = 0; foreach ( $list as $key => $value ) { $accountPrice += $value ['receivablesPrice']; } $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'priceClass' => 3, 'cid' => $this->staff [0] ['cid'], 'staff' => $this->staff [0] ['sid'], 'accountPrice' => $accountPrice ); $invoiceStatistics->setInvoiceStatisticsByCondition ( $item ); return "/invoice"; }
  1775. */
  1776. function invoiceAggregate() {
  1777. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1778. Doo::loadModel ( 'invoiceStatistics' );
  1779. $invoiceStatistics = new invoiceStatistics ();
  1780. Doo::loadModel ( 'L_category' );
  1781. $Lcategory = new L_category ();
  1782. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  1783. $LcategoryList = $Lcategory->getCategory ();
  1784. // print_r($isList);
  1785. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  1786. foreach ( $LcategoryList as $key => $value ) {
  1787. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  1788. $month = 1;
  1789. $invoicePriceYear = 0;
  1790. $receivablesPriceYear = 0;
  1791. $accountPriceYear = 0;
  1792. for(; $month <= 12; $month ++) {
  1793. $flag = true;
  1794. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  1795. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  1796. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1797. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1798. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1799. ';
  1800. $invoicePriceYear += $v ['invoicePrice'];
  1801. $receivablesPriceYear += $v ['receivablesPrice'];
  1802. $accountPriceYear += $v ['accountPrice'];
  1803. $flag = false;
  1804. break;
  1805. }
  1806. }
  1807. if ($flag)
  1808. $html .= '<td class="taR"></td>
  1809. <td class="taR"></td>
  1810. <td class="taR"><b></b></td>
  1811. ';
  1812. }
  1813. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1814. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1815. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1816. ';
  1817. $html .= '</tr>';
  1818. }
  1819. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  1820. $invoicePriceYear = 0;
  1821. $receivablesPriceYear = 0;
  1822. $accountPriceYear = 0;
  1823. for($month = 1; $month <= 12; $month ++) {
  1824. $flag = true;
  1825. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  1826. if ($month == $v ['month']) {
  1827. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1828. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1829. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1830. ';
  1831. $invoicePriceYear += $v ['invoicePrice'];
  1832. $receivablesPriceYear += $v ['receivablesPrice'];
  1833. $accountPriceYear += $v ['accountPrice'];
  1834. $flag = false;
  1835. break;
  1836. }
  1837. }
  1838. if ($flag) {
  1839. $html .= '<td class="taR"></td>
  1840. <td class="taR"></td>
  1841. <td class="taR"><b></b></td>
  1842. ';
  1843. }
  1844. }
  1845. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1846. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1847. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1848. ';
  1849. $html .= '</tr>';
  1850. // print_r($isList);
  1851. $this->data ['html'] = $html;
  1852. $this->data ['LcategoryList'] = $LcategoryList;
  1853. $this->data ['isList'] = $isList;
  1854. $this->data ['year'] = $year;
  1855. $this->data ['memu'] = "invoice";
  1856. $this->data ['staff'] = $this->staff;
  1857. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1858. $this->render ( "/admin/invoiceAggregate", $this->data );
  1859. }
  1860. function invoiceAggregateStaff() {
  1861. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1862. Doo::loadModel ( 'invoiceStatistics' );
  1863. $invoiceStatistics = new invoiceStatistics ();
  1864. Doo::loadModel ( 'L_category' );
  1865. $Lcategory = new L_category ();
  1866. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  1867. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  1868. $cStaff = $Lcategory->getCategoryStaff ();
  1869. $html = '';
  1870. foreach ( $cStaff as $key => $value ) {
  1871. $categoryFir = true;
  1872. foreach ( $value ['staff'] as $k => $v ) {
  1873. if ($categoryFir) {
  1874. $width = count ( $value ['staff'] ) + 1;
  1875. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  1876. $categoryFir = false;
  1877. } else
  1878. $html .= '<tr>';
  1879. $html .= '<th>' . $v ['username'] . '</th>';
  1880. $invoicePriceStaffYear = 0;
  1881. $receivablesPriceStaffYear = 0;
  1882. $accountPriceStaffYear = 0;
  1883. for($month = 1; $month <= 12; $month ++) {
  1884. $flag = true;
  1885. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  1886. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  1887. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  1888. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  1889. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  1890. ';
  1891. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1892. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1893. $accountPriceStaffYear += $slv ['accountPrice'];
  1894. $flag = false;
  1895. break;
  1896. }
  1897. }
  1898. if ($flag)
  1899. $html .= '<td class="taR"></td>
  1900. <td class="taR"></td>
  1901. <td class="taR"><b></b></td>
  1902. ';
  1903. }
  1904. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1905. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1906. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1907. ';
  1908. }
  1909. $html .= '</tr>';
  1910. // 小计
  1911. if (! empty ( $value ['staff'] )) {
  1912. $html .= '<tr><th class="taR">小计</th>';
  1913. $invoicePriceStaffYear = 0;
  1914. $receivablesPriceStaffYear = 0;
  1915. $accountPriceStaffYear = 0;
  1916. for($month = 1; $month <= 12; $month ++) {
  1917. $flag = true;
  1918. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  1919. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  1920. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  1921. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  1922. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  1923. ';
  1924. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1925. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1926. $accountPriceStaffYear += $slv ['accountPrice'];
  1927. $flag = false;
  1928. break;
  1929. }
  1930. }
  1931. if ($flag)
  1932. $html .= '<td class="taR"></td>
  1933. <td class="taR"></td>
  1934. <td class="taR"><b></b></td>
  1935. ';
  1936. }
  1937. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1938. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1939. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1940. ';
  1941. $html .= '</tr>';
  1942. }
  1943. }
  1944. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  1945. $invoicePriceYear = 0;
  1946. $receivablesPriceYear = 0;
  1947. $accountPriceYear = 0;
  1948. for($month = 1; $month <= 12; $month ++) {
  1949. $flag = true;
  1950. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  1951. if ($month == $v ['month']) {
  1952. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  1953. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  1954. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  1955. ';
  1956. $invoicePriceYear += $v ['invoicePrice'];
  1957. $receivablesPriceYear += $v ['receivablesPrice'];
  1958. $accountPriceYear += $v ['accountPrice'];
  1959. $flag = false;
  1960. break;
  1961. }
  1962. }
  1963. if ($flag)
  1964. $html .= '<td class="taR"></td>
  1965. <td class="taR"></td>
  1966. <td class="taR"><b></b></td>
  1967. ';
  1968. }
  1969. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1970. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1971. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1972. ';
  1973. $html .= '</tr>';
  1974. $this->data ['html'] = $html;
  1975. $this->data ['isList'] = $toteList;
  1976. $this->data ['year'] = $year;
  1977. $this->data ['memu'] = "invoice";
  1978. $this->data ['staff'] = $this->staff;
  1979. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1980. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  1981. }
  1982. function invoiceAggregateCategory() {
  1983. Doo::loadClass ( 'XDeode' );
  1984. $XDeode = new XDeode ( 5 );
  1985. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  1986. $cid = $XDeode->decode ( $cid );
  1987. if (! is_numeric ( $cid ))
  1988. die ( 'illegal request' );
  1989. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1990. Doo::loadModel ( 'invoiceStatistics' );
  1991. $invoiceStatistics = new invoiceStatistics ();
  1992. Doo::loadModel ( 'staff' );
  1993. $staff = new staff ();
  1994. $list = $staff->getStaffByCid ( $cid );
  1995. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  1996. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  1997. if (empty ( $list ))
  1998. die ( '该办事处没有成员' );
  1999. $htmlA = $htmlB = $htmlC = $html = '';
  2000. foreach ( $list as $key => $value ) {
  2001. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  2002. $htmlB = '<tr><th class="taC">收款</th>';
  2003. $htmlC = '<tr><th class="taC">入账</th>';
  2004. $invoicePriceStaffYear = 0;
  2005. $receivablesPriceStaffYear = 0;
  2006. $accountPriceStaffYear = 0;
  2007. for($month = 1; $month <= 12; $month ++) {
  2008. $flag = true;
  2009. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  2010. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  2011. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  2012. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  2013. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  2014. $invoicePriceStaffYear += $v ['invoicePrice'];
  2015. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  2016. $accountPriceStaffYear += $v ['accountPrice'];
  2017. $flag = false;
  2018. break;
  2019. }
  2020. }
  2021. if ($flag) {
  2022. $htmlA .= '<td class="taR">-</td>';
  2023. $htmlB .= '<td class="taR">-</td>';
  2024. $htmlC .= '<td class="taR"><b>-</b></td>';
  2025. }
  2026. }
  2027. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  2028. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  2029. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  2030. $htmlA .= '</tr>';
  2031. $htmlB .= '</tr>';
  2032. $htmlC .= '</tr>';
  2033. $html .= $htmlA . $htmlB . $htmlC;
  2034. }
  2035. $htmlA = $htmlB = $htmlC = "";
  2036. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  2037. $htmlB = '<tr><th class="taC">收款</th>';
  2038. $htmlC = '<tr><th class="taC">入账</th>';
  2039. $invoicePriceStaffYear = 0;
  2040. $receivablesPriceStaffYear = 0;
  2041. $accountPriceStaffYear = 0;
  2042. for($month = 1; $month <= 12; $month ++) {
  2043. $flag = true;
  2044. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  2045. if ($month == $v ['month']) {
  2046. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  2047. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  2048. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  2049. $invoicePriceStaffYear += $v ['invoicePrice'];
  2050. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  2051. $accountPriceStaffYear += $v ['accountPrice'];
  2052. $flag = false;
  2053. break;
  2054. }
  2055. }
  2056. if ($flag) {
  2057. $htmlA .= '<td class="taR">-</td>';
  2058. $htmlB .= '<td class="taR">-</td>';
  2059. $htmlC .= '<td class="taR"><b>-</b></td>';
  2060. }
  2061. }
  2062. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  2063. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  2064. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  2065. $htmlA .= '</tr>';
  2066. $htmlB .= '</tr>';
  2067. $htmlC .= '</tr>';
  2068. $html .= $htmlA . $htmlB . $htmlC;
  2069. $this->data ['html'] = $html;
  2070. $this->data ['cidKey'] = $cidKey;
  2071. $this->data ['slist'] = $list;
  2072. $this->data ['isList'] = $toteList;
  2073. $this->data ['year'] = $year;
  2074. $this->data ['memu'] = "invoice";
  2075. $this->data ['staff'] = $this->staff;
  2076. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2077. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  2078. }
  2079. function invoiceAchieve() {
  2080. Doo::loadModel ( 'invoice' );
  2081. $invoice = new invoice ();
  2082. Doo::loadClass ( 'XDeode' );
  2083. $XDeode = new XDeode ( 5 );
  2084. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2085. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2086. $page_size = 18;
  2087. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2088. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2089. $get = "/" . $date;
  2090. $con = '';
  2091. if ($date == 'MONTHO')
  2092. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2093. elseif ($date == 'MONTHT')
  2094. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2095. elseif ($date == 'MONTHY')
  2096. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2097. if (! empty ( $MebSea )) {
  2098. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2099. $get .= "/" . $MebSea;
  2100. }
  2101. $pageinfo ['page'] = array (
  2102. 'previous' => ''
  2103. );
  2104. $sql = 'status=2 and printStatus=1 and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  2105. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  2106. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2107. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2108. // print_r($pageinfo);
  2109. $this->data ['MebSeaEn'] = $MebSea;
  2110. $this->data ['MebSea'] = urlencode ( $MebSea );
  2111. $this->data ['get'] = $get;
  2112. $this->data ['page'] = $pageinfo;
  2113. $this->data ['list'] = $list;
  2114. $this->data ['date'] = $date;
  2115. $this->data ['memu'] = "invoice";
  2116. $this->data ['staff'] = $this->staff;
  2117. $this->data ['receiptMemu'] = 'invoice';
  2118. $this->render ( "/admin/invoiceAchieve", $this->data );
  2119. }
  2120. function invoiceMyUnAccountAchieve() {
  2121. Doo::loadModel ( 'invoice' );
  2122. $invoice = new invoice ();
  2123. Doo::loadClass ( 'XDeode' );
  2124. $XDeode = new XDeode ( 5 );
  2125. Doo::loadModel ( 'staff' );
  2126. $staff = new staff ();
  2127. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2128. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2129. $page_size = 18;
  2130. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2131. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2132. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2133. $dateArr = explode ( ':', $date );
  2134. $D1 = '';
  2135. $D2 = '';
  2136. if (! empty ( $date )) {
  2137. $D1 = $dateArr [0];
  2138. $D2 = $dateArr [1];
  2139. }
  2140. $con = '';
  2141. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2142. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2143. if (! empty ( $MebSea )) {
  2144. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2145. }
  2146. $pageinfo ['page'] = array (
  2147. 'previous' => ''
  2148. );
  2149. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  2150. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  2151. $action = "invoiceMyUnAccountAchieve";
  2152. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2153. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2154. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2155. Doo::loadModel ( 'express' );
  2156. $express = new express ();
  2157. $expressList = $express->getExpressByAll ();
  2158. $this->data ['expressList'] = $expressList;
  2159. // print_r($list);
  2160. $this->data ['MebSeaEn'] = $MebSea;
  2161. $this->data ['get'] = $get;
  2162. $this->data ['page'] = $pageinfo;
  2163. $this->data ['date'] = $date;
  2164. $this->data ['list'] = $list;
  2165. $this->data ['memu'] = "invoice";
  2166. $this->data ['staff'] = $this->staff;
  2167. $this->data ['receiptMemu'] = 'invoice';
  2168. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  2169. }
  2170. function invoiceReceivablesAchieve() {
  2171. Doo::loadModel ( 'invoiceReceivables' );
  2172. $invoiceReceivables = new invoiceReceivables ();
  2173. Doo::loadClass ( 'XDeode' );
  2174. $XDeode = new XDeode ( 5 );
  2175. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2176. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2177. $page_size = 1;
  2178. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2179. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2180. $get = "/" . $date;
  2181. $con = '';
  2182. if ($date == 'MONTHO')
  2183. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2184. elseif ($date == 'MONTHT')
  2185. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2186. elseif ($date == 'MONTHY')
  2187. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2188. if (! empty ( $MebSea )) {
  2189. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  2190. $get .= "/" . $MebSea;
  2191. }
  2192. $pageinfo ['page'] = array (
  2193. 'previous' => ''
  2194. );
  2195. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  2196. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  2197. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2198. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  2199. // print_r($pageinfo);
  2200. $this->data ['MebSeaEn'] = $MebSea;
  2201. $this->data ['MebSea'] = urlencode ( $MebSea );
  2202. $this->data ['get'] = $get;
  2203. $this->data ['page'] = $pageinfo;
  2204. $this->data ['list'] = $list;
  2205. $this->data ['date'] = $date;
  2206. $this->data ['memu'] = "invoice";
  2207. $this->data ['staff'] = $this->staff;
  2208. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  2209. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  2210. }
  2211. /**
  2212. * 收款解绑
  2213. */
  2214. function invoiceUnBundLing() {
  2215. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  2216. Doo::loadModel ( 'invoice' );
  2217. $invoice = new invoice ();
  2218. Doo::loadModel ( 'invoiceReceivables' );
  2219. $invoiceReceivables = new invoiceReceivables ();
  2220. Doo::loadModel ( 'invoiceOperationLog' );
  2221. $invoiceOperationLog = new invoiceOperationLog ();
  2222. Doo::loadModel ( 'invoiceROLog' );
  2223. $invoiceROLog = new invoiceROLog ();
  2224. Doo::loadModel ( 'invoiceStatistics' );
  2225. $invoiceStatistics = new invoiceStatistics ();
  2226. $irid = $invoice->authcode ( $unBundKey );
  2227. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  2228. die ( 'illegal request' );
  2229. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2230. $invoiceDetails = $invoice->getInvoiceByIid ( $irDetails ['iid'] );
  2231. if (empty ( $irDetails ) || $irDetails ['bindStatus'] == 0 || $invoiceDetails ['untreadStatus'] == 2)
  2232. die ( 'illegal request' );
  2233. // 收款
  2234. $item = array (
  2235. 'irid' => $irDetails ['irid'],
  2236. 'bindStatus' => 0,
  2237. 'iid' => 0
  2238. );
  2239. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2240. // 收款操作日志
  2241. $item = array (
  2242. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  2243. 'date' => date ( "Y-m-d" ),
  2244. 'status' => 3,
  2245. 'img' => $this->staff [0] ['avatar'],
  2246. 'username' => $this->staff [0] ['username'],
  2247. 'uid' => $this->staff [0] ['sid'],
  2248. 'category' => $this->staff [0] ['category'],
  2249. 'irid' => $irid
  2250. );
  2251. $invoiceROLog->setInvoiceROLog ( $item );
  2252. // 扣除入账统计金额
  2253. $item = array (
  2254. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['bindDate'] ) ),
  2255. 'priceClass' => 3,
  2256. 'cid' => $invoiceDetails ['cid'],
  2257. 'staff' => $invoiceDetails ['sid'],
  2258. 'accountPrice' => - $irDetails ['receivablesPrice']
  2259. );
  2260. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2261. // 发票解绑去收款ID
  2262. $iridString = $invoiceDetails ['irid'];
  2263. if (! empty ( $invoiceDetails ['irid'] )) {
  2264. $list = explode ( ',', $invoiceDetails ['irid'] );
  2265. foreach ( $list as $key => $value ) {
  2266. if ($value == $irDetails ['irid']) {
  2267. unset ( $list [$key] );
  2268. break;
  2269. }
  2270. }
  2271. $iridString = implode ( ",", $list );
  2272. }
  2273. $item = array (
  2274. 'iid' => $invoiceDetails ['iid'],
  2275. 'irid' => $iridString,
  2276. 'updateTime' => date ( "Y-m-d H:i:s" )
  2277. );
  2278. if ($invoiceDetails ['untreadStatus'] == 3)
  2279. $item += array (
  2280. 'untreadStatus' => 0
  2281. );
  2282. $invoice->setInvoiceByCondition ( $item );
  2283. $item = array (
  2284. 'date' => date ( "Y-m-d H:i:s" ),
  2285. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  2286. 'status' => 11,
  2287. 'img' => $this->staff [0] ['avatar'],
  2288. 'username' => $this->staff [0] ['username'],
  2289. 'uid' => $this->staff [0] ['sid'],
  2290. 'category' => $this->staff [0] ['category'],
  2291. 'iid' => $invoiceDetails ['iid']
  2292. );
  2293. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2294. return "/invoiceReceivablesAS";
  2295. }
  2296. /**
  2297. * 发票管理
  2298. */
  2299. function invoiceAS() {
  2300. Doo::loadModel ( 'invoice' );
  2301. $invoice = new invoice ();
  2302. Doo::loadModel ( 'invoiceReceivables' );
  2303. $invoiceReceivables = new invoiceReceivables ();
  2304. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2305. $page_size = 18;
  2306. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2307. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  2308. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2309. $dateArr = explode ( ':', $date );
  2310. $D1 = '';
  2311. $D2 = '';
  2312. if (! empty ( $date )) {
  2313. $D1 = $dateArr [0];
  2314. $D2 = $dateArr [1];
  2315. }
  2316. $con = '1';
  2317. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2318. $con .= ' and date BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2319. if ($status == 'UNRECORD')
  2320. $con .= ' and untreadStatus=0';
  2321. elseif ($status == 'RECORD')
  2322. $con .= ' and untreadStatus=3';
  2323. elseif ($status == 'BOUNCED')
  2324. $con .= ' and untreadStatus=2';
  2325. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2326. if (! empty ( $MebSea )) {
  2327. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2328. }
  2329. $pageinfo ['page'] = array (
  2330. 'previous' => ''
  2331. );
  2332. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  2333. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2334. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  2335. // print_r($list);
  2336. // foreach ($list as $key=>$value){
  2337. // $list[$key]['rpSum']=0;
  2338. // if (!empty($value['irid']))
  2339. // $list[$key]['rpSum']=$invoiceReceivables->getSumOfReceivablesPrice($value['irid']);
  2340. // }
  2341. $this->data ['MebSeaEn'] = $MebSea;
  2342. $this->data ['MebSea'] = urlencode ( $MebSea );
  2343. $this->data ['date'] = $date;
  2344. $this->data ['page'] = $pageinfo;
  2345. $this->data ['get'] = $get;
  2346. $this->data ['list'] = $list;
  2347. $this->data ['status'] = $status;
  2348. $this->data ['memu'] = "invoice";
  2349. $this->data ['staff'] = $this->staff;
  2350. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2351. $this->render ( "/admin/invoiceAS", $this->data );
  2352. }
  2353. /**
  2354. * 收款管理
  2355. */
  2356. function invoiceReceivablesAS() {
  2357. Doo::loadModel ( 'invoiceReceivables' );
  2358. $invoiceReceivables = new invoiceReceivables ();
  2359. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2360. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  2361. $page_size = 6;
  2362. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2363. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  2364. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2365. $dateArr = explode ( ':', $date );
  2366. $D1 = '';
  2367. $D2 = '';
  2368. if (! empty ( $date )) {
  2369. $D1 = $dateArr [0];
  2370. $D2 = $dateArr [1];
  2371. }
  2372. $con = '1';
  2373. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2374. $con .= ' and date BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2375. $descField = 'bindDate';
  2376. if ($timeType == 'CREATE')
  2377. $descField = 'date';
  2378. if ($status == 'Unclaimed')
  2379. $con .= ' and bindStatus=0';
  2380. elseif ($status == 'Credited')
  2381. $con .= ' and bindStatus=1';
  2382. elseif ($status == 'Claim')
  2383. $con .= ' and bindStatus=0 and receivablesStaff="PUBLIC"';
  2384. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2385. if (! empty ( $MebSea )) {
  2386. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  2387. }
  2388. $pageinfo ['page'] = array (
  2389. 'previous' => ''
  2390. );
  2391. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  2392. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2393. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $con, 'desc', $descField );
  2394. // print_r($list);
  2395. $this->data ['timeType'] = $timeType;
  2396. $this->data ['MebSeaEn'] = $MebSea;
  2397. $this->data ['MebSea'] = urlencode ( $MebSea );
  2398. $this->data ['date'] = $date;
  2399. $this->data ['page'] = $pageinfo;
  2400. $this->data ['get'] = $get;
  2401. $this->data ['list'] = $list;
  2402. $this->data ['status'] = $status;
  2403. $this->data ['memu'] = "invoice";
  2404. $this->data ['staff'] = $this->staff;
  2405. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2406. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  2407. }
  2408. function invoiceApprovalAchieve() {
  2409. Doo::loadModel ( 'invoice' );
  2410. $invoice = new invoice ();
  2411. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2412. $page_size = 12;
  2413. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2414. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2415. $get = "/" . $date;
  2416. $con = '';
  2417. if ($date == 'MONTHO')
  2418. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2419. elseif ($date == 'MONTHT')
  2420. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2421. elseif ($date == 'MONTHY')
  2422. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2423. if (! empty ( $MebSea )) {
  2424. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2425. $get .= "/" . $MebSea;
  2426. }
  2427. $pageinfo ['page'] = array (
  2428. 'previous' => ''
  2429. );
  2430. $sql = '(status=1 or status=3 or status=4) and processApprovals!=""' . $con;
  2431. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  2432. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2433. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2434. // print_r($list);
  2435. $this->data ['MebSeaEn'] = $MebSea;
  2436. $this->data ['MebSea'] = urlencode ( $MebSea );
  2437. $this->data ['get'] = $get;
  2438. $this->data ['page'] = $pageinfo;
  2439. $this->data ['list'] = $list;
  2440. $this->data ['date'] = $date;
  2441. $this->data ['memu'] = "invoice";
  2442. $this->data ['staff'] = $this->staff;
  2443. $this->data ['receiptMemu'] = 'invoiceApproval';
  2444. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  2445. }
  2446. function invoiceTAchieve() {
  2447. Doo::loadModel ( 'invoice' );
  2448. $invoice = new invoice ();
  2449. Doo::loadClass ( 'XDeode' );
  2450. $XDeode = new XDeode ( 5 );
  2451. Doo::loadModel ( 'staff' );
  2452. $staff = new staff ();
  2453. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2454. $page_size = 2;
  2455. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2456. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2457. $get = "/" . $date;
  2458. $con = '';
  2459. if ($date == 'MONTHO')
  2460. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2461. elseif ($date == 'MONTHT')
  2462. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2463. elseif ($date == 'MONTHY')
  2464. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2465. if (! empty ( $MebSea )) {
  2466. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2467. $get .= "/" . $MebSea;
  2468. }
  2469. $pageinfo ['page'] = array (
  2470. 'previous' => ''
  2471. );
  2472. $sql = "";
  2473. $action = "";
  2474. if ($this->ACTION == 'invoicePrintAchieve') {
  2475. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2476. $action = "invoicePrintAchieve";
  2477. } elseif ($this->ACTION == 'invoicePostAchieve') {
  2478. // and untreadStatus=0
  2479. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  2480. $action = "invoicePostAchieve";
  2481. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  2482. $sql = " printStatus=1 and untreadStatus=2 and status=2 " . $con;
  2483. $action = "invoiceUntreadAchieve";
  2484. }
  2485. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2486. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2487. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2488. $this->data ['MebSeaEn'] = $MebSea;
  2489. $this->data ['MebSea'] = urlencode ( $MebSea );
  2490. $this->data ['get'] = $get;
  2491. $this->data ['page'] = $pageinfo;
  2492. $this->data ['date'] = $date;
  2493. $this->data ['memu'] = "invoice";
  2494. $this->data ['staff'] = $this->staff;
  2495. if ($this->ACTION == 'invoicePrintAchieve') {
  2496. foreach ( $list as $key => $value ) {
  2497. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2498. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2499. if (! empty ( $lastApprover )) {
  2500. $lastApproverKey = array_keys ( $lastApprover );
  2501. $lastApprover = end ( $lastApprover );
  2502. $staffDetail = $staff->getOne ( array (
  2503. 'where' => 'sid=' . end ( $lastApproverKey ),
  2504. 'asArray' => true
  2505. ) );
  2506. $lastApprover ['username'] = $staffDetail ['username'];
  2507. }
  2508. $list [$key] ['lastApprover'] = $lastApprover;
  2509. }
  2510. $this->data ['receiptMemu'] = 'invoicePrint';
  2511. $this->data ['list'] = $list;
  2512. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  2513. } elseif ($this->ACTION == 'invoicePostAchieve') {
  2514. Doo::loadModel ( 'express' );
  2515. $express = new express ();
  2516. $expressList = $express->getExpressByAll ();
  2517. $this->data ['expressList'] = $expressList;
  2518. $this->data ['receiptMemu'] = 'invoicePost';
  2519. $this->data ['list'] = $list;
  2520. $this->render ( "/admin/invoicePostAchieve", $this->data );
  2521. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  2522. $this->data ['receiptMemu'] = 'invoiceUntread';
  2523. $this->data ['list'] = $list;
  2524. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  2525. }
  2526. }
  2527. /**
  2528. *
  2529. * @deprecated 获得与我有关可收款的发票 废弃 function ajaxGetInvoiceByStaff() { $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] ); $html = ""; $i = 1; foreach ( $list as $key => $value ) { $html .= '<tr> <td>' . $value ['invoiceElement'] . '</td> <td>¥' . $value ['invoicePrice'] . '</td>'; if (! empty ( $value ['invoiceType'] )) { $html .= '<td>增值税专用发票</td> <td>' . $value ['invoiceCompany'] . '</td>'; } else { $html .= '<td>增值税普通发票</td> <td>' . $value ['invoiceTitle'] . '</td>'; } $html .= '<td><label><input type="radio" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim"> 使用Ta</label></td></tr> <script> $(\'input[node-Claim="true_' . $i . '"]\').click(function() { var invoiceKey= $(this).attr("p-data"); var claimKey=$("input[name=\'key\']").val(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareInvoicePrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { claimKey : claimKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }, error : function(err) { } }); }); </script> '; $i ++; } echo json_encode ( array ( 'status' => 1, 'html' => $html ) ); }
  2530. */
  2531. /**
  2532. * 获取一条收款信息
  2533. */
  2534. function ajaxGetInvoiceReceivables() {
  2535. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2536. Doo::loadModel ( 'invoiceReceivables' );
  2537. $invoiceReceivables = new invoiceReceivables ();
  2538. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2539. echo json_encode ( array (
  2540. 'status' => 1,
  2541. 'detail' => $detail
  2542. ) );
  2543. }
  2544. /**
  2545. * 异步获取办事处用户
  2546. */
  2547. function ajaxGetStaffByCategory() {
  2548. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  2549. Doo::loadModel ( 'staff' );
  2550. $staff = new staff ();
  2551. if ($cid == "PUBLIC") {
  2552. echo json_encode ( array (
  2553. 'status' => 1,
  2554. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  2555. ) );
  2556. die ();
  2557. }
  2558. if (! is_numeric ( $cid )) {
  2559. echo json_encode ( array (
  2560. 'status' => 0,
  2561. 'msg' => 'illegal request'
  2562. ) );
  2563. die ();
  2564. }
  2565. $staffList = $staff->getStaffByCid ( $cid );
  2566. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  2567. foreach ( $staffList as $key => $value ) {
  2568. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2569. }
  2570. echo json_encode ( array (
  2571. 'status' => 1,
  2572. 'html' => $html
  2573. ) );
  2574. }
  2575. /**
  2576. * 异步获取一条发票的邮寄信息
  2577. */
  2578. function ajaxGetInvoicePostDetail() {
  2579. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2580. Doo::loadModel ( 'invoice' );
  2581. $invoice = new invoice ();
  2582. $iid = $invoice->authcode ( $iid );
  2583. Doo::loadModel ( 'express' );
  2584. $express = new express ();
  2585. $expressList = $express->getExpressByAll ();
  2586. if (! is_numeric ( $iid )) {
  2587. echo json_encode ( array (
  2588. 'status' => 0,
  2589. 'msg' => 'illegal request'
  2590. ) );
  2591. die ();
  2592. }
  2593. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  2594. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  2595. $html = "";
  2596. foreach ( $expressList as $key => $value ) {
  2597. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  2598. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  2599. else
  2600. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  2601. }
  2602. $invoiceDetail ['eaHtml'] = $html;
  2603. echo json_encode ( array (
  2604. 'status' => 1,
  2605. 'invoiceDetail' => $invoiceDetail
  2606. ) );
  2607. }
  2608. /**
  2609. *
  2610. * @deprecated --需求变更 废弃 function ajaxCompareClaimPrice() { $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : ""; $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); if (empty ( $detail ) || empty ( $detailM )) { echo json_encode ( array ( 'status' => 2, 'msg' => '非法请求,请重新登录' ) ); die (); } $iridString = ""; if (empty ( $detail ['irid'] )) $iridString = $detailM ['irid']; else $iridString = $detail ['irid'] . ',' . $detailM ['irid']; $item = array ( 'irid' => $iridString, 'bindTime' => date ( "Y-m-d H:i:s" ), 'updateTime' => date ( "Y-m-d H:i:s" ), 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "收款入账" . $detailM ['receivablesSerial'] . "到发票" . $detail ['invoiceSerial'], 'status' => 8, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $item = array ( 'iid' => $detail ['iid'], 'irid' => $detailM ['irid'], 'bindDate' => date ( "Y-m-d H:i:s" ), 'bindStatus' => 1 ); $invoiceReceivables->setInvoiceReceivablesByCondition ( $item ); $price = 0; $priceStatus = 0; $isReceivables = 0; $invoiceReceivables = new invoiceReceivables (); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => '<tr><td>¥' . $detailM ['receivablesPrice'] . '</td><td>' . $detailM ['receivablesMessage'] . '</td><td>' . $detailM ['receivablesBank'] . '</td> <td>' . $detailM ['receivablesDate'] . '</td><td><a node-remove="Da' . $detailM ['iridKey'] . '" href="javascript:void(0);">移除</a></td></tr> <script> $(\'a[node-remove="Da' . $detailM ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var iridKey="' . $detailM ["iridEn"] . '"; var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("移除处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxReceivablesRemove"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { key : iridKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[data-invoice=\"myReceivables\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> ', 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  2611. */
  2612. /**
  2613. *
  2614. * @deprecated 从发票中移除已经入账的收款 --需求变更 废弃 function ajaxReceivablesRemove() { $iridKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridKey ); // echo $detail['irid']."<br/>"; $invoiceIrid = explode ( ",", $detail ['irid'] ); foreach ( $invoiceIrid as $key => $value ) { if ($value == $detailM ['irid']) unset ( $invoiceIrid [$key] ); } $invoiceIrid = implode ( ",", $invoiceIrid ); // echo $invoiceIrid."ddd"; // print_r($invoiceIrid); $item = array ( 'irid' => $invoiceIrid, 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); $item = array ( 'iid' => 0, 'irid' => $detailM ['irid'], 'bindDate' => '', 'bindStatus' => 0 ); $invoiceReceivables->setInvoiceReceivablesByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "收款移除" . $detailM ['receivablesSerial'], 'status' => 10, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $price = 0; $priceStatus = 0; $isReceivables = 0; $invoiceReceivables = new invoiceReceivables (); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceIrid ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => '<tr id="' . $detailM ['receivablesSerial'] . '" > <td>¥' . $detailM ['receivablesPrice'] . '</td> <td>' . $detailM ['receivablesMessage'] . '</td> <td>' . $detailM ['receivablesBank'] . '</td> <td>' . $detailM ['receivablesDate'] . '</td><td> <a href="javascript:void(0)" node-Claim="true_' . $detailM ['iridKey'] . '" p-data="' . $detailM ['iridEn'] . '" name="invoiceClaim" class="button">入账</a> </td></tr> <script> $(\'a[node-Claim="true_' . $detailM ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("入账处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareClaimPrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { irid : irid, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[box-enter=\"true\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> ', 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  2615. */
  2616. /**
  2617. * 我的收款中 选择哪个发票入账,进行金额判断
  2618. */
  2619. function ajaxCompareInvoicePrice() {
  2620. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2621. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2622. Doo::loadModel ( 'invoice' );
  2623. $invoice = new invoice ();
  2624. Doo::loadModel ( 'invoiceReceivables' );
  2625. $invoiceReceivables = new invoiceReceivables ();
  2626. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2627. $keyList = explode ( ';', $claimKey );
  2628. $receivablesPrice = 0;
  2629. foreach ( $keyList as $key => $value ) {
  2630. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  2631. $receivablesPrice += $detailM ['receivablesPrice'];
  2632. }
  2633. if ($receivablesPrice > $detail ['invoicePrice']) {
  2634. $price = $receivablesPrice - $detail ['invoicePrice'];
  2635. echo json_encode ( array (
  2636. 'status' => 1,
  2637. 'price' => $price
  2638. ) );
  2639. } else
  2640. echo json_encode ( array (
  2641. 'status' => 2
  2642. ) );
  2643. }
  2644. /**
  2645. * @ 获得与我有关收款数据 --需求变更 废弃 function ajaxGetReceivalblesByStaff() { $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $detail = $invoice->getInvoiceByIid ( $iid ); $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] ); $html = ""; $i = 1; foreach ( $list ['myClaim'] as $key => $value ) { $html .= '<tr id="' . $value ['receivablesSerial'] . '" > <td>¥' . $value ['receivablesPrice'] . '</td> <td>' . $value ['receivablesMessage'] . '</td> <td>' . $value ['receivablesBank'] . '</td> <td>' . $value ['receivablesDate'] . '</td>'; $html .= '<td> <a href="javascript:void(0)" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim" class="button">入账</a> </td></tr> <script> $(\'a[node-Claim="true_' . $i . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("入账处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareClaimPrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { irid : irid, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[box-enter=\"true\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> '; $i ++; } $html2 = ""; $list2 = $invoiceReceivables->getInvoiceReceivablesByIid ( $iid, 1 ); foreach ( $list2 as $key => $value ) { $html2 .= '<tr id="' . $value ['receivablesSerial'] . '" > <td>¥' . $value ['receivablesPrice'] . '</td> <td>' . $value ['receivablesMessage'] . '</td> <td>' . $value ['receivablesBank'] . '</td> <td>' . $value ['receivablesDate'] . '</td>'; $html2 .= '<td> <a href="javascript:void(0)" node-remove="Da' . $value ['iridKey'] . '" >移除</a> </td></tr> <script> $(\'a[node-remove="Da' . $value ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var iridKey="' . $value ["iidKey"] . '"; var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("移除处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxReceivablesRemove"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { key : iridKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[data-invoice=\"myReceivables\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> '; $i ++; } $price = 0; $priceStatus = 0; $isReceivables = 0; $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => $html, 'html2' => $html2, 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  2646. */
  2647. function ajaxGetInvoiceInfoByType() {
  2648. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  2649. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  2650. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  2651. if (empty ( $serial )) {
  2652. echo json_encode ( array (
  2653. 'status' => 2,
  2654. 'msg' => 'illegal request'
  2655. ) );
  2656. die ();
  2657. }
  2658. if ($type == 'INVOICE') {
  2659. Doo::loadModel ( 'invoice' );
  2660. $invoice = new invoice ();
  2661. Doo::loadModel ( 'invoiceOperationLog' );
  2662. $invoiceOperationLog = new invoiceOperationLog ();
  2663. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2664. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2665. if (empty ( $detail ))
  2666. $html = '';
  2667. else {
  2668. $html = '
  2669. <div class="modal-dialog modal-lg">
  2670. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  2671. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  2672. <tr>
  2673. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2674. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2675. </tr>
  2676. <tr>
  2677. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2678. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2679. </tr>
  2680. <tr>
  2681. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  2682. </td>
  2683. </tr>
  2684. <tr>
  2685. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  2686. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  2687. </tr>
  2688. <tr>
  2689. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2690. </tr></tbody></table>';
  2691. if ($detail ['invoiceType'] == 0)
  2692. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2693. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2694. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  2695. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  2696. </tr>';
  2697. else
  2698. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2699. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2700. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2701. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  2702. ';
  2703. $html .= '<tr>
  2704. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2705. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2706. </tr>
  2707. <tr>
  2708. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  2709. <th class="taC">银行账户</th><td>' . $detail ['bank'] . '</td>
  2710. </tr></tbody></table>';
  2711. if ($detail ['doPost'] == 1)
  2712. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2713. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2714. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2715. </tr><tr>
  2716. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2717. </tr><tr>
  2718. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2719. </tr></tbody></table>';
  2720. if (! empty ( $invoiceOperationLogList )) {
  2721. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2722. foreach ( $invoiceOperationLogList as $key => $value ) {
  2723. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  2724. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2725. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2726. if ($value ['status'] == 2) {
  2727. $html .= '<span class="colGreen">同意</span>';
  2728. } elseif ($value ['status'] == 3) {
  2729. $html .= '<span class="colOrange">退回</span>';
  2730. } elseif ($value ['status'] == 5) {
  2731. $html .= '<span class="colGreen">打印</span>';
  2732. } elseif ($value ['status'] == 4) {
  2733. $html .= '<span class="colRed">终止</span>';
  2734. }
  2735. $html .= $value ['operation'] . '</p></blockquote>';
  2736. }
  2737. }
  2738. $html .= '</td></tr></tbody></table>';
  2739. }
  2740. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2741. }
  2742. echo json_encode ( array (
  2743. 'status' => 1,
  2744. 'html' => $html
  2745. ) );
  2746. die ();
  2747. } elseif ($type == 'RECEIVABLES') {
  2748. Doo::loadModel ( 'invoiceReceivables' );
  2749. $invoiceReceivables = new invoiceReceivables ();
  2750. //
  2751. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  2752. if (empty ( $detail ))
  2753. $html = '';
  2754. else {
  2755. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList"><table class="table table-bordered table-condensed">
  2756. <tbody><tr>
  2757. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  2758. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  2759. </tr><tr>
  2760. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2761. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  2762. </tr>
  2763. <tr>
  2764. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  2765. <th class="taC">银行到帐</th><td>' . $detail ['receivablesDate'] . '</td>
  2766. </tr>
  2767. <tr>
  2768. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['bindDate'] . '</td>
  2769. </tr>
  2770. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2771. }
  2772. echo json_encode ( array (
  2773. 'status' => 1,
  2774. 'html' => $html
  2775. ) );
  2776. die ();
  2777. } elseif ($type == 'IRTC') {
  2778. Doo::loadModel ( 'invoice' );
  2779. $invoice = new invoice ();
  2780. Doo::loadModel ( 'invoiceOperationLog' );
  2781. $invoiceOperationLog = new invoiceOperationLog ();
  2782. Doo::loadModel ( 'invoiceReceivables' );
  2783. $invoiceReceivables = new invoiceReceivables ();
  2784. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2785. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2786. if (empty ( $detail ))
  2787. $html = '';
  2788. else {
  2789. $receivablesPriceedHtml = '';
  2790. $receivablesPrice = $detail ['invoicePrice'];
  2791. if (! empty ( $detail ['irid'] )) {
  2792. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  2793. if (empty ( $irList ))
  2794. $irList [0] ['sumPrice'] = 0;
  2795. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  2796. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  2797. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  2798. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  2799. </tr></tbody></table>';
  2800. $receivablesPrice = $balance;
  2801. }
  2802. if ($loss)
  2803. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  2804. $html = $receivablesPriceedHtml . '
  2805. <table class="table table-bordered table-condensed"><tbody>
  2806. <tr>
  2807. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2808. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2809. </tr>
  2810. <tr>
  2811. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2812. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2813. </tr>
  2814. <tr>
  2815. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  2816. </tr>
  2817. <tr>
  2818. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  2819. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  2820. </tr>
  2821. <tr>
  2822. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2823. </tr></tbody></table>';
  2824. if ($detail ['invoiceType'] == 0) {
  2825. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2826. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2827. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  2828. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  2829. </tr>';
  2830. $receivablesMessage = $detail ['invoiceTitle'];
  2831. } else {
  2832. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2833. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2834. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2835. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  2836. ';
  2837. $receivablesMessage = $detail ['invoiceCompany'];
  2838. }
  2839. $html .= '<tr>
  2840. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2841. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2842. </tr>
  2843. <tr>
  2844. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  2845. <th class="taC">银行账户</th><td>' . $detail ['bank'] . '</td>
  2846. </tr></tbody></table>';
  2847. if ($detail ['doPost'] == 1)
  2848. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2849. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2850. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2851. </tr><tr>
  2852. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2853. </tr><tr>
  2854. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2855. </tr></tbody></table>';
  2856. if (! empty ( $invoiceOperationLogList )) {
  2857. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2858. foreach ( $invoiceOperationLogList as $key => $value ) {
  2859. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  2860. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2861. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2862. if ($value ['status'] == 2) {
  2863. $html .= '<span class="colGreen">同意</span>';
  2864. } elseif ($value ['status'] == 3) {
  2865. $html .= '<span class="colOrange">退回</span>';
  2866. } elseif ($value ['status'] == 5) {
  2867. $html .= '<span class="colGreen">打印</span>';
  2868. }
  2869. $html .= $value ['operation'] . '</p></blockquote>';
  2870. }
  2871. }
  2872. $html .= '</td></tr></tbody></table>';
  2873. }
  2874. }
  2875. echo json_encode ( array (
  2876. 'status' => 1,
  2877. 'html' => $html,
  2878. 'receivablesPrice' => $receivablesPrice,
  2879. 'receivablesMessage' => $receivablesMessage,
  2880. 'receivablesDate' => date ( "Y-m-d" ),
  2881. 'iidKey' => $serial
  2882. ) );
  2883. die ();
  2884. }
  2885. }
  2886. function ajaxGetInvoiceReceivablesByStaff() {
  2887. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  2888. if (empty ( $postData )) {
  2889. echo json_encode ( array (
  2890. 'status' => 2,
  2891. 'msg' => 'illegal request'
  2892. ) );
  2893. die ();
  2894. }
  2895. Doo::loadModel ( 'invoiceReceivables' );
  2896. $invoiceReceivables = new invoiceReceivables ();
  2897. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  2898. if (empty ( $detail )) {
  2899. echo json_encode ( array (
  2900. 'status' => 2,
  2901. 'msg' => 'illegal request'
  2902. ) );
  2903. die ();
  2904. }
  2905. Doo::loadModel ( 'L_category' );
  2906. $lCategory = new L_category ();
  2907. Doo::loadModel ( 'staff' );
  2908. $staff = new staff ();
  2909. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  2910. $category = $lCategory->getCategory ();
  2911. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  2912. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  2913. foreach ( $category as $key => $value ) {
  2914. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2915. if ($value ['cid'] == $detail ['cid'])
  2916. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2917. }
  2918. foreach ( $staffList as $key => $value ) {
  2919. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2920. if ($value ['sid'] == $detail ['sid'])
  2921. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2922. }
  2923. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  2924. echo json_encode ( array (
  2925. 'status' => 1,
  2926. 'categoryHtml' => $categoryHtml,
  2927. 'staffHtml' => $staffHtml,
  2928. 'rbankHtml' => $rbankHtml,
  2929. 'detail' => $detail
  2930. ) );
  2931. }
  2932. function ajaxGetInvoiceReceivablesByIrid() {
  2933. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  2934. if (empty ( $irid )) {
  2935. echo json_encode ( array (
  2936. 'status' => 2,
  2937. 'msg' => 'illegal request'
  2938. ) );
  2939. die ();
  2940. }
  2941. Doo::loadModel ( 'invoiceReceivables' );
  2942. $invoiceReceivables = new invoiceReceivables ();
  2943. Doo::loadModel ( 'invoice' );
  2944. $invoice = new invoice ();
  2945. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  2946. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 " ); //
  2947. $receivablesHtml = '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="70">收款金额</th><th class="taC">银行到帐信息</th><th class="taC">银行/到帐时间</th><th class="taC">收款认领</th><th class="taC">开票单位</th></tr>
  2948. <tr>
  2949. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2950. <td>' . $detail ['receivablesMessage'] . '</td>
  2951. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  2952. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  2953. <td>' . $detail ['recepitTitleMark'] . '</td>
  2954. </tr></tbody></table>';
  2955. $isInvoice = false;
  2956. $invoiceHtml = '';
  2957. if (empty ( $invoiceDetail )) {
  2958. $isInvoice = true;
  2959. } else {
  2960. $invoiceHtml = '<table class="table table-bordered table-condensed">
  2961. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  2962. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  2963. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  2964. } else {
  2965. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  2966. }
  2967. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  2968. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  2969. } else {
  2970. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  2971. }
  2972. $invoiceHtml .= '
  2973. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  2974. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  2975. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  2976. </tr>
  2977. ';
  2978. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceDetail ['irid'] );
  2979. $balance = $invoiceDetail ['invoicePrice'] - $irList [0] ['sumPrice'];
  2980. $priceString = '';
  2981. if ($balance < $detail ['receivablesPrice']) {
  2982. $priceString = '收款金额超过开票金额,';
  2983. }
  2984. if ($balance > $detail ['receivablesPrice']) {
  2985. $priceString = '收款金额低于开票金额,';
  2986. }
  2987. $invoiceHtml .= '</tbody></table>
  2988. <script>
  2989. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  2990. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  2991. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  2992. if(invoiceKey==""){
  2993. alert("入账错误,请重新刷新页面");
  2994. return false;
  2995. }
  2996. if(window.confirm("' . $priceString . '确定入账吗?")){
  2997. $("#IBR").submit();
  2998. }else{
  2999. return false;
  3000. }
  3001. });
  3002. </script>
  3003. ';
  3004. }
  3005. echo json_encode ( array (
  3006. 'status' => 1,
  3007. 'irkey' => $detail ['iridEn'],
  3008. 'receivablesHtml' => $receivablesHtml,
  3009. 'isInvoice' => $isInvoice,
  3010. 'invoiceHtml' => $invoiceHtml
  3011. ) );
  3012. }
  3013. function ajaxGetInvoiceReceivablesByTitle() {
  3014. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  3015. if (empty ( $title )) {
  3016. echo json_encode ( array (
  3017. 'status' => 2,
  3018. 'msg' => 'illegal request'
  3019. ) );
  3020. die ();
  3021. }
  3022. Doo::loadModel ( 'invoice' );
  3023. $invoice = new invoice ();
  3024. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 " );
  3025. $invoiceHtml = '';
  3026. if (! empty ( $invoiceDetail )) {
  3027. $invoiceHtml = '<table class="table table-bordered table-condensed">
  3028. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  3029. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3030. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  3031. } else {
  3032. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  3033. }
  3034. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3035. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  3036. } else {
  3037. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  3038. }
  3039. $invoiceHtml .= '
  3040. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  3041. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  3042. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="#">入账</a></td>
  3043. </tr>
  3044. ';
  3045. $invoiceHtml .= '</tbody></table>
  3046. <script>
  3047. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  3048. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  3049. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  3050. if(invoiceKey==""){
  3051. alert("入账错误,请重新刷新页面");
  3052. return false;
  3053. }
  3054. if(window.confirm("确定入账吗?")){
  3055. $("#IBR").submit();
  3056. }else{
  3057. return false;
  3058. }
  3059. });
  3060. </script>
  3061. ';
  3062. }
  3063. echo json_encode ( array (
  3064. 'status' => 1,
  3065. 'invoiceHtml' => $invoiceHtml
  3066. ) );
  3067. }
  3068. function ajaxInvoicePushNotice() {
  3069. Doo::loadModel ( 'invoice' );
  3070. $invoice = new invoice ();
  3071. $approval = $invoice->getOne ( array (
  3072. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  3073. 'desc' => 'iid',
  3074. 'asArray' => true
  3075. ) );
  3076. $isNotice = false;
  3077. if (! empty ( $approval ))
  3078. $isNotice = true;
  3079. $response = array (
  3080. 'error' => 0,
  3081. 'isNotice' => $isNotice
  3082. );
  3083. echo json_encode ( $response );
  3084. exit ();
  3085. }
  3086. public function ajaxCheckInvoiceNoUniqueness() {
  3087. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  3088. Doo::loadModel ( 'invoice' );
  3089. $invoice = new invoice ();
  3090. if (! empty ( $invoiceNo )) {
  3091. $info = $invoice->getOne ( array (
  3092. 'where' => "invoiceNo = '" . $invoiceNo . "'",
  3093. 'asArray' => TRUE
  3094. ) );
  3095. if (! empty ( $info )) {
  3096. echo json_encode ( array (
  3097. 'error' => '发票号已存在'
  3098. ) );
  3099. die ();
  3100. } else
  3101. echo json_encode ( array (
  3102. 'ok' => '可以使用!'
  3103. ) );
  3104. die ();
  3105. }
  3106. }
  3107. function ajaxCheckInvoicePrice() {
  3108. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3109. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3110. Doo::loadModel ( 'invoice' );
  3111. $invoice = new invoice ();
  3112. Doo::loadModel ( 'invoiceReceivables' );
  3113. $invoiceReceivables = new invoiceReceivables ();
  3114. Doo::loadClass ( 'XDeode' );
  3115. $XDeode = new XDeode ( 5 );
  3116. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  3117. $iidKey = $XDeode->decode ( $iidKey );
  3118. $info = $invoice->getInvoiceByIid ( $iidKey );
  3119. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  3120. if (empty ( $irList ))
  3121. $irList [0] ['sumPrice'] = 0;
  3122. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  3123. if ($balance < $receivablesPrice) {
  3124. echo json_encode ( array (
  3125. 'error' => '收款金额超过开票金额。'
  3126. ) );
  3127. die ();
  3128. }
  3129. if ($balance > $receivablesPrice) {
  3130. echo json_encode ( array (
  3131. 'error' => '收款金额低于开票金额。'
  3132. ) );
  3133. die ();
  3134. }
  3135. }
  3136. }
  3137. /**
  3138. * 旧输入导入
  3139. */
  3140. function importInvoice() {
  3141. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  3142. $data ['emsg'] = "";
  3143. if ($emsg != "")
  3144. $data ['emsg'] = "请填写完整的数据";
  3145. $data ['time'] = time ();
  3146. $this->render ( "/admin/invoiceImport", $data );
  3147. }
  3148. function uploadInvoice() {
  3149. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  3150. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  3151. $file = $_FILES ['Filedata'] ['tmp_name'];
  3152. $error = false;
  3153. if (! is_uploaded_file ( $file )) {
  3154. $error = '400 Bad Request';
  3155. }
  3156. if ($error) {
  3157. header ( 'HTTP/1.0 ' . $error );
  3158. die ( 'Error ' . $error );
  3159. } else {
  3160. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  3161. $this->IoHandler = new IoHandler ();
  3162. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  3163. // $filedir=$_POST['time'];
  3164. // 调用定义物理路径
  3165. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  3166. $this->IoHandler->MakeDir ( $t );
  3167. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  3168. if ($filename != 'xlsx')
  3169. return "";
  3170. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  3171. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  3172. $upload_dir = $t . "/" . $upload_file;
  3173. $k = move_uploaded_file ( $file, $upload_dir );
  3174. if ($k) {
  3175. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  3176. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  3177. }
  3178. }
  3179. }
  3180. }
  3181. function importInvoiceDo() {
  3182. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  3183. if ($path != "") {
  3184. Doo::loadModel ( 'invoice' );
  3185. Doo::loadModel ( 'staff' );
  3186. $staff = new staff ();
  3187. Doo::loadModel ( 'invoiceStatistics' );
  3188. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  3189. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  3190. // print_r ( $exlArray );
  3191. // die ();
  3192. // echo json_encode($exlArray);die;
  3193. foreach ( $exlArray as $key => $value ) {
  3194. // 开票
  3195. $invoice = new invoice ();
  3196. $invoice->invoiceNo = $value ['invoiceNo'];
  3197. $invoice->invoiceType = 0;
  3198. if ($value ['invoiceNo'] == '专')
  3199. $invoice->invoiceType = 1;
  3200. $invoice->invoicePrice = $value ['invoicePrice'];
  3201. $invoice->invoiceTitle = $value ['invoiceTitle'];
  3202. if ($value ['invoiceNo'] == '专')
  3203. $invoice->invoiceCompany = $value ['invoiceTitle'];
  3204. $invoice->userName = $value ['userName'];
  3205. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  3206. $invoice->sid = $sDetail ['sid'];
  3207. $invoice->cid = $sDetail ['cid'];
  3208. $invoice->categoryName = $sDetail ['category'];
  3209. $invoice->invoiceElement = $value ['invoiceElement'];
  3210. $invoice->remark = $value ['remark'];
  3211. $invoice->date = $value ['date'];
  3212. $invoice->printStatus = 1;
  3213. $invoice->status = 2;
  3214. $invoice->postStatus = 1;
  3215. $invoice->untreadStatus = 0;
  3216. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3217. $invoice->insert ();
  3218. // 汇总
  3219. $invoiceStatistics = new invoiceStatistics ();
  3220. // 扣除入账统计金额
  3221. $item = array (
  3222. 'date' => $value ['date'],
  3223. 'priceClass' => 1,
  3224. 'cid' => $sDetail ['cid'],
  3225. 'staff' => $sDetail ['sid'],
  3226. 'invoicePrice' => $value ['invoicePrice']
  3227. );
  3228. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3229. }
  3230. return '/importInvoice?count=' . count ( $exlArray );
  3231. // return "/keyonline";
  3232. }
  3233. echo 'no file';
  3234. }
  3235. function importInvoiceReceivables() {
  3236. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  3237. $data ['emsg'] = "";
  3238. if ($emsg != "")
  3239. $data ['emsg'] = "请填写完整的数据";
  3240. $data ['time'] = time ();
  3241. $this->render ( "/admin/invoiceReceivablesImport", $data );
  3242. }
  3243. // 导入入账数据
  3244. function importInvoiceReceivablesDo() {
  3245. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  3246. include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3247. if ($path != "") {
  3248. Doo::loadModel ( 'invoiceReceivables' );
  3249. Doo::loadModel ( 'invoice' );
  3250. Doo::loadModel ( 'staff' );
  3251. $staff = new staff ();
  3252. Doo::loadModel ( 'invoiceStatistics' );
  3253. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  3254. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  3255. // print_r ( $exlArray );
  3256. // die ();
  3257. // echo json_encode($exlArray);die;
  3258. foreach ( $exlArray as $key => $value ) {
  3259. // 收款
  3260. $invoiceReceivables = new invoiceReceivables ();
  3261. $invoice = new invoice ();
  3262. $invoiceReceivables->bindStatus = 1;
  3263. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  3264. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  3265. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  3266. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  3267. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  3268. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  3269. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  3270. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3271. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  3272. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  3273. $invoiceReceivables->iid = $iDetail ['iid'];
  3274. $irid = $invoiceReceivables->insert ();
  3275. // 发票绑定收款
  3276. $detail = $iDetail;
  3277. $iridString = "";
  3278. if (empty ( $detail ['irid'] ))
  3279. $iridString = $irid;
  3280. else
  3281. $iridString = $detail ['irid'] . ',' . $irid;
  3282. $item = array (
  3283. 'irid' => $iridString,
  3284. 'iid' => $detail ['iid']
  3285. );
  3286. $invoice->setInvoiceByCondition ( $item );
  3287. // 汇总
  3288. $invoiceStatistics = new invoiceStatistics ();
  3289. // 扣除入账统计金额
  3290. $item = array (
  3291. 'date' => $value ['receivablesDate'],
  3292. 'priceClass' => 3,
  3293. 'cid' => $sDetail ['cid'],
  3294. 'staff' => $sDetail ['sid'],
  3295. 'irid' => $irid,
  3296. 'accountPrice' => $value ['receivablesPrice']
  3297. );
  3298. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3299. }
  3300. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  3301. echo 'data count ' . count ( $exlArray );
  3302. die ();
  3303. // return "/keyonline";
  3304. }
  3305. echo 'no file';
  3306. }
  3307. /**
  3308. * 格式化excel文件为数组
  3309. * @param unknown_type $file_url
  3310. * @param unknown_type $mcid
  3311. */
  3312. function _format_excel_to_array($file_url = "", $sType = "") {
  3313. if (! file_exists ( $file_url )) {
  3314. return array ();
  3315. }
  3316. Doo::loadClass ( 'PHPExcel' );
  3317. $PHPExcel = new PHPExcel ();
  3318. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  3319. if (! $PHPReader->canRead ( $file_url )) {
  3320. $PHPReader = new PHPExcel_Reader_Excel5 ();
  3321. if (! $PHPReader->canRead ( $file_url )) {
  3322. echo 'no Excel';
  3323. return;
  3324. }
  3325. }
  3326. $PHPExcel = $PHPReader->load ( $file_url );
  3327. /* * 读取excel文件中的第一个工作表 */
  3328. $currentSheet = $PHPExcel->getSheet ( 0 );
  3329. /* * 取得最大的列号 */
  3330. $allColumn = $currentSheet->getHighestColumn ();
  3331. /* * 取得一共有多少行 */
  3332. $allRow = $currentSheet->getHighestRow ();
  3333. $excel_array = array ();
  3334. $conk = 2;
  3335. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  3336. $excel_column = array ();
  3337. // 后期改进
  3338. if ($allColumn == 'AM')
  3339. $allColumn = 'Z';
  3340. /* * 从第A列开始输出 */
  3341. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  3342. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  3343. if ($val instanceof PHPExcel_RichText)
  3344. $val = $val->__toString ();
  3345. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  3346. // $val = "'" . addslashes ( $val ) . "'";
  3347. if ($sType == 'invoiceReceivables') {
  3348. if ($currentColumn == 'A')
  3349. $excel_column ['invoiceNo'] = $val;
  3350. elseif ($currentColumn == 'B')
  3351. $excel_column ['receivablesPrice'] = $val;
  3352. elseif ($currentColumn == 'C') {
  3353. $excel_column ['receivablesMessage'] = $val;
  3354. } elseif ($currentColumn == 'D') {
  3355. $excel_column ['receivablesBank'] = $val;
  3356. } elseif ($currentColumn == 'E') {
  3357. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  3358. } elseif ($currentColumn == 'F') {
  3359. $excel_column ['receivablesStaff'] = $val;
  3360. } elseif ($currentColumn == 'G') {
  3361. $excel_column ['sourcePrice'] = $val;
  3362. }
  3363. } else {
  3364. if ($currentColumn == 'A')
  3365. $excel_column ['invoiceNo'] = $val;
  3366. elseif ($currentColumn == 'B')
  3367. $excel_column ['invoiceType'] = $val;
  3368. elseif ($currentColumn == 'C') {
  3369. $excel_column ['invoicePrice'] = $val;
  3370. } elseif ($currentColumn == 'D') {
  3371. $excel_column ['invoiceTitle'] = $val;
  3372. } elseif ($currentColumn == 'E') {
  3373. $excel_column ['userName'] = $val;
  3374. } elseif ($currentColumn == 'F') {
  3375. $excel_column ['categoryName'] = $val;
  3376. } elseif ($currentColumn == 'G') {
  3377. $excel_column ['invoiceElement'] = $val;
  3378. } elseif ($currentColumn == 'H') {
  3379. $excel_column ['remark'] = $val;
  3380. } elseif ($currentColumn == 'I') {
  3381. $excel_column ['date'] = $this->excelTime ( $val );
  3382. }
  3383. }
  3384. }
  3385. array_push ( $excel_array, $excel_column );
  3386. }
  3387. return $excel_array;
  3388. }
  3389. function excelTime($date, $time = false) {
  3390. if (function_exists ( 'GregorianToJD' )) {
  3391. if (is_numeric ( $date )) {
  3392. $jd = GregorianToJD ( 1, 1, 1970 );
  3393. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  3394. $date = explode ( '/', $gregorian );
  3395. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  3396. return $date_str;
  3397. }
  3398. } else {
  3399. $date = $date > 25568 ? $date + 1 : 25569;
  3400. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  3401. $ofs = (70 * 365 + 17 + 2) * 86400;
  3402. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  3403. }
  3404. return $date;
  3405. }
  3406. /**
  3407. * 旧输入导入
  3408. */
  3409. function _GetFileEXT($filename) {
  3410. $pics = explode ( '.', $filename );
  3411. $num = count ( $pics );
  3412. return $pics [$num - 1];
  3413. }
  3414. function showCache($path = "") {
  3415. // if (file_exists ( $path )) {
  3416. // $htm = file_get_contents ( $path );
  3417. // } else {
  3418. Doo::loadModel ( 'invoiceStatistics' );
  3419. $invoiceStatistics = new invoiceStatistics ();
  3420. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  3421. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  3422. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  3423. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  3424. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  3425. /*
  3426. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  3427. */
  3428. file_put_contents ( $path, $htm, FILE_APPEND );
  3429. // }
  3430. return $htm;
  3431. }
  3432. /**
  3433. * 获取get或者POST值
  3434. *
  3435. * @param string $name 属性名称
  3436. * @return fixed 值
  3437. */
  3438. function get_args($name) {
  3439. if (isset ( $_GET [$name] )) {
  3440. if (is_array ( $_GET [$name] ))
  3441. return $_GET [$name];
  3442. else
  3443. return addslashes ( $_GET [$name] );
  3444. } elseif (isset ( $_POST [$name] )) {
  3445. if (is_array ( $_POST [$name] ))
  3446. return $_POST [$name];
  3447. else
  3448. return addslashes ( $_POST [$name] );
  3449. } else
  3450. return false;
  3451. }
  3452. function SafeFilter(&$arr) {
  3453. $ra = Array (
  3454. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  3455. '/script/',
  3456. '/javascript/',
  3457. '/vbscript/',
  3458. '/expression/',
  3459. '/applet/',
  3460. '/meta/',
  3461. '/xml/',
  3462. '/blink/',
  3463. '/link/',
  3464. '/style/',
  3465. '/embed/',
  3466. '/object/',
  3467. '/frame/',
  3468. '/layer/',
  3469. '/title/',
  3470. '/bgsound/',
  3471. '/base/',
  3472. '/onload/',
  3473. '/onunload/',
  3474. '/onchange/',
  3475. '/onsubmit/',
  3476. '/onreset/',
  3477. '/onselect/',
  3478. '/onblur/',
  3479. '/onfocus/',
  3480. '/onabort/',
  3481. '/onkeydown/',
  3482. '/onkeypress/',
  3483. '/onkeyup/',
  3484. '/onclick/',
  3485. '/ondblclick/',
  3486. '/onmousedown/',
  3487. '/onmousemove/',
  3488. '/onmouseout/',
  3489. '/onmouseover/',
  3490. '/onmouseup/',
  3491. '/onunload/'
  3492. );
  3493. if (is_array ( $arr )) {
  3494. foreach ( $arr as $key => $value ) {
  3495. if (! is_array ( $value )) {
  3496. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  3497. {
  3498. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  3499. }
  3500. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  3501. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  3502. } else {
  3503. SafeFilter ( $arr [$key] );
  3504. }
  3505. }
  3506. }
  3507. }
  3508. /**
  3509. * Escape String
  3510. *
  3511. * @access public
  3512. * @param string
  3513. * @param bool whether or not the string will be used in a LIKE condition
  3514. * @return string
  3515. */
  3516. function escape_str($str, $like = FALSE) {
  3517. if (is_array ( $str )) {
  3518. foreach ( $str as $key => $val ) {
  3519. $str [$key] = $this->escape_str ( $val, $like );
  3520. }
  3521. return $str;
  3522. }
  3523. var_dump ( Doo::db ()->getDbObject () );
  3524. die ();
  3525. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  3526. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  3527. } elseif (function_exists ( 'mysql_escape_string' )) {
  3528. $str = mysql_escape_string ( $str );
  3529. } else {
  3530. $str = addslashes ( $str );
  3531. }
  3532. // escape LIKE condition wildcards
  3533. if ($like === TRUE) {
  3534. $str = str_replace ( array (
  3535. '%',
  3536. '_'
  3537. ), array (
  3538. '\\%',
  3539. '\\_'
  3540. ), $str );
  3541. }
  3542. return $str;
  3543. }
  3544. /**
  3545. * 获得分页数据
  3546. * @param unknown_type $table
  3547. * @param unknown_type $condition
  3548. * @param unknown_type $on_page
  3549. * @param unknown_type $page_size
  3550. */
  3551. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  3552. $page_c = "";
  3553. $page ['previous'] = $this->get_previous ( $on_page );
  3554. $page ['on_page'] = $on_page;
  3555. $total_count = $this->get_table_count ( $table, $condition );
  3556. $total = intval ( $total_count / $page_size );
  3557. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  3558. $page ['total_data'] = $total_count;
  3559. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  3560. $i = 1;
  3561. $page_max = 1;
  3562. $page_width = 3;
  3563. if ($on_page >= $page_width) {
  3564. $page_max = intval ( $on_page / $page_width ) + 1;
  3565. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  3566. }
  3567. for(; $i <= $page ['total_page']; $i ++) {
  3568. if ($i == $on_page)
  3569. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  3570. else
  3571. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  3572. if ($i == ($page_width * $page_max))
  3573. break;
  3574. }
  3575. $page ['page'] = $page_c;
  3576. $page ['lower'] = (-- $on_page) * $page_size;
  3577. return $page;
  3578. }
  3579. /**
  3580. * 获取上一页
  3581. * @param unknown_type $on_page
  3582. */
  3583. function get_previous($on_page = 1) {
  3584. return $on_page != 0 ? $on_page - 1 : $on_page;
  3585. }
  3586. /**
  3587. * 获取总页数
  3588. * @param unknown_type $table
  3589. * @param unknown_type $condition
  3590. */
  3591. public function get_table_count($table = "", $condition = "") {
  3592. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  3593. $sql = "select count(*) as count from " . $table . " where " . $condition;
  3594. // echo $sql;die;
  3595. $query = Doo::db ()->query ( $sql );
  3596. $result = $query->fetch ();
  3597. return $result ['count'];
  3598. }
  3599. function isInvoiceNew($type = "GLOBAL") {
  3600. Doo::loadModel ( 'invoice' );
  3601. $invoice = new invoice ();
  3602. Doo::loadModel ( 'invoiceReceivables' );
  3603. $invoiceReceivables = new invoiceReceivables ();
  3604. Doo::loadModel ( 'staff' );
  3605. $staff = new staff ();
  3606. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  3607. // 我的发票待处理
  3608. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  3609. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  3610. 'desc' => 'iid',
  3611. 'asArray' => TRUE
  3612. ) );
  3613. // 我的收款待入账
  3614. /*
  3615. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  3616. */
  3617. // 发票审批
  3618. $approval = $invoice->getOne ( array (
  3619. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  3620. 'desc' => 'iid',
  3621. 'asArray' => true
  3622. ) );
  3623. // 发票邮寄
  3624. $post = $invoice->getOne ( array (
  3625. 'where' => "postStatus=0 and doPost=1 and status=2",
  3626. 'asArray' => TRUE
  3627. ) );
  3628. // 发票打印
  3629. $print = $invoice->getOne ( array (
  3630. 'where' => "status=2 and printStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  3631. 'desc' => 'iid',
  3632. 'asArray' => TRUE
  3633. ) );
  3634. // 发票退票
  3635. $untread = $invoice->getOne ( array (
  3636. 'where' => " printStatus=1 and untreadStatus=1 and status=2 ",
  3637. 'asArray' => TRUE
  3638. ) );
  3639. $new = array (
  3640. 'GLOBAL' => FALSE,
  3641. 'pendingInvoice' => FALSE,
  3642. // 'myClaim' => FALSE,
  3643. 'approval' => FALSE,
  3644. 'post' => FALSE,
  3645. 'print' => FALSE,
  3646. 'untread' => FALSE
  3647. );
  3648. // || ! empty ( $myClaim )
  3649. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  3650. $new ['GLOBAL'] = TRUE;
  3651. if (! empty ( $pendingInvoice ))
  3652. $new ['pendingInvoice'] = TRUE;
  3653. // if (! empty ( $myClaim ))
  3654. // $new ['myClaim'] = TRUE;
  3655. if (! empty ( $approval ))
  3656. $new ['approval'] = TRUE;
  3657. if (! empty ( $post ))
  3658. $new ['post'] = TRUE;
  3659. if (! empty ( $print ))
  3660. $new ['print'] = TRUE;
  3661. if (! empty ( $untread ))
  3662. $new ['untread'] = TRUE;
  3663. return $new;
  3664. }
  3665. function setWXMsg($rid, $typeMsg = '') {
  3666. Doo::loadModel ( 'invoice' );
  3667. $invoice = new invoice ();
  3668. $invoiceDetail = $invoice->getOne ( array (
  3669. 'where' => 'iid=' . $rid,
  3670. 'asArray' => true
  3671. ) );
  3672. if (! empty ( $invoiceDetail )) {
  3673. Doo::loadModel ( 'staff' );
  3674. $staff = new staff ();
  3675. $staffmsg = $staff->getOne ( array (
  3676. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  3677. 'asArray' => TRUE
  3678. ) );
  3679. if (! empty ( $staffmsg ['wxid'] )) {
  3680. require_once (SITE_PATH . '/protected/class/client.php');
  3681. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  3682. $user = $staffmsg ['wxid'];
  3683. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  3684. if (empty ( $expCom ))
  3685. $expCom [0] = '';
  3686. $msg = "";
  3687. if (empty ( $typeMsg ))
  3688. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  3689. elseif ($typeMsg == "PRINT")
  3690. $msg = '太好了,您的发票已打印完成。';
  3691. $result = $client->SendMsg ( $user, $msg, 'text' );
  3692. }
  3693. }
  3694. }
  3695. private function msgSend($msg, $title, $url, $user, $text = '') {
  3696. $token = $this->getAccessToken ();
  3697. if ($text == 'text') {
  3698. $data = '{
  3699. "touser": "' . $user . '",
  3700. "toparty": "",
  3701. "totag": "",
  3702. "msgtype": "text",
  3703. "agentid": 1000002,
  3704. "text": {
  3705. "content": "' . $msg . '"
  3706. },
  3707. "safe":0
  3708. }';
  3709. } else {
  3710. $data = '{
  3711. "touser": "' . $user . '",
  3712. "toparty": "",
  3713. "totag": "",
  3714. "msgtype": "news",
  3715. "agentid": 1000002,
  3716. "news": {
  3717. "articles":[
  3718. {
  3719. "title": "' . $title . '",
  3720. "description": "' . $msg . '",
  3721. "url": "' . $url . '",
  3722. "picurl": ""
  3723. }
  3724. ]
  3725. }
  3726. }';
  3727. }
  3728. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  3729. if ($result->errmsg != 'ok') {
  3730. return 0;
  3731. } else {
  3732. return 1;
  3733. }
  3734. }
  3735. private function getAccessToken() {
  3736. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  3737. //$file = './access_token.txt';
  3738. //$data = json_decode ( file_get_contents ( $file ) );
  3739. //if ($data->expire_time < time () or ! $data->expire_time) {
  3740. // 如果是企业号用以下URL获取access_token
  3741. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  3742. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  3743. $res = json_decode ( $this->httpGet ( $url ) );
  3744. $access_token = $res->access_token;
  3745. //echo $access_token;
  3746. // if ($access_token) {
  3747. // $data->expire_time = time () + 7000;
  3748. // $data->access_token = $access_token;
  3749. // $fp = fopen ( $file, "w" );
  3750. // fwrite ( $fp, json_encode ( $data ) );
  3751. // fclose ( $fp );
  3752. // }
  3753. // } else {
  3754. // $access_token = $data->access_token;
  3755. // }
  3756. return $access_token;
  3757. }
  3758. private function httpGet($url) {
  3759. $curl = curl_init ();
  3760. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  3761. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  3762. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  3763. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  3764. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  3765. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  3766. curl_setopt ( $curl, CURLOPT_URL, $url );
  3767. $res = curl_exec ( $curl );
  3768. curl_close ( $curl );
  3769. return $res;
  3770. }
  3771. private function httpPost($url, $data) {
  3772. $curl = curl_init ();
  3773. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  3774. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  3775. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  3776. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  3777. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  3778. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  3779. curl_setopt ( $curl, CURLOPT_URL, $url );
  3780. curl_setopt ( $curl, CURLOPT_POST, 1 );
  3781. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  3782. $res = curl_exec ( $curl );
  3783. curl_close ( $curl );
  3784. return $res;
  3785. }
  3786. }
  3787. ?>