feat(webstatement): tambah dukungan upload SFTP per cabang
Menambahkan parameter "branch" untuk mendukung upload file CSV ke direktori SFTP berdasarkan cabang. Perubahan ini mencakup: - Memodifikasi fungsi `uploadToSftpKartu` agar menerima parameter cabang untuk menentukan direktori tujuan di SFTP. - Membuat log upload yang lebih spesifik untuk setiap cabang berdasarkan parameter "branch". - Memastikan direktori cabang pada SFTP dibuat jika belum ada. - Menyesuaikan fungsi `updateSftpLogSuccess` untuk mencatat log keberhasilan berdasarkan cabang. - Mengupdate log pembuatan dan upload CSV agar mencantumkan informasi cabang. - Menyesuaikan format log `updateCsvLogSuccess` untuk menangani pembuatan file CSV untuk beberapa cabang. Perubahan ini memastikan fleksibilitas dan akuntabilitas dalam mengelola file CSV biaya kartu per cabang. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -273,8 +273,7 @@
|
|||||||
*
|
*
|
||||||
* @return bool True if upload successful, false otherwise
|
* @return bool True if upload successful, false otherwise
|
||||||
*/
|
*/
|
||||||
private function uploadToSftpKartu(string $localFilePath)
|
private function uploadToSftpKartu(string $localFilePath, string $branch = ''): bool
|
||||||
: bool
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Update status SFTP upload dimulai
|
// Update status SFTP upload dimulai
|
||||||
@@ -294,26 +293,37 @@
|
|||||||
$disk = Storage::disk('sftpKartu');
|
$disk = Storage::disk('sftpKartu');
|
||||||
|
|
||||||
// Tentukan path tujuan di server SFTP
|
// Tentukan path tujuan di server SFTP
|
||||||
$remotePath = env('BIAYA_KARTU_REMOTE_PATH', '/');
|
$remotePath = env('BIAYA_KARTU_REMOTE_PATH', '/');
|
||||||
|
|
||||||
|
// Add branch directory if provided
|
||||||
|
if (!empty($branch)) {
|
||||||
|
$remotePath = rtrim($remotePath, '/') . '/' . $branch;
|
||||||
|
|
||||||
|
// Create branch directory if it doesn't exist
|
||||||
|
if (!$disk->exists($remotePath)) {
|
||||||
|
$disk->makeDirectory($remotePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$remoteFilePath = rtrim($remotePath, '/') . '/' . $filename;
|
$remoteFilePath = rtrim($remotePath, '/') . '/' . $filename;
|
||||||
|
|
||||||
// Upload file ke server SFTP
|
// Upload file ke server SFTP
|
||||||
$result = $disk->put($remoteFilePath, $fileContent);
|
$result = $disk->put($remoteFilePath, $fileContent);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->updateSftpLogSuccess();
|
$this->updateSftpLogSuccess($branch);
|
||||||
Log::info("File CSV biaya kartu ATM berhasil diunggah ke SFTP: {$remoteFilePath}");
|
Log::info("File CSV biaya kartu ATM untuk cabang {$branch} berhasil diunggah ke SFTP: {$remoteFilePath}");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->updateSftpLogFailed("Gagal mengunggah file CSV biaya kartu ATM ke SFTP: {$remoteFilePath}");
|
$this->updateSftpLogFailed("Gagal mengunggah file CSV biaya kartu ATM ke SFTP: {$remoteFilePath}");
|
||||||
|
|
||||||
Log::error("Gagal mengunggah file CSV biaya kartu ATM ke SFTP: {$remoteFilePath}");
|
Log::error("Gagal mengunggah file CSV biaya kartu ATM untuk cabang {$branch} ke SFTP: {$remoteFilePath}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->updateSftpLogFailed($e->getMessage());
|
$this->updateSftpLogFailed($e->getMessage());
|
||||||
|
|
||||||
Log::error("Error saat mengunggah file ke SFTP: " . $e->getMessage(), [
|
Log::error("Error saat mengunggah file ke SFTP untuk cabang {$branch}: " . $e->getMessage(), [
|
||||||
'file' => $e->getFile(),
|
'file' => $e->getFile(),
|
||||||
'line' => $e->getLine(),
|
'line' => $e->getLine(),
|
||||||
'periode' => $this->periode
|
'periode' => $this->periode
|
||||||
@@ -322,6 +332,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateSftpLogSuccess(string $branch = ''): void
|
||||||
|
{
|
||||||
|
$message = 'File berhasil diupload ke SFTP';
|
||||||
|
if (!empty($branch)) {
|
||||||
|
$message .= " untuk cabang {$branch}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->syncLog->update([
|
||||||
|
'is_ftp' => true,
|
||||||
|
'ftp_at' => Carbon::now(),
|
||||||
|
'ftp_notes' => $message,
|
||||||
|
'ftp_destination' => env('SFTP_KARTU_HOST', '/'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Log::info($message . ' untuk periode ' . $this->periode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update log saat upload SFTP dimulai
|
* Update log saat upload SFTP dimulai
|
||||||
*/
|
*/
|
||||||
@@ -337,22 +364,6 @@
|
|||||||
Log::info('Memulai upload ke SFTP untuk periode ' . $this->periode);
|
Log::info('Memulai upload ke SFTP untuk periode ' . $this->periode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update log saat upload SFTP berhasil
|
|
||||||
*/
|
|
||||||
private function updateSftpLogSuccess()
|
|
||||||
: void
|
|
||||||
{
|
|
||||||
$this->syncLog->update([
|
|
||||||
'is_ftp' => true,
|
|
||||||
'ftp_at' => Carbon::now(),
|
|
||||||
'ftp_notes' => 'File berhasil diupload ke SFTP',
|
|
||||||
'ftp_destination' => env('SFTP_KARTU_HOST', '/'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Log::info('File berhasil diupload ke SFTP untuk periode ' . $this->periode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update log saat upload SFTP gagal
|
* Update log saat upload SFTP gagal
|
||||||
*/
|
*/
|
||||||
@@ -370,22 +381,23 @@
|
|||||||
/**
|
/**
|
||||||
* Update log saat pembuatan CSV berhasil
|
* Update log saat pembuatan CSV berhasil
|
||||||
*/
|
*/
|
||||||
private function updateCsvLogSuccess($result)
|
private function updateCsvLogSuccess($results): void
|
||||||
: void
|
|
||||||
{
|
{
|
||||||
// Get file info
|
foreach ($results as $result) {
|
||||||
$fileInfo = pathinfo($result['localFilePath']);
|
// Get file info
|
||||||
$fileName = $fileInfo['basename'];
|
$fileInfo = pathinfo($result['localFilePath']);
|
||||||
|
$fileName = $fileInfo['basename'];
|
||||||
|
|
||||||
$this->syncLog->update([
|
$this->syncLog->update([
|
||||||
'is_csv' => true,
|
'is_csv' => true,
|
||||||
'csv_at' => Carbon::now(),
|
'csv_at' => Carbon::now(),
|
||||||
'csv_notes' => 'File CSV berhasil dibuat: ' . $fileName,
|
'csv_notes' => 'File CSV untuk cabang ' . $result['branch'] . ' berhasil dibuat: ' . $fileName,
|
||||||
'file_path' => $result['localFilePath'],
|
'file_path' => $result['localFilePath'],
|
||||||
'file_name' => $fileName,
|
'file_name' => $fileName,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Log::info('File CSV berhasil dibuat: ' . $result['localFilePath']);
|
Log::info('File CSV untuk cabang ' . $result['branch'] . ' berhasil dibuat: ' . $result['localFilePath']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user