Skip to content
Code-Schnipsel Gruppen Projekte
Commit d387be0d erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

feat: open items management erp#41

Übergeordneter c1e7e559
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -164,6 +164,7 @@ function ($userId, $searchParams, $forceRefresh) {
);
$items[] = [
'documentId' => $Item->getDocumentId(),
'documentNo' => $Item->getDocumentNo(),
'documentType' => $documentType,
'documentTypeTitle' => $documentTypeTitle,
......
......@@ -39,9 +39,11 @@ function ($searchParams) {
return [
'grid' => [],
'totals' => [
'display_gross_toPay' => '',
'display_gross_paid' => '',
'display_gross_total' => ''
'display_net' => 0,
'display_vat' => 0,
'display_gross' => 0,
'display_paid' => 0,
'display_open' => 0
]
];
}
......
......@@ -177,6 +177,7 @@
.openItems-total {
background-color: #efefef;
border-top: 1px dotted black;
height: 80px;
padding: 20px;
text-align: right;
......
......@@ -81,6 +81,7 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
this.$currentRecordsUserId = false;
this.$UserRecordsSearch = null;
this.$currentUserRecordsSearch = '';
this.$refreshTotalsOnly = false;
this.addEvents({
onCreate: this.$onCreate,
......@@ -116,12 +117,14 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
search : this.$currentSearch,
currency: this.$Currency.getAttribute('value')
}).then(function (result) {
result.grid.data = result.grid.data.map(function (entry) {
return self.$parseGridRow(entry);
});
if (!this.$refreshTotalsOnly) {
result.grid.data = result.grid.data.map(function (entry) {
return self.$parseGridRow(entry);
});
this.$Grid.setData(result.grid);
this.$refreshButtonStatus();
this.$Grid.setData(result.grid);
this.$refreshButtonStatus();
}
this.$Total.set(
'html',
......@@ -135,6 +138,7 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
);
this.$currentRecordsUserId = null;
this.$refreshTotalsOnly = false;
this.Loader.hide();
}.bind(this)).catch(function (err) {
......@@ -161,12 +165,18 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
var Entry = entries[i];
if (Entry.userId === userId) {
self.$Grid.setDataByRow(i, self.$parseGridRow(result.grid.data[0]));
if (!result.grid.data.length) {
self.$Grid.deleteRow(i);
} else {
self.$Grid.setDataByRow(i, self.$parseGridRow(result.grid.data[0]));
}
break;
}
}
this.Loader.hide();
this.$refreshTotalsOnly = true;
this.refresh();
}.bind(this)).catch(function (err) {
console.error(err);
this.Loader.hide();
......@@ -830,6 +840,10 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
dataIndex: 'documentType',
dataType : 'string',
hidden : true
}, {
dataIndex: 'documentId',
dataType : 'string',
hidden : true
}]
});
......@@ -925,7 +939,22 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
break;
case 'Order':
// @todo
require(['package/quiqqer/order/bin/backend/Orders'], function (Orders) {
Orders.addPaymentToOrder(
Row.documentId,
Data.amount,
Data.payment_method,
Data.date
).then(function () {
Win.close();
self.$refreshUserEntry(self.$currentRecordsUserId).then(function () {
self.$refreshUserRecords(self.$GridDetails, true);
});
}).catch(function (err) {
Win.Loader.hide();
});
});
break;
}
};
......@@ -964,7 +993,13 @@ define('package/quiqqer/customer/bin/backend/controls/OpenItems/OpenItems', [
break;
case 'order':
// @todo
require(['package/quiqqer/order/bin/backend/controls/panels/Orders'], function (Orders) {
var Handler = new Orders();
Handler.openOrder(Row.documentId).then(function () {
self.Loader.hide();
});
});
break;
default:
......
......@@ -9,7 +9,9 @@
/>
<!-- Open items -->
<event on="onTransactionCreate" fire="\QUI\ERP\Customer\OpenItemsList\Events::onTransactionCreate"/>
<event on="onTransactionCreate" fire="\QUI\ERP\Customer\OpenItemsList\Events::onTransactionCreate" priority="500"/>
<event on="onQuiqqerInvoicePaymentStatusChanged" fire="\QUI\ERP\Customer\OpenItemsList\Events::onQuiqqerInvoicePaymentStatusChanged" />
<event on="onQuiqqerOrderPaidStatusChanged" fire="\QUI\ERP\Customer\OpenItemsList\Events::onQuiqqerOrderPaidStatusChanged" />
<event on="onQuiqqerInvoiceTemporaryInvoicePostEnd" fire="\QUI\ERP\Customer\OpenItemsList\Events::onQuiqqerInvoiceTemporaryInvoicePostEnd"/>
<event on="onQuiqqerOrderCreated" fire="\QUI\ERP\Customer\OpenItemsList\Events::onQuiqqerOrderCreated"/>
......
......@@ -7,6 +7,7 @@
use QUI\ERP\Accounting\Invoice\InvoiceTemporary;
use QUI\ERP\Accounting\Invoice\Invoice;
use QUI\ERP\Order\Settings;
use QUI\ERP\Order\Order;
/**
* Class Events
......@@ -45,6 +46,64 @@ public static function onTransactionCreate(Transaction $Transaction)
}
}
/**
* quiqqer/invoice: onQuiqqerInvoicePaymentStatusChanged
*
* Update open records of user if a transaction was made against one of his open items
*
* @param Invoice $Invoice
* @param int $currentStatus
* @param int $oldStatus
* @return void
*/
public static function onQuiqqerInvoicePaymentStatusChanged(
Invoice $Invoice,
int $currentStatus,
int $oldStatus
) {
try {
$User = $Invoice->getCustomer();
} catch (\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return;
}
try {
Handler::updateOpenItemsRecord($User);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
/**
* quiqqer/order: onQuiqqerOrderPaidStatusChanged
*
* Update open records of user if a transaction was made against one of his open items
*
* @param Order $Order
* @param int $currentStatus
* @param int $oldStatus
* @return void
*/
public static function onQuiqqerOrderPaidStatusChanged(
Order $Order,
int $currentStatus,
int $oldStatus
) {
try {
$User = $Order->getCustomer();
} catch (\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return;
}
try {
Handler::updateOpenItemsRecord($User);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
/**
* quiqqer/invoice: onQuiqqerInvoiceTemporaryInvoicePostEnd
*
......
......@@ -98,7 +98,8 @@ protected static function getOpenInvoices(QUI\Interfaces\Users\User $User)
'type' => 'NOT IN',
'value' => [
QUI\ERP\Constants::PAYMENT_STATUS_PAID,
QUI\ERP\Constants::PAYMENT_STATUS_CANCELED
QUI\ERP\Constants::PAYMENT_STATUS_CANCELED,
QUI\ERP\Constants::PAYMENT_STATUS_DEBIT
]
],
// 'time_for_payment' => [
......@@ -114,6 +115,13 @@ protected static function getOpenInvoices(QUI\Interfaces\Users\User $User)
foreach ($result as $row) {
try {
$Invoice = $Invoices->get($row['id']);
// Filter invoices that are considered paid (even if not in database)
if ($Invoice->isPaid()) {
continue;
}
$invoices[] = $Invoices->get($row['id']);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
......@@ -131,7 +139,7 @@ protected static function getOpenInvoices(QUI\Interfaces\Users\User $User)
*/
protected static function parseInvoiceToOpenItem(Invoice $Invoice)
{
$Item = new Item(self::DOCUMENT_TYPE_INVOICE);
$Item = new Item($Invoice->getCleanId(), self::DOCUMENT_TYPE_INVOICE);
// Basic data
$Item->setDocumentNo($Invoice->getId());
......@@ -225,6 +233,7 @@ protected static function getOpenOrders(QUI\Interfaces\Users\User $User)
'value' => [
QUI\ERP\Constants::PAYMENT_STATUS_PAID,
QUI\ERP\Constants::PAYMENT_STATUS_CANCELED,
QUI\ERP\Constants::PAYMENT_STATUS_DEBIT,
QUI\ERP\Constants::PAYMENT_STATUS_PLAN
]
],
......@@ -254,7 +263,7 @@ protected static function getOpenOrders(QUI\Interfaces\Users\User $User)
*/
protected static function parseOrderToOpenItem(QUI\ERP\Order\Order $Order)
{
$Item = new Item(self::DOCUMENT_TYPE_ORDER);
$Item = new Item($Order->getCleanId(), self::DOCUMENT_TYPE_ORDER);
// Basic data
$Item->setDocumentNo($Order->getPrefixedId());
......
......@@ -23,6 +23,11 @@ class Item
*/
protected $description = '';
/**
* @var int|string
*/
protected $documentId;
/**
* @var string
*/
......@@ -101,10 +106,12 @@ class Item
/**
* Item constructor.
*
* @param int|string $documentId - Internal document id
* @param string $documentType - Type of document (e.g. invoice, order etc.)
*/
public function __construct(string $documentType)
public function __construct($documentId, string $documentType)
{
$this->documentId = $documentId;
$this->documentType = $documentType;
}
......@@ -194,6 +201,14 @@ public function setLocale(Locale $Locale)
$this->Locale = $Locale;
}
/**
* @return int|string
*/
public function getDocumentId()
{
return $this->documentId;
}
/**
* @return string
*/
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren