diff --git a/VERSION.txt b/VERSION.txt index f8f87624c1..80ba0b3252 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.77 \ No newline at end of file +5.3.78 \ No newline at end of file diff --git a/app/Console/Commands/HostedMigrations.php b/app/Console/Commands/HostedMigrations.php index a672a9e1ed..27d6fcd91e 100644 --- a/app/Console/Commands/HostedMigrations.php +++ b/app/Console/Commands/HostedMigrations.php @@ -85,8 +85,6 @@ class HostedMigrations extends Command } $path = public_path('storage/migrations/import'); - - nlog(public_path('storage/migrations/import')); $directory = new DirectoryIterator($path); diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index c09058cda8..f80e21e6e7 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -79,8 +79,6 @@ class ImportMigrations extends Command $this->buildCache(); $path = $this->option('path') ?? public_path('storage/migrations/import'); - - nlog(public_path('storage/migrations/import')); $directory = new DirectoryIterator($path); diff --git a/app/DataMapper/BaseSettings.php b/app/DataMapper/BaseSettings.php index b35e31ccc1..3e0bb50124 100644 --- a/app/DataMapper/BaseSettings.php +++ b/app/DataMapper/BaseSettings.php @@ -46,7 +46,6 @@ class BaseSettings return is_null($value) ? '' : (string) $value; case 'bool': case 'boolean': - nlog($value); return boolval($value); case 'object': return json_decode($value); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3e81d97c8a..0e0b70570a 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -124,7 +124,7 @@ class Handler extends ExceptionHandler } }); - if ($this->validException($exception) && auth()->guard('contact')->user()->company->account->report_errors) { + if ($this->validException($exception)) { app('sentry')->captureException($exception); } } diff --git a/app/Helpers/Invoice/ProRata.php b/app/Helpers/Invoice/ProRata.php index e3291b25c2..c768af3009 100644 --- a/app/Helpers/Invoice/ProRata.php +++ b/app/Helpers/Invoice/ProRata.php @@ -54,10 +54,7 @@ class ProRata { $days = $from_date->copy()->diffInDays($to_date); $days_in_frequency = $this->getDaysInFrequency($frequency); -nlog($from_date->format('Y-m-d')); -nlog($days); -nlog($days_in_frequency); -nlog($amount); + return round( (($days/$days_in_frequency) * $amount),2); } diff --git a/app/Http/Controllers/RecurringExpenseController.php b/app/Http/Controllers/RecurringExpenseController.php index a3bbf630f2..21a6be0614 100644 --- a/app/Http/Controllers/RecurringExpenseController.php +++ b/app/Http/Controllers/RecurringExpenseController.php @@ -276,7 +276,8 @@ class RecurringExpenseController extends BaseController } $recurring_expense = $this->recurring_expense_repo->save($request->all(), $recurring_expense); - + $recurring_expense->service()->triggeredActions($request)->save(); + $this->uploadLogo($request->file('company_logo'), $recurring_expense->company, $recurring_expense); event(new RecurringExpenseWasUpdated($recurring_expense, $recurring_expense->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); @@ -372,6 +373,7 @@ class RecurringExpenseController extends BaseController public function store(StoreRecurringExpenseRequest $request) { $recurring_expense = $this->recurring_expense_repo->save($request->all(), RecurringExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id)); + $recurring_expense->service()->triggeredActions($request)->save(); event(new RecurringExpenseWasCreated($recurring_expense, $recurring_expense->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index 16e217c0af..4788ae88da 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -388,7 +388,10 @@ class RecurringInvoiceController extends BaseController $recurring_invoice = $this->recurring_invoice_repo->save($request->all(), $recurring_invoice); - $recurring_invoice->service()->deletePdf()->save(); + $recurring_invoice->service() + ->triggeredActions($request) + ->deletePdf() + ->save(); event(new RecurringInvoiceWasUpdated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 4770fa148f..c4907663ec 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -280,6 +280,7 @@ class TaskController extends BaseController $old_task = json_decode(json_encode($task)); $task = $this->task_repo->save($request->all(), $task); + $task = $this->task_repo->triggeredActions($request, $task); if($task->status_order != $old_task->status_order) $this->task_repo->sortStatuses($old_task, $task); @@ -377,6 +378,7 @@ class TaskController extends BaseController public function store(StoreTaskRequest $request) { $task = $this->task_repo->save($request->all(), TaskFactory::create(auth()->user()->company()->id, auth()->user()->id)); + $task = $this->task_repo->triggeredActions($request, $task); event(new TaskWasCreated($task, $task->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index cf97db87d7..42c71fcd0b 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -238,7 +238,8 @@ class BillingPortalPurchase extends Component { $company = $this->subscription->company; $user = $this->subscription->user; - + $user->setCompany($company); + $client_repo = new ClientRepository(new ClientContactRepository()); $data = [ diff --git a/app/Http/ValidationRules/PaymentAmountsBalanceRule.php b/app/Http/ValidationRules/PaymentAmountsBalanceRule.php index e192edfbdf..ba0c2117a7 100644 --- a/app/Http/ValidationRules/PaymentAmountsBalanceRule.php +++ b/app/Http/ValidationRules/PaymentAmountsBalanceRule.php @@ -75,12 +75,6 @@ class PaymentAmountsBalanceRule implements Rule return true; } - // nlog(request()->input('invoices')); - // nlog($payment_amounts); - // nlog($invoice_amounts); - // nlog(request()->all()); - nlog($payment_amounts ." >= " . $invoice_amounts); - return round($payment_amounts,2) >= round($invoice_amounts,2); } diff --git a/app/Import/Transformer/BaseTransformer.php b/app/Import/Transformer/BaseTransformer.php index 2762ce8938..fc4840fb0f 100644 --- a/app/Import/Transformer/BaseTransformer.php +++ b/app/Import/Transformer/BaseTransformer.php @@ -74,7 +74,6 @@ class BaseTransformer ->where('id_number', $client_name); if ($client_id_search->count() >= 1) { - // nlog("found via id number => {$client_id_search->first()->id}"); return $client_id_search->first()->id; } @@ -83,7 +82,6 @@ class BaseTransformer ->where('name', $client_name); if ($client_name_search->count() >= 1) { - // nlog("found via name {$client_name_search->first()->id}"); return $client_name_search->first()->id; } } @@ -94,13 +92,10 @@ class BaseTransformer )->where('email', $client_email); if ($contacts->count() >= 1) { - // nlog("found via contact {$contacts->first()->client_id}"); return $contacts->first()->client_id; } } - // nlog("did not find client"); - return null; } diff --git a/app/Import/Transformers/BaseTransformer.php b/app/Import/Transformers/BaseTransformer.php index 97c21a2614..cf0b219927 100644 --- a/app/Import/Transformers/BaseTransformer.php +++ b/app/Import/Transformers/BaseTransformer.php @@ -66,14 +66,12 @@ class BaseTransformer if ( $client_id_search->count() >= 1 ) { return $client_id_search->first()->id; - nlog("found via id number"); } $client_name_search = $clients->where( 'name', $client_name ); if ( $client_name_search->count() >= 1 ) { return $client_name_search->first()->id; - nlog("found via name"); } if ( ! empty( $client_email ) ) { @@ -82,10 +80,8 @@ class BaseTransformer if ( $contacts->count() >= 1 ) { return $contacts->first()->client_id; - nlog("found via contact"); } } - // nlog("did not find client"); return null; } diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 5041107ecc..ae006fb828 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -483,8 +483,6 @@ class CompanyImport implements ShouldQueue $tmp_company->db = config('database.default'); $tmp_company->account_id = $this->account->id; -nlog($tmp_company); - if(Ninja::isHosted()) $tmp_company->subdomain = MultiDB::randomSubdomainGenerator(); else diff --git a/app/Mail/SupportMessageSent.php b/app/Mail/SupportMessageSent.php index afc8d0ea94..57fdfe67a7 100644 --- a/app/Mail/SupportMessageSent.php +++ b/app/Mail/SupportMessageSent.php @@ -46,7 +46,7 @@ class SupportMessageSent extends Mailable $log_file->seek(PHP_INT_MAX); $last_line = $log_file->key(); - $lines = new LimitIterator($log_file, $last_line - 100, $last_line); + $lines = new LimitIterator($log_file, max(0,$last_line - 100), $last_line); $log_lines = iterator_to_array($lines); } @@ -76,7 +76,7 @@ class SupportMessageSent extends Mailable ->replyTo($user->email, $user->present()->name()) ->subject($subject) ->view('email.support.message', [ - 'support_message' => $this->data['message'], + 'support_message' => nl2br($this->data['message']), 'system_info' => $system_info, 'laravel_log' => $log_lines, 'logo' => $company->present()->logo(), diff --git a/app/Models/Company.php b/app/Models/Company.php index 964a226f21..24e1ff98f2 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -99,6 +99,7 @@ class Company extends BaseModel 'report_include_drafts', 'client_registration_fields', 'convert_rate_to_client', + 'markdown_email_enabled', ]; protected $hidden = [ diff --git a/app/PaymentDrivers/Eway/CreditCard.php b/app/PaymentDrivers/Eway/CreditCard.php index bf7aab9657..98982d5346 100644 --- a/app/PaymentDrivers/Eway/CreditCard.php +++ b/app/PaymentDrivers/Eway/CreditCard.php @@ -255,9 +255,6 @@ class CreditCard $response = $this->eway_driver->init()->eway->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction); - nlog('eway'); - nlog($response); - $response_status = ErrorCode::getStatus($response->ResponseMessage); if(!$response_status['success']){ diff --git a/app/PaymentDrivers/PayFastPaymentDriver.php b/app/PaymentDrivers/PayFastPaymentDriver.php index 333ecb7ea4..74d3883e9d 100644 --- a/app/PaymentDrivers/PayFastPaymentDriver.php +++ b/app/PaymentDrivers/PayFastPaymentDriver.php @@ -151,8 +151,6 @@ class PayFastPaymentDriver extends BaseDriver if($this->company_gateway->getConfigField('passphrase')) $fields['passphrase'] = $this->company_gateway->getConfigField('passphrase'); - nlog(http_build_query($fields)); - return md5(http_build_query($fields)); } diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index cccf3d04d8..8aec2c5604 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -13,6 +13,7 @@ namespace App\Repositories; use App\Factory\ClientFactory; use App\Models\Client; +use App\Models\Company; use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\SavesDocuments; @@ -59,10 +60,10 @@ class ClientRepository extends BaseRepository } $client->fill($data); - - if(auth()->user() && !$client->country_id){ - $client->country_id = auth()->user()->company()->settings->country_id; + if(!$client->country_id){ + $company = Company::find($client->company_id); + $client->country_id = $company->settings->country_id; } diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 518a70a979..4834518daf 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -203,7 +203,7 @@ class TaskRepository extends BaseRepository $last = end($log); - if($last[1] !== 0){ + if(is_array($last) && $last[1] !== 0){ $new = [time(), 0]; $log = array_merge($log, [$new]); @@ -212,6 +212,7 @@ class TaskRepository extends BaseRepository } + return $task; } public function stop(Task $task) @@ -220,7 +221,7 @@ class TaskRepository extends BaseRepository $last = end($log); - if($last[1] === 0){ + if(is_array($last) && $last[1] === 0){ $last[1] = time(); @@ -231,5 +232,21 @@ class TaskRepository extends BaseRepository $task->save(); } + return $task; + + } + + public function triggeredActions($request, $task) + { + + if ($request->has('start') && $request->input('start') == 'true') { + $task = $this->start($task); + } + + if ($request->has('stop') && $request->input('stop') == 'true') { + $task = $this->stop($task); + } + + return $task; } } diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index 5b10db4fc3..8bc082d590 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -41,70 +41,15 @@ class HandleRestore extends AbstractService foreach ($this->invoice->payments as $payment) { //restore the payment record - // $payment->restore(); $this->invoice->restore(); -// //determine the paymentable amount before paymentable restoration -// $pre_restore_amount = $payment->paymentables() -// ->where('paymentable_type', '=', 'invoices') -// ->sum(\DB::raw('amount')); - -// nlog("first pre restore amount = {$pre_restore_amount}"); - -// $pre_restore_amount -= $payment->paymentables() -// ->where('paymentable_type', '=', 'invoices') -// ->sum(\DB::raw('refunded')); - -// nlog("second pre restore amount = {$pre_restore_amount}"); - - - //restore the paymentables - // $payment->paymentables() - // ->where('paymentable_type', '=', 'invoices') - // ->where('paymentable_id', $this->invoice->id) - // ->restore(); - - //determine the post restore paymentable amount (we need to increment the payment amount by the difference between pre and post) -// $payment_amount = $payment->paymentables() -// ->where('paymentable_type', '=', 'invoices') -// ->sum(\DB::raw('amount')); - -// nlog("first payment_amount = {$payment_amount}"); - -// $payment_amount -= $payment->paymentables() -// ->where('paymentable_type', '=', 'invoices') -// ->sum(\DB::raw('refunded')); - -// nlog("second payment_amount = {$payment_amount}"); - -// nlog($payment->amount . " == " . $payment_amount); - - // if ($payment->amount == $payment_amount) { - // $payment->is_deleted = false; - // $payment->save(); - - // $this->payment_total += $payment_amount; - // } else { - // $payment->is_deleted = false; - // $payment->amount += ($payment_amount - $pre_restore_amount); - // $payment->applied += ($payment_amount - $pre_restore_amount); - // $payment->save(); - - // $this->payment_total += ($payment_amount - $pre_restore_amount); - // } } //adjust ledger balance $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Restored invoice {$this->invoice->number}")->save(); - //adjust paid to dates - // $this->invoice->client->service()->updatePaidToDate($this->payment_total)->save(); - $this->invoice->client->service()->updateBalance($this->invoice->balance)->save(); - // you only need to touch the ledger ONCE per transaction. - // $this->invoice->ledger()->updatePaymentBalance($this->payment_total*-1, "Restored payment for invoice {$this->invoice->number}")->save(); - $this->windBackInvoiceNumber(); $this->invoice->is_deleted = false; diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 83cd30e3a8..9b29b072a9 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -96,10 +96,10 @@ class MarkPaid extends AbstractService $payment->ledger() ->updatePaymentBalance($payment->amount * -1); - $client = $this->invoice->client->fresh(); - $client->paid_to_date += $payment->amount; - $client->balance += $payment->amount * -1; - $client->save(); + $this->invoice->client->fresh(); + $this->invoice->client->paid_to_date += $payment->amount; + $this->invoice->client->balance += $payment->amount * -1; + $this->invoice->client->push(); $this->invoice = $this->invoice ->service() diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 5c7c532006..292521ea5a 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -47,12 +47,6 @@ class MarkSent extends AbstractService ->updateBalance($adjustment, true) ->save(); - /*Adjust client balance*/ - $this->client - ->service() - ->updateBalance($adjustment) - ->save(); - /*Update ledger*/ $this->invoice ->ledger() @@ -68,6 +62,12 @@ class MarkSent extends AbstractService ->setReminder() ->save(); + /*Adjust client balance*/ + $this->client->fresh(); + $this->client->balance += $adjustment; + $this->client->save(); + + $this->invoice->markInvitationsSent(); event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index 2636a5376f..538502113b 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -57,7 +57,10 @@ class TriggeredActions extends AbstractService $this->invoice = $this->invoice->service()->markSent()->save(); } - + if ($this->request->has('cancel') && $this->request->input('cancel') == 'true') { + $this->invoice = $this->invoice->service()->handleCancellation()->save(); + } + return $this->invoice; } diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 02e7a03a3b..87e650b969 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -678,7 +678,7 @@ class Design extends BaseDesign $elements = [ ['element' => 'div', 'properties' => ['style' => 'display: flex; flex-direction: column;'], 'elements' => [ - ['element' => 'p', 'content' => strtr(str_replace("labels", "", $_variables['values']['$entity.public_notes']), $_variables), 'properties' => ['data-ref' => 'total_table-public_notes', 'style' => 'text-align: left;']], + ['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;']], ['element' => 'p', 'content' => '', 'properties' => ['style' => 'text-align: left; display: flex; flex-direction: column; page-break-inside: auto;'], 'elements' => [ ['element' => 'span', 'content' => '$entity.terms_label: ', 'properties' => ['hidden' => $this->entityVariableCheck('$entity.terms'), 'data-ref' => 'total_table-terms-label', 'style' => 'font-weight: bold; text-align: left; margin-top: 1rem;']], ['element' => 'span', 'content' => strtr(str_replace("labels", "", $_variables['values']['$entity.terms']), $_variables['labels']), 'properties' => ['data-ref' => 'total_table-terms', 'style' => 'text-align: left;']], diff --git a/app/Services/Quote/TriggeredActions.php b/app/Services/Quote/TriggeredActions.php index ea38a696c5..3ee1046702 100644 --- a/app/Services/Quote/TriggeredActions.php +++ b/app/Services/Quote/TriggeredActions.php @@ -50,6 +50,10 @@ class TriggeredActions extends AbstractService $this->quote = $this->quote->service()->convert()->save(); } + if ($this->request->has('approve') && $this->request->input('approve') == 'true' && in_array($this->quote->status_id, [Quote::STATUS_SENT, Quote::STATUS_DRAFT])) { + $this->quote = $this->quote->service()->convert()->save(); + } + return $this->quote; } diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 453f1c3c89..0ed2aad259 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -167,6 +167,7 @@ class CompanyTransformer extends EntityTransformer 'report_include_drafts' => (bool) $company->report_include_drafts, 'client_registration_fields' => (array) $company->client_registration_fields, 'convert_rate_to_client' => (bool) $company->convert_rate_to_client, + 'markdown_email_enabled' => (bool) $company->markdown_email_enabled, ]; } diff --git a/config/ninja.php b/config/ninja.php index 7ef7b53d3b..89b2ac54fa 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.77', - 'app_tag' => '5.3.77', + 'app_version' => '5.3.78', + 'app_tag' => '5.3.78', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/database/migrations/2022_03_29_014025_reverse_apple_domain_for_hosted.php b/database/migrations/2022_03_29_014025_reverse_apple_domain_for_hosted.php index a1174083a3..5ccaa8f6d6 100644 --- a/database/migrations/2022_03_29_014025_reverse_apple_domain_for_hosted.php +++ b/database/migrations/2022_03_29_014025_reverse_apple_domain_for_hosted.php @@ -1,5 +1,6 @@ each(function ($company){ + $company->update(['markdown_email_enabled' => true]); + }); + } /** diff --git a/resources/views/email/support/message.blade.php b/resources/views/email/support/message.blade.php index 7ecc3d7b05..332f9888e2 100644 --- a/resources/views/email/support/message.blade.php +++ b/resources/views/email/support/message.blade.php @@ -1,6 +1,8 @@ @component('email.template.admin', ['settings' => $settings, 'logo' => $logo ?? 'https://www.invoiceninja.com/wp-content/uploads/2015/10/logo-white-horizontal-1.png']) {{-- Body --}} - {{ $support_message }} + {!! $support_message !!} + +