Thanks for your reply. I am working with a copy of the live database locally, so the data should be the same. As for the code, here are the 3 queries that I mentioned that are being run on the first load:
$this->sales = DB::table('contacts')
->leftJoin('appointments', 'contacts.id', 'appointments.contact_id')
->leftJoin('apps', 'contacts.id', 'apps.contact_id')
->leftJoin('bars', 'contacts.id', 'bars.contact_id')
->leftJoin('results', 'contacts.id', 'results.contact_id')
->leftJoin('key_indicators', 'contacts.id', 'key_indicators.contact_id')
->where('contacts.company_id', auth()->user()->company_id)
->where(function ($query) {
$query->where('appointments.date', '>=', $this->startDate)
->orWhere('apps.date', '>=', $this->startDate)
->orWhere('bars.date', '>=', $this->startDate);})
->where(function ($query) {
$query->where('appointments.date', '<=', $this->endDate)
->orWhere('apps.date', '<=', $this->endDate)
->orWhere('bars.date', '<=', $this->endDate);})
->where(function($query) {
$query->where('results.results', 'Sold: Net')
->orWhere('results.results', 'Sold: Pending')
->orWhere('results.results', 'Sold Gross: Holding Pattern')
->orWhere('results.results', 'Sold')
->orWhere('results.results', 'Sold: Rejected for Finance')
->orWhere('results.results', 'Sold: Cancelled');
})->select('contacts.id as id', 'contacts.primary_first as first', 'contacts.primary_last as last', 'contacts.lead_source_detail as source', 'appointments.date as date', 'appointments.rep as rep', 'appointments.rep2 as rep2',
'results.gross_sale_amount as gross_sale_amount', 'results.net_sale_amount as net_sale_amount', 'results.results as result', 'key_indicators.exp_manu as exp_manu', 'key_indicators.vol_manu as vol_manu',
'key_indicators.manu_payments_complete as manu_payments_complete', 'key_indicators.dont_attribute_manu as dont_attribute_manu',
'key_indicators.exp_install as exp_install', 'key_indicators.vol_install as vol_install', 'key_indicators.install_payments_complete as install_payments_complete', 'key_indicators.dont_attribute_install as dont_attribute_install',
'key_indicators.rep_commission as commission1', 'key_indicators.rep2_commission as commission2', 'key_indicators.rep3_commission as commission3', 'key_indicators.rep4_commission as commission4')
->orderBy('appointments.date')
->get();
// Get the payments made
$this->payments = DB::table('p_l_payments')->where('company_id', auth()->user()->company_id)
->whereBetween('date', [$this->startDate, $this->endDate])
->orderBy('date')
->get();
// Get the leads purchased
$this->purchasedLeads = InternetLead::where('company_id', auth()->user()->company_id)
->whereBetween('date', [$this->startDate, $this->endDate])
->orderBy('date')
->get();
And here is an example of how I am using them in my functions.
public function getGrossSales()
{
$this->showData['grossSales'] = $this->sales->filter(function (array $value, int $key) {
return $value['result'] == 'Sold: Net' ||
$value['result'] == 'Sold: Pending' ||
$value['result'] == 'Sold Gross: Holding Pattern' ||
$value['result'] == 'Sold' ||
$value['result'] == 'Sold: Rejected for Finance' ||
$value['result'] == 'Sold: Cancelled';
});
}
As mentioned previously, even if I have a function that does not use one of these public variables, it will still take a really long time to load after clicking the button to call the function.