diff --git a/app/Models/Credit.php b/app/Models/Credit.php index f1aac09e2aff..77e72dfedbeb 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -288,11 +288,21 @@ class Credit extends BaseModel return Storage::disk(config('filesystems.default'))->{$type}($file_path); } + try { + $file_exists = Storage::disk(config('filesystems.default'))->exists($file_path); + } catch (\Exception $e) { + nlog($e->getMessage()); + } + + if ($file_exists) { + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } + + if (Storage::disk('public')->exists($file_path)) { return Storage::disk('public')->{$type}($file_path); } - $file_path = (new CreateEntityPdf($invitation))->handle(); return Storage::disk('public')->{$type}($file_path); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 6740f6c9ecd2..2a5cf63a0688 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -451,6 +451,17 @@ class Invoice extends BaseModel return Storage::disk(config('filesystems.default'))->{$type}($file_path); } + try { + $file_exists = Storage::disk(config('filesystems.default'))->exists($file_path); + } catch (\Exception $e) { + nlog($e->getMessage()); + } + + if ($file_exists) { + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } + + try { $file_exists = Storage::disk('public')->exists($file_path); } catch (\Exception $e) { diff --git a/app/Models/Quote.php b/app/Models/Quote.php index c512c288aa19..ddbad4a9687a 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -247,6 +247,16 @@ class Quote extends BaseModel return Storage::disk(config('filesystems.default'))->{$type}($file_path); } + try { + $file_exists = Storage::disk(config('filesystems.default'))->exists($file_path); + } catch (\Exception $e) { + nlog($e->getMessage()); + } + + if ($file_exists) { + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } + if (Storage::disk('public')->exists($file_path)) { return Storage::disk('public')->{$type}($file_path); } diff --git a/app/Models/SystemLog.php b/app/Models/SystemLog.php index 16d0eebac678..6d84e4b349f4 100644 --- a/app/Models/SystemLog.php +++ b/app/Models/SystemLog.php @@ -41,6 +41,8 @@ class SystemLog extends Model const CATEGORY_SECURITY = 5; + const CATEGORY_LOG = 6; + /* Event IDs*/ const EVENT_PAYMENT_RECONCILIATION_FAILURE = 10; @@ -127,6 +129,8 @@ class SystemLog extends Model const TYPE_LOGIN_FAILURE = 801; + const TYPE_GENERIC = 900; + protected $fillable = [ 'client_id', 'company_id', diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index 7755719457d5..57e8de922f05 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -16,10 +16,12 @@ use App\Factory\CreditFactory; use App\Factory\InvoiceItemFactory; use App\Jobs\Ninja\TransactionLog; use App\Jobs\Payment\EmailRefundPayment; +use App\Jobs\Util\SystemLogger; use App\Models\Activity; use App\Models\Credit; use App\Models\Invoice; use App\Models\Payment; +use App\Models\SystemLog; use App\Models\TransactionEvent; use App\Repositories\ActivityRepository; use App\Utils\Ninja; @@ -77,6 +79,8 @@ class RefundPayment TransactionLog::dispatch(TransactionEvent::PAYMENT_REFUND, $transaction, $this->payment->company->db); + SystemLogger::dispatch(['user' => auth()->user() ? auth()->user()->email : '', 'paymentables' => $this->payment->paymentables->makeHidden(['id','payment_id', 'paymentable_id','paymentable_type', 'deleted_at'])->toArray(), 'request' => request() ? request()->all() : []], SystemLog::CATEGORY_LOG, SystemLog::EVENT_USER, SystemLog::TYPE_GENERIC, $this->payment->client, $this->payment->company); + return $this->payment; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 47da35455d9f..4806a89d1d35 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -150,7 +150,7 @@ class HtmlEngine $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$invoice'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$number_short'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number_short')]; - $data['$entity.terms'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->terms), $this->client) ?: '', 'label' => ctrans('texts.invoice_terms')]; + $data['$entity.terms'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->terms ?: ''), $this->client) ?: '', 'label' => ctrans('texts.invoice_terms')]; $data['$terms'] = &$data['$entity.terms']; $data['$view_link'] = ['value' => ''.ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; $data['$viewLink'] = &$data['$view_link']; @@ -185,7 +185,7 @@ class HtmlEngine $data['$entity'] = ['value' => '', 'label' => ctrans('texts.quote')]; $data['$number'] = ['value' => $this->entity->number ?: '', 'label' => ctrans('texts.quote_number')]; $data['$number_short'] = ['value' => $this->entity->number ?: '', 'label' => ctrans('texts.quote_number_short')]; - $data['$entity.terms'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->terms), $this->client) ?: '', 'label' => ctrans('texts.quote_terms')]; + $data['$entity.terms'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->terms ?: ''), $this->client) ?: '', 'label' => ctrans('texts.quote_terms')]; $data['$terms'] = &$data['$entity.terms']; $data['$view_link'] = ['value' => ''.ctrans('texts.view_quote').'', 'label' => ctrans('texts.view_quote')]; $data['$viewLink'] = &$data['$view_link']; @@ -210,7 +210,7 @@ class HtmlEngine $data['$entity'] = ['value' => '', 'label' => ctrans('texts.credit')]; $data['$number'] = ['value' => $this->entity->number ?: '', 'label' => ctrans('texts.credit_number')]; $data['$number_short'] = ['value' => $this->entity->number ?: '', 'label' => ctrans('texts.credit_number_short')]; - $data['$entity.terms'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->terms), $this->client) ?: '', 'label' => ctrans('texts.credit_terms')]; + $data['$entity.terms'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->terms ?: ''), $this->client) ?: '', 'label' => ctrans('texts.credit_terms')]; $data['$terms'] = &$data['$entity.terms']; $data['$view_link'] = ['value' => ''.ctrans('texts.view_credit').'', 'label' => ctrans('texts.view_credit')]; $data['$viewButton'] = &$data['$view_link']; @@ -303,7 +303,7 @@ class HtmlEngine $data['$invoice.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')]; $data['$invoice.custom3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice3', $this->entity->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice3')]; $data['$invoice.custom4'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice4', $this->entity->custom_value4, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice4')]; - $data['$invoice.public_notes'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->public_notes), $this->client) ?: '', 'label' => ctrans('texts.public_notes')]; + $data['$invoice.public_notes'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->public_notes ?: ''), $this->client) ?: '', 'label' => ctrans('texts.public_notes')]; $data['$entity.public_notes'] = &$data['$invoice.public_notes']; $data['$public_notes'] = &$data['$invoice.public_notes']; $data['$notes'] = &$data['$public_notes']; @@ -535,7 +535,7 @@ class HtmlEngine $data['$description'] = ['value' => '', 'label' => ctrans('texts.description')]; //$data['$entity_footer'] = ['value' => $this->client->getSetting("{$this->entity_string}_footer"), 'label' => '']; - $data['$entity_footer'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->footer), $this->client), 'label' => '']; + $data['$entity_footer'] = ['value' => Helpers::processReservedKeywords(\nl2br($this->entity->footer ?: ''), $this->client), 'label' => '']; $data['$footer'] = &$data['$entity_footer']; $data['$page_size'] = ['value' => $this->settings->page_size, 'label' => '']; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index ab020712c33f..e9e009a7b989 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -300,10 +300,10 @@ trait MakesInvoiceValues $data[$key][$table_type.'.notes'] = Helpers::processReservedKeywords($item->notes, $entity); $data[$key][$table_type.'.description'] = Helpers::processReservedKeywords($item->notes, $entity); - $data[$key][$table_type.".{$_table_type}1"] = strlen($item->custom_value1) > 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}1", $item->custom_value1, $entity) : ''; - $data[$key][$table_type.".{$_table_type}2"] = strlen($item->custom_value2) > 2 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}2", $item->custom_value2, $entity) : ''; - $data[$key][$table_type.".{$_table_type}3"] = strlen($item->custom_value3) > 3 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}3", $item->custom_value3, $entity) : ''; - $data[$key][$table_type.".{$_table_type}4"] = strlen($item->custom_value4) > 4 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}4", $item->custom_value4, $entity) : ''; + $data[$key][$table_type.".{$_table_type}1"] = strlen($item->custom_value1) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}1", $item->custom_value1, $entity) : ''; + $data[$key][$table_type.".{$_table_type}2"] = strlen($item->custom_value2) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}2", $item->custom_value2, $entity) : ''; + $data[$key][$table_type.".{$_table_type}3"] = strlen($item->custom_value3) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}3", $item->custom_value3, $entity) : ''; + $data[$key][$table_type.".{$_table_type}4"] = strlen($item->custom_value4) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}4", $item->custom_value4, $entity) : ''; if ($item->quantity > 0 || $item->cost > 0) { $data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $entity_currency);