Skip to content

Commit

Permalink
Merge pull request #249 from bcgov/jp-bugfix-0027
Browse files Browse the repository at this point in the history
[Test Migration]  Pledges and event report issue [jp-bugfix-0027]
  • Loading branch information
steffipravasi authored Jun 22, 2023
2 parents ebaf646 + a5a86ce commit 5d02113
Show file tree
Hide file tree
Showing 37 changed files with 874 additions and 1,795 deletions.
23 changes: 20 additions & 3 deletions app/Exports/PledgeCharitiesExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

// use App\Models\EmployeeJob;
use App\Models\Pledge;
use App\Models\PledgeCharityStaging;
use App\Models\ProcessHistory;
use App\Models\BankDepositForm;

use Illuminate\Support\Facades\DB;

use App\Models\PledgeCharityStaging;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\AfterSheet;
use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
Expand Down Expand Up @@ -169,6 +170,22 @@ public function registerEvents(): array
'end_at' => now(),
]);

// Clean up Staging table
PledgeCharityStaging::where('history_id', $this->history_id)
->orWhere('updated_at', '<', today() )
->delete();

// Clean Up files over 14 days
$retention_days = env('REPORT_RETENTION_DAYS') ?: 14;
$prcs = ProcessHistory::where('id', $this->history_id)->first();

$file_names = ProcessHistory::where('process_name', $prcs->process_name)
->whereBetween('updated_at', [ today()->subdays( $retention_days + 90), today()->subdays( $retention_days + 1), ])
->pluck('filename')
->toArray();

Storage::disk('public')->delete( $file_names );

},

];
Expand Down
48 changes: 32 additions & 16 deletions app/Exports/PledgesExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
use App\Models\BankDepositForm;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\AfterSheet;
use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
Expand Down Expand Up @@ -49,17 +50,17 @@ public function query()
public function headings(): array
{
return [
// [
// 'Report title : Annual Pledges and Events',
// ],
// [
// 'Run at : ' . now(),
// ],
// [
// '',
// ],
[
'Report title : Annual Pledges and Events',
],
[
'Run at : ' . now(),
],
[
'',
],
[
'Calander Year',
'Calandar Year',
'Name',
'Org Code',
'Org Descr',
Expand Down Expand Up @@ -158,6 +159,21 @@ public function registerEvents(): array
'end_at' => now(),
]);

// Clean up Staging table
PledgeStaging::where('history_id', $this->history_id)
->orWhere('updated_at', '<', today() )
->delete();

// Clean Up files over 14 days
$retention_days = env('REPORT_RETENTION_DAYS') ?: 14;
$prcs = ProcessHistory::where('id', $this->history_id)->first();

$file_names = ProcessHistory::where('process_name', $prcs->process_name)
->whereBetween('updated_at', [ today()->subdays( $retention_days + 90), today()->subdays( $retention_days + 1), ])
->pluck('filename')
->toArray();

Storage::disk('public')->delete( $file_names );
},

];
Expand Down Expand Up @@ -192,8 +208,8 @@ protected function populate_staging_table($filters)
THEN employee_jobs.office_city
ELSE pledges.city
END as city
,'Bi-Weekly' AS type
,'' AS sub_type
,'Pledge' AS type
,'Bi-Weekly' AS sub_type
,pledges.type AS pool_type
,pledges.region_id
,pledges.pay_period_amount AS pledge
Expand Down Expand Up @@ -245,8 +261,8 @@ protected function populate_staging_table($filters)
THEN employee_jobs.office_city
ELSE pledges.city
END as city
,'One-Time' AS type
,'' AS sub_type
,'Pledge' AS type
,'One-Time' AS sub_type
,pledges.type AS pool_type
,pledges.region_id
,pledges.one_time_amount
Expand Down Expand Up @@ -283,7 +299,7 @@ protected function populate_staging_table($filters)
],

