diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index bb2cf5ca6c25..6f74fb8a250d 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -383,7 +383,8 @@ class CheckData extends Command $wrong_paid_to_dates = 0; foreach (Client::cursor() as $client) { - $invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); + //$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); + $invoice_balance = Invoice::where('client_id', $client->id)->where('is_deleted', false)->where('status_id', '>', 1)->withTrashed()->sum('balance'); $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); @@ -395,7 +396,7 @@ class CheckData extends Command } } - $this->logMessage("{$wrong_paid_to_dates} clients with incorrect paid_to_dates"); + $this->logMessage("{$wrong_paid_to_dates} clients with incorrect client balances"); } private function checkLogoFiles() diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index 1e4604ba5671..bfbc60cd6d08 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -125,6 +125,7 @@ class ImportMigrations extends Command { $company = Company::factory()->create([ 'account_id' => $account->id, + 'is_disabled' => true, ]); if (! $account->default_company_id) { diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index e26563431475..7fae83a722c5 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -115,10 +115,10 @@ class Import implements ShouldQueue 'vendors', 'projects', 'products', + 'credits', 'invoices', 'recurring_invoices', 'quotes', - 'credits', 'payments', 'company_gateways', 'client_gateway_tokens', @@ -180,6 +180,8 @@ class Import implements ShouldQueue { set_time_limit(0); +info(print_r(array_keys($this->data),1)); + foreach ($this->data as $key => $resource) { if (! in_array($key, $this->available_imports)) { //throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration."); @@ -777,7 +779,8 @@ class Import implements ShouldQueue } private function processPayments(array $data): void - { + {info(print_r($this->ids,1)); + Payment::reguard(); $rules = [ @@ -838,6 +841,11 @@ class Import implements ShouldQueue //depending on the status, we do a final action. $payment = $this->updatePaymentForStatus($payment, $modified['status_id']); + if($modified['is_deleted']) + $payment->service()->deletePayment(); + + // if(isset($modified['deleted_at'])) + // $payment->delete(); } Payment::reguard(); diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 78daafd6081c..0e52ea0cbb33 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -73,6 +73,9 @@ class ActivityRepository extends BaseRepository */ public function createBackup($entity, $activity) { + if($entity->company->is_disabled) + return; + $backup = new Backup(); if (get_class($entity) == Invoice::class || get_class($entity) == Quote::class || get_class($entity) == Credit::class) { diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 6157f40ccc2a..286012ca6a80 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -36,11 +36,15 @@ class DeletePayment public function run() { + if($this->payment->is_deleted) + return $this->payment; + return $this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment ->updateCreditables() //return the credits first ->adjustInvoices() ->updateClient() ->deletePaymentables() + ->cleanupPayment() ->save(); } @@ -52,6 +56,15 @@ class DeletePayment //set applied amount to 0 + private function cleanupPayment() + { + $this->payment->is_deleted = true; + // $entity->save(); + $this->payment->delete(); + + return $this; + } + private function deletePaymentables() { $this->payment->paymentables()->update(['deleted_at' => now()]); diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 739321840703..75e2f54fc8cf 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -577,10 +577,10 @@ trait GeneratesCounter $search[] = '{$counter}'; $replace[] = $counter; - $search[] = '{$clientCounter}'; + $search[] = '{$client_counter}'; $replace[] = $counter; - $search[] = '{$groupCounter}'; + $search[] = '{$group_counter}'; $replace[] = $counter; if (strstr($pattern, '{$user_id}')) { @@ -600,20 +600,39 @@ trait GeneratesCounter $replace[] = str_replace($format, $date, $matches[1]); } - $search[] = '{$custom1}'; - $replace[] = $entity->custom_value1; + if($entity instanceof Client){ + $search[] = '{$client_custom1}'; + $replace[] = $entity->custom_value1; - $search[] = '{$custom2}'; - $replace[] = $entity->custom_value2; + $search[] = '{$client_custom2}'; + $replace[] = $entity->custom_value2; - $search[] = '{$custom3}'; - $replace[] = $entity->custom_value3; + $search[] = '{$client_custom3}'; + $replace[] = $entity->custom_value3; - $search[] = '{$custom4}'; - $replace[] = $entity->custom_value4; + $search[] = '{$client_custom4}'; + $replace[] = $entity->custom_value4; - $search[] = '{$id_number}'; - $replace[] = $entity->id_number; + $search[] = '{$id_number}'; + $replace[] = $entity->id_number; + } + else + { + $search[] = '{$client_custom1}'; + $replace[] = $entity->client->custom_value1; + + $search[] = '{$client_custom2}'; + $replace[] = $entity->client->custom_value2; + + $search[] = '{$client_custom3}'; + $replace[] = $entity->client->custom_value3; + + $search[] = '{$client_custom4}'; + $replace[] = $entity->client->custom_value4; + + $search[] = '{$id_number}'; + $replace[] = $entity->client->id_number; + } return str_replace($search, $replace, $pattern); } diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php index b22de8319de5..5c629c81066f 100644 --- a/resources/views/index/index.blade.php +++ b/resources/views/index/index.blade.php @@ -95,6 +95,55 @@ document.addEventListener('DOMContentLoaded', function(event) { document.getElementById('loader').style.display = 'none'; }); + + /* + function invokeServiceWorkerUpdateFlow() { + // you have a better UI here, reloading is not a great user experince here. + const confirmed = confirm('New version of the app is available. Refresh now'); + if (confirmed) { + window.location.reload(); + } + } + async function handleServiceWorker() { + if ('serviceWorker' in navigator) { + // get the ServiceWorkerRegistration instance + const registration = await navigator.serviceWorker.getRegistration(); + // (it is also returned from navigator.serviceWorker.register() function) + + if (registration) { + // detect Service Worker update available and wait for it to become installed + registration.addEventListener('updatefound', () => { + if (registration.installing) { + // wait until the new Service worker is actually installed (ready to take over) + registration.installing.addEventListener('statechange', () => { + if (registration.waiting) { + // if there's an existing controller (previous Service Worker), show the prompt + if (navigator.serviceWorker.controller) { + invokeServiceWorkerUpdateFlow(registration); + } else { + // otherwise it's the first install, nothing to do + console.log('Service Worker initialized for the first time'); + } + } + }); + } + }); + + let refreshing = false; + + // detect controller change and refresh the page + navigator.serviceWorker.addEventListener('controllerchange', () => { + if (!refreshing) { + window.location.reload(); + refreshing = true; + } + }); + } + } + } + + handleServiceWorker(); + */