mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improve queries
This commit is contained in:
parent
094d43be4f
commit
953e2e3e48
@ -194,10 +194,14 @@ class RequiredClientInfo extends Component
|
|||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($this->db);
|
MultiDB::setDb($this->db);
|
||||||
$contact = ClientContact::withTrashed()->find($this->contact_id);
|
$contact = ClientContact::withTrashed()->with(['client' => function ($query) {
|
||||||
$company = $contact->company;
|
$query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client'
|
||||||
$this->company_gateway = CompanyGateway::withTrashed()->find($this->company_gateway_id);
|
}])->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->client_name = $contact->client->name;
|
||||||
$this->contact_first_name = $contact->first_name;
|
$this->contact_first_name = $contact->first_name;
|
||||||
@ -268,7 +272,10 @@ class RequiredClientInfo extends Component
|
|||||||
{
|
{
|
||||||
|
|
||||||
MultiDB::setDb($this->db);
|
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 = [];
|
$rules = [];
|
||||||
|
|
||||||
@ -310,7 +317,11 @@ class RequiredClientInfo extends Component
|
|||||||
|
|
||||||
|
|
||||||
MultiDB::setDb($this->db);
|
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) {
|
foreach ($data as $field => $value) {
|
||||||
|
@ -41,8 +41,8 @@ class PaymentMethod
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$this->getGateways()
|
$this->getGateways()
|
||||||
->getMethods()
|
->getMethods();
|
||||||
->buildUrls();
|
// ->buildUrls();
|
||||||
|
|
||||||
return $this->getPaymentUrls();
|
return $this->getPaymentUrls();
|
||||||
}
|
}
|
||||||
@ -154,6 +154,19 @@ class PaymentMethod
|
|||||||
//** Plucks the remaining keys into its own collection
|
//** Plucks the remaining keys into its own collection
|
||||||
$this->payment_methods = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique());
|
$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*/
|
/* Loop through custom gateways if any exist and append them to the methods collection*/
|
||||||
$this->getCustomGateways();
|
$this->getCustomGateways();
|
||||||
|
|
||||||
@ -162,10 +175,14 @@ class PaymentMethod
|
|||||||
foreach ($gateway->driver($this->client)->gatewayTypes() as $type) {
|
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 (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)) {
|
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 {
|
} 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;
|
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()
|
private function buildUrls()
|
||||||
{
|
{
|
||||||
foreach ($this->payment_methods as $key => $child_array) {
|
foreach ($this->payment_methods as $key => $child_array) {
|
||||||
|
@ -175,6 +175,11 @@ class InvoiceService
|
|||||||
|
|
||||||
public function markSent($fire_event = false)
|
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->invoice = (new MarkSent($this->invoice->client, $this->invoice))->run($fire_event);
|
||||||
|
|
||||||
$this->setExchangeRate();
|
$this->setExchangeRate();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user