123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572 |
- <?php
-
- namespace App\Http\Controllers\Api;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- 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\SubHistory;
- use App\Model\Module\Memo;
- use App\Model\Module\Attachment;
-
- use App\Jobs\StoreCompound;
- use App\Jobs\StoreNotice;
- use App\Jobs\StoreCompoundEPBT;
- use App\Jobs\UpdateCompoundPrice;
- use App\Http\Resources\CompoundResource;
-
- class CompoundResourceController extends BaseController
- {
- /**
- * @var ServiceCategory
- */
- protected $compound;
-
- /**
- * ServiceController constructor.
- *
- * @param ServiceCategory $ServiceCategory
- */
- public function __construct(Compound $compound)
- {
- $this->compound = $compound;
- }
-
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
-
- $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
- $start = $dateS->copy()->startOfDay();
-
- if($end_date != ''){
- $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
- $end = $dateE->copy()->endOfDay();
-
- }else{
- $end = $dateS->copy()->endOfDay();
- }
-
-
- if(!empty($day3))
- {
- $compound = Compound::where('jenis_n', $jenis)->whereBetween('created_at', array($start->subDays(3), $end->subDays(3)));
- }
- else if(!empty($day7))
- {
- $compound = Compound::where('jenis_n', $jenis)->whereBetween('created_at', array($start->subDays(7), $end->subDays(7)));
- }
- else
- {
- $compound = Compound::where(function($query) use ($jenis){$query->where('jenis', $jenis)->orWhere('jenis_n', $jenis); })
- ->whereBetween('created_at', array($start, $end));
-
- }
-
- if($modul == 'All'){
- $compound = $compound;
- }else if($modul == '06-07'){
- $compound = $compound->where(function($q){
- $q->where('modul', '06')->orWhere('modul','07');
- });
- }else {
- $compound = $compound->where('modul', $modul);
- }
-
- if($status == 'All'){
- $compound = $compound;
- }else {
- $compound = $compound->where('status', $status);
- }
-
- return $compound;
- }
-
- private function searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7){
-
- if(!empty($day3))
- {
- $compound = Compound::where('jenis_n', $jenis)->where('created_at', Carbon::now()->subDays(3));
-
- }
- else if(!empty($day7))
- {
- $compound = Compound::where('jenis_n', $jenis)->where('created_at', Carbon::now()->subDays(7));
- }
- else
- {
- $compound = Compound::where('jenis', $jenis)->orWhere('jenis_n', $jenis);
- }
-
- if($modul == 'All'){
- $compound = $compound;
- }else if($modul == '06-07'){
- $compound = $compound->where(function($q){
- $q->where(function($query){
- $query->where('modul', '06')->orWhere('modul','07');
- });
- });
- }else {
- $compound = $compound->where('modul', $modul);
-
- }
-
- if($status == 'All'){
- $compound = $compound;
- }else {
- $compound = $compound->where('status', $status);
- }
-
- return $compound;
- }
-
- private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
-
- if(!empty($start_date)){
- $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
- }else{
- $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7);
- }
-
- if($enforcer == 'All'){
- return $compound;
- }else {
- $compound = $compound->where('dikeluarkan', $enforcer)->orWhere('dikeluarkan_n', $enforcer);
- return $compound;
- }
- }
-
- private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7){
- $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
-
- if($faulty == 'All'){
-
- $compound = $compound->whereIn('jbkod', $department);
-
- return $compound;
- }else {
- $compound = $compound->where('seksyen_kesalahan', $faulty)->orWhere('seksyen_kesalahan_n', $faulty);
- return $compound;
- }
- }
-
- private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7){
- $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7);
-
- if(!empty($plate_no)){
- $compound = $compound->where('no_plate',$plate_no);
- return $compound;
- }else{
- return $compound;
- }
- }
-
- private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7){
- $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7);
- if(!empty($kpd)){
- if($modul == '02'){
- $compound = $compound->where('kpd',$kpd)->orWhere('non', $kpd);
- }
- else{
- $compound = $compound->where('kpd',$kpd);
- }
- return $compound;
- }else{
- $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
- return $compound;
- }
- }
-
- private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7){
- $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7);
- if(!empty($company_no)){
- $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
- return $compound;
- }else{
- return $compound;
- }
- }
-
- private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7){
- $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7);
- if(!empty($nric)){
- $compound = $compound->where('identity',$nric);
- return $compound;
- }else{
- return $compound;
- }
- }
-
- private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7){
- $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7);
- if(!empty($license)){
- $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
- return $compound;
- }else{
- return $compound;
- }
- }
-
- private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7){
- $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7);
- if(!empty($namaP)){
- $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
- return $compound;
- }else{
- return $compound;
- }
- }
-
- private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name,$day3, $day7){
- $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7);
-
- if(!empty($company_name)){
- $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
- return $compound;
- }else{
- return $compound;
- }
- }
-
- public function index(Request $request)
- {
-
- // $per_page = '';
- // $kpd = '';
- // $modul = '03';
- // $status = 'All';
- // $jenis = 'Pelbagai_KT';
- // if(!empty($request->department)){
- // $department = array (
- // 0 => '5df355f891d6e66b9c5e626d',
- // 1 => '5df721c5cde7fd741433c6b2',
- // 2 => '5df722a24636f4594f4a3c3d',
- // 3 => '5f17a31795dbfd3320761bfe',
- // 4 => '5f3b872fea58cb3c1b0e7b8d',
- // );
- // }else {
- // $department = [];
- // }
- // // ["5df355f891d6e66b9c5e626d","5df721c5cde7fd741433c6b2","5df722a24636f4594f4a3c3d","5f17a31795dbfd3320761bfe","5f3b872fea58cb3c1b0e7b8d"]
- // $start_date = '';
- // $end_date = '';
- // // $start_date = '2020-09-29';
- // // $end_date = '2020-10-09';
-
- // $enforcer = 'All';
- // $faulty = 'All';
-
- // $plate_no = strtolower('');
- // $company_no = strtolower('');
- // $nric = '';
- // $license = '';
- // $namaP = '';
- // $company_name = '';
- // $day3 = '';
- // $day7 = '';
-
- /////////////////////////////////////////////////////////////////////////////////
-
- $per_page = $request->per_page;
- $kpd = $request->kpd;
-
- $modul = $request->modul;
- $status = $request->status;
- $jenis = $request->type;
- if(!empty($request->department)){
- $department = json_decode($request->department);
- }else {
- $department = [];
- }
- $start_date = $request->start_date;
- $end_date = $request->end_date;
-
- $enforcer = $request->enforcer;
- $faulty = $request->faulty;
-
- $plate_no = strtolower($request->plate_no);
- $company_no = strtolower($request->company_no);
- $nric = $request->nric;
- $license = $request->license;
- $namaP = $request->nameP;
- $company_name = $request->company_name;
- $day3='';
- $day7='';
-
- if ($request->has('day3')) {
- $day3 = $request->day3; //has() checks if param exist and filled
- }
- if ($request->has('day7')) {
- $day3 = $request->day7; //has() checks if param exist and filled
- }
-
- $nested_data = array();
-
- $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name, $day3, $day7)->orderBy('created_at','ASC')->get();
- // dd($compound);
-
- info($compound);
-
- return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
- ->addColumn('index', function($row) {
- $curr = Carbon::now();
- $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
-
- if($curr->diffInDays($dtC) <= 3){
- $html = 'New';
- }else{ $html = ''; }
- return $html;
- })->addColumn('status_kemaskini', function($row) {
- $data = '';
-
- if($row['status'] == 'Berbayar'){
-
- if ($row['modul'] == '02') {
-
- $data = '<b>Selesai</b><div style="margin-top: 8px"><span></span><br/></div>';
- $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
- }
- else{
- $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
- $data .= 'RM '.$row['amount_payment'].'</div>';
- $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
- }
-
- if($row['updated_by'] !== null ){
- $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
- $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
- }else {
- if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
- $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
- $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
- }else {
- $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
- $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
- }
- }
-
- }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
- $data = '<b>'.$row['status'].'</b>';
- $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
- $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
- $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
- }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
- $data = '<b>'.$row['status'].'</b>';
- $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
- $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
- $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
- }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
- $data = '<b>'.$row['status'].'</b>';
- $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
- $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
- $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
- }
- else
- {
- $data = $row['status'];
- }
-
- return $data;
- })->addColumn('kesalahan', function($row) {
- $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
- return $data;
- })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
- }
-
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function generateNumber($jenis, $tag, $modul)
- {
- $num= '';
-
- if($modul == '02')
- {
- //check if theres no 001, start fresh with 0001
- if (empty(Compound::where('jenis_n', $jenis)->where('non', $tag.'0001')->first())) {
-
- $num = '0001';
-
- }
- else{
-
- //check the lastest compound number stored in dbase filtered by jenis
- $notice = Compound::where('jenis_n', $jenis)->withTrashed()->latest()->first();
-
- //sanitize compound number to return only integer
- $num = filter_var($notice['non'], FILTER_SANITIZE_NUMBER_INT);
-
- //compulsory increment to store new compound number, WHILE number is found, keep looping
- do{
-
- (int)$num += 1;
-
- //add 0s at the fornt if number is less than 1000
- if ((strlen((string) $num)) == 1) {
-
- $num = '000'.$num;
-
- }elseif ((strlen((string)$num)) == 2){
-
- $num = '00'.$num;
-
- }elseif ((strlen((string)$num )) == 3) {
-
- $num = '0'.$num;
- }
-
- }while(!empty(Compound::where('jenis_n', $jenis)->where('non', $tag.$num)->first()));
-
- }
- }else if($modul == '03')
- {
- //check if theres no 001, start fresh with 0001
- if (empty(Compound::where('jenis', $jenis)->where('kpd', $tag.'0001')->first())) {
-
- $num = '0001';
-
- }
- else{
-
- //check the lastest compound number stored in dbase filtered by jenis
- $compound = Compound::where('jenis', $jenis)->withTrashed()->latest()->first();
-
- //sanitize compound number to return only integer
- $num = filter_var($compound['kpd'], FILTER_SANITIZE_NUMBER_INT);
-
- //compulsory increment to store new compound number, WHILE number is found, keep looping
- do{
-
- (int)$num += 1;
-
- //add 0s at the fornt if number is less than 1000
- if ((strlen((string) $num)) == 1) {
-
- $num = '000'.$num;
-
- }elseif ((strlen((string)$num)) == 2){
-
- $num = '00'.$num;
-
- }elseif ((strlen((string)$num )) == 3) {
-
- $num = '0'.$num;
- }
-
- }while(!empty(Compound::where('jenis', $jenis)->where('kpd', $tag.$num)->first()));
-
- }
- }
-
-
- //return kpd with tag
- $num = $tag . $num;
-
- return $num;
- }
-
- /**
- * Store a created compound from notice.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
-
- $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
-
- $saved ='';
- $kpd = '';
- $no_siri = '';
- $data = array();
- $faulty = $request->seksyen;
-
- $faulty = Faulty::where('_id',$request->get('seksyen'))->orWhere('nama', 'like', $faulty)->first();
-
- if($request->jenis == 'Parkir')
- {
-
- if(!empty($faulty)){
-
- $countKPD = $this->compound->withTrashed()->count();
-
- do {
- $countKPD = $countKPD + 1;
- } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
-
- $kpd = 'KP'.$countKPD;
- $no_siri = date('yn').'-'.$countKPD;
-
- $fileData = [
- 'no_siri' => $no_siri,
- ];
-
- //only for compound parkir
- $compoundData = [
- 'jenis' => 'Parkir',
- 'kpd' => 'KPD'.$kpd,
- 'nama' => '-',
- 'identity' => '-',
- 'alamat' => '-',
- "no_plate" => strtolower($request->no_plate),
- "no_cukai_jalan" => $request->noCukaijalan,
- "jenis_kenderaan" => $request->jenisKenderaan,
- "model_kenderaan" => $request->modelKenderaan,
- "warna_kenderaan" => $request->warnakenderaan,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "no_parking" => $request->noParking,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '-',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '-',
- "receipt" => '-',
- "modul" => '03',
- "penguatkuasa" => '-',
- "created_c" => Carbon::now()->toDateTimeString(),
- ];
-
- $file = ConfidentialFile::create($fileData);
- $saved = $file->compound()->create($compoundData);
- }
-
- }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB')){
-
- $compound = Compound::where('jenis_n', $request->jenis)->orWhere('non', $request->non)->first();
-
- if(!empty($compound)) {
-
- $saved = '';
-
- if(!($compound->modul == '03' && isset($compound->kpd)))
- {
- if($request->jenis == 'Pelbagai_KT'){
- $kpd = $this->generateNumber($request->jenis, 'KT', '03');
- $compound->kpd = $kpd;
- $compound->jenis = $request->jenis;
- $compound->nama = $request->namaP;
- $compound->identity = $request->noIc;
- $compound->nama_syarikat = $request->namaS;
- $compound->no_daftar_syarikat = strtolower($request->daftarNo);
- $compound->alamat = $request->alamat;
- $compound->lokasi_kejadian = $request->alamat_tempat_kesalahan;
- // $compound->no_plate = $request->no_plate;
- // $compound->no_cukai_jalan = $request->no_cukai_jalan;
- // $compound->nama_kawasan = $request->namaKawasan;
- // $compound->nama_taman = $request->namaTaman;
- // $compound->nama_jalan = $request->namaJalan;
- $compound->butiran_kesalahan = $request->butiran_kesalahan;
- $compound->catatan = $request->catatan;
- $compound->latlong = $request->Latlong;
- $compound->akta = $faulty->deed_law_id;
- $compound->seksyen_kesalahan = $faulty->_id;
- $compound->jumlah_asal_kompaun = $faulty->amount;
- $compound->dikeluarkan = $staff->_id;
- $compound->status = 'Belum Bayar';
- $compound->modul = '03';
- $compound->no_akaun_lesen = $request->lesen;
- $compound->created_c = Carbon::now()->toDateTimeString();
-
-
- }elseif($request->jenis == 'Pelbagai_JPB'){
- $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
- $compound->kpd = $kpd;
- $compound->jenis = $request->jenis;
- $compound->nama = $request->namaP;
- $compound->identity = $request->noIc;
- $compound->nama_syarikat = $request->namaS;
- $compound->no_daftar_syarikat = strtolower($request->daftarNo);
- $compound->alamat = $request->alamat;
- $compound->lokasi_kejadian = $request->alamat_tempat_kesalahan;
- // $compound->no_plate = $request->no_plate;
- // $compound->no_cukai_jalan = $request->no_cukai_jalan;
- // $compound->nama_kawasan => $request->namaKawasan;
- // $compound->nama_taman => $request->namaTaman;
- // $compound->nama_jalan => $request->namaJalan;
- $compound->butiran_kesalahan = $request->butiran_kesalahan;
- $compound->catatan = $request->catatan;
- $compound->latlong = $request->Latlong;
- $compound->akta = $faulty->deed_law_id;
- $compound->seksyen_kesalahan = $faulty->_id;
- $compound->jumlah_asal_kompaun = $faulty->amount;
- $compound->dikeluarkan = $staff->_id;
- $compound->status = 'Belum Bayar';
- $compound->modul = '03';
- $compound->no_akaun_lesen = $request->lesen;
- $compound->created_c = Carbon::now()->toDateTimeString();
-
- }
-
- $saved = $compound->save();
-
- }
- else
- {
- return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
- }
-
-
- if($saved){
- // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- // if(!empty($compound)){
- // dispatch(new UpdateCompoundPrice($kpd));
- // $tawaran = '';
- // if($compound->jumlah_kemaskini_kompaun != ''){
- // $tawaran = $compound->jumlah_kemaskini_kompaun;
- // }else{
- // $tawaran = $compound->jumlah_asal_kompaun;
- // }
- $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
-
- array_push($data, array('kpd' => $kpd));
-
- // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
-
- return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
- // }
- }
- }
- else{
- return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
- }
- }
-
- }
- }
-
- /**
- *
- * Store a newly created notice
- *
- **/
- public function storeNewNotice(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)){
-
- $data = array();
-
- $non = '';
- // $kpd = '';
- $no_siri ='';
- $noticeData = [];
-
- if($request->jenis == 'Parkir'){
-
- //for compound numbering
- // $countKPD = $this->compound->withTrashed()->count();
- // $kpd = 'KPD'.$countKPD;
- // $non = 'KPD'.$countKPD;
-
- // $no_siri = date('yn').'-'.$countKPD.'-0';
-
- // $compoundData = [
- // 'jenis' => 'Parkir',
- // 'kpd' => $kpd,
- // 'non' => $non,
- // 'nama' => '-',
- // 'identity' => '-',
- // 'alamat' => '-',
- // "no_plate" => strtolower($request->no_plate),
- // "no_cukai_jalan" => $request->noCukaijalan,
- // "jenis_kenderaan" => $request->jenisKenderaan,
- // "model_kenderaan" => $request->modelKenderaan,
- // "warna_kenderaan" => $request->warnakenderaan,
- // "nama_kawasan" => $request->namaKawasan,
- // "nama_taman" => $request->namaTaman,
- // "nama_jalan" => $request->namaJalan,
- // "no_parking" => $request->noParking,
- // "catatan" => $request->catatan,
- // "lokasi_kejadian" => '-',
- // 'latlong' => $request->Latlong,
- // 'jbkod' => $request->jabatan,
- // 'akta' => $faulty->deed_law_id,
- // 'seksyen_kesalahan' => $faulty->_id,
- // 'jumlah_asal_kompaun' => $faulty->amount,
- // 'jumlah_kemaskini_kompaun' => '-',
- // 'dikeluarkan' => $staff->_id,
- // "status" => 'Belum Bayar',
- // "amount_payment" => '-',
- // "receipt" => '-',
- // "modul" => $request->modul,
- // "penguatkuasa" => '-',
- // "notis_created" => Carbon::now()->toDateTimeString(),
- // ];
- }elseif($request->jenis == 'Notis_NKG'){
-
- // $kpd = $this->generateNumber($request->jenis, 'KT', '02');
- // $non = 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
-
- $non = $this->generateNumber($request->jenis, 'NKG', '02');
-
- $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-1';
-
- $noticeData = [
- 'jenis' => 'Pelbagai_KT',
- 'jenis_n' => $request->jenis,
- 'kpd' => '-',
- 'non' => $non,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "butiran_kesalahan_n" => $request->butiran_kesalahan,
- "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta_n' => $faulty->deed_law_id,
- 'seksyen_kesalahan_n' => $faulty->_id,
- 'dikeluarkan_n' => $staff->_id,
- "status" => 'Belum Bayar',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- // "maklumat_tambahan" => $request->butiran_kesalahan,
- "tindakan" => $request->tindakan,
- "tempoh" => $request->tempoh,
- // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toiso(),
- "created_n" => Carbon::now()->toDateTimeString(),
- ];
- }elseif($request->jenis == 'Notis_NMH'){
-
- // $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
- // $non = 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
-
- $non = $this->generateNumber($request->jenis, 'NMH', '02');
-
- $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-2';
-
- $noticeData = [
- 'jenis' => 'Pelbagai_JPB',
- 'jenis_n' => $request->jenis,
- 'kpd' => '-',
- 'non' => $non,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "butiran_kesalahan_n" => $request->butiran_kesalahan,
- "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta_n' => $faulty->deed_law_id,
- 'seksyen_kesalahan_n' => $faulty->_id,
- 'dikeluarkan_n' => $staff->_id,
- "status" => 'Belum Bayar',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- // "maklumat_tambahan" => $request->butiran_kesalahan,
- "tindakan" => $request->tindakan,
- "tempoh" => $request->tempoh,
- // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
- "created_n" => Carbon::now()->toDateTimeString(),
- ];
- }
- elseif($request->jenis == 'Notis_NHN'){
-
- //HN bcs other N stands for notice. compound number no need front N
- // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
- // $non = 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
-
- $non = $this->generateNumber($request->jenis, 'NHN', '02' );
-
- $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-3';
-
- $noticeData = [
- 'jenis' => 'Pelbagai_KT',
- 'jenis_n' => $request->jenis,
- 'kpd' => '-',
- 'non' => $non,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "butiran_kesalahan_n" => $request->butiran_kesalahan,
- "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta_n' => $faulty->deed_law_id,
- 'seksyen_kesalahan_n' => $faulty->_id,
- 'dikeluarkan_n' => $staff->_id,
- "status" => 'Belum Bayar',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- // "maklumat_tambahan" => $request->butiran_kesalahan,
- "tindakan" => '-',
- "tempoh" => $request->tempoh,
- // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
- "created_n" => Carbon::now()->toDateTimeString(),
- ];
- }
- elseif($request->jenis == 'Notis_PA'){
-
- // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
- // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
-
- $non = $this->generateNumber($request->jenis, 'PA', '02');
-
- $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
-
- $noticeData = [
- 'jenis' => 'Pelbagai_KT',
- 'jenis_n' => $request->jenis,
- 'kpd' => '-',
- 'non' => $non,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "butiran_kesalahan_n" => $request->butiran_kesalahan,
- "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta_n' => $faulty->deed_law_id,
- 'seksyen_kesalahan_n' => $faulty->_id,
- 'dikeluarkan_n' => $staff->_id,
- "status" => 'Belum Bayar',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- // "maklumat_tambahan" => $request->butiran_kesalahan,
- "tindakan" => $request->tindakan,
- "tempoh" => $request->tempoh,
- // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
- "created_n" => Carbon::now()->toDateTimeString(),
- "bil_haiwan" => $request->bil_haiwan,
- ];
- }elseif($request->jenis == 'Notis_NPPM'){
-
- // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
- // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
-
- $non = $this->generateNumber($request->jenis, 'NPPM', '02');
-
- $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-5';
-
- $noticeData = [
- 'jenis' => 'Pelbagai_KT',
- 'jenis_n' => $request->jenis,
- 'kpd' => '-',
- 'non' => $non,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "butiran_kesalahan_n" => $request->butiran_kesalahan,
- "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta_n' => $faulty->deed_law_id,
- 'seksyen_kesalahan_n' => $faulty->_id,
- 'dikeluarkan_n' => $staff->_id,
- "status" => 'Belum Bayar',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- // "maklumat_tambahan" => $request->butiran_kesalahan,
- "tindakan" => '-',
- "tempoh" => $request->tempoh,
- // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
- "created_n" => Carbon::now()->toDateTimeString(),
- ];
- }
-
- $fileData = [
- 'no_siri' => $no_siri,
- ];
-
- $file = ConfidentialFile::create($fileData);
- $saved = $file->compound()->create($noticeData);
-
- if($saved){
- // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- // if(!empty($compound)){
- // dispatch(new UpdateCompoundPrice($kpd));
- // $tawaran = '';
- // if($compound->jumlah_kemaskini_kompaun != ''){
- // $tawaran = $compound->jumlah_kemaskini_kompaun;
- // }else{
- // $tawaran = $compound->jumlah_asal_kompaun;
- // }
- $this->dispatch(new StoreNotice($request->all(), $non, $staff->_id, $no_siri));
-
- //mobile already accept 'kpd' string, so no need to change string name to 'notis'.
- array_push($data, array(
- 'non' => $non
- ));
-
- return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
- // }
- }
- }
- }
- }
-
- /**
- * Store a newly created compound (parkir, KT, JPB).
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function storeNewCompound(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();
-
- $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
- if(!empty($faulty)){
-
- $kpd = '';
- $no_siri ='';
-
- if($request->jenis == 'Parkir')
- {
- //for compound numbering
- $countKPD = $this->compound->where('jenis','Parkir')->withTrashed()->count();
- $kpd = 'KPD'.$countKPD;
-
- $no_siri = date('yn').'-'.$countKPD.'-0K';
-
- //only for compound parkir
- $compoundData = [
- 'jenis' => 'Parkir',
- 'kpd' => $kpd,
- 'nama' => '-',
- 'identity' => '-',
- 'alamat' => '-',
- "no_plate" => strtolower($request->no_plate),
- "no_cukai_jalan" => $request->noCukaijalan,
- "jenis_kenderaan" => $request->jenisKenderaan,
- "model_kenderaan" => $request->modelKenderaan,
- "warna_kenderaan" => $request->warnakenderaan,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- "no_parking" => $request->noParking,
- "catatan" => $request->catatan,
- "lokasi_kejadian" => '-',
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '-',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '-',
- "receipt" => '-',
- "modul" => '03',
- "penguatkuasa" => '-',
- "created_c" => Carbon::now()->toDateTimeString(),
- ];
- }
- elseif ($request->jenis == 'Pelbagai_KT') {
-
- $kpd = $this->generateNumber($request->jenis, 'KT', '03');
-
- $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1K';
-
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "lokasi_kejadian" => $request->alamat_tempat_pesalah,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- "butiran_kesalahan" => $request->butiran_kesalahan,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '-',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '-',
- "receipt" => '-',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- "created_c" => Carbon::now()->toDateTimeString(),
- ];
- }
- elseif ($request->jenis == 'Pelbagai_JPB') {
-
- $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
-
- $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2K';
-
- $compoundData = [
- 'jenis' => $request->jenis,
- 'kpd' => $kpd,
- 'nama' => $request->namaP,
- 'identity' => $request->noIc,
- 'nama_syarikat' => $request->namaS,
- 'no_daftar_syarikat' => strtolower($request->daftarNo),
- 'alamat' => $request->alamat,
- "lokasi_kejadian" => $request->alamat_tempat_pesalah,
- "nama_kawasan" => $request->namaKawasan,
- "nama_taman" => $request->namaTaman,
- "nama_jalan" => $request->namaJalan,
- 'latlong' => $request->Latlong,
- 'jbkod' => $request->jabatan,
- 'akta' => $faulty->deed_law_id,
- 'seksyen_kesalahan' => $faulty->_id,
- "butiran_kesalahan" => $request->butiran_kesalahan,
- 'jumlah_asal_kompaun' => $faulty->amount,
- 'jumlah_kemaskini_kompaun' => '-',
- 'dikeluarkan' => $staff->_id,
- "status" => 'Belum Bayar',
- "amount_payment" => '-',
- "receipt" => '-',
- "modul" => $request->modul,
- "penguatkuasa" => '-',
- "no_akaun_lesen" => $request->lesen,
- "created_c" => Carbon::now()->toDateTimeString(),
- ];
- }
-
- $fileData = [
- 'no_siri' => $no_siri,
- ];
-
- $file = ConfidentialFile::create($fileData);
- $saved = $file->compound()->create($compoundData);
-
-
- if($saved){
-
- // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
- // if(!empty($compound)){
-
- // dispatch(new UpdateCompoundPrice($kpd));
-
- // $tawaran = '';
- // if($compound->jumlah_kemaskini_kompaun != ''){
- // $tawaran = $compound->jumlah_kemaskini_kompaun;
- // }else{
- // $tawaran = $compound->jumlah_asal_kompaun;
- // }
-
- $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
-
- array_push($data, array('kpd' => $kpd));
-
- // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
-
- return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
-
- }
- return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
- }
- return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
- }
- }
-
-
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- //
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- //
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
-
- public function updateStatusNoticeViaDashboard(Request $request)
- {
- $compound = $this->compound::with('ConfidentialFile')->find($request->id);
- $staff = StaffDetail::find($request->current_id);
- if(!empty($compound) && !empty($staff)){
- if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
-
- if($compound->status != $request->status){
- $compound->status = $request->status;
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $saved = $compound->save();
-
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
- 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- if($request->status == "Berbayar"){
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
- }else{
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
- }else{
-
- if($request->remark != ''){
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $compound->save();
-
- $saved = $compound->save();
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
- 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Tiada kemaskini!',
- ];
- return response()->json($response, 200);
- }
-
- }
-
- }else{
-
- if($compound->status != 'Berbayar' && $compound->status != $request->status){
- $compound->status = $request->status;
- $compound->catatan_dari_admin = $request->remark;
- // $compound->amount_payment = $request->amount;
- $compound->update_by = $request->current_id;
- $saved = $compound->save();
-
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Status notis telah dikemaskini",
- 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- if($request->status == "Berbayar"){
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
- }else{
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
- }else{
-
- if($request->remark != ''){
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $compound->save();
-
- $saved = $compound->save();
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
- 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Tiada kemaskini!',
- ];
- return response()->json($response, 200);
- }
-
- }
- }
- }else{
- $response = [
- 'success' => false,
- 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
- ];
- return response()->json($response, 200);
- }
- }
-
- public function updateStatusPaymentViaDashboard(Request $request)
- {
- $compound = $this->compound::with('ConfidentialFile')->find($request->id);
- $staff = StaffDetail::find($request->current_id);
- if(!empty($compound) && !empty($staff)){
- if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
-
- if($compound->status != $request->status){
- $compound->status = $request->status;
- $compound->catatan_dari_admin = $request->remark;
- $compound->amount_payment = $request->amount;
- $compound->update_by = $request->current_id;
- $saved = $compound->save();
-
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
- 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- if($request->status == "Berbayar"){
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
- }else{
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
- }else{
-
- if($request->remark != ''){
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $compound->save();
-
- $saved = $compound->save();
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
- 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Tiada kemaskini!',
- ];
- return response()->json($response, 200);
- }
-
- }
-
- }else{
-
- if($compound->status != 'Berbayar' && $compound->status != $request->status){
- $compound->status = $request->status;
- $compound->catatan_dari_admin = $request->remark;
- $compound->amount_payment = $request->amount;
- $compound->update_by = $request->current_id;
- $saved = $compound->save();
-
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
- 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- if($request->status == "Berbayar"){
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
- }else{
- return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
- }else{
-
- if($request->remark != ''){
- $compound->catatan_dari_admin = $request->remark;
- $compound->update_by = $request->current_id;
- $compound->save();
-
- $saved = $compound->save();
- if($saved){
-
- $gDate = $compound->created_at->format('F Y');
- $historyData = [
- 'tarikh_kumpulan' => $gDate,
- ];
- $subHistory = [
- 'no_siri' => $compound->ConfidentialFile->no_siri,
- 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
- 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
- ];
-
- $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
- if(!empty($groupByDate)){
- $groupByDate->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
- }else{
- $history = History::create($historyData);
- $history->subhistory()->create($subHistory);
- $historySaved = $compound->ConfidentialFile->history()->attach($history);
- }
-
- return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
- ];
- return response()->json($response, 200);
- }
-
- }else{
- $response = [
- 'success' => false, 'message' => 'Tiada kemaskini!',
- ];
- return response()->json($response, 200);
- }
-
- }
- }
- }else{
- $response = [
- 'success' => false,
- 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
- ];
- return response()->json($response, 200);
- }
-
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
|