feat: add account linking and improve sales table
- Add many-to-many relationships between Sale/Expense and Account models - Create pivot tables for account_sale and account_expense with migrations - Implement account syncing during sale/expense creation and editing - Add accounts_list attribute to display comma-separated account names - Introduce SaleService with DTO for sale creation logic - Simplify sales table columns to show branch, reference, date, and creator - Calculate and store aggregated financial fields from transactions - Make series field read-only instead of disabled in sale form
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Expense extends Model
|
||||
@@ -43,4 +44,14 @@ class Expense extends Model
|
||||
{
|
||||
return $this->belongsTo(Branch::class);
|
||||
}
|
||||
|
||||
public function accounts(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Account::class, 'account_expense')->withTimestamps();
|
||||
}
|
||||
|
||||
public function getAccountsListAttribute(): string
|
||||
{
|
||||
return $this->accounts->pluck('account')->implode(', ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Sale extends Model
|
||||
@@ -43,4 +44,19 @@ class Sale extends Model
|
||||
{
|
||||
return $this->belongsTo(Branch::class);
|
||||
}
|
||||
|
||||
public function accounts(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Account::class, 'account_sale')->withTimestamps();
|
||||
}
|
||||
|
||||
public function getAccountsListAttribute(): string
|
||||
{
|
||||
return $this->accounts->pluck('account')->implode(', ');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user