refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
56
app/Models/Journal/Day.php
Normal file
56
app/Models/Journal/Day.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Journal;
|
||||
|
||||
use App\Traits\HasUuid;
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Traits\Journalable;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\ModelBinding as Model;
|
||||
use App\Interfaces\IsJournalableInterface;
|
||||
|
||||
class Day extends Model implements IsJournalableInterface
|
||||
{
|
||||
use Journalable, HasUuid;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $dates = [
|
||||
'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the account record associated with the debt.
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the information of the Entry for the journal.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInfoForJournalEntry()
|
||||
{
|
||||
return [
|
||||
'type' => 'day',
|
||||
'id' => $this->id,
|
||||
'rate' => $this->rate,
|
||||
'comment' => $this->comment,
|
||||
'date' => $this->date,
|
||||
'day' => $this->date->day,
|
||||
'day_name' => mb_convert_case(DateHelper::getShortDay($this->date), MB_CASE_TITLE, 'UTF-8'),
|
||||
'month' => $this->date->month,
|
||||
'month_name' => mb_convert_case(DateHelper::getShortMonth($this->date), MB_CASE_UPPER, 'UTF-8'),
|
||||
'year' => $this->date->year,
|
||||
'happens_today' => $this->date->isToday(),
|
||||
];
|
||||
}
|
||||
}
|
||||
83
app/Models/Journal/Entry.php
Normal file
83
app/Models/Journal/Entry.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Journal;
|
||||
|
||||
use App\Traits\HasUuid;
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Traits\Journalable;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\ModelBinding as Model;
|
||||
use App\Interfaces\IsJournalableInterface;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property \Carbon\Carbon $date
|
||||
*/
|
||||
class Entry extends Model implements IsJournalableInterface
|
||||
{
|
||||
use Journalable, HasUuid;
|
||||
|
||||
protected $table = 'entries';
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'account_id',
|
||||
'title',
|
||||
'post',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the account record associated with the entry.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry date.
|
||||
*
|
||||
* @param string $value
|
||||
* @return \Carbon\Carbon
|
||||
*/
|
||||
public function getDateAttribute($value)
|
||||
{
|
||||
// Default to created_at, but show journalEntry->date if the entry type is JournalEntry
|
||||
return $this->journalEntry ? $this->journalEntry->date : $this->created_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the information of the Entry for the journal.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInfoForJournalEntry()
|
||||
{
|
||||
return [
|
||||
'type' => 'entry',
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'post' => $this->post,
|
||||
'day' => $this->date->day,
|
||||
'day_name' => mb_convert_case(DateHelper::getShortDay($this->date), MB_CASE_TITLE, 'UTF-8'),
|
||||
'month' => $this->date->month,
|
||||
'month_name' => mb_convert_case(DateHelper::getShortMonth($this->date), MB_CASE_UPPER, 'UTF-8'),
|
||||
'year' => $this->date->year,
|
||||
'date' => $this->date,
|
||||
'created_at' => DateHelper::getShortDateWithTime($this->created_at),
|
||||
];
|
||||
}
|
||||
}
|
||||
127
app/Models/Journal/JournalEntry.php
Normal file
127
app/Models/Journal/JournalEntry.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Journal;
|
||||
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\ModelBinding as Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Interfaces\IsJournalableInterface;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Account $account
|
||||
* @property User $invitedBy
|
||||
* @property int $account_id
|
||||
* @property IsJournalableInterface $journalable
|
||||
* @property int $journalable_id
|
||||
* @property string $journalable_type
|
||||
* @property \Carbon\Carbon|null $date
|
||||
*/
|
||||
class JournalEntry extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'journal_entries';
|
||||
|
||||
protected $dates = [
|
||||
'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Eager load with every entry.
|
||||
*/
|
||||
protected $with = [
|
||||
'journalable',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all of the owning "journal-able" models.
|
||||
*
|
||||
* @return MorphTo
|
||||
*/
|
||||
public function journalable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account record associated with the journal entry.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry in the journal.
|
||||
*
|
||||
* @param \App\Interfaces\IsJournalableInterface $resourceToLog
|
||||
* @return self
|
||||
*/
|
||||
public static function add(IsJournalableInterface $resourceToLog): self
|
||||
{
|
||||
$journal = new self;
|
||||
$journal->account_id = $resourceToLog->account_id;
|
||||
$journal->date = now(DateHelper::getTimezone());
|
||||
if ($resourceToLog instanceof \App\Models\Account\Activity) {
|
||||
$journal->date = $resourceToLog->happened_at;
|
||||
} elseif ($resourceToLog instanceof \App\Models\Journal\Entry) {
|
||||
$journal->date = $resourceToLog->attributes['date'];
|
||||
}
|
||||
$journal->save();
|
||||
$resourceToLog->journalEntries()->save($journal);
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an entry in the journal.
|
||||
*
|
||||
* @param \App\Interfaces\IsJournalableInterface $resourceToLog
|
||||
* @return self
|
||||
*/
|
||||
public function edit(IsJournalableInterface $resourceToLog): self
|
||||
{
|
||||
if ($resourceToLog instanceof \App\Models\Journal\Entry) {
|
||||
$this->date = $resourceToLog->attributes['date'];
|
||||
}
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the information about the object represented by the Journal Entry.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getObjectData()
|
||||
{
|
||||
// Instantiating the object
|
||||
/** @var IsJournalableInterface */
|
||||
$correspondingObject = $this->journalable;
|
||||
|
||||
return $correspondingObject->getInfoForJournalEntry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter by real entry (day rate or journal entry).
|
||||
*
|
||||
* @param Builder $query
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeEntry(Builder $query): Builder
|
||||
{
|
||||
return $query->where('journalable_type', '!=', 'App\Models\Account\Activity');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user