Skip to content

Commit

Permalink
Offline feature added to Invoice model;
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-thomas committed Sep 17, 2023
1 parent 14fcf3f commit 19f1227
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ public function up(): void
{
Schema::create((new Invoice())->getTable(), function (Blueprint $table) {
$table->id();
$table->smallInteger('number'); // Max value: 65535
$table->smallInteger('number'); // Max value: 65535 TODO: bigger range needed
$table->string('token', 128)->nullable()->unique();
$table->string('transaction_id', 256)->nullable()->unique();
$table->string('gateway');
$table->unsignedDecimal('amount', 10);
$table->string('status', 32)->default(Status::PENDING->name);
$table->boolean('offline')->default(false);
$table->timestamps();
});
}
Expand Down
41 changes: 33 additions & 8 deletions src/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
namespace Hans\Lyra\Models;

use Hans\Lyra\Helpers\Enums\Status;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;

/**
* @property int $id
* @property int $number
* @property string $token
* @property string $transaction_id
* @property string $gateway
* @property int $amount
* @property Status $status
* @property int $id
* @property int $number
* @property string $token
* @property string $transaction_id
* @property string $gateway
* @property int $amount
* @property Status $status
* @property boolean $offline
* @property Collection $items
* @method static Builder offline()
*/
class Invoice extends Model
{
Expand All @@ -31,6 +34,7 @@ class Invoice extends Model
'gateway',
'amount',
'status',
'offline'
];

/**
Expand All @@ -39,7 +43,8 @@ class Invoice extends Model
* @var array
*/
protected $casts = [
'status' => Status::class,
'status' => Status::class,
'offline' => 'bool'
];

/**
Expand All @@ -52,6 +57,26 @@ protected static function booted()
self::creating(fn (self $model) => $model->number = generate_unique_invoice_number());
}

/**
* @param Builder $builder
*
* @return void
*/
public function scopeOffline(Builder $builder): void
{
$builder->where('offline', 1);
}

/**
* @return $this
*/
public function setOffline(): self
{
$this->offline = true;

return $this;
}

/**
* Relationship's definition with Invoicable.
*
Expand Down

0 comments on commit 19f1227

Please sign in to comment.