123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
-
- namespace App\Http\Controllers\api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\User;
- use App\Model\UserDetail;
- use App\Model\Module\Compound;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\Department;
- use App\Model\Module\DeedLaw;
- use App\Model\Module\Faulty;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\ReportPayment;
- use App\Model\Module\ApiIntegration;
-
- class PaymentController extends BaseController
- {
-
- /**
- * Create compound list controller for kelantanpay.
- *
- * @return json
- */
- public function paymentCompound(Request $request)
- {
- $data = array();
-
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Gagal', 'penguatkuasa tidak wujud');
- }else {
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
- if (!empty($compound)) {
-
- $jumlah = '';
- if($compound->jumlah_kemaskini_kompaun == ''){
- $jumlah = $compound->jumlah_asal_kompaun;
- }else{
- $jumlah = $compound->jumlah_kemaskini_kompaun;
- }
-
- if($request->jumlah_bayar != $jumlah){
- array_push($data, array(
- 'kpd' => $request->kpd,
- 'jumlah_kompaun' => $jumlah,
- 'jumlah_bayar' => $request->jumlah_bayar,
- ));
-
- return $this->sendError($data, 'Jumlah yang dibayar tidak sama dengan jumlah kompaun!');
- }else{
-
- if($compound->status == 'Belum Bayar'){
-
- $kompaun = Compound::where('kpd', $request->kpd)->first();
- $kesalahan = Faulty::where('itkod', $kompaun->seksyen_kesalahan)->first();
-
- $reportData = [
- 'name' => $request->name,
- 'kesalahan' => $kesalahan->nama,
- 'kpd' => $request->kpd,
- 'nric' => $request->ic,
- 'mobile' => $request->telefon,
- 'email' => $request->email,
- 'total' => $request->jumlah_bayar,
- 'penguatkuasa' => $staff->no_badan,
-
- ];
-
- $report = ReportPayment::create($reportData);
-
- $compound->status = 'Berbayar';
- $compound->receipt = $request->receipt;
- $compound->amount_payment = $jumlah;
- $compound->save();
-
- array_push($data, array(
- 'kpd' => $request->kpd,
- 'amount' => $jumlah,
- ));
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Pembayaran kompaun ".$request->kpd." telah dibuat secara tunai",
- 'huraian' => "Pembayaran tunai diserahkan kepada ".$staff->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse($data, 'Kompaun ini berjaya dibayar!');
-
- }else if($compound->status == 'Berbayar'){
- array_push($data, array(
- 'kpd' => $request->kpd,
- 'amount' => $jumlah,
- ));
- return $this->sendError($data, 'Kompaun ini dah dibayar!');
- }
- }
-
- }else {
- return $this->sendError($data, 'Tiada data');
- }
- }
- }
-
- public function updatePayment(Request $request){
- $compound = Compound::with('ConfidentialFile')->where('kpd', $request->orderid)->first();
- if(!empty($compound)){
- $compound->status = 'Berbayar';
- $compound->save();
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
- 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'status pembayaran kompaun berjaya dikemaskini dari BELUM BAYAR ke BERBAYAR');
- }else{
- return $this->sendError('', 'status pembayaran kompaun tidak dapat dikemaskini sebab rekod tidak dijumpai');
- }
- }
-
- public function reportpaymentList(){
- $nested_data = array();
- $report = ReportPayment::orderBy('updated_at','DESC')->get();
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($report as $a)
- {
- $n1 = ''; $enforcer = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "Baru/";
- }else{
- $n1 = "";
- }
-
- $staff = Staff::with('StaffDetail')->where('_id',$a->penguatkuasa)->first();
- if(!empty($staff)){
- $enforcer = '['.$staff->no_badan.'] '.$staff->StaffDetail->full_name;
- }
-
- // $noKPD = Compound::where('kpd', $a->kpd)->first();
- // $namaSeksyen = Faulty::where('itkod',$a->seksyen_kesalahan)->first();
-
-
- array_push($nested_data, array(
- '#' => $n1.$i,
- 'kpd' => $a->kpd,
- 'nama' => $a->name,
- 'kesalahan' => $a->kesalahan,
- 'identity' => $a->nric,
- 'mobile' => $a->mobile,
- 'email' => $a->email,
- 'jumlah' => 'Rm '.$a->total,
- 'no_badan' => $enforcer,
- ));
-
- $i++;
- }
- return \DataTables::of($nested_data)->make(true);
- }
- }
|