feat(webstatement): tambahkan pengaturan tujuan output dan unggah ke SFTP untuk combine PDF
- Memperbarui `CombinePdfJob`:
- Menambahkan parameter baru `outputDestination`, `branchCode`, dan `period` pada constructor untuk pengaturan tujuan output.
- Menambahkan opsi tujuan output ke `local` atau `sftp` pada proses combine PDF.
- Menambahkan metode baru `uploadToSftp` untuk mengunggah file PDF hasil gabungan ke SFTP.
- Mengatur jalur unggahan SFTP ke `combine/{period}/{branchCode}/{filename}`.
- Menambahkan log informasi terkait jalur dan status unggahan file PDF ke SFTP.
- Memperbarui `CombinePdfController`:
- Menambahkan konfigurasi `output_destination` untuk menentukan tujuan output (`local` atau `sftp`).
- Memperbarui pemanggilan `CombinePdfJob::dispatch` dengan parameter baru untuk konfigurasi output dan SFTP.
- Menyesuaikan log dan respons untuk mencerminkan tujuan output yang disetel.
- Tujuan pembaruan ini:
- Memungkinkan pengaturan flexibel tujuan penyimpanan file PDF ke lokal atau SFTP.
- Menyediakan log yang lebih informatif terkait proses combine PDF dan unggahan SFTP.
- Mempermudah integrasi dan pengelolaan file PDF dengan pengaturan jalur dan periodisasi yang jelas.
Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -32,6 +32,9 @@ class CombinePdfController extends Controller
|
|||||||
// Configuration: Set r23 file source - 'local' or 'sftp'
|
// Configuration: Set r23 file source - 'local' or 'sftp'
|
||||||
$file_r23 = 'local'; // Change this to 'sftp' to use SFTP for r23 files
|
$file_r23 = 'local'; // Change this to 'sftp' to use SFTP for r23 files
|
||||||
|
|
||||||
|
// Configuration: Set output destination - 'local' or 'sftp'
|
||||||
|
$output_destination = 'local'; // Change this to 'sftp' to upload combined PDFs to SFTP
|
||||||
|
|
||||||
// Get period from request or use current period
|
// Get period from request or use current period
|
||||||
$period = $period ?? date('Ym');
|
$period = $period ?? date('Ym');
|
||||||
|
|
||||||
@@ -112,10 +115,10 @@ class CombinePdfController extends Controller
|
|||||||
$password = $this->generatePassword($account);
|
$password = $this->generatePassword($account);
|
||||||
|
|
||||||
// Dispatch job to combine PDFs or apply password protection
|
// Dispatch job to combine PDFs or apply password protection
|
||||||
CombinePdfJob::dispatch($pdfFiles, $outputDir, $outputFilename, $password);
|
CombinePdfJob::dispatch($pdfFiles, $outputDir, $outputFilename, $password, $output_destination, $branchCode, $period);
|
||||||
$processedCount++;
|
$processedCount++;
|
||||||
|
|
||||||
Log::info("Queued PDF processing for account {$accountNumber} - r14: local, r23: {$file_r23}, password: {$password}");
|
Log::info("Queued PDF processing for account {$accountNumber} - r14: local, r23: {$file_r23}, output: {$output_destination}, password: {$password}");
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error("Error processing PDF for account {$accountNumber}: {$e->getMessage()}");
|
Log::error("Error processing PDF for account {$accountNumber}: {$e->getMessage()}");
|
||||||
$errorCount++;
|
$errorCount++;
|
||||||
@@ -123,7 +126,7 @@ class CombinePdfController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => "PDF combination process has been queued (r14: local, r23: {$file_r23})",
|
'message' => "PDF combination process has been queued (r14: local, r23: {$file_r23}, output: {$output_destination})",
|
||||||
'processed' => $processedCount,
|
'processed' => $processedCount,
|
||||||
'skipped' => $skippedCount,
|
'skipped' => $skippedCount,
|
||||||
'errors' => $errorCount,
|
'errors' => $errorCount,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Owenoj\PDFPasswordProtect\Facade\PDFPasswordProtect;
|
use Owenoj\PDFPasswordProtect\Facade\PDFPasswordProtect;
|
||||||
use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger;
|
use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger;
|
||||||
|
|
||||||
@@ -21,6 +22,9 @@ class CombinePdfJob implements ShouldQueue
|
|||||||
protected $outputPath;
|
protected $outputPath;
|
||||||
protected $outputFilename;
|
protected $outputFilename;
|
||||||
protected $password;
|
protected $password;
|
||||||
|
protected $outputDestination;
|
||||||
|
protected $branchCode;
|
||||||
|
protected $period;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
@@ -29,13 +33,19 @@ class CombinePdfJob implements ShouldQueue
|
|||||||
* @param string $outputPath Directory where the combined PDF will be saved
|
* @param string $outputPath Directory where the combined PDF will be saved
|
||||||
* @param string $outputFilename Filename for the combined PDF
|
* @param string $outputFilename Filename for the combined PDF
|
||||||
* @param string $password Password to protect the PDF
|
* @param string $password Password to protect the PDF
|
||||||
|
* @param string $outputDestination Output destination: 'local' or 'sftp'
|
||||||
|
* @param string $branchCode Branch code for SFTP path
|
||||||
|
* @param string $period Period for SFTP path
|
||||||
*/
|
*/
|
||||||
public function __construct(array $pdfFiles, string $outputPath, string $outputFilename, string $password)
|
public function __construct(array $pdfFiles, string $outputPath, string $outputFilename, string $password, string $outputDestination = 'local', string $branchCode = '', string $period = '')
|
||||||
{
|
{
|
||||||
$this->pdfFiles = $pdfFiles;
|
$this->pdfFiles = $pdfFiles;
|
||||||
$this->outputPath = $outputPath;
|
$this->outputPath = $outputPath;
|
||||||
$this->outputFilename = $outputFilename;
|
$this->outputFilename = $outputFilename;
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
|
$this->outputDestination = $outputDestination;
|
||||||
|
$this->branchCode = $branchCode;
|
||||||
|
$this->period = $period;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,10 +96,43 @@ class CombinePdfJob implements ShouldQueue
|
|||||||
Log::info("PDF password protection applied successfully.");
|
Log::info("PDF password protection applied successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info("PDFs combined successfully. Output file: {$fullPath}");
|
// Handle output destination
|
||||||
|
if ($this->outputDestination === 'sftp') {
|
||||||
|
$this->uploadToSftp($fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info("PDFs combined successfully. Output file: {$fullPath}, Destination: {$this->outputDestination}");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error("Error combining PDFs: " . $e->getMessage());
|
Log::error("Error combining PDFs: " . $e->getMessage());
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload the combined PDF to SFTP server
|
||||||
|
*
|
||||||
|
* @param string $localFilePath
|
||||||
|
*/
|
||||||
|
private function uploadToSftp(string $localFilePath): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Define SFTP path: combine/{period}/{branchCode}/{filename}
|
||||||
|
$sftpPath = "combine/{$this->period}/{$this->branchCode}/{$this->outputFilename}";
|
||||||
|
|
||||||
|
// Read the local file content
|
||||||
|
$fileContent = File::get($localFilePath);
|
||||||
|
|
||||||
|
// Upload to SFTP
|
||||||
|
Storage::disk('sftpStatement')->put($sftpPath, $fileContent);
|
||||||
|
|
||||||
|
Log::info("Combined PDF uploaded to SFTP: {$sftpPath}");
|
||||||
|
|
||||||
|
// Optionally, remove the local file after successful upload
|
||||||
|
// File::delete($localFilePath);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error("Error uploading combined PDF to SFTP: {$e->getMessage()}");
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user