123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- <?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\Department;
- use App\Model\Module\DeedLaw;
- use App\Model\Module\Faulty;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
-
- use App\Jobs\StoreCompound;
- use App\Jobs\UpdateCompoundPrice;
- use App\Http\Resources\CompoundResource;
-
- class CompoundResourceController extends BaseController
- {
- /**
- * @var ServiceCategory
- */
- protected $compound;
-
- /**
- * ServiceController constructor.
- *
- * @param ServiceCategory $ServiceCategory
- */
- public function __construct(Compound $compound)
- {
- $this->compound = $compound;
- }
-
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date){
- $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
- $start = $dateS->copy()->startOfDay();
-
- if($end_date != ''){
- $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
- if($modul == '06-07'){
- $compound = Compound::where(function($q){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07');
- });
- })->where('status', $status)->where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
- }else if($status != 'Berbayar'){
- if($status == 'All'){
- $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis)
- ->whereBetween('created_at', array($start, $end));
- }else{
- $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis)
- ->whereBetween('created_at', array($start, $end));
- }
- // $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis)
- // ->whereBetween('created_at', array($start, $end));
- }else{
- $compound = Compound::where('status', $status)->where('jenis', $jenis)
- ->whereBetween('created_at', array($start, $end));
- }
- return $compound;
- }
-
- private function searchCompoundAllWithoutDate($jenis,$modul,$status){
- if($modul == '06-07'){
- $compound = Compound::where(function($q){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07');
- });
- })->where('status', $status)->where('jenis', $jenis);
- }else if($status != 'Berbayar'){
- if($status == 'All'){
- $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis);
- }else{
- $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis);
- }
- }else{
- $compound = Compound::where('status', $status)->where('jenis', $jenis);
- }
- return $compound;
- }
-
- private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){
- if(!empty($start_date)){
- $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date);
- }else{
- $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status);
- }
-
- if($enforcer == 'All'){
- return $compound;
- }else {
- $compound = $compound->where('dikeluarkan', $enforcer);
- return $compound;
- }
- }
-
- private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date){
- $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
- if($faulty == 'All'){
- return $compound;
- }else {
- $compound = $compound->where('seksyen_kesalahan', $faulty);
- return $compound;
- }
- }
-
- public function index(Request $request)
- {
- //
- $per_page = $request->per_page;
- $kpd = $request->kpd;
-
- $modul = $request->modul;
- $status = $request->status;
- $jenis = $request->type;
-
- $start_date = $request->start_date;
- $end_date = $request->end_date;
-
- $enforcer = $request->enforcer;
- $faulty = $request->faulty;
-
- $plate_no = strtolower($request->plate_no);
- $company_no = strtolower($request->company_no);
- $nric = $request->nric;
-
- $nested_data = array();
-
- if(!empty($plate_no)) {
- $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
- $compound = $compound->where('no_plate',$plate_no)->orderBy('created_at','ASC')->get();
- }else if(!empty($kpd)){
- $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
- $compound = $compound->where('kpd',$kpd)->orderBy('created_at','ASC')->get();
- }else if(!empty($company_no)){
- $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
- $compound = $compound->where('no_daftar_syarikat',$company_no)->orderBy('created_at','ASC')->get();
- }else if(!empty($nric)){
- $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
- $compound = $compound->where('identity',$nric)->orderBy('created_at','ASC')->get();
- }else{
- $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
- $compound = $compound->orderBy('created_at','ASC')->get();
- }
-
- // return $compound;
- return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
- ->addColumn('index', function($row) {
- $curr = Carbon::now();
- $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
- if($curr->diffInDays($dtC) <= 3){
- $html = 'New';
- }else{ $html = ''; }
- return $html;
- })->rawColumns(['index'])->make(true);
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- //
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
- $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
- if(!empty($faulty)){
-
- $data = array();
- $countKPD = $this->compound->withTrashed()->count();
-
- do {
- $countKPD = $countKPD + 1;
- } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
-
- $kpd = 'KP' . $countKPD;
- $no_siri = date('yn').'-'.$countKPD;
-
- $fileData = [
- 'no_siri' => $no_siri,
- ];
-
- if($request->jenis == 'Parkir'){
- $compoundData = [
- 'jenis' => 'Parkir',
- 'kpd' => $kpd,
- 'nama' => '-',
- 'identity' => '-',
- 'alamat' => '-',
- "no_plate" => strtolower($request->no_plate),
- "no_cukai_jalan" => $request->noCukaijalan,
- "jenis_kenderaan" => $request->jenisKenderaan,
- "model_kenderaan" => $request->modelKenderaan,
- "warna_kenderaan" => $request->warnakenderaan,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "no_parking" => $request->noParking,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '03',
- "penguatkuasa" => '',
- ];
- }elseif($request->jenis == 'Pelbagai_KT'){
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "no_plate" => $request->no_plate,
- "no_cukai_jalan" => $request->no_cukai_jalan,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '03',
- "penguatkuasa" => '',
- "no_telefon" => $request->tel,
- "no_akaun_lesen" => $request->lesen,
- "maklumat_tambahan" => '-',
- ];
- }elseif($request->jenis == 'Pelbagai_JPB'){
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "no_plate" => $request->no_plate,
- "no_cukai_jalan" => $request->no_cukai_jalan,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '03',
- "penguatkuasa" => '',
- "no_telefon" => $request->tel,
- "no_akaun_lesen" => $request->lesen,
- "maklumat_tambahan" => '-',
- ];
- }
-
- $file = ConfidentialFile::create($fileData);
- $saved = $file->compound()->create($compoundData);
-
- if($saved){
- // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- // if(!empty($compound)){
- dispatch(new UpdateCompoundPrice($kpd));
- // $tawaran = '';
- // if($compound->jumlah_kemaskini_kompaun != ''){
- // $tawaran = $compound->jumlah_kemaskini_kompaun;
- // }else{
- // $tawaran = $compound->jumlah_asal_kompaun;
- // }
- $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
- array_push($data, array('kpd' => $kpd));
-
- return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
- // }
- }
- }
- }
- }
-
-
- public function storeNotice(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
- $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
- if(!empty($faulty)){
-
- $data = array();
- $countKPD = $this->compound->withTrashed()->count();
-
- do {
- $countKPD = $countKPD + 1;
- } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
-
- $kpd = 'KP' . $countKPD;
- $no_siri = date('yn').'-'.$countKPD;
-
- $fileData = [
- 'no_siri' => $no_siri,
- ];
-
- if($request->jenis == 'Parkir'){
- $compoundData = [
- 'jenis' => 'Parkir',
- 'kpd' => $kpd,
- 'nama' => '-',
- 'identity' => '-',
- 'alamat' => '-',
- "no_plate" => strtolower($request->no_plate),
- "no_cukai_jalan" => $request->noCukaijalan,
- "jenis_kenderaan" => $request->jenisKenderaan,
- "model_kenderaan" => $request->modelKenderaan,
- "warna_kenderaan" => $request->warnakenderaan,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "no_parking" => $request->noParking,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '05',
- "penguatkuasa" => '',
- ];
- }elseif($request->jenis == 'Pelbagai_KT'){
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "no_plate" => $request->no_plate,
- "no_cukai_jalan" => $request->no_cukai_jalan,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '05',
- "penguatkuasa" => '',
- "no_telefon" => $request->tel,
- "no_akaun_lesen" => $request->lesen,
- "maklumat_tambahan" => '-',
- ];
- }elseif($request->jenis == 'Pelbagai_JPB'){
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "no_plate" => $request->no_plate,
- "no_cukai_jalan" => $request->no_cukai_jalan,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '05',
- "penguatkuasa" => '',
- "no_telefon" => $request->tel,
- "no_akaun_lesen" => $request->lesen,
- "maklumat_tambahan" => '-',
- ];
- }
- elseif($request->jenis == 'Lesen'){
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "no_plate" => $request->no_plate,
- "no_cukai_jalan" => $request->no_cukai_jalan,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '',
- "receipt" => '',
- "modul" => '05',
- "penguatkuasa" => '',
- "no_telefon" => $request->tel,
- "no_akaun_lesen" => $request->lesen,
- "bil_haiwan" => $request->bil_haiwan,
- ];
- }
-
- $file = ConfidentialFile::create($fileData);
- $saved = $file->compound()->create($compoundData);
-
- if($saved){
- // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- // if(!empty($compound)){
- dispatch(new UpdateCompoundPrice($kpd));
- // $tawaran = '';
- // if($compound->jumlah_kemaskini_kompaun != ''){
- // $tawaran = $compound->jumlah_kemaskini_kompaun;
- // }else{
- // $tawaran = $compound->jumlah_asal_kompaun;
- // }
- $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
- array_push($data, array('kpd' => $kpd));
-
- return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
- // }
- }
- }
- }
- }
-
-
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- //
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- //
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
-
- public function updateStatusPaymentViaDashboard(Request $request)
- {
- $compound = $this->compound::with('ConfidentialFile')->find($request->id);
- $staff = StaffDetail::find($request->current_id);
- if(!empty($compound) && !empty($staff)){
- if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
-
- if($compound->status != $request->status){
- $compound->status = $request->status;
- $compound->catatan_dari_admin = $request->remark;
- $compound->amount_payment = $request->amount;
- $compound->update_by = $request->current_id;
- $saved = $compound->save();
-
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
- 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- if($request->status == "Berbayar"){
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
- }else{
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
- }else{
-
- if($request->remark != ''){
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $compound->save();
-
- $saved = $compound->save();
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
- 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Tiada kemaskini!',
- ];
- return response()->json($response, 200);
- }
-
- }
-
- }else{
-
- if($compound->status != 'Berbayar' && $compound->status != $request->status){
- $compound->status = $request->status;
- $compound->catatan_dari_admin = $request->remark;
- $compound->amount_payment = $request->amount;
- $compound->update_by = $request->current_id;
- $saved = $compound->save();
-
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
- 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- if($request->status == "Berbayar"){
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
- }else{
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
- }else{
-
- if($request->remark != ''){
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $compound->save();
-
- $saved = $compound->save();
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
- 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Tiada kemaskini!',
- ];
- return response()->json($response, 200);
- }
-
- }
- }
- }else{
- $response = [
- 'success' => false,
- 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
- ];
- return response()->json($response, 200);
- }
-
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
|