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

/**
 * 受注管理系ロジック
 *
 * @package     Onedepo_Logic_Orderview
 * @author      netnee <mail@example.com>
 * @access      public
 */
class Onedepo_Logic_Money {

    var $money;
    var $data;
    
    var $deposit_date_start;
    var $deposit_date_end;
    var $orderno_start;
    var $orderno_end;
    var $sellermember;
    var $state;
    var $display;
    var $sort;
    var $from;

    
    /**
    * 出品者支払いリスト取得
    * 
    */
    function PaymentListSalePrc($odno)
    {

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Moneymanege#PaymentListSalePrc");
        
        $this->data = $this->money->PaymentListSalePrc($odno);
                                                                                                                                                                       
        return $this->data;
        
    }
    
    function PaymentList()
    {
        $where = array();
        $params = array();
       
      
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Moneymanege#PaymentList");
        

        // AND検索の為に半角空白で分割
        $this->sellermember = mb_convert_kana($this->sellermember, "s", "UTF-8");
        $member = explode(" ", $this->sellermember);

        // LIKEを使うもの
        $like = array("lastnm" => $this->sellermember);
        $this->makeLikeParams($like, $where, $params);
        //--
        
        
        // 受注No と 日付
        $date = array("depositdate" => array($this->deposit_date_start, $this->deposit_date_end),
                      "orderno" => array($this->orderno_start,$this->orderno_end));

        foreach ($date as $key => $val) {
            if (!empty($val)) {
                if (!empty($val[0])) {
                    $where[] = $key .">= ?";
                    $params[] = str_replace("/", "-", $val[0]);
                }
                if (!empty($val[1])) {
                    $where[] = $key ."<= ?";
                    $params[] = str_replace("/", "-", $val[1]);
                }
            }
        }
        
     
        //state
        if($this->state == "2"){
                    $where[] = "sellerpaydate IS NOT NULL";
        }
        
        if($this->state == "3"){
                    $where[] = "sellerpaydate IS NULL";
        }
   
        //sort
        if ($this->sort == "1")       $sortkey = "depositdate";
        else if ($this->sort == "2")  $sortkey = "sellercd";
        else if ($this->sort == "3")  $sortkey = "orderno";
        else $sortkey =  "depositdate";
        
        if (!is_numeric($this->from))$this->from = 1;
        $from = ($this->from-1)*$this->display;
        
        $this->data = $this->money->PaymentList($where, 
                                                    $params, 
                                                    $sortkey,
                                                    $this->display,
                                                    $from);
                                                    
                                                                                                                       
        return $this->data;
        
    }
    
    function makeLikeParams($basearr, &$where, &$params)
    {
        foreach ($basearr as $key => $val) {
            if(!empty($val)) {
                if (is_array($val)) {

                    foreach ($val as $v) {
                        if (!empty($v)) {
                            $where[] = $key ." LIKE ?";
                            $params[] = '%'. $v .'%';
                        }
                    }

                } else {
                    $where[] = $key ." LIKE ?";
                    $params[] = '%'. $val .'%';
                }
            }
        }
        
    }
    
    function update($orderno, $updcnt, $upduser)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Moneymanege#update");
        
        $this->data = $this->money->update($orderno, $updcnt, $upduser);
                                                                                                                                                                       
        return $this->data;
        
    }
    
}
?>