Skip to content

Commit

Permalink
Format files
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcage committed Sep 5, 2022
1 parent b3d1a17 commit 8228606
Show file tree
Hide file tree
Showing 188 changed files with 1,022 additions and 847 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/BackupDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
config('database.connections.mysql.username'),
config('database.connections.mysql.password'),
config('database.connections.mysql.database'),
storage_path('backups/backup-' . Str::slug(now()->toDateTimeString()) . '.sql.gz')
storage_path('backups/backup-'.Str::slug(now()->toDateTimeString()).'.sql.gz')
));
}

Expand Down
1 change: 1 addition & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function render($request, Throwable $exception)
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthorized.'], 403);
}

return redirect()->guest(route('login'));
}

Expand Down
12 changes: 7 additions & 5 deletions app/Exports/Accounting/BaseTransactionsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function headings(): array
__('Category'),
];
if (self::useSecondaryCategories()) {
$headings[] = __('Secondary Category');
$headings[] = __('Secondary Category');
}
$headings[] = __('Project');
if (self::useLocations()) {
Expand All @@ -37,6 +37,7 @@ public function headings(): array
if (self::useCostCenters()) {
$headings[] = __('Cost Center');
}

return array_merge($headings, [
__('Description'),
__('Supplier'),
Expand All @@ -49,7 +50,7 @@ public function headings(): array
}

/**
* @param Transaction $transaction
* @param Transaction $transaction
*/
public function map($transaction): array
{
Expand All @@ -73,6 +74,7 @@ public function map($transaction): array
if (self::useCostCenters()) {
$data[] = $transaction->cost_center;
}

return array_merge($data, [
$transaction->description,
optional($transaction->supplier)->name,
Expand All @@ -96,9 +98,9 @@ public function columnFormats(): array
protected function applyStyles(Worksheet $sheet)
{
parent::applyStyles($sheet);
$sheet->getStyle('D2:D' . $sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKGREEN));
$sheet->getStyle('E2:E' . $sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKRED));
$sheet->getStyle('F2:F' . $sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKRED));
$sheet->getStyle('D2:D'.$sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKGREEN));
$sheet->getStyle('E2:E'.$sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKRED));
$sheet->getStyle('F2:F'.$sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKRED));
}

private static function useSecondaryCategories(): bool
Expand Down
6 changes: 3 additions & 3 deletions app/Exports/Accounting/BudgetTransactionsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function headings(): array
}

/**
* @param Transaction $transaction
* @param Transaction $transaction
*/
public function map($transaction): array
{
Expand All @@ -78,7 +78,7 @@ public function columnFormats(): array
protected function applyStyles(Worksheet $sheet)
{
parent::applyStyles($sheet);
$sheet->getStyle('C2:C' . $sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKGREEN));
$sheet->getStyle('D2:D' . $sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKRED));
$sheet->getStyle('C2:C'.$sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKGREEN));
$sheet->getStyle('D2:D'.$sheet->getHighestRow())->getFont()->setColor(new Color(Color::COLOR_DARKRED));
}
}
2 changes: 1 addition & 1 deletion app/Exports/Accounting/Sheets/TransactionsSummarySheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TransactionsSummarySheet extends BaseExport implements FromView, WithColum
/**
* Constructor.
*
* @param array<Carbon> $months
* @param array<Carbon> $months
*/
public function __construct(array $months)
{
Expand Down
4 changes: 2 additions & 2 deletions app/Exports/Accounting/SuppliersExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function headings(): array
}

/**
* @param Supplier $supplier
* @param Supplier $supplier
*/
public function map($supplier): array
{
Expand All @@ -65,7 +65,7 @@ public function map($supplier): array
$supplier->iban,
$supplier->transactions()->count(),
$supplier->transactions()->where('type', 'spending')->sum('amount'),
$supplier->remarks
$supplier->remarks,
];
}
}
10 changes: 5 additions & 5 deletions app/Exports/Accounting/TransactionsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class TransactionsExport extends BaseTransactionsExport
private ?Wallet $wallet;

/**
* @param string[] $advancedFilter
* @param string|Carbon $dateFrom
* @param string|Carbon $dateTo
* @param string[] $advancedFilter
* @param string|Carbon $dateFrom
* @param string|Carbon $dateTo
*/
public function __construct(
?Wallet $wallet,
Expand All @@ -53,11 +53,11 @@ public function query(): \Illuminate\Database\Eloquent\Builder
->forFilter($this->filter)
->forAdvancedFilter($this->advancedFilter)
->when(
!empty($this->dateFrom),
! empty($this->dateFrom),
fn ($qry) => $qry->whereDate('date', '>=', $this->dateFrom)
)
->when(
!empty($this->dateTo),
! empty($this->dateTo),
fn ($qry) => $qry->whereDate('date', '<=', $this->dateTo)
)
->orderBy('date', 'ASC')
Expand Down
8 changes: 5 additions & 3 deletions app/Exports/CommunityVolunteers/CommunityVolunteersExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function collection(): Collection
}

