more eager loading
This commit is contained in:
parent
f47ae3b636
commit
1441a56908
@ -28,7 +28,7 @@ class Vendors extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$vendors = Contact::vendor()->collect();
|
$vendors = Contact::with('bills.transactions')->vendor()->collect();
|
||||||
|
|
||||||
return view('purchases.vendors.index', compact('vendors'));
|
return view('purchases.vendors.index', compact('vendors'));
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ class Vendors extends Controller
|
|||||||
$counts = [];
|
$counts = [];
|
||||||
|
|
||||||
// Handle bills
|
// Handle bills
|
||||||
$bills = Bill::where('contact_id', $vendor->id)->get();
|
$bills = Bill::with('transactions')->where('contact_id', $vendor->id)->get();
|
||||||
|
|
||||||
$counts['bills'] = $bills->count();
|
$counts['bills'] = $bills->count();
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class Vendors extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle payments
|
// Handle payments
|
||||||
$transactions = Transaction::where('contact_id', $vendor->id)->expense()->get();
|
$transactions = Transaction::with('category')->where('contact_id', $vendor->id)->expense()->get();
|
||||||
|
|
||||||
$counts['transactions'] = $transactions->count();
|
$counts['transactions'] = $transactions->count();
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Customers extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$customers = Contact::customer()->collect();
|
$customers = Contact::with('invoices.transactions')->customer()->collect();
|
||||||
|
|
||||||
return view('sales.customers.index', compact('customers'));
|
return view('sales.customers.index', compact('customers'));
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ class Customers extends Controller
|
|||||||
$counts = [];
|
$counts = [];
|
||||||
|
|
||||||
// Handle invoices
|
// Handle invoices
|
||||||
$invoices = Invoice::where('contact_id', $customer->id)->get();
|
$invoices = Invoice::with('transactions')->where('contact_id', $customer->id)->get();
|
||||||
|
|
||||||
$counts['invoices'] = $invoices->count();
|
$counts['invoices'] = $invoices->count();
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class Customers extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle transactions
|
// Handle transactions
|
||||||
$transactions = Transaction::where('contact_id', $customer->id)->income()->get();
|
$transactions = Transaction::with('category')->where('contact_id', $customer->id)->income()->get();
|
||||||
|
|
||||||
$counts['transactions'] = $transactions->count();
|
$counts['transactions'] = $transactions->count();
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class Contact extends Model
|
|||||||
|
|
||||||
$collection = in_array($this->type, $this->getCustomerTypes()) ? 'invoices' : 'bills';
|
$collection = in_array($this->type, $this->getCustomerTypes()) ? 'invoices' : 'bills';
|
||||||
|
|
||||||
$this->$collection()->accrued()->notPaid()->each(function ($item) use (&$amount) {
|
$this->$collection->whereNotIn('status', ['draft', 'cancelled', 'paid'])->each(function ($item) use (&$amount) {
|
||||||
$unpaid = $item->amount - $item->paid;
|
$unpaid = $item->amount - $item->paid;
|
||||||
|
|
||||||
$amount += $this->convertToDefault($unpaid, $item->currency_code, $item->currency_rate);
|
$amount += $this->convertToDefault($unpaid, $item->currency_code, $item->currency_rate);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user