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

refactor: global process representation; cleanup -> cash input deprecated classes removed

Übergeordneter a7e4ca29
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
<?xml version="1.0" encoding="UTF-8"?>
<database>
<global>
<table name="payments_cash_inputs">
<field type="BIGINT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY">id</field>
<field type="BIGINT(20) NULL">orderId</field>
<field type="BIGINT(20) NULL">orderInProcessId</field>
<field type="BIGINT(20) NULL">invoiceId</field>
<field type="BIGINT(20) NULL">invoiceTemporaryId</field>
<field type="DOUBLE NULL">amount</field>
<field type="timestamp NULL default NULL">date</field>
<field type="TEXT NULL">currencyData</field>
<field type="TEXT NULL">user</field>
<table name="process">
<field type="VARCHAR(250) NOT NULL">id</field>
<field type="TEXT NULL">history</field>
<primary>id</primary>
<auto_increment>id</auto_increment>
</table>
</global>
</database>
\ No newline at end of file
......@@ -92,12 +92,19 @@ public function toArray()
* Add a comment
*
* @param string $message
* @param int|false $time - optional, unix timestamp
*/
public function addComment($message)
public function addComment($message, $time = false)
{
if ($time === false) {
$time = time();
}
$message = QUI\Utils\Security\Orthos::clearFormRequest($message);
$this->comments[] = [
'message' => $message,
'time' => time()
'time' => (int)$time
];
}
......
<?php
/**
* This file contains QUI\ERP\Payments\CashInput
*/
namespace QUI\ERP\Payments;
use QUI;
use QUI\Interfaces\Users\User;
/**
* Class CashInput
*
* @package QUI\ERP\Payments
*/
class CashInput
{
/**
* @var null|QUI\ERP\Accounting\Invoice\Invoice
*/
protected $Invoice = null;
/**
* @var null|QUI\ERP\Accounting\Invoice\InvoiceTemporary
*/
protected $InvoiceTemporary = null;
/**
* @var null|QUI\ERP\Order\Order
*/
protected $Order = null;
/**
* @var null|QUI\ERP\Order\OrderInProcess
*/
protected $OrderInProgress = null;
/**
* @var null|User
*/
protected $User = null;
/**
* @var null|QUI\ERP\Currency\Currency
*/
protected $Currency = null;
/**
* @var double
*/
protected $amount = 0;
/**
* @var int
*/
protected $date;
/**
* CashInput constructor.
*/
public function __construct()
{
$this->Currency = QUI\ERP\Currency\Handler::getDefaultCurrency();
}
//region getter
/**
* Return the current amount of the cash input
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* Return the currency of the cash input
*
* @return null|QUI\ERP\Currency\Currency
*/
public function getCurrency()
{
return $this->Currency;
}
/**
* Returns the invoice which is associated with the cash input
*
* @return null|QUI\ERP\Accounting\Invoice\Invoice
*/
public function getInvoice()
{
return $this->Invoice;
}
/**
* Returns the invoice which is associated with the cash input
*
* @return null|QUI\ERP\Accounting\Invoice\InvoiceTemporary
*/
public function getInvoiceTemporary()
{
return $this->InvoiceTemporary;
}
/**
* Returns the order which is associated with the cash input
*
* @return null|QUI\ERP\Order\Order
*/
public function getOrder()
{
return $this->Order;
}
/**
* Returns the order which is associated with the cash input
*
* @return null|QUI\ERP\Order\OrderInProcess
*/
public function getOrderInProgress()
{
return $this->OrderInProgress;
}
/**
* @return null|User
*/
public function getUser()
{
return $this->User;
}
//endregion
//region setter
/**
* @param $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}
/**
* @param QUI\ERP\Currency\Currency $Currency
*/
public function setCurrency(QUI\ERP\Currency\Currency $Currency)
{
$this->Currency = $Currency;
}
/**
* @param int $date
*/
public function setDate($date)
{
$this->date = $date;
}
/**
* @param QUI\ERP\Accounting\Invoice\Invoice $Invoice
*/
public function setInvoice(QUI\ERP\Accounting\Invoice\Invoice $Invoice)
{
$this->Invoice = $Invoice;
}
/**
* @param QUI\ERP\Accounting\Invoice\InvoiceTemporary $Invoice
*/
public function setInvoiceTemporary(QUI\ERP\Accounting\Invoice\InvoiceTemporary $Invoice)
{
$this->InvoiceTemporary = $Invoice;
}
/**
* @param QUI\ERP\Order\Order $Order
*/
public function setOrder(QUI\ERP\Order\Order $Order)
{
$this->Order = $Order;
}
/**
* @param QUI\ERP\Order\OrderInProcess $Order
*/
public function setOrderInProgress(QUI\ERP\Order\OrderInProcess $Order)
{
$this->OrderInProgress = $Order;
}
/**
* @param User $User
*/
public function setUser(User $User)
{
$this->User = $User;
}
//endregion
/**
* Return the cash input as an array
* This array fits as database values
*
* @return array
*/
public function toArray()
{
// defaults
$user = '';
$orderId = '';
$orderInProcessId = '';
$invoiceId = '';
$invoiceTemporaryId = '';
if ($this->Order !== null) {
$orderId = $this->Order->getId();
}
if ($this->OrderInProgress !== null) {
$orderInProcessId = $this->OrderInProgress->getId();
}
if ($this->Invoice !== null) {
$invoiceId = $this->Invoice->getId();
}
if ($this->InvoiceTemporary !== null) {
$invoiceTemporaryId = $this->InvoiceTemporary->getId();
}
if ($this->User !== null) {
$user = $this->User->getAttributes();
}
return [
'orderId' => $orderId,
'orderInProcessId' => $orderInProcessId,
'invoiceId' => $invoiceId,
'invoiceTemporaryId' => $invoiceTemporaryId,
'amount' => $this->amount,
'date' => $this->date,
'currencyData' => $this->Currency->toArray(),
'user' => $user,
];
}
}
<?php
/**
* This file contains QUI\ERP\Payments\CashInputs
*/
namespace QUI\ERP\Payments;
use QUI;
use QUI\ERP\Currency\Handler as Currencies;
use QUI\ERP\Order\Order;
use QUI\ERP\Order\OrderInProcess;
use QUI\ERP\Accounting\Invoice\Invoice;
use QUI\ERP\Accounting\Invoice\InvoiceTemporary;
/**
* Class CashInputs
*
* @deprecated wird abgelöst von Transactions
* @package QUI\ERP\Payments
*/
class CashInputs extends QUI\Utils\Singleton
{
/**
* Return the payments cash inputs table name
*
* @return string
*/
public function table()
{
return QUI::getDBTableName('payments_cash_inputs');
}
/**
* Add a payment amount to specific object
*
* @param CashInput $CashInput
* @param Order|OrderInProcess|Invoice|InvoiceTemporary $Parent
*/
public function addPayment(CashInput $CashInput, $Parent)
{
QUI::getDataBase()->insert(
$this->table(),
$CashInput->toArray()
);
}
/**
* @param Invoice $Invoice
* @return array
*/
public function getPaymentsFromInvoice(Invoice $Invoice)
{
$result = QUI::getDataBase()->fetch([
'from' => $this->table(),
'where' => [
'invoiceId' => $Invoice->getId(),
],
]);
return $this->parseResult($result);
}
/**
* @param $Order
* @return array
*/
public function getPaymentsFromOrder(Order $Order)
{
$result = QUI::getDataBase()->fetch([
'from' => $this->table(),
'where' => [
'orderId' => $Order->getId(),
],
]);
return $this->parseResult($result);
}
/**
* @param array $result
* @return array
*/
protected function parseResult(array $result)
{
$cashInputs = [];
foreach ($result as $entry) {
$cashInputs[] = $this->parseDataToCashInput($entry);
}
return $cashInputs;
}
/**
* Parse database data from a cash input to a cash input object
*
* @param array $data
* @return CashInput
*/
protected function parseDataToCashInput($data)
{
$CashInput = new CashInput();
$Packages = QUI::getPackageManager();
if (isset($data['amount'])) {
$CashInput->setAmount($data['amount']);
}
// currency
if (isset($data['currency'])) {
$currency = $data['currency'];
$Currency = Currencies::getDefaultCurrency();
if (is_string($currency)) {
$currency = json_decode($currency, true);
}
if (is_array($currency) && isset($currency['code'])) {
$Currency = Currencies::getCurrency($currency['code']);
}
$CashInput->setCurrency($Currency);
}
// user
if (isset($data['user'])) {
$userData = $data['user'];
if (is_string($userData)) {
$userData = json_decode($userData, true);
}
try {
$User = QUI\ERP\User::convertUserDataToErpUser($userData);
$CashInput->setUser($User);
} catch (QUI\Exception $Exception) {
}
}
// order
if (isset($data['orderId'])
&& $Packages->isInstalled('quiqqer/order')) {
try {
$Orders = QUI\ERP\Order\Handler::getInstance();
$Order = $Orders->get($data['orderId']);
$CashInput->setOrder($Order);
} catch (QUI\Exception $Exception) {
}
}
// order in process
if (isset($data['orderInProcessId'])
&& $Packages->isInstalled('quiqqer/order')) {
try {
$Orders = QUI\ERP\Order\Handler::getInstance();
$Order = $Orders->getOrderInProcess($data['orderInProcessId']);
$CashInput->setOrderInProgress($Order);
} catch (QUI\Exception $Exception) {
}
}
// invoice
if (isset($data['invoiceId'])
&& $Packages->isInstalled('quiqqer/invoice')) {
try {
$Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance();
$Invoice = $Invoices->getInvoice($data['invoiceId']);
$CashInput->setInvoice($Invoice);
} catch (QUI\Exception $Exception) {
}
}
// invoice temporary
if (isset($data['invoiceTemporaryId'])
&& $Packages->isInstalled('quiqqer/invoice')) {
try {
$Invoices = QUI\ERP\Accounting\Invoice\Handler::getInstance();
$Invoice = $Invoices->getTemporaryInvoice($data['invoiceTemporaryId']);
$CashInput->setInvoiceTemporary($Invoice);
} catch (QUI\Exception $Exception) {
}
}
return $CashInput;
}
}
......@@ -7,10 +7,10 @@
namespace QUI\ERP;
use QUI;
use QUI\Permissions\Permission;
/**
* Class Process
* - represents a complete erp process
*
* @package QUI\ERP
*/
......@@ -26,6 +26,11 @@ class Process
*/
protected $transactions = null;
/**
* @var null|QUI\ERP\Comments
*/
protected $History = null;
/**
* Process constructor.
*
......@@ -36,25 +41,31 @@ public function __construct($processId)
$this->processId = $processId;
}
//region messages
/**
* Add a comment to the history
* Return the db table name
*
* @param string $comment
* @return string
*/
public function addHistory($comment)
protected function table()
{
$history = $this->getAttribute('history');
$History = QUI\ERP\Comments::unserialize($history);
return QUI::getDBTableName('process');
}
$History->addComment($comment);
//region messages
$this->setAttribute('history', $History->toJSON());
/**
* Add a comment to the history for the complete process
*
* @param string $message
* @param int|bool $time - optional, unix timestamp
*/
public function addHistory($message, $time = false)
{
$this->getHistory()->addComment($message, $time);
QUI::getDataBase()->update(
Handler::getInstance()->invoiceTable(),
['history' => $History->toJSON()],
$this->table(),
['history' => $this->getHistory()->toJSON()],
['id' => $this->processId]
);
}
......@@ -66,9 +77,25 @@ public function addHistory($comment)
*/
public function getHistory()
{
$history = $this->getAttribute('history');
if ($this->History === null) {
$result = QUI::getDataBase()->fetch([
'from' => $this->table(),
'where' => [
'id' => $this->processId
],
'limit' => 1
]);
$history = '';
if (isset($result[0]['history'])) {
$history = $result[0]['history'];
}
$this->History = QUI\ERP\Comments::unserialize($history);
}
return QUI\ERP\Comments::unserialize($history);
return $this->History;
}
//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