Ejemplo n.º 1
0
 public function yuranProcess()
 {
     // Session::flash('error', 'Sistem dalam Pengemaskinian. Proses Yuran tergendala. Harap Maaf.');
     // return Redirect::back();
     // check for repeated payment for the selected month
     $doneMonth = Yuran::where('bulan_tahun', Request::get('bulan_tahun'))->first();
     $currentMonth = date('m');
     $currentYear = date('Y');
     $postedDate = explode('-', Request::get('bulan_tahun'));
     $postedMonth = $postedDate[0];
     $postedYear = $postedDate[1];
     if ($postedYear > $currentYear || $postedYear < $currentYear) {
         Session::flash('error', 'Gagal. Potongan hendaklah pada tahun semasa.');
         return Redirect::back();
     }
     if ($postedYear == $currentYear) {
         if ($postedMonth > $currentMonth) {
             Session::flash('error', 'Gagal. Potongan hendaklah pada bulan semasa atau sebelum.');
             return Redirect::back();
         }
     }
     if (!empty($doneMonth)) {
         Session::flash('error', 'Gagal. Bulan yang dipilih telah dibuat potongan.');
         return Redirect::back();
     }
     $profiles = Profile::where('status', 1)->where('zon_gaji_id', '!=', 20)->where('tarikh_ahli', 'not like', Carbon::now()->format('Y-m') . '%')->get();
     foreach ($profiles as $profile) {
         $jumlahPotongan = '0.00';
         $tka = Tka::where('status', 1)->first();
         $takaful = Takaful::where('status', 1)->first();
         $dates = explode('-', Request::get('bulan_tahun'));
         $tarikh = $dates[1] . '-' . $dates[0] . '01 00:00:00';
         $potongan = AkaunPotongan::where('no_gaji', $profile->no_gaji)->where('status', 1)->first();
         // check bayaran yuran sudah dibuat atau belum
         // jika belum proses bayaran
         // jika sudah, skip proses bayaran
         if (!$this->checkPotongan($profile->no_gaji)) {
             $yuran = $profile->jumlah_yuran_bulanan;
             $pertaruhan = $profile->jumlah_pertaruhan;
             $tka = Tka::where('status', 1)->first()->jumlah;
             $takaful = Takaful::where('status', 1)->first()->jumlah;
             // kod = 1
             $pwt = $this->getJumlah($profile->no_gaji, 1, 'bulanan');
             $pwtcp = $this->getJumlah($profile->no_gaji, 1, 'caj_proses');
             $pwtins = $this->getJumlah($profile->no_gaji, 1, 'insurans');
             // Kod = 2
             $bs = $this->getJumlah($profile->no_gaji, 2, 'bulanan');
             // Kod = 3;
             $rt = $this->getJumlah($profile->no_gaji, 3, 'bulanan');
             // Kod = 5
             $tb = $this->getJumlah($profile->no_gaji, 5, 'bulanan');
             $tbcp = $this->getJumlah($profile->no_gaji, 5, 'caj_proses');
             $tbins = $this->getJumlah($profile->no_gaji, 5, 'insurans');
             // kod = 6
             $kc = $this->getJumlah($profile->no_gaji, 6, 'bulanan');
             $kccp = $this->getJumlah($profile->no_gaji, 6, 'caj_proses');
             $kcins = $this->getJumlah($profile->no_gaji, 6, 'insurans');
             // if($profile->no_gaji == 3374)
             //     return $pwt;
             Yuran::create(['no_gaji' => $profile->no_gaji, 'bulan_tahun' => Request::get('bulan_tahun'), 'yuran' => $yuran, 'pertaruhan' => $pertaruhan, 'tka' => $tka, 'takaful' => $takaful, 'pwt' => $pwt, 'pwtcp' => $pwtcp, 'pwtins' => $pwtins, 'bs' => $bs, 'rt' => $rt, 'tb' => $tb, 'tbcp' => $tbcp, 'tbins' => $tbins, 'kc' => $kc, 'kccp' => $kccp, 'kcins' => $kcins, 'zon_gaji_id' => $profile->zon_gaji_id]);
         }
     }
     return Redirect::route('members.yuran.index');
 }