123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523 |
- <?php
-
- namespace App\Http\Controllers\Main;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use LynX39\LaraPdfMerger\Facades\PdfMerger;
-
- use File;
- use Carbon\Carbon;
- use PDF;
-
- 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\Investigation;
- use App\Model\Module\ItemInventory;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
- use App\Model\Module\CodeMukim;
-
- use App\Jobs\StoreCompoundEPBT;
- use App\Jobs\UpdateCompoundPrice;
-
- class TaskController extends Controller
- {
- /**
- * Create Task list controller.
- *
- * @return json
- */
- public function requestUpdateTask(Request $request){
- $id = Auth::guard('sadmin')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $file = ConfidentialFile::where('no_siri',$request->confidential)->first();
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- if($request->dashboard == "true"){
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
- $faulty = Faulty::with('DeedLaw', 'Department') ->where('_id', $compound->seksyen_kesalahan)
- ->orWhere('_id', $compound->seksyen_kesalahan_n)->first();
- $jbkod = $compound->jbkod;
-
- $roles = Roles::where('kod', $request->kategori_modul)->first();
-
- if($compound->modul == $request->kategori_modul){
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah berada di dalam kategori modul '.$roles->name);
- }else{
-
- $reg_id = array();
- if(!empty($roles->staff_detail_ids)){
- foreach($roles->staff_detail_ids as $s){
- $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){
- $q->where('jbkod', $jbkod);
- }])->where('_id', $s)->first();
- if(!empty($staff->StaffDetail)){
- if($staff->token_firebase != ''){
- $reg_id[] = $staff->token_firebase;
- }
- }
- }
- }
-
- if(count($reg_id) > 0) {
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', url('api/push/notification'), [
- 'verify' => false,
- 'form_params' => [
- 'title' => $roles->name.' '.$compound->kpd,
- 'msg' => 'Kompaun ini telah di pindahkan ke modul '.$roles->name,
- 'register_id' => $reg_id,
- ]
- ]);
- }
- if(!($request->kategori_modul == '03' && $compound->modul == '02'))
- {
- $compound->modul = $request->kategori_modul;
- $compound->save();
- }
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Serahan Modul",
- 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah diserahkan ke modul ".$roles->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);
- }
-
- return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya diserahkan ke kategori modul '.$roles->name);
- }
- }else if($request->dashboard == "false"){
-
- $compound = Compound::with('ConfidentialFile')->where('confidential_file_id',$request->confidential)->first();
-
- $data = array();
- $kpd = '';
-
- if($compound->penguatkuasa == $request->penguatkuasa){
-
- $staff = StaffDetail::where('_id',$request->penguatkuasa)->first();
-
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah diserahkan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->full_name);
- }else{
-
- $staff = Staff::with('StaffDetail')->where('_id',$request->penguatkuasa)->where(function($q){
- $q->where('roles_access','PenguatKuasa')->orWhere('roles_access','PPenguatKuasa');
- })->first();
- $role = Roles::where('kod', $compound->modul)->first();
-
- if($compound->modul == '02')
- {
- $compound = Compound::with('ConfidentialFile')->where('non',$request->non)->first();
- $faulty = Faulty::where('_id', $compound->seksyen_kesalahan_n)->first();
- $department = Department::where('_id', $compound->jbkod)->first();
- $deedlaw = DeedLaw::where('_id', $compound->akta_n)->first();
- $jbkod = $compound->jbkod;
- $kpd = $compound->non;
-
- // dd($faulty);
-
- array_push($data, array(
- 'non' => $compound->non,
- 'jenis' => $compound->jenis_n,
- 'nama' => $compound->nama,
- 'identity' => $compound->identity,
- 'alamat' => $compound->alamat,
- 'nama_kawasan' =>$compound->nama_kawasan,
- 'nama_taman' => $compound->nama_taman,
- 'nama_jalan' =>$compound->nama_jalan,
- 'catatan' => $compound->catatan,
- 'latlong' => $compound->latlong,
- 'jabatan' => $department->jnama,
- 'akta' => $deedlaw->nama,
- 'seksyen' => $faulty->nama,
- 'tempoh' => $compound->tempoh,
- 'tindakan' => $compound->tindakan ?? "",
- 'created_n' => $compound->created_n,
- ));
-
- }
- else{
- $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
- $faulty = Faulty::with('DeedLaw', 'Department') ->where('_id', $compound->seksyen_kesalahan)->first();
- $jbkod = $compound->jbkod;
- $kpd = $compound->kpd;
- }
-
- // if($compound->modul == '02')
- // {
- // $this->dispatch(new StoreCompoundEPBT($request->all(), $compound->kpd, $user->StaffDetail->full_name, $user->StaffDetail->no_badan, $compound->seksyen_kesalahan));
-
- // dd($faulty);
-
- // array_push($data, array(
- // 'non' => $compound->non,
- // 'jenis' => $compound->jenis_n,
- // 'nama' => $compound->nama,
- // 'identity' => $compound->identity,
- // 'alamat' => $compound->alamat,
- // 'nama_kawasan' =>$compound->nama_kawasan,
- // 'nama_taman' => $compound->nama_taman,
- // 'nama_jalan' =>$compound->nama_jalan,
- // 'catatan' => $compound->catatan,
- // 'latlong' => $compound->latlong,
- // 'jabatan' => $faulty['Department']['jnama'],
- // 'akta' => $faulty['DeedLaw']['nama'],
- // 'tempoh' => $compound->tempoh,
- // 'tindakan' => $compound->tindakan ?? "",
- // 'created_n' => $compound->created_n,
- // ));
-
- // }
-
- info(json_encode($data));
-
- if(!empty($staff)){
- if($staff->token_firebase != '') {
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', url('api/push/notification'), [
- 'verify' => false,
- 'form_params' => [
- 'title' => $role->name.' '.$kpd,
- 'msg' => 'Kompaun ini berada di ruangan '.$role->name ,
- 'data' => json_encode($data),
- 'register_id[]' => $staff->token_firebase,
- ]
- ]);
- }
-
- $compound->penguatkuasa = $request->penguatkuasa;
- $compound->save();
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Menugaskan Penguatkuasa ".$staff->StaffDetail->full_name,
- 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah ditugaskan kepada penguatkuasa <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);
- }
-
- return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya ditugaskan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->StaffDetail->full_name);
- }else{
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Data penguatkuasa tidak ditemui');
- }
- }
- }
- }
-
- public function requestUpdateToCourt(Request $request)
- {
- $id = Auth::guard('sadmin')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
- $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
- $jbkod = $compound->jbkod;
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- if($request->dashboard == "true"){
-
- if(!isset($compound->tarikh_mahkamah) )
- {
- $compound->tarikh_mahkamah = $request->start_date;
- $compound->save();
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Serahan Tarikh Mahkamah",
- 'huraian' => $compound->kpd. " diserahkan ke mahkamah pada ".$request->start_date,
- ];
-
- $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);
- }
-
- return redirect()->back()->with('success_msg', 'Berjaya kemaskini tarikh serahan ke mahkamah untuk kompaun ' . $compound->kpd);
- }
- else{
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Pindahan tarikh ke mahkamah telah dilakukan untuk kompaun ini!');
- }
- }
- }
-
- public function requestViewAllPdf($kpd) {
-
- $ready_view_pdf = false;
- $availablePDF = array();
- $now = Carbon::now()->format('d/m/Y h:i:s A');
-
- $site = SiteSetting::first();
- $compound = Compound::with('ConfidentialFile','Attachment','CompoundInvestigation')->where('kpd', $kpd)->orWhere('non', $kpd)->first();
- if(empty($compound))
- {
- $kpd = (int)$kpd;
- $compound = Compound::with('ConfidentialFile','Attachment','CompoundInvestigation')->where('kpd', $kpd)->orWhere('non', $kpd)->first();
- }
- $file = ConfidentialFile::with(['Memo' => function($q){
- $q->orderBy('updated_at','ASC');
- }],['Investigation' => function($q){
- $q->with(['Attachment' => function($w){
- $w->first();
- }])->orderBy('updated_at','ASC');
- }],['ItemInventory' => function($w){
- $w->with('Barcode');
- }])->where('_id',$compound->ConfidentialFile->_id)->first();
-
- /**
- ** Compound
- **/
- $tawaran = '';
- if($compound->jumlah_kemaskini_kompaun == ''){
- $tawaran = $compound->jumlah_asal_kompaun;
- }else{
- $tawaran = $compound->jumlah_kemaskini_kompaun;
- }
-
- $staff = Staff::with('StaffDetail')->where('_id', $compound->dikeluarkan)->first();
- $staffN = Staff::with('StaffDetail')->where('_id', $compound->dikeluarkan_n)->first();
- $faulty = Faulty::with('DeedLaw')->where('_id',$compound->seksyen_kesalahan)->first();
- $faultyN = Faulty::with('DeedLaw')->where('_id', $compound->seksyen_kesalahan_n)->first();
- $department = Department::where('_id', $compound->jbkod)->first();
- $departmentN = Department::where('_id', $compound->jbkod)->first();
-
- info($faultyN);
-
- $upload [] = [ 'name' => 'compound', 'contents' => $compound ];
- $upload [] = [ 'name' => 'faulty', 'contents' => $faulty ];
- $upload [] = [ 'name' => 'faultyN', 'contents' => $faultyN ];
- $upload [] = [ 'name' => 'staff', 'contents' => $staff ];
- $upload [] = [ 'name' => 'staffN', 'contents' => $staffN ];
- $upload [] = [ 'name' => 'department', 'contents' => $department ];
- $upload [] = [ 'name' => 'departmentN', 'contents' => $departmentN ];
- $upload [] = [ 'name' => 'tawaran', 'contents' => $tawaran ];
- $upload [] = [ 'name' => 'site', 'contents' => $site ];
- $upload [] = [ 'name' => 'type', 'contents' => 'mbip' ];
- $upload [] = [ 'name' => 'file', 'contents' => $file ];
- $upload [] = [ 'name' => 'now', 'contents' => $now ];
-
-
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', 'https://files.sipadu.my/api/compound/pdf', [
- 'multipart' => $upload
- ]);
-
- $response = json_decode($result->getBody()->getContents());
- if($response->success == true){
- $compound->pdf_path = $response->data;
- $compound->save();
- }
-
- /**
- ** Investigation
- **/
- $upload [] = [ 'name' => 'file', 'contents' => $file ]; $temp = [];
- if(!empty($file->Investigation)){
- foreach($file->Investigation as $i => $in){
- $attach = Investigation::with('Attachment')->where('_id',$in->_id)->first();
- foreach ($attach->Attachment as $key => $p) {
- $temp[] = $p->path;
- }
- }
- $upload [] = [ 'name' => 'fileInvest', 'contents' => json_encode($temp)];
- }
-
- /**
- ** All Memo in file
- **/
- if(!empty($file->Memo)){
-
- $memoData = array();
-
- foreach($file->Memo as $i => $m){
- $memo = Memo::with('Attachment')->where('_id',$m->_id)->first();
-
- $staffD = Staff::with('StaffDetail')->where('_id',$memo->dikeluarkan)->first();
- $staffS = Staff::with('StaffDetail')->where('_id',$memo->disahkan)->first();
- $kesalahan = Faulty::where('itkod', $memo->itkod)->first();
-
- $dikeluarkan = ''; $disahkan = ''; $faulty = ''; $modul = '';
- if(!empty($staffD)){
- $dikeluarkan = $staffD->StaffDetail->full_name;
- }
-
- if(!empty($staffS)){
- $disahkan = $staffD->StaffDetail->full_name;
- }
-
- if(!empty($kesalahan)){
- $faulty ='['.$kesalahan->skter.'] '.$kesalahan->nama;
- }
-
- if($memo->modul != '-'){
- $r = Roles::where('kod',$memo->modul)->first();
- if(!empty($r)){
- $modul = $r->name;
- }
- }
-
- $update = Carbon::parse($memo->updated)->toDateTimeString();
- $mula = date('d/m/Y h:i a', strtotime($memo->tarikh_mula));
- $akhir = date('d/m/Y', strtotime($memo->tarikh_akhir));
-
- if($memo->jenis_data == "manual"){
- $dataM = [
- 'memo' => $memo,
- 'dikeluarkan' => $dikeluarkan,
- 'disahkan' => $disahkan,
- 'update' => $update,
- 'mula' => $mula,
- 'akhir' => $akhir,
- 'faulty' => $faulty,
- 'modul' => $modul,
- 'attachment' => [],
- ];
-
- $memoData[] = $dataM;
- }else if($memo->jenis_data == "pdf"){
- foreach($m->Attachment as $key => $a){
- $pdf[] = $a->path;
- }
-
- $dataM = [
- 'memo' => $memo,
- 'dikeluarkan' => $dikeluarkan,
- 'disahkan' => $disahkan,
- 'update' => $update,
- 'mula' => $mula,
- 'akhir' => $akhir,
- 'faulty' => $faulty,
- 'modul' => $modul,
- 'attachment' => $pdf,
- ];
-
- $memoData[] = $dataM;
- }
- }
-
- $upload [] = [ 'name' => 'memo', 'contents' => json_encode($memoData)];
- }
-
- /**
- ** Inventory
- **/
- if(count($file->ItemInventory) > 0){
-
- $dataItem = array();
-
- foreach ($file->ItemInventory as $key => $b) {
- $barcode = '';
- foreach ($b->Barcode as $key => $br) {
- $barcode .= ', '.$br->barcode_id;
-
- $data = [
- 'item' => $b,
- 'barcode' => $barcode,
- ];
- }
-
- $dataItem[] = $data;
- }
-
- $upload [] = [ 'name' => 'inventori', 'contents' => json_encode($dataItem)];
- }
-
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', 'https://files.sipadu.my/api/store/compound/pdf', [
- 'multipart' => $upload
- ]);
-
- $response = json_decode($result->getBody()->getContents());
- if($response->success == true){
- return redirect($response->data);
- }else if($response->success == false){
- return response()->json($response->message);
- }
- }
-
-
- public function insertdata()
- {
-
- $roads = CodeMukim::all()->toArray();
-
- $response = json_decode(file_get_contents(public_path(). '/mukim_kawasan_jalan_mbip.json'));
- $temp = [];
- if($response->success == true){
-
- foreach ($response->data as $key => $r)
- {
- // search value in db COde Mukim, if none, add to array
- if(!in_array($r->_id, array_column($roads, '_id')))
- {
-
- $com = new CodeMukim();
- $com->_id = new \MongoDB\BSON\ObjectID($r->_id);
- $com->JLN_MKKOD = $r->JLN_MKKOD;
- $com->MKM_MNAMA = $r->MKM_MNAMA;
- $com->JLN_KWKOD = $r->JLN_KWKOD;
- $com->KWS_KNAMA = $r->KWS_KNAMA;
- $com->JLN_JNAMA = $r->JLN_JNAMA;
- $com->save();
-
- if(!$com)
- {
- $temp[] = $r;
- }
- }
-
- }
-
- return 'data not inserted : ' . json_encode($temp);
-
- }
- }
- }
|