<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */


require_once 'Pager.php';

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * 基本情報変更確認
 *
 * @package     Admin.Itemmanage.Order.
 * @author      T.Shimano <shimano@fuco.jp>
 * @access      public
 */
class Admin_Itemmanage_Delivery_List
{   
    //検索条件
    var $suppliercode;
    var $suppliermode;
    var $deliverydatefrom;
    var $deliverydateto;
    var $ordernumber;
    var $jancode;

    //入力値
    var $orderunitprice;
    var $ordernum;
    var $ischecked;
    var $clear;//PagerのextraVars Pagerで遷移する際に、値を消去する

    //並び替え条件
    var $sortmode;

    //テーブル操作クラス
   	var $c_supplier;
    var $c_delivery;

	var $checkitem;

    //出力用変数
    var $deliverylist;

    var $title;
   	var $pagename;

    // 入力パラメータ
    var $cnt;         // 総登録件数
    var $pageID;      // ページ番号
    
	var $Pager_perPage;
	var $Pager_delta;
	var $Pager_append;
	var $Pager_clearIfVoid;
	var $Pager_urlVar;
	var $Pager_useSessions;
	var $Pager_closeSession;
	var $Pager_mode;
	var $Pager_prevImg;
	var $Pager_nextImg;
	var $Pager_altPage;
	var $Pager_altPrev;
	var $Pager_altNext;
	var $Pager_altFirst;
	var $Pager_altLast;
	var $Pager_firstPagePre;
	var $Pager_firstPageText;
	var $Pager_firstPagePost;
	var $Pager_lastPagePre;
	var $Pager_lastPageText;
	var $Pager_lastPagePost;
	var $Pager_separator;
	var $Pager_spacesBeforeSeparator;
	var $Pager_spacesAfterSeparator;

	function getPager()
	{
        // Pager設定
        $pageparams = array(
        'totalItems'    => $this->cnt,
        'perPage'       => $this->Pager_perPage,       // １ページの行数
        'delta'         => $this->Pager_delta,       // 表示ページから、前後に表示するページ数
        'append'        => $this->Pager_append,
        'currentPage'   => $this->pageID,
        'clearIfVoid'   => $this->Pager_clearIfVoid,
        'urlVar'        => $this->Pager_urlVar,
        'useSessions'   => $this->Pager_useSessions,
        'closeSession'  => $this->Pager_closeSession,
        'mode'          => $this->Pager_mode,
        'prevImg'       => $this->Pager_prevImg,
        'nextImg'       => $this->Pager_nextImg,
        'altPage'       => $this->Pager_altPage,
        'altPrev'       => $this->Pager_altPrev,
        'altNext'       => $this->Pager_altNext,
        'altFirst'      => $this->Pager_altFirst,
        'altLast'       => $this->Pager_altLast,
        'firstPagePre'  => $this->Pager_firstPagePre,
        'firstPageText' => $this->Pager_firstPageText,
        'firstPagePost' => $this->Pager_firstPagePost,
        'lastPagePre'   => $this->Pager_lastPagePre,
        'lastPageText'  => $this->Pager_lastPageText,
        'lastPagePost'  => $this->Pager_lastPagePost,
        'separator'     => $this->Pager_separator,
        'spacesBeforeSeparator' => $this->Pager_spacesBeforeSeparator,
        'spacesAfterSeparator'  => $this->Pager_spacesAfterSeparator,
        'extraVars'     => array('clear' => 1),
        );
        
        // Pager出力
        $pager = & Pager::factory($pageparams);
        $this->pagedata = $pager->getPageData();
        $link =	$pager->getLinks();
        return $link["all"];
	}

    function execute()
    {
        $this -> setPagerParam();
        $log =& LogFactory::getLog();
        $log->debug("Admin_Itemmanage_Delivery_Listが実行されました", "Admin_Itemmanage_Delivery_List#execute");

        if(is_null($this -> suppliercode)){
            return 'input';
        } else {
            return 'success';
        }
    }

    function getSupplierName()
    {
        $name = $this -> c_supplier -> selectKey($this -> suppliercode);
        return $name["suppliernm"];
    }

    function getDeliverylist()
    {
        return $this -> deliverylist;
    }

    function setPagerParam()
    {

        //JANコードから注文番号の取得 と、SQLの条件作成
        $conditions = $this -> getSQL();
        $this->deliverylist = $this -> c_delivery -> selectDelivery($conditions, 
        $this->Pager_perPage, $this->Pager_perPage*($this->pageID - 1), $this->sortmode);
        
        $this -> cnt = $this -> c_delivery -> countDelivery($conditions);

    }
    
    function getCnt()
    {
        return $this -> cnt;
    }
    
    function getSQL()
    {
        $conditions ="";
        if($this -> jancode != ""){
            $array = $this -> c_delivery -> getOrderNoFromJancd($this -> jancode);
            if($array != null){
                $arrayOrderNo = array();
                foreach($array as $oneOrderNo){
                    $arrayOrderNo[] = "stk.orderno = '" . $oneOrderNo["orderno"] . "'";
                }
                $implodeOrderNo = implode($arrayOrderNo, ' OR ');
            }else{
                //JANコードが存在しない誤ったコードの場合
                $implodeOrderNo = " FALSE ";
            }
            
            $conditions .= "AND (" . $implodeOrderNo . ")"; 
        }

        if($this -> suppliercode != "")
            $conditions .= " AND stk.suppliercd = " . $this -> suppliercode;

        if($this -> deliverydatefrom != "")
            $conditions .= " AND stk.orderdate >= '" . $this -> deliverydatefrom . "'";

        if($this -> deliverydateto != "")
            $conditions .= " AND stk.orderdate <= '" . $this -> deliverydateto . "'";

        if($this -> ordernumber != "")
            $conditions .= " AND stk.orderno LIKE '%" . $this -> ordernumber ."%'";

        if($this -> suppliermode != "")
            $conditions .= " AND stk.supplidiv = "  . $this -> suppliermode;
        
        return $conditions;    	
    }
    
    function getCheckedArray()
    {
        if(is_null($this -> ischecked) || $this -> clear == 1) return array();
        return $this -> ischecked;
    }

    function getOrderUnitPrice()
    {
        if(is_null($this -> orderunitprice)  || $this -> clear == 1) return array();
        return $this -> orderunitprice;
    }

    function getOrderNum()
    {
        if(is_null($this -> ordernum)  || $this -> clear == 1) return array();
        return $this -> ordernum;
    }
}
?>