123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- <?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)->first();
- dd($kpd);
- 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->jumlah_kemaskini_kompaun == ''){
- $tawaran = $c->jumlah_asal_kompaun;
- }else{
- $tawaran = $c->jumlah_kemaskini_kompaun;
- }
-
- if($c->jenis == 'Pelbagai'){
- array_push($data, array(
- "no_plate" => $c->no_plate,
- 'nama' => $c->nama,
- 'identity' => $c->identity,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'alamat' => $c->alamat,
- 'jumlah' => $tawaran,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama,
- 'latlong' => $c->latlong,
- 'created_at' => $c->created_at->format('d/m/Y h:i:s A'),
- 'kpd' => $c->kpd,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'amount_before_14' => $c->Faulty->amount_before_14,
- 'amount_before_30' => $c->Faulty->amount_before_30,
- 'amount' => $c->Faulty->amount,
- 'jenis' => $c->jenis,
- 'keterangan'=> $c->catatan,
- 'no_telefon' => $c->no_telefon,
- 'no_lesen' => $c->no_akaun_lesen,
- 'lokasi_dikompaun' => $c->lokasi_kejadian,
- 'no_cukai_jalan' => $c->no_cukai_jalan,
- ));
- }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' => $tawaran,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama,
- 'latlong' => $c->latlong,
- 'created_at' => $c->created_at->format('d/m/Y h:i:s A'),
- 'kpd' => $c->kpd,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'amount_before_14' => $c->Faulty->amount_before_14,
- 'amount_before_30' => $c->Faulty->amount_before_30,
- 'amount' => $c->Faulty->amount,
- '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(); $timestamp = time();
- $start = Carbon::createFromTimestamp($timestamp)->startOfDay();
- $end = Carbon::createFromTimestamp($timestamp)->endOfDay();
- $compound = Compound::with('ConfidentialFile','Faulty','Department')->where('modul','02')->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->jumlah_kemaskini_kompaun == ''){
- $tawaran = $c->jumlah_asal_kompaun;
- }else{
- $tawaran = $c->jumlah_kemaskini_kompaun;
- }
-
- if($c->jenis == 'Pelbagai'){
- array_push($data, array(
- "no_plate" => $c->no_plate,
- 'nama' => $c->nama,
- 'identity' => $c->identity,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'alamat' => $c->alamat,
- 'jumlah' => $tawaran,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama,
- 'latlong' => $c->latlong,
- 'created_at' => $c->created_at->format('d/m/Y h:i:s A'),
- 'kpd' => $c->kpd,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'amount_before_14' => $c->Faulty->amount_before_14,
- 'amount_before_30' => $c->Faulty->amount_before_30,
- 'amount' => $c->Faulty->amount,
- 'jenis' => $c->jenis,
- 'keterangan'=> $c->catatan,
- 'no_telefon' => $c->no_telefon,
- 'no_lesen' => $c->no_akaun_lesen,
- 'lokasi_dikompaun' => $c->lokasi_kejadian,
- 'no_cukai_jalan' => $c->no_cukai_jalan,
- ));
- }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' => $tawaran,
- 'akta' => '['.$akta->akkod.'] '.$akta->nama,
- 'seksyen_kesalahan' => '['.$c->Faulty->sketr.'] '.$c->Faulty->nama,
- 'latlong' => $c->latlong,
- 'created_at' => $c->created_at->format('d/m/Y h:i:s A'),
- 'kpd' => $c->kpd,
- 'jabatan' => '['.$c->Department->jbkod.'] '.$c->Department->jnama,
- 'amount_before_14' => $c->Faulty->amount_before_14,
- 'amount_before_30' => $c->Faulty->amount_before_30,
- 'amount' => $c->Faulty->amount,
- 'jenis' => $c->jenis,
- 'keterangan'=> $c->catatan
- ));
- }
- }
- }
-
- return $this->sendResponse($data, 'Senarai data kompaun');
- }
- }
-
- }
|