123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
-
- namespace App\Http\Controllers\api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\Module\Department;
- use App\Model\Module\Roles;
- use App\Model\Module\Attachment;
- use App\Model\Module\Faulty;
- use App\Model\Module\Memo;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\Compound;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
-
- use App\Jobs\UpdateCompoundPrice;
-
- class MemoController extends BaseController
- {
-
- /**
- * Create a memo list controller.
- *
- * @return json
- */
-
- public function memoList($no_siri){
-
- $nested_data = array();
- $memo = ConfidentialFile::with(['Memo' => 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." <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);
- $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." <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);
- $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.' )']);
- }
- }
- }
|