From 7ff3397616befbec0e11e6a7aca75f941a5205da Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 13 May 2022 07:52:02 +1000 Subject: [PATCH] limit system logs in client response --- app/Models/Client.php | 2 +- app/Services/Report/ProfitLoss.php | 65 +++++++++++++++++++++++++++--- routes/api.php | 2 +- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index fd28df5e9c5c..199cf9fbd472 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -253,7 +253,7 @@ class Client extends BaseModel implements HasLocalePreference public function system_logs() { - return $this->hasMany(SystemLog::class)->orderBy('id', 'desc'); + return $this->hasMany(SystemLog::class)->take(50)->orderBy('id', 'desc'); } public function timezone() diff --git a/app/Services/Report/ProfitLoss.php b/app/Services/Report/ProfitLoss.php index 7fda7c236247..a97ff59269df 100644 --- a/app/Services/Report/ProfitLoss.php +++ b/app/Services/Report/ProfitLoss.php @@ -131,6 +131,24 @@ class ProfitLoss } + private function filterInvoicePaymentIncome() + { + + $invoices = $this->invoicePaymentIncome(); + + $this->income = 0; + $this->income_taxes = 0; + $this->income_map = $invoices; + + foreach($invoices as $invoice){ + $this->income += $invoice->net_amount; + $this->income_taxes += $invoice->net_converted_taxes; + } + + return $this; + + } + private function filterPaymentIncome() { $payments = $this->paymentIncome(); @@ -186,15 +204,50 @@ class ProfitLoss GROUP BY currency_id "), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date] ); - - // - // $total = array_reduce( commissionsArray, function ($sum, $entry) { - // $sum += $entry->commission; - // return $sum; - // }, 0); } + /** + => [ + {#2047 + +"amount": "110.000000", + +"total_taxes": "10.0000000000000000", + +"net_converted_amount": "110.0000000000", + +"net_converted_taxes": "10.00000000000000000000", + +"currency_id": ""1"", + }, + {#2444 + +"amount": "50.000000", + +"total_taxes": "4.5454545454545455", + +"net_converted_amount": "61.1682150381", + +"net_converted_taxes": "5.56074682164393914741", + +"currency_id": ""2"", + }, + ] + */ + + private function invoicePaymentIncome() + { + return \DB::select( \DB::raw(" + SELECT + sum(invoices.amount - invoices.balance) as amount, + sum(invoices.total_taxes) * ((sum(invoices.amount - invoices.balance)/invoices.amount)) as total_taxes, + (sum(invoices.amount - invoices.balance) / IFNULL(invoices.exchange_rate, 1)) AS net_converted_amount, + (sum(invoices.total_taxes) * ((sum(invoices.amount - invoices.balance)/invoices.amount)) / IFNULL(invoices.exchange_rate, 1)) AS net_converted_taxes, + IFNULL(JSON_EXTRACT( settings, '$.currency_id' ), :company_currency) AS currency_id + FROM clients + JOIN invoices + on invoices.client_id = clients.id + WHERE invoices.status_id IN (3,4) + AND invoices.company_id = :company_id + AND invoices.amount > 0 + AND clients.is_deleted = 0 + AND invoices.is_deleted = 0 + AND (invoices.date BETWEEN :start_date AND :end_date) + GROUP BY currency_id + "), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $this->start_date, 'end_date' => $this->end_date] ); + } + /** +"payments": "12260.870000", +"payments_converted": "12260.870000000000", diff --git a/routes/api.php b/routes/api.php index e7992191791f..0c5b72d88754 100644 --- a/routes/api.php +++ b/routes/api.php @@ -152,7 +152,7 @@ Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale Route::post('recurring_quotes/bulk', 'RecurringQuoteController@bulk')->name('recurring_quotes.bulk'); Route::put('recurring_quotes/{recurring_quote}/upload', 'RecurringQuoteController@upload'); - Route::post('refresh', 'Auth\LoginController@refresh')->middleware('throttle:20,1'); + Route::post('refresh', 'Auth\LoginController@refresh')->middleware('throttle:30,1'); Route::post('reports/clients', 'Reports\ClientReportController'); Route::post('reports/contacts', 'Reports\ClientContactReportController');