diff --git a/app/Mail/Admin/EntityFailedSendObject.php b/app/Mail/Admin/EntityFailedSendObject.php index 1120115dd855..d1a9ea3cac8b 100644 --- a/app/Mail/Admin/EntityFailedSendObject.php +++ b/app/Mail/Admin/EntityFailedSendObject.php @@ -77,7 +77,6 @@ class EntityFailedSendObject private function setTemplate() { - // nlog($this->template); switch ($this->template) { case 'invoice': diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index 469830f8b532..da2c1030fbc1 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -104,7 +104,6 @@ class EntitySentObject private function setTemplate() { - // nlog($this->template); switch ($this->template) { case 'invoice': diff --git a/app/Models/Account.php b/app/Models/Account.php index 4e18792f8a62..e6a5701f558c 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -527,11 +527,11 @@ class Account extends BaseModel public function emailsSent() { - if (is_null(Cache::get($this->key))) { + if (is_null(Cache::get("email_quota".$this->key))) { return 0; } - return Cache::get($this->key); + return Cache::get("email_quota".$this->key); } public function emailQuotaExceeded() :bool diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index c6234bf12728..e33453092eeb 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -45,6 +45,9 @@ use Illuminate\Support\Str; * @method static \Illuminate\Database\Eloquent\Builder|BaseModel count() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel create() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel insert() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereHas() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel withTrashed() + * * @method \App\Models\Company company() * @method int companyId() * @method Builder|static exclude($columns) diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index c51e9bddf662..2de9ed0b9b20 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -46,8 +46,8 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $email * @property string|null $email_verified_at * @property string|null $confirmation_code - * @property int $is_primary - * @property int $confirmed + * @property bool $is_primary + * @property bool $confirmed * @property int|null $last_login * @property int|null $failed_logins * @property string|null $oauth_user_id @@ -59,8 +59,8 @@ use Laracasts\Presenter\PresentableTrait; * @property string|null $avatar_size * @property string $password * @property string|null $token - * @property int $is_locked - * @property int $send_email + * @property bool $is_locked + * @property bool $send_email * @property string|null $contact_key * @property string|null $remember_token * @property int|null $created_at diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 89e4462de56c..ae0d4b2333d2 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -103,9 +103,9 @@ use Laracasts\Presenter\PresentableTrait; * @property-read mixed $valid_until * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read int|null $history_count - * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read int|null $invitations_count * @property-read \App\Models\Invoice|null $invoice + * @property-read \App\Models\QuoteInvitation|null $invitations * @property-read \App\Models\Project|null $project * @property-read \App\Models\User $user * @property-read \App\Models\Vendor|null $vendor @@ -185,50 +185,6 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read \Illuminate\Database\Eloquent\Collection $activities - * @property-read \Illuminate\Database\Eloquent\Collection $documents - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @mixin \Eloquent */ class Quote extends BaseModel diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index ab9d447b82bc..c55fadf26c47 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -319,73 +319,6 @@ class Design extends BaseDesign return $elements; } - //@deprecated - // public function entityDetailsx(): array - // { - // if ($this->type === 'statement') { - // $s_date = $this->translateDate($this->options['start_date'], $this->client->date_format(), $this->client->locale()) . " - " . $this->translateDate($this->options['end_date'], $this->client->date_format(), $this->client->locale()); - - // return [ - // ['element' => 'p', 'content' => "

".ctrans('texts.statement')."

", 'properties' => ['data-ref' => 'statement-label']], - // ['element' => 'p', 'content' => ctrans('texts.statement_date'), 'properties' => ['data-ref' => 'statement-label'],'elements' => - // ['element' => 'span', 'content' => "{$s_date} "] - // ], - // ['element' => 'p', 'content' => '$balance_due_label', 'properties' => ['data-ref' => 'statement-label'],'elements' => - // ['element' => 'span', 'content' => Number::formatMoney($this->invoices->sum('balance'), $this->client)] - // ], - // ]; - // } - - // $variables = $this->context['pdf_variables']['invoice_details']; - - // if ($this->entity instanceof Quote) { - // $variables = $this->context['pdf_variables']['quote_details']; - - // if ($this->entity->partial > 0) { - // $variables[] = '$quote.balance_due'; - // } - // } - - // if ($this->entity instanceof Credit) { - // $variables = $this->context['pdf_variables']['credit_details']; - // } - - // if ($this->vendor) { - // $variables = $this->context['pdf_variables']['purchase_order_details']; - // } - - // $elements = []; - - // // We don't want to show account balance or invoice total on PDF.. or any amount with currency. - // if ($this->type == self::DELIVERY_NOTE) { - // $variables = array_filter($variables, function ($m) { - // return !in_array($m, ['$invoice.balance_due', '$invoice.total']); - // }); - // } - - // foreach ($variables as $variable) { - // $_variable = explode('.', $variable)[1]; - // $_customs = ['custom1', 'custom2', 'custom3', 'custom4']; - - // /* 2/7/2022 don't show custom values if they are empty */ - // $var = str_replace("custom", "custom_value", $_variable); - - // if (in_array($_variable, $_customs) && !empty($this->entity->{$var})) { - // $elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($_variable)};"],'elements' => [ - // ['element' => 'div', 'content' => $variable . '_label', 'properties' => ['class' => 'entity-details-cell', 'data-ref' => 'entity_details-' . substr($variable, 1) . '_label']], - // ['element' => 'div', 'content' => $variable, 'properties' => ['class' => 'entity-details-cell', 'data-ref' => 'entity_details-' . substr($variable, 1)]], - // ]]; - // } else { - // $elements[] = ['element' => 'div', 'properties' => ['style' => "display: table-row; visibility: {$this->entityVariableCheck($variable)};"], 'elements' => [ - // ['element' => 'div', 'content' => $variable . '_label', 'properties' => ['class' => 'entity-details-cell','data-ref' => 'entity_details-' . substr($variable, 1) . '_label']], - // ['element' => 'div', 'content' => $variable, 'properties' => ['class' => 'entity-details-cell','data-ref' => 'entity_details-' . substr($variable, 1)]], - // ]]; - // } - // } - - // return $elements; - // } - public function entityDetails(): array { if ($this->type === 'statement') { @@ -911,7 +844,6 @@ class Design extends BaseDesign $variables = $this->context['pdf_variables']['total_columns']; - $elements = [ ['element' => 'div', 'properties' => ['style' => 'display: flex; flex-direction: column;'], 'elements' => [ ['element' => 'p', 'content' => strtr(str_replace(["labels","values"], ["",""], $_variables['values']['$entity.public_notes']), $_variables), 'properties' => ['data-ref' => 'total_table-public_notes', 'style' => 'text-align: left;']], diff --git a/app/Services/Quote/SendEmail.php b/app/Services/Quote/SendEmail.php index 2530fe598bbf..445d321ff97c 100644 --- a/app/Services/Quote/SendEmail.php +++ b/app/Services/Quote/SendEmail.php @@ -37,8 +37,6 @@ class SendEmail */ public function run() { - nlog($this->reminder_template); - nlog("is there a template"); if (! $this->reminder_template) { $this->reminder_template = $this->quote->calculateTemplate('quote'); diff --git a/app/Services/Report/ProfitLoss.php b/app/Services/Report/ProfitLoss.php index 45e53a20d8f0..4bdbac75bbfa 100644 --- a/app/Services/Report/ProfitLoss.php +++ b/app/Services/Report/ProfitLoss.php @@ -11,18 +11,19 @@ namespace App\Services\Report; -use App\Libraries\Currency\Conversion\CurrencyApi; -use App\Libraries\MultiDB; -use App\Models\Company; -use App\Models\Currency; -use App\Models\Expense; -use App\Models\Payment; use App\Utils\Ninja; use App\Utils\Number; +use League\Csv\Writer; +use App\Models\Company; +use App\Models\Expense; +use App\Models\Invoice; +use App\Models\Payment; +use App\Models\Currency; +use App\Libraries\MultiDB; +use Illuminate\Support\Str; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\App; -use Illuminate\Support\Str; -use League\Csv\Writer; +use App\Libraries\Currency\Conversion\CurrencyApi; class ProfitLoss { @@ -279,8 +280,6 @@ class ProfitLoss ->with(['company', 'client']) ->cursor() ->each(function ($payment) { - $company = $payment->company; - $client = $payment->client; $map = new \stdClass; $amount_payment_paid = 0; @@ -293,8 +292,8 @@ class ProfitLoss $tax_amount_credit_converted = $tax_amount_credit_converted = 0; foreach ($payment->paymentables as $pivot) { - if ($pivot->paymentable instanceof \App\Models\Invoice) { - $invoice = $pivot->paymentable; + if ($pivot->paymentable_type == 'invoices') { + $invoice = Invoice::withTrashed()->find($pivot->paymentable_id); $amount_payment_paid += $pivot->amount - $pivot->refunded; $amount_payment_paid_converted += $amount_payment_paid / ($payment->exchange_rate ?: 1); @@ -303,7 +302,7 @@ class ProfitLoss $tax_amount_converted += (($amount_payment_paid / $invoice->amount) * $invoice->total_taxes) / $payment->exchange_rate; } - if ($pivot->paymentable instanceof \App\Models\Credit) { + if ($pivot->paymentable_type == 'credits') { $amount_credit_paid += $pivot->amount - $pivot->refunded; $amount_credit_paid_converted += $amount_payment_paid / ($payment->exchange_rate ?: 1); diff --git a/app/Utils/Ninja.php b/app/Utils/Ninja.php index c09039ccd91a..16f357d4df0b 100644 --- a/app/Utils/Ninja.php +++ b/app/Utils/Ninja.php @@ -156,15 +156,17 @@ class Ninja public static function triggerForwarding(string $company_key, string $email) { try { - Http::withHeaders([ + $x = Http::withHeaders([ 'X-API-HOSTED-SECRET' => config('ninja.ninja_hosted_secret'), ])->post(config('ninja.license_url').'/api/v1/enable_forwarding', [ 'account_key' => $company_key, 'email' => $email, ]); + + nlog($x->body()); } catch (\Exception $e) { - nlog("attempt forwarding for{$email} - {$company_key}"); + nlog("Attempt forwarding for {$email} - {$company_key} Failed"); } } diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 2c6fdf0e7ea7..b29466641441 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -194,8 +194,8 @@ class Number /** * Formats a given value based on the clients currency AND country. * - * @param floatval $value The number to be formatted - * @param $entity + * @param float $value The number to be formatted + * @param mixed $entity * @return string The formatted value */ public static function formatMoneyNoRounding($value, $entity) :string diff --git a/app/Utils/PaymentHtmlEngine.php b/app/Utils/PaymentHtmlEngine.php index 399446aa68c9..7cba02291c88 100644 --- a/app/Utils/PaymentHtmlEngine.php +++ b/app/Utils/PaymentHtmlEngine.php @@ -278,9 +278,9 @@ class PaymentHtmlEngine /** * generateLabelsAndValues * - * @return void + * @return array */ - public function generateLabelsAndValues() + public function generateLabelsAndValues(): array { $data = []; diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index ccaff2acc951..ef90d1dc3cb7 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -288,11 +288,6 @@ class SystemHealth return $result; } - private static function checkDbConnection() - { - return DB::connection()->getPdo(); - } - public static function testMailServer($request = null) { if ($request->driver == 'log') { diff --git a/tests/Feature/Account/AccountEmailQuotaTest.php b/tests/Feature/Account/AccountEmailQuotaTest.php index fa70035d97bd..6d242e52a38e 100644 --- a/tests/Feature/Account/AccountEmailQuotaTest.php +++ b/tests/Feature/Account/AccountEmailQuotaTest.php @@ -126,7 +126,7 @@ class AccountEmailQuotaTest extends TestCase $account->save(); - Cache::put($account->key, 3000); + Cache::put("email_quota".$account->key, 3000); $count = $account->emailsSent();