<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shoplesssale.php');

class PaDefault extends CustomPage {
	public $ssetParid=1;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'shoplesssale','sttColumnHead'=>'shlst'),
			array('sttTableName'=>$this->sysTableHead.'shoplesssalecont','sttColumnHead'=>'shlsct'),);
		$this->sUiName='Platform/shop/sale_lesssale';
	}
	public function OnBInitial(){
		$this->sMetaTitle='缺货登记';
		$this->sLimitCount=0;
		$this->sApp=new shoplesssale($this->sConnString);
		//-- ------ #Options ------ --
		//Type
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=139;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_State_lesssale';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sState1);
		$this->sState2=$this->sState1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sState2,$tmpAR0);
		
		
		
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'shlstID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT 
			A.shlstID,A.shlstName,A.shlstNumCode,A.shlstParid,A.shlstState
			FROM '.$this->sysTableHead.'shoplesssale AS A 
			WHERE 1=1 
			AND A.shlstID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.shlstName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!=''){
			$tmpSQL.=' AND A.shlstNumCode LIKE \'%'.$this->sSearchData[1].'%\' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.shlstParid='.$this->sSearchData[2].' ';
		}
		if($this->sSearchData[3]!='-1'){
			$tmpSQL.=' AND A.shlstState='.$this->sSearchData[3].' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.
			$this->sSearchData[0].$this->sysSPLIT1.
			$this->sSearchData[1].$this->sysSPLIT1.
			$this->sSearchData[2].$this->sysSPLIT1.
			$this->sSearchData[3];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'shlstID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'shlstName','stcoctUiName'=>'缺货登记标题');
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'shoplesssale AS A 
			INNER JOIN '.$this->sysTableHead.'shoplesssalecont AS B ON B.shlsctIndexID=A.shlstID ';
		$Coun0=2;
		foreach ($this->sTable as $Row0){
			if (count($this->sTable)>2) {
				$tmpSQL.=' INNER JOIN '.$Row0['sttTableName'].' AS '.$this->sysTableMark[$Coun0].' ON '.$this->sysTableMark[$Coun0].'.'.$Row0['sttColumnHead'].'IndexID=A.shlstID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.shlstID='.$tmpAR0[0].' ';
		$tmpDataCollection0=$this->sDb->Search($tmpSQL);
		if(count($tmpDataCollection0)>0){
			$tmpRow=$tmpDataCollection0[0];
			$this->sMainID=$tmpRow[$this->sTable[0]['sttColumnHead'].'ID'];
			//-- #Get value --
			$Coun0=0;
			while (count($this->sUiDescription_Normal)>$Coun0) {
				if(isset($tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']])){
					$this->sUiDescription_Normal[$Coun0]['Value']=$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']];
					//Spical set
					if($this->sUiDescription_Normal[$Coun0]['stcotName']=='shlstParid'){
						$tmpSQL=' SELECT A.dptName FROM '.$this->sysTableHead.'downproduct AS A WHERE 1=1 AND A.dptID='.$tmpRow['shlstParid'].' ';
						$tmpDataCollection1=$this->sDb->Search($tmpSQL);
						if(count($tmpDataCollection1)>0){
							$this->sUiDescription_Normal[$Coun0]['ShowValue']=$tmpDataCollection1[0]['dptName'];
						}
					}
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='shlstParid' && ($pFlag=='Normal' || $pFlag=='List' || $pFlag=='Search')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_shop/sale/sale.php';
			$pColumn['Parameter']=$tmpParameters;
			
			$tmpSQL=' SELECT A.shstID,A.shstName AS tName
				FROM {Nets.TableHead}shopsale AS A
				WHERE 1=1 AND A.shstRecycle=0 AND A.shstChecked>1 AND A.shstID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
			
		}else if($pColumn['stcotName']=='shlstState' && $pFlag=='Search'){
			$pColumn['Option']=$this->sState2;
		}else if($pColumn['stcotName']=='shlstState' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sState1;
			
		}
		return $pColumn;
	}
}
//-- ------ #Instanct ------ --
$tmpDefault=new PaDefault();
$tmpDefault->OnPage();
$tmpControls=new CustomControls();
$tmpControlPage=new CustomControlPage();
$tmpComHead->sMenuid=$tmpDefault->sMenuid;
$tmpDefault->sysMetaTitle=$tmpDefault->sMetaTitle.' - '.$tmpDefault->sysFileConfig['sysTitle'];
//-- ------ #Template ------ --
require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php'); ?>