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

Merge branch 'dev'

Übergeordnete 1439aba8 a0eff6b6
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -196,27 +196,46 @@ public function createInvoice(RequestInterface $Request, ResponseInterface $Resp
// Payment method
$Payments = QUI\ERP\Accounting\Payments\Payments::getInstance();
$payments = $Payments->getPayments([
'where' => [
'payment_type' => QUI\ERP\Accounting\Payments\Methods\Invoice\Payment::class
]
]);
$Customer = $InvoiceDraft->getCustomer();
$Payment = false;
// Set default payment method
if (!empty($payments)) {
$DefaultPayment = $payments[0];
$InvoiceDraft->setAttribute('payment_method', $DefaultPayment->getId());
if ($Customer) {
$customerDefaultPaymentId = $Customer->getAttribute('quiqqer.erp.standard.payment');
if (!empty($customerDefaultPaymentId)) {
try {
$Payment = $Payments->getPayment($customerDefaultPaymentId);
} catch (\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
}
}
}
if (!empty($invoiceData['payment_method'])) {
if (!$Payment && !empty($invoiceData['payment_method'])) {
try {
$Payment = $Payments->getPayment((int)$invoiceData['payment_method']);
$InvoiceDraft->setAttribute('payment_method', $Payment->getId());
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
// Set default payment method
if (!$Payment) {
$payments = $Payments->getPayments([
'where' => [
'payment_type' => QUI\ERP\Accounting\Payments\Methods\Invoice\Payment::class
]
]);
if (!empty($payments)) {
$Payment = $payments[0];
}
}
if ($Payment) {
$InvoiceDraft->setAttribute('payment_method', $Payment->getId());
}
// Currency
if (!empty($invoiceData['currency']) && CurrencyHandler::existCurrency($invoiceData['currency'])) {
$InvoiceDraft->setCurrency($invoiceData['currency']);
......@@ -249,29 +268,40 @@ public function createInvoice(RequestInterface $Request, ResponseInterface $Resp
$InvoiceDraft->setAttribute('additional_invoice_text', $invoiceText);
}
// Articles
// Articles - Existing products
$ProductList = new QUI\ERP\Products\Product\ProductList();
$ProductList->setUser($InvoiceDraft->getCustomer());
foreach ($invoiceData['articles'] as $article) {
$Article = null;
if (empty($article['quiqqerProductId'])) {
continue;
}
if (!empty($article['quiqqerProductId'])) {
try {
$Product = QUI\ERP\Products\Handler\Products::getProduct((int)$article['quiqqerProductId']);
$UniqueProduct = $Product->createUniqueProduct($InvoiceDraft->getCustomer());
$UniqueProduct->setQuantity((float)$article['quantity']);
try {
$Product = QUI\ERP\Products\Handler\Products::getProduct((int)$article['quiqqerProductId']);
$UniqueProduct->recalculation();
$UniqueProduct = $Product->createUniqueProduct($InvoiceDraft->getCustomer());
$UniqueProduct->setQuantity((float)$article['quantity']);
$Article = $UniqueProduct->toArticle(null, false);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
$ProductList->addProduct($UniqueProduct);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
if (!$Article) {
$Article = new QUI\ERP\Accounting\Article($article);
$ProductList->recalculate();
foreach ($ProductList->getProducts() as $Product) {
$InvoiceDraft->addArticle($Product->toArticle());
}
// Articles - Custom
foreach ($invoiceData['articles'] as $article) {
if (!empty($article['quiqqerProductId'])) {
continue;
}
$Article->calc();
$Article = new QUI\ERP\Accounting\Article($article);
$InvoiceDraft->addArticle($Article);
}
......
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