more eager loading
This commit is contained in:
		@@ -28,7 +28,7 @@ class Vendors extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $vendors = Contact::vendor()->collect();
 | 
			
		||||
        $vendors = Contact::with('bills.transactions')->vendor()->collect();
 | 
			
		||||
 | 
			
		||||
        return view('purchases.vendors.index', compact('vendors'));
 | 
			
		||||
    }
 | 
			
		||||
@@ -51,7 +51,7 @@ class Vendors extends Controller
 | 
			
		||||
        $counts = [];
 | 
			
		||||
 | 
			
		||||
        // Handle bills
 | 
			
		||||
        $bills = Bill::where('contact_id', $vendor->id)->get();
 | 
			
		||||
        $bills = Bill::with('transactions')->where('contact_id', $vendor->id)->get();
 | 
			
		||||
 | 
			
		||||
        $counts['bills'] = $bills->count();
 | 
			
		||||
 | 
			
		||||
@@ -78,7 +78,7 @@ class Vendors extends Controller
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 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();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ class Customers extends Controller
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        $customers = Contact::customer()->collect();
 | 
			
		||||
        $customers = Contact::with('invoices.transactions')->customer()->collect();
 | 
			
		||||
 | 
			
		||||
        return view('sales.customers.index', compact('customers'));
 | 
			
		||||
    }
 | 
			
		||||
@@ -49,7 +49,7 @@ class Customers extends Controller
 | 
			
		||||
        $counts = [];
 | 
			
		||||
 | 
			
		||||
        // Handle invoices
 | 
			
		||||
        $invoices = Invoice::where('contact_id', $customer->id)->get();
 | 
			
		||||
        $invoices = Invoice::with('transactions')->where('contact_id', $customer->id)->get();
 | 
			
		||||
 | 
			
		||||
        $counts['invoices'] = $invoices->count();
 | 
			
		||||
 | 
			
		||||
@@ -76,7 +76,7 @@ class Customers extends Controller
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 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();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -135,7 +135,7 @@ class Contact extends Model
 | 
			
		||||
 | 
			
		||||
        $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;
 | 
			
		||||
 | 
			
		||||
            $amount += $this->convertToDefault($unpaid, $item->currency_code, $item->currency_rate);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user