update patch 1
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthenticationHelper
|
||||
{
|
||||
|
||||
|
||||
public static function CurrentLogin()
|
||||
{
|
||||
$auth = Auth::user()->username;
|
||||
return $auth;
|
||||
}
|
||||
|
||||
|
||||
public static function CurrentLoginData()
|
||||
{
|
||||
$auth = Auth::user();
|
||||
return $auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Options;
|
||||
|
||||
class DocxHelper
|
||||
{
|
||||
/**
|
||||
* Edit prefix dalam file DOCX dan konversi menjadi PDF.
|
||||
*
|
||||
* @param string $filePath Path file DOCX asli.
|
||||
* @param array $prefixes Array pasangan placeholder dan value untuk mengganti teks dalam DOCX.
|
||||
* @param string $outputPdfPath Path output untuk menyimpan PDF.
|
||||
* Contoh: ['PREFIX_PLACEHOLDER_1' => 'NewPrefix1', ...]
|
||||
* @return string Path dari file PDF yang dihasilkan.
|
||||
*
|
||||
*/
|
||||
public static function parsePrefix($filePath, array $prefixes)
|
||||
{
|
||||
$templateProcessor = new TemplateProcessor($filePath);
|
||||
|
||||
foreach ($prefixes as $placeholder => $value) {
|
||||
if($value[1] == 'TEXT'){
|
||||
$templateProcessor->setValue($placeholder, $value[0]);
|
||||
|
||||
}
|
||||
|
||||
if($value[1] == 'IMAGE'){
|
||||
if (file_exists(storage_path('app/signature/'.$value[0]))) {
|
||||
$templateProcessor->setImageValue(str_replace(['${', '}'], '', $placeholder), array('path' => storage_path('app/signature/'.$value[0]), 'width' => 50, 'height' => 50, 'ratio' => true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$docx_temp_name = pathinfo($filePath, PATHINFO_FILENAME) . '.docx'; // Nama unik untuk file sementara
|
||||
|
||||
if (!file_exists(storage_path('app/public/uploads/temp_docx'))) {
|
||||
mkdir(storage_path('app/public/uploads/temp_docx'), 0777, true);
|
||||
}
|
||||
|
||||
$editedDocxPath = storage_path('app/public/uploads/temp_docx/' . $docx_temp_name);
|
||||
|
||||
$templateProcessor->saveAs($editedDocxPath);
|
||||
return $editedDocxPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Konversi file DOCX yang telah diedit prefix menjadi PDF.
|
||||
*
|
||||
* @param array $prefixes Array pasangan placeholder dan value untuk mengganti teks dalam DOCX.
|
||||
* @param string $docx_path Path file DOCX yang akan diconvert.
|
||||
* @param string $pdf_path Path output untuk menyimpan PDF.
|
||||
* @return string Path file PDF yang dihasilkan.
|
||||
*/
|
||||
public static function ConvertPDFWithPrefix($prefixes,$docx_path,$pdf_path)
|
||||
{
|
||||
$inputFilePath = DocxHelper::parsePrefix($docx_path, $prefixes);
|
||||
$libreOfficePath = env('LIBREOFFICE_PATH');
|
||||
|
||||
$command = '"'.$libreOfficePath.'" --headless --convert-to pdf "'.$inputFilePath.'" --outdir "'.dirname($pdf_path).'"';
|
||||
$output = [];
|
||||
$returnVar = 0;
|
||||
exec($command, $output, $returnVar);
|
||||
|
||||
if ($returnVar !== 0) {
|
||||
dd('failed to convert PDF File. Return Code: '.$returnVar);
|
||||
} else {
|
||||
$pathInfo = pathinfo($inputFilePath);
|
||||
$newExtension = 'pdf';
|
||||
$outputFilePath = dirname($pdf_path) . DIRECTORY_SEPARATOR . $pathInfo['filename'] . '.' . $newExtension;
|
||||
}
|
||||
|
||||
return $outputFilePath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Inserts a new record into the MS_PREFIX_DOCUMENT table with the provided details.
|
||||
*
|
||||
* @param int $documentId The ID of the document.
|
||||
* @param string $prefixKey The prefix key associated with the document.
|
||||
* @param string $tableName The name of the table where the prefix is applied.
|
||||
* @param string $columnName The name of the column where the prefix is applied.
|
||||
* @param string $createdBy The identifier of the user who created the record.
|
||||
* @param string $updatedBy The identifier of the user who last updated the record.
|
||||
* @return bool Returns true if the record was successfully inserted, false otherwise.
|
||||
*/
|
||||
public static function createPrefixDocument($documentId, $prefixKey, $tableName, $columnName, $createdBy, $updatedBy) {
|
||||
$result = DB::table('MS_PREFIX_DOCUMENT')->insert([
|
||||
'DOCUMENT_ID' => $documentId,
|
||||
'PREFIX_KEY' => $prefixKey,
|
||||
'TABLE_NAME' => $tableName,
|
||||
'COLUMN_NAME' => $columnName,
|
||||
'CREATED_BY' => $createdBy,
|
||||
'UPDATED_BY' => $updatedBy,
|
||||
'CREATED_AT' => now(),
|
||||
'UPDATED_AT' => now()
|
||||
]);
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the prefix mappings for a given document ID from the MS_PREFIX_DOCUMENT table.
|
||||
*
|
||||
* This function queries the database to obtain prefix mappings associated with the provided
|
||||
* document ID. It then retrieves the corresponding values from the specified tables and columns
|
||||
* for each mapping. If a value is not found, 'N/A' is used as a default.
|
||||
* buatkan sebuah view yang telah di join table untuk menjalankan fungsi ini.
|
||||
* @param string $documentId The ID of the document for which to retrieve prefix mappings.
|
||||
* @return array An associative array of prefix keys and their corresponding values.
|
||||
*/
|
||||
public static function getDocumentPrefixWithData($documentId,$dataId) {
|
||||
|
||||
$prefixes = [];
|
||||
$mappings = DB::table('MS_PREFIX_DOCUMENT')
|
||||
->where('DOCUMENT_ID', $documentId)
|
||||
->get();
|
||||
foreach ($mappings as $mapping) {
|
||||
$value = DB::table($mapping->table_name)
|
||||
->where('ID', $dataId)
|
||||
->value($mapping->column_name);
|
||||
|
||||
$prefixes[$mapping->prefix_key] = array($value !== null ? $value : '', $mapping->type) ;
|
||||
}
|
||||
|
||||
return $prefixes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class EncryptHelper
|
||||
{
|
||||
|
||||
public static function encryptLDAP($value)
|
||||
{
|
||||
$key = env('CRYPTO_KEY', ''); // Ambil kunci dari .env atau gunakan default
|
||||
$iv = env('CRYPTO_IV', ''); // Ambil IV dari .env atau gunakan default
|
||||
|
||||
try {
|
||||
$ivDecoded = base64_decode($iv);
|
||||
$cipher = openssl_encrypt($value, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $ivDecoded);
|
||||
return base64_encode($cipher);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function decryptLDAP($value)
|
||||
{
|
||||
$key = env('CRYPTO_KEY', ''); // Ambil kunci dari .env atau gunakan default
|
||||
$iv = env('CRYPTO_IV', ''); // Ambil IV dari .env atau gunakan default
|
||||
$ivDecoded = base64_decode($iv);
|
||||
|
||||
try {
|
||||
$value = base64_decode($value);
|
||||
$decrypted = openssl_decrypt($value, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $ivDecoded);
|
||||
return $decrypted;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GlobalHelper
|
||||
{
|
||||
/**
|
||||
* Get the client's age from Oracle using FN_GET_AGE function.
|
||||
*
|
||||
* @param string $birthDate Birth date in 'YYYY-MM-DD' format
|
||||
* @param string $loanStartdate Birth date in 'YYYY-MM-DD' format
|
||||
* @return int|null The client's age, or null if no data is found
|
||||
*/
|
||||
public static function getClientAge($birthDate, $loanStartdate)
|
||||
{
|
||||
try {
|
||||
$query = "SELECT ADMIN_AJK.FN_GET_AGE(:birthDate, :loanstartdate) AS age FROM dual";
|
||||
$result = DB::select($query, [
|
||||
'birthDate' => date('Y-m-d', strtotime($birthDate)),
|
||||
'loanstartdate' => date('Y-m-d', strtotime($loanStartdate))
|
||||
]);
|
||||
if (!empty($result) && isset($result[0]->age)) {
|
||||
return (int) $result[0]->age;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the result of auto underwriting for SPAJK.
|
||||
*
|
||||
* @param string $spajk_id SPAJK ID
|
||||
* @return boolean The result of auto underwriting
|
||||
*/
|
||||
public static function GetCriteriaUnderWriting($spajk_id)
|
||||
{
|
||||
try {
|
||||
$query = "SELECT FN_GET_AUTOUW_SPAJK(:spajk_id) AS RESULT FROM DUAL";
|
||||
$result = DB::select($query, ['spajk_id' => $spajk_id]);
|
||||
if (!empty($result) && isset($result[0]->result)) {
|
||||
if($result[0]->result == 'AUTOUW_CRITERIA_OK') {
|
||||
return TRUE;
|
||||
}else{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate SPAJK number based on partner ID
|
||||
*
|
||||
* @param integer $partner_id Partner ID
|
||||
* @return string|null SPAJK number or null if error occurs
|
||||
*/
|
||||
public static function GenerateSPAJKNo($partner_id)
|
||||
{
|
||||
try {
|
||||
$query = "SELECT FN_GEN_SPAJKNO(:partner_id) AS RESULT FROM DUAL";
|
||||
$result = DB::select($query, ['partner_id' => $partner_id]);
|
||||
if (!empty($result) && isset($result[0]->result)) {
|
||||
return $result[0]->result;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate Net Premium of a policy
|
||||
*
|
||||
* @param array $params Parameters to calculate the net premium
|
||||
* - percentage_fee: The percentage of the fee
|
||||
* - percentage_ppn: The percentage of the ppn
|
||||
* - percentage_pph: The percentage of the pph
|
||||
* - gross_premium: The gross premium
|
||||
* - premi_gross_total: The total gross premium
|
||||
*
|
||||
* @return float The calculated net premium
|
||||
*/
|
||||
public static function calculateNetPremi($params){
|
||||
$percentage_fee = isset($params['percentage_fee']) ? $params['percentage_fee'] : 0;
|
||||
$percentage_ppn = isset($params['percentage_ppn']) ? $params['percentage_ppn'] : 0;
|
||||
$percentage_pph = isset($params['percentage_pph']) ? $params['percentage_pph'] : 0;
|
||||
$UP = isset($params['gross_premium']) ? $params['gross_premium'] : 0;
|
||||
$premi_gross_total = isset($params['premi_gross_total']) ? $params['premi_gross_total'] : 0;
|
||||
|
||||
$fee = round($percentage_fee / 100 * $UP,0);
|
||||
$dpp_include_ppn = 100 / (100 + $percentage_ppn);
|
||||
|
||||
$dpp = round($dpp_include_ppn * $fee,0);
|
||||
$ppn = round($percentage_ppn / 100 * $dpp,0);
|
||||
$pph = round($percentage_pph / 100 * $dpp,0);
|
||||
$premi_net_total = $premi_gross_total - $fee + $ppn + $pph;
|
||||
return $premi_net_total;
|
||||
}
|
||||
|
||||
private static function FaktorPenurunan($B40, $B14, $J5) {
|
||||
$result = round((1 - pow(1 + $B40, -$B14 + $J5)) / (1 - pow(1 + $B40, -$B14)), 3);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Fungsi untuk menghitung Premi Substandard
|
||||
private static function CalculatePremiSubstandard($EP, $UP, $faktorPenurunan) {
|
||||
$EP_per_month = round($EP / 12, 2);
|
||||
$UP_ceiling = ceil($UP);
|
||||
$premiSubstandard = ($EP_per_month / 1000) * $UP_ceiling * $faktorPenurunan;
|
||||
|
||||
return round($premiSubstandard, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menghitung premi substandard berdasarkan parameter yang diberikan.
|
||||
*
|
||||
* @param array $params parameter yang diperlukan
|
||||
* - extra_premium: nilai extra premi (EP)
|
||||
* - gross_premium: nilai premi bruto (UP)
|
||||
* - loan_interest: bunga pinjaman per bulan
|
||||
* - loan_coverage_month: masa asuransi dalam bulan
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function calculateExtraPremi($params){
|
||||
$EP = isset($params['extra_premium']) ? $params['extra_premium'] : 0; // Nilai Extra Premi (EP)
|
||||
$UP = isset($params['gross_premium']) ? $params['gross_premium'] : 0;
|
||||
$loan_interest = isset($params['loan_interest']) ? $params['loan_interest'] : 0;
|
||||
$masa_asuransi_bulan = isset($params['loan_coverage_month']) ? $params['loan_coverage_month'] : 0;
|
||||
|
||||
// Menghitung faktor penurunan
|
||||
$iloan = round($loan_interest / 12, 8);
|
||||
$faktor_penurunan = 0;
|
||||
|
||||
for ($i = 0; $i < $masa_asuransi_bulan; $i++) {
|
||||
$faktor_perbulan = self::FaktorPenurunan($iloan, $masa_asuransi_bulan, $i);
|
||||
$faktor_penurunan = $faktor_penurunan + $faktor_perbulan;
|
||||
}
|
||||
|
||||
$result = self::CalculatePremiSubstandard($EP, $UP,round($faktor_penurunan,2));
|
||||
return round($result,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the extra mortality based on given parameters.
|
||||
*
|
||||
* @param array $params {
|
||||
* Array containing parameters for calculation.
|
||||
*
|
||||
* @type int 'em' The extra mortality percentage (default 0).
|
||||
* @type int 'gross_premi' The gross premium amount (default 0).
|
||||
* }
|
||||
* @return int The calculated extra mortality value.
|
||||
*/
|
||||
|
||||
public static function calculateExtraMortality($params){
|
||||
$em = isset($params['extra_mortality']) ? $params['extra_mortality'] : 0;
|
||||
$gross_premi = isset($params['gross_premi']) ? $params['gross_premi'] : 0;
|
||||
|
||||
$gross_premi_total = intval($em) / 100 * intval($gross_premi);
|
||||
$gross_premi_total = round(intval($gross_premi_total), 0);
|
||||
$extra_mortality = intval($gross_premi_total) + intval( $gross_premi);
|
||||
|
||||
return $extra_mortality;
|
||||
}
|
||||
|
||||
|
||||
public static function calculateGrossPremi($params)
|
||||
{
|
||||
try {
|
||||
$product_id = isset($params['product_id']) ? $params['product_id'] : 0;
|
||||
$usia_masuk = isset($params['usia_masuk']) ? $params['usia_masuk'] : 0;
|
||||
$loan_start_date = isset($params['loan_start_date']) ? $params['loan_start_date'] : '0000-00-00';
|
||||
$loan_end_date = isset($params['loan_end_date']) ? $params['loan_end_date'] : '0000-00-00';
|
||||
$loan_amount = isset($params['loan_amount']) ? $params['loan_amount'] : 0; //Besar Pinjaman (UP)
|
||||
|
||||
$query = "SELECT PREMIUM_RATE_ID, PREMIUM_RATE_CODE, FORMULA_RATE_ID, FORMULA_RATE_CODE FROM VW_PRODUCT_DETAIL WHERE PRODUCT_ID = :product_id";
|
||||
$product_premi = DB::select($query, ['product_id' => $product_id])[0];
|
||||
|
||||
if (!empty($product_premi)) {
|
||||
$premium_rate_id = $product_premi->premium_rate_id;
|
||||
$formula_rate_code = $product_premi->formula_rate_code;
|
||||
|
||||
switch ($formula_rate_code) {
|
||||
case 'RUP': //ROUNDING UP
|
||||
return self::calculatePremiRoundingUp($loan_start_date, $loan_end_date, $usia_masuk, $loan_amount, $premium_rate_id);
|
||||
case 'PRO': //PRORATE
|
||||
return self::calculatePremiProrate($loan_start_date, $loan_end_date, $usia_masuk, $loan_amount, $premium_rate_id);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function calculatePremiProrate($loan_start_date, $loan_end_date, $usia_masuk, $loan_ammount, $RatePremi)
|
||||
{
|
||||
try {
|
||||
$loan_start_date_obj = \Carbon\Carbon::createFromFormat('d-m-Y', $loan_start_date);
|
||||
$loan_end_date_obj = \Carbon\Carbon::createFromFormat('d-m-Y', $loan_end_date);
|
||||
$difference = $loan_start_date_obj->diff($loan_end_date_obj);
|
||||
$coverage_year = $difference->y;
|
||||
$coverage_day = $difference->d;
|
||||
|
||||
$add_month = ($coverage_day >= 1 && $coverage_day <= 31) ? 1 : 0;
|
||||
$masa_asuransi_month = $loan_start_date_obj->diffInMonths($loan_end_date_obj) + $add_month;
|
||||
$coverage_month_mod = $masa_asuransi_month % 12;
|
||||
|
||||
if ($coverage_year == 0) {
|
||||
throw new \Exception("Loan tidak boleh kurang dari 1 tahun.");
|
||||
}
|
||||
|
||||
$rate_low = DB::table('MS_RATE_PREMI as mrp')
|
||||
->where('mrp.AGE', '=', $usia_masuk)
|
||||
->where('mrp.INSURANCE_PERIODE_YEAR', '=', $coverage_year)
|
||||
->where('mrp.MS_PREMIUM_RATE_ID', '=', $RatePremi)
|
||||
->value('mrp.PREMI_VALUE') ?? 0;
|
||||
|
||||
$rate_high = DB::table('MS_RATE_PREMI as mrp')
|
||||
->where('mrp.AGE', '=', $usia_masuk)
|
||||
->where('mrp.INSURANCE_PERIODE_YEAR', '=', ($coverage_year + 1))
|
||||
->where('mrp.MS_PREMIUM_RATE_ID', '=', $RatePremi)
|
||||
->value('mrp.PREMI_VALUE') ?? 0;
|
||||
|
||||
|
||||
|
||||
if (!isset($rate_low) || !isset($rate_high)) {
|
||||
throw new \Exception("Rate untuk perhitungan Gross Premium tidak tersedia.");
|
||||
}
|
||||
|
||||
$calculate_rate = ($rate_low + $coverage_month_mod / 12 * ($rate_high - $rate_low));
|
||||
$up = ceil($loan_ammount);
|
||||
|
||||
$premi_standard = $calculate_rate / 1000 * $up;
|
||||
$premi = round($premi_standard, 0);
|
||||
|
||||
return $premi;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function calculatePremiRoundingUp($loan_start_date, $loan_end_date, $usia_masuk, $loan_ammount, $RatePremi)
|
||||
{
|
||||
try {
|
||||
$loan_start_date_obj = \Carbon\Carbon::createFromFormat('d-m-Y', $loan_start_date);
|
||||
$loan_end_date_obj = \Carbon\Carbon::createFromFormat('d-m-Y', $loan_end_date);
|
||||
$masa_asuransi = $loan_start_date_obj->diffInMonths($loan_end_date_obj);
|
||||
$round_up = ceil($masa_asuransi / 12);
|
||||
|
||||
$premi_value = DB::table('MS_RATE_PREMI as mrp')
|
||||
->where('mrp.AGE', '=', $usia_masuk)
|
||||
->where('mrp.INSURANCE_PERIODE_YEAR', '=', $round_up)
|
||||
->where('mrp.MS_PREMIUM_RATE_ID', '=', $RatePremi)
|
||||
->value('mrp.PREMI_VALUE');
|
||||
|
||||
$up = ceil($loan_ammount);
|
||||
if (!isset($premi_value)) {
|
||||
throw new \Exception("Rate untuk perhitungan Gross Premium tidak tersedia.");
|
||||
}
|
||||
|
||||
$premi_standard = $premi_value / 1000 * $up;
|
||||
$premi = round($premi_standard, 0);
|
||||
|
||||
return $premi;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function generateCertificateSPAJK($product_id,$partner_id)
|
||||
{
|
||||
$product_prefix = DB::table('PRODUCT as p')
|
||||
->select('mbp.ABBREVIATION as prefx')
|
||||
->join('MS_BASIC_PRODUCT as mbp', 'p.BASIC_PRODUCT', '=', 'mbp.ID')
|
||||
->where('p.ID', '=', $product_id)
|
||||
->first();
|
||||
|
||||
$no_certif = DB::select("SELECT SEQ_NO_CERTIFICATE.NEXTVAL as no_certif FROM dual");
|
||||
$no_certif_value = $no_certif[0]->no_certif;
|
||||
$formatted_no_certif = str_pad($no_certif_value, 5, '0', STR_PAD_LEFT);
|
||||
|
||||
|
||||
$partner = DB::table('MS_PARTNER')
|
||||
->select('abbreviation_name as prefx')
|
||||
->where('code', '=', $partner_id)
|
||||
->first();
|
||||
|
||||
$singkatan_value = $product_prefix ? $product_prefix->prefx : '';
|
||||
$partner_value = $partner ? $partner->prefx : '';
|
||||
|
||||
$awalan = "PK";
|
||||
$certifNo = $awalan . '/' . $singkatan_value . '/' . $partner_value . '-' . $formatted_no_certif;
|
||||
|
||||
return $certifNo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class QueryHelper
|
||||
{
|
||||
/**
|
||||
* Execute a stored procedure with input and output parameters.
|
||||
*
|
||||
* @param string $procedureName The name of the stored procedure.
|
||||
* @param array $inputParams An associative array of input parameters.
|
||||
* @param array $outputParams An associative array of output parameters with PDO types.
|
||||
* @return array An associative array of output parameters with their values.
|
||||
*/
|
||||
public static function returnProcedure($connection, $procedureName, $inputParams = [], $outputParams = [])
|
||||
{
|
||||
$connection = $connection->getPdo();
|
||||
|
||||
$inputPlaceholders = [];
|
||||
$outputPlaceholders = [];
|
||||
$bindings = [];
|
||||
|
||||
foreach ($inputParams as $key => $value) {
|
||||
$inputPlaceholders[] = ":{$key}";
|
||||
$bindings[":{$key}"] = $value;
|
||||
}
|
||||
|
||||
foreach ($outputParams as $key => $type) {
|
||||
$outputPlaceholders[] = ":{$key}";
|
||||
$bindings[":{$key}"] = null;
|
||||
}
|
||||
|
||||
// Build the SQL statement
|
||||
$sql = sprintf(
|
||||
'BEGIN %s(%s, %s); END;',
|
||||
$procedureName,
|
||||
implode(', ', $inputPlaceholders),
|
||||
implode(', ', $outputPlaceholders)
|
||||
);
|
||||
|
||||
// Prepare the callable statement
|
||||
$stmt = $connection->prepare($sql);
|
||||
|
||||
// Bind input parameters
|
||||
foreach ($inputParams as $key => $value) {
|
||||
$stmt->bindValue(":{$key}", $value);
|
||||
}
|
||||
|
||||
// Bind output parameters with specific types
|
||||
foreach ($outputParams as $key => $type) {
|
||||
$stmt->bindParam(":{$key}", $bindings[":{$key}"], $type, 255);
|
||||
}
|
||||
// Execute the procedure
|
||||
$stmt->execute();
|
||||
|
||||
// Fetch the output parameters
|
||||
$outputResults = [];
|
||||
foreach ($outputParams as $key => $type) {
|
||||
$outputResults[$key] = $bindings[":{$key}"];
|
||||
}
|
||||
|
||||
$connection = null;
|
||||
return $outputResults;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function execProcedure($connection, $procedureName, $inputParams = [])
|
||||
{
|
||||
// Get the database connection
|
||||
$connection = $connection->getPdo();
|
||||
|
||||
// Build the parameter placeholders for the stored procedure
|
||||
$placeholders = [];
|
||||
$bindings = [];
|
||||
|
||||
foreach ($inputParams as $key => $value) {
|
||||
$placeholders[] = ":{$key}";
|
||||
$bindings[":{$key}"] = $value;
|
||||
}
|
||||
|
||||
// Build the SQL statement
|
||||
$sql = sprintf(
|
||||
'BEGIN %s(%s); END;',
|
||||
$procedureName,
|
||||
implode(', ', $placeholders)
|
||||
);
|
||||
|
||||
// Prepare the callable statement
|
||||
$stmt = $connection->prepare($sql);
|
||||
|
||||
// Bind input parameters
|
||||
foreach ($inputParams as $key => $value) {
|
||||
$stmt->bindValue(":{$key}", $value);
|
||||
}
|
||||
|
||||
|
||||
// Execute the procedure
|
||||
$stmt->execute();
|
||||
$connection = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class StrHelper
|
||||
{
|
||||
|
||||
public static function bindWhereClause($requestValue, $queryField)
|
||||
{
|
||||
$sql_query = '';
|
||||
if ($requestValue != null && !empty($requestValue)) {
|
||||
return " AND " . $queryField . " LIKE '%" . $requestValue . "%'";
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
public static function bindWhereDateClause($requestValue, $queryField)
|
||||
{
|
||||
$sql_query = '';
|
||||
if ($requestValue != null && !empty($requestValue)) {
|
||||
if ($queryField == 'loan_start_date') {
|
||||
return " AND vw.loan_start_date >= TO_DATE('" . $requestValue . "', 'YYYY-MM-DD')";
|
||||
}
|
||||
|
||||
if ($queryField == 'loan_end_date') {
|
||||
return " AND vw.loan_end_date <= TO_DATE('" . $requestValue . "', 'YYYY-MM-DD')";
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user