Tukar step pampasan v3 ke v2:
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Pampasan;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Log\Logger;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PampasanController extends Controller
|
||||
{
|
||||
public function terimaPampasan(Request $request)
|
||||
{
|
||||
$validated = $this->validate($request, [
|
||||
'norujukan' => 'required|string',
|
||||
'baucerno' => 'required|string',
|
||||
'kodcaw' => 'required|string',
|
||||
'jumlah_pampasan' => 'required|numeric',
|
||||
'denominasi' => 'nullable|array',
|
||||
'teller' => 'required|string',
|
||||
]);
|
||||
|
||||
try {
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Cawangan tidak dijumpai untuk kodcaw: ' . $request->kodcaw,
|
||||
], 404);
|
||||
}
|
||||
|
||||
$pampasan = Pampasan::on($cawangan['mysql'])->create([
|
||||
'norujukan' => $validated['norujukan'],
|
||||
'baucerno' => $validated['baucerno'],
|
||||
'kodcaw' => $validated['kodcaw'],
|
||||
'jumlah_pampasan' => $validated['jumlah_pampasan'],
|
||||
'denominasi' => isset($validated['denominasi']) ? json_encode($validated['denominasi']) : null,
|
||||
'teller' => $validated['teller'],
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pampasan berjaya dibayar.',
|
||||
'data' => $pampasan,
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Database error: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateStatusPampasan(Request $request)
|
||||
{
|
||||
$norujukan = $request->norujukan;
|
||||
$kodcaw = $request->kodcaw;
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
$pampasan = Pampasan::on($cawangan['mysql'])->where("norujukan", $norujukan)->first();
|
||||
|
||||
$pampasan->status = 1;
|
||||
|
||||
$pampasan->save();
|
||||
|
||||
// dd($pampasan);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status Pampasan berjaya dituntut.',
|
||||
'data' => $pampasan,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function getPampasan()
|
||||
{
|
||||
$pampasan = Pampasan::on('mysql71')->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Status Pampasan berjaya dituntut.',
|
||||
'data' => $pampasan,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function getPampasanByNoRujukan()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pampasan extends Model
|
||||
{
|
||||
protected $table = 'pampasan';
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'norujukan',
|
||||
'baucerno',
|
||||
'kodcaw',
|
||||
'jumlah_pampasan',
|
||||
'teller',
|
||||
'nota'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// protected $hidden = [];
|
||||
}
|
||||
+16
-16
@@ -69,10 +69,10 @@ class AddNmJbgUntungPembiayaanColumnsToPalsuTable extends Migration
|
||||
// Add index and foreign key constraint to existing norujukan column
|
||||
if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
|
||||
// Add index to norujukan column for better performance
|
||||
$table->index('norujukan');
|
||||
// $table->index('norujukan');
|
||||
|
||||
// Add foreign key constraint named 'norujukan'
|
||||
$table->foreign('norujukan', 'norujukan')->references('norujukan')->on('gadai');
|
||||
// $table->foreign('norujukan', 'norujukan')->references('norujukan')->on('gadai');
|
||||
}
|
||||
|
||||
});
|
||||
@@ -87,21 +87,21 @@ class AddNmJbgUntungPembiayaanColumnsToPalsuTable extends Migration
|
||||
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
|
||||
|
||||
// Drop foreign key constraint and index from norujukan column
|
||||
if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
|
||||
try {
|
||||
$table->dropForeign('norujukan');
|
||||
echo "Dropped foreign key 'norujukan' on connection '{$dbase}'\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Warning: Could not drop foreign key 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
|
||||
}
|
||||
// if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
|
||||
// try {
|
||||
// $table->dropForeign('norujukan');
|
||||
// echo "Dropped foreign key 'norujukan' on connection '{$dbase}'\n";
|
||||
// } catch (\Exception $e) {
|
||||
// echo "Warning: Could not drop foreign key 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
|
||||
// }
|
||||
|
||||
try {
|
||||
$table->dropIndex(['norujukan']);
|
||||
echo "Dropped index on 'norujukan' column on connection '{$dbase}'\n";
|
||||
} catch (\Exception $e) {
|
||||
echo "Warning: Could not drop index on 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// $table->dropIndex(['norujukan']);
|
||||
// echo "Dropped index on 'norujukan' column on connection '{$dbase}'\n";
|
||||
// } catch (\Exception $e) {
|
||||
// echo "Warning: Could not drop index on 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
|
||||
// }
|
||||
// }
|
||||
|
||||
// Drop other columns if they exist
|
||||
$columnsToCheck = ['nilaimarhun', 'jbg', 'untung','untungonepercent','untungcajlain', 'pembiayaan'];
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreatePampasanTable extends Migration
|
||||
{
|
||||
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; // ikut pattern sedia ada
|
||||
DB::connection($connection)->select('SELECT 1');
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return $db_connection ? array_values($db_connection) : [];
|
||||
}
|
||||
|
||||
public function up()
|
||||
{
|
||||
foreach ($this->getActiveDB() as $dbase) {
|
||||
if (!Schema::connection($dbase)->hasTable('pampasan')) {
|
||||
Schema::connection($dbase)->create('pampasan', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('norujukan', 50)->unique()->index();
|
||||
$table->string('baucerno', 30)->index();
|
||||
$table->string('kodcaw', 20)->index();
|
||||
$table->decimal('jumlah_pampasan', 11, 2);
|
||||
|
||||
if (Schema::getConnection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION) >= '5.7') {
|
||||
$table->json('denominasi')->nullable();
|
||||
} else {
|
||||
$table->longText('denominasi')->nullable();
|
||||
}
|
||||
$table->string('teller', 100);
|
||||
$table->tinyInteger('status')
|
||||
->default(0)
|
||||
->comment('0 = belum dituntut, 1 = dituntut');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
foreach ($this->getActiveDB() as $dbase) {
|
||||
Schema::connection($dbase)->dropIfExists('pampasan');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,6 +379,11 @@ $router->group(['prefix'=>'api'], function () use ($router){
|
||||
$router->post('CreatePanjar/{kodcaw}',['uses'=>'PanjarController@create']);
|
||||
$router->post('DeletePanjar/{kodcaw}',['uses'=>'PanjarController@delete']);
|
||||
|
||||
//API PAMPASAN GUNA PANJAR
|
||||
$router->post('pampasan/terimaPampasan',['uses'=>'PampasanController@terimaPampasan']);
|
||||
$router->put('pampasan/updateStatusPampasan', ['uses' => 'PampasanController@updateStatusPampasan']);
|
||||
$router->get('pampasan', ['uses' => 'PampasanController@getPampasan']);
|
||||
|
||||
|
||||
//API KELULUSAN
|
||||
$router->get('SenaraiKelulusan/{kodcaw}',['uses'=>'KelulusanController@list']);
|
||||
|
||||
Reference in New Issue
Block a user