update patch 1
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
@@ -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 '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Agent;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class AgentController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = DB::table('ADMIN_SKT.TM_AGEN AS A')
|
||||
->leftJoin('ADMIN_SKT.D_KTR AS K', 'A.KTR_ADMINISTRASI', '=', 'K.KDKTR')
|
||||
->leftJoin('ADMIN_SKT.RF_JABATAN_AGEN AS J', 'A.KD_JABATAN_AGEN', '=', 'J.KD_JABATAN')
|
||||
->select(
|
||||
'A.NO_AGEN',
|
||||
'A.NAMA',
|
||||
'J.SINGKATAN_JABATAN',
|
||||
'K.KDKTR',
|
||||
'K.NMKTR',
|
||||
DB::raw("TO_CHAR(A.TGL_LISENSI_AKHIR, 'DD-MM-YYYY') AS TGL_LISENSI_AKHIR")
|
||||
);
|
||||
|
||||
// Filter based on search input
|
||||
if ($request->filled('no_agen')) {
|
||||
$query->where('A.NO_AGEN', 'like', '%' . $request->input('no_agen') . '%');
|
||||
}
|
||||
if ($request->filled('nama')) {
|
||||
$query->where(DB::raw('LOWER(A.NAMA)'), 'like', '%' . strtolower($request->input('nama')) . '%');
|
||||
}
|
||||
if ($request->filled('title')) {
|
||||
$query->where(DB::raw('LOWER(J.SINGKATAN_JABATAN)'), 'like', '%' . strtolower($request->input('title')) . '%');
|
||||
}
|
||||
if ($request->filled('kpa_code')) {
|
||||
$query->where('K.KDKTR', 'like', '%' . $request->input('kpa_code') . '%');
|
||||
}
|
||||
if ($request->filled('kpa_name')) {
|
||||
$query->where('K.NMKTR', 'like', '%' . $request->input('kpa_name') . '%');
|
||||
}
|
||||
|
||||
// Add condition for TGL_LISENSI_AKHIR
|
||||
$query->where('A.TGL_LISENSI_AKHIR', '>=', DB::raw('SYSDATE'));
|
||||
|
||||
// Sort and get results
|
||||
$query->orderBy('A.NO_AGEN', 'asc');
|
||||
|
||||
$results = $query->get();
|
||||
return DataTables::of($results)->make(true); // Get the final results
|
||||
|
||||
// Uncomment the line below to return results in JSON format if needed
|
||||
// return response()->json($results);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||
|
||||
class ConfirmPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Confirm Password Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password confirmations and
|
||||
| uses a simple trait to include the behavior. You're free to explore
|
||||
| this trait and override any functions that require customization.
|
||||
|
|
||||
*/
|
||||
|
||||
use ConfirmsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users when the intended url fails.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||
|
||||
class VerificationController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email Verification Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling email verification for any
|
||||
| user that recently registered with the application. Emails may also
|
||||
| be re-sent if the user didn't receive the original email message.
|
||||
|
|
||||
*/
|
||||
|
||||
use VerifiesEmails;
|
||||
|
||||
/**
|
||||
* Where to redirect users after verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('signed')->only('verify');
|
||||
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Backend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\AdminRequest;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class AdminsController extends Controller
|
||||
{
|
||||
|
||||
public function index(): Renderable
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['admin.view']);
|
||||
|
||||
$pageInfo = [
|
||||
'title' => 'User Access List',
|
||||
'sub_title' => 'List User Access System',
|
||||
'path' => url()->current()
|
||||
];
|
||||
|
||||
return view('backend.pages.admins.index', [
|
||||
'admins' => Admin::all(),
|
||||
'pageInfo' => $pageInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Renderable
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['admin.create']);
|
||||
|
||||
$pageInfo = [
|
||||
'title' => 'Create User Access',
|
||||
'sub_title' => 'Create new User',
|
||||
'path' => url()->current()
|
||||
];
|
||||
|
||||
return view('backend.pages.admins.create', [
|
||||
'roles' => Role::all(),
|
||||
'pageInfo' => $pageInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(AdminRequest $request): RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['admin.create']);
|
||||
|
||||
$admin = new Admin();
|
||||
$admin->name = $request->name;
|
||||
$admin->password = Hash::make($request->password);
|
||||
$admin->username = $request->username;
|
||||
$admin->email = $request->email;
|
||||
$admin->save();
|
||||
|
||||
if ($request->roles) {
|
||||
$admin->assignRole($request->roles);
|
||||
}
|
||||
|
||||
session()->flash('success', __('Admin has been created.'));
|
||||
return redirect()->route('admin.admins.index');
|
||||
}
|
||||
|
||||
public function edit(int $id): Renderable
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['admin.edit']);
|
||||
|
||||
$pageInfo = [
|
||||
'title' => 'Edit User Access',
|
||||
'sub_title' => 'Update User Access data',
|
||||
'path' => url()->current()
|
||||
];
|
||||
|
||||
|
||||
$admin = Admin::findOrFail($id);
|
||||
return view('backend.pages.admins.edit', [
|
||||
'admin' => $admin,
|
||||
'roles' => Role::all(),
|
||||
'pageInfo' => $pageInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(AdminRequest $request, int $id): RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['admin.edit']);
|
||||
|
||||
$admin = Admin::findOrFail($id);
|
||||
$admin->name = $request->name;
|
||||
$admin->email = $request->email;
|
||||
$admin->username = $request->username;
|
||||
|
||||
if ($request->password) {
|
||||
$admin->password = Hash::make($request->password);
|
||||
}
|
||||
$admin->save();
|
||||
$admin->roles()->detach();
|
||||
if ($request->roles) {
|
||||
$admin->assignRole($request->roles);
|
||||
}
|
||||
|
||||
session()->flash('success', 'Admin has been updated.');
|
||||
return back();
|
||||
}
|
||||
|
||||
public function destroy(int $id): RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['admin.delete']);
|
||||
|
||||
$admin = Admin::findOrFail($id);
|
||||
$admin->delete();
|
||||
session()->flash('success', 'Admin has been deleted.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||
|
||||
class ConfirmPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Confirm Password Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password confirmations and
|
||||
| uses a simple trait to include the behavior. You're free to explore
|
||||
| this trait and override any functions that require customization.
|
||||
|
|
||||
*/
|
||||
|
||||
use ConfirmsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users when the intended url fails.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo;
|
||||
|
||||
/**
|
||||
* show login form for admin guard
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('backend.auth.login');
|
||||
}
|
||||
|
||||
|
||||
protected function redirectTo()
|
||||
{
|
||||
if (Auth::guard('admin')->check()) {
|
||||
// Redirect admins to their dashboard
|
||||
return RouteServiceProvider::ADMIN_DASHBOARD;
|
||||
}
|
||||
|
||||
if (Auth::guard('web')->check()) {
|
||||
// Redirect users to the home page
|
||||
return redirect()->route('trx_order_elevation.index');
|
||||
}
|
||||
|
||||
// Default redirection (optional)
|
||||
return '/login';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* login admin
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
// Validate Login Data
|
||||
$request->validate([
|
||||
'email' => 'required|max:50',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
// Attempt to login
|
||||
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
|
||||
session()->flash('success', 'Successully Logged in !');
|
||||
Session::put('current_guard', 'admin');
|
||||
return redirect()->route('admin.dashboard');
|
||||
} else if (Auth::guard('admin')->attempt(['username' => $request->email, 'password' => $request->password], $request->remember)) {
|
||||
session()->flash('success', 'Successully Logged in !');
|
||||
Session::put('current_guard', 'admin');
|
||||
return redirect()->route('admin.dashboard');
|
||||
|
||||
}else if (Auth::guard('web')->attempt(['username' => $request->email, 'password' => $request->password], $request->remember)) {
|
||||
session()->flash('success', 'Successully Logged in !');
|
||||
Session::put('current_guard', 'web');
|
||||
return redirect()->route('admin.dashboard');
|
||||
}else if (Auth::guard('web')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
|
||||
session()->flash('success', 'Successully Logged in !');
|
||||
Session::put('current_guard', 'web');
|
||||
return redirect()->route('admin.dashboard');
|
||||
}
|
||||
// error
|
||||
session()->flash('error', 'Invalid email and password..');
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* logout admin guard
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
try{
|
||||
Auth::guard('admin')->logout();
|
||||
return redirect()->route('admin.login');
|
||||
|
||||
}catch (Exception $e) {
|
||||
Auth::guard('web')->logout();
|
||||
return redirect()->route('admin.login');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Backend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Admin;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
|
||||
return view(
|
||||
'backend.pages.dashboard.index',
|
||||
[
|
||||
'total_admins' => Admin::count(),
|
||||
'total_roles' => Role::count(),
|
||||
'total_permissions' => Permission::count(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MenuRoleController extends Controller
|
||||
{
|
||||
public function index($roleId)
|
||||
{
|
||||
// Ambil semua data dari tabel menus
|
||||
$menus = DB::table('menus')
|
||||
->orderBy('parent_id', 'ASC')
|
||||
->orderBy('order', 'ASC')
|
||||
->get();
|
||||
|
||||
$savedMenuIds = DB::table('role_menu')
|
||||
->where('role_id', $roleId)
|
||||
->pluck('menu_id')
|
||||
->toArray();
|
||||
|
||||
|
||||
// Jika $savedMenuIds null, set ke array kosong
|
||||
if (is_null($savedMenuIds)) {
|
||||
$savedMenuIds = [];
|
||||
}
|
||||
|
||||
// Membentuk struktur tree
|
||||
$menuTree = $this->buildTree($menus, $savedMenuIds);
|
||||
|
||||
$pageInfo = [
|
||||
'title' => 'Assign Role Menu',
|
||||
'sub_title' => 'Assign Role in Menu',
|
||||
'path' => url()->current()
|
||||
];
|
||||
|
||||
return view('backend.pages.menurole.index', [
|
||||
'menuTree' => $menuTree,
|
||||
'pageInfo' => $pageInfo,
|
||||
'role_id' => $roleId
|
||||
]);
|
||||
}
|
||||
|
||||
private function buildTree($menus, $savedMenuIds, $parentId = 0)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($menus as $menu) {
|
||||
if ($menu->parent_id == $parentId) {
|
||||
$children = $this->buildTree($menus, $savedMenuIds, $menu->id);
|
||||
|
||||
$node = [
|
||||
'id' => $menu->id,
|
||||
'text' => $menu->title,
|
||||
'attributes' => ['url' => $menu->url],
|
||||
'checked' => in_array($menu->id, $savedMenuIds)
|
||||
];
|
||||
|
||||
if ($children) {
|
||||
$node['children'] = $children;
|
||||
}
|
||||
|
||||
$tree[] = $node;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
public function saveMenu(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'menu_ids' => 'required',
|
||||
'role_id' => 'required|integer'
|
||||
]);
|
||||
$selectedMenuIds = json_decode($request->input('menu_ids', '[]'));
|
||||
$roleId = $request->input('role_id');
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
DB::table('role_menu')->where('role_id', $roleId)->delete();
|
||||
$dataToInsert = [];
|
||||
foreach ($selectedMenuIds as $menuId) {
|
||||
$results = DB::select('SELECT parent_id FROM menus WHERE id = ?', [$menuId]);
|
||||
if($results[0]->parent_id){ //jika memiliki parent_id, insert juga
|
||||
$dataToInsert[] = [
|
||||
'menu_id' => $results[0]->parent_id,
|
||||
'role_id' => $roleId
|
||||
];
|
||||
}
|
||||
$dataToInsert[] = [
|
||||
'menu_id' => $menuId,
|
||||
'role_id' => $roleId
|
||||
];
|
||||
}
|
||||
|
||||
$dataToInsert = array_unique(array_map('serialize', $dataToInsert));
|
||||
$dataToInsert = array_map('unserialize', $dataToInsert);
|
||||
|
||||
DB::table('role_menu')->insert($dataToInsert);
|
||||
DB::commit();
|
||||
return response()->json(['success' => true], 200);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Backend;
|
||||
|
||||
use App\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\RoleRequest;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class RolesController extends Controller
|
||||
{
|
||||
public function index(): Renderable
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['role.view']);
|
||||
$pageInfo = [
|
||||
'title' => 'List Roles',
|
||||
'sub_title' => 'List All User Roles',
|
||||
'path' => url()->current()
|
||||
];
|
||||
return view('backend.pages.roles.index', [
|
||||
'roles' => Role::all(), 'pageInfo' => $pageInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Renderable
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['role.create']);
|
||||
|
||||
$pageInfo = [
|
||||
'title' => 'Create Roles',
|
||||
'sub_title' => 'Create User Roles',
|
||||
'path' => url()->current()
|
||||
];
|
||||
|
||||
return view('backend.pages.roles.create', [
|
||||
'all_permissions' => Permission::all(),
|
||||
'permission_groups' => User::getpermissionGroups(),
|
||||
'pageInfo' => $pageInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(RoleRequest $request): RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['role.create']);
|
||||
|
||||
// Process Data.
|
||||
$role = Role::create(['name' => $request->name, 'guard_name' => 'admin']);
|
||||
|
||||
// $role = DB::table('roles')->where('name', $request->name)->first();
|
||||
$permissions = $request->input('permissions');
|
||||
|
||||
if (!empty($permissions)) {
|
||||
$role->syncPermissions($permissions);
|
||||
}
|
||||
|
||||
session()->flash('success', 'Role has been created.');
|
||||
return redirect()->route('admin.roles.index');
|
||||
}
|
||||
|
||||
public function edit(int $id): Renderable|RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['role.edit']);
|
||||
|
||||
$role = Role::findById($id, 'admin');
|
||||
if (!$role) {
|
||||
session()->flash('error', 'Role not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
$pageInfo = [
|
||||
'title' => 'Create Roles',
|
||||
'sub_title' => 'Create User Roles',
|
||||
'path' => url()->current()
|
||||
];
|
||||
|
||||
return view('backend.pages.roles.edit', [
|
||||
'role' => $role,
|
||||
'all_permissions' => Permission::all(),
|
||||
'permission_groups' => User::getpermissionGroups(),
|
||||
'pageInfo' => $pageInfo
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(RoleRequest $request, int $id): RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['role.edit']);
|
||||
|
||||
$role = Role::findById($id, 'admin');
|
||||
if (!$role) {
|
||||
session()->flash('error', 'Role not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
$permissions = $request->input('permissions');
|
||||
if (!empty($permissions)) {
|
||||
$role->name = $request->name;
|
||||
$role->save();
|
||||
$role->syncPermissions($permissions);
|
||||
}
|
||||
|
||||
session()->flash('success', 'Role has been updated.');
|
||||
return back();
|
||||
}
|
||||
|
||||
public function destroy(int $id): RedirectResponse
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['role.delete']);
|
||||
|
||||
$role = Role::findById($id, 'admin');
|
||||
if (!$role) {
|
||||
session()->flash('error', 'Role not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
$role->delete();
|
||||
session()->flash('success', 'Role has been deleted.');
|
||||
return redirect()->route('admin.roles.index');
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
use App\Traits\AuthorizationChecker;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
//
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, AuthorizationChecker;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,700 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GenerateDataMasterController extends Controller
|
||||
{
|
||||
public function GetMsBasicProduct()
|
||||
{
|
||||
$data = DB::table('MS_BASIC_PRODUCT')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsSpajkStatus()
|
||||
{
|
||||
$data = DB::table('SPAJK_STATUS')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsMarketingType()
|
||||
{
|
||||
$data = DB::table('MS_MARKETING_TYPE')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsDeliveryStatus()
|
||||
{
|
||||
$data = DB::table('MS_DELIVERY_STATUS')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsPartner()
|
||||
{
|
||||
$data = DB::table('MS_PARTNER')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsPartnerRegion($id)
|
||||
{
|
||||
|
||||
$data = DB::table('MS_PARTNER_REGION')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->where('PARTNER_CODE', $id)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsPaymentMethod()
|
||||
{
|
||||
$data = DB::table('MS_PAYMENT_METHOD')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsCountry()
|
||||
{
|
||||
$data = DB::table('MS_COUNTRY')
|
||||
->select('ID', 'COUNTRY_NAME', 'COUNTRY_CODE')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->country_name,
|
||||
'code' => $item->country_code
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function GetMsNationality()
|
||||
{
|
||||
$data = DB::table('MS_NATIONALITY')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function GetMsProvince()
|
||||
{
|
||||
$data = DB::table('MS_PROVINCE')
|
||||
->select('ID', 'DESCRIPTION','CODE')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function GetMsCity($provinceId)
|
||||
{
|
||||
$data = DB::table('MS_CITY')
|
||||
->select('ID', 'NAME','CODE')
|
||||
->where('PROVINCE_CODE', $provinceId)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function GetMsDistrict($cityId)
|
||||
{
|
||||
$data = DB::table('MS_DISTRICT')
|
||||
->select('ID', 'NAME','CODE')
|
||||
->where('CITY_CODE', $cityId)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function GetMsSubDistrict($districtId)
|
||||
{
|
||||
$data = DB::table('MS_SUB_DISTRICT')
|
||||
->select('ID', 'NAME','CODE')
|
||||
->where('DISTRICT_CODE', $districtId)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function GetMsJobType()
|
||||
{
|
||||
$data = DB::table('MS_JOB_TYPE')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsPartnerBranch($id)
|
||||
{
|
||||
$data = DB::table('MS_PARTNER_BRANCH')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->where('PARTNER_REGION_CODE', $id)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsPartnerUnit($id)
|
||||
{
|
||||
$data = DB::table('MS_PARTNER_UNIT')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->where('PARTNER_BRANCH_CODE', $id)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsIdentityType()
|
||||
{
|
||||
$data = DB::table('MS_IDENTITY_TYPE')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsChannel($code)
|
||||
{
|
||||
$data = DB::table('MS_CHANNEL')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->where('MARKETING_TYPE', $code)
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => trim($item->id),
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsChannelList()
|
||||
{
|
||||
$data = DB::table('MS_CHANNEL')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => trim($item->id),
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsDistribution()
|
||||
{
|
||||
$data = DB::table('MS_DISTRIBUTION_CHANNEL')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetProduct()
|
||||
{
|
||||
$data = DB::table('PRODUCT')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetProductCategory()
|
||||
{
|
||||
$data = DB::table('MS_PRODUCT_CATEGORY')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => trim($item->id),
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetOptions()
|
||||
{
|
||||
$roundingType = DB::table('MS_OPTIONS')
|
||||
->select('CODE', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $roundingType->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetRoundingType()
|
||||
{
|
||||
$roundingType = DB::table('MS_ROUNDING_TYPE')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $roundingType->map(function ($item) {
|
||||
return [
|
||||
'value' => trim($item->id),
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetBank()
|
||||
{
|
||||
$roundingType = DB::table('MS_BANK')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->orderBy('DESCRIPTION', 'asc')
|
||||
->get();
|
||||
|
||||
$dropdownList = $roundingType->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsSpajkdocument()
|
||||
{
|
||||
$roundingType = DB::table('MS_DOCUMENT_SPAJK')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $roundingType->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function GetDocumentFormat()
|
||||
{
|
||||
$roundingType = DB::table('MS_DOCUMENT_FORMAT')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $roundingType->map(function ($item) {
|
||||
return [
|
||||
'value' => trim($item->id),
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsDocumentSendTo()
|
||||
{
|
||||
$products = DB::table('MS_DOCUMENT_SENDTO')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $products->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsAutoUwStatus()
|
||||
{
|
||||
$products = DB::table('MS_AUTOUW_STATUS')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $products->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetSpajkStatus()
|
||||
{
|
||||
$products = DB::table('SPAJK_STATUS')
|
||||
->select('ID', 'DESCRIPTION')
|
||||
->whereIn('code', ['SWA', 'UPE', 'UPO', 'UDE', 'UAP'])
|
||||
->get();
|
||||
|
||||
$dropdownList = $products->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsPolicyByPartner($id)
|
||||
{
|
||||
$products = DB::table('POLICY')
|
||||
->select('ID', 'POLICY_NO', 'PARTNER_CODE')
|
||||
->where('PARTNER_CODE', $id)
|
||||
->get();
|
||||
|
||||
$dropdownList = $products->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->policy_no,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsPolicyProduct($id)
|
||||
{
|
||||
$products = DB::table('POLICY_PRODUCT')
|
||||
->join('PRODUCT', 'POLICY_PRODUCT.PRODUCT_ID', '=', 'PRODUCT.ID')
|
||||
->join('MS_MARKETING_TYPE', 'PRODUCT.MARKETING_TYPE', '=', 'MS_MARKETING_TYPE.ID')
|
||||
->join('MS_CHANNEL', 'PRODUCT.CHANNEL_CODE', '=', 'MS_CHANNEL.ID')
|
||||
->select('POLICY_PRODUCT.POLICY_ID AS POLICY_ID', 'MS_MARKETING_TYPE.DESCRIPTION AS MARKETING', 'MS_CHANNEL.DESCRIPTION AS CHANNEL', 'MS_MARKETING_TYPE.ID AS MARKETING_ID', 'MS_CHANNEL.ID AS CHANNEL_ID')
|
||||
->where('POLICY_PRODUCT.POLICY_ID', $id)
|
||||
->get();
|
||||
|
||||
$dropdownList = $products->map(function ($item) {
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function getAllMsCity()
|
||||
{
|
||||
$data = DB::table('MS_CITY')
|
||||
->select('ID', 'NAME','CODE')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function getAllMsDistrict()
|
||||
{
|
||||
$data = DB::table('MS_DISTRICT')
|
||||
->select('ID', 'NAME','CODE')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
|
||||
public function getAllMsSubDistrict()
|
||||
{
|
||||
$data = DB::table('MS_SUB_DISTRICT')
|
||||
->select('ID', 'NAME','CODE')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsGender()
|
||||
{
|
||||
$data = DB::table('MS_GENDER')
|
||||
->select('ID', 'CODE','DESCRIPTION')
|
||||
->orderBy('DESCRIPTION', 'ASC')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsLoanType()
|
||||
{
|
||||
$data = DB::table('MS_LOAN_TYPE')
|
||||
->select('ID', 'CODE','DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsPendingUWType()
|
||||
{
|
||||
$data = DB::table('MS_PENDING_UW')
|
||||
->select('ID','CODE', 'NAME')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->code.' - '.$item->name,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsMedicalType()
|
||||
{
|
||||
$data = DB::table('MS_MEDICAL_TYPE')
|
||||
->select('ID','CODE', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
|
||||
public function GetMsEM()
|
||||
{
|
||||
$data = DB::table('MS_EXTRA_MORTALITY')
|
||||
->select('ID','CODE', 'DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->description,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsClIcd()
|
||||
{
|
||||
$data = DB::table('MS_CL_ICD')
|
||||
->select('ID', 'ICD_CODE','ICD_SHORT_DESC')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->id,
|
||||
'text' => $item->icd_code.' - '.$item->icd_short_desc,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
public function GetMsDecision()
|
||||
{
|
||||
$data = DB::table('MS_UW_DECISION')
|
||||
->select('ID', 'CODE','DESCRIPTION')
|
||||
->get();
|
||||
|
||||
$dropdownList = $data->map(function ($item) {
|
||||
return [
|
||||
'value' => $item->code,
|
||||
'text' => $item->description
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($dropdownList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function redirectAdmin()
|
||||
{
|
||||
return redirect()->route('admin.dashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
|
||||
'web' => [
|
||||
\App\Http\Middleware\LogLoginMiddleware::class,
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'cache.css' => \App\Http\Middleware\CacheCssMiddleware::class,
|
||||
'menu' => \App\Http\Middleware\MenuMiddleware::class,
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (Auth::guard('admin')) {
|
||||
if (!$request->expectsJson()) {
|
||||
return route('admin.login');
|
||||
}
|
||||
} else {
|
||||
if (!$request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CacheCssMiddleware
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$response = $next($request);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
|
||||
|
||||
class CheckForMaintenanceMode extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\LoginLog;
|
||||
|
||||
class LogLoginMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (Auth::check()) {
|
||||
$user = Auth::user();
|
||||
|
||||
// Cek apakah sudah ada log login terbaru (opsional)
|
||||
$latestLog = LoginLog::where('user_id', $user->id)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (!$latestLog || $latestLog->created_at->diffInMinutes(now()) > 5) { // Interval waktu opsional
|
||||
LoginLog::create([
|
||||
'user_id' => $user->id,
|
||||
'ip_address' => $request->ip(),
|
||||
'user_agent' => $request->userAgent(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Spatie\Menu\Laravel\Facades\Menu;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
class MenuMiddleware
|
||||
{
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$menu = Menu::new()
|
||||
->addClass('nav nav-pills nav-sidebar flex-column nav-flat')
|
||||
->setWrapperTag('ul')
|
||||
->setAttributes([
|
||||
'data-widget' => 'treeview',
|
||||
'role' => 'menu',
|
||||
'data-accordion' => 'false'
|
||||
]);
|
||||
|
||||
$menu->html('<li class="nav-item">
|
||||
<a href="'.url('/').'" class="nav-link">
|
||||
<i class="nav-icon mdi mdi-home"></i>
|
||||
<p>Halaman Utama </p>
|
||||
</a>
|
||||
</li>');
|
||||
|
||||
// Ambil data menu utama
|
||||
$user = Auth::guard('admin')->user();
|
||||
$role = $user->roles->first();
|
||||
$currentRoleId = $role ? $role->id : null;
|
||||
|
||||
$menus = DB::select("
|
||||
SELECT m.*, rm.menu_id AS assigned_menu_id
|
||||
FROM menus m
|
||||
LEFT JOIN role_menu rm
|
||||
ON m.id = rm.menu_id
|
||||
WHERE m.parent_id IS NULL AND rm.role_id = '".$currentRoleId."'
|
||||
ORDER BY m.id
|
||||
");
|
||||
|
||||
|
||||
|
||||
foreach ($menus as $item) {
|
||||
// Ambil submenu jika ada
|
||||
$children = DB::select("
|
||||
SELECT m.*, rm.menu_id AS assigned_menu_id
|
||||
FROM menus m
|
||||
LEFT JOIN role_menu rm
|
||||
ON m.id = rm.menu_id
|
||||
WHERE m.parent_id = '".$item->id."' AND rm.role_id = '".$currentRoleId."'
|
||||
ORDER BY m.id
|
||||
");
|
||||
|
||||
|
||||
|
||||
if (isset($children)) {
|
||||
// Menu dengan child
|
||||
$submenu = Menu::new()->addClass('nav nav-treeview');
|
||||
|
||||
foreach ($children as $child) {
|
||||
|
||||
$submenu->html(
|
||||
'<li class="nav-item">' .
|
||||
'<a href="' . url($child->url) . '" class="nav-link">' .
|
||||
'<i class="' . $child->icon . ' nav-icon"></i>' .
|
||||
'<p>' . $child->title . '</p>' .
|
||||
'</a>' .
|
||||
'</li>'
|
||||
);
|
||||
}
|
||||
$menu->html(
|
||||
'<li class="nav-item">' .
|
||||
'<a href="#" class="nav-link">' .
|
||||
'<i class="nav-icon ' . $item->icon . '"></i>' .
|
||||
'<p>' . $item->title . '<i class="fas fa-angle-left right"></i></p>' .
|
||||
'</a>' .
|
||||
$submenu->render() .
|
||||
'</li>'
|
||||
);
|
||||
} else {
|
||||
// Menu tanpa child
|
||||
$menu->html(
|
||||
'<li class="nav-item">' .
|
||||
'<a href="' . url($item->url) . '" class="nav-link">' .
|
||||
'<i class="nav-icon ' . $item->icon . '"></i>' .
|
||||
'<p>' . $item->title . '</p>' .
|
||||
'</a>' .
|
||||
'</li>'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
view()->share('menu', $menu->render());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if(Auth::guard('admin')->check()){
|
||||
return redirect(RouteServiceProvider::ADMIN_DASHBOARD);
|
||||
}
|
||||
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdminRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$adminId = $this->route('admin');
|
||||
|
||||
return [
|
||||
'name' => 'required|max:50',
|
||||
'email' => 'required|max:100|email|unique:admins,email,' . $adminId,
|
||||
'username' => 'required|max:100|unique:admins,username,' . $adminId,
|
||||
'password' => $adminId ? 'nullable|confirmed' : 'confirmed',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RoleRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$roleId = $this->route('role');
|
||||
|
||||
return [
|
||||
'name' => 'required|max:100|unique:roles,name,' . $roleId,
|
||||
'permissions' => 'required|array|min:1',
|
||||
'permissions.*' => 'string|exists:permissions,name',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Models\LoginLog;
|
||||
|
||||
class LogLoginActivity
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(Login $event): void
|
||||
{
|
||||
// Ambil data user yang login
|
||||
$user = $event->user;
|
||||
|
||||
// Simpan log login
|
||||
LoginLog::create([
|
||||
'user_id' => $user->id,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
'status' => 'login',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Auth\Events\Logout;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Models\LoginLog;
|
||||
|
||||
class LogLogoutActivity
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(Logout $event): void
|
||||
{
|
||||
// Ambil data user yang logout
|
||||
$user = $event->user;
|
||||
|
||||
// Simpan log logout
|
||||
LoginLog::create([
|
||||
'user_id' => $user->id,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
'status' => 'logout', // Kolom tambahan untuk menandakan logout
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class Admin extends Authenticatable
|
||||
{
|
||||
use Notifiable, HasRoles;
|
||||
|
||||
/**
|
||||
* Set the default guard for this model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $guard_name = 'admin';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public static function getpermissionGroups()
|
||||
{
|
||||
$permission_groups = DB::table('permissions')
|
||||
->select('group_name as name')
|
||||
->groupBy('group_name')
|
||||
->get();
|
||||
return $permission_groups;
|
||||
}
|
||||
|
||||
public static function getpermissionsByGroupName($group_name)
|
||||
{
|
||||
$permissions = DB::table('permissions')
|
||||
->select('name', 'id')
|
||||
->where('group_name', $group_name)
|
||||
->get();
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
public static function roleHasPermissions($role, $permissions)
|
||||
{
|
||||
$hasPermission = true;
|
||||
foreach ($permissions as $permission) {
|
||||
if (!$role->hasPermissionTo($permission->name)) {
|
||||
$hasPermission = false;
|
||||
return $hasPermission;
|
||||
}
|
||||
}
|
||||
return $hasPermission;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class LoginLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'ip_address',
|
||||
'user_agent',
|
||||
'status'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['title', 'url', 'icon', 'parent_id', 'order'];
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Menu::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Menu::class, 'parent_id')->orderBy('order');
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,33 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
if (env('REDIRECT_HTTPS')) {
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
\Illuminate\Auth\Events\Login::class => [
|
||||
\App\Listeners\LogLoginActivity::class,
|
||||
],
|
||||
\Illuminate\Auth\Events\Logout::class => [
|
||||
\App\Listeners\LogLogoutActivity::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* This namespace is applied to your controller routes.
|
||||
*
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'App\Http\Controllers';
|
||||
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
|
||||
/**
|
||||
* The path to the "admin" route for your application.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const ADMIN_DASHBOARD = '/admin';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapWebRoutes()
|
||||
{
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
trait AuthorizationChecker
|
||||
{
|
||||
/**
|
||||
* Check if the user is authorized to perform the action.
|
||||
*
|
||||
* @param Authenticatable $user
|
||||
* @param array|string $permissions
|
||||
* @return void
|
||||
*/
|
||||
public function checkAuthorization($user, $permissions): void
|
||||
{
|
||||
if (is_null($user) || !$user->can($permissions)) {
|
||||
abort(403, 'Sorry !! You are unauthorized to perform this action.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable, HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public static function getpermissionGroups()
|
||||
{
|
||||
$permission_groups = DB::table('permissions')
|
||||
->select('group_name as name')
|
||||
->groupBy('group_name')
|
||||
->get();
|
||||
return $permission_groups;
|
||||
}
|
||||
|
||||
public static function getpermissionsByGroupName($group_name)
|
||||
{
|
||||
$permissions = DB::table('permissions')
|
||||
->select('name', 'id')
|
||||
->where('group_name', $group_name)
|
||||
->get();
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
public static function roleHasPermissions($role, $permissions)
|
||||
{
|
||||
$hasPermission = true;
|
||||
foreach ($permissions as $permission) {
|
||||
if (!$role->hasPermissionTo($permission->name)) {
|
||||
$hasPermission = false;
|
||||
return $hasPermission;
|
||||
}
|
||||
}
|
||||
return $hasPermission;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user