123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
-
- namespace App\Http\Controllers\api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
-
- use Validator;
- use Session;
- 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\Roles;
- use App\Model\Module\Department;
- use App\Model\Module\DeedLaw;
- use App\Model\Module\Faulty;
- use App\Model\Module\Compound;
- use App\Model\Module\CompoundInvestigation;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\Investigation;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
-
- class InvestigationController extends BaseController
- {
-
- /**
- * Create a investigation list controller.
- *
- * @return json
- */
- public function investigationAttachmentList($no_siri)
- {
- $nested_data = array();
- $file = ConfidentialFile::with(['Investigation' => function($q){
- $q->orderBy('updated_at', 'desc');
- }])->where('no_siri',$no_siri)->first();
-
- $curr = Carbon::now()->getTimestamp();
-
- if(!empty($file->Investigation)){
- foreach($file->Investigation as $a)
- {
- $n1 = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "Baru/";
- }else{
- $n1 = "";
- }
-
- array_push($nested_data, array(
- 'tarikh' => $n1.$a->updated_at->format('d/m/Y'),
- 'masa' => $a->updated_at->format('h:i A'),
- 'subjek' => $a->subjek,
- 'kategori' => $a->kategori,
- 'tindakan' => $a->_id
- ));
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function deleteAttachment(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first();
- if(!empty($staff)){
- $attach = Investigation::with('Attachment')->where('_id',$request->id)->first();
- if(!empty($attach->Attachment)){
- foreach($attach->Attachment as $a){
- $a->delete();
- }
- $attach->delete();
-
- $file = ConfidentialFile::where('no_siri',$request->no_siri)->first();
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $file->no_siri,
- 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini pengesahan kompaun ".$request->kpd,
- 'huraian' => "Rekod lampiran ".$attach->kategori." (".$attach->subjek.") dikemaskini/di buang oleh ".$staff->StaffDetail->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);
- $file->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $file->history()->attach($history);
- }
-
- return response()->json(['status' => 'true', 'desc' => 'Buang rekod lampiran ( '.$attach->subjek.' )']);
- }else{
- return response()->json(['status' => 'false', 'desc' => 'Buang rekod lampiran ( '.$attach->subjek.' )']);
- }
- }
- }
- }
|