Update Bugs Fix Import
This commit is contained in:
@@ -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'])) {
|
||||
@@ -431,7 +432,8 @@ class CorporateController extends Controller
|
||||
$result_headers = array_keys($headers_map_to_table_fields);
|
||||
$result_headers = array_merge($result_headers, ['Ingest Code', 'Ingest Note']);
|
||||
|
||||
// dd($result_headers);
|
||||
$import->read($fileRead);
|
||||
$import->write($fileWrite, 'xsls');
|
||||
$import->addArrayToRow($result_headers);
|
||||
}
|
||||
$doc_headers_indexes = [];
|
||||
@@ -460,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(),
|
||||
@@ -473,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',
|
||||
|
||||
Reference in New Issue
Block a user