Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
<?php
namespace HiEvents\Services\Domain\Tax;
use Illuminate\Support\Collection;
class TaxAndFeeOrderRollupService
{
public function rollup(Collection $orderItems): array
{
$orderRollup = [];
foreach ($orderItems as $orderItem) {
$itemTaxRollUp = $orderItem->getTaxesAndFeesRollup();
foreach ($itemTaxRollUp as $type => $taxesAndFees) {
$orderRollup[$type] ??= [];
foreach ($taxesAndFees as $taxOrFee) {
$foundIndex = array_search($taxOrFee['name'], array_column($orderRollup[$type], 'name'), true);
if ($foundIndex === false) {
$orderRollup[$type][] = [
'name' => $taxOrFee['name'],
'value' => $taxOrFee['value'],
'rate' => $taxOrFee['rate'],
'type' => $taxOrFee['type'],
];
} else {
$orderRollup[$type][$foundIndex]['value'] += $taxOrFee['value'];
}
}
}
}
return $orderRollup;
}
}