123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
-
- namespace App\Http\Controllers\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
-
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\Module\Compound;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\Department;
- use App\Model\Module\Faulty;
-
- class StatisticController extends BaseController
- {
-
- /**
- * Create compound report controller for kelantanpay.
- *
- * @return json
- */
-
- public function compoundBasedFaulty($start_date, $end_date){
-
- $temp = [];
- if($start_date == 'null'){
- $compound = Compound::with('Faulty')->distinct('seksyen_kesalahan')->groupBy('seksyen_kesalahan')->get();
- foreach ($compound as $key => $c) {
- $temp[] = $c->faulty;
- }
- }else {
- $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
- $start = $dateS->copy()->startOfDay();
-
- if($end_date != 'null'){
- $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- $compound = Compound::with('Faulty')->distinct('seksyen_kesalahan')->whereBetween('created_at', array($start, $end))
- ->groupBy('seksyen_kesalahan')->get();
- foreach ($compound as $key => $c) {
- $temp[] = $c->faulty;
- }
- }
-
- return $temp;
- }
-
- private function kadarKompaunDiBayar($id,$start_date,$end_date){
- $total = 0;
-
- if($start_date == 'null'){
- $compound = Compound::where('seksyen_kesalahan', $id)->where('status','Berbayar')->get();
- foreach ($compound as $key => $c) {
- $total += $c->amount_payment;
- }
- }else{
- $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
- $start = $dateS->copy()->startOfDay();
-
- if($end_date != 'null'){
- $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- $compound = Compound::with('Faulty')->where('seksyen_kesalahan', $id)->where('status','Berbayar')
- ->whereBetween('created_at', array($start, $end))->get();
- foreach ($compound as $key => $c) {
- $total += ($c->Faulty->amount - $c->amount_payment);
- }
- }
- return $total;
- }
-
- private function kadarKompaunKurang($id,$start_date,$end_date){
- $total = 0;
-
- if($start_date == 'null'){
- $compound = Compound::with('Faulty')->where('seksyen_kesalahan', $id)->where('status','Berbayar')->get();
- foreach ($compound as $key => $c) {
- $total += ($c->Faulty->amount - $c->amount_payment);
- }
- }else{
- $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
- $start = $dateS->copy()->startOfDay();
-
- if($end_date != 'null'){
- $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- $compound = Compound::with('Faulty')->where('seksyen_kesalahan', $id)->where('status','Berbayar')
- ->whereBetween('created_at', array($start, $end))->get();
- foreach ($compound as $key => $c) {
- $total += ($c->Faulty->amount - $c->amount_payment);
- }
- }
-
- return $total;
- }
-
- public function reportCompoundList($start_date, $end_date)
- {
- $nested_data = array();
- $noFaulty = $this->compoundBasedFaulty($start_date, $end_date);
-
- if($start_date == 'null'){
- foreach ($noFaulty as $key => $f) {
-
- $jumlah_kompaun = 0; $jumlah_kadar_kompaun = 0;
- $jumlah_kompaun_dibayar = 0; $jumlah_kadar_kompaun_dibayar = 0;
- $jumlah_kompaun_belum_bayar = 0; $jumlah_tunggakkan = 0;
- $jumlah_kompaun_kurg = 0; $jumlah_kadar_kompaun_kurg = 0;
-
- $jumlah_kompaun = count(Compound::where('seksyen_kesalahan', $f->_id)->get());
- $jumlah_kadar_kompaun = floatval($f->amount) * $jumlah_kompaun;
- $jumlah_kompaun_dibayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Berbayar')->get());
- $jumlah_kompaun_belum_bayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Belum Bayar')->get());
- $jumlah_tunggakkan = ($jumlah_kompaun_belum_bayar - $jumlah_kompaun_dibayar) * floatval($f->amount);
- $jumlah_kompaun_kurg = count(Compound::where('seksyen_kesalahan', $f->_id)->where('jumlah_kemaskini_kompaun','!=','')->get());
-
- $jumlah_kadar_kompaun_dibayar = $this->kadarKompaunDiBayar($f->_id,$start_date,$end_date);
- $jumlah_kadar_kompaun_kurg = $this->kadarKompaunKurang($f->_id,$start_date,$end_date);
-
- array_push($nested_data, array(
- 'kesalahan' => $f->nama,
- 'jumlahK' => $jumlah_kompaun,
- 'amaunK' => $jumlah_kadar_kompaun,
- 'jumlahB' => $jumlah_kompaun_dibayar,
- 'amaunB' => $jumlah_kadar_kompaun_dibayar,
- 'belumB' => $jumlah_kompaun_belum_bayar,
- 'amaunT' => $jumlah_tunggakkan,
- 'kBatal' => '0',
- 'amaunBatal' => '0',
- 'kompaunKurang' => $jumlah_kompaun_kurg,
- 'amaunKurang' => $jumlah_kadar_kompaun_kurg,
- ));
-
- }
- }else{
-
- $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
- $start = $dateS->copy()->startOfDay();
-
- if($end_date != 'null'){
- $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- foreach ($noFaulty as $key => $f) {
-
- $jumlah_kompaun = 0; $jumlah_kadar_kompaun = 0;
- $jumlah_kompaun_dibayar = 0; $jumlah_kadar_kompaun_dibayar = 0;
- $jumlah_kompaun_belum_bayar = 0; $jumlah_tunggakkan = 0;
- $jumlah_kompaun_kurg = 0; $jumlah_kadar_kompaun_kurg = 0;
-
- $jumlah_kompaun = count(Compound::where('seksyen_kesalahan', $f->_id)->whereBetween('created_at', array($start, $end))->get());
- $jumlah_kadar_kompaun = floatval($f->amount) * $jumlah_kompaun;
- $jumlah_kompaun_dibayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Berbayar')->whereBetween('created_at', array($start, $end))->get());
- $jumlah_kompaun_belum_bayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Belum Bayar')->whereBetween('created_at', array($start, $end))->get());
- $jumlah_tunggakkan = ($jumlah_kompaun_belum_bayar - $jumlah_kompaun_dibayar) * floatval($f->amount);
- $jumlah_kompaun_kurg = count(Compound::where('seksyen_kesalahan', $f->_id)->where('jumlah_kemaskini_kompaun','!=','')->whereBetween('created_at', array($start, $end))->get());
-
- $jumlah_kadar_kompaun_dibayar = $this->kadarKompaunDiBayar($f->_id,$start_date,$end_date);
- $jumlah_kadar_kompaun_kurg = $this->kadarKompaunKurang($f->_id,$start_date,$end_date);
-
- array_push($nested_data, array(
- 'kesalahan' => $f->nama,
- 'jumlahK' => $jumlah_kompaun,
- 'amaunK' => $jumlah_kadar_kompaun,
- 'jumlahB' => $jumlah_kompaun_dibayar,
- 'amaunB' => $jumlah_kadar_kompaun_dibayar,
- 'belumB' => $jumlah_kompaun_belum_bayar,
- 'amaunT' => $jumlah_tunggakkan,
- 'kBatal' => '0',
- 'amaunBatal' => '0',
- 'kompaunKurang' => $jumlah_kompaun_kurg,
- 'amaunKurang' => $jumlah_kadar_kompaun_kurg,
- ));
-
- }
- }
-
- return \DataTables::of($nested_data)->addIndexColumn()->make(true);
- }
- }
|