| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179 | 
							- <?php
 
- /**
 
-  * @author darkredz
 
-  */
 
- class ReceiptExtendController extends DooController {
 
- 	public $staff;
 
- 	public $verifyId;
 
- 	public $executeId;
 
- 	
 
- 	// public static $NEW2 = 0;
 
- 	public $AGENCY = "日常相关费用";
 
- 	public $TRAVEL = "差旅相关费用";
 
- 	public $TRAIN = "培训班费用";
 
- 	public $OTHER = "其他";
 
- 	private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
 
- 	private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
 
- 	private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
 
- 	private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
 
- 	private function showCache($path) {
 
- 		if (file_exists ( $path )) {
 
- 			echo "<!DOCTYPE html>";
 
- 			include $path;
 
- 			die ();
 
- 		}
 
- 	}
 
- 	private function cacheFile($path) {
 
- 		$content = ob_get_contents ();
 
- 		$fp = fopen ( $path, "w" );
 
- 		fwrite ( $fp, $content );
 
- 		fclose ( $fp );
 
- 	}
 
- 	private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
 
- 		$collectHtml = "";
 
- 		$sumPrice = 0.00;
 
- 		for($i = 1; $i <= 12; $i ++) {
 
- 			$falg = true;
 
- 			foreach ( $receiptCollectList as $key => $value ) {
 
- 				if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
 
- 					$sumPrice += $value ['price'];
 
- 					if ($classType == "b") {
 
- 						$collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
 
- 						$falg = false;
 
- 						break;
 
- 					} else {
 
- 						$collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
 
- 						$falg = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 			}
 
- 			if ($falg)
 
- 				$collectHtml .= '<td class="taR">-</td>';
 
- 		}
 
- 		$collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
 
- 		return $collectHtml;
 
- 	}
 
- 	public function beforeRun($resource, $action) {
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$sid = $XDeode->decode ( $_COOKIE ["staff"] );
 
- 		// 单独判断公司汇总的访问权限
 
- 		if ($action == 'companyCategoryCollect') {
 
- 			Doo::loadModel ( "receiptAuthorityManage" );
 
- 			$invoiceCompanyManage = new receiptAuthorityManage ();
 
- 			
 
- 			$icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
 
- 			if (empty ( $icm ))
 
- 				die ( 'illegal request' );
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		$detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
 
- 		
 
- 		$accessModular = 'RECEIPTSEXTEND'; // 是否已经开放的方法
 
- 		$accessAuthority = 'RECEIPTS';
 
- 		if (empty ( $detail ['cldAccessArray'] ))
 
- 			die ( 'illegal request' );
 
- 		else {
 
- 			if (in_array ( $accessAuthority, $detail ['cldAccessArray'] )) {
 
- 				if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
 
- 					$flag = true;
 
- 				} else {
 
- 					$flag = false;
 
- 				}
 
- 			} else {
 
- 				die ( 'illegal request' );
 
- 			}
 
- 		}
 
- 		if (! $flag)
 
- 			die ( 'illegal request' );
 
- 	}
 
- 	function __construct() {
 
- 		if (isset ( $_COOKIE ["staff"] )) {
 
- 			
 
- 			if (! empty ( $_COOKIE ["staff"] )) {
 
- 				
 
- 				Doo::loadModel ( 'staff' );
 
- 				Doo::loadModel ( 'verify' );
 
- 				$verify = new verify ();
 
- 				$staff = new staff ();
 
- 				Doo::loadModel ( "execute" );
 
- 				$execute = new execute ();
 
- 				
 
- 				$verifyList = $verify->find ( array (
 
- 						'select' => 'staff',
 
- 						'asArray' => true 
 
- 				) );
 
- 				$list = array ();
 
- 				
 
- 				// 判断角色的审批权限
 
- 				foreach ( $verifyList as $key => $value ) {
 
- 					$ver = json_decode ( $value ['staff'] );
 
- 					
 
- 					foreach ( $ver as $k => $v ) {
 
- 						if ($v [1] == 'ROLE') {
 
- 							$roleList = json_decode ( $v [3] );
 
- 							foreach ( $roleList as $t => $g ) {
 
- 								$gList = explode ( "_", $g );
 
- 								array_push ( $list, $gList [0] );
 
- 								// print_r($list);
 
- 							}
 
- 						} else
 
- 							array_push ( $list, $v [0] );
 
- 					}
 
- 				}
 
- 				
 
- 				// 判断执行人的审批权限
 
- 				$executeList = $execute->find ( array (
 
- 						'where'=>'mold !="日常收支"',
 
- 						'select' => 'staff',
 
- 						'asArray' => true 
 
- 				) );
 
- 				$list2 = array ();
 
- 				foreach ( $executeList as $key => $value ) {
 
- 					$ver = json_decode ( $value ['staff'] );
 
- 					
 
- 					foreach ( $ver as $k => $v ) {
 
- 						array_push ( $list2, $v [0] );
 
- 					}
 
- 				}
 
- 				//print_r($executeList);
 
- 				$eidList = file_get_contents ( "protected/config/execute/execute.ini" );
 
- 				$eidList = array_filter ( explode ( ",", $eidList ) );
 
- 				
 
- 				$this->executeId = array_merge ( $list2, $eidList );
 
- 				
 
- 				$this->verifyId = $list;
 
- 				$this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
 
- 				
 
- 				// 检测用户信息完成
 
- 				$this->data ['isStaffCompleteMsg'] = false;
 
- 				$detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
 
- 				if (! empty ( $detail ))
 
- 					$this->data ['isStaffCompleteMsg'] = true;
 
- 				
 
- 				return "/";
 
- 			}
 
- 		}
 
- 		
 
- 		Doo::loadCore ( 'uri/DooUriRouter' );
 
- 		$router = new DooUriRouter ();
 
- 		$routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
 
- 		
 
- 		if ($routeRs ['1'] != "login") {
 
- 			header ( 'Content-Type:text/html;charset=utf-8' );
 
- 			@header ( "Location: /login" );
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 查看审批培训班结算
 
- 	 */
 
- 	function receiptTrain() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
 
- 		
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		$trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		
 
- 		// 如有已入账已收款的发票,自动取消办事处已收款
 
- 		// Doo::loadModel ( 'RIExtend' );
 
- 		// $RIExtend = new RIExtend ();
 
- 		// $RIExtendList=$RIExtend->getRIExtendByRid($rid);
 
- 		// if (!empty($RIExtendList)){
 
- 		// foreach ($RIExtenreceiptTrainRevenuedList as $key=>$value){
 
- 		// $RIExtend = new RIExtend ();
 
- 		// $RIExtend->delete(array (
 
- 		// 'where' => 'iid=' . $value['iid'],
 
- 		// 'limit' => 1
 
- 		// ));
 
- 		// }
 
- 		// }
 
- 		
 
- 		$data ['receiptMemu'] = 'expenses';
 
- 		if ($showType == 'approval') {
 
- 			$data ['receiptMemu'] = 'approvalExpenses';
 
- 			// if ($receiptDetail ['status'] != 2)
 
- 			// die ();
 
- 		} elseif ($showType == 'implement') {
 
- 			$data ['receiptMemu'] = 'implement';
 
- 			// if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
 
- 			// die ();
 
- 		}
 
- 		$data ['showType'] = $showType;
 
- 		
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		// 汇总表合计
 
- 		// 收入合计
 
- 		Doo::loadModel ( 'invoiceTraining' );
 
- 		$invoiceTraining = new invoiceTraining ();
 
- 		$invoiceTrainingDetail = array (
 
- 				'invoiceArriveAmount' => '0.00',
 
- 				'RIAmount' => '0.00',
 
- 				'invoiceTotalAmount' => '0.00',
 
- 				'invoiceCompanyAmount' => '0.00',
 
- 				'invoiceArriveAmountM'=>'0.00',
 
- 				'invoiceCompanyAmountM'=>'0.00'
 
- 		);
 
- 		if ($receiptDetail ['invoiceTrainId'] != 0) {
 
- 			$invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
 
- 		}
 
- 		// print_r($invoiceTrainingDetail);
 
- 		$invoiceArriveAmount = $RIAmount = 0;
 
- 		if (! empty ( $invoiceTrainingDetail )) {
 
- 			$invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
 
- 			$RIAmount = $invoiceTrainingDetail ['RIAmount'];
 
- 		}
 
- 		$data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
 
- 		// 支出项目
 
- 		Doo::loadModel ( 'accountItem' );
 
- 		$accountItem = new accountItem ();
 
- 		
 
- 		// 项目金额合计
 
- 		Doo::loadModel ( 'RItem' );
 
- 		$RItem = new RItem ();
 
- 		// 讲师获得
 
- 		Doo::loadModel ( 'RILecturer' );
 
- 		$RILecturer = new RILecturer ();
 
- 		$RItemList = $RItem->getRItemByRid ( $rid );
 
- 		$RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
 
- 		// 支出项金额详情
 
- 		$aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
 
- 		
 
- 		// 利润
 
- 		$profit = $invoiceArriveAmount - $aiData ['total'];
 
- 		$companyProfit = $profit * 0.6;
 
- 		$categoryProfit = $profit * 0.4;
 
- 		
 
- 		$data ['profit'] = sprintf ( "%.2f", $profit );
 
- 		$data ['companyProfit'] = sprintf ( "%.2f", $companyProfit );
 
- 		$data ['categoryProfit'] = sprintf ( "%.2f", $categoryProfit );
 
- 		// 发票利润
 
- 		$data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
 
- 		
 
- 		// 发票公司利润
 
- 		$invoiceCompanyProfit = $data ['invoiceProfit'] * 0.6;
 
- 		$data ['invoiceCompanyProfit'] = sprintf ( "%.2f", $invoiceCompanyProfit );
 
- 		// 办事处利润
 
- 		$invoiceCategoryProfit = $data ['invoiceProfit'] * 0.4;
 
- 		$data ['invoiceCategoryProfit'] = sprintf ( "%.2f", $invoiceCategoryProfit );
 
- 		
 
- 		// print_r($aiData['dataList']);
 
- 		$categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
 
- 		$data ['categoryActualExpenditure'] = sprintf ( "%.2f", $categoryActualExpenditure );
 
- 		// 备用金
 
- 		$sum = 0;
 
- 		$data ['receiptLoanDetail'] = array (
 
- 				'sum' => '0.00' 
 
- 		);
 
- 		if (! empty ( $receiptDetail ['trainLoanRid'] )) {
 
- 			
 
- 			$receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
 
- 			foreach ($receiptLoanList as $key=>$value){
 
- 				$sum+=$value['sum'];
 
- 			}
 
- 			$data ['receiptLoanDetail'] = array (
 
- 					'sum' => $sum
 
- 			);
 
- 			//$data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
 
- 			//$sum = $data ['receiptLoanDetail'] ['sum'];
 
- 		}
 
- 		
 
- 		$payment = $sum + $RIAmount - $categoryActualExpenditure;
 
- 		$data ['payment'] = sprintf ( "%.2f", $payment );
 
- 		$data ['paymentAbs']=sprintf ( "%.2f",abs($payment));
 
-         Doo::loadClass ( 'authcode.func' );
 
-         $data ['paymentAuthCode'] = authcode($payment,'');
 
- 		$data ['total'] = sprintf ( "%.2f", $aiData ['total'] );
 
- 		$data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
 
- 		$data ['aiList'] = $aiData ['dataList'];
 
- 		
 
- 		// 占比计算
 
- 		if ($invoiceArriveAmount != 0) {
 
- 			$data ['totalProportion'] = sprintf ( "%.2f", $aiData ['total'] / $invoiceArriveAmount * 100 );
 
- 			$data ['profitProportion'] = sprintf ( "%.2f", $profit / $invoiceArriveAmount * 100 ); // number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
 
- 			$data ['sumProportion'] = sprintf ( "%.2f", $sum / $invoiceArriveAmount * 100 ); // number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
 
- 			$data ['invoiceTotalAmountProportion'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount * 100 );
 
- 			$data ['RIAmountProportion'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount * 100 );
 
- 			$data ['companyProfitProportion'] = sprintf ( "%.2f", $companyProfit / $invoiceArriveAmount * 100 );
 
- 			$data ['categoryProportion'] = sprintf ( "%.2f", $categoryProfit / $invoiceArriveAmount * 100 );
 
- 			$data ['categoryActualExpenditureProportion'] = sprintf ( "%.2f", $categoryActualExpenditure / $invoiceArriveAmount * 100 );
 
- 			$data ['paymentProportion'] = sprintf ( "%.2f", $payment / $invoiceArriveAmount * 100 );
 
- 		} else {
 
- 			$data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
 
- 		}
 
- 		// 发票金额占比计算
 
- 		if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
 
- 			// 支出
 
- 			$data ['invoicetotalProportion'] = sprintf ( "%.2f", $aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 利润
 
- 			$data ['invoiceprofitProportion'] = sprintf ( "%.2f", $data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 公司利润
 
- 			$data ['invoicecompanyProfitProportion'] = sprintf ( "%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 办事处利润
 
- 			$data ['invoicecategoryProportion'] = sprintf ( "%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 公司收款
 
- 			$data ['invoiceTotalAmountProportionB'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 备用金
 
- 			$data ['invoicesumProportion'] = sprintf ( "%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 办事处收款
 
- 			$data ['invoiceRIAmountProportion'] = sprintf ( "%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 办事处实际支出
 
- 			$data ['ICAEP'] = sprintf ( "%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 			// 付总部款
 
- 			$data ['invoicepaymentProportion'] = sprintf ( "%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount'] * 100 );
 
- 		} else {
 
- 			$data ['invoiceprofitProportion'] = $data ['invoiceRIAmountProportion'] = $data ['invoicetotalProportion'] = $data ['invoiceTotalAmountProportionB'] = $data ['invoicesumProportion'] = $data ['ICAEP'] = $data ['invoicepaymentProportion'] = $data ['invoicecompanyProfitProportion'] = $data ['invoicecategoryProportion'] = 0;
 
- 		}
 
- 		
 
- 		// 是否写入过流水
 
- 		$accountType = 0;
 
- 		if ($receiptDetail ['Rtype'] == 0) {
 
- 			$accountType = 3;
 
- 		} elseif ($receiptDetail ['Rtype'] == 1) {
 
- 			if ($receiptDetail ['Rtype'] == 0) {
 
- 				$accountType = 1;
 
- 			} elseif ($receiptDetail ['Rtype'] == 1) {
 
- 				$accountType = 2;
 
- 			}
 
- 		} elseif ($receiptDetail ['Rtype'] == 2) {
 
- 			$accountType = 4;
 
- 		} elseif ($receiptDetail ['Rtype'] == 3) {
 
- 			$accountType = 12;
 
- 		}
 
- 		Doo::loadModel ( 'wasteBook' );
 
- 		$wasteBook = new wasteBook ();
 
- 		$wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptDetail ['rid'] );
 
- 		$data ['wbDetail'] = $wbDetail;
 
- 		
 
- 		// 讲师人数
 
- 		Doo::loadModel ( 'RILecturer' );
 
- 		$RILecturer = new RILecturer ();
 
- 		$RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
 
- 		$data ['lectureCount'] = count ( $RILecturerList );
 
- 		
 
- 		// 审批组
 
- 		Doo::loadModel ( 'verify' );
 
- 		$verify = new verify ();
 
- 		$veList = $verify->getVerifyByAll ();
 
- 		
 
- 		// 办事处
 
- 		Doo::loadModel ( 'L_category' );
 
- 		$lCategory = new L_category ();
 
- 		$data ['category'] = $lCategory->getCategory ();
 
- 		
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['veList'] = $veList;
 
- 		$data ['trainEdiType'] = $trainEdiType;
 
- 		$data ['ridKey'] = $ridKey;
 
- 		
 
- 		$summaryJson = array (
 
- 				0 => array (
 
- 						'invoiceTotalAmount' => $data ['invoiceTrainingDetail'] ['invoiceTotalAmount'],
 
- 						'invoiceArriveAmount' => $data ['invoiceTrainingDetail'] ['invoiceArriveAmount']
 
- 				),
 
- 				1 => array (
 
- 						'1' => $data ['total'],
 
- 						'2' => $data ['invoicetotalProportion'] . '%',
 
- 						'3' => $data ['total'],
 
- 						'4' => $data ['totalProportion'] . '%'
 
- 				),
 
- 				2 => array (
 
- 						'1' => $data ['invoiceProfit'],
 
- 						'2' => $data ['invoiceprofitProportion'] . '%',
 
- 						'3' => $data ['profit'],
 
- 						'4' => $data ['profitProportion'] . '%'
 
- 				),
 
- 		
 
- 				3 => array (
 
- 						'1' => $data ['invoiceCompanyProfit'],
 
- 						'2' => $data ['invoicecompanyProfitProportion'] . '%',
 
- 						'3' => $data ['companyProfit'],
 
- 						'4' => $data ['companyProfitProportion'] . '%'
 
- 				),
 
- 				4 => array (
 
- 						'1' => $data ['invoiceCategoryProfit'],
 
- 						'2' => $data ['invoicecategoryProportion'] . '%',
 
- 						'3' => $data ['categoryProfit'],
 
- 						'4' => $data ['categoryProportion'] . '%'
 
- 				),
 
- 				5 => array (
 
- 						'1' =>$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'],
 
- 						'2' => $data ['invoiceTotalAmountProportionB'] . '%',
 
- 						'3' => $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'],
 
- 						'4' => $data ['invoiceTotalAmountProportion'] . '%'
 
- 				),
 
- 		
 
- 				6 => array (
 
- 						'1' =>$data ['receiptLoanDetail'] ['sum'],
 
- 						'2' => $data ['invoicesumProportion'] . '%',
 
- 						'3' => $data ['receiptLoanDetail'] ['sum'],
 
- 						'4' => $data ['sumProportion'] . '%'
 
- 				),
 
- 				7 => array (
 
- 						'1' =>$data ['invoiceTrainingDetail'] ['RIAmount'],
 
- 						'2' => $data ['invoiceRIAmountProportion'] . '%',
 
- 						'3' => $data ['invoiceTrainingDetail'] ['RIAmount'],
 
- 						'4' => $data ['RIAmountProportion'] . '%'
 
- 				),
 
- 				8 => array (
 
- 						'1' =>$data ['categoryActualExpenditure'],
 
- 						'2' => $data ['ICAEP'] . '%',
 
- 						'3' => $data ['categoryActualExpenditure'] ,
 
- 						'4' => $data ['categoryActualExpenditureProportion'] . '%'
 
- 				),
 
- 				9 => array (
 
- 						'1' =>$data ['payment'],
 
- 						'2' => $data ['invoicepaymentProportion'] . '%',
 
- 						'3' => $data ['payment'] ,
 
- 						'4' => $data ['paymentProportion'] . '%'
 
- 				),
 
- 				10 => array (
 
- 						'participants' =>$data ['receiptTrainingDetail'] ['participants'],
 
- 						'lectureCount' => $data ['lectureCount'] ,
 
- 				),
 
- 				11=>array(
 
- 						'total'=>$data ['total'],
 
- 						'totalProportion'=>$data ['totalProportion']
 
- 				),
 
- 		);
 
- 		$data ['summaryJson'] =URLEncode(json_encode($summaryJson));
 
- 		$data ['aiListJson'] =URLEncode(json_encode($data ['aiList']));
 
- 		 
 
- 		$data['inputDate']=date ( "Y-m-d H:i:s" );
 
- 		
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrain", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班借款
 
- 	 */
 
- 	function receiptTrainLoan() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		Doo::loadModel ( 'verify' );
 
- 		$verify = new verify ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		$data ['receiptMemu'] = 'expenses';
 
- 		if ($showType == 'approval') {
 
- 			$data ['receiptMemu'] = 'approvalExpenses';
 
- 			// if ($receiptDetail ['status'] != 2)
 
- 			// die ();
 
- 		} elseif ($showType == 'implement') {
 
- 			$data ['receiptMemu'] = 'implement';
 
- 			// if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
 
- 			// die ();
 
- 		}
 
- 		$data ['showType'] = $showType;
 
- 		
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		// 借款详情HTML
 
- 		// 获得借款信息
 
- 		$receiptLoanHtml = '';
 
- 		if (! empty ( $receiptDetail ['trainLoanRid'] )) {
 
- 			
 
- 			
 
- 			$receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
 
- 			foreach ($receiptLoanList as $key=>$value){
 
- 				// 获得某费用单审批信息
 
- 				$verifylist = $verify->getVerifyByRid ( $value ['rid'] );
 
- 				Doo::loadClass ( 'receipt.func' );
 
- 				$extendHtml = '';
 
- 				$receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
 
- 			
 
- 			}
 
- 						
 
- 		}
 
- 		
 
- 		$data ['receiptLoanHtml'] = $receiptLoanHtml;
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "LOAN";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrainLoan", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算 ---开票
 
- 	 */
 
- 	function receiptTrainInvoice() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		Doo::loadModel ( 'invoice' );
 
- 		$invoice = new invoice ();
 
- 		Doo::loadModel ( 'invoiceTraining' );
 
- 		$invoiceTraining = new invoiceTraining ();
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		$data ['receiptMemu'] = 'expenses';
 
- 		if ($showType == 'approval') {
 
- 			$data ['receiptMemu'] = 'approvalExpenses';
 
- 			// if ($receiptDetail ['status'] != 2)
 
- 			// die ();
 
- 		} elseif ($showType == 'implement') {
 
- 			$data ['receiptMemu'] = 'implement';
 
- 			// if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
 
- 			// die ();
 
- 		}
 
- 		$data ['showType'] = $showType;
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		$invoiceList = $invoiceTrainingDetail = array ('invoiceTotalAmount'=>0,'invoiceArriveAmount'=>0);
 
- 		if ($receiptDetail ['invoiceTrainId'] != 0) {
 
- 			$invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
 
- 			$invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
 
- 		}
 
- 		//收款是否完成更新状态
 
-         //$RIC=$invoiceTrainingDetail['RIAmount']+$invoiceTrainingDetail['invoiceCompanyAmount'];
 
- 		if ($invoiceTrainingDetail['invoiceTotalAmount']<=$invoiceTrainingDetail['invoiceArriveAmount']&&$receiptDetail['paidStatus']==0){
 
-             $receipt = new receipt ();
 
-             $itemData = array (
 
-                 'rid' => $rid,
 
-                 'paidStatus' => 1,
 
-             );
 
-             $receipt->setReceiptByCondition($itemData);
 
-         }
 
- 		// print_r($invoiceList);
 
- 		$data ['invoiceList'] = $invoiceList;
 
- 		$data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "INVOICE";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrainInvoice", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算
 
- 	 */
 
- 	function receiptTrainItem() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
-         $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		Doo::loadModel ( 'RItem' );
 
- 		$RItem = new RItem ();
 
- 		Doo::loadModel ( 'accountItem' );
 
- 		$accountItem = new accountItem ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		$data ['receiptMemu'] = 'expenses';
 
- 		if ($showType == 'approval') {
 
- 			$data ['receiptMemu'] = 'approvalExpenses';
 
- 			// if ($receiptDetail ['status'] != 2)
 
- 			// die ();
 
- 		} elseif ($showType == 'implement') {
 
- 			$data ['receiptMemu'] = 'implement';
 
- 			// if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
 
- 			// die ();
 
- 		}
 
- 		$data ['showType'] = $showType;
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		$RItemList = $RItem->getRItemByRid ( $rid,$name );
 
- 		$aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );
 
- 		
 
- 		// print_r($RItemList);
 
-         $data ['name'] = $name;
 
- 		$data ['RItemList'] = $RItemList;
 
- 		$data ['aiList'] = $aiList;
 
- 		
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "ITEM";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrainItem", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算-讲师
 
- 	 */
 
- 	function receiptTrainLecturer() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		Doo::loadModel ( 'RILecturer' );
 
- 		$RILecturer = new RILecturer ();
 
- 		
 
- 		Doo::loadModel ( 'lecturer' );
 
- 		$lecturer = new lecturer ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		$data ['receiptMemu'] = 'expenses';
 
- 		if ($showType == 'approval') {
 
- 			$data ['receiptMemu'] = 'approvalExpenses';
 
- 			// if ($receiptDetail ['status'] != 2)
 
- 			// die ();
 
- 		} elseif ($showType == 'implement') {
 
- 			$data ['receiptMemu'] = 'implement';
 
- 			// if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6))
 
- 			// die ();
 
- 		}
 
- 		$data ['showType'] = $showType;
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		$RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
 
- 		
 
- 		$lecturerList = $lecturer->getLecturerAll ();
 
- 		$INSIDEhtml = $OUTSIDEhtml = '';
 
- 		foreach ( $lecturerList as $key => $value ) {
 
- 			if ($value ['ltype'] == 'INSIDE') {
 
- 				$INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
 
- 			} elseif ($value ['ltype'] == 'OUTSIDE') {
 
- 				$OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
 
- 			}
 
- 		}
 
- 		$data ['INSIDEhtml'] = $INSIDEhtml;
 
- 		$data ['OUTSIDEhtml'] = $OUTSIDEhtml;
 
- 		// print_r($RItemList);
 
- 		$data ['RILecturerList'] = $RILecturerList;
 
- 		
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "LECTURER";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrainLecturer", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算编辑-协助
 
- 	 */
 
- 	function receiptTrainAssistEdi() {
 
- 		$ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		Doo::loadModel ( 'RAssist' );
 
- 		$RAssist = new RAssist ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
 
- 			die ();
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		$RAssistList = $RAssist->getRAssistByRid ( $rid );
 
- 		$assistStaffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
 
- 		
 
- 		// print_r($RAssistList);
 
- 		$data ['$assistStaffList'] = $assistStaffList;
 
- 		$data ['RAssistList'] = $RAssistList;
 
- 		
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "ASSIST";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['receiptMemu'] = 'saeaBorad';
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrainAssistEdi", $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加协助人
 
- 	 */
 
- 	function receiptTrainAssistAddDo() {
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
 
- 		$sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : "";
 
- 		
 
- 		if (! empty ( $ridKey ) && ! empty ( $sidKey )) {
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			Doo::loadModel ( 'RAssist' );
 
- 			$RAssist = new RAssist ();
 
- 			
 
- 			$rid = $XDeode->decode ( $ridKey );
 
- 			$sid = $XDeode->decode ( $sidKey );
 
- 			if (! is_numeric ( $rid ) || ! is_numeric ( $sid )) {
 
- 				die ( 'illegal request' );
 
- 			}
 
- 			
 
- 			$RAssist->rid = $rid;
 
- 			$RAssist->sid = $sid;
 
- 			$RAssist->date = date ( "Y-m-d" );
 
- 			$RAssist->insert ();
 
- 			
 
- 			$XDeode = new XDeode ( 7 );
 
- 			return '/receiptTrainAssistEdi/' . $XDeode->encode ( $rid ) . '.html';
 
- 		} else
 
- 			die ( 'illegal request' );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除协作人
 
- 	 */
 
- 	function receiptTrainAssistDelDo() {
 
- 		$aidKey = isset ( $this->params ['aidKey'] ) ? $this->params ['aidKey'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$aid = $XDeode->decode ( $aidKey );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		if (! is_numeric ( $aid )) {
 
- 			die ( 'illegal request--id' );
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'RAssist' );
 
- 		$RAssist = new RAssist ();
 
- 		
 
- 		$RAssist->delete ( array (
 
- 				'where' => 'aid=' . $aid 
 
- 		) );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		return '/receiptTrainAssistEdi/' . $XDeode->encode ( $rid ) . '.html';
 
- 	}
 
- 	
 
- 	/*
 
- 	 * 培训班结算-审批
 
- 	 */
 
- 	function receiptTrainApproval() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		
 
- 		Doo::loadModel ( 'lecturer' );
 
- 		$lecturer = new lecturer ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		// 是否有权访问
 
- 		if ($showType != 'info') {
 
- 			if (! in_array ( $this->staff [0] ['sid'], $this->verifyId )) {
 
- 				die ( 'illegal request-verifyId' );
 
- 			}
 
- 		}
 
- 		
 
- 		// 用户的访问页面类型
 
- 		$data ['receiptMemu'] = 'expenses';
 
- 		if ($showType == 'approval') {
 
- 			$data ['receiptMemu'] = 'approvalExpenses';
 
- 			// if ($receiptDetail ['status'] != 2)
 
- 			// die ();
 
- 		}
 
- 		$data ['showType'] = $showType;
 
- 		
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		// 获取审批日志
 
- 		Doo::loadModel ( 'receiptLog' );
 
- 		$receiptLog = new receiptLog ();
 
- 		
 
- 		// echo $rid;
 
- 		$rlList = $receiptLog->find ( array (
 
- 				'where' => 'rid=' . $rid,
 
- 				'asc' => 'rlid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$data ['rlList'] = $rlList;
 
- 		
 
- 		// 审批组
 
- 		Doo::loadModel ( 'verify' );
 
- 		$verify = new verify ();
 
- 		$verifyList = $verify->getOne ( array (
 
- 				'where' => 'vid=' . $receiptDetail ['verify'],
 
- 				'asArray' => true 
 
- 		) );
 
- 		$verifyList = json_decode ( $verifyList ['staff'], true );
 
- 		$verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
 
- 		$verifyList = $this->fnGetReceiptApprovalProcess ( $verifyList, $verifyStaff );
 
- 		$data ['verifyList'] = $verifyList ['verifyList'];
 
- 		// print_r($verifyList['verifyList']);
 
- 		
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "APPROVAL";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		if ($showType == 'approval') {
 
- 			$this->render ( "/receipt/receiptTrainApproval", $data );
 
- 		} else {
 
- 			$this->render ( "/receipt/receiptTrainApprovalInfo", $data );
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算--执行
 
- 	 */
 
- 	function receiptTrainImplement() {
 
- 		$showType = isset ( $this->params ['showType'] ) ? $this->params ['showType'] : 'implement';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		
 
- 		Doo::loadModel ( 'lecturer' );
 
- 		$lecturer = new lecturer ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		// 是否有权访问
 
- 		
 
- 		if (! in_array ( $this->staff [0] ['sid'], $this->executeId )) {
 
- 			die ( 'illegal request' );
 
- 		}
 
- 		
 
- 		// 用户的访问页面类型
 
- 		
 
- 		$data ['receiptMemu'] = 'implement';
 
- 		// if (! ($receiptDetail ['status'] == 1 || $receiptDetail ['status'] == 6)) {
 
- 		// die ();
 
- 		// }
 
- 		$data ['showType'] = $showType;
 
- 		
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		// 获取审批日志
 
- 		Doo::loadModel ( 'receiptLog' );
 
- 		$receiptLog = new receiptLog ();
 
- 		
 
- 		// echo $rid;
 
- 		$rlList = $receiptLog->find ( array (
 
- 				'where' => 'rid=' . $rid,
 
- 				'asc' => 'rlid',
 
- 				'asArray' => true 
 
- 		) );
 
- 		
 
- 		$data ['rlList'] = $rlList;
 
- 		
 
- 		// 审批组
 
- 		Doo::loadModel ( 'verify' );
 
- 		$verify = new verify ();
 
- 		$verifyList = $verify->getOne ( array (
 
- 				'where' => 'vid=' . $receiptDetail ['verify'],
 
- 				'asArray' => true 
 
- 		) );
 
- 		$verifyList = json_decode ( $verifyList ['staff'], true );
 
- 		$verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
 
- 		$verifyList = $this->fnGetReceiptApprovalProcess ( $verifyList, $verifyStaff );
 
- 		$data ['verifyList'] = $verifyList ['verifyList'];
 
- 		// print_r($verifyList['verifyList']);
 
- 		
 
- 		// 执行组
 
- 		$executeList = json_decode ( $receiptDetail ['executeCopy'], true );
 
- 		$executeStaff = array ();
 
- 		if (! empty ( $receiptDetail ['executeStaff'] )) {
 
- 			$executeStaff = json_decode ( $receiptDetail ['executeStaff'], true );
 
- 		}
 
- 		
 
- 		$button2 = 0;
 
- 		if (isset ( $executeList )) {
 
- 			foreach ( $executeList as $op => $lo ) {
 
- 				
 
- 				$executeList [$op] ['date'] = "";
 
- 				$executeList [$op] ['opinion'] = "";
 
- 				$executeList [$op] ['status'] = "";
 
- 				
 
- 				foreach ( $executeStaff as $m => $u ) {
 
- 					if ($lo [0] == $m) {
 
- 						$executeList [$op] ['date'] = $u ['date'];
 
- 						$executeList [$op] ['opinion'] = $u ['opinion'];
 
- 						$executeList [$op] ['status'] = $u ['status'];
 
- 						break;
 
- 					}
 
- 				}
 
- 				
 
- 				if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
 
- 					$button2 = 1;
 
- 					$executeList [$op] ['status'] = 4;
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		//执行人是否是最后一位
 
- 		$executeCopy = json_decode ( $receiptDetail ['executeCopy'], true );
 
- 		$executeStaff = json_decode ( $receiptDetail ['executeStaff'], true );
 
- 		$executePrimary=count($executeCopy)-1;
 
- 		$lastOne=true;
 
- 		if($executePrimary!=count($executeStaff)){
 
- 			$lastOne=false;
 
- 		}
 
- 		$data['lastOne']=$lastOne;
 
- 		// 是否写入过流水
 
- 		$accountType = 0;
 
- 		if ($receiptDetail ['Rtype'] == 3) {
 
- 			$accountType = 12;
 
- 		}
 
- 		Doo::loadModel ( 'wasteBook' );
 
- 		$wasteBook = new wasteBook ();
 
- 		$wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptDetail ['rid'] );
 
- 		$data ['wbDetail'] = $wbDetail;
 
- 		
 
- 		
 
- 		$data ['button2'] = $button2;
 
- 		$data ['executeList'] = $executeList;
 
- 		
 
- 		$data ['receiptTrainingDetail'] = $receiptTrainingDetail;
 
- 		$data ['receiptDetail'] = $receiptDetail;
 
- 		$data ['trainEdiType'] = "implement";
 
- 		$data ['ridKey'] = $ridKey;
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptTrainImplement", $data );
 
- 	}
 
- 	function receiptTrainApprovalDo() {
 
- 		$opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
 
- 		$statusKey = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : '';
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
 
- 		
 
- 		if (! empty ( $ridKey ) && ! empty ( $statusKey )) {
 
- 			
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			$rid = $XDeode->decode ( $ridKey );
 
- 			
 
- 			if ($statusKey == 'AGREE') {
 
- 				$status = 1;
 
- 			} elseif ($statusKey == 'END') {
 
- 				$status = 3;
 
- 			} else {
 
- 				die ( 'illegal request--status' );
 
- 			}
 
- 			
 
- 			Doo::loadModel ( "verify" );
 
- 			$verify = new verify ();
 
- 			Doo::loadModel ( "receiptDetail" );
 
- 			$receiptDetailObj = new receiptDetail ();
 
- 			Doo::loadModel ( "itemStatistics" );
 
- 			Doo::loadModel ( "statistics" );
 
- 			$statistics = new statistics ();
 
- 			$itemStatistics = new itemStatistics ();
 
- 			
 
- 			Doo::loadModel ( "receipt" );
 
- 			$receipt = new receipt ();
 
- 			
 
- 			$receiptDetail = $receipt->getOne ( array (
 
- 					'where' => 'rid=' . $rid . ' and status=2 ',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			//计算汇款金额
 
- 			// 收入合计
 
- 			Doo::loadModel ( 'invoiceTraining' );
 
- 			$invoiceTraining = new invoiceTraining ();
 
- 			$invoiceTrainingDetail = array (
 
- 					'invoiceArriveAmount' => '0.00',
 
- 					'RIAmount' => '0.00',
 
- 					'invoiceTotalAmount' => '0.00',
 
- 					'invoiceCompanyAmount' => '0.00',
 
- 					'invoiceArriveAmountM'=>'0.00',
 
- 					'invoiceCompanyAmountM'=>'0.00'
 
- 			);
 
- 			if ($receiptDetail ['invoiceTrainId'] != 0) {
 
- 				$invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail['invoiceTrainId'] );
 
- 			}
 
- 			$invoiceArriveAmount = $RIAmount = 0;
 
- 			if (! empty ( $invoiceTrainingDetail )) {
 
- 				$invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
 
- 				$RIAmount = $invoiceTrainingDetail ['RIAmount'];
 
- 			}
 
- 			
 
- 			// 备用金
 
- 			$sum = 0;
 
- 			if (! empty ( $receiptDetail ['trainLoanRid'] )) {
 
- 				
 
- 				$receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
 
- 				foreach ($receiptLoanList as $key=>$value){
 
- 					$sum+=$value['sum'];
 
- 				}
 
- 				
 
- 				
 
- // 				$receiptLoanDetailBak = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
 
- // 				$sum = $receiptLoanDetailBak ['sum'];
 
- 			}
 
- 			
 
- 			// 支出项金额详情
 
- 			// 项目金额合计
 
- 			Doo::loadModel ( 'RItem' );
 
- 			$RItem = new RItem ();
 
- 			Doo::loadModel ( 'accountItem' );
 
- 			$accountItem = new accountItem ();
 
- 			// 讲师获得
 
- 			Doo::loadModel ( 'RILecturer' );
 
- 			$RILecturer = new RILecturer ();
 
- 			$RItemList = $RItem->getRItemByRid ( $rid );
 
- 			$RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
 
- 			// 支出项金额详情
 
- 			$aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
 
- 			$categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
 
- 			
 
- 			$payment = $sum + $RIAmount - $categoryActualExpenditure;
 
- 			
 
- 			
 
- 			
 
- 			
 
- 			
 
- 			$nslist = explode ( ',', $receiptDetail ['nowStaff'] );
 
- 			$nsflag = true;
 
- 			foreach ( $nslist as $value ) {
 
- 				if ($value == $this->staff ['0'] ['sid']) {
 
- 					$nsflag = false;
 
- 					break;
 
- 				}
 
- 			}
 
- 			// 该用户是否能审批
 
- 			if (empty ( $receiptDetail ) || $nsflag)
 
- 				return "/approvalExpenses/pendApproval";
 
- 			
 
- 			$verifyDetail = $verify->getOne ( array (
 
- 					'where' => ' vid =' . $receiptDetail ['verify'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			$verifyString = $verifyDetail ['staff'];
 
- 			$verifyDetail = json_decode ( $verifyDetail ['staff'], true );
 
- 			$verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
 
- 			
 
- 			if (empty ( $opinion )) {
 
- 				if ($status == 3)
 
- 					$opinion = "终止";
 
- 				else
 
- 					$opinion = "同意支付";
 
- 			}
 
- 			
 
- 			$nowStaff = 0;
 
- 			$nowStaffList = array ();
 
- 			
 
- 			if (empty ( $verifyStaff )) {
 
- 				
 
- 				// 还需加入是否已经进入角色审批
 
- 				if ($verifyDetail [0] [1] == 'ROLE') {
 
- 					
 
- 					$vStaffString = json_decode ( $verifyDetail [0] [3] );
 
- 					
 
- 					foreach ( $vStaffString as $key => $value ) {
 
- 						$staffK = explode ( "_", $value );
 
- 						if ($staffK [0] != $this->staff [0] ['sid'])
 
- 							array_push ( $nowStaffList, $staffK [0] );
 
- 					}
 
- 					
 
- 					// print_r($verifyDetail);
 
- 					// die;
 
- 					if (! empty ( $nowStaffList )) {
 
- 						$nowStaff = implode ( ',', $nowStaffList );
 
- 						$verifyStaff = array (
 
- 								$this->staff [0] ['sid'] . "_R" => array (
 
- 										'date' => date ( 'Y-m-d' ),
 
- 										'opinion' => $opinion,
 
- 										'status' => $status,
 
- 										'nextStaff' => $verifyDetail [0] [0],
 
- 										'ROLE' => 1 
 
- 								) 
 
- 						);
 
- 					} else {
 
- 						$nowStaff = $verifyDetail [1] [0];
 
- 						$verifyStaff = array (
 
- 								$this->staff [0] ['sid'] . "_R" => array (
 
- 										'date' => date ( 'Y-m-d' ),
 
- 										'opinion' => $opinion,
 
- 										'status' => $status,
 
- 										'nextStaff' => $verifyDetail [1] [0] 
 
- 								) 
 
- 						);
 
- 					}
 
- 				} else {
 
- 					
 
- 					if ($verifyDetail [1] [1] == 'ROLE') {
 
- 						$vStaffString = json_decode ( $verifyDetail [1] [3] );
 
- 						// echo "dd";
 
- 						foreach ( $vStaffString as $key => $value ) {
 
- 							$staffK = explode ( "_", $value );
 
- 							array_push ( $nowStaffList, $staffK [0] );
 
- 						}
 
- 						$nowStaff = implode ( ',', $nowStaffList );
 
- 						$verifyStaff = array (
 
- 								$this->staff [0] ['sid'] => array (
 
- 										'date' => date ( 'Y-m-d' ),
 
- 										'opinion' => $opinion,
 
- 										'status' => $status,
 
- 										'nextStaff' => $verifyDetail [1] [0],
 
- 										'ROLE' => 1 
 
- 								) 
 
- 						);
 
- 					} else {
 
- 						$nowStaff = $verifyDetail [1] [0];
 
- 						$verifyStaff = array (
 
- 								$this->staff [0] ['sid'] => array (
 
- 										'date' => date ( 'Y-m-d' ),
 
- 										'opinion' => $opinion,
 
- 										'status' => $status,
 
- 										'nextStaff' => $verifyDetail [1] [0] 
 
- 								) 
 
- 						);
 
- 					}
 
- 				}
 
- 				
 
- 				if ($status == 3)
 
- 					$verifyStaff = array (
 
- 							'final' => $status,
 
- 							$this->staff [0] ['sid'] => array (
 
- 									'date' => date ( 'Y-m-d' ),
 
- 									'opinion' => $opinion,
 
- 									'status' => $status 
 
- 							) 
 
- 					);
 
- 				
 
- 				$vStaffString = json_encode ( $verifyStaff );
 
- 				$receipt->nowStaff = $nowStaff;
 
- 				$receipt->verifyStaff = $vStaffString;
 
- 			} else {
 
- 				$VS = end ( $verifyStaff );
 
- 				
 
- 				// 非角色审批
 
- 				if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
 
- 					$nextStaff = 0;
 
- 					$roleSTF = false;
 
- 					foreach ( $verifyDetail as $key => $value ) {
 
- 						if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
 
- 							if (isset ( $verifyDetail [$key + 1] )) {
 
- 								$nextStaff = $verifyDetail [$key + 1] [0];
 
- 								if ($verifyDetail [$key + 1] [1] == 'ROLE')
 
- 									$roleSTF = true;
 
- 							}
 
- 							break;
 
- 						}
 
- 					}
 
- 					
 
- 					if (! $roleSTF) {
 
- 						$nowStaff = $nextStaff;
 
- 						$verifyStaff [$this->staff [0] ['sid']] = array (
 
- 								'date' => date ( 'Y-m-d' ),
 
- 								'opinion' => $opinion,
 
- 								'status' => $status,
 
- 								'nextStaff' => $nextStaff 
 
- 						);
 
- 					} else {
 
- 						// 获取角色下的所有用户ID
 
- 						$nowStaffList = array ();
 
- 						foreach ( $verifyDetail as $vfk ) {
 
- 							if ($vfk [1] == 'ROLE') {
 
- 								$vStaffString = json_decode ( $vfk [3] );
 
- 								foreach ( $vStaffString as $key => $value ) {
 
- 									$staffK = explode ( "_", $value );
 
- 									array_push ( $nowStaffList, $staffK [0] );
 
- 								}
 
- 							}
 
- 						}
 
- 						
 
- 						$nowStaff = implode ( ',', $nowStaffList );
 
- 						$verifyStaff [$this->staff [0] ['sid']] = array (
 
- 								'date' => date ( 'Y-m-d' ),
 
- 								'opinion' => $opinion,
 
- 								'status' => $status,
 
- 								'nextStaff' => $nextStaff,
 
- 								'ROLE' => 0 
 
- 						);
 
- 					}
 
- 					
 
- 					if ($status == 3) {
 
- 						$verifyStaff ['final'] = $status;
 
- 						$verifyStaff [$this->staff [0] ['sid']] = array (
 
- 								'date' => date ( 'Y-m-d' ),
 
- 								'opinion' => $opinion,
 
- 								'status' => $status 
 
- 						);
 
- 					}
 
- 					$vStaffString = json_encode ( $verifyStaff );
 
- 					$receipt->nowStaff = $nowStaff;
 
- 					$receipt->verifyStaff = $vStaffString;
 
- 				}
 
- 				
 
- 				// 角色审批
 
- 				if (isset ( $VS ['ROLE'] )) {
 
- 					
 
- 					// 找出角色人 当前审批角色组
 
- 					$verifyJSStaff = array ();
 
- 					$nowStaffList2 = array ();
 
- 					foreach ( $verifyDetail as $key => $value ) {
 
- 						if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
 
- 							$verifyJSStaff = json_decode ( $value [3] );
 
- 							foreach ( $verifyJSStaff as $m ) {
 
- 								$staffK = explode ( "_", $m );
 
- 								array_push ( $nowStaffList2, $staffK [0] );
 
- 							}
 
- 							// print_r($nowStaffList2);
 
- 						}
 
- 					}
 
- 					
 
- 					$RoleVerifyStaff = array ();
 
- 					foreach ( $verifyStaff as $key => $value ) {
 
- 						if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
 
- 							foreach ( $nowStaffList2 as $m ) {
 
- 								if ($key == $m . "_R")
 
- 									$RoleVerifyStaff [$key] = $value;
 
- 							}
 
- 						}
 
- 					}
 
- 					
 
- 					$jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
 
- 					if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
 
- 					                                              // 下一个审批人ID
 
- 						$nextStaff = 0;
 
- 						$falg = false;
 
- 						foreach ( $verifyDetail as $key => $value ) {
 
- 							if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
 
- 								
 
- 								if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
 
- 									$falg = true;
 
- 									$vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
 
- 									$nowStaffList = array ();
 
- 									foreach ( $vStaffString as $v ) {
 
- 										$staffK = explode ( "_", $v );
 
- 										array_push ( $nowStaffList, $staffK [0] );
 
- 									}
 
- 									$nowStaff = implode ( ',', $nowStaffList );
 
- 									
 
- 									$nextStaff = $verifyDetail [$key + 1] [0];
 
- 								} elseif (isset ( $verifyDetail [$key + 1] )) {
 
- 									$nextStaff = $verifyDetail [$key + 1] [0];
 
- 									$nowStaff = $nextStaff;
 
- 								} else
 
- 									$nowStaff = '';
 
- 								break;
 
- 							}
 
- 						}
 
- 						
 
- 						if ($falg)
 
- 							$verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
 
- 									'date' => date ( 'Y-m-d' ),
 
- 									'opinion' => $opinion,
 
- 									'status' => $status,
 
- 									'nextStaff' => $nextStaff,
 
- 									'ROLE' => 1 
 
- 							);
 
- 						else
 
- 							$verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
 
- 									'date' => date ( 'Y-m-d' ),
 
- 									'opinion' => $opinion,
 
- 									'status' => $status,
 
- 									'nextStaff' => $nextStaff 
 
- 							);
 
- 						
 
- 						// print_r($verifyStaff);
 
- 						// echo $nowStaff;die;
 
- 					} else { // 进入下一个角色或者审批人
 
- 					         
 
- 						// echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
 
- 					         //
 
- 						$nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
 
- 						
 
- 						$verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
 
- 								'date' => date ( 'Y-m-d' ),
 
- 								'opinion' => $opinion,
 
- 								'status' => $status,
 
- 								'nextStaff' => $VS ['nextStaff'],
 
- 								'ROLE' => 1 
 
- 						);
 
- 						// print_r($verifyStaff);
 
- 						// die;
 
- 					}
 
- 					if ($status == 3) {
 
- 						$verifyStaff ['final'] = $status;
 
- 						$verifyStaff [$this->staff [0] ['sid']] = array (
 
- 								'date' => date ( 'Y-m-d' ),
 
- 								'opinion' => $opinion,
 
- 								'status' => $status 
 
- 						);
 
- 					}
 
- 					$vStaffString = json_encode ( $verifyStaff );
 
- 					$receipt->verifyStaff = $vStaffString;
 
- 					$receipt->nowStaff = $nowStaff;
 
- 				}
 
- 				// print_r($verifyStaff);die;
 
- 			}
 
- 			// print_r($verifyDetail);
 
- 			$roleKey = 0;
 
- 			$roleId = 0;
 
- 			$verifyDetailCopy = array ();
 
- 			foreach ( $verifyDetail as $k => $v ) {
 
- 				if ($v [1] == 'ROLE') {
 
- 					$roleId = $v [0];
 
- 					$roleVerify = json_decode ( $v [3], true );
 
- 					$roleKey = $k;
 
- 					$roleArray = array ();
 
- 					foreach ( $roleVerify as $o => $p ) {
 
- 						$staffID = explode ( '_', $p );
 
- 						$exp = array (
 
- 								0 => $staffID [0],
 
- 								1 => $staffID [1] 
 
- 						);
 
- 						array_push ( $roleArray, $exp );
 
- 					}
 
- 					$verifyDetailCopy [$v [0]] = $roleArray;
 
- 				}
 
- 			}
 
- 			// print_r($verifyDetail);
 
- 			foreach ( $verifyDetailCopy as $k => $v ) {
 
- 				foreach ( $verifyDetail as $m => $n ) {
 
- 					if ($n [0] == $k) {
 
- 						array_splice ( $verifyDetail, $m, 1, $v );
 
- 					}
 
- 				}
 
- 			}
 
- 			
 
- 			Doo::loadModel ( "receiptLog" );
 
- 			$receiptLog = new receiptLog ();
 
- 			// 审批日志
 
- 			if (! isset ( $verifyStaff ['final'] )) {
 
- 				
 
- 				if (! empty ( $roleId )) {
 
- 					Doo::loadModel ( "role" );
 
- 					$role = new role ();
 
- 					$roleInfo = $role->getOne ( array (
 
- 							'where' => 'rid=' . $roleId,
 
- 							'asArray' => true 
 
- 					) );
 
- 					
 
- 					$receiptLog->rolename = $roleInfo ['name'];
 
- 				}
 
- 				
 
- 				$receiptLog->username = $this->staff [0] ['username'];
 
- 				$receiptLog->uid = $this->staff [0] ['sid'];
 
- 				$receiptLog->date = date ( "Y-m-d" );
 
- 				$receiptLog->opinion = $opinion;
 
- 				$receiptLog->img = $this->staff [0] ['avatar'];
 
- 				$receiptLog->status = 1;
 
- 				$receiptLog->rid = $rid;
 
- 				$receiptLog->insert ();
 
- 			}
 
- 			
 
- 			if (isset ( $verifyStaff ['final'] )) { // rDetail
 
- 				$receipt->verifyBreakup = $verifyString;
 
- 				$receipt->status = 3;
 
- 				$receiptDetailObj->status = 3;
 
- 				$receiptDetailObj->update ( array (
 
- 						'where' => 'rid=' . $rid 
 
- 				) );
 
- 				
 
- 				if (! empty ( $roleId )) {
 
- 					Doo::loadModel ( "role" );
 
- 					$role = new role ();
 
- 					$roleInfo = $role->getOne ( array (
 
- 							'where' => 'rid=' . $roleId,
 
- 							'asArray' => true 
 
- 					) );
 
- 					
 
- 					$receiptLog->rolename = $roleInfo ['name'];
 
- 				}
 
- 				
 
- 				$receiptLog->username = $this->staff [0] ['username'];
 
- 				$receiptLog->uid = $this->staff [0] ['sid'];
 
- 				$receiptLog->date = date ( "Y-m-d" );
 
- 				$receiptLog->opinion = $opinion;
 
- 				$receiptLog->img = $this->staff [0] ['avatar'];
 
- 				$receiptLog->status = 3;
 
- 				$receiptLog->rid = $rid;
 
- 				$receiptLog->insert ();
 
- 				
 
- 				// 微信企业号通知
 
- 				// $this->setWXMsg ( $rid, 3 );
 
- 			} elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
 
- 				$receipt->status = 1;
 
- 				$reviseSum = 0;
 
- 				$receipt->verifyBreakup = $verifyString;
 
- 				
 
- 				$receiptDetailObj = new receiptDetail ();
 
- 				$receiptDetailObj->status = 1;
 
- 				$receiptDetailObj->pastDate = date ( "Y-m-d" );
 
- 				$receiptDetailObj->update ( array (
 
- 						'where' => 'rid=' . $rid 
 
- 				) );
 
- 				
 
- 				$dateArray = explode ( "-", $receiptDetail ['date'] );
 
- 				$dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
 
- 				$stat = $statistics->getOne ( array (
 
- 						'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
 
- 						'asArray' => true 
 
- 				) );
 
- 				if (empty ( $stat )) {
 
- 					$statistics->date = $receiptDetail ['date'];
 
- 					$statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
 
- 					$statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
 
- 					$statistics->agPrice = $receiptDetail ['sum'];
 
- 					$statistics->rePrice = $reviseSum;
 
- 					$statistics->insert ();
 
- 				} else {
 
- 					$statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
 
- 					$statistics->rePrice = $stat ['rePrice'] + $reviseSum;
 
- 					$statistics->update ( array (
 
- 							'where' => 'sid=' . $stat ['sid'] 
 
- 					) );
 
- 				}
 
- 				
 
- 				$dateArray = explode ( "-", $receiptDetail ['date'] );
 
- 				$dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
 
- 				$accountItem = json_decode ( $receiptDetail ['accountItem'], true );
 
- 				foreach ( $accountItem ['cSum'] as $key => $value ) {
 
- 					if ($key == "trainSum") {
 
- 						$iStatistics = $itemStatistics->getOne ( array (
 
- 								'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
 
- 								'asArray' => true 
 
- 						) );
 
- 						if (empty ( $iStatistics )) {
 
- 							$itemStatistics->cid = $receiptDetail ['cid'];
 
- 							$itemStatistics->staff = $receiptDetail ['staff'];
 
- 							$itemStatistics->price = $receiptDetail ['sum'];
 
- 							$itemStatistics->itemCategory = $this->TRAIN;
 
- 							$itemStatistics->date = $receiptDetail ['date'];
 
- 							$itemStatistics->insert ();
 
- 						} else {
 
- 							if (! empty ( $value )) {
 
- 								$itemStatistics->price = $receiptDetail ['sum'] + $iStatistics ['price'];
 
- 								$itemStatistics->update ( array (
 
- 										'where' => 'sid=' . $iStatistics ['sid'] 
 
- 								) );
 
- 							}
 
- 						}
 
- 					}
 
- 				}
 
- 				$receipt->pastDate = date ( "Y-m-d" );
 
- 				
 
- 				// 微信企业号通知
 
- 				// $this->setWXMsg ( $rid, 1 );
 
- 			}
 
- 			
 
- 			//汇款金额
 
- 			$receipt->amount=$payment;
 
- 			
 
- 			$receipt->update ( array (
 
- 					'where' => ' rid = ' . $rid 
 
- 			) );
 
- 		}
 
- 		return "/approvalExpenses/pendApproval";
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算--撤回
 
- 	 */
 
- 	function receiptTrainApprovalBackDo() {
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
 
- 		$opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
 
- 		
 
- 		if (! empty ( $ridKey )) {
 
- 			
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			$rid = $XDeode->decode ( $ridKey );
 
- 			
 
- 			// 操作记录
 
- 			Doo::loadModel ( "receipt" );
 
- 			$receipt = new receipt ();
 
- 			Doo::loadModel ( "receiptLog" );
 
- 			$receiptLog = new receiptLog ();
 
- 			Doo::loadModel ( "verify" );
 
- 			$verify = new verify ();
 
- 			
 
- 			$receiptInfo = $receipt->getOne ( array (
 
- 					'where' => 'rid=' . $rid . ' and status=2',
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			if (empty ( $receiptInfo )) {
 
- 				echo json_encode ( array (
 
- 						'status' => 2 
 
- 				) );
 
- 				die ();
 
- 			}
 
- 			
 
- 			$vr = $verify->getOne ( array (
 
- 					'where' => 'vid=' . $receiptInfo ['verify'],
 
- 					'asArray' => true 
 
- 			) );
 
- 			
 
- 			$jd = json_decode ( $vr ['staff'] );
 
- 			$roleId = 0;
 
- 			
 
- 			foreach ( $jd as $key => $value ) {
 
- 				if ($value [1] == 'ROLE') {
 
- 					$pos = strpos ( $value [3], $this->staff [0] ['sid'] );
 
- 					if ($pos !== false) {
 
- 						$roleId = $value [0];
 
- 					}
 
- 				}
 
- 			}
 
- 			// 审批日志
 
- 			// echo $roleId;die;
 
- 			if (! empty ( $roleId )) {
 
- 				Doo::loadModel ( "role" );
 
- 				$role = new role ();
 
- 				$roleInfo = $role->getOne ( array (
 
- 						'where' => 'rid=' . $roleId,
 
- 						'asArray' => true 
 
- 				) );
 
- 				
 
- 				$receiptLog->rolename = $roleInfo ['name'];
 
- 			}
 
- 			
 
- 			$receiptLog->username = $this->staff [0] ['username'];
 
- 			$receiptLog->uid = $this->staff [0] ['sid'];
 
- 			$receiptLog->date = date ( "Y-m-d" );
 
- 			$receiptLog->opinion = $opinion;
 
- 			$receiptLog->img = $this->staff [0] ['avatar'];
 
- 			$receiptLog->status = 4;
 
- 			$receiptLog->rid = $rid;
 
- 			$receiptLog->insert ();
 
- 			
 
- 			$receipt->status = 4;
 
- 			$receipt->update ( array (
 
- 					'where' => 'rid=' . $rid 
 
- 			) );
 
- 			
 
- 			// 微信企业号通知
 
- 			$this->setWXMsg ( $rid, 2 );
 
- 			
 
- 			echo json_encode ( array (
 
- 					'status' => 1 
 
- 			) );
 
- 			die ();
 
- 		}
 
- 		echo json_encode ( array (
 
- 				'status' => 2 
 
- 		) );
 
- 		die ();
 
- 	}
 
- 	
 
- 	function receiptTrainItemEdiDo(){
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
 
- 		$riidKey = $this->get_args ( 'riidKey' ) ? $this->get_args ( 'riidKey' ) : "";
 
- 		
 
- 		// 支出项信息
 
- 		$item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
 
- 		$price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
 
- 		$date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
 
- 		$inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
 
- 		$describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
 
- 		
 
- 		$payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		$riid = $XDeode->decode ( $riidKey );
 
- 		if (! is_numeric ( $rid ) || ! is_numeric ( $riid )) {
 
- 			die ( 'illegal request--id' );
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'RItem' );
 
- 		$RItem = new RItem ();
 
- 		Doo::loadModel ( 'receiptDetail' );
 
- 		
 
- 		
 
- 		$rDetail = $receipt->getReceiptByRid ( $rid );
 
- 		if (! ($rDetail ['status'] == 5 || $rDetail ['status'] == 4 || $rDetail ['status'] == 2)) {
 
- 			die ( 'illegal request-status' );
 
- 		}
 
- 		
 
- 		$detail = $RItem->getRItemByRiid ( $riid );
 
- 		if (empty ( $detail )) {
 
- 			die ( 'illegal request-dataError' );
 
- 		}
 
- 		//创建人可以删除协助人
 
-         if(!($rDetail['staff']==$this->staff [0] ['sid'])){
 
- 		if (! ($this->staff [0] ['sid'] == $detail ['createrId'] || $this->staff [0] ['username'] == $detail ['creater'])) {
 
- 			die ( 'illegal request-sidError' );
 
- 		}
 
-         }
 
- 		if ( ! empty ( $item ) &&  is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
 
- 			
 
- 			//--------------------移除支出信息
 
- 			
 
- 			$this->_receiptTrainItemDel($RItem, $rDetail, $riid, $rid, $detail, $receipt);
 
- 			
 
- 			//---------------------添加支出信息
 
- 			
 
- 			$receiptDetail = new receiptDetail ();
 
- 			$receipt = new receipt ();
 
- 			$RItem = new RItem ();
 
- 			
 
- 			$order = array (
 
- 					"\r\n",
 
- 					"\n",
 
- 					"\r"
 
- 			);
 
- 			$replace = '<br/>';
 
- 			$describe = str_replace ( $order, $replace, $describe );
 
- 			$itemData = array (
 
- 					'rid' => $rid,
 
- 					'item' => $item,
 
- 					'price' => $price,
 
- 			
 
- 					'date' => $date,
 
- 					'inputer' => $inputer,
 
- 			        'identifying'=>$detail['identifying'],
 
- 					'describe' => $describe,
 
- 					'creater' => $this->staff['0']['username'],
 
- 					'createrId' => $this->staff['0']['sid'],
 
- 					'creatDate' => date ( "Y-m-d H:i:s" )
 
- 			);
 
- 			if($payType=='company'){
 
- 				$itemData += array (
 
- 						'payType' => 1
 
- 				);
 
- 			}
 
- 			$RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
 
- 			$XDeode = new XDeode ( 7 );
 
- 			if($payType=='company'){
 
- 				return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
 
- 			}else{
 
- 				return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
 
- 			}
 
- 		}else
 
- 			die ( 'illegal request-dataError' );
 
- 		
 
- 	}
 
- 	
 
- 	//移除培训班结算-支出列
 
- 	private function _receiptTrainItemDel($RItem,$rDetail,$riid,$rid,$detail,$receipt){
 
- 		$RItem->delete ( array (
 
- 				'where' => 'riid=' . $riid
 
- 		) );
 
- 		
 
- 		// 更新费用合计金额
 
- 		$rInfo = $receipt->getReceiptByRid ( $rid );
 
- 		$receipt = new receipt ();
 
- 		$receipt->sum = $rDetail ['sum'] - $detail ['price'];
 
- 		$receipt->update ( array (
 
- 				'where' => 'rid=' . $rid
 
- 		) );
 
- 		Doo::loadModel ( 'receiptDetail' );
 
- 		$receiptDetail = new receiptDetail ();
 
- 		$rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, $detail ['item'], '培训班费用' );
 
- 		$receiptDetail = new receiptDetail ();
 
- 		$rdInfo ['price'] -= $detail ['price'];
 
- 		$receiptDetail->price = $rdInfo ['price'];
 
- 		$receiptDetail->update ( array (
 
- 				'where' => 'rid=' . $rid . ' and item like "' . $detail ['item'] . '" and itemCategory like "培训班费用"'
 
- 		) );
 
- 		
 
- 		//汇总金额--提交审批之后有 支出项时 需要更新汇总
 
- 		if($detail['payType']==1){
 
- 			Doo::loadModel ( "statistics" );
 
- 			$statistics = new statistics ();
 
- 		
 
- 			$dateArray = explode ( "-", $rInfo ['date'] );
 
- 			$dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
 
- 		
 
- 			$stat = $statistics->getOne ( array (
 
- 					'where' => 'staff=' . $rInfo ['staff'] . $dateCondition,
 
- 					'asArray' => true
 
- 			) );
 
- 			if (!empty($stat)){
 
- 				$statistics->rePrice = $stat ['rePrice'] - $detail['price'];
 
- 					
 
- 				$statistics->update ( array (
 
- 						'where' => 'sid=' . $stat ['sid']
 
- 				) );
 
- 			}
 
- 		}
 
- 		
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 移除培训班结算-支出列
 
- 	 */
 
- 	function receiptTrainItemDelDo() {
 
- 		$riidKey = isset ( $this->params ['riidKey'] ) ? $this->params ['riidKey'] : '';
 
- 		$ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		$riid = $XDeode->decode ( $riidKey );
 
- 		if (! is_numeric ( $rid ) || ! is_numeric ( $riid )) {
 
- 			die ( 'illegal request--id' );
 
- 		}
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'RItem' );
 
- 		$RItem = new RItem ();
 
- 		
 
- 		$rDetail = $receipt->getReceiptByRid ( $rid );
 
- 		if (! ($rDetail ['status'] == 5 || $rDetail ['status'] == 4 || $rDetail ['status'] == 2)) {
 
- 			die ( 'illegal request-status' );
 
- 		}
 
- 		
 
- 		$detail = $RItem->getRItemByRiid ( $riid );
 
- 		if (empty ( $detail )) {
 
- 			die ( 'illegal request-dataError' );
 
- 		}
 
- 		
 
- 		if (! ($this->staff [0] ['sid'] == $detail ['createrId'] || $this->staff [0] ['username'] == $detail ['creater'])) {
 
- 			die ( 'illegal request-sidError' );
 
- 		}
 
- 		
 
- 		$this->_receiptTrainItemDel($RItem, $rDetail, $riid, $rid, $detail, $receipt);
 
- 		
 
- 		
 
- 		$XDeode = new XDeode ( 7 );
 
- 		if ($rDetail ['status'] == 2) {
 
- 			return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
 
- 		} else {
 
- 			return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 生成对冲收款
 
- 	 */
 
- 	function invoiceReceivablesStrikeAddDo() {
 
- 		$iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
 
- 		
 
- 		if (empty ( $iidKey ) || empty ( $ridKey )) {
 
- 			die ( 'illegal request--idKey' );
 
- 		}
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$XDeode7 = new XDeode ( 7 );
 
- 		$iid = $XDeode->decode ( $iidKey );
 
- 		$rid = $XDeode7->decode ( $ridKey );
 
- 		
 
- 		Doo::loadModel ( 'invoiceReceivables' );
 
- 		$invoiceReceivables = new invoiceReceivables ();
 
- 		Doo::loadModel ( 'invoice' );
 
- 		$invoice = new invoice ();
 
- 		Doo::loadModel ( 'invoiceTraining' );
 
- 		$invoiceTraining = new invoiceTraining ();
 
- 		Doo::loadModel ( 'invoiceOperationLog' );
 
- 		$invoiceOperationLog = new invoiceOperationLog ();
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		
 
- 		$detail = $invoice->getInvoiceByIid ( $iid );
 
- 		$invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $detail ['trainId'] );
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		$receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
 
- 		
 
- 		if (empty ( $invoiceTrainingDetail ) || empty ( $detail ) || $detail ['untreadStatus'] == 3 || ! empty ( $detail ['irid'] )) {
 
- 			die ( 'illegal request--trainId-status-irid' );
 
- 		}
 
- 		// 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
 
- 		// 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
 
- 		// 添加收款
 
- 		$item = array (
 
- 				'iid' => $detail ['iid'],
 
- 				'bindStatus' => 1,
 
- 				'bindPrice' => $detail ['invoicePrice'],
 
- 				'inputStaff' => $this->staff [0] ['username'],
 
- 				'source' => 2,
 
- 				'bindDate' => date ( "Y-m-d" ),
 
- 				'confirmTime' => date ( "Y-m-d H:i:s" ),
 
- 				
 
- 				'receivablesPrice' => $detail ['invoicePrice'],
 
- 				'OriginalPrice' => $detail ['invoicePrice'],
 
- 				'receivablesMessage' => $receiptTrainingDetail ['trainName'] . '冲账',
 
- 				'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
 
- 				'receivablesBank' => '财务录入',
 
- 				'receivablesDate' => date ( "Y-m-d" ),
 
- 				'inputStaff' => $this->staff [0] ['username'],
 
- 				'date' => date ( "Y-m-d" ),
 
- 				'receivablesCategory' => $detail ['cid'] . ":" . $detail ['categoryName'],
 
- 				'receivablesStaff' => $detail ['sid'] . "-" . $detail ['userName'] 
 
- 		);
 
- 		$irid = $invoiceReceivables->addInvoiceReceivables ( $item );
 
- 		// 更新发票绑定收款
 
- 		$iridString = "";
 
- 		if (empty ( $detail ['irid'] ))
 
- 			$iridString = $irid;
 
- 		else
 
- 			$iridString = $detail ['irid'] . ',' . $irid;
 
- 		$item = array (
 
- 				'iid' => $detail ['iid'],
 
- 				'irid' => $iridString,
 
- 				'untreadStatus' => 3,
 
- 				'bindTime' => date ( "Y-m-d H:i:s" ) 
 
- 		);
 
- 		$invoice->setInvoiceByCondition ( $item );
 
- 		
 
- 		// 在是对冲收款 确保已收款不被删除
 
- 		// Doo::loadModel ( 'RIExtend' );
 
- 		// $RIExtend = new RIExtend ();
 
- 		
 
- 		// 操作日志
 
- 		$item = array (
 
- 				'date' => date ( "Y-m-d H:i:s" ),
 
- 				'operation' => "收款" . $invoiceTrainingDetail ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
 
- 				'status' => 8,
 
- 				'img' => $this->staff [0] ['avatar'],
 
- 				'username' => $this->staff [0] ['username'],
 
- 				'uid' => $this->staff [0] ['sid'],
 
- 				'category' => $this->staff [0] ['category'],
 
- 				'iid' => $detail ['iid'] 
 
- 		);
 
- 		$invoiceOperationLog->setInvoiceOperationLog ( $item );
 
- 		// 是否加入统计--冲账不需要加入汇总
 
- 		
 
- 		return '/receiptTrainInvoice/approval/' . $ridKey . '.html';
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 培训班结算--执行
 
- 	 */
 
- 	function receiptTrainImplementDo() {
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
 
- 		$implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
 
- 		
 
- 		if (! empty ( $ridKey )) {
 
- 			Doo::loadModel ( 'receipt' );
 
- 			$receipt = new receipt ();
 
- 			Doo::loadModel ( 'wasteBook' );
 
- 			$wasteBook = new wasteBook ();
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			
 
- 			$rid = $XDeode->decode ( $ridKey );
 
- 			
 
- 			$rinfo = $receipt->getReceiptByRid ( $rid );
 
- 			if (empty ( $rinfo )) {
 
- 				die ( 'illegal request--rid' );
 
- 			}
 
- 			
 
- 			$accountType = '';
 
- 			if ($rinfo ['Rtype'] == 1) {
 
- 				if ($rinfo ['loanRid'] != 0)
 
- 					$accountType = 2;
 
- 				else
 
- 					$accountType = 1;
 
- 			} elseif ($rinfo ['Rtype'] == 2) {
 
- 				$accountType = 4;
 
- 			} elseif ($rinfo ['Rtype'] == 0) {
 
- 				$accountType = 3;
 
- 			} elseif ($rinfo ['Rtype'] == 3) {
 
- 				$accountType = 12;
 
- 			}
 
- 			
 
- 			if (empty ( $accountType ))
 
- 				die ( 'illegal request' );
 
- 			
 
- 			$executeCopy = json_decode ( $rinfo ['executeCopy'], true );
 
- 			$executeStaff = json_decode ( $rinfo ['executeStaff'], true );
 
- 			
 
- 			if (empty ( $executeStaff )) {
 
- 				
 
- 				$executeStaff = array (
 
- 						$this->staff [0] ['sid'] => array (
 
- 								'date' => date ( 'Y-m-d' ),
 
- 								'opinion' => $implementOpinions,
 
- 								'status' => 1 
 
- 						) 
 
- 				);
 
- 			} else {
 
- 				
 
- 				$executeStaff [$this->staff [0] ['sid']] = array (
 
- 						'date' => date ( 'Y-m-d' ),
 
- 						'opinion' => $implementOpinions,
 
- 						'status' => 1 
 
- 				);
 
- 			}
 
- 			
 
- 			if (count ( $executeStaff ) == count ( $executeCopy )) {
 
- 				// 费用执行没有
 
- 				$wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rinfo ['rid'] );
 
- 				if (empty ( $wbDetail )) {
 
- 					die ( 'illegal request--wate' );
 
- 				}
 
- 				
 
- 				$receipt->executeStaff = json_encode ( $executeStaff );
 
- 				
 
- 				$receipt->status = 8;
 
- 				if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
 
- 					$receipt->status = 9;
 
- 				
 
- 				if ($rinfo ['status'] == 6) {
 
- 					$receipt->loanDate = date ( "Y-m-d" );
 
- 				}
 
- 				
 
- 				$receipt->executeDate = date ( "Y-m-d" );
 
- 			} else {
 
- 				$receipt->executeStaff = json_encode ( $executeStaff );
 
- 			}
 
- 			
 
- 			$receipt->update ( array (
 
- 					'where' => 'rid=' . $rid 
 
- 			) );
 
- 			return '/hisImplement/train';
 
- 		}
 
- 		die ( 'illegal request-dataError' );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 生成执行流水
 
- 	 */
 
- 	function receiptTrainImplementWateDo() {
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
 
- 		$bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
 
- 		
 
- 		$amountTrain = $this->get_args ( 'amount' )  ? $this->get_args ( 'amount' ) : '';
 
- 		$expensesType = $this->get_args ( 'expensesType' ) ? $this->get_args ( 'expensesType' ) : "";
 
- 		
 
- 		$inputDate = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : date ( "Y-m-d H:i:s" );
 
- 		$remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : "";
 
- 		
 
- 		$actionType = $this->get_args ( 'actionType' ) ? $this->get_args ( 'actionType' ) : "";
 
- 		if (! empty ( $actionType )) {
 
- 			if ($actionType != 'NOTRAIN')
 
- 				die ( 'illegal request--errorActionType' );
 
- 		}
 
- 		
 
- 		if (! empty ( $ridKey )) {
 
- 			Doo::loadModel ( 'receipt' );
 
- 			$receipt = new receipt ();
 
- 			Doo::loadModel ( 'wasteBook' );
 
- 			$wasteBook = new wasteBook ();
 
- 			Doo::loadClass ( 'XDeode' );
 
- 			$XDeode = new XDeode ( 5 );
 
- 			$rid = $XDeode->decode ( $ridKey );
 
- 			
 
- 			$rinfo = $receipt->getReceiptByRid ( $rid );
 
- 			$amount=$rinfo['amount'];
 
- 			
 
- 			if (empty ( $rinfo )) {
 
- 				die ( 'illegal request--noData' );
 
- 			}
 
- 			$accountType = '';
 
- 			if ($rinfo ['Rtype'] == 0) {
 
- 				$accountType = 3;
 
- 				$expensesType='EXPENDITURE';
 
- 			} elseif ($rinfo ['Rtype'] == 1) {
 
- 				if (! empty ( $rinfo ['accountItem'] )){
 
- 					$accountType = 2;
 
- 					if ($amount>=0){
 
- 						$expensesType='EXPENDITURE';
 
- 					}else{
 
- 						$expensesType='INCOME';
 
- 					}
 
- 				}else{
 
- 					$accountType = 1;
 
- 					$expensesType='EXPENDITURE';
 
- 				}
 
- 			} elseif ($rinfo ['Rtype'] == 2) {
 
- 				$accountType = 4;
 
- 				$expensesType='EXPENDITURE';
 
- 			} elseif ($rinfo ['Rtype'] == 3) {//培训班结算 收支类型
 
- 				$accountType = 12;
 
-                 Doo::loadClass ( 'authcode.func' );
 
-                 $amountTrain=authcode($amountTrain);
 
-                 if(!is_numeric ( $amountTrain )) {
 
-                     die('illegal request--payType');
 
-                 }
 
- 				if($amountTrain>=0){
 
- 					$expensesType='INCOME';
 
- 				}else{
 
- 					$expensesType='EXPENDITURE';
 
- 				}
 
- 				$amount=$amountTrain;
 
- 			}
 
- 			
 
- 			if (empty ( $accountType )) {
 
- 				die ( 'illegal request--accountType' );
 
- 			}
 
- 			if (empty ( $bank ) || (! ($bank == 'CGBDeposit' || $bank == 'ICBCDeposit' || $bank == 'HUADeposit' || $bank == 'PersonalDeposit'))) {
 
- 				die ( 'illegal request--Bank' );
 
- 			}
 
- 			
 
- 			if($accountType==12){
 
- 			$receipt->amount = $amount;
 
- 			$receipt->update ( array (
 
- 					'where' => 'rid=' . $rid 
 
- 			) );
 
- 			}
 
- 			/*
 
- 			// 更新借款汇款金额
 
- 			if ($accountType == 1) {
 
- 				Doo::loadModel ( 'loanReceipt' );
 
- 				$loanReceipt = new loanReceipt ();
 
- 				$loanReceipt->amount = $amount;
 
- 				
 
- 				$loanReceipt->update ( array (
 
- 						'where' => ' rid = ' . $rinfo ['loanRid'] 
 
- 				) );
 
- 			}
 
- */
 
- 			
 
- 			
 
- 			//汇款金额正数
 
- 			$amount=abs($amount);
 
- 			// $accountType = 12;
 
- 			$accountBank = $bank;
 
- 			if ($expensesType == "INCOME") {
 
- 				$expensesTypeWaste = 1;
 
- 				$accountPriceShow = $accountPrice = $amount;
 
- 			} elseif ($expensesType == "EXPENDITURE") {
 
- 				$expensesTypeWaste = 2;
 
- 				$accountPriceShow = $amount;
 
- 				$accountPrice = - $amount;
 
- 			} else {
 
- 				die ( 'illegal request--expensesType' );
 
- 			}
 
- 			
 
- 			// 公司流水记录
 
- 			$abDetail = $wasteBook->getAccountBookByAid ( $expensesTypeWaste, $accountType, $rid );
 
- 			// 银行
 
- 			if (empty ( $abDetail )) {
 
- 				$item = array (
 
- 						'dataID' => $rid,
 
- 						'expensesType' => $expensesTypeWaste,
 
- 						'accountType' => $accountType,
 
- 						'accountPriceShow' => $accountPriceShow,
 
- 						'accountPrice' => $accountPrice,
 
- 						'accountBank' => $accountBank,
 
- 						
 
- 						'category' => $rinfo ['category'] [0] ['title'],
 
- 						'cid' => $rinfo ['category'] [0] ['cid'],
 
- 						'name' => $rinfo ['staffDetail'] ['username'],
 
- 						'sid' => $rinfo ['staffDetail'] ['sid'],
 
- 						'inputDate' => $inputDate,
 
- 						'remarks'=>$remarks
 
- 				);
 
- 				$wasteBook->setAccountBookStatistics ( $item );
 
- 			}
 
- 		}
 
- 		
 
- 		if (empty ( $actionType )) {
 
- 			$XDeode = new XDeode ( 7 );
 
- 			return '/receiptTrain/implement/' . $XDeode->encode ( $rid ) . '.html?trainEdiType=COLLECT';
 
- 		} elseif ($actionType == 'NOTRAIN') {
 
- 			$XDeode = new XDeode ( 5 );
 
- 			if ($rinfo['Rtype']==1){
 
- 				return "/implement/loan/" . $XDeode->encode ( $rid ) . ".html";
 
- 			}elseif($rinfo['Rtype']==0){
 
- 				return "/implement/receipt/" . $XDeode->encode ( $rid ) . ".html";
 
- 			}elseif($rinfo['Rtype']==2){
 
- 				return "/implement/public/" . $XDeode->encode ( $rid ) . ".html";
 
- 			}
 
- 			
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 费用流水
 
- 	 */
 
- 	function receiptWasteBook() {
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		
 
- 		$receiptList = $receipt->getReceiptByWaste ();
 
- 		foreach ($receiptList as $key=>$value){
 
- 			$receiptList[$key]['balance']='';
 
- 			if($value['Rtype']==1){
 
- 				$receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
 
- 				$receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
 
- 			}elseif($value['Rtype']==3){
 
- 				$payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
 
- 				$receiptList[$key]['payment']=$payment;
 
- 				$receiptList[$key]['paymentABS']=abs($payment);
 
- 			}
 
- 			$receiptList[$key]['amountABS']=abs($value['amount']);
 
- 		}
 
- 		
 
- 		
 
- 		$data ['inputDate'] = date ( "Y-m-d H:i:s" );
 
- 		$data ['receiptList'] = $receiptList;
 
- 		
 
- 		$data ['memu'] = "receipt";
 
- 		$data ['staff'] = $this->staff;
 
- 		
 
- 		$data ['receiptMemu'] = 'receiptWasteBook';
 
- 		$data ['verifyId'] = $this->verifyId;
 
- 		$data ['executeId'] = $this->executeId;
 
- 		
 
- 		$this->render ( "/receipt/receiptWasteBook", $data );
 
- 	}
 
- 	
 
- 	function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
 
- 		// 收入合计
 
- 		Doo::loadModel ( 'invoiceTraining' );
 
- 		$invoiceTraining = new invoiceTraining ();
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		$invoiceTrainingDetail = array (
 
- 				'invoiceArriveAmount' => '0.00',
 
- 				'RIAmount' => '0.00',
 
- 				'invoiceTotalAmount' => '0.00',
 
- 				'invoiceCompanyAmount' => '0.00',
 
- 				'invoiceArriveAmountM'=>'0.00',
 
- 				'invoiceCompanyAmountM'=>'0.00'
 
- 		);
 
- 		if ($invoiceTrainId != 0) {
 
- 			$invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
 
- 		}
 
- 		$invoiceArriveAmount = $RIAmount = 0;
 
- 		if (! empty ( $invoiceTrainingDetail )) {
 
- 			$invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
 
- 			$RIAmount = $invoiceTrainingDetail ['RIAmount'];
 
- 		}
 
- 			
 
- 		// 备用金
 
- 		$sum = 0;
 
- 		if (! empty ( $trainLoanRid )) {
 
- 			
 
- 			$receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
 
- 			foreach ($receiptLoanList as $key=>$value){
 
- 				$sum+=$value['sum'];
 
- 			}
 
- 			
 
- // 			$receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
 
- // 			$sum = $receiptLoanDetailBak ['sum'];
 
- 		}
 
- 			
 
- 		// 支出项金额详情
 
- 		// 项目金额合计
 
- 		Doo::loadModel ( 'RItem' );
 
- 		$RItem = new RItem ();
 
- 		Doo::loadModel ( 'accountItem' );
 
- 		$accountItem = new accountItem ();
 
- 		// 讲师获得
 
- 		Doo::loadModel ( 'RILecturer' );
 
- 		$RILecturer = new RILecturer ();
 
- 		$RItemList = $RItem->getRItemByRid ($rid );
 
- 		$RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
 
- 		// 支出项金额详情
 
- 		$aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
 
- 		$categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
 
- 			
 
- 		$payment = $sum + $RIAmount - $categoryActualExpenditure;
 
- 		return $payment;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 费用流水新增
 
- 	 */
 
- 	function receiptWasteBookAddDo() {
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
 
- 		if (empty ( $ridKey )) {
 
- 			die ( 'illegal request--ridKey' );
 
- 		}
 
- 		
 
- 		$receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : "";
 
- 		$receivedRemarks = $this->get_args ( 'receivedRemarks' ) ? $this->get_args ( 'receivedRemarks' ) : "";
 
- 		$receivedInputDate = $this->get_args ( 'receivedInputDate' ) ? $this->get_args ( 'receivedInputDate' ) : date ( "Y-m-d H:i:s" );
 
- 		$amountTrain = $this->get_args ( 'paymentAuthCode' )  ? $this->get_args ( 'paymentAuthCode' ) : '';
 
- 		
 
- 		if ( empty ( $receivedBank )) {
 
- 			die ( 'illegal request--Bank' );
 
- 		}
 
- 		
 
- 		
 
- 		/*
 
- 		$expensesType = $this->get_args ( 'expensesType' ) ? $this->get_args ( 'expensesType' ) : "";
 
- 		$expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : "";
 
- 		$expenditurePrice = $this->get_args ( 'expenditurePrice' ) ? $this->get_args ( 'expenditurePrice' ) : "";
 
- 		$expenditureRemarks = $this->get_args ( 'expenditureRemarks' ) ? $this->get_args ( 'expenditureRemarks' ) : "";
 
- 		$expenditureInputDate = $this->get_args ( 'expenditureInputDate' ) ? $this->get_args ( 'expenditureInputDate' ) : date ( "Y-m-d H:i:s" );
 
- 		$receivedPrice = $this->get_args ( 'receivedPrice' ) ? $this->get_args ( 'receivedPrice' ) : "";
 
- 		
 
- 		if (empty ( $expenditureBank ) || empty ( $receivedBank )) {
 
- 			die ( 'illegal request--Bank' );
 
- 		}
 
-         $expenditurePrice=str_replace(',','',$expenditurePrice);
 
-         $receivedPrice=str_replace(',','',$receivedPrice);
 
-         if ($expensesType == "INCOME") {
 
-             if(!is_numeric($receivedPrice)){
 
-                 die ( 'illegal request--receivedPrice' );
 
-             }
 
-         } elseif ($expensesType == "EXPENDITURE") {
 
-             if(!is_numeric($expenditurePrice)){
 
-                 die ( 'illegal request--expenditurePrice' );
 
-             }
 
-         }
 
-         */
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 5 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		
 
- 		$detail = $receipt->getReceiptByRid ( $rid );
 
- 		if (empty ( $detail )) {
 
- 			die ( 'illegal request--noData' );
 
- 		}
 
- 		$amount=$detail['amount'];
 
- 		
 
- 		$accountType = '';
 
- 		/*
 
- 		if ($detail ['Rtype'] == 1) {
 
- 			if (! empty ( $detail ['accountItem'] ))
 
- 				$accountType = 2;
 
- 			else
 
- 				$accountType = 1;
 
- 		} elseif ($detail ['Rtype'] == 2) {
 
- 			$accountType = 4;
 
- 		} elseif ($detail ['Rtype'] == 0) {
 
- 			$accountType = 3;
 
- 		} elseif ($detail ['Rtype'] == 3) {
 
- 			$accountType = 12;
 
- 		}
 
- 		*/
 
- 		
 
- 		if ($detail ['Rtype'] == 0) {
 
- 			$accountType = 3;
 
- 			$expensesType='EXPENDITURE';
 
- 		} elseif ($detail ['Rtype'] == 1) {
 
- 			if (! empty ( $rinfo ['accountItem'] )){
 
- 				$accountType = 2;
 
- 				if ($amount>=0){
 
- 					$expensesType='EXPENDITURE';
 
- 				}else{
 
- 					$expensesType='INCOME';
 
- 				}
 
- 			}else{
 
- 				$accountType = 1;
 
- 				$expensesType='EXPENDITURE';
 
- 			}
 
- 		} elseif ($detail ['Rtype'] == 2) {
 
- 			$accountType = 4;
 
- 			$expensesType='EXPENDITURE';
 
- 		} elseif ($detail ['Rtype'] == 3) {//培训班结算 收支类型
 
- 			$accountType = 12;
 
- 			Doo::loadClass ( 'authcode.func' );
 
- 			$amountTrain=authcode($amountTrain);
 
- 			if(!is_numeric ( $amountTrain )) {
 
- 				die('illegal request--payType');
 
- 			}
 
- 			
 
- 			if($amountTrain>=0){
 
- 				$expensesType='INCOME';
 
- 			}else{
 
- 				$expensesType='EXPENDITURE';
 
- 			}
 
- 			$amount=$amountTrain;
 
- 		}
 
- 		
 
- 		//汇款金额正数
 
- 		$amount=abs($amount);
 
- 		//$accountType = 12;
 
- 		$accountBank = $receivedBank;
 
- 		$inputDate = $receivedInputDate;
 
- 		if ($expensesType == "INCOME") {
 
- 			$expensesTypeWaste = 1;
 
- 			$accountPriceShow = $accountPrice = $amount;
 
- 		} elseif ($expensesType == "EXPENDITURE") {
 
- 			$expensesTypeWaste = 2;
 
- 			$accountPriceShow = $amount;
 
- 			$accountPrice = - $amount;
 
- 		} else {
 
- 			die ( 'illegal request--expensesType' );
 
- 		}
 
- 		
 
- 		
 
- 		/*
 
- 		$accountPriceShow = $accountPrice = 0;
 
- 		$expensesTypeWaste = 0;
 
- 		$accountBank = '';
 
- 		$inputDate = date ( "Y-m-d H:i:s" );
 
- 		if ($expensesType == "INCOME") {
 
- 			$expensesTypeWaste = 1;
 
- 			$accountPriceShow = $receivedPrice;
 
- 			$accountPrice = $receivedPrice;
 
- 			$accountBank = $receivedBank;
 
- 			$inputDate = $receivedInputDate;
 
- 		} elseif ($expensesType == "EXPENDITURE") {
 
- 			$expensesTypeWaste = 2;
 
- 			$accountPriceShow = $expenditurePrice;
 
- 			$accountPrice = - $expenditurePrice;
 
- 			$accountBank = $expenditureBank;
 
- 			$inputDate = $expenditureInputDate;
 
- 		} else {
 
- 			die ( 'illegal request--expensesType' );
 
- 		}
 
- 		*/
 
- 		
 
- 		$receipt = new receipt ();
 
- 		$receipt->amount = $accountPrice;
 
- 		$receipt->update ( array (
 
- 				'where' => 'rid=' . $rid 
 
- 		) );
 
- 		
 
- 		
 
- 		// 更新借款汇款金额
 
- 		if ($accountType == 1) {
 
- 			Doo::loadModel ( 'loanReceipt' );
 
- 			$loanReceipt = new loanReceipt ();
 
- 			$loanReceipt->amount = $accountPrice;
 
- 			
 
- 			$loanReceipt->update ( array (
 
- 					'where' => ' rid = ' . $detail ['loanRid'] 
 
- 			));
 
- 		}
 
- 		
 
- 		// 公司流水记录
 
- 		Doo::loadModel ( 'wasteBook' );
 
- 		$wasteBook = new wasteBook ();
 
- 		
 
- 		$abDetail = $wasteBook->getAccountBookByAid ( $expensesTypeWaste, $accountType, $rid );
 
- 		// 银行
 
- 		if (empty ( $abDetail )) {
 
- 			$item = array (
 
- 					'dataID' => $rid,
 
- 					'expensesType' => $expensesTypeWaste,
 
- 					'accountType' => $accountType,
 
- 					'accountPriceShow' => $accountPriceShow,
 
- 					'accountPrice' => $accountPrice,
 
- 					'accountBank' => $accountBank,
 
- 					
 
- 					'category' => $detail ['category'] [0] ['title'],
 
- 					'cid' => $detail ['category'] [0] ['cid'],
 
- 					'name' => $detail ['staffDetail'] ['username'],
 
- 					'sid' => $detail ['staffDetail'] ['sid'],
 
- 					'inputDate' => $inputDate 
 
- 			);
 
- 			$wasteBook->setAccountBookStatistics ( $item );
 
- 		}
 
- 		return '/receiptWasteBook';
 
- 	}
 
-     /**
 
-      * 培训班结算营收总计
 
-      */
 
- 	function receiptTrainRevenue(){
 
-         //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
 
-         Doo::loadModel ( 'receipt' );
 
-         $receipt = new receipt ();
 
-         //获得可查看的办事处
 
-         Doo::loadModel ( "receiptTrainManage" );
 
-         $invoiceCategoryManage = new receiptTrainManage ();
 
-         $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
 
-         if(empty($imcStaff)){
 
-             die ( 'illegal request--Insufficient Permissions' );
 
-         }
 
-         $cidList = array ();
 
-         foreach ( $imcStaff as $key => $value ) {
 
-             array_push ( $cidList, $value ['cid'] );
 
-         }
 
-         $cidString=implode ( ',', $cidList );
 
-         //初始化收款数据
 
-         $where=" where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and paidStatus=0 and invoiceTrainId!=0 ";
 
-         $sql="select invoiceTrainId,rid
 
-         from CLD_receipt as a
 
-         ".$where." and a.cid in (".$cidString.") ";
 
-         $receipt->initReceiptTrainRevenue($sql);
 
-         $unpaid=$receipt->getReceiptTrainByPaid(0,5,$cidString);
 
-         $paid=$receipt->getReceiptTrainByPaid(1,5,$cidString);
 
-         $MonthPriceList=$receipt->getReceiptTrainByYearChart($cidString);
 
-         $income=$month=$pay=$profit=array();
 
-         for ($i=1;$i<=12;$i++){
 
-             $flag=true;
 
-             array_push($month,date("Y").'-'.$i);
 
-             foreach ($MonthPriceList as $key=>$value){
 
-                 if($key==$i){
 
-                     $flag=false;
 
-                     array_push($income,$value['ITprice']);
 
-                     array_push($pay,$value['RIprice']);
 
-                     array_push($profit,$value['ITprice']-$value['RIprice']);
 
-                 }
 
-             }
 
-             if ($flag){
 
-                 array_push($income,0);
 
-                 array_push($pay,0);
 
-                 array_push($profit,0);
 
-             }
 
-         }
 
-         $data ['income'] =json_encode ( $income );
 
-         $data ['pay'] =json_encode ( $pay );
 
-         $data ['profit'] =json_encode ( $profit );
 
-         $data ['month'] =json_encode ( $month );
 
-         $data ['paid'] = $paid;
 
-         $data ['unpaid'] = $unpaid;
 
-         $data ['memu'] = "receipt";
 
-         $data ['staff'] = $this->staff;
 
-         //var_dump( $this->executeId) ;
 
-         //die;
 
-         $data ['receiptMemu'] = 'receiptTrainRevenue';
 
-         $data ['verifyId'] = $this->verifyId;
 
-         $data ['executeId'] = $this->executeId;
 
-         $this->render ( "/receipt/receiptTrainRevenue", $data );
 
-     }
 
-     /**
 
-      * 所有培训班结算
 
-      */
 
-     function receiptTrainRevenueAchieve(){
 
-         //$paid = $this->get_args ( 'paid' )  ? $this->get_args ( 'paid' ) : '';
 
-         $paid =isset ( $this->params ['paid'] ) ? $this->params ['paid'] : 'ALL';
 
-         $cidKey = $this->get_args ( 'cidKey' )  ? $this->get_args ( 'cidKey' ) : '';
 
-         $page_size = 12;
 
-         $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
 
-         $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
 
-         $get='/'.$paid ;//= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
 
-         Doo::loadModel ( 'receipt' );
 
-         $receipt = new receipt ();
 
-         Doo::loadModel ( 'L_category' );
 
-         $Lcategory = new L_category ();
 
-         Doo::loadClass ( 'XDeode' );
 
-         $XDeode = new XDeode ( 5 );
 
-         $cidSql=$cid='';
 
-         if(!empty($cidKey)){
 
-             $cid = $XDeode->decode ( $cidKey );
 
-             $cidSql=" and a.cid=".$cid." ";
 
-         }
 
-         //获得可查看的办事处
 
-         Doo::loadModel ( "receiptTrainManage" );
 
-         $invoiceCategoryManage = new receiptTrainManage ();
 
-         $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
 
-         $cidList = array ();
 
-         foreach ( $imcStaff as $key => $value ) {
 
-             array_push ( $cidList, $value ['cid'] );
 
-         }
 
-         if(!empty($cid)&&!in_array($cid, $cidList)){
 
-             die("illegal request-cid");
 
-         }
 
-         $cidString=implode ( ',', $cidList );
 
-         $categoryList = $Lcategory->getCategoryInCid ( $cidString );
 
-         $psSql='';$paidKey='';
 
-         if(!empty($paid)&&$paid!="ALL"){
 
-             if ($paid=='UNPAID'){
 
-                 $paidKey='0';
 
-             }elseif($paid=='PAID'){
 
-                 $paidKey='1';
 
-             }
 
-             $psSql=" and a.paidStatus=".$paidKey." ";
 
-         }
 
-         $dateArr = explode ( ':', $trainEndDate );
 
-         $D1 = $dateString = '';
 
-         $D2 = '';
 
-         if (! empty ( $trainEndDate )) {
 
-             $D1 = $dateArr [0];
 
-             if (isset ( $dateArr [1] ))
 
-                 $D2 = $dateArr [1];
 
-             else
 
-                 $D2 = '';
 
-             $dateString = $D1 . ":" . $D2;
 
-         }
 
-         $dateSql='';
 
-         if (! empty ( $D1 ) && ! empty ( $D2 )){
 
-             $dateSql = ' and trainEndDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
 
-         }elseif (! empty ( $D1 ) && empty ( $D2 )){
 
-             $dateSql = ' and trainEndDate like "%' . $D1 . '%"  ';
 
-         }
 
-         $selectCount=" count(*) as count ";
 
-         $where=" where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0  and invoiceTrainId!=0 ".$psSql;
 
-         $sql = "select ".$selectCount."
 
-                 from CLD_receipt as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid) 
 
-                   ".$where." and a.cid in (".$cidString.") ".$cidSql.$dateSql;
 
-         $action="receiptTrainRevenueAchieve";
 
-         $pageinfo = $this->get_page (  $sql, $page, $page_size, $action, $get, "" );
 
-         $limit = $pageinfo ['lower'] . ',' . $page_size;
 
-         $rtpa=$receipt->getReceiptTrainByPaidAll($paidKey,$cid,$dateSql,$limit,$cidString,$where);
 
-         //金额合计功能
 
-         $sql="select invoiceTrainId,rid
 
-         from CLD_receipt as a
 
-         ".$where." and a.cid in (".$cidString.") ";
 
-         $receiptTrainPriceList=$receipt->getReceiptTrainSumByItid($sql);
 
-         $data ['receiptTrainPriceList']=$receiptTrainPriceList;
 
-         $data ['dateString']=$dateString;
 
-         $data ['cidKey']=$cidKey;
 
-         $data ['categoryList'] =$categoryList;
 
-         $data ['paid'] = $paid;
 
-         $data ['get'] = $get;
 
-         $data ['page'] = $pageinfo;
 
-         $data ['onpage'] = $page;
 
-         $data ['rtpa'] = $rtpa;
 
-         $data ['memu'] = "receipt";
 
-         $data ['staff'] = $this->staff;
 
-         $data ['receiptMemu'] = 'receiptTrainRevenue';
 
-         $data ['verifyId'] = $this->verifyId;
 
-         $data ['executeId'] = $this->executeId;
 
-         $this->render ( "/receipt/receiptTrainRevenueAchieve", $data );
 
-     }
 
-     /*
 
-      * 全年办事处汇总明细
 
-      */
 
-     function receiptSummaryStatisticsByAgency(){
 
-     	
 
-     	//$cidIn = $this->get_args ( 'cidIn' ) ? $this->get_args ( 'cidIn' ) : '12,10,9';
 
-     	include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
 
-     	Doo::loadClass ( 'XDeode' );
 
-     	
 
-     	$cidKeyIn=file_get_contents( "protected/config/receipt/summary.conf.ini");
 
-     	if(!empty($cidKeyIn)){
 
- 	    	$cidKeyIn=explode(',', $cidKeyIn);$cidIn=array();
 
- 	    	foreach ($cidKeyIn as $key=>$value){
 
- 	    		$XDeode = new XDeode ( 5 );
 
- 	    		array_push($cidIn, $XDeode->decode($value));
 
- 	    	}
 
- 	    	$cidIn=implode(',', $cidIn);
 
-     	}
 
-     	$year= $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date('Y');
 
-     	
 
-     	
 
-     	$sectionHtml=$sectionItemHtml='';
 
-     	if(!empty($cidIn)){
 
-     		Doo::loadModel ( 'receiptDetail' );
 
-     		$receiptDetail = new receiptDetail ();
 
-     		Doo::loadModel ( 'accountItem' );
 
-     		$accountItem = new accountItem ();
 
-     		Doo::loadModel ( 'L_category' );
 
-     		$category = new L_category ();
 
-     		
 
-     		$aiList=$accountItem->getCategory();
 
-     		$aiAllList=$accountItem->getAccountItem();
 
-     		$list=$receiptDetail->getReceiptDetailByYear($cidIn,$year);
 
-     		
 
-     		$cidArray=explode(',', $cidIn);
 
-     		$dataSummary=array();
 
-     		foreach ($cidArray as $cak=>$cav){
 
-     			$dataSummary[$cav]=array();
 
-     			for($month=1;$month<=12;$month++){
 
-     				foreach ($aiList as $aik=>$aiv){
 
-     					$dataSummary[$cav][$month][$aiv['category']]=array();
 
-     				}
 
-     				$dataSummary[$cav][$month]['报销金额调整']=array();
 
-     			}
 
-     		}
 
-     		foreach ($list as $key=>$value){
 
-     			array_push($dataSummary[$value['cid']][$value['month']][$value['itemCategory']], $value);
 
-     		}
 
-     		
 
-     		//print_r($dataSummary);die;
 
-     		
 
-     		Doo::loadClass ( 'receipt.func' );
 
-     		//构建数据html
 
-     		$cglist=$category->getCategoryInCid($cidIn);
 
-     		$summaryDateHtml=_getReceiptSummaryHtml($cglist,$aiAllList,$dataSummary,$year);
 
-     		
 
-     		//构建栏目展示Html
 
-     		foreach ($aiAllList as $key=>$value){
 
-     			//栏目
 
-     			$sectionCount=count($value)+1;
 
-     			$sectionHtml.='<th colspan="'.$sectionCount.'">'.$key.'</th>';
 
-     			//栏目细则
 
-     			$sectionItemHtml.='<th class="colRed">合计</th>';
 
-     			foreach ($value as $k=>$v){
 
-     				$sectionItemHtml.='<th>'.$v['name'].'</th>';
 
-     			}
 
-     		}
 
-     		
 
-     	}
 
-     	
 
-     	//办事处显示设置
 
-     	$categoryList=$category->getCategory();
 
-     	$selectedSummary=$cidKeyIn;
 
-     	foreach ($categoryList as $key=>$value){
 
-     		$categoryList[$key]['checked']='';
 
-     		foreach ($selectedSummary as $v){
 
-     			if($value['cidKey']==$v){
 
-     				$categoryList[$key]['checked']='checked';
 
-     				break;
 
-     			}
 
-     		}
 
-     	}
 
-     	
 
-     	//年份展示
 
-     	Doo::loadClass ( 'date.func' );
 
-     	$dateHtml=_getDateHtml($year);
 
-     	
 
-     	$summarData=json_encode($dataSummary);
 
-     	
 
-     	$data['summarData']=URLEncode($summarData);
 
-     	$data['categoryList']=$categoryList;
 
-     	
 
-     	$data['dateHtml']=$dateHtml;
 
-     	$data['sectionHtml']=$sectionHtml;
 
-     	$data['sectionItemHtml']=$sectionItemHtml;
 
-     	$data['summaryDateHtml']=$summaryDateHtml;
 
-     	
 
-     	$data['year']=$year;
 
-     	
 
-     	$data ['memu'] = "receipt";
 
-     	$data ['staff'] = $this->staff;
 
-     	
 
-     	$data ['receiptMemu'] = 'companyCategoryCollect';
 
-     	$data ['verifyId'] = $this->verifyId;
 
-     	$data ['executeId'] = $this->executeId;
 
-     	
 
-     	$this->render ( "/receipt/receiptSummaryStatisticsByAgency", $data );
 
-     }
 
-     
 
-     //设置办事处展示明细
 
-     function setSummaryCategory(){
 
-     	$cidKey= $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : "";
 
-     	
 
-     	$cidKey=implode(',', $cidKey);
 
-     	file_put_contents ( "protected/config/receipt/summary.conf.ini", $cidKey);
 
-     	
 
-     	return '/receiptSummaryStatisticsByAgency';
 
-     }
 
-     
 
-     //导出办事处全年费用汇总excel
 
-     function exportReceiptSummaryExcel(){
 
-     	$summaryData= $this->get_args ( 'summaryData' ) ? $this->get_args ( 'summaryData' ) : "";
 
-     	$year= $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
 
-     	//$cidIn = $this->get_args ( 'cidIn' ) ? $this->get_args ( 'cidIn' ) : '12,10,9';
 
-     	
 
-     	Doo::loadClass ( 'XDeode' );
 
-     	
 
-     	$cidKeyIn=file_get_contents( "protected/config/receipt/summary.conf.ini");
 
-     	$cidKeyIn=explode(',', $cidKeyIn);$cidIn=array();
 
-     	foreach ($cidKeyIn as $key=>$value){
 
-     		$XDeode = new XDeode ( 5 );
 
-     		array_push($cidIn, $XDeode->decode($value));
 
-     	}
 
-     	$cidIn=implode(',', $cidIn);
 
-     	
 
-     	if(!empty($summaryData)){
 
-     		
 
-     		Doo::loadModel ( 'accountItem' );
 
-     		$accountItem = new accountItem ();
 
-     		Doo::loadModel ( 'L_category' );
 
-     		$category = new L_category ();
 
-     		
 
-     		$aiAllList=$accountItem->getAccountItem();
 
-     		$cglist=$category->getCategoryInCid($cidIn);
 
-     		
 
-     		$summaryData=json_decode(urldecode($summaryData), true);
 
-     		Doo::loadClass ( 'receipt.func' );
 
-     		
 
-     		excelRCData($summaryData,$aiAllList,$cglist,$year);
 
-     	}
 
-     	
 
-     	die ( 'illegal request--excel Data null' );
 
-     }
 
-     
 
- 	function exportReceiptTrainExcel() {
 
- 		$rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
 
- 		$ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
 
- 		
 
- 		$summaryJson = $this->get_args ( 'summaryJson' ) ? $this->get_args ( 'summaryJson' ) : "";
 
- 		$aiListJson = $this->get_args ( 'aiListJson' ) ? $this->get_args ( 'aiListJson' ) : "";
 
- 		
 
- 		
 
- 		Doo::loadClass ( 'XDeode' );
 
- 		$XDeode = new XDeode ( 7 );
 
- 		$rid = $XDeode->decode ( $ridKey );
 
- 		
 
- 		if (! is_numeric ( $rid ))
 
- 			die ( 'illegal request' );
 
- 		
 
- 		Doo::loadModel ( 'receipt' );
 
- 		$receipt = new receipt ();
 
- 		Doo::loadModel ( 'receiptTraining' );
 
- 		$receiptTraining = new receiptTraining ();
 
- 		
 
- 		$receiptDetail = $receipt->getReceiptByRid ( $rid );
 
- 		$receiptTrainDetail = $receiptTraining->getReceiptTrainingByRtid ( $rtidKey );
 
- 		
 
- 		
 
- 		
 
- 		$summary=json_decode(urldecode($summaryJson), true);
 
- 		$aiList=json_decode(urldecode($aiListJson), true);
 
- 		//借款相关
 
- 		$receiptLoanDetail=array();
 
- 		if (! empty ( $receiptDetail ['trainLoanRid'] )) {
 
- 			$receiptLoanDetail = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
 
- 		}
 
- 		
 
- 		//收入
 
- 		Doo::loadModel ( 'invoice' );
 
- 		$invoice = new invoice ();
 
- 		Doo::loadModel ( 'invoiceTraining' );
 
- 		$invoiceTraining = new invoiceTraining ();
 
- 		$invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
 
- 		$invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
 
- 		
 
- 		//支出
 
- 		Doo::loadModel ( 'RItem' );
 
- 		$RItem = new RItem ();
 
- 		$RItemList = $RItem->getRItemByRid ( $rid );
 
- 		
 
- 		//讲师
 
- 		Doo::loadModel ( 'RILecturer' );
 
- 		$RILecturer = new RILecturer ();
 
- 		$RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
 
- 		
 
- 		Doo::loadClass ( 'receipt.func' );
 
- 		excelData ( $receiptTrainDetail, $receiptDetail, $summary, $aiList,$receiptLoanDetail,$invoiceList,$RItemList,$RILecturerList,$invoiceTrainingDetail );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获得审批流程
 
- 	 */
 
- 	private function fnGetReceiptApprovalProcess($verifyList = array(), $verifyStaff = array()) {
 
- 		Doo::loadModel ( 'role' );
 
- 		$role = new role ();
 
- 		Doo::loadModel ( 'staff' );
 
- 		$staff = new staff ();
 
- 		
 
- 		$flag = true;
 
- 		$roleKey = $button = 0;
 
- 		$endStaffArray = array ();
 
- 		$roleArrayCopy = array ();
 
- 		foreach ( $verifyList as $k => $v ) {
 
- 			
 
- 			if ($v [1] == 'ROLE') {
 
- 				if (! empty ( $verifyStaff )) {
 
- 					$endStaffArray = end ( $verifyStaff );
 
- 					if ($v [0] == $endStaffArray ['nextStaff']) {
 
- 						$roleId = $v [0];
 
- 					}
 
- 				}
 
- 				
 
- 				$roleVerify = json_decode ( $v [3], true );
 
- 				$roleKey = $k;
 
- 				$roleArray = array ();
 
- 				$rolename = $role->getOne ( array (
 
- 						'where' => 'rid=' . $v [0],
 
- 						'asArray' => true 
 
- 				) );
 
- 				
 
- 				foreach ( $roleVerify as $o => $p ) {
 
- 					$staffID = explode ( '_', $p );
 
- 					$staffInfo = $staff->getOne ( array (
 
- 							'where' => 'sid=' . $staffID [0],
 
- 							'asArray' => true 
 
- 					) );
 
- 					// print_r($staffID);
 
- 					$exp = array (
 
- 							0 => $staffInfo ['sid'],
 
- 							1 => $staffID [1],
 
- 							2 => $staffInfo ['avatar'],
 
- 							'date' => '',
 
- 							'date' => '',
 
- 							'opinion' => '',
 
- 							'status' => '',
 
- 							'rolename' => $rolename ['name'] 
 
- 					);
 
- 					array_push ( $roleArray, $exp );
 
- 				}
 
- 				$roleArrayCopy [$v [0]] = $roleArray;
 
- 				// $verifyList[$k]['roleArray']=$roleArray;
 
- 			}
 
- 			// print_r($roleArray);
 
- 			
 
- 			$verifyList [$k] ['date'] = "";
 
- 			$verifyList [$k] ['opinion'] = "";
 
- 			$verifyList [$k] ['status'] = "";
 
- 			if (empty ( $verifyStaff )) {
 
- 				$verifyList [$k] ['date'] = "";
 
- 				$verifyList [$k] ['opinion'] = "";
 
- 				if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
 
- 					$verifyList [$k] ['status'] = 4;
 
- 					$button = 4;
 
- 					$flag = false;
 
- 				}
 
- 			} else {
 
- 				
 
- 				foreach ( $verifyStaff as $m => $u ) {
 
- 					if ($v [0] == $m) {
 
- 						$verifyList [$k] ['date'] = $u ['date'];
 
- 						$verifyList [$k] ['opinion'] = $u ['opinion'];
 
- 						$verifyList [$k] ['status'] = $u ['status'];
 
- 						$flag = false;
 
- 						break;
 
- 					}
 
- 				}
 
- 				
 
- 				$endStaffArray = end ( $verifyStaff );
 
- 				if (isset ( $endStaffArray ['ROLE'] )) {
 
- 				} else {
 
- 					$endKey = key ( $verifyStaff );
 
- 					if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
 
- 						$button = 4;
 
- 						$verifyList [$k] ['status'] = 4;
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$rolename ['name'] = '';
 
- 		if (! empty ( $roleId )) {
 
- 			Doo::loadModel ( 'role' );
 
- 			$role = new role ();
 
- 			$rolename = $role->getOne ( array (
 
- 					'where' => 'rid=' . $roleId,
 
- 					'asArray' => true 
 
- 			) );
 
- 		}
 
- 		
 
- 		if (! empty ( $verifyStaff ))
 
- 			$endStaffArray = end ( $verifyStaff );
 
- 		
 
- 		$KOP = false;
 
- 		foreach ( $roleArrayCopy as $P => $A ) {
 
- 			
 
- 			foreach ( $A as $MKI => $AVL ) {
 
- 				if (! empty ( $verifyStaff )) {
 
- 					// &&$rolename['rid']==$endStaffArray['nextStaff']
 
- 					if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
 
- 						$button = 4;
 
- 						$roleArrayCopy [$P] [$MKI] ['status'] = 4;
 
- 					}
 
- 					
 
- 					foreach ( $verifyStaff as $m => $u ) {
 
- 						$AVLFK = $AVL [0] . '_R';
 
- 						// echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
 
- 						
 
- 						if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
 
- 							$roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
 
- 							$roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
 
- 							$roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
 
- 							
 
- 							break;
 
- 						}
 
- 					}
 
- 				} else {
 
- 					
 
- 					if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
 
- 						$button = 4;
 
- 						$roleArrayCopy [$P] [$MKI] ['status'] = 4;
 
- 					}
 
- 				}
 
- 				// $roleArray[$MKI]['rolename']=$rolename['name'];
 
- 				$KOP = true;
 
- 			}
 
- 		}
 
- 		
 
- 		foreach ( $roleArrayCopy as $k => $v ) {
 
- 			foreach ( $verifyList as $m => $n ) {
 
- 				if ($n [0] == $k) {
 
- 					array_splice ( $verifyList, $m, 1, $v );
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		return array (
 
- 				'verifyList' => $verifyList,
 
- 				'isApproval' => $button 
 
- 		);
 
- 	}
 
- 	function _GetFileEXT($filename) {
 
- 		$pics = explode ( '.', $filename );
 
- 		
 
- 		$num = count ( $pics );
 
- 		
 
- 		return $pics [$num - 1];
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取get或者POST值
 
- 	 * @param string $name 属性名称
 
- 	 * @return fixed 值
 
- 	 */
 
- 	function get_args($name) {
 
- 		if (isset ( $_GET [$name] )) {
 
- 			if (is_array ( $_GET [$name] ))
 
- 				return $_GET [$name];
 
- 			else
 
- 				return addslashes ( $_GET [$name] );
 
- 		} elseif (isset ( $_POST [$name] )) {
 
- 			if (is_array ( $_POST [$name] ))
 
- 				return $_POST [$name];
 
- 			else
 
- 				return addslashes ( $_POST [$name] );
 
- 		} else
 
- 			return false;
 
- 	}
 
- 	function num_to_rmb($num) {
 
- 		$c1 = "零壹贰叁肆伍陆柒捌玖";
 
- 		$c2 = "分角元拾佰仟万拾佰仟亿";
 
- 		// 精确到分后面就不要了,所以只留两个小数位
 
- 		$num = round ( $num, 2 );
 
- 		// 将数字转化为整数
 
- 		$num = $num * 100;
 
- 		if (strlen ( $num ) > 10) {
 
- 			return "金额太大,请检查";
 
- 		}
 
- 		$i = 0;
 
- 		$c = "";
 
- 		while ( 1 ) {
 
- 			if ($i == 0) {
 
- 				// 获取最后一位数字
 
- 				$n = substr ( $num, strlen ( $num ) - 1, 1 );
 
- 			} else {
 
- 				$n = $num % 10;
 
- 			}
 
- 			// 每次将最后一位数字转化为中文
 
- 			$p1 = substr ( $c1, 3 * $n, 3 );
 
- 			$p2 = substr ( $c2, 3 * $i, 3 );
 
- 			
 
- 			if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
 
- 				$c = $p1 . $p2 . $c;
 
- 			} else {
 
- 				$c = $p1 . $c;
 
- 			}
 
- 			$i = $i + 1;
 
- 			// 去掉数字最后一位了
 
- 			
 
- 			$num = $num / 10;
 
- 			// echo $num.'</br>';
 
- 			$num = ( int ) $num;
 
- 			// $num =floor($num);
 
- 			// $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
 
- 			// echo $num.'</br>';
 
- 			// 结束循环
 
- 			if ($num == 0) {
 
- 				break;
 
- 			}
 
- 		}
 
- 		// echo $c.'</br>';
 
- 		$j = 0;
 
- 		$slen = strlen ( $c );
 
- 		while ( $j < $slen ) {
 
- 			// utf8一个汉字相当3个字符
 
- 			$m = substr ( $c, $j, 6 );
 
- 			// 处理数字中很多0的情况,每次循环去掉一个汉字“零”
 
- 			if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
 
- 				$left = substr ( $c, 0, $j );
 
- 				$right = substr ( $c, $j + 3 );
 
- 				$c = $left . $right;
 
- 				$j = $j - 3;
 
- 				$slen = $slen - 3;
 
- 			}
 
- 			$j = $j + 3;
 
- 		}
 
- 		// 这个是为了去掉类似23.0中最后一个“零”字
 
- 		if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
 
- 			$c = substr ( $c, 0, strlen ( $c ) - 3 );
 
- 		}
 
- 		// 将处理的汉字加上“整”
 
- 		if (empty ( $c )) {
 
- 			return "零元整";
 
- 		} else {
 
- 			return $c . "整";
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获得分页数据
 
- 	 * @param unknown_type $table
 
- 	 * @param unknown_type $condition
 
- 	 * @param unknown_type $on_page
 
- 	 * @param unknown_type $page_size
 
- 	 */
 
- 	function get_page($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
 
- 		$page_c = "";
 
- 		$page ['previous'] = $this->get_previous ( $on_page );
 
- 		$page ['on_page'] = $on_page;
 
- 		$total_count = $this->get_table_count ( $sql );
 
- 		$total = intval ( $total_count / $page_size );
 
- 		
 
- 		$page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
 
- 		$page ['total_data'] = $total_count;
 
- 		$page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
 
- 		
 
- 		$i = 1;
 
- 		$page_max = 1;
 
- 		$page_width = 3;
 
- 		
 
- 		if ($on_page >= $page_width) {
 
- 			$page_max = intval ( $on_page / $page_width ) + 1;
 
- 			$i = intval ( $on_page / $page_width ) * $page_width - 1;
 
- 		}
 
- 		
 
- 		for(; $i <= $page ['total_page']; $i ++) {
 
- 			if ($i == $on_page)
 
- 				$page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
 
- 			else
 
- 				$page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
 
- 			
 
- 			if ($i == ($page_width * $page_max))
 
- 				break;
 
- 		}
 
- 		
 
- 		$page ['page'] = $page_c;
 
- 		$page ['lower'] = (-- $on_page) * $page_size;
 
- 		return $page;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取总页数
 
- 	 * @param unknown_type $table
 
- 	 * @param unknown_type $condition
 
- 	 */
 
- 	public function get_table_count($sql="") {
 
- 		// $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
 
- 		$query = Doo::db ()->query ( $sql );
 
- 		$result = $query->fetch ();
 
- 		return $result ['count'];
 
- 	}
 
- 	/**
 
- 	 * 获取上一页
 
- 	 * @param unknown_type $on_page
 
- 	 */
 
- 	function get_previous($on_page = 1) {
 
- 		return $on_page != 0 ? $on_page - 1 : $on_page;
 
- 	}
 
- }
 
- ?>
 
 
  |