Improve queries

This commit is contained in:
David Bomba 2024-06-15 16:51:34 +10:00
parent 094d43be4f
commit 953e2e3e48
3 changed files with 66 additions and 9 deletions

View File

@ -194,10 +194,14 @@ class RequiredClientInfo extends Component
public function mount()
{
MultiDB::setDb($this->db);
$contact = ClientContact::withTrashed()->find($this->contact_id);
$company = $contact->company;
$this->company_gateway = CompanyGateway::withTrashed()->find($this->company_gateway_id);
$contact = ClientContact::withTrashed()->with(['client' => function ($query) {
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
}])->find($this->contact_id);
$this->company_gateway = CompanyGateway::withTrashed()->with('company')->find($this->company_gateway_id);
$company = $this->company_gateway->company;
$this->client_name = $contact->client->name;
$this->contact_first_name = $contact->first_name;
@ -268,7 +272,10 @@ class RequiredClientInfo extends Component
{
MultiDB::setDb($this->db);
$contact = ClientContact::withTrashed()->find($this->contact_id);
$contact = ClientContact::withTrashed()->with(['client' => function ($query) {
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
}])->find($this->contact_id);
$rules = [];
@ -310,7 +317,11 @@ class RequiredClientInfo extends Component
MultiDB::setDb($this->db);
$_contact = ClientContact::withTrashed()->find($this->contact_id);
// $_contact = ClientContact::withTrashed()->with('client')->find($this->contact_id);
$_contact = ClientContact::withTrashed()->with(['client' => function ($query) {
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
}])->find($this->contact_id);
foreach ($data as $field => $value) {

View File

@ -41,8 +41,8 @@ class PaymentMethod
public function run()
{
$this->getGateways()
->getMethods()
->buildUrls();
->getMethods();
// ->buildUrls();
return $this->getPaymentUrls();
}
@ -154,6 +154,19 @@ class PaymentMethod
//** Plucks the remaining keys into its own collection
$this->payment_methods = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique());
//@15-06-2024
foreach($this->payment_methods as $key => $type)
{
foreach ($type as $gateway_id => $gateway_type_id)
{
$gate = $this->gateways->where('id',$gateway_id)->first();
$this->buildUrl($gate, $gateway_type_id);
}
}
//@15-06-2024
$this->payment_methods =[];
/* Loop through custom gateways if any exist and append them to the methods collection*/
$this->getCustomGateways();
@ -162,10 +175,14 @@ class PaymentMethod
foreach ($gateway->driver($this->client)->gatewayTypes() as $type) {
if (isset($gateway->fees_and_limits) && is_object($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, GatewayType::CREDIT_CARD)) {
if ($this->validGatewayForAmount($gateway->fees_and_limits->{GatewayType::CREDIT_CARD}, $this->amount)) {
$this->payment_methods[] = [$gateway->id => $type];
// $this->payment_methods[] = [$gateway->id => $type];
//@15-06-2024
$this->buildUrl($gateway, $type);
}
} else {
$this->payment_methods[] = [$gateway->id => null];
// $this->payment_methods[] = [$gateway->id => null];
//@15-06-2024
$this->buildUrl($gateway, null);
}
}
}
@ -173,6 +190,30 @@ class PaymentMethod
return $this;
}
//@15-06-2024
private function buildUrl(CompanyGateway $gateway, ?int $type = null)
{
$fee_label = $gateway->calcGatewayFeeLabel($this->amount, $this->client, $type);
if (! $type || (GatewayType::CUSTOM == $type)) {
$this->payment_urls[] = [
'label' => $gateway->getConfigField('name').$fee_label,
'company_gateway_id' => $gateway->id,
'gateway_type_id' => GatewayType::CREDIT_CARD,
];
} else {
$this->payment_urls[] = [
'label' => $gateway->getTypeAlias($type).$fee_label,
'company_gateway_id' => $gateway->id,
'gateway_type_id' => $type,
];
}
}
//@deprecated as buildUrl() supercedes
private function buildUrls()
{
foreach ($this->payment_methods as $key => $child_array) {

View File

@ -175,6 +175,11 @@ class InvoiceService
public function markSent($fire_event = false)
{
$this->invoice->loadMissing(['client' => function ($q) {
$q->without('documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
}]);
$this->invoice = (new MarkSent($this->invoice->client, $this->invoice))->run($fire_event);
$this->setExchangeRate();