/**
* @param CommunityVolunteer $communityVolunteer
* @param CommunityVolunteer $communityVolunteer
*/
public function map($communityVolunteer): array
{
Expand All @@ -51,7 +51,7 @@ public function map($communityVolunteer): array

private static function mapField($field, $communityVolunteer)
{
if (isset($field['value_export']) && gettype($field['value_export']) == 'string') {
if (isset($field['value_export']) && gettype($field['value_export']) == 'string') {
$value = $communityVolunteer->{$field['value_export']};
} elseif (gettype($field['value']) == 'string') {
$value = $communityVolunteer->{$field['value']};
Expand All @@ -63,8 +63,10 @@ private static function mapField($field, $communityVolunteer)
if ($value !== null) {
$prefix = $field['prefix'] ?? '';
$valueString = is_array($value) ? implode(', ', $value) : $value;
return $prefix . $valueString;

return $prefix.$valueString;
}

return null;
}

Expand Down
10 changes: 7 additions & 3 deletions app/Exports/Fundraising/DonorsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class DonorsExport extends BaseExport implements FromQuery, WithHeadings, WithMapping, WithColumnFormatting
{
private Collection $usedCurrenciesChannels;

private array $years;

public function __construct()
Expand Down Expand Up @@ -78,17 +79,18 @@ public function headings(): array
];
if (Auth::user()->can('viewAny', Donation::class)) {
foreach ($this->years as $year) {
$headings[] = __('Donations') . ' ' . $year;
$headings[] = __('Donations').' '.$year;
}
foreach ($this->usedCurrenciesChannels as $cc) {
$headings[] = $cc->currency . ' via ' . $cc->channel . ' in ' . $cc->year;
$headings[] = $cc->currency.' via '.$cc->channel.' in '.$cc->year;
}
}

return $headings;
}

/**
* @param Donor $donor
* @param Donor $donor
*/
public function map($donor): array
{
Expand Down Expand Up @@ -120,6 +122,7 @@ public function map($donor): array
->first())->total ?? null;
}
}

return $map;
}

Expand All @@ -141,6 +144,7 @@ public function columnFormats(): array
$formats[$column] = config('fundraising.currencies_excel_format')[$cc->currency];
}
}

return $formats;
}

Expand Down
14 changes: 8 additions & 6 deletions app/Exports/Fundraising/Sheets/DonationsSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
class DonationsSheet extends BaseExport implements FromCollection, WithHeadings, WithMapping
{
private Collection $donations;

private ?int $year;

protected string $currencyColumn = 'G';

protected string $exchangedCurrencyColumn = 'H';

public function __construct(Collection $donations, ?int $year = null)
Expand All @@ -34,7 +36,7 @@ public function collection(): Collection

public function title(): string
{
return __('Donations') . ($this->year !== null ? ' ' . $this->year : '');
return __('Donations').($this->year !== null ? ' '.$this->year : '');
}

public function headings(): array
Expand All @@ -52,7 +54,7 @@ public function headings(): array
}

