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


/**
 * 受注テーブル関連
 *
 * @package     Onedepo.Db.Member.Customer
 * @author      netnee Y.Shiozawa<yukie.shiozawa@netnee.jp>
 * @access      public
 */
class Onedepo_Db_Moneymanage
{
    var $dbaccess;

    //検索値からの取得
    function PaymentListSalePrc($odno = array())
    {
        $log =& LogFactory::getLog();

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        
        $sql  = "SELECT * FROM v_payment_list";

        foreach ($odno as $key => $val) {
            if ($key==0)    $sql .= " WHERE orderno =";
            else            $sql .= " or orderno =";
            $sql .= " $val";
        }
        
        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->error($data->userinfo, "Onedepo_Db_Moneymanage#PaymentListSalePrc");
            die($data->getMessage());
        }

        $this->dbaccess->doClose($db);

        return $data;
    }
    
    
    
    function PaymentList($where = array(), $params = array(), $sortkey, $to, $from)
    {
        $log =& LogFactory::getLog();

        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        
        $sql  = "SELECT * FROM v_payment_other";

        foreach ($where as $key => $val) {
            if ($key==0)    $sql .= " WHERE";
            else            $sql .= " AND";
            $sql .= " $val";
        }
        
        $sql .= " ORDER BY ". $sortkey;

        $nolimit = $sql;
        $sql .= " LIMIT ". $to  ." OFFSET ". $from;

        $data = $db->getAll($sql, $params);
        if (DB::isError($data)) {
            $log->error($data->userinfo, "Onedepo_Db_Moneymanage#PaymentList");
            die($data->getMessage());
        }
        
        $nolimit = sprintf($nolimit, $sort);
        $nolimitdata = $db->getAll($nolimit, $params);
        $cnt = count($nolimitdata);
        $data += array("recordcount" => $cnt);

        $this->dbaccess->doClose($db);

        return $data;
    }
    
    function update($orderno, $updcnt, $updtuser)
    {
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Moneymanage#update";        
        
        $db = $this->dbaccess->doConnect();
        $db->autoCommit();

        $params = array($orderno, $updtuser, $_SERVER['REMOTE_ADDR'], $updcnt);
        
        $sql  = "select f_deposit_update_sellerpaydate(?, ?, ?, ?);";
        $res = $db->getOne($sql, $params);
        
        if (DB::isError($res) || $res < 0) {
            $log->error("rollback". $res->userinfo, $func_name, $params);
            $db->rollback();
            $this->dbaccess->doClose($db);
            return false;
        }
        $log->debug("commit", $func_name);

        $db->commit();
        $this->dbaccess->doClose($db);
        return true;
      
    }
    
    
}
?>
