Continue dev on pampasan module
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Audit;
|
||||
use App\Polis;
|
||||
use App\Cawangan;
|
||||
use App\LookupAlasan;
|
||||
use App\Pampasan;
|
||||
use App\Palsu;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
@@ -24,7 +26,7 @@ class BarangkesController extends Controller
|
||||
return response()->json(['error' => 'Invalid kodcaw'], 403);
|
||||
}
|
||||
|
||||
$query = DB::connection($cawangan['mysql'])->table('palsu')
|
||||
$palsu_query = Palsu::on($cawangan['mysql'])
|
||||
->select([
|
||||
'tarikh',
|
||||
'norujukan',
|
||||
@@ -35,33 +37,34 @@ class BarangkesController extends Controller
|
||||
'untung',
|
||||
'untungonepercent',
|
||||
'untungcajlain'
|
||||
]);
|
||||
])
|
||||
->when($request->filled('jenis'), function($query) use($request){
|
||||
return $query->where('jenis', $request->jenis);
|
||||
})
|
||||
->when($request->filled('tarikh_mula') && $request->filled('tarikh_akhir'), function($query) use($request){
|
||||
return $query->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir]);
|
||||
})
|
||||
->with('tebus:norujukan');
|
||||
|
||||
// Only apply whereBetween if tarikh_mula and tarikh_akhir are provided
|
||||
if ($request->filled('tarikh_mula') && $request->filled('tarikh_akhir')) {
|
||||
$query->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir]);
|
||||
}
|
||||
$palsu_array = $palsu_query->get()->toArray();
|
||||
$pampasan_array = Pampasan::on($cawangan['mysql'])->where('kodcaw', $request->kodcaw)->get()->toArray();
|
||||
|
||||
$result = $query->get();
|
||||
|
||||
$pampasan = Http::get(config('app_parameter.api_v3') . "pampasan", ['kodcaw' => $request->kodcaw])
|
||||
->json()['data'];
|
||||
|
||||
$palsu_array = $result->toArray();
|
||||
|
||||
// dd($pampasan, $palsu_array);
|
||||
|
||||
$indexedArray2 = collect($pampasan)->keyBy('norujukan');
|
||||
$indexedArray2 = collect($pampasan_array)->keyBy('norujukan');
|
||||
|
||||
$merged = collect($palsu_array)->map(function ($item) use ($indexedArray2) {
|
||||
$id = $item->norujukan;
|
||||
$itemArray = (array) $item; // Convert object to array
|
||||
$id = $item['norujukan'];
|
||||
$itemArray = $item; // Already an array from toArray()
|
||||
$additional = $indexedArray2->get($id, []);
|
||||
|
||||
// Add exists_in_tebus flag based on relationship
|
||||
$itemArray['gadaian_sudah_tebus'] = !is_null($item['tebus']);
|
||||
|
||||
// Remove the tebus relationship data to keep response clean
|
||||
unset($itemArray['tebus']);
|
||||
|
||||
return array_merge($itemArray, $additional);
|
||||
})->values()->toArray();
|
||||
|
||||
// dd($merged, $status);
|
||||
|
||||
$filteredResults = [];
|
||||
|
||||
if ($status == 'dituntut') {
|
||||
@@ -78,7 +81,7 @@ class BarangkesController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($status == 'all') {
|
||||
if ($status == 'all' || $status == null) {
|
||||
$filteredResults = $merged;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Palsu;
|
||||
use App\Pampasan;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
@@ -67,6 +68,11 @@ class PampasanController extends Controller
|
||||
|
||||
$pampasan->save();
|
||||
|
||||
// Update corresponding palsu table record status to 1
|
||||
Palsu::on($cawangan['mysql'])
|
||||
->where('norujukan', $norujukan)
|
||||
->update(['status' => 1]);
|
||||
|
||||
// dd($pampasan);
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use App\Audit;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
@@ -30,6 +31,8 @@ class Palsu extends Model
|
||||
'untungonepercent',
|
||||
'untungcajlain',
|
||||
'pembiayaan',
|
||||
'jenis',
|
||||
'status',
|
||||
];
|
||||
|
||||
// public static function boot()
|
||||
@@ -87,4 +90,9 @@ class Palsu extends Model
|
||||
// {
|
||||
// return $this->belongsTo(Daerah::class, 'koddaerah', 'koddaerah');
|
||||
// }
|
||||
|
||||
public function tebus(): HasOne
|
||||
{
|
||||
return $this->hasOne(Tebus::class, 'norujukan', 'norujukan');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AddJenisColumnToPalsuTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Get active database connections
|
||||
*/
|
||||
private function getActiveDB(): array
|
||||
{
|
||||
$config_db = array_keys(config("database.connections"));
|
||||
|
||||
$db_connection = array_filter($config_db, function($connection) {
|
||||
try {
|
||||
if ($connection == 'mysql7') {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::connection($connection)->select('SELECT 1');
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return $db_connection ? array_values($db_connection) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
|
||||
if (!Schema::connection($dbase)->hasColumn('palsu', 'jenis')) {
|
||||
$table->string('jenis', 50)->nullable()->comment('Jenis/Type classification');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
|
||||
if (Schema::connection($dbase)->hasColumn('palsu', 'jenis')) {
|
||||
$table->dropColumn('jenis');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateJenisToPampasanForSempornaRecords extends Migration
|
||||
{
|
||||
/**
|
||||
* Semporna norujukan records to update
|
||||
*/
|
||||
private function getSempornaRecords(): array
|
||||
{
|
||||
return [
|
||||
'011237240808-0003',
|
||||
'011237240719-0015',
|
||||
'011237240806-0011',
|
||||
'011237240828-0001',
|
||||
'011237240904-0007',
|
||||
'011237240904-0008',
|
||||
'011237240904-0009',
|
||||
'011237240719-0023',
|
||||
'011237240719-0024',
|
||||
'011237240719-0025',
|
||||
'011237240618-0026',
|
||||
'011237240719-0027',
|
||||
'011237240719-0028',
|
||||
'011237240618-0020',
|
||||
'011237240719-0030',
|
||||
'011237240618-0029',
|
||||
'011237240731-0026',
|
||||
'011237240912-0009'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$semporna_records = $this->getSempornaRecords();
|
||||
|
||||
// Update jenis to 'pampasan' for Semporna records in mysql34 (Semporna branch)
|
||||
try {
|
||||
$updated = DB::connection('mysql34')->table('palsu')
|
||||
->whereIn('norujukan', $semporna_records)
|
||||
->update(['jenis' => 'pampasan']);
|
||||
|
||||
echo "Updated {$updated} Semporna records with jenis = 'pampasan'\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error updating Semporna records: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$semporna_records = $this->getSempornaRecords();
|
||||
|
||||
// Revert jenis to null for Semporna records
|
||||
try {
|
||||
$reverted = DB::connection('mysql34')->table('palsu')
|
||||
->whereIn('norujukan', $semporna_records)
|
||||
->update(['jenis' => null]);
|
||||
|
||||
echo "Reverted {$reverted} Semporna records jenis to null\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error reverting Semporna records: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateNonSempornaRecordsJenisToHapuskira extends Migration
|
||||
{
|
||||
/**
|
||||
* Get active database connections
|
||||
*/
|
||||
private function getActiveDB(): array
|
||||
{
|
||||
$config_db = array_keys(config("database.connections"));
|
||||
|
||||
$db_connection = array_filter($config_db, function($connection) {
|
||||
try {
|
||||
if ($connection == 'mysql7') {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::connection($connection)->select('SELECT 1');
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return $db_connection ? array_values($db_connection) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Semporna norujukan records to exclude
|
||||
*/
|
||||
private function getSempornaRecords(): array
|
||||
{
|
||||
return [
|
||||
'011237240808-0003',
|
||||
'011237240719-0015',
|
||||
'011237240806-0011',
|
||||
'011237240828-0001',
|
||||
'011237240904-0007',
|
||||
'011237240904-0008',
|
||||
'011237240904-0009',
|
||||
'011237240719-0023',
|
||||
'011237240719-0024',
|
||||
'011237240719-0025',
|
||||
'011237240618-0026',
|
||||
'011237240719-0027',
|
||||
'011237240719-0028',
|
||||
'011237240618-0020',
|
||||
'011237240719-0030',
|
||||
'011237240618-0029',
|
||||
'011237240731-0026',
|
||||
'011237240912-0009'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
$semporna_records = $this->getSempornaRecords();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
try {
|
||||
if ($dbase == 'mysql34') {
|
||||
// For Semporna (mysql34), update only non-Semporna records to 'hapuskira'
|
||||
$updated = DB::connection($dbase)->table('palsu')
|
||||
->whereNotIn('norujukan', $semporna_records)
|
||||
->update(['jenis' => 'hapuskira']);
|
||||
|
||||
if ($updated > 0) {
|
||||
echo "Updated {$updated} non-Semporna records in {$dbase} to jenis = 'hapuskira'\n";
|
||||
}
|
||||
} else {
|
||||
// For all other databases, update all records to 'hapuskira'
|
||||
$updated = DB::connection($dbase)->table('palsu')
|
||||
->update(['jenis' => 'hapuskira']);
|
||||
|
||||
if ($updated > 0) {
|
||||
echo "Updated {$updated} records in {$dbase} to jenis = 'hapuskira'\n";
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "Error updating {$dbase}: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
try {
|
||||
// Revert all jenis values to null except Semporna records which should remain 'pampasan'
|
||||
if ($dbase == 'mysql34') {
|
||||
$semporna_records = $this->getSempornaRecords();
|
||||
$reverted = DB::connection($dbase)->table('palsu')
|
||||
->whereNotIn('norujukan', $semporna_records)
|
||||
->update(['jenis' => null]);
|
||||
|
||||
if ($reverted > 0) {
|
||||
echo "Reverted {$reverted} non-Semporna records in {$dbase} jenis to null\n";
|
||||
}
|
||||
} else {
|
||||
$reverted = DB::connection($dbase)->table('palsu')
|
||||
->update(['jenis' => null]);
|
||||
|
||||
if ($reverted > 0) {
|
||||
echo "Reverted {$reverted} records in {$dbase} jenis to null\n";
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "Error reverting {$dbase}: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AddStatusColumnToPalsuTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Get active database connections
|
||||
*/
|
||||
private function getActiveDB(): array
|
||||
{
|
||||
$config_db = array_keys(config("database.connections"));
|
||||
|
||||
$db_connection = array_filter($config_db, function($connection) {
|
||||
try {
|
||||
if ($connection == 'mysql7') {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::connection($connection)->select('SELECT 1');
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return $db_connection ? array_values($db_connection) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
|
||||
if (!Schema::connection($dbase)->hasColumn('palsu', 'status')) {
|
||||
$table->unsignedSmallInteger('status')->default(0)->comment('Status value');
|
||||
}
|
||||
});
|
||||
|
||||
// Update existing rows to have status = 0
|
||||
DB::connection($dbase)->table('palsu')
|
||||
->whereNull('status')
|
||||
->update(['status' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
|
||||
if (Schema::connection($dbase)->hasColumn('palsu', 'status')) {
|
||||
$table->dropColumn('status');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateAllPalsuStatusToOne extends Migration
|
||||
{
|
||||
/**
|
||||
* Get active database connections
|
||||
*/
|
||||
private function getActiveDB(): array
|
||||
{
|
||||
$config_db = array_keys(config("database.connections"));
|
||||
|
||||
$db_connection = array_filter($config_db, function($connection) {
|
||||
try {
|
||||
if ($connection == 'mysql7') {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::connection($connection)->select('SELECT 1');
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return $db_connection ? array_values($db_connection) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
try {
|
||||
// Update all status values to 1 in palsu table
|
||||
$updated = DB::connection($dbase)->table('palsu')
|
||||
->update(['status' => 1]);
|
||||
|
||||
if ($updated > 0) {
|
||||
echo "Updated {$updated} records in {$dbase} palsu table to status = 1\n";
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "Error updating {$dbase}: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
try {
|
||||
// Revert all status values back to 0 in palsu table
|
||||
$reverted = DB::connection($dbase)->table('palsu')
|
||||
->update(['status' => 0]);
|
||||
|
||||
if ($reverted > 0) {
|
||||
echo "Reverted {$reverted} records in {$dbase} palsu table to status = 0\n";
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "Error reverting {$dbase}: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateSempornaRecordsStatusToZero extends Migration
|
||||
{
|
||||
/**
|
||||
* Semporna norujukan records to update status to 0
|
||||
*/
|
||||
private function getSempornaRecords(): array
|
||||
{
|
||||
return [
|
||||
'011237240808-0003',
|
||||
'011237240719-0015',
|
||||
'011237240806-0011',
|
||||
'011237240828-0001',
|
||||
'011237240904-0007',
|
||||
'011237240904-0008',
|
||||
'011237240904-0009',
|
||||
'011237240719-0023',
|
||||
'011237240719-0024',
|
||||
'011237240719-0025',
|
||||
'011237240618-0026',
|
||||
'011237240719-0027',
|
||||
'011237240719-0028',
|
||||
'011237240618-0020',
|
||||
'011237240719-0030',
|
||||
'011237240618-0029',
|
||||
'011237240731-0026',
|
||||
'011237240912-0009'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$semporna_records = $this->getSempornaRecords();
|
||||
|
||||
// Update status to 0 for Semporna records in mysql34 (Semporna branch)
|
||||
try {
|
||||
$updated = DB::connection('mysql34')->table('palsu')
|
||||
->whereIn('norujukan', $semporna_records)
|
||||
->update(['status' => 0]);
|
||||
|
||||
echo "Updated {$updated} Semporna records with status = 0\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error updating Semporna records status: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$semporna_records = $this->getSempornaRecords();
|
||||
|
||||
// Revert status to 1 for Semporna records
|
||||
try {
|
||||
$reverted = DB::connection('mysql34')->table('palsu')
|
||||
->whereIn('norujukan', $semporna_records)
|
||||
->update(['status' => 1]);
|
||||
|
||||
echo "Reverted {$reverted} Semporna records status to 1\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Error reverting Semporna records status: " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user