Feat: Adds multi currency to imports and exports (#89)

* Also adds ability for user to export configurations
This commit is contained in:
hackerESQ
2025-04-10 20:47:35 -05:00
committed by GitHub
parent eae345f243
commit 1ef8dd9378
23 changed files with 445 additions and 77 deletions
+64
View File
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace App\Exports\Sheets;
use App\Models\Holding;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
class ConfigSheet implements FromCollection, WithHeadings, WithTitle
{
public function __construct(
public bool $empty = false
) {}
public function headings(): array
{
return [
'Key',
'Value',
];
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
$configs = collect();
if ($this->empty) {
return $configs;
}
// collect user settings
$configs->push([
'key' => 'name',
'value' => auth()->user()->name,
], [
'key' => 'locale',
'value' => auth()->user()->getLocale(),
], [
'key' => 'display_currency',
'value' => auth()->user()->getCurrency(),
]);
// reinvested holdings
Holding::myHoldings()->where('reinvest_dividends', true)->get()->each(function ($holding) use (&$configs) {
$configs->push([
'key' => 'reinvested_dividends',
'value' => $holding->id,
]);
});
return $configs;
}
public function title(): string
{
return 'Config';
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ class DailyChangesSheet implements FromCollection, WithHeadings, WithTitle
*/
public function collection()
{
return $this->empty ? collect() : DailyChange::myDailyChanges()->get();
return $this->empty ? collect() : DailyChange::myDailyChanges()->withDailyPerformance()->get();
}
public function title(): string
+25 -1
View File
@@ -25,6 +25,7 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
'Quantity',
'Cost Basis',
'Sale Price',
'Currency',
'Split',
'Reinvested Dividend',
'Date',
@@ -38,7 +39,30 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
*/
public function collection()
{
return $this->empty ? collect() : Transaction::myTransactions()->get();
if ($this->empty) {
return collect();
}
return Transaction::myTransactions()
->withMarketData()
->get()
->map(function ($transaction) {
return [
'id' => $transaction->id,
'symbol' => $transaction->symbol,
'portfolio_id' => $transaction->portfolio_id,
'transaction_type' => $transaction->transaction_type,
'quantity' => $transaction->quantity,
'cost_basis' => $transaction->cost_basis,
'sale_price' => $transaction->sale_price,
'currency' => $transaction->market_data_currency,
'split' => $transaction->split,
'reinvested_dividend' => $transaction->reinvested_dividend,
'date' => $transaction->date,
'created_at' => $transaction->created_at,
'updated_at' => $transaction->updated_at,
];
});
}
public function title(): string