Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PaymentController.php 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Config;
  6. use File;
  7. use Carbon\Carbon;
  8. use App\Model\Staff;
  9. use App\Model\StaffDetail;
  10. use App\Model\User;
  11. use App\Model\UserDetail;
  12. use App\Model\Module\Compound;
  13. use App\Model\Module\ConfidentialFile;
  14. use App\Model\Module\Department;
  15. use App\Model\Module\DeedLaw;
  16. use App\Model\Module\Faulty;
  17. use App\Model\Module\History;
  18. use App\Model\Module\SubHistory;
  19. use App\Model\Module\ReportPayment;
  20. use App\Model\Module\ApiIntegration;
  21. class PaymentController extends BaseController
  22. {
  23. /**
  24. * Create compound list controller for kelantanpay.
  25. *
  26. * @return json
  27. */
  28. public function paymentCompound(Request $request)
  29. {
  30. $data = array();
  31. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  32. if(empty($staff)){
  33. return $this->sendError('Gagal', 'penguatkuasa tidak wujud');
  34. }else {
  35. $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  36. if (!empty($compound)) {
  37. $jumlah = '';
  38. if($compound->jumlah_kemaskini_kompaun == ''){
  39. $jumlah = $compound->jumlah_asal_kompaun;
  40. }else{
  41. $jumlah = $compound->jumlah_kemaskini_kompaun;
  42. }
  43. if($request->jumlah_bayar != $jumlah){
  44. array_push($data, array(
  45. 'kpd' => $request->kpd,
  46. 'jumlah_kompaun' => $jumlah,
  47. 'jumlah_bayar' => $request->jumlah_bayar,
  48. ));
  49. return $this->sendError($data, 'Jumlah yang dibayar tidak sama dengan jumlah kompaun!');
  50. }else{
  51. if($compound->status == 'Belum Bayar'){
  52. $kompaun = Compound::where('kpd', $request->kpd)->first();
  53. $kesalahan = Faulty::where('itkod', $kompaun->seksyen_kesalahan)->first();
  54. $reportData = [
  55. 'name' => $request->name,
  56. 'kesalahan' => $kesalahan->nama,
  57. 'kpd' => $request->kpd,
  58. 'nric' => $request->ic,
  59. 'mobile' => $request->telefon,
  60. 'email' => $request->email,
  61. 'total' => $request->jumlah_bayar,
  62. 'penguatkuasa' => $staff->no_badan,
  63. ];
  64. $report = ReportPayment::create($reportData);
  65. $compound->status = 'Berbayar';
  66. $compound->receipt = $request->receipt;
  67. $compound->amount_payment = $jumlah;
  68. $compound->save();
  69. array_push($data, array(
  70. 'kpd' => $request->kpd,
  71. 'amount' => $jumlah,
  72. ));
  73. $now = Carbon::now();
  74. $gDate = $now->format('F Y');
  75. $historyData = [
  76. 'tarikh_kumpulan' => $gDate,
  77. ];
  78. $subHistory = [
  79. 'no_siri' => $compound->ConfidentialFile->no_siri,
  80. 'tajuk' => "Pembayaran kompaun ".$request->kpd." telah dibuat secara tunai",
  81. 'huraian' => "Pembayaran tunai diserahkan kepada ".$staff->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  82. ];
  83. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  84. if(!empty($groupByDate)){
  85. $groupByDate->subhistory()->create($subHistory);
  86. $compound->ConfidentialFile->history()->attach($groupByDate);
  87. }else{
  88. $history = History::create($historyData);
  89. $history->subhistory()->create($subHistory);
  90. $compound->ConfidentialFile->history()->attach($history);
  91. }
  92. return $this->sendResponse($data, 'Kompaun ini berjaya dibayar!');
  93. }else if($compound->status == 'Berbayar'){
  94. array_push($data, array(
  95. 'kpd' => $request->kpd,
  96. 'amount' => $jumlah,
  97. ));
  98. return $this->sendError($data, 'Kompaun ini dah dibayar!');
  99. }
  100. }
  101. }else {
  102. return $this->sendError($data, 'Tiada data');
  103. }
  104. }
  105. }
  106. public function updatePayment(Request $request){
  107. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->orderid)->first();
  108. if(!empty($compound)){
  109. $compound->status = 'Berbayar';
  110. $compound->save();
  111. $now = Carbon::now();
  112. $gDate = $now->format('F Y');
  113. $historyData = [
  114. 'tarikh_kumpulan' => $gDate,
  115. ];
  116. $subHistory = [
  117. 'no_siri' => $compound->ConfidentialFile->no_siri,
  118. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  119. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  120. ];
  121. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  122. if(!empty($groupByDate)){
  123. $groupByDate->subhistory()->create($subHistory);
  124. $compound->ConfidentialFile->history()->attach($groupByDate);
  125. }else{
  126. $history = History::create($historyData);
  127. $history->subhistory()->create($subHistory);
  128. $compound->ConfidentialFile->history()->attach($history);
  129. }
  130. return $this->sendResponse('', 'status pembayaran kompaun berjaya dikemaskini dari BELUM BAYAR ke BERBAYAR');
  131. }else{
  132. return $this->sendError('', 'status pembayaran kompaun tidak dapat dikemaskini sebab rekod tidak dijumpai');
  133. }
  134. }
  135. public function reportpaymentList(){
  136. $nested_data = array();
  137. $report = ReportPayment::orderBy('updated_at','DESC')->get();
  138. $curr = Carbon::now()->getTimestamp();
  139. $i = 1;
  140. foreach($report as $a)
  141. {
  142. $n1 = ''; $enforcer = '';
  143. $reg_time = $a->updated_at;
  144. $expiry_date = $reg_time->addDays(3);
  145. $expiry_date = $expiry_date->getTimestamp();
  146. if($curr < $expiry_date) {
  147. $n1 = "Baru/";
  148. }else{
  149. $n1 = "";
  150. }
  151. $staff = Staff::with('StaffDetail')->where('_id',$a->penguatkuasa)->first();
  152. if(!empty($staff)){
  153. $enforcer = '['.$staff->no_badan.'] '.$staff->StaffDetail->full_name;
  154. }
  155. // $noKPD = Compound::where('kpd', $a->kpd)->first();
  156. // $namaSeksyen = Faulty::where('itkod',$a->seksyen_kesalahan)->first();
  157. array_push($nested_data, array(
  158. '#' => $n1.$i,
  159. 'kpd' => $a->kpd,
  160. 'nama' => $a->name,
  161. 'kesalahan' => $a->kesalahan,
  162. 'identity' => $a->nric,
  163. 'mobile' => $a->mobile,
  164. 'email' => $a->email,
  165. 'jumlah' => 'Rm '.$a->total,
  166. 'no_badan' => $enforcer,
  167. ));
  168. $i++;
  169. }
  170. return \DataTables::of($nested_data)->make(true);
  171. }
  172. }