diff --git a/cp/app/Controllers/FinancialsController.php b/cp/app/Controllers/FinancialsController.php index 564bb6e..89bdce3 100644 --- a/cp/app/Controllers/FinancialsController.php +++ b/cp/app/Controllers/FinancialsController.php @@ -23,6 +23,39 @@ class FinancialsController extends Controller return view($response,'admin/financials/invoices.twig'); } + public function viewInvoice(Request $request, Response $response, $args) + { + $invoiceNumberPattern = '/^[A-Za-z]+\d+-?\d+$/'; + + if (preg_match($invoiceNumberPattern, $args)) { + $invoiceNumber = $args; // valid format + } else { + $this->container->get('flash')->addMessage('error', 'Invalid invoice number'); + return $response->withHeader('Location', '/invoices')->withStatus(302); + } + + $db = $this->container->get('db'); + $invoice_details = $db->selectRow('SELECT * FROM invoices WHERE invoice_number = ?', + [ $invoiceNumber ] + ); + $billing = $db->selectRow('SELECT * FROM registrar_contact WHERE id = ?', + [ $invoice_details['billing_contact_id'] ] + ); + $issueDate = new \DateTime($invoice_details['issue_date']); + $firstDayPrevMonth = (clone $issueDate)->modify('first day of last month')->format('Y-m-d'); + $lastDayPrevMonth = (clone $issueDate)->modify('last day of last month')->format('Y-m-d'); + $statement = $db->select('SELECT * FROM statement WHERE date BETWEEN ? AND ? AND registrar_id = ?', + [ $firstDayPrevMonth, $lastDayPrevMonth, $invoice_details['registrar_id'] ] + ); + + return view($response,'admin/financials/viewInvoice.twig', [ + 'invoice_details' => $invoice_details, + 'billing' => $billing, + 'statement' => $statement + ]); + + } + public function deposit(Request $request, Response $response) { if ($_SESSION["auth_roles"] != 0) { diff --git a/cp/resources/views/admin/financials/invoices.twig b/cp/resources/views/admin/financials/invoices.twig index c50f41a..0008102 100644 --- a/cp/resources/views/admin/financials/invoices.twig +++ b/cp/resources/views/admin/financials/invoices.twig @@ -24,6 +24,7 @@
+ {% include 'partials/flash.twig' %}
diff --git a/cp/resources/views/admin/financials/viewInvoice.twig b/cp/resources/views/admin/financials/viewInvoice.twig new file mode 100644 index 0000000..2f42022 --- /dev/null +++ b/cp/resources/views/admin/financials/viewInvoice.twig @@ -0,0 +1,136 @@ +{% extends "layouts/app.twig" %} + +{% block title %}{{ __('View Invoice') }}{% endblock %} + +{% block content %} +
+ + + +
+
+
+
+
+
+

Provider / Registry

+
+ Street Address
+ State, City
+ Region, Postal Code
+ ltd@example.com +
+
+
+

Client / Registrar

+
+ {{ billing.first_name }} {{ billing.last_name }}
+ {{ billing.org }}
+ {{ billing.street1 }}
+ {{ billing.city }}, {{ billing.sp }}
+ {{ billing.pc }}, {{ billing.cc }}
+ {{ billing.email }} +
+
+
+

Invoice Issued On: {{ invoice_details.issue_date|date("Y-m-d") }}

+
+
+

Due Date: {{ invoice_details.due_date|date("Y-m-d") }}

+
+
+

Invoice {{ invoice_details.invoice_number }} {% set status = invoice_details.payment_status %} + + {{ status|capitalize }} + +

+
+
+ + + + + + + + + {% if statement is not empty %} + {% set totalAmount = 0 %} + {% for item in statement %} + + + + + + {% set totalAmount = totalAmount + item.amount %} + {% endfor %} + {% else %} + + + + {% endif %} + + + + + + + + + + + + + + + + +
ProductAmount
{{ loop.index }} +

{{ item.command }} {{ item.domain_name }}

+
{{ item.amount }}
No items found.
Subtotal{{ totalAmount|number_format(2, '.', ',') }}
Vat RateTODO
Vat DueTODO
Total Due{{ invoice_details.total_amount }}
+

Notes: {{ invoice_details.notes }}

+

Thank you very much for doing business with us. We look forward to working with + you again!

+
+
+
+
+
+
+
+
    +
  • + Copyright © 2023 + Namingo. +
  • +
+
+
+
+ +
+{% endblock %} \ No newline at end of file diff --git a/cp/resources/views/partials/js-invoices.twig b/cp/resources/views/partials/js-invoices.twig index 545a397..6737fce 100644 --- a/cp/resources/views/partials/js-invoices.twig +++ b/cp/resources/views/partials/js-invoices.twig @@ -6,6 +6,17 @@