12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070 |
- <?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)->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' => '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,
- 'jumlah' => $c->jumlah_asal_kompaun,
- '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');
- }
- }
-
- }
|