123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- <?php
-
- namespace App\Http\Controllers\Officer;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use Carbon\Carbon;
-
- use App\SiteSetting;
- 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\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
-
- use App\Jobs\StoreCompound;
- use App\Jobs\StoreCompoundManual;
- use App\Jobs\UpdateCompoundPrice;
-
- class CompoundController extends Controller
- {
- public function returnDepartment($id){
- $department = StaffDetail::where("_id", $id)->first();
- return $department->department_ids;
- }
-
- public function returnCompound($modul,$id, $status){
- $department = $this->returnDepartment($id);
-
- if($status == 'Belum Bayar'){
- if($modul == '06-07'){
- $compound = Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get();
- }else{
- $compound = Compound::where('modul',$modul)->where('status','Belum Bayar')->get();
- }
- }else{
- $compound = Compound::where('status','Berbayar')->get();
- }
-
- $temp = [];
- foreach($compound as $c){
- if(in_array($c->jbkod, (array)$department)) {
- $temp[] = $c;
- }
- }
-
- return $temp;
- }
-
- /**
- * Create compound list interface controller.
- *
- * @return json
- */
- public function index(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles','Department');
- }])->find($id);
-
- $roles = $user->StaffDetail->Roles->toArray();
- $department = $user->StaffDetail->Department;
- $site = SiteSetting::first();
-
- $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
- $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
- $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
- $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
- $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
- $comp = count($this->returnCompound('', $id, 'Berbayar'));
-
- return view('officer.compound.compound_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
- }
-
- public function investigation_index(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $roles = $user->StaffDetail->Roles->toArray();
- $department = $user->StaffDetail->Department;
- $site = SiteSetting::first();
-
- $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
- $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
- $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
- $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
- $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
- $comp = count($this->returnCompound('', $id, 'Berbayar'));
-
- return view('officer.compound.investigation_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
- }
-
- public function notice_index(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $roles = $user->StaffDetail->Roles->toArray();
- $department = $user->StaffDetail->Department;
- $site = SiteSetting::first();
-
- $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
- $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
- $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
- $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
- $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
- $comp = count($this->returnCompound('', $id, 'Berbayar'));
-
- return view('officer.compound.notice_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
- }
-
- public function confiscated_index(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $roles = $user->StaffDetail->Roles->toArray();
- $department = $user->StaffDetail->Department;
- $site = SiteSetting::first();
-
- $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
- $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
- $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
- $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
- $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
- $comp = count($this->returnCompound('', $id, 'Berbayar'));
-
- return view('officer.compound.confiscated_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
- }
-
- public function collapsed_index(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $roles = $user->StaffDetail->Roles->toArray();
- $department = $user->StaffDetail->Department;
- $site = SiteSetting::first();
-
- $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
- $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
- $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
- $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
- $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
- $comp = count($this->returnCompound('', $id, 'Berbayar'));
-
- return view('officer.compound.collapsed_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
- }
-
- public function completed_index(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $roles = $user->StaffDetail->Roles->toArray();
- $department = $user->StaffDetail->Department;
- $site = SiteSetting::first();
-
- $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
- $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
- $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
- $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
- $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
- $comp = count($this->returnCompound('', $id, 'Berbayar'));
-
- return view('officer.compound.completed_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
- }
-
- public function viewCompoundHistoryDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::with('History','History.SubHistory')->where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $role = Roles::where('kod',$compound->modul)->first();
- $site = SiteSetting::first();
- return view('officer.compound_detail.history_detail', compact('user','compound','file','role','site'));
- }
-
- public function viewCompoundDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles','Department');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $faulty = Faulty::with(['DeedLaw' => function($q){
- $q->with('Department');
- }])->where('_id',$compound->seksyen_kesalahan)->first();
- $role = Roles::where('kod',$compound->modul)->first();
-
- $total = ''; $enforcer = '';
- if($compound->jumlah_kemaskini_kompaun == ''){
- $total = $compound->jumlah_asal_kompaun;
- }else{
- $total = $compound->jumlah_kemaskini_kompaun;
- }
-
- $site = SiteSetting::first();
- $enforcer = Staff::with('StaffDetail')->where('_id',$compound->dikeluarkan)->first();
- return view('officer.compound_detail.compound_detail', compact('user','compound','akta','faulty','role','total','enforcer','site'));
- }
-
- public function viewCompoundMemoDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $roles = Roles::all();
- $role = Roles::where('kod',$compound->modul)->first();
- $site = SiteSetting::first();
- return view('officer.compound_detail.memo_detail', compact('user','compound','file','roles','role','site'));
- }
-
- public function viewCompoundEditMemoDetail($kpd, $memo){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $memo = Memo::where('_id',$memo)->first();
- $roles = Roles::all();
- $site = SiteSetting::first();
- return view('officer.compound_detail.compound_memo_edit', compact('user','compound','file','roles','memo','site'));
- }
-
- public function viewCompoundInvestigationDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $investigation = Compound::with('CompoundInvestigation')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $faulty = Faulty::where('_id',$compound->seksyen_kesalahan)->first();
- $akta = DeedLaw::where('akkod',$faulty->akkod)->first();
- $role = Roles::where('kod',$compound->modul)->first();
-
- $total = ''; $enforcer = '';
- if($compound->jumlah_kemaskini_kompaun == ''){
- $total = $compound->jumlah_asal_kompaun;
- }else{
- $total = $compound->jumlah_kemaskini_kompaun;
- }
-
- $site = SiteSetting::first();
- $enforcer = Staff::with('StaffDetail')->where('_id',$compound->dikeluarkan)->first();
- return view('officer.compound_detail.investigation_detail', compact('user','compound','investigation','file','akta','faulty','role','total','enforcer','site'));
- }
-
- public function viewCompoundNoticeDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $role = Roles::where('kod',$compound->modul)->first();
- $site = SiteSetting::first();
- return view('officer.compound_detail.notice_detail', compact('user','compound','file','role','site'));
- }
-
- public function viewCompoundInventoryDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $role = Roles::where('kod',$compound->modul)->first();
- $site = SiteSetting::first();
- return view('officer.compound_detail.inventory_detail', compact('user','compound','file','role','site'));
- }
-
- public function viewCompoundAuctionDetail($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $role = Roles::where('kod',$compound->modul)->first();
- $site = SiteSetting::first();
- return view('officer.compound_detail.auction_detail', compact('user','compound','file','role','site'));
- }
-
- public function viewTaskIndex($kpd){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Roles');
- }])->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- $roles = Roles::all();
- $staffs = StaffDetail::where('roles_access','PenguatKuasa')->where('jbkod',$user->StaffDetail->jbkod)->get();
- $role = Roles::where('kod',$compound->modul)->first();
- $site = SiteSetting::first();
-
- $currentS = '';
- $s = StaffDetail::where('roles_access','PenguatKuasa')->where('no_badan',$compound->penguatkuasa)->first();
- if(!empty($s)){
- $currentS = '['.$s->no_badan.'] '.$s->full_name;
- }
- return view('officer.compound_detail.compound_job',compact('user','compound','roles','staffs','role','currentS','site'));
- }
-
- public function manualCompound(){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with(['StaffDetail' => function($q){
- $q->with('Department');
- }])->find($id);
-
- $finalFaulty = [];
- $site = SiteSetting::first();
-
- $faulty = Faulty::with('Department');
- $department = $user->StaffDetail->department_ids;
- $faulty->whereHas('Department', function($q) use ($department) {
- $q->whereIn('_id', $department);
- });
-
- $akta = DeedLaw::orderBy('nama','ASC')->get();
- $staff = StaffDetail::whereHas('Department', function($q) use ($department) {
- $q->whereIn('_id', $department);
- })->where('roles_access', 'PenguatKuasa');
-
- $faulty = $faulty->get();
- $staff = $staff->get();
- return view('officer.compound.compound_form',compact('user','site','department','akta','faulty','staff'));
- }
-
- /**
- * Create generate kpd number controller.
- *
- * @return value
- */
- public function generateKPD($uniq_id,$range){
- $allowedNumbers = range(0, 9);
- shuffle($allowedNumbers);
- $digits = array_rand($allowedNumbers, $range);
-
- $number = '';
- foreach($digits as $d){
- $number .= $allowedNumbers[$d];
- }
-
- return $uniq_id.$number;
- }
-
- public function storemanualCompound(Request $request){
- $id = Auth::guard('ofr')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
- if(!empty($faulty)){
-
- $kpd = 'KP' . $this->generateKPD($request->get('uniq_id'), 5);
- $no_siri = $this->generateKPD('', 5);
-
- $this->dispatch(new StoreCompoundManual($request->all(), $kpd, $request->staff, $no_siri));
-
- $data = array();
- $dataExist = false;
-
- do {
- $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- if(!empty($compound)){
- $tawaran = '';
- if($compound->jumlah_kemaskini_kompaun != ''){
- $tawaran = $compound->jumlah_kemaskini_kompaun;
- }else{
- $tawaran = $compound->jumlah_asal_kompaun;
- }
-
- array_push($data, array('kpd' => $kpd, 'jumlah_kompoun' => $tawaran));
- $dataExist = true;
- }
- }while(!$dataExist);
-
- return redirect()->back()->with('success_msg', 'Berjaya simpan rekod kompaun!');
-
- }else{
- return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Rekod seksyen kesalahan tidak ditemui!');
- }
- }
- }
|