added more scopes
This commit is contained in:
parent
70bfe8c524
commit
430c092ebe
@ -9,7 +9,7 @@ class Payments extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'bill', 'category', 'contact'])->type('expense')->usingSearchString(request('search'));
|
||||
$model = Model::with(['account', 'bill', 'category', 'contact'])->expense()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
|
@ -9,7 +9,7 @@ class BillTransactions extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'category', 'contact', 'bill'])->type('expense')->isDocument()->usingSearchString(request('search'));
|
||||
$model = Model::with(['account', 'category', 'contact', 'bill'])->expense()->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
|
@ -9,7 +9,7 @@ class Revenues extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'category', 'contact', 'invoice'])->type('income')->usingSearchString(request('search'));
|
||||
$model = Model::with(['account', 'category', 'contact', 'invoice'])->income()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
|
@ -9,7 +9,7 @@ class InvoiceTransactions extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::with(['account', 'category', 'contact', 'invoice'])->type('income')->isDocument()->usingSearchString(request('search'));
|
||||
$model = Model::with(['account', 'category', 'contact', 'invoice'])->income()->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
|
@ -50,7 +50,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
@ -131,7 +131,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function edit(Item $item)
|
||||
{
|
||||
$categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
|
@ -65,7 +65,7 @@ class Search extends Controller
|
||||
}
|
||||
}/*
|
||||
|
||||
$income_transactions = Transaction::type('income')->usingSearchString($keyword)->get();
|
||||
$income_transactions = Transaction::income()->usingSearchString($keyword)->get();
|
||||
|
||||
if ($income_transactions->count()) {
|
||||
foreach ($income_transactions as $transaction) {
|
||||
@ -107,7 +107,7 @@ class Search extends Controller
|
||||
}
|
||||
}
|
||||
/*
|
||||
$payments = Transaction::type('expense')->usingSearchString($keyword)->get();
|
||||
$payments = Transaction::expense()->usingSearchString($keyword)->get();
|
||||
|
||||
if ($revenues->count()) {
|
||||
foreach ($revenues as $revenue) {
|
||||
|
@ -30,7 +30,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function create(IRequest $request)
|
||||
{
|
||||
$categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::item()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
|
||||
|
||||
|
@ -27,7 +27,7 @@ class Invoices extends Controller
|
||||
->accrued()->where('contact_id', user()->contact->id)
|
||||
->collect(['invoice_number'=> 'desc']);
|
||||
|
||||
$categories = collect(Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'));
|
||||
$categories = collect(Category::income()->enabled()->orderBy('name')->pluck('name', 'id'));
|
||||
|
||||
$statuses = $this->getInvoiceStatuses();
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Payments extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$payments = Transaction::type('income')->where('contact_id', '=', user()->contact->id)->paginate();
|
||||
$payments = Transaction::income()->where('contact_id', '=', user()->contact->id)->paginate();
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods('all');
|
||||
|
||||
|
@ -41,7 +41,7 @@ class Bills extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$statuses = $this->getBillStatuses();
|
||||
|
||||
@ -67,7 +67,7 @@ class Bills extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -106,7 +106,7 @@ class Bills extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$number = $this->getNextBillNumber();
|
||||
|
||||
@ -202,7 +202,7 @@ class Bills extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
return view('purchases.bills.edit', compact('bill', 'vendors', 'currencies', 'currency', 'items', 'taxes', 'categories'));
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class Payments extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$payments = Transaction::type('expense')->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
|
||||
$payments = Transaction::expense()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
@ -68,7 +68,7 @@ class Payments extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -156,7 +156,7 @@ class Payments extends Controller
|
||||
|
||||
$vendors = Contact::vendor()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::expense()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
|
@ -78,7 +78,7 @@ class Vendors extends Controller
|
||||
}
|
||||
|
||||
// Handle payments
|
||||
$transactions = Transaction::where('contact_id', $vendor->id)->type('expense')->get();
|
||||
$transactions = Transaction::where('contact_id', $vendor->id)->expense()->get();
|
||||
|
||||
$counts['transactions'] = $transactions->count();
|
||||
|
||||
|
@ -76,7 +76,7 @@ class Customers extends Controller
|
||||
}
|
||||
|
||||
// Handle transactions
|
||||
$transactions = Transaction::where('contact_id', $customer->id)->type('income')->get();
|
||||
$transactions = Transaction::where('contact_id', $customer->id)->income()->get();
|
||||
|
||||
$counts['transactions'] = $transactions->count();
|
||||
|
||||
|
@ -42,7 +42,7 @@ class Invoices extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$statuses = $this->getInvoiceStatuses();
|
||||
|
||||
@ -68,7 +68,7 @@ class Invoices extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -109,7 +109,7 @@ class Invoices extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$number = $this->getNextInvoiceNumber();
|
||||
|
||||
@ -205,7 +205,7 @@ class Invoices extends Controller
|
||||
|
||||
$taxes = Tax::enabled()->orderBy('name')->get();
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
return view('sales.invoices.edit', compact('invoice', 'customers', 'currencies', 'currency', 'items', 'taxes', 'categories'));
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ class Revenues extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$revenues = Transaction::type('income')->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
|
||||
$revenues = Transaction::income()->with(['account', 'category', 'contact'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
@ -68,7 +68,7 @@ class Revenues extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
@ -156,7 +156,7 @@ class Revenues extends Controller
|
||||
|
||||
$customers = Contact::customer()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
$categories = Category::income()->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
|
@ -96,6 +96,28 @@ class Transaction extends Model
|
||||
return $query->whereIn($this->table . '.type', (array) $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only income.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIncome($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'income');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only expense.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeExpense($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'expense');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get only transfers.
|
||||
*
|
||||
|
@ -68,6 +68,50 @@ class Category extends Model
|
||||
return $query->whereIn($this->table . '.type', (array) $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only income.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIncome($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'income');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only expense.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeExpense($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'expense');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only item.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeItem($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'item');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to include only other.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOther($query)
|
||||
{
|
||||
return $query->where($this->table . '.type', '=', 'other');
|
||||
}
|
||||
|
||||
public function scopeName($query, $name)
|
||||
{
|
||||
return $query->where('name', '=', $name);
|
||||
@ -81,6 +125,6 @@ class Category extends Model
|
||||
*/
|
||||
public function scopeTransfer($query)
|
||||
{
|
||||
return $query->where('type', 'other')->pluck('id')->first();
|
||||
return $query->where($this->table . '.type', '=', 'other')->pluck('id')->first();
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class ExpenseSummary extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
|
@ -16,8 +16,8 @@ class IncomeExpenseSummary extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$income_transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
|
@ -30,7 +30,7 @@ class IncomeSummary extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
|
@ -40,8 +40,8 @@ class ProfitLoss extends Report
|
||||
|
||||
public function setData()
|
||||
{
|
||||
$income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$income_transactions = $this->applyFilters(Transaction::income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
$expense_transactions = $this->applyFilters(Transaction::expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
|
@ -47,11 +47,11 @@ class TaxSummary extends Report
|
||||
switch ($this->model->settings->basis) {
|
||||
case 'cash':
|
||||
// Invoice Payments
|
||||
$invoices = $this->applyFilters(Transaction::with(['invoice', 'invoice.totals'])->type('income')->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$invoices = $this->applyFilters(Transaction::with(['invoice', 'invoice.totals'])->income()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$this->setTotals($invoices, 'paid_at');
|
||||
|
||||
// Bill Payments
|
||||
$bills = $this->applyFilters(Transaction::with(['bill', 'bill.totals'])->type('expense')->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$bills = $this->applyFilters(Transaction::with(['bill', 'bill.totals'])->expense()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||
$this->setTotals($bills, 'paid_at');
|
||||
|
||||
break;
|
||||
|
@ -15,7 +15,7 @@ class ExpensesByCategory extends Widget
|
||||
|
||||
public function show()
|
||||
{
|
||||
Category::with('expense_transactions')->type('expense')->each(function ($category) {
|
||||
Category::with('expense_transactions')->expense()->each(function ($category) {
|
||||
$amount = 0;
|
||||
|
||||
$this->applyFilters($category->expense_transactions())->each(function ($transaction) use (&$amount) {
|
||||
|
@ -15,7 +15,7 @@ class IncomeByCategory extends Widget
|
||||
|
||||
public function show()
|
||||
{
|
||||
Category::with('income_transactions')->type('income')->each(function ($category) {
|
||||
Category::with('income_transactions')->income()->each(function ($category) {
|
||||
$amount = 0;
|
||||
|
||||
$this->applyFilters($category->income_transactions())->each(function ($transaction) use (&$amount) {
|
||||
|
@ -11,7 +11,7 @@ class LatestExpenses extends Widget
|
||||
|
||||
public function show()
|
||||
{
|
||||
$transactions = $this->applyFilters(Transaction::with('category')->type('expense')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get();
|
||||
$transactions = $this->applyFilters(Transaction::with('category')->expense()->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get();
|
||||
|
||||
return $this->view('widgets.latest_expenses', [
|
||||
'transactions' => $transactions,
|
||||
|
@ -11,7 +11,7 @@ class LatestIncome extends Widget
|
||||
|
||||
public function show()
|
||||
{
|
||||
$transactions = $this->applyFilters(Transaction::with('category')->type('income')->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get();
|
||||
$transactions = $this->applyFilters(Transaction::with('category')->income()->orderBy('paid_at', 'desc')->isNotTransfer()->take(5))->get();
|
||||
|
||||
return $this->view('widgets.latest_income', [
|
||||
'transactions' => $transactions,
|
||||
|
@ -18,7 +18,7 @@ class TotalExpenses extends Widget
|
||||
{
|
||||
$current = $open = $overdue = 0;
|
||||
|
||||
$this->applyFilters(Transaction::type('expense')->isNotTransfer())->each(function ($transaction) use (&$current) {
|
||||
$this->applyFilters(Transaction::expense()->isNotTransfer())->each(function ($transaction) use (&$current) {
|
||||
$current += $transaction->getAmountConvertedToDefault();
|
||||
});
|
||||
|
||||
|
@ -18,7 +18,7 @@ class TotalIncome extends Widget
|
||||
{
|
||||
$current = $open = $overdue = 0;
|
||||
|
||||
$this->applyFilters(Transaction::type('income')->isNotTransfer())->each(function ($transaction) use (&$current) {
|
||||
$this->applyFilters(Transaction::income()->isNotTransfer())->each(function ($transaction) use (&$current) {
|
||||
$current += $transaction->getAmountConvertedToDefault();
|
||||
});
|
||||
|
||||
|
@ -41,7 +41,7 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) {
|
||||
'currency_code' => setting('default.currency'),
|
||||
'currency_rate' => '1',
|
||||
'notes' => $faker->text(5),
|
||||
'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(),
|
||||
'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
'contact_email' => $contact->email,
|
||||
|
@ -42,7 +42,7 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) {
|
||||
'currency_code' => setting('default.currency'),
|
||||
'currency_rate' => '1',
|
||||
'notes' => $faker->text(5),
|
||||
'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(),
|
||||
'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
'contact_email' => $contact->email,
|
||||
|
@ -16,7 +16,7 @@ $factory->define(Item::class, function (Faker $faker) use ($company) {
|
||||
'description' => $faker->text(100),
|
||||
'purchase_price' => $faker->randomFloat(2, 10, 20),
|
||||
'sale_price' => $faker->randomFloat(2, 10, 20),
|
||||
'category_id' => $company->categories()->type('item')->get()->random(1)->pluck('id')->first(),
|
||||
'category_id' => $company->categories()->item()->get()->random(1)->pluck('id')->first(),
|
||||
'tax_id' => null,
|
||||
'enabled' => $faker->boolean ? 1 : 0,
|
||||
];
|
||||
|
@ -31,13 +31,13 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) {
|
||||
$factory->state(Transaction::class, 'income', function (Faker $faker) use ($company) {
|
||||
return [
|
||||
'type' => 'income',
|
||||
'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(),
|
||||
'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) {
|
||||
return [
|
||||
'type' => 'expense',
|
||||
'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(),
|
||||
'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
];
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user