';
		if($detail['version']==1){
				
			if(!empty($detail['officeJson'])){
				$officeJson=json_decode($detail['officeJson'],true);
				$html .= '
					
					| 日常相关费用 | 
';
				// 日常相关费用
				$total=0;
				foreach ( $officeJson['daily'] as $key => $value ) {
					if(!empty($value['price'])){
						$html .= '
							
								| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
						$total=bcadd($total,$value ['price'],2);
					}
				}
				$html .= '
				
					| 合计 | ¥' .$total . ' | 
';
				// 其他
				$html .= '
					| 其他 | 
';
				$total=0;
				foreach ( $officeJson['other'] as $key => $value ) {
					if(!empty($value['price'])){
						$html .= '
							
								| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
						$total=bcadd($total,$value ['price'],2);
					}
				}
				$html .= '
				
					| 合计 | ¥' . $total . ' | 
';
			}
			if(!empty($detail['traveJson'])){
				$traveJson=json_decode($detail['traveJson'],true);
				// 差旅
				$html .= '
					| 差旅相关费用 | 
';
				$total=0;
				foreach ( $traveJson['trave'] as $key => $value ) {
					if(!empty($value['price'])){
						$html .= '
							
								| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
						$total=bcadd($total,$value ['price'],2);
					}
				}
				$html .= '
				
					| 合计 | ¥' . $total . ' | 
';
			}
			if(!empty($detail['trainJson'])){
				$trainJson=json_decode($detail['trainJson'],true);
				// 内部培训费用
				$html .= '
					| 内部培训费用 | 
';
				$total=0;
				foreach ( $trainJson['train'] as $key => $value ) {
					if(!empty($value['price'])){
						$html .= '
							
								| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
						$total=bcadd($total,$value ['price'],2);
					}
				}
				$html .= '
				
					| 合计 | ¥' . $total . ' | 
';
			}
				
		}
		return $html;
	}
	
	function getWasteReceiptHtml($detail = array(),$accountType=1) {
		if (empty ( $detail ))
			return '';
		
		$html = '';
		
		
		
		
// 		die;
		if ($detail ['Rtype'] == 0) { // 报销单
			
			if($detail ['version']==1){
				$html .= $this->getReceiptVerson1Html($detail);
			}else{
				
			
			
			$html .= '
						
					
					| 日常相关费用 | 
';
			foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
				$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
			}
			$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . ' | 
';
			
			$html .= '
					| 差旅相关费用 | 
';
			foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
				$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
			}
			$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . ' | 
';
            if(isset($detail ['accountItem'] ['内部培训费用'])){
            $html .= '
					| 内部培训费用 | 
';
            foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
                $html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
            }
            $html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . ' | 
';
            }
			
			$html .= '
					| 其他 | 
';
			foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
				$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
			}
			$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . ' | 
';
			
			}
			
			
			$html .= '
					| 报销金额调整 | 
';
			foreach ( $detail ['reviseDetail'] as $key => $value ) {
				$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
			}
			$html .= '
				
					| 合计 | ¥' . $detail ['revisePrice'] . ' | 
';
			
			$html .= '
				| 产生费用所在办事处 | 
|---|
	  			| ' . $detail ['category'] [0] ['title'] . ' | 
|---|
	  			| 报销说明 | 
|---|
	  						| ' . $detail ['explanation'] . ' | 
	  			
	  			
								| (' . $detail ['receiptOrder'] . ')本次报销费用合计 | ¥' . $detail ['sum'] . ' ' . $detail ['sumCN'] . '
 | 
	  						
					
';
		} elseif ($detail ['Rtype'] == 2) {//对公汇款
			$html .= '
					
						
					
					| 办事处相关费用 | 
';
			foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
				$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
			}
			$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . ' | 
';
			
			$html .= '
				| 产生费用所在办事处 | 
|---|
	  			| ' . $detail ['category'] [0] ['title'] . ' | 
|---|
	  			| 报销说明 | 
|---|
	  						| ' . $detail ['explanation'] . ' | 
			
	  			
								| (' . $detail ['receiptOrder'] . ')本次报销费用合计 | ¥' . $detail ['sum'] . ' ' . $detail ['sumCN'] . '
 | 
	  						
					
';
		} elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
			
			Doo::loadModel ( 'loanReceipt' );
			$loanReceipt = new loanReceipt ();
				
			$loanList = $loanReceipt->getOne ( array (
					'where' => 'rid=' . $detail ['loanRid'],
					'desc' => 'rid',
					'asArray' => true
			) );
			// print_r($loanList);
				
			$loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
				
			$html .= '
						
							
								| 借款费用 | 
';
			foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
				$html .= '
						| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
			}
			$html .= '
								| 产生费用所在办事处 | 
							
								| ' . $detail ['category'] [0] ['title'] . ' | 
							
								| 费用说明 | 
							
								| ' . $loanList ['explanation'] . ' | 
							
								| (' . $loanList ['receiptOrder'] . ')本次费用合计 | ¥' . $loanList ['sum'] . ' ' . $loanList ['sumCN'] . '
 | 
						
					
					';
			
			if ( $accountType==2) {
				
				$balance=$detail ['sum']-$loanList ['sum'];
				$balanceCN=$this->num_to_rmb($balance);
				
				
				if($detail ['version']==1){
					$html .= $this->getReceiptVerson1Html($detail);
				}else{
					
				$html .= '
						
					
					| 日常相关费用 | 
';
				foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
					$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
				}
				$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . ' | 
';
				
				$html .= '
					| 差旅相关费用 | 
';
				foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
					$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
				}
				$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . ' | 
';
                if(isset($detail ['accountItem'] ['内部培训费用'])){
                    $html .= '
					| 内部培训费用 | 
';
                    foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
                        $html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
                    }
                    $html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . ' | 
';
                }
				
				$html .= '
					| 其他 | 
';
				foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
					$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
				}
				$html .= '
				
					| 合计 | ¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . ' | 
';
				
				}
				
				
				$html .= '
					| 报销金额调整 | 
';
				foreach ( $detail ['reviseDetail'] as $key => $value ) {
					$html .= '
				
					| ' . $value ['name'] . ' | ¥' . $value ['price'] . ' | 
';
				}
				$html .= '
				
					| 合计 | ¥' . $detail ['revisePrice'] . ' | 
';
				
				$html .= '
				| 产生费用所在办事处 | 
|---|
	  			| ' . $detail ['category'] [0] ['title'] . ' | 
|---|
	  			| 报销说明 | 
|---|
	  						| ' . $detail ['explanation'] . ' | 
		
	  			
								| (' . $detail ['receiptOrder'] . ')本次报销费用合计 | ¥' . $detail ['sum'] . ' ' . $detail ['sumCN'] . '
 | 
				
                                | 借款结余 | ¥'.$balance.' '.$balanceCN.'
 | 
						
										
										
	  						
					
