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:
31
app/Services/Sales/SaleService.php
Normal file
31
app/Services/Sales/SaleService.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Sales;
|
||||
|
||||
use App\DataObjects\CreateSaleDTO;
|
||||
use App\Models\Sale;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SaleService
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function create(array $data): Sale
|
||||
{
|
||||
|
||||
$tData = new CreateSaleDTO(
|
||||
reference_number: $data['current_series'],
|
||||
happened_on: Carbon::parse($data['happened_on']),
|
||||
branch_id: $data['branch_id'],
|
||||
user_id: Auth::user()->id,
|
||||
);
|
||||
return Sale::create($tData->toArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user