changed from server 30/12/2024
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Tebus;
|
||||
use App\Transaction;
|
||||
use App\TransaksiKeuntungan;
|
||||
use App\WTD;
|
||||
use App\AkruNet;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class GeneralLedger
|
||||
@@ -517,6 +518,43 @@ class GeneralLedger
|
||||
$mulaCarbon = new Carbon($this->mula);
|
||||
$hinggaCarbon = new Carbon($this->hingga);
|
||||
|
||||
if($this->isFullMonth($this->mula,$this->hingga) && $mulaCarbon->month < 10){
|
||||
$lastDayOfPreviousMonth = $mulaCarbon->subMonth()->endOfMonth();
|
||||
|
||||
$balancesheet_previousmonth = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$lastDayOfPreviousMonth->toDateString())->first()->toArray();
|
||||
$balancesheet_currentmonth = imbangdugabackup::on($cawangan['mysql'])->where('tarikh',$this->hingga)->first()->toArray();
|
||||
// dd($lastDayOfPreviousMonth->toDateString(),$this->hingga,$balancesheet_previousmonth['keun_sebenar'],$balancesheet_currentmonth['keun_sebenar']);
|
||||
|
||||
$realprofit_previousmonth = ($lastDayOfPreviousMonth->year == $hinggaCarbon->year) ? $balancesheet_previousmonth['keun_sebenar'] : 0;
|
||||
$realprofit_currentmonth = $balancesheet_currentmonth['keun_sebenar'];
|
||||
|
||||
$total_keuntungan_sebenar = $realprofit_currentmonth - $realprofit_previousmonth;
|
||||
|
||||
$month = $lastDayOfPreviousMonth->month;
|
||||
$className_previous = "App\StokAudit{$month}";
|
||||
|
||||
$month_current = $hinggaCarbon->month;
|
||||
$className_current = "App\StokAudit{$month_current}";
|
||||
|
||||
$stokaudit_previous = $className_previous::on($cawangan['mysql'])->where('tahun',$lastDayOfPreviousMonth->year);
|
||||
$stokaudit_current = $className_current::on($cawangan['mysql'])->where('tahun',$hinggaCarbon->year);
|
||||
|
||||
$akrunet = AkruNet::on($cawangan['mysql'])->where('bulan',$month_current)->where('tahun',$hinggaCarbon->year)->first()->toArray();
|
||||
|
||||
|
||||
$stokaudit_previous = $stokaudit_previous->sum('upahblmbyar');
|
||||
$stokaudit_current = $stokaudit_current->sum('upahblmbyar');
|
||||
|
||||
// $pend_terakru = $balancesheet_currentmonth['pend_terakru'];
|
||||
|
||||
$total = $akrunet['jumlah'] - $stokaudit_current;
|
||||
$total_keuntungan_semasa = abs($total) - $stokaudit_previous;
|
||||
|
||||
$array_keuntungan = ['keuntungan_sebenar' => abs($total_keuntungan_sebenar), 'keuntungan_semasa' => abs($total_keuntungan_semasa)];
|
||||
|
||||
return $array_keuntungan;
|
||||
}
|
||||
|
||||
/* Start Keuntungan Sebenar Calculation */
|
||||
$collection_trans = Transaction::on('mysql7')
|
||||
->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
@@ -718,6 +756,24 @@ class GeneralLedger
|
||||
})->sum($sumtype);
|
||||
}
|
||||
|
||||
private function isFullMonth($startDate,$endDate){
|
||||
// Parse the dates to Carbon instances
|
||||
$start = Carbon::parse($startDate);
|
||||
$end = Carbon::parse($endDate);
|
||||
|
||||
// Check if the start date is the first day of the month
|
||||
$isFirstDay = $start->isSameDay($start->copy()->startOfMonth());
|
||||
|
||||
// Check if the end date is the last day of the month
|
||||
$isLastDay = $end->isSameDay($end->copy()->endOfMonth());
|
||||
|
||||
// Check if both dates are in the same month and year
|
||||
$isSameMonth = $start->isSameMonth($end) && $start->isSameYear($end);
|
||||
|
||||
// Return true only if all conditions are met
|
||||
return $isFirstDay && $isLastDay && $isSameMonth;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user