403Webshell
Server IP : 37.9.174.138  /  Your IP : 216.73.216.117
Web Server : Apache
System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64
User : ftpuser ( 1001)
PHP Version : 8.4.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/ttjs.cz/dev/modules/ttjs/code/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/ttjs.cz/dev/modules/ttjs/code/Stocks.php
<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace modules\ttjs\code;

/**
 * Description of Stocks
 *
 * @author maros
 */
class Stocks extends \app\classes\PDOCollection {

    protected $user;
    protected $year;
    protected $defaultStock;
    protected $defaultStockSnapshot;
    protected $thisMonthSnapshot;
    protected $prevMonthSnapshot;
    protected $sold;
    protected $deprecated;
    protected $received;
    protected $thisMonthShowDay = 0; //show stocks in current month from day x

    public static function getMonths($keyPrefix = "") {
        $t = \app\classes\Translator::getInstance();
        return array(
            $keyPrefix . "01" => $t->_get("Január"),
            $keyPrefix . "02" => $t->_get("Február"),
            $keyPrefix . "03" => $t->_get("Marec"),
            $keyPrefix . "04" => $t->_get("Apríl"),
            $keyPrefix . "05" => $t->_get("Máj"),
            $keyPrefix . "06" => $t->_get("Jún"),
            $keyPrefix . "07" => $t->_get("Júl"),
            $keyPrefix . "08" => $t->_get("August"),
            $keyPrefix . "09" => $t->_get("September"),
            $keyPrefix . "10" => $t->_get("Október"),
            $keyPrefix . "11" => $t->_get("November"),
            $keyPrefix . "12" => $t->_get("December")
        );
    }

    public function __construct(\app\classes\BasicUser $user, $year) {
        $year = intval($year);
        $this->user = $user;
        $this->year = $year;
        $stock = $user->getStock();
        parent::__construct("stocks", "snapshot", "SELECT * FROM stocks WHERE "
                . "users_id=:users_id AND snapshot LIKE :snapshot AND state=:ACTIVE "
                . "ORDER BY snapshot ASC", array(
            "users_id" => $user->_get("id"),
            "snapshot" => $year . "%",
            "ACTIVE" => \app\constants\State::ACTIVE
        ));

        $lastSnapshot = 0;
        if ($this->getElementsCount() > 0) {
            $lastSnapshotArray = end($this->collection);
            $lastSnapshot = intval($lastSnapshotArray["snapshot"]);
        }
        $this->sold = $this->getSoldItems();
        $this->deprecated = $this->getDeprecatedItems();
        $this->received = $this->getReceivedItems();

        $thisMonth = array(
            "items_count" => $stock->_get("items_count"),
            "total_commission" => $stock->_get("total_commission"),
            "unpaid_commission" => $stock->_get("unpaid_commission"),
        );
        $this->prevMonthSnapshot = intval(date('Ym', strtotime('last day of -1 month')));
        $this->thisMonthSnapshot = intval(date("Ym"));
        $prevMonth = array(
            "items_count" =>
            $stock->_get("items_count") +
            (isset($this->sold[$this->thisMonthSnapshot]) ? $this->sold[$this->thisMonthSnapshot]["items_count"] : 0) +
            (isset($this->deprecated[$this->thisMonthSnapshot]) ? $this->deprecated[$this->thisMonthSnapshot]["items_count"] : 0) -
            (isset($this->received[$this->thisMonthSnapshot]) ? $this->received[$this->thisMonthSnapshot]["items_count"] : 0),
            "total_commission" => "?",
            "unpaid_commission" => "?"
        );

        $this->collection[$this->prevMonthSnapshot] = $prevMonth;
        $this->collection[intval(date("Ym"))] = $thisMonth;

        $this->defaultStock = $this->user->getDefaultStock();
        $this->defaultStockSnapshot = intval(date('Ym', strtotime($this->defaultStock->_get("created") . ' -1 months')));
    }

    protected function getReceivedItems() {
        $sql = "
                SELECT 
                    EXTRACT(YEAR_MONTH FROM `created`) AS `snapshot`, 
                    SUM(`items_count`) AS `items_count`,
                    SUM(`approx_commission`) AS `approx_commission`
                FROM `pdso_offers`
                WHERE 
                    `users_id`=:users_id AND 
                    YEAR(`created`)=:year AND
                    state=:ACTIVE
                GROUP BY `snapshot`
                ORDER BY `snapshot` ASC
                ";
        $collection = new \app\classes\PDOCollection("pdso_offers", "snapshot", $sql, array(
            "users_id" => $this->user->_get("id"),
            "year" => $this->year,
            "ACTIVE" => \app\constants\State::ACTIVE
        ));
        return $collection->toArray();
    }

