Skip to content

Add docstrings to methods in App/Helpers #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/Helpers/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class Api
{
/**
* Get unresolved issues from Sentry.
*
* @return array
*/
public static function getSentryUnresolvedIssues()
{
$organization = config('app.sentry_organization');
Expand All @@ -30,6 +35,12 @@ public static function getSentryUnresolvedIssues()
}
}

/**
* Get outdated packages from Composer.
*
* @param string $flag
* @return array
*/
public static function getComposerOutdatedPackages($flag = '--no-dev')
{
$composer = config('app.composer');
Expand Down
34 changes: 21 additions & 13 deletions app/Helpers/Cetak.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
class Cetak
{
/**
* Cetak Dokumen.
* Print a document.
*
* @param string $jenis kak|spj|sk|st|dpr|spd|bon
* @param collection $model
* @param string $filename
* @return string
* @param string $jenis The type of document (kak|spj|sk|st|dpr|spd|bon)
* @param collection $model The model collection
* @param string $filename The filename for the document
* @param int $template_id The template ID
* @param string|null $tanggal The date (optional)
* @param string|null $pengelola The manager (optional)
* @return string The filename of the saved document
* @throws \Exception
*/
public static function cetak($jenis, $models, $filename, $template_id, $tanggal = null, $pengelola = null)
{
Expand Down Expand Up @@ -65,9 +69,13 @@ public static function cetak($jenis, $models, $filename, $template_id, $tanggal
}

/**
* Ambil TemplateProsessor.
* Get the TemplateProcessor.
*
* @param string $jenis kak|spj|sk|st|dpr|spd|bon
* @param string $jenis The type of document (kak|spj|sk|st|dpr|spd|bon)
* @param int $id The ID of the model
* @param int $template_id The template ID
* @param string|null $tanggal The date (optional)
* @param string|null $pengelola The manager (optional)
* @return TemplateProcessor
*/
public static function getTemplate(string $jenis, $id, $template_id, $tanggal, $pengelola)
Expand Down Expand Up @@ -169,7 +177,7 @@ public static function getTemplate(string $jenis, $id, $template_id, $tanggal, $
}

/**
* Ambil XML dari dokumen utama.
* Get the XML from the main document.
*
* @param TemplateProcessor $templateProcessor
* @return string
Expand All @@ -180,7 +188,7 @@ public static function getMainXml($templateProcessor)
}

/**
* Ambil XML dari dokumen yangakan digabung.
* Get the XML from the document to be merged.
*
* @param TemplateProcessor $templateProcessor
* @return string
Expand All @@ -195,9 +203,9 @@ public static function getModifiedInnerXml($templateProcessor)
}

/**
* Format nilai KAK.
* Format the KAK values.
*
* @param string $id
* @param string $id The ID of the KAK
* @return array
*/
public static function kak($id)
Expand Down Expand Up @@ -409,9 +417,9 @@ public static function kuitansi($id)
}

/**
* Format nilai SPJ.
* Format the SPJ values.
*
* @param string $id
* @param string $id The ID of the SPJ
* @return array
*/
public static function spj($id)
Expand Down
24 changes: 24 additions & 0 deletions app/Helpers/Fonnte.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function __construct()
$this->account_token = config('fonnte.token');
}

/**
* Make a request to the Fonnte API.
*
* @param string $endpoint The API endpoint to call.
* @param array $params The parameters to send with the request.
* @return array The response from the API.
*/
protected function makeRequest($endpoint, $params = [])
{
$token = $this->account_token;
Expand Down Expand Up @@ -53,6 +60,13 @@ protected function makeRequest($endpoint, $params = [])
];
}

/**
* Send a WhatsApp message using the Fonnte API.
*
* @param string $phoneNumber The phone number to send the message to.
* @param string $message The message to send.
* @return array The response from the API.
*/
public function sendWhatsAppMessage($phoneNumber, $message)
{
return $this->makeRequest(self::ENDPOINTS['send_message'], [
Expand All @@ -61,11 +75,21 @@ public function sendWhatsAppMessage($phoneNumber, $message)
]);
}

/**
* Update the WhatsApp group list using the Fonnte API.
*
* @return array The response from the API.
*/
public function updateWhatsappGroupList()
{
return $this->makeRequest(self::ENDPOINTS['update_group']);
}

/**
* Get the WhatsApp group list using the Fonnte API.
*
* @return array The response from the API.
*/
public function getWhatsappGroupList()
{
return $this->makeRequest(self::ENDPOINTS['list_group']);
Expand Down
30 changes: 30 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ class Helper
'IV/e' => 15,
];

/**
* Get the name of the last sheet in an Excel file.
*
* @param string $file The path to the Excel file.
* @return string The name of the last sheet.
*/
public static function getLastSheetName($file)
{
$reader = new Reader;
Expand All @@ -271,6 +277,12 @@ public static function getLastSheetName($file)
return $name;
}

/**
* Format a phone number to a WhatsApp URL.
*
* @param string $telepon The phone number to format.
* @return string The formatted WhatsApp URL.
*/
public static function formatTelepon($telepon)
{
$wa = str_replace('+62 08', '628', $telepon);
Expand All @@ -280,6 +292,12 @@ public static function formatTelepon($telepon)
return "https://wa.me/{$wa}";
}

/**
* Check if the current date is within a specific quarter.
*
* @param int $tw The quarter to check (1, 2, 3, or 4).
* @return bool True if the current date is within the specified quarter, false otherwise.
*/
public static function is_triwulan($tw)
{
$now = Carbon::now();
Expand All @@ -297,6 +315,12 @@ public static function is_triwulan($tw)
}
}

/**
* Check if the current date is within a specific cumulative quarter.
*
* @param int $tw The cumulative quarter to check (1, 2, 3, or 4).
* @return bool True if the current date is within the specified cumulative quarter, false otherwise.
*/
public static function is_triwulan_kumulatif($tw)
{
$now = Carbon::now();
Expand All @@ -314,6 +338,12 @@ public static function is_triwulan_kumulatif($tw)
}
}

/**
* Get the current quarter based on the given month.
*
* @param int $month The month to determine the quarter.
* @return int The current quarter (1, 2, 3, or 4).
*/
public static function getTriwulanBerjalan($month)
{
return (int) ceil($month / 3);
Expand Down