<?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: */

/**
 * 入金管理 
 *
 * @package     
 * @author      Your Name <mail@example.com>
 * @access      public
 */
class Seller_Itemexhibit_Receive_List
{
    var $auth;
    var $c_itemexhibit;
    var $data;
    var $membercd;
    var $range;
    var $range_y;
    var $d;
    var $viewdata;

    function execute()
    {
        $log =& LogFactory::getLog();

        $this->membercd = $this->auth->getAuthData("membercd");

        if (empty($this->range)) $this->range = (int)date("m");
        if (empty($this->range_y)) $this->range_y = (int)date("Y");
        if (isset($this->d))     $d = true;
        else                     $d = false;
        $sdate = $this->getSdate();
        $edate = $this->getEdate();
        $this->data = $this->c_itemexhibit->getReceiveManageList(
                                            $this->membercd, 
                                            $sdate, 
                                            $edate,
                                            $d);

        $this->makeViewdata();
        return 'success';
    }

    function makeViewdata() {
        $i = 0;
        foreach ($this->data as $key => $val) {
            $sortdata = array();
            foreach ($val as $k => $v) {
                $data = array();
                $this->viewdata[$i]["orderno"]       = $key;
                $this->viewdata[$i]["orderdate"]     = $v["orderdate"];
                $this->viewdata[$i]["ordermembernm"] = $v["ordermembernm"];
                $data["sellnumber"] = $itemnm = "";
                if (!empty($v["itemcd"]) && !empty($v["structcd"]) &&
                    !empty($v["stockcd"]) && !empty($v["sellercd"])) {
                    $data["sellnumber"] = $v["itemcd"] ."-".
                                          $v["structcd"] ."-".
                                          $v["stockcd"] ."-".
                                          $v["sellercd"];

                    $variationnm = $this->c_itemexhibit->getVariationNm($v["itemcd"], $v["structcd"]);
                    $itemnm = $v["itemnm"] ." ". $variationnm;
                }
                $data["title"]      = (!empty($itemnm)) ? $itemnm : $v["itemnm"];
                $data["count"]      = $v["count"];
                $data["price"]      = $v["price"];
                $sortdata[] = $data;
            }
            usort($sortdata, array($this, "sortSellnumber"));
            $this->viewdata[$i]["data"] = $sortdata;
            $i++;
        }

    }

    function getRangeY() {
        $r = array();
        for ($i = 2007; $i <= date("Y"); $i++) $r[] = $i;
        return $r;
    }

    function sortSellnumber($a, $b) {
        if ($a["sellnumber"]==$b["sellnumber"]) return 0;
        return (!empty($a["sellnumber"])) ? -1 : 1;
    }

    function getSdate() {
        $time = mktime(0,0,0,$this->range,1,$this->range_y);
        return date("Y-m-d", $time);
    }
    function getEdate() {
        // 次の月の1日とする
        $time = mktime(0,0,0,$this->range+1,1,$this->range_y);
        return date("Y-m-d", $time);
    }
}
?>
