function($q){
$q->orderBy('updated_at', 'desc');
}])->where('no_siri',$no_siri)->first();
$curr = Carbon::now()->getTimestamp();
$i = 1;
foreach($memo->Memo as $a)
{
$n1 = ''; $dikeluarkan = ''; $disahkan = ''; $modul = '';
$reg_time = $a->updated_at;
$expiry_date = $reg_time->addDays(3);
$expiry_date = $expiry_date->getTimestamp();
if($curr < $expiry_date) {
$n1 = "Baru/";
}else{
$n1 = "";
}
$staffD = Staff::with('StaffDetail')->where('_id',$a->dikeluarkan)->first();
if(!empty($staffD)){
$dikeluarkan = $staffD->StaffDetail->full_name;
}
$staffS = Staff::with('StaffDetail')->where('_id',$a->disahkan)->first();
if(!empty($staffS)){
$disahkan = $staffD->StaffDetail->full_name;
}
if($a->modul != '-'){
$modul = Roles::where('kod',$a->modul)->first();
$modul = $modul->name;
}else{
$modul = '-';
}
array_push($nested_data, array(
'index' => $n1.$i,
'modul' => $modul,
'jenis' => $a->jenis_memo,
'no_rujukan' => $a->no_rujukan,
'mula' => date('d/m/Y h:i a', strtotime($a->tarikh_mula)),
'akhir' => date('d/m/Y h:i a', strtotime($a->tarikh_akhir)),
'dikeluakan' => $dikeluarkan,
'disahkan' => $disahkan,
'tindakan' => $a->_id
));
$i++;
}
return \DataTables::of($nested_data)->make(true);
}
public function deleteMemo(Request $request){
$staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first();
$compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first();
$memo = Memo::with('Attachment')->where('_id',$request->id)->first();
$compound->ConfidentialFile->memo()->detach($memo);
if(!empty($memo)){
if($memo->jenis_data == "pdf"){
$memo->attachment()->delete();
$memo->delete();
$now = Carbon::now();
$gDate = $now->format('F Y');
$historyData = [
'tarikh_kumpulan' => $gDate,
];
$subHistory = [
'no_siri' => $compound->ConfidentialFile->no_siri,
'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan,
'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->StaffDetail->full_name.".",
];
$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);
}
$this->dispatch(new UpdateCompoundPrice($request->kpd));
return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
}else if($memo->jenis_data == "manual"){
$memo->delete();
$now = Carbon::now();
$gDate = $now->format('F Y');
$historyData = [
'tarikh_kumpulan' => $gDate,
];
$subHistory = [
'no_siri' => $compound->ConfidentialFile->no_siri,
'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan,
'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->StaffDetail->full_name.".",
];
$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);
}
$this->dispatch(new UpdateCompoundPrice($request->kpd));
return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
}else{
return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
}
}else{
return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
}
}
}