HEX
Server: Apache
System: Linux server1.royalgt4.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
User: mostafedeg (1125)
PHP: 5.6.40
Disabled: mail,passthru,parse_ini_file,show_source,eval,assert,pcntl_exec,dl,putenv,proc_open,popen
Upload Files
File: /home/mostafedeg/public_html/erp/models/mysql/ext/BuypriceshistorybookMySqlExtDAO.class.php
<?php

/**
 * Class that operate on table 'buypriceshistorybook'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2021-09-29 22:15
 */
class BuypriceshistorybookMySqlExtDAO extends BuypriceshistorybookMySqlDAO {

    public function insertOrUpdatePlusEX($obj) {
        //must have UNIQUE constraint on the "combination" of the columns
        //ALTER TABLE `buypriceshistorybook` ADD UNIQUE( `theDate`, `storeId`, `productid`, `sizeid`, `colorid`);
        $sql = "INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('" . $obj->theDate . "', $obj->storeId, $obj->productid, $obj->sizeid, $obj->colorid
                    , $obj->buyprice, $obj->buyQuantity, $obj->sellQuantity, $obj->del, $obj->userid, '" . $obj->sysDate . "')
                ON DUPLICATE KEY UPDATE buyprice = $obj->buyprice,
                        buyQuantity =buyQuantity+$obj->buyQuantity, sellQuantity = sellQuantity+$obj->sellQuantity,
                        del = $obj->del,userid = $obj->userid,sysDate = '" . $obj->sysDate . "' ";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function insertOrUpdatePlusEXBuyPriceNoUpdate($obj) {
        //must have UNIQUE constraint on the "combination" of the columns
        //ALTER TABLE `buypriceshistorybook` ADD UNIQUE( `theDate`, `storeId`, `productid`, `sizeid`, `colorid`);
        $sql = "INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('" . $obj->theDate . "', $obj->storeId, $obj->productid, $obj->sizeid, $obj->colorid
                    , $obj->buyprice, $obj->buyQuantity, $obj->sellQuantity, $obj->del, $obj->userid, '" . $obj->sysDate . "')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity+$obj->buyQuantity, sellQuantity = sellQuantity+$obj->sellQuantity,
                        del = $obj->del,userid = $obj->userid,sysDate = '" . $obj->sysDate . "' ";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function insertOrUpdateMinusEX($obj) {
        //must have UNIQUE constraint on the "combination" of the columns
        //ALTER TABLE `buypriceshistorybook` ADD UNIQUE( `theDate`, `storeId`, `productid`, `sizeid`, `colorid`);
        $sql = "INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('" . $obj->theDate . "', $obj->storeId, $obj->productid, $obj->sizeid, $obj->colorid
                    , $obj->buyprice, $obj->buyQuantity, $obj->sellQuantity, $obj->del, $obj->userid, '" . $obj->sysDate . "')
                ON DUPLICATE KEY UPDATE buyprice = $obj->buyprice,
                        buyQuantity =buyQuantity-$obj->buyQuantity, sellQuantity = sellQuantity-$obj->sellQuantity,
                        del = $obj->del,userid = $obj->userid,sysDate = '" . $obj->sysDate . "' ";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function insertOrUpdateMinusEXBuyPriceNoUpdate($obj) {
        //must have UNIQUE constraint on the "combination" of the columns
        //ALTER TABLE `buypriceshistorybook` ADD UNIQUE( `theDate`, `storeId`, `productid`, `sizeid`, `colorid`);
        $sql = "INSERT INTO buypriceshistorybook (theDate, storeId, productid, sizeid, colorid, buyprice, buyQuantity, sellQuantity, del, userid, sysDate)
                    VALUES ('" . $obj->theDate . "', $obj->storeId, $obj->productid, $obj->sizeid, $obj->colorid
                    , $obj->buyprice, $obj->buyQuantity, $obj->sellQuantity, $obj->del, $obj->userid, '" . $obj->sysDate . "')
                ON DUPLICATE KEY UPDATE buyQuantity =buyQuantity-$obj->buyQuantity, sellQuantity = sellQuantity-$obj->sellQuantity,
                        del = $obj->del,userid = $obj->userid,sysDate = '" . $obj->sysDate . "' ";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function plusSellQuantityByValue($changeInQuantity, $id) {
        $sql = "UPDATE buypriceshistorybook set sellQuantity = sellQuantity+$changeInQuantity where id = $id";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function minusSellQuantityByValue($changeInQuantity, $id) {
        $sql = "UPDATE buypriceshistorybook set sellQuantity = sellQuantity-$changeInQuantity where id = $id";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function plusBuyQuantityByValue($changeInQuantity, $id) {
        $sql = "UPDATE buypriceshistorybook set buyQuantity = buyQuantity+$changeInQuantity where id = $id";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function minusBuyQuantityByValue($changeInQuantity, $id) {
        $sql = "UPDATE buypriceshistorybook set buyQuantity = buyQuantity-$changeInQuantity where id = $id";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function getBuyPriceOfFirstAvailableSellQuantity($storeId, $productid, $sizeid, $colorid, $queryString = '') {
        $sql = "SELECT *
                FROM buypriceshistorybook
                where del=0 and storeId=$storeId and productid=$productid and sizeid=$sizeid and colorid=$colorid
                and buyQuantity > sellQuantity and buyQuantity > 0 " . $queryString . "
                order by theDate asc limit 1";
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->getRow($sqlQuery);
    }

}

?>