/**
* @param Donation $donation
* @param Donation $donation
*/
public function map($donation): array
{
Expand All @@ -76,17 +78,17 @@ protected function applyStyles(Worksheet $sheet)

// Set exchange currency format
for ($i = 0; $i < $cnt; $i++) {
$sheet->getStyle($this->currencyColumn . ($i + 2))->getNumberFormat()->setFormatCode(config('fundraising.currencies_excel_format')[$this->donations[$i]->currency]);
$sheet->getStyle($this->currencyColumn.($i + 2))->getNumberFormat()->setFormatCode(config('fundraising.currencies_excel_format')[$this->donations[$i]->currency]);
}

if ($cnt > 0) {
$sumCell = $this->exchangedCurrencyColumn . ($cnt + 2);
$sumCell = $this->exchangedCurrencyColumn.($cnt + 2);

// Set currency format
$sheet->getStyle($this->exchangedCurrencyColumn . '1:' . $sumCell)->getNumberFormat()->setFormatCode(config('fundraising.base_currency_excel_format'));
$sheet->getStyle($this->exchangedCurrencyColumn.'1:'.$sumCell)->getNumberFormat()->setFormatCode(config('fundraising.base_currency_excel_format'));

// Total sum cell value
$sumCell = $this->exchangedCurrencyColumn . ($cnt + 2);
$sumCell = $this->exchangedCurrencyColumn.($cnt + 2);
// $sheet->setCellValue($sumCell, '=SUM(H2:H' . ($cnt + 1) . ')');
$sheet->setCellValue($sumCell, $this->donations->sum('exchange_amount'));
$sheet->getStyle($sumCell)->getFont()->setUnderline(Font::UNDERLINE_DOUBLEACCOUNTING);
Expand Down
5 changes: 4 additions & 1 deletion app/Exports/Fundraising/Sheets/DonationsWithDonorSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class DonationsWithDonorSheet extends DonationsSheet
{
protected string $currencyColumn = 'H';

protected string $exchangedCurrencyColumn = 'I';

public function headings(): array
Expand All @@ -15,18 +16,20 @@ public function headings(): array
$headings->splice(1, 0, [
__('Donor'),
]);

return $headings->toArray();
}

/**
* @param Donation $donation
* @param Donation $donation
*/
public function map($donation): array
{
$map = collect(parent::map($donation));
$map->splice(1, 0, [
$donation->donor->full_name,
]);

return $map->toArray();
}
}
2 changes: 1 addition & 1 deletion app/Exports/Visitors/Sheets/VisitorCheckInsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function headings(): array
}

/**
* @param VisitorCheckin $checkin
* @param VisitorCheckin $checkin
*/
public function map($checkin): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Exports/Visitors/Sheets/VisitorDataExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function headings(): array
}

/**
* @param Visitor $visitor
* @param Visitor $visitor
*/
public function map($visitor): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DashboardController extends Controller
\App\View\Widgets\UsersWidget::class,
];

function __invoke()
public function __invoke()
{
return response()->json([
'data' => collect($this->dashboardWidgets)
Expand Down
19 changes: 10 additions & 9 deletions app/Http/Controllers/Accounting/API/BudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function donations(Budget $budget)
->additional([
'meta' => [
'total_exchange_amount' => $budget->donations()->sum('exchange_amount'),
]
],
]);
}

Expand All @@ -116,16 +116,16 @@ public function export(Budget $budget, Request $request)

$export = new BudgetTransactionsExport($budget);

$file_name = config('app.name') . ' ' . __('Budget') . ' [' . $budget->name . '] (' . Carbon::now()->toDateString() . ')';
$file_ext = "xlsx";
$file_name = config('app.name').' '.__('Budget').' ['.$budget->name.'] ('.Carbon::now()->toDateString().')';
$file_ext = 'xlsx';

if ($request->has('include_pictures')) {
$options = new Archive();
$options->setSendHttpHeaders(true);
$zip = new ZipStream($file_name . '.zip', $options);
$temp_file = 'temp/' . uniqid() . '.' . $file_ext;
$zip = new ZipStream($file_name.'.zip', $options);
$temp_file = 'temp/'.uniqid().'.'.$file_ext;
$export->store($temp_file);
$zip->addFileFromPath($file_name . '.' . $file_ext, storage_path('app/' . $temp_file));
$zip->addFileFromPath($file_name.'.'.$file_ext, storage_path('app/'.$temp_file));
Storage::delete($temp_file);
foreach ($budget->transactions as $transaction) {
if (empty($transaction->receipt_pictures)) {
Expand All @@ -138,17 +138,18 @@ public function export(Budget $budget, Request $request)
$ext = pathinfo($picture_path, PATHINFO_EXTENSION);
$id = (string) $transaction->receipt_no;
if ($counter > 0) {
$id .= " (" . ($counter + 1) . ')';
$id .= ' ('.($counter + 1).')';
}
$zip->addFileFromPath('receipts/' . $id . '.' . $ext, $picture_path);
$zip->addFileFromPath('receipts/'.$id.'.'.$ext, $picture_path);
$counter++;
}
}
}
$zip->finish();

return;
}

return $export->download($file_name . '.' . $file_ext);
return $export->download($file_name.'.'.$file_ext);
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Accounting/API/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\Accounting\StoreCategory;
use Illuminate\Http\Request;
use App\Http\Resources\Accounting\Category as CategoryResource;
use App\Models\Accounting\Category;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Validation\Rule;

Expand Down Expand Up @@ -115,6 +115,7 @@ private function addCanUpdate($items)
return $items->map(function ($e) {
$e['can_update'] = request()->user()->can('update', $e);
$e['children'] = $this->addCanUpdate($e['children']);

return $e;
});
}
Expand Down
Loading

0 comments on commit 8228606

Please sign in to comment.