Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReplacedQuote
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 newQuotation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 oldQuotation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8/**
9 * The link between a new quotation and the older one it replaced.
10 *
11 * Written when a commercial fills in "Replace quotation" on the add-quote form.
12 * Two consequences flow from a row existing here:
13 *   1. the old quote is moved to status 20 (Rechazado-duplicado), and
14 *   2. the old quote drops out of the KPI / productividad reports, so a
15 *      renegotiated job is counted once instead of twice.
16 *
17 * Both sides are tbl_quotations.id (the internal, immutable id) rather than the
18 * quote_id string, which is user-editable and gets renumbered.
19 *
20 * Not named Tbl* because the table itself has no tbl_ prefix — the spec named
21 * it `replaced_quotes`.
22 */
23class ReplacedQuote extends Model
24{
25    protected $table = 'replaced_quotes';
26
27    protected $fillable = [
28        'new_quotation_id',
29        'old_quotation_id',
30        'company_id',
31        'created_by',
32    ];
33
34    protected $casts = [
35        'new_quotation_id' => 'integer',
36        'old_quotation_id' => 'integer',
37        'company_id' => 'integer',
38    ];
39
40    /** The replacement — the quote that counts. */
41    public function newQuotation(): BelongsTo
42    {
43        return $this->belongsTo(TblQuotations::class, 'new_quotation_id', 'id');
44    }
45
46    /** The superseded quote — the one excluded from the reports. */
47    public function oldQuotation(): BelongsTo
48    {
49        return $this->belongsTo(TblQuotations::class, 'old_quotation_id', 'id');
50    }
51}