api tebus
This commit is contained in:
@@ -62,6 +62,9 @@ class Gadai extends Model
|
|||||||
'tagcetak' ,
|
'tagcetak' ,
|
||||||
'lel1stop' ,
|
'lel1stop' ,
|
||||||
'tebus',
|
'tebus',
|
||||||
|
'bakihargajualan',
|
||||||
|
'hargajualan',
|
||||||
|
'upah12'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Gadai;
|
use App\Gadai;
|
||||||
use App\Cawangan;
|
use App\Cawangan;
|
||||||
|
use App\Transaction;
|
||||||
|
use App\TransaksiKeuntungan;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@@ -116,13 +118,20 @@ class GadaiController extends Controller
|
|||||||
|
|
||||||
public function updateGadaiMarhunOnline($kodcaw,$norujukan,Request $request)
|
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 = Carbon::now();
|
||||||
$current = new Carbon();
|
$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_upah = $gadai['bakiupah'] - $request->bayaran;
|
||||||
|
$baki_hargajualan = $gadai['bakihargajualan'] - $request->bayaran;
|
||||||
if($gadai['bakipjm'] == null){
|
if($gadai['bakipjm'] == null){
|
||||||
$baki_pinjaman = $gadai['pinjaman'];
|
$baki_pinjaman = $gadai['pinjaman'];
|
||||||
}else{
|
}else{
|
||||||
@@ -134,15 +143,62 @@ class GadaiController extends Controller
|
|||||||
$baki_upah = 0;
|
$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(
|
$update_gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->update(array(
|
||||||
'bakipjm' => $baki_pinjaman,
|
'bakipjm' => $baki_pinjaman,
|
||||||
'bakiupah' => $baki_upah,
|
'bakiupah' => $baki_upah,
|
||||||
'jbg' => 0,
|
'jbg' => 0,
|
||||||
't_update' => $current->toDateString()
|
't_update' => $current->toDateString(),
|
||||||
|
'bakihargajualan' => $baki_hargajualan
|
||||||
));
|
));
|
||||||
return response()->json($update_gadai, 200);
|
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)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
Gadai::findOrFail($id)->delete();
|
Gadai::findOrFail($id)->delete();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace App;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Transaction extends Model
|
class TransaksiKeuntungan extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'transaksi_keuntungan';
|
protected $table = 'transaksi_keuntungan';
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
@@ -14,7 +14,7 @@ class Transaction extends Model
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'norujukan','bayaran_keuntungan','tarikh_bayaran','tempoh','kodcaw'
|
'norujukan','bayaran_keuntungan','tarikh_bayaran','kodcaw'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ $router->group(['prefix'=>'api'], function () use ($router){
|
|||||||
$router->put('gadai/{kodcaw}/norujukan/{norujukan}',['uses'=>'GadaiController@updateGadaiMarhunOnline']);
|
$router->put('gadai/{kodcaw}/norujukan/{norujukan}',['uses'=>'GadaiController@updateGadaiMarhunOnline']);
|
||||||
$router->put('gadai/norujukan/{kodcaw}/{norujukan}',['uses'=>'GadaiController@daftarGadaiMarhun']);
|
$router->put('gadai/norujukan/{kodcaw}/{norujukan}',['uses'=>'GadaiController@daftarGadaiMarhun']);
|
||||||
|
|
||||||
|
//Tebus API
|
||||||
|
$router->get('tebusonline/{kodcaw}/{norujukan}',['uses'=>'GadaiController@showTebusToday']);
|
||||||
|
|
||||||
//Lelong API
|
//Lelong API
|
||||||
$router->get('lelong',['uses'=>'LelongController@showAllLelongs']);
|
$router->get('lelong',['uses'=>'LelongController@showAllLelongs']);
|
||||||
$router->get('lelong/cawangan/{kodcaw}',['uses'=>'LelongController@showAllLelongByCawangan']);
|
$router->get('lelong/cawangan/{kodcaw}',['uses'=>'LelongController@showAllLelongByCawangan']);
|
||||||
|
|||||||
Reference in New Issue
Block a user