| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171 |
- <?php
- /**
- * @author darkredz
- */
- class ReceiptController extends DooController {
- public $staff;
- public $verifyId;
- public static $NEW = 0;
-
- public $AGENCY="日常相关费用";
- public $TRAVEL="差旅相关费用";
- public $TRAIN="培训班费用";
- public $OTHER="其他";
- private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
- private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
- private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
- private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
-
- private function showCache($path){
- if(file_exists($path)){
- echo "<!DOCTYPE html>";
- include $path;die;
- }
- }
-
- private function cacheFile($path){
- $content = ob_get_contents();
- $fp = fopen($path, "w");
- fwrite($fp, $content);
- fclose($fp);
- }
-
- private function getReceiptCount(){
-
- $status=2;
- $year=date('Y');
-
- Doo::loadModel('receipt');
- $receipt=new receipt();
- Doo::loadModel('verify');
- $verify=new verify();
-
- //user verify ID
- $vidList=array();
- $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
- foreach ($verifyDetail as $key=>$value){
- array_push($vidList, $value['vid']);
- }
- $vid=implode(",", $vidList);
- if(empty($verifyDetail))
- $vid=0;
-
- $dateCondition=" and Year(date) =".$year;
- $approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
-
- $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
-
- return count($receiptList);
- }
-
- private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
- $collectHtml="";$sumPrice=0.00;
- for ($i=1;$i<=12;$i++){
- $falg=true;
- foreach ($receiptCollectList as $key=>$value){
- if($value['itemCategory']==$itemCategory&&$value['month']==$i){
- $sumPrice+=$value['price'];
- if ($classType=="b"){
- $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
- }else{
- $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
- }
- }
- }
- if ($falg)
- $collectHtml.='<td class="taR">-</td>';
- }
- $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
- return $collectHtml;
- }
-
- function __construct() {
- if(isset($_COOKIE["staff"])){
-
- if(!empty($_COOKIE["staff"])){
-
- Doo::loadModel ( 'staff' );
- Doo::loadModel('verify');
- $verify=new verify();
- $staff = new staff ();
-
- $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
- $list=array();
- foreach ($verifyList as $key=>$value){
- $ver=json_decode($value['staff']);
- foreach ($ver as $k=>$v){
- array_push($list, $v[0]);
- }
- }
-
- $this->verifyId=$list;
- $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
- self::$NEW= $this->getReceiptCount();
- return "/";
- }
- }
-
- Doo::loadCore ( 'uri/DooUriRouter' );
- $router = new DooUriRouter ();
- $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
-
- if($routeRs['1']!="login"){
- header ( 'Content-Type:text/html;charset=utf-8' );
- @header ( "Location: /login" );
- }
- }
-
- function myReceipt(){
-
- //all approval past withdraw
- $item=isset($this->params['item'])?$this->params['item']:"";
- if(empty($item))
- $item=$this->get_args('item')?$this->get_args('item'):"";
-
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
- $moth=$this->get_args('moth')?$this->get_args('moth'):"";
-
- Doo::loadModel('receipt');
- $receipt=new receipt();
-
- //pre-loaded
- if(!empty($item)&&($item=="past"||$item=="withdraw")){
- //have cache
- $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
- if(!empty($moth))//yearPage
- $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
-
- $this->showCache($path);
- }
-
- Doo::loadModel('L_category');
- $Lcategory=new L_category();
- Doo::loadModel('verify');
- Doo::loadModel('statistics');
- $statistics=new statistics();
- $verify=new verify();
-
- $condition=" and status!=4 ";
- if($item=="approval")
- $condition=" and status=2 ";
- elseif ($item=="withdraw")
- $condition=" and status=3 ";
- elseif ($item=="past")
- $condition=" and status=1 ";
- $dateCondition=" and Year(date) =".$year;
- if(!empty($moth)){
- $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
- $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
- }else
- $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
-
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
- $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
- foreach ($receiptList as $key=>$vlaue){
- $receiptList[$key]['accountItem']=json_decode($vlaue['accountItem'],true);
- $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$vlaue['cid'],'asArray'=>true));
- $receiptList[$key]['category']=$categoryDetil['title'];
- $verifyList=$verify->getOne(array('where'=>'vid='.$vlaue['verify'],'asArray'=>true));
- $verifyList=json_decode($verifyList['staff']);//status opinion
- $verifyStaff=json_decode($vlaue['verifyStaff'],true);
- foreach ($verifyList as $k=>$v){
- //init verifyStaff
- $verifyList[$k]['date']="";
- $verifyList[$k]['opinion']="";
- $verifyList[$k]['status']="";
- if (empty($verifyStaff)){
- $verifyList[$k]['date']="";
- $verifyList[$k]['opinion']="";
- if ($v[0]==$this->staff[0]['sid'])
- $verifyList[$k]['status']=4;
- }else{
- foreach ($verifyStaff as $m=>$u){
- if ($v[0]==$m){
- $verifyList[$k]['date']=$u['date'];
- $verifyList[$k]['opinion']=$u['opinion'];
- $verifyList[$k]['status']=$u['status'];
- break;
- }
- }
- }
- }
- $receiptList[$key]['verifyList']=$verifyList;
- }
- //print_r($receiptList);die;
- $mothHtml="";
- for($i=1;$i<=12;$i++){
- if($moth==$i)
- $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
- else
- $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
- }
-
- $data['mothHtml']=$mothHtml;
- $data['receiptList']=$receiptList;
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='receipt';
- $data['verifyId']=$this->verifyId;
- $data['item']=$item;
- $data['year']=$year;
-
- if(!empty($item)&&($item=="past"||$item=="withdraw")){
- //sufficient condition to generate cache
- if(empty($moth)&&($year<date("Y"))){
- $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
- if(empty($receiptList)){ //generated files
- ob_start();
- $this->render ( "/admin/saea_myList", $data );
- $this->cacheFile($path);die;
- // $content = ob_get_contents();
- // $fp = fopen($path, "w");
- // fwrite($fp, $content);
- // fclose($fp);
- }
- }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
- $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$moth,'asArray'=>true));
- if(empty($receiptList)){ //generated files
- ob_start();
- $this->render ( "/admin/saea_myList", $data );
- $this->cacheFile($path);die;
- }
- }
- }
- $this->render ( "/admin/saea_myList", $data );
- }
-
- function saeaCreate(){
-
- Doo::loadModel('accountItem');
- Doo::loadModel('verify');
- Doo::loadModel('receipt');
- Doo::loadModel('L_category');
- $lCategory=new L_category();
- $receipt=new receipt();
- $verify=new verify();
- $accountItem=new accountItem();
-
- // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
- // if(!empty($receiptDetail))
- // return "/referReceipt/".$receiptDetail['rid'];
-
- $acItem=$accountItem->find(array('asArray'=>true));
- $veList=$verify->find(array('asArray'=>true));
-
- foreach ($veList as $key=>$value){
- $veList[$key]['staff']=json_decode($value['staff']);
- }
-
- $data['category']=$lCategory->find(array('asArray'=>true));
- $data['veList']=$veList;
- $data['acItem']=$acItem;
- $data['memu']="receipt";
- $data['staff']=$this->staff;
-
- $data['receiptMemu']='saeaCreate';
- $data['verifyId']=$this->verifyId;
-
- $this->render ( "/admin/saea_create", $data );
- }
-
- function addReceipt(){
- $agency=$this->get_args('agency');
- $travel=$this->get_args('travel');
- $train=$this->get_args('train');
- $other=$this->get_args('other');
- $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
- $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
- $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
-
- if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
-
- Doo::loadModel('receipt');
- Doo::loadModel('receiptDetail');
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- $receipt=new receipt();
-
- // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
- // if(!empty($receiptDetail))
- // return "/referReceipt/".$receiptDetail['rid'];
-
- $aItem=$accountItem->find(array('asArray'=>true));
- $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
- $ag=$tr=$ta=$ot=0;
- $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
-
- foreach ($aItem as $key=>$value){
- if ($value['category']==$this->AGENCY){
- if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
- array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
- $sum+=$agency[$ag];$agencySum+=$agency[$ag];
- }
- $ag++;
- }
-
- if($value['category']==$this->TRAVEL){
- if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
- array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
- $sum+=$travel[$tr];$travelSum+=$travel[$tr];
- }
- $tr++;
- }
-
- if($value['category']==$this->TRAIN){
- if (is_numeric($train[$ta])&&$train[$ta]!=0){
- array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
- $sum+=$train[$ta];$trainSum+=$train[$ta];
- }
- $ta++;
- }
-
- if($value['category']==$this->OTHER){
- if (is_numeric($other[$ot])&&$other[$ot]!=0){
- array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
- $sum+=$other[$ot];$otherSum+=$other[$ot];
- }
- $ot++;
- }
- }
- $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
-
- //报销单
- $receipt->accountItem=json_encode($accountJson);
- $receipt->staff=$this->staff[0]['sid'];
- $receipt->sum=number_format($sum, 2, '.', '');
- $receipt->date=date("Y-m-d");
- $receipt->cid=$cid;
- $receipt->status=4;
- $receipt->verify=$verify;
- $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
- $receipt->explanation=$explanation;
- $rid=$receipt->insert();
-
- //报销详情
- foreach ($accountJson[$this->AGENCY] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->AGENCY;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
- foreach ($accountJson[$this->TRAVEL] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->TRAVEL;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
- foreach ($accountJson[$this->TRAIN] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->TRAIN;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
- foreach ($accountJson[$this->OTHER] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->OTHER;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
-
- return "/referReceipt/".$rid;
- }
- return "/saeaCreate";
- }
-
- function referReceipt(){
- //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
-
- Doo::loadModel('receipt');
- Doo::loadModel('verify');
- $verify=new verify();
- $receipt=new receipt();
- Doo::loadModel('L_category');
- $lCategory=new L_category();
-
- $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 ','asArray'=>true));
- if(empty($receiptDetail))
- return "/addReceipt";
-
-
- foreach ($receiptDetail as $key=>$value){
- $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
- $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
- $v=json_decode($veList['staff']);
- array_push($v[0], $veList['description']);
- $receiptDetail[$key]['staff']=$v;
- $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
- $receiptDetail[$key]['category']=$category['title'];
- }
-
- $data['receiptDetail']=$receiptDetail;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='saeaCreate';
- $data['verifyId']=$this->verifyId;
-
- $this->render ( "/admin/saea_confirm", $data );
- }
-
- function editReceipt(){
- //edit status 4
- $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
- //echo $rid;
- Doo::loadModel('accountItem');
- Doo::loadModel('verify');
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $verify=new verify();
- $accountItem=new accountItem();
- Doo::loadModel('L_category');
- $lCategory=new L_category();
-
- $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 and rid='.$rid,'asArray'=>true));
- if(empty($receiptDetail))
- return "/saeaCreate";
-
- $acItem=$accountItem->find(array('asArray'=>true));
- $veList=$verify->find(array('asArray'=>true));
-
- foreach ($veList as $key=>$value){
- $veList[$key]['staff']=json_decode($value['staff']);
- }
-
- //配置编辑信息
- $accountItemList=json_decode($receiptDetail['accountItem'],true);
- foreach ($acItem as $key=>$value){
- foreach ($accountItemList[$this->AGENCY] as $k=>$v){
- if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
- $acItem[$key]['price']=$v['price'];
- }
- }
- foreach ($accountItemList[$this->TRAIN] as $k=>$v){
- if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
- $acItem[$key]['price']=$v['price'];
- }
- }
- foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
- if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
- $acItem[$key]['price']=$v['price'];
- }
- }
- foreach ($accountItemList[$this->OTHER] as $k=>$v){
- if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
- $acItem[$key]['price']=$v['price'];
- }
- }
- }
-
- $data['category']=$lCategory->find(array('asArray'=>true));
- $data['cSum']=$accountItemList['cSum'];
- $data['sum']=$receiptDetail['sum'];
- $data['receiptDetail']=$receiptDetail;
- $data['veList']=$veList;
- $data['acItem']=$acItem;
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='saeaCreate';
- $data['verify']=$receiptDetail['verify'];
- $data['verifyId']=$this->verifyId;
- $data['rid']=$rid;
-
- $this->render ( "/admin/saea_edit", $data );
- }
-
- function updateReceipt(){
- $agency=$this->get_args('agency');
- $travel=$this->get_args('travel');
- $train=$this->get_args('train');
- $other=$this->get_args('other');
- $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
- $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
- $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
- $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
-
- if(!empty($verify)&&!empty($explanation)){
-
- Doo::loadModel('receipt');
- Doo::loadModel('receiptDetail');
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- $receipt=new receipt();
-
- $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 and rid='.$rid,'asArray'=>true));
- if(empty($receiptDetail))
- return "/saeaCreate";
-
- $aItem=$accountItem->find(array('asArray'=>true));
- $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
- $ag=$tr=$ta=$ot=0;
- $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
-
- foreach ($aItem as $key=>$value){
- if ($value['category']==$this->AGENCY){
- if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
- array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
- $sum+=$agency[$ag];$agencySum+=$agency[$ag];
- }
- $ag++;
- }
-
- if($value['category']==$this->TRAVEL){
- if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
- array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
- $sum+=$travel[$tr];$travelSum+=$travel[$tr];
- }
- $tr++;
- }
-
-
- if($value['category']==$this->TRAIN){
- if (is_numeric($train[$ta])&&$train[$ta]!=0){
- array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
- $sum+=$train[$ta];$trainSum+=$train[$ta];
- }
- $ta++;
- }
-
- if($value['category']==$this->OTHER){
- if (is_numeric($other[$ot])&&$other[$ot]!=0){
- array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
- $sum+=$other[$ot];$otherSum+=$other[$ot];
- }
- $ot++;
- }
- }
- $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
-
- //报销单
- $rid=$receipt->rid=$receiptDetail['rid'];
- $receipt->accountItem=json_encode($accountJson);
- $receipt->staff=$this->staff[0]['sid'];
- $receipt->sum=number_format($sum, 2, '.', '');
- $receipt->date=date("Y-m-d");
- $receipt->cid=$cid;
- $receipt->status=4;
- $receipt->verify=$verify;
- $receipt->explanation=$explanation;
- $receipt->update();
-
- $receiptDetail=new receiptDetail();
- $receiptDetail->delete(array('where'=>'rid='.$rid));
-
- //报销详情
- foreach ($accountJson[$this->AGENCY] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->AGENCY;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
- foreach ($accountJson[$this->TRAVEL] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->TRAVEL;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
- foreach ($accountJson[$this->TRAIN] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->TRAIN;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
- foreach ($accountJson[$this->OTHER] as $key=>$value){
- $receiptDetail=new receiptDetail();
- $receiptDetail->staff=$this->staff[0]['sid'];
- $receiptDetail->item=$value['name'];
- $receiptDetail->itemCategory=$this->OTHER;
- $receiptDetail->price=number_format($value['price'], 2, '.', '');
- $receiptDetail->date=date("Y-m-d");
- $receiptDetail->cid=$cid;
- $receiptDetail->rid=$rid;
- $receiptDetail->status=4;
- $receiptDetail->insert();
- }
-
- return "/referReceipt/".$rid;
- }
- return "/editReceipt/1";
- }
-
- function approvedReceipt(){
- $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
-
- Doo::loadModel('receipt');
- Doo::loadModel('receiptDetail');
- $receipt=new receipt();
- $receiptDetail=new receiptDetail();
- Doo::loadModel('statistics');
- Doo::loadModel('itemStatistics');
- $statistics=new statistics();
- $itemStatistics=new itemStatistics();
-
- $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 and rid='.$rid,'asArray'=>true));
- if(empty($receiptDetailList))
- return "/saeaCreate";
-
- $receipt->rid=$receiptDetailList['rid'];
- $receipt->status=2;
- $receipt->update();
-
- $receiptDetail->status=2;
- $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
-
- //statistics item
- $dateArray=explode("-", $receiptDetailList['date']);
- $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
-
- $accountItem=json_decode($receiptDetailList['accountItem'],true);
- //print_r($accountItem['cSum']['agencySum']);die;
- // foreach ($accountItem['cSum'] as $key=>$value){
- // if($key=="agencySum"){
- // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
- // if(empty($iStatistics)){
- // $itemStatistics->cid=$this->staff[0]['cid'];
- // $itemStatistics->staff=$this->staff[0]['sid'];
- // $itemStatistics->price=$value;
- // $itemStatistics->itemCategory=$this->AGENCY;
- // $itemStatistics->date=date("Y-m-d");
- // $itemStatistics->insert();
- // }else{
- // if (!empty($value)){
- // $itemStatistics->price=$value+$iStatistics['price'];
- // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- // }
- // }
- // }elseif($key=="travelSum"){
- // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
- // if(empty($iStatistics)){
- // $itemStatistics->cid=$this->staff[0]['cid'];
- // $itemStatistics->staff=$this->staff[0]['sid'];
- // $itemStatistics->price=$value;
- // $itemStatistics->itemCategory=$this->TRAVEL;
- // $itemStatistics->date=date("Y-m-d");
- // $itemStatistics->insert();
- // }else{
- // if (!empty($value)){
- // $itemStatistics->price=$value+$iStatistics['price'];
- // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- // }
- // }
- // }elseif($key=="trainSum"){
- // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
- // if(empty($iStatistics)){
- // $itemStatistics->cid=$this->staff[0]['cid'];
- // $itemStatistics->staff=$this->staff[0]['sid'];
- // $itemStatistics->price=$value;
- // $itemStatistics->itemCategory=$this->TRAIN;
- // $itemStatistics->date=date("Y-m-d");
- // $itemStatistics->insert();
- // }else{
- // if (!empty($value)){
- // $itemStatistics->price=$value+$iStatistics['price'];
- // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- // }
- // }
- // }elseif($key=="otherSum"){
- // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
- // if(empty($iStatistics)){
- // $itemStatistics->cid=$this->staff[0]['cid'];
- // $itemStatistics->staff=$this->staff[0]['sid'];
- // $itemStatistics->price=$value;
- // $itemStatistics->itemCategory=$this->OTHER;
- // $itemStatistics->date=date("Y-m-d");
- // $itemStatistics->insert();
- // }else{
- // if (!empty($value)){
- // $itemStatistics->price=$value+$iStatistics['price'];
- // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- // }
- // }
- // }
- // }
-
- $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
- if(empty($stat)){
- $statistics->date=date("Y-m-d");
- $statistics->cid=$this->staff[0]['cid'];
- $statistics->staff=$this->staff[0]['sid'];
- $statistics->agPrice=0;
- $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
- $statistics->insert();
- }else{
- $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
- $statistics->update(array('where'=>'sid='.$stat['sid']));
- }
-
- return "/myReceipt";
- }
-
-
-
- function approval(){
-
- $status=isset($this->params['status'])?$this->params['status']:'';
- $year=$this->get_args('year')?$this->get_args('year'):date('Y');
- $month=$this->get_args('month')?$this->get_args('month'):"";
- $cid=$this->get_args('cid')?$this->get_args('cid'):0;
- $sid=$this->get_args('sid')?$this->get_args('sid'):0;
-
- if (empty($status))
- $status=$this->get_args('status')?$this->get_args('status'):2;
-
- $vidList=array();
- $button=0;
-
- Doo::loadModel('verify');
- Doo::loadModel('receipt');
- Doo::loadModel('staff');
- $staff=new staff();
- $receipt=new receipt();
- $verify=new verify();
- Doo::loadModel('L_category');
- $Lcategory=new L_category();
-
- //user verify ID
- $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
- foreach ($verifyDetail as $key=>$value){
- array_push($vidList, $value['vid']);
- }
- $vid=implode(",", $vidList);
- if(empty($verifyDetail))
- $vid=0;
- $dateCondition=" and Year(date) =".$year;
- if(!empty($month))
- $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
-
- $categoryList=$Lcategory->find(array('asArray'=>true));
- $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
- $cateCondition="";$staffCondition="";$approvalCondition="";
- if (!empty($cid))
- $cateCondition=' and cid='.$cid;
- if(!empty($sid)){
- $staffCondition=' and staff='.$sid;
- $cateCondition="";
- }
- if($status==2)
- $approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
- $ap="";
- if($status==4){
- $ap=4;$status=2;
- $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
- }
-
- //get Receipt By verifyID status 2
- $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
- $Locate=0;
- if($ap==4)
- $status=4;
- foreach ($receiptList as $key=>$value){
- $receiptList[$key]['Locate']=$Locate;$Locate++;
- $receiptList[$key]['reviseDetail']=array();
- if (!empty($value['reviseDetail']))
- $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
- $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
- $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
- $receiptList[$key]['category']=$categoryDetil['title'];
- $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
- $verifyList=json_decode($verifyList['staff'],true);//status opinion
- $verifyStaff=json_decode($value['verifyStaff'],true);
- foreach ($verifyList as $k=>$v){
- //init verifyStaff
- $verifyList[$k]['date']="";
- $verifyList[$k]['opinion']="";
- $verifyList[$k]['status']="";
- if (empty($verifyStaff)){
- $verifyList[$k]['date']="";
- $verifyList[$k]['opinion']="";
- if ($v[0]==$this->staff[0]['sid']){
- $verifyList[$k]['status']=4;
- $button=4;
- }
- }else{
- $flag=true;
- foreach ($verifyStaff as $m=>$u){
- if ($v[0]==$m){
- $verifyList[$k]['date']=$u['date'];
- $verifyList[$k]['opinion']=$u['opinion'];
- $verifyList[$k]['status']=$u['status'];
- $flag=false;
- break;
- }
- // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
- // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
- // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
- }
- if($flag){//检测可编辑
- if($v[0]==$this->staff[0]['sid']){
- $verifyList[$k]['status']=4;$button=4;
- }
- }
- }
- }
- $receiptList[$key]['verifyList']=$verifyList;
- $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
- $receiptList[$key]['button']=$button;
- }
- //print_r($receiptList);die;
- //$data['verifyDetail']=$verifyDetail;
-
- $mothHtml="";
- for($i=1;$i<=12;$i++){
- if($month==$i)
- $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
- else
- $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
- }
- $data['mothHtml']=$mothHtml;
-
- $data['receiptList']=$receiptList;
- $data['receiptApprovalCount']=count($receiptList);
- $data['status']=$status;
- $data['year']=$year;
- $data['categoryList']=$categoryList;
- $data['staffList']=$staffList;
- $data['cid']=$cid;
- $data['sid']=$sid;
- $data['ap']=$ap;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='approval';
- $data['verifyId']=$this->verifyId;
-
- $this->render ( "/admin/saea_reportList", $data );
- }
-
- function remittance(){
- $year=$this->get_args('year')?$this->get_args('year'):date('Y');
- $month=$this->get_args('month')?$this->get_args('month'):"";
-
- Doo::loadModel('receipt');
- $receipt=new receipt();
- Doo::loadModel('staff');
- $staff=new staff();
-
- $dateCondition=" and Year(pastDate) =".$year;
- if(!empty($month))
- $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
-
- //get Receipt By verifyID status 1
- $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
- $dateList=$receipt->find(array('select'=>'pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
- $dataList=array();
- foreach ($dateList as $d=>$a){
- $dataList[$a['pastDate']]=array();$daySum=0;
- foreach ($receiptList as $key=>$value){
- if($a['pastDate']==$value['pastDate']){
- $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
- $list=array();
- foreach ($oderList as $v){
- array_push($list, $v['receiptOrder']);
- }
- $receiptList[$key]['receiptOrder']=implode(",", $list);
-
- $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
- $receiptList[$key]['username']=$sinfo['username'];
- $daySum+=$value['sum'];
- array_push($dataList[$a['pastDate']], $receiptList[$key]);
- }
- $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
- }
- }
- //print_r($dataList);die;
- $data['dataList']=$dataList;
-
- $mothHtml="";
- for($i=1;$i<=12;$i++){
- if($month==$i)
- $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
- else
- $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
- }
- $data['year']=$year;
- $data['mothHtml']=$mothHtml;
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='approval';
- $data['verifyId']=$this->verifyId;
-
- $this->render ( "/admin/saeaReportListPay", $data );
- }
-
- function revocationAdjustment(){
- $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
- $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
- $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
-
- if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
- Doo::loadModel('receipt');
- $receipt=new receipt();
-
- $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
- if (empty($receiptDetail['reviseDetail']))
- return "/approval";
-
- $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
- $RD=array();
- foreach ($reviseDetail as $key=>$value){
- if ($value['price']==$price&&$value['sid']==$sid)
- continue;
- array_push($RD, $value);
- }
-
- $reviseDetailString=json_encode($RD);
- $receipt->reviseDetail=$reviseDetailString;
- $receipt->sum=$receiptDetail['sum']+$price;
- $receipt->update(array('where'=>'rid='.$rid));
- }
- return "/approval";
- }
-
- function updateApprovalReceipt(){
- $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
- $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
- $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
- $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
-
- if(!empty($rid)){
- Doo::loadModel("receipt");
- Doo::loadModel("verify");
- Doo::loadModel("receiptDetail");
- $receiptDetailObj=new receiptDetail();
- Doo::loadModel("itemStatistics");
- Doo::loadModel("statistics");
- $statistics=new statistics();
- $itemStatistics=new itemStatistics();
- $verify=new verify();
- $receipt=new receipt();
-
- $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
- if (empty($receiptDetail))
- return "/approval";
-
- $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
- if(empty($opinion)){
- if ($status==3)
- $opinion="退回";
- else
- $opinion="同意支付";
- }
-
- if(empty($verifyStaff)){
- $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
- if($status==3)
- $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
-
- $vStaffString=json_encode($verifyStaff);
- $receipt->verifyStaff=$vStaffString;
- }else{
- if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)){
- $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
- if($status==3){
- $verifyStaff['final']=$status;
- $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
- }
- $vStaffString=json_encode($verifyStaff);
- $receipt->verifyStaff=$vStaffString;
- }
- }
-
- $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
- $verifyDetail=json_decode($verifyDetail['staff'],true);
-
- if (isset($verifyStaff['final'])){//rDetail
- $receipt->status=3;
- $receiptDetailObj->status=3;
- $receiptDetailObj->update(array('where'=>'rid='.$rid));
- }elseif(count($verifyStaff)==count($verifyDetail)){
- $receipt->status=1;
- if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
- $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
- $reviseSum=0;
- foreach ($reviseDetail as $key=>$value){
- $receiptDetailObj=new receiptDetail();
- $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
- $receiptDetailObj->item=$value['description'];
- $receiptDetailObj->itemCategory="报销金额调整";
- $receiptDetailObj->price=$value['price'];
- $receiptDetailObj->date=$receiptDetail['date'];
- $receiptDetailObj->cid=$this->staff[0]['cid'];
- $receiptDetailObj->rid=$rid;
- $receiptDetailObj->status=1;
- $receiptDetailObj->insert();
- $reviseSum+=$value['price'];
- }
-
- $itemStatistics=new itemStatistics();
- $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
- $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
- $itemStatistics->price=$reviseSum;
- $itemStatistics->itemCategory="报销金额调整";
- $itemStatistics->date=$receiptDetail['date'];
- $itemStatistics->insert();
- }
- $receiptDetailObj=new receiptDetail();
- $receiptDetailObj->status=1;
- $receiptDetailObj->update(array('where'=>'rid='.$rid));
-
- $dateArray=explode("-", $receiptDetail['date']);
- $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
- $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
- if(empty($stat)){
- $statistics->date=$receiptDetail['date'];
- $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
- $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
- $statistics->agPrice=$receiptDetail['sum'];
- $statistics->rePrice=$reviseSum;
- $statistics->insert();
- }else{
- $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
- $statistics->rePrice=$stat['rePrice']+$reviseSum;
- $statistics->update(array('where'=>'sid='.$stat['sid']));
- }
-
- $dateArray=explode("-", $receiptDetail['date']);
- $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
- $accountItem=json_decode($receiptDetail['accountItem'],true);
- foreach ($accountItem['cSum'] as $key=>$value){
- if($key=="agencySum"){
- $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
- if(empty($iStatistics)){
- $itemStatistics->cid=$receiptDetail['cid'];;
- $itemStatistics->staff=$receiptDetail['staff'];
- $itemStatistics->price=$value;
- $itemStatistics->itemCategory=$this->AGENCY;
- $itemStatistics->date=$receiptDetail['date'];
- $itemStatistics->insert();
- }else{
- if (!empty($value)){
- $itemStatistics->price=$value+$iStatistics['price'];
- $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- }
- }
- }elseif($key=="travelSum"){
- $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
- if(empty($iStatistics)){
- $itemStatistics->cid=$receiptDetail['cid'];
- $itemStatistics->staff=$receiptDetail['staff'];
- $itemStatistics->price=$value;
- $itemStatistics->itemCategory=$this->TRAVEL;
- $itemStatistics->date=$receiptDetail['date'];
- $itemStatistics->insert();
- }else{
- if (!empty($value)){
- $itemStatistics->price=$value+$iStatistics['price'];
- $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- }
- }
- }elseif($key=="trainSum"){
- $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
- if(empty($iStatistics)){
- $itemStatistics->cid=$receiptDetail['cid'];
- $itemStatistics->staff=$receiptDetail['staff'];
- $itemStatistics->price=$value;
- $itemStatistics->itemCategory=$this->TRAIN;
- $itemStatistics->date=$receiptDetail['date'];
- $itemStatistics->insert();
- }else{
- if (!empty($value)){
- $itemStatistics->price=$value+$iStatistics['price'];
- $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- }
- }
- }elseif($key=="otherSum"){
- $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
- if(empty($iStatistics)){
- $itemStatistics->cid=$receiptDetail['cid'];
- $itemStatistics->staff=$receiptDetail['staff'];
- $itemStatistics->price=$value;
- $itemStatistics->itemCategory=$this->OTHER;
- $itemStatistics->date=$receiptDetail['date'];
- $itemStatistics->insert();
- }else{
- if (!empty($value)){
- $itemStatistics->price=$value+$iStatistics['price'];
- $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
- }
- }
- }
- }
- $receipt->pastDate=date("Y-m-d");
- }
-
- $receipt->update(array('where'=>'rid='.$rid));
- return "/approval#".$Locate;
- }
- }
-
- function revisePrice(){
- $description=$this->get_args('description')?$this->get_args('description'):"";
- $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
- $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
-
- if (!empty($rid)){
- Doo::loadModel("receipt");
- $receipt=new receipt();
-
- $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
- if (empty($receiptDetail))
- return "/approval";
-
- $reviseDetail=array();
- if (empty($receiptDetail['reviseDetail'])){
- array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
- $reviseDetailString=json_encode($reviseDetail);
- $receipt->reviseDetail=$reviseDetailString;
- $receipt->revisePrice=$price;
- $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
- }else{
- $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
- array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
- $reviseDetailString=json_encode($reviseDetail);
- $receipt->reviseDetail=$reviseDetailString;
- $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
- $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
- }
- $receipt->update(array('where'=>'rid='.$rid));
- }
- return "/approval";
- }
-
- function personalCollect(){
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
-
- $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
- $this->showCache($path);
-
- Doo::loadModel("receiptDetail");
- Doo::loadModel("itemStatistics");
- Doo::loadModel('statistics');
- $statistics=new statistics();
- $itemStatistics=new itemStatistics();
- $receiptDetail=new receiptDetail();
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
- $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
-
- //create collect html
- $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
- $adjustment=array();
-
- $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
- array_push($collectArray['日常相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
- array_push($collectArray['差旅相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
- array_push($collectArray['培训班费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'其他');
- array_push($collectArray['其他'], $collectHtml);
-
- $data['collectArray']=$collectArray;
- //statistics html
- $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- //Adjustment price html
- $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
- array_push($adjustment, $collectHtml);
- $data['adjustment']=$adjustment;
-
- //total price html
- $collectHtml="";$total=0;
- for ($i=1;$i<=12;$i++){
- $sumPrice=0;
- foreach ($receiptCollectList as $key=>$value){
- if($value['month']==$i){
- $sumPrice+=$value['price'];
- }
- }
- if ($sumPrice==0)
- $collectHtml.='<td class="taR">-</td>';
- else
- $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
- $total+=$sumPrice;
- }
- $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
- $data['totalPrice']=$collectHtml;
- $data['year']=$year;
- $data['totalYear']=$total;
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='personalCollect';
- $data['verifyId']=$this->verifyId;
-
- //year staff status 2,4
- if($year<date("Y")){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
- if(empty($receiptList)){
- ob_start();
- $this->render ( "/admin/saea_slist_collect", $data );
- $this->cacheFile($path);die;
- }
- }
- $this->render ( "/admin/saea_slist_collect", $data );
- }
-
- function personalCollectDetail(){
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
-
- $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
- $this->showCache($path);
-
- Doo::loadModel("receiptDetail");
- Doo::loadModel("itemStatistics");
- Doo::loadModel('statistics');
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- $statistics=new statistics();
- $itemStatistics=new itemStatistics();
- $receiptDetail=new receiptDetail();
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
-
- $accountList=$accountItem->find(array('asArray'=>true));
-
- //create CollectDetail HTML
- $collectHtml=array();
- foreach ($accountList as $key=>$value){
- $html="";$asum=0;
- for ($i=1;$i<=12;$i++){
- $falg=true;
- foreach ($receiptCollectList as $v) {
- if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
- $asum+=$v['price'];
- $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
- $collectHtml[$value['category']][$value['name']]=$html;
- }
- $data['collectHtml']=$collectHtml;
-
- //create Adjustment price html
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
-
- $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
- $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
- array_push($collectArray['日常相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
- array_push($collectArray['差旅相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
- array_push($collectArray['培训班费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
- array_push($collectArray['其他'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
- array_push($adjustment, $collectHtml);
-
- //total price html
- $collectHtml="";$total=0;
- for ($i=1;$i<=12;$i++){
- $sumPrice=0;
- foreach ($receiptCollectList as $key=>$value){
- if($value['month']==$i){
- $sumPrice+=$value['price'];
- }
- }
- if ($sumPrice==0)
- $collectHtml.='<td class="taR">-</td>';
- else
- $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
- $total+=$sumPrice;
- }
- $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
-
- //statistics html
- $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $data['collectArray']=$collectArray;
- $data['adjustment']=$adjustment;
- $data['totalPrice']=$collectHtml;
- $data['totalYear']=$total;
- $data['year']=$year;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='personalCollect';
- $data['verifyId']=$this->verifyId;
-
- //year staff status 2,4
- if($year<date("Y")){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
- if(empty($receiptList)){
- ob_start();
- $this->render ( "/admin/saeaCollectArticles", $data );
- $this->cacheFile($path);die;
- }
- }
-
- $this->render ( "/admin/saeaCollectArticles", $data );
- }
-
- function companyCategoryCollect(){
-
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
-
- $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
- $this->showCache($path);
-
- Doo::loadModel('L_category');
- Doo::loadModel('itemStatistics');
- Doo::loadModel('statistics');
- $statistics=new statistics();
- $Lcategory=new L_category();
- $itemStatistics=new itemStatistics();
-
- $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
- $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
-
- //ceatre companyCollectHtml
- foreach ($LcategoryList as $value){
- $html="";$asum=0;
- for ($i=1;$i<=12;$i++){
- $falg=true;
- foreach ($itemStatisticsList as $v){
- if($value['cid']==$v['cid']&&$i==$v['month']){
- $asum+=$v['price'];
- $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
- $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
- }
- $data['companyHtml']=$collectHtml;
-
- //total price html
- $collectHtml="";$total=0;
- for ($i=1;$i<=12;$i++){
- $sumPrice=0;
- foreach ($itemStatisticsList as $key=>$value){
- if($value['month']==$i){
- $sumPrice+=$value['price'];
- }
- }
- if ($sumPrice==0)
- $collectHtml.='<td class="taR">-</td>';
- else
- $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
- $total+=$sumPrice;
- }
- $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
- $data['companyTotalHtml']=$collectHtml;
- $data['total']=$total;
-
- //statistics html
- $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $data['year']=$year;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- //year staff status 2,4
- if($year<date("Y")){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
- if(empty($receiptList)){
- ob_start();
- $this->render ( "/admin/saeaCompanyCollect", $data );
- $this->cacheFile($path);die;
- }
- }
-
- $this->render ( "/admin/saeaCompanyCollect", $data );
- }
-
- function categoryCollectDetail(){
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
- $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
-
- $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
- $this->showCache($path);
-
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('L_category');
- $Lcategory=new L_category();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
-
- $LcategoryList=$Lcategory->find(array('asArray'=>true));
-
- if ($cid==0){
- $cid=$this->get_args('cid')?$this->get_args('cid'):0;
- if ($cid==0)
- $cid=$LcategoryList[0]['cid'];
- }
- $data['LcategoryList']=$LcategoryList;
-
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'cid='.$cid." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
- $accountList=$accountItem->find(array('asArray'=>true));
- //create CollectDetail HTML
- $collectHtml=array();
- foreach ($accountList as $key=>$value){
- $html="";$asum=0;
- for ($i=1;$i<=12;$i++){
- $falg=true;
- foreach ($receiptCollectList as $v) {
- if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
- $asum+=$v['price'];
- $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
- $collectHtml[$value['category']][$value['name']]=$html;
- }
- $data['collectHtml']=$collectHtml;
-
- //create Adjustment price html
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'cid='.$cid." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
-
- $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
- $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
- array_push($collectArray['日常相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
- array_push($collectArray['差旅相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
- array_push($collectArray['培训班费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
- array_push($collectArray['其他'], $collectHtml);
- $data['collectArray']=$collectArray;
-
- $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
- array_push($adjustment, $collectHtml);
- $data['adjustment']=$adjustment;
-
- //total price html
- $collectHtml="";$total=0;
- for ($i=1;$i<=12;$i++){
- $sumPrice=0;
- foreach ($receiptCollectList as $key=>$value){
- if($value['month']==$i){
- $sumPrice+=$value['price'];
- }
- }
- if ($sumPrice==0)
- $collectHtml.='<td class="taR">-</td>';
- else
- $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
- $total+=$sumPrice;
- }
- $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
-
- //statistics html
- $stList=$statistics->statisticsByCid($year,$cid);
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $data['totalYear']=$total;
- $data['year']=$year;
- $data['cid']=$cid;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- //year staff status 2,4
- if($year<date("Y")){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
- if(empty($receiptList)){
- ob_start();
- $this->render ( "/admin/saeaCategoryCollectDetail", $data );
- $this->cacheFile($path);die;
- }
- }
-
- $this->render ( "/admin/saeaCategoryCollectDetail", $data );
- }
-
- function staffCollect(){
-
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
-
- $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
- //$this->showCache($path);
-
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('L_category');
- $Lcategory=new L_category();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel('itemStatistics');
- $itemStatistics=new itemStatistics();
-
- /*
- $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
- 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
- */
-
- //statistics html
- $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- //---
- $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
- $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
- $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
- $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
-
- //ceatre companyCollectHtml
- foreach ($categoryList as $vlu){
- $count=$vlu['count']+1;
- $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
- $m1=0;$m2=0;$m3=0;$m4=0;$m5=0;$m6=0;$m7=0;$m8=0;$m9=0;$m10=0;$m11=0;$m12=0;$m13=0;
- foreach ($staffList as $value){
- if ($vlu['cid']==$value['cid']){
-
- $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
- $asum=0;
- for ($i=1;$i<=12;$i++){
- $falg=true;
- foreach ($itemStatisticsList as $v){
- if($value['sid']==$v['staff']&&$i==$v['month']){
- if ($v['month']==1)
- $m1+=$v['price'];
- if ($v['month']==2)
- $m2+=$v['price'];
- if ($v['month']==3)
- $m3+=$v['price'];
- if ($v['month']==4)
- $m4+=$v['price'];
- if ($v['month']==5)
- $m5+=$v['price'];
- if ($v['month']==6)
- $m6+=$v['price'];
- if ($v['month']==7)
- $m7+=$v['price'];
- if ($v['month']==8)
- $m8+=$v['price'];
- if ($v['month']==9)
- $m9+=$v['price'];
- if ($v['month']==10)
- $m10+=$v['price'];
- if ($v['month']==11)
- $m11+=$v['price'];
- if ($v['month']==12)
- $m12+=$v['price'];
- $asum+=$v['price'];
- $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $m13+=$asum;
- $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
- $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
- $html="";
- }
- }
- $hl='<th class="taR">小计</th><td class="taR">¥'.$m1.'</td><td class="taR">¥'.$m2.'</td><td class="taR">¥'.$m3.'</td><td class="taR">¥'.$m4.'</td><td class="taR">¥'.$m5.'</td>
- <td class="taR">¥'.$m6.'</td><td class="taR">¥'.$m7.'</td><td class="taR">¥'.$m8.'</td><td class="taR">¥'.$m9.'</td><td class="taR">¥'.$m10.'</td><td class="taR">¥'.$m11.'</td>
- <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
- $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
- }
- $data['companyHtml']=$collectHtml;
-
- //total price html
- $collectHtml="";$total=0;
- for ($i=1;$i<=12;$i++){
- $sumPrice=0;
- foreach ($itemStatisticsList as $key=>$value){
- if($value['month']==$i){
- $sumPrice+=$value['price'];
- }
- }
- if ($sumPrice==0)
- $collectHtml.='<td class="taR">-</td>';
- else
- $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
- $total+=$sumPrice;
- }
- $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
- $data['companyTotalHtml']=$collectHtml;
- $data['total']=$total;
-
- $data['year']=$year;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- if ($year<=date("Y")){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
- if(empty($receiptList)){ //generated files
- ob_start();
- $this->render ( "/admin/saeaStaffCollectB", $data );
- $this->cacheFile($path);die;
- }
- }
-
- $this->render ( "/admin/saeaStaffCollectB", $data );
-
- }
-
- function staffCollectBak(){
-
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
- $month=$this->get_args('month')?$this->get_args('month'):1;
-
- $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
- $this->showCache($path);
-
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('L_category');
- $Lcategory=new L_category();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel('itemStatistics');
- $itemStatistics=new itemStatistics();
-
- $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
- $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
-
- $LcategoryList=$Lcategory->find(array('asArray'=>true));
- $staffList=$staff->find(array('asArray'=>true));
-
- $htmlArray=array();
- foreach ($LcategoryList as $value){
- $htmlArray[$value['title']]=array();
- foreach ($staffList as $v){
- if($value['cid']==$v['cid']){
- $html="";$falg=true;$staffSumPrice=0;
-
- foreach ($itemStatisticsList as $a){
- if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
- if(empty($a['price'])){
- $html.='<td class="taR">-</td>';$falg=false;break;
- }else{
- $staffSumPrice+=$a['price'];
- $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
- }
- }
- }
- if ($falg){
- $html.='<td class="taR">-</td>';$falg=true;
- }
-
- $falg=true;
- foreach ($itemStatisticsList as $a){
- if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
- if(empty($a['price'])){
- $html.='<td class="taR">-</td>';$falg=false;break;
- }else{
- $staffSumPrice+=$a['price'];
- $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
- }
- }
- }
- if ($falg){
- $html.='<td class="taR">-</td>';$falg=true;
- }
-
- $falg=true;
- foreach ($itemStatisticsList as $a){
- if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
- if(empty($a['price'])){
- $html.='<td class="taR">-</td>';$falg=false;break;
- }else{
- $staffSumPrice+=$a['price'];
- $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
- }
- }
- }
- if ($falg){
- $html.='<td class="taR">-</td>';$falg=true;
- }
-
- $falg=true;
- foreach ($itemStatisticsList as $a){
- if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
- if(!empty($a['price'])){
- $staffSumPrice+=$a['price'];
- $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
- }else{
- $html.='<td class="taR">-</td>';$falg=false;break;
- }
- }
- }
- if ($falg){
- $html.='<td class="taR">-</td>';$falg=true;
- }
-
- $falg=true;
- foreach ($itemStatisticsList as $a){
- if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
- if(!empty($a['price'])){
- $staffSumPrice+=$a['price'];
- $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
- }else{
- $html.='<td class="taR">-</td>';$falg=false;break;
- }
- }
- }
- if ($falg){
- $html.='<td class="taR">-</td>';$falg=true;
- }
-
- $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
- $htmlArray[$value['title']][$v['username']]=$html;
- }
- }
-
- /*-- ---*/
- //合计费用
- $cateHtml="";$catePrice=0;$cateFalg=true;
- foreach ($itemCategoryList as $l){
- if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
- if(empty($l['price'])){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
- }else{
- $catePrice+=$l['price'];
- $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
- }
- }
- }
- if ($cateFalg){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
- }
-
- $cateFalg=true;
- foreach ($itemCategoryList as $l){
- if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
- if(empty($l['price'])){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
- }else{
- $catePrice+=$l['price'];
- $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
- }
- }
- }
- if ($cateFalg){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
- }
-
- $cateFalg=true;
- foreach ($itemCategoryList as $l){
- if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
- if(empty($l['price'])){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
- }else{
- $catePrice+=$l['price'];
- $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
- }
- }
- }
- if ($cateFalg){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
- }
-
- $cateFalg=true;
- foreach ($itemCategoryList as $l){
- if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
- if(empty($l['price'])){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
- }else{
- $catePrice+=$l['price'];
- $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
- }
- }
- }
- if ($cateFalg){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
- }
-
- $cateFalg=true;
- foreach ($itemCategoryList as $l){
- if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
- if(empty($l['price'])){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
- }else{
- $catePrice+=$l['price'];
- $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
- }
- }
- }
- if ($cateFalg){
- $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
- }
-
- $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
- $htmlArray[$value['title']]['合计']=$cateHtml;
- /*-- ---*/
- }
-
- //print_r($htmlArray);die;
- $data['htmlArray']=$htmlArray;
-
- //statistics html
- $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
- 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $monthHtml="";
- for ($i=1;$i<=12;$i++){
- if ($i==$month)
- $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
- else
- $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
- }
-
- $data['monthHtml']=$monthHtml;
- $data['year']=$year;
- $data['month']=$month;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
- if(empty($receiptList)){ //generated files
- ob_start();
- $this->render ( "/admin/saeaStaffCollect", $data );
- $this->cacheFile($path);die;
- }
- }
-
- $this->render ( "/admin/saeaStaffCollect", $data );
- }
-
- function staffCollectMonthDetail(){
-
- $year=$this->get_args('year')?$this->get_args('year'):"";
- $month=$this->get_args('month')?$this->get_args('month'):"";
- if(!$year)
- $year=isset($this->params['year'])?$this->params['year']:date("Y");
- if(!$month)
- $month=isset($this->params['month'])?$this->params['month']:1;
-
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel('L_category');
- $lCategory=new L_category();
-
- $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
- $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
-
- $list=array();
- foreach ($categoryList as $vlu){
- //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
- $r1=0;$r2=0;$r3=0;$r4=0;$r5=0;$r6=0;$r7=0;$r8=0;$r9=0;$r10=0;$r11=0;$r12=0;$r13=0;
- $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
- $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
- $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
- $s1=0;
- $m1=0;
- foreach ($staffList as $value){
- if ($vlu['cid']==$value['cid']){
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- if(!empty($receiptCollectList)){
-
- $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
-
- $html="";
- $psum=0;
- $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='日常相关费用'){
-
- if($v['item']==$va){
- if ($va=='市内交通费')
- $r1+=$v['price'];
- if ($va=='市内出租费')
- $r2+=$v['price'];
- if ($va=='办事处房租')
- $r3+=$v['price'];
- if ($va=='电话费')
- $r4+=$v['price'];
- if ($va=='水费')
- $r5+=$v['price'];
- if ($va=='电费')
- $r6+=$v['price'];
- if ($va=='办公费用')
- $r7+=$v['price'];
- if ($va=='邮寄费')
- $r8+=$v['price'];
- if ($va=='其他费用')
- $r9+=$v['price'];
- if ($va=='车辆费用')
- $r10+=$v['price'];
- if ($va=='广告费')
- $r11+=$v['price'];
- if ($va=='团队建设费')
- $r13+=$v['price'];
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
- $r12+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['日常相关费用']=$psum.$html;
-
- /*-----------------------------------*/
-
- $html="";
- $psum=0;
- $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='差旅相关费用'){
-
- if($v['item']==$va){
- if ($va=='往来交通费')
- $c1+=$v['price'];
- if ($va=='市内交通费')
- $c2+=$v['price'];
- if ($va=='出差住宿费')
- $c3+=$v['price'];
- if ($va=='出差补助')
- $c4+=$v['price'];
- if ($va=='其他费用')
- $c5+=$v['price'];
-
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $c6+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['差旅相关费用']=$psum.$html;
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='培训班费用'){
-
- if($v['item']==$va){
-
- if ($va=='场租费')
- $p1+=$v['price'];
- if ($va=='薪酬')
- $p2+=$v['price'];
- if ($va=='住宿费')
- $p3+=$v['price'];
- if ($va=='交通费')
- $p4+=$v['price'];
- if ($va=='餐饮费')
- $p5+=$v['price'];
- if ($va=='办公费')
- $p6+=$v['price'];
- if ($va=='公关费')
- $p7+=$v['price'];
- if ($va=='其他')
- $p8+=$v['price'];
-
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $p9+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['培训班费用']=$psum.$html;
-
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('公关费','广告费','借款','可自加费用');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='其他'){
-
- if($v['item']==$va){
- if ($va=='公关费')
- $t1+=$v['price'];
- if ($va=='广告费')
- $t2+=$v['price'];
- if ($va=='借款')
- $t3+=$v['price'];
- if ($va=='可自加费用')
- $t4+=$v['price'];
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $t5+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['其他']=$psum.$html;
-
- /*-------------------------------------*/
- $html="";
- $psum=0;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='报销金额调整'){
-
- if (!empty($v['price'])){
- $psum+=$v['price'];
- }
- }
- }
- $s1+=$psum;
- if(!empty($psum))
- $psum='<td class="taR colOrange">¥'.$psum.'</td>';
- else
- $psum='<td class="taR colOrange">-</td>';
- $receiptL['报销金额调整']=$psum.$html;
-
- }else{
- $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
- }
-
- $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
-
- if(!empty($monthStaffPrice[0]['price'])){
- $m1+=$monthStaffPrice[0]['price'];
- $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
- }else
- $receiptL['monthStaffPrice']='<td><b>-</b></td>';
- $list[$value['username']]=$receiptL;
-
-
- }
- }
- $receiptL['日常相关费用']='<td class="colGreen taR">'.$r12.'</td><td class="taR">'.$r1.'</td><td class="taR">'.$r2.'</td><td class="taR">'.$r3.'</td><td class="taR">'.$r4.'</td><td class="taR">'.$r5.'</td>
- <td class="taR">'.$r6.'</td><td class="taR">'.$r7.'</td><td class="taR">'.$r8.'</td><td class="taR">'.$r9.'</td><td class="taR">'.$r10.'</td><td class="taR">'.$r11.'</td><td class="taR">'.$r13.'</td>';
- $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
- <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
- $receiptL['培训班费用']='<td class="colGreen taR">'.$p9.'</td><td class="taR">'.$p1.'</td><td class="taR">'.$p2.'</td><td class="taR">'.$p3.'</td><td class="taR">'.$p4.'</td>
- <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
- $receiptL['其他']='<td class="colGreen taR">'.$t5.'</td><td class="taR">'.$t1.'</td><td class="taR">'.$t2.'</td><td class="taR">'.$t3.'</td><td class="taR">'.$t4.'</td>';
- $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
- $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
- $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
- }
- $data['list']=$list;
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
-
- //statistics html
- $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
- 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $monthHtml="";
- for ($i=1;$i<=12;$i++){
- if ($i==$month)
- $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
- else
- $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
- }
-
- $data['monthHtml']=$monthHtml;
- $data['year']=$year;
- $data['month']=$month;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- $this->render ( "/admin/staffCollectMonthDetail", $data );
- //$this->render ( "/admin/saeaStaffCollectDetail", $data );
- }
-
- function staffCollectMonthDetail2(){
-
- $year=$this->get_args('year')?$this->get_args('year'):"";
- $month=$this->get_args('month')?$this->get_args('month'):"";
- if(!$year)
- $year=isset($this->params['year'])?$this->params['year']:date("Y");
- if(!$month)
- $month=isset($this->params['month'])?$this->params['month']:1;
-
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel('L_category');
- $lCategory=new L_category();
-
- $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
- $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
-
- $list=array();
- foreach ($categoryList as $vlu){
- //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
- $r1=0;$r2=0;$r3=0;$r4=0;$r5=0;$r6=0;$r7=0;$r8=0;$r9=0;$r10=0;$r11=0;$r12=0;$r13=0;
- $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
- $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
- $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
- $s1=0;
- $m1=0;
- foreach ($staffList as $value){
- if ($vlu['cid']==$value['cid']){
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- if(!empty($receiptCollectList)){
-
- $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
-
- $html="";
- $psum=0;
- $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='日常相关费用'){
-
- if($v['item']==$va){
- if ($va=='市内交通费')
- $r1+=$v['price'];
- if ($va=='市内出租费')
- $r2+=$v['price'];
- if ($va=='办事处房租')
- $r3+=$v['price'];
- if ($va=='电话费')
- $r4+=$v['price'];
- if ($va=='水费')
- $r5+=$v['price'];
- if ($va=='电费')
- $r6+=$v['price'];
- if ($va=='办公费用')
- $r7+=$v['price'];
- if ($va=='邮寄费')
- $r8+=$v['price'];
- if ($va=='其他费用')
- $r9+=$v['price'];
- if ($va=='车辆费用')
- $r10+=$v['price'];
- if ($va=='广告费')
- $r11+=$v['price'];
- if ($va=='团队建设费')
- $r13+=$v['price'];
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
- $r12+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['日常相关费用']=$psum.$html;
-
- /*-----------------------------------*/
-
- $html="";
- $psum=0;
- $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='差旅相关费用'){
-
- if($v['item']==$va){
- if ($va=='往来交通费')
- $c1+=$v['price'];
- if ($va=='市内交通费')
- $c2+=$v['price'];
- if ($va=='出差住宿费')
- $c3+=$v['price'];
- if ($va=='出差补助')
- $c4+=$v['price'];
- if ($va=='其他费用')
- $c5+=$v['price'];
-
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $c6+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['差旅相关费用']=$psum.$html;
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='培训班费用'){
-
- if($v['item']==$va){
-
- if ($va=='场租费')
- $p1+=$v['price'];
- if ($va=='薪酬')
- $p2+=$v['price'];
- if ($va=='住宿费')
- $p3+=$v['price'];
- if ($va=='交通费')
- $p4+=$v['price'];
- if ($va=='餐饮费')
- $p5+=$v['price'];
- if ($va=='办公费')
- $p6+=$v['price'];
- if ($va=='公关费')
- $p7+=$v['price'];
- if ($va=='其他')
- $p8+=$v['price'];
-
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $p9+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['培训班费用']=$psum.$html;
-
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('公关费','广告费','借款','可自加费用');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='其他'){
-
- if($v['item']==$va){
- if ($va=='公关费')
- $t1+=$v['price'];
- if ($va=='广告费')
- $t2+=$v['price'];
- if ($va=='借款')
- $t3+=$v['price'];
- if ($va=='可自加费用')
- $t4+=$v['price'];
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $t5+=$psum;
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['其他']=$psum.$html;
-
- /*-------------------------------------*/
- $html="";
- $psum=0;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='报销金额调整'){
-
- if (!empty($v['price'])){
- $psum+=$v['price'];
- }
- }
- }
- $s1+=$psum;
- if(!empty($psum))
- $psum='<td class="taR colOrange">¥'.$psum.'</td>';
- else
- $psum='<td class="taR colOrange">-</td>';
- $receiptL['报销金额调整']=$psum.$html;
-
- }else{
- $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
- }
-
- $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
-
- if(!empty($monthStaffPrice[0]['price'])){
- $m1+=$monthStaffPrice[0]['price'];
- $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
- }else
- $receiptL['monthStaffPrice']='<td><b>-</b></td>';
- $list[$value['username']]=$receiptL;
-
-
- }
- }
- $receiptL['日常相关费用']='<td class="colGreen taR">'.$r12.'</td><td class="taR">'.$r1.'</td><td class="taR">'.$r2.'</td><td class="taR">'.$r3.'</td><td class="taR">'.$r4.'</td><td class="taR">'.$r5.'</td>
- <td class="taR">'.$r6.'</td><td class="taR">'.$r7.'</td><td class="taR">'.$r8.'</td><td class="taR">'.$r9.'</td><td class="taR">'.$r10.'</td><td class="taR">'.$r11.'</td><td class="taR">'.$r13.'</td>';
- $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
- <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
- $receiptL['培训班费用']='<td class="colGreen taR">'.$p9.'</td><td class="taR">'.$p1.'</td><td class="taR">'.$p2.'</td><td class="taR">'.$p3.'</td><td class="taR">'.$p4.'</td>
- <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
- $receiptL['其他']='<td class="colGreen taR">'.$t5.'</td><td class="taR">'.$t1.'</td><td class="taR">'.$t2.'</td><td class="taR">'.$t3.'</td><td class="taR">'.$t4.'</td>';
- $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
- $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
- $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
- }
- $data['list']=$list;
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
-
- //statistics html
- $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
- 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $monthHtml="";
- for ($i=1;$i<=12;$i++){
- if ($i==$month)
- $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
- else
- $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
- }
-
- $data['monthHtml']=$monthHtml;
- $data['year']=$year;
- $data['month']=$month;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- $this->render ( "/admin/staffCollectMonthDetail2", $data );
- //$this->render ( "/admin/saeaStaffCollectDetail", $data );
- }
-
- function companyMonthCollectDetail(){
-
- $year=$this->get_args('year')?$this->get_args('year'):"";
- $month=$this->get_args('month')?$this->get_args('month'):"";
- if(!$year)
- $year=isset($this->params['year'])?$this->params['year']:date("Y");
- if(!$month)
- $month=isset($this->params['month'])?$this->params['month']:1;
-
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel('L_category');
- $lCategory=new L_category();
-
- $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
-
- $categoryList=$lCategory->find(array('asArray'=>true));
-
- $list=array();
- foreach ($categoryList as $value){
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'cid='.$value['cid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- if(!empty($receiptCollectList)){
-
- $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
- $html="";
- $psum=0;
- $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='日常相关费用'){
-
- if($v['item']==$va){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['日常相关费用']=$psum.$html;
-
- /*-----------------------------------*/
-
- $html="";
- $psum=0;
- $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='差旅相关费用'){
-
- if($v['item']==$va){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['差旅相关费用']=$psum.$html;
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='培训班费用'){
-
- if($v['item']==$va){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['培训班费用']=$psum.$html;
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('公关费','广告费','借款','可自加费用');
- foreach ($item as $va){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='其他'){
-
- if($v['item']==$va){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['其他']=$psum.$html;
-
- /*-------------------------------------*/
- $html="";
- $psum=0;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='报销金额调整'){
-
- if (!empty($v['price']))
- $psum+=$v['price'];
- }
- }
-
- if(!empty($psum))
- $psum='<td class="taR colOrange">¥'.$psum.'</td>';
- else
- $psum='<td class="taR colOrange">-</td>';
- $receiptL['报销金额调整']=$psum.$html;
- }else{
- $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
- }
-
- $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'cid='.$value['cid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
-
- if(!empty($monthStaffPrice[0]['price']))
- $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
- else
- $receiptL['monthStaffPrice']='<td><b>-</b></td>';
- $list[$value['title']]=$receiptL;
- }
-
- $data['list']=$list;
-
-
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
-
-
-
- //statistics html
- $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
- 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $monthHtml="";
- for ($i=1;$i<=12;$i++){
- if ($i==$month)
- $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
- else
- $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
- }
-
- $data['monthHtml']=$monthHtml;
- $data['year']=$year;
- $data['month']=$month;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
-
-
- $this->render ( "/admin/companyMonthCollectDetail", $data );
- }
-
- function staffCollectDetail(){
- $year=$this->get_args('year')?$this->get_args('year'):date("Y");
- $staffname=$this->get_args('username')?$this->get_args('username'):"";
- $pcid=$this->get_args('category')?$this->get_args('category'):"";
- if(!$staffname){
- $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
- $staffname= urldecode($staffname);
- }
-
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel("receiptDetail");
- $receiptDetail=new receiptDetail();
- Doo::loadModel('accountItem');
- $accountItem=new accountItem();
- Doo::loadModel('statistics');
- $statistics=new statistics();
- Doo::loadModel('L_category');
- $lCategory=new L_category();
-
- $staffList=$staff->find(array('asArray'=>true));
-
- $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
- foreach ($staffList as $value){
- if ($value['username']==$staffname&&$value['username']!='admin'){
- $stTitle=$value['category'].'-'.$value['username'];
- $staffId=$value['sid'];
- $cid=$value['cid'];
- $ocid=$value['cid'];
- if (!empty($value['othercid']))
- $cid=$value['cid'].','.$value['othercid'];
- $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
- }elseif ($value['username']!='admin')
- $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
- }
- $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
- if(empty($pcid))
- $pcid=$ocid;
-
- $data['ocid']=$pcid;
-
- $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
- $this->showCache($path);
-
- //
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
-
- $accountList=$accountItem->find(array('asArray'=>true));
- //create CollectDetail HTML
- $collectHtml=array();
- foreach ($accountList as $key=>$value){
- $html="";$asum=0;
- for ($i=1;$i<=12;$i++){
- $falg=true;
- foreach ($receiptCollectList as $v) {
- if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
- $asum+=$v['price'];
- $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
- $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
- $collectHtml[$value['category']][$value['name']]=$html;
- }
- $data['collectHtml']=$collectHtml;
-
- //create Adjustment price html
- $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
- 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
-
- $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
- $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
- array_push($collectArray['日常相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
- array_push($collectArray['差旅相关费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
- array_push($collectArray['培训班费用'], $collectHtml);
-
- $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
- array_push($collectArray['其他'], $collectHtml);
- $data['collectArray']=$collectArray;
-
- $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
- array_push($adjustment, $collectHtml);
- $data['adjustment']=$adjustment;
-
- //total price html
- $collectHtml="";$total=0;
- for ($i=1;$i<=12;$i++){
- $sumPrice=0;
- foreach ($receiptCollectList as $key=>$value){
- if($value['month']==$i){
- $sumPrice+=$value['price'];
- }
- }
- if ($sumPrice==0)
- $collectHtml.='<td class="taR">-</td>';
- else
- $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
- $total+=$sumPrice;
- }
- $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
-
- //statistics html
- $stList=$statistics->statisticsByYear($year,$staffId);
- if(empty($stList))
- $stList=array('rePrice'=>0,'agPrice'=>0);
- $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
-
- $data['totalPrice']=$collectHtml;
- $data['totalYear']=$total;
-
- $data['stHtml']=$stHtml;
- $data['year']=$year;
- $data['stTitle']=$stTitle;
-
- $data['memu']="receipt";
- $data['staff']=$this->staff;
- $data['receiptMemu']='companyCategoryCollect';
- $data['verifyId']=$this->verifyId;
-
- if ($year<date("Y")){
- Doo::loadModel('receipt');
- $receipt=new receipt();
- $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
- if(empty($receiptList)){ //generated files
- ob_start();
- $this->render ( "/admin/saeaStaffCollectDetail", $data );
- $this->cacheFile($path);die;
- }
- }
-
- $this->render ( "/admin/saeaStaffCollectDetail", $data );
- }
-
- function _getMonthCollectDetail($receiptCollectList){
-
- if(!empty($receiptCollectList)){
-
- $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
-
- $html="";
- $psum=0;
- $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
- foreach ($item as $value){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='日常相关费用'){
-
- if($v['item']==$value){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['日常相关费用']=$psum.$html;
-
- /*-----------------------------------*/
-
- $html="";
- $psum=0;
- $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
- foreach ($item as $value){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='差旅相关费用'){
- if($v['item']==$value){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['差旅相关费用']=$psum.$html;
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
- foreach ($item as $value){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='培训班费用'){
- if($v['item']==$value){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
-
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['培训班费用']=$psum.$html;
- /*-------------------------------------*/
- $html="";
- $psum=0;
- $item=array('公关费','广告费','借款','可自加费用');
- foreach ($item as $value){
- $falg=true;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='其他'){
- if($v['item']==$value){
- $psum+=$v['price'];
- $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
- }
- }
- }
- if($falg)
- $html.='<td class="taR">-</td>';
- }
-
- if(!empty($psum))
- $psum='<td class="colGreen taR">¥'.$psum.'</td>';
- else
- $psum='<td class="colGreen taR">-</td>';
- $receiptL['其他']=$psum.$html;
-
- /*-------------------------------------*/
- $html="";
- $psum=0;
- foreach ($receiptCollectList as $v){
- if($v['itemCategory']=='报销金额调整'){
-
- if (!empty($v['price']))
- $psum+=$v['price'];
- }
- }
-
- if(!empty($psum))
- $psum='<td class="taR colOrange">¥'.$psum.'</td>';
- else
- $psum='<td class="taR colOrange">-</td>';
- $receiptL['报销金额调整']=$psum.$html;
- }else{
- $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
- <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
- $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
- }
- return $receiptL;
- }
-
- function eMail(){
- Doo::loadModel('staff');
- $staff=new staff();
- Doo::loadModel('receipt');
- $receipt=new receipt();
- Doo::loadModel('L_category');
- $Lcategory=new L_category();
- Doo::loadModel("verify");
- $verify=new verify();
-
- $staffList=$staff->find(array('asArray'=>true));
-
- foreach ($staffList as $key=>$value){
-
- if($value['username']!='admin'){
- //提交人
-
- $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
- if(!empty($receiptList)){
-
- $html='<br><div><style></style>
- <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
- <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
- <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
- <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
- </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
- <tbody><tr>
- <td style="padding: 0 40px;" align="left">
- <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
- </td></tr><tr>
- <td style="padding: 0 40px;" align="left"><p style="margin-top:0px;margin-bottom:40px;color:#383838;font-size:20px;line-height:32px;">美好的一天从今天开始,您需要关注以下事项:</p></td>
- </tr>
- </tbody> </table></td> </tr> <tr><td>
- <table style="background-color:#f5f6f7;width:100%;padding:0 0 20px;border-left:1px solid #ddd;border-right:1px solid #ddd;" cellpadding="0" cellspacing="0" align="left">
- <tbody> <tr><td>
- <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
- 以下报销单完成了审批,等着收款吧:</p>
- </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
- foreach ($receiptList as $k=>$v){
- $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
- $html.='
- <tr>
- <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
- <td align="left">
- <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
- <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
- <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
- <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
- </tr>';
- }
-
- $html.=' </tbody></table></td></tr></tbody></table></td></tr>
- <tr><td style="height:150px;border:1px solid #ddd;border-top:none;background-color:#fff;" align="center"><a href="http://cld.smartcost.com.cn/approval" style="display:block;height:50px;width:260px;background-color:#0390ff;font-weight:normal;font-size:18px;color:white;line-height:50px;text-align:center;text-decoration:none;border-radius:3px;">立即登录</a></td>
- </tr></tbody></table></td> </tr></tbody></table> </div><br>';
-
- if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
- $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
- $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
- $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
- $receipt=new receipt();
- $receipt->notice=1;
- $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
- }
- }
-
- //审批人
- $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
- $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
- <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
- <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
- <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
- </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
- <tbody><tr><td style="padding: 0 40px;" align="left">
- <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
- </td></tr><tr><td style="padding: 0 40px;" align="left"><p style="margin-top:0px;margin-bottom:40px;color:#383838;font-size:20px;line-height:32px;">美好的一天从今天开始,您需要关注以下事项:</p></td>
- </tr></tbody></table></td> </tr> <tr><td><table style="background-color:#f5f6f7;width:100%;padding:0 0 20px;border-left:1px solid #ddd;border-right:1px solid #ddd;" cellpadding="0" cellspacing="0" align="left">
- <tbody><tr><td><p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">以下报销单需要您的审批:</p></td>
- </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
-
- foreach ($verifyList as $k=>$v){
- $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
- foreach ($receiptList as $r=>$l){
- $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
- $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
- $html.='
- <tr>
- <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
- <td align="left">
- <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
- <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
- <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
- <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
- </tr>';
- }
-
- }
- $html.='
- </tbody></table></td></tr> </tbody></table></td></tr><tr>
- <td style="height:150px;border:1px solid #ddd;border-top:none;background-color:#fff;" align="center"><a href="http://cld.smartcost.com.cn/approval" style="display:block;height:50px;width:260px;background-color:#0390ff;font-weight:normal;font-size:18px;color:white;line-height:50px;text-align:center;text-decoration:none;border-radius:3px;">立即登录</a></td>
- </tr></tbody></table></td></tr></tbody></table></div><br>';
-
- if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
- $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
- // $receipt=new receipt();
- // $receipt->notice=1;
- // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
- }
-
- }
- }
- }
-
- // Email发送函数
- function SMail($toemail, $subject, $contents) {
- Doo::loadClass('class.phpmailer');
- $mail = new PHPMailer();
- $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
- $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
- $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
- $mail->Password = "cDO1GjtY1seH"; //密码
- $mail->CharSet = "UTF8";
- $mail->SMTPAuth = true;
- $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
- $mail->Mailer = "smtp";
- $mail->Port = 25;
- $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
- $mail->MsgHTML($contents);
- $mail->AddAddress($toemail);
- $mail->CharSet = "UTF-8";
- return $mail->Send();
- }
- /**
- * 获取get或者POST值
- * @param string $name 属性名称
- * @return fixed 值
- */
- function get_args($name) {
- if (isset ( $_GET [$name] )) {
- if (is_array ( $_GET [$name] ))
- return $_GET [$name];
- else
- return addslashes ( $_GET [$name] );
-
- } elseif (isset ( $_POST [$name] )) {
- if (is_array ( $_POST [$name] ))
- return $_POST [$name];
- else
- return addslashes ( $_POST [$name] );
- } else
- return false;
- }
- }
- ?>
|