Added VAT calculation

This commit is contained in:
Pinga 2023-12-14 16:07:25 +02:00
parent 8a144a6add
commit b404c59113
6 changed files with 45 additions and 10 deletions

View file

@ -5,6 +5,7 @@ namespace App\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Container\ContainerInterface;
use Mpociot\VatCalculator\VatCalculator;
class FinancialsController extends Controller
{
@ -44,9 +45,14 @@ class FinancialsController extends Controller
$billing = $db->selectRow('SELECT * FROM registrar_contact WHERE id = ?',
[ $invoice_details['billing_contact_id'] ]
);
$billing_vat = $db->selectValue('SELECT vat_number FROM registrar WHERE id = ?',
[ $invoice_details['registrar_id'] ]
);
$company_name = $db->selectValue("SELECT value FROM settings WHERE name = 'company_name'");
$address = $db->selectValue("SELECT value FROM settings WHERE name = 'address'");
$address2 = $db->selectValue("SELECT value FROM settings WHERE name = 'address2'");
$cc = $db->selectValue("SELECT value FROM settings WHERE name = 'cc'");
$vat_number = $db->selectValue("SELECT value FROM settings WHERE name = 'vat_number'");
$phone = $db->selectValue("SELECT value FROM settings WHERE name = 'phone'");
$email = $db->selectValue("SELECT value FROM settings WHERE name = 'email'");
@ -57,15 +63,36 @@ class FinancialsController extends Controller
[ $firstDayPrevMonth, $lastDayPrevMonth, $invoice_details['registrar_id'] ]
);
$vatCalculator = new VatCalculator();
$vatCalculator->setBusinessCountryCode(strtoupper($cc));
$grossPrice = $vatCalculator->calculate($invoice_details['total_amount'], strtoupper($billing['cc']));
$taxRate = $vatCalculator->getTaxRate();
$netPrice = $vatCalculator->getNetPrice();
$taxValue = $vatCalculator->getTaxValue();
if ($vatCalculator->shouldCollectVAT(strtoupper($billing['cc']))) {
$validVAT = $vatCalculator->isValidVatNumberFormat($vat_number);
} else {
$validVAT = null;
}
$totalAmount = $grossPrice + $taxValue;
return view($response,'admin/financials/viewInvoice.twig', [
'invoice_details' => $invoice_details,
'billing' => $billing,
'billing_vat' => $billing_vat,
'statement' => $statement,
'company_name' => $company_name,
'address' => $address,
'address2' => $address2,
'cc' => $cc,
'vat_number' => $vat_number,
'phone' => $phone,
'email' => $email,
'vatRate' => ($taxRate * 100) . "%",
'vatAmount' => $taxValue,
'validVAT' => $validVAT,
'netPrice' => $netPrice,
'total' => $totalAmount,
'currentUri' => $uri
]);

View file

@ -42,7 +42,8 @@
"jeremykendall/php-domain-parser": "^6.3",
"matthiasmullie/scrapbook": "^1.5",
"guzzlehttp/guzzle": "^7.8",
"league/flysystem": "^3.23"
"league/flysystem": "^3.23",
"mpociot/vat-calculator": "^3.6"
},
"autoload": {
"psr-4": {

View file

@ -34,8 +34,10 @@
<p class="h3">Provider / Registry</p>
<address>
{{ company_name }}<br>
{{ vat_number }}<br>
{{ address }}<br>
{{ address2 }}<br>
{{ cc }}<br>
{{ email }}
</address>
</div>
@ -43,6 +45,7 @@
<p class="h3">Client / Registrar</p>
<address>
{{ billing.org }}<br>
{{ billing_vat }} {% if validVAT %}<svg xmlns="http://www.w3.org/2000/svg" class="icon text-success" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" /></svg>{% endif %}<br>
{{ billing.street1 }}<br>
{{ billing.city }}, {{ billing.sp }}<br>
{{ billing.pc }}, {{ billing.cc }}<br>
@ -96,19 +99,19 @@
{% endif %}
<tr>
<td colspan="2" class="strong text-end">Subtotal</td>
<td class="text-end">{{ totalAmount|number_format(2, '.', ',') }}</td>
<td class="text-end">{{ netPrice }}</td>
</tr>
<tr>
<td colspan="2" class="strong text-end">Vat Rate</td>
<td class="text-end">TODO</td>
<td class="text-end">{{ vatRate }}</td>
</tr>
<tr>
<td colspan="2" class="strong text-end">Vat Due</td>
<td class="text-end">TODO</td>
<td class="text-end">{{ vatAmount }}</td>
</tr>
<tr>
<td colspan="2" class="font-weight-bold text-uppercase text-end">Total Due</td>
<td class="font-weight-bold text-end">{{ invoice_details.total_amount }}</td>
<td class="font-weight-bold text-end">{{ total }}</td>
</tr>
</table>
<p class="text-secondary text-center mt-5">Notes: {{ invoice_details.notes }}</p>

View file

@ -713,7 +713,9 @@ INSERT INTO `registry`.`settings` (`name`, `value`) VALUES
('whois-43-queries', '0'),
('company_name', 'Example Registry LLC'),
('address', '123 Example Street, Example City'),
('address2', '48000, Ukraine'),
('address2', '48000'),
('cc', 'Ukraine'),
('vat_number', '0'),
('phone', '+123456789'),
('handle', 'RXX'),
('email', 'contact@example.com');

View file

@ -691,7 +691,9 @@ INSERT INTO registry.settings (name, value) VALUES
('whois-43-queries', '0'),
('company_name', 'Example Registry LLC'),
('address', '123 Example Street, Example City'),
('address2', '48000, Ukraine'),
('address2', '48000'),
('cc', 'Ukraine'),
('vat_number', '0'),
('phone', '+123456789'),
('handle', 'RXX'),
('email', 'contact@example.com');

View file

@ -9,7 +9,7 @@ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' -o caddy-stabl
gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg caddy-stable.gpg.key
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update && apt upgrade
apt install -y bzip2 caddy composer curl gettext git gnupg2 net-tools php8.2 php8.2-bcmath php8.2-cli php8.2-common php8.2-curl php8.2-ds php8.2-fpm php8.2-gd php8.2-gmp php8.2-gnupg php8.2-imap php8.2-intl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-swoole php8.2-xml pv unzip wget whois
apt install -y bzip2 caddy composer curl gettext git gnupg2 net-tools php8.2 php8.2-bcmath php8.2-cli php8.2-common php8.2-curl php8.2-ds php8.2-fpm php8.2-gd php8.2-gmp php8.2-gnupg php8.2-imap php8.2-intl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-redis php8.2-soap php8.2-swoole php8.2-xml pv redis unzip wget whois
```
### Configure time: