Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source of Truth [Sync up master from TEST] on June 16, 2023 #224

Merged
merged 11 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/ChallengeSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function store(Request $request){
'challenge_final_date' => 'required|date|after_or_equal:challenge_end_date',
'campaign_start_date' => 'required|date',
'campaign_end_date' => 'required|date|after:campaign_start_date',
// 'campaign_final_date' => 'required|date|after_or_equal:campaign_end_date',
'campaign_final_date' => 'required|date|after_or_equal:campaign_end_date',
],[

]);
Expand All @@ -56,7 +56,7 @@ public function store(Request $request){

$setting->campaign_start_date = $request->campaign_start_date;
$setting->campaign_end_date = $request->campaign_end_date;
// $setting->campaign_final_date = $request->campaign_final_date;
$setting->campaign_final_date = $request->campaign_final_date;

$setting->save();

Expand Down
16 changes: 12 additions & 4 deletions app/Http/Controllers/ChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function index(Request $request) {
$campaign_year,
$campaign_year,
$campaign_year,
$campaign_year,
$prior_year,
];

$sql = <<<SQL
Expand Down Expand Up @@ -112,11 +114,17 @@ public function index(Request $request) {
order by A.donors / (select ee_count from eligible_employee_by_bus where eligible_employee_by_bus.campaign_year = ?
and eligible_employee_by_bus.organization_code = 'GOV'
and eligible_employee_by_bus.business_unit_code = A.business_unit_code
) * 100 desc, organization_name
) * 100 desc,
abs(A.donors / (select ee_count from eligible_employee_by_bus where eligible_employee_by_bus.campaign_year = ?
and eligible_employee_by_bus.organization_code = 'GOV'
and eligible_employee_by_bus.business_unit_code = A.business_unit_code
) * 100) - COALESCE((select participation_rate from historical_challenge_pages where year = ?
-- and historical_challenge_pages.organization_name = A.organization_name
and historical_challenge_pages.business_unit_code = A.business_unit_code
),0)

SQL;


$challenges = DB::select($sql, $parameters);

} else {
Expand All @@ -139,7 +147,7 @@ public function index(Request $request) {
and D1.as_of_date <= ?
)
and eligible_employee_count >= 5
order by participation_rate desc;
order by participation_rate desc, abs(change_rate);
SQL;

$challenges = DB::select($sql, $parameters);
Expand All @@ -162,7 +170,7 @@ public function index(Request $request) {
from historical_challenge_pages, (SELECT @row_number:=0) AS temp
where year = ?
and donors >= 5
order by participation_rate desc;
order by participation_rate desc, abs(`change`);
SQL;

$challenges = DB::select($sql, $parameters);
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function __construct()
*/
public function index(Request $request)
{
return view('home');

$campaignYear = CampaignYear::where('calendar_year', '<=', today()->year + 1 )
->orderBy('calendar_year', 'desc')
->first();

return view('home', compact('campaignYear'));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Modify2ndDailyCampaignView extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
DB::statement($this->dropView());
DB::statement($this->create_New_View());
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
DB::statement($this->dropView());
DB::statement($this->create_Old_View());

}

/**
* Reverse the migrations.
*
* @return void
*/
private function create_New_View(): string
{
return <<<SQL

CREATE VIEW daily_campaign_view AS

-- Pledge (Gov)
(select 'pledges' as type, eligible_employee_details.business_unit as business_unit_code, eligible_employee_details.tgb_reg_district,
eligible_employee_details.deptid, eligible_employee_details.dept_name,
1 as donors, pledges.goal_amount as dollars,
(select calendar_year - 1 from campaign_years where pledges.campaign_year_id = campaign_years.id) as campaign_year,
organizations.code as organization_code, pledges.emplid, pledges.pecsf_id
from pledges
left outer join organizations on pledges.organization_id = organizations.id
left outer join eligible_employee_details on organizations.code = eligible_employee_details.organization_code and pledges.emplid = eligible_employee_details.emplid
where as_of_date = (select max(as_of_date) from eligible_employee_details e1
where 1 = 1
-- and e1.organization_code = eligible_employee_details.organization_code
and e1.year = YEAR( CURDATE() )
and e1.as_of_date <= CURDATE())
and pledges.emplid is not null
and organizations.code = 'GOV'
and pledges.deleted_at is null)
union all
-- Pledge (Non Gov)
(select 'pledges' as type, business_units.linked_bu_code,
'','','',
1 as donors, pledges.goal_amount as dollars,
(select calendar_year - 1 from campaign_years where pledges.campaign_year_id = campaign_years.id) as campaign_year,
organizations.code, pledges.emplid, pledges.pecsf_id
from pledges
left outer join organizations on pledges.organization_id = organizations.id and organizations.deleted_at is null
left outer join business_units on organizations.bu_code = business_units.code and business_units.deleted_at is null
where 1=1
and organizations.code <> 'GOV'
and pledges.deleted_at is null)
-- eForm (Gov)
union all
(select 'eform' as type, eligible_employee_details.business_unit,
(select code from regions where regions.id = bank_deposit_forms.region_id),
department_id, '',
case when event_type in ('Fundraiser', 'Gaming') then 0 else 1 end, bank_deposit_forms.deposit_amount as dollars,
(select calendar_year - 1 from campaign_years where bank_deposit_forms.campaign_year_id = campaign_years.id) as campaign_year,
bank_deposit_forms.organization_code, bank_deposit_forms.bc_gov_id, bank_deposit_forms.pecsf_id
from bank_deposit_forms
left outer join business_units on business_units.id = bank_deposit_forms.business_unit and business_units.deleted_at is null
left outer join eligible_employee_details on bank_deposit_forms.organization_code = eligible_employee_details.organization_code
and bank_deposit_forms.bc_gov_id = eligible_employee_details.emplid
where as_of_date = (select max(as_of_date) from eligible_employee_details e1
where 1 = 1
and e1.year = YEAR( CURDATE() )
and e1.as_of_date <= CURDATE())
and bank_deposit_forms.organization_code = 'GOV'
and bank_deposit_forms.bc_gov_id is not null
and bank_deposit_forms.approved = 1
and bank_deposit_forms.deleted_at is null)
-- eForm (non-Gov)
union all
(select 'eform' as type, business_units.linked_bu_code,
(select code from regions where regions.id = bank_deposit_forms.region_id), department_id, '',
case when event_type in ('Fundraiser', 'Gaming') then 0 else 1 end, bank_deposit_forms.deposit_amount as dollars,
(select calendar_year - 1 from campaign_years where bank_deposit_forms.campaign_year_id = campaign_years.id) as campaign_year,
organization_code, bank_deposit_forms.bc_gov_id, bank_deposit_forms.pecsf_id
from bank_deposit_forms
left outer join organizations on bank_deposit_forms.organization_code = organizations.code and organizations.deleted_at is null
left outer join business_units on business_units.id = bank_deposit_forms.business_unit and business_units.deleted_at is null
where bank_deposit_forms.organization_code <> 'GOV'
and bank_deposit_forms.approved = 1
and bank_deposit_forms.deleted_at is null)

SQL;

}


/**
* Reverse the migrations.
*
* @return void
*/
private function dropView(): string
{
return <<<SQL

DROP VIEW IF EXISTS daily_campaign_view;

SQL;

}


private function create_Old_View(): string
{
return <<<SQL

CREATE VIEW daily_campaign_view AS

-- Pledge (Gov)
(select 'pledges' as type, eligible_employee_details.business_unit as business_unit_code, eligible_employee_details.tgb_reg_district,
eligible_employee_details.deptid, eligible_employee_details.dept_name,
1 as donors, pledges.goal_amount as dollars,
(select calendar_year - 1 from campaign_years where pledges.campaign_year_id = campaign_years.id) as campaign_year,
organizations.code as organization_code, pledges.emplid, pledges.pecsf_id
from pledges
left outer join organizations on pledges.organization_id = organizations.id
left outer join eligible_employee_details on organizations.code = eligible_employee_details.organization_code and pledges.emplid = eligible_employee_details.emplid
where as_of_date = (select max(as_of_date) from eligible_employee_details e1
where 1 = 1
-- and e1.organization_code = eligible_employee_details.organization_code
and e1.year = YEAR( CURDATE() )
and e1.as_of_date <= CURDATE())
and pledges.emplid is not null
and organizations.code = 'GOV'
and pledges.deleted_at is null)
union all
-- Pledge (Non Gov)
(select 'pledges' as type, business_units.linked_bu_code,
'','','',
1 as donors, pledges.goal_amount as dollars,
(select calendar_year - 1 from campaign_years where pledges.campaign_year_id = campaign_years.id) as campaign_year,
organizations.code, pledges.emplid, pledges.pecsf_id
from pledges
left outer join organizations on pledges.organization_id = organizations.id and organizations.deleted_at is null
left outer join business_units on organizations.bu_code = business_units.code and business_units.deleted_at is null
where 1=1
and organizations.code <> 'GOV'
and pledges.deleted_at is null)
-- eForm (Gov)
union all
(select 'eform' as type, business_units.linked_bu_code,
(select code from regions where regions.id = bank_deposit_forms.region_id), department_id, '',
case when event_type in ('Fundraiser', 'Gaming') then 0 else 1 end, bank_deposit_forms.deposit_amount as dollars,
(select calendar_year - 1 from campaign_years where bank_deposit_forms.campaign_year_id = campaign_years.id) as campaign_year,
organization_code, bank_deposit_forms.bc_gov_id, bank_deposit_forms.pecsf_id
from bank_deposit_forms
left outer join business_units on business_units.id = bank_deposit_forms.business_unit and business_units.deleted_at is null
where bank_deposit_forms.organization_code = 'GOV'
and bank_deposit_forms.approved = 1
and bank_deposit_forms.deleted_at is null)
-- eForm (non-Gov)
union all
(select 'eform' as type, business_units.linked_bu_code,
(select code from regions where regions.id = bank_deposit_forms.region_id), department_id, '',
case when event_type in ('Fundraiser', 'Gaming') then 0 else 1 end, bank_deposit_forms.deposit_amount as dollars,
(select calendar_year - 1 from campaign_years where bank_deposit_forms.campaign_year_id = campaign_years.id) as campaign_year,
organization_code, bank_deposit_forms.bc_gov_id, bank_deposit_forms.pecsf_id
from bank_deposit_forms
left outer join organizations on bank_deposit_forms.organization_code = organizations.code and organizations.deleted_at is null
left outer join business_units on business_units.id = bank_deposit_forms.business_unit and business_units.deleted_at is null
where bank_deposit_forms.organization_code <> 'GOV'
and bank_deposit_forms.approved = 1
and bank_deposit_forms.deleted_at is null)

SQL;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddCampaignYearIdIndexInPledge extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('pledges', function (Blueprint $table) {
//
$table->index(['campaign_year_id','organization_id', 'emplid', 'pecsf_id']);

});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('pledges', function (Blueprint $table) {
//
$table->dropIndex(['campaign_year_id','organization_id', 'emplid', 'pecsf_id']);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddCampaignYearIdIndexInBankDepositForm extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bank_deposit_forms', function (Blueprint $table) {
//
$table->index(['campaign_year_id','organization_code', 'bc_gov_id', 'pecsf_id'], 'year_org_emplid_pecsf_id');
$table->index(['organization_code', 'bc_gov_id', 'approved']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('bank_deposit_forms', function (Blueprint $table) {
//
$table->dropIndex( 'year_org_emplid_pecsf_id' );
$table->dropindex(['organization_code', 'bc_gov_id', 'approved']);

});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddNameIndexInDepartment extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('departments', function (Blueprint $table) {
//
$table->index(['yearcd', 'department_name', 'business_unit_code'], 'year_name_bu');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('departments', function (Blueprint $table) {
//
$table->dropIndex( 'year_name_bu' );
});
}
}
Loading