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


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

require_once 'Pager.php';

/**
 * [[機能説明]]
 *
 * @package     [[package名]]
 * @author      Your Name <mail@example.com>
 * @access      public
 */
class Admin_Ordermanage_Forwarding_List_List
{
  var $order;
  var $orderview;
  
  var $results;
/*
  var $order_date_start;
  var $order_date_end;
  var $order_time_start;
  var $order_time_end;
  var $orderno_start;
  var $orderno_end;
  var $ordermember;
  var $mailaddr;
  var $state;
  var $display;
*/
  var $cardcompany = array(1 => "VISA", 
                           2 => "MASTER",
                           3 => "NICOS",
                           4 => "JCB",
                           5 => "アメックス");

    var $cont;
    var $pagedata;    // Pagerデータ
    var $links;       // Pagerリンク
    var $from;
    
    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;
    
    var $odno;

    var $sumprice;

    var $fw;
    var $fws;

    /**
     * [[機能説明]]
     *
     * @access  public
     */
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Admin_Ordermanage_Listが実行されました", "Admin_Ordermanage_List#execute");
        
        $to = $this->display; 
        //$this->state = 5;
        
        //$this->results = $this->order->OrderSearchResults($to);
        $where[] = "fwstate_cnt > 0";
        $sortkey = "orderno";
        if (!is_numeric($this->from))$this->from = 1;
        if (empty($to)) $to = 10;
        $from = ($this->from-1)*$to;
        
        $this->results = $this->order->SearchResults($where, 
                                                     $params, 
                                                     $sortkey,
                                                     $to,
                                                     $from);

        foreach($this->results as $key => $value){
             $odno[] = $this->results[$key]["orderno"];
        }

        //詳細情報の取得
        foreach($odno as $key => $v){
            $res[] = $this->orderview->listprice($v);
        }

        //購入合計金額取得の為に
        foreach ($res as $key => $value) {
            foreach ($res[$key] as $key => $value) {
                if (($value["typediv"]==1 || 
                    $value["typediv"]==2 ||
                    $value["typediv"]==3 || 
                    $value["typediv"]==10 || 
                    $value["typediv"]==11) &&
                    ($value["forwardstate"]!=8 && $value["forwardstate"]!=9)) {
                    $salesprice[$value["orderno"]][] = $value["price"];
                } else {
                    $otherprice[$value["orderno"]][] = $value["price"];
                }
                // 出荷状態
                if ($value["typediv"]==1) {
                    $fw[$value["orderno"]][] = $value["forwardstate"];
                    $fws[$value["orderno"]][] = $value["fwstate"];
                }
            }
        }

        foreach($salesprice as $key => $value){
            $price[$key][] = number_format(array_sum($value));
        }
        $this->sumprice = $price;
       
        // 出荷状態C
        foreach($fw as $key => $value) {
            foreach ($value as $v) {
                if (!in_array($v, $f[$key])) $f[$key][] = $v;
            }
            $f[$key] = array_sum($f[$key]);
        }
        $this->fw = $f;
        // 出荷状態
        foreach($fws as $key => $value) {
            foreach ($value as $v) {
                if (!in_array($v, $fs[$key])) $fs[$key][] = $v;
            }
        }
        $this->fws = $fs;

        // Pager設定
        $pageparams = array(
            //'itemData'      => $this->results,
            'totalItems'    => $this->results["recordcount"],
            'perPage'       => $to,                       // １ページの行数
            'delta'         => $this->Pager_delta,       // 表示ページから、前後に表示するページ数
            'append'        => $this->Pager_append,
            '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
            );

            // Pager出力
            $pager = & Pager::factory($pageparams);
            $this->pagedata = $pager->getPageData();
            $this->links = $pager->getLinks();
            
          $this->cont = $this->results["recordcount"];
          unset($this->results["recordcount"]);
        
        
        return 'success';
    }
    
    function getLink()
    {
        return $this->links;
    }
    

}
?>
