added function to update all ig
This commit is contained in:
@@ -3834,18 +3834,20 @@ class AdminPageController extends Controller
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->simplePaginate(5);
|
||||
$check = app(AccountService::class);
|
||||
|
||||
$array_all = [];
|
||||
$array_all = ['current_page' => $cawangan->currentPage()];
|
||||
foreach($cawangan as $caw){
|
||||
try{
|
||||
$test =$check->checkAccount($caw['kodcaw'],'8');
|
||||
$array_all[$caw['kodcaw']] = $test;
|
||||
$test =$check->checkAccount($caw['kodcaw'],$request->month);
|
||||
$array_all['data'][$caw['details_caw']] = $test;
|
||||
}catch(\Exception $e){
|
||||
Log::error($caw['kodcaw']);
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($array_all);
|
||||
$response = $array_all;
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\imbangdugabackup;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Reports\ImbangDugaService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BalanceSheetsController extends Controller
|
||||
{
|
||||
@@ -24,10 +25,27 @@ class BalanceSheetsController extends Controller
|
||||
|
||||
public function insertBalanceSheets(Request $request){
|
||||
$igService = new ImbangDugaService($request->kodcaw,$request->tarikh);
|
||||
|
||||
$insert_imbangduga = $igService->setImbangDugaBackup();
|
||||
|
||||
return $insert_imbangduga;
|
||||
}
|
||||
|
||||
public function updateIGBalanceSheets(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->get();
|
||||
$date = Carbon::now()->month($request->month);
|
||||
$lastDay = (clone $date)->endOfMonth();
|
||||
|
||||
try{
|
||||
foreach($cawangan as $caw){
|
||||
$igService = new ImbangDugaService($caw['kodcaw'],$lastDay->toDateString());
|
||||
$insert_imbangduga = $igService->setImbangDugaBackup();
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
return response('success');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\GlCode;
|
||||
use App\GlDetail;
|
||||
use App\imbangdugabackup;
|
||||
use App\imbangdugalama;
|
||||
use App\Lelong;
|
||||
use App\Panjar;
|
||||
@@ -511,103 +512,94 @@ class GeneralLedger
|
||||
$hinggaCarbon = new Carbon($this->hingga);
|
||||
|
||||
/* Start Keuntungan Sebenar Calculation */
|
||||
$get_norujukan = Gadai::on($cawangan['mysql'])
|
||||
->selectRaw("norujukan,CASE WHEN (YEAR(t_gadai) = YEAR(t_update) and MONTH(t_gadai) = MONTH(t_update)) THEN '1' ELSE '0' END AS result")
|
||||
->whereNotNull('hargajualan')->having('result','=',1)->whereDate('t_update','>=',$this->mula)->whereDate('t_update','<=',$this->hingga)->where('sttebus','<>','')->pluck('norujukan');
|
||||
$sum_keun = Transaction::on('mysql7')
|
||||
->selectRaw("trans.norujukan,SUM(CASE WHEN (transaction.trans_type) <> 'A' THEN (trans.keuntungan_rebet) ELSE 0 END) AS sum_keun,SUM(CASE WHEN (transaction.trans_type) = 'A' AND (trans.margin_semasa) = 0 THEN (trans.bayaran_keuntungan) ELSE 0 END) AS sum_bayaran")
|
||||
->leftJoin('transaksi_keuntungan as trans', function($join)
|
||||
{
|
||||
$collection_trans = Transaction::on('mysql7')
|
||||
->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.kodcaw', $this->kodcaw)
|
||||
->whereDate('transaction.created_at' ,'>=', $this->mula)
|
||||
->whereDate('transaction.created_at' ,'<=', $this->hingga)
|
||||
->get();
|
||||
|
||||
$array_norujukan = $collection_trans->pluck('norujukan')->toArray();
|
||||
|
||||
$collection_gadai = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $array_norujukan)->whereYear('t_gadai',$mulaCarbon->year)->get();
|
||||
|
||||
$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;
|
||||
});
|
||||
|
||||
$total_ansuran = $keuntungan_semasa_collection->filter(function ($transaction){
|
||||
return $transaction->trans_type == 'A';
|
||||
})->sum('bayaran_keuntungan');
|
||||
|
||||
$total_tebus = $keuntungan_semasa_collection->filter(function ($transaction){
|
||||
return $transaction->trans_type !== 'A';
|
||||
})->sum('keuntungan_rebet');
|
||||
|
||||
$total_keuntungan_sebenar = $total_ansuran + $total_tebus;
|
||||
/* End Keuntungan Sebenar Calculation */
|
||||
|
||||
/* Start Keuntungan Semasa Calculation */
|
||||
$collection_trans = Transaction::on('mysql7')
|
||||
->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->whereIn('trans.norujukan',$get_norujukan)->get()->toArray();
|
||||
|
||||
$sum_keuntungan = ($sum_keun) ? $sum_keun[0]['sum_keun'] : 0;
|
||||
$sum_bayaran = ($sum_keun) ? $sum_keun[0]['sum_bayaran'] : 0;
|
||||
|
||||
// $get_norujukan_ansuran = Gadai::on($cawangan['mysql'])
|
||||
// ->selectRaw("norujukan,CASE WHEN (YEAR(t_gadai) = YEAR(t_update) and MONTH(t_gadai) = MONTH(t_update)) THEN '1' ELSE '0' END AS result")
|
||||
// ->whereNotNull('hargajualan')
|
||||
// ->having('result','=',1)
|
||||
// ->whereDate('t_update','>=',$this->mula)->whereDate('t_update','<=',$this->hingga)
|
||||
// ->where('sttebus','=','')
|
||||
// ->where('tagbaru','=',1)
|
||||
// ->pluck('norujukan');
|
||||
|
||||
// $summation_ansuran = TransaksiKeuntungan::on('mysql7')
|
||||
// ->whereIn('norujukan',$get_norujukan_ansuran)->sum('bayaran_keuntungan');
|
||||
|
||||
$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','=',$this->kodcaw)
|
||||
->where('trans.trans_type','=','A')
|
||||
->where('transaksi_keuntungan.margin_semasa','>','0')
|
||||
->whereDate('transaksi_keuntungan.tarikh_bayaran','>=',$this->mula)
|
||||
->whereDate('transaksi_keuntungan.tarikh_bayaran','<=',$this->hingga)
|
||||
->where('transaction.kodcaw', $this->kodcaw)
|
||||
->whereDate('transaction.created_at' ,'>=', $this->mula)
|
||||
->whereDate('transaction.created_at' ,'<=', $this->hingga)
|
||||
->get();
|
||||
|
||||
|
||||
$array_norujukan = $collection_trans->pluck('norujukan')->toArray();
|
||||
|
||||
$collection_gadai = Gadai::on($cawangan['mysql'])->whereIn('norujukan',$array_norujukan)->where('tagbaru',1)->get();
|
||||
$collection_gadai = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $array_norujukan)->where('tagbaru',0)->get();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
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) && ($t_gadai->year == $t_bayaran->year)) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$summation_ansuran = $keuntungan_semasa_collection->sum('bayaran_keuntungan');
|
||||
$total_ansuran = $keuntungan_semasa_collection->filter(function ($transaction){
|
||||
return $transaction->trans_type == 'A';
|
||||
})->sum('bayaran_keuntungan');
|
||||
|
||||
$total_keuntungan_sebenar = $sum_keuntungan + $sum_bayaran + $summation_ansuran;
|
||||
/* End Keuntungan Sebenar Calculation */
|
||||
|
||||
/* Start Keuntungan Semasa Calculation */
|
||||
$get_norujukan = Gadai::on($cawangan['mysql'])
|
||||
->selectRaw("norujukan,CASE WHEN (YEAR(t_gadai) = YEAR(t_update) and MONTH(t_gadai) = MONTH(t_update)) THEN '1' ELSE '0' END AS result")
|
||||
->whereNotNull('hargajualan')->where('tagbaru',0)->having('result','=',0)->pluck('norujukan');
|
||||
|
||||
$summation = Transaction::on('mysql7')
|
||||
->selectRaw("SUM(CASE WHEN (transaction.trans_type) <> 'A' THEN (trans.keuntungan_rebet) ELSE 0 END) AS sum_keun,SUM(CASE WHEN (transaction.trans_type) = 'A' THEN (trans.bayaran_keuntungan) ELSE 0 END) AS sum_bayaran")
|
||||
->leftJoin('transaksi_keuntungan as trans', function($join)
|
||||
{
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->whereIn('trans.norujukan',$get_norujukan)
|
||||
->whereDate('trans.tarikh_bayaran' ,'>=', $this->mula)
|
||||
->whereDate('trans.tarikh_bayaran' ,'<=', $this->hingga)
|
||||
->whereYear('tarikh_bayaran','=',$mulaCarbon->year)
|
||||
->where('trans.kodcaw',$this->kodcaw)
|
||||
->get()->toArray();
|
||||
$total_tebus = $keuntungan_semasa_collection->filter(function ($transaction){
|
||||
return $transaction->trans_type !== 'A';
|
||||
})->sum('keuntungan_rebet');
|
||||
|
||||
/* Keuntungan Lelong */
|
||||
$upahlelong = Lelong::on($cawangan['mysql'])
|
||||
->where([['t_jual','>=',$this->mula],['t_jual','<=',$this->hingga],['t_jual','>','2022-07-24']])
|
||||
->whereYear('t_jual','=',$mulaCarbon->year)
|
||||
->sum('bakiupah');
|
||||
|
||||
$sum_keuntungan = ($summation) ? $summation[0]['sum_keun'] : 0;
|
||||
$sum_bayaran = ($summation) ? $summation[0]['sum_bayaran'] : 0;
|
||||
|
||||
// $total_keuntungan_semasa = ($sum_keuntungan + $sum_bayaran + $upahlelong) - $total_keuntungan_sebenar;
|
||||
$total_keuntungan_semasa = ($sum_keuntungan + $sum_bayaran + $upahlelong);
|
||||
->where([['tagujrah','=',0],['t_jual', '>=', $this->mula], ['t_jual', '<=', $this->hingga], ['t_jual', '>', '2022-07-24']])
|
||||
->whereYear('t_jual', '=', $mulaCarbon->year)
|
||||
->sum('bakiupah');
|
||||
|
||||
$total_keuntungan_semasa = ($total_ansuran + $total_tebus + $upahlelong);
|
||||
/* End Keuntungan Semasa Calculation */
|
||||
|
||||
$array_keuntungan = ['keuntungan_sebenar' => $total_keuntungan_sebenar, 'keuntungan_semasa' => $total_keuntungan_semasa];
|
||||
|
||||
@@ -59,9 +59,9 @@ class AccountService{
|
||||
$total_bds = -($cash['bds']);
|
||||
$total_perubatan = -($cash['perubatan']);
|
||||
$total_keraian = -($cash['keraian']);
|
||||
$total_keun_sebenar = $real_profit;
|
||||
$total_keun_sebenar = $current_profit['keuntungan_sebenar'];
|
||||
$total_rugilelong = $remain_auction['rugi'] - $remain_auction['rugilelong'];
|
||||
$total_bakilelong = - $remain_auction['baki'] - $remain_auction['bakilelong'];
|
||||
$total_bakilelong = $remain_auction['baki'] - $remain_auction['bakilelong'];
|
||||
$total_pend_terakru = $akru_net;
|
||||
$total_ujrah = $akru_net_ujrah;
|
||||
$total_onepercent = $akru_net_onepercent;
|
||||
|
||||
@@ -928,7 +928,6 @@ class ImbangDugaService
|
||||
} else {
|
||||
$booltally = false;
|
||||
}
|
||||
// dd($totalharta[0],$totaltanggungan[0],$pend_terakru,$keuntungan_penggadai,$keun_sebenar);
|
||||
|
||||
imbangdugabackup::on($cawangan['mysql'])->where('tarikh', $this->tarikh)->update([
|
||||
'tunaiditangan' => $tunaiditangan,
|
||||
|
||||
@@ -29,5 +29,6 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
|
||||
$router->get('balancesheets/get',['uses' => 'BalanceSheetsController@getBalanceSheetsList']);
|
||||
|
||||
$router->get('updateig',['uses' => 'BalanceSheetsController@insertBalanceSheets']);
|
||||
$router->get('updateigall',['uses' => 'BalanceSheetsController@updateIGBalanceSheets']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user