BankDepositForm::selectRaw(" ?, 'Event', bank_deposit_forms.id
,year(bank_deposit_forms.created_at)
,campaign_years.calendar_year
,bank_deposit_forms.organization_code
,bank_deposit_forms.bc_gov_id
,bank_deposit_forms.pecsf_id
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Controllers/Admin/CRACharityReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ public function index(Request $request)
// })
->addColumn('download_file_link', function ($process) {
if ($process->status == 'Completed') {
$url = route('reporting.cra-charities.download-export-file', $process->id);
$link = '<a class="" href="'.$url.'">'. $process->original_filename . '</a>';
$retention_days = env('REPORT_RETENTION_DAYS') ?: 14;
if ($process->updated_at >= today()->subdays($retention_days) ) {
$url = route('reporting.cra-charities.download-export-file', $process->id);
$link = '<a class="" href="'.$url.'">'. $process->original_filename . '</a>';
} else {
$link = $process->original_filename;
}
} else {
// $link = $process->original_filename;
$link = '';
Expand Down
59 changes: 33 additions & 26 deletions app/Http/Controllers/Admin/CampaignPledgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,42 +697,49 @@ public function getNonGovUserDetail(Request $request) {

if($request->ajax()) {

// Get Region from Org
$org = Organization::where('id', $request->org_id)->first();
$pecsf_bu = $org ? ($org->business_unit ? $org->business_unit->name : '') : '';
$formatted_result = (object) [
'pecsf_bu' => $pecsf_bu,
];

// Search for the Non-Gov History
$pledge = Pledge::join('campaign_years', 'pledges.campaign_year_id', 'campaign_years.id')
->where('pledges.organization_id', $request->org_id )
->where('pledges.pecsf_id', $request->pecsf_id)
->orderBy('pledges.id', 'desc')
->orderBy('campaign_years.calendar_year', 'desc')
->first();

if ($pledge) {
$formatted_result = (object) [
'first_name' => $pledge->first_name,
'last_name' => $pledge->last_name,
'city' => $pledge->city,
];

return json_encode( $formatted_result );
}


// Search Non-Gov History
$history = NonGovPledgeHistory::leftJoin('organizations', 'non_gov_pledge_histories.org_code', 'organizations.code')
->where('organizations.id', $request->org_id )
->where('non_gov_pledge_histories.pecsf_id', $request->pecsf_id)
->orderBy('non_gov_pledge_histories.yearcd', 'desc')
->first();

if ($history) {
$formatted_result = (object) [
'first_name' => $history->first_name,
'last_name' => $history->last_name,
'city' => $history->city,
];

return json_encode( $formatted_result );
$formatted_result->first_name = $pledge->first_name;
$formatted_result->last_name = $pledge->last_name;
$formatted_result->city = $pledge->city;

} else {
// Search Non-Gov History
$history = NonGovPledgeHistory::leftJoin('organizations', 'non_gov_pledge_histories.org_code', 'organizations.code')
->where('organizations.id', $request->org_id )
->where('non_gov_pledge_histories.pecsf_id', $request->pecsf_id)
->orderBy('non_gov_pledge_histories.yearcd', 'desc')
->first();

if ($history) {
$formatted_result->first_name = $history->first_name;
$formatted_result->last_name = $history->last_name;
$formatted_result->city = $history->city;
}
}

return response()->noContent();
if (isset($formatted_result->city)) {
$city = City::where('city', trim($formatted_result->city) )->first();
$formatted_result->pecsf_region = $city ? ($city->region ? $city->region->name : '') : '';
}

return json_encode( $formatted_result );

// return response()->noContent();

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function index(Request $request)
}

// Prepare for the datatables
$processes = ProcessHistory::where('process_name', $this->process_name);
$processes = ProcessHistory::where('process_name', $this->process_name)
->with('created_by');

return Datatables::of($processes)
// ->addColumn('short_message', function ($process) {
Expand Down
14 changes: 6 additions & 8 deletions app/Http/Controllers/Admin/EventSubmissionQueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,30 @@ public function details(Request $request){


if($submissions[0]->organization_code == "RET"){
$existing = BankDepositForm::where("organization_code","=","RET")
$existing = BankDepositForm::where("pecsf_id","LIKE","R".substr(date("Y"),2,2)."%")
->orderBy("pecsf_id","desc")
->whereNotNull("pecsf_id")
->get();

if(count($existing) > 0)
{
$submissions[0]->pecsf_id = "R".str_pad((intval(str_replace("R","",$existing[0]->pecsf_id)) +1),3,'0',STR_PAD_LEFT);
$submissions[0]->pecsf_id = "R".substr(date("Y"),2,2).str_pad((intval(count($existing)) +1),3,'0',STR_PAD_LEFT);
}
else{
$submissions[0]->pecsf_id = "R".substr(date("Y"),2,2)."001";

}
}
$existing = [];

if($submissions[0]->event_type == "Gaming")
{
$existing = BankDepositForm::where("event_type","=","Gaming")
->where("pecsf_id","LIKE","G%")
->where("pecsf_id","LIKE","G".substr(date("Y"),2,2)."%")
->orderBy("pecsf_id","desc")
->get();

if(count($existing) > 0)
{
$submissions[0]->pecsf_id = "G".(intval(str_replace("G","",$existing[0]->pecsf_id)) + 1);
$submissions[0]->pecsf_id = "G".substr(date("Y"),2,2).str_pad((intval(count($existing)) +1),3,'0',STR_PAD_LEFT);
}
else{
$submissions[0]->pecsf_id = "G".substr(date("Y"),2,2)."001";
Expand All @@ -191,13 +189,13 @@ public function details(Request $request){
if($submissions[0]->event_type == "Fundraiser")
{
$existing = BankDepositForm::where("event_type","=","Fundraiser")
->where("pecsf_id","LIKE","F%")
->where("pecsf_id","LIKE","F".substr(date("Y"),2,2)."%")
->orderBy("pecsf_id","desc")
->get();

if(count($existing) > 0)
{
$submissions[0]->pecsf_id = "F".(intval(str_replace("F","",$existing[0]->pecsf_id)) + 1);
$submissions[0]->pecsf_id = "F".substr(date("Y"),2,2).str_pad((intval(count($existing)) +1),3,'0',STR_PAD_LEFT);
}
else{
$submissions[0]->pecsf_id = "F".substr(date("Y"),2,2)."001";
Expand Down
Loading

0 comments on commit 5d02113

Please sign in to comment.