Jobs billed by a fixed monthly fee get a monthly fee field, kept behind the quotes permission like the quoted amount. A billing material now has a billing month: a new draft adds every monthly fee job with something to bill, each on an invoice of its own, and bills one line for every unbilled month from the job's start up to the billing month (or its end or completion), so skipped months are caught up and no month is billed twice. Their expenses are billed alongside, their hours are covered by the fee and marked billed, and the job keeps running. Co-Authored-By: Claude Opus 5.5 <[email protected]>
91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Jobs\Infrastructure\Persistence\Eloquent;
|
|
|
|
use App\Modules\Jobs\Domain\Enums\JobKind;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
|
use App\Modules\Jobs\Domain\Enums\Priority;
|
|
use Carbon\CarbonImmutable;
|
|
use Database\Factories\CustomerJobFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Table;
|
|
use Illuminate\Database\Eloquent\Attributes\UseFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Persistence model of a customer job, used only inside the Jobs
|
|
* Infrastructure layer. Service units, members, tags and links are in
|
|
* their own tables, read and written by the repository.
|
|
*
|
|
* @property int $id
|
|
* @property string $number
|
|
* @property string $name
|
|
* @property string|null $description
|
|
* @property int $customer_id
|
|
* @property CarbonImmutable|null $starts_on
|
|
* @property CarbonImmutable|null $due_on
|
|
* @property CarbonImmutable|null $planned_from
|
|
* @property CarbonImmutable|null $planned_to
|
|
* @property JobKind $kind
|
|
* @property JobStatus $status
|
|
* @property Priority $priority
|
|
* @property PaymentBasis|null $payment_basis
|
|
* @property string|null $estimated_hours
|
|
* @property string|null $customer_reference
|
|
* @property string|null $instructions
|
|
* @property int $responsible_user_id
|
|
* @property int|null $contact_user_id
|
|
* @property int|null $customer_contact_id
|
|
* @property int|null $biller_user_id
|
|
* @property int|null $billing_unit_id
|
|
* @property int $created_by
|
|
* @property int|null $quoted_amount_cents
|
|
* @property int|null $monthly_fee_cents
|
|
* @property CarbonImmutable|null $completed_at
|
|
* @property int|null $quick_sale_year
|
|
* @property CarbonImmutable $created_at
|
|
*/
|
|
#[Table('customer_jobs')]
|
|
#[Fillable([
|
|
'number', 'name', 'description', 'customer_id', 'starts_on', 'due_on', 'planned_from', 'planned_to',
|
|
'kind', 'status', 'priority', 'payment_basis', 'estimated_hours', 'quoted_amount_cents', 'monthly_fee_cents', 'customer_reference', 'instructions',
|
|
'responsible_user_id', 'contact_user_id', 'customer_contact_id', 'biller_user_id', 'billing_unit_id', 'created_by', 'completed_at',
|
|
])]
|
|
#[UseFactory(CustomerJobFactory::class)]
|
|
class CustomerJobModel extends Model
|
|
{
|
|
/** @use HasFactory<CustomerJobFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'customer_id' => 'integer',
|
|
'quoted_amount_cents' => 'integer',
|
|
'monthly_fee_cents' => 'integer',
|
|
'quick_sale_year' => 'integer',
|
|
'completed_at' => 'immutable_datetime',
|
|
'starts_on' => 'immutable_date',
|
|
'due_on' => 'immutable_date',
|
|
'planned_from' => 'immutable_date',
|
|
'planned_to' => 'immutable_date',
|
|
'kind' => JobKind::class,
|
|
'status' => JobStatus::class,
|
|
'priority' => Priority::class,
|
|
'payment_basis' => PaymentBasis::class,
|
|
'responsible_user_id' => 'integer',
|
|
'contact_user_id' => 'integer',
|
|
'customer_contact_id' => 'integer',
|
|
'biller_user_id' => 'integer',
|
|
'billing_unit_id' => 'integer',
|
|
'created_by' => 'integer',
|
|
'created_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
}
|