update import/export excel request log
This commit is contained in:
@@ -16,6 +16,12 @@ use Illuminate\Support\Facades\Storage;
|
||||
use App\Services\RequestLogService;
|
||||
use App\Exceptions\ImportRowException;
|
||||
use App\Events\RequestLoged;
|
||||
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
|
||||
|
||||
use Exception;
|
||||
use PDF;
|
||||
|
||||
@@ -207,7 +213,7 @@ class RequestLogController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Request LOG
|
||||
* Generate Request LOG PDF
|
||||
*/
|
||||
public function generateRequestLog($id)
|
||||
{
|
||||
@@ -238,6 +244,55 @@ class RequestLogController extends Controller
|
||||
return $requestLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Export Excel Request LOG
|
||||
*/
|
||||
|
||||
public function generateDataRequestLogExcel(){
|
||||
$file_name = 'Data Request LOG';
|
||||
// Membuat penulis entitas Spout
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
// Membuka penulis untuk menulis ke file
|
||||
$writer->openToFile(public_path('files/Data Request LOG.xlsx'));
|
||||
|
||||
// Sheet 1
|
||||
$writer->getCurrentSheet()->setName('Data');
|
||||
$headers_map_to_table_fields = RequestLog::$listing_data_doc_headers;
|
||||
$headerRow = WriterEntityFactory::createRowFromArray($headers_map_to_table_fields);
|
||||
$writer->addRow($headerRow);
|
||||
|
||||
$dataRequestLog = RequestLog::query()
|
||||
// ->whereHas('corporatePlan', function ($corporatePlan) use ($corporate_id) {
|
||||
// $corporatePlan->where('corporate_id', $corporate_id);
|
||||
// })
|
||||
->with('member')
|
||||
->orderBy('id', 'desc')
|
||||
->get()->toArray();
|
||||
|
||||
// dd($dataRequestLog);
|
||||
foreach ($dataRequestLog as $index => $row){
|
||||
$serviceType = $this->getServiceName($row['service_code']);
|
||||
|
||||
$rowData = [
|
||||
$row['id'], // id
|
||||
$row['code'], // code
|
||||
$row['member']['name'], // name
|
||||
$row['submission_date'], // submission date
|
||||
$serviceType, // service type
|
||||
$row['payment_type_name'], // service type
|
||||
$row['status'], // service type
|
||||
];
|
||||
$row = WriterEntityFactory::createRowFromArray($rowData);
|
||||
$writer->addRow($row);
|
||||
}
|
||||
$writer->close();
|
||||
|
||||
return Helper::responseJson([
|
||||
'file_name' => "Data Request Log " . date('Y-m-d h:i:s'),
|
||||
"file_url" => url('files/Data Request LOG.xlsx')
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateFinalLog(Request $request, $id)
|
||||
{
|
||||
$requestLog = RequestLog::findOrFail($id);
|
||||
@@ -350,7 +405,7 @@ class RequestLogController extends Controller
|
||||
|
||||
}
|
||||
|
||||
public function importClaim(Request $request)
|
||||
public function importRequestLog(Request $request)
|
||||
{
|
||||
|
||||
$request->validate([
|
||||
@@ -398,38 +453,20 @@ class RequestLogController extends Controller
|
||||
$row_data[$headers_map_to_table_fields[$doc_headers_indexes[$header_index]]] = $cell->getValue();
|
||||
}
|
||||
try { // Process the Row Data
|
||||
$claimRequestService = new RequestLogService();
|
||||
$requestLog = new RequestLogService();
|
||||
|
||||
$claimRequestService->handleRequestLogRow($row_data);
|
||||
$requestLog->handleRequestLogRow($row_data);
|
||||
|
||||
// Write Success Result to File
|
||||
// $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(),
|
||||
]), $sheet->getName());
|
||||
}
|
||||
// catch (\Exception $e) {
|
||||
// // throw new \Exception($e);
|
||||
// // Write Server Error to File
|
||||
// // $import->read($fileRead);
|
||||
// // $import->write($fileWrite, 'xsls');
|
||||
// dd( $e->getMessage());
|
||||
// $import->addArrayToRow(array_merge($row_data, [
|
||||
// 'Ingest Code' => 500,
|
||||
// 'Ingest Note' => env('APP_DEBUG') ? $e->getMessage() : 'Server Error',
|
||||
// ]), $sheet->getName());
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -623,6 +660,15 @@ class RequestLogController extends Controller
|
||||
return $service;
|
||||
}
|
||||
|
||||
public function getServiceName($code){
|
||||
$service = DB::table('services')
|
||||
->select('name')
|
||||
->where('code', $code)
|
||||
->get()
|
||||
->first();
|
||||
return $service->name;
|
||||
}
|
||||
|
||||
public static function getNextCode(Request $request)
|
||||
{
|
||||
// $last_number = RequestLog::max('code');
|
||||
|
||||
Reference in New Issue
Block a user