migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\DTOs;
|
||||
|
||||
readonly class EarningsDTO
|
||||
{
|
||||
public function __construct(
|
||||
public float $baseAmount,
|
||||
public float $distanceAmount,
|
||||
public float $totalBonus,
|
||||
public float $totalPenalty,
|
||||
public float $tipAmount,
|
||||
public float $grossAmount,
|
||||
public float $commissionRate,
|
||||
public float $commissionAmount,
|
||||
public float $netAmount,
|
||||
public string $currency,
|
||||
public array $breakdown = [],
|
||||
public array $bonuses = [],
|
||||
public array $penalties = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Create DTO from calculation result.
|
||||
*/
|
||||
public static function fromCalculation(array $data): self
|
||||
{
|
||||
return new self(
|
||||
baseAmount: (float) ($data['base_amount'] ?? 0),
|
||||
distanceAmount: (float) ($data['distance_amount'] ?? 0),
|
||||
totalBonus: (float) ($data['total_bonus'] ?? 0),
|
||||
totalPenalty: (float) ($data['total_penalty'] ?? 0),
|
||||
tipAmount: (float) ($data['tip_amount'] ?? 0),
|
||||
grossAmount: (float) ($data['gross_amount'] ?? 0),
|
||||
commissionRate: (float) ($data['commission_rate'] ?? 0),
|
||||
commissionAmount: (float) ($data['commission_amount'] ?? 0),
|
||||
netAmount: (float) ($data['net_amount'] ?? 0),
|
||||
currency: $data['currency'] ?? config('restaurant-delivery.pricing.currency', 'BDT'),
|
||||
breakdown: $data['breakdown'] ?? [],
|
||||
bonuses: $data['bonuses'] ?? [],
|
||||
penalties: $data['penalties'] ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to array.
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'base_amount' => $this->baseAmount,
|
||||
'distance_amount' => $this->distanceAmount,
|
||||
'total_bonus' => $this->totalBonus,
|
||||
'total_penalty' => $this->totalPenalty,
|
||||
'tip_amount' => $this->tipAmount,
|
||||
'gross_amount' => $this->grossAmount,
|
||||
'commission_rate' => $this->commissionRate,
|
||||
'commission_amount' => $this->commissionAmount,
|
||||
'net_amount' => $this->netAmount,
|
||||
'currency' => $this->currency,
|
||||
'breakdown' => $this->breakdown,
|
||||
'bonuses' => $this->bonuses,
|
||||
'penalties' => $this->penalties,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted amounts for display.
|
||||
*/
|
||||
public function toFormattedArray(): array
|
||||
{
|
||||
$symbol = config('restaurant-delivery.pricing.currency_symbol', '৳');
|
||||
|
||||
return [
|
||||
'base_amount' => $symbol.number_format($this->baseAmount, 2),
|
||||
'distance_amount' => $symbol.number_format($this->distanceAmount, 2),
|
||||
'total_bonus' => $symbol.number_format($this->totalBonus, 2),
|
||||
'total_penalty' => $symbol.number_format($this->totalPenalty, 2),
|
||||
'tip_amount' => $symbol.number_format($this->tipAmount, 2),
|
||||
'gross_amount' => $symbol.number_format($this->grossAmount, 2),
|
||||
'commission_amount' => $symbol.number_format($this->commissionAmount, 2),
|
||||
'net_amount' => $symbol.number_format($this->netAmount, 2),
|
||||
'commission_rate' => $this->commissionRate.'%',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user