Add module to enable or disable ujrah type payment

- Added migration to create table to store the parameter values
- Added ability to determine if branch is using calculation method v1 or v2
- Added API to enable client to get the payability of the ujrah payment and also change the parameter itself
This commit is contained in:
Afiq Hamzah
2024-05-18 22:33:55 +08:00
parent 67652b6f45
commit 87515f010a
4 changed files with 339 additions and 1 deletions
@@ -0,0 +1,121 @@
<?php
namespace App\Http\Controllers;
use App\Cawangan;
use App\PayableUjrahBranch;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
class PayableUjrahBranchController extends Controller
{
public function index()
{
$payableUjrahBranch = PayableUjrahBranch::with('cawangan_information')->get()->toJson();
return json_encode($payableUjrahBranch);
}
public function create(Request $request)
{
$validated_data = $request->validate([
'details_caw' => 'required',
'kodcaw' => 'required',
]);
$created_branch = PayableUjrahBranch::create($validated_data);
return response(json_encode($created_branch), 200);
}
public function syncStatus(Request $request)
{
$getDetailCawanganFromKodCaw = function($kodcaw){
$cawangan_details = Cawangan::all(['kodcaw', 'details_caw']);
return $cawangan_details->where('kodcaw', $kodcaw)->first()->details_caw;
};
// payable ujrah updates
$previous_payable_ujrah_branch = PayableUjrahBranch::select('kodcaw as branch', 'gadaian_ujrah_payable')->get();
$payable_ujrah_branch = collect($request->gadai_ujrah_payable_branches);
$payable_ujrah_branch_updates = $this->findDiff($previous_payable_ujrah_branch, $payable_ujrah_branch, 'branch');
$payable_ujrah_branch_updates->each(function ($item, $key) {
PayableUjrahBranch::where('kodcaw', $key)->update(['gadaian_ujrah_payable' => $item['gadaian_ujrah_payable']]);
});
$generateUpdateMessagePayableUjrahBranch = function($updateData) use($getDetailCawanganFromKodCaw){
return $updateData->map(function($item, $index) use($getDetailCawanganFromKodCaw) {
$cawanganName = $getDetailCawanganFromKodCaw($index);
$gadaian_ujrah_payable_note = $item['gadaian_ujrah_payable'] === 0 ? 'gadaian ujrah payment disabled' : 'gadaian ujrah payment enabled';
return "$cawanganName $gadaian_ujrah_payable_note";
});
};
// tawarruq version updates
$previous_branch_tawarruq_version = Cawangan::select('kodcaw as branch', 'version as tawarruq_version')->get();
$branch_tawarruq_version = collect($request->branch_tawarruq_version);
$arrahn_master_db_updates = $this->findDiff($previous_branch_tawarruq_version, $branch_tawarruq_version, 'branch');
$arrahn_master_db_updates->each(function ($item, $key) {
Cawangan::where('kodcaw', $key)->update(['version' => $item['tawarruq_version']]);
});
$generateUpdateMessageTawarruqVersion = function($updateData) use($getDetailCawanganFromKodCaw){
return $updateData->map(function($item, $index) use($getDetailCawanganFromKodCaw) {
$cawanganName = $getDetailCawanganFromKodCaw($index);
$tawarruq_version = $item['tawarruq_version'];
return "$cawanganName change to use tawarruq version : $tawarruq_version";
});
};
return response()->json([
'status' => 'success',
'updates_done' => [
'updated_branch_tawarruq_version' => $generateUpdateMessageTawarruqVersion($arrahn_master_db_updates),
'updated_payable_ujrah' => $generateUpdateMessagePayableUjrahBranch($payable_ujrah_branch_updates),
]
]);
}
public function delete()
{
}
// SUPPORTING METHODS
public function findDiff(Collection $collectionA, Collection $collectionB, $compare_key = 'id')
{
// Filter and find differences
$differences = $collectionA->mapWithKeys(function ($itemA) use ($collectionB, $compare_key) {
$itemB = $collectionB->firstWhere($compare_key, $itemA[$compare_key]);
if ($itemB) {
$diff = collect($itemB)->diffAssoc($itemA);
if ($diff->isNotEmpty()) {
return [$itemA[$compare_key] => $diff];
}
} else {
return [$itemA[$compare_key] => collect($itemA)];
}
return [];
})->filter();
return $differences;
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PayableUjrahBranch extends Model
{
protected $fillable = [
'details_caw',
'kodcaw',
'gadaian_ujrah_payable',
];
public function cawangan_information()
{
return $this->belongsTo(Cawangan::class, 'kodcaw', 'kodcaw');
}
}
@@ -0,0 +1,187 @@
<?php
use App\PayableUjrahBranch;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddPayableUjrahBranchesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('payable_ujrah_branches', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('details_caw');
$table->string('kodcaw');
$table->boolean('gadaian_ujrah_payable')->default(false);
$table->timestamps();
});
$this->getBranches()->each(function($branch) {
PayableUjrahBranch::create([
'details_caw' => $branch['details_caw'],
'kodcaw' => $branch['kodcaw'],
]);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('payable_ujrah_branches');
}
public function getBranches()
{
$branches = [
[
"details_caw" => "Kota Bharu 2",
"kodcaw" => "KB2"
],
[
"details_caw" => "Wakaf Che Yeh",
"kodcaw" => "WCY"
],
[
"details_caw" => "1 Stop",
"kodcaw" => "1STOP"
],
[
"details_caw" => "Jelawat",
"kodcaw" => "020301"
],
[
"details_caw" => "Wakaf Bharu",
"kodcaw" => "WB"
],
[
"details_caw" => "Kok Lanas",
"kodcaw" => "ALS"
],
[
"details_caw" => "Pasir Puteh",
"kodcaw" => "020306"
],
[
"details_caw" => "Machang",
"kodcaw" => "ARM"
],
[
"details_caw" => "Pasir Mas",
"kodcaw" => "APM"
],
[
"details_caw" => "Gua Musang",
"kodcaw" => "010311"
],
[
"details_caw" => "Guchil",
"kodcaw" => "GC"
],
[
"details_caw" => "Jeli",
"kodcaw" => "JLI"
],
[
"details_caw" => "Rantau Panjang",
"kodcaw" => "ARP"
],
[
"details_caw" => "Kuantan",
"kodcaw" => "010621"
],
[
"details_caw" => "Pasir Gudang",
"kodcaw" => "010136"
],
[
"details_caw" => "Skudai",
"kodcaw" => "011235"
],
[
"details_caw" => "Putatan",
"kodcaw" => "011227"
],
[
"details_caw" => "Bentong",
"kodcaw" => "010620"
],
[
"details_caw" => "Raub",
"kodcaw" => "010617"
],
[
"details_caw" => "Kangar",
"kodcaw" => "010915"
],
[
"details_caw" => "Sandakan",
"kodcaw" => "011228"
],
[
"details_caw" => "Sungai Petani",
"kodcaw" => "010219"
],
[
"details_caw" => "Tawau",
"kodcaw" => "011229"
],
[
"details_caw" => "Api-Api",
"kodcaw" => "011230"
],
[
"details_caw" => "Kajang",
"kodcaw" => "011013"
],
[
"details_caw" => "Raja Laut",
"kodcaw" => "011412"
],
[
"details_caw" => "Beaufort",
"kodcaw" => "011231"
],
[
"details_caw" => "Kota Belud",
"kodcaw" => "011232"
],
[
"details_caw" => "Tuaran",
"kodcaw" => "011234"
],
[
"details_caw" => "Keningau",
"kodcaw" => "011233"
],
[
"details_caw" => "Tanah Merah",
"kodcaw" => "020303"
],
[
"details_caw" => "Temerloh",
"kodcaw" => "010618"
],
[
"details_caw" => "Semporna",
"kodcaw" => "011237"
],
[
"details_caw" => "Kota Bharu 1",
"kodcaw" => "KB1"
]
];
return collect($branches);
}
}
+11 -1
View File
@@ -31,6 +31,15 @@ $router->group(['namespace' => '\Rap2hpoutre\LaravelLogViewer'], function() use
// });
$router->group(['prefix'=>'api'], function () use ($router){
$router->group([
'prefix' => 'payable-ujrah-branches',
], function($router){
$router->get('/', 'PayableUjrahBranchController@index');
$router->post('/', 'PayableUjrahBranchController@create');
$router->post('/sync-status', 'PayableUjrahBranchController@syncStatus');
});
//Customer API
$router->get('customers',['uses'=>'CustomerController@showAllCustomers']);
$router->get('customers/cawangan/{kodcaw}',['uses'=>'CustomerController@showAllCustomersByCawangan']);
@@ -126,7 +135,7 @@ $router->group(['prefix'=>'api'], function () use ($router){
$router->get('tebus/laporanjenistawarruqujrah/{kodcaw}',['uses'=>'TebusController@getLaporanTebusPengasinganUjrah']);
//Ansuran Ujrah (Laporan Range Date)
$router->get('ansuranujrah/laporan/{kodcaw}',['uses'=>'GadaiController@getLaporanAnsuranUjrah']);
$router->get('ansuranujrah/laporan/{kodcaw}',['uses'=>'GadaiController@getLaporanAnsuranUjrah']);
@@ -831,6 +840,7 @@ $router->group(['prefix'=>'admin'], function () use ($router){
$router->get('ig/bayaran_penghutang',['uses'=>'AdminPageController@SenaraiBayaranHutang']);
});
$router->group(['prefix'=>'lelong'], function () use ($router){
$router->get('upahtawarruq/{kodcaw}/{norujukan}/{jeniskeuntungan}',['uses'=>'TebusController@upahTawarruq']);
$router->get('upahrebettawarruq/{kodcaw}/{norujukan}/{jeniskeuntungan}',['uses'=>'TebusController@upahRebetTawarruq']);