appointments.php
3 days ago
employees.php
3 days ago
index.html
3 days ago
packages.php
3 days ago
subscriptions.php
3 days ago
packages.php
119 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | VAPLoader::import('libraries.invoice.classes.appointments'); |
| 15 | |
| 16 | /** |
| 17 | * Class used to generate the invoices of the packages. |
| 18 | * Since the invoices of the packages are almost equals to |
| 19 | * the invoices of the appointments, this class will extend |
| 20 | * the methods declared by VAPInvoiceAppointments. |
| 21 | * |
| 22 | * @since 1.6 |
| 23 | */ |
| 24 | class VAPInvoicePackages extends VAPInvoiceAppointments |
| 25 | { |
| 26 | /** |
| 27 | * @override |
| 28 | * Returns the destination absolute path of the invoices folder. |
| 29 | * |
| 30 | * @return string The invoice folder path. |
| 31 | * |
| 32 | * @since 1.7 |
| 33 | */ |
| 34 | public function getInvoiceFolderPath() |
| 35 | { |
| 36 | return parent::getInvoiceFolderPath() . DIRECTORY_SEPARATOR . 'packages'; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @override |
| 41 | * Returns the destination URI of the invoices folder. |
| 42 | * |
| 43 | * @return string The invoice folder URI. |
| 44 | * |
| 45 | * @since 1.7 |
| 46 | */ |
| 47 | public function getInvoiceFolderURI() |
| 48 | { |
| 49 | return parent::getInvoiceFolderURI() . 'packages/'; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @override |
| 54 | * Returns the page template that will be used to |
| 55 | * generate the invoice. |
| 56 | * |
| 57 | * @return string The base HTML. |
| 58 | */ |
| 59 | protected function getPageTemplate() |
| 60 | { |
| 61 | $data = array( |
| 62 | 'order' => $this->order, |
| 63 | 'breakdown' => $this->getBreakdown(), |
| 64 | 'usetaxbd' => VAPFactory::getConfig()->getBool('usetaxbd', false), |
| 65 | ); |
| 66 | |
| 67 | // create layout file (always read from the site section of VikAppointments) |
| 68 | $layout = new JLayoutFile('templates.invoice.package', null, [ |
| 69 | 'component' => 'com_vikappointments', |
| 70 | 'client' => 'site', |
| 71 | ]); |
| 72 | |
| 73 | return $layout->render($data); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Extracts an overall breakdown from the order. |
| 78 | * |
| 79 | * @return array |
| 80 | * |
| 81 | * @since 1.7 |
| 82 | */ |
| 83 | protected function getBreakdown() |
| 84 | { |
| 85 | $arr = array(); |
| 86 | |
| 87 | // group all breakdowns at the same level |
| 88 | foreach ($this->order->packages as $item) |
| 89 | { |
| 90 | if ($item->totals->breakdown) |
| 91 | { |
| 92 | $arr = array_merge($arr, $item->totals->breakdown); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $breakdown = array(); |
| 97 | |
| 98 | // iterate breakdowns |
| 99 | foreach ($arr as $bd) |
| 100 | { |
| 101 | if (!isset($breakdown[$bd->name])) |
| 102 | { |
| 103 | $breakdown[$bd->name] = 0; |
| 104 | } |
| 105 | |
| 106 | $breakdown[$bd->name] += $bd->tax; |
| 107 | } |
| 108 | |
| 109 | // check if we have a tax for the payment |
| 110 | if ($this->order->totals->payTax > 0) |
| 111 | { |
| 112 | // manually register payment tax within the breakdown |
| 113 | $breakdown[JText::translate('VAPINVPAYTAX')] = $this->order->totals->payTax; |
| 114 | } |
| 115 | |
| 116 | return $breakdown; |
| 117 | } |
| 118 | } |
| 119 |