fix skit2

This commit is contained in:
hafifierahman
2024-10-09 08:04:21 +08:00
parent d3fe2cf03d
commit 4d9fe3b9f4
3 changed files with 195 additions and 4 deletions
@@ -628,4 +628,98 @@ class GeneralLedger
return $wtd;
}
public function getTotalKeuntungan() : Float{
/* Keuntungan Semasa */
$keuntungan_semasa = $this->CurrentProfit($this->mula,$this->hingga,$this->kodcaw);
$totalkeuntungan=$keuntungan_semasa['onepercent'];
return $totalkeuntungan;
}
public function getTotalUjrah() : Float{
/* Keuntungan Semasa */
$keuntungan_semasa = $this->CurrentProfit($this->mula,$this->hingga,$this->kodcaw);
$totalujrah = $keuntungan_semasa['ujrah'];
return $totalujrah;
}
public function CurrentProfit($start,$end,$kodcaw){
$start = new Carbon($start);
$year = $start->format('Y');
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$collection_trans = TransaksiKeuntungan::on('mysql7')
->leftJoin('transaction as trans', function($join)
{
$join->on('transaksi_keuntungan.norujukan', '=', 'trans.norujukan');
$join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at');
})
->where('trans.kodcaw','=',$kodcaw)
->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $end)
->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'>=', $start)
->whereYear('transaksi_keuntungan.tarikh_bayaran','=',$year)
->get();
$array_norujukan = $collection_trans->pluck('norujukan')->toArray();
$collection_gadai = Gadai::on($cawangan['mysql'])->whereIn('norujukan',$array_norujukan)->get();
/* filtering untuk gadai yang ditebus pada bukan bulan yang sama */
$keuntungan_semasa_collection = $collection_trans->filter(function ($trans) use ($collection_gadai) {
foreach ($collection_gadai as $gadai) {
if($gadai->norujukan === $trans->norujukan){
$t_gadai = Carbon::parse($gadai->t_gadai);
$t_bayaran = Carbon::parse($trans->tarikh_bayaran);
if ($t_gadai->month === $t_bayaran->month) {
return false;
}else{
return true;
}
}
}
return false;
});
$ujrah = $this->filterCollection($keuntungan_semasa_collection,'A','ujrah');
$onepercent = $this->filterCollection($keuntungan_semasa_collection,'A','onepercent');
$ujrah_rebet = $this->filterCollection($keuntungan_semasa_collection,'T','ujrah_rebet');
$onepercent_rebet = $this->filterCollection($keuntungan_semasa_collection,'T','onepercent_rebet');
$upahlelong = Lelong::on($cawangan['mysql'])
->selectRaw('SUM(ujrah) as ujrah,SUM(onepercent) as onepercent')
->where([['tagujrah','=',1],['t_jual','>=',$start],['t_jual','<=',$end]])
->whereYear('t_jual','=',$year)
->get()->toArray();
$ujrah_lelong = (empty($upahlelong)) ? 0 : $upahlelong[0]['ujrah'];
$onepercent_lelong = (empty($upahlelong)) ? 0 : $upahlelong[0]['onepercent'];
$total_onepercent = $onepercent + $onepercent_rebet + $onepercent_lelong;
$total_ujrah = $ujrah + $ujrah_rebet + $ujrah_lelong;
return ['ujrah' => $total_ujrah,'onepercent' => $total_onepercent];
}
private function filterCollection($collection,$type,$sumtype) : Float{
$array_type = ['T','S','P','AT'];
return $collection->filter(function ($item) use($type,$array_type) {
if($type == 'T')
return in_array($item->trans_type, $array_type);
return $item->trans_type === $type;
})->sum($sumtype);
}
}