From a7e4c4c4b132d98f5776bf19e95c37af35506639 Mon Sep 17 00:00:00 2001 From: "LAPTOP-DGCU80CH\\user1" Date: Wed, 18 Nov 2020 09:15:27 +0800 Subject: [PATCH] api tebus --- app/Gadai.php | 3 ++ app/Http/Controllers/GadaiController.php | 64 ++++++++++++++++++++++-- app/TransaksiKeuntungan.php | 4 +- routes/web.php | 3 ++ 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/app/Gadai.php b/app/Gadai.php index 0c4a8fe..9c8d1c4 100644 --- a/app/Gadai.php +++ b/app/Gadai.php @@ -62,6 +62,9 @@ class Gadai extends Model 'tagcetak' , 'lel1stop' , 'tebus', + 'bakihargajualan', + 'hargajualan', + 'upah12' ]; /** diff --git a/app/Http/Controllers/GadaiController.php b/app/Http/Controllers/GadaiController.php index 74328a3..cef4ef8 100644 --- a/app/Http/Controllers/GadaiController.php +++ b/app/Http/Controllers/GadaiController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use App\Gadai; use App\Cawangan; +use App\Transaction; +use App\TransaksiKeuntungan; use Illuminate\Http\Request; use Carbon\Carbon; @@ -116,13 +118,20 @@ class GadaiController extends Controller public function updateGadaiMarhunOnline($kodcaw,$norujukan,Request $request) { - $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); - $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); - $current = Carbon::now(); $current = new Carbon(); + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); + + $upahsemasa = $gadai['jbg'] * (($gadai['kadarupah']/100 )* $gadai['bakipjm']); + + if($request->bayaran < $upahsemasa){ + $upahsemasa = $request->bayaran; + } + $baki_upah = $gadai['bakiupah'] - $request->bayaran; + $baki_hargajualan = $gadai['bakihargajualan'] - $request->bayaran; if($gadai['bakipjm'] == null){ $baki_pinjaman = $gadai['pinjaman']; }else{ @@ -134,15 +143,62 @@ class GadaiController extends Controller $baki_upah = 0; } + $transaction = Transaction::on('mysql7')->create([ + 'trans_type' => 'A', + 'norujukan' => $norujukan, + 'nokp' => $gadai['nokp'], + 'teller' => 'online', + 'kodcaw' => 'online', + 'duit_masuk' => $request->bayaran, + 'created_at' => $current, + ]); + + $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([ + 'norujukan' => $norujukan, + 'bayaran_keuntungan' => $upahsemasa, + 'tarikh_bayaran'=> $current, + 'kodcaw'=> 'online' + ]); + $update_gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->update(array( 'bakipjm' => $baki_pinjaman, 'bakiupah' => $baki_upah, 'jbg' => 0, - 't_update' => $current->toDateString() + 't_update' => $current->toDateString(), + 'bakihargajualan' => $baki_hargajualan )); return response()->json($update_gadai, 200); } + public function showTebusToday($kodcaw,$norujukan){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + + $gadai_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); + + $upahsemasa = $gadai_data['jbg'] * (($gadai_data['kadarupah']/100 )* $gadai_data['bakipjm']); + + $transaction = Transaction::on('mysql7')->where('norujukan','=',$norujukan)->get(); + + $transaction_keuntungan = TransaksiKeuntungan::on('mysql7')->where('norujukan','=',$norujukan)->get(); + + $totalBayaranKeuntungan = 0; + $totalBayaran = 0; + + foreach($transaction as $index=>$trans){ + $totalBayaran += $trans['duit_masuk']; + } + + foreach($transaction_keuntungan as $index=>$untung){ + $totalBayaranKeuntungan += $untung['bayaran_keuntungan']; + } + + $rebet = $gadai_data['upah12'] - $totalBayaranKeuntungan - $upahsemasa; + + $harga_tebus = $gadai_data['bakihargajualan'] - $rebet; + + return response()->json($harga_tebus); + } + public function delete($id) { Gadai::findOrFail($id)->delete(); diff --git a/app/TransaksiKeuntungan.php b/app/TransaksiKeuntungan.php index 6b55b4e..f6d1664 100644 --- a/app/TransaksiKeuntungan.php +++ b/app/TransaksiKeuntungan.php @@ -4,7 +4,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; -class Transaction extends Model +class TransaksiKeuntungan extends Model { protected $table = 'transaksi_keuntungan'; public $timestamps = false; @@ -14,7 +14,7 @@ class Transaction extends Model * @var array */ protected $fillable = [ - 'norujukan','bayaran_keuntungan','tarikh_bayaran','tempoh','kodcaw' + 'norujukan','bayaran_keuntungan','tarikh_bayaran','kodcaw' ]; /** diff --git a/routes/web.php b/routes/web.php index ba86833..eeb97a3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,6 +43,9 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->put('gadai/{kodcaw}/norujukan/{norujukan}',['uses'=>'GadaiController@updateGadaiMarhunOnline']); $router->put('gadai/norujukan/{kodcaw}/{norujukan}',['uses'=>'GadaiController@daftarGadaiMarhun']); + //Tebus API + $router->get('tebusonline/{kodcaw}/{norujukan}',['uses'=>'GadaiController@showTebusToday']); + //Lelong API $router->get('lelong',['uses'=>'LelongController@showAllLelongs']); $router->get('lelong/cawangan/{kodcaw}',['uses'=>'LelongController@showAllLelongByCawangan']);