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


/**
 * 
 *
 * @package     Onedepo.Db.Deposit
 * @author      netnee
 * @access      public
 */
class Onedepo_Db_Deposit
{
    var $dbaccess;


    function getDepositFromOrder($membercd){
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Deposit#getDepositFromOrder";
        
        $db = $this->dbaccess->doConnect();
        $db->setFetchMode(DB_FETCHMODE_ASSOC);

        $params = array($membercd);
        $sql  = "select o.orderno,d.depositdiv, d.cardcompany, d.cardnumber, ";
        $sql .= "d.cardname, d.cardexp, d.remiseinfo, o.sendpostalcd, o.sendprefcd, ";
        $sql .= "o.sendmailaddr, o.sendbuyer, ";
        $sql .= "o.sendaddr1, o.sendaddr2, o.sendtelno1, o.addressee ";
        $sql .= "from t_deposit d join t_order_title o using(orderno)";
        $sql .= "where ordermember=? ";
        $sql .= "and d.delflg=FALSE and o.delflg=FALSE ";
        $sql .= "order by o.adddate desc limit 1";

        $orderno = $db->getRow($sql, $params);
        
        if (DB::isError($orderno)) {
            $log->error("error ". $orderno->userinfo, $func_name);
            $this->dbaccess->doClose($db);
            return false;
        }

        $this->dbaccess->doClose($db);
        return $orderno;
    }
    
    
    
    function DepositUpdateState($orderno, $today, $state, $upduser, $updcnt){
      
        $log =& LogFactory::getLog();
        $func_name = "Onedepo_Db_Deposit#DepositUpdateState";

        $db = $this->dbaccess->doConnect();
        $db->autoCommit();
        $params = array($orderno, $today, $state, $upduser, $_SERVER['REMOTE_ADDR'], $updcnt);

        $sql  = "select f_deposit_state_update(?, ?, ?, ?, ?, ?);";

        $res = $db->getOne($sql, $params);

        if (DB::isError($res) || $res < 0) {
            $log->error("rollback". $res->userinfo, $func_name);
            $db->rollback();
            $this->dbaccess->doClose($db);
            return false;
        }
        $log->debug("commit", $func_name);

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