b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Mrgig / MV / Model / CustomerInvoice /
Filename/home/dev2.destoffenstraat.com/app/code/Mrgig/MV/Model/CustomerInvoice/VatTransactionLine.php
Size3.01 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified23-Mar-2022 11:14
Last accessed23-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace Mrgig\MV\Model\CustomerInvoice;

use Mrgig\MV\Helper\Data as DataHelper;
use Mrgig\MV\Helper\Api as ApiHelper;
use Magento\Framework\App\ResourceConnection;

class VatTransactionLine
{
private const SALES_ORDER_TAX_TABLE = 'sales_order_tax';

protected $container = [];

public function __construct(
DataHelper $dataHelper,
ApiHelper $apiHelper,
ResourceConnection $resourceConnection
) {
$this->dataHelper = $dataHelper;
$this->apiHelper = $apiHelper;
$this->resourceConnection = $resourceConnection;
}

public function transactionLine($invoice, $taxId, $vatScenarioId)
{
$this->container['amountTurnoverCur'] = $this->getTotal($invoice);
$this->container['canChange'] = true;
$this->container['fiscalYear'] = $this->getFiscalYear($invoice->getCreatedAt());
$this->container['vatAmountCur'] = $this->getTaxAmount($invoice);
$this->container['vatCodeId'] = $taxId;
$this->container['vatScenarioId'] = $vatScenarioId;
$this->container['vatType'] = 0;

return [$this->container];
}

public function getFiscalYear($date)
{
return date('Y', strtotime($date));
}

public function getTotal($invoice)
{
$discountAmount = $invoice->getBaseDiscountAmount();
if (strpos($invoice->getBaseDiscountAmount(), '-') !== false) {
$discountAmount = str_replace('-', '', $invoice->getBaseDiscountAmount());
}
$total = $invoice->getBaseSubtotal() + $invoice->getShippingAmount();
if($discountAmount > 0) {
$taxPercent = $this->getTaxPercent($invoice->getOrder()->getId());
if(!empty($taxPercent) && $taxPercent > 0) {
$getTaxAmount = $invoice->getBaseGrandTotal() * $taxPercent / (100 + $taxPercent);
$total = $invoice->getBaseGrandTotal() - $getTaxAmount;
$total = number_format((float)$total, 2, '.', '');
}
}
return $total;
}


public function getTaxAmount($invoice)
{
$discountAmount = $invoice->getBaseDiscountAmount();
if (strpos($invoice->getBaseDiscountAmount(), '-') !== false) {
$discountAmount = str_replace('-', '', $invoice->getBaseDiscountAmount());
}
$taxAmount = $invoice->getTaxAmount();
if($discountAmount > 0) {
$taxPercent = $this->getTaxPercent($invoice->getOrder()->getId());
if(!empty($taxPercent) && $taxPercent > 0) {
$taxAmount = $invoice->getBaseGrandTotal() * $taxPercent / (100 + $taxPercent);
$taxAmount = number_format((float)$taxAmount, 2, '.', '');
}
}
return $taxAmount;
}

public function getTaxPercent(int $orderId): float
{
$table = $this->resourceConnection->getTableName(self::SALES_ORDER_TAX_TABLE);
$connection = $this->resourceConnection->getConnection();
$select = $connection->select();
$select->from(['order_tax' => $table], ['percent' => 'order_tax.percent']);
$select->where('order_tax.order_id = ?', $orderId);
$percent = (float) $connection->fetchOne($select);

return $percent;
}
}