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

fix: double invoice creation solved + a lot of dragons are here -.-

Übergeordneter 9864bb46
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -14,12 +14,16 @@
function ($orderId) {
// check if invoice is installed
QUI::getPackage('quiqqer/invoice');
QUI\ERP\Order\Settings::getInstance()->set('order', 'autoInvoicePost', 0);
QUI\ERP\Order\Settings::getInstance()->forceCreateInvoiceOn();
$Handler = QUI\ERP\Order\Handler::getInstance();
$Order = $Handler->get($orderId);
$Invoice = $Order->createInvoice();
QUI\ERP\Order\Settings::getInstance()->forceCreateInvoiceOff();
return $Invoice->getId();
},
['orderId'],
......
......@@ -15,8 +15,12 @@
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_backend_post',
function ($orderId) {
QUI\ERP\Order\Settings::getInstance()->forceCreateInvoiceOn();
$Order = QUI\ERP\Order\Handler::getInstance()->get($orderId);
$Invoice = $Order->post();
$Invoice = $Order->createInvoice();
QUI\ERP\Order\Settings::getInstance()->forceCreateInvoiceOff();
return $Invoice->getId();
},
......
......@@ -274,9 +274,10 @@ protected function setDataBaseData(array $data)
$this->successful = (int)$data['successful'];
$this->setAttributes([
'paid_status' => (int)$data['paid_status'],
'paid_data' => json_decode($data['paid_data'], true),
'paid_date' => $data['paid_date']
'paid_status' => (int)$data['paid_status'],
'paid_data' => json_decode($data['paid_data'], true),
'paid_date' => $data['paid_date'],
'temporary_invoice_id' => $data['temporary_invoice_id'],
]);
if (isset($data['payment_data'])) {
......
......@@ -42,6 +42,7 @@
{if $Invoice}
{assign var=Customer value=$Invoice->getCustomer()}
{$Invoice|get_class}
{else}
{assign var=Customer value=$Order->getCustomer()}
{/if}
......
......@@ -53,14 +53,22 @@ public function refresh()
/**
* It return the invoice, if an invoice exist for the order
*
* @return QUI\ERP\Accounting\Invoice\Invoice
* @return QUI\ERP\Accounting\Invoice\Invoice|QUI\ERP\Accounting\Invoice\InvoiceTemporary
*
* @throws QUI\Exception
* @throws QUI\ERP\Accounting\Invoice\Exception
*/
public function getInvoice()
{
return InvoiceHandler::getInstance()->getInvoice($this->invoiceId);
try {
return InvoiceHandler::getInstance()->getInvoice($this->invoiceId);
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
return InvoiceHandler::getInstance()->getTemporaryInvoice(
$this->getAttribute('temporary_invoice_id')
);
}
/**
......@@ -85,7 +93,8 @@ public function getView()
*/
public function createInvoice($PermissionUser = null)
{
if ($this->isPosted()) {
if (Settings::getInstance()->forceCreateInvoice() === false &&
$this->isPosted()) {
return $this->getInvoice();
}
......@@ -100,8 +109,12 @@ public function createInvoice($PermissionUser = null)
$PermissionUser = QUI::getUsers()->getUserBySession();
}
$InvoiceFactory = QUI\ERP\Accounting\Invoice\Factory::getInstance();
$TemporaryInvoice = $InvoiceFactory->createInvoice($PermissionUser, $this->getHash());
$InvoiceFactory = QUI\ERP\Accounting\Invoice\Factory::getInstance();
$TemporaryInvoice = $InvoiceFactory->createInvoice(
QUI::getUserBySession(),
$this->getHash()
);
QUI::getDataBase()->update(
Handler::getInstance()->table(),
......@@ -176,6 +189,7 @@ public function createInvoice($PermissionUser = null)
$TemporaryInvoice->getId()
);
$this->setAttribute('temporary_invoice_id', $TemporaryInvoice->getId());
$TemporaryInvoice->validate();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
......@@ -208,10 +222,22 @@ public function createInvoice($PermissionUser = null)
*/
public function isPosted()
{
if (!$this->invoiceId) {
if (!$this->invoiceId && !$this->getAttribute('temporary_invoice_id')) {
return false;
}
if (!$this->invoiceId && $this->getAttribute('temporary_invoice_id')) {
try {
InvoiceHandler::getInstance()->getTemporaryInvoice(
$this->getAttribute('temporary_invoice_id')
);
return true;
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
try {
$this->getInvoice();
} catch (QUI\Exception $Exception) {
......
......@@ -216,10 +216,12 @@ protected function calculatePayments()
['id' => $this->getId()]
);
$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) {
$this->createOrder(QUI::getUsers()->getSystemUser());
$Order = $this->createOrder();
}
// Payment Status has changed
......@@ -229,7 +231,7 @@ protected function calculatePayments()
QUI::getEvents()->fireEvent(
'onQuiqqerOrderPaymentStatusChanged',
[$this, $calculations['paidStatus'], $oldPaidStatus]
[$Order, $calculations['paidStatus'], $oldPaidStatus]
);
QUI\ERP\Debug::getInstance()->log(
......@@ -359,11 +361,15 @@ public function createOrder($PermissionUser = null)
// create invoice?
if (Settings::getInstance()->createInvoiceOnOrder()) {
$Order->createInvoice($SystemUser);
return $Order;
}
if (Settings::getInstance()->createInvoiceByPayment()
&& $Order->getPayment()->isSuccessful($Order->getHash())) {
$Order->createInvoice($SystemUser);
return $Order;
}
if (Settings::getInstance()->createInvoiceByPayment()
......@@ -382,11 +388,11 @@ public function createOrder($PermissionUser = null)
*/
protected function hasPermissions($PermissionUser = null)
{
if ($this->cUser === QUI::getUserBySession()->getId()) {
return true;
if ($PermissionUser === null) {
$PermissionUser = QUI::getUserBySession();
}
if ($PermissionUser && $this->cUser === $PermissionUser->getId()) {
if ($this->cUser === $PermissionUser->getId()) {
return true;
}
......@@ -394,6 +400,10 @@ protected function hasPermissions($PermissionUser = null)
return true;
}
if ($PermissionUser->isSU()) {
return true;
}
//@todo permissions prüfen
return false;
......
......@@ -21,6 +21,11 @@ class Settings extends QUI\Utils\Singleton
*/
protected $isInvoiceInstalled = null;
/**
* @var bool
*/
protected $forceCreateInvoice = false;
/**
* @var array
*/
......@@ -164,5 +169,35 @@ public function createInvoiceByPayment()
return $Config->get('order', 'autoInvoice') === 'byPayment';
}
/**
* should invoice creation still be executed even if an invoice already exists?
*
* @return bool
*/
public function forceCreateInvoice()
{
if ($this->isInvoiceInstalled() === false) {
return false;
}
return $this->forceCreateInvoice;
}
/**
* Set force create invoice on
*/
public function forceCreateInvoiceOn()
{
$this->forceCreateInvoice = true;
}
/**
* Set force create invoice off
*/
public function forceCreateInvoiceOff()
{
$this->forceCreateInvoice = false;
}
//endregion
}
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