PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.3
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.3
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Traits / InvoiceTrait.php

InvoiceTrait.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.3, at includes/Traits/InvoiceTrait.php

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Invoice Trait
4 *
5 * @package Easy_Invoice
6 * @subpackage Traits
7 */
8
9 namespace EasyInvoice\Traits;
10
11 use EasyInvoice\Controllers\SettingsController;
12
13 /**
14 * InvoiceTrait contains methods for invoice operations like generating invoice numbers, calculating due dates
15 */
16 trait InvoiceTrait {
17 /**
18 * Generate invoice number based on settings
19 *
20 * @param int $invoice_id The invoice ID
21 * @return string The generated invoice number
22 */
23 protected function generateInvoiceNumber($invoice_id) {
24 $settings_controller = new SettingsController();
25 $settings = $settings_controller->getSettings();
26
27 $prefix = $settings['invoice']['prefix'] ?: 'INV-';
28 $starting_number = intval($settings['invoice']['starting_number']) ?: 1001;
29
30 return $prefix . ($starting_number + $invoice_id - 1);
31 }
32
33 /**
34 * Calculate due date based on issue date and settings
35 *
36 * @param string $issue_date Issue date in Y-m-d format
37 * @return string Due date in Y-m-d format
38 */
39 protected function calculateDueDate($issue_date) {
40 $settings_controller = new SettingsController();
41 $settings = $settings_controller->getSettings();
42
43 $due_days = intval($settings['invoice']['due_days']) ?: 30;
44
45 $issue_timestamp = strtotime($issue_date);
46 $due_timestamp = strtotime("+{$due_days} days", $issue_timestamp);
47
48 return date('Y-m-d', $due_timestamp);
49 }
50 }