    protected function getSoldItems() {
        $sql = "
                SELECT 
                    EXTRACT(YEAR_MONTH FROM `sell_date`) AS `snapshot`, 
                    COUNT(*) AS `items_count`,
                    SUM(`commission`) AS `total_commission`
                FROM `sold_items`
                WHERE 
                    `users_id`=:users_id AND 
                    YEAR(`sell_date`)=:year AND
                    state=:ACTIVE
                GROUP BY `snapshot`
                ORDER BY `snapshot` ASC
                ";
        $collection = new \app\classes\PDOCollection("sold_items", "snapshot", $sql, array(
            "users_id" => $this->user->_get("id"),
            "year" => $this->year,
            "ACTIVE" => \app\constants\State::ACTIVE
        ));
        return $collection->toArray();
    }

    protected function getDeprecatedItems() {
        $sql = "
                SELECT 
                    EXTRACT(YEAR_MONTH FROM `deprecation_date`) AS `snapshot`, 
                    SUM(`items_count`) AS `items_count`
                FROM `deprecated_items`
                WHERE 
                    `users_id`=:users_id AND 
                    YEAR(`deprecation_date`)=:year AND
                    state=:ACTIVE
                GROUP BY `snapshot`
                ORDER BY `snapshot` ASC
                ";
        $collection = new \app\classes\PDOCollection("deprecated_items", "snapshot", $sql, array(
            "users_id" => $this->user->_get("id"),
            "year" => $this->year,
            "ACTIVE" => \app\constants\State::ACTIVE
        ));
        return $collection->toArray();
    }

    protected function getPaidCommissions() {
        $sql = "
                SELECT 
                    EXTRACT(YEAR_MONTH FROM `deprecation_date`) AS `snapshot`, 
                    SUM(`items_count`) AS `items_count`
                FROM `deprecated_items`
                WHERE 
                    `users_id`=:users_id AND 
                    YEAR(`deprecation_date`)=:year AND
                    state=:ACTIVE
                GROUP BY `snapshot`
                ORDER BY `snapshot` ASC
                ";
        $collection = new \app\classes\PDOCollection("deprecated_items", "snapshot", $sql, array(
            "users_id" => $this->user->_get("id"),
            "year" => $this->year,
            "ACTIVE" => \app\constants\State::ACTIVE
        ));
        return $collection->toArray();
    }

    protected function getIfIsset(&$array, $key, $item, $altReturn = 0) {
        if (isset($array[$key]) && isset($array[$key][$item])) {
            return $array[$key][$item];
        }
        return $altReturn;
    }

    public function getChartData() {
        $collection = $this->collection;
        $collection[$this->defaultStockSnapshot] = array(
            "items_count" => $this->defaultStock->_get("items_count"),
            "total_commission" => $this->defaultStock->_get("total_commission"),
            "unpaid_commission" => $this->defaultStock->_get("unpaid_commission")
        );
        $data = array();
        foreach (self::getMonths($this->year) as $key => $val) {
            $data[$key] = $this->getIfIsset($collection, $key, "items_count", "null");
        }

        if (intval(date("Y")) === $this->year && date("d") <= $this->thisMonthShowDay) {
            $data[date("Ym")] = "null";
        }
        return $data;
    }

    public function getTableData() {
        $data = array();
        foreach (self::getMonths($this->year) as $key => $val) {
            $data[$key] = array(
                "items_count_start" => "?",
                "items_count_received" => $this->getIfIsset($this->received, $key, "items_count"),
                "approx_commission" => $this->getIfIsset($this->received, $key, "approx_commission"),
                "items_count_deprecated" => $this->getIfIsset($this->deprecated, $key, "items_count"),
                "items_count_sold" => $this->getIfIsset($this->sold, $key, "items_count"),
                "items_count_end" => $this->getIfIsset($this->collection, $key, "items_count"),
                "total_commission" => $this->getIfIsset($this->sold, $key, "total_commission"),
            );
            $data[$key]["items_count_start"] = $data[$key]["items_count_end"] + $data[$key]["items_count_sold"] + $data[$key]["items_count_deprecated"] - $data[$key]["items_count_received"];

            if ($data[$key]["items_count_start"] < 0) { //IMPROVEMENT 2025
                $data[$key]["items_count_start"] = 0;
            }
        }
        return $data;
    }

