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();
}
$compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
if($modul == 'All'){
$compound = $compound;
}else if($modul == '06-07'){
$compound = $compound->where(function($q){
$q->where(function($query){
$query->where('modul', '06')->orWhere('modul','07');
});
});
}else {
$compound = $compound->where('modul', $modul);
}
if($status == 'All'){
$compound = $compound;
}else {
$compound = $compound->where('status', $status);
}
return $compound;
}
private function searchCompoundAllWithoutDate($jenis,$modul,$status){
$compound = Compound::where('jenis', $jenis);
if($modul == 'All'){
$compound = $compound;
}else if($modul == '06-07'){
$compound = $compound->where(function($q){
$q->where(function($query){
$query->where('modul', '06')->orWhere('modul','07');
});
});
}else {
$compound = $compound->where('modul', $modul);
}
if($status == 'All'){
$compound = $compound;
}else {
$compound = $compound->where('status', $status);
}
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,$department){
$compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
if($faulty == 'All'){
return $compound->whereIn('jbkod',$department);
}else {
$compound = $compound->where('seksyen_kesalahan', $faulty);
return $compound;
}
}
private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no){
$compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department);
if(!empty($plate_no)){
$compound = $compound->where('no_plate',$plate_no);
return $compound;
}else{
return $compound;
}
}
private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd){
$compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no);
if(!empty($kpd)){
$compound = $compound->where('kpd',$kpd);
return $compound;
}else{
$compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
return $compound;
}
}
private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no){
$compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd);
if(!empty($company_no)){
$compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
return $compound;
}else{
return $compound;
}
}
private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric){
$compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no);
if(!empty($nric)){
$compound = $compound->where('identity',$nric);
return $compound;
}else{
return $compound;
}
}
private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license){
$compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric);
if(!empty($license)){
$compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
return $compound;
}else{
return $compound;
}
}
private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP){
$compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license);
if(!empty($namaP)){
$compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
return $compound;
}else{
return $compound;
}
}
private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name){
$compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP);
if(!empty($company_name)){
$compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
return $compound;
}else{
return $compound;
}
}
public function index(Request $request)
{
// $per_page = '';
// $kpd = '';
// $modul = 'All';
// $status = 'All';
// $jenis = 'Pelbagai_JPB';
// if(!empty($request->department)){
// $department = ["5df721c5cde7fd741433c6b2","5d957899f3da686c08192026","5d9d4a699b802d5a31031a8a","5d9d4db1aa95fa07f7245e28","5d9d5955eb4f92300927f188","5d9e965fec0023467756a02a","5d9eba38e4be2267877896a8"];
// }else {
// $department = [];
// }
// $start_date = '2020-07-18';
// $end_date = '2020-08-14';
// $enforcer = 'All';
// $faulty = 'All';
// $plate_no = strtolower('');
// $company_no = strtolower('');
// $nric = '';
// $license = '';
// $namaP = '';
// $company_name = '';
/////////////////////////////////////////////////////////////////////////////////
$per_page = $request->per_page;
$kpd = $request->kpd;
$modul = $request->modul;
$status = $request->status;
$jenis = $request->type;
if(!empty($request->department)){
$department = json_decode($request->department);
}else {
$department = [];
}
$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;
$license = $request->license;
$namaP = $request->nameP;
$company_name = $request->company_name;
$nested_data = array();
$compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name)->orderBy('created_at','ASC')->get();
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;
})->addColumn('status_kemaskini', function($row) {
$data = '';
if($row['status'] == 'Berbayar'){
$data = ''.$row['status'].'
Bayaran:
';
$data .= 'RM '.$row['amount_payment'].'
';
$data .= 'Catatan:
'.$row['catatan_dari_admin'].'
';
if($row['updated_by'] !== null ){
$data .= 'Kemaskini:
';
$data .= $row['updated_at'].'
'.$row['updated_by']['no_badan'].'
';
}else {
if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
$data .= 'Kemaskini:
';
$data .= $row['tarikh_bayar'].'
'.$row['updates_by'].'
';
}else {
$data .= 'Kemaskini:
';
$data .= $row['updated_at'].'
'.$row['updates_by'].'
';
}
}
}else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
$data = ''.$row['status'].'';
$data .= 'Catatan:
'.$row['catatan_dari_admin'].'
';
$data .= 'Kemaskini:
';
$data .= $row['updated_at'].'
'.$row['updated_by']['no_badan'].'
';
}else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
$data = ''.$row['status'].'';
$data .= 'Catatan:
'.$row['catatan_dari_admin'].'
';
$data .= 'Kemaskini:
';
$data .= $row['updated_at'].'
'.$row['updated_by']['no_badan'].'
';
}else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
$data = ''.$row['status'].'';
$data .= 'Catatan:
'.$row['catatan_dari_admin'].'
';
$data .= 'Kemaskini:
';
$data .= $row['updated_at'].'
'.$row['updated_by']['no_badan'].'
';
}
else
{
$data = $row['status'];
}
return $data;
})->addColumn('kesalahan', function($row) {
$data = 'Seksyen '.$row['faulty_skter'].'
'.$row['faulty_name'];
return $data;
})->rawColumns(['index','status_kemaskini','kesalahan'])->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 ".$staff->full_name."",
];
$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 ".$staff->full_name."",
];
$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 ".$staff->full_name."",
];
$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 ".$staff->full_name."",
];
$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)
{
//
}
}