first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
<?php
// ##############################################################
$main_class = 'ExportOrdersBoard';
class ExportOrdersBoard extends Frame
{
protected $template = 'board/export_orders.tpl';
}

View File

@@ -0,0 +1,19 @@
<?php
// ##############################################################
$main_class = 'ExportProductsBoard';
class ExportProductsBoard extends Frame
{
protected $template = 'board/export_products.tpl';
public function handle()
{
if (getVal('Submit')) {
$export = new ExportProducts();
$export->getFile();
exit('Done');
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
// ##############################################################
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
$main_class = 'ExportSellingProducts';
class ExportSellingProducts extends Frame
{
protected $template = 'board/export_selling_products.tpl';
public function handle()
{
if (getVal('Submit')) {
$export = ServiceContainer::getService(\KupShop\AdminBundle\Util\Export\ExportProductsSelling::class);
$export->exportXLS();
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
use KupShop\AdminBundle\Util\Export\ExportUsers;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
class ExportUsersBoard extends Frame
{
protected $template = 'board/export_users.tpl';
public function handle()
{
if (getVal('Submit')) {
$export = ServiceContainer::getService(ExportUsers::class);
$export->exportXLSX();
}
}
}
return ExportUsersBoard::class;

View File

@@ -0,0 +1,88 @@
<?php
use KupShop\KupShopBundle\Context\DomainContext;
use KupShop\KupShopBundle\Util\Contexts;
use KupShop\OrderingBundle\Util\Order\OrderInfo;
use Query\Operator;
$main_class = 'IndexBoard';
class IndexBoard extends Frame
{
protected $template = 'board/index.tpl';
public function get_vars()
{
$vars = parent::get_vars();
$stats = [];
$today = new DateTime('today');
$todayRange = new \Range($today->format('Y-m-d 00:00:00'), $today->format('Y-m-d 23:59:59'));
$orders = sqlQueryBuilder()->select('COUNT(id)')
->from('orders')
->andWhere('status_storno=0')
->andWhere(Operator::between('date_created', $todayRange))
->andWhere(Operator::not(Operator::equals(['source' => OrderInfo::ORDER_SOURCE_RETURNS])));
$stats['today_orders'] = $orders->execute()->fetchOne();
$total_price = (findModule(Modules::CURRENCIES) ? 'total_price * currency_rate' : 'total_price');
$orders->select("SUM({$total_price})");
$stats['today_price'] = $orders->execute()->fetchOne();
$stats['unfinished_orders'] = returnSQLResult("SELECT COUNT(*) FROM orders WHERE status='0' AND status_storno='0'");
$stats['total_products'] = returnSQLResult('SELECT COUNT(*) FROM products');
$yesterday = (new DateTime('yesterday'))->format('Y-m-d H:i:s');
$stats['errors_critical'] = sqlQueryBuilder()->select('COUNT(*)')
->from('report_activities')
->where('date > :date')
->andWhere(Operator::equals(['severity' => 'error']))
->andWhere(Operator::not(Operator::equals(['type' => 'sync'])))
->setParameter('date', getAdminUser()['date_check_error'] ?? $yesterday)
->execute()->fetchColumn();
$stats['errors_sync'] = sqlQueryBuilder()->select('COUNT(*)')
->from('report_activities')
->where('date > :date')
->andWhere(Operator::equals(['severity' => 'error']))
->andWhere(Operator::equals(['type' => 'sync']))
->setParameter('date', getAdminUser()['date_check_error'] ?? $yesterday)
->execute()->fetchColumn();
$stats['errors_recommendation'] = sqlQueryBuilder()->select('COUNT(*)')
->from('report_activities')
->where('date > :date')
->andWhere(Operator::equals(['severity' => 'recommendation']))
->setParameter('date', $yesterday)
->execute()->fetchColumn();
$links = [];
$mainDomain = Contexts::get(DomainContext::class)->getSupported()[0];
$domain = join('.', array_slice(explode('.', $mainDomain), -2));
if (strpos($domain, 'kupshop.cz') !== false || strpos($domain, 'wpj.biz') !== false || strpos($domain, 'wpj.cloud') !== false || strpos($domain, 'wpjshop.cz') !== false) {
$domain = join('.', array_slice(explode('.', $mainDomain), -3));
}
$hash = md5(date('Y-m-d').'wpj_wpj');
$hash = base64_encode(json_encode(['url' => 'https://'.$domain, 'hash' => $hash]));
$links['klient'] = "https://klient.wpj.cz/list/{$hash}";
$vars['stats'] = $stats;
$vars['links'] = $links;
if (isAutoDeploy()) {
$vars['deploy_time'] = filemtime(__FILE__);
}
$vars['changelog_time'] = getAdminUser()['date_check_changelog'] ?? (new DateTime('yesterday'))->format('c');
return $vars;
}
}

View File

@@ -0,0 +1,178 @@
<?php
$main_class = 'usersImport';
class UsersImport extends Frame
{
use DatabaseCommunication;
protected $template = 'board/usersImport.tpl';
protected $errs = [];
protected $info = [];
protected $added_users = [];
public function get_vars()
{
$vars = parent::get_vars();
$vars['errs'] = $this->errs;
$vars['info'] = $this->info;
$vars['added_users'] = $this->added_users;
return $vars;
}
public function handle()
{
$try = getVal('Try');
$execute = getVal('Execute');
global $cfg;
if (!empty($execute) || (!empty($try))) {
if (!empty($_FILES['file']['tmp_name'])) {
$path = $cfg['Path']['data'].'tmp/users_import.xsl';
move_uploaded_file($_FILES['file']['tmp_name'], $path);
// Increase memory for large files
ini_set('memory_limit', '512M');
$import = new AutomaticImportTransform($path);
$users_array = $import->LoadBinfileAsArray();
/*
* A = jméno
* B = přijmení
* C = společnost
* D = email
* E = telefon
* F = ulice
* G = město
* H = země
* I = psč
* J = skupiny
* K = newsletter
* L = ICO
* M = DIC
* N = delivery name
* O = delivery surname
* P = delivery firm
* Q = delivery street
* R = delivery city
* S = delivery zip
* T = delivery_country
*/
$errs = [];
$added = 0;
$price_levels = sqlFetchAll(sqlQueryBuilder()->select('id, name')->from('price_levels')->execute(), ['id' => 'name']);
foreach (reset($users_array) as $index => $user) {
if ($index == 1) {
continue;
}
if (!empty($user['D'])) {
if (filter_var($user['D'], FILTER_VALIDATE_EMAIL)) {
$groups = [];
if (!empty($user['K'])) {
$groups = explode(';', str_replace(' ', '', $user['K']));
}
$fields = ['figure' => 'N'];
if (!empty($user['A'])) {
$fields['name'] = $user['A'];
}
if (!empty($user['B'])) {
$fields['surname'] = $user['B'];
}
if (!empty($user['C'])) {
$fields['firm'] = $user['C'];
}
if (!empty($user['E'])) {
$fields['phone'] = $user['E'];
}
if (!empty($user['F'])) {
$fields['street'] = $user['F'];
}
if (!empty($user['G'])) {
$fields['city'] = $user['G'];
}
if (!empty($user['H'])) {
$fields['zip'] = $user['H'];
}
if (!empty($user['I'])) {
$fields['state'] = $user['I'];
}
if (!empty($user['J'])) {
$fields['country'] = $user['J'];
}
if (!empty($user['L'])) {
$fields['get_news'] = ($user['L'] == 'ano') ? 'Y' : 'N';
}
if (!empty($user['M'])) {
$fields['ico'] = $user['M'];
}
if (!empty($user['N'])) {
$fields['dic'] = $user['N'];
}
if (!empty($user['O'])) {
$fields['delivery_name'] = $user['O'];
}
if (!empty($user['P'])) {
$fields['delivery_surname'] = $user['P'];
}
if (!empty($user['Q'])) {
$fields['delivery_firm'] = $user['Q'];
}
if (!empty($user['R'])) {
$fields['delivery_street'] = $user['R'];
}
if (!empty($user['S'])) {
$fields['delivery_city'] = $user['S'];
}
if (!empty($user['T'])) {
$fields['delivery_zip'] = $user['T'];
}
if (!empty($user['U'])) {
$fields['delivery_state'] = $user['U'];
}
if (!empty($user['V'])) {
$fields['delivery_country'] = $user['V'];
}
$price_level = null;
if (!empty($user['W'])) { // cenová hladina
$price_level = array_search(trim($user['W']), $price_levels);
}
if (empty($try)) {
$confirmed = false;
if (getVal('newsletter_confirm')) {
$confirmed = true;
}
$user['id'] = addUserEmail($user['D'], $groups, $fields, $confirmed);
if ($price_level) {
sqlQuery("REPLACE INTO users_dealer_price_level (id_user, id_price_level)
VALUES ('{$user['id']}', '{$price_level}')");
}
} else {
$fields['email'] = $user['D'];
$fields['groups'] = $groups;
$fields['price_level'] = ($price_level ? $price_level.' - '.$user['W'] : '');
$this->added_users[] = $fields;
}
++$added;
} else {
$errs[$index] = "Nevalidní email {$user['D']}";
}
} else {
$errs[$index] = 'Prázdný email - uživatel nemůže být přidán';
}
}
$info['test'] = !empty($try) ? 1 : 2;
$info['added'] = $added;
$this->info = $info;
$this->errs = $errs;
}
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
$main_class = 'usersUnsubscribe';
class usersUnsubscribe extends Frame
{
use DatabaseCommunication;
protected $template = 'board/usersUnsubscribe.tpl';
public function handle()
{
$emails = getVal('emails');
$emails = array_filter(preg_split('/[\s;,]/i', mb_strtolower($emails)));
if ($emails) {
$count = sqlQueryBuilder()->update('users')
->set('get_news', '"N"')
->set('date_updated', 'NOW()')
->set('date_unsubscribe', 'NOW()')
->where(Query\Operator::inStringArray($emails, 'email'))
->execute();
$this->returnOK("Odhlášeno {$count} uživatelů");
}
}
}