setQuery($q, 0, 1); $record = $dbo->loadAssoc(); if (!$record) { return [0, null]; } return [(float)$record['aliq'], $record['name']]; } /** * Gets the tax record data assigned to the given rate plan ID. * * @param int $ratep_id The rate plan ID. * * @return array Empty array or tax record found. * * @since 1.18.8 (J) - 1.8.8 (WP) */ public static function getTaxRecordFromRatePlan(int $ratep_id) { $dbo = JFactory::getDbo(); $dbo->setQuery( $dbo->getQuery(true) ->select([ $dbo->qn('p.id'), $dbo->qn('p.idiva'), $dbo->qn('t.name'), $dbo->qn('t.aliq'), $dbo->qn('t.taxcap'), ]) ->from($dbo->qn('#__vikbooking_prices', 'p')) ->leftJoin($dbo->qn('#__vikbooking_iva', 't') . ' ON ' . $dbo->qn('p.idiva') . ' = ' . $dbo->qn('t.id')) ->where($dbo->qn('p.id') . ' = ' . $ratep_id) ); return $dbo->loadAssoc() ?: []; } /** * Gets the tax rate assigned to the given tax ID. * * @param int $tax_id the tax ID. * * @return array float|int (tax rate) and string (tax name). */ public static function getTaxRateFromId($tax_id) { if (empty($tax_id)) { return [0, null]; } $dbo = JFactory::getDbo(); $q = "SELECT `t`.`name`, `t`.`aliq` FROM `#__vikbooking_iva` AS `t` WHERE `t`.`id`=" . (int)$tax_id; $dbo->setQuery($q, 0, 1); $record = $dbo->loadAssoc(); if (!$record) { return [0, null]; } return [(float)$record['aliq'], $record['name']]; } /** * Returns the whole tax rate record from the given ID. * * @param ?int $tax_id The tax record ID. * * @return array * * @since 1.18.8 (J) - 1.8.8 (WP) argument is nullable. */ public static function getTaxRateRecord(?int $tax_id) { static $tax_map = []; $tax_id = (int) $tax_id; if (isset($tax_map[$tax_id])) { return $tax_map[$tax_id]; } if (empty($tax_id)) { return []; } $dbo = JFactory::getDbo(); $q = "SELECT * FROM `#__vikbooking_iva` WHERE `id`=" . $tax_id; $dbo->setQuery($q, 0, 1); // cache value and return it $tax_map[$tax_id] = (array) $dbo->loadAssoc(); return $tax_map[$tax_id]; } /** * Gets the tax summary associative array. * * @param bool $sort if true, the array will be sorted by key desc. * * @return array */ public static function get($sort = true) { if ($sort) { krsort(static::$summary); } return static::$summary; } /** * Gets the tax names associative array. * * @return array */ public static function getNames() { return static::$tax_names; } /** * Sets the tax summary associative array. * * @param array $summary * * @return void */ public static function set(array $summary = []) { static::$summary = $summary; } /** * Sets the tax names associative array. * * @param array $names * * @return void */ public static function setNames(array $names = []) { static::$tax_names = $names; } }