    public function getApproxCommission() {
        return $this->db->getValue("SELECT SUM(approx_commission) FROM pdso_offers WHERE users_id=:users_id AND state=:ACTIVE", [
                    "users_id" => $this->user->_get("id"),
                    "ACTIVE" => \app\constants\State::ACTIVE
        ]);
    }

    public function renderTable() {
        $t = \app\classes\Translator::getInstance();
        $data = $this->getTableData();
        $skipThisMonth = false;
        if (intval(date("Y")) === $this->year && date("d") <= $this->thisMonthShowDay) {
            $tm = $data[date("Ym")];
            foreach ($tm as $key => $val) {
                $tm[$key] = 0;
            }
            $data[date("Ym")] = $tm;
            $skipThisMonth = true;
        }
        $cnf = new TtjsConfig();
        $currency = $cnf->getConfig(TtjsConfig::CURRENCY);
        $totals = array(
            "items_count_start" => 0,
            "items_count_received" => 0,
            "approx_commission" => 0,
            "items_count_deprecated" => 0,
            "items_count_sold" => 0,
            "items_count_end" => 0,
            "total_commission" => 0,
        );
        ?>
        <table class="table table-striped table-bordered text-center table-stats">
            <thead>
                <tr class="table-dark">
                    <th class="year"><?php echo $this->year ?></th>
                    <th><?php echo $t->_get("Počiatočný stav skladu (ks)") ?></th>
                    <th><?php echo $t->_get("Prijaté (ks)") ?></th>
                    <th><?php echo $t->_get("Odhadovaná provízia") ?></th>
                    <th><?php echo $t->_get("Vyradené (ks)") ?></th>
                    <th><?php echo $t->_get("Predané (ks)") ?></th>
                    <th><?php echo $t->_get("Konečný stav skladu (ks)") ?></th>
                    <th><?php echo $t->_get("Získané provízie") ?></th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach (self::getMonths($this->year) as $key => $val) {
                    $items = $data[$key];
                    $cleanItems = true;
                    foreach ($items as $key2 => $val2) {
                        $totals[$key2] = $totals[$key2] + $val2;
                        if ($val2 != 0) {
                            $cleanItems = false;
                        }
                    }
                    if ($cleanItems && (intval($key) <= $this->defaultStockSnapshot || $key > $this->thisMonthSnapshot)) {
                        foreach ($items as $key2 => $val2) {
                            $items[$key2] = "";
                        }
                    }
                    ?>
                    <tr>
                        <td><b><?php echo $val ?></b></td>
                        <?php if (($skipThisMonth && intval($key) === intval(date("Ym"))) || intval($key) === 202402) { ?>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        <?php } else { ?>
                            <td><?php echo $items["items_count_start"] ?></td>
                            <td><?php echo $items["items_count_received"] ?></td>
                            <td><?php echo $items["approx_commission"] === "" ? "" : Currency::getRoundedVal($items["approx_commission"], $currency, true) ?></td>
                            <td><?php echo $items["items_count_deprecated"] ?></td>
                            <td><?php echo $items["items_count_sold"] ?></td>
                            <td><?php echo $items["items_count_end"] ?></td>
                            <td><b><?php echo $items["total_commission"] === "" ? "" : Currency::getRoundedVal($items["total_commission"], $currency, true) ?></b></td>
                        <?php } ?>
                    </tr>
                <?php } ?>           
            </tbody>
            <tfoot>
                <tr class="table-primary">
                    <td><?php echo $t->_get("Celkom") ?></td>
                    <td></td>
                    <td><?php echo $totals["items_count_received"] ?></td>
                    <td><?php echo Currency::getRoundedVal($totals["approx_commission"], $currency, true) ?></td>
                    <td><?php echo $totals["items_count_deprecated"] ?></td>
                    <td><?php echo $totals["items_count_sold"] ?></td>
                    <td></td>
                    <td><?php echo Currency::getRoundedVal($totals["total_commission"], $currency, true) ?></td>
                </tr>
            </tfoot>
        </table>
        <?php
    }

