Update
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Internal\Http\Controllers\Api;
|
||||
|
||||
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\OLDLMS\DoctorRating;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||
use Box\Spout\Common\Entity\Style\CellAlignment;
|
||||
|
||||
class KatalogDokterController extends Controller
|
||||
{
|
||||
public function getData(Request $request)
|
||||
{
|
||||
$limit = $request->has('per_page') ? $request->input('per_page') : 50;
|
||||
$results = DB::connection('oldlms')->table('tm_dokter')
|
||||
->leftJoin('tm_users', 'tm_dokter.nIDUser', '=', 'tm_users.nID')
|
||||
->leftJoin('tx_jadwal_dokter', 'tm_dokter.nID', '=', 'tx_jadwal_dokter.nIDDokter')
|
||||
->leftJoin('tm_users_education', 'tm_dokter.nIDUser', '=', 'tm_users_education.nIDUser')
|
||||
->leftJoin('tm_healthcare', 'tx_jadwal_dokter.nIDHealthCare', '=', 'tm_healthcare.nID')
|
||||
->when($request->input('search'), function ($query, $search) {
|
||||
$query->where(function ($query) use ($search) {
|
||||
$query->orWhere('tm_users.sFirstname', 'like', "%" . $search . "%");
|
||||
$query->orWhere('tm_dokter.sSTR', 'like', "%" . $search . "%");
|
||||
$query->orWhere('tm_healthcare.sHealthCare', 'like', "%" . $search . "%");
|
||||
});
|
||||
})
|
||||
->when($request->has('orderBy'), function ($query) use ($request) {
|
||||
$orderBy = $request->orderBy;
|
||||
$direction = $request->order ?? 'asc';
|
||||
|
||||
$query->orderBy($orderBy, $direction);
|
||||
})
|
||||
->when($request->input('start_date') , function ($query, $start_date) {
|
||||
$query->where(function ($query) use ($start_date) {
|
||||
$query->where('tm_dokter.dSTRExpireDate', '>=', $start_date. ' 00:00:00');
|
||||
});
|
||||
})
|
||||
->when($request->input('end_date') , function ($query, $end_date) {
|
||||
$query->where(function ($query) use ($end_date) {
|
||||
$query->where('tm_dokter.dSTRExpireDate', '<=', $end_date. ' 23:59:59');
|
||||
});
|
||||
})
|
||||
// ->when($request->input('provider') , function ($query, $provider) {
|
||||
// $query->where(function ($query) use ($provider) {
|
||||
// $query->where('request_logs.organization_id', '=', $provider);
|
||||
// });
|
||||
// })
|
||||
// ->where('files.fileable_type', '=', 'App\Models\RequestLog')
|
||||
// ->where('request_logs.final_log', '=', '1')
|
||||
// ->where('request_logs.status_final_log', '=', 'approved')
|
||||
->select(
|
||||
DB::connection('oldlms')->raw("CONCAT(tm_users.sFirstName, ' ', IFNULL(tm_users.sMiddleName, ''), ' ', IFNULL(tm_users.sLastName, '')) as nama_dokter"),
|
||||
'tm_users_education.sUniversitas as lulusan',
|
||||
'tm_dokter.sSTR as str',
|
||||
'tx_jadwal_dokter.sSIP as sip',
|
||||
'tm_healthcare.sHealthCare as tempat_praktek',
|
||||
)
|
||||
->paginate($limit);
|
||||
|
||||
|
||||
|
||||
return response()->json(Helper::paginateResources($results));
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$start_date = $request->input('start_date') ? $request->input('start_date') : 'all';
|
||||
$end_date = $request->input('end_date') ? $request->input('end_date') : 'all';
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
$writer->openToFile(public_path('files/Report-Data-Katalog-Dokter-'.$start_date.'-'.$end_date.'.xlsx'));
|
||||
$header = [
|
||||
'No',
|
||||
'Nama Dokter',
|
||||
'Lulusan',
|
||||
'STR',
|
||||
'SIP',
|
||||
'Tempat Praktek',
|
||||
];
|
||||
$style = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
// ->setFontSize(15)
|
||||
// ->setFontColor(Color::BLUE)
|
||||
// ->setShouldWrapText()
|
||||
->setCellAlignment(CellAlignment::LEFT)
|
||||
// ->setBackgroundColor(Color::YELLOW)
|
||||
->build();
|
||||
|
||||
$headerRow = WriterEntityFactory::createRowFromArray($header, $style);
|
||||
$writer->addRow($headerRow);
|
||||
// ============================
|
||||
$results = DB::connection('oldlms')->table('tm_dokter')
|
||||
->leftJoin('tm_users', 'tm_dokter.nIDUser', '=', 'tm_users.nID')
|
||||
->leftJoin('tx_jadwal_dokter', 'tm_dokter.nID', '=', 'tx_jadwal_dokter.nIDDokter')
|
||||
->leftJoin('tm_users_education', 'tm_dokter.nIDUser', '=', 'tm_users_education.nIDUser')
|
||||
->leftJoin('tm_healthcare', 'tx_jadwal_dokter.nIDHealthCare', '=', 'tm_healthcare.nID')
|
||||
->when($request->input('search'), function ($query, $search) {
|
||||
$query->where(function ($query) use ($search) {
|
||||
$query->orWhere('tm_users.sFirstname', 'like', "%" . $search . "%");
|
||||
$query->orWhere('tm_dokter.sSTR', 'like', "%" . $search . "%");
|
||||
$query->orWhere('tm_healthcare.sHealthCare', 'like', "%" . $search . "%");
|
||||
});
|
||||
})
|
||||
->when($request->has('orderBy'), function ($query) use ($request) {
|
||||
$orderBy = $request->orderBy;
|
||||
$direction = $request->order ?? 'asc';
|
||||
|
||||
$query->orderBy($orderBy, $direction);
|
||||
})
|
||||
->when($request->input('start_date') , function ($query, $start_date) {
|
||||
$query->where(function ($query) use ($start_date) {
|
||||
$query->where('tm_dokter.dSTRExpireDate', '>=', $start_date. ' 00:00:00');
|
||||
});
|
||||
})
|
||||
->when($request->input('end_date') , function ($query, $end_date) {
|
||||
$query->where(function ($query) use ($end_date) {
|
||||
$query->where('tm_dokter.dSTRExpireDate', '<=', $end_date. ' 23:59:59');
|
||||
});
|
||||
})
|
||||
// ->when($request->input('provider') , function ($query, $provider) {
|
||||
// $query->where(function ($query) use ($provider) {
|
||||
// $query->where('request_logs.organization_id', '=', $provider);
|
||||
// });
|
||||
// })
|
||||
// ->where('files.fileable_type', '=', 'App\Models\RequestLog')
|
||||
// ->where('request_logs.final_log', '=', '1')
|
||||
// ->where('request_logs.status_final_log', '=', 'approved')
|
||||
->select(
|
||||
DB::connection('oldlms')->raw("CONCAT(tm_users.sFirstName, ' ', IFNULL(tm_users.sMiddleName, ''), ' ', IFNULL(tm_users.sLastName, '')) as nama_dokter"),
|
||||
'tm_users_education.sUniversitas as lulusan',
|
||||
'tm_dokter.sSTR as str',
|
||||
'tx_jadwal_dokter.sSIP as sip',
|
||||
'tm_healthcare.sHealthCare as tempat_praktek',
|
||||
)
|
||||
->get();
|
||||
$no=0;
|
||||
foreach($results as $item)
|
||||
{
|
||||
$no++;
|
||||
$rowData = [
|
||||
$no,
|
||||
$item->nama_dokter,
|
||||
$item->lulusan,
|
||||
$item->str,
|
||||
$item->sip,
|
||||
$item->tempat_praktek,
|
||||
];
|
||||
$style = (new StyleBuilder())
|
||||
//->setFontBold()
|
||||
// ->setFontSize(15)
|
||||
// ->setFontColor(Color::BLUE)
|
||||
// ->setShouldWrapText()
|
||||
->setCellAlignment(CellAlignment::LEFT)
|
||||
// ->setBackgroundColor(Color::YELLOW)
|
||||
->build();
|
||||
$row = WriterEntityFactory::createRowFromArray($rowData, $style);
|
||||
$writer->addRow($row);
|
||||
}
|
||||
$footer = [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
''
|
||||
];
|
||||
$style = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
// ->setFontSize(15)
|
||||
// ->setFontColor(Color::BLUE)
|
||||
// ->setShouldWrapText()
|
||||
->setCellAlignment(CellAlignment::LEFT)
|
||||
// ->setBackgroundColor(Color::YELLOW)
|
||||
->build();
|
||||
|
||||
$footerRow = WriterEntityFactory::createRowFromArray($footer, $style);
|
||||
$writer->addRow($footerRow);
|
||||
|
||||
$writer->close();
|
||||
|
||||
return Helper::responseJson([
|
||||
'file_name' => 'Report-Data-Katalog-Dokter-'. $start_date.'-'.$end_date,
|
||||
"file_url" => url('files/Report-Data-Katalog-Dokter-'. $start_date.'-'.$end_date.'.xlsx')
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user