Skip to content
Code-Schnipsel Gruppen Projekte
Commit ad2d5749 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix: invoice#29; feat: new transaction events implemented

Übergeordneter 6f8c2e7a
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -24,4 +24,7 @@
fire="\QUI\ERP\Order\EventHandling::onQuiqqerInvoiceTemporaryInvoicePostEnd"
/>
<event on="onTransactionStatusChange"
fire="\QUI\ERP\Order\EventHandling::onTransactionStatusChange"
/>
</events>
\ No newline at end of file
......@@ -1032,6 +1032,7 @@ public function addTransaction(Transaction $Transaction)
if ($this->getAttribute('paid_status') == self::PAYMENT_STATUS_PAID ||
$this->getAttribute('paid_status') == self::PAYMENT_STATUS_CANCELED
) {
$this->getAttribute('paid_status', self::PAYMENT_STATUS_OPEN);
$this->calculatePayments();
return;
......@@ -1149,7 +1150,7 @@ public function getPayments()
/**
* Return all transactions related to the order
*
* @return array
* @return Transaction[]
*/
public function getTransactions()
{
......
......@@ -102,7 +102,7 @@ public function __construct($orderHash, $User = false)
$this->id = $Basket->getId();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
QUI\System\Log::writeDebugException($Exception);
}
}
......
......@@ -171,6 +171,50 @@ public static function onTransactionCreate(Transaction $Transaction)
}
}
/**
* @param Transaction $Transaction
*/
public static function onTransactionStatusChange(Transaction $Transaction)
{
$Order = null;
try {
$Order = Handler::getInstance()->getOrderByGlobalProcessId(
$Transaction->getGlobalProcessId()
);
} catch (QUI\Exception $Exception) {
}
if ($Order === null && $Transaction->getHash() !== '') {
try {
$Order = Handler::getInstance()->getOrderByHash(
$Transaction->getHash()
);
} catch (QUI\Exception $Exception) {
}
if ($Order === null) {
try {
$Order = Handler::getInstance()->getOrderInProcessByHash(
$Transaction->getHash()
);
} catch (QUI\Exception $Exception) {
}
}
}
if ($Order === null) {
return;
}
try {
$Order->setAttribute('paid_status', Order::PAYMENT_STATUS_OPEN);
$Order->calculatePayments();
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
/**
* @param QUI\ERP\Accounting\Invoice\InvoiceTemporary $InvoiceTemporary
* @param QUI\ERP\Accounting\Invoice\Invoice $Invoice
......
......@@ -273,8 +273,7 @@ protected function calculatePayments()
$Order = $this;
// create order, if the payment status is paid and no order exists
if ($this->getAttribute('paid_status') === self::PAYMENT_STATUS_PAID
&& !$this->orderId) {
if ($this->getAttribute('paid_status') === self::PAYMENT_STATUS_PAID && !$this->orderId) {
$Order = $this->createOrder();
}
......@@ -391,7 +390,13 @@ public function createOrder($PermissionUser = null)
QUI\ERP\Debug::getInstance()->log('OrderInProcess:: Order calculatePayments');
try {
// reset & recalculation
$Order->setAttribute('paid_status', QUI\ERP\Accounting\Invoice\Invoice::PAYMENT_STATUS_OPEN);
$Order->calculatePayments();
if ($data['paid_status'] !== $Order->getAttribute('paid_status')) {
$Order->save();
}
} catch (QUI\Exception $Exception) {
if (defined('QUIQQER_DEBUG')) {
QUI\System\Log::writeException($Exception);
......
......@@ -661,7 +661,17 @@ protected function checkProcessing()
// show processing step if order is not paid
if ($Order instanceof Order && !$Order->isPaid()) {
return $render();
// if a payment transaction exists, maybe the transaction is in pending
// as long as, the order is "successful"
$transactions = $Order->getTransactions();
$isInPending = array_filter($transactions, function ($Transaction) {
/* @var $Transaction QUI\ERP\Accounting\Payments\Transactions\Transaction */
return $Transaction->isPending();
});
if (!$isInPending) {
return $render();
}
}
if ($Finish->getName() === $Current->getName()
......
......@@ -525,6 +525,10 @@ protected function parseListForGrid($data)
$paid = array_map(function ($Transaction) {
/* @var $Transaction QUI\ERP\Accounting\Payments\Transactions\Transaction */
if ($Transaction->isPending()) {
return 0;
}
return $Transaction->getAmount();
}, $transactions);
......
<?php
try {
$OrderProcess = new QUI\ERP\Order\OrderProcess(array(
$OrderProcess = new QUI\ERP\Order\OrderProcess([
'step' => $Site->getAttribute('order::step'),
'orderHash' => $Site->getAttribute('order::hash')
));
]);
$Engine->assign(array(
$Engine->assign([
'OrderProcess' => $OrderProcess
));
]);
} catch (QUI\DataBase\Exception $Exception) {
$ExceptionReplacement = new QUI\Exception(['quiqqer/quiqqer', 'exception.error']);
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren