add daily akru generate
This commit is contained in:
@@ -25,7 +25,7 @@ use Carbon\Carbon;
|
|||||||
use App\imbangdugalama;
|
use App\imbangdugalama;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class LaporanController extends Controller
|
class LaporanController extends Controller
|
||||||
{
|
{
|
||||||
@@ -1300,4 +1300,76 @@ class LaporanController extends Controller
|
|||||||
|
|
||||||
return response($jumlah);
|
return response($jumlah);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GenerateDailyAkrual(Request $request){
|
||||||
|
|
||||||
|
$current = Carbon::now();
|
||||||
|
$current = new Carbon();
|
||||||
|
$month_generate = $current->format('m');
|
||||||
|
$year_generate = $current->format('Y');
|
||||||
|
$harini = $current->toDateString();
|
||||||
|
|
||||||
|
$haripertama = $current->firstOfMonth();
|
||||||
|
$haripertama_extension = $haripertama->toDateString();
|
||||||
|
|
||||||
|
$month_sebelum = $current->subMonth()->format('m');
|
||||||
|
|
||||||
|
$cawangan = Cawangan::on('mysql7')->where('zone',$request->zone)->get();
|
||||||
|
|
||||||
|
$tebuscontroller = new TebusController();
|
||||||
|
|
||||||
|
foreach($cawangan as $index=>$caw){
|
||||||
|
DB::connection($caw['mysql'])->beginTransaction();
|
||||||
|
|
||||||
|
if($year_generate == 2022 && (int)$month_sebelum > 4){
|
||||||
|
$audit_backdate = $tebuscontroller->StokAuditGenerateTerakru($month_sebelum,$caw,$year_generate);
|
||||||
|
}
|
||||||
|
|
||||||
|
$audit_now = Gadai::on($caw['mysql'])
|
||||||
|
->where([['tagpalsu','=',0],['t_gadai','<=',$harini],['sttebus','=','']])
|
||||||
|
->orWhere([['tagpalsu','=',0],['t_update','>',$harini],['sttebus','!=',''],['t_gadai','<=',$harini]]);
|
||||||
|
|
||||||
|
$totaltunggakan_now = $audit_now->sum('tunggakan');
|
||||||
|
$totaltunggakan_past = $audit_backdate->sum('upahblmbyar');
|
||||||
|
|
||||||
|
$request_generate = new \Illuminate\Http\Request([
|
||||||
|
'mula' => $haripertama_extension,
|
||||||
|
'hingga' => $harini,
|
||||||
|
'kodcaw' => $caw['kodcaw'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$keuntungan = $this->SemakanKeuntunganLejer($request->kodcaw,$request_generate);
|
||||||
|
|
||||||
|
$data_keuntungan = $keuntungan->getContent();
|
||||||
|
$data = json_decode($data_keuntungan, true);
|
||||||
|
|
||||||
|
$calculation = $totaltunggakan_past - $data['keuntungan_semasa'];
|
||||||
|
$accrual_net = $totaltunggakan_now - $calculation;
|
||||||
|
|
||||||
|
$available_akru = AkruNet::on($caw['mysql'])
|
||||||
|
->where('bulan',(int)$month_generate)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
try{
|
||||||
|
if($available_akru){
|
||||||
|
if($available_akru['jumlah'] !== $accrual_net){
|
||||||
|
AkruNet::on($caw['mysql'])->where('bulan','=',$current->month)
|
||||||
|
->update(['jumlah' => $accrual_net]);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$akrunet = new AkruNet();
|
||||||
|
$akrunet->setConnection($caw['mysql']);
|
||||||
|
$akrunet->tahun = $year_generate;
|
||||||
|
$akrunet->bulan = $month_generate;
|
||||||
|
$akrunet->jumlah = $accrual_net;
|
||||||
|
$akrunet->save();
|
||||||
|
}
|
||||||
|
DB::connection($caw['mysql'])->commit();
|
||||||
|
}catch (\Throwable $e){
|
||||||
|
return response($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response('succesfully generated!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -739,6 +739,7 @@ $router->group(['prefix'=>'admin'], function () use ($router){
|
|||||||
|
|
||||||
$router->get('laporanllcaw/gadai',['uses'=>'AdminPageController@getLaporanGadaiAllCaw']);
|
$router->get('laporanllcaw/gadai',['uses'=>'AdminPageController@getLaporanGadaiAllCaw']);
|
||||||
$router->get('laporan/akrubulan',['uses'=>'AdminPageController@getLaporanAkruBulan']);
|
$router->get('laporan/akrubulan',['uses'=>'AdminPageController@getLaporanAkruBulan']);
|
||||||
|
$router->get('laporan/akrual/generatedaily',['uses'=>'LaporanController@GenerateDailyAkrual']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->group(['prefix'=>'lelong'], function () use ($router){
|
$router->group(['prefix'=>'lelong'], function () use ($router){
|
||||||
|
|||||||
Reference in New Issue
Block a user