123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- <?php
-
- namespace App\Http\Controllers\api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Support\Facades\Schema;
-
- use Carbon\Carbon;
-
- 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 RestfulapiController extends BaseController
- {
-
- /**
- * Create search compound by category controller.
- *
- * @return json
- */
- public function searchIdentity($request){
- $compound = Compound::with('Faulty','Department','DeedLaw')->where('identity',$request)->get();
- return $compound;
- }
-
- public function searchKpd($request){
-
- // if(!empty($request->non)){
- // $compound = Compound::with('Faulty','Department','DeedLaw')->where('non','like',$request)->get();
- // }
- // else{
- $compound = Compound::with('Faulty','Department','DeedLaw')->where('kpd','like',$request)->orWhere('non', 'like', $request)->get();
-
- // }
-
- return $compound;
- }
-
- public function searchSyarikat($request){
- $compound = Compound::with('Faulty','Department','DeedLaw')->where('no_daftar_syarikat','like',$request)->get();
- return $compound;
- }
-
- public function searchPlate($request){
- $compound = Compound::with('Faulty','Department','DeedLaw')->where('no_plate','like',$request)->get();
- return $compound;
- }
-
- /**
- * Create search compound controller.
- *
- * @return json
- */
- public function viewCompoundPersonal(Request $request)
- {
- $compound = array();
-
- //validate api key
- $api_integrasi = ApiIntegration::where('key', $request->key)->first();
-
- if(!empty($api_integrasi)){
-
- if($api_integrasi->status == 'active'){
-
- if($request->filled('mobile')){
-
- $jenis = $request->jenis;
- $ic = $request->ic_num;
- $notice = $request->non;
- $kawasan = $request->kawasan;
- $taman = $request->taman;
- $jalan = $request->jalan;
-
- //get date and convert to ISO format
- $date = $request->date;
-
- $compound = Compound::with('Faulty', 'Department', 'DeedLaw')
- ->where(function($q1) use ($notice, $ic, $date, $jalan, $taman, $kawasan) {
-
- //filter by date
- if(!empty($date) && $date != '-'){
-
- $start = Carbon::createFromFormat('Y-m-d', $date)->startOfDay();
- $end = Carbon::createFromFormat('Y-m-d', $date)->endOfDay();
-
- $q1->whereBetween('created_at', [$start, $end]);
-
- }
- })->where(function($q2) use ($jalan, $taman, $kawasan){
-
- //filter by nama kawasan
- if( (!empty($kawasan) && $kawasan != '-') )
- {
-
- $q2->where('nama_kawasan', 'LIKE', '%'.$kawasan.'%');
- }
-
- })->where(function($q3) use ($taman){
-
- //filter by nama taman
- if((!empty($taman) && $taman != '-'))
- {
-
- $q3->where('nama_taman', 'LIKE', '%'.$taman.'%');
- }
-
- })->where(function($q4) use ($jalan){
-
- //filter by nama jalan
- if((!empty($jalan) && $jalan != '-'))
- {
-
- $q4->where('nama_jalan', 'LIKE', '%'.$jalan.'%');
- }
-
- })->where(function($q3) use ($notice){
-
- //filter by no notice
- if(!empty($notice) && $notice != '-'){
-
- $q3->where('non', $notice)->orWhere('kpd', $notice);
- }
-
- })->orWhere(function($q4) use ($ic) {
-
- //filter by no ic
- if(!empty($ic) && $ic != '-'){
-
- $q4->where('identity', 'like', $ic);
- }
-
- })->get();
-
- }
- else if($request->filled('search')){
-
- $search = $request->search;
-
- $compound = Compound::with('Faulty','Department','DeedLaw')->where('kpd','like',$search)->orWhere('non', 'like', $search)
- ->orWhere('no_daftar_syarikat', $search)->orWhere('no_plate', $search)->orWhere('identity', $search)->get();
-
- }
- else{
-
- return $this->sendError('Could not search!', '');
- }
-
- if(count($compound) > 0){
-
- $data = array();
- $all_data = array();
-
- foreach($compound as $c){
-
- //check compound & notice created and convert to date & time
- $tarikh_n = '-'; $masa_n = '-'; $tarikh = '-'; $masa = '-';
-
- if (!empty($c->created_n))
- {
- $tarikh_n = Carbon::parse($c->created_n)->translatedFormat("l, d F, 'y");
- $masa_n = Carbon::parse($c->created_n)->translatedFormat("g:i A");
- }
-
- if(!empty($c->created_c))
- {
- $tarikh = Carbon::parse($c->created_c)->translatedFormat("l, d F, 'y");
- $masa = Carbon::parse($c->created_c)->translatedFormat("g:i A");
- }
-
- //set default data to '-' if not present
- array_push($data,array(
- "_id" => $c->_id ,
- "non" => $c->non ?? '-',
- "jenis_notis" => $c->jenis_n ?? '-',
- "kpd"=> $c->kpd ?? '-',
- "jenis_kompaun" => $c->jenis ?? '-',
- "nama"=> $c->nama ?? '-',
- "identity" => $c->identity ?? '-',
- "no_tel" => $c->no_tel ?? '-',
- "nama_syarikat" => $c->nama_syarikat ?? '-',
- "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat) ?? '-',
- "no_akaun_lesen" => $c->no_akaun_lesen ?? '-',
- "alamat" => $c->alamat ?? '-',
- "no_plate" => strtoupper($c->no_plate) ?? '-',
- "no_cukai_jalan" => $c->no_cukai_jalan ?? '-',
- "latlong" => $c->latlong ?? '-',
- "nama_kawasan" => $c->nama_kawasan ?? '-',
- "nama_taman" => $c->nama_taman ?? '-',
- "nama_jalan" => $c->nama_jalan ?? '-',
- "lokasi_kejadian" => $c->lokasi_kejadian,
- "jbkod" => $c->Department->jnama ?? '-',
- "akta_notis" => $c->deedlawNotis->nama ?? '-',
- "seksyen_kesalahan_notis" => $c->FaultyNotis->nama ?? '-',
- "akta" => $c->DeedLaw->nama ?? '-',
- "seksyen_kesalahan" => $c->Faulty->nama ?? '-',
- "catatan" => $c->catatan ?? '-',
- "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun ?? '-',
- "amount_payment" => $c->amount_payment ?? '-',
- "receipt" => $c->receipt ?? '-',
- "notis_dikeluarkan" => $c->dikeluarkan_n ?? '-',
- "kompaun_dikeluarkan" => $c->dikeluarkan_n ?? '-',
- "status" => $c->status,
- "tarikh_notis" => $tarikh_n ,
- "masa_notis" => $masa_n ,
- "tarikh_kompaun" => $tarikh,
- "masa_kompaun" => $masa
-
- ));
-
- array_push($all_data, $data);
-
- }
-
- return $this->sendResponse($data, 'Result Found');
-
- }else {
-
- return $this->sendResponse('', 'No Result');
- }
-
- }else{
-
- return $this->sendError('Invalid Api Key', '');
- }
-
- }else{
- return $this->sendError('Invalid Api Key', '');
- }
- }
-
- /**
- * Create update compound controller.
- *
- * @return json
- */
- public function updatePaymentIntegrasi(Request $request){
-
- $api_integrasi = ApiIntegration::where('key', $request->key)->first();
- if(!empty($api_integrasi)){
- if($api_integrasi->status == 'active'){
- $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
- if(!empty($compound)){
-
- if($compound->status != 'Berbayar'){
- $compound->status = 'Berbayar';
- $compound->receipt = $request->receipt;
- $compound->amount_payment = $request->amount;
- $compound->save();
-
- $now = Carbon::now();
- $gDate = $now->format('F Y');
-
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
- 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $compound->ConfidentialFile->history()->attach($history);
- }
-
- $kpd = Compound::where('kpd', $request->kp)->first();
- $department = Department::where('_id',$kpd->jbkod)->first();
- $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
- $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
-
- $data = [
- "_id" => $kpd->_id,
- "kpd"=> $kpd->kpd,
- "nama"=> $kpd->nama,
- "identity" => $kpd->identity,
- "nama_syarikat" => $kpd->nama_syarikat,
- "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
- "alamat" => $kpd->alamat,
- "no_plate" => $kpd->no_plate,
- "latlong" => $kpd->latlong,
- "jbkod" => $department->jnama,
- "akta" => "[".$akta->akkod."] ".$akta->nama,
- "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
- "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
- "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
- "amount_payment" => $kpd->amount_payment,
- "receipt" => $kpd->receipt,
- "dikeluarkan" => $kpd->dikeluarkan,
- "status" => $kpd->status,
- "updated_at" => $kpd->updated_at->toDateTimeString(),
- "created_at" => $kpd->created_at->toDateTimeString(),
- ];
-
- return $this->sendResponse($data, 'Successfully update compound status');
- }else{
- return $this->sendResponse('', 'This compound already been paid');
- }
-
- }else{
- return $this->sendError('Record compound not found!', '');
- }
- }else{
- return $this->sendError('Invalid Api Key', '');
- }
- }else{
- return $this->sendError('Invalid Api Key', '');
- }
- }
-
- public function compoundToEPBT()
- {
- $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
-
- if(!empty($compound))
- {
- $data = [];
- foreach ($compound as $key => $c)
- {
- if($c->jenis == 'Pelbagai_KT')
- {
- $data = [
- 'no_kom' => $c->kpd,
- 'jenis' => $c->jenis,
- 'nama' => $c->nama,
- 'no_ic' => $c->identity,
- 'no_tel' => $c->no_telefon,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'no_akaun_lesen' => $c->no_akaun_lesen,
- 'alamat' => $c->alamat,
- 'jabatan' => $c->Department->jnama,
- 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
- 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
- 'catatan' => $c->catatan,
- 'latlong' => $c->latlong,
- 'status' =>$c->status,
- 'amaun_bayar' => $c->amount_payment,
- 'receipt' => $c->receipt,
-
- ];
- }
- if($c->jenis == 'Pelbagai_JPB')
- {
- $data = [
- 'no_kom' => $c->kpd,
- 'jenis' => $c->jenis,
- 'nama' => $c->nama,
- 'no_ic' => $c->identity,
- 'no_tel' => $c->no_telefon,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'no_akaun_lesen' => $c->no_akaun_lesen,
- 'alamat' => $c->alamat,
- 'jabatan' => $c->Department->jnama,
- 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
- 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
- 'catatan' => $c->catatan,
- 'latlong' => $c->latlong,
- 'status' =>$c->status,
- 'amaun_bayar' => $c->amount_payment,
- 'receipt' => $c->receipt,
-
- ];
- }
- if($c->jenis == 'Pelbagai_PA')
- {
- $data = [
- 'no_kom' => $c->kpd,
- 'jenis' => $c->jenis,
- 'nama' => $c->nama,
- 'no_ic' => $c->identity,
- 'no_tel' => $c->no_telefon,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'no_akaun_lesen' => $c->no_akaun_lesen,
- 'alamat' => $c->alamat,
- 'jabatan' => $c->Department->jnama,
- 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
- 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
- 'bil_haiwan' => $c->bil_haiwan,
- 'catatan' => $c->catatan,
- 'latlong' => $c->latlong,
- 'status' =>$c->status,
- 'amaun_bayar' => $c->amount_payment,
- 'receipt' => $c->receipt,
-
- ];
- }
- if($c->jenis == 'Pelbagai_LESEN')
- {
- $data = [
- 'no_kom' => $c->kpd,
- 'jenis' => $c->jenis,
- 'nama' => $c->nama,
- 'no_ic' => $c->identity,
- 'no_tel' => $c->no_telefon,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'no_akaun_lesen' => $c->no_akaun_lesen,
- 'alamat' => $c->alamat,
- 'jabatan' => $c->Department->jnama,
- 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
- 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
- 'catatan' => $c->catatan,
- 'latlong' => $c->latlong,
- 'status' =>$c->status,
- 'amaun_bayar' => $c->amount_payment,
- 'receipt' => $c->receipt,
-
- ];
- }
- if($c->jenis == 'Parkir')
- {
- $data = [
- 'no_kom' => $c->kpd,
- 'jenis' => $c->jenis,
- 'nama' => $c->nama,
- 'no_ic' => $c->identity,
- 'no_tel' => $c->no_telefon,
- 'nama_syarikat' => $c->nama_syarikat,
- 'no_daftar_syarikat' => $c->no_daftar_syarikat,
- 'no_akaun_lesen' => $c->no_akaun_lesen,
- 'alamat' => $c->alamat,
- 'jabatan' => $c->Department->jnama,
- 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
- 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
- 'catatan' => $c->catatan,
- 'latlong' => $c->latlong,
- 'status' =>$c->status,
- 'amaun_bayar' => $c->amount_payment,
- 'receipt' => $c->receipt,
-
- ];
- }
-
- }
-
- return $this->sendResponse($data, 'Successfully update compound status');
- }
- }
-
- }
|