Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewNatoli committed Dec 16, 2016
2 parents fa6b62b + 4cea478 commit 23c1450
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 144 deletions.
Binary file modified .DS_Store
Binary file not shown.
230 changes: 109 additions & 121 deletions _ide_helper.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Child extends Model

public function household()
{
return $this->belongsToOne("Household");
return $this->belongsTo("\App\Household");
}

public function getAgeAttribute()
Expand Down
56 changes: 50 additions & 6 deletions app/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Carbon\Carbon;
use Illuminate\Support\Collection;
use LaravelAnalytics;
use Illuminate\Support\Facades\DB;

class DashboardController extends AdminController
{
Expand Down Expand Up @@ -58,11 +59,54 @@ public function __construct()

public function getIndex()
{
$accounts_pending_approval = User::query()->pending()->count();
$draftCount = Household::query()->draft()->count();
return view('admin.dashboard.index', [
'accounts_pending_approval' => $accounts_pending_approval,
'drafts' => $draftCount
]);
$stats = array();

$stats['accounts_pending_approval'] = User::query()->pending()->count();

// TODO: unify 'Y'/'N'/0/1
$stats['nominations_pending_review'] =
Household::where('draft', 'N')
->where('reviewed', 0)
->count();

$stats['nominations_approved'] =
Household::where('reviewed', 1)
->count();

$stats['nominations_reviewed'] =
Household::where('approved', 1)
->count();

$stats['children_approved'] =
Household::where('reviewed', 1)
->join('child', 'child.household_id', '=', 'household.id')
->count();

$stats['children_reviewed'] =
Household::where('household.approved', 1)
->join('child', 'child.household_id', '=', 'household.id')
->count();

$stats['children_pending'] =
Household::where('household.reviewed', 0)
->where('household.draft', 'N')
->join('child', 'child.household_id', '=', 'household.id')
->count();

$stats['drafts'] = Household::query()->draft()->count();

$stats['orgs'] =
DB::table('household')
->select(
'affiliation.type',
DB::raw('count(case when household.approved = 1 then 1 else null end) as approved'),
DB::raw('count(case when household.reviewed = 1 then 1 else null end) as reviewed'),
DB::raw('count(case when household.draft = "N" and household.reviewed = 0 then 1 else null end) as pending'))
->join('users', 'users.id', '=', 'household.nominator_user_id')
->join('affiliation', 'affiliation.id', '=', 'users.affiliation_id')
->groupBy('affiliation.type')
->get();

return view('admin.dashboard.index', $stats);
}
}
138 changes: 133 additions & 5 deletions app/Http/Controllers/Api/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use App\Child;
use App\Household;
use App\HouseholdAddress;

use PHPExcel;
use PHPExcel_Worksheet;
use PHPExcel_Writer_Excel2007;

use League\Csv\Writer;

class Export extends Controller {
public function export_data_excel(Request $request) {
header('Content-type: application/vnd.ms-excel');
Expand All @@ -38,11 +43,7 @@ public function export_data_excel(Request $request) {
}
$sheet->fromArray($array, NULL, 'A' . $i++);
}
$cells = $sheet->getRowIterator()->current()->getCellIterator();
$cells->setIterateOnlyExistingCells(true);
foreach ($cells as $cell) {
$sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
}
Export::AutoSizeSheet($sheet);
$excel->addSheet($sheet);
}

Expand All @@ -56,4 +57,131 @@ public function export_data_excel(Request $request) {
flush();
exit(0);
}

static function AutoSizeSheet(&$sheet) {
$cells = $sheet->getRowIterator()->current()->getCellIterator();
$cells->setIterateOnlyExistingCells(true);
foreach ($cells as $cell) {
$sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
}
}

