Update pengecekan hospital corporate
This commit is contained in:
@@ -172,23 +172,45 @@ class HospitalController extends Controller
|
|||||||
$failedRows = [];
|
$failedRows = [];
|
||||||
|
|
||||||
foreach ($processedData as $row) {
|
foreach ($processedData as $row) {
|
||||||
|
$q_check = DB::table('corporate_hospitals')
|
||||||
|
->where('code', '=', $row['code'])
|
||||||
|
->select('code')
|
||||||
|
->first();
|
||||||
$q = DB::table('organizations')
|
$q = DB::table('organizations')
|
||||||
->where('code', '=', $row['code'])
|
->where('code', '=', $row['code'])
|
||||||
->where('type', '=', 'hospital')
|
->where('type', '=', 'hospital')
|
||||||
->where('status', '=', 'active')
|
->where('status', '=', 'active')
|
||||||
->select('id', 'code', 'name')
|
->select('id', 'code', 'name')
|
||||||
->limit(1)
|
|
||||||
->first();
|
->first();
|
||||||
try {
|
try {
|
||||||
CorporateHospital::create(
|
if($q_check)
|
||||||
[
|
{
|
||||||
'corporate_id' => $corporate_id,
|
DB::table('corporate_hospitals')
|
||||||
'code' => $q->code,
|
->where('code','=', $q_check->code)
|
||||||
'name' => $q->name,
|
->update(
|
||||||
'organization_id' => $q->id,
|
[
|
||||||
'description' => $request->description ? $request->description : null,
|
'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++;
|
$importedRows++;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$failedRows[] = $row;
|
$failedRows[] = $row;
|
||||||
|
|||||||
Reference in New Issue
Block a user