<?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_Check
{
    var $actionChain;
    
    var $reason;
    var $other_reason;
    var $c_order;
    
    var $itemcd;

    var $no;
    var $row;

    var $mode;
    var $page;

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

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

        $errorList =& $this->actionChain->getCurErrorList();
        
        $this -> getItemData();
        
        if($this->reason <= 0){
            $errorList->add(1,"返品理由を選択してください。");
            return 'input';
        }
        if($this->reason == 8 && $this->other_reason == ""){
            $errorList->add(1,"返品理由（詳細）を入力してください。");
            return 'input';
        }
        
        return 'success';            

    }
    
    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) {
            $this->detail['orderdate'] = $this->sqlrow['orderdate'];
            $this->detail['orderno'] = $this->sqlrow['orderno'];
            $this->detail['orderrowno'] = $this->sqlrow['orderrowno'];
            $this->detail['itemnm'] = $this->sqlrow['itemnm'] ." ". $this->sqlrow['variationnm'];
            $this->detail['itemcd'] = $itemcd;

            return 'success';
        } else {
            return 'input';
        }
    }
    
    function setReason($value)
    {
        $this -> reason = $value;
    }

    function getReason()
    {
        return $this -> reason;
    }
    
    function getReasonStr()
    {
        switch($this->reason){
            case 1:
                return "商品を間違えて注文した";
                break;
            case 2:
                return "他で安い価格を見つけた";
                break;
            case 3:
                return "商品がしっかりと梱包されていなかった";
                break;
            case 4:
                return "商品が配送予定日までに届かなかった";
                break;
            case 5:
                return "商品に、配送中にできた目立った傷や破損がある";
                break;
            case 6:
                return "商品にトラブルや不具合がある";
                break;
            case 7:
                return "必要がなくなった";
                break;
            case 8:
                return "その他（詳細は下記に記入）";
                break;
            default:
                return "不明";
        }
    }
    
    function setOther_reason($value)
    {
        $this -> other_reason = $value;
    }
    
    function getOther_reason()
    {
        return $this -> other_reason;
    }

//070318 tominaga add ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    function setRow($value)
    {
        $this -> row = $value;
    }

    function getRow()
    {
        return $this -> row;
    }
    
    function setNo($value)
    {
        $this -> no = $value;
    }
    
    function getNo()
    {
        return $this -> no;
    }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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