Update pengecekan hospital corporate

This commit is contained in:
ivan-sim
2023-11-16 09:24:31 +07:00
parent 0dc10587a8
commit 77fdb46c46

View File

@@ -172,23 +172,45 @@ class HospitalController extends Controller
$failedRows = [];
foreach ($processedData as $row) {
$q_check = DB::table('corporate_hospitals')
->where('code', '=', $row['code'])
->select('code')
->first();
$q = DB::table('organizations')
->where('code', '=', $row['code'])
->where('type', '=', 'hospital')
->where('status', '=', 'active')
->select('id', 'code', 'name')
->limit(1)
->first();
try {
CorporateHospital::create(
[
'corporate_id' => $corporate_id,
'code' => $q->code,
'name' => $q->name,
'organization_id' => $q->id,
'description' => $request->description ? $request->description : null,
]
);
if($q_check)
{
DB::table('corporate_hospitals')
->where('code','=', $q_check->code)
->update(
[
'corporate_id' => $corporate_id,
'code' => $q->code,
'name' => $q->name,
'organization_id' => $q->id,
'description' => $request->description ? $request->description : null,
'updated_by' =>auth()->user()->id,
'updated_at' => date('Y-m-d H:i:s'),
]
);
}
else
{
CorporateHospital::create(
[
'corporate_id' => $corporate_id,
'code' => $q->code,
'name' => $q->name,
'organization_id' => $q->id,
'description' => $request->description ? $request->description : null,
]
);
}
$importedRows++;
} catch (\Exception $e) {
$failedRows[] = $row;