1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- <?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\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\Compound;
- use App\Model\Module\Department;
- use App\Model\Module\DeedLaw;
- use App\Model\Module\Faulty;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\History;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
- use App\Model\Module\ApiIntegration;
-
- use App\Jobs\StoreCompound;
- use App\Jobs\UpdateCompoundPrice;
-
- class CompoundController extends BaseController
- {
- /**
- * Create list compound for penguatkuasa controller.
- *
- * @return value
- */
-
- public function confidentialFileList(Request $request){
- $nested_data = array();
- $user = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
- if(!empty($user)){
- $no_badan = $user->no_badan; $modul = $request->modul;
- $compound = Compound::with('ConfidentialFile')->where('penguatkuasa', $no_badan)->where('modul', $modul)->orderBy('updated_at', 'desc')->get();
-
- foreach ($compound as $key => $a) {
- if(!empty($a->ConfidentialFile)){
- array_push($nested_data, array(
- 'kpd' => $a->kpd,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'no_siri' => $a->ConfidentialFile->no_siri,
- ));
- }
- }
-
- return $this->sendResponse($nested_data, 'Berjaya, dapatkan senarai file kulit');
- }else{
- return $this->sendError('', 'data kakitangan tidak ditemui');
- }
- }
-
- /**
- * Create generate kpd number controller.
- *
- * @return value
- */
- public function generateKPD(){
- // $allowedNumbers = range(0, 9);
- // shuffle($allowedNumbers);
- // $digits = array_rand($allowedNumbers, $range);
-
- // $number = '';
- // foreach($digits as $d){
- // $number .= $allowedNumbers[$d];
- // }
- $count = 0;
- do {
- $count = Compound::count();
- $count = $count + 1;
- } while (Compound::where("kpd", "=", 'KP'.$count)->first() instanceof Compound);
- return $count;
- }
-
- /**
- * Create compound list controller.
- *
- * @return json
- */
- public function storeCompound(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
-
- $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
- if(!empty($faulty)){
-
- $countKPD = 0;
- do {
- $countKPD = Compound::withTrashed()->count();
- $countKPD = $countKPD + 1;
- } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
-
- $kpd = 'KP' . $countKPD;
-
- // $kpd = '';
- // do {
- // $kpd = 'KP' . $this->generateKPD();
- // } while (Compound::where("kpd", "=", $kpd)->first() instanceof Compound);
-
- if($kpd != ''){
- $no_siri = $this->generateKPD();
-
- $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $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 $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
- }
-
- }else{
- return $this->sendError('Gagal', 'Rekod seksyen kesalahan tidak ditemui!');
- }
- }
- }
-
- public function storeCompoundAttachment(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
-
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
-
- $kpd = $request->get('kpd');
- $success_upload = 0; $count_upload = 0;
- $compound = Compound::with('ConfidentialFile')->where('kpd', $kpd)->orWhere('non', $kpd)->first();
- if(!empty($compound)){
-
- if($request->hasFile('file')) {
-
- $upload = [];
- foreach($request->file('file') as $f){
- $upload[] = [
- 'name' => 'file[]',
- 'contents' => fopen( $f->getPathname(), 'r' ),
- 'filename' => $f->getClientOriginalName()
- ];
- }
-
- $upload [] = [
- 'name' => 'kp',
- 'contents' => $kpd
- ];
-
- $upload [] = [
- 'name' => 'no_siri',
- 'contents' => $compound->ConfidentialFile->no_siri
- ];
-
- $upload [] = [
- 'name' => 'type',
- 'contents' => 'mbip'
- ];
-
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', 'https://files.sipadu.my/api/upload/compound/picture', [
- 'multipart' => $upload
- ]);
-
-
- $response = json_decode($result->getBody()->getContents());
- if($response->success == true){
- foreach ($response->data as $key => $d) {
- $attach = new Attachment();
- $attach->path = $d;
- $compound->attachment()->save($attach);
- }
- return $this->sendResponse('', $response->message);
- }else if($response->success == false){
- return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!');
- }
-
- }else{
- return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!');
- }
-
- }else{
- return $this->sendError('Gagal', 'Kompaun '.$kpd.' tidak ditemui!');
- }
- }
- }
-
- public function storeAcceptanceCompound(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token', $request->api_token)->first();
-
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
-
- $kpd = $request->get('kpd');
- $success_upload = 0; $count_upload = 0;
- $compound = Compound::with('ConfidentialFile')->where('kpd', $kpd)->first();
- if(!empty($compound)){
-
- if($request->hasFile('file')) {
-
- $upload = [];
- foreach($request->file('file') as $f){
- $upload[] = [
- 'name' => 'file[]',
- 'contents' => fopen( $f->getPathname(), 'r' ),
- 'filename' => $f->getClientOriginalName()
- ];
- }
-
- $upload [] = [
- 'name' => 'kp',
- 'contents' => $kpd
- ];
-
- $upload [] = [
- 'name' => 'no_siri',
- 'contents' => $compound->ConfidentialFile->no_siri
- ];
-
- $upload [] = [
- 'name' => 'type',
- 'contents' => 'proxy'
- ];
-
- $client = new \GuzzleHttp\Client();
- $result = $client->request('POST', 'https://files.sipadu.my/api/upload/acceptance/compound', [
- 'multipart' => $upload
- ]);
-
-
- $response = json_decode($result->getBody()->getContents());
- if($response->success == true){
- foreach ($response->data as $key => $d) {
- $attach = new Attachment();
- $attach->path = $d;
- $compound->attachment()->save($attach);
- }
- return $this->sendResponse('', $response->message);
- }else if($response->success == false){
- return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!');
- }
-
- }else{
- return $this->sendError('Gagal', 'Gambar kompaun '.$kpd.' tidak dimuatnaik!');
- }
-
- }else{
- return $this->sendError('Gagal', 'Kompaun '.$kpd.' tidak ditemui!');
- }
- }
- }
-
- public function compoundList($modul){
- $nested_data = array();
- if($modul == '06-07'){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) {
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->get();
- }
- // $compound = Compound::with(['ConfidentialFile' => function($q){
- // $q->where('status', 'Belum Bayar');
- // }])->orderBy('updated_at', 'desc')->get();
-
-
- $class = '';
- if($modul == '03'){
- $class = "success/";
- }else if($a->modul == '04'){
- $class = $cat_modul."/primary/";
- }else if($a->modul == '05'){
- $class = $cat_modul."/warning/";
- }else if($a->modul == '06'){
- $class = $cat_modul."/info/";
- }else if($a->modul == '07'){
- $class = $cat_modul."/danger/";
- }else if($a->modul == '08'){
- $class = $cat_modul."/inverse/";
- }
-
- $cat_modul = '-';
- if($modul != '-'){
- $cat = Roles::where('kod',$modul)->first();
- if(!empty($cat)){
- if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){
- $dump = explode(' ',trim($cat->name));
- $cat_modul = $dump[0];
- }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){
- $dump = explode('- ',trim($cat->name));
- $cat_modul = $dump[1];
- }else{
- $cat_modul = $cat->name;
- }
- }
- }
-
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($compound as $a) {
- if(!empty($a->ConfidentialFile)){
- $n1 = ''; $faulty = ''; $tawaran = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- /*$cat_modul = '-';
- if($a->modul != '-'){
- $cat = Roles::where('kod',$a->modul)->first();
- if(!empty($cat)){
- if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){
- $dump = explode(' ',trim($cat->name));
- $cat_modul = $dump[0];
- }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){
- $dump = explode('- ',trim($cat->name));
- $cat_modul = $dump[1];
- }else{
- $cat_modul = $cat->name;
- }
- }
- }*/
-
- // if($curr < $expiry_date) {
- // if($a->modul == '03'){
- // $n1 = "Baru/success/";
- // }else if($a->modul == '04'){
- // $n1 = "Baru/".$cat_modul."/primary/";
- // }else if($a->modul == '05'){
- // $n1 = "Baru/".$cat_modul."/warning/";
- // }else if($a->modul == '06'){
- // $n1 = "Baru/".$cat_modul."/info/";
- // }else if($a->modul == '07'){
- // $n1 = "Baru/".$cat_modul."/danger/";
- // }else if($a->modul == '08'){
- // $n1 = "Baru/".$cat_modul."/inverse/";
- // }
- // }else{
- // if($a->modul == '03'){
- // $n1 = "";
- // }else if($a->modul == '04'){
- // $n1 = $cat_modul."/primary/";
- // }else if($a->modul == '05'){
- // $n1 = $cat_modul."/warning/";
- // }else if($a->modul == '06'){
- // $n1 = $cat_modul."/info/";
- // }else if($a->modul == '07'){
- // $n1 = $cat_modul."/danger/";
- // }else if($a->modul == '08'){
- // $n1 = $cat_modul."/inverse/";
- // }
- // }
-
- if($curr < $expiry_date) {
- $n1 = "Baru/".$class;
- }else{
- $n1 = $class;
- }
-
- if($a->jumlah_kemaskini_kompaun == ''){
- $tawaran = $a->jumlah_asal_kompaun;
- }else{
- $tawaran = $a->jumlah_kemaskini_kompaun;
- }
-
- $no_plate = '-';
- if($a->no_plate != '-'){
- $no_plate = $a->no_plate;
- }else{
- $no_plate = '-';
- }
-
- // $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first();
- // if(!empty($faulty)){
- // $faulty = '['.$faulty->sketr.'] '.$faulty->nama;
- // }
- array_push($nested_data, array(
- 'kpd' => $n1.$a->kpd,
- 'jenis' => $a->jenis,
- 'no_plat' => $no_plate,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'nama' => $a->nama,
- 'nric' => $a->identity,
- 'seksyen' => '['.$a->Faulty->sketr.'] '.$a->Faulty->nama,
- 'jumlah' => 'RM '.$tawaran,
- 'status' => $a->status,
- 'tindakan' => $a->kpd
- ));
-
- $i++;
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function compoundFilterList($jbkod,$akta,$sec,$modul){
-
- $nested_data = array();
-
- if($modul == '06-07'){
- if($jbkod == "null" && $akta == "null" && $sec == "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) {
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->get();
- }else if($jbkod != "null" && $akta == "null" && $sec == "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) {
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->get();
- }
- }else if($jbkod != "null" && $akta != "null" && $sec == "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->get();
- }else {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->get();
- }
- }
- else if($jbkod != "null" && $akta != "null" && $sec != "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }
- }else if($jbkod != "null" && $akta == "null" && $sec != "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('seksyen_kesalahan',$sec)->get();
- }
- }
- else if($jbkod == "null" && $akta != "null" && $sec == "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->get();
- }
- else if($jbkod == "null" && $akta != "null" && $sec != "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }
- else if($jbkod == "null" && $akta == "null" && $sec != "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07')->where('status', 'Belum Bayar');
- });
- })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get();
- }
- }else{
-
- if($jbkod == "null" && $akta == "null" && $sec == "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->get();
- }else if($jbkod != "null" && $akta == "null" && $sec == "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->get();
- }else{
- $compound = Compound::with('ConfidentialFile')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->get();
- }
- }else if($jbkod != "null" && $akta != "null" && $sec == "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->get();
- }
- }
- else if($jbkod != "null" && $akta != "null" && $sec != "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }
- }else if($jbkod != "null" && $akta == "null" && $sec != "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get();
- }else{
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('seksyen_kesalahan',$sec)->get();
- }
- }
- else if($jbkod == "null" && $akta != "null" && $sec == "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->get();
- }
- else if($jbkod == "null" && $akta != "null" && $sec != "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }
- else if($jbkod == "null" && $akta == "null" && $sec != "null"){
- $compound = Compound::with('ConfidentialFile','Faulty')->where(function($q) use($modul){
- $q->where('modul', $modul)->where('status', 'Belum Bayar');
- })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get();
- }
- }
-
-
- $class = '';
- if($modul == '03'){
- $class = "success/";
- }else if($a->modul == '04'){
- $class = $cat_modul."/primary/";
- }else if($a->modul == '05'){
- $class = $cat_modul."/warning/";
- }else if($a->modul == '06'){
- $class = $cat_modul."/info/";
- }else if($a->modul == '07'){
- $class = $cat_modul."/danger/";
- }else if($a->modul == '08'){
- $class = $cat_modul."/inverse/";
- }
-
- $cat_modul = '-';
- if($modul != '-'){
- $cat = Roles::where('kod',$modul)->first();
- if(!empty($cat)){
- if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){
- $dump = explode(' ',trim($cat->name));
- $cat_modul = $dump[0];
- }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){
- $dump = explode('- ',trim($cat->name));
- $cat_modul = $dump[1];
- }else{
- $cat_modul = $cat->name;
- }
- }
- }
-
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($compound as $a) {
- if(!empty($a->ConfidentialFile)){
- $n1 = ''; $faulty = ''; $tawaran = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- /*$cat_modul = '-';
- if($a->modul != '-'){
- $cat = Roles::where('kod',$a->modul)->first();
- if(!empty($cat)){
- if ( preg_match('/\s/',$cat->name) && !preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name)){
- $dump = explode(' ',trim($cat->name));
- $cat_modul = $dump[0];
- }else if( preg_match('/\s/',$cat->name) && preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $cat->name) ){
- $dump = explode('- ',trim($cat->name));
- $cat_modul = $dump[1];
- }else{
- $cat_modul = $cat->name;
- }
- }
- }*/
-
- if($curr < $expiry_date) {
- $n1 = "Baru/".$class;
- }else{
- $n1 = $class;
- }
-
- if($a->jumlah_kemaskini_kompaun == ''){
- $tawaran = $a->jumlah_asal_kompaun;
- }else{
- $tawaran = $a->jumlah_kemaskini_kompaun;
- }
-
- $no_plate = '-';
- if($a->no_plate != '-'){
- $no_plate = $a->no_plate;
- }else{
- $no_plate = '-';
- }
-
- // $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first();
- // if(!empty($faulty)){
- // $faulty = '['.$faulty->sketr.'] '.$faulty->nama;
- // }
-
- if(strpos($jbkod, 'Pegawai') !== false) {
- $temp = explode("|",$jbkod);
- $user = StaffDetail::with('Department')->where('_id', $temp[1])->first();
- if(!empty($user->Department)){
- if(in_array($a->jbkod, (array)$user->department_ids)) {
- array_push($nested_data, array(
- 'kpd' => $n1.$a->kpd,
- 'jenis' => $a->jenis,
- 'no_plat' => $no_plate,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'nama' => $a->nama,
- 'nric' => $a->identity,
- 'seksyen' => $faulty,
- 'jumlah' => 'RM '.$tawaran,
- 'status' => $a->status,
- 'tindakan' => $a->kpd
- ));
-
- $i++;
- }
- }
- }else {
- array_push($nested_data, array(
- 'kpd' => $n1.$a->kpd,
- 'jenis' => $a->jenis,
- 'no_plat' => $no_plate,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'nama' => $a->nama,
- 'nric' => $a->identity,
- 'seksyen' => '['.$a->Faulty->sketr.'] '.$a->Faulty->nama,
- 'jumlah' => 'RM '.$tawaran,
- 'status' => $a->status,
- 'tindakan' => $a->kpd
- ));
-
- $i++;
- }
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function compoundCompleteLists(){
-
- $nested_data = array();
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->get();
-
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($compound as $a)
- {
- $n1 = ''; $faulty = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "Baru/";
- }else{
- $n1 = "";
- }
-
- if(!empty($a->ConfidentialFile)){
-
- $cat_modul = '-';
- if($a->modul != '-'){
- $cat = Roles::where('kod',$a->modul)->first();
- if(!empty($cat)){
- $cat_modul = $cat->name;
- }
- }
-
- $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first();
- if(!empty($faulty)){
- $faulty = '['.$faulty->sketr.'] '.$faulty->nama;
- }
-
- if($a->jumlah_kemaskini_kompaun == ''){
- $tawaran = $a->jumlah_asal_kompaun;
- }else{
- $tawaran = $a->jumlah_kemaskini_kompaun;
- }
-
- if($a->no_plate == '-'){
- $jenis = 'Pelbagai';
- }else{
- $jenis = 'Parkir';
- }
-
- array_push($nested_data, array(
- 'kpd' => $n1.$a->kpd,
- 'jenis' => $jenis,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'seksyen' => $faulty,
- 'jumlah' => 'RM '.$tawaran,
- 'bayaran' => 'RM '.$a->amount_payment,
- 'receipt' => $a->receipt,
- 'status' => $a->status,
- 'tindakan' => $a->kpd
- ));
-
- $i++;
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function compoundCompleteFilterList($jbkod,$akta,$sec){
-
- $nested_data = array();
-
- if($jbkod == "null" && $akta == "null" && $sec == "null"){
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->get();
- }else if($jbkod != "null" && $akta == "null" && $sec == "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->get();
- }else{
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->get();
- }
- }else if($jbkod != "null" && $akta != "null" && $sec == "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->get();
- }else{
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->get();
- }
- }
- else if($jbkod != "null" && $akta != "null" && $sec != "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }else{
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }
- }else if($jbkod != "null" && $akta == "null" && $sec != "null"){
- if(strpos($jbkod, 'Pegawai') !== false) {
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get();
- }else{
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('jbkod',$jbkod)->where('seksyen_kesalahan',$sec)->get();
- }
- }
- else if($jbkod == "null" && $akta != "null" && $sec == "null"){
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->get();
- }
- else if($jbkod == "null" && $akta != "null" && $sec != "null"){
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('akta',$akta)->where('seksyen_kesalahan',$sec)->get();
- }
- else if($jbkod == "null" && $akta == "null" && $sec != "null"){
- $compound = Compound::with('ConfidentialFile')->where(function($q) {
- $q->where('status', 'Berbayar');
- })->orderBy('updated_at', 'desc')->where('seksyen_kesalahan',$sec)->get();
- }
-
- $curr = Carbon::now()->getTimestamp();
- $i = 1;
- foreach($compound as $a)
- {
- $n1 = ''; $faulty = ''; $tawaran = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "Baru/";
- }else{
- $n1 = "";
- }
-
- if(!empty($a->ConfidentialFile)){
-
- $cat_modul = '-';
- if($a->modul != '-'){
- $cat = Roles::where('kod',$a->modul)->first();
- if(!empty($cat)){
- $cat_modul = $cat->name;
- }
- }
-
- $faulty = Faulty::where('_id',$a->seksyen_kesalahan)->first();
- if(!empty($faulty)){
- $faulty = '['.$faulty->sketr.'] '.$faulty->nama;
- }
-
- if($a->jumlah_kemaskini_kompaun == ''){
- $tawaran = $a->jumlah_asal_kompaun;
- }else{
- $tawaran = $a->jumlah_kemaskini_kompaun;
- }
-
- if($a->no_plate == '-'){
- $jenis = 'Pelbagai';
- }else{
- $jenis = 'Parkir';
- }
-
- if(strpos($jbkod, 'Pegawai') !== false) {
- $temp = explode("|",$jbkod);
- $user = StaffDetail::with('Department')->where('_id', $temp[1])->first();
- if(!empty($user->Department)){
- if(in_array($a->jbkod, (array)$user->department_ids)) {
- array_push($nested_data, array(
- 'kpd' => $n1.$a->kpd,
- 'jenis' => $jenis,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'seksyen' => $faulty,
- 'jumlah' => 'RM '.$tawaran,
- 'bayaran' => 'RM '.$a->amount_payment,
- 'receipt' => $a->receipt,
- 'status' => $a->status,
- 'tindakan' => $a->kpd
- ));
-
- $i++;
- }
- }
- }else{
- array_push($nested_data, array(
- 'kpd' => $n1.$a->kpd,
- 'jenis' => $jenis,
- 'tarikh' => $a->created_at->format('d/m/Y'),
- 'masa' => $a->created_at->format('h:i a'),
- 'seksyen' => $faulty,
- 'jumlah' => 'RM '.$tawaran,
- 'bayaran' => 'RM '.$a->amount_payment,
- 'receipt' => $a->receipt,
- 'status' => $a->status,
- 'tindakan' => $a->kpd
- ));
-
- $i++;
- }
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function viewCompoundToday(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
-
- $data = array(); $timestamp = time();
- $start = Carbon::createFromTimestamp($timestamp)->startOfDay();
- $end = Carbon::createFromTimestamp($timestamp)->endOfDay();
- $compound = Compound::with('ConfidentialFile','Faulty','Department')->where('modul','03')->where('dikeluarkan',$staff->_id)->whereBetween('created_at', [$start, $end])->orderBy('created_at','DESC')->get();
-
- foreach($compound as $c){
- if(!empty($c->Faulty) && !empty($c->Department)){
- $tawaran = '';
- $akta = DeedLaw::where('_id',$c->akta)->first();
- $faulty = Faulty::where('_id',$c->seksyen_kesalahan)->first();
-
- if($c->jenis != 'Parkir'){
- array_push($data, array(
- 'jenis' => $c->jenis,
- 'kpd' => $c->kpd,
- 'nama' => $c->nama,
- 'identity' => $c->identity,
- 'alamat' => $c->alamat,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'lokasi_dikompaun' => $c->lokasi_kejadian,
- 'nama_kawasan' => $c->nama_kawasan,
- 'nama_taman' => $c->nama_taman,
- 'nama_jalan' => $c->nama_jalan,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama,
- 'latlong' => $c->latlong,
- 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_c)),
- 'butiran_kesalahan'=> $c->butiran_kesalahan,
- 'no_lesen' => $c->no_akaun_lesen,
- 'no_cukai_jalan' => $c->no_cukai_jalan,
- 'tempoh' => $c->tempoh,
- 'tindakan' => $c->tindakan,
- 'bilangan_anjing' => $c->bil_haiwan ?? '0',
- ));
- }else if($c->jenis == 'Parkir'){
- array_push($data, array(
- "no_plate" => $c->no_plate,
- "no_cukai_jalan" => $c->no_cukai_jalan,
- "jenis_kenderaan" => $c->jenis_kenderaan,
- "model_kenderaan" => $c->model_kenderaan,
- "warna_kenderaan" => $c->warna_kenderaan,
- "nama_taman" => $c->nama_taman,
- "nama_jalan" => $c->nama_jalan,
- "nama_kawasan" => $c->nama_kawasan,
- "no_parking" => $c->no_parking,
- 'jumlah' => $c->jumlah_asal_kompaun,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama,
- 'latlong' => $c->latlong,
- 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_c)),
- 'kpd' => $c->kpd,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'jenis' => $c->jenis,
- 'keterangan'=> $c->catatan,
- ));
- }
- }
- }
-
- return $this->sendResponse($data, 'Senarai data kompaun');
- }
- }
-
- public function viewNoticeToday(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
-
- $data = array();
- $start = Carbon::now()->startOfDay()->toDateTimeString();
- $end = Carbon::now()->endOfDay()->toDateTimeString();
-
- $compound = Compound::with('ConfidentialFile','FaultyNotis','Department')->where('modul','02')
- ->where('dikeluarkan_n',$staff->_id)->whereBetween('created_n', [$start, $end])->orderBy('created_n','DESC')->get();
-
- foreach($compound as $c){
-
- if(!empty($c->FaultyNotis) && !empty($c->Department)){
-
- $akta = DeedLaw::where('_id',$c->akta_n)->first();
-
- if($c->jenis_n != 'Parkir'){
- array_push($data, array(
- 'jenis' => $c->jenis_n,
- 'non' => $c->non,
- 'nama' => $c->nama,
- 'identity' => $c->identity,
- 'alamat' => $c->alamat,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'lokasi_dikompaun' => $c->lokasi_kejadian,
- 'nama_kawasan' => $c->nama_kawasan,
- 'nama_taman' => $c->nama_taman,
- 'nama_jalan' => $c->nama_jalan,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->FaultyNotis->sketr.'] '.$c->FaultyNotis->nama,
- 'latlong' => $c->latlong,
- 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_n)),
- 'butiran_kesalahan'=> $c->butiran_kesalahan_n,
- 'no_lesen' => $c->no_akaun_lesen,
- 'no_cukai_jalan' => $c->no_cukai_jalan,
- 'tempoh' => $c->tempoh,
- 'tindakan' => $c->tindakan,
- 'bilangan_anjing' => $c->bil_haiwan ?? '0',
- ));
- }else if($c->jenis_n == 'Parkir'){
- array_push($data, array(
- "no_plate" => $c->no_plate,
- "no_cukai_jalan" => $c->no_cukai_jalan,
- "jenis_kenderaan" => $c->jenis_kenderaan,
- "model_kenderaan" => $c->model_kenderaan,
- "warna_kenderaan" => $c->warna_kenderaan,
- "nama_taman" => $c->nama_taman,
- "nama_jalan" => $c->nama_jalan,
- "nama_kawasan" => $c->nama_kawasan,
- "no_parking" => $c->no_parking,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->FaultyNotis->sketr.'] '.$c->FaultyNotis->nama,
- 'latlong' => $c->latlong,
- 'created_at' => date('d/m/Y h:i:s A', strtotime($c->created_n)),
- 'non' => $c->non,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'amount' => $c->FaultyNotis->amount,
- 'jenis' => $c->jenis,
- 'keterangan'=> $c->catatan
- ));
- }
- }
- }
-
- return $this->sendResponse($data, 'Senarai data kompaun');
- }
- }
-
- }
|