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


//JSONを扱うためのパーサ
//require_once(WEBAPP_DIR."/JSON.php");

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

/**
 * [[機能説明]]
 *
 * @package     [[package名]]
 * @author      Your Name <mail@example.com>
 * @access      public
 */
class Customer_Itembuy_Return_Form
{
    var $reason;
    var $other_reason;
    var $detail;
    var $c_order;

    var $no;
    var $row;
    var $sqlrow;

    var $mode;
    var $page;

    var $session;
    var $auth;

    /**
     * [[機能説明]]
     *
     * @access  public
     */
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Customer_itembuy_Return_Formが実行されました", "Customer_itembuy_Return_Form#execute");

        $sellerInfo = $this -> c_order -> getSellerInfo($this->no);
        if($sellerInfo["sellercd"] != "") return 'error';// onedepo以外はキャンセル・返品は不可能

        return $this->getItemData();
    }

    function getItemData()
    {

        $orderno = $this -> no;
        $orderrowno = $this -> row;
        $cd = $this->c_order->select_itemcd($orderno,$orderrowno);

        //ここでSQL
        $membercd = $this->auth->getAuthData("membercd");
        $this->sqlrow = $this->c_order->return_select($membercd,$orderno,$orderrowno,$cd["itemcd"],$cd["structcd"]);
        if(count($this->sqlrow) > 0) {
            /*
            $postdata        = array('orderdate'    =>$this->sqlrow['orderdate'],
            'orderno'      =>$this->sqlrow['orderno'],
            'itemnm'       =>$this->sqlrow['itemnm'],
            'itemcd'       =>$itemcd,
            'orderrowno'   =>$this->sqlrow['orderrowno'],
            'forwardstate' =>$this->sqlrow['forwardstate']);
            $this->session->removeParameter("return");
            $this->session->setParameter("return", $postdata);
            */
            $this->detail['orderdate'] = $this->sqlrow['orderdate'];

            // 返品可能日付を過ぎていればエラー
            $w_forwarddate = strtotime($this->sqlrow['forwarddate']);
            $w_now         = strtotime("now");
            if ((($w_now - $w_forwarddate)/(60*60*24)) > ITEMBUY_RETURN_DAY) return 'error';

            $this->detail['orderno'] = $this->sqlrow['orderno'];
            $this->detail['orderrowno'] = $this->sqlrow['orderrowno'];
            $this->detail['itemnm'] = $this->sqlrow['itemnm'] ." ". $this->sqlrow['variationnm'];
            $this->detail['itemcd'] = $cd['itemcd'];

            return 'success';
        } else {
            return 'input';
        }
    }


    function setReason($value)
    {
        $this -> reason = $value;
    }

    function getReason()
    {
        return $this -> reason;
    }

    function setOther_reason($value)
    {
        $this -> other_reason = $value;
    }

    function getOther_reason()
    {
        return $this -> other_reason;
    }

    function getDetail()
    {
        return $this -> detail;
    }

/*    function check_status()
    {
        if(isset($_GET['order_day'])) $this -> detail[0] = $_GET['order_day'];
        if(isset($_GET['order_number'])) $this -> detail[1] = $_GET['order_number'];
        if(isset($_GET['order_title'])) $this -> detail[2] = $_GET['order_title'];
        if(!(is_null($this -> detail)))
        {
            return true;
        }
        else
        {
            return false;
        }
    }*/

}
?>
