Files
kupshop/admin/lists/PosList.php
2025-08-02 16:30:27 +02:00

97 lines
3.1 KiB
PHP

<?php
use KupShop\AdminBundle\AdminList\BaseList;
class PosList extends BaseList
{
protected $template = 'list/pos.tpl';
public function __construct()
{
if (getVal('pagedivide') != '') {
$this->pageDivide = getVal('pagedivide');
}
}
protected $tableDef = [
'id' => 'id',
'fields' => [
'ID' => ['field' => 'pos.id', 'size' => 1],
'Datum' => ['field' => 'date', 'size' => 2.2, 'render' => 'renderTimestamp'],
'Objednávka' => ['field' => 'id_order', 'size' => 1, 'type' => 'order', 'type_id' => 'id_order'],
'Přijato' => ['field' => 'price', 'render' => 'renderShowInserted', 'size' => 1.3],
'Vydáno' => ['field' => 'price', 'render' => 'renderShowChoosed', 'size' => 1.3],
'Typ platby' => ['field' => 'method', 'render' => 'renderPayMethod', 'size' => 1],
'Popis' => ['field' => 'note', 'size' => 3],
'Zpracoval' => ['field' => 'admin', 'size' => 1],
],
'class' => 'getRowClass',
];
public function renderShowInserted($values, $column)
{
$price = $this->getListRowValue($values, $column['field']);
if ($price > 0) {
return $this->renderPrice($values, $column);
}
}
public function renderShowChoosed($values, $column)
{
$price = $this->getListRowValue($values, $column['field']);
if ($price < 0) {
$values['price'] = $price * -1;
return $this->renderPrice($values, $column);
}
}
public function renderTimestamp($values, $column)
{
$timestamp = $this->getListRowValue($values, $column['field']);
$days = ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota', 'Neděle'];
return $days[date('N', $timestamp) - 1].' '.date('j.n.Y H:i:s', $timestamp);
}
public function getRowClass($values)
{
return ($values['price'] > 0) ? 'row-green' : 'row-red';
}
public function renderPayMethod($values, $column)
{
$method = $this->getListRowValue($values, $column['field']);
switch ($method) {
case '1':
return 'Hotově';
case '2':
return 'Kartou';
case '3':
return 'Na fakturu';
default:
return '';
}
}
public function getQuery()
{
$qb = sqlQueryBuilder()
->select('pos.id', 'pos.note', 'pos.price', 'a.login as admin', 'pos.method', 'pos.id_order', 'UNIX_TIMESTAMP(date) AS date')
->from('order_payments', 'pos')
->leftJoin('pos', 'admins', 'a', 'pos.admin=a.id');
$method = getVal('method');
if (!empty($method)) {
$qb->where('pos.method = ?')->setParameter(0, $method);
}
$qb2 = sqlQueryBuilder()->select('SUM(price) as in_pos')->from('order_payments')->where('method=1 OR method=4 OR method=5');
$SQL = $qb2->execute();
$var['in_pos'] = sqlFetchArray($SQL)['in_pos'];
return ['qb' => $qb, 'in_pos' => $var['in_pos']];
}
}