ReceiptController.php 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public static $NEW = 0;
  9. public $AGENCY="日常相关费用";
  10. public $TRAVEL="差旅相关费用";
  11. public $TRAIN="培训班费用";
  12. public $OTHER="其他";
  13. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  14. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  15. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  16. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  17. private function showCache($path){
  18. if(file_exists($path)){
  19. echo "<!DOCTYPE html>";
  20. include $path;die;
  21. }
  22. }
  23. private function cacheFile($path){
  24. $content = ob_get_contents();
  25. $fp = fopen($path, "w");
  26. fwrite($fp, $content);
  27. fclose($fp);
  28. }
  29. private function getReceiptCount(){
  30. $status=2;
  31. $year=date('Y');
  32. Doo::loadModel('receipt');
  33. $receipt=new receipt();
  34. Doo::loadModel('verify');
  35. $verify=new verify();
  36. //user verify ID
  37. $vidList=array();
  38. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
  39. foreach ($verifyDetail as $key=>$value){
  40. array_push($vidList, $value['vid']);
  41. }
  42. $vid=implode(",", $vidList);
  43. if(empty($verifyDetail))
  44. $vid=0;
  45. $dateCondition=" and Year(date) =".$year;
  46. $approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  47. $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  48. return count($receiptList);
  49. }
  50. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  51. $collectHtml="";$sumPrice=0.00;
  52. for ($i=1;$i<=12;$i++){
  53. $falg=true;
  54. foreach ($receiptCollectList as $key=>$value){
  55. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  56. $sumPrice+=$value['price'];
  57. if ($classType=="b"){
  58. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  59. }else{
  60. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  61. }
  62. }
  63. }
  64. if ($falg)
  65. $collectHtml.='<td class="taR">-</td>';
  66. }
  67. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  68. return $collectHtml;
  69. }
  70. function __construct() {
  71. if(isset($_COOKIE["staff"])){
  72. if(!empty($_COOKIE["staff"])){
  73. Doo::loadModel ( 'staff' );
  74. Doo::loadModel('verify');
  75. $verify=new verify();
  76. $staff = new staff ();
  77. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  78. $list=array();
  79. foreach ($verifyList as $key=>$value){
  80. $ver=json_decode($value['staff']);
  81. foreach ($ver as $k=>$v){
  82. array_push($list, $v[0]);
  83. }
  84. }
  85. $this->verifyId=$list;
  86. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  87. self::$NEW= $this->getReceiptCount();
  88. return "/";
  89. }
  90. }
  91. Doo::loadCore ( 'uri/DooUriRouter' );
  92. $router = new DooUriRouter ();
  93. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  94. if($routeRs['1']!="login"){
  95. header ( 'Content-Type:text/html;charset=utf-8' );
  96. @header ( "Location: /login" );
  97. }
  98. }
  99. function myReceipt(){
  100. //all approval past withdraw
  101. $item=isset($this->params['item'])?$this->params['item']:"";
  102. if(empty($item))
  103. $item=$this->get_args('item')?$this->get_args('item'):"";
  104. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  105. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  106. Doo::loadModel('receipt');
  107. $receipt=new receipt();
  108. //pre-loaded
  109. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  110. //have cache
  111. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  112. if(!empty($moth))//yearPage
  113. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  114. $this->showCache($path);
  115. }
  116. Doo::loadModel('L_category');
  117. $Lcategory=new L_category();
  118. Doo::loadModel('verify');
  119. Doo::loadModel('statistics');
  120. $statistics=new statistics();
  121. $verify=new verify();
  122. $condition=" and status!=4 ";
  123. if($item=="approval")
  124. $condition=" and status=2 ";
  125. elseif ($item=="withdraw")
  126. $condition=" and status=3 ";
  127. elseif ($item=="past")
  128. $condition=" and status=1 ";
  129. $dateCondition=" and Year(date) =".$year;
  130. if(!empty($moth)){
  131. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  132. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  133. }else
  134. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  135. if(empty($stList))
  136. $stList=array('rePrice'=>0,'agPrice'=>0);
  137. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  138. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  139. foreach ($receiptList as $key=>$vlaue){
  140. $receiptList[$key]['accountItem']=json_decode($vlaue['accountItem'],true);
  141. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$vlaue['cid'],'asArray'=>true));
  142. $receiptList[$key]['category']=$categoryDetil['title'];
  143. $verifyList=$verify->getOne(array('where'=>'vid='.$vlaue['verify'],'asArray'=>true));
  144. $verifyList=json_decode($verifyList['staff']);//status opinion
  145. $verifyStaff=json_decode($vlaue['verifyStaff'],true);
  146. foreach ($verifyList as $k=>$v){
  147. //init verifyStaff
  148. $verifyList[$k]['date']="";
  149. $verifyList[$k]['opinion']="";
  150. $verifyList[$k]['status']="";
  151. if (empty($verifyStaff)){
  152. $verifyList[$k]['date']="";
  153. $verifyList[$k]['opinion']="";
  154. if ($v[0]==$this->staff[0]['sid'])
  155. $verifyList[$k]['status']=4;
  156. }else{
  157. foreach ($verifyStaff as $m=>$u){
  158. if ($v[0]==$m){
  159. $verifyList[$k]['date']=$u['date'];
  160. $verifyList[$k]['opinion']=$u['opinion'];
  161. $verifyList[$k]['status']=$u['status'];
  162. break;
  163. }
  164. }
  165. }
  166. }
  167. $receiptList[$key]['verifyList']=$verifyList;
  168. }
  169. //print_r($receiptList);die;
  170. $mothHtml="";
  171. for($i=1;$i<=12;$i++){
  172. if($moth==$i)
  173. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  174. else
  175. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  176. }
  177. $data['mothHtml']=$mothHtml;
  178. $data['receiptList']=$receiptList;
  179. $data['memu']="receipt";
  180. $data['staff']=$this->staff;
  181. $data['receiptMemu']='receipt';
  182. $data['verifyId']=$this->verifyId;
  183. $data['item']=$item;
  184. $data['year']=$year;
  185. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  186. //sufficient condition to generate cache
  187. if(empty($moth)&&($year<date("Y"))){
  188. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  189. if(empty($receiptList)){ //generated files
  190. ob_start();
  191. $this->render ( "/admin/saea_myList", $data );
  192. $this->cacheFile($path);die;
  193. // $content = ob_get_contents();
  194. // $fp = fopen($path, "w");
  195. // fwrite($fp, $content);
  196. // fclose($fp);
  197. }
  198. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  199. $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));
  200. if(empty($receiptList)){ //generated files
  201. ob_start();
  202. $this->render ( "/admin/saea_myList", $data );
  203. $this->cacheFile($path);die;
  204. }
  205. }
  206. }
  207. $this->render ( "/admin/saea_myList", $data );
  208. }
  209. function saeaCreate(){
  210. Doo::loadModel('accountItem');
  211. Doo::loadModel('verify');
  212. Doo::loadModel('receipt');
  213. Doo::loadModel('L_category');
  214. $lCategory=new L_category();
  215. $receipt=new receipt();
  216. $verify=new verify();
  217. $accountItem=new accountItem();
  218. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  219. // if(!empty($receiptDetail))
  220. // return "/referReceipt/".$receiptDetail['rid'];
  221. $acItem=$accountItem->find(array('asArray'=>true));
  222. $veList=$verify->find(array('asArray'=>true));
  223. foreach ($veList as $key=>$value){
  224. $veList[$key]['staff']=json_decode($value['staff']);
  225. }
  226. $data['category']=$lCategory->find(array('asArray'=>true));
  227. $data['veList']=$veList;
  228. $data['acItem']=$acItem;
  229. $data['memu']="receipt";
  230. $data['staff']=$this->staff;
  231. $data['receiptMemu']='saeaCreate';
  232. $data['verifyId']=$this->verifyId;
  233. $this->render ( "/admin/saea_create", $data );
  234. }
  235. function addReceipt(){
  236. $agency=$this->get_args('agency');
  237. $travel=$this->get_args('travel');
  238. $train=$this->get_args('train');
  239. $other=$this->get_args('other');
  240. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  241. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  242. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  243. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  244. Doo::loadModel('receipt');
  245. Doo::loadModel('receiptDetail');
  246. Doo::loadModel('accountItem');
  247. $accountItem=new accountItem();
  248. $receipt=new receipt();
  249. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  250. // if(!empty($receiptDetail))
  251. // return "/referReceipt/".$receiptDetail['rid'];
  252. $aItem=$accountItem->find(array('asArray'=>true));
  253. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  254. $ag=$tr=$ta=$ot=0;
  255. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  256. foreach ($aItem as $key=>$value){
  257. if ($value['category']==$this->AGENCY){
  258. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  259. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  260. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  261. }
  262. $ag++;
  263. }
  264. if($value['category']==$this->TRAVEL){
  265. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  266. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  267. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  268. }
  269. $tr++;
  270. }
  271. if($value['category']==$this->TRAIN){
  272. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  273. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  274. $sum+=$train[$ta];$trainSum+=$train[$ta];
  275. }
  276. $ta++;
  277. }
  278. if($value['category']==$this->OTHER){
  279. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  280. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  281. $sum+=$other[$ot];$otherSum+=$other[$ot];
  282. }
  283. $ot++;
  284. }
  285. }
  286. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  287. //报销单
  288. $receipt->accountItem=json_encode($accountJson);
  289. $receipt->staff=$this->staff[0]['sid'];
  290. $receipt->sum=number_format($sum, 2, '.', '');
  291. $receipt->date=date("Y-m-d");
  292. $receipt->cid=$cid;
  293. $receipt->status=4;
  294. $receipt->verify=$verify;
  295. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  296. $receipt->explanation=$explanation;
  297. $rid=$receipt->insert();
  298. //报销详情
  299. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  300. $receiptDetail=new receiptDetail();
  301. $receiptDetail->staff=$this->staff[0]['sid'];
  302. $receiptDetail->item=$value['name'];
  303. $receiptDetail->itemCategory=$this->AGENCY;
  304. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  305. $receiptDetail->date=date("Y-m-d");
  306. $receiptDetail->cid=$cid;
  307. $receiptDetail->rid=$rid;
  308. $receiptDetail->status=4;
  309. $receiptDetail->insert();
  310. }
  311. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  312. $receiptDetail=new receiptDetail();
  313. $receiptDetail->staff=$this->staff[0]['sid'];
  314. $receiptDetail->item=$value['name'];
  315. $receiptDetail->itemCategory=$this->TRAVEL;
  316. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  317. $receiptDetail->date=date("Y-m-d");
  318. $receiptDetail->cid=$cid;
  319. $receiptDetail->rid=$rid;
  320. $receiptDetail->status=4;
  321. $receiptDetail->insert();
  322. }
  323. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  324. $receiptDetail=new receiptDetail();
  325. $receiptDetail->staff=$this->staff[0]['sid'];
  326. $receiptDetail->item=$value['name'];
  327. $receiptDetail->itemCategory=$this->TRAIN;
  328. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  329. $receiptDetail->date=date("Y-m-d");
  330. $receiptDetail->cid=$cid;
  331. $receiptDetail->rid=$rid;
  332. $receiptDetail->status=4;
  333. $receiptDetail->insert();
  334. }
  335. foreach ($accountJson[$this->OTHER] as $key=>$value){
  336. $receiptDetail=new receiptDetail();
  337. $receiptDetail->staff=$this->staff[0]['sid'];
  338. $receiptDetail->item=$value['name'];
  339. $receiptDetail->itemCategory=$this->OTHER;
  340. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  341. $receiptDetail->date=date("Y-m-d");
  342. $receiptDetail->cid=$cid;
  343. $receiptDetail->rid=$rid;
  344. $receiptDetail->status=4;
  345. $receiptDetail->insert();
  346. }
  347. return "/referReceipt/".$rid;
  348. }
  349. return "/saeaCreate";
  350. }
  351. function referReceipt(){
  352. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  353. Doo::loadModel('receipt');
  354. Doo::loadModel('verify');
  355. $verify=new verify();
  356. $receipt=new receipt();
  357. Doo::loadModel('L_category');
  358. $lCategory=new L_category();
  359. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 ','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/addReceipt";
  362. foreach ($receiptDetail as $key=>$value){
  363. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  364. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  365. $v=json_decode($veList['staff']);
  366. array_push($v[0], $veList['description']);
  367. $receiptDetail[$key]['staff']=$v;
  368. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  369. $receiptDetail[$key]['category']=$category['title'];
  370. }
  371. $data['receiptDetail']=$receiptDetail;
  372. $data['memu']="receipt";
  373. $data['staff']=$this->staff;
  374. $data['receiptMemu']='saeaCreate';
  375. $data['verifyId']=$this->verifyId;
  376. $this->render ( "/admin/saea_confirm", $data );
  377. }
  378. function editReceipt(){
  379. //edit status 4
  380. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  381. //echo $rid;
  382. Doo::loadModel('accountItem');
  383. Doo::loadModel('verify');
  384. Doo::loadModel('receipt');
  385. $receipt=new receipt();
  386. $verify=new verify();
  387. $accountItem=new accountItem();
  388. Doo::loadModel('L_category');
  389. $lCategory=new L_category();
  390. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 and rid='.$rid,'asArray'=>true));
  391. if(empty($receiptDetail))
  392. return "/saeaCreate";
  393. $acItem=$accountItem->find(array('asArray'=>true));
  394. $veList=$verify->find(array('asArray'=>true));
  395. foreach ($veList as $key=>$value){
  396. $veList[$key]['staff']=json_decode($value['staff']);
  397. }
  398. //配置编辑信息
  399. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  400. foreach ($acItem as $key=>$value){
  401. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  402. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  403. $acItem[$key]['price']=$v['price'];
  404. }
  405. }
  406. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  407. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  408. $acItem[$key]['price']=$v['price'];
  409. }
  410. }
  411. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  412. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  413. $acItem[$key]['price']=$v['price'];
  414. }
  415. }
  416. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  417. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  418. $acItem[$key]['price']=$v['price'];
  419. }
  420. }
  421. }
  422. $data['category']=$lCategory->find(array('asArray'=>true));
  423. $data['cSum']=$accountItemList['cSum'];
  424. $data['sum']=$receiptDetail['sum'];
  425. $data['receiptDetail']=$receiptDetail;
  426. $data['veList']=$veList;
  427. $data['acItem']=$acItem;
  428. $data['memu']="receipt";
  429. $data['staff']=$this->staff;
  430. $data['receiptMemu']='saeaCreate';
  431. $data['verify']=$receiptDetail['verify'];
  432. $data['verifyId']=$this->verifyId;
  433. $data['rid']=$rid;
  434. $this->render ( "/admin/saea_edit", $data );
  435. }
  436. function updateReceipt(){
  437. $agency=$this->get_args('agency');
  438. $travel=$this->get_args('travel');
  439. $train=$this->get_args('train');
  440. $other=$this->get_args('other');
  441. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  442. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  443. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  444. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  445. if(!empty($verify)&&!empty($explanation)){
  446. Doo::loadModel('receipt');
  447. Doo::loadModel('receiptDetail');
  448. Doo::loadModel('accountItem');
  449. $accountItem=new accountItem();
  450. $receipt=new receipt();
  451. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 and rid='.$rid,'asArray'=>true));
  452. if(empty($receiptDetail))
  453. return "/saeaCreate";
  454. $aItem=$accountItem->find(array('asArray'=>true));
  455. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  456. $ag=$tr=$ta=$ot=0;
  457. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  458. foreach ($aItem as $key=>$value){
  459. if ($value['category']==$this->AGENCY){
  460. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  461. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  462. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  463. }
  464. $ag++;
  465. }
  466. if($value['category']==$this->TRAVEL){
  467. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  468. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  469. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  470. }
  471. $tr++;
  472. }
  473. if($value['category']==$this->TRAIN){
  474. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  475. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  476. $sum+=$train[$ta];$trainSum+=$train[$ta];
  477. }
  478. $ta++;
  479. }
  480. if($value['category']==$this->OTHER){
  481. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  482. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  483. $sum+=$other[$ot];$otherSum+=$other[$ot];
  484. }
  485. $ot++;
  486. }
  487. }
  488. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  489. //报销单
  490. $rid=$receipt->rid=$receiptDetail['rid'];
  491. $receipt->accountItem=json_encode($accountJson);
  492. $receipt->staff=$this->staff[0]['sid'];
  493. $receipt->sum=number_format($sum, 2, '.', '');
  494. $receipt->date=date("Y-m-d");
  495. $receipt->cid=$cid;
  496. $receipt->status=4;
  497. $receipt->verify=$verify;
  498. $receipt->explanation=$explanation;
  499. $receipt->update();
  500. $receiptDetail=new receiptDetail();
  501. $receiptDetail->delete(array('where'=>'rid='.$rid));
  502. //报销详情
  503. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  504. $receiptDetail=new receiptDetail();
  505. $receiptDetail->staff=$this->staff[0]['sid'];
  506. $receiptDetail->item=$value['name'];
  507. $receiptDetail->itemCategory=$this->AGENCY;
  508. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  509. $receiptDetail->date=date("Y-m-d");
  510. $receiptDetail->cid=$cid;
  511. $receiptDetail->rid=$rid;
  512. $receiptDetail->status=4;
  513. $receiptDetail->insert();
  514. }
  515. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  516. $receiptDetail=new receiptDetail();
  517. $receiptDetail->staff=$this->staff[0]['sid'];
  518. $receiptDetail->item=$value['name'];
  519. $receiptDetail->itemCategory=$this->TRAVEL;
  520. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  521. $receiptDetail->date=date("Y-m-d");
  522. $receiptDetail->cid=$cid;
  523. $receiptDetail->rid=$rid;
  524. $receiptDetail->status=4;
  525. $receiptDetail->insert();
  526. }
  527. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  528. $receiptDetail=new receiptDetail();
  529. $receiptDetail->staff=$this->staff[0]['sid'];
  530. $receiptDetail->item=$value['name'];
  531. $receiptDetail->itemCategory=$this->TRAIN;
  532. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  533. $receiptDetail->date=date("Y-m-d");
  534. $receiptDetail->cid=$cid;
  535. $receiptDetail->rid=$rid;
  536. $receiptDetail->status=4;
  537. $receiptDetail->insert();
  538. }
  539. foreach ($accountJson[$this->OTHER] as $key=>$value){
  540. $receiptDetail=new receiptDetail();
  541. $receiptDetail->staff=$this->staff[0]['sid'];
  542. $receiptDetail->item=$value['name'];
  543. $receiptDetail->itemCategory=$this->OTHER;
  544. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  545. $receiptDetail->date=date("Y-m-d");
  546. $receiptDetail->cid=$cid;
  547. $receiptDetail->rid=$rid;
  548. $receiptDetail->status=4;
  549. $receiptDetail->insert();
  550. }
  551. return "/referReceipt/".$rid;
  552. }
  553. return "/editReceipt/1";
  554. }
  555. function approvedReceipt(){
  556. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  557. Doo::loadModel('receipt');
  558. Doo::loadModel('receiptDetail');
  559. $receipt=new receipt();
  560. $receiptDetail=new receiptDetail();
  561. Doo::loadModel('statistics');
  562. Doo::loadModel('itemStatistics');
  563. $statistics=new statistics();
  564. $itemStatistics=new itemStatistics();
  565. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4 and rid='.$rid,'asArray'=>true));
  566. if(empty($receiptDetailList))
  567. return "/saeaCreate";
  568. $receipt->rid=$receiptDetailList['rid'];
  569. $receipt->status=2;
  570. $receipt->update();
  571. $receiptDetail->status=2;
  572. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  573. //statistics item
  574. $dateArray=explode("-", $receiptDetailList['date']);
  575. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  576. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  577. //print_r($accountItem['cSum']['agencySum']);die;
  578. // foreach ($accountItem['cSum'] as $key=>$value){
  579. // if($key=="agencySum"){
  580. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  581. // if(empty($iStatistics)){
  582. // $itemStatistics->cid=$this->staff[0]['cid'];
  583. // $itemStatistics->staff=$this->staff[0]['sid'];
  584. // $itemStatistics->price=$value;
  585. // $itemStatistics->itemCategory=$this->AGENCY;
  586. // $itemStatistics->date=date("Y-m-d");
  587. // $itemStatistics->insert();
  588. // }else{
  589. // if (!empty($value)){
  590. // $itemStatistics->price=$value+$iStatistics['price'];
  591. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  592. // }
  593. // }
  594. // }elseif($key=="travelSum"){
  595. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  596. // if(empty($iStatistics)){
  597. // $itemStatistics->cid=$this->staff[0]['cid'];
  598. // $itemStatistics->staff=$this->staff[0]['sid'];
  599. // $itemStatistics->price=$value;
  600. // $itemStatistics->itemCategory=$this->TRAVEL;
  601. // $itemStatistics->date=date("Y-m-d");
  602. // $itemStatistics->insert();
  603. // }else{
  604. // if (!empty($value)){
  605. // $itemStatistics->price=$value+$iStatistics['price'];
  606. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  607. // }
  608. // }
  609. // }elseif($key=="trainSum"){
  610. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  611. // if(empty($iStatistics)){
  612. // $itemStatistics->cid=$this->staff[0]['cid'];
  613. // $itemStatistics->staff=$this->staff[0]['sid'];
  614. // $itemStatistics->price=$value;
  615. // $itemStatistics->itemCategory=$this->TRAIN;
  616. // $itemStatistics->date=date("Y-m-d");
  617. // $itemStatistics->insert();
  618. // }else{
  619. // if (!empty($value)){
  620. // $itemStatistics->price=$value+$iStatistics['price'];
  621. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  622. // }
  623. // }
  624. // }elseif($key=="otherSum"){
  625. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  626. // if(empty($iStatistics)){
  627. // $itemStatistics->cid=$this->staff[0]['cid'];
  628. // $itemStatistics->staff=$this->staff[0]['sid'];
  629. // $itemStatistics->price=$value;
  630. // $itemStatistics->itemCategory=$this->OTHER;
  631. // $itemStatistics->date=date("Y-m-d");
  632. // $itemStatistics->insert();
  633. // }else{
  634. // if (!empty($value)){
  635. // $itemStatistics->price=$value+$iStatistics['price'];
  636. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  637. // }
  638. // }
  639. // }
  640. // }
  641. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  642. if(empty($stat)){
  643. $statistics->date=date("Y-m-d");
  644. $statistics->cid=$this->staff[0]['cid'];
  645. $statistics->staff=$this->staff[0]['sid'];
  646. $statistics->agPrice=0;
  647. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  648. $statistics->insert();
  649. }else{
  650. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  651. $statistics->update(array('where'=>'sid='.$stat['sid']));
  652. }
  653. return "/myReceipt";
  654. }
  655. function approval(){
  656. $status=isset($this->params['status'])?$this->params['status']:'';
  657. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  658. $month=$this->get_args('month')?$this->get_args('month'):"";
  659. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  660. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  661. if (empty($status))
  662. $status=$this->get_args('status')?$this->get_args('status'):2;
  663. $vidList=array();
  664. $button=0;
  665. Doo::loadModel('verify');
  666. Doo::loadModel('receipt');
  667. Doo::loadModel('staff');
  668. $staff=new staff();
  669. $receipt=new receipt();
  670. $verify=new verify();
  671. Doo::loadModel('L_category');
  672. $Lcategory=new L_category();
  673. //user verify ID
  674. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
  675. foreach ($verifyDetail as $key=>$value){
  676. array_push($vidList, $value['vid']);
  677. }
  678. $vid=implode(",", $vidList);
  679. if(empty($verifyDetail))
  680. $vid=0;
  681. $dateCondition=" and Year(date) =".$year;
  682. if(!empty($month))
  683. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  684. $categoryList=$Lcategory->find(array('asArray'=>true));
  685. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  686. $cateCondition="";$staffCondition="";$approvalCondition="";
  687. if (!empty($cid))
  688. $cateCondition=' and cid='.$cid;
  689. if(!empty($sid)){
  690. $staffCondition=' and staff='.$sid;
  691. $cateCondition="";
  692. }
  693. if($status==2)
  694. $approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  695. $ap="";
  696. if($status==4){
  697. $ap=4;$status=2;
  698. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  699. }
  700. //get Receipt By verifyID status 2
  701. $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  702. $Locate=0;
  703. if($ap==4)
  704. $status=4;
  705. foreach ($receiptList as $key=>$value){
  706. $receiptList[$key]['Locate']=$Locate;$Locate++;
  707. $receiptList[$key]['reviseDetail']=array();
  708. if (!empty($value['reviseDetail']))
  709. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  710. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  711. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  712. $receiptList[$key]['category']=$categoryDetil['title'];
  713. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  714. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  715. $verifyStaff=json_decode($value['verifyStaff'],true);
  716. foreach ($verifyList as $k=>$v){
  717. //init verifyStaff
  718. $verifyList[$k]['date']="";
  719. $verifyList[$k]['opinion']="";
  720. $verifyList[$k]['status']="";
  721. if (empty($verifyStaff)){
  722. $verifyList[$k]['date']="";
  723. $verifyList[$k]['opinion']="";
  724. if ($v[0]==$this->staff[0]['sid']){
  725. $verifyList[$k]['status']=4;
  726. $button=4;
  727. }
  728. }else{
  729. $flag=true;
  730. foreach ($verifyStaff as $m=>$u){
  731. if ($v[0]==$m){
  732. $verifyList[$k]['date']=$u['date'];
  733. $verifyList[$k]['opinion']=$u['opinion'];
  734. $verifyList[$k]['status']=$u['status'];
  735. $flag=false;
  736. break;
  737. }
  738. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  739. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  740. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  741. }
  742. if($flag){//检测可编辑
  743. if($v[0]==$this->staff[0]['sid']){
  744. $verifyList[$k]['status']=4;$button=4;
  745. }
  746. }
  747. }
  748. }
  749. $receiptList[$key]['verifyList']=$verifyList;
  750. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  751. $receiptList[$key]['button']=$button;
  752. }
  753. //print_r($receiptList);die;
  754. //$data['verifyDetail']=$verifyDetail;
  755. $mothHtml="";
  756. for($i=1;$i<=12;$i++){
  757. if($month==$i)
  758. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  759. else
  760. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  761. }
  762. $data['mothHtml']=$mothHtml;
  763. $data['receiptList']=$receiptList;
  764. $data['receiptApprovalCount']=count($receiptList);
  765. $data['status']=$status;
  766. $data['year']=$year;
  767. $data['categoryList']=$categoryList;
  768. $data['staffList']=$staffList;
  769. $data['cid']=$cid;
  770. $data['sid']=$sid;
  771. $data['ap']=$ap;
  772. $data['memu']="receipt";
  773. $data['staff']=$this->staff;
  774. $data['receiptMemu']='approval';
  775. $data['verifyId']=$this->verifyId;
  776. $this->render ( "/admin/saea_reportList", $data );
  777. }
  778. function remittance(){
  779. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  780. $month=$this->get_args('month')?$this->get_args('month'):"";
  781. Doo::loadModel('receipt');
  782. $receipt=new receipt();
  783. Doo::loadModel('staff');
  784. $staff=new staff();
  785. $dateCondition=" and Year(pastDate) =".$year;
  786. if(!empty($month))
  787. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  788. //get Receipt By verifyID status 1
  789. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  790. $dateList=$receipt->find(array('select'=>'pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  791. $dataList=array();
  792. foreach ($dateList as $d=>$a){
  793. $dataList[$a['pastDate']]=array();$daySum=0;
  794. foreach ($receiptList as $key=>$value){
  795. if($a['pastDate']==$value['pastDate']){
  796. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  797. $list=array();
  798. foreach ($oderList as $v){
  799. array_push($list, $v['receiptOrder']);
  800. }
  801. $receiptList[$key]['receiptOrder']=implode(",", $list);
  802. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  803. $receiptList[$key]['username']=$sinfo['username'];
  804. $daySum+=$value['sum'];
  805. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  806. }
  807. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  808. }
  809. }
  810. //print_r($dataList);die;
  811. $data['dataList']=$dataList;
  812. $mothHtml="";
  813. for($i=1;$i<=12;$i++){
  814. if($month==$i)
  815. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  816. else
  817. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  818. }
  819. $data['year']=$year;
  820. $data['mothHtml']=$mothHtml;
  821. $data['memu']="receipt";
  822. $data['staff']=$this->staff;
  823. $data['receiptMemu']='approval';
  824. $data['verifyId']=$this->verifyId;
  825. $this->render ( "/admin/saeaReportListPay", $data );
  826. }
  827. function revocationAdjustment(){
  828. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  829. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  830. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  831. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  832. Doo::loadModel('receipt');
  833. $receipt=new receipt();
  834. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  835. if (empty($receiptDetail['reviseDetail']))
  836. return "/approval";
  837. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  838. $RD=array();
  839. foreach ($reviseDetail as $key=>$value){
  840. if ($value['price']==$price&&$value['sid']==$sid)
  841. continue;
  842. array_push($RD, $value);
  843. }
  844. $reviseDetailString=json_encode($RD);
  845. $receipt->reviseDetail=$reviseDetailString;
  846. $receipt->sum=$receiptDetail['sum']+$price;
  847. $receipt->update(array('where'=>'rid='.$rid));
  848. }
  849. return "/approval";
  850. }
  851. function updateApprovalReceipt(){
  852. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  853. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  854. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  855. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  856. if(!empty($rid)){
  857. Doo::loadModel("receipt");
  858. Doo::loadModel("verify");
  859. Doo::loadModel("receiptDetail");
  860. $receiptDetailObj=new receiptDetail();
  861. Doo::loadModel("itemStatistics");
  862. Doo::loadModel("statistics");
  863. $statistics=new statistics();
  864. $itemStatistics=new itemStatistics();
  865. $verify=new verify();
  866. $receipt=new receipt();
  867. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  868. if (empty($receiptDetail))
  869. return "/approval";
  870. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  871. if(empty($opinion)){
  872. if ($status==3)
  873. $opinion="退回";
  874. else
  875. $opinion="同意支付";
  876. }
  877. if(empty($verifyStaff)){
  878. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  879. if($status==3)
  880. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  881. $vStaffString=json_encode($verifyStaff);
  882. $receipt->verifyStaff=$vStaffString;
  883. }else{
  884. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)){
  885. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  886. if($status==3){
  887. $verifyStaff['final']=$status;
  888. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  889. }
  890. $vStaffString=json_encode($verifyStaff);
  891. $receipt->verifyStaff=$vStaffString;
  892. }
  893. }
  894. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  895. $verifyDetail=json_decode($verifyDetail['staff'],true);
  896. if (isset($verifyStaff['final'])){//rDetail
  897. $receipt->status=3;
  898. $receiptDetailObj->status=3;
  899. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  900. }elseif(count($verifyStaff)==count($verifyDetail)){
  901. $receipt->status=1;
  902. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  903. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  904. $reviseSum=0;
  905. foreach ($reviseDetail as $key=>$value){
  906. $receiptDetailObj=new receiptDetail();
  907. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  908. $receiptDetailObj->item=$value['description'];
  909. $receiptDetailObj->itemCategory="报销金额调整";
  910. $receiptDetailObj->price=$value['price'];
  911. $receiptDetailObj->date=$receiptDetail['date'];
  912. $receiptDetailObj->cid=$this->staff[0]['cid'];
  913. $receiptDetailObj->rid=$rid;
  914. $receiptDetailObj->status=1;
  915. $receiptDetailObj->insert();
  916. $reviseSum+=$value['price'];
  917. }
  918. $itemStatistics=new itemStatistics();
  919. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  920. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  921. $itemStatistics->price=$reviseSum;
  922. $itemStatistics->itemCategory="报销金额调整";
  923. $itemStatistics->date=$receiptDetail['date'];
  924. $itemStatistics->insert();
  925. }
  926. $receiptDetailObj=new receiptDetail();
  927. $receiptDetailObj->status=1;
  928. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  929. $dateArray=explode("-", $receiptDetail['date']);
  930. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  931. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  932. if(empty($stat)){
  933. $statistics->date=$receiptDetail['date'];
  934. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  935. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  936. $statistics->agPrice=$receiptDetail['sum'];
  937. $statistics->rePrice=$reviseSum;
  938. $statistics->insert();
  939. }else{
  940. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  941. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  942. $statistics->update(array('where'=>'sid='.$stat['sid']));
  943. }
  944. $dateArray=explode("-", $receiptDetail['date']);
  945. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  946. $accountItem=json_decode($receiptDetail['accountItem'],true);
  947. foreach ($accountItem['cSum'] as $key=>$value){
  948. if($key=="agencySum"){
  949. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  950. if(empty($iStatistics)){
  951. $itemStatistics->cid=$receiptDetail['cid'];;
  952. $itemStatistics->staff=$receiptDetail['staff'];
  953. $itemStatistics->price=$value;
  954. $itemStatistics->itemCategory=$this->AGENCY;
  955. $itemStatistics->date=$receiptDetail['date'];
  956. $itemStatistics->insert();
  957. }else{
  958. if (!empty($value)){
  959. $itemStatistics->price=$value+$iStatistics['price'];
  960. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  961. }
  962. }
  963. }elseif($key=="travelSum"){
  964. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  965. if(empty($iStatistics)){
  966. $itemStatistics->cid=$receiptDetail['cid'];
  967. $itemStatistics->staff=$receiptDetail['staff'];
  968. $itemStatistics->price=$value;
  969. $itemStatistics->itemCategory=$this->TRAVEL;
  970. $itemStatistics->date=$receiptDetail['date'];
  971. $itemStatistics->insert();
  972. }else{
  973. if (!empty($value)){
  974. $itemStatistics->price=$value+$iStatistics['price'];
  975. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  976. }
  977. }
  978. }elseif($key=="trainSum"){
  979. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  980. if(empty($iStatistics)){
  981. $itemStatistics->cid=$receiptDetail['cid'];
  982. $itemStatistics->staff=$receiptDetail['staff'];
  983. $itemStatistics->price=$value;
  984. $itemStatistics->itemCategory=$this->TRAIN;
  985. $itemStatistics->date=$receiptDetail['date'];
  986. $itemStatistics->insert();
  987. }else{
  988. if (!empty($value)){
  989. $itemStatistics->price=$value+$iStatistics['price'];
  990. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  991. }
  992. }
  993. }elseif($key=="otherSum"){
  994. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  995. if(empty($iStatistics)){
  996. $itemStatistics->cid=$receiptDetail['cid'];
  997. $itemStatistics->staff=$receiptDetail['staff'];
  998. $itemStatistics->price=$value;
  999. $itemStatistics->itemCategory=$this->OTHER;
  1000. $itemStatistics->date=$receiptDetail['date'];
  1001. $itemStatistics->insert();
  1002. }else{
  1003. if (!empty($value)){
  1004. $itemStatistics->price=$value+$iStatistics['price'];
  1005. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  1006. }
  1007. }
  1008. }
  1009. }
  1010. $receipt->pastDate=date("Y-m-d");
  1011. }
  1012. $receipt->update(array('where'=>'rid='.$rid));
  1013. return "/approval#".$Locate;
  1014. }
  1015. }
  1016. function revisePrice(){
  1017. $description=$this->get_args('description')?$this->get_args('description'):"";
  1018. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  1019. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  1020. if (!empty($rid)){
  1021. Doo::loadModel("receipt");
  1022. $receipt=new receipt();
  1023. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  1024. if (empty($receiptDetail))
  1025. return "/approval";
  1026. $reviseDetail=array();
  1027. if (empty($receiptDetail['reviseDetail'])){
  1028. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  1029. $reviseDetailString=json_encode($reviseDetail);
  1030. $receipt->reviseDetail=$reviseDetailString;
  1031. $receipt->revisePrice=$price;
  1032. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  1033. }else{
  1034. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  1035. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  1036. $reviseDetailString=json_encode($reviseDetail);
  1037. $receipt->reviseDetail=$reviseDetailString;
  1038. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  1039. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  1040. }
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. }
  1043. return "/approval";
  1044. }
  1045. function personalCollect(){
  1046. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1047. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  1048. $this->showCache($path);
  1049. Doo::loadModel("receiptDetail");
  1050. Doo::loadModel("itemStatistics");
  1051. Doo::loadModel('statistics');
  1052. $statistics=new statistics();
  1053. $itemStatistics=new itemStatistics();
  1054. $receiptDetail=new receiptDetail();
  1055. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  1056. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  1057. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  1058. //create collect html
  1059. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  1060. $adjustment=array();
  1061. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  1062. array_push($collectArray['日常相关费用'], $collectHtml);
  1063. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  1064. array_push($collectArray['差旅相关费用'], $collectHtml);
  1065. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  1066. array_push($collectArray['培训班费用'], $collectHtml);
  1067. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  1068. array_push($collectArray['其他'], $collectHtml);
  1069. $data['collectArray']=$collectArray;
  1070. //statistics html
  1071. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1072. if(empty($stList))
  1073. $stList=array('rePrice'=>0,'agPrice'=>0);
  1074. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1075. //Adjustment price html
  1076. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  1077. array_push($adjustment, $collectHtml);
  1078. $data['adjustment']=$adjustment;
  1079. //total price html
  1080. $collectHtml="";$total=0;
  1081. for ($i=1;$i<=12;$i++){
  1082. $sumPrice=0;
  1083. foreach ($receiptCollectList as $key=>$value){
  1084. if($value['month']==$i){
  1085. $sumPrice+=$value['price'];
  1086. }
  1087. }
  1088. if ($sumPrice==0)
  1089. $collectHtml.='<td class="taR">-</td>';
  1090. else
  1091. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  1092. $total+=$sumPrice;
  1093. }
  1094. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  1095. $data['totalPrice']=$collectHtml;
  1096. $data['year']=$year;
  1097. $data['totalYear']=$total;
  1098. $data['memu']="receipt";
  1099. $data['staff']=$this->staff;
  1100. $data['receiptMemu']='personalCollect';
  1101. $data['verifyId']=$this->verifyId;
  1102. //year staff status 2,4
  1103. if($year<date("Y")){
  1104. Doo::loadModel('receipt');
  1105. $receipt=new receipt();
  1106. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  1107. if(empty($receiptList)){
  1108. ob_start();
  1109. $this->render ( "/admin/saea_slist_collect", $data );
  1110. $this->cacheFile($path);die;
  1111. }
  1112. }
  1113. $this->render ( "/admin/saea_slist_collect", $data );
  1114. }
  1115. function personalCollectDetail(){
  1116. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1117. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  1118. $this->showCache($path);
  1119. Doo::loadModel("receiptDetail");
  1120. Doo::loadModel("itemStatistics");
  1121. Doo::loadModel('statistics');
  1122. Doo::loadModel('accountItem');
  1123. $accountItem=new accountItem();
  1124. $statistics=new statistics();
  1125. $itemStatistics=new itemStatistics();
  1126. $receiptDetail=new receiptDetail();
  1127. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  1128. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  1129. $accountList=$accountItem->find(array('asArray'=>true));
  1130. //create CollectDetail HTML
  1131. $collectHtml=array();
  1132. foreach ($accountList as $key=>$value){
  1133. $html="";$asum=0;
  1134. for ($i=1;$i<=12;$i++){
  1135. $falg=true;
  1136. foreach ($receiptCollectList as $v) {
  1137. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  1138. $asum+=$v['price'];
  1139. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  1140. }
  1141. }
  1142. if($falg)
  1143. $html.='<td class="taR">-</td>';
  1144. }
  1145. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  1146. $collectHtml[$value['category']][$value['name']]=$html;
  1147. }
  1148. $data['collectHtml']=$collectHtml;
  1149. //create Adjustment price html
  1150. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  1151. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  1152. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  1153. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  1154. array_push($collectArray['日常相关费用'], $collectHtml);
  1155. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  1156. array_push($collectArray['差旅相关费用'], $collectHtml);
  1157. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  1158. array_push($collectArray['培训班费用'], $collectHtml);
  1159. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  1160. array_push($collectArray['其他'], $collectHtml);
  1161. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  1162. array_push($adjustment, $collectHtml);
  1163. //total price html
  1164. $collectHtml="";$total=0;
  1165. for ($i=1;$i<=12;$i++){
  1166. $sumPrice=0;
  1167. foreach ($receiptCollectList as $key=>$value){
  1168. if($value['month']==$i){
  1169. $sumPrice+=$value['price'];
  1170. }
  1171. }
  1172. if ($sumPrice==0)
  1173. $collectHtml.='<td class="taR">-</td>';
  1174. else
  1175. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  1176. $total+=$sumPrice;
  1177. }
  1178. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  1179. //statistics html
  1180. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1181. if(empty($stList))
  1182. $stList=array('rePrice'=>0,'agPrice'=>0);
  1183. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1184. $data['collectArray']=$collectArray;
  1185. $data['adjustment']=$adjustment;
  1186. $data['totalPrice']=$collectHtml;
  1187. $data['totalYear']=$total;
  1188. $data['year']=$year;
  1189. $data['memu']="receipt";
  1190. $data['staff']=$this->staff;
  1191. $data['receiptMemu']='personalCollect';
  1192. $data['verifyId']=$this->verifyId;
  1193. //year staff status 2,4
  1194. if($year<date("Y")){
  1195. Doo::loadModel('receipt');
  1196. $receipt=new receipt();
  1197. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  1198. if(empty($receiptList)){
  1199. ob_start();
  1200. $this->render ( "/admin/saeaCollectArticles", $data );
  1201. $this->cacheFile($path);die;
  1202. }
  1203. }
  1204. $this->render ( "/admin/saeaCollectArticles", $data );
  1205. }
  1206. function companyCategoryCollect(){
  1207. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1208. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  1209. $this->showCache($path);
  1210. Doo::loadModel('L_category');
  1211. Doo::loadModel('itemStatistics');
  1212. Doo::loadModel('statistics');
  1213. $statistics=new statistics();
  1214. $Lcategory=new L_category();
  1215. $itemStatistics=new itemStatistics();
  1216. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  1217. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  1218. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  1219. //ceatre companyCollectHtml
  1220. foreach ($LcategoryList as $value){
  1221. $html="";$asum=0;
  1222. for ($i=1;$i<=12;$i++){
  1223. $falg=true;
  1224. foreach ($itemStatisticsList as $v){
  1225. if($value['cid']==$v['cid']&&$i==$v['month']){
  1226. $asum+=$v['price'];
  1227. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  1228. }
  1229. }
  1230. if($falg)
  1231. $html.='<td class="taR">-</td>';
  1232. }
  1233. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  1234. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  1235. }
  1236. $data['companyHtml']=$collectHtml;
  1237. //total price html
  1238. $collectHtml="";$total=0;
  1239. for ($i=1;$i<=12;$i++){
  1240. $sumPrice=0;
  1241. foreach ($itemStatisticsList as $key=>$value){
  1242. if($value['month']==$i){
  1243. $sumPrice+=$value['price'];
  1244. }
  1245. }
  1246. if ($sumPrice==0)
  1247. $collectHtml.='<td class="taR">-</td>';
  1248. else
  1249. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  1250. $total+=$sumPrice;
  1251. }
  1252. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  1253. $data['companyTotalHtml']=$collectHtml;
  1254. $data['total']=$total;
  1255. //statistics html
  1256. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  1257. if(empty($stList))
  1258. $stList=array('rePrice'=>0,'agPrice'=>0);
  1259. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1260. $data['year']=$year;
  1261. $data['memu']="receipt";
  1262. $data['staff']=$this->staff;
  1263. $data['receiptMemu']='companyCategoryCollect';
  1264. $data['verifyId']=$this->verifyId;
  1265. //year staff status 2,4
  1266. if($year<date("Y")){
  1267. Doo::loadModel('receipt');
  1268. $receipt=new receipt();
  1269. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  1270. if(empty($receiptList)){
  1271. ob_start();
  1272. $this->render ( "/admin/saeaCompanyCollect", $data );
  1273. $this->cacheFile($path);die;
  1274. }
  1275. }
  1276. $this->render ( "/admin/saeaCompanyCollect", $data );
  1277. }
  1278. function categoryCollectDetail(){
  1279. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1280. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  1281. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  1282. $this->showCache($path);
  1283. Doo::loadModel('statistics');
  1284. $statistics=new statistics();
  1285. Doo::loadModel("receiptDetail");
  1286. $receiptDetail=new receiptDetail();
  1287. Doo::loadModel('L_category');
  1288. $Lcategory=new L_category();
  1289. Doo::loadModel('accountItem');
  1290. $accountItem=new accountItem();
  1291. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  1292. if ($cid==0){
  1293. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1294. if ($cid==0)
  1295. $cid=$LcategoryList[0]['cid'];
  1296. }
  1297. $data['LcategoryList']=$LcategoryList;
  1298. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  1299. 'where'=>'cid='.$cid." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  1300. $accountList=$accountItem->find(array('asArray'=>true));
  1301. //create CollectDetail HTML
  1302. $collectHtml=array();
  1303. foreach ($accountList as $key=>$value){
  1304. $html="";$asum=0;
  1305. for ($i=1;$i<=12;$i++){
  1306. $falg=true;
  1307. foreach ($receiptCollectList as $v) {
  1308. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  1309. $asum+=$v['price'];
  1310. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  1311. }
  1312. }
  1313. if($falg)
  1314. $html.='<td class="taR">-</td>';
  1315. }
  1316. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  1317. $collectHtml[$value['category']][$value['name']]=$html;
  1318. }
  1319. $data['collectHtml']=$collectHtml;
  1320. //create Adjustment price html
  1321. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  1322. 'where'=>'cid='.$cid." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  1323. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  1324. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  1325. array_push($collectArray['日常相关费用'], $collectHtml);
  1326. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  1327. array_push($collectArray['差旅相关费用'], $collectHtml);
  1328. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  1329. array_push($collectArray['培训班费用'], $collectHtml);
  1330. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  1331. array_push($collectArray['其他'], $collectHtml);
  1332. $data['collectArray']=$collectArray;
  1333. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  1334. array_push($adjustment, $collectHtml);
  1335. $data['adjustment']=$adjustment;
  1336. //total price html
  1337. $collectHtml="";$total=0;
  1338. for ($i=1;$i<=12;$i++){
  1339. $sumPrice=0;
  1340. foreach ($receiptCollectList as $key=>$value){
  1341. if($value['month']==$i){
  1342. $sumPrice+=$value['price'];
  1343. }
  1344. }
  1345. if ($sumPrice==0)
  1346. $collectHtml.='<td class="taR">-</td>';
  1347. else
  1348. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  1349. $total+=$sumPrice;
  1350. }
  1351. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  1352. //statistics html
  1353. $stList=$statistics->statisticsByCid($year,$cid);
  1354. if(empty($stList))
  1355. $stList=array('rePrice'=>0,'agPrice'=>0);
  1356. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1357. $data['totalYear']=$total;
  1358. $data['year']=$year;
  1359. $data['cid']=$cid;
  1360. $data['memu']="receipt";
  1361. $data['staff']=$this->staff;
  1362. $data['receiptMemu']='companyCategoryCollect';
  1363. $data['verifyId']=$this->verifyId;
  1364. //year staff status 2,4
  1365. if($year<date("Y")){
  1366. Doo::loadModel('receipt');
  1367. $receipt=new receipt();
  1368. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  1369. if(empty($receiptList)){
  1370. ob_start();
  1371. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  1372. $this->cacheFile($path);die;
  1373. }
  1374. }
  1375. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  1376. }
  1377. function staffCollect(){
  1378. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1379. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  1380. //$this->showCache($path);
  1381. Doo::loadModel('statistics');
  1382. $statistics=new statistics();
  1383. Doo::loadModel("receiptDetail");
  1384. $receiptDetail=new receiptDetail();
  1385. Doo::loadModel('L_category');
  1386. $Lcategory=new L_category();
  1387. Doo::loadModel('accountItem');
  1388. $accountItem=new accountItem();
  1389. Doo::loadModel('staff');
  1390. $staff=new staff();
  1391. Doo::loadModel('itemStatistics');
  1392. $itemStatistics=new itemStatistics();
  1393. /*
  1394. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  1395. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  1396. if(empty($stList))
  1397. $stList=array('rePrice'=>0,'agPrice'=>0);
  1398. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1399. */
  1400. //statistics html
  1401. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1405. //---
  1406. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  1407. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  1408. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  1409. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  1410. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  1411. //ceatre companyCollectHtml
  1412. foreach ($categoryList as $vlu){
  1413. $count=$vlu['count']+1;
  1414. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  1415. $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;
  1416. foreach ($staffList as $value){
  1417. if ($vlu['cid']==$value['cid']){
  1418. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  1419. $asum=0;
  1420. for ($i=1;$i<=12;$i++){
  1421. $falg=true;
  1422. foreach ($itemStatisticsList as $v){
  1423. if($value['sid']==$v['staff']&&$i==$v['month']){
  1424. if ($v['month']==1)
  1425. $m1+=$v['price'];
  1426. if ($v['month']==2)
  1427. $m2+=$v['price'];
  1428. if ($v['month']==3)
  1429. $m3+=$v['price'];
  1430. if ($v['month']==4)
  1431. $m4+=$v['price'];
  1432. if ($v['month']==5)
  1433. $m5+=$v['price'];
  1434. if ($v['month']==6)
  1435. $m6+=$v['price'];
  1436. if ($v['month']==7)
  1437. $m7+=$v['price'];
  1438. if ($v['month']==8)
  1439. $m8+=$v['price'];
  1440. if ($v['month']==9)
  1441. $m9+=$v['price'];
  1442. if ($v['month']==10)
  1443. $m10+=$v['price'];
  1444. if ($v['month']==11)
  1445. $m11+=$v['price'];
  1446. if ($v['month']==12)
  1447. $m12+=$v['price'];
  1448. $asum+=$v['price'];
  1449. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  1450. }
  1451. }
  1452. if($falg)
  1453. $html.='<td class="taR">-</td>';
  1454. }
  1455. $m13+=$asum;
  1456. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  1457. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  1458. $html="";
  1459. }
  1460. }
  1461. $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>
  1462. <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>
  1463. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  1464. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  1465. }
  1466. $data['companyHtml']=$collectHtml;
  1467. //total price html
  1468. $collectHtml="";$total=0;
  1469. for ($i=1;$i<=12;$i++){
  1470. $sumPrice=0;
  1471. foreach ($itemStatisticsList as $key=>$value){
  1472. if($value['month']==$i){
  1473. $sumPrice+=$value['price'];
  1474. }
  1475. }
  1476. if ($sumPrice==0)
  1477. $collectHtml.='<td class="taR">-</td>';
  1478. else
  1479. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  1480. $total+=$sumPrice;
  1481. }
  1482. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  1483. $data['companyTotalHtml']=$collectHtml;
  1484. $data['total']=$total;
  1485. $data['year']=$year;
  1486. $data['memu']="receipt";
  1487. $data['staff']=$this->staff;
  1488. $data['receiptMemu']='companyCategoryCollect';
  1489. $data['verifyId']=$this->verifyId;
  1490. if ($year<=date("Y")){
  1491. Doo::loadModel('receipt');
  1492. $receipt=new receipt();
  1493. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  1494. if(empty($receiptList)){ //generated files
  1495. ob_start();
  1496. $this->render ( "/admin/saeaStaffCollectB", $data );
  1497. $this->cacheFile($path);die;
  1498. }
  1499. }
  1500. $this->render ( "/admin/saeaStaffCollectB", $data );
  1501. }
  1502. function staffCollectBak(){
  1503. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1504. $month=$this->get_args('month')?$this->get_args('month'):1;
  1505. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  1506. $this->showCache($path);
  1507. Doo::loadModel('statistics');
  1508. $statistics=new statistics();
  1509. Doo::loadModel("receiptDetail");
  1510. $receiptDetail=new receiptDetail();
  1511. Doo::loadModel('L_category');
  1512. $Lcategory=new L_category();
  1513. Doo::loadModel('accountItem');
  1514. $accountItem=new accountItem();
  1515. Doo::loadModel('staff');
  1516. $staff=new staff();
  1517. Doo::loadModel('itemStatistics');
  1518. $itemStatistics=new itemStatistics();
  1519. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  1520. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  1521. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  1522. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  1523. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  1524. $staffList=$staff->find(array('asArray'=>true));
  1525. $htmlArray=array();
  1526. foreach ($LcategoryList as $value){
  1527. $htmlArray[$value['title']]=array();
  1528. foreach ($staffList as $v){
  1529. if($value['cid']==$v['cid']){
  1530. $html="";$falg=true;$staffSumPrice=0;
  1531. foreach ($itemStatisticsList as $a){
  1532. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  1533. if(empty($a['price'])){
  1534. $html.='<td class="taR">-</td>';$falg=false;break;
  1535. }else{
  1536. $staffSumPrice+=$a['price'];
  1537. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  1538. }
  1539. }
  1540. }
  1541. if ($falg){
  1542. $html.='<td class="taR">-</td>';$falg=true;
  1543. }
  1544. $falg=true;
  1545. foreach ($itemStatisticsList as $a){
  1546. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  1547. if(empty($a['price'])){
  1548. $html.='<td class="taR">-</td>';$falg=false;break;
  1549. }else{
  1550. $staffSumPrice+=$a['price'];
  1551. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  1552. }
  1553. }
  1554. }
  1555. if ($falg){
  1556. $html.='<td class="taR">-</td>';$falg=true;
  1557. }
  1558. $falg=true;
  1559. foreach ($itemStatisticsList as $a){
  1560. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  1561. if(empty($a['price'])){
  1562. $html.='<td class="taR">-</td>';$falg=false;break;
  1563. }else{
  1564. $staffSumPrice+=$a['price'];
  1565. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  1566. }
  1567. }
  1568. }
  1569. if ($falg){
  1570. $html.='<td class="taR">-</td>';$falg=true;
  1571. }
  1572. $falg=true;
  1573. foreach ($itemStatisticsList as $a){
  1574. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  1575. if(!empty($a['price'])){
  1576. $staffSumPrice+=$a['price'];
  1577. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  1578. }else{
  1579. $html.='<td class="taR">-</td>';$falg=false;break;
  1580. }
  1581. }
  1582. }
  1583. if ($falg){
  1584. $html.='<td class="taR">-</td>';$falg=true;
  1585. }
  1586. $falg=true;
  1587. foreach ($itemStatisticsList as $a){
  1588. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  1589. if(!empty($a['price'])){
  1590. $staffSumPrice+=$a['price'];
  1591. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  1592. }else{
  1593. $html.='<td class="taR">-</td>';$falg=false;break;
  1594. }
  1595. }
  1596. }
  1597. if ($falg){
  1598. $html.='<td class="taR">-</td>';$falg=true;
  1599. }
  1600. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  1601. $htmlArray[$value['title']][$v['username']]=$html;
  1602. }
  1603. }
  1604. /*-- ---*/
  1605. //合计费用
  1606. $cateHtml="";$catePrice=0;$cateFalg=true;
  1607. foreach ($itemCategoryList as $l){
  1608. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  1609. if(empty($l['price'])){
  1610. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  1611. }else{
  1612. $catePrice+=$l['price'];
  1613. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  1614. }
  1615. }
  1616. }
  1617. if ($cateFalg){
  1618. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  1619. }
  1620. $cateFalg=true;
  1621. foreach ($itemCategoryList as $l){
  1622. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  1623. if(empty($l['price'])){
  1624. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  1625. }else{
  1626. $catePrice+=$l['price'];
  1627. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  1628. }
  1629. }
  1630. }
  1631. if ($cateFalg){
  1632. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  1633. }
  1634. $cateFalg=true;
  1635. foreach ($itemCategoryList as $l){
  1636. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  1637. if(empty($l['price'])){
  1638. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  1639. }else{
  1640. $catePrice+=$l['price'];
  1641. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  1642. }
  1643. }
  1644. }
  1645. if ($cateFalg){
  1646. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  1647. }
  1648. $cateFalg=true;
  1649. foreach ($itemCategoryList as $l){
  1650. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  1651. if(empty($l['price'])){
  1652. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  1653. }else{
  1654. $catePrice+=$l['price'];
  1655. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  1656. }
  1657. }
  1658. }
  1659. if ($cateFalg){
  1660. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  1661. }
  1662. $cateFalg=true;
  1663. foreach ($itemCategoryList as $l){
  1664. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  1665. if(empty($l['price'])){
  1666. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  1667. }else{
  1668. $catePrice+=$l['price'];
  1669. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  1670. }
  1671. }
  1672. }
  1673. if ($cateFalg){
  1674. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  1675. }
  1676. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  1677. $htmlArray[$value['title']]['合计']=$cateHtml;
  1678. /*-- ---*/
  1679. }
  1680. //print_r($htmlArray);die;
  1681. $data['htmlArray']=$htmlArray;
  1682. //statistics html
  1683. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  1684. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  1685. if(empty($stList))
  1686. $stList=array('rePrice'=>0,'agPrice'=>0);
  1687. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1688. $monthHtml="";
  1689. for ($i=1;$i<=12;$i++){
  1690. if ($i==$month)
  1691. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  1692. else
  1693. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  1694. }
  1695. $data['monthHtml']=$monthHtml;
  1696. $data['year']=$year;
  1697. $data['month']=$month;
  1698. $data['memu']="receipt";
  1699. $data['staff']=$this->staff;
  1700. $data['receiptMemu']='companyCategoryCollect';
  1701. $data['verifyId']=$this->verifyId;
  1702. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  1703. Doo::loadModel('receipt');
  1704. $receipt=new receipt();
  1705. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  1706. if(empty($receiptList)){ //generated files
  1707. ob_start();
  1708. $this->render ( "/admin/saeaStaffCollect", $data );
  1709. $this->cacheFile($path);die;
  1710. }
  1711. }
  1712. $this->render ( "/admin/saeaStaffCollect", $data );
  1713. }
  1714. function staffCollectMonthDetail(){
  1715. $year=$this->get_args('year')?$this->get_args('year'):"";
  1716. $month=$this->get_args('month')?$this->get_args('month'):"";
  1717. if(!$year)
  1718. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  1719. if(!$month)
  1720. $month=isset($this->params['month'])?$this->params['month']:1;
  1721. Doo::loadModel('staff');
  1722. $staff=new staff();
  1723. Doo::loadModel("receiptDetail");
  1724. $receiptDetail=new receiptDetail();
  1725. Doo::loadModel('accountItem');
  1726. $accountItem=new accountItem();
  1727. Doo::loadModel('statistics');
  1728. $statistics=new statistics();
  1729. Doo::loadModel('L_category');
  1730. $lCategory=new L_category();
  1731. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  1732. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  1733. $list=array();
  1734. foreach ($categoryList as $vlu){
  1735. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  1736. $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;
  1737. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  1738. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  1739. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  1740. $s1=0;
  1741. $m1=0;
  1742. foreach ($staffList as $value){
  1743. if ($vlu['cid']==$value['cid']){
  1744. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  1745. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  1746. if(!empty($receiptCollectList)){
  1747. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  1748. $html="";
  1749. $psum=0;
  1750. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  1751. foreach ($item as $va){
  1752. $falg=true;
  1753. foreach ($receiptCollectList as $v){
  1754. if($v['itemCategory']=='日常相关费用'){
  1755. if($v['item']==$va){
  1756. if ($va=='市内交通费')
  1757. $r1+=$v['price'];
  1758. if ($va=='市内出租费')
  1759. $r2+=$v['price'];
  1760. if ($va=='办事处房租')
  1761. $r3+=$v['price'];
  1762. if ($va=='电话费')
  1763. $r4+=$v['price'];
  1764. if ($va=='水费')
  1765. $r5+=$v['price'];
  1766. if ($va=='电费')
  1767. $r6+=$v['price'];
  1768. if ($va=='办公费用')
  1769. $r7+=$v['price'];
  1770. if ($va=='邮寄费')
  1771. $r8+=$v['price'];
  1772. if ($va=='其他费用')
  1773. $r9+=$v['price'];
  1774. if ($va=='车辆费用')
  1775. $r10+=$v['price'];
  1776. if ($va=='广告费')
  1777. $r11+=$v['price'];
  1778. if ($va=='团队建设费')
  1779. $r13+=$v['price'];
  1780. $psum+=$v['price'];
  1781. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  1782. }
  1783. }
  1784. }
  1785. if($falg)
  1786. $html.='<td class="taR">-</td>';
  1787. }
  1788. $r12+=$psum;
  1789. if(!empty($psum))
  1790. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  1791. else
  1792. $psum='<td class="colGreen taR">-</td>';
  1793. $receiptL['日常相关费用']=$psum.$html;
  1794. /*-----------------------------------*/
  1795. $html="";
  1796. $psum=0;
  1797. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  1798. foreach ($item as $va){
  1799. $falg=true;
  1800. foreach ($receiptCollectList as $v){
  1801. if($v['itemCategory']=='差旅相关费用'){
  1802. if($v['item']==$va){
  1803. if ($va=='往来交通费')
  1804. $c1+=$v['price'];
  1805. if ($va=='市内交通费')
  1806. $c2+=$v['price'];
  1807. if ($va=='出差住宿费')
  1808. $c3+=$v['price'];
  1809. if ($va=='出差补助')
  1810. $c4+=$v['price'];
  1811. if ($va=='其他费用')
  1812. $c5+=$v['price'];
  1813. $psum+=$v['price'];
  1814. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  1815. }
  1816. }
  1817. }
  1818. if($falg)
  1819. $html.='<td class="taR">-</td>';
  1820. }
  1821. $c6+=$psum;
  1822. if(!empty($psum))
  1823. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  1824. else
  1825. $psum='<td class="colGreen taR">-</td>';
  1826. $receiptL['差旅相关费用']=$psum.$html;
  1827. /*-------------------------------------*/
  1828. $html="";
  1829. $psum=0;
  1830. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  1831. foreach ($item as $va){
  1832. $falg=true;
  1833. foreach ($receiptCollectList as $v){
  1834. if($v['itemCategory']=='培训班费用'){
  1835. if($v['item']==$va){
  1836. if ($va=='场租费')
  1837. $p1+=$v['price'];
  1838. if ($va=='薪酬')
  1839. $p2+=$v['price'];
  1840. if ($va=='住宿费')
  1841. $p3+=$v['price'];
  1842. if ($va=='交通费')
  1843. $p4+=$v['price'];
  1844. if ($va=='餐饮费')
  1845. $p5+=$v['price'];
  1846. if ($va=='办公费')
  1847. $p6+=$v['price'];
  1848. if ($va=='公关费')
  1849. $p7+=$v['price'];
  1850. if ($va=='其他')
  1851. $p8+=$v['price'];
  1852. $psum+=$v['price'];
  1853. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  1854. }
  1855. }
  1856. }
  1857. if($falg)
  1858. $html.='<td class="taR">-</td>';
  1859. }
  1860. $p9+=$psum;
  1861. if(!empty($psum))
  1862. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  1863. else
  1864. $psum='<td class="colGreen taR">-</td>';
  1865. $receiptL['培训班费用']=$psum.$html;
  1866. /*-------------------------------------*/
  1867. $html="";
  1868. $psum=0;
  1869. $item=array('公关费','广告费','借款','可自加费用');
  1870. foreach ($item as $va){
  1871. $falg=true;
  1872. foreach ($receiptCollectList as $v){
  1873. if($v['itemCategory']=='其他'){
  1874. if($v['item']==$va){
  1875. if ($va=='公关费')
  1876. $t1+=$v['price'];
  1877. if ($va=='广告费')
  1878. $t2+=$v['price'];
  1879. if ($va=='借款')
  1880. $t3+=$v['price'];
  1881. if ($va=='可自加费用')
  1882. $t4+=$v['price'];
  1883. $psum+=$v['price'];
  1884. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  1885. }
  1886. }
  1887. }
  1888. if($falg)
  1889. $html.='<td class="taR">-</td>';
  1890. }
  1891. $t5+=$psum;
  1892. if(!empty($psum))
  1893. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  1894. else
  1895. $psum='<td class="colGreen taR">-</td>';
  1896. $receiptL['其他']=$psum.$html;
  1897. /*-------------------------------------*/
  1898. $html="";
  1899. $psum=0;
  1900. foreach ($receiptCollectList as $v){
  1901. if($v['itemCategory']=='报销金额调整'){
  1902. if (!empty($v['price'])){
  1903. $psum+=$v['price'];
  1904. }
  1905. }
  1906. }
  1907. $s1+=$psum;
  1908. if(!empty($psum))
  1909. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  1910. else
  1911. $psum='<td class="taR colOrange">-</td>';
  1912. $receiptL['报销金额调整']=$psum.$html;
  1913. }else{
  1914. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  1915. <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>';
  1916. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  1917. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  1918. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  1919. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  1920. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  1921. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  1922. }
  1923. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  1924. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  1925. if(!empty($monthStaffPrice[0]['price'])){
  1926. $m1+=$monthStaffPrice[0]['price'];
  1927. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  1928. }else
  1929. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  1930. $list[$value['username']]=$receiptL;
  1931. }
  1932. }
  1933. $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>
  1934. <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>';
  1935. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  1936. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  1937. $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>
  1938. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  1939. $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>';
  1940. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  1941. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  1942. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  1943. }
  1944. $data['list']=$list;
  1945. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  1946. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  1947. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  1948. //statistics html
  1949. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  1950. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  1951. if(empty($stList))
  1952. $stList=array('rePrice'=>0,'agPrice'=>0);
  1953. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  1954. $monthHtml="";
  1955. for ($i=1;$i<=12;$i++){
  1956. if ($i==$month)
  1957. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  1958. else
  1959. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  1960. }
  1961. $data['monthHtml']=$monthHtml;
  1962. $data['year']=$year;
  1963. $data['month']=$month;
  1964. $data['memu']="receipt";
  1965. $data['staff']=$this->staff;
  1966. $data['receiptMemu']='companyCategoryCollect';
  1967. $data['verifyId']=$this->verifyId;
  1968. $this->render ( "/admin/staffCollectMonthDetail", $data );
  1969. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  1970. }
  1971. function staffCollectMonthDetail2(){
  1972. $year=$this->get_args('year')?$this->get_args('year'):"";
  1973. $month=$this->get_args('month')?$this->get_args('month'):"";
  1974. if(!$year)
  1975. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  1976. if(!$month)
  1977. $month=isset($this->params['month'])?$this->params['month']:1;
  1978. Doo::loadModel('staff');
  1979. $staff=new staff();
  1980. Doo::loadModel("receiptDetail");
  1981. $receiptDetail=new receiptDetail();
  1982. Doo::loadModel('accountItem');
  1983. $accountItem=new accountItem();
  1984. Doo::loadModel('statistics');
  1985. $statistics=new statistics();
  1986. Doo::loadModel('L_category');
  1987. $lCategory=new L_category();
  1988. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  1989. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  1990. $list=array();
  1991. foreach ($categoryList as $vlu){
  1992. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  1993. $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;
  1994. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  1995. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  1996. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  1997. $s1=0;
  1998. $m1=0;
  1999. foreach ($staffList as $value){
  2000. if ($vlu['cid']==$value['cid']){
  2001. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2002. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  2003. if(!empty($receiptCollectList)){
  2004. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  2005. $html="";
  2006. $psum=0;
  2007. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  2008. foreach ($item as $va){
  2009. $falg=true;
  2010. foreach ($receiptCollectList as $v){
  2011. if($v['itemCategory']=='日常相关费用'){
  2012. if($v['item']==$va){
  2013. if ($va=='市内交通费')
  2014. $r1+=$v['price'];
  2015. if ($va=='市内出租费')
  2016. $r2+=$v['price'];
  2017. if ($va=='办事处房租')
  2018. $r3+=$v['price'];
  2019. if ($va=='电话费')
  2020. $r4+=$v['price'];
  2021. if ($va=='水费')
  2022. $r5+=$v['price'];
  2023. if ($va=='电费')
  2024. $r6+=$v['price'];
  2025. if ($va=='办公费用')
  2026. $r7+=$v['price'];
  2027. if ($va=='邮寄费')
  2028. $r8+=$v['price'];
  2029. if ($va=='其他费用')
  2030. $r9+=$v['price'];
  2031. if ($va=='车辆费用')
  2032. $r10+=$v['price'];
  2033. if ($va=='广告费')
  2034. $r11+=$v['price'];
  2035. if ($va=='团队建设费')
  2036. $r13+=$v['price'];
  2037. $psum+=$v['price'];
  2038. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2039. }
  2040. }
  2041. }
  2042. if($falg)
  2043. $html.='<td class="taR">-</td>';
  2044. }
  2045. $r12+=$psum;
  2046. if(!empty($psum))
  2047. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2048. else
  2049. $psum='<td class="colGreen taR">-</td>';
  2050. $receiptL['日常相关费用']=$psum.$html;
  2051. /*-----------------------------------*/
  2052. $html="";
  2053. $psum=0;
  2054. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  2055. foreach ($item as $va){
  2056. $falg=true;
  2057. foreach ($receiptCollectList as $v){
  2058. if($v['itemCategory']=='差旅相关费用'){
  2059. if($v['item']==$va){
  2060. if ($va=='往来交通费')
  2061. $c1+=$v['price'];
  2062. if ($va=='市内交通费')
  2063. $c2+=$v['price'];
  2064. if ($va=='出差住宿费')
  2065. $c3+=$v['price'];
  2066. if ($va=='出差补助')
  2067. $c4+=$v['price'];
  2068. if ($va=='其他费用')
  2069. $c5+=$v['price'];
  2070. $psum+=$v['price'];
  2071. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2072. }
  2073. }
  2074. }
  2075. if($falg)
  2076. $html.='<td class="taR">-</td>';
  2077. }
  2078. $c6+=$psum;
  2079. if(!empty($psum))
  2080. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2081. else
  2082. $psum='<td class="colGreen taR">-</td>';
  2083. $receiptL['差旅相关费用']=$psum.$html;
  2084. /*-------------------------------------*/
  2085. $html="";
  2086. $psum=0;
  2087. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  2088. foreach ($item as $va){
  2089. $falg=true;
  2090. foreach ($receiptCollectList as $v){
  2091. if($v['itemCategory']=='培训班费用'){
  2092. if($v['item']==$va){
  2093. if ($va=='场租费')
  2094. $p1+=$v['price'];
  2095. if ($va=='薪酬')
  2096. $p2+=$v['price'];
  2097. if ($va=='住宿费')
  2098. $p3+=$v['price'];
  2099. if ($va=='交通费')
  2100. $p4+=$v['price'];
  2101. if ($va=='餐饮费')
  2102. $p5+=$v['price'];
  2103. if ($va=='办公费')
  2104. $p6+=$v['price'];
  2105. if ($va=='公关费')
  2106. $p7+=$v['price'];
  2107. if ($va=='其他')
  2108. $p8+=$v['price'];
  2109. $psum+=$v['price'];
  2110. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2111. }
  2112. }
  2113. }
  2114. if($falg)
  2115. $html.='<td class="taR">-</td>';
  2116. }
  2117. $p9+=$psum;
  2118. if(!empty($psum))
  2119. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2120. else
  2121. $psum='<td class="colGreen taR">-</td>';
  2122. $receiptL['培训班费用']=$psum.$html;
  2123. /*-------------------------------------*/
  2124. $html="";
  2125. $psum=0;
  2126. $item=array('公关费','广告费','借款','可自加费用');
  2127. foreach ($item as $va){
  2128. $falg=true;
  2129. foreach ($receiptCollectList as $v){
  2130. if($v['itemCategory']=='其他'){
  2131. if($v['item']==$va){
  2132. if ($va=='公关费')
  2133. $t1+=$v['price'];
  2134. if ($va=='广告费')
  2135. $t2+=$v['price'];
  2136. if ($va=='借款')
  2137. $t3+=$v['price'];
  2138. if ($va=='可自加费用')
  2139. $t4+=$v['price'];
  2140. $psum+=$v['price'];
  2141. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2142. }
  2143. }
  2144. }
  2145. if($falg)
  2146. $html.='<td class="taR">-</td>';
  2147. }
  2148. $t5+=$psum;
  2149. if(!empty($psum))
  2150. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2151. else
  2152. $psum='<td class="colGreen taR">-</td>';
  2153. $receiptL['其他']=$psum.$html;
  2154. /*-------------------------------------*/
  2155. $html="";
  2156. $psum=0;
  2157. foreach ($receiptCollectList as $v){
  2158. if($v['itemCategory']=='报销金额调整'){
  2159. if (!empty($v['price'])){
  2160. $psum+=$v['price'];
  2161. }
  2162. }
  2163. }
  2164. $s1+=$psum;
  2165. if(!empty($psum))
  2166. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  2167. else
  2168. $psum='<td class="taR colOrange">-</td>';
  2169. $receiptL['报销金额调整']=$psum.$html;
  2170. }else{
  2171. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  2172. <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>';
  2173. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  2174. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2175. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  2176. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2177. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2178. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  2179. }
  2180. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2181. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  2182. if(!empty($monthStaffPrice[0]['price'])){
  2183. $m1+=$monthStaffPrice[0]['price'];
  2184. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  2185. }else
  2186. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  2187. $list[$value['username']]=$receiptL;
  2188. }
  2189. }
  2190. $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>
  2191. <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>';
  2192. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  2193. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  2194. $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>
  2195. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  2196. $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>';
  2197. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  2198. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  2199. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  2200. }
  2201. $data['list']=$list;
  2202. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2203. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  2204. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  2205. //statistics html
  2206. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  2207. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  2208. if(empty($stList))
  2209. $stList=array('rePrice'=>0,'agPrice'=>0);
  2210. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  2211. $monthHtml="";
  2212. for ($i=1;$i<=12;$i++){
  2213. if ($i==$month)
  2214. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  2215. else
  2216. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  2217. }
  2218. $data['monthHtml']=$monthHtml;
  2219. $data['year']=$year;
  2220. $data['month']=$month;
  2221. $data['memu']="receipt";
  2222. $data['staff']=$this->staff;
  2223. $data['receiptMemu']='companyCategoryCollect';
  2224. $data['verifyId']=$this->verifyId;
  2225. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  2226. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  2227. }
  2228. function companyMonthCollectDetail(){
  2229. $year=$this->get_args('year')?$this->get_args('year'):"";
  2230. $month=$this->get_args('month')?$this->get_args('month'):"";
  2231. if(!$year)
  2232. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  2233. if(!$month)
  2234. $month=isset($this->params['month'])?$this->params['month']:1;
  2235. Doo::loadModel('staff');
  2236. $staff=new staff();
  2237. Doo::loadModel("receiptDetail");
  2238. $receiptDetail=new receiptDetail();
  2239. Doo::loadModel('accountItem');
  2240. $accountItem=new accountItem();
  2241. Doo::loadModel('statistics');
  2242. $statistics=new statistics();
  2243. Doo::loadModel('L_category');
  2244. $lCategory=new L_category();
  2245. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  2246. $categoryList=$lCategory->find(array('asArray'=>true));
  2247. $list=array();
  2248. foreach ($categoryList as $value){
  2249. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2250. 'where'=>'cid='.$value['cid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  2251. if(!empty($receiptCollectList)){
  2252. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  2253. $html="";
  2254. $psum=0;
  2255. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  2256. foreach ($item as $va){
  2257. $falg=true;
  2258. foreach ($receiptCollectList as $v){
  2259. if($v['itemCategory']=='日常相关费用'){
  2260. if($v['item']==$va){
  2261. $psum+=$v['price'];
  2262. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2263. }
  2264. }
  2265. }
  2266. if($falg)
  2267. $html.='<td class="taR">-</td>';
  2268. }
  2269. if(!empty($psum))
  2270. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2271. else
  2272. $psum='<td class="colGreen taR">-</td>';
  2273. $receiptL['日常相关费用']=$psum.$html;
  2274. /*-----------------------------------*/
  2275. $html="";
  2276. $psum=0;
  2277. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  2278. foreach ($item as $va){
  2279. $falg=true;
  2280. foreach ($receiptCollectList as $v){
  2281. if($v['itemCategory']=='差旅相关费用'){
  2282. if($v['item']==$va){
  2283. $psum+=$v['price'];
  2284. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2285. }
  2286. }
  2287. }
  2288. if($falg)
  2289. $html.='<td class="taR">-</td>';
  2290. }
  2291. if(!empty($psum))
  2292. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2293. else
  2294. $psum='<td class="colGreen taR">-</td>';
  2295. $receiptL['差旅相关费用']=$psum.$html;
  2296. /*-------------------------------------*/
  2297. $html="";
  2298. $psum=0;
  2299. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  2300. foreach ($item as $va){
  2301. $falg=true;
  2302. foreach ($receiptCollectList as $v){
  2303. if($v['itemCategory']=='培训班费用'){
  2304. if($v['item']==$va){
  2305. $psum+=$v['price'];
  2306. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2307. }
  2308. }
  2309. }
  2310. if($falg)
  2311. $html.='<td class="taR">-</td>';
  2312. }
  2313. if(!empty($psum))
  2314. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2315. else
  2316. $psum='<td class="colGreen taR">-</td>';
  2317. $receiptL['培训班费用']=$psum.$html;
  2318. /*-------------------------------------*/
  2319. $html="";
  2320. $psum=0;
  2321. $item=array('公关费','广告费','借款','可自加费用');
  2322. foreach ($item as $va){
  2323. $falg=true;
  2324. foreach ($receiptCollectList as $v){
  2325. if($v['itemCategory']=='其他'){
  2326. if($v['item']==$va){
  2327. $psum+=$v['price'];
  2328. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2329. }
  2330. }
  2331. }
  2332. if($falg)
  2333. $html.='<td class="taR">-</td>';
  2334. }
  2335. if(!empty($psum))
  2336. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2337. else
  2338. $psum='<td class="colGreen taR">-</td>';
  2339. $receiptL['其他']=$psum.$html;
  2340. /*-------------------------------------*/
  2341. $html="";
  2342. $psum=0;
  2343. foreach ($receiptCollectList as $v){
  2344. if($v['itemCategory']=='报销金额调整'){
  2345. if (!empty($v['price']))
  2346. $psum+=$v['price'];
  2347. }
  2348. }
  2349. if(!empty($psum))
  2350. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  2351. else
  2352. $psum='<td class="taR colOrange">-</td>';
  2353. $receiptL['报销金额调整']=$psum.$html;
  2354. }else{
  2355. $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>
  2356. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2357. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  2358. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2359. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  2360. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2361. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2362. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  2363. }
  2364. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2365. 'where'=>'cid='.$value['cid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  2366. if(!empty($monthStaffPrice[0]['price']))
  2367. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  2368. else
  2369. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  2370. $list[$value['title']]=$receiptL;
  2371. }
  2372. $data['list']=$list;
  2373. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2374. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  2375. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  2376. //statistics html
  2377. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  2378. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  2379. if(empty($stList))
  2380. $stList=array('rePrice'=>0,'agPrice'=>0);
  2381. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  2382. $monthHtml="";
  2383. for ($i=1;$i<=12;$i++){
  2384. if ($i==$month)
  2385. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  2386. else
  2387. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  2388. }
  2389. $data['monthHtml']=$monthHtml;
  2390. $data['year']=$year;
  2391. $data['month']=$month;
  2392. $data['memu']="receipt";
  2393. $data['staff']=$this->staff;
  2394. $data['receiptMemu']='companyCategoryCollect';
  2395. $data['verifyId']=$this->verifyId;
  2396. $this->render ( "/admin/companyMonthCollectDetail", $data );
  2397. }
  2398. function staffCollectDetail(){
  2399. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  2400. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  2401. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  2402. if(!$staffname){
  2403. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  2404. $staffname= urldecode($staffname);
  2405. }
  2406. Doo::loadModel('staff');
  2407. $staff=new staff();
  2408. Doo::loadModel("receiptDetail");
  2409. $receiptDetail=new receiptDetail();
  2410. Doo::loadModel('accountItem');
  2411. $accountItem=new accountItem();
  2412. Doo::loadModel('statistics');
  2413. $statistics=new statistics();
  2414. Doo::loadModel('L_category');
  2415. $lCategory=new L_category();
  2416. $staffList=$staff->find(array('asArray'=>true));
  2417. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  2418. foreach ($staffList as $value){
  2419. if ($value['username']==$staffname&&$value['username']!='admin'){
  2420. $stTitle=$value['category'].'-'.$value['username'];
  2421. $staffId=$value['sid'];
  2422. $cid=$value['cid'];
  2423. $ocid=$value['cid'];
  2424. if (!empty($value['othercid']))
  2425. $cid=$value['cid'].','.$value['othercid'];
  2426. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  2427. }elseif ($value['username']!='admin')
  2428. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  2429. }
  2430. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  2431. if(empty($pcid))
  2432. $pcid=$ocid;
  2433. $data['ocid']=$pcid;
  2434. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  2435. $this->showCache($path);
  2436. //
  2437. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  2438. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  2439. $accountList=$accountItem->find(array('asArray'=>true));
  2440. //create CollectDetail HTML
  2441. $collectHtml=array();
  2442. foreach ($accountList as $key=>$value){
  2443. $html="";$asum=0;
  2444. for ($i=1;$i<=12;$i++){
  2445. $falg=true;
  2446. foreach ($receiptCollectList as $v) {
  2447. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  2448. $asum+=$v['price'];
  2449. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  2450. }
  2451. }
  2452. if($falg)
  2453. $html.='<td class="taR">-</td>';
  2454. }
  2455. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  2456. $collectHtml[$value['category']][$value['name']]=$html;
  2457. }
  2458. $data['collectHtml']=$collectHtml;
  2459. //create Adjustment price html
  2460. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  2461. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  2462. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  2463. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  2464. array_push($collectArray['日常相关费用'], $collectHtml);
  2465. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  2466. array_push($collectArray['差旅相关费用'], $collectHtml);
  2467. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  2468. array_push($collectArray['培训班费用'], $collectHtml);
  2469. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  2470. array_push($collectArray['其他'], $collectHtml);
  2471. $data['collectArray']=$collectArray;
  2472. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  2473. array_push($adjustment, $collectHtml);
  2474. $data['adjustment']=$adjustment;
  2475. //total price html
  2476. $collectHtml="";$total=0;
  2477. for ($i=1;$i<=12;$i++){
  2478. $sumPrice=0;
  2479. foreach ($receiptCollectList as $key=>$value){
  2480. if($value['month']==$i){
  2481. $sumPrice+=$value['price'];
  2482. }
  2483. }
  2484. if ($sumPrice==0)
  2485. $collectHtml.='<td class="taR">-</td>';
  2486. else
  2487. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  2488. $total+=$sumPrice;
  2489. }
  2490. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  2491. //statistics html
  2492. $stList=$statistics->statisticsByYear($year,$staffId);
  2493. if(empty($stList))
  2494. $stList=array('rePrice'=>0,'agPrice'=>0);
  2495. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  2496. $data['totalPrice']=$collectHtml;
  2497. $data['totalYear']=$total;
  2498. $data['stHtml']=$stHtml;
  2499. $data['year']=$year;
  2500. $data['stTitle']=$stTitle;
  2501. $data['memu']="receipt";
  2502. $data['staff']=$this->staff;
  2503. $data['receiptMemu']='companyCategoryCollect';
  2504. $data['verifyId']=$this->verifyId;
  2505. if ($year<date("Y")){
  2506. Doo::loadModel('receipt');
  2507. $receipt=new receipt();
  2508. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  2509. if(empty($receiptList)){ //generated files
  2510. ob_start();
  2511. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  2512. $this->cacheFile($path);die;
  2513. }
  2514. }
  2515. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  2516. }
  2517. function _getMonthCollectDetail($receiptCollectList){
  2518. if(!empty($receiptCollectList)){
  2519. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  2520. $html="";
  2521. $psum=0;
  2522. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  2523. foreach ($item as $value){
  2524. $falg=true;
  2525. foreach ($receiptCollectList as $v){
  2526. if($v['itemCategory']=='日常相关费用'){
  2527. if($v['item']==$value){
  2528. $psum+=$v['price'];
  2529. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2530. }
  2531. }
  2532. }
  2533. if($falg)
  2534. $html.='<td class="taR">-</td>';
  2535. }
  2536. if(!empty($psum))
  2537. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2538. else
  2539. $psum='<td class="colGreen taR">-</td>';
  2540. $receiptL['日常相关费用']=$psum.$html;
  2541. /*-----------------------------------*/
  2542. $html="";
  2543. $psum=0;
  2544. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  2545. foreach ($item as $value){
  2546. $falg=true;
  2547. foreach ($receiptCollectList as $v){
  2548. if($v['itemCategory']=='差旅相关费用'){
  2549. if($v['item']==$value){
  2550. $psum+=$v['price'];
  2551. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2552. }
  2553. }
  2554. }
  2555. if($falg)
  2556. $html.='<td class="taR">-</td>';
  2557. }
  2558. if(!empty($psum))
  2559. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2560. else
  2561. $psum='<td class="colGreen taR">-</td>';
  2562. $receiptL['差旅相关费用']=$psum.$html;
  2563. /*-------------------------------------*/
  2564. $html="";
  2565. $psum=0;
  2566. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  2567. foreach ($item as $value){
  2568. $falg=true;
  2569. foreach ($receiptCollectList as $v){
  2570. if($v['itemCategory']=='培训班费用'){
  2571. if($v['item']==$value){
  2572. $psum+=$v['price'];
  2573. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2574. }
  2575. }
  2576. }
  2577. if($falg)
  2578. $html.='<td class="taR">-</td>';
  2579. }
  2580. if(!empty($psum))
  2581. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2582. else
  2583. $psum='<td class="colGreen taR">-</td>';
  2584. $receiptL['培训班费用']=$psum.$html;
  2585. /*-------------------------------------*/
  2586. $html="";
  2587. $psum=0;
  2588. $item=array('公关费','广告费','借款','可自加费用');
  2589. foreach ($item as $value){
  2590. $falg=true;
  2591. foreach ($receiptCollectList as $v){
  2592. if($v['itemCategory']=='其他'){
  2593. if($v['item']==$value){
  2594. $psum+=$v['price'];
  2595. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  2596. }
  2597. }
  2598. }
  2599. if($falg)
  2600. $html.='<td class="taR">-</td>';
  2601. }
  2602. if(!empty($psum))
  2603. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  2604. else
  2605. $psum='<td class="colGreen taR">-</td>';
  2606. $receiptL['其他']=$psum.$html;
  2607. /*-------------------------------------*/
  2608. $html="";
  2609. $psum=0;
  2610. foreach ($receiptCollectList as $v){
  2611. if($v['itemCategory']=='报销金额调整'){
  2612. if (!empty($v['price']))
  2613. $psum+=$v['price'];
  2614. }
  2615. }
  2616. if(!empty($psum))
  2617. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  2618. else
  2619. $psum='<td class="taR colOrange">-</td>';
  2620. $receiptL['报销金额调整']=$psum.$html;
  2621. }else{
  2622. $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>
  2623. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2624. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  2625. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2626. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  2627. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2628. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  2629. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  2630. }
  2631. return $receiptL;
  2632. }
  2633. function eMail(){
  2634. Doo::loadModel('staff');
  2635. $staff=new staff();
  2636. Doo::loadModel('receipt');
  2637. $receipt=new receipt();
  2638. Doo::loadModel('L_category');
  2639. $Lcategory=new L_category();
  2640. Doo::loadModel("verify");
  2641. $verify=new verify();
  2642. $staffList=$staff->find(array('asArray'=>true));
  2643. foreach ($staffList as $key=>$value){
  2644. if($value['username']!='admin'){
  2645. //提交人
  2646. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  2647. if(!empty($receiptList)){
  2648. $html='<br><div><style></style>
  2649. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  2650. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  2651. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  2652. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  2653. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  2654. <tbody><tr>
  2655. <td style="padding: 0 40px;" align="left">
  2656. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  2657. </td></tr><tr>
  2658. <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>
  2659. </tr>
  2660. </tbody> </table></td> </tr> <tr><td>
  2661. <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">
  2662. <tbody> <tr><td>
  2663. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  2664. 以下报销单完成了审批,等着收款吧:</p>
  2665. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  2666. foreach ($receiptList as $k=>$v){
  2667. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  2668. $html.='
  2669. <tr>
  2670. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  2671. <td align="left">
  2672. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  2673. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  2674. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  2675. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  2676. </tr>';
  2677. }
  2678. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  2679. <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>
  2680. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  2681. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  2682. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  2683. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  2684. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  2685. $receipt=new receipt();
  2686. $receipt->notice=1;
  2687. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  2688. }
  2689. }
  2690. //审批人
  2691. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  2692. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  2693. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  2694. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  2695. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  2696. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  2697. <tbody><tr><td style="padding: 0 40px;" align="left">
  2698. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  2699. </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>
  2700. </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">
  2701. <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>
  2702. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  2703. foreach ($verifyList as $k=>$v){
  2704. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  2705. foreach ($receiptList as $r=>$l){
  2706. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  2707. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  2708. $html.='
  2709. <tr>
  2710. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  2711. <td align="left">
  2712. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  2713. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  2714. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  2715. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  2716. </tr>';
  2717. }
  2718. }
  2719. $html.='
  2720. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  2721. <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>
  2722. </tr></tbody></table></td></tr></tbody></table></div><br>';
  2723. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  2724. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  2725. // $receipt=new receipt();
  2726. // $receipt->notice=1;
  2727. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  2728. }
  2729. }
  2730. }
  2731. }
  2732. // Email发送函数
  2733. function SMail($toemail, $subject, $contents) {
  2734. Doo::loadClass('class.phpmailer');
  2735. $mail = new PHPMailer();
  2736. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  2737. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  2738. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  2739. $mail->Password = "cDO1GjtY1seH"; //密码
  2740. $mail->CharSet = "UTF8";
  2741. $mail->SMTPAuth = true;
  2742. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  2743. $mail->Mailer = "smtp";
  2744. $mail->Port = 25;
  2745. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  2746. $mail->MsgHTML($contents);
  2747. $mail->AddAddress($toemail);
  2748. $mail->CharSet = "UTF-8";
  2749. return $mail->Send();
  2750. }
  2751. /**
  2752. * 获取get或者POST值
  2753. * @param string $name 属性名称
  2754. * @return fixed 值
  2755. */
  2756. function get_args($name) {
  2757. if (isset ( $_GET [$name] )) {
  2758. if (is_array ( $_GET [$name] ))
  2759. return $_GET [$name];
  2760. else
  2761. return addslashes ( $_GET [$name] );
  2762. } elseif (isset ( $_POST [$name] )) {
  2763. if (is_array ( $_POST [$name] ))
  2764. return $_POST [$name];
  2765. else
  2766. return addslashes ( $_POST [$name] );
  2767. } else
  2768. return false;
  2769. }
  2770. }
  2771. ?>