46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace External\HannahBundle\Resources\script;
|
|
|
|
use KupShop\AdminBundle\Util\Script\Script;
|
|
|
|
class FixInvoiceNumberSAP extends Script
|
|
{
|
|
protected static $name = '[HANNAH] FIX SAP INVOICE NUMBER';
|
|
protected static $defaultParameters = [];
|
|
|
|
protected function run(array $arguments)
|
|
{
|
|
$this->log('Starting...');
|
|
$this->fix();
|
|
$this->log('Done');
|
|
}
|
|
|
|
// fix
|
|
private function fix()
|
|
{
|
|
$orders = $this->getData();
|
|
// projít dané objednávky přes json_decode a přidat do json sapInvoiceNumber hodnotu z sapInvoiceNumbers
|
|
foreach ($orders as $orderFromDB) {
|
|
$decodedJson = json_decode($orderFromDB['note_admin'], true);
|
|
$order = new \Order($orderFromDB['id']);
|
|
// $order->setData
|
|
$order->setData('sapInvoiceNumber', end($decodedJson['sapInvoiceNumbers']));
|
|
$this->log("Přidán sapInvoiceNumber pro objednávku {$orderFromDB['id']}");
|
|
}
|
|
}
|
|
|
|
private function getData()
|
|
{
|
|
$ordersWithoutsapInvoiceNumber = sqlQueryBuilder()->select('id,note_admin')
|
|
->from('orders')
|
|
->andWhere('date_created > "2024-10-01 00:00:00"')
|
|
->andWhere('JSON_EXTRACT(note_admin, "$.sapInvoiceNumbers") IS NOT NULL AND JSON_EXTRACT(note_admin, "$.sapInvoiceNumber") IS NULL')
|
|
->execute()->fetchAll();
|
|
|
|
return $ordersWithoutsapInvoiceNumber;
|
|
}
|
|
}
|
|
|
|
return FixInvoiceNumberSAP::class;
|