public function link_report() {
$excel = new PHPExcel();

$sheet = new PHPExcel_Worksheet($excel, "Heads of Household");
$sheet->fromArray(["Family Number", "Last Name", "First Name"], NULL, 'A1');
$households = Household::all(); // TODO ATN ::where('approved', 1);
$i=2;
foreach($households as $h) {
$sheet->fromArray([$h->id, $h->name_last, $h->name_first], NULL, 'A' . $i++);
}
Export::AutoSizeSheet($sheet);
$excel->addSheet($sheet);

$sheet = new PHPExcel_Worksheet($excel, "Children");
$sheet->fromArray([
"Family Number",
"Head of Household",
"Child Number",
"Child First Name",
"Age",
"Wish List",
"Bike?",
"Bike Style",
"Bike Size",
"Clothes?",
"Shirt Size",
"Pants Size",
"Shoe Size",

], NULL, 'A1');
$children = Child::join('household', 'household.id', '=', 'child.household_id')
->where('household.deleted_at')
->select('child.*')
->get();
$i=2;
foreach($children as $c) {
$sheet->fromArray([
$c->household_id,
$c->household->name_last . ", " . $c->household->name_first,
$c->id,
$c->name_first,
$c->age,
$c->additional_ideas,
($c->bike_want == "Y") ? "Yes" : "",
($c->bike_want == "Y") ? $c->bike_style : "",
($c->bike_want == "Y") ? $c->bike_size : "",
($c->clothes_want == "Y") ? "Yes" : "",
$c->clothes_size_shirt,
$c->clothes_size_pants,
$c->shoe_size,
], NULL, 'A' . $i++);
}
Export::AutoSizeSheet($sheet);
$excel->addSheet($sheet);

$excel->removeSheetByIndex(0);

header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="GiftProjectTheLinkReport_' . date("YmdHis") . '.xlsx"');
header('Cache-Control: max-age=0');

$writer = new PHPExcel_Writer_Excel2007($excel);
$writer->setOffice2003Compatibility(true);
$writer->save('php://output');

flush();
exit(0);
}

static function newCSV($headers) {
$csv = Writer::createFromFileObject(new \SplTempFileObject());
$csv->insertOne($headers);
return $csv;
}

public function bike_report() {
$csv = Export::newCSV(["family id", "child name", "age", "bike style", "bike size"]);
$children = Child::where('bike_want', 'Y')
->join('household', 'household.id', '=', 'child.household_id')
->where('approved', 1)
->get();
foreach($children as $child) {
$csv->insertOne([$child->household_id, $child->name_last . ", " . $child->name_first, $child->age, $child->bike_style, $child->bike_size]);
}
$csv->output('GiftProjectBikeReport_' . date("YmdHis") . '.csv');

flush();
exit(0);
}

public function division_report() {
$csv = Export::newCSV(["family number", "head of household", "street", "street2", "city", "state", "zip", "phone numbers", "email", "division", "response area"]);
$households = Household::where('approved', 1)->get();

foreach($households as $h) {
$a = $h->address->count() ? $h->address[0] : new HouseholdAddress();
$phones = implode(", ", array_map(function($p){
return $p['phone_number'] . " (" . $p['phone_type'] . ")";
}, $h->phone->toArray()));
$csv->insertOne([
$h->id,
$h->name_last . ", " . $h->name_first,
$a->address_street,
$a->address_street2,
$a->address_city,
$a->address_state,
$a->address_zip,
$phones,
$h->email,
$a->cmpd_division,
$a->cmpd_response_area]);
}

$csv->output('GiftProjectDivisionReport_' . date("YmdHis") . '.csv');

flush();
exit(0);
}
}
3 changes: 3 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
Route::get('cmpd_info', ['uses' => 'CmpdDivision@info']);
Route::post('upload_household_form_file', ['uses' => 'HouseholdController@upload_attachment']);
Route::get('export_data_excel', ['uses' => 'Export@export_data_excel']);
Route::get('bike_report', ['uses' => 'Export@bike_report']);
Route::get('division_report', ['uses' => 'Export@division_report']);
Route::get('link_report', ['uses' => 'Export@link_report']);
});

// Admin routes
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"delatbabel/elocryptfive": "1.5",
"greggilbert/recaptcha": "dev-master",
"league/flysystem-aws-s3-v3": "~1.0",
"phpoffice/phpexcel": "1.8.1"
"phpoffice/phpexcel": "1.8.1",
"league/csv": "8.1.2"
},
"require-dev": {
"mockery/mockery": "0.9.*",
Expand Down
61 changes: 59 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified public/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions resources/assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ $(function () {
todayHighlight: true
});

$('#color').colorpicker().on('changeColor.colorpicker', function (event) {
/*$('#color').colorpicker().on('changeColor.colorpicker', function (event) {
$(this).css('background-color', event.color.toHex());
});
});*/

if (!$('input[type=date]').val()) {
$('input[type=date]').datepicker("setDate", new Date());
Expand Down
Loading

0 comments on commit 23c1450

Please sign in to comment.