<?php

/**
 * Class that operate on table 'quickprofitclient'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2019-01-21 13:45
 */
class QuickprofitclientMySqlExtDAO extends QuickprofitclientMySqlDAO {

    public function insertOrUpdatePlusEX($obj) {
        //must have UNIQUE constraint on the "combination" of the two columns
        //ALTER TABLE quickprofitclient ADD CONSTRAINT uq_quickprofitclient UNIQUE(`clientId`, `theDate`)
        $sql = " INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice,sellCostLastBuyPricewithTax,sellCostMeanBuyPricewithTax,returnSellCostLastBuyPricewithTax,returnSellCostMeanBuyPricewithTax)
                    VALUES ($obj->clientId, '" . $obj->theDate . "', $obj->sellVal, $obj->sellCostBuyPrice, $obj->sellCostLastBuyPrice
                    , $obj->sellCostMeanBuyPrice, $obj->sellCostLastBuyPricewithDiscount, $obj->sellCostMeanBuyPricewithDiscount, $obj->sellCostOverAllAveragePrice
                    , $obj->returnSellVal, $obj->returnSellCostBuyPrice, $obj->returnSellCostLastBuyPrice, $obj->returnSellCostMeanBuyPrice
                    , $obj->returnSellCostLastBuyPricewithDiscount, $obj->returnSellCostMeanBuyPricewithDiscount, $obj->returnSellCostOverAllAveragePrice ,$obj->sellCostLastBuyPricewithTax, $obj->sellCostMeanBuyPricewithTax, $obj->returnSellCostLastBuyPricewithTax, $obj->returnSellCostMeanBuyPricewithTax)
                ON DUPLICATE KEY UPDATE sellVal = sellVal+$obj->sellVal, sellCostBuyPrice =sellCostBuyPrice+$obj->sellCostBuyPrice
                        , sellCostLastBuyPrice = sellCostLastBuyPrice+$obj->sellCostLastBuyPrice, sellCostMeanBuyPrice = sellCostMeanBuyPrice+$obj->sellCostMeanBuyPrice
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount+$obj->sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount+$obj->sellCostMeanBuyPricewithDiscount
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice+$obj->sellCostOverAllAveragePrice
                            , sellCostLastBuyPricewithTax = sellCostLastBuyPricewithTax+$obj->sellCostLastBuyPricewithTax
                            , sellCostMeanBuyPricewithTax = sellCostMeanBuyPricewithTax+$obj->sellCostMeanBuyPricewithTax
                        , returnSellVal = returnSellVal+$obj->returnSellVal, returnSellCostBuyPrice = returnSellCostBuyPrice+$obj->returnSellCostBuyPrice, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice+$obj->returnSellCostLastBuyPrice
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice+$obj->returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount+$obj->returnSellCostLastBuyPricewithDiscount
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount+$obj->returnSellCostMeanBuyPricewithDiscount
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice+$obj->returnSellCostOverAllAveragePrice
                            , returnSellCostLastBuyPricewithTax = returnSellCostLastBuyPricewithTax+$obj->returnSellCostLastBuyPricewithTax
                            , returnSellCostMeanBuyPricewithTax = returnSellCostMeanBuyPricewithTax+$obj->returnSellCostMeanBuyPricewithTax";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function insertOrUpdateMinusEX($obj) {
        //must have UNIQUE constraint on the "combination" of the two columns
        //ALTER TABLE quickprofitclient ADD CONSTRAINT uq_quickprofitclient UNIQUE(`clientId`, `theDate`)
        $sql = " INSERT INTO quickprofitclient (clientId, theDate, sellVal, sellCostBuyPrice, sellCostLastBuyPrice, sellCostMeanBuyPrice, sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount, sellCostOverAllAveragePrice, returnSellVal, returnSellCostBuyPrice, returnSellCostLastBuyPrice, returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount, returnSellCostMeanBuyPricewithDiscount,returnSellCostOverAllAveragePrice,sellCostLastBuyPricewithTax,sellCostMeanBuyPricewithTax,returnSellCostLastBuyPricewithTax,returnSellCostMeanBuyPricewithTax)
                    VALUES ($obj->clientId, '" . $obj->theDate . "', $obj->sellVal, $obj->sellCostBuyPrice, $obj->sellCostLastBuyPrice
                    , $obj->sellCostMeanBuyPrice, $obj->sellCostLastBuyPricewithDiscount, $obj->sellCostMeanBuyPricewithDiscount, $obj->sellCostOverAllAveragePrice
                    , $obj->returnSellVal, $obj->returnSellCostBuyPrice, $obj->returnSellCostLastBuyPrice, $obj->returnSellCostMeanBuyPrice
                    , $obj->returnSellCostLastBuyPricewithDiscount, $obj->returnSellCostMeanBuyPricewithDiscount, $obj->returnSellCostOverAllAveragePrice, $obj->sellCostLastBuyPricewithTax, $obj->sellCostMeanBuyPricewithTax, $obj->returnSellCostLastBuyPricewithTax, $obj->returnSellCostMeanBuyPricewithTax)
                ON DUPLICATE KEY UPDATE sellVal = sellVal-$obj->sellVal, sellCostBuyPrice =sellCostBuyPrice-$obj->sellCostBuyPrice
                        , sellCostLastBuyPrice = sellCostLastBuyPrice-$obj->sellCostLastBuyPrice, sellCostMeanBuyPrice = sellCostMeanBuyPrice-$obj->sellCostMeanBuyPrice
                        , sellCostLastBuyPricewithDiscount = sellCostLastBuyPricewithDiscount-$obj->sellCostLastBuyPricewithDiscount, sellCostMeanBuyPricewithDiscount = sellCostMeanBuyPricewithDiscount-$obj->sellCostMeanBuyPricewithDiscount
                            , sellCostOverAllAveragePrice = sellCostOverAllAveragePrice-$obj->sellCostOverAllAveragePrice
                            , sellCostLastBuyPricewithTax = sellCostLastBuyPricewithTax-$obj->sellCostLastBuyPricewithTax
                            , sellCostMeanBuyPricewithTax = sellCostMeanBuyPricewithTax-$obj->sellCostMeanBuyPricewithTax
                        , returnSellVal = returnSellVal-$obj->returnSellVal, returnSellCostBuyPrice = returnSellCostBuyPrice-$obj->returnSellCostBuyPrice, returnSellCostLastBuyPrice = returnSellCostLastBuyPrice-$obj->returnSellCostLastBuyPrice
                        , returnSellCostMeanBuyPrice = returnSellCostMeanBuyPrice-$obj->returnSellCostMeanBuyPrice, returnSellCostLastBuyPricewithDiscount = returnSellCostLastBuyPricewithDiscount-$obj->returnSellCostLastBuyPricewithDiscount
                        , returnSellCostMeanBuyPricewithDiscount = returnSellCostMeanBuyPricewithDiscount-$obj->returnSellCostMeanBuyPricewithDiscount
                            , returnSellCostOverAllAveragePrice = returnSellCostOverAllAveragePrice-$obj->returnSellCostOverAllAveragePrice
                            , returnSellCostLastBuyPricewithTax = returnSellCostLastBuyPricewithTax-$obj->returnSellCostLastBuyPricewithTax
                            , returnSellCostMeanBuyPricewithTax = returnSellCostMeanBuyPricewithTax-$obj->returnSellCostMeanBuyPricewithTax";
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function queryAllEX($queryString) {
        $sql = "SELECT quickprofitclient.*, client.clientname as clientname , clientarea.name as areaName
                FROM quickprofitclient
                join  client on  client.clientid = quickprofitclient.clientId
                left join clientarea on clientarea.id = client.clientareaid
                where 1 $queryString";
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function truncate() {
        $sql = "TRUNCATE quickprofitclient";
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

}

?>