Merge remote-tracking branch 'origin/prod-kopkb' into test/merge-prod-kopkb
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Anggota extends Model
|
||||
{
|
||||
protected $table = 'anggota';
|
||||
protected $connection = 'mysql7';
|
||||
|
||||
protected $fillable = [
|
||||
'no_anggota',
|
||||
'nama',
|
||||
'noic',
|
||||
'no_tel',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ApprovalWithdrawal extends Model
|
||||
{
|
||||
protected $table = 'approval_withdrawal';
|
||||
public $timestamps = true;
|
||||
protected $primaryKey = 'id';
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'kodcaw',
|
||||
'pc_name',
|
||||
'operasi_name',
|
||||
'amount',
|
||||
'approval_status',
|
||||
'updated_serahan_v2',
|
||||
'updated_pendahuluan_v3',
|
||||
'denopendser_id_v2',
|
||||
'gldetail_id_v2',
|
||||
'denopendser_id_v3',
|
||||
'gldetail_id_v3',
|
||||
'action',
|
||||
'approval_timestamp',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CloneDatabase extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'migrate:clone';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate Laravel migrations from an existing database';
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tables = DB::connection('mysql7')->select("SHOW TABLES");
|
||||
|
||||
$namedatabase = DB::connection('mysql7')->getDatabaseName();
|
||||
|
||||
if (empty($tables)) {
|
||||
$this->error("No tables found in database");
|
||||
return;
|
||||
}
|
||||
|
||||
$boolreject = false;
|
||||
$list_of_rejected = ($boolreject) ? $this->rejected_table() : [];
|
||||
// Get table names
|
||||
$tableNames = array_map(fn($table) => is_array($table) ? array_values($table) : $table, $tables);
|
||||
$tableString = collect($tables)->pluck('Tables_in_' .$namedatabase)->reject(fn($table) => in_array($table, $list_of_rejected))->implode(',');
|
||||
// Run migration generator
|
||||
Artisan::call("migrate:generate --path=database/migrations --tables=" .$tableString);
|
||||
// Artisan::call("migrate:status");
|
||||
|
||||
$this->info("Migrations generated successfully for database");
|
||||
}
|
||||
|
||||
protected function rejected_table() : Array{
|
||||
return [
|
||||
'alert','auditbarcode','auditdaftar',
|
||||
'auditrekodsemakan','audtrail','bakipelanggan',
|
||||
'bandar','batchlel_xtra','bayaranpenebusan','belian',
|
||||
'brand','checker','configkaunter','gadaisimulasi','gadaitemp',
|
||||
'gadaixtra','hapusgadaionline','hargaemasbeli',
|
||||
'hargaemasjual','imbangan','inoutmarxtra',
|
||||
'jemas00', 'jemasbeli','jemasxtra',
|
||||
'jenisakaun','jualan','jualemas','jumlahtebus',
|
||||
'karat','karatbeli','karatjual','karatxtra',
|
||||
'ku_nm', 'ku_nmbaru', 'ku_nmxtra', 'kumpulan',
|
||||
'kurangxtra', 'lapringkasan', 'laptebus', 'lapterkumpul',
|
||||
'lapterkumpulharian','lelkarat','lelmarhun_xtra', 'marhunbeli',
|
||||
'marhunjual', 'marhunsimulasi', 'marhunxtra', 'model',
|
||||
'outmarhun', 'outmarhunxtra', 'palsu', 'pemeriksaan',
|
||||
'pengesahangadai', ' peratusan', 'percentonline',
|
||||
'polisxtra','product','ramalan', 'rekodtangguh', 'sahabat',
|
||||
'simpanan', 'simulasi_batchlel', 'simulasi_batchlelxtra',
|
||||
'simulasi_lelmarhun', 'simulasi_lelong', 'simulasi_lelongxtra',
|
||||
'tagpelanggan', 'tangguhlelong', 'taraf',
|
||||
'tebus_xtra', 'tebuslelong', 'temp_ic', 'tempimbang',
|
||||
'tempnosiri', 'tempnosirixtra', 'temppwd', 'temptarikhaging',
|
||||
'tunaigadteb', 'tuntutbakixtra', 'ubs_code', 'ugama',
|
||||
'updateserver', 'zparameter', 'zparameterxtra','ZPARAMETER1'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Cawangan;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ImportCsv extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'csv:import';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import CSV file to MySQL table';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$file = resource_path('data/anggota.csv');
|
||||
$handle = fopen($file, 'r');
|
||||
$header = fgetcsv($handle);
|
||||
|
||||
$columnMap = [
|
||||
'no_anggota' => 'no_anggota',
|
||||
'nama' => 'nama',
|
||||
'no_kp' => 'noic',
|
||||
'telefon' => 'no_tel',
|
||||
];
|
||||
|
||||
$chunk = [];
|
||||
$chunkSize = 1000;
|
||||
$totalRows = 0;
|
||||
|
||||
$bar = $this->output->createProgressBar();
|
||||
$bar->start();
|
||||
|
||||
try {
|
||||
while (($row = fgetcsv($handle)) !== false) {
|
||||
$csvData = array_combine($header, $row);
|
||||
$data = [];
|
||||
|
||||
foreach ($columnMap as $csvCol => $dbCol) {
|
||||
$data[$dbCol] = $csvData[$csvCol] ?? null;
|
||||
}
|
||||
|
||||
$data['status'] = 1;
|
||||
$chunk[] = $data;
|
||||
|
||||
if (count($chunk) >= $chunkSize) {
|
||||
DB::table('anggota')->insertOrIgnore($chunk);
|
||||
$totalRows += count($chunk);
|
||||
$chunk = [];
|
||||
$bar->advance($chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($chunk)) {
|
||||
DB::table('anggota')->insertOrIgnore($chunk);
|
||||
$totalRows += count($chunk);
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->info("\n✅ Successfully imported {$totalRows} rows");
|
||||
} catch (\Exception $e) {
|
||||
$this->error("\n❌ Error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Cawangan;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InsertSempornaData extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'palsu:insert-data {kodcaw=011237 : The kodcaw value to insert data for}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Insert sample data into palsu table for specific kodcaw';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$kodcaw = $this->argument('kodcaw');
|
||||
|
||||
$this->info("Inserting data for kodcaw: {$kodcaw}");
|
||||
|
||||
// Validate if kodcaw exists in Cawangan table
|
||||
$cawangan = DB::connection('mysql7')->table('arrahn_master_db')->where('kodcaw', $kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
$this->error("Error: kodcaw '{$kodcaw}' not found in Cawangan table!");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Convert stdClass to array if needed
|
||||
$cawangan = (array) $cawangan;
|
||||
|
||||
if (!isset($cawangan['mysql']) || empty($cawangan['mysql'])) {
|
||||
$this->error("Error: Database connection not found for kodcaw '{$kodcaw}'!");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->info("Using database connection: {$cawangan['mysql']}");
|
||||
|
||||
$data = [
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240808-0003',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 1748.20,
|
||||
'jbg' => 4,
|
||||
'untung' => 78.00,
|
||||
'untungonepercent' => 52.00,
|
||||
'untungcajlain' => 26.00,
|
||||
'pembiayaan' => 1300.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0015',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 8499.80,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 519.30,
|
||||
'untungonepercent' => 305.55,
|
||||
'untungcajlain' => 213.75,
|
||||
'pembiayaan' => 6790.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240806-0011',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 8740.98,
|
||||
'jbg' => 4,
|
||||
'untung' => 475.40,
|
||||
'untungonepercent' => 279.60,
|
||||
'untungcajlain' => 195.80,
|
||||
'pembiayaan' => 6990.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240828-0001',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 8121.20,
|
||||
'jbg' => 3,
|
||||
'untung' => 316.65,
|
||||
'untungonepercent' => 182.70,
|
||||
'untungcajlain' => 133.95,
|
||||
'pembiayaan' => 6090.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240904-0007',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 16135.20,
|
||||
'jbg' => 3,
|
||||
'untung' => 617.10,
|
||||
'untungonepercent' => 363.00,
|
||||
'untungcajlain' => 254.10,
|
||||
'pembiayaan' => 12100.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240904-0008',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 12101.40,
|
||||
'jbg' => 3,
|
||||
'untung' => 462.60,
|
||||
'untungonepercent' => 272.10,
|
||||
'untungcajlain' => 190.50,
|
||||
'pembiayaan' => 9070.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240904-0009',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 6050.70,
|
||||
'jbg' => 3,
|
||||
'untung' => 231.00,
|
||||
'untungonepercent' => 135.90,
|
||||
'untungcajlain' => 95.10,
|
||||
'pembiayaan' => 4530.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0023',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 19001.24,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 149.18,
|
||||
'untungonepercent' => 87.75,
|
||||
'untungcajlain' => 61.43,
|
||||
'pembiayaan' => 1950.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0024',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 8499.80,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 65.03,
|
||||
'untungonepercent' => 38.25,
|
||||
'untungcajlain' => 26.78,
|
||||
'pembiayaan' => 850.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0025',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 15972.57,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 122.40,
|
||||
'untungonepercent' => 72.00,
|
||||
'untungcajlain' => 50.40,
|
||||
'pembiayaan' => 1600.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240618-0026',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 8552.90,
|
||||
'jbg' => 5.5,
|
||||
'untung' => 187.00,
|
||||
'untungonepercent' => 110.00,
|
||||
'untungcajlain' => 77.00,
|
||||
'pembiayaan' => 2000.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0027',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 42923.11,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 328.95,
|
||||
'untungonepercent' => 193.50,
|
||||
'untungcajlain' => 135.45,
|
||||
'pembiayaan' => 4300.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0028',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 41872.04,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 321.30,
|
||||
'untungonepercent' => 189.00,
|
||||
'untungcajlain' => 132.30,
|
||||
'pembiayaan' => 4200.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240618-0020',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 15495.86,
|
||||
'jbg' => 5.5,
|
||||
'untung' => 280.50,
|
||||
'untungonepercent' => 165.00,
|
||||
'untungcajlain' => 115.50,
|
||||
'pembiayaan' => 3000.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240719-0030',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 17483.01,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 133.88,
|
||||
'untungonepercent' => 78.75,
|
||||
'untungcajlain' => 55.13,
|
||||
'pembiayaan' => 1750.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240618-0029',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 10062.25,
|
||||
'jbg' => 5.5,
|
||||
'untung' => 280.50,
|
||||
'untungonepercent' => 165.00,
|
||||
'untungcajlain' => 115.50,
|
||||
'pembiayaan' => 3000.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240731-0026',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 10283.50,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 558.45,
|
||||
'untungonepercent' => 328.50,
|
||||
'untungcajlain' => 229.95,
|
||||
'pembiayaan' => 7300.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240715-0027',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 29624.77,
|
||||
'jbg' => 4.5,
|
||||
'untung' => 1147.50,
|
||||
'untungonepercent' => 675.00,
|
||||
'untungcajlain' => 472.50,
|
||||
'pembiayaan' => 15000.00,
|
||||
],
|
||||
[
|
||||
'kodcaw' => $kodcaw,
|
||||
'tarikh' => '2024-11-28',
|
||||
'norujukan' => '011237240912-0009',
|
||||
'teller' => 'DM',
|
||||
'nota' => 'Barang Kes Semporna 28/11/24',
|
||||
'nilaimarhun' => 12654.35,
|
||||
'jbg' => 3,
|
||||
'untung' => 428.40,
|
||||
'untungonepercent' => 252.00,
|
||||
'untungcajlain' => 176.40,
|
||||
'pembiayaan' => 8400.00,
|
||||
],
|
||||
];
|
||||
|
||||
$insertedCount = 0;
|
||||
$skippedCount = 0;
|
||||
|
||||
// Start database transaction
|
||||
DB::connection($cawangan['mysql'])->beginTransaction();
|
||||
|
||||
try {
|
||||
foreach ($data as $record) {
|
||||
// Check if record already exists
|
||||
$exists = DB::connection($cawangan['mysql'])->table('palsu')
|
||||
->where('kodcaw', $record['kodcaw'])
|
||||
->where('norujukan', $record['norujukan'])
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
DB::connection($cawangan['mysql'])->table('palsu')->insert($record);
|
||||
$insertedCount++;
|
||||
$this->line("✓ Inserted: {$record['norujukan']}");
|
||||
} else {
|
||||
$skippedCount++;
|
||||
$this->line("- Skipped: {$record['norujukan']} (already exists)");
|
||||
}
|
||||
}
|
||||
|
||||
// Commit the transaction if everything is successful
|
||||
DB::connection($cawangan['mysql'])->commit();
|
||||
$this->info("✓ Transaction committed successfully!");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Rollback the transaction if any error occurs
|
||||
DB::connection($cawangan['mysql'])->rollback();
|
||||
$this->error("✗ Transaction failed and rolled back: " . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->info("\nSummary:");
|
||||
$this->info("Inserted: {$insertedCount} records");
|
||||
$this->info("Skipped: {$skippedCount} records");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Console\Scheduling\Schedule;
|
||||
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
|
||||
|
||||
use App\Jobs\WhatsappUnsoldCommodityScanner;
|
||||
use Faker\Provider\ar_SA\Color;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
@@ -22,6 +23,8 @@ class Kernel extends ConsoleKernel
|
||||
Commands\CawanganDebugConnections::class,
|
||||
Commands\ClearCachesAll::class,
|
||||
Commands\RestartSupervisor::class,
|
||||
Commands\InsertSempornaData::class,
|
||||
//Commands\ImportCsv::class,
|
||||
|
||||
];
|
||||
|
||||
|
||||
+2
-1
@@ -61,7 +61,8 @@ class Customer extends Model
|
||||
'kumpulan',
|
||||
'telefon2',
|
||||
'nota_pekerjaan',
|
||||
'tagpelanggan'
|
||||
'tagpelanggan',
|
||||
'tag_anggota'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -23,7 +23,8 @@ class GlDetail extends Model
|
||||
'amaun',
|
||||
'pendahuluan',
|
||||
'serahan',
|
||||
'teller'
|
||||
'teller',
|
||||
'date_created'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ use App\Status;
|
||||
use App\LookupStatus;
|
||||
use App\ARFiles;
|
||||
use App\WTDDraft;
|
||||
use App\WTDSimulasi;
|
||||
use App\SerahBaki;
|
||||
use App\WTD;
|
||||
use App\StokAudit1;
|
||||
@@ -2363,19 +2364,84 @@ class AdminPageController extends Controller
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
$latestbatch = SerahBaki::on($cawangan['mysql'])->where('norujukan','baru')->get()->toArray();
|
||||
//$latestbatch = SerahBaki::on($cawangan['mysql'])->where('norujukan','baru')->get()->toArray();
|
||||
//new added
|
||||
$serahBaki = SerahBaki::on($cawangan['mysql'])
|
||||
->where('norujukan', 'baru')
|
||||
->get();
|
||||
|
||||
$allBatchNo = $serahBaki->pluck('batchno')->unique()->toArray();
|
||||
|
||||
$wtddraftData = WTDDraft::on('mysql7')
|
||||
->selectRaw("
|
||||
batchno_serah,
|
||||
YEAR(t_jual) as tahun,
|
||||
GROUP_CONCAT(
|
||||
DISTINCT MONTH(t_jual)
|
||||
ORDER BY MONTH(t_jual)
|
||||
SEPARATOR ','
|
||||
) as bulan
|
||||
")
|
||||
->where('kodcaw', $request->kodcaw)
|
||||
->whereIn('batchno_serah', $allBatchNo)
|
||||
->groupBy('batchno_serah', DB::raw('YEAR(t_jual)'))
|
||||
->get()
|
||||
->groupBy('batchno_serah')
|
||||
->map(function ($rows) {
|
||||
return $rows->map(function ($row) {
|
||||
return [
|
||||
'tahun' => $row->tahun,
|
||||
'bulan' => $row->bulan
|
||||
];
|
||||
})->values();
|
||||
});
|
||||
|
||||
$finalData = $serahBaki->map(function ($item) use ($wtddraftData) {
|
||||
$batchno = $item->batchno;
|
||||
|
||||
$tahun = null;
|
||||
$bulan = [];
|
||||
|
||||
if (!empty($wtddraftData[$batchno])) {
|
||||
// ambil tahun pertama (kebiasaannya satu tahun sahaja)
|
||||
$tahun = $wtddraftData[$batchno][0]['tahun'];
|
||||
|
||||
// convert string "2,3,4,5" → array
|
||||
$bulan = explode(',', $wtddraftData[$batchno][0]['bulan']);
|
||||
}
|
||||
|
||||
return [
|
||||
'batchno' => $batchno,
|
||||
'norujukan' => $item->norujukan,
|
||||
'tarikh' => $item->tarikh,
|
||||
't_jual' => $item->t_jual,
|
||||
'baki' => $item->baki,
|
||||
't_htr_ag' => $item->t_htr_ag,
|
||||
'aktif' => $item->aktif,
|
||||
'tahun' => $tahun,
|
||||
'bulan' => implode(',',$bulan),
|
||||
// field lain kekal
|
||||
];
|
||||
});
|
||||
|
||||
$finalDataArray = $finalData->toArray();
|
||||
//end new added
|
||||
|
||||
$batch_old = WTDDraft::on('mysql7')->select('kodcaw')->where('batchno_serah',0)->where('kodcaw',$request->kodcaw)
|
||||
->groupBy('kodcaw')->get();
|
||||
|
||||
$batch_old_noruj = WTDDraft::on('mysql7')->where('batchno_serah',0)->where('kodcaw',$request->kodcaw)->pluck('norujukan');
|
||||
$lelong_data = Lelong::on($cawangan['mysql'])->whereIn('norujukan',$batch_old_noruj)->get();
|
||||
|
||||
|
||||
foreach($batch_old as $index=>$bo)
|
||||
{
|
||||
array_push($latestbatch,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
|
||||
//array_push($latestbatch,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
|
||||
array_push($finalDataArray,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
|
||||
|
||||
}
|
||||
|
||||
$data = $this->paginate($latestbatch,8);
|
||||
//$data = $this->paginate($latestbatch,8);
|
||||
$data = $this->paginate($finalDataArray,8);
|
||||
|
||||
return response()->json($data,200);
|
||||
|
||||
@@ -2697,8 +2763,9 @@ class AdminPageController extends Controller
|
||||
't_update' => $current->toDateString()));
|
||||
}
|
||||
|
||||
$serahbakiupdate = SerahBaki::on($cawangan['mysql'])->where('batchno',$batchno)->update(array('aktif' => 1,'t_jual' => $current->toDateString(),'nopelanggan' => $request->nocek));;
|
||||
|
||||
//$serahbakiupdate = SerahBaki::on($cawangan['mysql'])->where('batchno',$batchno)->update(array('aktif' => 1,'t_jual' => $current->toDateString(),'nopelanggan' => $request->nocek));;
|
||||
$serahbakiupdate = SerahBaki::on($cawangan['mysql'])->where('batchno',$batchno)->update(array('aktif' => 1,'t_jual' => $current->toDateString(),'nopelanggan' => $request->nocek,'t_htr_ag' => $request->tarikhAG));
|
||||
|
||||
return response()->json('success',200);
|
||||
|
||||
}catch (\Throwable $e){
|
||||
@@ -3080,34 +3147,83 @@ class AdminPageController extends Controller
|
||||
|
||||
|
||||
|
||||
public function BilanganPengadai(Request $request){
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_gadai','>=',$request->mula],['t_gadai','<=',$request->hingga]])
|
||||
->where('sttebus','=','')
|
||||
->select('nokp','sttebus')
|
||||
->groupBy('nokp')->get();
|
||||
|
||||
$gadai_pluck_nokp = $gadai->pluck('nokp');
|
||||
|
||||
if($request->jenis == 'pekerja'){
|
||||
|
||||
$customers = Customer::on('mysql7')
|
||||
->selectRaw('COUNT(*) AS bilangangadai')
|
||||
->addSelect(DB::connection($cawangan['mysql'])
|
||||
->raw('keterangan as keterangan'))
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp)
|
||||
->join('pekerjaan','customer.kodkerja','=','pekerjaan.kodkerja')
|
||||
->groupBy('pekerjaan.kodkerja')
|
||||
->get();
|
||||
|
||||
public function BilanganPengadai(Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
->where('t_gadai', '>=', $request->mula)
|
||||
->where('t_gadai', '<=', $request->hingga)
|
||||
->where('sttebus', '')
|
||||
->select('nokp')
|
||||
->groupBy('nokp')
|
||||
->get();
|
||||
|
||||
$gadai_pluck_nokp = $gadai->pluck('nokp');
|
||||
$jenis = $request->jenis;
|
||||
$filter_value = $request->value ?? null;
|
||||
|
||||
$customers = [];
|
||||
|
||||
if ($jenis === 'pekerja') {
|
||||
$customers = Customer::on('mysql7')
|
||||
->selectRaw('pekerjaan.keterangan, COUNT(*) AS bilangangadai')
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp)
|
||||
->join('pekerjaan', 'customer.kodkerja', '=', 'pekerjaan.kodkerja')
|
||||
->groupBy('pekerjaan.kodkerja')
|
||||
->get();
|
||||
|
||||
} elseif ($jenis === 'agama') {
|
||||
$agamaMap = [
|
||||
'01' => 'Islam',
|
||||
'02' => 'Hindu',
|
||||
'03' => 'Buddha',
|
||||
'04' => 'Kristian',
|
||||
'05' => 'Lain-lain',
|
||||
'' => 'Tiada Data',
|
||||
];
|
||||
|
||||
$query = Customer::on('mysql7')
|
||||
->selectRaw('kodugama as keterangan, COUNT(*) as bilangangadai')
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp);
|
||||
|
||||
if ($filter_value) {
|
||||
$query->where('kodugama', $filter_value); // contoh: '01'
|
||||
}
|
||||
|
||||
|
||||
|
||||
$customers = $query->groupBy('kodugama')->get();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
$customer->keterangan = $agamaMap[$customer->keterangan] ?? $customer->keterangan;
|
||||
}
|
||||
|
||||
} elseif ($jenis === 'bangsa') {
|
||||
$bangsaMap = [
|
||||
'M' => 'Melayu',
|
||||
'C' => 'Cina',
|
||||
'I' => 'India',
|
||||
'L' => 'Lain-lain',
|
||||
'' => 'Tiada Data',
|
||||
];
|
||||
|
||||
$query = Customer::on('mysql7')
|
||||
->selectRaw('bangsa as keterangan, COUNT(*) as bilangangadai')
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp);
|
||||
|
||||
if ($filter_value) {
|
||||
$query->where('bangsa', $filter_value); // contoh: 'M'
|
||||
}
|
||||
|
||||
$customers = $query->groupBy('bangsa')->get();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
$customer->keterangan = $bangsaMap[$customer->keterangan] ?? $customer->keterangan;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($customers);
|
||||
}
|
||||
|
||||
@@ -3708,16 +3824,16 @@ class AdminPageController extends Controller
|
||||
|
||||
$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh', $lastDayOfYear)->first();
|
||||
$get_imbangduga = optional($get_imbangduga)->toArray() ?? [];
|
||||
if(empty($get_imbangduga)){
|
||||
$requestData = new Request([
|
||||
'tarikh' => $request->tarikh,
|
||||
'kodcaw' => $kodcaw,
|
||||
]);
|
||||
$exception_case = $this->AkruKeuntunganSebenar($requestData);
|
||||
}
|
||||
// if(empty($get_imbangduga)){
|
||||
// $requestData = new Request([
|
||||
// 'tarikh' => $request->tarikh,
|
||||
// 'kodcaw' => $kodcaw,
|
||||
// ]);
|
||||
// $exception_case = $this->AkruKeuntunganSebenar($requestData);
|
||||
// }
|
||||
|
||||
$backdate_keun_sebenar += isset($get_imbangduga['keun_sebenar']) ? $get_imbangduga['keun_sebenar'] : 0;
|
||||
$backdate_keun_sebenar += $exception_case;
|
||||
$backdate_keun_sebenar += (float) ($exception_case ?? 0);
|
||||
$recentDate->subYear()->startOfYear();
|
||||
}
|
||||
|
||||
@@ -3906,4 +4022,222 @@ class AdminPageController extends Controller
|
||||
'result' => $status === 'completed' ? $result : null,
|
||||
]);
|
||||
}
|
||||
|
||||
//function wtd baru
|
||||
public function janaSimulasiWTD(Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
//listing sag belum tuntut cwgn
|
||||
$sag_cwgn = collect(
|
||||
Lelong::on($cawangan['mysql'])
|
||||
->selectRaw('norujukan')
|
||||
->whereYear('t_jual', $request->tahun)
|
||||
->whereNull('trkhtuntut')
|
||||
->where('baki', '>', 0)
|
||||
->pluck('norujukan') // lebih bersih
|
||||
);
|
||||
|
||||
//listing sag blocked
|
||||
$sag_online = collect(
|
||||
WTDDraft::on('mysql7')
|
||||
->selectRaw('norujukan')
|
||||
->where('kodcaw', '=', $request->kodcaw)
|
||||
->pluck('norujukan')
|
||||
);
|
||||
//dd($sag_online);
|
||||
//filter sag yg tk wujud dlm wtd_draft
|
||||
$filtersag = $sag_cwgn->diff($sag_online);
|
||||
|
||||
//query baru
|
||||
$tarikh_belum_tuntut = Lelong::on($cawangan['mysql'])
|
||||
->selectRaw('
|
||||
MONTH(t_jual) as bulan,
|
||||
SUM(pinjaman) as pembiayaan,
|
||||
ABS(SUM(baki)) as baki,
|
||||
COUNT(DISTINCT norujukan) as jumlah_norujukan,
|
||||
kodcaw
|
||||
')
|
||||
->whereIn('norujukan', $filtersag)
|
||||
->groupBy('bulan', 'kodcaw')
|
||||
->orderBy('bulan')
|
||||
->get();
|
||||
|
||||
$tarikh_belum_tuntut = $tarikh_belum_tuntut->map(function ($item) {
|
||||
$item->bulan = \Carbon\Carbon::create()->month($item->bulan)->format('F');
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json($tarikh_belum_tuntut);
|
||||
}
|
||||
|
||||
public function RekodSimulasiWTD(Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
$rekod_simulasi = Lelong::on($cawangan['mysql'])
|
||||
->join('gadai','lelong.norujukan','=','gadai.norujukan')
|
||||
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp')
|
||||
->whereMonth('lelong.t_jual', $request->month)
|
||||
->whereYear('lelong.t_jual', $request->year)
|
||||
->whereNull('lelong.trkhtuntut')
|
||||
->where('lelong.baki', '>', 0)
|
||||
->get();
|
||||
|
||||
return response()->json($rekod_simulasi);
|
||||
}
|
||||
|
||||
public function prosesSimulasiWTD(Request $request)
|
||||
{
|
||||
$proses = $request->input;
|
||||
|
||||
// dd($proses, $cawangan);
|
||||
|
||||
$baki = 0;
|
||||
$jumlahPembiayaan = 0;
|
||||
$simulasi = WTDSimulasi::max('simulasi')+1;
|
||||
|
||||
foreach ($proses as $item) {
|
||||
WTDSimulasi::create([
|
||||
'bulan' => $item['bulan'],
|
||||
'tahun' => $item['tahun'],
|
||||
'kodcaw' => $item['kodcaw'],
|
||||
'jumlah_sag' => $item['jumlah_sag'],
|
||||
'pembiayaan'=> $item['pembiayaan'],
|
||||
'baki'=> $item['baki'],
|
||||
'simulasi' => $simulasi,
|
||||
]);
|
||||
$baki += $item['baki'];
|
||||
$jumlahPembiayaan = $item['pembiayaan'];
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success','simulasi' => $simulasi,'baki' => $baki,'pinjaman' => $jumlahPembiayaan]);
|
||||
}
|
||||
|
||||
public function pengesahanSimulasiWTD(Request $request)
|
||||
{
|
||||
// Decode the JSON records from the request
|
||||
$records = json_decode($request->records, true);
|
||||
|
||||
// Retrieve and clean 'kodcaw' from the request
|
||||
$kodcaw = $request->kodcaw;
|
||||
$kodcaw_clean = str_replace('"', '', $kodcaw);
|
||||
|
||||
// Get the database connection for the branch (cawangan)
|
||||
$cawangan = Cawangan::where('kodcaw', $kodcaw_clean)->first();
|
||||
|
||||
// Check if 'Cawangan' exists
|
||||
if (!$cawangan) {
|
||||
return response()->json(['status' => 'error', 'message' => 'Invalid branch code (kodcaw).'], 404);
|
||||
}
|
||||
|
||||
$cawangan_connection = $cawangan->mysql;
|
||||
|
||||
// Get the latest batch number and increment it
|
||||
$latestBatch = SerahBaki::on($cawangan_connection)->max('batchno') + 1;
|
||||
|
||||
// Initialize total variables
|
||||
$totalPembiayaan = 0;
|
||||
$totalBaki = 0;
|
||||
|
||||
|
||||
try {
|
||||
// Iterate through the records and save them to the WTDDraft table
|
||||
foreach ($records as $record) {
|
||||
// Check if 'bulan' and 'tahun' exist in the record
|
||||
if (!isset($record['bulan']) || !isset($record['tahun'])) {
|
||||
return response()->json(['status' => 'error', 'message' => 'Missing bulan or tahun in records.'], 400);
|
||||
}
|
||||
$month = DateTime::createFromFormat('F', $record["bulan"])->format('n');
|
||||
|
||||
|
||||
// Query norujukan records from the database
|
||||
$query_norujukan = Lelong::on($cawangan_connection)
|
||||
->join('gadai', 'lelong.norujukan', '=', 'gadai.norujukan')
|
||||
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp, lelong.t_jual')
|
||||
->whereMonth('lelong.t_jual', $month)
|
||||
->whereYear('lelong.t_jual', $record["tahun"])
|
||||
->whereNull('lelong.trkhtuntut')
|
||||
->where('lelong.baki', '>', 0)
|
||||
->get();
|
||||
|
||||
// Save each record to the WTDDraft table
|
||||
foreach ($query_norujukan as $query) {
|
||||
$wtddraft = new WTDDraft();
|
||||
$wtddraft->nokp = $query['nokp'];
|
||||
$wtddraft->kodcaw = $kodcaw_clean;
|
||||
$wtddraft->norujukan = $query['norujukan'];
|
||||
$wtddraft->t_jual = $query['t_jual'];
|
||||
$wtddraft->t_gadai = $query['t_gadai'] ?? null; // Optional: ensure 't_gadai' exists
|
||||
$wtddraft->t_lelong = $query['t_lelong'];
|
||||
$wtddraft->batchno_serah = $latestBatch;
|
||||
$wtddraft->save();
|
||||
}
|
||||
|
||||
// Accumulate totals
|
||||
$totalPembiayaan += $record['pembiayaan'] ?? 0;
|
||||
$totalBaki += $record['baki'] ?? 0;
|
||||
}
|
||||
|
||||
// Create a new record in the SerahBaki table
|
||||
SerahBaki::on($cawangan_connection)->create([
|
||||
'norujukan' => 'baru',
|
||||
'batchno' => $latestBatch,
|
||||
'hargajual' => 0.00,
|
||||
'pinjaman' => $totalPembiayaan,
|
||||
'upah' => 0.00,
|
||||
'cajlel' => 0.00,
|
||||
'gst_cl' => 0.00,
|
||||
'gst_hj' => 0.00,
|
||||
'baki' => $totalBaki,
|
||||
'tarikh' => Carbon::now()->toDateString(),
|
||||
't_jual' => Carbon::now()->toDateString(),
|
||||
'nopelanggan' => '',
|
||||
'aktif' => 0,
|
||||
]);
|
||||
|
||||
// Return a success response with the new batch number
|
||||
return response()->json(['status' => 'success', 'batchno' => $latestBatch], 200);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Log the error and return a failure response
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getLine());
|
||||
return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function simulasiToDraft(Request $request)
|
||||
{
|
||||
$bulan = $request->bulan;
|
||||
|
||||
if (!$bulan || count($bulan) === 0) {
|
||||
return response()->json(['error' => 'Sila pilih sekurang-kurangnya satu bulan.'], 400);
|
||||
}
|
||||
|
||||
$simulasi = WTDSimulasi::whereIn('bulan', $bulan)->get();
|
||||
|
||||
if ($simulasi->isEmpty()) {
|
||||
return response()->json(['error' => 'Tiada data untuk bulan yang dipilih.'], 404);
|
||||
}
|
||||
|
||||
// foreach ($simulasi as $data) {
|
||||
// WTDDraft::create([
|
||||
// 'nokp' => $data->nokp ?? null,
|
||||
// 'kodcaw' => $data->kodcaw ?? null,
|
||||
// 'norujukan' => $data->norujukan ?? null,
|
||||
// 't_jual' => $data->t_jual ?? null,
|
||||
// 't_gadai' => $data->t_gadai ?? null,
|
||||
// 't_lelong' => $data->t_lelong ?? null,
|
||||
// 'batchno_serah' => $data->simulasi, // Simpan sebagai rujukan
|
||||
// ]);
|
||||
// }
|
||||
|
||||
//dd($bulan, $simulasi);
|
||||
|
||||
return response()->json(['message' => 'Data berjaya dipindahkan ke WTD Draft!']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Audit;
|
||||
use App\Polis;
|
||||
use App\Cawangan;
|
||||
use App\LookupAlasan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BarangkesController extends Controller
|
||||
{
|
||||
public function LaporanBarangKes(Request $request)
|
||||
{
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['error' => 'Invalid kodcaw'], 403);
|
||||
}
|
||||
|
||||
$query = DB::connection($cawangan['mysql'])->table('palsu')
|
||||
->select([
|
||||
'tarikh',
|
||||
'norujukan',
|
||||
'nota',
|
||||
'pembiayaan',
|
||||
'nilaimarhun',
|
||||
'jbg',
|
||||
'untung',
|
||||
'untungonepercent',
|
||||
'untungcajlain'
|
||||
])
|
||||
->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir]);
|
||||
|
||||
$result = $query->get();
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
}
|
||||
@@ -462,7 +462,7 @@ class CallCenterController extends Controller
|
||||
if($fasa == 1){
|
||||
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',5.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',7],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
@@ -470,7 +470,7 @@ class CallCenterController extends Controller
|
||||
|
||||
}elseif($fasa == 2){
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tempoh','<=',11.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
@@ -510,12 +510,12 @@ class CallCenterController extends Controller
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
if($fasa == 1){
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',5.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',7],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
}elseif($fasa == 2){
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tempoh','<=',11.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0]])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
}
|
||||
@@ -530,7 +530,7 @@ class CallCenterController extends Controller
|
||||
$caw_notis->kodcaw = $kodcaw;
|
||||
$caw_notis->peringatan = 1;
|
||||
$caw_notis->daritempoh = 5;
|
||||
$caw_notis->hinggatempoh = 5;
|
||||
$caw_notis->hinggatempoh = 7;
|
||||
$caw_notis->status = 1;
|
||||
$caw_notis->save();
|
||||
|
||||
@@ -540,7 +540,7 @@ class CallCenterController extends Controller
|
||||
$caw_notis->kodcaw = $kodcaw;
|
||||
$caw_notis->peringatan = 1;
|
||||
$caw_notis->daritempoh = 11;
|
||||
$caw_notis->hinggatempoh = 11;
|
||||
$caw_notis->hinggatempoh = 12;
|
||||
$caw_notis->status = 1;
|
||||
$caw_notis->save();
|
||||
|
||||
@@ -599,7 +599,7 @@ class CallCenterController extends Controller
|
||||
$notis = Notis::create([
|
||||
'tarikh_notis' => $tarikh_notis,
|
||||
'daritempoh' => 5,
|
||||
'hinggatempoh' => 5,
|
||||
'hinggatempoh' => 7,
|
||||
'sts_notis' => 1,
|
||||
'peringatan' => 1
|
||||
]);
|
||||
@@ -607,7 +607,7 @@ class CallCenterController extends Controller
|
||||
$notis = Notis::create([
|
||||
'tarikh_notis' => $tarikh_notis,
|
||||
'daritempoh' => 11,
|
||||
'hinggatempoh' => 11,
|
||||
'hinggatempoh' => 12,
|
||||
'sts_notis' => 1,
|
||||
'peringatan' => 1
|
||||
]);
|
||||
@@ -1564,4 +1564,162 @@ class CallCenterController extends Controller
|
||||
}
|
||||
return response()->json($cawnotis_all);
|
||||
}
|
||||
|
||||
public function rekodgadai(Request $request)
|
||||
{
|
||||
$nokp = $request->nokp;
|
||||
$kodcaw = $request->kodcaw;
|
||||
// Dapatkan maklumat cawangan
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', $kodcaw)
|
||||
->first();
|
||||
|
||||
if (!$cawangan || empty($cawangan->mysql)) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Cawangan tidak dijumpai atau konfigurasi DB tidak lengkap',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
// Query rekod gadai dari DB cawangan yang betul
|
||||
$gadai = Gadai::on($cawangan->mysql)
|
||||
->where('nokp', $nokp)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => !$gadai->isEmpty(),
|
||||
'message' => $gadai->isEmpty() ? 'Tiada rekod gadai' : 'Rekod gadai dijumpai',
|
||||
'data' => $gadai
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Ralat semasa ambil data: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function rekodgadaiBatch(Request $request)
|
||||
{
|
||||
$nokpList = $request->input('nokp_list', []);
|
||||
$kodcaw = $request->input('kodcaw');
|
||||
|
||||
if (empty($nokpList) || empty($kodcaw)) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Parameter tidak lengkap',
|
||||
'data' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', $kodcaw)
|
||||
->first();
|
||||
|
||||
if (!$cawangan || empty($cawangan->mysql)) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Cawangan tidak dijumpai',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$gadai = Gadai::on($cawangan->mysql)
|
||||
->whereIn('nokp', $nokpList)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => !$gadai->isEmpty(),
|
||||
'message' => $gadai->isEmpty() ? 'Tiada rekod gadai' : 'Rekod gadai dijumpai',
|
||||
'data' => $gadai
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Ralat semasa ambil data: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function customerUpdate($nokp,Request $request){
|
||||
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
|
||||
$customer_update = Customer::on('mysql7')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->update(array(
|
||||
'nota_arcc'=>$request->nota_arcc,
|
||||
));
|
||||
|
||||
return response()->json($customer_update, 200);
|
||||
}
|
||||
|
||||
|
||||
public function customerUpdateKaunter($nokp,$kodcaw, Request $request){
|
||||
$current = Carbon::now();
|
||||
|
||||
DB::connection('mysql7')->beginTransaction();
|
||||
|
||||
try{
|
||||
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
|
||||
|
||||
$customer_info = DB::connection('mysql7')->table('customer')
|
||||
->select('kodcaw','kodkerja','nota_pekerjaan','nota_arcc','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','poskod')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->get()->toArray();
|
||||
|
||||
|
||||
$old_data = json_encode($customer_info);
|
||||
|
||||
$customer_update = Customer::on('mysql7')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->update(array(
|
||||
'nota_arcc' => $request->nota_arcc,
|
||||
));
|
||||
|
||||
if($customer_update)
|
||||
{
|
||||
$customer_info_new = DB::connection('mysql7')->table('customer')
|
||||
->select('kodcaw','kodkerja','nota_pekerjaan','nota_arcc','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->get()->toArray();
|
||||
|
||||
$new_data = json_encode($customer_info_new);
|
||||
|
||||
$audit_customer = DB::connection('mysql7')
|
||||
->table('audit_customer')
|
||||
->insert([
|
||||
'username' => $request->namateller,
|
||||
'old_data' => $old_data,
|
||||
'new_data' => $new_data,
|
||||
'kodcaw' => $customer_info[0]->kodcaw,
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
'customer_name' => $customer_info[0]->nama,
|
||||
'customer_nokp' => $nokp,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::connection('mysql7')->commit();
|
||||
|
||||
return response()->json($customer_update, 200);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
DB::connection('mysql7')->rollback();
|
||||
return response()->json($e->getMessage(),400);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use App\Blacklist;
|
||||
use App\AuditCustomer;
|
||||
use Illuminate\Http\Request;
|
||||
use App\TuntutBaki;
|
||||
use App\Anggota;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -23,11 +24,27 @@ use DB;
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
||||
public function showAllCustomers(){
|
||||
$customer = Customer::on('mysql7')->get();
|
||||
public function showAllCustomers(Request $request)
|
||||
{
|
||||
$nama = $request->query('nama');
|
||||
$kodcaw = $request->query('kodcaw');
|
||||
|
||||
$query = Customer::on('mysql7');
|
||||
|
||||
if ($nama) {
|
||||
$query->where('nama', 'LIKE', '%' . $nama . '%');
|
||||
}
|
||||
|
||||
if ($kodcaw) {
|
||||
$query->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
$customer = $query->get();
|
||||
|
||||
return response()->json($customer);
|
||||
}
|
||||
|
||||
|
||||
public function getLatestCustomer($kodcaw){
|
||||
$customer = Customer::on('mysql7')->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first();
|
||||
|
||||
@@ -346,6 +363,7 @@ class CustomerController extends Controller
|
||||
'nota'=>$request->nota,
|
||||
'kodkerja'=>$request->kodkerja,
|
||||
'nota_pekerjaan'=>$request->nota_pekerjaan,
|
||||
// 'nota_arcc'=>$request->nota_arcc,
|
||||
'tujuangadai'=>$request->tujuangadai
|
||||
]);
|
||||
|
||||
@@ -374,13 +392,40 @@ class CustomerController extends Controller
|
||||
'kodnegeri' => $poskod['kodnegeri'],
|
||||
'kodkerja'=>$request->kodkerja,
|
||||
'nota_pekerjaan'=>$request->nota_pekerjaan,
|
||||
// 'nota_arcc'=>$request->nota_arcc,
|
||||
'telefon' => $request->telefon1,
|
||||
'telefon2' => $request->telefon2
|
||||
'telefon2' => $request->telefon2,
|
||||
));
|
||||
|
||||
return response()->json($customer_update, 200);
|
||||
}
|
||||
|
||||
public function assignAnggota($noic, Request $request)
|
||||
{
|
||||
// Semak sama ada pelanggan wujud
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', $noic)
|
||||
->orWhere('kplama', $noic)
|
||||
->first();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pelanggan tidak dijumpai.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Kemaskini tag_anggota
|
||||
$customer->tag_anggota = 1;
|
||||
$customer->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tag anggota berjaya dikemaskini.',
|
||||
'data' => $customer
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function customerUpdateKaunter($nokp,$kodcaw, Request $request){
|
||||
$current = Carbon::now();
|
||||
|
||||
@@ -408,6 +453,7 @@ class CustomerController extends Controller
|
||||
'kodkerja' => $request->kodkerja,
|
||||
// 'nota_pekerjaan' => $request->nota_pekerjaan,
|
||||
'nota_pekerjaan' => $request->kodkerja === '6' ? $request->nota_pekerjaan : null,
|
||||
// 'nota_arcc' => $request->nota_arcc,
|
||||
'noakaun' => $request->noakaun,
|
||||
'nota' => $request->nota,
|
||||
'alamat1' => $request->alamat,
|
||||
@@ -485,6 +531,7 @@ class CustomerController extends Controller
|
||||
'kodbank' => $request->kodbank,
|
||||
'kodkerja' => $request->kodkerja,
|
||||
'nota_pekerjaan' => $request->nota_pekerjaan,
|
||||
// 'nota_arcc' => $request->nota_arcc,
|
||||
'noakaun' => $request->noakaun,
|
||||
'nota' => $request->nota,
|
||||
'nama' => $request->nama,
|
||||
@@ -805,6 +852,14 @@ class CustomerController extends Controller
|
||||
return response()->json($blacklist);
|
||||
}
|
||||
|
||||
public function anggotaKoperasi(Request $request){
|
||||
|
||||
$anggota = Anggota::where('noic',$request->noic)->first();
|
||||
|
||||
return response()->json($anggota);
|
||||
}
|
||||
|
||||
|
||||
public function showCustomerByEachCawangan($ic)
|
||||
{
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
@@ -962,4 +1017,41 @@ class CustomerController extends Controller
|
||||
return json_encode(['status'=> 'success']);
|
||||
|
||||
}
|
||||
|
||||
public function searchByName(Request $request)
|
||||
{
|
||||
$nama = $request->query('nama');
|
||||
$kodcaw = $request->query('kodcaw');
|
||||
|
||||
$query = Customer::query();
|
||||
|
||||
if ($kodcaw) {
|
||||
$query->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
if ($nama) {
|
||||
$query->where('nama', 'like', '%' . $nama . '%');
|
||||
}
|
||||
|
||||
$results = $query->get();
|
||||
|
||||
return response()->json($results);
|
||||
}
|
||||
|
||||
// public function createNotaArcc($kodcaw, Request $request)
|
||||
// {
|
||||
// $current = Carbon::now();
|
||||
|
||||
// $customer = Customer::on('mysql7')->create([
|
||||
// 'kodcaw' => $kodcaw,
|
||||
// 'tarikhdaftar' => $current->toDateString(),
|
||||
// 'nota_arcc' => $request->nota_arcc,
|
||||
// 'teller' => $request->teller,
|
||||
// 'aktif' => 'A'
|
||||
// ]);
|
||||
|
||||
// return response()->json($customer, 201);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +120,25 @@ class GadaiController extends Controller
|
||||
return response()->json($gadai_all);
|
||||
}
|
||||
|
||||
public function showOneGadaiByNorujukanKodcaw($kodcaw,$norujukan){
|
||||
|
||||
$cawangan_all = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->get();
|
||||
|
||||
$gadai_all = [];
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
||||
if(sizeof($gadai) != 0){
|
||||
array_push($gadai_all,$gadai);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return response()->json($gadai_all);
|
||||
}
|
||||
|
||||
public function showOneGadaiByCawanganOnly($kodcaw,$tarikh){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
@@ -981,77 +1000,188 @@ class GadaiController extends Controller
|
||||
return response()->json($ansuran);
|
||||
}
|
||||
|
||||
public function getLaporanAnsuranUjrah($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
public function getLaporanAnsuranUjrah($kodcaw, Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
|
||||
$ansuran_data = Transaction::on('mysql7')
|
||||
->select('transaction.norujukan',
|
||||
'trans.tarikh_bayaran',
|
||||
'transaction.nokp',
|
||||
'transaction.kodcaw',
|
||||
'transaction.trans_type',
|
||||
'cust.nama','trans.bayaran_pembiayaan',
|
||||
'transaction.duit_masuk',
|
||||
'trans.bayaran_keuntungan',
|
||||
'transaction.teller',
|
||||
'trans.ujrah',
|
||||
'trans.onepercent')
|
||||
->leftJoin('transaksi_keuntungan as trans', function($join)
|
||||
{
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->leftJoin('customer as cust', function($join)
|
||||
{
|
||||
$join->on('transaction.nokp', '=', 'cust.kpbaru');
|
||||
$join->orOn('transaction.nokp', '=', 'cust.kplama');
|
||||
})
|
||||
->where('transaction.kodcaw','=',$kodcaw)
|
||||
->where('transaction.trans_type','=','A')
|
||||
->whereDate('transaction.created_at', '>=', $request->mula)
|
||||
->whereDate('transaction.created_at', '<=', $request->akhir)
|
||||
->orderBy('transaction.teller')
|
||||
->orderBy('trans.tarikh_bayaran')
|
||||
->get();
|
||||
// Bina query asas dahulu
|
||||
$query = Transaction::on('mysql7')
|
||||
->select(
|
||||
'transaction.norujukan',
|
||||
'trans.tarikh_bayaran',
|
||||
'transaction.nokp',
|
||||
'transaction.kodcaw',
|
||||
'transaction.trans_type',
|
||||
'cust.nama',
|
||||
'trans.bayaran_pembiayaan',
|
||||
'transaction.duit_masuk',
|
||||
'trans.bayaran_keuntungan',
|
||||
'transaction.teller',
|
||||
'trans.ujrah',
|
||||
'trans.onepercent'
|
||||
)
|
||||
->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->leftJoin('customer as cust', function ($join) {
|
||||
$join->on('transaction.nokp', '=', 'cust.kpbaru');
|
||||
$join->orOn('transaction.nokp', '=', 'cust.kplama');
|
||||
})
|
||||
->where('transaction.kodcaw', '=', $kodcaw)
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', $request->mula)
|
||||
->whereDate('transaction.created_at', '<=', $request->akhir);
|
||||
|
||||
$ansuran = [];
|
||||
// Tambah filter berdasarkan jenis
|
||||
if ($request->jenis == 'arrahnpay') {
|
||||
$query->where('transaction.teller', '=', 'Online');
|
||||
} elseif ($request->jenis == 'kaunter') {
|
||||
$query->where('transaction.teller', '!=', 'Online');
|
||||
}
|
||||
|
||||
if($ansuran_data){
|
||||
foreach($ansuran_data as $index=>$ansuranData){
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan',$ansuranData['norujukan'])->first();
|
||||
// Dapatkan data selepas filter
|
||||
$ansuran_data = $query
|
||||
->orderBy('transaction.teller')
|
||||
->orderBy('trans.tarikh_bayaran')
|
||||
->get();
|
||||
|
||||
array_push($ansuran,[
|
||||
"norujukan" => $ansuranData['norujukan'],
|
||||
"tarikh_bayaran" => $ansuranData['tarikh_bayaran'],
|
||||
"nokp" => $ansuranData['nokp'],
|
||||
"kodcaw" => $ansuranData['kodcaw'],
|
||||
"trans_type" => $ansuranData['trans_type'],
|
||||
"nama" => $ansuranData['nama'],
|
||||
"tempoh" => $gadai['tempoh'],
|
||||
"bakipjm" => $gadai['bakipjm'],
|
||||
"bayaran_pembiayaan" => $ansuranData['bayaran_pembiayaan'],
|
||||
"duit_masuk" => $ansuranData['duit_masuk'],
|
||||
"bayaran_keuntungan" => $ansuranData['bayaran_keuntungan'],
|
||||
"teller" => $ansuranData['teller'],
|
||||
"ansuranujrah" => $ansuranData['ujrah'],
|
||||
"ansuranonepercent" => $ansuranData['onepercent'],
|
||||
"t_gadai" => $gadai['t_gadai'],
|
||||
]);
|
||||
}
|
||||
$ansuran = [];
|
||||
|
||||
// Loop data dan tambahkan maklumat dari jadual gadai
|
||||
if ($ansuran_data) {
|
||||
foreach ($ansuran_data as $index => $ansuranData) {
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan', $ansuranData['norujukan'])->first();
|
||||
|
||||
array_push($ansuran, [
|
||||
"norujukan" => $ansuranData['norujukan'],
|
||||
"tarikh_bayaran" => $ansuranData['tarikh_bayaran'],
|
||||
"nokp" => $ansuranData['nokp'],
|
||||
"kodcaw" => $ansuranData['kodcaw'],
|
||||
"trans_type" => $ansuranData['trans_type'],
|
||||
"nama" => $ansuranData['nama'],
|
||||
"tempoh" => optional($gadai)->tempoh,
|
||||
"bakipjm" => optional($gadai)->bakipjm,
|
||||
"bayaran_pembiayaan" => $ansuranData['bayaran_pembiayaan'],
|
||||
"duit_masuk" => $ansuranData['duit_masuk'],
|
||||
"bayaran_keuntungan" => $ansuranData['bayaran_keuntungan'],
|
||||
"teller" => $ansuranData['teller'],
|
||||
"ansuranujrah" => $ansuranData['ujrah'],
|
||||
"ansuranonepercent" => $ansuranData['onepercent'],
|
||||
"t_gadai" => optional($gadai)->t_gadai,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Susun ikut teller dan tarikh bayar
|
||||
usort($ansuran, function ($a, $b) {
|
||||
$compare_teller = strcmp($a['teller'], $b['teller']);
|
||||
|
||||
if ($compare_teller === 0) {
|
||||
return strcmp($a['tarikh_bayaran'], $b['tarikh_bayaran']);
|
||||
}
|
||||
|
||||
usort($ansuran, function ($a, $b) {
|
||||
$compare_teller = strcmp($a['teller'], $b['teller']);
|
||||
return $compare_teller;
|
||||
});
|
||||
|
||||
if ($compare_teller === 0) {
|
||||
return strcmp($a['tarikh_bayaran'], $b['tarikh_bayaran']);
|
||||
}
|
||||
return response()->json($ansuran);
|
||||
}
|
||||
|
||||
return $compare_teller;
|
||||
});
|
||||
|
||||
return response()->json($ansuran);
|
||||
}
|
||||
// public function getLaporanAnsuranUjrah($kodcaw, Request $request)
|
||||
// {
|
||||
// $cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
// $semuaDescpt = Transaction::on('mysql7')
|
||||
// ->where('kodcaw', '=', $kodcaw)
|
||||
// ->pluck('descpt');
|
||||
|
||||
// dd($semuaDescpt);
|
||||
|
||||
// Dapatkan connection cawangan
|
||||
// $connection = $cawangan['mysql'];
|
||||
|
||||
// // Mula query utama ansuran
|
||||
// $query = Transaction::on('mysql7')
|
||||
// ->select(
|
||||
// 'transaction.norujukan',
|
||||
// 'trans.tarikh_bayaran',
|
||||
// 'transaction.nokp',
|
||||
// 'transaction.kodcaw',
|
||||
// 'transaction.trans_type',
|
||||
// 'cust.nama',
|
||||
// 'trans.bayaran_pembiayaan',
|
||||
// 'transaction.duit_masuk',
|
||||
// 'trans.bayaran_keuntungan',
|
||||
// 'transaction.teller',
|
||||
// 'trans.ujrah',
|
||||
// 'trans.onepercent'
|
||||
// )
|
||||
// ->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
// $join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
// $join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
// })
|
||||
// ->leftJoin('customer as cust', function ($join) {
|
||||
// $join->on('transaction.nokp', '=', 'cust.kpbaru');
|
||||
// $join->orOn('transaction.nokp', '=', 'cust.kplama');
|
||||
// })
|
||||
// ->where('transaction.kodcaw', '=', $kodcaw)
|
||||
// ->where('transaction.trans_type', '=', 'A')
|
||||
// ->whereDate('transaction.created_at', '>=', $request->mula)
|
||||
// ->whereDate('transaction.created_at', '<=', $request->akhir);
|
||||
|
||||
|
||||
// // 💡 Tambah filter ikut jenis
|
||||
// if ($request->jenis == 'online') {
|
||||
// $query->where('transaction.descpt', 'LIKE', 'Laporan Ansuran Pembiayaan (Arrahn Pay)%');
|
||||
// } elseif ($request->jenis == 'kaunter') {
|
||||
// $query->where('transaction.descpt', 'LIKE', 'Laporan Ansuran Pembiayaan (Kaunter aros)%');
|
||||
// } else {
|
||||
// $query->where('transaction.descpt', 'LIKE', 'Laporan Ansuran Pembiayaan%');
|
||||
// }
|
||||
|
||||
// // Order by
|
||||
// $query->orderBy('transaction.teller')->orderBy('trans.tarikh_bayaran');
|
||||
|
||||
// // Dapatkan data
|
||||
// $ansuran_data = $query->get();
|
||||
|
||||
// // Proses data
|
||||
// $ansuran = [];
|
||||
// if ($ansuran_data) {
|
||||
// foreach ($ansuran_data as $index => $ansuranData) {
|
||||
// $gadai = Gadai::on($connection)->where('norujukan', $ansuranData['norujukan'])->first();
|
||||
|
||||
// array_push($ansuran, [
|
||||
// "norujukan" => $ansuranData['norujukan'],
|
||||
// "tarikh_bayaran" => $ansuranData['tarikh_bayaran'],
|
||||
// "nokp" => $ansuranData['nokp'],
|
||||
// "kodcaw" => $ansuranData['kodcaw'],
|
||||
// "trans_type" => $ansuranData['trans_type'],
|
||||
// "nama" => $ansuranData['nama'],
|
||||
// "tempoh" => $gadai['tempoh'] ?? null,
|
||||
// "bakipjm" => $gadai['bakipjm'] ?? null,
|
||||
// "bayaran_pembiayaan" => $ansuranData['bayaran_pembiayaan'],
|
||||
// "duit_masuk" => $ansuranData['duit_masuk'],
|
||||
// "bayaran_keuntungan" => $ansuranData['bayaran_keuntungan'],
|
||||
// "teller" => $ansuranData['teller'],
|
||||
// "ansuranujrah" => $ansuranData['ujrah'],
|
||||
// "ansuranonepercent" => $ansuranData['onepercent'],
|
||||
// "t_gadai" => $gadai['t_gadai'] ?? null,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Susun data
|
||||
// usort($ansuran, function ($a, $b) {
|
||||
// $compare_teller = strcmp($a['teller'], $b['teller']);
|
||||
// return $compare_teller === 0
|
||||
// ? strcmp($a['tarikh_bayaran'], $b['tarikh_bayaran'])
|
||||
// : $compare_teller;
|
||||
// });
|
||||
|
||||
// return response()->json($ansuran);
|
||||
// }
|
||||
|
||||
public function getAnsuranSummary($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
@@ -3802,4 +3932,11 @@ class GadaiController extends Controller
|
||||
|
||||
return response()->json($view);
|
||||
}
|
||||
|
||||
public function getApprovalFromOperation(Request $request){
|
||||
$ansuranserv = new AnsServ($request->kodcaw);
|
||||
$view = $ansuranserv->getApprovalFromOperation($request);
|
||||
|
||||
return response()->json($view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@ use App\Audit;
|
||||
use App\Mohon;
|
||||
use App\Cawangan;
|
||||
use App\Mohonid;
|
||||
use App\MohonAnggota;
|
||||
use App\Customer;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class KelulusanController extends Controller
|
||||
{
|
||||
@@ -201,6 +204,98 @@ class KelulusanController extends Controller
|
||||
return response()->json($kelulusan,201);
|
||||
}
|
||||
|
||||
public function updateAnggota($kodcaw, Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
|
||||
// Dapatkan sambungan database cawangan
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['success' => false, 'message' => 'Kod cawangan tidak sah'], 404);
|
||||
}
|
||||
|
||||
$nokp = $request->nokp;
|
||||
$komen = $request->komenkelulusan;
|
||||
$namaoperasi = $request->namaoperasi;
|
||||
$status = $request->sahkan; // 1 = Lulus, 2 = Batal
|
||||
|
||||
// Debug log masuk
|
||||
Log::info('UpdateKelulusanAnggota triggered', [
|
||||
'kodcaw' => $kodcaw,
|
||||
'nokp' => $nokp,
|
||||
'status' => $status,
|
||||
'komen' => $komen,
|
||||
'namaoperasi' => $namaoperasi
|
||||
]);
|
||||
|
||||
// Kalau LULUS
|
||||
if ($status == 1) {
|
||||
$kelulusan = MohonAnggota::on($cawangan['mysql'])
|
||||
->where('nokp', '=', $nokp)
|
||||
->update([
|
||||
'status' => 'DILULUSKAN',
|
||||
'komen' => $komen,
|
||||
'peloperasi' => $namaoperasi,
|
||||
'datetime_pelulus' => $harini,
|
||||
'updated_at' => $harini,
|
||||
]);
|
||||
|
||||
// Update CUSTOMER di pusat (mysql7)
|
||||
Customer::on('mysql7')
|
||||
->where('kpbaru', '=', $nokp)
|
||||
->update([
|
||||
'tag_anggota' => 1,
|
||||
]);
|
||||
}
|
||||
// Kalau BATAL / TOLAK
|
||||
else if ($status == 2) {
|
||||
$kelulusan = MohonAnggota::on($cawangan['mysql'])
|
||||
->where('nokp', '=', $nokp)
|
||||
->update([
|
||||
'status' => 'DITOLAK',
|
||||
'komen' => $komen,
|
||||
'peloperasi' => $namaoperasi,
|
||||
'datetime_pelulus' => $harini,
|
||||
'updated_at' => $harini,
|
||||
]);
|
||||
} else {
|
||||
return response()->json(['success' => false, 'message' => 'Status tidak sah'], 400);
|
||||
}
|
||||
|
||||
// 🧾 Simpan audit log
|
||||
$audit = new Audit();
|
||||
$audit->users = $namaoperasi;
|
||||
$audit->actions = ($status == 1)
|
||||
? "Kelulusan anggota oleh operasi (tag_anggota=1)"
|
||||
: "Pembatalan / tolak anggota oleh operasi";
|
||||
$audit->new_data = json_encode([
|
||||
'nokp' => $nokp,
|
||||
'status' => $status,
|
||||
'komen' => $komen,
|
||||
]);
|
||||
$audit->kodcaw = $kodcaw;
|
||||
$audit->created_at = $harini;
|
||||
$audit->updated_at = $harini;
|
||||
$audit->save();
|
||||
|
||||
Log::info('Kelulusan anggota dikemas kini', [
|
||||
'nokp' => $nokp,
|
||||
'status' => $status,
|
||||
'updated_tag_anggota' => ($status == 1) ? 1 : 0
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => ($status == 1) ? 'DILULUSKAN' : 'DITOLAK',
|
||||
'updated_rows' => $kelulusan
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updatekomen($kodcaw,$norujukan,Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
@@ -284,6 +379,64 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
return response()->json($kelulusan);
|
||||
}
|
||||
|
||||
public function createKelulusanAnggota(Request $request, $kodcaw)
|
||||
{
|
||||
try {
|
||||
$harini = Carbon::now();
|
||||
|
||||
// ✅ Dapatkan maklumat cawangan (database connection)
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['success' => false, 'message' => 'Cawangan tidak dijumpai'], 404);
|
||||
}
|
||||
|
||||
// ✅ Simpan ke dalam model MohonAnggota
|
||||
$kelulusan = new MohonAnggota();
|
||||
$kelulusan->setConnection($cawangan['mysql']); // guna connection cawangan dinamik
|
||||
$kelulusan->tarikh = $harini->toDateString();
|
||||
$kelulusan->nokp = $request->nokp;
|
||||
$kelulusan->nama = $request->nama ?? null;
|
||||
$kelulusan->status = 'MENUNGGU OPERASI';
|
||||
$kelulusan->komen = $request->komen;
|
||||
$kelulusan->teller = $request->teller;
|
||||
$kelulusan->peloperasi = null;
|
||||
$kelulusan->created_at = $harini;
|
||||
$kelulusan->updated_at = $harini;
|
||||
$kelulusan->save();
|
||||
|
||||
// ✅ Simpan audit trail
|
||||
$audit = new Audit();
|
||||
$audit->users = $request->teller;
|
||||
$audit->actions = 'Mohon kelulusan anggota';
|
||||
$audit->new_data = json_encode(['mohon_anggota_id' => $kelulusan->id]);
|
||||
$audit->kodcaw = $kodcaw;
|
||||
$audit->created_at = $harini;
|
||||
$audit->updated_at = $harini;
|
||||
$audit->save();
|
||||
|
||||
// ✅ Return JSON response ke frontend
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Permohonan kelulusan anggota berjaya dihantar kepada operasi.',
|
||||
'data' => [
|
||||
'id' => $kelulusan->id,
|
||||
'nokp' => $kelulusan->nokp,
|
||||
'status' => $kelulusan->status,
|
||||
'komen' => $kelulusan->komen,
|
||||
'teller' => $kelulusan->teller,
|
||||
],
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('❌ createKelulusanAnggota error: ' . $th->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
//KEPOHONAN EDIT DAN HAPUS
|
||||
|
||||
public function kepohonancreate(REQUEST $request,$kodcaw,$norujukan)
|
||||
@@ -298,13 +451,16 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
'tarikh'=> $harini->toDateString(),
|
||||
'mohon' => $request->mohon,
|
||||
'norujukan' => $norujukan,
|
||||
'katalaluan' => '',
|
||||
'katalaluan' => $request->komen,
|
||||
'pinjaman' => $request->pinjaman,
|
||||
'nilaimarhun' => $request->nilaimarhun,
|
||||
'berat' => $request->berat,
|
||||
'margin' => $request->margin,
|
||||
'benar' => '0',
|
||||
'teller' => $request->teller
|
||||
'teller' => $request->teller,
|
||||
'tagoperasi'=> ($request->tagoperasi) ? true : false,
|
||||
'masa' => $harini->toTimeString(),
|
||||
'ansuran' => ($request->ansuran) ? $request->ansuran : 0.00,
|
||||
]);
|
||||
|
||||
return response()->json($mohonid,201);
|
||||
@@ -322,18 +478,24 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$norujukan)
|
||||
->where('recno','=',$request->recno)
|
||||
->update(array(
|
||||
'katalaluan' => $request->komen,
|
||||
'benar' => '2',
|
||||
'id' => $request->khazanah
|
||||
'id' => $request->khazanah,
|
||||
'timestamp_approved_by_pc' => $harini,
|
||||
));
|
||||
}else{
|
||||
$benar = ($request->tagoperasi == 1) ? 0 : 1;
|
||||
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$norujukan)
|
||||
->where('recno','=',$request->recno)
|
||||
->update(array(
|
||||
'benar' => '1',
|
||||
'id' => $request->khazanah
|
||||
'benar' => $benar,
|
||||
'id' => $request->khazanah,
|
||||
'timestamp_approved_by_pc' => $harini,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -381,16 +543,30 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
$arraykelulusan = [];
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$kelulusan=Mohon::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('masalulus','=','')
|
||||
->where('pelulus','=','operasi')
|
||||
->get();
|
||||
$kelulusan = Mohon::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('masalulus','=','')
|
||||
->where('pelulus','=','operasi')
|
||||
->get();
|
||||
|
||||
if(sizeof($kelulusan) != 0){
|
||||
array_push($arraykelulusan,["kelulusanall" => $kelulusan,"cawangan" => $cawangan['details_caw'],"cawangankod" => $cawangan['kodcaw']]);
|
||||
$mohonid_data = Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->whereNotNull('id')
|
||||
->whereNotNull('timestamp_approved_by_pc')
|
||||
->where('tagoperasi', '1')
|
||||
->whereNull('operasi')
|
||||
->get();
|
||||
|
||||
// Check if EITHER has data (not just $kelulusan)
|
||||
if(sizeof($kelulusan) != 0 || sizeof($mohonid_data) != 0){
|
||||
array_push($arraykelulusan,[
|
||||
"kelulusanall" => $kelulusan,
|
||||
"kelulusanMohonid" => $mohonid_data,
|
||||
"cawangan" => $cawangan['details_caw'],
|
||||
"cawangankod" => $cawangan['kodcaw']
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($arraykelulusan,200);
|
||||
}
|
||||
@@ -417,4 +593,124 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
return response()->json($arraykelulusan,200);
|
||||
}
|
||||
|
||||
public function UpdateHapusAnsuranOperasi(Request $request){
|
||||
$harini = Carbon::now();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
if($request->sahkan === 1){
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->where('recno','=',$request->siri)
|
||||
->where('tagoperasi', '=', 1)
|
||||
->update(array(
|
||||
'operasi' => $request->namaoperasi,
|
||||
'timestamp_approved_by_operasi' => $harini,
|
||||
'benar' => 1,
|
||||
));
|
||||
}else if($request->sahkan === 2){
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->where('recno','=',$request->siri)
|
||||
->where('tagoperasi', '=', 1)
|
||||
->update(array(
|
||||
'operasi' => $request->namaoperasi,
|
||||
'timestamp_approved_by_operasi' => $harini,
|
||||
'benar' => 2,
|
||||
));
|
||||
}
|
||||
|
||||
return response()->json($kelulusan,202);
|
||||
|
||||
}
|
||||
|
||||
public function getApproval(Request $request){
|
||||
$harini = Carbon::now();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('teller','=',$request->teller)
|
||||
->where('mohon','=',$request->mohon)
|
||||
->where('benar','=',0)
|
||||
->latest('masa')
|
||||
->first();
|
||||
|
||||
return response()->json($kelulusan, 200);
|
||||
}
|
||||
|
||||
public function getApprovalList(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->groupBy('mohon')
|
||||
->pluck('mohon');
|
||||
|
||||
return response()->json($kelulusan, 200);
|
||||
}
|
||||
|
||||
public function getApprovalLaporan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->selectRaw('recno, benar, tarikh, onlineid, mohon, norujukan, id, katalaluan, benar, operasi, pinjaman, ansuran, nilaimarhun, berat, margin, teller ,masa, timestamp_approved_by_pc, timestamp_approved_by_operasi')
|
||||
->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir])
|
||||
->where('mohon', $request->mohon)
|
||||
->orderBy('tarikh', 'desc')
|
||||
->orderBy('masa', 'desc')
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json($kelulusan, 200);
|
||||
}
|
||||
|
||||
public function listKelulusanAnggota(Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
Log::info($request->all());
|
||||
$cawangan = Cawangan::on('mysql7')->get();
|
||||
|
||||
$array_kelulusan = [];
|
||||
|
||||
foreach ($cawangan as $caw) {
|
||||
|
||||
$kelulusan = MohonAnggota::on($caw['mysql'])
|
||||
->whereDate('tarikh', $harini->toDateString())
|
||||
->where(function ($query) {
|
||||
$query->where('peloperasi', '=', 0)
|
||||
->orWhereNull('peloperasi');
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
if ($kelulusan->isNotEmpty()) {
|
||||
|
||||
// Kumpul semua nokp daripada senarai kelulusan
|
||||
$nokpList = $kelulusan->pluck('nokp')->unique()->toArray();
|
||||
|
||||
// Ambil semua nama daripada table customer (main DB)
|
||||
$customers = Customer::whereIn('kpbaru', $nokpList)
|
||||
->pluck('nama', 'kpbaru')
|
||||
->toArray();
|
||||
|
||||
// Masukkan nama ke dalam setiap item kelulusan
|
||||
$kelulusan = $kelulusan->map(function ($item) use ($customers) {
|
||||
$item->nama = $customers[$item->nokp] ?? '-';
|
||||
return $item;
|
||||
});
|
||||
|
||||
// Tambah ke array utama
|
||||
$array_kelulusan[] = [
|
||||
"kelulusanall" => $kelulusan,
|
||||
"cawangan" => $caw['details_caw'],
|
||||
"cawangankod" => $caw['kodcaw']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($array_kelulusan, 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ use Carbon\Carbon;
|
||||
use App\imbangdugalama;
|
||||
use App\Services\Reports\ImbangDugaService;
|
||||
use App\Services\Reports\Account\GeneralLedger;
|
||||
use App\Mohonid;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -845,7 +846,8 @@ $date = new Carbon($request->tarikh);
|
||||
$bilangan_gadai = $gadai->count();
|
||||
$bilangan_tebus = $tebus->count();
|
||||
// $bilangan_ansuran = $ansuran->count();
|
||||
$bilangan_customer_baru = Customer::on($cawangan['mysql'])->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
|
||||
//$bilangan_customer_baru = Customer::on($cawangan['mysql'])->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
|
||||
$bilangan_customer_baru = Customer::on('mysql7')->whereBetween('tarikhdaftar', [$request->mula, $request->akhir])->where('kodcaw', $request->kodcaw)->count();
|
||||
|
||||
//f
|
||||
$data_lelong = Lelong::on($cawangan['mysql'])->where([['t_jual','>=',$request->mula],['t_jual','<=',$request->akhir]])->get();
|
||||
@@ -1698,4 +1700,47 @@ $date = new Carbon($request->tarikh);
|
||||
|
||||
return response()->json($array_imbangduga,200);
|
||||
}
|
||||
|
||||
public function getLaporanKelulusan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
$laporan_kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->whereBetween('tarikh', [$request->mula, $request->akhir])
|
||||
->when($request->mohon, function($query, $mohon) {
|
||||
return $query->where('mohon', $mohon);
|
||||
})
|
||||
->get();
|
||||
|
||||
if($laporan_kelulusan->isEmpty()){
|
||||
return response()->json(['message' => 'No data found'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Laporan kelulusan retrieved successfully',
|
||||
'data' => $laporan_kelulusan,
|
||||
'count' => $laporan_kelulusan->count(),
|
||||
'timestamp' => Carbon::now()->toISOString()
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getListofKelulusan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
$laporan_kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->groupBy('mohon')
|
||||
->pluck('mohon');
|
||||
|
||||
if($laporan_kelulusan->isEmpty()){
|
||||
return response()->json(['message' => 'No data found'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'List of Type Kelulusan retrieved successfully',
|
||||
'data' => $laporan_kelulusan,
|
||||
'count' => $laporan_kelulusan->count(),
|
||||
'timestamp' => Carbon::now()->toISOString()
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ use App\Services\RingkasanHarianServices;
|
||||
use App\Services\OnePercentServices;
|
||||
use App\Services\MasterServices;
|
||||
use App\Support\v2\Calculation;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
|
||||
use Log;
|
||||
use DB;
|
||||
@@ -223,16 +225,12 @@ class LelongController extends Controller
|
||||
|
||||
$rugitotal=$rugilelong + $ansrugi;
|
||||
|
||||
if($kodcaw == 'APM')
|
||||
// $bakilelong += 4498.1;
|
||||
$bakilelong += 1228.07;
|
||||
|
||||
if($kodcaw == '010617')
|
||||
$rugitotal -= 6.1;
|
||||
|
||||
if($kodcaw == '011229'){
|
||||
$rugitotal -= 919.7;
|
||||
$bakilelong -= 144;
|
||||
}
|
||||
|
||||
if($kodcaw == '011412')
|
||||
@@ -240,31 +238,13 @@ class LelongController extends Controller
|
||||
|
||||
if($kodcaw == '020303')
|
||||
{
|
||||
$bakilelong -= 542.6;
|
||||
$rugitotal += 0.01;
|
||||
}
|
||||
|
||||
if($kodcaw === '011232')
|
||||
{
|
||||
$bakilelong += 6;
|
||||
}
|
||||
|
||||
if($kodcaw === 'ARP'){
|
||||
$rugitotal += 119;
|
||||
}
|
||||
|
||||
if($kodcaw == '020301'){
|
||||
$bakilelong -= 719.50;
|
||||
}
|
||||
|
||||
if($kodcaw == '011227'){
|
||||
$bakilelong -= 896.65;
|
||||
}
|
||||
|
||||
if($kodcaw == 'GC'){
|
||||
$bakilelong += 2135.75;
|
||||
$bakilelong -= 3; //added 15/10/2024 sebab ada kemusykilan 3 ringgit daripada rugi lelong
|
||||
}
|
||||
|
||||
$arraylelong = ['bakilelong' => $bakilelong, 'rugilelong' => $rugitotal];
|
||||
|
||||
@@ -625,9 +605,9 @@ class LelongController extends Controller
|
||||
|
||||
if($cawangan['tagarrahnbid'] == 1){
|
||||
if(env('APP_ENV') != 'production'){
|
||||
$link = 'http://niklah.arrahn.com.my/api/portalApi';
|
||||
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
|
||||
}else{
|
||||
$link = 'http://adminbid.arrahn/api/portalApi';
|
||||
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
|
||||
}
|
||||
|
||||
$lelong = Http::withOptions(['verify' => true])->get($link,[
|
||||
@@ -1772,5 +1752,147 @@ class LelongController extends Controller
|
||||
return response()->json($tuntutbaki,200);
|
||||
}
|
||||
|
||||
public function LaporanLelong(Request $request)
|
||||
{
|
||||
// Validate required input
|
||||
$validator = Validator::make($request->all(), [
|
||||
'kodcaw' => 'required|string',
|
||||
'tarikhmula' => 'required|date',
|
||||
'tarikhhingga' => 'required|date|after_or_equal:tarikhmula',
|
||||
'batchno' => 'nullable|string'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => $validator->errors()], 400);
|
||||
}
|
||||
|
||||
|
||||
// Get cawangan details
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['error' => 'Invalid kodcaw'], 403);
|
||||
}
|
||||
|
||||
// Query lelong data
|
||||
$lelong_query = Lelong::on($cawangan['mysql'])
|
||||
->leftJoin('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->join('lelmarhun', 'lelmarhun.norujukan', '=', 'lelong.norujukan')
|
||||
->join('pembeli', 'pembeli.nopembeli', '=', 'lelong.nopembeli')
|
||||
->whereBetween('lelong.t_lelong', [$request->tarikhmula, $request->tarikhhingga]);
|
||||
|
||||
// Optional: Filter by batch number
|
||||
if ($request->has('batchno') && !empty($request->batchno)) {
|
||||
$lelong_query->where('lelong.batchno', $request->batchno);
|
||||
}
|
||||
// Select required fields
|
||||
$lelong_data = $lelong_query->select(
|
||||
'lelong.batchno', 'lelong.t_lelong', 'gadai.t_gadai', 'gadai.nokp', 'lelong.pinjaman',
|
||||
'lelong.baki', 'lelong.norujukan', 'gadai.marhun', 'lelong.nilaimarhun',
|
||||
'lelong.bakiupah', 'lelong.cajlelong', 'lelong.hargajual', 'lelong.hargaasas',
|
||||
'pembeli.nama', 'pembeli.nokp AS nokppembeli', 'lelong.tagujrah', 'lelong.ujrah',
|
||||
'lelong.onepercent', 'lelong.teller'
|
||||
)
|
||||
->distinct()
|
||||
->orderByRaw("
|
||||
SUBSTRING_INDEX(SUBSTRING_INDEX(lelong.norujukan, '-', 1), '^[A-Za-z]+', -1),
|
||||
CAST(SUBSTRING_INDEX(lelong.norujukan, '-', -1) AS UNSIGNED)
|
||||
")
|
||||
->get();
|
||||
// dd($lelong_data);
|
||||
|
||||
// If no data found, return a message
|
||||
if ($lelong_data->isEmpty()) {
|
||||
return response()->json([
|
||||
'message' => 'Tiada lelongan dalam tarikh dipilih.',
|
||||
'data' => [],
|
||||
'totals' => [
|
||||
'total_pinjaman' => 0,
|
||||
'total_nilaimarhun' => 0,
|
||||
'total_keuntungan' => 0,
|
||||
'total_onepercent' => 0,
|
||||
'total_ujrah' => 0,
|
||||
'total_cajlelong' => 0,
|
||||
'total_hargajual' => 0,
|
||||
'total_baki' => 0,
|
||||
'total_hargaasas' => 0
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Calculate totals safely (prevent null values)
|
||||
$totals = [
|
||||
'total_pinjaman' => $lelong_data->sum(fn($item) => $item->pinjaman ?? 0),
|
||||
'total_nilaimarhun' => $lelong_data->sum(fn($item) => $item->nilaimarhun ?? 0),
|
||||
'total_keuntungan' => $lelong_data->sum(fn($item) => $item->bakiupah ?? 0),
|
||||
'total_onepercent' => $lelong_data->sum(fn($item) => $item->onepercent ?? 0),
|
||||
'total_ujrah' => $lelong_data->sum(fn($item) => $item->ujrah ?? 0),
|
||||
'total_cajlelong' => $lelong_data->sum(fn($item) => $item->cajlelong ?? 0),
|
||||
'total_hargajual' => $lelong_data->sum(fn($item) => $item->hargajual ?? 0),
|
||||
'total_baki' => $lelong_data->sum(fn($item) => $item->baki ?? 0),
|
||||
'total_hargaasas' => $lelong_data->sum(fn($item) => $item->hargaasas ?? 0)
|
||||
];
|
||||
|
||||
$tarikh_lelongs = $lelong_data->pluck('t_lelong')->first(); // Get first date
|
||||
|
||||
// Return JSON response
|
||||
return response()->json([
|
||||
'data' => $lelong_data,
|
||||
'totals' => $totals,
|
||||
'tarikh_lelong' => $tarikh_lelongs
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function LookupBatchLel($kodcaw,Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
$harini = new Carbon;
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
$batchlel = BatchLel::on($cawangan['mysql'])
|
||||
->select('batchno','tarikh')
|
||||
->when($kodcaw, function ($query, $kodcaw) {
|
||||
return $query->where('kodcaw', $kodcaw);
|
||||
})
|
||||
->orderBy('tarikh', 'DESC')
|
||||
->get();
|
||||
|
||||
return response()->json($batchlel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function showBelumTuntutBakiRangeDate($kodcaw,Request $request){
|
||||
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
$belumtuntutbaki = Lelong::on($cawangan['mysql'])
|
||||
->select('lelong.t_jual','lelong.norujukan','lelong.baki','gadai.nokp','gadai.pinjaman','lelong.bakiupah','lelong.cajlelong','lelong.hargajual','lelong.hargaasas','lelong.nilaimarhun')
|
||||
->leftJoin('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->where('t_jual','>=',$request->mula)
|
||||
->where('t_jual','<=',$request->akhir)
|
||||
->where('baki','>',0)
|
||||
->whereNull('trkhtuntut');
|
||||
|
||||
$belumtuntut = $belumtuntutbaki->get();
|
||||
|
||||
$arrayblm = [];
|
||||
foreach($belumtuntut as $index=>$blm)
|
||||
{
|
||||
$customer = Customer::on('mysql7')
|
||||
->select('nama','telefon','telefon2','alamat1','alamat2','poskod','koddaerah')
|
||||
->where('kpbaru','=',$blm['nokp'])
|
||||
->orWhere('kplama','=',$blm['nokp'])
|
||||
->first();
|
||||
array_push($arrayblm,['nama'=>$customer['nama'],'nokp'=>$blm['nokp'],'norujukan'=>$blm['norujukan'],'t_jual'=>$blm['t_jual'],'hargajual'=>$blm['hargajual'],'pinjaman'=>$blm['pinjaman'],'bakiupah'=>$blm['bakiupah'],'cajlelong'=>$blm['cajlelong'],'baki'=>$blm['baki'],'hargaasas'=>$blm['hargaasas'],'nilaimarhun'=>$blm['nilaimarhun']]);
|
||||
|
||||
}
|
||||
|
||||
return response()->json($arrayblm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,16 +94,19 @@ class PendahuluanSerahanController extends Controller
|
||||
->where('pendahuluan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}else if($request->jenis == 'serahan'){
|
||||
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
->where('descpt','NOT LIKE','SERAHAN BAYAR ONLINE%')
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}else{
|
||||
}else if($request->jenis == 'serahan'){
|
||||
$gldetail = GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->whereBetween('tarikh', [$request->mula, $request->hingga])
|
||||
->where(function ($query) {
|
||||
$query->where('descpt', 'NOT LIKE', 'SERAHAN BAYAR ONLINE%')
|
||||
->where('descpt', 'NOT LIKE', 'SERAHAN LELONG%'); // Using AND instead of OR
|
||||
})
|
||||
->where('serahan', '>', 0)
|
||||
->orderBy('tarikh', 'desc')
|
||||
->get();
|
||||
|
||||
}else if($request->jenis == 'online'){
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
@@ -111,7 +114,43 @@ class PendahuluanSerahanController extends Controller
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}
|
||||
}else if($request->jenis == 'serahanlelong'){
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
->where('descpt','LIKE','SERAHAN LELONG%')
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}else if($request->jenis == 'serahankepadav3'){
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
->where('descpt','LIKE','Serahan Kepada V3%')
|
||||
->where('teller','LIKE','%AUTO%')
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
|
||||
}else if($request->jenis == 'serahanonline'){
|
||||
$gldetail = GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->whereBetween('tarikh', [$request->mula, $request->hingga])
|
||||
->where(function ($query) {
|
||||
$query->where('descpt', 'LIKE', 'SERAHAN%')
|
||||
->orWhere('descpt', 'LIKE', 'Serahan%')
|
||||
->orWhere('descpt', 'LIKE', 'serahan%'); // Add more variations if needed
|
||||
})
|
||||
->where('serahan', '>', 0)
|
||||
->orderBy('tarikh', 'desc')
|
||||
->get();
|
||||
}else{
|
||||
$gldetail = GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->whereBetween('tarikh', [$request->mula, $request->hingga])
|
||||
->orderBy('tarikh', 'desc')
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
return response()->json($gldetail,200);
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Reports\AgingService as ReportAgingService;
|
||||
use App\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use App\StokAudit1;
|
||||
use App\StokAudit2;
|
||||
use App\StokAudit3;
|
||||
use App\StokAudit4;
|
||||
use App\StokAudit5;
|
||||
use App\StokAudit6;
|
||||
use App\StokAudit7;
|
||||
use App\StokAudit8;
|
||||
use App\StokAudit9;
|
||||
use App\StokAudit10;
|
||||
use App\StokAudit11;
|
||||
use App\StokAudit12;
|
||||
|
||||
class AgingController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportAgingService = new ReportAgingService($kod_cawangan, $request);
|
||||
return $reportAgingService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAgingbackup(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw', 'mysql')->get();
|
||||
|
||||
$kodcaw_array = array_column($cawangan_available->toArray(), 'kodcaw');
|
||||
$kod_caw_with_cawangan_detail_array = $cawangan_available->pluck('details_caw', 'kodcaw')->toArray();
|
||||
|
||||
// Step 1: Fetch the ansuran data grouped by cawangan
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
transaction.kodcaw as kod_cawangan,
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran,
|
||||
GROUP_CONCAT(transaction.norujukan) as norujukan_list
|
||||
')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
|
||||
$total_nilai_marhun_by_cawangan = [];
|
||||
|
||||
// Step 2: Loop through ansuran_query and fetch nilai_marhun per kodcaw
|
||||
foreach ($ansuran_query as $ansuran_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$norujukan_list = explode(',', $ansuran_cawangan->norujukan_list); // Convert to array
|
||||
|
||||
// Get database connection for this branch
|
||||
$mysql_connection = $cawangan_available->where('kodcaw', $kodcaw)->first()->mysql ?? null;
|
||||
if (!$mysql_connection) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sum nilai_marhun for matching norujukan in gadai table
|
||||
$total_nilai_marhun_by_cawangan[$kodcaw] = Gadai::on($mysql_connection)
|
||||
->whereIn('norujukan', $norujukan_list)
|
||||
->sum('nilaimarhun');
|
||||
}
|
||||
|
||||
// Step 3: Merge ansuran summary with total_nilai_marhun
|
||||
$summary_ansuran_by_cawangan = $ansuran_query
|
||||
->filter(function ($ansuran_cawangan) use ($kodcaw_array) {
|
||||
return in_array($ansuran_cawangan['kod_cawangan'], $kodcaw_array);
|
||||
})
|
||||
->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array, $total_nilai_marhun_by_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$kodcaw] ?? 'Unknown';
|
||||
$ansuran_cawangan->total_nilai_marhun = $total_nilai_marhun_by_cawangan[$kodcaw] ?? 0;
|
||||
unset($ansuran_cawangan->norujukan_list); // Remove unnecessary field
|
||||
return $ansuran_cawangan;
|
||||
})
|
||||
->values();
|
||||
|
||||
// Step 4: Calculate overall totals
|
||||
$total_summary = [
|
||||
'bilangan_ansuran' => 0,
|
||||
'bayaran_pembiayaan' => 0,
|
||||
'bayaran_kos_keuntungan' => 0,
|
||||
'jumlah_bayaran' => 0,
|
||||
'total_nilai_marhun' => 0,
|
||||
];
|
||||
|
||||
foreach ($summary_ansuran_by_cawangan as $ansuran_cawangan) {
|
||||
$total_summary['bilangan_ansuran'] += $ansuran_cawangan->bilangan_ansuran ?? 0;
|
||||
$total_summary['bayaran_pembiayaan'] += $ansuran_cawangan->bayaran_pembiayaan ?? 0;
|
||||
$total_summary['bayaran_kos_keuntungan'] += $ansuran_cawangan->bayaran_kos_keuntungan ?? 0;
|
||||
$total_summary['jumlah_bayaran'] += $ansuran_cawangan->jumlah_bayaran ?? 0;
|
||||
$total_summary['total_nilai_marhun'] += $ansuran_cawangan->total_nilai_marhun ?? 0;
|
||||
}
|
||||
|
||||
// Step 5: Prepare the overall ansuran summary
|
||||
$summary_ansuran = [
|
||||
'bilangan_ansuran' => $total_summary['bilangan_ansuran'],
|
||||
'bayaran_pembiayaan' => $total_summary['bayaran_pembiayaan'],
|
||||
'bayaran_kos_keuntungan' => $total_summary['bayaran_kos_keuntungan'],
|
||||
'jumlah_bayaran' => $total_summary['jumlah_bayaran'],
|
||||
'total_nilai_marhun' => $total_summary['total_nilai_marhun'],
|
||||
];
|
||||
|
||||
$response = [
|
||||
'summary_aging_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_aging' => $summary_ansuran, // Now contains the grand totals
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAging(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)
|
||||
->select('kodcaw', 'details_caw', 'mysql')->get();
|
||||
|
||||
$kod_caw_with_cawangan_detail_array = $cawangan_available->pluck('details_caw', 'kodcaw')->toArray();
|
||||
|
||||
$current = Carbon::now();
|
||||
$endDate = Carbon::parse($request->endDate);
|
||||
$bulan = $endDate->month;
|
||||
$tahun = $endDate->year;
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($kod_caw_with_cawangan_detail_array as $kodcaw => $details_caw) {
|
||||
$cawangan = $cawangan_available->firstWhere('kodcaw', $kodcaw);
|
||||
if (!$cawangan) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine which table to query
|
||||
if ($current->month == $bulan && $current->year == $tahun) {
|
||||
$audit = Gadai::on($cawangan->mysql)
|
||||
->where(function ($q) use ($endDate) {
|
||||
$q->where([
|
||||
['tagpalsu', '=', 0],
|
||||
['t_gadai', '<=', $endDate->toDateString()],
|
||||
['sttebus', '=', '']
|
||||
])
|
||||
->orWhere([
|
||||
['tagpalsu', '=', 0],
|
||||
['t_update', '>', $endDate->toDateString()],
|
||||
['sttebus', '!=', ''],
|
||||
['t_gadai', '<=', $endDate->toDateString()]
|
||||
]);
|
||||
});
|
||||
} else {
|
||||
$tableMap = [
|
||||
1 => StokAudit1::class, 2 => StokAudit2::class, 3 => StokAudit3::class,
|
||||
4 => StokAudit4::class, 5 => StokAudit5::class, 6 => StokAudit6::class,
|
||||
7 => StokAudit7::class, 8 => StokAudit8::class, 9 => StokAudit9::class,
|
||||
10 => StokAudit10::class, 11 => StokAudit11::class, 12 => StokAudit12::class,
|
||||
];
|
||||
|
||||
$model = $tableMap[$bulan] ?? null;
|
||||
if (!$model) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$audit = $model::on($cawangan->mysql)->where('tahun', $tahun);
|
||||
}
|
||||
|
||||
// Categorize data by tempoh
|
||||
$summary = [];
|
||||
|
||||
for ($i = 1; $i <= 13; $i++) {
|
||||
$query = clone $audit;
|
||||
|
||||
if ($i == 13) {
|
||||
$filtered = $query->where('tempoh', '>', 12);
|
||||
} elseif ($i == 1) {
|
||||
$filtered = $query->whereBetween('tempoh', [0.01, 1.5]);
|
||||
} elseif ($i == 12) {
|
||||
$filtered = $query->where('tempoh', 12);
|
||||
} else {
|
||||
$filtered = $query->where([['tempoh','>',$i-(0.5)],['tempoh','<=',$i+(0.5)]]);
|
||||
}
|
||||
|
||||
$labelMap = [
|
||||
1 => '1 Bulan',
|
||||
2 => '2 Bulan',
|
||||
3 => '3 Bulan',
|
||||
4 => '4 Bulan',
|
||||
5 => '5 Bulan',
|
||||
6 => '6 Bulan',
|
||||
7 => '7 bulan',
|
||||
8 => '8 Bulan',
|
||||
9 => '9 Bulan',
|
||||
10 => '10 Bulan',
|
||||
11 => '11 Bulan',
|
||||
12 => '12 Bulan',
|
||||
13 => '> 12 Bulan'
|
||||
];
|
||||
|
||||
$summary[] = [
|
||||
'label' => $labelMap[$i],
|
||||
'count' => $filtered->count(),
|
||||
'sum_bakipjm' => $filtered->sum('bakipjm'),
|
||||
];
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'kodcaw' => $kodcaw,
|
||||
'cawangan' => $details_caw,
|
||||
'tahun' => $tahun,
|
||||
'bulan' => $bulan,
|
||||
'summary_by_tempoh' => $summary
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Customer;
|
||||
use App\Tebus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\GadaianService as ReportGadaianService;
|
||||
use App\Helper;
|
||||
use App\Services\Reports\RingkasanHarianService as ReportRingkasanHarianService;
|
||||
|
||||
|
||||
class AnalisaController extends Controller
|
||||
{
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportGadaianService = new ReportGadaianService($kod_cawangan, $request);
|
||||
return $reportGadaianService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanPelangganBaru(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Iterate through each branch and get data
|
||||
$response = array_map(function ($db_connection, $cawangan_detail) use ($request) {
|
||||
// Pass the required parameters to the service constructor
|
||||
$reportRingkasanHarianService = new ReportRingkasanHarianService($cawangan_detail['kodcaw'], $request);
|
||||
|
||||
// Get the customer count from the service
|
||||
$bilangan_customer_baru = $reportRingkasanHarianService->getCustomerSummary(); // Call public method
|
||||
|
||||
// Return the response
|
||||
return [
|
||||
'kodcaw' => $cawangan_detail['kodcaw'],
|
||||
'details_caw' => $cawangan_detail['details_caw'],
|
||||
'total_pelanggan_baru' => $bilangan_customer_baru,
|
||||
];
|
||||
}, $active_cawangan_db_connection, $active_cawangan_detail);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
// public function getSummaryLaporanPelangganAktif(Request $request)
|
||||
// {
|
||||
// $startDate = $request->startDate;
|
||||
// $endDate = $request->endDate;
|
||||
|
||||
// // Dapatkan senarai cawangan aktif
|
||||
// $active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// // Dapatkan maklumat cawangan
|
||||
// $cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
// ->whereIn('mysql', $active_cawangan_db_connection)
|
||||
// ->get();
|
||||
|
||||
// $active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
// return [
|
||||
// 'kodcaw' => $c->kodcaw,
|
||||
// 'details_caw' => $c->details_caw,
|
||||
// 'mysql' => $c->mysql,
|
||||
// ];
|
||||
// })->toArray();
|
||||
|
||||
// $response = array_map(function ($cawangan) use ($startDate, $endDate) {
|
||||
// $db_connection = $cawangan['mysql'];
|
||||
|
||||
// $total_aktif = Gadai::on($db_connection)
|
||||
// ->where(function ($query) use ($startDate) {
|
||||
// $query->where('sttebus', '')
|
||||
// ->where('t_update', '>=', $startDate);
|
||||
// })
|
||||
// ->where('t_gadai', '<=', $endDate)
|
||||
// ->distinct('nokp')
|
||||
// ->count('nokp');
|
||||
|
||||
// return [
|
||||
// 'kodcaw' => $cawangan['kodcaw'],
|
||||
// 'details_caw' => $cawangan['details_caw'],
|
||||
// 'total_pelanggan_aktif' => $total_aktif,
|
||||
// ];
|
||||
// }, $active_cawangan_detail);
|
||||
|
||||
|
||||
// return response()->json($response);
|
||||
// }
|
||||
|
||||
|
||||
public function getSummaryLaporanPelangganAktif(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
$active_cawangan = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', Helper::getActiveCawanganDbConnection())
|
||||
->get();
|
||||
|
||||
$response = $active_cawangan->map(function ($cawangan) use ($startDate, $endDate) {
|
||||
$db = $cawangan->mysql;
|
||||
|
||||
// Ambil nokp dari Gadai
|
||||
$nokp_gadai = DB::connection($db)->table('gadai')
|
||||
->whereBetween('t_gadai', [$startDate, $endDate])
|
||||
->pluck('nokp')
|
||||
->toArray();
|
||||
|
||||
// Ambil nokp dari Tebus
|
||||
$nokp_tebus = DB::connection($db)->table('tebus as t')
|
||||
->join('gadai as g', 't.norujukan', '=', 'g.norujukan')
|
||||
->whereBetween('t.t_tebus', [$startDate, $endDate])
|
||||
->pluck('g.nokp')
|
||||
->toArray();
|
||||
|
||||
// Gabung semua nokp
|
||||
$semua_nokp = collect(array_merge($nokp_gadai, $nokp_tebus))
|
||||
->filter(fn($item) => !empty($item))
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($semua_nokp->isEmpty()) {
|
||||
// Jika array kosong, kita kembalikan hasil kosong
|
||||
$pelanggan_aktif = collect();
|
||||
} else {
|
||||
$pelanggan_aktif = Customer::on($db)
|
||||
->where(function ($query) use ($semua_nokp) {
|
||||
$query->whereIn('kpbaru', $semua_nokp)
|
||||
->orWhereIn('kplama', $semua_nokp);
|
||||
})
|
||||
->get(['nama', 'kpbaru', 'kplama'])
|
||||
->toArray();;
|
||||
}
|
||||
|
||||
return [
|
||||
'kodcaw' => $cawangan->kodcaw,
|
||||
'details_caw' => $cawangan->details_caw,
|
||||
'total_pelanggan_aktif' => count($semua_nokp),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Reports\AnsuranService as ReportAnsuranService;
|
||||
@@ -19,46 +20,99 @@ class AnsuranController extends Controller
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAnsuran(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw', 'mysql')->get();
|
||||
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran
|
||||
');
|
||||
$kodcaw_array = array_column($cawangan_available->toArray(), 'kodcaw');
|
||||
$kod_caw_with_cawangan_detail_array = $cawangan_available->pluck('details_caw', 'kodcaw')->toArray();
|
||||
|
||||
$summary_ansuran = (clone $ansuran_query)->get()->toArray()[0];
|
||||
// Step 1: Fetch the ansuran data grouped by cawangan
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
transaction.kodcaw as kod_cawangan,
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran,
|
||||
GROUP_CONCAT(transaction.norujukan) as norujukan_list
|
||||
')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
|
||||
$summary_ansuran_by_cawangan = (clone $ansuran_query)
|
||||
->addSelect('transaction.kodcaw as kod_cawangan')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
$total_nilai_marhun_by_cawangan = [];
|
||||
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw')->get()->toArray();
|
||||
$kodcaw_array = array_column($cawangan_available, 'kodcaw');
|
||||
$cawangan_detail_array = array_column($cawangan_available, 'details_caw');
|
||||
$kod_caw_with_cawangan_detail_array = array_combine($kodcaw_array, $cawangan_detail_array);
|
||||
// Step 2: Loop through ansuran_query and fetch nilai_marhun per kodcaw
|
||||
foreach ($ansuran_query as $ansuran_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$norujukan_list = explode(',', $ansuran_cawangan->norujukan_list); // Convert to array
|
||||
|
||||
$summary_ansuran_by_cawangan = $summary_ansuran_by_cawangan->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array) {
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$ansuran_cawangan['kod_cawangan']];
|
||||
return $ansuran_cawangan;
|
||||
});
|
||||
// Get database connection for this branch
|
||||
$mysql_connection = $cawangan_available->where('kodcaw', $kodcaw)->first()->mysql ?? null;
|
||||
if (!$mysql_connection) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response = [
|
||||
'summary_ansuran_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_ansuran' => $summary_ansuran,
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
// Sum nilai_marhun for matching norujukan in gadai table
|
||||
$total_nilai_marhun_by_cawangan[$kodcaw] = Gadai::on($mysql_connection)
|
||||
->whereIn('norujukan', $norujukan_list)
|
||||
->sum('nilaimarhun');
|
||||
}
|
||||
|
||||
// Step 3: Merge ansuran summary with total_nilai_marhun
|
||||
$summary_ansuran_by_cawangan = $ansuran_query
|
||||
->filter(function ($ansuran_cawangan) use ($kodcaw_array) {
|
||||
return in_array($ansuran_cawangan['kod_cawangan'], $kodcaw_array);
|
||||
})
|
||||
->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array, $total_nilai_marhun_by_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$kodcaw] ?? 'Unknown';
|
||||
$ansuran_cawangan->total_nilai_marhun = $total_nilai_marhun_by_cawangan[$kodcaw] ?? 0;
|
||||
unset($ansuran_cawangan->norujukan_list); // Remove unnecessary field
|
||||
return $ansuran_cawangan;
|
||||
})
|
||||
->values();
|
||||
|
||||
// Step 4: Calculate overall totals
|
||||
$total_summary = [
|
||||
'bilangan_ansuran' => 0,
|
||||
'bayaran_pembiayaan' => 0,
|
||||
'bayaran_kos_keuntungan' => 0,
|
||||
'jumlah_bayaran' => 0,
|
||||
'total_nilai_marhun' => 0,
|
||||
];
|
||||
|
||||
foreach ($summary_ansuran_by_cawangan as $ansuran_cawangan) {
|
||||
$total_summary['bilangan_ansuran'] += $ansuran_cawangan->bilangan_ansuran ?? 0;
|
||||
$total_summary['bayaran_pembiayaan'] += $ansuran_cawangan->bayaran_pembiayaan ?? 0;
|
||||
$total_summary['bayaran_kos_keuntungan'] += $ansuran_cawangan->bayaran_kos_keuntungan ?? 0;
|
||||
$total_summary['jumlah_bayaran'] += $ansuran_cawangan->jumlah_bayaran ?? 0;
|
||||
$total_summary['total_nilai_marhun'] += $ansuran_cawangan->total_nilai_marhun ?? 0;
|
||||
}
|
||||
|
||||
// Step 5: Prepare the overall ansuran summary
|
||||
$summary_ansuran = [
|
||||
'bilangan_ansuran' => $total_summary['bilangan_ansuran'],
|
||||
'bayaran_pembiayaan' => $total_summary['bayaran_pembiayaan'],
|
||||
'bayaran_kos_keuntungan' => $total_summary['bayaran_kos_keuntungan'],
|
||||
'jumlah_bayaran' => $total_summary['jumlah_bayaran'],
|
||||
'total_nilai_marhun' => $total_summary['total_nilai_marhun'],
|
||||
];
|
||||
|
||||
$response = [
|
||||
'summary_ansuran_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_ansuran' => $summary_ansuran, // Now contains the grand totals
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\TransactionOnline;
|
||||
|
||||
class BayaranOnlineController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$transactionOnlineQuery = TransactionOnline::filter($request);
|
||||
|
||||
$formatMoney = fn($x) => number_format($x, 2, '.', ',');
|
||||
|
||||
$sumTotalPayments = (clone $transactionOnlineQuery)->sum('total_payment');
|
||||
$sumTotalPayments = $formatMoney($sumTotalPayments);
|
||||
$nosPayments = (clone $transactionOnlineQuery)->count('total_payment');
|
||||
|
||||
$transactions = (clone $transactionOnlineQuery)->select('kodcaw', DB::raw('sum(total_payment) as totalCawanganPayment'), DB::raw('count(reference_no) as totalReferenceNo'))
|
||||
->groupBy('kodcaw')
|
||||
->get()
|
||||
->map(function($x) use($formatMoney) {
|
||||
$x['totalCawanganPayment'] = $formatMoney($x['totalCawanganPayment']);
|
||||
return $x;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'nosPayments' => $nosPayments,
|
||||
'sumTotalPayments' => $sumTotalPayments,
|
||||
'transactions' => $transactions,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\TransactionOnline;
|
||||
|
||||
class BayaranOnlineDetailController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
|
||||
$transactionOnlineQuery = TransactionOnline::filter($request);
|
||||
|
||||
$formatMoney = fn($x) => number_format($x, 2, '.', ',');
|
||||
|
||||
$sumTotalPayments = (clone $transactionOnlineQuery)->sum('total_payment');
|
||||
$sumTotalPayments = $formatMoney($sumTotalPayments);
|
||||
$sumPaymentNos = (clone $transactionOnlineQuery)->count('total_payment');
|
||||
|
||||
$transactions = (clone $transactionOnlineQuery)->select('nokp', 'customer_name', 'norujukan', 'reference_no', 'kodcaw', 'total_payment', 'tarikh', 'masa', 'status')
|
||||
->get()
|
||||
->groupBy('nokp')
|
||||
->map(fn($x) => $x->groupBy('cawangan.details_caw'))
|
||||
->map(function ($cawangan) {
|
||||
|
||||
$all_entries = $cawangan->collapse();
|
||||
|
||||
$first = $all_entries->first();
|
||||
|
||||
$payment_details = $cawangan->map(function ($cawangan_payments) {
|
||||
return [
|
||||
'paymentNos' => $cawangan_payments->count(),
|
||||
'paymentSum' => $cawangan_payments->sum('total_payment'),
|
||||
'paymentDetails' => $cawangan_payments->map(function ($x) {
|
||||
|
||||
$payment_details = collect($x)->except('nokp', 'customer_name', 'kodcaw', 'cawangan');
|
||||
|
||||
return $payment_details;
|
||||
}),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'customer_name' => $first->customer_name,
|
||||
'nokp' => $first->nokp,
|
||||
'payments' => $payment_details,
|
||||
];
|
||||
})
|
||||
->values();
|
||||
|
||||
|
||||
return response()->json([
|
||||
'sumTotalPayments' => $sumTotalPayments,
|
||||
'sumPaymentNos' => $sumPaymentNos,
|
||||
'transactions' => $transactions,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -26,18 +26,29 @@ class GadaianController extends Controller
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
$active_cawangan_db_name = array_map(function ($db_connection) {
|
||||
return config('database.connections' . '.' . $db_connection . '.' . 'database');
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
$summary_gadaian_data = array_map(function ($db_connection) use ($request) {
|
||||
$query = Gadai::on($db_connection);
|
||||
|
||||
$query->select(DB::raw('count(norujukan) as total_gadaian, sum(berat) as sum_berat, sum(nilaimarhun) as sum_nilai_marhun, sum(pinjaman) as sum_pinjaman'));
|
||||
$query->select(DB::raw('count(norujukan) as total_gadaian, sum(berat) as sum_berat, sum(nilaimarhun) as sum_nilai_marhun, sum(pinjaman) as sum_pinjaman, sum(upah12) as sum_upah_12'));
|
||||
|
||||
$query->when($request->filled('startDate') and $request->filled('endDate'), function ($q) use ($request) {
|
||||
return $q->where('t_gadai', '>=', $request->startDate)
|
||||
@@ -54,4 +65,131 @@ class GadaianController extends Controller
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanGadaiTebus(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Loop through each DB
|
||||
$summary_data = array_map(function ($db_connection) use ($startDate, $endDate) {
|
||||
$result = DB::connection($db_connection)->table('gadai as g')
|
||||
->join('tebus as t', function ($join) {
|
||||
$join->on(DB::raw('DATE(g.t_gadai)'), '=', DB::raw('DATE(t.t_tebus)'))
|
||||
->on('g.norujukan', '=', 't.norujukan');
|
||||
})
|
||||
->whereDate('g.t_gadai', '>=', $startDate)
|
||||
->whereDate('g.t_gadai', '<=', $endDate)
|
||||
->whereDate('t.t_tebus', '>=', $startDate)
|
||||
->whereDate('t.t_tebus', '<=', $endDate)
|
||||
->where('g.upah12', '>=', 0.00)
|
||||
->selectRaw('
|
||||
COUNT(DISTINCT g.norujukan) as total_gadai_tebus_samahari,
|
||||
SUM(g.pinjaman) as jumlah_pinjaman
|
||||
')
|
||||
->first(); // ambil satu hasil, bukan collection
|
||||
|
||||
return (array) $result ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
];
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
|
||||
// Gabung cawangan + hasil
|
||||
$response = array_map(function ($cawangan_detail, $summary_row) {
|
||||
return array_merge($cawangan_detail, $summary_row ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
]);
|
||||
}, $active_cawangan_detail, $summary_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
public function getSummaryLaporanGadaiTebusMasa(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Ambil connection aktif
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Dapatkan butiran cawangan
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Loop through each DB
|
||||
$summary_data = array_map(function ($db_connection) use ($startDate, $endDate) {
|
||||
$result = DB::connection($db_connection)->table('gadai as g')
|
||||
->join('tebus as t', function ($join) {
|
||||
$join->on(DB::raw('DATE(g.t_gadai)'), '=', DB::raw('DATE(t.t_tebus)'))
|
||||
->on('g.norujukan', '=', 't.norujukan');
|
||||
})
|
||||
->whereDate('g.t_gadai', '>=', $startDate)
|
||||
->whereDate('g.t_gadai', '<=', $endDate)
|
||||
->whereDate('t.t_tebus', '>=', $startDate)
|
||||
->whereDate('t.t_tebus', '<=', $endDate)
|
||||
->where('g.upah12', '>=', 0.00)
|
||||
->selectRaw('
|
||||
COUNT(DISTINCT g.norujukan) as total_gadai_tebus_samahari,
|
||||
SUM(g.pinjaman) as jumlah_pinjaman
|
||||
')
|
||||
->first(); // ambil satu hasil, bukan collection
|
||||
|
||||
return (array) $result ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
];
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
|
||||
// Gabung cawangan + hasil
|
||||
$response = array_map(function ($cawangan_detail, $summary_row) {
|
||||
return array_merge($cawangan_detail, $summary_row ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
]);
|
||||
}, $active_cawangan_detail, $summary_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function getLaporanGadaiTebusMasaCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$ReportGadaianService = new ReportGadaianService($kod_cawangan, $request);
|
||||
return $ReportGadaianService->getCawanganReportGadaiTebusMasa();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Lelong;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\LelonganService as ReportLelonganService;
|
||||
use App\Helper;
|
||||
|
||||
|
||||
class LelonganController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportLelonganService = new ReportLelonganService($kod_cawangan, $request);
|
||||
return $reportLelonganService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanLelong(Request $request)
|
||||
{
|
||||
$onDate = $request->onDate;
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branches in the order we want
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Preserve keys while mapping database names
|
||||
$active_cawangan_db_name = array_combine(
|
||||
$active_cawangan_db_connection,
|
||||
array_map(function ($db_connection) {
|
||||
return config('database.connections.' . $db_connection . '.database');
|
||||
}, $active_cawangan_db_connection)
|
||||
);
|
||||
// dd($active_cawangan_db_name);
|
||||
|
||||
// Retrieve branch details and re-index by db_name
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw', 'db_name')
|
||||
->whereIn('db_name', array_values($active_cawangan_db_name))
|
||||
->get()
|
||||
->keyBy('db_name')
|
||||
->toArray();
|
||||
// dd($active_cawangan_detail);
|
||||
|
||||
// Retrieve lelong summary data and re-index by db_connection
|
||||
$summary_lelongan_data = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$query = Lelong::on($db_connection)
|
||||
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->select(DB::raw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as sum_berat,
|
||||
sum(lelong.nilaimarhun) as sum_nilai_marhun,
|
||||
sum(gadai.pinjaman) as sum_pinjaman,
|
||||
sum(lelong.pinjaman) as sum_bakipjm,
|
||||
sum(lelong.bakiupah) as sum_bakiupah,
|
||||
sum(lelong.cajlain) as sum_cajlain,
|
||||
sum(lelong.cajlelong) as sum_cajlelong,
|
||||
sum(lelong.hargajual) as sum_hargajual,
|
||||
sum(lelong.baki) as sum_baki'));
|
||||
|
||||
|
||||
if ($request->filled('startDate') && $request->filled('endDate')) {
|
||||
$query->whereBetween('lelong.t_jual', [$request->startDate, $request->endDate]);
|
||||
}
|
||||
|
||||
$summary_lelongan_data[$db_connection] = $query->first()->toArray();
|
||||
}
|
||||
|
||||
// Ensure data is sorted according to getActiveCawanganDbConnection()
|
||||
$response = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$db_name = $active_cawangan_db_name[$db_connection] ?? null;
|
||||
if ($db_name && isset($active_cawangan_detail[$db_name])) {
|
||||
$response[] = array_merge(
|
||||
$active_cawangan_detail[$db_name],
|
||||
$summary_lelongan_data[$db_connection] ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanBakiLelongBelumTuntut(Request $request)
|
||||
{
|
||||
$onDate = $request->onDate;
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branches in the order we want
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Preserve keys while mapping database names
|
||||
$active_cawangan_db_name = array_combine(
|
||||
$active_cawangan_db_connection,
|
||||
array_map(function ($db_connection) {
|
||||
return config('database.connections.' . $db_connection . '.database');
|
||||
}, $active_cawangan_db_connection)
|
||||
);
|
||||
// dd($active_cawangan_db_name);
|
||||
|
||||
// Retrieve branch details and re-index by db_name
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw', 'db_name')
|
||||
->whereIn('db_name', array_values($active_cawangan_db_name))
|
||||
->get()
|
||||
->keyBy('db_name')
|
||||
->toArray();
|
||||
// dd($active_cawangan_detail);
|
||||
|
||||
// Retrieve lelong summary data and re-index by db_connection
|
||||
$summary_lelongan_data = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$query = Lelong::on($db_connection)
|
||||
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->select(DB::raw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as sum_berat,
|
||||
sum(lelong.nilaimarhun) as sum_nilai_marhun,
|
||||
sum(gadai.pinjaman) as sum_pinjaman,
|
||||
sum(lelong.pinjaman) as sum_bakipjm,
|
||||
sum(lelong.bakiupah) as sum_bakiupah,
|
||||
sum(lelong.cajlain) as sum_cajlain,
|
||||
sum(lelong.cajlelong) as sum_cajlelong,
|
||||
sum(lelong.hargajual) as sum_hargajual,
|
||||
sum(lelong.baki) as sum_baki'))
|
||||
->where(function ($query) use ($request) {
|
||||
$query->whereNull('lelong.trkhtuntut')
|
||||
->orWhere('lelong.trkhtuntut', '>', $request->endDate); // or use a specific date: '2025-06-01'
|
||||
})
|
||||
->where('lelong.baki', '>', 0.00)
|
||||
->orderBy('lelong.norujukan', 'asc');
|
||||
|
||||
|
||||
if ($request->filled('startDate') && $request->filled('endDate')) {
|
||||
$query->whereBetween('lelong.t_lelong', [$request->startDate, $request->endDate]);
|
||||
}
|
||||
|
||||
$summary_lelongan_data[$db_connection] = $query->first()->toArray();
|
||||
}
|
||||
|
||||
// Ensure data is sorted according to getActiveCawanganDbConnection()
|
||||
$response = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$db_name = $active_cawangan_db_name[$db_connection] ?? null;
|
||||
if ($db_name && isset($active_cawangan_detail[$db_name])) {
|
||||
$response[] = array_merge(
|
||||
$active_cawangan_detail[$db_name],
|
||||
$summary_lelongan_data[$db_connection] ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getLaporanBakiLelongBelumTuntutCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportLelonganService = new ReportLelonganService($kod_cawangan, $request);
|
||||
return $reportLelonganService->getCawanganReportBakiLelongBelumTuntut();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Vault;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\OutstandingService as ReportOutstandingService;
|
||||
use App\Helper;
|
||||
|
||||
|
||||
class OutstandingController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportOutstandingService = new ReportOutstandingService($kod_cawangan, $request);
|
||||
return $reportOutstandingService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanOutstanding(Request $request)
|
||||
{
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Query outstanding summary for each branch
|
||||
$summary_Outstanding_data = array_map(function ($db_connection) use ($endDate) {
|
||||
// SAG LAMA
|
||||
$queryLama = Gadai::on($db_connection)
|
||||
->selectRaw('COUNT(norujukan) as total_gadaian, SUM(pinjaman) as sum_pinjaman')
|
||||
->where('tagbaru', 0)
|
||||
->where('sttebus', '');
|
||||
|
||||
// SAG BARU
|
||||
$queryBaru = Gadai::on($db_connection)
|
||||
->selectRaw('COUNT(norujukan) as total_gadaian2, SUM(pinjaman) as sum_pinjaman2')
|
||||
->where('tagbaru', 1)
|
||||
->where('sttebus', '');
|
||||
|
||||
// SEMUA
|
||||
$queryAll = Gadai::on($db_connection)
|
||||
->selectRaw('COUNT(norujukan) as total_gadaian_all, SUM(pinjaman) as sum_pinjaman_all')
|
||||
->where('sttebus', '');
|
||||
|
||||
if (!empty($endDate)) {
|
||||
$queryLama->where('t_gadai', '<=', $endDate);
|
||||
$queryBaru->where('t_gadai', '<=', $endDate);
|
||||
$queryAll->where('t_gadai', '<=', $endDate);
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
$queryLama->first()->toArray(),
|
||||
$queryBaru->first()->toArray(),
|
||||
$queryAll->first()->toArray()
|
||||
);
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
// Combine data with branch info
|
||||
$response = array_map(function ($cawangan_detail, $outstanding_data) {
|
||||
return array_merge($cawangan_detail, $outstanding_data);
|
||||
}, $active_cawangan_detail, $summary_Outstanding_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanPetibesi(Request $request)
|
||||
{
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Query petibesi summary for each branch
|
||||
$summary_petibesi_data = array_map(function ($db_connection) use ($endDate) {
|
||||
|
||||
|
||||
// SEMUA
|
||||
$queryAll = Vault::on($db_connection)
|
||||
->selectRaw('bakieod');
|
||||
|
||||
if (!empty($endDate)) {
|
||||
$queryAll->where('tarikh', '=', $endDate);
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
$queryAll->first()->toArray()
|
||||
);
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
// Combine data with branch info
|
||||
$response = array_map(function ($cawangan_detail, $petibesi_data) {
|
||||
return array_merge($cawangan_detail, $petibesi_data);
|
||||
}, $active_cawangan_detail, $summary_petibesi_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -21,14 +21,24 @@ class PenebusanController extends Controller
|
||||
|
||||
public function getSummaryLaporanTebus(Request $request)
|
||||
{
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
$active_cawangan_db_name = array_map(function ($db_connection) {
|
||||
return config('database.connections' . '.' . $db_connection . '.' . 'database');
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
$summary_penebusan_data = array_map(function ($db_connection) use ($request) {
|
||||
$penebusan = Tebus::on($db_connection)
|
||||
@@ -39,8 +49,8 @@ class PenebusanController extends Controller
|
||||
->select(DB::raw('
|
||||
count(tebus.norujukan) as bilangan_tebus,
|
||||
sum(gadai.berat) as berat,
|
||||
sum(gadai.bakipjm) as nilai_pinjaman,
|
||||
sum(tebus.pinjaman) as baki_pinjaman,
|
||||
sum(gadai.pinjaman) as nilai_pinjaman,
|
||||
sum(gadai.bakipjm) as baki_pinjaman,
|
||||
sum(tebus.nilaimarhun) as nilai_marhun,
|
||||
sum(tebus.bakiupah) as keuntungan_asal,
|
||||
sum(tebus.bakipjm - gadai.bakipjm) as keuntungan_rebet,
|
||||
|
||||
@@ -51,16 +51,66 @@ class StokAuditController extends Controller
|
||||
// dd($request->kodcaw);
|
||||
$daritempoh = $request->daritempoh;
|
||||
$hinggatempoh = $request->hinggatempoh;
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
// Query asal gadai
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]])
|
||||
->where([
|
||||
['tagpalsu', '=', 0],
|
||||
['tempoh', '>=', $daritempoh],
|
||||
['tempoh', '<=', $hinggatempoh],
|
||||
['sttebus', '=', ''],
|
||||
['taglel', '=', 0],
|
||||
])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
// dd($audit);
|
||||
->orderBy('sirig', 'ASC')
|
||||
->get();
|
||||
|
||||
// Dapatkan semua norujukan awal
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
$rekodaudit = $audit->get();
|
||||
|
||||
// Dapatkan tarikh terkini untuk setiap norujukan ikut trans_type T
|
||||
$tarikhTerkiniT = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'T')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Dapatkan tarikh terkini untuk setiap norujukan ikut trans_type A
|
||||
$tarikhTerkiniA = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'A')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Filter audit ikut tarikh masing-masing
|
||||
$rekodaudit = $audit->filter(function ($item) use ($tarikhTerkiniT, $tarikhTerkiniA) {
|
||||
$norujukan = $item->norujukan;
|
||||
|
||||
$adaTebusTerkini = isset($tarikhTerkiniT[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'T')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT[$norujukan])))
|
||||
->exists();
|
||||
|
||||
$adaAnsuranTerkini = isset($tarikhTerkiniA[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA[$norujukan])))
|
||||
->exists();
|
||||
|
||||
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
||||
})->values();
|
||||
|
||||
// Gunakan hanya norujukan yang dah ditapis
|
||||
$arraynorujukan = $rekodaudit->pluck('norujukan')->toArray();
|
||||
|
||||
$gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
|
||||
->select('nokp')
|
||||
->groupBy('nokp')
|
||||
@@ -68,28 +118,23 @@ class StokAuditController extends Controller
|
||||
|
||||
// dd($gadainokp);
|
||||
|
||||
foreach($gadainokp as $index1=>$cal){
|
||||
$customer = Customer::on('mysql7')->where('kpbaru','=',$cal['nokp'])
|
||||
->orWhere('kplama','=',$cal['nokp'])
|
||||
foreach ($gadainokp as $index1 => $cal) {
|
||||
$customer = Customer::on('mysql7')->where('kpbaru', '=', $cal['nokp'])
|
||||
->orWhere('kplama', '=', $cal['nokp'])
|
||||
->first();
|
||||
|
||||
$listsag = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
|
||||
// ->where('nokp','=',$cal['nokp'])
|
||||
->where('nokp', 'like', '%'.$cal['nokp'].'%')
|
||||
->where('nokp', 'like', '%' . $cal['nokp'] . '%')
|
||||
->get();
|
||||
|
||||
foreach($listsag as $index2=>$cal2){
|
||||
|
||||
if($cal2){
|
||||
$checkingnokp = null;
|
||||
foreach ($listsag as $index2 => $cal2) {
|
||||
if ($cal2) {
|
||||
$checkingnokp = BlastWasap::on('mysql7')
|
||||
->where('nokp','=',$cal['nokp'])
|
||||
->where('norujukan','=',$cal2['norujukan'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where('nokp', '=', $cal['nokp'])
|
||||
->where('norujukan', '=', $cal2['norujukan'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->first();
|
||||
|
||||
// $gadainokp[$index1]['blasted'] = $checkingnokp;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,17 +142,24 @@ class StokAuditController extends Controller
|
||||
$gadainokp[$index1]['listsag'] = $listsag;
|
||||
$gadainokp[$index1]['blasted'] = $checkingnokp;
|
||||
}
|
||||
|
||||
$totalrekod = $audit->sum('pinjaman');
|
||||
$totalberat = $audit->sum('berat');
|
||||
$totalnilaimarhun = $audit->sum('nilaimarhun');
|
||||
$totalpinjaman = $audit->sum('pinjaman');
|
||||
$totalbakipjm = $audit->sum('bakipjm');
|
||||
$totaltunggakan = $audit->sum('tunggakan');
|
||||
// Total dikira berdasarkan hasil audit yang telah ditapis
|
||||
$totalrekod = $rekodaudit->sum('pinjaman');
|
||||
$totalberat = $rekodaudit->sum('berat');
|
||||
$totalnilaimarhun = $rekodaudit->sum('nilaimarhun');
|
||||
$totalpinjaman = $rekodaudit->sum('pinjaman');
|
||||
$totalbakipjm = $rekodaudit->sum('bakipjm');
|
||||
$totaltunggakan = $rekodaudit->sum('tunggakan');
|
||||
|
||||
$arrayrekod = ['rekod' => $gadainokp, 'total' => $totalrekod,'totalberat' => $totalberat,'totalnilaimarhun' => $totalnilaimarhun,'totalpinjaman'=>$totalpinjaman,'totalbakipjm'=>$totalbakipjm,'totaltunggakan'=>$totaltunggakan];
|
||||
// dd($arrayrekod);
|
||||
return response()->json($arrayrekod,200);
|
||||
$arrayrekod = [
|
||||
'rekod' => $gadainokp,
|
||||
'total' => $totalrekod,
|
||||
'totalberat' => $totalberat,
|
||||
'totalnilaimarhun' => $totalnilaimarhun,
|
||||
'totalpinjaman' => $totalpinjaman,
|
||||
'totalbakipjm' => $totalbakipjm,
|
||||
'totaltunggakan' => $totaltunggakan,
|
||||
];
|
||||
return response()->json($arrayrekod, 200);
|
||||
}
|
||||
|
||||
|
||||
@@ -380,4 +432,151 @@ class StokAuditController extends Controller
|
||||
'totaltunggakan'=>$totaltunggakan ?? null];
|
||||
return response()->json($arrayrekod,200);
|
||||
}
|
||||
|
||||
|
||||
public function LaporanAuditKhasByNorujukan($kodcaw, Request $request)
|
||||
{
|
||||
$daritempoh = $request->daritempoh;
|
||||
$hinggatempoh = $request->hinggatempoh;
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
// Ambil semua rekod gadai asas
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([
|
||||
['tagpalsu', '=', 0],
|
||||
['tempoh', '>=', $daritempoh],
|
||||
['tempoh', '<=', $hinggatempoh],
|
||||
['sttebus', '=', ''],
|
||||
['taglel', '=', 0],
|
||||
])
|
||||
->orderBy('norujukan', 'ASC') // susun ikut norujukan
|
||||
->get();
|
||||
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
|
||||
// Tarikh terkini ikut trans_type T
|
||||
$tarikhTerkiniT = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'T')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Tarikh terkini ikut trans_type A
|
||||
$tarikhTerkiniA = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'A')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Filter audit
|
||||
$rekodaudit = $audit->filter(function ($item) use ($tarikhTerkiniT, $tarikhTerkiniA) {
|
||||
$norujukan = $item->norujukan;
|
||||
|
||||
$adaTebusTerkini = isset($tarikhTerkiniT[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'T')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT[$norujukan])))
|
||||
->exists();
|
||||
|
||||
$adaAnsuranTerkini = isset($tarikhTerkiniA[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA[$norujukan])))
|
||||
->exists();
|
||||
|
||||
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
||||
})->values();
|
||||
|
||||
// Attach customer info + blast untuk setiap norujukan
|
||||
foreach ($rekodaudit as $index => $rekod) {
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', '=', $rekod->nokp)
|
||||
->orWhere('kplama', '=', $rekod->nokp)
|
||||
->first();
|
||||
|
||||
$rekodaudit[$index]['customer'] = $customer;
|
||||
|
||||
$rekodaudit[$index]['blasted'] = BlastWasap::on('mysql7')
|
||||
->where('nokp', $rekod->nokp)
|
||||
->where('norujukan', $rekod->norujukan)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->first();
|
||||
|
||||
// 👉 Kira keuntungan (tunggakan sebenar) guna function
|
||||
$upah = $this->kiraupahUjrahOnePercent($kodcaw, $rekod->norujukan);
|
||||
$keuntungan = $upah['ujrah'] + $upah['onepercent'];
|
||||
|
||||
// Save ke dalam rekod
|
||||
$rekodaudit[$index]['tunggakan'] = $this->floorTo5SenFrom2dp($keuntungan);
|
||||
}
|
||||
|
||||
// Summary total
|
||||
$summary = [
|
||||
'totalrekod' => $rekodaudit->count(),
|
||||
'totalberat' => $rekodaudit->sum('berat'),
|
||||
'totalnilaimarhun'=> $rekodaudit->sum('nilaimarhun'),
|
||||
'totalpinjaman' => $rekodaudit->sum('pinjaman'),
|
||||
'totalbakipjm' => $rekodaudit->sum('bakipjm'),
|
||||
'totaltunggakan' => $rekodaudit->sum('tunggakan'),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'rekod' => $rekodaudit,
|
||||
'summary' => $summary,
|
||||
]);
|
||||
}
|
||||
|
||||
public function kiraupahUjrahOnePercent($kodcaw,$norujukan){
|
||||
$onepercentservices = new OnePercentServices();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->first();
|
||||
|
||||
$gadai_data = Gadai::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$norujukan)
|
||||
->first();
|
||||
|
||||
if($gadai_data['tempoh'] >= 12.0){
|
||||
$tempoh = 12;
|
||||
}else{
|
||||
$tempoh = $gadai_data['tempoh'];
|
||||
}
|
||||
|
||||
$bilang_bln = $tempoh - $gadai_data['tempohbayar'];
|
||||
$array_upah = $onepercentservices->kiraanKeuntunganSebenar($gadai_data['pinjaman'],$gadai_data['nilaimarhun'],$gadai_data['kadarupah'],$gadai_data['percentpinj']);
|
||||
$ujrah = $bilang_bln * $array_upah['ujrah'];
|
||||
$onepercent = $bilang_bln * $array_upah['onepercent'];
|
||||
$onepercent_semasa = $onepercent;
|
||||
$ujrah_semasa = $ujrah;
|
||||
|
||||
return ['ujrah' => $ujrah_semasa, 'onepercent' => $onepercent_semasa];
|
||||
}
|
||||
|
||||
// dalam Controller (private/protected)
|
||||
private function floorTo5SenFrom2dp($amount)
|
||||
{
|
||||
// pastikan numeric
|
||||
$amount = (float) $amount;
|
||||
|
||||
// 1) Tukar ke sen dan buang sebarang pecahan sen (hanya baca 2 dp)
|
||||
// tambah epsilon kecil untuk elak isu floating point
|
||||
$cents = (int) floor($amount * 100 + 0.0000001);
|
||||
|
||||
// 2) Floor ke gandaan 5 sen
|
||||
$cents5 = (int) (floor($cents / 5) * 5);
|
||||
|
||||
// balik ke ringgit
|
||||
return $cents5 / 100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -669,11 +669,45 @@ class TebusController extends Controller
|
||||
}
|
||||
|
||||
public function listhistorypenebusan($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
|
||||
|
||||
$listtebus = Tebus::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->get();
|
||||
->where('norujukan', $request->norujukan)
|
||||
->get();
|
||||
|
||||
foreach ($listtebus as $tebus) {
|
||||
// Cari transaction padan berdasarkan norujukan dan trans_type = 'A'
|
||||
$transaction = \DB::connection('mysql7')
|
||||
->table('transaction')
|
||||
->where('norujukan', $tebus->norujukan)
|
||||
->whereIn('trans_type', ['T', 'AT'])
|
||||
->first();
|
||||
|
||||
// Jika wujud, cari transaksi_keuntungan yang padan ikut tarikh
|
||||
if ($transaction) {
|
||||
$createdDate = Carbon::parse($transaction->created_at)->toDateString();
|
||||
|
||||
$keuntungan = \DB::connection('mysql7')
|
||||
->table('transaksi_keuntungan')
|
||||
->where('norujukan', $tebus->norujukan)
|
||||
->whereDate('tarikh_bayaran', $createdDate)
|
||||
->first();
|
||||
|
||||
if ($transaction->trans_type == 'T') {
|
||||
$tebus->bayaran_keuntungan = number_format($keuntungan->keuntungan_rebet ?? 0, 2);
|
||||
} elseif ($transaction->trans_type == 'AT') {
|
||||
$tebus->bayaran_keuntungan = number_format($keuntungan->bayaran_keuntungan ?? 0, 2);
|
||||
}
|
||||
|
||||
$tebus->bayaran_pembiayaan = number_format($keuntungan->bayaran_pembiayaan ?? 0, 2);
|
||||
$tebus->duit_masuk = number_format($transaction->duit_masuk ?? 0, 2);
|
||||
$tebus->trans_type = $transaction->trans_type ?? null;
|
||||
} else {
|
||||
$tebus->bayaran_keuntungan = null;
|
||||
$tebus->bayaran_pembiayaan = null;
|
||||
$tebus->duit_masuk = null;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($listtebus);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,24 @@ class TransactionController extends Controller
|
||||
|
||||
public function getTransactionByRujukan($norujukan){
|
||||
|
||||
$transaction = Transaction::on('mysql7')->where([['norujukan','=',$norujukan],['trans_type','=','A']])->get();
|
||||
$transactions = Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->get();
|
||||
|
||||
return response()->json($transaction);
|
||||
foreach ($transactions as $transaction) {
|
||||
$createdDate = Carbon::parse($transaction->created_at)->toDateString();
|
||||
|
||||
$keuntungan = \DB::connection('mysql7')
|
||||
->table('transaksi_keuntungan')
|
||||
->whereDate('tarikh_bayaran', $createdDate)
|
||||
->where('norujukan', $transaction->norujukan)
|
||||
->first(); // ambil seluruh rekod
|
||||
|
||||
$transaction->bayaran_keuntungan = number_format($keuntungan->bayaran_keuntungan ?? 0, 2);
|
||||
$transaction->bayaran_pembiayaan = number_format($keuntungan->bayaran_pembiayaan ?? 0, 2);
|
||||
}
|
||||
return response()->json($transactions);
|
||||
}
|
||||
|
||||
public function getTransactionByid($id){
|
||||
|
||||
@@ -25,8 +25,7 @@ class TransactionOnlineController extends Controller
|
||||
{
|
||||
public function getTransactionOnline(Request $request)
|
||||
{
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id', $request->billplz_id)->first();
|
||||
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('norujukan',$request->norujukan)->where('billplz_id', $request->billplz_id)->first();
|
||||
return response()->json($transactionOnline);
|
||||
}
|
||||
|
||||
@@ -117,6 +116,13 @@ class TransactionOnlineController extends Controller
|
||||
$transactions = TransactionOnline::on('mysql7')->where([['status', '=', 'PAID'], ['update_status', 0]])->get();
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$checkTime = $this->checkTime();
|
||||
|
||||
if($checkTime == 'rejected'){
|
||||
return response()->json('rejected-time');
|
||||
}
|
||||
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', '=', $transaction['kodcaw'])
|
||||
@@ -138,6 +144,7 @@ class TransactionOnlineController extends Controller
|
||||
'descpt' => 'SERAHAN BAYAR ONLINE - ' . $transaction['norujukan'],
|
||||
'serahan' => $transaction['total_payment'],
|
||||
'teller' => 'ONLINE',
|
||||
'date_created' => $current
|
||||
];
|
||||
|
||||
try {
|
||||
@@ -451,8 +458,10 @@ class TransactionOnlineController extends Controller
|
||||
$ujrah_calculation = $this->getUjrah($kodcaw, $norujukan);
|
||||
|
||||
$onepercent = new Calculation();
|
||||
$ujrahasal = $onepercent->getRoundedMethod($ujrahasal);
|
||||
$onepercentasal = $onepercent->getRoundedMethod($onepercentasal);
|
||||
$ujrah = $onepercent->getRoundedMethod($ujrahasal * $bilang_bln);
|
||||
$ujrah_rebate = $onepercent->getRoundedMethod($ujrah_calculation['ujrah_sebenar'] - $ujrah_calculation['ujrah_rebet']);
|
||||
$ujrah_rebate = $onepercent->getRoundedMethod($keuntungan['ujrah'] * $bilang_bln);
|
||||
$keun = $onepercent->getRoundedMethod($onepercentasal * $bilang_bln);
|
||||
$keuntungan_rebate = $onepercent->getRoundedMethod($keuntungan['onepercent'] * $bilang_bln);
|
||||
|
||||
@@ -745,5 +754,21 @@ class TransactionOnlineController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function checkTime(){
|
||||
$current = Carbon::now();
|
||||
|
||||
$startRange1 = Carbon::today()->setTime(19, 0);
|
||||
$endRange1 = Carbon::today()->setTime(19, 30);
|
||||
|
||||
$startRange2 = Carbon::today()->setTime(23, 0);
|
||||
$endRange2 = Carbon::today()->setTime(23, 30);
|
||||
|
||||
if ($current->between($startRange1, $endRange1) || $current->between($startRange2, $endRange2)) {
|
||||
return 'rejected';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ use App\Vault;
|
||||
use App\Cawangan;
|
||||
use App\Tunai;
|
||||
use App\AddTunai;
|
||||
use App\ApprovalWithdrawal;
|
||||
use App\Audit;
|
||||
use App\DenoPendSer;
|
||||
use App\GlDetail;
|
||||
use App\imbangdugalama;
|
||||
use App\GlCode;
|
||||
@@ -14,6 +16,7 @@ use App\Tebus;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class VaultController extends Controller
|
||||
{
|
||||
@@ -283,7 +286,8 @@ class VaultController extends Controller
|
||||
'ktacct' => '1000/010',
|
||||
'descpt' => 'SERAHAN BAYAR ONLINE',
|
||||
'serahan' => $request->amaun,
|
||||
'teller' => 'ONLINE'
|
||||
'teller' => 'ONLINE',
|
||||
'date_created' => $current
|
||||
]);
|
||||
|
||||
// $audit = new Audit();
|
||||
@@ -314,7 +318,8 @@ class VaultController extends Controller
|
||||
'ktacct' => $request->ktacct,
|
||||
'descpt' => $request->keterangan,
|
||||
'pendahuluan' => $request->amaun,
|
||||
'teller' => $request->teller
|
||||
'teller' => $request->teller,
|
||||
'date_created' => $current
|
||||
]);
|
||||
}else if($request->jenisgldetail == 'serahan')
|
||||
{
|
||||
@@ -325,7 +330,9 @@ class VaultController extends Controller
|
||||
'ktacct' => $request->ktacct,
|
||||
'descpt' => $request->keterangan,
|
||||
'serahan' => $request->amaun,
|
||||
'teller' => $request->teller
|
||||
'teller' => $request->teller,
|
||||
'date_created' => $current
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -718,6 +725,4 @@ class VaultController extends Controller
|
||||
return response()->json($vault);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MohonAnggota extends Model
|
||||
{
|
||||
protected $table = 'mohon_anggota';
|
||||
protected $connection = 'mysql7';
|
||||
|
||||
protected $fillable = [
|
||||
'tarikh', 'nokp', 'status', 'komen', 'siri', 'teller', 'pelulus', 'peloperasi'
|
||||
];
|
||||
}
|
||||
+11
-1
@@ -27,7 +27,17 @@ class Mohonid extends Model
|
||||
'nilaimarhun',
|
||||
'berat',
|
||||
'margin',
|
||||
'teller'
|
||||
'teller',
|
||||
'masa',
|
||||
'tagoperasi',
|
||||
'ansuran',
|
||||
'operasi',
|
||||
'timestamp_approved_by_pc',
|
||||
'timestamp_approved_by_operasi',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use App\Audit;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Palsu extends Model
|
||||
{
|
||||
protected $table = 'palsu';
|
||||
protected $primaryKey = 'recno';
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'recno',
|
||||
'kodcaw',
|
||||
'norujukan',
|
||||
'teller',
|
||||
'nota',
|
||||
'nilaimarhun',
|
||||
'jbg',
|
||||
'untung',
|
||||
'untungonepercent',
|
||||
'untungcajlain',
|
||||
'pembiayaan',
|
||||
];
|
||||
|
||||
// public static function boot()
|
||||
// {
|
||||
// parent::boot();
|
||||
|
||||
// $current = Carbon::now();
|
||||
// $current = new Carbon();
|
||||
|
||||
// static::created(function (Poskod $poskod) use($current){
|
||||
|
||||
// Audit::create([
|
||||
// 'users' => request()->all()['user']['name'],
|
||||
// 'actions' => 'Tambah poskod',
|
||||
// 'norujukan' => $poskod->recno,
|
||||
// 'new_data' => $poskod->toJson(),
|
||||
// 'old_data' => '',
|
||||
// 'kodcaw' => request()->all()['user']['cawangan'],
|
||||
// 'created_at' => $current,
|
||||
// 'updated_at' => $current,
|
||||
// ]);
|
||||
|
||||
// });
|
||||
|
||||
|
||||
// static::updated(function (Poskod $poskod) use($current) {
|
||||
|
||||
// Audit::create([
|
||||
// 'users' => request()->all()['user']['name'],
|
||||
// 'actions' => 'Kemaskini poskod',
|
||||
// 'norujukan' => $poskod->recno,
|
||||
// 'new_data' => $poskod->toJson(),
|
||||
// 'old_data' => json_encode($poskod->getOriginal()),
|
||||
// 'kodcaw' => request()->all()['user']['cawangan'],
|
||||
// 'created_at' => $current,
|
||||
// 'updated_at' => $current,
|
||||
// ]);
|
||||
|
||||
// });
|
||||
// }
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [],
|
||||
|
||||
// public function negeri(): BelongsTo
|
||||
// {
|
||||
// return $this->belongsTo(Negeri::class, 'kodnegeri', 'kodnegeri');
|
||||
// }
|
||||
|
||||
// public function daerah(): BelongsTo
|
||||
// {
|
||||
// return $this->belongsTo(Daerah::class, 'koddaerah', 'koddaerah');
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Penyelarasan extends Model
|
||||
{
|
||||
protected $table = 'penyelarasan';
|
||||
// public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'kodcaw',
|
||||
'rugilelong',
|
||||
'bakilelong',
|
||||
'lain-lain',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\QueryBuilders;
|
||||
|
||||
use App\TransactionOnline;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransactionOnlineBuilder extends Builder
|
||||
{
|
||||
public function filter(Request $request)
|
||||
{
|
||||
return $this->with('cawangan')
|
||||
->whereDatePaidBetween($request)
|
||||
->when($request->filled('kodcaw'), fn($query) => $query->whereCawanganCode($request->kodcaw))
|
||||
->when($request->filled('status'), fn($query) => $query->whereStatus($request->status))
|
||||
->when($request->isNotFilled('status'), fn($query) => $query->whereStatus('PAID'))
|
||||
->when($request->filled('orderBy'), fn($query) => $query->orderByColumn($request->orderBy));
|
||||
}
|
||||
|
||||
public function whereDatePaidBetween(Request $request): self
|
||||
{
|
||||
$startDate = $request->filled('startDate') ?
|
||||
Carbon::parse($request->startDate)->startOfDay() :
|
||||
Carbon::now()->startOfDay();
|
||||
|
||||
$endDate = $request->filled('endDate') ?
|
||||
Carbon::parse($request->endDate)->endOfDay() :
|
||||
Carbon::now()->endOfDay();
|
||||
|
||||
return $this->whereBetween('paid_at', [$startDate, $endDate]);
|
||||
}
|
||||
|
||||
public function whereCawanganCode(string $kodcaw): self
|
||||
{
|
||||
return $this->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
public function whereStatus(string $status): self
|
||||
{
|
||||
return $this->where('status', $status);
|
||||
}
|
||||
|
||||
public function orderByColumn(string $orderBy): self
|
||||
{
|
||||
return $this->orderBy($orderBy, 'desc');
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,8 @@ class OnePercentServices
|
||||
$formula_margin = ($this->maks_margin - $margin) / $this->maks_margin;
|
||||
$ujrah_margin = $formula_margin * $kadarujrah;
|
||||
$rebate_ujrah = $nilaimarhun*($ujrah_margin/100);
|
||||
$ujrah_sebenar = $ujrah;
|
||||
// $ujrah_sebenar = $ujrah;
|
||||
$ujrah_sebenar = $ujrah - $rebate_ujrah;
|
||||
|
||||
return $ujrah_sebenar;
|
||||
}
|
||||
@@ -57,6 +58,9 @@ class OnePercentServices
|
||||
$onepercent = $this->kiraanOnePercent($pembiayaan);
|
||||
$ujrah_sebenar = $this->kiraanUjrahSebenar($nilaimarhun,$kadarujrah,$margin);
|
||||
|
||||
$onepercent = (!empty($onepercent)) ? $this->getRoundedMethod($onepercent) : 0;
|
||||
$ujrah_sebenar = (!empty($ujrah_sebenar)) ? $this->getRoundedMethod($ujrah_sebenar) : 0;
|
||||
|
||||
$keuntungan = $onepercent + $ujrah_sebenar;
|
||||
|
||||
return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar];
|
||||
@@ -67,6 +71,9 @@ class OnePercentServices
|
||||
$onepercent = $this->kiraanOnePercent($pembiayaan);
|
||||
$ujrah_sebenar = $this->kiraanUjrah($nilaimarhun,$kadarujrah,$margin);
|
||||
|
||||
$onepercent = (!empty($onepercent)) ? $this->getRoundedMethod($onepercent) : 0;
|
||||
$ujrah_sebenar = (!empty($ujrah_sebenar)) ? $this->getRoundedMethod($ujrah_sebenar) : 0;
|
||||
|
||||
$keuntungan = $onepercent + $ujrah_sebenar;
|
||||
|
||||
return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar];
|
||||
@@ -78,4 +85,26 @@ class OnePercentServices
|
||||
|
||||
return isset($kadarujrah[0]) ? $kadarujrah[0]['kadarujrah'] : 0;
|
||||
}
|
||||
|
||||
public function getRoundedMethod(float $number = 0.0) : Float{
|
||||
$number_string = number_format(floor($number * 100)/100,2);
|
||||
|
||||
$rounded = substr($number_string, 0, -1);
|
||||
$lastDigit = substr($number_string, -1);
|
||||
|
||||
if ($lastDigit >= 0 && $lastDigit <= 2) {
|
||||
if(strpos($rounded,',')){
|
||||
$rounded = str_replace(',','',$rounded);
|
||||
}
|
||||
return $rounded;
|
||||
} elseif ($lastDigit >= 3 && $lastDigit <= 7) {
|
||||
$rounded = $rounded . '5';
|
||||
if(strpos($rounded,',')){
|
||||
$rounded = str_replace(',','',$rounded);
|
||||
}
|
||||
return $rounded;
|
||||
} else {
|
||||
return round($number,PHP_ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,7 +518,7 @@ class GeneralLedger
|
||||
$mulaCarbon = new Carbon($this->mula);
|
||||
$hinggaCarbon = new Carbon($this->hingga);
|
||||
|
||||
if($this->isFullMonth($this->mula,$this->hingga) && $mulaCarbon->month < 10){
|
||||
if($this->isFullMonth($this->mula,$this->hingga) && $mulaCarbon->month < 10 && $mulaCarbon->year == 2024){
|
||||
$lastDayOfPreviousMonth = $mulaCarbon->subMonth()->endOfMonth();
|
||||
|
||||
$balancesheet_previousmonth = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayOfPreviousMonth->toDateString())->first()->toArray();
|
||||
@@ -714,7 +714,7 @@ class GeneralLedger
|
||||
$t_gadai = Carbon::parse($gadai->t_gadai);
|
||||
$t_bayaran = Carbon::parse($trans->tarikh_bayaran);
|
||||
|
||||
if ($t_gadai->month === $t_bayaran->month) {
|
||||
if ($t_gadai->month === $t_bayaran->month && $t_gadai->year === $t_bayaran->year) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
|
||||
@@ -61,6 +61,18 @@ class AnsuranService
|
||||
];
|
||||
});
|
||||
|
||||
// **Tidak Group By Teller** untuk keseluruhan laporan
|
||||
$total_ansuran_keseluruhan = $total_ansuran->map(function ($ansuran) {
|
||||
return [
|
||||
'norujukan' => $ansuran['norujukan'],
|
||||
'nama' => $ansuran['nama'],
|
||||
'no_kp' => $ansuran['no_kp'],
|
||||
'bayaran_pembiayaan' => $ansuran['bayaran_pembiayaan'],
|
||||
'bayaran_keuntungan' => $ansuran['bayaran_keuntungan'],
|
||||
'jumlah_ansuran' => $ansuran['jumlah_ansuran'],
|
||||
];
|
||||
});
|
||||
|
||||
$total_ansuran = $total_ansuran->groupBy('teller');
|
||||
|
||||
$ansuran_tellers = $total_ansuran->keys();
|
||||
@@ -86,6 +98,7 @@ class AnsuranService
|
||||
],
|
||||
'cawangan_detail' => $cawangan_detail,
|
||||
'total_ansuran' => $total_ansuran,
|
||||
'total_ansuran_keseluruhan' => $total_ansuran_keseluruhan, // Tambahkan keseluruhan laporan
|
||||
'summary_ansuran' => $total_summary_ansuran,
|
||||
];
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Marhun;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GadaianService
|
||||
{
|
||||
@@ -191,4 +192,213 @@ class GadaianService
|
||||
|
||||
return $marhun_gadaian;
|
||||
}
|
||||
|
||||
public function getCawanganReportGadaiTebusMasa()
|
||||
{
|
||||
$cawangan_connection = Cawangan::where('kodcaw', $this->kod_cawangan)->firstOrFail()->mysql;
|
||||
$online_connection = Helper::getOnlineArrahnConnection();
|
||||
$startDate = $this->startDate;
|
||||
$endDate = $this->endDate;
|
||||
|
||||
// 1. Ambil data gadai dari cawangan
|
||||
$gadai_data = DB::connection($cawangan_connection)->table('gadai')
|
||||
->whereBetween('t_gadai', [$startDate, $endDate])
|
||||
->get();
|
||||
|
||||
if ($gadai_data->isEmpty()) {
|
||||
return response()->json([
|
||||
'query' => [
|
||||
'startDate' => Helper::formatDate($startDate),
|
||||
'endDate' => Helper::formatDate($endDate),
|
||||
],
|
||||
'cawangan_detail' => $this->getCawanganDetail($cawangan_connection),
|
||||
'gadaian' => [],
|
||||
'summary_gadaian' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Ambil norujukan & tarikh dari gadai
|
||||
$norujukans = $gadai_data->pluck('norujukan')->unique();
|
||||
$tarikh_set = $gadai_data->pluck('t_gadai')->map(fn($d) => date('Y-m-d', strtotime($d)))->unique();
|
||||
|
||||
// 3. Ambil transaksi tebus dari online server
|
||||
$transaksi_tebus = DB::connection($online_connection)->table('transaction')
|
||||
->whereIn('trans_type', ['T', 'AT'])
|
||||
->whereIn('norujukan', $norujukans)
|
||||
->whereIn(DB::raw('DATE(created_at)'), $tarikh_set)
|
||||
->get()
|
||||
->groupBy(fn($trans) => $trans->norujukan . '|' . date('Y-m-d', strtotime($trans->created_at)));
|
||||
|
||||
// 4. Padankan
|
||||
$matched = collect();
|
||||
|
||||
foreach ($gadai_data as $item) {
|
||||
$tarikh = date('Y-m-d', strtotime($item->t_gadai));
|
||||
$key = $item->norujukan . '|' . $tarikh;
|
||||
|
||||
if ($transaksi_tebus->has($key)) {
|
||||
$trans = $transaksi_tebus[$key]->first(); // satu transaksi je
|
||||
|
||||
$masa_gadai = $item->masa;
|
||||
$masa_tebus = date('H:i:s', strtotime($trans->created_at));
|
||||
$beza_saat = abs(strtotime($masa_tebus) - strtotime($masa_gadai));
|
||||
$beza_masa = gmdate("H:i:s", $beza_saat);
|
||||
|
||||
$matched->push((object)[
|
||||
't_gadai' => $item->t_gadai,
|
||||
'norujukan' => $item->norujukan,
|
||||
'nokp' => $item->nokp,
|
||||
'semakbarcode' => $item->semakbarcode,
|
||||
'masa' => $masa_gadai,
|
||||
'masa_tebus' => $masa_tebus,
|
||||
'beza_minit' => $beza_masa,
|
||||
'berat' => $item->berat,
|
||||
'nilaimarhun' => $item->nilaimarhun,
|
||||
'pinjaman' => $item->pinjaman,
|
||||
'upah12' => $item->upah12,
|
||||
'percentpinj' => $item->percentpinj,
|
||||
'teller' => $item->teller,
|
||||
'bakipjm' => $item->bakipjm,
|
||||
'bakiupah' => $item->bakiupah,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Data tambahan
|
||||
$customer_info = $this->getCustomerInfo($matched);
|
||||
$marhun_info = $this->getMarhunGadaiTebusMasa($matched, $cawangan_connection);
|
||||
$cawangan_detail = $this->getCawanganDetail($cawangan_connection);
|
||||
$summary = $this->getTotalSummaryGadaiTebusMasa($matched);
|
||||
|
||||
// 6. Gabung akhir
|
||||
$report_data = $matched->zip($customer_info, $marhun_info)->map(function ($data) {
|
||||
[$gadai, $customer, $marhun] = $data;
|
||||
|
||||
return [
|
||||
'no_rujukan' => $gadai->norujukan,
|
||||
'nama' => $customer['nama'] ?? '-',
|
||||
'alamat' => $customer['alamat1'] ?? '-',
|
||||
'no_kp' => $gadai->nokp,
|
||||
'masa' => $gadai->masa,
|
||||
'masa_tebus' => $gadai->masa_tebus,
|
||||
'beza_minit' => $gadai->beza_minit,
|
||||
'marhun' => $marhun,
|
||||
'berat' => $gadai->berat,
|
||||
'nilai_marhun' => $gadai->nilaimarhun,
|
||||
'pinjaman' => $gadai->pinjaman,
|
||||
'peratusan_margin_pinjaman' => $gadai->percentpinj,
|
||||
'bakipjm' => $gadai->bakipjm,
|
||||
'keuntungan' => $gadai->bakiupah,
|
||||
'teller' => $gadai->teller,
|
||||
't_gadai' => $gadai->t_gadai,
|
||||
];
|
||||
});
|
||||
|
||||
$report_data = $report_data->sortBy(function ($item) {
|
||||
list($hours, $minutes, $seconds) = explode(':', $item['beza_minit']);
|
||||
return ((int)$hours * 3600) + ((int)$minutes * 60) + (int)$seconds;
|
||||
})->values();
|
||||
|
||||
return response()->json([
|
||||
'query' => [
|
||||
'startDate' => Helper::formatDate($startDate),
|
||||
'endDate' => Helper::formatDate($endDate),
|
||||
],
|
||||
'cawangan_detail' => $cawangan_detail,
|
||||
'gadaian' => $report_data,
|
||||
'summary_gadaian' => $summary,
|
||||
]);
|
||||
}
|
||||
|
||||
private function formatBezaMinit($minit)
|
||||
{
|
||||
if (is_null($minit)) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
$abs = abs($minit);
|
||||
$jam = floor($abs / 60);
|
||||
$baki = $abs % 60;
|
||||
$tanda = $minit < 0 ? '-' : '';
|
||||
|
||||
return "{$tanda}{$jam} jam {$baki} minit";
|
||||
}
|
||||
|
||||
|
||||
private function getTotalGadaiTebusMasa($query_total_gadaitebusmasa)
|
||||
{
|
||||
$total_gadaitebusmasa = (clone $query_total_gadaitebusmasa)
|
||||
->select('gadai.t_gadai',
|
||||
'gadai.norujukan',
|
||||
'gadai.nokp',
|
||||
'gadai.semakbarcode',
|
||||
'gadai.masa',
|
||||
'gadai.berat',
|
||||
'gadai.nilaimarhun',
|
||||
'gadai.pinjaman',
|
||||
'gadai.upah12',
|
||||
'gadai.percentpinj',
|
||||
'gadai.teller',
|
||||
'gadai.nokp',
|
||||
'gadai.bakipjm',
|
||||
'gadai.bakiupah',
|
||||
DB::raw('TIMEDIFF(TIME(trans.created_at), gadai.masa) as beza_minit'))
|
||||
->where('gadai.upah12', '>=', 0.00)
|
||||
->orderBy('gadai.teller')
|
||||
->orderBy('gadai.sirig')
|
||||
->get();
|
||||
return $total_gadaitebusmasa;
|
||||
}
|
||||
|
||||
private function getTotalSummaryGadaiTebusMasa($collection)
|
||||
{
|
||||
return [
|
||||
'total_gadaitebusmasa' => $collection->count(),
|
||||
'total_berat' => $collection->sum('berat'),
|
||||
'total_nilai_marhun' => $collection->sum('nilaimarhun'),
|
||||
'total_pembiayaan' => $collection->sum('pinjaman'),
|
||||
'total_bakipjm' => $collection->sum('bakipjm'),
|
||||
'total_keuntungan' => $collection->sum('bakiupah'),
|
||||
];
|
||||
}
|
||||
|
||||
private function getTotalSummaryGadaiTebusMasaGroupByTeller($query_total_gadaitebusmasa)
|
||||
{
|
||||
|
||||
$total_summary_gadaian_groupByTeller = (clone $query_total_gadaitebusmasa)
|
||||
->selectRaw('count(gadai.norujukan) as total_gadaitebusmasa,
|
||||
sum(gadai.berat) as total_berat,
|
||||
sum(gadai.nilaimarhun) as total_nilai_marhun,
|
||||
sum(gadai.pinjaman) as total_pembiayaan,
|
||||
sum(gadai.bakipjm) as total_bakipjm,
|
||||
sum(gadai.bakiupah) as total_keuntungan')
|
||||
->where('gadai.upah12', '>=', 0.00)
|
||||
->groupBy('gadai.teller')
|
||||
->get();
|
||||
return $total_summary_gadaian_groupByTeller;
|
||||
}
|
||||
|
||||
private function getMarhunGadaiTebusMasa($total_gadaitebusmasa, $cawangan_connection)
|
||||
{
|
||||
|
||||
$extract_norujukan = $total_gadaitebusmasa->pluck('norujukan');
|
||||
|
||||
$marhun_gadaitebusmasa = Marhun::on($cawangan_connection)
|
||||
->select('norujukan', 'bil', 'marhun')
|
||||
->whereIn('norujukan', $extract_norujukan)
|
||||
->get()
|
||||
->groupBy('norujukan')
|
||||
->toArray();
|
||||
|
||||
$marhun_gadaitebusmasa = array_map(function ($gadaian) {
|
||||
return array_map(function ($norujukan) {
|
||||
return $norujukan['bil'] . ' ' . $norujukan['marhun'];
|
||||
}, $gadaian);
|
||||
}, $marhun_gadaitebusmasa);
|
||||
|
||||
$marhun_gadaitebusmasa = array_map(function ($gadaian) {
|
||||
return implode(',', $gadaian);
|
||||
}, $marhun_gadaitebusmasa);
|
||||
return $marhun_gadaitebusmasa;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ class ImbangDugaService
|
||||
$t_gadai = Carbon::parse($gadai->t_gadai);
|
||||
$t_bayaran = Carbon::parse($trans->tarikh_bayaran);
|
||||
|
||||
if ($t_gadai->month === $t_bayaran->month) {
|
||||
if ($t_gadai->month === $t_bayaran->month && $t_gadai->year === $t_bayaran->year) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
@@ -239,8 +239,17 @@ class ImbangDugaService
|
||||
$ujrah_rebet = $this->filterCollection($keuntungan_semasa_collection, 'T', 'ujrah_rebet');
|
||||
$onepercent_rebet = $this->filterCollection($keuntungan_semasa_collection, 'T', 'onepercent_rebet');
|
||||
|
||||
$total_onepercent = $onepercent + $onepercent_rebet;
|
||||
$total_ujrah = $ujrah + $ujrah_rebet;
|
||||
$upahlelong = Lelong::on($cawangan['mysql'])
|
||||
->selectRaw('SUM(ujrah) as ujrah,SUM(onepercent) as onepercent')
|
||||
->where([['tagujrah','=',1],['t_jual','>=',$start],['t_jual','<=',$end]])
|
||||
->whereYear('t_jual','=',$year)
|
||||
->get()->toArray();
|
||||
|
||||
$ujrah_lelong = (empty($upahlelong)) ? 0 : $upahlelong[0]['ujrah'];
|
||||
$onepercent_lelong = (empty($upahlelong)) ? 0 : $upahlelong[0]['onepercent'];
|
||||
|
||||
$total_onepercent = $onepercent + $onepercent_rebet + $onepercent_lelong;
|
||||
$total_ujrah = $ujrah + $ujrah_rebet + $ujrah_lelong;
|
||||
|
||||
return ['ujrah' => $total_ujrah, 'onepercent' => $total_onepercent];
|
||||
}
|
||||
@@ -318,8 +327,17 @@ class ImbangDugaService
|
||||
$month = (clone $tarikh)->month;
|
||||
|
||||
$lastDayPreviousMonth = $tarikh->subMonthsNoOverflow()->endOfMonth()->toDateString();
|
||||
$lastEndYear = $tarikh->subMonthsNoOverflow()->endOfMonth();
|
||||
$lastYear = Carbon::now()->subYear()->year;
|
||||
|
||||
$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayPreviousMonth)->first()->toArray();
|
||||
//$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayPreviousMonth)->first()->toArray();
|
||||
|
||||
/* Added because if the last month is not the same year */
|
||||
if($lastEndYear->year != $lastYear){
|
||||
$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayPreviousMonth)->first()->toArray();
|
||||
}else{
|
||||
$get_imbangduga['keun_sebenar'] = 0;
|
||||
}
|
||||
|
||||
$collection_trans = Transaction::on('mysql7')
|
||||
->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
@@ -608,6 +626,51 @@ class ImbangDugaService
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
if($this->kodcaw == 'GC'){
|
||||
$transaksi_data = [];
|
||||
TransaksiKeuntungan::on('mysql7')
|
||||
->where('tarikh_bayaran', '<=', $daterequest)
|
||||
->where('kodcaw', $this->kodcaw)
|
||||
->chunk(1000, function ($transactions) use (&$transaksi_data) {
|
||||
$transaksi_data = array_merge($transaksi_data, $transactions->pluck('norujukan')->toArray());
|
||||
});
|
||||
|
||||
$gadaiData = [];
|
||||
$chunkedTransaksiData = array_chunk($transaksi_data, 1000);
|
||||
|
||||
foreach ($chunkedTransaksiData as $chunk) {
|
||||
Gadai::on($cawangan['mysql'])
|
||||
->whereIn('norujukan', $chunk)
|
||||
->where(function ($query) {
|
||||
$query->where([
|
||||
['sttebus', '=', ''],
|
||||
['hargajualan', '<>', null]
|
||||
])
|
||||
->orWhere([
|
||||
['sttebus', '!=', ''],
|
||||
['t_update', '>', $this->tarikh],
|
||||
['hargajualan', '<>', null]
|
||||
]);
|
||||
})
|
||||
->orderBy('norujukan')
|
||||
->chunk(1000, function ($gadaiChunk) use (&$gadaiData) {
|
||||
$gadaiData = array_merge($gadaiData, $gadaiChunk->pluck('norujukan')->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
$totalPembiayaan = 0;
|
||||
$chunkedGadaiData = array_chunk($gadaiData, 1000);
|
||||
|
||||
foreach ($chunkedGadaiData as $chunk) {
|
||||
$totalPembiayaan += TransaksiKeuntungan::on('mysql7')
|
||||
->whereIn('norujukan', $chunk)
|
||||
->where('tarikh_bayaran', '<=', $daterequest)
|
||||
->sum('bayaran_pembiayaan');
|
||||
}
|
||||
|
||||
return $totalPembiayaan;
|
||||
}
|
||||
|
||||
$transaksi_data = TransaksiKeuntungan::on('mysql7')
|
||||
->where('tarikh_bayaran' ,'<=', $daterequest)
|
||||
->where('kodcaw',$this->kodcaw)
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\CawanganDetail;
|
||||
use App\Customer;
|
||||
use App\Lelong;
|
||||
use App\Marhun;
|
||||
use App\LelMarhun;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
|
||||
class LelonganService
|
||||
{
|
||||
|
||||
public $kod_cawangan;
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
|
||||
public function __construct($kod_cawangan, Request $request)
|
||||
{
|
||||
$this->kod_cawangan = $kod_cawangan;
|
||||
$this->startDate = $request->startDate;
|
||||
$this->endDate = $request->endDate;
|
||||
}
|
||||
|
||||
public function getCawanganReport()
|
||||
{
|
||||
$cawangan_connection = Cawangan::where('kodcaw', $this->kod_cawangan)->first()->mysql;
|
||||
|
||||
$query_total_lelongan = Lelong::on($cawangan_connection)
|
||||
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan') // Joining gadai table
|
||||
->select(
|
||||
'lelong.norujukan',
|
||||
'gadai.nokp',
|
||||
'gadai.masa',
|
||||
'lelong.berat',
|
||||
'lelong.nilaimarhun',
|
||||
'gadai.pinjaman',
|
||||
'gadai.percentpinj',
|
||||
'lelong.teller',
|
||||
'gadai.bakipjm', // Fetch pinjaman from gadai
|
||||
'gadai.marhun' // Fetch marhun from gadai
|
||||
);
|
||||
|
||||
$query_total_lelongan->when(!empty($this->startDate) and !empty($this->endDate), function ($q) {
|
||||
return $q->where('lelong.t_jual', '>=', $this->startDate)
|
||||
->where('lelong.t_jual', '<=', $this->endDate);
|
||||
});
|
||||
|
||||
$total_lelongan = $this->getTotalLelongan($query_total_lelongan);
|
||||
// dd($total_lelongan);
|
||||
$total_summary_lelongan_teller = $this->getTotalSummaryLelonganGroupByTeller($query_total_lelongan);
|
||||
$total_summary_lelongan = $this->getTotalSummaryLelongan($query_total_lelongan);
|
||||
$customer_info = $this->getCustomerInfo($total_lelongan);
|
||||
$marhun_lelongan = $this->getMarhunLelongan($total_lelongan, $cawangan_connection);
|
||||
$cawangan_detail = $this->getCawanganDetail($cawangan_connection);
|
||||
|
||||
$total_lelongan = $total_lelongan->zip($customer_info, $marhun_lelongan)->map(function ($data) {
|
||||
|
||||
[$lelong, $customer_info, $marhun_lelongan] = $data;
|
||||
|
||||
return [
|
||||
'no_rujukan' => $lelong['norujukan'],
|
||||
'nama' => $customer_info['nama'],
|
||||
'alamat' => $customer_info['alamat1'],
|
||||
'no_kp' => $lelong['nokp'],
|
||||
'masa' => $lelong['masa'],
|
||||
'marhun' => $marhun_lelongan,
|
||||
'berat' => $lelong['berat'],
|
||||
'nilai_marhun' => $lelong['nilaimarhun'],
|
||||
'pinjaman' => $lelong['pinjaman'],
|
||||
'peratusan_margin_pinjaman' => $lelong['percentpinj'],
|
||||
'bakipjm' => $lelong['bakipjm'],
|
||||
'keuntungan' => $lelong['bakiupah'],
|
||||
'cajlelong' => $lelong['cajlelong'],
|
||||
'hargajual' => $lelong['hargajual'],
|
||||
'baki' => $lelong['baki'],
|
||||
'teller' => $lelong['teller'],
|
||||
];
|
||||
dd($data);
|
||||
});
|
||||
|
||||
|
||||
$total_lelongan = $total_lelongan->groupBy('teller');
|
||||
|
||||
$lelongan_tellers = $total_lelongan->keys();
|
||||
|
||||
$total_lelongan = $total_lelongan
|
||||
->zip($total_summary_lelongan_teller)
|
||||
->map(function ($data) {
|
||||
|
||||
[$lelongan, $summary] = $data;
|
||||
|
||||
return [
|
||||
'lelongan' => $lelongan,
|
||||
'summary_lelongan_teller' => $summary,
|
||||
];
|
||||
});
|
||||
|
||||
$total_lelongan = $lelongan_tellers->combine($total_lelongan);
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
'startDate' => Helper::formatDate($this->startDate),
|
||||
'endDate' => Helper::formatDate($this->endDate),
|
||||
],
|
||||
'cawangan_detail' => $cawangan_detail,
|
||||
'lelongan' => $total_lelongan,
|
||||
'summary_lelongan' => $total_summary_lelongan,
|
||||
];
|
||||
|
||||
return json_encode($data);
|
||||
|
||||
}
|
||||
|
||||
private function getCawanganDetail($cawangan_connection)
|
||||
{
|
||||
$cawangan_detail = CawanganDetail::on($cawangan_connection)->get()
|
||||
->map(function ($detail) {
|
||||
return [
|
||||
'nama' => $detail['namacaw'],
|
||||
'code' => $detail['kodcaw'] . ' Ar-Rahn ' . $detail['cawangan'],
|
||||
'alamat' => $detail['alamat1'],
|
||||
'waktu_operasi' => $detail['alamat4'],
|
||||
];
|
||||
});
|
||||
|
||||
return $cawangan_detail[0];
|
||||
|
||||
}
|
||||
|
||||
private function getTotalSummaryLelongan(Builder $query_total_lelongan)
|
||||
{
|
||||
|
||||
$total_summary_lelongan = (clone $query_total_lelongan)
|
||||
->selectRaw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as total_berat,
|
||||
sum(lelong.nilaimarhun) as total_nilai_marhun,
|
||||
sum(lelong.pinjaman) as total_pembiayaan,
|
||||
sum(gadai.bakipjm) as total_bakipjm,
|
||||
sum(lelong.bakiupah) as total_keuntungan,
|
||||
sum(lelong.cajlelong) as total_cajlelong,
|
||||
sum(lelong.hargajual) as total_hargajual,
|
||||
sum(lelong.baki) as total_baki')
|
||||
->get()
|
||||
->map(function ($x) {
|
||||
return [
|
||||
'total_lelongan' => $x['total_lelongan'],
|
||||
'total_berat' => $x['total_berat'],
|
||||
'total_nilai_marhun' => $x['total_nilai_marhun'],
|
||||
'total_pembiayaan' => $x['total_pembiayaan'],
|
||||
'total_bakipjm' => $x['total_bakipjm'],
|
||||
'total_keuntungan' => $x['total_keuntungan'],
|
||||
'total_cajlelong' => $x['total_cajlelong'],
|
||||
'total_hargajual' => $x['total_hargajual'],
|
||||
'total_baki' => $x['total_baki']
|
||||
];
|
||||
});
|
||||
// dd($total_summary_lelongan);
|
||||
|
||||
return $total_summary_lelongan[0];
|
||||
}
|
||||
private function getTotalSummaryLelonganGroupByTeller(Builder $query_total_lelongan)
|
||||
{
|
||||
|
||||
$total_summary_lelongan_groupByTeller = (clone $query_total_lelongan)
|
||||
->selectRaw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as total_berat,
|
||||
sum(lelong.nilaimarhun) as total_nilai_marhun,
|
||||
sum(lelong.pinjaman) as total_pembiayaan,
|
||||
sum(gadai.bakipjm) as total_bakipjm,
|
||||
sum(lelong.bakiupah) as total_keuntungan,
|
||||
sum(lelong.cajlelong) as total_cajlelong,
|
||||
sum(lelong.hargajual) as total_hargajual,
|
||||
sum(lelong.baki) as total_baki')
|
||||
->groupBy('lelong.teller')
|
||||
->get();
|
||||
return $total_summary_lelongan_groupByTeller;
|
||||
}
|
||||
|
||||
private function getTotalLelongan(Builder $query_total_lelongan)
|
||||
{
|
||||
$total_lelongan = (clone $query_total_lelongan)
|
||||
->select('lelong.t_lelong',
|
||||
'lelong.norujukan',
|
||||
'gadai.nokp',
|
||||
'gadai.semakbarcode',
|
||||
'gadai.masa',
|
||||
'lelong.berat',
|
||||
'lelong.nilaimarhun',
|
||||
'lelong.pinjaman',
|
||||
'gadai.upah12',
|
||||
'gadai.percentpinj',
|
||||
'lelong.teller',
|
||||
'gadai.nokp',
|
||||
'gadai.bakipjm',
|
||||
'lelong.bakiupah',
|
||||
'lelong.cajlelong',
|
||||
'lelong.hargajual',
|
||||
'lelong.baki')
|
||||
->orderBy('lelong.teller')
|
||||
->orderBy('gadai.sirig')
|
||||
->get();
|
||||
return $total_lelongan;
|
||||
}
|
||||
|
||||
private function getCustomerInfo($total_lelongan)
|
||||
{
|
||||
|
||||
$extract_nokp = $total_lelongan->pluck('nokp');
|
||||
// dd($extract_nokp);
|
||||
|
||||
$customer_info = Customer::on('mysql7')
|
||||
->select(['nama', 'alamat1', 'kpbaru', 'kplama'])
|
||||
->where(function ($query) use ($extract_nokp) {
|
||||
$query->whereIn('kpbaru', $extract_nokp)
|
||||
->orWhereIn('kplama', $extract_nokp);
|
||||
})
|
||||
->get();
|
||||
// dd($customer_info);
|
||||
|
||||
$customer_info = collect($extract_nokp)->map(function ($nokp) use ($customer_info) {
|
||||
return $customer_info->where('kpbaru', $nokp)->first() ?? $customer_info->where('kplama', $nokp)->first();
|
||||
})->toArray();
|
||||
|
||||
return $customer_info;
|
||||
}
|
||||
|
||||
private function getMarhunLelongan($total_lelongan, $cawangan_connection)
|
||||
{
|
||||
|
||||
$extract_norujukan = $total_lelongan->pluck('norujukan');
|
||||
|
||||
$marhun_lelongan = LelMarhun::on($cawangan_connection)
|
||||
->select('norujukan', 'bil', 'marhun')
|
||||
->whereIn('norujukan', $extract_norujukan)
|
||||
->get()
|
||||
->groupBy('norujukan')
|
||||
->toArray();
|
||||
|
||||
$marhun_lelongan = array_map(function ($lelongan) {
|
||||
return array_map(function ($norujukan) {
|
||||
return $norujukan['bil'] . ' ' . $norujukan['marhun'];
|
||||
}, $lelongan);
|
||||
}, $marhun_lelongan);
|
||||
|
||||
$marhun_lelongan = array_map(function ($lelongan) {
|
||||
return implode(',', $lelongan);
|
||||
}, $marhun_lelongan);
|
||||
return $marhun_lelongan;
|
||||
}
|
||||
|
||||
public function getCawanganReportBakiLelongBelumTuntut()
|
||||
{
|
||||
$cawangan_connection = Cawangan::where('kodcaw', $this->kod_cawangan)->first()->mysql;
|
||||
$endDate = $this->endDate;
|
||||
$query_total_lelongan = Lelong::on($cawangan_connection)
|
||||
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan') // Joining gadai table
|
||||
->select(
|
||||
'lelong.t_lelong',
|
||||
'lelong.norujukan',
|
||||
'gadai.nokp',
|
||||
'gadai.masa',
|
||||
'lelong.berat',
|
||||
'lelong.nilaimarhun',
|
||||
'gadai.pinjaman',
|
||||
'gadai.percentpinj',
|
||||
'lelong.teller',
|
||||
'gadai.bakipjm', // Fetch pinjaman from gadai
|
||||
'gadai.marhun' // Fetch marhun from gadai
|
||||
)
|
||||
->where(function ($query) use ($endDate) {
|
||||
$query->whereNull('lelong.trkhtuntut')
|
||||
->orWhere('lelong.trkhtuntut', '>', $endDate); // or use a specific date: '2025-06-01'
|
||||
})
|
||||
->where('lelong.baki', '>', 0.00)
|
||||
->orderBy('lelong.norujukan', 'asc');
|
||||
|
||||
|
||||
$query_total_lelongan->when(!empty($this->startDate) and !empty($this->endDate), function ($q) {
|
||||
return $q->where('lelong.t_lelong', '>=', $this->startDate)
|
||||
->where('lelong.t_lelong', '<=', $this->endDate);
|
||||
});
|
||||
|
||||
$total_lelongan = $this->getTotalLelongan($query_total_lelongan);
|
||||
// dd($total_lelongan);
|
||||
$total_summary_lelongan_teller = $this->getTotalSummaryLelonganGroupByTeller($query_total_lelongan);
|
||||
$total_summary_lelongan = $this->getTotalSummaryLelongan($query_total_lelongan);
|
||||
$customer_info = $this->getCustomerInfo($total_lelongan);
|
||||
$marhun_lelongan = $this->getMarhunLelongan($total_lelongan, $cawangan_connection);
|
||||
$cawangan_detail = $this->getCawanganDetail($cawangan_connection);
|
||||
|
||||
$total_lelongan = $total_lelongan->zip($customer_info, $marhun_lelongan)->map(function ($data) {
|
||||
|
||||
[$lelong, $customer_info, $marhun_lelongan] = $data;
|
||||
|
||||
return [
|
||||
'no_rujukan' => $lelong['norujukan'],
|
||||
'nama' => $customer_info['nama'] ?? '-',
|
||||
'alamat' => $customer_info['alamat1'] ?? '-',
|
||||
'no_kp' => $lelong['nokp'],
|
||||
'masa' => $lelong['masa'],
|
||||
'marhun' => $marhun_lelongan,
|
||||
'berat' => $lelong['berat'],
|
||||
'nilai_marhun' => $lelong['nilaimarhun'],
|
||||
'pinjaman' => $lelong['pinjaman'],
|
||||
'peratusan_margin_pinjaman' => $lelong['percentpinj'],
|
||||
'bakipjm' => $lelong['bakipjm'],
|
||||
'keuntungan' => $lelong['bakiupah'],
|
||||
'cajlelong' => $lelong['cajlelong'],
|
||||
'hargajual' => $lelong['hargajual'],
|
||||
'baki' => $lelong['baki'],
|
||||
'teller' => $lelong['teller'],
|
||||
't_lelong' => $lelong['t_lelong'],
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
$total_lelongan = $total_lelongan->groupBy('teller');
|
||||
|
||||
$lelongan_tellers = $total_lelongan->keys();
|
||||
|
||||
$total_lelongan = $total_lelongan
|
||||
->zip($total_summary_lelongan_teller)
|
||||
->map(function ($data) {
|
||||
|
||||
[$lelongan, $summary] = $data;
|
||||
|
||||
return [
|
||||
'lelongan' => $lelongan,
|
||||
'summary_lelongan_teller' => $summary,
|
||||
];
|
||||
});
|
||||
|
||||
$total_lelongan = $lelongan_tellers->combine($total_lelongan);
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
'startDate' => Helper::formatDate($this->startDate),
|
||||
'endDate' => Helper::formatDate($this->endDate),
|
||||
],
|
||||
'cawangan_detail' => $cawangan_detail,
|
||||
'lelongan' => $total_lelongan,
|
||||
'summary_lelongan' => $total_summary_lelongan,
|
||||
];
|
||||
|
||||
return json_encode($data);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -398,7 +398,7 @@ class OnePercentService
|
||||
$t_gadai = Carbon::parse($gadai->t_gadai);
|
||||
$t_bayaran = Carbon::parse($trans->tarikh_bayaran);
|
||||
|
||||
if ($t_gadai->month === $t_bayaran->month) {
|
||||
if (($t_gadai->month == $t_bayaran->month) && ($t_gadai->year == $t_bayaran->year)) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
|
||||
@@ -266,6 +266,12 @@ class RingkasanHarianService
|
||||
|
||||
}
|
||||
|
||||
// Public method that calls the private method
|
||||
public function getCustomerSummary()
|
||||
{
|
||||
return $this->getBilanganCustomerBaru(); // Access the private method here
|
||||
}
|
||||
|
||||
private function getBayarRugiLelong()
|
||||
{
|
||||
$bayarRugiLelong = TuntutBaki::on($this->connectionCawangan)
|
||||
|
||||
@@ -8,6 +8,8 @@ use App\Tunai;
|
||||
use App\Transaction;
|
||||
use App\TransaksiKeuntungan;
|
||||
use App\Cawangan;
|
||||
use App\Mohon;
|
||||
use App\Mohonid;
|
||||
use App\TransaksiGadai;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -39,7 +41,14 @@ class AnsuranServices
|
||||
$tarikh = Carbon::now();
|
||||
$harisemasa = $tarikh->toDateString();
|
||||
|
||||
$audit = new Audit();
|
||||
$audit->users = $request->teller;
|
||||
$audit->actions = 'Hapus Ansuran';
|
||||
$audit->norujukan = $request->norujukan;
|
||||
$audit->new_data = '';
|
||||
|
||||
if($harisemasa !== $tarikh_request->toDateString()){
|
||||
Log::debug('Date mismatch: ' . $harisemasa . ' vs ' . $tarikh_request->toDateString());
|
||||
return 'date not equal';
|
||||
}
|
||||
$transaction_gadai = TransaksiGadai::on('mysql7')->where('id',$request->tg_id)->first();
|
||||
@@ -49,8 +58,11 @@ class AnsuranServices
|
||||
return 'wrong teller';
|
||||
}
|
||||
|
||||
$audit->old_data = $transaction_gadai;
|
||||
|
||||
|
||||
try{
|
||||
DB::connection('mysql7')->transaction(function () use($cawangan,$request,$harisemasa,$transaction,$transaction_gadai){
|
||||
DB::connection('mysql7')->transaction(function () use($cawangan,$request,$harisemasa,$transaction,$transaction_gadai,$audit){
|
||||
|
||||
try{
|
||||
DB::connection($cawangan['mysql'])->transaction(function () use($cawangan,$request,$transaction_gadai,$harisemasa,$transaction){
|
||||
@@ -91,6 +103,17 @@ class AnsuranServices
|
||||
'softDelete' => 1,
|
||||
));
|
||||
|
||||
$gadai_updated = Gadai::on($cawangan['mysql'])
|
||||
->select('percentpinj','bakipjm','tempoh','t_update','bakihargajualan','tempohbayar','lelong_tawarruq','margin_semasa','tunggakanujrah','tunggakanonepercent')
|
||||
->where('norujukan',$request->norujukan)->first();
|
||||
|
||||
$tarikh_audit = Carbon::now();
|
||||
$audit->new_data = $gadai_updated;
|
||||
$audit->kodcaw = $this->cawangan;
|
||||
$audit->created_at = $tarikh_audit;
|
||||
$audit->updated_at = $tarikh_audit;
|
||||
$audit->save();
|
||||
|
||||
|
||||
return 'success';
|
||||
|
||||
@@ -103,18 +126,6 @@ class AnsuranServices
|
||||
}
|
||||
|
||||
return 'success';
|
||||
|
||||
// $audit = new Audit();
|
||||
// $audit->users = $request->teller;
|
||||
// $audit->actions = 'Hapus Ansuran';
|
||||
// $audit->norujukan = $norujukan;
|
||||
// $audit->new_data = $new_data;
|
||||
// $audit->old_data = $old_data;
|
||||
// $audit->kodcaw = $kodcaw;
|
||||
// $audit->created_at = $current;
|
||||
// $audit->updated_at = $current;
|
||||
// $audit->save();
|
||||
|
||||
}
|
||||
|
||||
public function getLatestAdvanceWithoutDelete(Request $request){
|
||||
@@ -125,5 +136,21 @@ class AnsuranServices
|
||||
return $latest;
|
||||
}
|
||||
|
||||
public function getApprovalFromOperation(Request $request){
|
||||
$tarikh = Carbon::now();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first();
|
||||
|
||||
$latest = Mohon::on($cawangan['mysql'])
|
||||
->whereDate('tarikh',$tarikh->toDateString())
|
||||
->where('teller',$request->teller)
|
||||
->where('masalulus','=','')
|
||||
->where('operasi','=','')
|
||||
->where('status','Hapus Ansuran')
|
||||
->latest('tarikh')
|
||||
->first();
|
||||
|
||||
return $latest;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Support\v2\GadaiV2 as Version2Gadai;
|
||||
use App\Support\v2\Penebusan;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnePercent extends MasterServices
|
||||
{
|
||||
protected $kodcaw;
|
||||
@@ -61,18 +63,30 @@ class OnePercent extends MasterServices
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function getKadarUjrah(HttpRequest $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw',$request->kodcaw)->first();
|
||||
$onePercentServices = new Calculation();
|
||||
$kadarujrah = $onePercentServices->getKadarUjrah($request->nilaimarhun,$cawangan['group_id']);
|
||||
public function getKadarUjrah(HttpRequest $request)
|
||||
{
|
||||
// Log::info('[DEBUG-CONTROLLER] Data request', [
|
||||
// 'nokp' => $request->nokp,
|
||||
// 'kodcaw' => $request->kodcaw,
|
||||
// 'nilaimarhun' => $request->nilaimarhun
|
||||
// ]);
|
||||
|
||||
return $kadarujrah;
|
||||
}
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
$onePercentServices = new Calculation();
|
||||
|
||||
$kadarujrah = $onePercentServices->getKadarUjrah(
|
||||
$request->nilaimarhun,
|
||||
$cawangan['group_id'],
|
||||
$request->nokp
|
||||
);
|
||||
|
||||
return $kadarujrah;
|
||||
}
|
||||
|
||||
public function getOnePercent(HttpRequest $request){
|
||||
$margin = (!is_numeric($request->margin)) ? 0 : $request->margin;
|
||||
$onePercentServices = new Calculation();
|
||||
$keuntungan = $onePercentServices->kiraanKeuntunganSebenar($request->pembiayaan,$request->nilaimarhun,$request->kadarujrah,$margin);
|
||||
$keuntungan = $onePercentServices->kiraanKeuntunganSebenar($request->pembiayaan,$request->nilaimarhun,$request->kadarujrah,$margin, $request->nokp);
|
||||
|
||||
return $keuntungan;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Support\v2;
|
||||
|
||||
use App\Audit;
|
||||
use App\Cawangan;
|
||||
use App\Customer;
|
||||
use App\KadarUpah;
|
||||
use App\Support\v2\Calculation;
|
||||
use Carbon\Carbon;
|
||||
@@ -57,6 +58,34 @@ class GadaiV2
|
||||
}
|
||||
}
|
||||
|
||||
private function getKadarUpahAnggota($nokp, $total_nilai_marhun = 0, $groupid = 2): ?float
|
||||
{
|
||||
if (!$nokp) {
|
||||
return null; // tiada nokp = tak boleh tentukan kadar
|
||||
}
|
||||
|
||||
$customer = Customer::on('mysql7')
|
||||
->select('tag_anggota')
|
||||
->where(function ($q) use ($nokp) {
|
||||
$q->where('kpbaru', $nokp)
|
||||
->orWhere('kplama', $nokp);
|
||||
})
|
||||
->first();
|
||||
|
||||
$customer = $customer ? $customer->toArray() : [];
|
||||
|
||||
if (isset($customer['tag_anggota']) && $customer['tag_anggota'] == 1) {
|
||||
return 0.00; // ahli — kadar 0.00 memang sah
|
||||
}
|
||||
|
||||
$kadar = KadarUpah::where('min', '<=', $total_nilai_marhun)
|
||||
->where('max', '>=', $total_nilai_marhun)
|
||||
->where('group_id', $groupid)
|
||||
->value('kadarujrah');
|
||||
|
||||
return is_null($kadar) ? null : (float) $kadar; // tak jumpa row = null (block)
|
||||
}
|
||||
|
||||
public function createMarhun($norujukan,HttpRequest $request){
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
@@ -82,15 +111,24 @@ class GadaiV2
|
||||
$total_nilai_marhun = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('n_marhun');
|
||||
$total_berat = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('berat');
|
||||
|
||||
//query kadar upah baru
|
||||
$kadar_raw = KadarUpah::where('min','<=',$total_nilai_marhun)->where('max','>=',$total_nilai_marhun)->where('group_id',$cawangan['group_id'])->first();
|
||||
$kadar_raw = $this->getKadarUpahAnggota($request->nokp, $total_nilai_marhun, $cawangan['group_id']);
|
||||
|
||||
if (is_null($kadar_raw)) {
|
||||
Log::error('[BLOCKED] Kadar upah tidak dijumpai', [
|
||||
'nokp' => $request->nokp,
|
||||
'total_nilai_marhun' => $total_nilai_marhun,
|
||||
'group_id' => $cawangan['group_id'],
|
||||
]);
|
||||
throw new \Exception("Kadar upah tidak dijumpai, transaksi dibatalkan!");
|
||||
}
|
||||
|
||||
// $kadar_raw = 0.00 (ahli) akan lepas ke sini dan diteruskan
|
||||
|
||||
|
||||
// query kadar upah lama
|
||||
// $kadar_raw = KadarUpah::where('min','<=',$total_nilai_marhun)->where('max','>=',$total_nilai_marhun)->first();
|
||||
|
||||
$onepercentservices = new Calculation();
|
||||
$keuntungan = $onepercentservices->kiraanKeuntunganSebenar($request->pinjaman,$total_nilai_marhun,$kadar_raw['kadarujrah'],$margin_pinjam);
|
||||
$keuntungan = $onepercentservices->kiraanKeuntunganSebenar($request->pinjaman,$total_nilai_marhun,$kadar_raw,$margin_pinjam);
|
||||
// $upah1 = $request->pinjaman * ($kadar_raw['kadarupdah']/100);
|
||||
// $upah6 = $upah1 * 6;
|
||||
// $upah12 = $upah1 * 12;
|
||||
@@ -105,7 +143,7 @@ class GadaiV2
|
||||
|
||||
$hargajualan = $request->pinjaman + $upah12;
|
||||
|
||||
$akrual = $this->kiraupahTawarruqStokAuditUjrahOnePercent(0.5,0,$kadar_raw['kadarujrah'],$request->pinjaman,$total_nilai_marhun,$margin_pinjam);
|
||||
$akrual = $this->kiraupahTawarruqStokAuditUjrahOnePercent(0.5,0,$kadar_raw,$request->pinjaman,$total_nilai_marhun,$margin_pinjam);
|
||||
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$norujukan)
|
||||
@@ -113,7 +151,7 @@ class GadaiV2
|
||||
'nilaimarhun' => $total_nilai_marhun,
|
||||
'berat'=> $total_berat,
|
||||
'pinjaman' => $request->pinjaman,
|
||||
'kadarupah' => $kadar_raw['kadarujrah'],
|
||||
'kadarupah' => $kadar_raw,
|
||||
'marhun' => $request->marhun,
|
||||
'percentpinj' => $margin_pinjam,
|
||||
'teller' => $request->teller,
|
||||
@@ -134,7 +172,7 @@ class GadaiV2
|
||||
'upahdibayar' => 0.00,
|
||||
'tempohbayar' => 0.00,
|
||||
'lelong_tawarruq' => 1,
|
||||
'kadarujrah' => $kadar_raw['kadarujrah'],
|
||||
'kadarujrah' => $kadar_raw,
|
||||
'ujrah' => $ujrah,
|
||||
'onepercent' => $onepercent,
|
||||
'margin_semasa' => $margin_pinjam,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\QueryBuilders\TransactionOnlineBuilder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TransactionOnline extends Model
|
||||
@@ -24,4 +25,14 @@ class TransactionOnline extends Model
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
|
||||
public function cawangan()
|
||||
{
|
||||
return $this->belongsTo(Cawangan::class, 'kodcaw', 'kodcaw');
|
||||
}
|
||||
|
||||
public function newEloquentBuilder($query)
|
||||
{
|
||||
return new TransactionOnlineBuilder($query);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user