InvoiceController.php 226 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130
  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. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // var_dump($flag) ;
  64. if (! $flag)
  65. die ( 'illegal request' );
  66. }
  67. function __construct() {
  68. if (isset ( $_COOKIE ["staff"] )) {
  69. if (! empty ( $_COOKIE ["staff"] )) {
  70. Doo::loadModel ( 'staff' );
  71. $staff = new staff ();
  72. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  73. $this->ACTION = $uriPartsOrig [1];
  74. $this->data ['new'] = $this->isInvoiceNew ();
  75. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  76. return "/";
  77. }
  78. }
  79. Doo::loadCore ( 'uri/DooUriRouter' );
  80. $router = new DooUriRouter ();
  81. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  82. if ($routeRs ['1'] != "login") {
  83. header ( 'Content-Type:text/html;charset=utf-8' );
  84. @header ( "Location: /login" );
  85. }
  86. }
  87. function testSend() {
  88. // 测试根据规则发送信息 普通发送
  89. // $pendingApprovalsSid = 41;
  90. // Doo::loadModel ( 'staff' );
  91. // $staff = new staff ();
  92. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  93. // // 发送微信审批通知
  94. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  95. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  96. // Doo::loadModel ( 'staff' );
  97. // $staff = new staff ();
  98. // $toparty = $this->getToparty ( '广东办' );
  99. // $wxList = array ();
  100. // if (! empty ( $toparty )) {
  101. // $userList = $this->getUserByToparty ( $toparty );
  102. // $userCon = implode ( ',', $userList );
  103. // // echo $userCon;
  104. // $sidList = $staff->getStaffByWxid ( $userCon );
  105. // foreach ( $sidList as $key => $value ) {
  106. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  107. // if ($falg) {
  108. // array_push ( $wxList, $value ['wxid'] );
  109. // }
  110. // }
  111. // $wxString = implode ( '|', $wxList );
  112. // print_r ( $wxList );
  113. // echo $wxString;
  114. // }
  115. // 测试发送
  116. /*
  117. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  118. */
  119. // print_r ( $userList );
  120. // $msTouser='caipin|outaozhen';
  121. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  122. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  123. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  124. // $toparty= $this->getToparty('广东办');
  125. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  126. // $toparty = 26;
  127. // $msg = '';
  128. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  129. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  130. }
  131. function invoice() {
  132. Doo::loadModel ( 'invoice' );
  133. $invoice = new invoice ();
  134. Doo::loadModel ( 'express' );
  135. $express = new express ();
  136. $expressList = $express->getExpressByAll ();
  137. $this->data ['expressList'] = $expressList;
  138. // Doo::loadModel ( 'invoiceReceivables' );
  139. // $invoiceReceivables = new invoiceReceivables ();
  140. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  141. Doo::loadModel ( 'invoiceStatistics' );
  142. $invoiceStatistics = new invoiceStatistics ();
  143. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  144. $year = date ( "Y" );
  145. $tmp_date = date ( "Ym" );
  146. $tmp_year = substr ( $tmp_date, 0, 4 );
  147. $tmp_mon = substr ( $tmp_date, 4, 2 );
  148. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  149. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  150. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  151. $htm = $this->showCache ( $path );
  152. Doo::loadClass ( 'XDeode' );
  153. $XDeode = new XDeode ( 5 );
  154. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  155. $invoiceList = $invoice->getMyInvoice ( $sid );
  156. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  157. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  158. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  159. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  160. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  161. // print_r($myInvoiceUnAccount);
  162. $this->data ['isMonth'] = $isMonth;
  163. $this->data ['htm'] = $htm;
  164. $this->data ['invoiceList'] = $invoiceList;
  165. $this->data ['receivablesList'] = $list;
  166. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  167. $this->data ['memu'] = "invoice";
  168. $this->data ['staff'] = $this->staff;
  169. $this->data ['receiptMemu'] = 'invoice';
  170. $this->render ( "/admin/invoice", $this->data );
  171. }
  172. function invoiceExpress() {
  173. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  174. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  175. $this->data ['expressCom'] = $expressCom;
  176. $this->data ['expressNumber'] = $expressNumber;
  177. $this->render ( "/admin/invoiceExpress", $this->data );
  178. }
  179. function invoiceAdd() {
  180. Doo::loadModel ( 'L_category' );
  181. $lCategory = new L_category ();
  182. $category = $lCategory->find ( array (
  183. 'asArray' => true
  184. ) );
  185. $this->data ['category'] = $category;
  186. $this->data ['memu'] = "invoice";
  187. $this->data ['staff'] = $this->staff;
  188. $this->data ['receiptMemu'] = 'invoice';
  189. $this->render ( "/admin/invoiceAdd", $this->data );
  190. }
  191. /**
  192. * 提交一份开票申请,并记录下操作日志
  193. *
  194. * @since 1.0.0
  195. * @var integer cid 办事处ID
  196. * @var integer invoiceType 发票类型
  197. * @var integer doPost 是否邮寄
  198. * @var integer invoicePrice 开票金额
  199. * @var string invoiceElement 开票内容
  200. * @var string invoiceTitle 发票抬头
  201. * @var string invoiceCompany 单位名称
  202. * @var string TIN 纳税人识别码
  203. * @var string address 注册地址
  204. * @var string phone 注册电话
  205. * @var string bank 开户银行
  206. * @var string bankAccount 银行账户
  207. * @var string recipients 收件人
  208. * @var string recipientsPhone 收件人手机/电话
  209. * @var string recipientsAddress 收件地址
  210. * @var string mailItems 邮寄物品
  211. * @var string remark 备注
  212. * @return string 返回跳转开票主页路径
  213. */
  214. function invoiceAddDo() {
  215. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  216. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  217. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  218. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  219. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  220. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  221. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  222. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  223. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  224. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  225. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  226. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  227. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  228. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  229. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  230. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  231. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  232. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  233. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  234. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  235. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  236. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  237. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  238. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  239. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  240. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  241. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  242. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  243. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  244. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  245. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  246. /*
  247. * $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;
  248. */
  249. if (empty ( $this->staff [0] ))
  250. die ( 'illegal request' );
  251. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  252. Doo::loadModel ( 'invoice' );
  253. $invoice = new invoice ();
  254. Doo::loadModel ( 'L_category' );
  255. $lCategory = new L_category ();
  256. Doo::loadModel ( 'invoiceManage' );
  257. $invoiceManage = new invoiceManage ();
  258. Doo::loadModel ( 'invoiceOperationLog' );
  259. $invoiceOperationLog = new invoiceOperationLog ();
  260. $categoryDetil = $lCategory->getOne ( array (
  261. 'SELECT' => 'title',
  262. 'where' => 'cid=' . $cid,
  263. 'asArray' => true
  264. ) );
  265. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  266. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  267. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  268. // print_r(current($invoiceManageDetail ['staffList']));
  269. // die;
  270. $moldManage = array ();
  271. foreach ( $invoiceManageList as $key => $value ) {
  272. if ($value ['mold'] == '发票打印')
  273. $moldManage [$value ['mold']] = $value ['staffList'];
  274. elseif ($value ['mold'] == '发票邮寄')
  275. $moldManage [$value ['mold']] = $value ['staffList'];
  276. elseif ($value ['mold'] == '发票退票')
  277. $moldManage [$value ['mold']] = $value ['staffList'];
  278. }
  279. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  280. $item = array (
  281. 'cid' => $cid,
  282. 'categoryName' => $categoryDetil ['title'],
  283. 'invoiceElement' => $invoiceElement,
  284. 'invoiceQuantity' => $invoiceQuantity,
  285. 'invoiceUnitPrice' => $invoiceUnitPrice,
  286. 'invoicePrice' => $invoicePrice,
  287. 'invoiceType' => $invoiceType,
  288. 'doPost' => $doPost,
  289. 'status' => 1,
  290. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  291. 'date' => date ( "Y-m-d H:i:s" ),
  292. 'updateTime' => date ( "Y-m-d H:i:s" ),
  293. 'sid' => $this->staff [0] ['sid'],
  294. 'userName' => $this->staff [0] ['username'],
  295. 'invoiceManage' => $invoiceManageDetail ['staff'],
  296. 'pendingApprovals' => $pendingApprovalsSid,
  297. 'moldManage' => json_encode ( $moldManage ),
  298. 'remark' => $remark
  299. );
  300. if ($invoiceType == 0)
  301. $item += array (
  302. 'invoiceTitle' => $invoiceTitle,
  303. 'TIN' => $TINT,
  304. 'address' => $addressT,
  305. 'phone' => $phoneT,
  306. 'bank' => $bankT,
  307. 'bankAccount' => $bankAccountT
  308. );
  309. else {
  310. $item += array (
  311. 'invoiceCompany' => $invoiceCompany,
  312. 'TIN' => $TIN,
  313. 'address' => $address,
  314. 'phone' => $phone,
  315. 'bank' => $bank,
  316. 'bankAccount' => $bankAccount
  317. );
  318. }
  319. if ($doPost == 1) {
  320. $mailList = array (
  321. 'invoice' => 1,
  322. 'mailItems' => $mailItems
  323. );
  324. if (! empty ( $softLock ))
  325. $mailList += array (
  326. 'softLock' => $softLockNum
  327. );
  328. else
  329. $mailList += array (
  330. 'softLock' => 0
  331. );
  332. if (! empty ( $contract ))
  333. $mailList += array (
  334. 'contract' => $contractNum
  335. );
  336. else
  337. $mailList += array (
  338. 'contract' => 0
  339. );
  340. if (! empty ( $instructions ))
  341. $mailList += array (
  342. 'instructions' => $instructionsNum
  343. );
  344. else
  345. $mailList += array (
  346. 'instructions' => 0
  347. );
  348. if (! empty ( $remittance ))
  349. $mailList += array (
  350. 'remittance' => $remittance
  351. );
  352. else
  353. $mailList += array (
  354. 'remittance' => ''
  355. );
  356. $mailString = '发票x1,备注:' . $mailItems;
  357. if (! empty ( $softLock ))
  358. $mailString .= ',软件锁x' . $softLockNum;
  359. if (! empty ( $contract ))
  360. $mailString .= ',合同x' . $contractNum;
  361. if (! empty ( $instructions ))
  362. $mailString .= ',说明书x' . $instructionsNum;
  363. if (! empty ( $remittance ))
  364. $mailString .= ',汇款账号单';
  365. $item += array (
  366. 'recipients' => $recipients,
  367. 'recipientsPhone' => $recipientsPhone,
  368. 'recipientsAddress' => $recipientsAddress,
  369. 'mailItems' => $mailString,
  370. 'mailItemsJson' => json_encode ( $mailList )
  371. );
  372. }
  373. $iid = $invoice->addInvoice ( $item );
  374. $item = array (
  375. 'date' => date ( "Y-m-d H:i:s" ),
  376. 'operation' => "创建",
  377. 'status' => 1,
  378. 'img' => $this->staff [0] ['avatar'],
  379. 'username' => $this->staff [0] ['username'],
  380. 'uid' => $this->staff [0] ['sid'],
  381. 'category' => $this->staff [0] ['category'],
  382. 'iid' => $iid
  383. );
  384. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  385. $item = array (
  386. 'date' => date ( "Y-m-d H:i:s" ),
  387. 'operation' => "提交审批",
  388. 'status' => 1,
  389. 'img' => $this->staff [0] ['avatar'],
  390. 'username' => $this->staff [0] ['username'],
  391. 'uid' => $this->staff [0] ['sid'],
  392. 'category' => $this->staff [0] ['category'],
  393. 'iid' => $iid
  394. );
  395. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  396. Doo::loadModel ( 'staff' );
  397. $staff = new staff ();
  398. $username2 = $staff->getOne ( array (
  399. 'select' => 'wxid',
  400. 'where' => 'sid=' . $pendingApprovalsSid,
  401. 'asArray' => TRUE
  402. ) );
  403. // 发送微信审批通知
  404. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  405. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  406. }
  407. return "/invoice";
  408. }
  409. function invoiceEdit() {
  410. Doo::loadClass ( 'XDeode' );
  411. $XDeode = new XDeode ( 5 );
  412. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  413. $iid = $XDeode->decode ( $iid );
  414. if (! is_numeric ( $iid ))
  415. die ( 'illegal request' );
  416. Doo::loadModel ( 'invoice' );
  417. $invoice = new invoice ();
  418. Doo::loadModel ( 'invoiceOperationLog' );
  419. $invoiceOperationLog = new invoiceOperationLog ();
  420. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  421. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  422. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  423. $this->data ['operation'] = $operation;
  424. $this->data ['invoiceDetail'] = $invoiceDetail;
  425. $this->data ['memu'] = "invoice";
  426. $this->data ['staff'] = $this->staff;
  427. $this->data ['receiptMemu'] = 'invoice';
  428. $this->render ( "/admin/invoiceEdit", $this->data );
  429. }
  430. /**
  431. * 重新编辑退回的发票
  432. * @return string
  433. */
  434. function invoiceEditDo() {
  435. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  436. Doo::loadModel ( 'invoice' );
  437. $invoice = new invoice ();
  438. $iid = $invoice->authcode ( $iidKey );
  439. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  440. die ( 'illegal request' );
  441. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  442. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  443. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  444. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  445. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  446. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  447. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  448. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  449. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  450. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  451. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  452. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  453. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  454. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  455. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  456. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  457. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  458. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  459. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  460. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  461. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  462. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  463. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  464. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  465. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  466. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  467. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  468. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  469. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  470. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  471. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  472. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  473. Doo::loadModel ( 'invoiceManage' );
  474. $invoiceManage = new invoiceManage ();
  475. Doo::loadModel ( 'invoiceOperationLog' );
  476. $invoiceOperationLog = new invoiceOperationLog ();
  477. $cid = explode ( ':', $cid );
  478. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  479. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  480. $moldManage = array ();
  481. foreach ( $invoiceManageList as $key => $value ) {
  482. if ($value ['mold'] == '发票打印')
  483. $moldManage [$value ['mold']] = $value ['staffList'];
  484. elseif ($value ['mold'] == '发票邮寄')
  485. $moldManage [$value ['mold']] = $value ['staffList'];
  486. elseif ($value ['mold'] == '发票打印')
  487. $moldManage [$value ['mold']] = $value ['staffList'];
  488. }
  489. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  490. $item = array (
  491. 'iid' => $iid,
  492. 'cid' => $cid [0],
  493. 'categoryName' => $cid [1],
  494. 'invoiceElement' => $invoiceElement,
  495. 'invoiceQuantity' => $invoiceQuantity,
  496. 'invoiceUnitPrice' => $invoiceUnitPrice,
  497. 'invoicePrice' => $invoicePrice,
  498. 'invoiceType' => $invoiceType,
  499. 'doPost' => $doPost,
  500. 'status' => 1,
  501. 'updateTime' => date ( "Y-m-d H:i:s" ),
  502. 'remark' => $remark
  503. );
  504. if ($invoiceType == 0)
  505. $item += array (
  506. 'invoiceTitle' => $invoiceTitle,
  507. 'TIN' => $TINT,
  508. 'address' => $addressT,
  509. 'phone' => $phoneT,
  510. 'bank' => $bankT,
  511. 'bankAccount' => $bankAccountT
  512. );
  513. else {
  514. $item += array (
  515. 'invoiceCompany' => $invoiceCompany,
  516. 'TIN' => $TIN,
  517. 'address' => $address,
  518. 'phone' => $phone,
  519. 'bank' => $bank,
  520. 'bankAccount' => $bankAccount
  521. );
  522. }
  523. if ($doPost == 1) {
  524. $mailList = array (
  525. 'invoice' => 1,
  526. 'mailItems' => $mailItems
  527. );
  528. if (! empty ( $softLock ))
  529. $mailList += array (
  530. 'softLock' => $softLockNum
  531. );
  532. else
  533. $mailList += array (
  534. 'softLock' => '0'
  535. );
  536. if (! empty ( $contract ))
  537. $mailList += array (
  538. 'contract' => $contractNum
  539. );
  540. else
  541. $mailList += array (
  542. 'contract' => '0'
  543. );
  544. if (! empty ( $instructions ))
  545. $mailList += array (
  546. 'instructions' => $instructionsNum
  547. );
  548. else
  549. $mailList += array (
  550. 'instructions' => '0'
  551. );
  552. if (! empty ( $remittance ))
  553. $mailList += array (
  554. 'remittance' => $remittance
  555. );
  556. else
  557. $mailList += array (
  558. 'remittance' => ''
  559. );
  560. $mailString = '发票x1,备注:' . $mailItems;
  561. if (! empty ( $softLock ))
  562. $mailString .= ',软件锁x' . $softLockNum;
  563. if (! empty ( $contract ))
  564. $mailString .= ',合同x' . $contractNum;
  565. if (! empty ( $instructions ))
  566. $mailString .= ',说明书x' . $instructionsNum;
  567. if (! empty ( $remittance ))
  568. $mailString .= ',汇款账号单';
  569. $item += array (
  570. 'recipients' => $recipients,
  571. 'recipientsPhone' => $recipientsPhone,
  572. 'recipientsAddress' => $recipientsAddress,
  573. 'mailItems' => $mailString,
  574. 'mailItemsJson' => json_encode ( $mailList )
  575. );
  576. }
  577. $invoice->setInvoiceByCondition ( $item );
  578. $item = array (
  579. 'date' => date ( "Y-m-d H:i:s" ),
  580. 'operation' => "重新提交审批",
  581. 'status' => 1,
  582. 'img' => $this->staff [0] ['avatar'],
  583. 'username' => $this->staff [0] ['username'],
  584. 'uid' => $this->staff [0] ['sid'],
  585. 'category' => $this->staff [0] ['category'],
  586. 'iid' => $iid
  587. );
  588. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  589. }
  590. return "/invoice";
  591. }
  592. /**
  593. * 培训班
  594. */
  595. function invoiceTraining() {
  596. Doo::loadModel ( 'L_category' );
  597. $lCategory = new L_category ();
  598. Doo::loadModel ( 'invoiceTraining' );
  599. $invoiceTraining = new invoiceTraining ();
  600. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  601. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  602. $category = $lCategory->getCategory ();
  603. $itid = array ();
  604. foreach ( $itTodoList as $value ) {
  605. array_push ( $itid, $value ['itid'] );
  606. }
  607. foreach ( $itedList as $value ) {
  608. array_push ( $itid, $value ['itid'] );
  609. }
  610. $itid = implode ( ',', $itid );
  611. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  612. // print_r($itTodoList);
  613. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  614. $this->data ['itTodoList'] = $itTodoList;
  615. $this->data ['itedList'] = $itedList;
  616. $this->data ['category'] = $category;
  617. $this->data ['memu'] = "invoice";
  618. $this->data ['staff'] = $this->staff;
  619. $this->data ['receiptMemu'] = 'invoiceTraining';
  620. $this->render ( "/admin/invoiceTraining", $this->data );
  621. }
  622. /**
  623. * 创建培训班
  624. */
  625. function invoiceTrainingAdd() {
  626. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  627. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  628. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  629. if (empty ( $this->staff [0] ))
  630. die ( 'illegal request' );
  631. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  632. Doo::loadModel ( 'invoiceTraining' );
  633. $invoiceTraining = new invoiceTraining ();
  634. Doo::loadModel ( 'invoice' );
  635. $invoice = new invoice ();
  636. Doo::loadModel ( 'L_category' );
  637. $lCategory = new L_category ();
  638. Doo::loadModel ( 'invoiceManage' );
  639. $invoiceManage = new invoiceManage ();
  640. Doo::loadModel ( 'invoiceOperationLog' );
  641. $invoiceOperationLog = new invoiceOperationLog ();
  642. $item = array (
  643. 'cid' => $cid,
  644. 'trainName' => $trainName,
  645. 'trainDate' => $trainDate,
  646. 'creator' => $this->staff [0] ['sid'],
  647. 'creatorDate' => date ( "Y-m-d H:i:s" )
  648. );
  649. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  650. }
  651. return "/invoiceTraining";
  652. }
  653. /**
  654. * 删除培训班
  655. */
  656. function invoiceTrainingDelDo() {
  657. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  658. if (! empty ( $itid )) {
  659. Doo::loadModel ( 'invoiceTraining' );
  660. $invoiceTraining = new invoiceTraining ();
  661. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  662. }
  663. return "/invoiceTraining";
  664. }
  665. /**
  666. * 培训班详情
  667. */
  668. function invoiceTrainingDetail() {
  669. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  670. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  671. Doo::loadModel ( 'invoiceTraining' );
  672. $invoiceTraining = new invoiceTraining ();
  673. Doo::loadModel ( 'invoiceStore' );
  674. $invoiceStore = new invoiceStore ();
  675. if (empty ( $itid ))
  676. die ( 'illegal request' );
  677. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  678. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid );
  679. // print_r($isList);
  680. $trainlist = array ();
  681. foreach ( $isList as $key => $value ) {
  682. $irDetail = array ();
  683. if ($value ['apStatus'] == 1) {
  684. // array_push ( $irDetail, '' );
  685. array_push ( $irDetail, '<input class="hide" disabled type="checkbox" >' );
  686. } else {
  687. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  688. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  689. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  690. }
  691. array_push ( $irDetail, $value ['invoiceSerial'] );
  692. if ($value ['invoiceType'] == 1)
  693. array_push ( $irDetail, $value ['invoiceCompany'] );
  694. else
  695. array_push ( $irDetail, $value ['invoiceTitle'] );
  696. array_push ( $irDetail, $value ['TIN'] );
  697. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  698. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  699. } else
  700. array_push ( $irDetail, $value ['mailItems'] );
  701. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  702. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  703. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  704. array_push ( $irDetail, $value ['invoiceElement'] );
  705. array_push ( $irDetail, $value ['invoiceQuantity'] );
  706. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  707. if ($value ['invoiceType'] == 1)
  708. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  709. else
  710. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  711. array_push ( $irDetail, $value ['remark'] );
  712. if ($value ['status'] == 1)
  713. array_push ( $irDetail, '审批中' );
  714. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  715. array_push ( $irDetail, '已出票' );
  716. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  717. array_push ( $irDetail, '已入账' );
  718. else
  719. array_push ( $irDetail, '' );
  720. array_push ( $irDetail, $value ['invoiceNo'] );
  721. array_push ( $irDetail, $value ['printTime'] );
  722. $html = '';
  723. foreach ( $value ['invoiceReceivables'] as $value ) {
  724. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  725. }
  726. array_push ( $irDetail, $html );
  727. array_push ( $trainlist, $irDetail );
  728. }
  729. $trainlistJson = json_encode ( $trainlist );
  730. if (empty ( $detail ))
  731. die ( 'illegal request' );
  732. $this->data ['trainStatus'] = $trainStatus;
  733. $this->data ['itid'] = $itid;
  734. $this->data ['trainlistJson'] = $trainlistJson;
  735. $this->data ['iTrainDetail'] = $detail;
  736. $this->data ['memu'] = "invoice";
  737. $this->data ['staff'] = $this->staff;
  738. $this->data ['receiptMemu'] = 'invoiceTraining';
  739. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  740. }
  741. /**
  742. * 上传培训班发票
  743. * @return string
  744. */
  745. function invoiceTrainingUpload() {
  746. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  747. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  748. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  749. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  750. header ( "HTTP/1.1 500 Internal Server Error" );
  751. echo "POST exceeded maximum allowed size.";
  752. exit ( 0 );
  753. }
  754. // Settings
  755. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  756. $upload_name = "Filedata";
  757. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  758. $extension_whitelist = array (
  759. "doc",
  760. "txt",
  761. "jpg",
  762. "gif",
  763. "png"
  764. ); // Allowed file extensions
  765. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  766. // Other variables
  767. $MAX_FILENAME_LENGTH = 260;
  768. $file_name = "";
  769. $file_extension = "";
  770. $uploadErrors = array (
  771. 0 => "文件上传成功",
  772. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  773. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  774. 3 => "上传的文件仅为部分文件",
  775. 4 => "没有文件上传",
  776. 6 => "缺少临时文件夹"
  777. );
  778. $nk = time ();
  779. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  780. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  781. echo "文件无法保存.";
  782. exit ( 0 );
  783. }
  784. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  785. echo json_encode ( array (
  786. 'filename' => $file_name,
  787. 'id' => $nk
  788. ) );
  789. exit ( 0 );
  790. }
  791. /**
  792. * 导入发票临时仓库
  793. */
  794. function invoiceStoreImport() {
  795. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  796. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  797. if ($path != "" && ! empty ( $trainingKey )) {
  798. Doo::loadModel ( 'invoiceStore' );
  799. Doo::loadModel ( 'staff' );
  800. $staff = new staff ();
  801. Doo::loadModel ( 'invoiceTraining' );
  802. $invoiceTraining = new invoiceTraining ();
  803. Doo::loadClass ( 'XDeode' );
  804. $XDeode = new XDeode ( 5 );
  805. $itid = $XDeode->decode ( $trainingKey );
  806. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path, 'invoiceTrain' );
  807. $userName = $this->staff [0] ['username'];
  808. $sDetail = $staff->getStaffByName ( $userName );
  809. // 可以优化
  810. foreach ( $exlArray as $key => $value ) {
  811. // 开票
  812. $invoice = new invoiceStore ();
  813. $invoice->trainId = $itid;
  814. $invoice->invoiceType = 0;
  815. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  816. $invoice->invoiceType = 1;
  817. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  818. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  819. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  820. $invoice->invoiceTitle = $value ['invoiceTitle'];
  821. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  822. $invoice->invoiceCompany = $value ['invoiceTitle'];
  823. $invoice->userName = $userName;
  824. $invoice->sid = $sDetail ['sid'];
  825. $invoice->cid = $sDetail ['cid'];
  826. $invoice->categoryName = $sDetail ['category'];
  827. $invoice->invoiceElement = $value ['invoiceElement'];
  828. $invoice->remark = $value ['remark'];
  829. $invoice->date = $value ['date'];
  830. $invoice->printTime = $value ['date'];
  831. $invoice->ipSource = 1;
  832. $invoice->printStatus = 1;
  833. $invoice->status = 2;
  834. $invoice->postStatus = 1;
  835. $invoice->untreadStatus = 0;
  836. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  837. $invoice->TIN = $value ['TIN'];
  838. $invoice->address = $value ['address'];
  839. $invoice->phone = $value ['phone'];
  840. $invoice->bank = $value ['bank'];
  841. $invoice->bankAccount = $value ['bankAccount'];
  842. $invoice->recipientsAddress = $value ['recipientsAddress'];
  843. $invoice->recipients = $value ['recipients'];
  844. $invoice->recipientsPhone = $value ['recipientsPhone'];
  845. $iid = $invoice->insert ();
  846. }
  847. // 加入发票总数量
  848. $item = array (
  849. 'itid' => $itid,
  850. 'invoiceTotal' => count ( $exlArray )
  851. );
  852. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  853. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  854. }
  855. echo 'no file';
  856. }
  857. /**
  858. * 编辑仓库里的发票
  859. */
  860. function invoiceStoreEdit() {
  861. Doo::loadClass ( 'XDeode' );
  862. $XDeode = new XDeode ( 5 );
  863. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  864. $iid = $XDeode->decode ( $iid );
  865. if (! is_numeric ( $iid ))
  866. die ( 'illegal request' );
  867. Doo::loadModel ( 'invoiceStore' );
  868. $invoiceStore = new invoiceStore ();
  869. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  870. // print_r($invoiceDetail);
  871. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  872. $this->data ['invoiceDetail'] = $invoiceDetail;
  873. $this->data ['memu'] = "invoice";
  874. $this->data ['staff'] = $this->staff;
  875. $this->data ['receiptMemu'] = 'invoiceTraining';
  876. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  877. }
  878. function invoiceStoreEditDo() {
  879. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  880. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  881. Doo::loadModel ( 'invoiceStore' );
  882. $invoice = new invoiceStore ();
  883. Doo::loadClass ( 'XDeode' );
  884. $XDeode = new XDeode ( 5 );
  885. $iid = $XDeode->decode ( $storeKey );
  886. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  887. die ( 'illegal request' );
  888. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  889. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  890. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  891. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  892. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  893. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  894. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  895. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  896. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  897. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  898. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  899. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  900. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  901. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  902. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  903. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  904. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  905. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  906. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  907. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  908. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  909. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  910. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  911. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  912. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  913. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  914. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  915. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  916. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  917. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  918. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  919. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  920. $cid = explode ( ':', $cid );
  921. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  922. $item = array (
  923. 'isid' => $iid,
  924. 'cid' => $cid [0],
  925. 'categoryName' => $cid [1],
  926. 'invoiceElement' => $invoiceElement,
  927. 'invoiceQuantity' => $invoiceQuantity,
  928. 'invoiceUnitPrice' => $invoiceUnitPrice,
  929. 'invoicePrice' => $invoicePrice,
  930. 'invoiceType' => $invoiceType,
  931. 'doPost' => $doPost,
  932. 'status' => 1,
  933. 'updateTime' => date ( "Y-m-d H:i:s" ),
  934. 'remark' => $remark
  935. );
  936. if ($invoiceType == 0)
  937. $item += array (
  938. 'invoiceTitle' => $invoiceTitle,
  939. 'TIN' => $TINT,
  940. 'address' => $addressT,
  941. 'phone' => $phoneT,
  942. 'bank' => $bankT,
  943. 'bankAccount' => $bankAccountT
  944. );
  945. else {
  946. $item += array (
  947. 'invoiceCompany' => $invoiceCompany,
  948. 'TIN' => $TIN,
  949. 'address' => $address,
  950. 'phone' => $phone,
  951. 'bank' => $bank,
  952. 'bankAccount' => $bankAccount
  953. );
  954. }
  955. if ($doPost == 1) {
  956. $mailList = array (
  957. 'invoice' => 1,
  958. 'mailItems' => $mailItems
  959. );
  960. if (! empty ( $softLock ))
  961. $mailList += array (
  962. 'softLock' => $softLockNum
  963. );
  964. else
  965. $mailList += array (
  966. 'softLock' => '0'
  967. );
  968. if (! empty ( $contract ))
  969. $mailList += array (
  970. 'contract' => $contractNum
  971. );
  972. else
  973. $mailList += array (
  974. 'contract' => '0'
  975. );
  976. if (! empty ( $instructions ))
  977. $mailList += array (
  978. 'instructions' => $instructionsNum
  979. );
  980. else
  981. $mailList += array (
  982. 'instructions' => '0'
  983. );
  984. if (! empty ( $remittance ))
  985. $mailList += array (
  986. 'remittance' => $remittance
  987. );
  988. else
  989. $mailList += array (
  990. 'remittance' => ''
  991. );
  992. $mailString = '发票x1,备注:' . $mailItems;
  993. if (! empty ( $softLock ))
  994. $mailString .= ',软件锁x' . $softLockNum;
  995. if (! empty ( $contract ))
  996. $mailString .= ',合同x' . $contractNum;
  997. if (! empty ( $instructions ))
  998. $mailString .= ',说明书x' . $instructionsNum;
  999. if (! empty ( $remittance ))
  1000. $mailString .= ',汇款账号单';
  1001. $item += array (
  1002. 'recipients' => $recipients,
  1003. 'recipientsPhone' => $recipientsPhone,
  1004. 'recipientsAddress' => $recipientsAddress,
  1005. 'mailItems' => $mailString,
  1006. 'mailItemsJson' => json_encode ( $mailList )
  1007. );
  1008. }
  1009. $invoice->setInvoiceStoreByCondition ( $item );
  1010. }
  1011. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1012. }
  1013. /**
  1014. *
  1015. * @return string
  1016. */
  1017. function invoiceStoreDelete() {
  1018. Doo::loadClass ( 'XDeode' );
  1019. $XDeode = new XDeode ( 5 );
  1020. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1021. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1022. $isid = $XDeode->decode ( $iStoreKey );
  1023. $itid = $XDeode->decode ( $trainKey );
  1024. if (! is_numeric ( $isid ))
  1025. die ( 'illegal request' );
  1026. Doo::loadModel ( 'invoiceStore' );
  1027. $invoiceStore = new invoiceStore ();
  1028. $invoiceStore->delete ( array (
  1029. 'where' => 'isid=' . $isid,
  1030. 'limit' => 1
  1031. ) );
  1032. Doo::loadModel ( 'invoiceTraining' );
  1033. $invoiceTraining = new invoiceTraining ();
  1034. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1035. $item = array (
  1036. 'itid' => $itid,
  1037. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1038. );
  1039. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1040. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1041. }
  1042. /**
  1043. * 批量删除库里发票
  1044. */
  1045. function invoiceStoreBatchDelete() {
  1046. Doo::loadClass ( 'XDeode' );
  1047. $XDeode = new XDeode ( 5 );
  1048. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1049. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1050. $tid = $XDeode->decode ( $trainKey );
  1051. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1052. die ( 'illegal request' );
  1053. Doo::loadModel ( 'invoiceStore' );
  1054. $isidKeyList = explode ( ',', $storeKey );
  1055. $isidList = array ();
  1056. foreach ( $isidKeyList as $value ) {
  1057. $isid = $XDeode->decode ( $value );
  1058. if (! empty ( $isid ) && is_numeric ( $isid ))
  1059. array_push ( $isidList, $isid );
  1060. }
  1061. $isidString = implode ( ',', $isidList );
  1062. $invoiceStore = new invoiceStore ();
  1063. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1064. $isidList = array ();
  1065. foreach ( $isList as $key => $value ) {
  1066. if ($value ['apStatus'] == 0)
  1067. array_push ( $isidList, $value ['isid'] );
  1068. }
  1069. $isidString = implode ( ',', $isidList );
  1070. // print_r($isList);
  1071. // echo $isidString;
  1072. $invoiceStore = new invoiceStore ();
  1073. $invoiceStore->delete ( array (
  1074. 'where' => "isid in ( " . $isidString . ")",
  1075. 'asArray' => TRUE
  1076. ) );
  1077. Doo::loadModel ( 'invoiceTraining' );
  1078. $invoiceTraining = new invoiceTraining ();
  1079. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1080. $item = array (
  1081. 'itid' => $tid,
  1082. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1083. );
  1084. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1085. // echo $tid;
  1086. // echo $storeKey;
  1087. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1088. }
  1089. /**
  1090. * 仓库发票提交审批
  1091. * @return string
  1092. */
  1093. function invoiceStoreApproval() {
  1094. Doo::loadClass ( 'XDeode' );
  1095. $XDeode = new XDeode ( 5 );
  1096. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1097. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1098. $isid = $XDeode->decode ( $iStoreKey );
  1099. $trainId = $XDeode->decode ( $trainKey );
  1100. if (! is_numeric ( $isid ))
  1101. die ( 'illegal request' );
  1102. Doo::loadModel ( 'invoiceStore' );
  1103. Doo::loadModel ( 'invoice' );
  1104. $invoice = new invoice ();
  1105. // 拷贝插入一条发票数据
  1106. $invoiceStore = new invoiceStore ();
  1107. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1108. $invoiceStore = new invoiceStore ();
  1109. $item = array (
  1110. 'isid' => $isid,
  1111. 'iid' => $iid,
  1112. 'apStatus' => 1
  1113. );
  1114. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1115. Doo::loadModel ( 'invoiceManage' );
  1116. $invoiceManage = new invoiceManage ();
  1117. Doo::loadModel ( 'invoiceOperationLog' );
  1118. $invoiceOperationLog = new invoiceOperationLog ();
  1119. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1120. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1121. $moldManage = array ();
  1122. foreach ( $invoiceManageList as $key => $value ) {
  1123. if ($value ['mold'] == '发票打印')
  1124. $moldManage [$value ['mold']] = $value ['staffList'];
  1125. elseif ($value ['mold'] == '发票邮寄')
  1126. $moldManage [$value ['mold']] = $value ['staffList'];
  1127. elseif ($value ['mold'] == '发票退票')
  1128. $moldManage [$value ['mold']] = $value ['staffList'];
  1129. }
  1130. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1131. $item = array (
  1132. 'iid' => $iid,
  1133. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1134. 'date' => date ( "Y-m-d H:i:s" ),
  1135. 'status' => 1,
  1136. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1137. 'trainId' => $trainId,
  1138. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1139. 'moldManage' => json_encode ( $moldManage ),
  1140. 'pendingApprovals' => $pendingApprovalsSid
  1141. );
  1142. $invoice->setInvoiceByCondition ( $item );
  1143. Doo::loadModel ( 'invoiceTraining' );
  1144. $invoiceTraining = new invoiceTraining ();
  1145. $item = array (
  1146. 'itid' => $trainId,
  1147. 'submitStatus' => 1
  1148. );
  1149. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1150. $item = array (
  1151. 'date' => date ( "Y-m-d H:i:s" ),
  1152. 'operation' => "创建",
  1153. 'status' => 1,
  1154. 'img' => $this->staff [0] ['avatar'],
  1155. 'username' => $this->staff [0] ['username'],
  1156. 'uid' => $this->staff [0] ['sid'],
  1157. 'category' => $this->staff [0] ['category'],
  1158. 'iid' => $iid
  1159. );
  1160. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1161. $item = array (
  1162. 'date' => date ( "Y-m-d H:i:s" ),
  1163. 'operation' => "提交审批",
  1164. 'status' => 1,
  1165. 'img' => $this->staff [0] ['avatar'],
  1166. 'username' => $this->staff [0] ['username'],
  1167. 'uid' => $this->staff [0] ['sid'],
  1168. 'category' => $this->staff [0] ['category'],
  1169. 'iid' => $iid
  1170. );
  1171. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1172. Doo::loadModel ( 'staff' );
  1173. $staff = new staff ();
  1174. $username2 = $staff->getOne ( array (
  1175. 'select' => 'wxid',
  1176. 'where' => 'sid=' . $pendingApprovalsSid,
  1177. 'asArray' => TRUE
  1178. ) );
  1179. // 发送微信审批通知
  1180. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1181. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1182. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1183. }
  1184. /**
  1185. * 批量提交发票
  1186. * @return string
  1187. */
  1188. function invoiceStoreBatchApproval() {
  1189. Doo::loadClass ( 'XDeode' );
  1190. $XDeode = new XDeode ( 5 );
  1191. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1192. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1193. $trainId = $XDeode->decode ( $trainKey );
  1194. $isidKeyList = explode ( ',', $storeKey );
  1195. $isidList = array ();
  1196. foreach ( $isidKeyList as $value ) {
  1197. $isid = $XDeode->decode ( $value );
  1198. if (! empty ( $isid ) && is_numeric ( $isid ))
  1199. array_push ( $isidList, $isid );
  1200. }
  1201. $isidString = implode ( ',', $isidList );
  1202. if (! is_numeric ( $trainId ))
  1203. die ( 'illegal request' );
  1204. Doo::loadModel ( 'invoiceStore' );
  1205. Doo::loadModel ( 'invoice' );
  1206. // 判断哪些已经加入审批过
  1207. // 拷贝插入一条发票数据
  1208. $invoiceStore = new invoiceStore ();
  1209. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1210. $invoiceStore = new invoiceStore ();
  1211. $item = array (
  1212. 'apStatus' => 1
  1213. );
  1214. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1215. // 获得正式发票ID
  1216. $invoice = new invoice ();
  1217. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1218. $sqlList = array ();
  1219. $iidString = '';
  1220. $iida = array ();
  1221. foreach ( $iidList as $key => $value ) {
  1222. $sqlList [$value ['isid']] = $value ['iid'];
  1223. array_push ( $iida, $value ['iid'] );
  1224. }
  1225. $iidString = implode ( ',', $iida );
  1226. $ids = implode ( ',', array_keys ( $sqlList ) );
  1227. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1228. foreach ( $sqlList as $id => $ordinal ) {
  1229. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1230. }
  1231. $sql .= "END WHERE isid IN ($ids)";
  1232. $invoiceStore = new invoiceStore ();
  1233. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1234. Doo::loadModel ( 'invoiceManage' );
  1235. $invoiceManage = new invoiceManage ();
  1236. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1237. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1238. $moldManage = array ();
  1239. foreach ( $invoiceManageList as $key => $value ) {
  1240. if ($value ['mold'] == '发票打印')
  1241. $moldManage [$value ['mold']] = $value ['staffList'];
  1242. elseif ($value ['mold'] == '发票邮寄')
  1243. $moldManage [$value ['mold']] = $value ['staffList'];
  1244. elseif ($value ['mold'] == '发票退票')
  1245. $moldManage [$value ['mold']] = $value ['staffList'];
  1246. }
  1247. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1248. // 批量更新发票信息
  1249. $item = array (
  1250. 'date' => date ( "Y-m-d H:i:s" ),
  1251. 'status' => 1,
  1252. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1253. 'trainId' => $trainId,
  1254. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1255. 'moldManage' => json_encode ( $moldManage ),
  1256. 'pendingApprovals' => $pendingApprovalsSid
  1257. );
  1258. $invoice = new invoice ();
  1259. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1260. // 批量更新发票序列号
  1261. $sqlList = array ();
  1262. foreach ( $iida as $value ) {
  1263. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1264. }
  1265. $ids = implode ( ',', array_keys ( $sqlList ) );
  1266. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1267. foreach ( $sqlList as $id => $ordinal ) {
  1268. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1269. }
  1270. $sql .= "END WHERE iid IN ($ids)";
  1271. $invoiceStore = new invoiceStore ();
  1272. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1273. // 批量生产操作日志
  1274. Doo::loadModel ( 'invoiceOperationLog' );
  1275. $sqlList = array ();
  1276. foreach ( $iida as $key => $value ) {
  1277. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1278. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1279. array_push ( $sqlList, $sql );
  1280. }
  1281. $iolSql = implode ( ',', $sqlList );
  1282. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1283. $invoiceOperationLog = new invoiceOperationLog ();
  1284. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1285. Doo::loadModel ( 'invoiceTraining' );
  1286. $invoiceTraining = new invoiceTraining ();
  1287. $item = array (
  1288. 'itid' => $trainId,
  1289. 'submitStatus' => 1
  1290. );
  1291. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1292. // Doo::loadModel ( 'invoiceOperationLog' );
  1293. // $item = array (
  1294. // 'date' => date ( "Y-m-d H:i:s" ),
  1295. // 'operation' => "创建",
  1296. // 'status' => 1,
  1297. // 'img' => $this->staff [0] ['avatar'],
  1298. // 'username' => $this->staff [0] ['username'],
  1299. // 'uid' => $this->staff [0] ['sid'],
  1300. // 'category' => $this->staff [0] ['category'],
  1301. // 'iid' => $iid
  1302. // );
  1303. // $invoiceOperationLog = new invoiceOperationLog ();
  1304. // $invoiceOperationLog->setInvoiceOperationLog ( $item ,$iidString);
  1305. // $item = array (
  1306. // 'date' => date ( "Y-m-d H:i:s" ),
  1307. // 'operation' => "提交审批",
  1308. // 'status' => 1,
  1309. // 'img' => $this->staff [0] ['avatar'],
  1310. // 'username' => $this->staff [0] ['username'],
  1311. // 'uid' => $this->staff [0] ['sid'],
  1312. // 'category' => $this->staff [0] ['category'],
  1313. // 'iid' => $iid
  1314. // );
  1315. // $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1316. Doo::loadModel ( 'staff' );
  1317. $staff = new staff ();
  1318. $username2 = $staff->getOne ( array (
  1319. 'select' => 'wxid',
  1320. 'where' => 'sid=' . $pendingApprovalsSid,
  1321. 'asArray' => TRUE
  1322. ) );
  1323. // 发送微信审批通知
  1324. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1325. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1326. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1327. }
  1328. /**
  1329. */
  1330. function invoiceStoreMailItemSet() {
  1331. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1332. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1333. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1334. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1335. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1336. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1337. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1338. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1339. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1340. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1341. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1342. Doo::loadClass ( 'XDeode' );
  1343. $XDeode = new XDeode ( 5 );
  1344. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1345. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1346. $isid = $XDeode->decode ( $storeKey );
  1347. $trainId = $XDeode->decode ( $trainKey );
  1348. if (! is_numeric ( $isid ))
  1349. die ( 'illegal request' );
  1350. Doo::loadModel ( 'invoiceStore' );
  1351. $invoiceStore = new invoiceStore ();
  1352. $mailList = array (
  1353. 'invoice' => 1,
  1354. 'mailItems' => $mailItems
  1355. );
  1356. if (! empty ( $softLock ))
  1357. $mailList += array (
  1358. 'softLock' => $softLockNum
  1359. );
  1360. else
  1361. $mailList += array (
  1362. 'softLock' => 0
  1363. );
  1364. if (! empty ( $contract ))
  1365. $mailList += array (
  1366. 'contract' => $contractNum
  1367. );
  1368. else
  1369. $mailList += array (
  1370. 'contract' => 0
  1371. );
  1372. if (! empty ( $instructions ))
  1373. $mailList += array (
  1374. 'instructions' => $instructionsNum
  1375. );
  1376. else
  1377. $mailList += array (
  1378. 'instructions' => 0
  1379. );
  1380. if (! empty ( $remittance ))
  1381. $mailList += array (
  1382. 'remittance' => $remittance
  1383. );
  1384. else
  1385. $mailList += array (
  1386. 'remittance' => ''
  1387. );
  1388. $mailString = '发票x1,备注:' . $mailItems;
  1389. if (! empty ( $softLock ))
  1390. $mailString .= ',软件锁x' . $softLockNum;
  1391. if (! empty ( $contract ))
  1392. $mailString .= ',合同x' . $contractNum;
  1393. if (! empty ( $instructions ))
  1394. $mailString .= ',说明书x' . $instructionsNum;
  1395. if (! empty ( $remittance ))
  1396. $mailString .= ',汇款账号单';
  1397. $item = array (
  1398. 'isid' => $isid,
  1399. 'doPost' => 1,
  1400. 'mailItems' => $mailString,
  1401. 'mailItemsJson' => json_encode ( $mailList )
  1402. );
  1403. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1404. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1405. }
  1406. /**
  1407. * 批量设置邮寄物品
  1408. */
  1409. function invoiceStoreBatchMailItemSet() {
  1410. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1411. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1412. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1413. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1414. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1415. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1416. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1417. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1418. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1419. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1420. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1421. Doo::loadClass ( 'XDeode' );
  1422. $XDeode = new XDeode ( 5 );
  1423. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1424. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1425. $isidKeyList = explode ( ',', $storeKey );
  1426. $isidList = array ();
  1427. foreach ( $isidKeyList as $value ) {
  1428. $isid = $XDeode->decode ( $value );
  1429. if (! empty ( $isid ) && is_numeric ( $isid ))
  1430. array_push ( $isidList, $isid );
  1431. }
  1432. $isidString = implode ( ',', $isidList );
  1433. $trainId = $XDeode->decode ( $trainKey );
  1434. if (! is_numeric ( $isid ))
  1435. die ( 'illegal request' );
  1436. Doo::loadModel ( 'invoiceStore' );
  1437. $invoiceStore = new invoiceStore ();
  1438. $mailList = array (
  1439. 'invoice' => 1,
  1440. 'mailItems' => $mailItems
  1441. );
  1442. if (! empty ( $softLock ))
  1443. $mailList += array (
  1444. 'softLock' => $softLockNum
  1445. );
  1446. else
  1447. $mailList += array (
  1448. 'softLock' => 0
  1449. );
  1450. if (! empty ( $contract ))
  1451. $mailList += array (
  1452. 'contract' => $contractNum
  1453. );
  1454. else
  1455. $mailList += array (
  1456. 'contract' => 0
  1457. );
  1458. if (! empty ( $instructions ))
  1459. $mailList += array (
  1460. 'instructions' => $instructionsNum
  1461. );
  1462. else
  1463. $mailList += array (
  1464. 'instructions' => 0
  1465. );
  1466. if (! empty ( $remittance ))
  1467. $mailList += array (
  1468. 'remittance' => $remittance
  1469. );
  1470. else
  1471. $mailList += array (
  1472. 'remittance' => ''
  1473. );
  1474. $mailString = '发票x1,备注:' . $mailItems;
  1475. if (! empty ( $softLock ))
  1476. $mailString .= ',软件锁x' . $softLockNum;
  1477. if (! empty ( $contract ))
  1478. $mailString .= ',合同x' . $contractNum;
  1479. if (! empty ( $instructions ))
  1480. $mailString .= ',说明书x' . $instructionsNum;
  1481. if (! empty ( $remittance ))
  1482. $mailString .= ',汇款账号单';
  1483. $item = array (
  1484. 'doPost' => 1,
  1485. 'mailItems' => $mailString,
  1486. 'mailItemsJson' => json_encode ( $mailList )
  1487. );
  1488. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1489. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1490. }
  1491. /**
  1492. * 废弃
  1493. */
  1494. function ajaxGetMailItemByIstore() {
  1495. Doo::loadClass ( 'XDeode' );
  1496. $XDeode = new XDeode ( 5 );
  1497. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1498. $isid = $XDeode->decode ( $storeKey );
  1499. if (! is_numeric ( $isid ))
  1500. die ( 'illegal request' );
  1501. Doo::loadModel ( 'invoiceStore' );
  1502. $invoiceStore = new invoiceStore ();
  1503. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1504. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1505. echo json_encode ( $isDetail ['mailItemsJson'] );
  1506. exit ();
  1507. }
  1508. /**
  1509. * 终止开票
  1510. */
  1511. function invoiceDroppedDo() {
  1512. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1513. Doo::loadModel ( 'invoice' );
  1514. $invoice = new invoice ();
  1515. Doo::loadModel ( 'invoiceOperationLog' );
  1516. $invoiceOperationLog = new invoiceOperationLog ();
  1517. $iid = $invoice->authcode ( $droppedIidKey );
  1518. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1519. die ( 'illegal request' );
  1520. $item = array (
  1521. 'iid' => $iid,
  1522. 'status' => 4,
  1523. 'updateTime' => date ( "Y-m-d H:i:s" )
  1524. );
  1525. $invoice->setInvoiceByCondition ( $item );
  1526. $item = array (
  1527. 'date' => date ( "Y-m-d H:i:s" ),
  1528. 'operation' => '终止了开票',
  1529. 'status' => 4,
  1530. 'img' => $this->staff [0] ['avatar'],
  1531. 'username' => $this->staff [0] ['username'],
  1532. 'uid' => $this->staff [0] ['sid'],
  1533. 'category' => $this->staff [0] ['category'],
  1534. 'iid' => $iid
  1535. );
  1536. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1537. return "/invoice";
  1538. }
  1539. /**
  1540. * 更新退票的邮寄信息
  1541. */
  1542. function invoiceUntreadMailDo() {
  1543. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1544. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1545. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1546. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1547. Doo::loadModel ( 'invoice' );
  1548. $invoice = new invoice ();
  1549. $iid = $invoice->authcode ( $untreadIidKey );
  1550. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1551. die ( 'illegal request' );
  1552. $item = array (
  1553. 'iid' => $iid,
  1554. 'untreadCompany' => $untreadCompany,
  1555. 'untreadNumber' => $untreadNumber,
  1556. 'untreadItems' => $untreadItems
  1557. );
  1558. $invoice->setInvoiceByCondition ( $item );
  1559. return "/invoice";
  1560. }
  1561. /**
  1562. * 申请退票 --
  1563. */
  1564. function invoiceUntreadDo() {
  1565. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1566. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1567. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1568. Doo::loadModel ( 'invoice' );
  1569. $invoice = new invoice ();
  1570. Doo::loadModel ( 'invoiceOperationLog' );
  1571. $invoiceOperationLog = new invoiceOperationLog ();
  1572. Doo::loadModel ( 'invoiceReceivables' );
  1573. $invoiceReceivables = new invoiceReceivables ();
  1574. $iid = $invoice->authcode ( $untreadIidKey );
  1575. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1576. die ( 'illegal request' );
  1577. /*
  1578. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1579. */
  1580. $item = array (
  1581. 'iid' => $iid,
  1582. 'untreadStatus' => 1,
  1583. 'untreadReason' => $untreadReason,
  1584. 'untreadPost' => $untreadPost,
  1585. 'updateTime' => date ( "Y-m-d H:i:s" )
  1586. );
  1587. $invoice->setInvoiceByCondition ( $item );
  1588. $item = array (
  1589. 'date' => date ( "Y-m-d H:i:s" ),
  1590. 'operation' => '申请退票',
  1591. 'status' => 7,
  1592. 'img' => $this->staff [0] ['avatar'],
  1593. 'username' => $this->staff [0] ['username'],
  1594. 'uid' => $this->staff [0] ['sid'],
  1595. 'category' => $this->staff [0] ['category'],
  1596. 'iid' => $iid
  1597. );
  1598. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1599. return "/invoice";
  1600. }
  1601. /**
  1602. * 删除已终止的开票
  1603. */
  1604. function invoiceDelDo() {
  1605. Doo::loadClass ( 'XDeode' );
  1606. $XDeode = new XDeode ( 5 );
  1607. Doo::loadModel ( 'invoice' );
  1608. $invoice = new invoice ();
  1609. Doo::loadModel ( 'invoiceOperationLog' );
  1610. $invoiceOperationLog = new invoiceOperationLog ();
  1611. Doo::loadClass ( 'XDeode' );
  1612. $XDeode = new XDeode ( 5 );
  1613. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1614. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1615. $iid = $XDeode->decode ( $iid );
  1616. if (! is_numeric ( $iid ))
  1617. die ( 'illegal request' );
  1618. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1619. if (empty ( $invoiceDetail ))
  1620. die ( 'illegal request' );
  1621. $item = array (
  1622. 'iid' => $iid,
  1623. 'isDelete' => 1,
  1624. 'updateTime' => date ( "Y-m-d H:i:s" )
  1625. );
  1626. $invoice->setInvoiceByCondition ( $item );
  1627. $item = array (
  1628. 'date' => date ( "Y-m-d H:i:s" ),
  1629. 'operation' => '删除了已终止的发票',
  1630. 'status' => 4,
  1631. 'img' => $this->staff [0] ['avatar'],
  1632. 'username' => $this->staff [0] ['username'],
  1633. 'uid' => $this->staff [0] ['sid'],
  1634. 'category' => $this->staff [0] ['category'],
  1635. 'iid' => $iid
  1636. );
  1637. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1638. return "/invoice";
  1639. }
  1640. function invoiceApproval() {
  1641. Doo::loadModel ( 'invoice' );
  1642. $invoice = new invoice ();
  1643. Doo::loadClass ( 'XDeode' );
  1644. $XDeode = new XDeode ( 5 );
  1645. Doo::loadModel ( 'staff' );
  1646. $staff = new staff ();
  1647. $invoiceList = $invoice->find ( array (
  1648. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1649. 'desc' => 'iid',
  1650. 'asArray' => true
  1651. ) );
  1652. foreach ( $invoiceList as $key => $value ) {
  1653. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1654. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1655. if (! empty ( $lastApprover )) {
  1656. $lastApproverKey = array_keys ( $lastApprover );
  1657. $lastApprover = end ( $lastApprover );
  1658. $staffDetail = $staff->getOne ( array (
  1659. 'where' => 'sid=' . end ( $lastApproverKey ),
  1660. 'asArray' => true
  1661. ) );
  1662. $lastApprover ['username'] = $staffDetail ['username'];
  1663. }
  1664. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1665. }
  1666. $ilist = $invoice->getInvoiceByProcessStatus ();
  1667. // print_r($ilist);
  1668. $this->data ['invoiceList'] = $invoiceList;
  1669. $this->data ['ilist'] = $ilist;
  1670. $this->data ['memu'] = "invoice";
  1671. $this->data ['staff'] = $this->staff;
  1672. $this->data ['receiptMemu'] = 'invoiceApproval';
  1673. $this->render ( "/admin/invoiceApproval", $this->data );
  1674. }
  1675. function invoiceDetail() {
  1676. Doo::loadClass ( 'XDeode' );
  1677. $XDeode = new XDeode ( 5 );
  1678. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1679. $iid = $XDeode->decode ( $iid );
  1680. if (! is_numeric ( $iid ))
  1681. die ( 'illegal request' );
  1682. Doo::loadModel ( 'invoice' );
  1683. $invoice = new invoice ();
  1684. Doo::loadModel ( 'invoiceOperationLog' );
  1685. $invoiceOperationLog = new invoiceOperationLog ();
  1686. $invoiceDetail = $invoice->getOne ( array (
  1687. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1688. 'asArray' => true
  1689. ) );
  1690. if (empty ( $invoiceDetail ))
  1691. die ( 'illegal request' );
  1692. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1693. $this->data ['invoiceDetail'] = $invoiceDetail;
  1694. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1695. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1696. $this->data ['memu'] = "invoice";
  1697. $this->data ['staff'] = $this->staff;
  1698. $this->data ['receiptMemu'] = 'invoiceApproval';
  1699. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1700. }
  1701. /**
  1702. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1703. *
  1704. * @since 1.0.0
  1705. * @var integer iid 开票ID 已加密
  1706. * @var integer status 发票审批状态
  1707. * @var integer opintion 审批发票的意见
  1708. * @return string 如操作成功返回审批首页
  1709. */
  1710. function invoiceApprovalDo() {
  1711. Doo::loadModel ( 'invoice' );
  1712. $invoice = new invoice ();
  1713. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1714. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1715. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1716. $iid = $invoice->authcode ( $iid );
  1717. if (! is_numeric ( $iid ))
  1718. die ( 'illegal request' );
  1719. // && ! empty ( $opinion )
  1720. if (! empty ( $iid ) && ! empty ( $status )) {
  1721. if (! ($status == 2 || $status == 3 || $status == 4))
  1722. die ( 'illegal request' );
  1723. Doo::loadModel ( 'invoiceOperationLog' );
  1724. $invoiceOperationLog = new invoiceOperationLog ();
  1725. $invoiceDetail = $invoice->getOne ( array (
  1726. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1727. 'asArray' => true
  1728. ) );
  1729. if (empty ( $invoiceDetail ))
  1730. die ( 'illegal request' );
  1731. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1732. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1733. if ($status == 3) {
  1734. $invoice->status = $status;
  1735. $item = array (
  1736. 'operation' => $opinion
  1737. );
  1738. } else {
  1739. if (empty ( $processApprovals )) {
  1740. $processApprovals = array (
  1741. $this->staff [0] ['sid'] => array (
  1742. 'date' => date ( "Y-m-d H:i:s" ),
  1743. 'opinion' => $opinion,
  1744. 'status' => $status
  1745. )
  1746. );
  1747. // var_dump(next($invoiceManage));
  1748. $nextInvoiceManage = next ( $invoiceManage );
  1749. // print_r($nextInvoiceManage);
  1750. if ($status != 4 && $nextInvoiceManage !== false)
  1751. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1752. $invoice->processApprovals = json_encode ( $processApprovals );
  1753. // var_dump($invoice);
  1754. // print_r($invoiceManage);
  1755. } else {
  1756. $processApprovals [$this->staff [0] ['sid']] = array (
  1757. 'date' => date ( "Y-m-d H:i:s" ),
  1758. 'opinion' => $opinion,
  1759. 'status' => $status
  1760. );
  1761. $pendingApprovals = 0;
  1762. foreach ( $invoiceManage as $key => $value ) {
  1763. if ($value [0] == $this->staff [0] ['sid']) {
  1764. if (isset ( $invoiceManage [$key + 1] ))
  1765. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1766. break;
  1767. }
  1768. }
  1769. if ($status != 4 && ! empty ( $pendingApprovals ))
  1770. $invoice->pendingApprovals = $pendingApprovals;
  1771. $invoice->processApprovals = json_encode ( $processApprovals );
  1772. }
  1773. $item = array (
  1774. 'operation' => $opinion
  1775. );
  1776. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1777. $invoice->status = $status;
  1778. $invoice->pendingApprovals = 0;
  1779. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1780. } elseif ($status == 4) {
  1781. $invoice->status = $status;
  1782. $item = array (
  1783. 'operation' => $opinion
  1784. );
  1785. }
  1786. }
  1787. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1788. $invoice->update ( array (
  1789. 'where' => 'iid=' . $iid
  1790. ) );
  1791. $item += array (
  1792. 'date' => date ( "Y-m-d H:i:s" ),
  1793. 'img' => $this->staff [0] ['avatar'],
  1794. 'username' => $this->staff [0] ['username'],
  1795. 'uid' => $this->staff [0] ['sid'],
  1796. 'category' => $this->staff [0] ['category'],
  1797. 'status' => $status,
  1798. 'iid' => $iid
  1799. );
  1800. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1801. return '/invoiceApproval';
  1802. }
  1803. die ( 'illegal request' );
  1804. }
  1805. /**
  1806. * 展示需要打印的发票数据
  1807. *
  1808. * @since 1.0.0
  1809. */
  1810. function invoicePrint() {
  1811. Doo::loadModel ( 'invoice' );
  1812. $invoice = new invoice ();
  1813. Doo::loadClass ( 'XDeode' );
  1814. $XDeode = new XDeode ( 5 );
  1815. Doo::loadModel ( 'staff' );
  1816. $staff = new staff ();
  1817. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1818. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1819. foreach ( $toPrint as $key => $value ) {
  1820. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1821. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1822. if (! empty ( $lastApprover )) {
  1823. $lastApproverKey = array_keys ( $lastApprover );
  1824. $lastApprover = end ( $lastApprover );
  1825. $staffDetail = $staff->getOne ( array (
  1826. 'where' => 'sid=' . end ( $lastApproverKey ),
  1827. 'asArray' => true
  1828. ) );
  1829. $lastApprover ['username'] = $staffDetail ['username'];
  1830. }
  1831. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1832. }
  1833. foreach ( $printed as $key => $value ) {
  1834. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1835. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1836. if (! empty ( $lastApprover )) {
  1837. $lastApproverKey = array_keys ( $lastApprover );
  1838. $lastApprover = end ( $lastApprover );
  1839. $staffDetail = $staff->getOne ( array (
  1840. 'where' => 'sid=' . end ( $lastApproverKey ),
  1841. 'asArray' => true
  1842. ) );
  1843. $lastApprover ['username'] = $staffDetail ['username'];
  1844. }
  1845. $printed [$key] ['lastApprover'] = $lastApprover;
  1846. }
  1847. $this->data ['printed'] = $printed;
  1848. $this->data ['toPrint'] = $toPrint;
  1849. $this->data ['memu'] = "invoice";
  1850. $this->data ['staff'] = $this->staff;
  1851. $this->data ['receiptMemu'] = 'invoicePrint';
  1852. $this->render ( "/admin/invoicePrint", $this->data );
  1853. }
  1854. /**
  1855. * 展示发票打印的详情页面
  1856. *
  1857. * @since 1.0.0
  1858. */
  1859. function invoicePrintDetail() {
  1860. Doo::loadClass ( 'XDeode' );
  1861. $XDeode = new XDeode ( 5 );
  1862. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1863. $iid = $XDeode->decode ( $iid );
  1864. if (! is_numeric ( $iid ))
  1865. die ( 'illegal request' );
  1866. Doo::loadModel ( 'invoice' );
  1867. $invoice = new invoice ();
  1868. Doo::loadModel ( 'invoiceOperationLog' );
  1869. $invoiceOperationLog = new invoiceOperationLog ();
  1870. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1871. if (empty ( $invoiceDetail ))
  1872. die ( 'illegal request' );
  1873. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1874. $this->data ['invoiceDetail'] = $invoiceDetail;
  1875. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1876. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1877. $this->data ['memu'] = "invoice";
  1878. $this->data ['staff'] = $this->staff;
  1879. $this->data ['receiptMemu'] = 'invoicePrint';
  1880. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1881. }
  1882. /**
  1883. * 所有待打印 发票
  1884. */
  1885. function invoicePrintStayAchieve() {
  1886. Doo::loadModel ( 'invoice' );
  1887. $invoice = new invoice ();
  1888. Doo::loadClass ( 'XDeode' );
  1889. $XDeode = new XDeode ( 5 );
  1890. Doo::loadModel ( 'staff' );
  1891. $staff = new staff ();
  1892. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1893. $page_size = 12;
  1894. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1895. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1896. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1897. $get = "/" . $status;
  1898. $con = ' and status=2 ';
  1899. if ($status == 'TOPRINT')
  1900. $con = ' and status=2 and printStatus=0 ';
  1901. elseif ($status == 'PRINTED')
  1902. $con = ' and status=2 and printStatus=1';
  1903. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1904. $dateArr = explode ( ':', $date );
  1905. $D1 = '';
  1906. $D2 = '';
  1907. if (! empty ( $date )) {
  1908. $D1 = $dateArr [0];
  1909. $D2 = $dateArr [1];
  1910. }
  1911. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  1912. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1913. if (! empty ( $MebSea )) {
  1914. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1915. }
  1916. $pageinfo ['page'] = array (
  1917. 'previous' => ''
  1918. );
  1919. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1920. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1921. $action = "invoicePrintStayAchieve";
  1922. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1923. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1924. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  1925. $this->data ['MebSeaEn'] = $MebSea;
  1926. $this->data ['MebSea'] = urlencode ( $MebSea );
  1927. $this->data ['get'] = $get;
  1928. $this->data ['page'] = $pageinfo;
  1929. $this->data ['date'] = $date;
  1930. $this->data ['status'] = $status;
  1931. $this->data ['memu'] = "invoice";
  1932. $this->data ['staff'] = $this->staff;
  1933. foreach ( $list as $key => $value ) {
  1934. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1935. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1936. if (! empty ( $lastApprover )) {
  1937. $lastApproverKey = array_keys ( $lastApprover );
  1938. $lastApprover = end ( $lastApprover );
  1939. $staffDetail = $staff->getOne ( array (
  1940. 'where' => 'sid=' . end ( $lastApproverKey ),
  1941. 'asArray' => true
  1942. ) );
  1943. $lastApprover ['username'] = $staffDetail ['username'];
  1944. }
  1945. $list [$key] ['lastApprover'] = $lastApprover;
  1946. }
  1947. $this->data ['receiptMemu'] = 'invoicePrint';
  1948. $this->data ['list'] = $list;
  1949. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  1950. }
  1951. /**
  1952. * 填写票号并完成打印
  1953. * @since 1.0.0
  1954. */
  1955. function invoicePrintDo() {
  1956. Doo::loadModel ( 'invoice' );
  1957. $invoice = new invoice ();
  1958. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1959. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  1960. $iid = $invoice->authcode ( $iid );
  1961. if (! is_numeric ( $iid ))
  1962. die ( 'illegal request' );
  1963. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  1964. Doo::loadModel ( 'invoiceOperationLog' );
  1965. $invoiceOperationLog = new invoiceOperationLog ();
  1966. Doo::loadModel ( 'invoiceStatistics' );
  1967. $invoiceStatistics = new invoiceStatistics ();
  1968. // $info=$invoice->getOne(array('where'=>"invoiceNo = '".$invoiceNo."'",'asArray' => TRUE));
  1969. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  1970. if (empty ( $invoicePrintDetail ))
  1971. die ( 'illegal request' );
  1972. $item = array (
  1973. 'iid' => $iid,
  1974. 'printStatus' => 1,
  1975. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1976. 'printer' => $this->staff [0] ['username'],
  1977. 'printTime' => date ( "Y-m-d H:i:s" ),
  1978. 'invoiceNo' => $invoiceNo
  1979. );
  1980. $invoice->setInvoiceByCondition ( $item );
  1981. $item = array (
  1982. 'date' => date ( "Y-m-d H:i:s" ),
  1983. 'operation' => '打印发票号:'.$invoiceNo,
  1984. 'status' => 5,
  1985. 'img' => $this->staff [0] ['avatar'],
  1986. 'username' => $this->staff [0] ['username'],
  1987. 'uid' => $this->staff [0] ['sid'],
  1988. 'category' => $this->staff [0] ['category'],
  1989. 'iid' => $iid
  1990. );
  1991. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1992. // 去统计--负票不汇总
  1993. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  1994. $item = array (
  1995. 'date' => date ( "Y-m-d H:i:s" ),
  1996. 'priceClass' => 1,
  1997. 'cid' => $invoicePrintDetail ['cid'],
  1998. 'staff' => $invoicePrintDetail ['sid'],
  1999. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2000. );
  2001. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2002. }
  2003. // 发送通知信息到微信-去除
  2004. // $this->setWXMsg($iid,'PRINT');
  2005. // 申请人获取微信通知
  2006. Doo::loadModel ( 'staff' );
  2007. $staff = new staff ();
  2008. Doo::loadClass ( 'XDeode' );
  2009. $XDeode = new XDeode ( 5 );
  2010. $username2 = $staff->getOne ( array (
  2011. 'select' => 'wxid',
  2012. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2013. 'asArray' => TRUE
  2014. ) );
  2015. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2016. $msg = '';
  2017. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2018. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2019. return "/invoicePrint";
  2020. }
  2021. }
  2022. /**
  2023. * 需要邮寄的发票
  2024. * @since 1.0.0
  2025. */
  2026. function invoicePost() {
  2027. Doo::loadModel ( 'invoice' );
  2028. $invoice = new invoice ();
  2029. Doo::loadModel ( 'express' );
  2030. $express = new express ();
  2031. $invoicePost = $invoice->getPostByInvoice ();
  2032. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2033. $expressList = $express->getExpressByAll ();
  2034. $this->data ['expressList'] = $expressList;
  2035. $this->data ['invoicePost'] = $invoicePost;
  2036. $this->data ['invoicePosted'] = $invoicePosted;
  2037. $this->data ['memu'] = "invoice";
  2038. $this->data ['staff'] = $this->staff;
  2039. $this->data ['receiptMemu'] = 'invoicePost';
  2040. $this->render ( "/admin/invoicePost", $this->data );
  2041. }
  2042. /**
  2043. * 添加发票邮寄信息
  2044. */
  2045. function invoiceExpressAddDo() {
  2046. Doo::loadModel ( 'invoice' );
  2047. $invoice = new invoice ();
  2048. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2049. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2050. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2051. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2052. $iid = $iid = $invoice->authcode ( $iid );
  2053. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2054. die ( 'illegal request' );
  2055. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2056. $item = array (
  2057. 'iid' => $iid,
  2058. 'postStatus' => 1,
  2059. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2060. 'postTime' => date ( "Y-m-d H:i:s" ),
  2061. 'expressCompany' => $expressCompany,
  2062. 'expressNumber' => $expressNumber,
  2063. 'actualItems' => $actualItems,
  2064. 'poster' => $this->staff [0] ['username']
  2065. );
  2066. $invoice->setInvoiceByCondition ( $item );
  2067. // 微信通知-去掉
  2068. // $this->setWXMsg ( $iid );
  2069. Doo::loadModel ( 'staff' );
  2070. $staff = new staff ();
  2071. Doo::loadClass ( 'XDeode' );
  2072. $XDeode = new XDeode ( 5 );
  2073. $username2 = $staff->getOne ( array (
  2074. 'select' => 'wxid',
  2075. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2076. 'asArray' => TRUE
  2077. ) );
  2078. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2079. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2080. if (empty ( $expCom ))
  2081. $expCom [0] = '';
  2082. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2083. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2084. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2085. return '/invoicePost';
  2086. }
  2087. function invoiceExpressUpdateDo() {
  2088. Doo::loadModel ( 'invoice' );
  2089. $invoice = new invoice ();
  2090. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2091. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2092. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2093. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2094. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2095. $iid = $invoice->authcode ( $iid );
  2096. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2097. die ( 'illegal request' );
  2098. $item = array (
  2099. 'iid' => $iid,
  2100. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2101. 'expressCompany' => $expressCompany,
  2102. 'expressNumber' => $expressNumber,
  2103. 'actualItems' => $actualItems,
  2104. 'poster' => $this->staff [0] ['username']
  2105. );
  2106. $invoice->setInvoiceByCondition ( $item );
  2107. return $action;
  2108. }
  2109. /**
  2110. * 可退票管理
  2111. */
  2112. function invoiceUntreadIsAchieve() {
  2113. Doo::loadModel ( 'invoice' );
  2114. $invoice = new invoice ();
  2115. Doo::loadClass ( 'XDeode' );
  2116. $XDeode = new XDeode ( 5 );
  2117. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2118. $page_size = 18;
  2119. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2120. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2121. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2122. $dateArr = explode ( ':', $date );
  2123. $D1 = '';
  2124. $D2 = '';
  2125. if (! empty ( $date )) {
  2126. $D1 = $dateArr [0];
  2127. $D2 = $dateArr [1];
  2128. }
  2129. $con = '';
  2130. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2131. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2132. // if ($date == 'MONTHO')
  2133. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2134. // elseif ($date == 'MONTHT')
  2135. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2136. // elseif ($date == 'MONTHY')
  2137. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2138. if (! empty ( $MebSea )) {
  2139. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2140. }
  2141. $pageinfo ['page'] = array (
  2142. 'previous' => ''
  2143. );
  2144. // printStatus=1 and
  2145. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2146. $action = "invoiceUntreadIsAchieve";
  2147. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2148. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2149. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2150. // print_r($list);
  2151. $this->data ['MebSeaEn'] = $MebSea;
  2152. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2153. $this->data ['get'] = $get;
  2154. $this->data ['page'] = $pageinfo;
  2155. $this->data ['date'] = $date;
  2156. $this->data ['list'] = $list;
  2157. $this->data ['memu'] = "invoice";
  2158. $this->data ['staff'] = $this->staff;
  2159. $this->data ['receiptMemu'] = 'invoice';
  2160. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2161. }
  2162. /**
  2163. * 退票处理页面
  2164. */
  2165. function invoiceUntread() {
  2166. Doo::loadModel ( 'invoice' );
  2167. $invoice = new invoice ();
  2168. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2169. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2170. foreach ( $establishedInvoice as $key => $value ) {
  2171. // months
  2172. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2173. $nowDate = strtotime ( 'now' );
  2174. $establishedInvoice [$key] ['lossShow'] = false;
  2175. if ($lossDate < $nowDate)
  2176. $establishedInvoice [$key] ['lossShow'] = true;
  2177. }
  2178. $this->data ['untreadInvoice'] = $untreadInvoice;
  2179. $this->data ['establishedInvoice'] = $establishedInvoice;
  2180. $this->data ['memu'] = "invoice";
  2181. $this->data ['staff'] = $this->staff;
  2182. $this->data ['receiptMemu'] = 'invoiceUntread';
  2183. $this->render ( "/admin/invoiceUntread", $this->data );
  2184. }
  2185. /**
  2186. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2187. */
  2188. function invoiceUntreadEstablishedDo() {
  2189. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2190. Doo::loadModel ( 'invoice' );
  2191. $invoice = new invoice ();
  2192. Doo::loadModel ( 'invoiceOperationLog' );
  2193. $invoiceOperationLog = new invoiceOperationLog ();
  2194. Doo::loadModel ( 'invoiceReceivables' );
  2195. Doo::loadModel ( 'invoiceStatistics' );
  2196. $iid = $invoice->authcode ( $untreadIidKey );
  2197. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2198. die ( 'illegal request' );
  2199. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2200. if ($invoiceDetails ['untreadStatus'] != 1)
  2201. die ( 'illegal request' );
  2202. $item = array (
  2203. 'iid' => $iid,
  2204. // 'irid'=>'',
  2205. 'untreadStatus' => 2,
  2206. 'updateTime' => date ( "Y-m-d H:i:s" )
  2207. );
  2208. $invoice->setInvoiceByCondition ( $item );
  2209. $item = array (
  2210. 'date' => date ( "Y-m-d H:i:s" ),
  2211. 'operation' => '已确认退票',
  2212. 'status' => 6,
  2213. 'img' => $this->staff [0] ['avatar'],
  2214. 'username' => $this->staff [0] ['username'],
  2215. 'uid' => $this->staff [0] ['sid'],
  2216. 'category' => $this->staff [0] ['category'],
  2217. 'iid' => $iid
  2218. );
  2219. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2220. // 收款解绑以及入账扣除 收款扣除
  2221. if (! empty ( $invoiceDetails ['irid'] )) {
  2222. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2223. foreach ( $iridList as $value ) {
  2224. $invoiceReceivables = new invoiceReceivables ();
  2225. $irDetails = $invoiceReceivables->getOne ( array (
  2226. 'where' => " irid=" . $value . ' and bindStatus=1',
  2227. 'asArray' => TRUE
  2228. ) );
  2229. $item = array (
  2230. 'irid' => $value,
  2231. 'bindStatus' => 0,
  2232. 'untreadStatus' => 1,
  2233. 'untreadStaff' => $invoiceDetails ['userName'],
  2234. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2235. 'iid' => 0
  2236. );
  2237. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2238. if (! empty ( $irDetails )) {
  2239. // 扣除入账
  2240. $invoiceStatistics = new invoiceStatistics ();
  2241. $item = array (
  2242. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2243. 'priceClass' => 3,
  2244. 'cid' => $invoiceDetails ['cid'],
  2245. 'staff' => $invoiceDetails ['sid'],
  2246. 'accountPrice' => - $irDetails ['receivablesPrice']
  2247. );
  2248. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2249. // 扣除收款
  2250. $invoiceStatistics = new invoiceStatistics ();
  2251. $item = array (
  2252. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2253. 'priceClass' => 2,
  2254. 'cid' => $invoiceDetails ['cid'],
  2255. 'staff' => $invoiceDetails ['sid'],
  2256. 'irid' => $irDetails ['irid'],
  2257. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2258. );
  2259. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2260. }
  2261. }
  2262. }
  2263. return "/invoiceUntread";
  2264. }
  2265. /**
  2266. * 建立负票,关联原来发票
  2267. */
  2268. function invoiceLossDo() {
  2269. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2270. if (! empty ( $iidKey )) {
  2271. Doo::loadClass ( 'XDeode' );
  2272. $XDeode = new XDeode ( 5 );
  2273. Doo::loadModel ( 'invoice' );
  2274. $invoice = new invoice ();
  2275. Doo::loadModel ( 'invoiceOperationLog' );
  2276. $invoiceOperationLog = new invoiceOperationLog ();
  2277. $iidKey = $XDeode->decode ( $iidKey );
  2278. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2279. // 拷贝插入一条发票数据
  2280. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2281. // 更新负票
  2282. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2283. $invoice = new invoice ();
  2284. $item = array (
  2285. 'iid' => $iid,
  2286. 'sid' => $this->staff [0] ['sid'],
  2287. 'userName' => $this->staff [0] ['username'],
  2288. 'cid' => $this->staff [0] ['cid'],
  2289. 'categoryName' => $this->staff [0] ['category'],
  2290. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2291. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2292. 'invoiceSerial' => $invoiceSerial,
  2293. 'invoiceNo' => '',
  2294. 'printStatus' => 0,
  2295. 'untreadStatus' => 4,
  2296. // 关联发票号
  2297. 'lossIid' => $invoiceDetail ['iid']
  2298. );
  2299. $invoice->setInvoiceByCondition ( $item );
  2300. // 更新原发票
  2301. $invoice = new invoice ();
  2302. $item = array (
  2303. 'iid' => $invoiceDetail ['iid'],
  2304. 'lossIid' => $iid
  2305. );
  2306. $invoice->setInvoiceByCondition ( $item );
  2307. // 操作日志
  2308. $item = array (
  2309. 'date' => date ( "Y-m-d H:i:s" ),
  2310. 'operation' => "创建负票" . $invoiceSerial,
  2311. 'status' => 12,
  2312. 'img' => $this->staff [0] ['avatar'],
  2313. 'username' => $this->staff [0] ['username'],
  2314. 'uid' => $this->staff [0] ['sid'],
  2315. 'category' => $this->staff [0] ['category'],
  2316. 'iid' => $iid
  2317. );
  2318. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2319. // print_r($invoiceDetail);
  2320. // echo $iid;die;
  2321. }
  2322. return '/invoiceUntread';
  2323. }
  2324. function invoiceReceivables() {
  2325. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2326. Doo::loadModel ( 'L_category' );
  2327. $lCategory = new L_category ();
  2328. Doo::loadModel ( 'staff' );
  2329. $staff = new staff ();
  2330. Doo::loadModel ( 'invoiceReceivables' );
  2331. $invoiceReceivables = new invoiceReceivables ();
  2332. Doo::loadModel ( 'invoice' );
  2333. $invoice = new invoice ();
  2334. Doo::loadClass ( 'XDeode' );
  2335. $XDeode = new XDeode ( 5 );
  2336. $category = $lCategory->getCategory ();
  2337. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2338. $sql = 'bindStatus=1 and iid!=0';
  2339. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2340. // 获取未入账发票
  2341. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2342. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2343. foreach ( $invoiceUnAccount as $key => $value ) {
  2344. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2345. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2346. if (! empty ( $lastApprover )) {
  2347. $lastApproverKey = array_keys ( $lastApprover );
  2348. $lastApprover = end ( $lastApprover );
  2349. $staffDetail = $staff->getOne ( array (
  2350. 'where' => 'sid=' . end ( $lastApproverKey ),
  2351. 'asArray' => true
  2352. ) );
  2353. $lastApprover ['username'] = $staffDetail ['username'];
  2354. }
  2355. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2356. }
  2357. foreach ( $invoiceExistAccount as $key => $value ) {
  2358. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2359. if (empty ( $irList ))
  2360. $irList [0] ['sumPrice'] = 0;
  2361. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2362. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2363. $invoiceExistAccount [$key] ['balance'] = $balance;
  2364. }
  2365. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2366. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2367. $this->data ['halfList'] = $halfList;
  2368. $this->data ['halfCount'] = count ( $halfList );
  2369. // print_r($receivablesList);
  2370. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2371. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2372. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2373. $this->data ['receivablesInput'] = $receivablesInput;
  2374. $this->data ['year'] = date ( 'Y' );
  2375. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2376. $this->data ['receivablesList'] = $receivablesList;
  2377. $this->data ['staffList'] = $staffList;
  2378. $this->data ['category'] = $category;
  2379. $this->data ['memu'] = "invoice";
  2380. $this->data ['staff'] = $this->staff;
  2381. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2382. $this->render ( "/admin/invoiceReceivables", $this->data );
  2383. }
  2384. /**
  2385. * 新添加收款直接入账发票
  2386. */
  2387. function invoiceCompareClaimPrice() {
  2388. // 收款录入
  2389. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2390. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2391. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2392. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2393. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2394. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2395. Doo::loadModel ( 'invoiceReceivables' );
  2396. $invoiceReceivables = new invoiceReceivables ();
  2397. Doo::loadModel ( 'invoiceROLog' );
  2398. $invoiceROLog = new invoiceROLog ();
  2399. Doo::loadModel ( 'invoiceStatistics' );
  2400. Doo::loadModel ( 'invoice' );
  2401. $invoice = new invoice ();
  2402. Doo::loadClass ( 'XDeode' );
  2403. $XDeode = new XDeode ( 5 );
  2404. Doo::loadModel ( 'invoiceOperationLog' );
  2405. $invoiceOperationLog = new invoiceOperationLog ();
  2406. $iidKey = $XDeode->decode ( $iidKey );
  2407. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2408. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2409. die ( 'illegal request' );
  2410. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2411. // 收款录入 并绑定发票
  2412. Doo::db ()->beginTransaction ();
  2413. $bindStatus=0;
  2414. if ($receivablesPrice<=$invoiceDetail['invoicePrice'])
  2415. $bindStatus=1;
  2416. $item = array (
  2417. 'bindStatus' => $bindStatus,
  2418. 'iid' => $invoiceDetail ['iid'],
  2419. 'bindPrice'=>$invoiceDetail['invoicePrice'],
  2420. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2421. 'receivablesPrice' => $receivablesPrice,
  2422. 'receivablesMessage' => $receivablesMessage,
  2423. 'receivablesSerial' => $receivablesSerial,
  2424. 'receivablesBank' => $receivablesBank,
  2425. 'receivablesDate' => $receivablesDate,
  2426. 'inputStaff' => $this->staff [0] ['username'],
  2427. 'accountClerk' => $this->staff [0] ['username'],
  2428. 'date' => date ( "Y-m-d" ),
  2429. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2430. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2431. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2432. );
  2433. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2434. $item = array ();
  2435. // 收款操作日志
  2436. $item = array (
  2437. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2438. );
  2439. $item += array (
  2440. 'date' => date ( "Y-m-d" ),
  2441. 'status' => 1,
  2442. 'img' => $this->staff [0] ['avatar'],
  2443. 'username' => $this->staff [0] ['username'],
  2444. 'uid' => $this->staff [0] ['sid'],
  2445. 'category' => $this->staff [0] ['category'],
  2446. 'irid' => $irid
  2447. );
  2448. $invoiceROLog->setInvoiceROLog ( $item );
  2449. // 收款统计
  2450. $invoiceStatistics = new invoiceStatistics ();
  2451. $item = array (
  2452. 'date' => $receivablesDate,
  2453. 'priceClass' => 2,
  2454. 'irid' => $irid,
  2455. 'cid' => $invoiceDetail ['cid'],
  2456. 'staff' => $invoiceDetail ['sid'],
  2457. 'receivablesPrice' => $receivablesPrice
  2458. );
  2459. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2460. // 收款 入 发票
  2461. $detail = $invoiceDetail;
  2462. $iridString = "";
  2463. if (empty ( $detail ['irid'] ))
  2464. $iridString = $irid;
  2465. else
  2466. $iridString = $detail ['irid'] . ',' . $irid;
  2467. $item = array (
  2468. 'irid' => $iridString,
  2469. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2470. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2471. 'iid' => $detail ['iid']
  2472. );
  2473. $invoiceReceivables = new invoiceReceivables ();
  2474. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2475. if ($detail ['invoicePrice'] <= $sum)
  2476. $item += array (
  2477. 'untreadStatus' => 3
  2478. );
  2479. $invoice->setInvoiceByCondition ( $item );
  2480. // 操作日志
  2481. $item = array (
  2482. 'date' => date ( "Y-m-d H:i:s" ),
  2483. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2484. 'status' => 8,
  2485. 'img' => $this->staff [0] ['avatar'],
  2486. 'username' => $this->staff [0] ['username'],
  2487. 'uid' => $this->staff [0] ['sid'],
  2488. 'category' => $this->staff [0] ['category'],
  2489. 'iid' => $detail ['iid']
  2490. );
  2491. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2492. // 入账汇总
  2493. $invoiceStatistics = new invoiceStatistics ();
  2494. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2495. // $accountPrice = 0;
  2496. // foreach ( $list as $key => $value ) {
  2497. // $accountPrice += $value ['receivablesPrice'];
  2498. // }
  2499. $item = array (
  2500. 'date' => $receivablesDate,
  2501. 'priceClass' => 3,
  2502. 'cid' => $invoiceDetail ['cid'],
  2503. 'staff' => $invoiceDetail ['sid'],
  2504. 'accountPrice' => $receivablesPrice
  2505. );
  2506. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2507. Doo::db ()->commit ();
  2508. }
  2509. return '/invoiceReceivables';
  2510. }
  2511. /**
  2512. * 检索未入账发票数据 function sir() { }
  2513. */
  2514. /**
  2515. * 录入收款数据
  2516. * @return string
  2517. */
  2518. function invoiceReceivablesDo() {
  2519. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2520. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2521. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2522. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2523. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2524. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2525. Doo::loadModel ( 'invoiceReceivables' );
  2526. $invoiceReceivables = new invoiceReceivables ();
  2527. Doo::loadModel ( 'invoiceROLog' );
  2528. $invoiceROLog = new invoiceROLog ();
  2529. Doo::loadModel ( 'invoiceStatistics' );
  2530. $invoiceStatistics = new invoiceStatistics ();
  2531. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2532. $item = array (
  2533. 'receivablesPrice' => $receivablesPrice,
  2534. 'receivablesMessage' => $receivablesMessage,
  2535. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2536. 'receivablesBank' => $receivablesBank,
  2537. 'receivablesDate' => $receivablesDate,
  2538. 'inputStaff' => $this->staff [0] ['username'],
  2539. 'date' => date ( "Y-m-d" ),
  2540. 'receivablesCategory' => $receivablesCategory,
  2541. 'receivablesStaff' => $receivablesStaff
  2542. );
  2543. if ($receivablesCategory != 'PUBLIC') {
  2544. $item += array (
  2545. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2546. 'inputType' => 1
  2547. );
  2548. }
  2549. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2550. $item = array ();
  2551. // 收款操作日志
  2552. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2553. $item = array (
  2554. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2555. );
  2556. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2557. $item = array (
  2558. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2559. );
  2560. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2561. $receivablesStaff = explode ( '-', $receivablesStaff );
  2562. $item = array (
  2563. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2564. );
  2565. }
  2566. $item += array (
  2567. 'date' => date ( "Y-m-d" ),
  2568. 'status' => 1,
  2569. 'img' => $this->staff [0] ['avatar'],
  2570. 'username' => $this->staff [0] ['username'],
  2571. 'uid' => $this->staff [0] ['sid'],
  2572. 'category' => $this->staff [0] ['category'],
  2573. 'irid' => $irid
  2574. );
  2575. $invoiceROLog->setInvoiceROLog ( $item );
  2576. $item = array (
  2577. 'date' => $receivablesDate,
  2578. 'priceClass' => 2,
  2579. 'irid' => $irid,
  2580. 'receivablesPrice' => $receivablesPrice
  2581. );
  2582. if ($receivablesCategory != 'PUBLIC') {
  2583. $receivablesCategory = explode ( ":", $receivablesCategory );
  2584. $item += array (
  2585. 'cid' => $receivablesCategory [0]
  2586. );
  2587. }
  2588. if ($receivablesStaff2 != 'PUBLIC') {
  2589. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2590. $item += array (
  2591. 'staff' => $receivablesStaff [0]
  2592. );
  2593. }
  2594. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2595. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2596. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2597. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2598. if ($toparty != 0)
  2599. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2600. }
  2601. return "/invoiceReceivables";
  2602. }
  2603. /**
  2604. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2605. */
  2606. function invoiceReceivablesClaim() {
  2607. Doo::loadModel ( 'invoiceReceivables' );
  2608. $invoiceReceivables = new invoiceReceivables ();
  2609. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2610. $this->data ['receivablesList'] = $receivablesList;
  2611. $this->data ['memu'] = "invoice";
  2612. $this->data ['staff'] = $this->staff;
  2613. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2614. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2615. }
  2616. /**
  2617. * 更新收款相关数据
  2618. */
  2619. function invoiceReceivablesUpdateClaim() {
  2620. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2621. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2622. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2623. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2624. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2625. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2626. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2627. if (empty ( $claimKey ))
  2628. die ( 'illegal request' );
  2629. Doo::loadModel ( 'invoiceReceivables' );
  2630. $invoiceReceivables = new invoiceReceivables ();
  2631. Doo::loadModel ( 'invoiceROLog' );
  2632. $invoiceROLog = new invoiceROLog ();
  2633. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2634. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2635. if (empty ( $detail ))
  2636. die ( 'illegal request' );
  2637. $invoiceReceivables = new invoiceReceivables ();
  2638. $item = array (
  2639. 'irid' => $detail ['irid']
  2640. );
  2641. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2642. $item += array (
  2643. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2644. );
  2645. }
  2646. if (! empty ( $receivablesCategory ))
  2647. $item += array (
  2648. 'receivablesCategory' => $receivablesCategory
  2649. );
  2650. if (! empty ( $receivablesStaff ))
  2651. $item += array (
  2652. 'receivablesStaff' => $receivablesStaff
  2653. );
  2654. if (! empty ( $receivablesPrice ))
  2655. $item += array (
  2656. 'receivablesPrice' => $receivablesPrice
  2657. );
  2658. if (! empty ( $receivablesMessage ))
  2659. $item += array (
  2660. 'receivablesMessage' => $receivablesMessage
  2661. );
  2662. if (! empty ( $receivablesBank ))
  2663. $item += array (
  2664. 'receivablesBank' => $receivablesBank
  2665. );
  2666. if (! empty ( $receivablesDate ))
  2667. $item += array (
  2668. 'receivablesDate' => $receivablesDate
  2669. );
  2670. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2671. // 收款操作日志
  2672. $item = array ();
  2673. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2674. $item = array (
  2675. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2676. );
  2677. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2678. $item = array (
  2679. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2680. );
  2681. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2682. $receivablesStaff = explode ( '-', $receivablesStaff );
  2683. $item = array (
  2684. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2685. );
  2686. }
  2687. $item += array (
  2688. 'date' => date ( "Y-m-d" ),
  2689. 'status' => 1,
  2690. 'img' => $this->staff [0] ['avatar'],
  2691. 'username' => $this->staff [0] ['username'],
  2692. 'uid' => $this->staff [0] ['sid'],
  2693. 'category' => $this->staff [0] ['category'],
  2694. 'irid' => $detail ['irid']
  2695. );
  2696. $invoiceROLog->setInvoiceROLog ( $item );
  2697. return '/invoiceReceivablesAS';
  2698. }
  2699. function invoiceReceivablesDelete() {
  2700. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2701. if (empty ( $claimKey ))
  2702. die ( 'illegal request' );
  2703. Doo::loadModel ( 'invoiceReceivables' );
  2704. $invoiceReceivables = new invoiceReceivables ();
  2705. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  2706. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2707. if (empty ( $detail ))
  2708. die ( 'illegal request' );
  2709. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  2710. return '/invoiceReceivablesAS';
  2711. }
  2712. /**
  2713. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  2714. */
  2715. function invoiceReceivablesAscription() {
  2716. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2717. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2718. Doo::loadModel ( 'invoiceReceivables' );
  2719. $invoiceReceivables = new invoiceReceivables ();
  2720. Doo::loadModel ( 'invoiceROLog' );
  2721. $invoiceROLog = new invoiceROLog ();
  2722. Doo::loadModel ( 'invoiceStatistics' );
  2723. $invoiceStatistics = new invoiceStatistics ();
  2724. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2725. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  2726. $item = array (
  2727. 'irid' => $detail ['irid'],
  2728. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  2729. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  2730. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2731. 'recepitTitleMark' => $recepitTitleMark,
  2732. 'source' => 1
  2733. );
  2734. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2735. $item = array (
  2736. 'date' => date ( "Y-m-d" ),
  2737. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  2738. 'status' => 2,
  2739. 'img' => $this->staff [0] ['avatar'],
  2740. 'username' => $this->staff [0] ['username'],
  2741. 'uid' => $this->staff [0] ['sid'],
  2742. 'category' => $this->staff [0] ['category'],
  2743. 'irid' => $irid
  2744. );
  2745. $invoiceROLog->setInvoiceROLog ( $item );
  2746. $item = array (
  2747. 'cid' => $this->staff [0] ['cid'],
  2748. 'staff' => $this->staff [0] ['sid']
  2749. );
  2750. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  2751. }
  2752. return "/invoiceReceivablesClaim";
  2753. }
  2754. /**
  2755. */
  2756. function invoiceMyReceivables() {
  2757. Doo::loadModel ( 'invoiceReceivables' );
  2758. $invoiceReceivables = new invoiceReceivables ();
  2759. Doo::loadModel ( 'invoiceStatistics' );
  2760. $invoiceStatistics = new invoiceStatistics ();
  2761. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  2762. $year = date ( "Y" );
  2763. $tmp_date = date ( "Ym" );
  2764. $tmp_year = substr ( $tmp_date, 0, 4 );
  2765. $tmp_mon = substr ( $tmp_date, 4, 2 );
  2766. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  2767. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  2768. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  2769. $htm = $this->showCache ( $path );
  2770. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2771. $this->data ['isMonth'] = $isMonth;
  2772. $this->data ['htm'] = $htm;
  2773. $this->data ['list'] = $list;
  2774. $this->data ['memu'] = "invoice";
  2775. $this->data ['staff'] = $this->staff;
  2776. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  2777. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  2778. }
  2779. /**
  2780. * 收款绑定发票 ,一个收款只能绑定一个发票
  2781. */
  2782. function invoiceBindReceivables() {
  2783. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2784. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2785. Doo::loadModel ( 'invoice' );
  2786. $invoice = new invoice ();
  2787. Doo::loadModel ( 'invoiceReceivables' );
  2788. $invoiceReceivables = new invoiceReceivables ();
  2789. Doo::loadModel ( 'invoiceOperationLog' );
  2790. $invoiceOperationLog = new invoiceOperationLog ();
  2791. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  2792. die ( 'illegal request' );
  2793. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2794. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  2795. if (empty ( $detail ) && empty ( $detailM ))
  2796. die ( 'illegal request' );
  2797. if ($detail ['untreadStatus'] == 3)
  2798. die ( 'illegal request' );
  2799. // 修改 绑定状态改为 金额
  2800. $invoiceReceivables = new invoiceReceivables ();
  2801. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  2802. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  2803. $item = array (
  2804. 'bindPrice' => $invoicePrice
  2805. );
  2806. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  2807. $item = array (
  2808. 'bindPrice' => $invoicePrice,
  2809. 'bindStatus' => 1,
  2810. 'bindDate' => date ( "Y-m-d H:i:s" )
  2811. );
  2812. } else {
  2813. die ( 'illegal request' );
  2814. }
  2815. if ($detailM ['iid'] == 0) {
  2816. $item += array (
  2817. 'iid' => $detail ['iid']
  2818. );
  2819. } else {
  2820. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  2821. array_push ( $iidExtend, $detail ['iid'] );
  2822. $item += array (
  2823. 'iidExtend' => implode ( ',', $iidExtend )
  2824. );
  2825. }
  2826. $item += array (
  2827. 'irid' => $detailM ['irid'],
  2828. 'accountClerk' => $this->staff [0] ['username']
  2829. );
  2830. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2831. $iridString = "";
  2832. if (empty ( $detail ['irid'] ))
  2833. $iridString = $detailM ['irid'];
  2834. else
  2835. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  2836. $item = array (
  2837. 'iid' => $detail ['iid'],
  2838. 'irid' => $iridString
  2839. );
  2840. $invoiceReceivables = new invoiceReceivables ();
  2841. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2842. if ($detail ['invoicePrice'] <= $sum)
  2843. $item += array (
  2844. 'untreadStatus' => 3
  2845. );
  2846. // print_r($item);
  2847. // echo $sum;die;
  2848. $invoice->setInvoiceByCondition ( $item );
  2849. // 操作日志
  2850. $item = array (
  2851. 'date' => date ( "Y-m-d H:i:s" ),
  2852. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  2853. 'status' => 8,
  2854. 'img' => $this->staff [0] ['avatar'],
  2855. 'username' => $this->staff [0] ['username'],
  2856. 'uid' => $this->staff [0] ['sid'],
  2857. 'category' => $this->staff [0] ['category'],
  2858. 'iid' => $detail ['iid']
  2859. );
  2860. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2861. Doo::loadModel ( 'invoiceStatistics' );
  2862. $invoiceStatistics = new invoiceStatistics ();
  2863. $item = array (
  2864. 'date' => $detailM ['receivablesDate'],
  2865. 'priceClass' => 3,
  2866. 'cid' => $detail ['cid'],
  2867. 'staff' => $detail ['sid'],
  2868. 'accountPrice' => $detailM ['receivablesPrice']
  2869. );
  2870. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2871. return "/invoiceReceivables";
  2872. }
  2873. /**
  2874. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  2875. */
  2876. function invoiceAggregate() {
  2877. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2878. Doo::loadModel ( 'invoiceStatistics' );
  2879. $invoiceStatistics = new invoiceStatistics ();
  2880. Doo::loadModel ( 'L_category' );
  2881. $Lcategory = new L_category ();
  2882. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  2883. $LcategoryList = $Lcategory->getCategory ();
  2884. // print_r($isList);
  2885. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  2886. foreach ( $LcategoryList as $key => $value ) {
  2887. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  2888. $month = 1;
  2889. $invoicePriceYear = 0;
  2890. $receivablesPriceYear = 0;
  2891. $accountPriceYear = 0;
  2892. for(; $month <= 12; $month ++) {
  2893. $flag = true;
  2894. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  2895. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  2896. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  2897. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  2898. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  2899. ';
  2900. $invoicePriceYear += $v ['invoicePrice'];
  2901. $receivablesPriceYear += $v ['receivablesPrice'];
  2902. $accountPriceYear += $v ['accountPrice'];
  2903. $flag = false;
  2904. break;
  2905. }
  2906. }
  2907. if ($flag)
  2908. $html .= '<td class="taR"></td>
  2909. <td class="taR"></td>
  2910. <td class="taR"><b></b></td>
  2911. ';
  2912. }
  2913. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2914. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2915. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2916. ';
  2917. $html .= '</tr>';
  2918. }
  2919. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  2920. $invoicePriceYear = 0;
  2921. $receivablesPriceYear = 0;
  2922. $accountPriceYear = 0;
  2923. for($month = 1; $month <= 12; $month ++) {
  2924. $flag = true;
  2925. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  2926. if ($month == $v ['month']) {
  2927. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  2928. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  2929. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  2930. ';
  2931. $invoicePriceYear += $v ['invoicePrice'];
  2932. $receivablesPriceYear += $v ['receivablesPrice'];
  2933. $accountPriceYear += $v ['accountPrice'];
  2934. $flag = false;
  2935. break;
  2936. }
  2937. }
  2938. if ($flag) {
  2939. $html .= '<td class="taR"></td>
  2940. <td class="taR"></td>
  2941. <td class="taR"><b></b></td>
  2942. ';
  2943. }
  2944. }
  2945. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2946. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2947. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2948. ';
  2949. $html .= '</tr>';
  2950. // print_r($isList);
  2951. $this->data ['html'] = $html;
  2952. $this->data ['LcategoryList'] = $LcategoryList;
  2953. $this->data ['isList'] = $isList;
  2954. $this->data ['year'] = $year;
  2955. $this->data ['memu'] = "invoice";
  2956. $this->data ['staff'] = $this->staff;
  2957. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2958. $this->render ( "/admin/invoiceAggregate", $this->data );
  2959. }
  2960. function invoiceAggregateStaff() {
  2961. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2962. Doo::loadModel ( 'invoiceStatistics' );
  2963. $invoiceStatistics = new invoiceStatistics ();
  2964. Doo::loadModel ( 'L_category' );
  2965. $Lcategory = new L_category ();
  2966. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  2967. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  2968. $cStaff = $Lcategory->getCategoryStaff ();
  2969. $html = '';
  2970. foreach ( $cStaff as $key => $value ) {
  2971. $categoryFir = true;
  2972. foreach ( $value ['staff'] as $k => $v ) {
  2973. if ($categoryFir) {
  2974. $width = count ( $value ['staff'] ) + 1;
  2975. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  2976. $categoryFir = false;
  2977. } else
  2978. $html .= '<tr>';
  2979. $html .= '<th>' . $v ['username'] . '</th>';
  2980. $invoicePriceStaffYear = 0;
  2981. $receivablesPriceStaffYear = 0;
  2982. $accountPriceStaffYear = 0;
  2983. for($month = 1; $month <= 12; $month ++) {
  2984. $flag = true;
  2985. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  2986. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  2987. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  2988. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  2989. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  2990. ';
  2991. $invoicePriceStaffYear += $slv ['invoicePrice'];
  2992. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  2993. $accountPriceStaffYear += $slv ['accountPrice'];
  2994. $flag = false;
  2995. break;
  2996. }
  2997. }
  2998. if ($flag)
  2999. $html .= '<td class="taR"></td>
  3000. <td class="taR"></td>
  3001. <td class="taR"><b></b></td>
  3002. ';
  3003. }
  3004. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3005. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3006. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3007. ';
  3008. }
  3009. $html .= '</tr>';
  3010. // 小计
  3011. if (! empty ( $value ['staff'] )) {
  3012. $html .= '<tr><th class="taR">小计</th>';
  3013. $invoicePriceStaffYear = 0;
  3014. $receivablesPriceStaffYear = 0;
  3015. $accountPriceStaffYear = 0;
  3016. for($month = 1; $month <= 12; $month ++) {
  3017. $flag = true;
  3018. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3019. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3020. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3021. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3022. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3023. ';
  3024. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3025. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3026. $accountPriceStaffYear += $slv ['accountPrice'];
  3027. $flag = false;
  3028. break;
  3029. }
  3030. }
  3031. if ($flag)
  3032. $html .= '<td class="taR"></td>
  3033. <td class="taR"></td>
  3034. <td class="taR"><b></b></td>
  3035. ';
  3036. }
  3037. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3038. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3039. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3040. ';
  3041. $html .= '</tr>';
  3042. }
  3043. }
  3044. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3045. $invoicePriceYear = 0;
  3046. $receivablesPriceYear = 0;
  3047. $accountPriceYear = 0;
  3048. for($month = 1; $month <= 12; $month ++) {
  3049. $flag = true;
  3050. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3051. if ($month == $v ['month']) {
  3052. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3053. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3054. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3055. ';
  3056. $invoicePriceYear += $v ['invoicePrice'];
  3057. $receivablesPriceYear += $v ['receivablesPrice'];
  3058. $accountPriceYear += $v ['accountPrice'];
  3059. $flag = false;
  3060. break;
  3061. }
  3062. }
  3063. if ($flag)
  3064. $html .= '<td class="taR"></td>
  3065. <td class="taR"></td>
  3066. <td class="taR"><b></b></td>
  3067. ';
  3068. }
  3069. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3070. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3071. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3072. ';
  3073. $html .= '</tr>';
  3074. $this->data ['html'] = $html;
  3075. $this->data ['isList'] = $toteList;
  3076. $this->data ['year'] = $year;
  3077. $this->data ['memu'] = "invoice";
  3078. $this->data ['staff'] = $this->staff;
  3079. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3080. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3081. }
  3082. function invoiceAggregateCategory() {
  3083. Doo::loadClass ( 'XDeode' );
  3084. $XDeode = new XDeode ( 5 );
  3085. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3086. $cid = $XDeode->decode ( $cid );
  3087. if (! is_numeric ( $cid ))
  3088. die ( 'illegal request' );
  3089. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3090. Doo::loadModel ( 'invoiceStatistics' );
  3091. $invoiceStatistics = new invoiceStatistics ();
  3092. Doo::loadModel ( 'staff' );
  3093. $staff = new staff ();
  3094. $list = $staff->getStaffByCid ( $cid );
  3095. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3096. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3097. if (empty ( $list ))
  3098. die ( '该办事处没有成员' );
  3099. $htmlA = $htmlB = $htmlC = $html = '';
  3100. foreach ( $list as $key => $value ) {
  3101. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3102. $htmlB = '<tr><th class="taC">收款</th>';
  3103. $htmlC = '<tr><th class="taC">入账</th>';
  3104. $invoicePriceStaffYear = 0;
  3105. $receivablesPriceStaffYear = 0;
  3106. $accountPriceStaffYear = 0;
  3107. for($month = 1; $month <= 12; $month ++) {
  3108. $flag = true;
  3109. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3110. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3111. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3112. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3113. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3114. $invoicePriceStaffYear += $v ['invoicePrice'];
  3115. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3116. $accountPriceStaffYear += $v ['accountPrice'];
  3117. $flag = false;
  3118. break;
  3119. }
  3120. }
  3121. if ($flag) {
  3122. $htmlA .= '<td class="taR">-</td>';
  3123. $htmlB .= '<td class="taR">-</td>';
  3124. $htmlC .= '<td class="taR"><b>-</b></td>';
  3125. }
  3126. }
  3127. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3128. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3129. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3130. $htmlA .= '</tr>';
  3131. $htmlB .= '</tr>';
  3132. $htmlC .= '</tr>';
  3133. $html .= $htmlA . $htmlB . $htmlC;
  3134. }
  3135. $htmlA = $htmlB = $htmlC = "";
  3136. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3137. $htmlB = '<tr><th class="taC">收款</th>';
  3138. $htmlC = '<tr><th class="taC">入账</th>';
  3139. $invoicePriceStaffYear = 0;
  3140. $receivablesPriceStaffYear = 0;
  3141. $accountPriceStaffYear = 0;
  3142. for($month = 1; $month <= 12; $month ++) {
  3143. $flag = true;
  3144. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3145. if ($month == $v ['month']) {
  3146. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3147. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3148. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3149. $invoicePriceStaffYear += $v ['invoicePrice'];
  3150. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3151. $accountPriceStaffYear += $v ['accountPrice'];
  3152. $flag = false;
  3153. break;
  3154. }
  3155. }
  3156. if ($flag) {
  3157. $htmlA .= '<td class="taR">-</td>';
  3158. $htmlB .= '<td class="taR">-</td>';
  3159. $htmlC .= '<td class="taR"><b>-</b></td>';
  3160. }
  3161. }
  3162. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3163. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3164. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3165. $htmlA .= '</tr>';
  3166. $htmlB .= '</tr>';
  3167. $htmlC .= '</tr>';
  3168. $html .= $htmlA . $htmlB . $htmlC;
  3169. $this->data ['html'] = $html;
  3170. $this->data ['cidKey'] = $cidKey;
  3171. $this->data ['slist'] = $list;
  3172. $this->data ['isList'] = $toteList;
  3173. $this->data ['year'] = $year;
  3174. $this->data ['memu'] = "invoice";
  3175. $this->data ['staff'] = $this->staff;
  3176. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3177. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3178. }
  3179. function invoiceAchieve() {
  3180. Doo::loadModel ( 'invoice' );
  3181. $invoice = new invoice ();
  3182. Doo::loadClass ( 'XDeode' );
  3183. $XDeode = new XDeode ( 5 );
  3184. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3185. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3186. $page_size = 18;
  3187. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3188. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3189. $get = "/" . $date;
  3190. $con = '';
  3191. if ($date == 'MONTHO')
  3192. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3193. elseif ($date == 'MONTHT')
  3194. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3195. elseif ($date == 'MONTHY')
  3196. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3197. if (! empty ( $MebSea )) {
  3198. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3199. $get .= "/" . $MebSea;
  3200. }
  3201. $pageinfo ['page'] = array (
  3202. 'previous' => ''
  3203. );
  3204. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  3205. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  3206. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3207. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3208. // print_r($pageinfo);
  3209. $this->data ['MebSeaEn'] = $MebSea;
  3210. $this->data ['MebSea'] = urlencode ( $MebSea );
  3211. $this->data ['get'] = $get;
  3212. $this->data ['page'] = $pageinfo;
  3213. $this->data ['list'] = $list;
  3214. $this->data ['date'] = $date;
  3215. $this->data ['memu'] = "invoice";
  3216. $this->data ['staff'] = $this->staff;
  3217. $this->data ['receiptMemu'] = 'invoice';
  3218. $this->render ( "/admin/invoiceAchieve", $this->data );
  3219. }
  3220. function invoiceMyUnAccountAchieve() {
  3221. Doo::loadModel ( 'invoice' );
  3222. $invoice = new invoice ();
  3223. Doo::loadClass ( 'XDeode' );
  3224. $XDeode = new XDeode ( 5 );
  3225. Doo::loadModel ( 'staff' );
  3226. $staff = new staff ();
  3227. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3228. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3229. $page_size = 18;
  3230. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3231. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3232. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3233. $dateArr = explode ( ':', $date );
  3234. $D1 = '';
  3235. $D2 = '';
  3236. if (! empty ( $date )) {
  3237. $D1 = $dateArr [0];
  3238. $D2 = $dateArr [1];
  3239. }
  3240. $con = '';
  3241. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3242. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3243. if (! empty ( $MebSea )) {
  3244. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3245. }
  3246. $pageinfo ['page'] = array (
  3247. 'previous' => ''
  3248. );
  3249. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  3250. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  3251. $action = "invoiceMyUnAccountAchieve";
  3252. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3253. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3254. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3255. Doo::loadModel ( 'express' );
  3256. $express = new express ();
  3257. $expressList = $express->getExpressByAll ();
  3258. $this->data ['expressList'] = $expressList;
  3259. // print_r($list);
  3260. $this->data ['MebSeaEn'] = $MebSea;
  3261. $this->data ['get'] = $get;
  3262. $this->data ['page'] = $pageinfo;
  3263. $this->data ['date'] = $date;
  3264. $this->data ['list'] = $list;
  3265. $this->data ['memu'] = "invoice";
  3266. $this->data ['staff'] = $this->staff;
  3267. $this->data ['receiptMemu'] = 'invoice';
  3268. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  3269. }
  3270. function invoiceReceivablesAchieve() {
  3271. Doo::loadModel ( 'invoiceReceivables' );
  3272. $invoiceReceivables = new invoiceReceivables ();
  3273. Doo::loadClass ( 'XDeode' );
  3274. $XDeode = new XDeode ( 5 );
  3275. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3276. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3277. $page_size = 1;
  3278. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3279. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3280. $get = "/" . $date;
  3281. $con = '';
  3282. if ($date == 'MONTHO')
  3283. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3284. elseif ($date == 'MONTHT')
  3285. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3286. elseif ($date == 'MONTHY')
  3287. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3288. if (! empty ( $MebSea )) {
  3289. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  3290. $get .= "/" . $MebSea;
  3291. }
  3292. $pageinfo ['page'] = array (
  3293. 'previous' => ''
  3294. );
  3295. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  3296. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  3297. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3298. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  3299. // print_r($pageinfo);
  3300. $this->data ['MebSeaEn'] = $MebSea;
  3301. $this->data ['MebSea'] = urlencode ( $MebSea );
  3302. $this->data ['get'] = $get;
  3303. $this->data ['page'] = $pageinfo;
  3304. $this->data ['list'] = $list;
  3305. $this->data ['date'] = $date;
  3306. $this->data ['memu'] = "invoice";
  3307. $this->data ['staff'] = $this->staff;
  3308. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3309. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  3310. }
  3311. /**
  3312. * 收款解绑
  3313. */
  3314. function invoiceUnBundLing() {
  3315. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  3316. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  3317. Doo::loadModel ( 'invoice' );
  3318. $invoice = new invoice ();
  3319. Doo::loadModel ( 'invoiceReceivables' );
  3320. $invoiceReceivables = new invoiceReceivables ();
  3321. Doo::loadModel ( 'invoiceOperationLog' );
  3322. $invoiceOperationLog = new invoiceOperationLog ();
  3323. Doo::loadModel ( 'invoiceROLog' );
  3324. $invoiceROLog = new invoiceROLog ();
  3325. Doo::loadModel ( 'invoiceStatistics' );
  3326. Doo::loadClass ( 'XDeode' );
  3327. $XDeode = new XDeode ( 5 );
  3328. if (empty ( $iidKey ) )
  3329. die ( 'illegal request' );
  3330. $iid = $XDeode->decode ( $iidKey );
  3331. $irid = $invoice->authcode ( $unBundKey );
  3332. if ((! empty ( $irid ) && ! is_numeric ( $irid ))|| (! empty ( $iid ) && ! is_numeric ( $iid )))
  3333. die ( 'illegal request' );
  3334. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3335. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  3336. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails['iid'] )&& empty ( $irDetails['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  3337. die ( 'illegal request' );
  3338. //收款
  3339. $item = array (
  3340. 'irid' => $irDetails ['irid'],
  3341. 'bindPrice'=>$irDetails['bindPrice']-$invoiceDetails['invoicePrice'],
  3342. 'bindStatus' => 0
  3343. );
  3344. if ($irDetails['iid']==$iid)
  3345. $item += array (
  3346. 'iid' => 0
  3347. );
  3348. else{
  3349. $iidExtend=explode(',', $irDetails['iidExtend']);
  3350. foreach ($iidExtend as $key=>$value){
  3351. if ($value==$iid)
  3352. unset($iidExtend[$key]);
  3353. }
  3354. $iidExtend=implode(',', $iidExtend);
  3355. $item += array (
  3356. 'iidExtend' => $iidExtend
  3357. );
  3358. }
  3359. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3360. // 收款操作日志
  3361. $item = array (
  3362. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  3363. 'date' => date ( "Y-m-d" ),
  3364. 'status' => 3,
  3365. 'img' => $this->staff [0] ['avatar'],
  3366. 'username' => $this->staff [0] ['username'],
  3367. 'uid' => $this->staff [0] ['sid'],
  3368. 'category' => $this->staff [0] ['category'],
  3369. 'irid' => $irid
  3370. );
  3371. $invoiceROLog->setInvoiceROLog ( $item );
  3372. // 扣除入账统计金额
  3373. $invoiceStatistics = new invoiceStatistics ();
  3374. $item = array (
  3375. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3376. 'priceClass' => 3,
  3377. 'cid' => $invoiceDetails ['cid'],
  3378. 'staff' => $invoiceDetails ['sid'],
  3379. 'accountPrice' => - $irDetails ['receivablesPrice']
  3380. );
  3381. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3382. // 扣除收款统计金额
  3383. $invoiceStatistics = new invoiceStatistics ();
  3384. $item = array (
  3385. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3386. 'priceClass' => 2,
  3387. 'cid' => $invoiceDetails ['cid'],
  3388. 'staff' => $invoiceDetails ['sid'],
  3389. 'irid' => $irDetails ['irid'],
  3390. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  3391. );
  3392. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3393. // 发票解绑去收款ID
  3394. $iridString = $invoiceDetails ['irid'];
  3395. if (! empty ( $invoiceDetails ['irid'] )) {
  3396. $list = explode ( ',', $invoiceDetails ['irid'] );
  3397. foreach ( $list as $key => $value ) {
  3398. if ($value == $irDetails ['irid']) {
  3399. unset ( $list [$key] );
  3400. break;
  3401. }
  3402. }
  3403. $iridString = implode ( ",", $list );
  3404. }
  3405. $item = array (
  3406. 'iid' => $invoiceDetails ['iid'],
  3407. 'irid' => $iridString,
  3408. 'updateTime' => date ( "Y-m-d H:i:s" )
  3409. );
  3410. if ($invoiceDetails ['untreadStatus'] == 3)
  3411. $item += array (
  3412. 'untreadStatus' => 0
  3413. );
  3414. $invoice->setInvoiceByCondition ( $item );
  3415. $item = array (
  3416. 'date' => date ( "Y-m-d H:i:s" ),
  3417. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  3418. 'status' => 11,
  3419. 'img' => $this->staff [0] ['avatar'],
  3420. 'username' => $this->staff [0] ['username'],
  3421. 'uid' => $this->staff [0] ['sid'],
  3422. 'category' => $this->staff [0] ['category'],
  3423. 'iid' => $invoiceDetails ['iid']
  3424. );
  3425. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3426. return "/invoiceReceivablesAS";
  3427. }
  3428. /**
  3429. * 或者该收款下的所以发票
  3430. */
  3431. function ajaxGetInvoiceReceivablesByInvoice() {
  3432. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  3433. Doo::loadModel ( 'invoice' );
  3434. $invoice = new invoice ();
  3435. Doo::loadModel ( 'invoiceReceivables' );
  3436. $invoiceReceivables = new invoiceReceivables ();
  3437. $irid = $invoice->authcode ( $irid );
  3438. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  3439. die ( 'illegal request' );
  3440. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3441. $iidString = $irDetails ['iid'];
  3442. $iidExtend=array_filter(explode(',', $irDetails ['iidExtend']));
  3443. if (! empty ( $irDetails ['iidExtend'] ))
  3444. $iidString .= ',' . implode(',', $iidExtend) ;
  3445. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  3446. $html = "";
  3447. foreach ( $invoiceList as $key => $value ) {
  3448. $title=$value['invoiceTitle'];
  3449. if (!empty($value['invoiceCompany']))
  3450. $title=$value['invoiceCompany'];
  3451. $html .= '<tr><td>'.$value['invoiceSerial'].'</td><td>¥'.$value['invoicePrice'].'</td><td>'.$title.'</td><td>'.$value['invoiceElement'].'</td><td><input type="radio" name="iidKey" value="'.$value['iidKey'].'"></td></tr>';
  3452. }
  3453. echo json_encode ( array (
  3454. 'status' => 1,
  3455. 'html' => $html
  3456. ) );
  3457. }
  3458. /**
  3459. * 发票管理
  3460. */
  3461. function invoiceAS() {
  3462. Doo::loadModel ( 'invoice' );
  3463. $invoice = new invoice ();
  3464. Doo::loadModel ( 'invoiceReceivables' );
  3465. $invoiceReceivables = new invoiceReceivables ();
  3466. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3467. $page_size = 18;
  3468. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3469. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3470. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3471. $dateArr = explode ( ':', $date );
  3472. $D1 = '';
  3473. $D2 = '';
  3474. if (! empty ( $date )) {
  3475. $D1 = $dateArr [0] . " 00:00:00 ";
  3476. if (isset ( $dateArr [1] ))
  3477. $D2 = $dateArr [1] . " 23:59:59 ";
  3478. else
  3479. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3480. // $D2 = $dateArr [1];
  3481. }
  3482. $con = ' status=2 ';
  3483. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3484. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3485. if ($status == 'UNRECORD')
  3486. $con .= ' and printStatus=1 and untreadStatus=0';
  3487. elseif ($status == 'RECORD')
  3488. $con .= ' and printStatus=1 and untreadStatus=3';
  3489. elseif ($status == 'BOUNCED')
  3490. $con .= ' and untreadStatus=2';
  3491. elseif ($status == 'PARTRECORD')
  3492. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3493. elseif ($status == 'All') {
  3494. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3495. }
  3496. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3497. if (! empty ( $MebSea )) {
  3498. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3499. }
  3500. $pageinfo ['page'] = array (
  3501. 'previous' => ''
  3502. );
  3503. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  3504. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3505. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3506. // foreach ($list as $key=>$value){
  3507. // $list[$key]['rpSum']=0;
  3508. // if (!empty($value['irid']))
  3509. // $list[$key]['rpSum']=$invoiceReceivables->getSumOfReceivablesPrice($value['irid']);
  3510. // }
  3511. $this->data ['MebSeaEn'] = $MebSea;
  3512. $this->data ['MebSea'] = urlencode ( $MebSea );
  3513. $this->data ['date'] = $date;
  3514. $this->data ['page'] = $pageinfo;
  3515. $this->data ['get'] = $get;
  3516. $this->data ['list'] = $list;
  3517. $this->data ['status'] = $status;
  3518. $this->data ['memu'] = "invoice";
  3519. $this->data ['staff'] = $this->staff;
  3520. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3521. $this->render ( "/admin/invoiceAS", $this->data );
  3522. }
  3523. /**
  3524. * 收款管理
  3525. */
  3526. function invoiceReceivablesAS() {
  3527. Doo::loadModel ( 'invoiceReceivables' );
  3528. $invoiceReceivables = new invoiceReceivables ();
  3529. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3530. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3531. $page_size = 10;
  3532. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3533. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3534. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3535. $dateArr = explode ( ':', $date );
  3536. $D1 = '';
  3537. $D2 = '';
  3538. if (! empty ( $date )) {
  3539. $D1 = $dateArr [0]; // ." 00:00:00 ";
  3540. if (isset ( $dateArr [1] ))
  3541. $D2 = $dateArr [1]; // ." 23:59:59 ";
  3542. else
  3543. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  3544. }
  3545. $descField = 'a.receivablesDate';
  3546. if ($timeType == 'CREATE')
  3547. $descField = 'a.date';
  3548. $con = '1';
  3549. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3550. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3551. // echo $con;
  3552. if ($status == 'Unclaimed')
  3553. $con .= ' and a.bindStatus=0';
  3554. elseif ($status == 'Credited')
  3555. $con .= ' and a.bindStatus=1';
  3556. elseif ($status == 'Claim')
  3557. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3558. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3559. if (! empty ( $MebSea )) {
  3560. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3561. }
  3562. $pageinfo ['page'] = array (
  3563. 'previous' => ''
  3564. );
  3565. $sql = 'select count(*) as count
  3566. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3567. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3568. where ' . $con . ' group by a.irid
  3569. ';
  3570. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  3571. // print_r($pageinfo);
  3572. // $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  3573. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3574. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  3575. // print_r($list);
  3576. $this->data ['timeType'] = $timeType;
  3577. $this->data ['MebSeaEn'] = $MebSea;
  3578. $this->data ['MebSea'] = urlencode ( $MebSea );
  3579. $this->data ['date'] = $date;
  3580. $this->data ['page'] = $pageinfo;
  3581. $this->data ['get'] = $get;
  3582. $this->data ['list'] = $list;
  3583. $this->data ['status'] = $status;
  3584. $this->data ['memu'] = "invoice";
  3585. $this->data ['staff'] = $this->staff;
  3586. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3587. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  3588. }
  3589. function invoiceApprovalAchieve() {
  3590. Doo::loadModel ( 'invoice' );
  3591. $invoice = new invoice ();
  3592. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3593. $page_size = 12;
  3594. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3595. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3596. $get = "/" . $date;
  3597. $con = '';
  3598. if ($date == 'MONTHO')
  3599. $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3600. elseif ($date == 'MONTHT')
  3601. $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3602. elseif ($date == 'MONTHY')
  3603. $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3604. if (! empty ( $MebSea )) {
  3605. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3606. $get .= "/" . $MebSea;
  3607. }
  3608. $pageinfo ['page'] = array (
  3609. 'previous' => ''
  3610. );
  3611. $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  3612. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  3613. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3614. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  3615. // print_r($list);
  3616. $this->data ['MebSeaEn'] = $MebSea;
  3617. $this->data ['MebSea'] = urlencode ( $MebSea );
  3618. $this->data ['get'] = $get;
  3619. $this->data ['page'] = $pageinfo;
  3620. $this->data ['list'] = $list;
  3621. $this->data ['date'] = $date;
  3622. $this->data ['memu'] = "invoice";
  3623. $this->data ['staff'] = $this->staff;
  3624. $this->data ['receiptMemu'] = 'invoiceApproval';
  3625. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  3626. }
  3627. function invoiceTAchieve() {
  3628. Doo::loadModel ( 'invoice' );
  3629. $invoice = new invoice ();
  3630. Doo::loadClass ( 'XDeode' );
  3631. $XDeode = new XDeode ( 5 );
  3632. Doo::loadModel ( 'staff' );
  3633. $staff = new staff ();
  3634. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3635. $page_size = 12;
  3636. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3637. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3638. $get = "/" . $date;
  3639. $con = '';
  3640. if ($date == 'MONTHO')
  3641. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3642. elseif ($date == 'MONTHT')
  3643. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3644. elseif ($date == 'MONTHY')
  3645. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3646. if (! empty ( $MebSea )) {
  3647. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3648. $get .= "/" . $MebSea;
  3649. }
  3650. $pageinfo ['page'] = array (
  3651. 'previous' => ''
  3652. );
  3653. $sql = "";
  3654. $action = "";
  3655. if ($this->ACTION == 'invoicePrintAchieve') {
  3656. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  3657. $action = "invoicePrintAchieve";
  3658. } elseif ($this->ACTION == 'invoicePostAchieve') {
  3659. // and untreadStatus=0
  3660. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  3661. $action = "invoicePostAchieve";
  3662. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  3663. $sql = " untreadStatus=2 and status=2 " . $con;
  3664. $action = "invoiceUntreadAchieve";
  3665. }
  3666. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3667. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3668. $this->data ['MebSeaEn'] = $MebSea;
  3669. $this->data ['MebSea'] = urlencode ( $MebSea );
  3670. $this->data ['get'] = $get;
  3671. $this->data ['page'] = $pageinfo;
  3672. $this->data ['date'] = $date;
  3673. $this->data ['memu'] = "invoice";
  3674. $this->data ['staff'] = $this->staff;
  3675. if ($this->ACTION == 'invoicePrintAchieve') {
  3676. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc',5 );
  3677. $this->data ['receiptMemu'] = 'invoicePrint';
  3678. $this->data ['list'] = $list;
  3679. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  3680. } elseif ($this->ACTION == 'invoicePostAchieve') {
  3681. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3682. Doo::loadModel ( 'express' );
  3683. $express = new express ();
  3684. $expressList = $express->getExpressByAll ();
  3685. $this->data ['expressList'] = $expressList;
  3686. $this->data ['receiptMemu'] = 'invoicePost';
  3687. $this->data ['list'] = $list;
  3688. $this->render ( "/admin/invoicePostAchieve", $this->data );
  3689. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  3690. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3691. $this->data ['receiptMemu'] = 'invoiceUntread';
  3692. $this->data ['list'] = $list;
  3693. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  3694. }
  3695. }
  3696. /**
  3697. *
  3698. * @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 ) ); }
  3699. */
  3700. /**
  3701. * 获取一条收款信息
  3702. */
  3703. function ajaxGetInvoiceReceivables() {
  3704. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3705. Doo::loadModel ( 'invoiceReceivables' );
  3706. $invoiceReceivables = new invoiceReceivables ();
  3707. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3708. echo json_encode ( array (
  3709. 'status' => 1,
  3710. 'detail' => $detail
  3711. ) );
  3712. }
  3713. /**
  3714. * 异步获取办事处用户
  3715. */
  3716. function ajaxGetStaffByCategory() {
  3717. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  3718. Doo::loadModel ( 'staff' );
  3719. $staff = new staff ();
  3720. if ($cid == "PUBLIC") {
  3721. echo json_encode ( array (
  3722. 'status' => 1,
  3723. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  3724. ) );
  3725. die ();
  3726. }
  3727. if (! is_numeric ( $cid )) {
  3728. echo json_encode ( array (
  3729. 'status' => 0,
  3730. 'msg' => 'illegal request'
  3731. ) );
  3732. die ();
  3733. }
  3734. $staffList = $staff->getStaffByCid ( $cid );
  3735. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  3736. foreach ( $staffList as $key => $value ) {
  3737. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  3738. }
  3739. echo json_encode ( array (
  3740. 'status' => 1,
  3741. 'html' => $html
  3742. ) );
  3743. }
  3744. /**
  3745. * 异步获取一条发票的邮寄信息
  3746. */
  3747. function ajaxGetInvoicePostDetail() {
  3748. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3749. Doo::loadModel ( 'invoice' );
  3750. $invoice = new invoice ();
  3751. $iid = $invoice->authcode ( $iid );
  3752. Doo::loadModel ( 'express' );
  3753. $express = new express ();
  3754. $expressList = $express->getExpressByAll ();
  3755. if (! is_numeric ( $iid )) {
  3756. echo json_encode ( array (
  3757. 'status' => 0,
  3758. 'msg' => 'illegal request'
  3759. ) );
  3760. die ();
  3761. }
  3762. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  3763. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  3764. $html = "";
  3765. foreach ( $expressList as $key => $value ) {
  3766. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  3767. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  3768. else
  3769. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  3770. }
  3771. $invoiceDetail ['eaHtml'] = $html;
  3772. echo json_encode ( array (
  3773. 'status' => 1,
  3774. 'invoiceDetail' => $invoiceDetail
  3775. ) );
  3776. }
  3777. /**
  3778. *
  3779. * @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 ) ); }
  3780. */
  3781. /**
  3782. *
  3783. * @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 ) ); }
  3784. */
  3785. /**
  3786. * 我的收款中 选择哪个发票入账,进行金额判断
  3787. */
  3788. function ajaxCompareInvoicePrice() {
  3789. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3790. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3791. Doo::loadModel ( 'invoice' );
  3792. $invoice = new invoice ();
  3793. Doo::loadModel ( 'invoiceReceivables' );
  3794. $invoiceReceivables = new invoiceReceivables ();
  3795. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3796. $keyList = explode ( ';', $claimKey );
  3797. $receivablesPrice = 0;
  3798. foreach ( $keyList as $key => $value ) {
  3799. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  3800. $receivablesPrice += $detailM ['receivablesPrice'];
  3801. }
  3802. if ($receivablesPrice > $detail ['invoicePrice']) {
  3803. $price = $receivablesPrice - $detail ['invoicePrice'];
  3804. echo json_encode ( array (
  3805. 'status' => 1,
  3806. 'price' => $price
  3807. ) );
  3808. } else
  3809. echo json_encode ( array (
  3810. 'status' => 2
  3811. ) );
  3812. }
  3813. /**
  3814. * 获得打印发票
  3815. */
  3816. function ajaxGetInvoiceInfoByPrint() {
  3817. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  3818. if (empty ( $serial )) {
  3819. echo json_encode ( array (
  3820. 'status' => 2,
  3821. 'msg' => 'illegal request'
  3822. ) );
  3823. die ();
  3824. }
  3825. Doo::loadModel ( 'invoice' );
  3826. $invoice = new invoice ();
  3827. Doo::loadModel ( 'invoiceOperationLog' );
  3828. $invoiceOperationLog = new invoiceOperationLog ();
  3829. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  3830. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  3831. if (empty ( $detail ))
  3832. $html = '';
  3833. else {
  3834. $html = '
  3835. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  3836. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  3837. <div class="modal-dialog modal-lg">
  3838. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  3839. <div class="modal-body saeaList">
  3840. <table class="table table-bordered table-condensed"><tbody>
  3841. <tr>
  3842. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  3843. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  3844. </tr>
  3845. <tr>
  3846. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  3847. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  3848. </tr>
  3849. <tr>
  3850. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  3851. </td>
  3852. </tr>
  3853. <tr>
  3854. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  3855. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  3856. </tr>
  3857. <tr>
  3858. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  3859. </tr></tbody></table>';
  3860. if ($detail ['invoiceType'] == 0)
  3861. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3862. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  3863. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  3864. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  3865. </tr>';
  3866. else
  3867. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3868. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  3869. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  3870. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  3871. ';
  3872. $html .= '<tr>
  3873. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  3874. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  3875. </tr>
  3876. <tr>
  3877. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  3878. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  3879. </tr></tbody></table>';
  3880. if ($detail ['doPost'] == 1)
  3881. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  3882. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  3883. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  3884. </tr><tr>
  3885. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  3886. </tr><tr>
  3887. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  3888. </tr></tbody></table>';
  3889. if (! empty ( $invoiceOperationLogList )) {
  3890. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  3891. foreach ( $invoiceOperationLogList as $key => $value ) {
  3892. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  3893. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  3894. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  3895. if ($value ['status'] == 2) {
  3896. $html .= '<span class="colGreen">同意</span>';
  3897. } elseif ($value ['status'] == 3) {
  3898. $html .= '<span class="colOrange">退回</span>';
  3899. } elseif ($value ['status'] == 5) {
  3900. $html .= '<span class="colGreen">打印</span>';
  3901. } elseif ($value ['status'] == 4) {
  3902. $html .= '<span class="colRed">终止</span>';
  3903. }
  3904. $html .= $value ['operation'] . '</p></blockquote>';
  3905. }
  3906. }
  3907. $html .= '</td>
  3908. <td><span class="colRed">*</span>No.<input name="invoiceNo" id="invoiceNo" value="" type="text" placeholder="输入发票号" aria-required="true" aria-invalid="true" class="n-invalid">
  3909. <span class="red" id="p-msg"></span>
  3910. </td>
  3911. </tr></tbody></table>';
  3912. }
  3913. $html .= '</div><div class="modal-footer"><button type="submit" class="button btn-green" data-toggle="modal">完成打印</button><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div>
  3914. </div></div></form>
  3915. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  3916. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  3917. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  3918. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  3919. ';
  3920. }
  3921. echo json_encode ( array (
  3922. 'status' => 1,
  3923. 'html' => $html
  3924. ) );
  3925. die ();
  3926. }
  3927. /**
  3928. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  3929. */
  3930. function ajaxGetInvoiceInfoByType() {
  3931. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  3932. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  3933. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  3934. if (empty ( $serial )) {
  3935. echo json_encode ( array (
  3936. 'status' => 2,
  3937. 'msg' => 'illegal request'
  3938. ) );
  3939. die ();
  3940. }
  3941. if ($type == 'INVOICE') {
  3942. Doo::loadModel ( 'invoice' );
  3943. $invoice = new invoice ();
  3944. Doo::loadModel ( 'invoiceOperationLog' );
  3945. $invoiceOperationLog = new invoiceOperationLog ();
  3946. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  3947. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  3948. if (empty ( $detail ))
  3949. $html = '';
  3950. else {
  3951. $html = '
  3952. <div class="modal-dialog modal-lg">
  3953. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  3954. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  3955. <tr>
  3956. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  3957. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  3958. </tr>
  3959. <tr>
  3960. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  3961. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  3962. </tr>
  3963. <tr>
  3964. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  3965. </td>
  3966. </tr>
  3967. <tr>
  3968. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  3969. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  3970. </tr>
  3971. <tr>
  3972. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  3973. </tr></tbody></table>';
  3974. if ($detail ['invoiceType'] == 0)
  3975. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3976. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  3977. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  3978. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  3979. </tr>';
  3980. else
  3981. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3982. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  3983. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  3984. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  3985. ';
  3986. $html .= '<tr>
  3987. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  3988. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  3989. </tr>
  3990. <tr>
  3991. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  3992. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  3993. </tr></tbody></table>';
  3994. if ($detail ['doPost'] == 1) {
  3995. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  3996. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  3997. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  3998. </tr><tr>
  3999. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4000. </tr><tr>
  4001. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4002. </tr>
  4003. ';
  4004. if ($detail ['expressCom'] == 'SF')
  4005. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="http://www.sf-express.com/cn/sc/dynamic_function/waybill/#search/bill-number/">' . $detail ['expressNumber'] . '</a> </td></tr>';
  4006. else
  4007. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="/invoiceExpress/' . $detail ['expressCom'] . '/' . $detail ['expressNumber'] . '.html">' . $detail ['expressNumber'] . '</a> </td></tr>';
  4008. $html .= '</tbody></table>';
  4009. }
  4010. if (! empty ( $invoiceOperationLogList )) {
  4011. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4012. foreach ( $invoiceOperationLogList as $key => $value ) {
  4013. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4014. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4015. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4016. if ($value ['status'] == 2) {
  4017. $html .= '<span class="colGreen">同意</span>';
  4018. } elseif ($value ['status'] == 3) {
  4019. $html .= '<span class="colOrange">退回</span>';
  4020. } elseif ($value ['status'] == 5) {
  4021. $html .= '<span class="colGreen">打印</span>';
  4022. } elseif ($value ['status'] == 4) {
  4023. $html .= '<span class="colRed">终止</span>';
  4024. }
  4025. $html .= $value ['operation'] . '</p></blockquote>';
  4026. }
  4027. }
  4028. $html .= '</td></tr></tbody></table>';
  4029. }
  4030. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  4031. }
  4032. echo json_encode ( array (
  4033. 'status' => 1,
  4034. 'html' => $html
  4035. ) );
  4036. die ();
  4037. } elseif ($type == 'RECEIVABLES') {
  4038. Doo::loadModel ( 'invoiceReceivables' );
  4039. $invoiceReceivables = new invoiceReceivables ();
  4040. //
  4041. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  4042. if (empty ( $detail ))
  4043. $html = '';
  4044. else {
  4045. $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">
  4046. <tbody><tr>
  4047. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  4048. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  4049. </tr><tr>
  4050. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  4051. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  4052. </tr>
  4053. <tr>
  4054. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  4055. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  4056. </tr>
  4057. <tr>
  4058. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['bindDate'] . '</td>
  4059. </tr>
  4060. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  4061. }
  4062. echo json_encode ( array (
  4063. 'status' => 1,
  4064. 'html' => $html
  4065. ) );
  4066. die ();
  4067. } elseif ($type == 'IRTC') {
  4068. Doo::loadModel ( 'invoice' );
  4069. $invoice = new invoice ();
  4070. Doo::loadModel ( 'invoiceOperationLog' );
  4071. $invoiceOperationLog = new invoiceOperationLog ();
  4072. Doo::loadModel ( 'invoiceReceivables' );
  4073. $invoiceReceivables = new invoiceReceivables ();
  4074. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4075. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4076. if (empty ( $detail ))
  4077. $html = '';
  4078. else {
  4079. $receivablesPriceedHtml = '';
  4080. $receivablesPrice = $detail ['invoicePrice'];
  4081. if (! empty ( $detail ['irid'] )) {
  4082. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  4083. if (empty ( $irList ))
  4084. $irList [0] ['sumPrice'] = 0;
  4085. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  4086. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  4087. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  4088. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  4089. </tr></tbody></table>';
  4090. $receivablesPrice = $balance;
  4091. }
  4092. if ($loss)
  4093. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  4094. $html = $receivablesPriceedHtml . '
  4095. <table class="table table-bordered table-condensed"><tbody>
  4096. <tr>
  4097. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4098. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4099. </tr>
  4100. <tr>
  4101. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4102. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4103. </tr>
  4104. <tr>
  4105. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  4106. </tr>
  4107. <tr>
  4108. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4109. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4110. </tr>
  4111. <tr>
  4112. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4113. </tr></tbody></table>';
  4114. if ($detail ['invoiceType'] == 0) {
  4115. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4116. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4117. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4118. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4119. </tr>';
  4120. $receivablesMessage = $detail ['invoiceTitle'];
  4121. } else {
  4122. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4123. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4124. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4125. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4126. ';
  4127. $receivablesMessage = $detail ['invoiceCompany'];
  4128. }
  4129. $html .= '<tr>
  4130. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4131. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4132. </tr>
  4133. <tr>
  4134. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  4135. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  4136. </tr></tbody></table>';
  4137. if ($detail ['doPost'] == 1)
  4138. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4139. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4140. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4141. </tr><tr>
  4142. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4143. </tr><tr>
  4144. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4145. </tr></tbody></table>';
  4146. if (! empty ( $invoiceOperationLogList )) {
  4147. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4148. foreach ( $invoiceOperationLogList as $key => $value ) {
  4149. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4150. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4151. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4152. if ($value ['status'] == 2) {
  4153. $html .= '<span class="colGreen">同意</span>';
  4154. } elseif ($value ['status'] == 3) {
  4155. $html .= '<span class="colOrange">退回</span>';
  4156. } elseif ($value ['status'] == 5) {
  4157. $html .= '<span class="colGreen">打印</span>';
  4158. }
  4159. $html .= $value ['operation'] . '</p></blockquote>';
  4160. }
  4161. }
  4162. $html .= '</td></tr></tbody></table>';
  4163. }
  4164. }
  4165. echo json_encode ( array (
  4166. 'status' => 1,
  4167. 'html' => $html,
  4168. 'receivablesPrice' => $receivablesPrice,
  4169. 'receivablesMessage' => $receivablesMessage,
  4170. 'receivablesDate' => date ( "Y-m-d" ),
  4171. 'iidKey' => $serial
  4172. ) );
  4173. die ();
  4174. }
  4175. }
  4176. function ajaxGetInvoiceReceivablesByStaff() {
  4177. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  4178. if (empty ( $postData )) {
  4179. echo json_encode ( array (
  4180. 'status' => 2,
  4181. 'msg' => 'illegal request'
  4182. ) );
  4183. die ();
  4184. }
  4185. Doo::loadModel ( 'invoiceReceivables' );
  4186. $invoiceReceivables = new invoiceReceivables ();
  4187. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  4188. if (empty ( $detail )) {
  4189. echo json_encode ( array (
  4190. 'status' => 2,
  4191. 'msg' => 'illegal request'
  4192. ) );
  4193. die ();
  4194. }
  4195. Doo::loadModel ( 'L_category' );
  4196. $lCategory = new L_category ();
  4197. Doo::loadModel ( 'staff' );
  4198. $staff = new staff ();
  4199. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  4200. $category = $lCategory->getCategory ();
  4201. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  4202. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  4203. foreach ( $category as $key => $value ) {
  4204. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  4205. if ($value ['cid'] == $detail ['cid'])
  4206. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  4207. }
  4208. foreach ( $staffList as $key => $value ) {
  4209. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4210. if ($value ['sid'] == $detail ['sid'])
  4211. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4212. }
  4213. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  4214. echo json_encode ( array (
  4215. 'status' => 1,
  4216. 'categoryHtml' => $categoryHtml,
  4217. 'staffHtml' => $staffHtml,
  4218. 'rbankHtml' => $rbankHtml,
  4219. 'detail' => $detail
  4220. ) );
  4221. }
  4222. function ajaxGetInvoiceReceivablesByIrid() {
  4223. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  4224. if (empty ( $irid )) {
  4225. echo json_encode ( array (
  4226. 'status' => 2,
  4227. 'msg' => 'illegal request'
  4228. ) );
  4229. die ();
  4230. }
  4231. Doo::loadModel ( 'invoiceReceivables' );
  4232. $invoiceReceivables = new invoiceReceivables ();
  4233. Doo::loadModel ( 'invoice' );
  4234. $invoice = new invoice ();
  4235. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  4236. $flag = true;
  4237. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  4238. $bakDetail = array ();
  4239. if ($flag === false) {
  4240. array_push ( $bakDetail, $invoiceDetail );
  4241. $invoiceDetail = $bakDetail;
  4242. }
  4243. $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>
  4244. <tr>
  4245. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  4246. <td>' . $detail ['receivablesMessage'] . '</td>
  4247. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  4248. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  4249. <td>' . $detail ['recepitTitleMark'] . '</td>
  4250. </tr></tbody></table>';
  4251. $isInvoice = false;
  4252. $invoiceHtml = '';
  4253. if (empty ( $invoiceDetail )) {
  4254. $isInvoice = true;
  4255. } else {
  4256. $invoiceHtml = '<table class="table table-bordered table-condensed">
  4257. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  4258. foreach ( $invoiceDetail as $key => $value ) {
  4259. $invoiceHtml .= '<tr>';
  4260. if (! empty ( $value ['invoiceType'] )) {
  4261. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  4262. } else {
  4263. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  4264. }
  4265. if (! empty ( $value ['invoiceType'] )) {
  4266. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  4267. } else {
  4268. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  4269. }
  4270. $invoiceHtml .= '
  4271. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  4272. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  4273. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  4274. </tr>
  4275. ';
  4276. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  4277. if (empty ( $irList ))
  4278. $irList [0] ['sumPrice'] = 0;
  4279. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  4280. $priceString = '';
  4281. if ($balance < $detail ['receivablesPrice']) {
  4282. $priceString = '收款金额超过开票金额,';
  4283. }
  4284. if ($balance > $detail ['receivablesPrice']) {
  4285. $priceString = '收款金额低于开票金额,';
  4286. }
  4287. }
  4288. $invoiceHtml .= '
  4289. <script>
  4290. $(\'a[bind-receivables^="ir"]\').click(function() {
  4291. var data = $(this).attr("data-ikey");
  4292. $("input[name=\'invoiceKey\']").val(data);
  4293. var invoiceKey=data;
  4294. if(invoiceKey==""){
  4295. alert("入账错误,请重新刷新页面");
  4296. return false;
  4297. }
  4298. if(window.confirm("' . $priceString . '确定入账吗?")){
  4299. $("#IBR").submit();
  4300. }else{
  4301. return false;
  4302. }
  4303. });
  4304. </script>
  4305. ';
  4306. $invoiceHtml .= '</tbody></table>';
  4307. }
  4308. echo json_encode ( array (
  4309. 'status' => 1,
  4310. 'irkey' => $detail ['iridEn'],
  4311. 'receivablesHtml' => $receivablesHtml,
  4312. 'isInvoice' => $isInvoice,
  4313. 'invoiceHtml' => $invoiceHtml
  4314. ) );
  4315. }
  4316. function ajaxGetInvoiceReceivablesByTitle() {
  4317. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  4318. if (empty ( $title )) {
  4319. echo json_encode ( array (
  4320. 'status' => 2,
  4321. 'msg' => 'illegal request'
  4322. ) );
  4323. die ();
  4324. }
  4325. Doo::loadModel ( 'invoice' );
  4326. $invoice = new invoice ();
  4327. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' " );
  4328. $invoiceHtml = '';
  4329. if (! empty ( $invoiceDetail )) {
  4330. $invoiceHtml = '<table class="table table-bordered table-condensed">
  4331. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  4332. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  4333. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  4334. } else {
  4335. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  4336. }
  4337. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  4338. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  4339. } else {
  4340. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  4341. }
  4342. $invoiceHtml .= '
  4343. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  4344. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  4345. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="#">入账</a></td>
  4346. </tr>
  4347. ';
  4348. $invoiceHtml .= '</tbody></table>
  4349. <script>
  4350. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  4351. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  4352. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  4353. if(invoiceKey==""){
  4354. alert("入账错误,请重新刷新页面");
  4355. return false;
  4356. }
  4357. if(window.confirm("确定入账吗?")){
  4358. $("#IBR").submit();
  4359. }else{
  4360. return false;
  4361. }
  4362. });
  4363. </script>
  4364. ';
  4365. }
  4366. echo json_encode ( array (
  4367. 'status' => 1,
  4368. 'invoiceHtml' => $invoiceHtml
  4369. ) );
  4370. }
  4371. function ajaxInvoicePushNotice() {
  4372. Doo::loadModel ( 'invoice' );
  4373. $invoice = new invoice ();
  4374. $approval = $invoice->getOne ( array (
  4375. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  4376. 'desc' => 'iid',
  4377. 'asArray' => true
  4378. ) );
  4379. $isNotice = false;
  4380. if (! empty ( $approval ))
  4381. $isNotice = true;
  4382. $response = array (
  4383. 'error' => 0,
  4384. 'isNotice' => $isNotice
  4385. );
  4386. echo json_encode ( $response );
  4387. exit ();
  4388. }
  4389. public function ajaxCheckInvoiceNoUniqueness() {
  4390. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  4391. Doo::loadModel ( 'invoice' );
  4392. $invoice = new invoice ();
  4393. if (! empty ( $invoiceNo )) {
  4394. $info = $invoice->getOne ( array (
  4395. 'where' => "invoiceNo = '" . $invoiceNo . "'",
  4396. 'asArray' => TRUE
  4397. ) );
  4398. if (! empty ( $info )) {
  4399. echo json_encode ( array (
  4400. 'error' => '发票号已存在'
  4401. ) );
  4402. die ();
  4403. } else
  4404. echo json_encode ( array (
  4405. 'ok' => '可以使用!'
  4406. ) );
  4407. die ();
  4408. }
  4409. }
  4410. function ajaxCheckInvoicePrice() {
  4411. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  4412. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  4413. Doo::loadModel ( 'invoice' );
  4414. $invoice = new invoice ();
  4415. Doo::loadModel ( 'invoiceReceivables' );
  4416. $invoiceReceivables = new invoiceReceivables ();
  4417. Doo::loadClass ( 'XDeode' );
  4418. $XDeode = new XDeode ( 5 );
  4419. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  4420. $iidKey = $XDeode->decode ( $iidKey );
  4421. $info = $invoice->getInvoiceByIid ( $iidKey );
  4422. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  4423. if (empty ( $irList ))
  4424. $irList [0] ['sumPrice'] = 0;
  4425. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  4426. if ($balance < $receivablesPrice) {
  4427. echo json_encode ( array (
  4428. 'error' => '收款金额超过开票金额。'
  4429. ) );
  4430. die ();
  4431. }
  4432. if ($balance > $receivablesPrice) {
  4433. echo json_encode ( array (
  4434. 'error' => '收款金额低于开票金额。'
  4435. ) );
  4436. die ();
  4437. }
  4438. }
  4439. }
  4440. /**
  4441. * 旧输入导入
  4442. */
  4443. function importInvoice() {
  4444. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4445. $data ['emsg'] = "";
  4446. if ($emsg != "")
  4447. $data ['emsg'] = "请填写完整的数据";
  4448. $data ['time'] = time ();
  4449. $this->render ( "/admin/invoiceImport", $data );
  4450. }
  4451. function uploadInvoice() {
  4452. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  4453. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  4454. $file = $_FILES ['Filedata'] ['tmp_name'];
  4455. $error = false;
  4456. if (! is_uploaded_file ( $file )) {
  4457. $error = '400 Bad Request';
  4458. }
  4459. if ($error) {
  4460. header ( 'HTTP/1.0 ' . $error );
  4461. die ( 'Error ' . $error );
  4462. } else {
  4463. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  4464. $this->IoHandler = new IoHandler ();
  4465. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  4466. // $filedir=$_POST['time'];
  4467. // 调用定义物理路径
  4468. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  4469. $this->IoHandler->MakeDir ( $t );
  4470. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  4471. if ($filename != 'xlsx')
  4472. return "";
  4473. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  4474. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  4475. $upload_dir = $t . "/" . $upload_file;
  4476. $k = move_uploaded_file ( $file, $upload_dir );
  4477. if ($k) {
  4478. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  4479. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  4480. }
  4481. }
  4482. }
  4483. }
  4484. function importInvoiceDo() {
  4485. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4486. if ($path != "") {
  4487. Doo::loadModel ( 'invoice' );
  4488. Doo::loadModel ( 'staff' );
  4489. $staff = new staff ();
  4490. Doo::loadModel ( 'invoiceStatistics' );
  4491. Doo::loadModel ( 'invoiceOperationLog' );
  4492. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  4493. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  4494. // print_r ( $exlArray );
  4495. // die ();
  4496. // echo json_encode($exlArray);die;
  4497. foreach ( $exlArray as $key => $value ) {
  4498. // 开票
  4499. $invoice = new invoice ();
  4500. $invoice->invoiceNo = $value ['invoiceNo'];
  4501. $invoice->invoiceType = 0;
  4502. if ($value ['invoiceType'] == '专')
  4503. $invoice->invoiceType = 1;
  4504. $invoice->invoicePrice = $value ['invoicePrice'];
  4505. $invoice->invoiceQuantity = 1;
  4506. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  4507. $invoice->invoiceTitle = $value ['invoiceTitle'];
  4508. if ($value ['invoiceType'] == '专')
  4509. $invoice->invoiceCompany = $value ['invoiceTitle'];
  4510. $invoice->userName = $value ['userName'];
  4511. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  4512. $invoice->sid = $sDetail ['sid'];
  4513. $invoice->cid = $sDetail ['cid'];
  4514. $invoice->categoryName = $sDetail ['category'];
  4515. $invoice->invoiceElement = $value ['invoiceElement'];
  4516. $invoice->remark = $value ['remark'];
  4517. $invoice->date = $value ['date'];
  4518. $invoice->printTime = $value ['date'];
  4519. $invoice->ipSource = 1;
  4520. $invoice->printStatus = 1;
  4521. $invoice->status = 2;
  4522. $invoice->postStatus = 1;
  4523. $invoice->untreadStatus = 0;
  4524. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4525. $iid = $invoice->insert ();
  4526. // 汇总
  4527. $invoiceStatistics = new invoiceStatistics ();
  4528. //
  4529. $item = array (
  4530. 'date' => $value ['date'],
  4531. 'priceClass' => 1,
  4532. 'cid' => $sDetail ['cid'],
  4533. 'staff' => $sDetail ['sid'],
  4534. 'invoicePrice' => $value ['invoicePrice']
  4535. );
  4536. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4537. $invoiceOperationLog = new invoiceOperationLog ();
  4538. $item = array (
  4539. 'date' => date ( "Y-m-d H:i:s" ),
  4540. 'operation' => date ( "Y-m-d" ) . " 导入",
  4541. 'status' => 1,
  4542. 'img' => $sDetail ['avatar'],
  4543. 'username' => $sDetail ['username'],
  4544. 'uid' => $sDetail ['sid'],
  4545. 'category' => $sDetail ['category'],
  4546. 'iid' => $iid
  4547. );
  4548. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4549. }
  4550. return '/importInvoice?count=' . count ( $exlArray );
  4551. // return "/keyonline";
  4552. }
  4553. echo 'no file';
  4554. }
  4555. function importInvoiceReceivables() {
  4556. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4557. $data ['emsg'] = "";
  4558. if ($emsg != "")
  4559. $data ['emsg'] = "请填写完整的数据";
  4560. $data ['time'] = time ();
  4561. $this->render ( "/admin/invoiceReceivablesImport", $data );
  4562. }
  4563. // 导入入账数据
  4564. function importInvoiceReceivablesDo() {
  4565. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4566. include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4567. if ($path != "") {
  4568. Doo::loadModel ( 'invoiceReceivables' );
  4569. Doo::loadModel ( 'invoice' );
  4570. Doo::loadModel ( 'staff' );
  4571. $staff = new staff ();
  4572. Doo::loadModel ( 'invoiceStatistics' );
  4573. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  4574. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  4575. // print_r ( $exlArray );
  4576. // die ();
  4577. // echo json_encode($exlArray);die;
  4578. foreach ( $exlArray as $key => $value ) {
  4579. // 收款
  4580. $invoiceReceivables = new invoiceReceivables ();
  4581. $invoice = new invoice ();
  4582. $invoiceReceivables->bindStatus = 1;
  4583. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  4584. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  4585. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  4586. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  4587. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  4588. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  4589. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  4590. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4591. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  4592. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  4593. $invoiceReceivables->iid = $iDetail ['iid'];
  4594. $irid = $invoiceReceivables->insert ();
  4595. // 发票绑定收款
  4596. $detail = $iDetail;
  4597. $iridString = "";
  4598. if (empty ( $detail ['irid'] ))
  4599. $iridString = $irid;
  4600. else
  4601. $iridString = $detail ['irid'] . ',' . $irid;
  4602. $item = array (
  4603. 'irid' => $iridString,
  4604. 'iid' => $detail ['iid']
  4605. );
  4606. $invoice->setInvoiceByCondition ( $item );
  4607. // 汇总
  4608. $invoiceStatistics = new invoiceStatistics ();
  4609. // 扣除入账统计金额
  4610. $item = array (
  4611. 'date' => $value ['receivablesDate'],
  4612. 'priceClass' => 3,
  4613. 'cid' => $sDetail ['cid'],
  4614. 'staff' => $sDetail ['sid'],
  4615. // 'irid' => $irid,
  4616. 'accountPrice' => $value ['receivablesPrice']
  4617. );
  4618. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4619. }
  4620. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  4621. echo 'data count ' . count ( $exlArray );
  4622. die ();
  4623. // return "/keyonline";
  4624. }
  4625. echo 'no file';
  4626. }
  4627. /**
  4628. * 格式化excel文件为数组
  4629. * @param unknown_type $file_url
  4630. * @param unknown_type $mcid
  4631. */
  4632. function _format_excel_to_array($file_url = "", $sType = "") {
  4633. if (! file_exists ( $file_url )) {
  4634. return array ();
  4635. }
  4636. Doo::loadClass ( 'PHPExcel' );
  4637. $PHPExcel = new PHPExcel ();
  4638. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  4639. if (! $PHPReader->canRead ( $file_url )) {
  4640. $PHPReader = new PHPExcel_Reader_Excel5 ();
  4641. if (! $PHPReader->canRead ( $file_url )) {
  4642. echo 'no Excel';
  4643. return;
  4644. }
  4645. }
  4646. $PHPExcel = $PHPReader->load ( $file_url );
  4647. /* * 读取excel文件中的第一个工作表 */
  4648. $currentSheet = $PHPExcel->getSheet ( 0 );
  4649. /* * 取得最大的列号 */
  4650. $allColumn = $currentSheet->getHighestColumn ();
  4651. /* * 取得一共有多少行 */
  4652. $allRow = $currentSheet->getHighestRow ();
  4653. $excel_array = array ();
  4654. $conk = 2;
  4655. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  4656. $excel_column = array ();
  4657. // 后期改进
  4658. if ($allColumn == 'AM')
  4659. $allColumn = 'Z';
  4660. /* * 从第A列开始输出 */
  4661. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  4662. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  4663. if ($val instanceof PHPExcel_RichText)
  4664. $val = $val->__toString ();
  4665. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  4666. // $val = "'" . addslashes ( $val ) . "'";
  4667. if ($sType == 'invoiceReceivables') {
  4668. if ($currentColumn == 'A')
  4669. $excel_column ['invoiceNo'] = $val;
  4670. elseif ($currentColumn == 'B')
  4671. $excel_column ['receivablesPrice'] = $val;
  4672. elseif ($currentColumn == 'C') {
  4673. $excel_column ['receivablesMessage'] = $val;
  4674. } elseif ($currentColumn == 'D') {
  4675. $excel_column ['receivablesBank'] = $val;
  4676. } elseif ($currentColumn == 'E') {
  4677. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  4678. } elseif ($currentColumn == 'F') {
  4679. $excel_column ['receivablesStaff'] = $val;
  4680. } elseif ($currentColumn == 'G') {
  4681. $excel_column ['sourcePrice'] = $val;
  4682. }
  4683. } elseif ($sType == "invoiceTrain") {
  4684. if ($currentColumn == 'A')
  4685. $excel_column ['invoiceTitle'] = $val;
  4686. elseif ($currentColumn == 'B')
  4687. $excel_column ['invoiceType'] = $val;
  4688. elseif ($currentColumn == 'C') {
  4689. $excel_column ['TIN'] = $val;
  4690. } elseif ($currentColumn == 'D') {
  4691. $excel_column ['address'] = $val;
  4692. } elseif ($currentColumn == 'E') {
  4693. $excel_column ['phone'] = $val;
  4694. } elseif ($currentColumn == 'F') {
  4695. $excel_column ['bank'] = $val;
  4696. } elseif ($currentColumn == 'G') {
  4697. $excel_column ['bankAccount'] = $val;
  4698. } elseif ($currentColumn == 'H') {
  4699. $excel_column ['invoiceElement'] = $val;
  4700. } elseif ($currentColumn == 'I') {
  4701. $excel_column ['invoiceQuantity'] = $val;
  4702. } elseif ($currentColumn == 'J') {
  4703. $excel_column ['invoiceUnitPrice'] = $val;
  4704. } elseif ($currentColumn == 'K') {
  4705. $excel_column ['remark'] = $val;
  4706. } elseif ($currentColumn == 'L') {
  4707. $excel_column ['recipientsAddress'] = $val;
  4708. } elseif ($currentColumn == 'M') {
  4709. $excel_column ['recipients'] = $val;
  4710. } elseif ($currentColumn == 'N') {
  4711. $excel_column ['recipientsPhone'] = $val;
  4712. }
  4713. } else {
  4714. if ($currentColumn == 'A')
  4715. $excel_column ['invoiceNo'] = $val;
  4716. elseif ($currentColumn == 'B')
  4717. $excel_column ['invoiceType'] = $val;
  4718. elseif ($currentColumn == 'C') {
  4719. $excel_column ['invoicePrice'] = $val;
  4720. } elseif ($currentColumn == 'D') {
  4721. $excel_column ['invoiceTitle'] = $val;
  4722. } elseif ($currentColumn == 'E') {
  4723. $excel_column ['userName'] = $val;
  4724. } elseif ($currentColumn == 'F') {
  4725. $excel_column ['categoryName'] = $val;
  4726. } elseif ($currentColumn == 'G') {
  4727. $excel_column ['invoiceElement'] = $val;
  4728. } elseif ($currentColumn == 'H') {
  4729. $excel_column ['remark'] = $val;
  4730. } elseif ($currentColumn == 'I') {
  4731. $excel_column ['date'] = $this->excelTime ( $val );
  4732. }
  4733. }
  4734. }
  4735. array_push ( $excel_array, $excel_column );
  4736. }
  4737. return $excel_array;
  4738. }
  4739. function excelTime($date, $time = false) {
  4740. if (function_exists ( 'GregorianToJD' )) {
  4741. if (is_numeric ( $date )) {
  4742. $jd = GregorianToJD ( 1, 1, 1970 );
  4743. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  4744. $date = explode ( '/', $gregorian );
  4745. $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" : '');
  4746. return $date_str;
  4747. }
  4748. } else {
  4749. $date = $date > 25568 ? $date + 1 : 25569;
  4750. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  4751. $ofs = (70 * 365 + 17 + 2) * 86400;
  4752. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  4753. }
  4754. return $date;
  4755. }
  4756. /**
  4757. * 旧输入导入
  4758. */
  4759. function _GetFileEXT($filename) {
  4760. $pics = explode ( '.', $filename );
  4761. $num = count ( $pics );
  4762. return $pics [$num - 1];
  4763. }
  4764. function showCache($path = "") {
  4765. // if (file_exists ( $path )) {
  4766. // $htm = file_get_contents ( $path );
  4767. // } else {
  4768. Doo::loadModel ( 'invoiceStatistics' );
  4769. $invoiceStatistics = new invoiceStatistics ();
  4770. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  4771. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  4772. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  4773. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  4774. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  4775. /*
  4776. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  4777. */
  4778. file_put_contents ( $path, $htm, FILE_APPEND );
  4779. // }
  4780. return $htm;
  4781. }
  4782. /**
  4783. * 获取get或者POST值
  4784. *
  4785. * @param string $name 属性名称
  4786. * @return fixed 值
  4787. */
  4788. function get_args($name) {
  4789. if (isset ( $_GET [$name] )) {
  4790. if (is_array ( $_GET [$name] ))
  4791. return $_GET [$name];
  4792. else
  4793. return addslashes ( $_GET [$name] );
  4794. } elseif (isset ( $_POST [$name] )) {
  4795. if (is_array ( $_POST [$name] ))
  4796. return $_POST [$name];
  4797. else
  4798. return addslashes ( $_POST [$name] );
  4799. } else
  4800. return false;
  4801. }
  4802. function SafeFilter(&$arr) {
  4803. $ra = Array (
  4804. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  4805. '/script/',
  4806. '/javascript/',
  4807. '/vbscript/',
  4808. '/expression/',
  4809. '/applet/',
  4810. '/meta/',
  4811. '/xml/',
  4812. '/blink/',
  4813. '/link/',
  4814. '/style/',
  4815. '/embed/',
  4816. '/object/',
  4817. '/frame/',
  4818. '/layer/',
  4819. '/title/',
  4820. '/bgsound/',
  4821. '/base/',
  4822. '/onload/',
  4823. '/onunload/',
  4824. '/onchange/',
  4825. '/onsubmit/',
  4826. '/onreset/',
  4827. '/onselect/',
  4828. '/onblur/',
  4829. '/onfocus/',
  4830. '/onabort/',
  4831. '/onkeydown/',
  4832. '/onkeypress/',
  4833. '/onkeyup/',
  4834. '/onclick/',
  4835. '/ondblclick/',
  4836. '/onmousedown/',
  4837. '/onmousemove/',
  4838. '/onmouseout/',
  4839. '/onmouseover/',
  4840. '/onmouseup/',
  4841. '/onunload/'
  4842. );
  4843. if (is_array ( $arr )) {
  4844. foreach ( $arr as $key => $value ) {
  4845. if (! is_array ( $value )) {
  4846. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  4847. {
  4848. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  4849. }
  4850. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  4851. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  4852. } else {
  4853. SafeFilter ( $arr [$key] );
  4854. }
  4855. }
  4856. }
  4857. }
  4858. /**
  4859. * Escape String
  4860. *
  4861. * @access public
  4862. * @param string
  4863. * @param bool whether or not the string will be used in a LIKE condition
  4864. * @return string
  4865. */
  4866. function escape_str($str, $like = FALSE) {
  4867. if (is_array ( $str )) {
  4868. foreach ( $str as $key => $val ) {
  4869. $str [$key] = $this->escape_str ( $val, $like );
  4870. }
  4871. return $str;
  4872. }
  4873. var_dump ( Doo::db ()->getDbObject () );
  4874. die ();
  4875. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  4876. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  4877. } elseif (function_exists ( 'mysql_escape_string' )) {
  4878. $str = mysql_escape_string ( $str );
  4879. } else {
  4880. $str = addslashes ( $str );
  4881. }
  4882. // escape LIKE condition wildcards
  4883. if ($like === TRUE) {
  4884. $str = str_replace ( array (
  4885. '%',
  4886. '_'
  4887. ), array (
  4888. '\\%',
  4889. '\\_'
  4890. ), $str );
  4891. }
  4892. return $str;
  4893. }
  4894. /**
  4895. * 获得分页数据
  4896. * @param unknown_type $table
  4897. * @param unknown_type $condition
  4898. * @param unknown_type $on_page
  4899. * @param unknown_type $page_size
  4900. */
  4901. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  4902. $page_c = "";
  4903. $page ['previous'] = $this->get_previous ( $on_page );
  4904. $page ['on_page'] = $on_page;
  4905. $total_count = $this->get_table_count ( $table, $condition );
  4906. $total = intval ( $total_count / $page_size );
  4907. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  4908. $page ['total_data'] = $total_count;
  4909. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  4910. $i = 1;
  4911. $page_max = 1;
  4912. $page_width = 3;
  4913. if ($on_page >= $page_width) {
  4914. $page_max = intval ( $on_page / $page_width ) + 1;
  4915. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  4916. }
  4917. for(; $i <= $page ['total_page']; $i ++) {
  4918. if ($i == $on_page)
  4919. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  4920. else
  4921. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  4922. if ($i == ($page_width * $page_max))
  4923. break;
  4924. }
  4925. $page ['page'] = $page_c;
  4926. $page ['lower'] = (-- $on_page) * $page_size;
  4927. return $page;
  4928. }
  4929. /**
  4930. * 获取上一页
  4931. * @param unknown_type $on_page
  4932. */
  4933. function get_previous($on_page = 1) {
  4934. return $on_page != 0 ? $on_page - 1 : $on_page;
  4935. }
  4936. /**
  4937. * 获取总页数
  4938. * @param unknown_type $table
  4939. * @param unknown_type $condition
  4940. */
  4941. public function get_table_count($table = "", $condition = "") {
  4942. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  4943. $sql = "select count(*) as count from " . $table . " where " . $condition;
  4944. // echo $sql;die;
  4945. $query = Doo::db ()->query ( $sql );
  4946. $result = $query->fetch ();
  4947. return $result ['count'];
  4948. }
  4949. /**
  4950. * 获得分页数据
  4951. * @param unknown_type $table
  4952. * @param unknown_type $condition
  4953. * @param unknown_type $on_page
  4954. * @param unknown_type $page_size
  4955. */
  4956. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  4957. $page_c = "";
  4958. $page ['previous'] = $this->get_previous ( $on_page );
  4959. $page ['on_page'] = $on_page;
  4960. $total_count = $this->getTableCountBySql ( $sql );
  4961. $total = intval ( $total_count / $page_size );
  4962. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  4963. $page ['total_data'] = $total_count;
  4964. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  4965. $i = 1;
  4966. $page_max = 1;
  4967. $page_width = 3;
  4968. if ($on_page >= $page_width) {
  4969. $page_max = intval ( $on_page / $page_width ) + 1;
  4970. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  4971. }
  4972. for(; $i <= $page ['total_page']; $i ++) {
  4973. if ($i == $on_page)
  4974. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  4975. else
  4976. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  4977. if ($i == ($page_width * $page_max))
  4978. break;
  4979. }
  4980. $page ['page'] = $page_c;
  4981. $page ['lower'] = (-- $on_page) * $page_size;
  4982. return $page;
  4983. }
  4984. /**
  4985. * 获得总页数 sql
  4986. * @param string $type
  4987. * @return boolean[]
  4988. */
  4989. public function getTableCountBySql($sql = "") {
  4990. $query = Doo::db ()->query ( $sql );
  4991. $result = $query->fetch ();
  4992. return $result ['count'];
  4993. }
  4994. function isInvoiceNew($type = "GLOBAL") {
  4995. Doo::loadModel ( 'invoice' );
  4996. $invoice = new invoice ();
  4997. Doo::loadModel ( 'invoiceReceivables' );
  4998. $invoiceReceivables = new invoiceReceivables ();
  4999. Doo::loadModel ( 'staff' );
  5000. $staff = new staff ();
  5001. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  5002. // 我的发票待处理
  5003. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  5004. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  5005. 'desc' => 'iid',
  5006. 'asArray' => TRUE
  5007. ) );
  5008. // 我的收款待入账
  5009. /*
  5010. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  5011. */
  5012. // 发票审批
  5013. $approval = $invoice->getOne ( array (
  5014. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  5015. 'desc' => 'iid',
  5016. 'asArray' => true
  5017. ) );
  5018. // 发票邮寄
  5019. $post = $invoice->getOne ( array (
  5020. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  5021. 'asArray' => TRUE
  5022. ) );
  5023. // 发票打印
  5024. $print = $invoice->getOne ( array (
  5025. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  5026. 'desc' => 'iid',
  5027. 'asArray' => TRUE
  5028. ) );
  5029. // 发票退票 printStatus=1 and
  5030. $untread = $invoice->getOne ( array (
  5031. 'where' => " untreadStatus=1 and status=2 ",
  5032. 'asArray' => TRUE
  5033. ) );
  5034. $new = array (
  5035. 'GLOBAL' => FALSE,
  5036. 'pendingInvoice' => FALSE,
  5037. // 'myClaim' => FALSE,
  5038. 'approval' => FALSE,
  5039. 'post' => FALSE,
  5040. 'print' => FALSE,
  5041. 'untread' => FALSE
  5042. );
  5043. // || ! empty ( $myClaim )
  5044. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  5045. $new ['GLOBAL'] = TRUE;
  5046. if (! empty ( $pendingInvoice ))
  5047. $new ['pendingInvoice'] = TRUE;
  5048. // if (! empty ( $myClaim ))
  5049. // $new ['myClaim'] = TRUE;
  5050. if (! empty ( $approval ))
  5051. $new ['approval'] = TRUE;
  5052. if (! empty ( $post ))
  5053. $new ['post'] = TRUE;
  5054. if (! empty ( $print ))
  5055. $new ['print'] = TRUE;
  5056. if (! empty ( $untread ))
  5057. $new ['untread'] = TRUE;
  5058. return $new;
  5059. }
  5060. function setWXMsg($rid, $typeMsg = '') {
  5061. Doo::loadModel ( 'invoice' );
  5062. $invoice = new invoice ();
  5063. $invoiceDetail = $invoice->getOne ( array (
  5064. 'where' => 'iid=' . $rid,
  5065. 'asArray' => true
  5066. ) );
  5067. if (! empty ( $invoiceDetail )) {
  5068. Doo::loadModel ( 'staff' );
  5069. $staff = new staff ();
  5070. $staffmsg = $staff->getOne ( array (
  5071. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  5072. 'asArray' => TRUE
  5073. ) );
  5074. if (! empty ( $staffmsg ['wxid'] )) {
  5075. require_once (SITE_PATH . '/protected/class/client.php');
  5076. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  5077. $user = $staffmsg ['wxid'];
  5078. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  5079. if (empty ( $expCom ))
  5080. $expCom [0] = '';
  5081. $msg = "";
  5082. if (empty ( $typeMsg ))
  5083. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  5084. elseif ($typeMsg == "PRINT")
  5085. $msg = '太好了,您的发票已打印完成。';
  5086. $result = $client->SendMsg ( $user, $msg, 'text' );
  5087. }
  5088. }
  5089. }
  5090. /**
  5091. * 获取微信部门
  5092. * @param string $category
  5093. * @return number|mixed
  5094. */
  5095. function getToparty($category = '') {
  5096. $token = $this->getAccessToken (); //
  5097. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  5098. $toparty = 0;
  5099. foreach ( $result ['department'] as $key => $value ) {
  5100. if ($value ['name'] == $category)
  5101. $toparty = $value ['id'];
  5102. }
  5103. return $toparty;
  5104. }
  5105. /**
  5106. * 获得某部门下的用户
  5107. * @param string $toparty
  5108. */
  5109. function getUserByToparty($toparty = '') {
  5110. $token = $this->getAccessToken (); //
  5111. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  5112. $userList = array ();
  5113. foreach ( $result ['userlist'] as $key => $value ) {
  5114. array_push ( $userList, "'" . $value ['userid'] . "'" );
  5115. }
  5116. return $userList;
  5117. }
  5118. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  5119. $token = $this->getAccessToken ();
  5120. if ($text == 'text') {
  5121. $data = '{
  5122. "touser": "' . $toparty . '",
  5123. "toparty": "",
  5124. "totag": "",
  5125. "msgtype": "text",
  5126. "agentid": 1000002,
  5127. "text": {
  5128. "content": "' . $msg . '"
  5129. },
  5130. "safe":0
  5131. }';
  5132. }
  5133. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  5134. if ($result->errmsg != 'ok') {
  5135. return 0;
  5136. } else {
  5137. return 1;
  5138. }
  5139. }
  5140. /**
  5141. * 获得可以发送微信用户列表
  5142. * @param string $category
  5143. * @return string
  5144. */
  5145. function getWxidByCategory($category = "") {
  5146. if (empty ( $category ))
  5147. return "";
  5148. Doo::loadModel ( 'staff' );
  5149. $staff = new staff ();
  5150. $toparty = $this->getToparty ( $category );
  5151. $wxList = array ();
  5152. $wxString = "";
  5153. if (! empty ( $toparty )) {
  5154. $userList = $this->getUserByToparty ( $toparty );
  5155. $userCon = implode ( ',', $userList );
  5156. // echo $userCon;
  5157. $sidList = $staff->getStaffByWxid ( $userCon );
  5158. foreach ( $sidList as $key => $value ) {
  5159. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  5160. if ($falg) {
  5161. array_push ( $wxList, $value ['wxid'] );
  5162. }
  5163. }
  5164. $wxString = implode ( '|', $wxList );
  5165. }
  5166. return $wxString;
  5167. }
  5168. /**
  5169. * 读取发送信息规则判断是否需要发送
  5170. * @param number $sid
  5171. * @param string $sendType
  5172. * @return boolean
  5173. */
  5174. function isSendNotification($sid = 0, $sendType = '') {
  5175. Doo::loadModel ( "notificationConf" );
  5176. $notificationConf = new notificationConf ();
  5177. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  5178. $conf = array ();
  5179. $sendFlag = true;
  5180. if (! empty ( $detail )) {
  5181. $conf = json_decode ( $detail ['conf'], true );
  5182. if (! empty ( $sendType )) {
  5183. if (isset ( $conf [$sendType] )) {
  5184. if ($conf [$sendType] == "CLOSE")
  5185. $sendFlag = false;
  5186. elseif ($conf [$sendType] == "Weekend") {
  5187. $day = date ( "w" );
  5188. if (1 <= $day && 5 >= $day)
  5189. $sendFlag = false;
  5190. } elseif ($conf [$sendType] == "OneToFriday") {
  5191. $day = date ( "w" );
  5192. if (0 == $day || 6 == $day)
  5193. $sendFlag = false;
  5194. }
  5195. }
  5196. } else
  5197. $sendFlag = false;
  5198. }
  5199. return $sendFlag;
  5200. }
  5201. /**
  5202. * 根据规则发送信息
  5203. * @param unknown $msg
  5204. * @param unknown $title
  5205. * @param unknown $url
  5206. * @param unknown $user
  5207. * @param string $text
  5208. * @return number
  5209. */
  5210. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  5211. $token = $this->getAccessToken ();
  5212. $falg = $this->isSendNotification ( $sid, $sendType );
  5213. // if ($text == 'text') {
  5214. // $data = '{
  5215. // "touser": "' . $user . '",
  5216. // "toparty": "",
  5217. // "totag": "",
  5218. // "msgtype": "text",
  5219. // "agentid": 1000002,
  5220. // "text": {
  5221. // "content": "' . $msg . '"
  5222. // },
  5223. // "safe":0
  5224. // }';
  5225. // } else {
  5226. $data = '{
  5227. "touser": "' . $user . '",
  5228. "toparty": "",
  5229. "totag": "",
  5230. "msgtype": "news",
  5231. "agentid": 1000002,
  5232. "news": {
  5233. "articles":[
  5234. {
  5235. "title": "' . $title . '",
  5236. "description": "' . $msg . '",
  5237. "url": "' . $url . '",
  5238. "picurl": ""
  5239. }
  5240. ]
  5241. }
  5242. }';
  5243. // }
  5244. if ($falg) {
  5245. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  5246. if ($result->errmsg != 'ok') {
  5247. return 0;
  5248. } else {
  5249. return 1;
  5250. }
  5251. } else
  5252. return 0;
  5253. }
  5254. private function getAccessToken() {
  5255. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  5256. // $file = './access_token.txt';
  5257. // $data = json_decode ( file_get_contents ( $file ) );
  5258. // if ($data->expire_time < time () or ! $data->expire_time) {
  5259. // 如果是企业号用以下URL获取access_token
  5260. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  5261. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  5262. $res = json_decode ( $this->httpGet ( $url ) );
  5263. $access_token = $res->access_token;
  5264. // echo $access_token;
  5265. // if ($access_token) {
  5266. // $data->expire_time = time () + 7000;
  5267. // $data->access_token = $access_token;
  5268. // $fp = fopen ( $file, "w" );
  5269. // fwrite ( $fp, json_encode ( $data ) );
  5270. // fclose ( $fp );
  5271. // }
  5272. // } else {
  5273. // $access_token = $data->access_token;
  5274. // }
  5275. return $access_token;
  5276. }
  5277. private function httpGet($url) {
  5278. $curl = curl_init ();
  5279. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  5280. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  5281. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  5282. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  5283. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  5284. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  5285. curl_setopt ( $curl, CURLOPT_URL, $url );
  5286. $res = curl_exec ( $curl );
  5287. curl_close ( $curl );
  5288. return $res;
  5289. }
  5290. private function httpPost($url, $data) {
  5291. $curl = curl_init ();
  5292. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  5293. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  5294. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  5295. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  5296. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  5297. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  5298. curl_setopt ( $curl, CURLOPT_URL, $url );
  5299. curl_setopt ( $curl, CURLOPT_POST, 1 );
  5300. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  5301. $res = curl_exec ( $curl );
  5302. curl_close ( $curl );
  5303. return $res;
  5304. }
  5305. }
  5306. ?>