Merge remote-tracking branch 'origin/staging' into origin/production

This commit is contained in:
Linksehat Staging Server
2023-09-04 15:07:09 +07:00
206 changed files with 29759 additions and 24113 deletions

View File

@@ -404,10 +404,11 @@ class CorporateController extends Controller
$file_name = now()->getPreciseTimestamp(3) . '-' . $request->file('file')->getClientOriginalName();
$file = $request->file('file')->storeAs('temp', $file_name);
$corporate = Corporate::with(['plans'])->findOrFail($corporate_id);
$fileWrite = Storage::disk('public')->path('temp/result-' . $file_name);
$fileRead = Storage::path('temp/' . $file_name);
$import = new ImportService();
$import->read(Storage::path('temp/' . $file_name));
$import->write(Storage::disk('public')->path('temp/result-' . $file_name), 'xsls');
$import->read($fileRead);
$import->write($fileWrite, 'xsls');
foreach ($import->sheetsIterator() as $sheetIndex => $sheet) {
if (!in_array($sheet->getName(), ['Plan', 'Benefit'])) {
@@ -430,9 +431,11 @@ class CorporateController extends Controller
// Write Header to File
$result_headers = array_keys($headers_map_to_table_fields);
$result_headers = array_merge($result_headers, ['Ingest Code', 'Ingest Note']);
// $import->read($fileRead);
// $import->write($fileWrite, 'xsls');
$import->addArrayToRow($result_headers);
}
$doc_headers_indexes = [];
foreach ($sheet->getRowIterator() as $index => $row) {
if ($index == 1) { // First Row Must be Header
@@ -447,12 +450,10 @@ class CorporateController extends Controller
// TODO Validate if First Row not Header
} else { // Next Row Should be Data
$row_data = [];
foreach ($row->getCells() as $header_index => $cell) {
if (isset($headers_map_to_table_fields[$doc_headers_indexes[$header_index]]))
$row_data[$headers_map_to_table_fields[$doc_headers_indexes[$header_index]]] = $cell->getValue();
}
try { // Process the Row Data
$corporateService = new CorporateService();
if ($sheet->getName() == 'Plan') {
@@ -461,12 +462,16 @@ class CorporateController extends Controller
$corporateService->handleBenefitRow($corporate, $row_data);
}
// Write Success Result to File
$import->addArrayToRow(array_merge($row_data, [
'Ingest Code' => 200,
'Ingest Note' => 'Success',
]), $sheet->getName());
// $import->read($fileRead);
// $import->write($fileWrite, 'xsls');
$result_headers = array_merge($row_data, ['Ingest Code' =>200, 'Ingest Note' => 'Success']);
$import->addArrayToRow($result_headers, $sheet->getName());
} catch (ImportRowException $e) {
// Write Data Validation Error to File
// $import->read($fileRead);
// $import->write($fileWrite, 'xsls');
$import->addArrayToRow(array_merge($row_data, [
'Ingest Code' => $e->getCode(),
'Ingest Note' => $e->getMessage(),
@@ -474,6 +479,8 @@ class CorporateController extends Controller
} catch (\Exception $e) {
// throw new \Exception($e);
// Write Server Error to File
// $import->read($fileRead);
// $import->write($fileWrite, 'xsls');
$import->addArrayToRow(array_merge($row_data, [
'Ingest Code' => 500,
'Ingest Note' => env('APP_DEBUG') ? $e->getMessage() : 'Server Error',

View File

@@ -92,7 +92,7 @@ class DivisionController extends Controller
'code' => [
'required',
// Rule::unique('corporate_plans')->where('corporate_id', $corporate_id)->ignore($corporatePlan->id)
Rule::unique('corporate_divisions')->where('corporate_id', $corporate_id)
// Rule::unique('corporate_divisions')->where('corporate_id', $corporate_id)
],
'name' => 'required'
]);

View File

@@ -0,0 +1,103 @@
<?php
namespace Modules\Internal\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use App\Models\OLDLMS\DoctorRating;
class DoctorRatingController extends Controller
{
/**
* Display a listing of the resource.
* @param int|null $id
* @return \Illuminate\Http\JsonResponse
*/
public function index($id = null)
{
$query = DoctorRating::query();
if ($id !== null) {
$query->where('nID', $id);
}
$doctorRatings = $query->with([
'user' => function ($query) {
$query->select('nID', 'sFirstName'); // Select only necessary columns
}
])
->select('nIDUser', 'nIDDokter', 'nRating', 'sNotes', 'dCreateOn')
->get();
// $prescriptions->toArray();
// dd($prescriptions);
return response()->json($doctorRatings);
// return response()->json(Helper::paginateResources(LivechatResource::collection($livechat)));
}
/**
* Show the form for creating a new resource.
* @return Renderable
*/
public function create()
{
return view('internal::create');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view('internal::edit');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}

View File

@@ -5,9 +5,14 @@ namespace Modules\Internal\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Models\OLDLMS\Livechat;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Modules\Internal\Transformers\LivechatResource;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class LivechatController extends Controller
{
@@ -15,34 +20,29 @@ class LivechatController extends Controller
* Display a listing of the resource.
* @return Renderable
*/
public function index()
public function index(Request $request)
{
$startDate = $request->startDate;
$endDate = $request->endDate;
$livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare')
->where('nIDAppointment', '!=', null)->where('nIDAppointment', '!=', '')
->latest()
->paginate(15);
->where('nIDAppointment', '!=', null)
->where('nIDAppointment', '!=', '');
if ($startDate) {
$livechat = $livechat->where('dCreateOn', '>=', $startDate);
}
if ($endDate) {
$livechat = $livechat->where('dCreateOn', '<=', $endDate);
}
$livechat = $livechat->latest()->paginate(15);
return response()->json(Helper::paginateResources(LivechatResource::collection($livechat)));
}
/**
* Show the form for creating a new resource.
* @return Renderable
*/
public function create()
{
return view('internal::create');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
}
/**
* Show the specified resource.
* @param int $id
@@ -57,34 +57,95 @@ class LivechatController extends Controller
return response()->json(new LivechatResource($livechat));
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
public function export(Request $request)
{
return view('internal::edit');
}
$startDate = $request->has('startDate') ? $request->input('startDate') : '';
$endDate = $request->has('endDate') ? $request->input('endDate') : '';
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}
$liveChats = Livechat::with('user:nID,sFirstName,sLastName,sEmail,sPhone', 'doctor:nID,nIDSpesialis,nIDUser', 'doctor.user:nID,sFirstName,sLastName', 'appointment:nID,sPaymentStatus', 'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment', 'healthCare:nID,sHealthCare')
->where(function (Builder $query) use ($startDate, $endDate) {
// $query->where('nIDAppointment', '!=', null);
// $query->where('nIDAppointment', '!=', '');
if ($startDate) {
$query->where('dCreateOn', '>=', $startDate);
}
if ($endDate) {
$query->where('dCreateOn', '<=', $endDate);
}
})
->get(['nId', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia']);
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
$headers = [
['value' => 'No', 'cell' => 'A1', 'mergeCell' => true, 'mergeToCell' => 'A2'],
['value' => 'Nama Dokter', 'cell' => 'B1', 'mergeCell' => true, 'mergeToCell' => 'B2'],
['value' => 'Nama Pasien', 'cell' => 'C1', 'mergeCell' => true, 'mergeToCell' => 'C2'],
['value' => 'No Telepon Pasien', 'cell' => 'D1', 'mergeCell' => true, 'mergeToCell' => 'D2'],
['value' => 'Email Pasien', 'cell' => 'E1', 'mergeCell' => true, 'mergeToCell' => 'E2'],
['value' => 'Faskes', 'cell' => 'F1', 'mergeCell' => true, 'mergeToCell' => 'F2'],
['value' => 'Tanggal Appointment', 'cell' => 'G1', 'mergeCell' => true, 'mergeToCell' => 'G2'],
['value' => 'Chat Via App/Website', 'cell' => 'H1', 'mergeCell' => true, 'mergeToCell' => 'I1'],
['value' => 'Pasien', 'cell' => 'H2', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Dokter', 'cell' => 'I2', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Status Appointment', 'cell' => 'J1', 'mergeCell' => true, 'mergeToCell' => 'J2'],
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
foreach ($headers as $header) {
$sheet->setCellValue($header['cell'], $header['value']);
if ($header['mergeCell'] === true) {
$sheet->mergeCells($header['cell'] . ':' . $header['mergeToCell']);
}
$sheet->getStyle($header['cell'])->getFont()->setBold(true);
$sheet->getStyle($header['cell'])->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
}
$startFrom = 3;
foreach ($liveChats as $indexLiveChat => $liveChat) {
$sheet->setCellValue('A' . $startFrom, $indexLiveChat + 1);
$sheet->setCellValue('B' . $startFrom, $liveChat->doctor->user->full_name ?? '-');
$sheet->setCellValue('C' . $startFrom, $liveChat->user->full_name ?? '-');
$sheet->setCellValue('D' . $startFrom, preg_replace('/(\d{3})(\d{4})(\d{3})/', '$1 $2 $3', $liveChat->user->sPhone) ?? '-');
$sheet->setCellValue('E' . $startFrom, $liveChat->user->sEmail ?? '-');
$sheet->setCellValue('F' . $startFrom, $liveChat->healthCare->sHealthCare ?? '-');
$sheet->setCellValue('G' . $startFrom, isset($liveChat->appointment->appointmentDetail) ? Carbon::parse($liveChat->appointment->appointmentDetail->dTanggalAppointment)->format('d-m-Y') . ' ' . $liveChat->appointment->appointmentDetail->tTimeAppointment : '-');
$sheet->setCellValue('H' . $startFrom, $liveChat->sMedia ?? '-');
$sheet->setCellValue('I' . $startFrom, $liveChat->sMediaDokter ?? '-');
$sheet->setCellValue('J' . $startFrom, $liveChat->appointment->paymentStatus ?? '-');
$startFrom++;
}
foreach (['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] as $header) {
if ($header === 'A') {
$spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(35, 'px');
} elseif ($header === 'H' || $header === 'I') {
$spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(100, 'px');
} else {
$spreadsheet->getActiveSheet()->getColumnDimension($header)->setAutoSize(true);
}
}
$spreadsheet->getActiveSheet()->getStyle('A3:A' . $startFrom)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet->getDefaultRowDimension()->setRowHeight(-1);
$sheet->setTitle('Live Chat Report');
$writer = new Xlsx($spreadsheet);
ob_start();
$writer->save('php://output');
$content = ob_get_contents();
ob_end_clean();
$fileName = 'result-' . now()->getPreciseTimestamp(3) . '-livechat-report.xlsx';
Storage::disk('public')->put('temp/' . $fileName, $content);
$fileUrl = url('storage/temp/' . $fileName);
return Helper::responseJson([
"file_url" => $fileUrl
]);
}
}

View File

@@ -120,7 +120,6 @@ class PlanController extends Controller
$result_headers = array_keys($headers_map_to_table_fields);
array_push($result_headers, ['Ingest Code', 'Ingest Note']);
$import->addArrayToRow($result_headers);
die('fuck');
$imported_plan_data = 0;
$failed_plan_data = [];