';
			}
			
		}
		
		return $html;
	}
	
	/**
	 * 计算流水
	 */
	function getWasteBookStatistics($waste = array(), $inComeStatistics) {
		$bakWaste ['bank'] = array (
				'CGBDeposit' => 0,
				'ICBCDeposit' => 0,
				'HUADeposit' => 0,
				'PersonalDeposit' => 0 
		);
		
		$bakWaste ['financial'] = array (
				'current' => array (
						'CGBDeposit' => 0,
						'ICBCDeposit' => 0 
				),
				'fixed' => array (
						'CGBDeposit' => 0,
						'ICBCDeposit' => 0 
				) 
		);
		
		// 存款
		foreach ( $waste ['bank'] as $key => $value ) {
			// 收入
			foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
				// 广发
				if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
					$waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
				}
				// 工商
				if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
					$waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
				}
				// 华润
				if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
					$waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
				}
				// 个人
				if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
					$waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
				}
			}
		}
		
		foreach ( $waste ['bank'] as $key => $value ) {
			// 支出
			foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
				// 广发
				if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
					
					$waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
				}
				// 工商
				if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
					$waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
				}
				// 华润
				if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
					$waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
				}
				// 个人
				if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
					$waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
				}
			}
		}
		
		// 活期
		foreach ( $waste ['financial'] ['current'] as $key => $value ) {
			foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
				// 广发
				if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
					$waste ['financial'] ['current'] ['CGBDeposit'] = $value  + $v ['accountPrice'];
				}
				// 工商
				if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
					$waste ['financial'] ['current'] ['ICBCDeposit'] = $value  + $v ['accountPrice'];
				}
				// 个人
				if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
					$waste ['bank'] ['PersonalDeposit'] = $value  + $v ['accountPrice'];
				}
			}
		}
		// print_r($inComeStatistics ['fixedStatistics']);
		// 固期
		foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
			foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
				// 广发
				if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
					$waste ['financial'] ['fixed'] ['CGBDeposit'] = $value  + $v ['accountPrice'];
				}
				// 工商---已经转变成个人理财固定代表含义
				if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
					$waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value  + $v ['accountPrice'];
				}
				// 个人
				if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
					$waste ['bank'] ['PersonalDeposit'] = $value  + $v ['accountPrice'];
				}
			}
		}
		
		$waste ['bank'] ['ICBCDeposit'] = sprintf("%.2f", $waste ['bank'] ['ICBCDeposit']);
		
		return $waste;
	}
	function lyt() {
		Doo::loadModel ( "receiptDetail" );
		$receiptDetail = new receiptDetail ();
		$receiptCollectList = $receiptDetail->find ( array (
				'where' => 'status=1 ',
				'asArray' => true 
		) );
		
		foreach ( $receiptCollectList as $key => $value ) {
			$receiptDetail = new receiptDetail ();
			
			$receiptDetail->pastDate = $value ['date'];
			
			$receiptDetail->update ( array (
					'where' => "rdid= '" . $value ['rdid'] . "'" 
			) );
		}
	}
	function staffCollectMonthDetail() {
        //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
		if (! $year)
			$year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
		if (! $month)
			$month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
		
		$nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
		if (! $nature){
				$nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
		}
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( "receiptDetail" );
		$receiptDetail = new receiptDetail ();
		Doo::loadModel ( 'accountItem' );
		$accountItem = new accountItem ();
		Doo::loadModel ( 'statistics' );
		$statistics = new statistics ();
		Doo::loadModel ( "receiptAuthorityManage" );
		$receiptAuthorityManage = new receiptAuthorityManage ();
        $aiList=$accountItem->getAccountItem();
		$imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
		$cidList = array ();
		foreach ( $imcStaff as $key => $value ) {
			array_push ( $cidList, $value ['cid'] );
		}
		$cidString = implode ( ',', $cidList );
		$naturecon='';
		if ($nature=='ONJOB'){
			$naturecon=' and (nature!=4 )';
		}elseif($nature=='LEAVEJOB'){
			$naturecon=' and (nature=4 )';
		}else{
			die ( 'illegal request--nature' );
		}
		
		$staffList = $staff->find ( array (
				'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
				'asArray' => true 
		) );
		$categoryList = $staff->find ( array (
				'select' => 'COUNT(*) as count,cid,category',
				'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
				'groupby' => 'cid',
				'asArray' => true 
		) );
		
		$list = array ();
        foreach($aiList as $key=>$value){
            foreach ($value as $v){
                $subtotal[$key][$v['name']]=0;
            }
        }
		foreach ( $categoryList as $vlu ) {
			$s1 = 0;
			$m1 = 0;
            $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
			foreach ( $staffList as $value ) {
				if ($vlu ['cid'] == $value ['cid']) {
					// pastDate
					$receiptCollectList = $receiptDetail->find ( array (
							'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
							'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
							'groupby' => 'item,Month(pastDate),itemCategory',
							'asArray' => true 
					) );
					if (! empty ( $receiptCollectList )) {
						
						$receiptL = array (
								'日常相关费用' => array (),
								'差旅相关费用' => array (),
                                '内部培训费用' => array (),
								'培训班费用' => array (),
								'其他' => array () 
						);
						
						$html = "";
						$psum = 0;
						foreach ( $aiList[$this->AGENCY] as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '日常相关费用') {
									if ($v ['item'] == $va['name']) {
                                        $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
										$psum += $v ['price'];
										$html .= '' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
                        $subtotal[$this->AGENCY]['AGENCY'] += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['日常相关费用'] = $psum . $html;
						
						/* ----------------------------------- */
						$html = "";
						$psum = 0;
						foreach ( $aiList[$this->TRAVEL] as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '差旅相关费用') {
									if ($v ['item'] == $va['name']) {
                                        $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
                        $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['差旅相关费用'] = $psum . $html;
						/* ------------------------------------- */
                        $html = "";
                        $psum = 0;
                        foreach ( $aiList[$this->INTTRAIN] as $va ) {
                            $falg = true;
                            foreach ( $receiptCollectList as $v ) {
                                if ($v ['itemCategory'] == '内部培训费用') {
                                    if ($v ['item'] == $va['name']) {
                                        $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
                                        $psum += $v ['price'];
                                        $html .= ' | ' . $v ['price'] . '';
                                        $falg = false;
                                        break;
                                    }
                                }
                            }
                            if ($falg)
                                $html .= ' | -';
                        }
                        $subtotal[$this->INTTRAIN]['INTTRAIN']  += $psum;
                        if (! empty ( $psum ))
                            $psum = ' | ¥' . $psum . '';
                        else
                            $psum = ' | -';
                        $receiptL ['内部培训费用'] = $psum . $html;
                        /* ----------------------------------- */
						$html = "";
						$psum = 0;
						foreach ( $aiList[$this->TRAIN] as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '培训班费用') {
									
									if ($v ['item'] == $va['name']) {
                                        $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
                        $subtotal[$this->TRAIN]['TRAIN'] += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['培训班费用'] = $psum . $html;
						
						/* ------------------------------------- */
						$html = "";
						$psum = 0;
						foreach ( $aiList[$this->OTHER] as $va ) {
							
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								
								if ($v ['itemCategory'] == '其他') {
									if (trim ( $v ['item'] ) == $va['name']) {
                                        $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
                        $subtotal[$this->OTHER]['OTHER'] += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['其他'] = $psum . $html;
						
						/* ------------------------------------- */
						$html = "";
						$psum = 0;
						foreach ( $receiptCollectList as $v ) {
							if ($v ['itemCategory'] == '报销金额调整') {
								
								if (! empty ( $v ['price'] )) {
									$psum += $v ['price'];
								}
							}
						}
						$s1 += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['报销金额调整'] = $psum . $html;
					} else {
                        $receiptL [$this->AGENCY] =' | -';
                        foreach ( $aiList[$this->AGENCY] as $va ) {
                            $receiptL [$this->AGENCY] .=' | -';
                        }
                        $receiptL [$this->TRAVEL] =' | -';
                        foreach ( $aiList[$this->TRAVEL] as $va ) {
                            $receiptL [$this->TRAVEL] .=' | -';
                        }
                        $receiptL [$this->INTTRAIN] =' | -';
                        foreach ( $aiList[$this->INTTRAIN] as $va ) {
                            $receiptL [$this->INTTRAIN] .=' | -';
                        }
                        $receiptL [$this->TRAIN] =' | -';
                        foreach ( $aiList[$this->TRAIN] as $va ) {
                            $receiptL [$this->TRAIN] .=' | -';
                        }
                        $receiptL [$this->OTHER] =' | -';
                        foreach ( $aiList[$this->OTHER] as $va ) {
                            $receiptL [$this->OTHER] .=' | -';
                        }
                        $receiptL ['报销金额调整'] = ' | -';
					}
					
					$monthStaffPrice = $receiptDetail->find ( array (
							'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
							'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
							'groupby' => 'Month(pastDate)',
							'asArray' => true 
					) );
					// echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
					if (! empty ( $monthStaffPrice [0] ['price'] )) {
						$m1 += $monthStaffPrice [0] ['price'];
						$receiptL ['monthStaffPrice'] = ' | ¥' . $monthStaffPrice [0] ['price'] . '';
					} else
						$receiptL ['monthStaffPrice'] = ' | -';
					
					$receiptL ['usernameEn'] = urlencode ( $value ['username'] );
					$list [$value ['username']] = $receiptL;
				}
			}
            $receiptL [$this->AGENCY] =' | '.$subtotal[$this->AGENCY]['AGENCY'].'';
            foreach ( $aiList[$this->AGENCY] as $va ) {
                $receiptL [$this->AGENCY] .=' | ' . $subtotal[$this->AGENCY][$va['name']] . '';
                $subtotal[$this->AGENCY][$va['name']]=0;
            }
            $receiptL [$this->TRAVEL] =' | '.$subtotal[$this->TRAVEL]['TRAVEL'].'';
            foreach ( $aiList[$this->TRAVEL] as $va ) {
                $receiptL [$this->TRAVEL] .=' | ' . $subtotal[$this->TRAVEL][$va['name']] . '';
                $subtotal[$this->TRAVEL][$va['name']]=0;
            }
            $receiptL [$this->INTTRAIN] =' | '.$subtotal[$this->INTTRAIN]['INTTRAIN'].'';
            foreach ( $aiList[$this->INTTRAIN] as $va ) {
                $receiptL [$this->INTTRAIN] .=' | ' . $subtotal[$this->INTTRAIN][$va['name']] . '';
                $subtotal[$this->INTTRAIN][$va['name']]=0;
            }
            $receiptL [$this->TRAIN] =' | '.$subtotal[$this->TRAIN]['TRAIN'].'';
            foreach ( $aiList[$this->TRAIN] as $va ) {
                $receiptL [$this->TRAIN] .=' | ' . $subtotal[$this->TRAIN][$va['name']] . '';
                $subtotal[$this->TRAIN][$va['name']]=0;
            }
            $receiptL [$this->OTHER] =' | '.$subtotal[$this->OTHER]['OTHER'].'';
            foreach ( $aiList[$this->OTHER] as $va ) {
                $receiptL [$this->OTHER] .=' | ' . $subtotal[$this->OTHER][$va['name']] . '';
                $subtotal[$this->OTHER][$va['name']]=0;
            }
			$receiptL ['报销金额调整'] = ' | ' . $s1 . '';
			$receiptL ['monthStaffPrice'] = ' | ¥' . $m1 . '';
            $receiptL ['usernameEn'] =false;
			$list ['' . $vlu ['category'] . '小计'] = $receiptL;
		}
		$data ['list'] = $list;
		// print_r($list);
		$receiptCollectList = $receiptDetail->find ( array (
				'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
				'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
				'groupby' => 'item,Month(pastDate),itemCategory',
				'asArray' => true 
		) );
		
		$data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
		
		// statistics html
		$stList = $statistics->getOne ( array (
				'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
				'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
				'groupby' => 'Month(date)',
				'asArray' => true 
		) );
		if (empty ( $stList ))
			$stList = array (
					'rePrice' => 0,
					'agPrice' => 0 
			);
		$data ['stList'] = array (
				'rePrice' => $stList ['rePrice'],
				'agPrice' => $stList ['agPrice'],
				'skPrice' => ($stList ['rePrice'] - $stList ['agPrice']) 
		);
		
		$monthHtml = "";
		for($i = 1; $i <= 12; $i ++) {
			if ($i == $month)
				$monthHtml .= '';
			else
				$monthHtml .= '';
		}
		
		$data ['monthHtml'] = $monthHtml;
		$data ['year'] = $year;
		$data ['month'] = $month;
		$data ['nature'] = $nature;
        $data ['aiList'] = $aiList;
		
		$data ['memu'] = "receipt";
		$data ['staff'] = $this->staff;
		$data ['receiptMemu'] = 'companyCategoryCollect';
		$data ['verifyId'] = $this->verifyId;
		$data ['executeId'] = $this->executeId;
		$this->render ( "/admin/staffCollectMonthDetail", $data );
		// $this->render ( "/admin/saeaStaffCollectDetail", $data );
	}
	function staffCollectMonthDetail2() {
		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
		if (! $year)
			$year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
		if (! $month)
			$month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
		
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( "receiptDetail" );
		$receiptDetail = new receiptDetail ();
		Doo::loadModel ( 'accountItem' );
		$accountItem = new accountItem ();
		Doo::loadModel ( 'statistics' );
		$statistics = new statistics ();
		Doo::loadModel ( 'L_category' );
		$lCategory = new L_category ();
		
		$staffList = $staff->find ( array (
				'where' => 'username!="admin"',
				'asArray' => true 
		) );
		$categoryList = $staff->find ( array (
				'select' => 'COUNT(*) as count,cid,category',
				'where' => 'username !="admin"',
				'groupby' => 'cid',
				'asArray' => true 
		) );
		
		$list = array ();
		foreach ( $categoryList as $vlu ) {
			// $html=' | '.$v['category'].'';
			$r1 = 0;
			$r2 = 0;
			$r3 = 0;
			$r4 = 0;
			$r5 = 0;
			$r6 = 0;
			$r7 = 0;
			$r8 = 0;
			$r9 = 0;
			$r10 = 0;
			$r11 = 0;
			$r12 = 0;
			$r13 = 0;
			$r14 = 0;
			$r15 = 0;
			$c1 = 0;
			$c2 = 0;
			$c3 = 0;
			$c4 = 0;
			$c5 = 0;
			$c6 = 0;
			$p1 = 0;
			$p2 = 0;
			$p3 = 0;
			$p4 = 0;
			$p5 = 0;
			$p6 = 0;
			$p7 = 0;
			$p8 = 0;
			$p9 = 0;
			$t1 = 0;
			$t2 = 0;
			$t3 = 0;
			$t4 = 0;
			$t5 = 0;
			$s1 = 0;
			$m1 = 0;
			foreach ( $staffList as $value ) {
				if ($vlu ['cid'] == $value ['cid']) {
					
					$receiptCollectList = $receiptDetail->find ( array (
							'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
							'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
							'groupby' => 'item,Month(date),itemCategory',
							'asArray' => true 
					) );
					
					if (! empty ( $receiptCollectList )) {
						
						$receiptL = array (
								'日常相关费用' => array (),
								'差旅相关费用' => array (),
								'培训班费用' => array (),
								'其他' => array () 
						);
						
						$html = "";
						$psum = 0;
						$item = array (
								'市内交通费',
								'市内出租费',
								'办事处房租',
								'电话费',
								'水费',
								'电费',
								'办公费用',
								'邮寄费',
								'其他费用',
								'车辆费用',
								'广告费',
								'团队建设费',
								'物业管理费',
								'宽带费' 
						);
						foreach ( $item as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '日常相关费用') {
									
									if ($v ['item'] == $va) {
										if ($va == '市内交通费')
											$r1 += $v ['price'];
										if ($va == '市内出租费')
											$r2 += $v ['price'];
										if ($va == '办事处房租')
											$r3 += $v ['price'];
										if ($va == '电话费')
											$r4 += $v ['price'];
										if ($va == '水费')
											$r5 += $v ['price'];
										if ($va == '电费')
											$r6 += $v ['price'];
										if ($va == '办公费用')
											$r7 += $v ['price'];
										if ($va == '邮寄费')
											$r8 += $v ['price'];
										if ($va == '其他费用')
											$r9 += $v ['price'];
										if ($va == '车辆费用')
											$r10 += $v ['price'];
										if ($va == '广告费')
											$r11 += $v ['price'];
										if ($va == '团队建设费')
											$r13 += $v ['price'];
										if ($va == '物业管理费')
											$r14 += $v ['price'];
										if ($va == '宽带费')
											$r15 += $v ['price'];
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
						
						$r12 += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['日常相关费用'] = $psum . $html;
						
						/* ----------------------------------- */
						
						$html = "";
						$psum = 0;
						$item = array (
								'往来交通费',
								'市内交通费',
								'出差住宿费',
								'出差补助',
								'其他费用' 
						);
						foreach ( $item as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '差旅相关费用') {
									
									if ($v ['item'] == $va) {
										if ($va == '往来交通费')
											$c1 += $v ['price'];
										if ($va == '市内交通费')
											$c2 += $v ['price'];
										if ($va == '出差住宿费')
											$c3 += $v ['price'];
										if ($va == '出差补助')
											$c4 += $v ['price'];
										if ($va == '其他费用')
											$c5 += $v ['price'];
										
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
						$c6 += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['差旅相关费用'] = $psum . $html;
						/* ------------------------------------- */
						$html = "";
						$psum = 0;
						$item = array (
								'场租费',
								'薪酬',
								'住宿费',
								'交通费',
								'餐饮费',
								'办公费',
								'公关费',
								'其他' 
						);
						foreach ( $item as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '培训班费用') {
									
									if ($v ['item'] == $va) {
										
										if ($va == '场租费')
											$p1 += $v ['price'];
										if ($va == '薪酬')
											$p2 += $v ['price'];
										if ($va == '住宿费')
											$p3 += $v ['price'];
										if ($va == '交通费')
											$p4 += $v ['price'];
										if ($va == '餐饮费')
											$p5 += $v ['price'];
										if ($va == '办公费')
											$p6 += $v ['price'];
										if ($va == '公关费')
											$p7 += $v ['price'];
										if ($va == '其他')
											$p8 += $v ['price'];
										
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
						$p9 += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['培训班费用'] = $psum . $html;
						
						/* ------------------------------------- */
						$html = "";
						$psum = 0;
						$item = array (
								'公关费',
								'广告费',
								'借款',
								'可自加费用' 
						);
						foreach ( $item as $va ) {
							$falg = true;
							foreach ( $receiptCollectList as $v ) {
								if ($v ['itemCategory'] == '其他') {
									
									if ($v ['item'] == $va) {
										if ($va == '公关费')
											$t1 += $v ['price'];
										if ($va == '广告费')
											$t2 += $v ['price'];
										if ($va == '借款')
											$t3 += $v ['price'];
										if ($va == '可自加费用')
											$t4 += $v ['price'];
										$psum += $v ['price'];
										$html .= ' | ' . $v ['price'] . '';
										$falg = false;
										break;
									}
								}
							}
							if ($falg)
								$html .= ' | -';
						}
						$t5 += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['其他'] = $psum . $html;
						
						/* ------------------------------------- */
						$html = "";
						$psum = 0;
						foreach ( $receiptCollectList as $v ) {
							if ($v ['itemCategory'] == '报销金额调整') {
								
								if (! empty ( $v ['price'] )) {
									$psum += $v ['price'];
								}
							}
						}
						$s1 += $psum;
						if (! empty ( $psum ))
							$psum = ' | ¥' . $psum . '';
						else
							$psum = ' | -';
						$receiptL ['报销金额调整'] = $psum . $html;
					} else {
						$receiptL ['日常相关费用'] = ' | - | - | - | - | - | - | - | - | - | - | - | - | -';
						$receiptL ['差旅相关费用'] = ' | - | - | - | - | - | -';
						$receiptL ['培训班费用'] = ' | - | - | - | - | - | - | - | - | -';
						$receiptL ['其他'] = ' | - | - | - | - | -';
						$receiptL ['报销金额调整'] = ' | -';
					}
					
					$monthStaffPrice = $receiptDetail->find ( array (
							'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
							'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
							'asArray' => true 
					) );
					
					if (! empty ( $monthStaffPrice [0] ['price'] )) {
						$m1 += $monthStaffPrice [0] ['price'];
						$receiptL ['monthStaffPrice'] = ' | ¥' . $monthStaffPrice [0] ['price'] . '';
					} else
						$receiptL ['monthStaffPrice'] = ' | -';
					$list [$value ['username']] = $receiptL;
				}
			}
			$receiptL ['日常相关费用'] = ' | ' . $r12 . ' | ' . $r1 . ' | ' . $r2 . ' | ' . $r3 . ' | ' . $r4 . ' | ' . $r5 . ' | ' . $r6 . ' | ' . $r7 . ' | ' . $r8 . ' | ' . $r9 . ' | ' . $r10 . ' | ' . $r11 . ' | ' . $r13 . ' | ' . $r14 . ' | ' . $r15 . '';
			$receiptL ['差旅相关费用'] = ' | ' . $c6 . ' | ' . $c1 . ' | ' . $c2 . ' | ' . $c3 . ' | ' . $c4 . ' | ' . $c5 . '';
			$receiptL ['培训班费用'] = ' | ' . $p9 . ' | ' . $p1 . ' | ' . $p2 . ' | ' . $p3 . ' | ' . $p4 . ' | ' . $p5 . ' | ' . $p6 . ' | ' . $p7 . ' | ' . $p8 . '';
			$receiptL ['其他'] = ' | ' . $t5 . ' | ' . $t1 . ' | ' . $t2 . ' | ' . $t3 . ' | ' . $t4 . '';
			$receiptL ['报销金额调整'] = ' | ' . $s1 . '';
			$receiptL ['monthStaffPrice'] = ' | ¥' . $m1 . '';
			$list ['' . $vlu ['category'] . '小计'] = $receiptL;
		}
		$data ['list'] = $list;
		
		$receiptCollectList = $receiptDetail->find ( array (
				'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
				'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
				'groupby' => 'item,Month(date),itemCategory',
				'asArray' => true 
		) );
		
		$data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
		
		// statistics html
		$stList = $statistics->getOne ( array (
				'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
				'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
				'groupby' => 'Month(date)',
				'asArray' => true 
		) );
		if (empty ( $stList ))
			$stList = array (
					'rePrice' => 0,
					'agPrice' => 0 
			);
		$data ['stList'] = array (
				'rePrice' => $stList ['rePrice'],
				'agPrice' => $stList ['agPrice'],
				'skPrice' => ($stList ['rePrice'] - $stList ['agPrice']) 
		);
		
		$monthHtml = "";
		for($i = 1; $i <= 12; $i ++) {
			if ($i == $month)
				$monthHtml .= '';
			else
				$monthHtml .= '';
		}
		
		$data ['monthHtml'] = $monthHtml;
		$data ['year'] = $year;
		$data ['month'] = $month;
		
		$data ['memu'] = "receipt";
		$data ['staff'] = $this->staff;
		$data ['receiptMemu'] = 'companyCategoryCollect';
		$data ['verifyId'] = $this->verifyId;
		$data ['executeId'] = $this->executeId;
		$this->render ( "/admin/staffCollectMonthDetail2", $data );
		// $this->render ( "/admin/saeaStaffCollectDetail", $data );
	}
	
	/**
	 * 用户报销单列表
	 */
	function receiptStatisticsStaffDetail() {
		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
		$username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
		
		Doo::loadModel ( "receipt" );
		$receipt = new receipt ();
		Doo::loadModel ( "receiptDetail" );
		$receiptDetail = new receiptDetail ();
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( 'accountItem' );
		$accountItem = new accountItem ();
		Doo::loadModel ( 'statistics' );
		$statistics = new statistics ();
		
		if (! empty ( $username )) {
			$username = addslashes ( urldecode ( $username ) );
			
			$staffDetail = $staff->getStaffByName ( $username );
			if (empty ( $staffDetail ))
				die ( 'illegal request' );
			
			$list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
			$itemList = $accountItem->getAccountItem ();
			$itemHtml = '';
			$categoryHtml = '';
			$itemKeyList = array_keys ( $itemList );
			$revisePrice = 0;
			// 报销单内容详情
			foreach ( $list as $key => $value ) {
				$accountItemList = json_decode ( $value ['accountItem'], true );
				$list [$key] ['accountItemList'] = $accountItemList;
				$receiptItemHtml = '';
				foreach ( $itemKeyList as $v ) {
					if ($v == '日常相关费用')
						$receiptItemHtml .= ' | ' . $accountItemList ['cSum'] ['agencySum'] . '';
					elseif ($v == '差旅相关费用')
						$receiptItemHtml .= ' | ' . $accountItemList ['cSum'] ['travelSum'] . '';
					elseif ($v == '培训班费用')
						$receiptItemHtml .= ' | ' . $accountItemList ['cSum'] ['trainSum'] . '';
                    elseif ($v == '内部培训费用'){
                        if (isset($accountItemList ['cSum'] ['inttrainSum'])){
                            $receiptItemHtml .= ' | ' . $accountItemList ['cSum'] ['inttrainSum'] . '';
                        }else{
                            $receiptItemHtml .= ' | 0';
                        }
                    }elseif ($v == '其他')
						$receiptItemHtml .= ' | ' . $accountItemList ['cSum'] ['otherSum'] . '';
					
					foreach ( $itemList [$v] as $ke => $va ) {
						$falg = true;
						if (! empty ( $accountItemList [$v] )) {
							foreach ( $accountItemList [$v] as $ve ) {
								if ($va ['name'] == $ve ['name']) {
									$receiptItemHtml .= ' | ' . $ve ['price'] . '';
									$falg = false;
									break;
								}
							}
						}
						if ($falg)
							$receiptItemHtml .= ' | ';
					}
				}
				// 金额调整和费用查看
				$revisePrice += $value ['revisePrice'];
				$receiptItemHtml .= ' | ' . $value ['revisePrice'] . '';
				$receiptItemHtml .= ' | 查看';
				$list [$key] ['receiptItemHtml'] = $receiptItemHtml;
			}
			
			// 报销单合计
			$receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
			$rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
			
			$receiptTotalHtml = '';
			// 报销单项目抬头
			foreach ( $itemKeyList as $value ) {
				$count = count ( $itemList [$value] ) + 1;
				$itemHtml .= ' | ' . $value . '';
				$categoryHtml .= ' | 合计';
				$sumfalg=true;
				foreach ( $rtl as $rtlValue ) {
					if ($rtlValue ['itemCategory'] == $value) {
						$receiptTotalHtml .= ' | ' . $rtlValue ['price'] . '';
						$sumfalg=false;
						break;
					}
				}
				if ($sumfalg)
					$receiptTotalHtml .= ' | ';
				
				foreach ( $itemList [$value] as $k => $v ) {
					$categoryHtml .= ' | ' . $v ['name'] . '';
					// 合计
					$falg = true;
					foreach ( $receiptTotalList as $ve ) {
						if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
							$receiptTotalHtml .= ' | ' . $ve ['price'] . '';
							$falg = false;
							break;
						}
					}
					if ($falg)
						$receiptTotalHtml .= ' | ';
				}
			}
			$receiptTotalHtml .= ' | ' . $revisePrice . '';
			
			$stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
			if (empty ( $stList ))
				$stList = array (
						'rePrice' => 0,
						'agPrice' => 0 
				);
			$data ['stList'] = array (
					'rePrice' => $stList ['rePrice'],
					'agPrice' => $stList ['agPrice'],
					'skPrice' => ($stList ['rePrice'] - $stList ['agPrice']) 
			);
			
			$monthHtml = "";
			for($i = 1; $i <= 12; $i ++) {
				if ($i == $month)
					$monthHtml .= '';
				else
					$monthHtml .= '';
			}
			
			$data ['username'] = urlencode ( $username );
			$data ['usernameEN'] = $username;
			$data ['monthHtml'] = $monthHtml;
			$data ['receiptTotalHtml'] = $receiptTotalHtml;
			$data ['list'] = $list;
			$data ['categoryHtml'] = $categoryHtml;
			$data ['itemHtml'] = $itemHtml;
			$data ['itemList'] = $itemList;
			$data ['year'] = $year;
			$data ['month'] = $month;
			
			$data ['memu'] = "receipt";
			$data ['staff'] = $this->staff;
			$data ['receiptMemu'] = 'companyCategoryCollect';
			$data ['verifyId'] = $this->verifyId;
			$data ['executeId'] = $this->executeId;
			$this->render ( "/admin/receiptStatisticsStaffDetail", $data );
		}
		die ( 'illegal request' );
	}
	function companyMonthCollectDetail() {
		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
		if (! $year)
			$year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
		if (! $month)
			$month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
		
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( "receiptDetail" );
		$receiptDetail = new receiptDetail ();
		Doo::loadModel ( 'accountItem' );
		$accountItem = new accountItem ();
		Doo::loadModel ( 'statistics' );
		$statistics = new statistics ();
		Doo::loadModel ( 'L_category' );
		$lCategory = new L_category ();
		
		$staffList = $staff->find ( array (
				'where' => 'username!="admin"',
				'asArray' => true 
		) );
		
		$categoryList = $lCategory->find ( array (
				'asArray' => true 
		) );
        $aiList=$accountItem->getAccountItem();
		$list = array ();
		foreach ( $categoryList as $value ) {
			$receiptCollectList = $receiptDetail->find ( array (
					'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
					'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
					'groupby' => 'item,Month(pastDate),itemCategory',
					'asArray' => true 
			) );
			
			if (! empty ( $receiptCollectList )) {
				
				$receiptL = array (
						'日常相关费用' => array (),
						'差旅相关费用' => array (),
                    '内部培训费用' => array (),
						'培训班费用' => array (),
						'其他' => array () 
				);
				
				$html = "";
				$psum = 0;
				foreach ( $aiList[$this->AGENCY] as $va ) {
					$falg = true;
					foreach ( $receiptCollectList as $v ) {
						if ($v ['itemCategory'] == $this->AGENCY) {
							
							if ($v ['item'] == $va['name']) {
								$psum += $v ['price'];
								$html .= ' | ' . $v ['price'] . '';
								$falg = false;
								break;
							}
						}
					}
					if ($falg)
						$html .= ' | -';
				}
				
				if (! empty ( $psum ))
					$psum = ' | ' . $psum . '';
				else
					$psum = ' | -';
				$receiptL [$this->AGENCY] = $psum . $html;
				
				/* ----------------------------------- */
				
				$html = "";
				$psum = 0;
				foreach (  $aiList[$this->TRAVEL] as $va ) {
					$falg = true;
					foreach ( $receiptCollectList as $v ) {
						if ($v ['itemCategory'] == $this->TRAVEL) {
							
							if ($v ['item'] == $va['name']) {
								$psum += $v ['price'];
								$html .= ' | ' . $v ['price'] . '';
								$falg = false;
								break;
							}
						}
					}
					if ($falg)
						$html .= ' | -';
				}
				if (! empty ( $psum ))
					$psum = ' | ' . $psum . '';
				else
					$psum = ' | -';
				$receiptL [$this->TRAVEL] = $psum . $html;
                /* ------------------------------------- */
                $html = "";
                $psum = 0;
                foreach ( $aiList[$this->INTTRAIN] as $va ) {
                    $falg = true;
                    foreach ( $receiptCollectList as $v ) {
                        if ($v ['itemCategory'] == $this->INTTRAIN) {
                            if ($v ['item'] == $va['name']) {
                                $psum += $v ['price'];
                                $html .= ' | ' . $v ['price'] . '';
                                $falg = false;
                                break;
                            }
                        }
                    }
                    if ($falg)
                        $html .= ' | -';
                }
                if (! empty ( $psum ))
                    $psum = ' | ' . $psum . '';
                else
                    $psum = ' | -';
                $receiptL [$this->INTTRAIN] = $psum . $html;
				/* ------------------------------------- */
				$html = "";
				$psum = 0;
				foreach ( $aiList[$this->TRAIN] as $va ) {
					$falg = true;
					foreach ( $receiptCollectList as $v ) {
						if ($v ['itemCategory'] == $this->TRAIN) {
							
							if ($v ['item'] == $va['name']) {
								$psum += $v ['price'];
								$html .= ' | ' . $v ['price'] . '';
								$falg = false;
								break;
							}
						}
					}
					if ($falg)
						$html .= ' | -';
				}
				if (! empty ( $psum ))
					$psum = ' | ' . $psum . '';
				else
					$psum = ' | -';
				$receiptL [$this->TRAIN] = $psum . $html;
				
				/* ------------------------------------- */
				$html = "";
				$psum = 0;
				foreach ( $aiList[$this->OTHER] as $va ) {
					$falg = true;
					foreach ( $receiptCollectList as $v ) {
						if ($v ['itemCategory'] == $this->OTHER) {
							
							if ($v ['item'] == $va['name']) {
								$psum += $v ['price'];
								$html .= ' | ' . $v ['price'] . '';
								$falg = false;
								break;
							}
						}
					}
					if ($falg)
						$html .= ' | -';
				}
				if (! empty ( $psum ))
					$psum = ' | ' . $psum . '';
				else
					$psum = ' | -';
				$receiptL [$this->OTHER] = $psum . $html;
				
				/* ------------------------------------- */
				$html = "";
				$psum = 0;
				foreach ( $receiptCollectList as $v ) {
					if ($v ['itemCategory'] == '报销金额调整') {
						
						if (! empty ( $v ['price'] ))
							$psum += $v ['price'];
					}
				}
				
				if (! empty ( $psum ))
					$psum = ' | ' . $psum . '';
				else
					$psum = ' | -';
				$receiptL ['报销金额调整'] = $psum . $html;
			} else {
                $receiptL [$this->AGENCY] =' | -';
                foreach ( $aiList[$this->AGENCY] as $va ) {
                    $receiptL [$this->AGENCY] .=' | -';
                }
                $receiptL [$this->TRAVEL] =' | -';
                foreach ( $aiList[$this->TRAVEL] as $va ) {
                    $receiptL [$this->TRAVEL] .=' | -';
                }
                $receiptL [$this->INTTRAIN] =' | -';
                foreach ( $aiList[$this->INTTRAIN] as $va ) {
                    $receiptL [$this->INTTRAIN] .=' | -';
                }
                $receiptL [$this->TRAIN] =' | -';
                foreach ( $aiList[$this->TRAIN] as $va ) {
                    $receiptL [$this->TRAIN] .=' | -';
                }
                $receiptL [$this->OTHER] =' | -';
                foreach ( $aiList[$this->OTHER] as $va ) {
                    $receiptL [$this->OTHER] .=' | -';
                }
				$receiptL ['报销金额调整'] = ' | -';
			}
			
			$monthStaffPrice = $receiptDetail->find ( array (
					'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
					'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
					'asArray' => true 
			) );
			
			if (! empty ( $monthStaffPrice [0] ['price'] ))
				$receiptL ['monthStaffPrice'] = ' | ' . $monthStaffPrice [0] ['price'] . '';
			else
				$receiptL ['monthStaffPrice'] = ' | -';
			$list [$value ['title']] = $receiptL;
		}
		
		$data ['list'] = $list;
		
		$receiptCollectList = $receiptDetail->find ( array (
				'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
				'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
				'groupby' => 'item,Month(pastDate),itemCategory',
				'asArray' => true 
		) );
		
		$data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
		
		 //print_r($data['monthPriceHtml']);
		// foreach ($data['monthPriceHtml'] as $value){
		// echo $value;
		// }
		// die;
		// statistics html
		$stList = $statistics->getOne ( array (
				'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
				'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
				'groupby' => 'Month(date)',
				'asArray' => true 
		) );
		if (empty ( $stList ))
			$stList = array (
					'rePrice' => 0,
					'agPrice' => 0 
			);
		$data ['stList'] = array (
				'rePrice' => $stList ['rePrice'],
				'agPrice' => $stList ['agPrice'],
				'skPrice' => ($stList ['rePrice'] - $stList ['agPrice']) 
		);
		
		$monthHtml = "";
		for($i = 1; $i <= 12; $i ++) {
			if ($i == $month)
				$monthHtml .= '';
			else
				$monthHtml .= '';
		}
        $data ['aiList'] = $aiList;
        
        $dateHtml = "";
        $now = date ( "Y" );
        for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
        		
        	if ($YEARD <= $now) {
        		$dateHtml .= '';
        	}
        }
        
        $data ['dateHtml'] = $dateHtml;
		$data ['monthHtml'] = $monthHtml;
		$data ['year'] = $year;
		$data ['month'] = $month;
		
		$data ['memu'] = "receipt";
		$data ['staff'] = $this->staff;
		$data ['receiptMemu'] = 'companyCategoryCollect';
		$data ['verifyId'] = $this->verifyId;
		$data ['executeId'] = $this->executeId;
		
		$this->render ( "/admin/companyMonthCollectDetail", $data );
	}
	function staffCollectDetail() {
		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
		$staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
		$pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
		if (! $staffname) {
			$staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
			$staffname = urldecode ( $staffname );
		}
		
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( "receiptDetail" );
		$receiptDetail = new receiptDetail ();
		Doo::loadModel ( 'accountItem' );
		$accountItem = new accountItem ();
		Doo::loadModel ( 'statistics' );
		$statistics = new statistics ();
		Doo::loadModel ( 'L_category' );
		$lCategory = new L_category ();
		
		Doo::loadModel ( "receiptAuthorityManage" );
		$receiptAuthorityManage = new receiptAuthorityManage ();
		
		$imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
		$cidList = array ();
		foreach ( $imcStaff as $key => $value ) {
			array_push ( $cidList, $value ['cid'] );
		}
		$cidString = implode ( ',', $cidList );
		
		$staffList = $staff->find ( array (
				'where' => ' cid in (' . $cidString . ')',
				'asArray' => true 
		) );
		
		$stHtml = '';
		$stTitle = "";
		$staffId = 0;
		$cid = 0;
		$ocid = 0;
		foreach ( $staffList as $value ) {
			if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
				$stTitle = $value ['category'] . '-' . $value ['username'];
				$staffId = $value ['sid'];
				$cid = $value ['cid'];
				$ocid = $value ['cid'];
				if (! empty ( $value ['othercid'] ))
					$cid = $value ['cid'] . ',' . $value ['othercid'];
				$stHtml .= '';
			} elseif ($value ['username'] != 'admin')
				$stHtml .= '';
		}
		$data ['lCategoryHtml'] = $lCategory->find ( array (
				'where' => 'cid in(' . $cid . ')',
				'asArray' => true 
		) );
		if (empty ( $pcid ))
			$pcid = $ocid;
		
		$data ['ocid'] = $pcid;
		
		$path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
		$this->showCache ( $path );
		
		//
		$receiptCollectList = $receiptDetail->find ( array (
				'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
				'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
				'groupby' => 'item,Month(pastDate),itemCategory',
				'asArray' => true 
		) );
		// echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
		// print_r($receiptCollectList);
		$accountList = $accountItem->find ( array (
				'asArray' => true 
		) );
		// create CollectDetail HTML
		$collectHtml = array ();
		foreach ( $accountList as $key => $value ) {
			$html = "";
			$asum = 0;
			for($i = 1; $i <= 12; $i ++) {
				$falg = true;
				foreach ( $receiptCollectList as $v ) {
					if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
						
						if ($v ['item'] == '可自加费用') {
							// echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].' | 
';
						}
						$asum += $v ['price'];
						$html .= '' . $v ['price'] . '';
						$falg = false;
						break;
					}
				}
				if ($falg)
					$html .= ' | -';
			}
			$html .= ' | ' . $asum . '';
			$collectHtml [$value ['category']] [$value ['name']] = $html;
		}
		$data ['collectHtml'] = $collectHtml;
		
		// print_r($collectHtml);
		
		// create Adjustment price html
		$receiptCollectList = $receiptDetail->find ( array (
				'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
				'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
				'groupby' => 'itemCategory,Month(pastDate)',
				'asArray' => true 
		) );
		
		$adjustment = array ();
		$collectArray = array (
				'日常相关费用' => array (),
				'差旅相关费用' => array (),
				'培训班费用' => array (),
            '内部培训费用'=>array(),
				'其他' => array () 
		);
		
		$collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
		array_push ( $collectArray ['日常相关费用'], $collectHtml );
		
		$collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
		array_push ( $collectArray ['差旅相关费用'], $collectHtml );
		
		$collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
		array_push ( $collectArray ['培训班费用'], $collectHtml );
        $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
        array_push ( $collectArray ['内部培训费用'], $collectHtml );
		$collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
		array_push ( $collectArray ['其他'], $collectHtml );
		
		$data ['collectArray'] = $collectArray;
		
		$collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
		array_push ( $adjustment, $collectHtml );
		$data ['adjustment'] = $adjustment;
		
		// total price html
		$collectHtml = "";
		$total = 0;
		for($i = 1; $i <= 12; $i ++) {
			$sumPrice = 0;
			foreach ( $receiptCollectList as $key => $value ) {
				if ($value ['month'] == $i) {
					$sumPrice += $value ['price'];
				}
			}
			if ($sumPrice == 0)
				$collectHtml .= ' | -';
			else
				$collectHtml .= ' | ¥' . $sumPrice . '';
			$total += $sumPrice;
		}
		$collectHtml .= ' | ¥' . $total . '';
		
		// statistics html
		$stList = $statistics->statisticsByYear ( $year, $staffId );
		if (empty ( $stList ))
			$stList = array (
					'rePrice' => 0,
					'agPrice' => 0 
			);
		$data ['stList'] = array (
				'rePrice' => $stList ['rePrice'],
				'agPrice' => $stList ['agPrice'],
				'skPrice' => ($stList ['rePrice'] - $stList ['agPrice']) 
		);
		
		$data ['totalPrice'] = $collectHtml;
		$data ['totalYear'] = $total;
		
		$data ['stHtml'] = $stHtml;
		$data ['year'] = $year;
		$data ['stTitle'] = $stTitle;
		
		$data ['staffname'] = urlencode ( $staffname );
		
		$data ['memu'] = "receipt";
		$data ['staff'] = $this->staff;
		$data ['receiptMemu'] = 'companyCategoryCollect';
		$data ['verifyId'] = $this->verifyId;
		$data ['executeId'] = $this->executeId;
		if ($year < date ( "Y" )) {
			Doo::loadModel ( 'receipt' );
			$receipt = new receipt ();
			$receiptList = $receipt->find ( array (
					'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
					'asArray' => true 
			) );
			if (empty ( $receiptList )) { // generated files
				ob_start ();
				$this->render ( "/admin/saeaStaffCollectDetail", $data );
				$this->cacheFile ( $path );
				die ();
			}
		}
		
		$this->render ( "/admin/saeaStaffCollectDetail", $data );
	}
	function BUGFLAG() {
		$status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
		$year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
		$month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
		$cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
		$sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
		
		if (empty ( $status ))
			$status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
		
		$page_size = 12;
		$page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
		
		$vidList = array ();
		$button = 0;
		
		Doo::loadModel ( 'verify' );
		$verify = new verify ();
		Doo::loadModel ( 'receipt' );
		$receipt = new receipt ();
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( 'L_category' );
		$Lcategory = new L_category ();
		
		$dateCondition = " and Year(date) =" . $year;
		
		if (! empty ( $month ))
			$dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
		
		$categoryList = $Lcategory->find ( array (
				'asArray' => true 
		) );
		$staffList = $staff->find ( array (
				'where' => 'cid=' . $cid,
				'asArray' => true 
		) );
		$cateCondition = "";
		$staffCondition = "";
		$approvalCondition = "";
		if (! empty ( $cid ))
			$cateCondition = ' and cid=' . $cid;
		if (! empty ( $sid )) {
			$staffCondition = ' and staff=' . $sid;
			$cateCondition = "";
		}
		
		$approvalCondition = " and status=" . $status;
		if ($status == 2) {
			// 查找角色审批人
			$approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
		}
		
		if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
			$approvalCondition = ' and status=2  ';
		}
		
		if ($status == 1) {
			$approvalCondition = ' and (status=' . $status . ' or status=6)  ';
		}
		
		// nowStaff like "%'.$this->staff[0]['sid'].'%"
		$pageinfo ['page'] = array (
				'previous' => '' 
		);
		if ($status == 0) {
			$pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . '  and status!=5', $page, $page_size, "approvalExpenses", "", "" );
			
			$receiptList = $receipt->find ( array (
					'where' => 'status!=5  ' . $dateCondition . $cateCondition . $staffCondition,
					'limit' => $pageinfo ['lower'] . ',' . $page_size,
					'desc' => 'rid',
					'asArray' => true 
			) );
			// echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
		} else
			$receiptList = $receipt->find ( array (
					'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
					'desc' => 'rid',
					'asArray' => true 
			) );
		
		$rLRes = $receipt->find ( array (
				'where' => 'status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )' . $cateCondition . $staffCondition,
				'desc' => 'rid',
				'asArray' => true 
		) );
		
		// echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
		// print_r($pageinfo);
		
		$Locate = 0;
		
		foreach ( $receiptList as $key => $value ) {
			$receiptList [$key] ['Locate'] = $Locate;
			$Locate ++;
			$receiptList [$key] ['reviseDetail'] = array ();
			if (! empty ( $value ['reviseDetail'] ))
				$receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
			$receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
			$categoryDetil = $Lcategory->getOne ( array (
					'where' => 'cid=' . $value ['cid'],
					'asArray' => true 
			) );
			$receiptList [$key] ['category'] = $categoryDetil ['title'];
			$verifyList = $verify->getOne ( array (
					'where' => 'vid=' . $value ['verify'],
					'asArray' => true 
			) );
			$verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
			$verifyStaff = json_decode ( $value ['verifyStaff'], true );
			foreach ( $verifyList as $k => $v ) {
				// init verifyStaff
				$verifyList [$k] ['date'] = "";
				$verifyList [$k] ['opinion'] = "";
				$verifyList [$k] ['status'] = "";
				if (empty ( $verifyStaff )) {
					$verifyList [$k] ['date'] = "";
					$verifyList [$k] ['opinion'] = "";
					if ($v [0] == $this->staff [0] ['sid']) {
						$verifyList [$k] ['status'] = 4;
						$button = 4;
					}
				} else {
					$flag = true;
					foreach ( $verifyStaff as $m => $u ) {
						if ($v [0] == $m) {
							$verifyList [$k] ['date'] = $u ['date'];
							$verifyList [$k] ['opinion'] = $u ['opinion'];
							$verifyList [$k] ['status'] = $u ['status'];
							$flag = false;
							break;
						}
						// elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
						// if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
						// if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
					}
					if ($flag) { // 检测可编辑
						if ($v [0] == $this->staff [0] ['sid']) {
							$verifyList [$k] ['status'] = 4;
							$button = 4;
						}
					}
				}
			}
			$receiptList [$key] ['verifyList'] = $verifyList;
			$receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
					'where' => 'sid=' . $value ['staff'],
					'asArray' => true 
			) );
			$receiptList [$key] ['button'] = $button;
			$receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
		}
		// print_r($receiptList);die;
		// $data['verifyDetail']=$verifyDetail;
		
		$mothHtml = "";
		for($i = 1; $i <= 12; $i ++) {
			if ($month == $i)
				$mothHtml .= '';
			else
				$mothHtml .= '';
		}
		$data ['mothHtml'] = $mothHtml;
		
		$data ['page'] = $pageinfo;
		$data ['receiptList'] = $receiptList;
		$data ['receiptApprovalCount'] = count ( $rLRes );
		$data ['status'] = $status;
		$data ['year'] = $year;
		$data ['categoryList'] = $categoryList;
		$data ['staffList'] = $staffList;
		$data ['cid'] = $cid;
		$data ['sid'] = $sid;
		
		// print_r($receiptList);
		
		$data ['memu'] = "receipt";
		$data ['staff'] = $this->staff;
		$data ['receiptMemu'] = 'approvalExpenses';
		$data ['verifyId'] = $this->verifyId;
		
		$data ['executeId'] = $this->executeId;
		$this->render ( "/admin/FALG", $data );
	}
	function ajaxGetReceiptOrder() {
		$receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
		
		if (! empty ( $receiptOrder )) {
			Doo::loadModel ( 'receipt' );
			$receipt = new receipt ();
			Doo::loadModel ( 'staff' );
			$staff = new staff ();
			
			$receiptInfo = $receipt->getOne ( array (
					'where' => ' receiptOrder="' . $receiptOrder . '"',
					'asArray' => true 
			) );
			$verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
			
			$html = ' | 
         			| 单号:' . $receiptOrder . ' | 金额:¥' . $receiptInfo ['sum'] . ' | 
         		
';
			foreach ( $verifyStaff as $key => $value ) {
				$staffInfo = $staff->getOne ( array (
						'select' => 'username',
						'where' => ' sid="' . $key . '"',
						'asArray' => true 
				) );
				$html .= '| ' . $staffInfo ['username'] . ' | ' . $value ['opinion'] . ' | 
|---|
';
			}
			$html .= '
' . $v ['price'] . '';
							$falg = false;
							break;
						}
					}
				}
				if ($falg)
					$html .= ' | -';
			}
			
			if (! empty ( $psum ))
				$psum = ' | ' . $psum . '';
			else
				$psum = ' | -';
			$receiptL ['日常相关费用'] = $psum . $html;
			
			/* ----------------------------------- */
			
			$html = "";
			$psum = 0;
			foreach ( $aiList[$this->TRAVEL] as $value ) {
				$falg = true;
				foreach ( $receiptCollectList as $v ) {
					if ($v ['itemCategory'] == '差旅相关费用') {
						if ($v ['item'] == $value['name']) {
							$psum += $v ['price'];
							$html .= ' | ' . $v ['price'] . '';
							$falg = false;
							break;
						}
					}
				}
				if ($falg)
					$html .= ' | -';
			}
			
			if (! empty ( $psum ))
				$psum = ' | ' . $psum . '';
			else
				$psum = ' | -';
			$receiptL ['差旅相关费用'] = $psum . $html;
            /* ----------------------------------- */
            $html = "";
            $psum = 0;
            foreach ( $aiList[$this->INTTRAIN] as $value ) {
                $falg = true;
                foreach ( $receiptCollectList as $v ) {
                    if ($v ['itemCategory'] == '内部培训费用') {
                        if ($v ['item'] == $value['name']) {
                            $psum += $v ['price'];
                            $html .= ' | ' . $v ['price'] . '';
                            $falg = false;
                            break;
                        }
                    }
                }
                if ($falg)
                    $html .= ' | -';
            }
            if (! empty ( $psum ))
                $psum = ' | ' . $psum . '';
            else
                $psum = ' | -';
            $receiptL ['内部培训费用'] = $psum . $html;
			/* ------------------------------------- */
			$html = "";
			$psum = 0;
			foreach ( $aiList[$this->TRAIN] as $value ) {
				$falg = true;
				foreach ( $receiptCollectList as $v ) {
					if ($v ['itemCategory'] == '培训班费用') {
						if ($v ['item'] == $value['name']) {
							$psum += $v ['price'];
							$html .= ' | ' . $v ['price'] . '';
							$falg = false;
							break;
						}
					}
				}
				if ($falg)
					$html .= ' | -';
			}
			
			if (! empty ( $psum ))
				$psum = ' | ' . $psum . '';
			else
				$psum = ' | -';
			$receiptL ['培训班费用'] = $psum . $html;
			
			/* ------------------------------------- */
			$html = "";
			$psum = 0;
			foreach ( $aiList[$this->OTHER] as $value ) {
				$falg = true;
				foreach ( $receiptCollectList as $v ) {
					if ($v ['itemCategory'] == '其他') {
						if ($v ['item'] == $value['name']) {
							$psum += $v ['price'];
							$html .= ' | ' . $v ['price'] . '';
							$falg = false;
							break;
						}
					}
				}
				if ($falg)
					$html .= ' | -';
			}
			
			if (! empty ( $psum ))
				$psum = ' | ' . $psum . '';
			else
				$psum = ' | -';
			$receiptL ['其他'] = $psum . $html;
			
			/* ------------------------------------- */
			$html = "";
			$psum = 0;
			foreach ( $receiptCollectList as $v ) {
				if ($v ['itemCategory'] == '报销金额调整') {
					
					if (! empty ( $v ['price'] ))
						$psum += $v ['price'];
				}
			}
			
			if (! empty ( $psum ))
				$psum = ' | ' . $psum . '';
			else
				$psum = ' | -';
			$receiptL ['报销金额调整'] = $psum . $html;
		} else {
            $receiptL [$this->AGENCY] =' | -';
            foreach ( $aiList[$this->AGENCY] as $va ) {
                $receiptL [$this->AGENCY] .=' | -';
            }
            $receiptL [$this->TRAVEL] =' | -';
            foreach ( $aiList[$this->TRAVEL] as $va ) {
                $receiptL [$this->TRAVEL] .=' | -';
            }
            $receiptL [$this->INTTRAIN] =' | -';
            foreach ( $aiList[$this->INTTRAIN] as $va ) {
                $receiptL [$this->INTTRAIN] .=' | -';
            }
            $receiptL [$this->TRAIN] =' | -';
            foreach ( $aiList[$this->TRAIN] as $va ) {
                $receiptL [$this->TRAIN] .=' | -';
            }
            $receiptL [$this->OTHER] =' | -';
            foreach ( $aiList[$this->OTHER] as $va ) {
                $receiptL [$this->OTHER] .=' | -';
            }
            $receiptL ['报销金额调整'] = ' | -';
		}
		return $receiptL;
	}
	function eMail() {
		Doo::loadModel ( 'staff' );
		$staff = new staff ();
		Doo::loadModel ( 'receipt' );
		$receipt = new receipt ();
		Doo::loadModel ( 'L_category' );
		$Lcategory = new L_category ();
		Doo::loadModel ( "verify" );
		$verify = new verify ();
		
		$staffList = $staff->find ( array (
				'asArray' => true 
		) );
		
		foreach ( $staffList as $key => $value ) {
			
			if ($value ['username'] != 'admin') {
				// 提交人
				
				$receiptList = $receipt->find ( array (
						'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
						'asArray' => true 
				) );
				if (! empty ( $receiptList )) {
					
					$html = ' | 
    
      | 
          | CLD 邮件提醒 |  | 
             
               | Hi,' . $value ['username'] . ' |  
               | 美好的一天从今天开始,您需要关注以下事项: |  |  | 
              | 
             	以下报销单完成了审批,等着收款吧: |  |  ';
					
					foreach ( $receiptList as $k => $v ) {
						$category = $Lcategory->getOne ( array (
								'where' => 'cid=' . $v ['cid'],
								'asArray' => true 
						) );
						$html .= '
                  
                  ';
					}
					
					$html .= '| 
 | ' . $v ['receiptOrder'] . ' | ' . $category ['title'] . ' | ¥' . $v ['sum'] . '元 | ' . $v ['date'] . ' |  |  |  | 立即登录 |  | 
  
';
					
					if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
						$this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
						$this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
						$this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
						$receipt = new receipt ();
						$receipt->notice = 1;
						$receipt->update ( array (
								'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0' 
						) );
					}
				}
				
				// 审批人
				$verifyList = $verify->find ( array (
						'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
						'asArray' => true 
				) );
				$html = '
 
     | 
           | CLD 邮件提醒 |  | 
             | Hi,' . $value ['username'] . ' |  | 美好的一天从今天开始,您需要关注以下事项: |  |  | 
             | 以下报销单需要您的审批: |  | ';
				
				foreach ( $verifyList as $k => $v ) {
					$receiptList = $receipt->find ( array (
							'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
							'asArray' => true 
					) );
					foreach ( $receiptList as $r => $l ) {
						$category = $Lcategory->getOne ( array (
								'where' => 'cid=' . $l ['cid'],
								'asArray' => true 
						) );
						$staffDetile = $staff->getOne ( array (
								'where' => 'sid=' . $l ['staff'],
								'asArray' => true 
						) );
						$html .= '
	                  
	                  ';
					}
				}
				$html .= '| 
 | ' . $l ['receiptOrder'] . ' | ' . $category ['title'] . '-' . $staffDetile ['username'] . ' | ¥' . $l ['sum'] . '元 | ' . $l ['date'] . ' |  |  |  
           | 立即登录 | 
 | 
 
';
				
				if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
					$this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
					// $receipt=new receipt();
					// $receipt->notice=1;
					// $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
				}
			}
		}
	}
	function setWXMsg($rid, $type) {
		Doo::loadModel ( "receipt" );
		$receipt = new receipt ();
		$receiptDetail = $receipt->getOne ( array (
				'where' => 'rid=' . $rid,
				'asArray' => true 
		) );
		if (! empty ( $receiptDetail )) {
			Doo::loadModel ( 'staff' );
			$staff = new staff ();
			$staffmsg = $staff->getOne ( array (
					'where' => "sid='" . $receiptDetail ['staff'] . "'",
					'asArray' => TRUE 
			) );
			if (! empty ( $staffmsg ['wxid'] )) {
				require_once (SITE_PATH . '/protected/class/client.php');
				$client = new client ( 'http://m.cld.smartcost.com.cn/' );
				$user = $staffmsg ['wxid'];
				$receiptName = '';
				$msg = '';
				switch ($receiptDetail ['Rtype']) {
					case 0 :
						$receiptName = '报销';
						break;
					case 1 :
						$receiptName = '借款';
						break;
					case 2 :
						$receiptName = '对公汇款';
						break;
				}
				switch ($type) {
					case 1 :
						$msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
						break;
					case 2 :
						$msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
						break;
					case 3 :
						$msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
						break;
				}
				
				// $result = $client->SendMsg ( $user, $msg, 'text' );
			}
		}
	}
	
	// Email发送函数
	function SMail($toemail, $subject, $contents) {
		Doo::loadClass ( 'class.phpmailer' );
		$mail = new PHPMailer ();
		$mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
		$mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
		$mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
		$mail->Password = "cDO1GjtY1seH"; // 密码
		$mail->CharSet = "UTF8";
		$mail->SMTPAuth = true;
		$mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
		$mail->Mailer = "smtp";
		$mail->Port = 25;
		$mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
		$mail->MsgHTML ( $contents );
		$mail->AddAddress ( $toemail );
		$mail->CharSet = "UTF-8";
		return $mail->Send ();
	}
	function h5Upload() {
		$POST_MAX_SIZE = ini_get ( 'post_max_size' );
		$unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
		$multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
		
		if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
			header ( "HTTP/1.1 500 Internal Server Error" );
			echo "POST exceeded maximum allowed size.";
			exit ( 0 );
		}
		
		// Settings
		$save_path = DOO::conf ()->SITE_PATH . "upload/swfupload/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
		$upload_name = "Filedata";
		$max_file_size_in_bytes = 2147483647; // 2GB in bytes
		$extension_whitelist = array (
				"doc",
				"txt",
				"jpg",
				"gif",
				"png" 
		); // Allowed file extensions
		$valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
		                                                         
		// Other variables
		$MAX_FILENAME_LENGTH = 260;
		$file_name = "";
		$file_extension = "";
		$uploadErrors = array (
				0 => "文件上传成功",
				1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
				2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
				3 => "上传的文件仅为部分文件",
				4 => "没有文件上传",
				6 => "缺少临时文件夹" 
		);
		
		$nk = time ();
		$file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
		
		if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
			echo "文件无法保存.";
			exit ( 0 );
		}
		
		// Return output to the browser (only supported by SWFUpload for Flash Player 9)
		
		echo json_encode ( array (
				'filename' => $file_name,
				'id' => $nk 
		) );
		exit ( 0 );
	}
	function swfupload() {
		$POST_MAX_SIZE = ini_get ( 'post_max_size' );
		$unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
		$multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
		
		if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
			header ( "HTTP/1.1 500 Internal Server Error" );
			echo "POST exceeded maximum allowed size.";
			exit ( 0 );
		}
		
		// Settings
		$save_path = DOO::conf ()->SITE_PATH . "upload/swfupload/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
		$upload_name = "Filedata";
		$max_file_size_in_bytes = 2147483647; // 2GB in bytes
		$extension_whitelist = array (
				"doc",
				"txt",
				"jpg",
				"gif",
				"png" 
		); // Allowed file extensions
		$valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
		                                                         
		// Other variables
		$MAX_FILENAME_LENGTH = 260;
		$file_name = "";
		$file_extension = "";
		$uploadErrors = array (
				0 => "文件上传成功",
				1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
				2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
				3 => "上传的文件仅为部分文件",
				4 => "没有文件上传",
				6 => "缺少临时文件夹" 
		);
		
		$nk = time ();
		$file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
		
		if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
			echo "文件无法保存.";
			exit ( 0 );
		}
		
		// Return output to the browser (only supported by SWFUpload for Flash Player 9)
		
		echo json_encode ( array (
				'filename' => $file_name,
				'id' => $nk 
		) );
		exit ( 0 );
	}
	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.'';
			$num = ( int ) $num;
			// $num =floor($num);
			// $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
			// echo $num.'';
			// 结束循环
			if ($num == 0) {
				break;
			}
		}
		// echo $c.'';
		$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($table = "", $condition = "", $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 ( $table, $condition );
		$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 .= '' . $i . '';
			else
				$page_c .= '' . $i . '';
			
			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($table = "", $condition = "") {
		// $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
		$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
		
		// echo $sql;die;
		$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;
	}
	
	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;
	}
	
}
?> 
' . $value ['1'] . '' . $value ['date'] . ''; if (isset ( $value ['rolename'] )) $htmlLoan .= $value ['rolename']; $htmlLoan .= '
' . $value ['opinion'] . '