    public function renderMobileTable() {
        $t = \app\classes\Translator::getInstance();
        $data = $this->getTableData();
        $skipThisMonth = false;
        if (intval(date("Y")) === $this->year && date("d") <= $this->thisMonthShowDay) {
            $tm = $data[date("Ym")];
            foreach ($tm as $key => $val) {
                $tm[$key] = 0;
            }
            $data[date("Ym")] = $tm;
            $skipThisMonth = true;
        }
        $cnf = new TtjsConfig();
        $currency = $cnf->getConfig(TtjsConfig::CURRENCY);
        $totals = array(
            "items_count_start" => 0,
            "items_count_received" => 0,
            "approx_commission" => 0,
            "items_count_deprecated" => 0,
            "items_count_sold" => 0,
            "items_count_end" => 0,
            "total_commission" => 0,
        );
        ?>
        <table class="table table-striped table-bordered text-center table-stats table-stats-mobile">            
            <tbody>
                <?php
                $htmls = array();
                foreach (self::getMonths($this->year) as $key => $val) {
                    if (($skipThisMonth && intval($key) === intval(date("Ym"))) || intval($key) === 202402) {
                        continue;
                    }
                    $items = $data[$key];
                    $cleanItems = true;
                    foreach ($items as $key2 => $val2) {
                        $totals[$key2] = $totals[$key2] + $val2;
                        if ($val2 != 0) {
                            $cleanItems = false;
                        }
                    }

                    if ($cleanItems && (intval($key) <= $this->defaultStockSnapshot || $key > $this->thisMonthSnapshot)) {
                        foreach ($items as $key2 => $val2) {
                            $items[$key2] = "";
                        }
                    }

                    if ($cleanItems) {
                        continue;
                    }
                    ob_start();
                    ?>
                    <tr class="table-dark">
                        <td colspan="2">
                            <b>
                                <?php echo $val ?> 
                            </b>
                            <?php echo $this->year ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Počiatočný stav skladu (ks)") ?></td>
                        <td><?php echo $items["items_count_start"] ?></td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Prijaté (ks)") ?></td>
                        <td><?php echo $items["items_count_received"] ?></td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Odhadovaná provízia") ?></td>
                        <td><?php echo $items["approx_commission"] === "" ? "" : Currency::getRoundedVal($items["approx_commission"], $currency, true) ?></td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Vyradené (ks)") ?></td>
                        <td><?php echo $items["items_count_deprecated"] ?></td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Predané (ks)") ?></td>
                        <td><?php echo $items["items_count_sold"] ?></td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Konečný stav skladu (ks)") ?></td>
                        <td><?php echo $items["items_count_end"] ?></td>
                    </tr>
                    <tr>
                        <td class="fw-bold"><?php echo $t->_get("Získané provízie") ?></td>
                        <td><b><?php echo $items["total_commission"] === "" ? "" : Currency::getRoundedVal($items["total_commission"], $currency, true) ?></b></td>
                    </tr>                    
                    <?php
                    $htmls[] = ob_get_clean();
                }

                foreach (array_reverse($htmls) as $html) {
                    echo $html;
                }
                ?>      
                <tr class="table-dark">
                    <td colspan="2">
                        <b>
                            <?php echo $t->_get("Celkom") ?>
                        </b>
                        <?php echo $this->year ?>
                    </td>
                </tr>               
                <tr class="table-primary">
                    <td class="fw-bold"><?php echo $t->_get("Prijaté (ks)") ?></td>
                    <td><?php echo $totals["items_count_received"] ?></td>
                </tr>
                <tr class="table-primary">
                    <td class="fw-bold"><?php echo $t->_get("Odhadovaná provízia") ?></td>
                    <td><?php echo Currency::getRoundedVal($totals["approx_commission"], $currency, true) ?></td>
                </tr>
                <tr class="table-primary">
                    <td class="fw-bold"><?php echo $t->_get("Vyradené (ks)") ?></td>
                    <td><?php echo $totals["items_count_deprecated"] ?></td>
                </tr>
                <tr class="table-primary">
                    <td class="fw-bold"><?php echo $t->_get("Predané (ks)") ?></td>
                    <td><?php echo $totals["items_count_sold"] ?></td>
                </tr>              
                <tr class="table-primary">
                    <td class="fw-bold"><?php echo $t->_get("Získané provízie") ?></td>
                    <td><b><?php echo Currency::getRoundedVal($totals["total_commission"], $currency, true) ?></b></td>
                </tr>          
            </tbody>       
        </table>
        <?php
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit