IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Console/Commands/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Console/Commands/CommunicationSchedule.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class CommunicationSchedule extends Command {

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'communication:publish';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create All Scheduled task of Communication Part.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct() {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle() {
        // Publish Scheduled homework
        $today_date = \Carbon\Carbon::today()->format('Y-m-d');

        $homeworks = \App\Homework::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($homeworks->count() > 0) {
            foreach ($homeworks as $var) {
                $hw = \App\Homework::where('idHomework', '=', $var->idHomework)->first();
                $hw->publishDate = today_date();
                $hw->isPublished = 'Y';
                $hw->update();
            }
        }

        // Publish Scheduled Newsletters
//
        $newletters = \App\NewsLetter::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($newletters->count() > 0) {
            foreach ($newletters as $var) {
                $news = \App\NewsLetter::where('idNewsletter', '=', $var->idNewsletter)->first();
                $news->publishDate = today_date();
                $news->isPublished = 'Y';
                $news->update();
            }
        }
//
//        // Publish Scheduled Circuller
        $circullars = \App\Noticeboard::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($circullars->count() > 0) {
            foreach ($circullars as $var) {
                $news = \App\Noticeboard::where('idNoticeboard', '=', $var->idNoticeboard)->first();
                $news->publishDate = today_date();
                $news->isPublished = 'Y';
                $news->update();
            }
        }
//
//        //Publish Scheduled Thoughts
        $week_thoughts = \App\WeekThought::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($week_thoughts->count() > 0) {
            foreach ($week_thoughts as $var) {
                $wt = \App\WeekThought::where('idThought', '=', $var->idThought)->first();
                $wt->publishDate = today_date();
                $wt->isPublished = 'Y';
                $wt->update();
            }
        }
//
//        //Publish Short Stories
        $shstories = \App\ShortStory::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($shstories->count() > 0) {
            foreach ($shstories as $var) {
                $ss = \App\ShortStory::where('idStory', '=', $var->idStory)->first();
                $ss->publishDate = today_date();
                $ss->isPublished = 'Y';
                $ss->update();
            }
        }
//
//        // Publish Positive News
        $pnews = \App\PositiveNews::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($pnews->count() > 0) {
            foreach ($pnews as $var) {
                $pn = \App\PositiveNews::where('idNews', '=', $var->idNews)->first();
                $pn->publishDate = today_date();
                $pn->isPublished = 'Y';
                $pn->update();
            }
        }
//
//        //Publish Practice Set 
        $psets = \App\PracticeSet::whereDate('publishDate', '=', $today_date)->where('isPublished', '=', 'N')->get();
        if ($psets->count() > 0) {
            foreach ($psets as $var) {
                $pst = \App\PracticeSet::where('idSet', '=', $var->idSet)->first();
                $pst->publishDate = today_date();
                $pst->isPublished = 'Y';
                $pst->update();
            }
        }

        // Calculate Late Arrival and Overtime
//        $now = \Carbon\Carbon::now();
//        $m = $now->month;
//        $employees = \App\Employee::orderBy('idEmployee', 'desc')->where('idSchool', '=', '1')->get();
//        foreach ($employees as $var) {
//            $emp_shift = \App\AssignShift::where('idEmployee', '=', $var->idEmployee)->first();
//
//            // Get Assigned Overtime to Specific Employee
//            $emp_overtime = \App\AssignOvertime::where('idEmployee', '=', $var->idEmployee)->first();
//            if ($emp_overtime != null) {
//                $overtime_start = \Carbon\Carbon::parse($emp_overtime->otAfter);
//            } else {
//                $desig_overtime = \App\AssignOvertime::where('idDesignation', '=', $var->idDesignation)->first();
//                $overtime_start = \Carbon\Carbon::parse($desig_overtime->otAfter);
//            }
//
//            // Get Late Arrival Allowed Master
//            $emp_latemaster = \App\LateArrivalMaster::where('idEmployee', '=', $var->idEmployee)->first();
//            if ($emp_latemaster != null) {
//                $latearrival_start = \Carbon\Carbon::parse($emp_latemaster->lateAllowed);
//                $halfday_after = $emp_latemaster->halfDayAfter;
//                $lateallowed_times = $emp_latemaster->lateAllowedTimes;
//            } else {
//                $desig_latemaster = \App\AssignOvertime::where('idDesignation', '=', $var->idDesignation)->first();
//                $latearrival_start = \Carbon\Carbon::parse($desig_latemaster->lateAllowed);
//                $halfday_after = $desig_latemaster->halfDayAfter;
//                $lateallowed_times = $desig_latemaster->lateAllowedTimes;
//            }
//
//            if ($emp_shift != null) {
//                $shift_details = \App\ShiftDetail::where('weekOff', '=', 'N')->where('idShift', '=', $emp_shift->idShift)->get();
//                foreach ($shift_details as $det) {
//                    $shift_fromtime = \Carbon\Carbon::parse($det->fromTime);
//
//                    $shift_totime = \Carbon\Carbon::parse($det->toTime);
//                    $duration = $shift_totime->diffInHours($shift_fromtime);
//
//                    $status_in = \App\EmpAttendance::where('status', '=', 'IN')
//                                    ->where('date', '=', $today_date)->first();
//                    $status_out = \App\EmpAttendance::where('status', '=', 'IN')
//                                    ->where('date', '=', $today_date)->first();
//
//                    //If Late allowed is per month 
//
//                    if ($status_in != null) {
//                        $intime = $status_in->TimeStamp->format('H:i:s');
//                        if ($halfday_after != null) {
//                            $late = $duration / 2;
//                        } elseif ($lateallowed_times != null && $lateallowed_times == 'monthly') {
//                            //Get Data if employee is already late in month
//                            $lateattendance = \App\EmpAttendance::whereNotNull('lateHours')
//                                            ->where('idMonth', '=', $m)->select(DB::raw('SUM(lateHours) as latehours'))->first();
//                            if (($lateattendance != null && ($lateattendance->latehours) > 0)) {
//                                $late = $intime->diffInHours($latearrival_start);
//                            }
//                        } else {
//                            $late = $intime->diffInHours($latearrival_start);
//                        }
//                        $status_in->lateHours = $late;
//                        $status_in->update();
//                    }
//                    if ($status_out != null) {
//                        $outtime = $status_out->TimeStamp->format('H:i:s');
//                        $over_time = $outtime->diffInHours($overtime_start);
//                        $status_in->otHours = $over_time;
//                        $status_in->update();
//                    }
//                }
//            } else {
//                $desigshift = \App\AssignShift::where('idDesignation', '=', $var->idDesignation)->first();
//                if ($desigshift != null) {
//                    $shift_details = \App\ShiftDetail::where('idShift', '=', $desigshift->idShift)->get();
//                    foreach ($shift_details as $det) {
//                        $shift_fromtime = \Carbon\Carbon::parse($det->fromTime);
//
//                        $shift_totime = \Carbon\Carbon::parse($det->toTime);
//                        $duration = $shift_totime->diffInHours($shift_fromtime);
//
//                        $status_in = \App\EmpAttendance::where('status', '=', 'IN')
//                                        ->where('date', '=', $today_date)->first();
//                        $status_out = \App\EmpAttendance::where('status', '=', 'IN')
//                                        ->where('date', '=', $today_date)->first();
//                        if ($status_in != null) {
//                            $intime = $status_in->TimeStamp->format('H:i:s');
//                            if ($halfday_after != null) {
//                                $late = $duration / 2;
//                            } elseif ($lateallowed_times != null && $lateallowed_times == 'monthly') {
//                                //Get Data if employee is already late in month
//                                $lateattendance = \App\EmpAttendance::whereNotNull('lateHours')
//                                                ->where('idMonth', '=', $m)->select(DB::raw('SUM(lateHours) as latehours'))->first();
//                                if (($lateattendance != null && ($lateattendance->latehours) > 0)) {
//                                    $late = $intime->diffInHours($latearrival_start);
//                                }
//                            } else {
//                                $late = $intime->diffInHours($latearrival_start);
//                            }
//                            $status_in->lateHours = $late;
//                            $status_in->update();
//                        }
//                        if ($status_out != null) {
//                            $outtime = $status_out->TimeStamp->format('H:i:s');
//                            $over_time = $outtime->diffInHours($overtime_start);
//                            $status_in->otHours = $over_time;
//                            $status_in->update();
//                        }
//                    }
//                }
//            }
//        }

        $this->info('Data Published successfully!');
    }

}

Copyright © 2021 - 2025 IMMREX7