![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/update-batches/ |
<?php use Carbon\Carbon; use Corals\Modules\Timesheet\Facades\Timesheet; use Corals\Modules\Timesheet\Models\Entry; use Corals\Modules\Timesheet\Models\Project; use Corals\User\Communication\Models\NotificationTemplate; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; Schema::table('timesheet_projects', function (Blueprint $table) { $table->string('type')->nullable(); $table->string('budget_by')->nullable(); $table->boolean('send_email_on_exceed_limit')->nullable(); $table->decimal('fee')->nullable(); $table->decimal('budget_alert_limit')->nullable(); $table->boolean('reset_budget_each_month')->nullable(); $table->string('bill_by')->nullable(); }); Schema::table('users', function (Blueprint $table) { $table->date('birth_date')->nullable(); $table->boolean('birth_date_visible')->default(0); }); Schema::table('timesheet_project_user', function (Blueprint $table) { $table->decimal('user_rate')->nullable(); }); Project::query()->where('billable', 1) ->update([ 'type' => 'time_and_materials', 'bill_by' => 'project_billable_rate' ]); Project::query()->where('billable', 0) ->update([ 'type' => 'non_billable', 'bill_by' => null ]); Schema::table('timesheet_projects', function (Blueprint $table) { $table->dropColumn('billable'); }); DB::table('settings')->insert([ [ 'code' => 'admin_currency', 'type' => 'TEXT', 'label' => 'Admin Currency', 'value' => 'USD', 'editable' => 1, 'is_public' => 1, 'hidden' => 0, 'category' => 'Timesheet', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), ], [ 'code' => 'total_working_hours_per_month', 'type' => 'NUMBER', 'category' => 'Timesheet', 'label' => 'Total Working Hours Per Month', 'value' => '176', 'editable' => 1, 'is_public' => 1, 'hidden' => 0, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), ], ]); NotificationTemplate::updateOrCreate( [ 'name' => 'notifications.project_budget.exceed', 'event_name' => 'notifications.project_budget.exceed', 'friendly_name' => 'Project Budget Exceed', 'title' => 'Project Budget Exceed', 'body' => [ 'mail' => 'Hello {client_name}, <p>Project {project_name} budget has been exceeded</p>' ], 'via' => ["mail"] ]); Schema::table('timesheet_entries', function (Blueprint $table) { $table->decimal('cost')->after('amount'); }); Entry::query() ->whereNull('hourly_rate') ->with(['project', 'user']) ->chunkById(500, function ($entries) { foreach ($entries as $entry) { logger($entry->id); $calculation = Timesheet::getEntryHourlyRate($entry->project, $entry->user_id, $entry->activity_id, Timesheet::getEntryTotalHours($entry)); $entryHours = $entry->hours + (($entry->minutes ?? 0) / 60); $userRate = $entry->user->hourly_rate ?? 0; if (!$userRate && $entry->user->salary) { $userRate = round($entry->user->salary / 176, 1); } $cost = $entryHours * $userRate; $entry->update([ 'hourly_rate' => data_get($calculation, 'hourly_rate'), 'amount' => data_get($calculation, 'amount'), 'cost' => $cost, ]); } });