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,88 @@
<?php
namespace KupShop\OrderingBundle;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use Query\Operator;
use Query\QueryBuilder;
class OrdersItemsExcelExport extends OrdersExcelExport
{
protected $ORDERS_ITEMS_LIMIT = 1000000;
protected function prepareFields()
{
$fields = parent::prepareFields();
unset($fields['items']);
$arrayFields = ['item_descr' => [
'spec' => function (QueryBuilder $qb) {
$qb->leftJoin('o', 'order_items', 'oi', 'oi.id_order = o.id')
->leftJoin('oi', 'products', 'p', 'p.id = oi.id_product')
->leftJoin('oi', 'products_variations', 'pv', 'pv.id = oi.id_variation')
->groupBy('o.id, oi.id')
->addOrderBy('oi.id');
return 'oi.descr AS item_descr';
},
'name' => 'Položka',
'width' => 16,
],
'item_code' => ['field' => Operator::coalesce(findModule(\Modules::PRODUCTS_VARIATIONS, \Modules::SUB_CODE) ? 'pv.code' : null, 'p.code').' AS item_code', 'name' => 'Kód'],
'item_ean' => ['field' => Operator::coalesce(findModule(\Modules::PRODUCTS_VARIATIONS, \Modules::SUB_CODE) ? 'pv.ean' : null, 'p.ean').' AS item_ean', 'name' => 'EAN'],
'item_total_price' => ['field' => 'oi.total_price * (oi.tax + 100) / 100 AS item_total_price', 'name' => 'Cena s DPH', 'type' => DataType::TYPE_NUMERIC, 'format' => '0.00'],
'item_pieces' => ['field' => 'oi.pieces AS item_pieces', 'name' => 'Kusů', 'type' => DataType::TYPE_NUMERIC],
'item_piece_price' => ['field' => 'oi.piece_price * (oi.tax + 100) / 100 AS item_piece_price', 'name' => 'Cena za kus s DPH', 'type' => DataType::TYPE_NUMERIC, 'format' => '0.00'],
'item_tax' => ['field' => 'oi.tax AS item_tax', 'name' => 'DPH', 'type' => DataType::TYPE_NUMERIC],
'item_total_price_without_discounts' => ['field' => 'oi.note', 'name' => 'Cena s DPH před slevou', 'type' => DataType::TYPE_NUMERIC, 'format' => '0.00'],
'item_discounts' => ['field' => 'oi.note', 'name' => 'Slevy na položce', 'format' => '0.00'],
];
if (findModule(\Modules::PRODUCTS, \Modules::SUB_PRICE_BUY)) {
$arrayFields['item_price_buy'] = ['field' => 'COALESCE(oi.price_buy, pv.price_buy, p.price_buy, 0) as item_price_buy', 'name' => 'Nákupní cena', 'type' => DataType::TYPE_NUMERIC];
}
$fields = array_merge($fields, $arrayFields);
return $fields;
}
protected function prepareRow($row, \Order $order): array
{
$row = parent::prepareRow($row, $order);
$row['item_total_price_without_discounts'] = $this->renderOrderItemPriceWithoutDiscounts($row);
$row['item_discounts'] = $this->renderOrderItemDiscounts($row);
return $row;
}
protected function renderOrderItemPriceWithoutDiscounts(array $row): string
{
if (!empty($row['note'])) {
$note = json_decode($row['note'] ?? '', true) ?: [];
if (!empty($note['priceWithoutDiscounts'])) {
return $note['priceWithoutDiscounts'];
}
}
return $row['item_total_price'] ?: '';
}
protected function renderOrderItemDiscounts(array $row): string
{
if (!empty($row['note'])) {
$note = json_decode($row['note'] ?? '', true) ?: [];
$discounts = [];
foreach ($note['discounts'] ?? [] as $discount) {
$discountPrice = toDecimal((float) $discount['discountPrice'])->addVat($row['item_tax']);
$discountPrice = number_format($discountPrice->asFloat(), 2, '.', '');
$discounts[] = $discount['name'].': '.$discountPrice;
}
return implode(';', $discounts);
}
return '';
}
}