Skip to content

Commit

Permalink
Merge pull request #24 from anshour/main
Browse files Browse the repository at this point in the history
Fixing bug : items not filtered by donor_id
  • Loading branch information
nuradiyana committed Feb 15, 2024
2 parents 1d88540 + f96e526 commit 407f799
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Jobs/GenerateDonorRecapFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public function handle(): void

$path = \sprintf('%s/%s/%s.pdf', Recap::getFileGeneratedBasePath(), now()->year, Str::random(64));

$donorId = $this->donor->getAttribute('donor_id');
$content = GeneratePdf::view('recap::recap', [
'donor' => $this->donor,
'recap' => $this->donationRecap,
'items' => $this->donationRecap->getItemCollection(),
'summaries' => $this->donationRecap->getCategoryItemsSummaries(),
'items' => $this->donationRecap->getItemCollection($donorId),
'summaries' => $this->donationRecap->getCategoryItemsSummaries($donorId),
])->base64pdf();

if (Str::isJson($content)) {
Expand All @@ -68,7 +69,7 @@ public function handle(): void

public function uniqueId(): string
{
return $this->donationRecap->getKey().'|'.$this->donor->getKey();
return $this->donationRecap->getKey() . '|' . $this->donor->getKey();
}

public function failed(Throwable $exception): void
Expand Down
8 changes: 4 additions & 4 deletions src/Models/DonationRecap.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public function isLastRecordProcessed(): bool
return $this->getAttribute('count_total') === ($this->getAttribute('count_progress') + 1);
}

public function getItemCollection(): Collection
public function getItemCollection(string $donorId): Collection
{
return $this->items()->oldest('donation_transaction_date')->get();
return $this->items()->where('donor_id', $donorId)->oldest('donation_transaction_date')->get();
}

public function getCategoryItemsSummaries(): DonationSummaries
public function getCategoryItemsSummaries(string $donorId): DonationSummaries
{
$collection = $this->items()->select([
$collection = $this->items()->where('donor_id', $donorId)->select([
DB::raw('donation_funding_category_id as category_id'),
DB::raw('donation_funding_category_name as category'),
DB::raw('sum(donation_amount) as donation_amount'),
Expand Down

0 comments on commit 407f799

Please sign in to comment.