From ebf77f07a0e41b80a45077bcccb3e5940e732049 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 14:37:53 +1100 Subject: [PATCH 01/18] Updates for creating new account --- app/Console/Commands/CreateAccount.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Console/Commands/CreateAccount.php b/app/Console/Commands/CreateAccount.php index 4bfa4c7a1326..057f07638a64 100644 --- a/app/Console/Commands/CreateAccount.php +++ b/app/Console/Commands/CreateAccount.php @@ -74,6 +74,7 @@ class CreateAccount extends Command $company->save(); $account->default_company_id = $company->id; + $account->set_react_as_default_ap = true; $account->save(); $email = $this->option('email') ?? 'admin@example.com'; From 2f694fb3871537e3c54be7f4a10c0d33234dfa49 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 14:58:07 +1100 Subject: [PATCH 02/18] Add playwright to workflow --- .github/workflows/playwright.yml | 143 +++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 .github/workflows/playwright.yml diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 000000000000..855ab040f975 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,143 @@ +on: + push: + branches: + - v5-develop + - v5-stable + pull_request: + branches: + - v5-develop + +name: phpunit +jobs: + run: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: ['ubuntu-20.04', 'ubuntu-22.04'] + php-versions: ['8.1','8.2'] + phpunit-versions: ['latest'] + ci_node_total: [ 8 ] + ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7] + laravel: [9.*] + dependency-version: [prefer-stable] + + env: + DB_CONNECTION: mysql + DB_DATABASE1: ninja + DB_USERNAME1: root + DB_PASSWORD1: ninja + DB_HOST1: '127.0.0.1' + DB_DATABASE: ninja + DB_USERNAME: root + DB_PASSWORD: ninja + DB_HOST: '127.0.0.1' + REDIS_PORT: 6379 + BROADCAST_DRIVER: log + CACHE_DRIVER: redis + QUEUE_CONNECTION: redis + SESSION_DRIVER: redis + NINJA_ENVIRONMENT: hosted + MULTI_DB_ENABLED: false + NINJA_LICENSE: ${{ secrets.ninja_license }} + TRAVIS: true + MAIL_MAILER: log + + services: + mariadb: + image: mariadb:10.6 + ports: + - 32768:3306 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_USER: ninja + MYSQL_PASSWORD: ninja + MYSQL_DATABASE: ninja + MYSQL_ROOT_PASSWORD: ninja + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + redis: + image: redis + ports: + - 6379/tcp + options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Add hosts to /etc/hosts + run: | + sudo echo "127.0.0.1 ninja.test" | sudo tee -a /etc/hosts + + - name: Start MariaDB service + run: | + sudo systemctl start mysql.service + - name: Verify MariaDB connection + env: + DB_PORT: ${{ job.services.mariadb.ports[3306] }} + DB_PORT1: ${{ job.services.mariadb.ports[3306] }} + + run: | + while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do + sleep 1 + done + - name: Setup PHP shivammathur/setup-php@v2 + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mysql, mysqlnd, sqlite3, bcmath, gmp, gd, curl, zip, openssl, mbstring, xml, redis + + - uses: actions/checkout@v1 + with: + ref: v5-develop + fetch-depth: 1 + + - name: Copy .env + run: | + cp .env.ci .env + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.php }}-composer- + + - name: Install composer dependencies + run: | + composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + composer install + + - name: Prepare Laravel Application + env: + REDIS_PORT: ${{ job.services.redis.ports['6379'] }} + run: | + php artisan key:generate + php artisan config:clear + php artisan ninja:post-update + php artisan optimize + + - name: Migrate Database + run: | + php artisan migrate:fresh --seed --force && php artisan db:seed --force + php artisan ninja:create-account --email=user@example.com --password=--password + + - name: Prepare React FrontEnd + run: | + git clone https://${{secrets.commit_secret}}@github.com/invoiceninja/ui.git + cd ui + git checkout main + npm i + npm run build + + mkdir -p ../public/react/${{ github.event.release.tag_name }}/ + cp -r dist/react/* ../public/react/${{ github.event.release.tag_name }}/ + cp -r dist/react/* ../public/react/ + + mkdir -p ../public/tinymce_6.4.2/tinymce/js/ + cp -r node_modules/tinymce ../public/tinymce_6.4.2/tinymce/js/ + cd .. + rm -rf ui + php artisan ninja:react + npx playwright install + npx playwright test --workers=1 From b19243a5db0b68a212bde9eb1898d362dab7e65a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 14:58:33 +1100 Subject: [PATCH 03/18] Add playwright to workflow --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 855ab040f975..ee6c928e236b 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -7,7 +7,7 @@ on: branches: - v5-develop -name: phpunit +name: playwright jobs: run: runs-on: ${{ matrix.operating-system }} From 7fdac3a7ea47974748bb7878bf316cd481a79174 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 15:41:53 +1100 Subject: [PATCH 04/18] Add playwright to workflow --- .github/workflows/playwright.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index ee6c928e236b..56c54b41540f 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -2,7 +2,6 @@ on: push: branches: - v5-develop - - v5-stable pull_request: branches: - v5-develop @@ -13,12 +12,10 @@ jobs: runs-on: ${{ matrix.operating-system }} strategy: matrix: - operating-system: ['ubuntu-20.04', 'ubuntu-22.04'] - php-versions: ['8.1','8.2'] + operating-system: ['ubuntu-20.04'] + php-versions: ['8.2'] phpunit-versions: ['latest'] - ci_node_total: [ 8 ] - ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7] - laravel: [9.*] + laravel: [10.*] dependency-version: [prefer-stable] env: @@ -137,7 +134,7 @@ jobs: mkdir -p ../public/tinymce_6.4.2/tinymce/js/ cp -r node_modules/tinymce ../public/tinymce_6.4.2/tinymce/js/ cd .. - rm -rf ui php artisan ninja:react + cd ui npx playwright install npx playwright test --workers=1 From f33e94129b57333b490583bd344b0e1eaf0113ad Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 19:27:53 +1100 Subject: [PATCH 05/18] remove playwright from gh actions --- .github/workflows/playwright.yml | 140 ------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 .github/workflows/playwright.yml diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml deleted file mode 100644 index 56c54b41540f..000000000000 --- a/.github/workflows/playwright.yml +++ /dev/null @@ -1,140 +0,0 @@ -on: - push: - branches: - - v5-develop - pull_request: - branches: - - v5-develop - -name: playwright -jobs: - run: - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - operating-system: ['ubuntu-20.04'] - php-versions: ['8.2'] - phpunit-versions: ['latest'] - laravel: [10.*] - dependency-version: [prefer-stable] - - env: - DB_CONNECTION: mysql - DB_DATABASE1: ninja - DB_USERNAME1: root - DB_PASSWORD1: ninja - DB_HOST1: '127.0.0.1' - DB_DATABASE: ninja - DB_USERNAME: root - DB_PASSWORD: ninja - DB_HOST: '127.0.0.1' - REDIS_PORT: 6379 - BROADCAST_DRIVER: log - CACHE_DRIVER: redis - QUEUE_CONNECTION: redis - SESSION_DRIVER: redis - NINJA_ENVIRONMENT: hosted - MULTI_DB_ENABLED: false - NINJA_LICENSE: ${{ secrets.ninja_license }} - TRAVIS: true - MAIL_MAILER: log - - services: - mariadb: - image: mariadb:10.6 - ports: - - 32768:3306 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_USER: ninja - MYSQL_PASSWORD: ninja - MYSQL_DATABASE: ninja - MYSQL_ROOT_PASSWORD: ninja - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - redis: - image: redis - ports: - - 6379/tcp - options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 - - steps: - - name: Add hosts to /etc/hosts - run: | - sudo echo "127.0.0.1 ninja.test" | sudo tee -a /etc/hosts - - - name: Start MariaDB service - run: | - sudo systemctl start mysql.service - - name: Verify MariaDB connection - env: - DB_PORT: ${{ job.services.mariadb.ports[3306] }} - DB_PORT1: ${{ job.services.mariadb.ports[3306] }} - - run: | - while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do - sleep 1 - done - - name: Setup PHP shivammathur/setup-php@v2 - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mysql, mysqlnd, sqlite3, bcmath, gmp, gd, curl, zip, openssl, mbstring, xml, redis - - - uses: actions/checkout@v1 - with: - ref: v5-develop - fetch-depth: 1 - - - name: Copy .env - run: | - cp .env.ci .env - - - name: Get Composer Cache Directory - id: composer-cache - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.php }}-composer- - - - name: Install composer dependencies - run: | - composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} - composer install - - - name: Prepare Laravel Application - env: - REDIS_PORT: ${{ job.services.redis.ports['6379'] }} - run: | - php artisan key:generate - php artisan config:clear - php artisan ninja:post-update - php artisan optimize - - - name: Migrate Database - run: | - php artisan migrate:fresh --seed --force && php artisan db:seed --force - php artisan ninja:create-account --email=user@example.com --password=--password - - - name: Prepare React FrontEnd - run: | - git clone https://${{secrets.commit_secret}}@github.com/invoiceninja/ui.git - cd ui - git checkout main - npm i - npm run build - - mkdir -p ../public/react/${{ github.event.release.tag_name }}/ - cp -r dist/react/* ../public/react/${{ github.event.release.tag_name }}/ - cp -r dist/react/* ../public/react/ - - mkdir -p ../public/tinymce_6.4.2/tinymce/js/ - cp -r node_modules/tinymce ../public/tinymce_6.4.2/tinymce/js/ - cd .. - php artisan ninja:react - cd ui - npx playwright install - npx playwright test --workers=1 From b1f61e1fbef888eca4818c636f318c1bd04669c5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 19:32:12 +1100 Subject: [PATCH 06/18] Add Malagasy Ariary currency --- .../2023_10_10_083024_add_ariary_currency.php | 39 +++++++++++++++++++ database/seeders/CurrenciesSeeder.php | 1 + 2 files changed, 40 insertions(+) create mode 100644 database/migrations/2023_10_10_083024_add_ariary_currency.php diff --git a/database/migrations/2023_10_10_083024_add_ariary_currency.php b/database/migrations/2023_10_10_083024_add_ariary_currency.php new file mode 100644 index 000000000000..51978dbab5c7 --- /dev/null +++ b/database/migrations/2023_10_10_083024_add_ariary_currency.php @@ -0,0 +1,39 @@ +id = 119; + $cur->code = 'MGA'; + $cur->name = 'Malagasy ariary'; + $cur->symbol = 'Ar'; + $cur->thousand_separator = ','; + $cur->decimal_separator = '.'; + $cur->precision = 0; + $cur->save(); + } + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/database/seeders/CurrenciesSeeder.php b/database/seeders/CurrenciesSeeder.php index 3005940fa1f9..c9ae3f523b43 100644 --- a/database/seeders/CurrenciesSeeder.php +++ b/database/seeders/CurrenciesSeeder.php @@ -141,6 +141,7 @@ class CurrenciesSeeder extends Seeder ['id' => 116, 'name' => 'Silver Troy Ounce', 'code' => 'XAG', 'symbol' => 'XAG', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['id' => 117, 'name' => 'Gold Troy Ounce', 'code' => 'XAU', 'symbol' => 'XAU', 'precision' => '3', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['id' => 118, 'name' => 'Nicaraguan Córdoba', 'code' => 'NIO', 'symbol' => 'C$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], + ['id' => 119, 'name' => 'Malagasy ariary', 'code' => 'MGA', 'symbol' => 'AR', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'], ]; foreach ($currencies as $currency) { From e17029223c10bdc83362174fb4beebdc18bf2a2e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 19:32:42 +1100 Subject: [PATCH 07/18] Add Malagasy Ariary currency --- database/seeders/CurrenciesSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/seeders/CurrenciesSeeder.php b/database/seeders/CurrenciesSeeder.php index c9ae3f523b43..b2c8b35af751 100644 --- a/database/seeders/CurrenciesSeeder.php +++ b/database/seeders/CurrenciesSeeder.php @@ -141,7 +141,7 @@ class CurrenciesSeeder extends Seeder ['id' => 116, 'name' => 'Silver Troy Ounce', 'code' => 'XAG', 'symbol' => 'XAG', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['id' => 117, 'name' => 'Gold Troy Ounce', 'code' => 'XAU', 'symbol' => 'XAU', 'precision' => '3', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['id' => 118, 'name' => 'Nicaraguan Córdoba', 'code' => 'NIO', 'symbol' => 'C$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], - ['id' => 119, 'name' => 'Malagasy ariary', 'code' => 'MGA', 'symbol' => 'AR', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'], + ['id' => 119, 'name' => 'Malagasy ariary', 'code' => 'MGA', 'symbol' => 'Ar', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'], ]; foreach ($currencies as $currency) { From e5997128d6621444c6df57199abb946802bac70d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Oct 2023 21:00:38 +1100 Subject: [PATCH 08/18] Fixes for entity images --- app/Console/Commands/CreateAccount.php | 7 +++++++ app/DataMapper/CompanySettings.php | 2 ++ app/Utils/HtmlEngine.php | 10 ++++++---- database/seeders/RandomDataSeeder.php | 8 +++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/CreateAccount.php b/app/Console/Commands/CreateAccount.php index 057f07638a64..d2ff960b2019 100644 --- a/app/Console/Commands/CreateAccount.php +++ b/app/Console/Commands/CreateAccount.php @@ -63,11 +63,18 @@ class CreateAccount extends Command private function createAccount() { + $settings = CompanySettings::defaults(); + + $settings->name = "Untitled Company"; + $settings->currency_id = '1'; + $settings->language_id = '1'; + $account = Account::factory()->create(); $company = Company::factory()->create([ 'account_id' => $account->id, 'portal_domain' => config('ninja.app_url'), 'portal_mode' => 'domain', + 'settings' => $settings, ]); $company->client_registration_fields = ClientRegistrationFields::generate(); diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index e4e8ff3085c5..bebf00b65d1f 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -841,6 +841,8 @@ class CompanySettings extends BaseSettings { $notification = new stdClass; $notification->email = []; + $notification->email = ['invoice_sent_all']; + // $notification->email = ['all_notifications']; return $notification; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 058f9ed36731..d12ff9094da7 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -1013,9 +1013,9 @@ html { */ protected function generateEntityImagesMarkup() { - if ($this->client->getSetting('embed_documents') === false) { - return ''; - } + // if ($this->client->getSetting('embed_documents') === false) { + // return ''; + // } $dom = new \DOMDocument('1.0', 'UTF-8'); @@ -1029,7 +1029,7 @@ html { $image = $dom->createElement('img'); - $image->setAttribute('src', $document->generateUrl()); + $image->setAttribute('src', "data:image/png;base64,".base64_encode($document->getFile())); $image->setAttribute('style', 'max-height: 100px; margin-top: 20px;'); $container->appendChild($image); @@ -1040,6 +1040,8 @@ html { $html = $dom->saveHTML(); $dom = null; + + nlog($html); return $html; } diff --git a/database/seeders/RandomDataSeeder.php b/database/seeders/RandomDataSeeder.php index e508ba0daaee..027fad32815a 100644 --- a/database/seeders/RandomDataSeeder.php +++ b/database/seeders/RandomDataSeeder.php @@ -89,10 +89,16 @@ class RandomDataSeeder extends Seeder Model::unguard(); $faker = \Faker\Factory::create(); - + $settings= CompanySettings::defaults(); + + $settings->name = "Random Test Company"; + $settings->currency_id = '1'; + $settings->language_id = '1'; + $account = Account::factory()->create(); $company = Company::factory()->create([ 'account_id' => $account->id, + 'settings' => $settings, ]); $account->default_company_id = $company->id; From b25f58db6f1337f0c4f0c6e208dd296003712636 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 08:58:47 +1100 Subject: [PATCH 09/18] Implement embed documents on pdf --- app/Utils/HtmlEngine.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index d12ff9094da7..46f741e7b4c6 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -12,21 +12,22 @@ namespace App\Utils; -use App\Helpers\Epc\EpcQrGenerator; -use App\Helpers\SwissQr\SwissQrGenerator; -use App\Models\Country; -use App\Models\CreditInvitation; -use App\Models\GatewayType; -use App\Models\InvoiceInvitation; -use App\Models\QuoteInvitation; -use App\Models\RecurringInvoiceInvitation; -use App\Utils\Traits\AppSetup; -use App\Utils\Traits\DesignCalculator; -use App\Utils\Traits\MakesDates; -use App\Utils\Traits\MakesHash; use Exception; +use App\Models\Account; +use App\Models\Country; +use App\Models\GatewayType; +use App\Utils\Traits\AppSetup; +use App\Models\QuoteInvitation; +use App\Utils\Traits\MakesHash; +use App\Models\CreditInvitation; +use App\Utils\Traits\MakesDates; +use App\Models\InvoiceInvitation; +use App\Helpers\Epc\EpcQrGenerator; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; +use App\Utils\Traits\DesignCalculator; +use App\Helpers\SwissQr\SwissQrGenerator; +use App\Models\RecurringInvoiceInvitation; class HtmlEngine { @@ -1013,14 +1014,14 @@ html { */ protected function generateEntityImagesMarkup() { - // if ($this->client->getSetting('embed_documents') === false) { + // if (!$this->client->getSetting('embed_documents') && !$this->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { // return ''; // } $dom = new \DOMDocument('1.0', 'UTF-8'); $container = $dom->createElement('div'); - $container->setAttribute('style', 'display:grid; grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr);'); + $container->setAttribute('style', 'display:grid; grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr);justify-items: center;'); foreach ($this->entity->documents as $document) { if (!$document->isImage()) { @@ -1030,7 +1031,7 @@ html { $image = $dom->createElement('img'); $image->setAttribute('src', "data:image/png;base64,".base64_encode($document->getFile())); - $image->setAttribute('style', 'max-height: 100px; margin-top: 20px;'); + $image->setAttribute('style', 'max-width: 50%; margin-top: 20px;'); $container->appendChild($image); } From d267dc1f092880b30797c6c180b58e78448361b7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 10:25:21 +1100 Subject: [PATCH 10/18] Minor fixes --- app/Services/Invoice/InvoiceService.php | 2 +- app/Utils/HtmlEngine.php | 2 - tests/Unit/LateFeeTest.php | 118 ++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 3 deletions(-) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 1122683a7735..e7d8eb2f6869 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -402,7 +402,7 @@ class InvoiceService $balance = $this->invoice->balance; //return early if type three does not exist. - if (! collect($this->invoice->line_items)->contains('type_id', 3)) { + if (! collect($this->invoice->line_items)->contains('type_id', '3')) { return $this; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 46f741e7b4c6..f96d37be5df8 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -1042,8 +1042,6 @@ html { $dom = null; - nlog($html); - return $html; } diff --git a/tests/Unit/LateFeeTest.php b/tests/Unit/LateFeeTest.php index 383e9b2424dd..5721f79e0727 100644 --- a/tests/Unit/LateFeeTest.php +++ b/tests/Unit/LateFeeTest.php @@ -22,6 +22,8 @@ use App\Jobs\Util\ReminderJob; use App\DataMapper\InvoiceItem; use App\DataMapper\FeesAndLimits; use App\DataMapper\CompanySettings; +use App\Factory\InvoiceItemFactory; +use App\Factory\ClientGatewayTokenFactory; use Illuminate\Foundation\Testing\DatabaseTransactions; /** @@ -93,6 +95,122 @@ class LateFeeTest extends TestCase return $client; } + public function testLateFeeRemovals() + { + + $data = []; + $data[1]['min_limit'] = -1; + $data[1]['max_limit'] = -1; + $data[1]['fee_amount'] = 0.00; + $data[1]['fee_percent'] = 1; + $data[1]['fee_tax_name1'] = ''; + $data[1]['fee_tax_rate1'] = 0; + $data[1]['fee_tax_name2'] = ''; + $data[1]['fee_tax_rate2'] = 0; + $data[1]['fee_tax_name3'] = ''; + $data[1]['fee_tax_rate3'] = 0; + $data[1]['adjust_fee_percent'] = false; + $data[1]['fee_cap'] = 0; + $data[1]['is_enabled'] = true; + + $cg = new \App\Models\CompanyGateway; + $cg->company_id = $this->company->id; + $cg->user_id = $this->user->id; + $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; + $cg->require_cvv = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->fees_and_limits = $data; + $cg->save(); + + $cgt = ClientGatewayTokenFactory::create($this->company->id); + $cgt->client_id = $this->client->id; + $cgt->token = ''; + $cgt->gateway_customer_reference = ''; + $cgt->gateway_type_id = 1; + $cgt->company_gateway_id = $cg->id; + $cgt->save(); + + $line_items = []; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + $item->type_id = '1'; + + $line_items[] = $item; + + $invoice_item = new InvoiceItem; + $invoice_item->type_id = '5'; + $invoice_item->product_key = trans('texts.fee'); + $invoice_item->quantity = 1; + $invoice_item->cost = 10; + + $line_items[] = $item; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 1; + $item->type_id = '3'; + + $line_items[] = $item; + + $this->assertTrue(collect($line_items)->contains('type_id', '3')); + $this->assertTrue(collect($line_items)->contains('type_id', 3)); + + $i = Invoice::factory()->create([ + + 'client_id' => $this->client->id, + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'line_items' => $line_items, + ]); + + $i = $i->calc()->getInvoice(); + + $this->assertEquals(3, count($i->line_items)); + + $invoice_items = (array) $i->line_items; + + $invoice_items = collect($invoice_items)->filter(function ($item) { + return $item->type_id != '3'; + }); + + $i->line_items = $invoice_items; + + $i->line_items = collect($i->line_items) + ->reject(function ($item) { + return $item->type_id == '3'; + })->toArray(); + + $this->assertEquals(2, count($i->line_items)); + + $i->service()->autoBill(); + + $i = $i->fresh(); + + $this->assertCount(2, $i->line_items); + + $line_items = $i->line_items; + + $invoice_item = new InvoiceItem; + $invoice_item->type_id = '5'; + $invoice_item->product_key = trans('texts.fee'); + $invoice_item->quantity = 1; + $invoice_item->cost = 10; + + $line_items[] = $item; + + $i->line_items = $line_items; + + $i = $i->calc()->getInvoice(); + + $this->assertCount(3, $i->line_items); + + } + public function testLateFeeAdded() { From 5dcb65c17b2d49c2f431e3d87d850d65a76dc55d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 10:47:55 +1100 Subject: [PATCH 11/18] Ensure paid to date stamp is not included in design --- app/Services/Client/Statement.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 4fe0ccc36fbe..5eff1ff260cf 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -62,6 +62,7 @@ class Statement } $variables = $html->generateLabelsAndValues(); + $variables['values']['$show_paid_stamp'] = 'none'; //do not show paid stamp on statement $state = [ 'template' => $template->elements([ From a36f2a9c4bca42b00fc7361ddcf9f186ec3c40df Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 14:18:56 +1100 Subject: [PATCH 12/18] Fixes for removing items from collection appropriately --- app/Helpers/Invoice/InvoiceItemSum.php | 2 +- .../Invoice/InvoiceItemSumInclusive.php | 3 +- .../ClientPortal/InvoiceController.php | 2 +- app/Services/Invoice/AddGatewayFee.php | 5 +- app/Services/Invoice/InvoiceService.php | 6 +- tests/Unit/LateFeeTest.php | 210 ++++++++++++++++-- 6 files changed, 200 insertions(+), 28 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 74625c98416c..b1f7fa9e6471 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -144,7 +144,7 @@ class InvoiceItemSum public function process(): self { - if (!$this->invoice->line_items || !is_array($this->invoice->line_items)) { + if (!$this->invoice->line_items || !is_iterable($this->invoice->line_items)) { $this->items = []; return $this; } diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index ad1a92600a08..7198abbfe8d1 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -131,8 +131,7 @@ class InvoiceItemSumInclusive public function process() { - if (! $this->invoice->line_items || ! is_array($this->invoice->line_items) || count($this->invoice->line_items) == 0) { - + if (!$this->invoice->line_items || ! is_iterable($this->invoice->line_items) || count($this->invoice->line_items) == 0) { return $this; } diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 3804ab890e94..bbed2ee5bbbf 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -195,7 +195,7 @@ class InvoiceController extends Controller //format data $invoices->map(function ($invoice) { - $invoice->service()->removeUnpaidGatewayFees(); + // $invoice->service()->removeUnpaidGatewayFees(); $invoice->balance = $invoice->balance > 0 ? Number::formatValue($invoice->balance, $invoice->client->currency()) : 0; $invoice->partial = $invoice->partial > 0 ? Number::formatValue($invoice->partial, $invoice->client->currency()) : 0; diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 5729a13195ec..08666ad1f4a5 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -29,7 +29,7 @@ class AddGatewayFee extends AbstractService { $gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount, $this->gateway_type_id, $this->invoice->uses_inclusive_taxes), $this->invoice->client->currency()->precision); - if (! $gateway_fee) { + if (! $gateway_fee || $gateway_fee == 0) { return $this->invoice; } @@ -52,6 +52,7 @@ class AddGatewayFee extends AbstractService $invoice_items = collect($invoice_items)->filter(function ($item) { return $item->type_id != '3'; }); + // })->toArray(); $this->invoice->line_items = $invoice_items; @@ -150,7 +151,7 @@ class AddGatewayFee extends AbstractService $this->invoice ->ledger() - ->updateInvoiceBalance($adjustment * -1, 'Adjustment for adding gateway fee'); + ->updateInvoiceBalance($adjustment * -1, 'Adjustment for adding gateway DISCOUNT'); } return $this->invoice; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index e7d8eb2f6869..7aad51649f2b 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -402,17 +402,19 @@ class InvoiceService $balance = $this->invoice->balance; //return early if type three does not exist. - if (! collect($this->invoice->line_items)->contains('type_id', '3')) { + if (! collect($this->invoice->line_items)->contains('type_id', 3)) { return $this; } $pre_count = count($this->invoice->line_items); - $this->invoice->line_items = collect($this->invoice->line_items) + $items = collect($this->invoice->line_items) ->reject(function ($item) { return $item->type_id == '3'; })->toArray(); + $this->invoice->line_items = array_values($items); + $this->invoice = $this->invoice->calc()->getInvoice(); // $this->deletePdf(); $this->deleteEInvoice(); diff --git a/tests/Unit/LateFeeTest.php b/tests/Unit/LateFeeTest.php index 5721f79e0727..74c708d0cacd 100644 --- a/tests/Unit/LateFeeTest.php +++ b/tests/Unit/LateFeeTest.php @@ -95,6 +95,159 @@ class LateFeeTest extends TestCase return $client; } + public function testModelBehaviourInsideMap() + { + $i = Invoice::factory()->count(5) + ->create([ + 'client_id' => $this->client->id, + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'tax_name1' => '', + 'tax_rate1' => 0, + 'tax_name2' => '', + 'tax_rate2' => 0, + 'tax_name3' => '', + 'tax_rate3' => 0, + 'discount' => 0, + ]); + + $i->each(function($invoice){ + $this->assertGreaterThan(1, count($invoice->line_items)); + }); + + $this->assertCount(5, $i); + + $invoices = $i->map(function ($invoice) { + $invoice->service()->removeUnpaidGatewayFees(); + return $invoice; + }); + + $invoices->each(function ($invoice) { + $this->assertGreaterThan(1, count($invoice->line_items)); + }); + + $ids = $invoices->pluck('id'); + + $invoices = $i->map(function ($invoice) { + + $line_items = $invoice->line_items; + + $item = new InvoiceItem; + $item->type_id = '3'; + $item->product_key = trans('texts.fee'); + $item->quantity = 1; + $item->cost = 10; + + $line_items[] = $item; + + $item = new InvoiceItem; + $item->type_id = '5'; + $item->product_key = trans('texts.fee'); + $item->quantity = 1; + $item->cost = 10; + + $line_items[] = $item; + $invoice->line_items = $line_items; + $invoice->saveQuietly(); + + return $invoice; + }); + + $invoices = Invoice::whereIn('id', $ids)->cursor()->map(function ($invoice){ + nlog("line item count = ".count($invoice->line_items)); + $this->assertGreaterThan(0, count($invoice->line_items)); + + $invoice->service()->removeUnpaidGatewayFees(); + $invoice = $invoice->fresh(); + $this->assertGreaterThan(0, count($invoice->line_items)); + + return $invoice; + }); + + $invoices->each(function ($invoice) { + nlog($invoice->line_items); + $this->assertGreaterThan(0, count($invoice->line_items)); + }); + + } + + public function testCollectionPassesIsArray() + { + $line_items = collect($this->invoice->line_items); + $this->assertTrue(is_array($this->invoice->line_items)); + $this->assertTrue(is_iterable($line_items)); + $this->assertFalse(is_array($line_items)); + } + + public function testLineItemResiliency() + { + $line_count = count($this->invoice->line_items); + $this->assertGreaterThan(0, $line_count); + + $this->invoice->service()->removeUnpaidGatewayFees(); + + $this->invoice = $this->invoice->fresh(); + + $this->assertCount($line_count, $this->invoice->line_items); + } + + public function testCollectionAsLineItemArray() + { + + $i = Invoice::factory()->create([ + 'client_id' => $this->client->id, + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'tax_name1' => '', + 'tax_rate1' => 0, + 'tax_name2' => '', + 'tax_rate2' => 0, + 'tax_name3' => '', + 'tax_rate3' => 0, + 'discount' => 0, + ]); + + $line_items = []; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + $item->type_id = '1'; + + $line_items[] = $item; + + $item = new InvoiceItem; + $item->type_id = '5'; + $item->product_key = trans('texts.fee'); + $item->quantity = 1; + $item->cost = 10; + + $line_items[] = $item; + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 1; + $item->type_id = '3'; + + $line_items[] = $item; + + $i->line_items = $line_items; + + $this->assertEquals(3, count($line_items)); + + $i = $i->calc()->getInvoice(); + + $this->assertEquals(3, count($i->line_items)); + $this->assertEquals(21, $i->amount); + + // $invoice_items = collect($invoice_items)->filter(function ($item) { + // return $item->type_id != '3'; + // }); + + // $this->invoice->line_items = $invoice_items; + + } + public function testLateFeeRemovals() { @@ -133,6 +286,20 @@ class LateFeeTest extends TestCase $cgt->company_gateway_id = $cg->id; $cgt->save(); + + $i = Invoice::factory()->create([ + 'client_id' => $this->client->id, + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'tax_name1' => '', + 'tax_rate1' => 0, + 'tax_name2' => '', + 'tax_rate2' => 0, + 'tax_name3' => '', + 'tax_rate3' => 0, + 'discount' => 0, + ]); + $line_items = []; $item = InvoiceItemFactory::create(); @@ -142,11 +309,11 @@ class LateFeeTest extends TestCase $line_items[] = $item; - $invoice_item = new InvoiceItem; - $invoice_item->type_id = '5'; - $invoice_item->product_key = trans('texts.fee'); - $invoice_item->quantity = 1; - $invoice_item->cost = 10; + $item = new InvoiceItem; + $item->type_id = '5'; + $item->product_key = trans('texts.fee'); + $item->quantity = 1; + $item->cost = 10; $line_items[] = $item; @@ -157,20 +324,12 @@ class LateFeeTest extends TestCase $line_items[] = $item; - $this->assertTrue(collect($line_items)->contains('type_id', '3')); - $this->assertTrue(collect($line_items)->contains('type_id', 3)); - - $i = Invoice::factory()->create([ - - 'client_id' => $this->client->id, - 'company_id' => $this->company->id, - 'user_id' => $this->user->id, - 'line_items' => $line_items, - ]); + $i->line_items = $line_items; $i = $i->calc()->getInvoice(); $this->assertEquals(3, count($i->line_items)); + $this->assertEquals(21, $i->amount); $invoice_items = (array) $i->line_items; @@ -180,6 +339,10 @@ class LateFeeTest extends TestCase $i->line_items = $invoice_items; + $i = $i->calc()->getInvoice(); + + $this->assertEquals(20, $i->amount); + $i->line_items = collect($i->line_items) ->reject(function ($item) { return $item->type_id == '3'; @@ -192,21 +355,28 @@ class LateFeeTest extends TestCase $i = $i->fresh(); $this->assertCount(2, $i->line_items); + $this->assertEquals(20, $i->amount); $line_items = $i->line_items; - $invoice_item = new InvoiceItem; - $invoice_item->type_id = '5'; - $invoice_item->product_key = trans('texts.fee'); - $invoice_item->quantity = 1; - $invoice_item->cost = 10; + $item = new InvoiceItem; + $item->type_id = '5'; + $item->product_key = trans('texts.fee'); + $item->quantity = 1; + $item->cost = 10; $line_items[] = $item; $i->line_items = $line_items; $i = $i->calc()->getInvoice(); + $this->assertEquals(30, $i->amount); + $this->assertCount(3, $i->line_items); + $i->service()->autoBill(); + $i = $i->fresh(); + + $this->assertEquals(30, $i->amount); $this->assertCount(3, $i->line_items); } From 35f7e125fb669147320ee2384fae099fa019cd79 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 14:22:11 +1100 Subject: [PATCH 13/18] Fixes for removing items from collection appropriately --- tests/Unit/LateFeeTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Unit/LateFeeTest.php b/tests/Unit/LateFeeTest.php index 74c708d0cacd..caa9c953422c 100644 --- a/tests/Unit/LateFeeTest.php +++ b/tests/Unit/LateFeeTest.php @@ -95,6 +95,29 @@ class LateFeeTest extends TestCase return $client; } + public function testAddLateFeeAppropriately() + { + $invoice_item = new InvoiceItem; + $invoice_item->type_id = '5'; + $invoice_item->product_key = trans('texts.fee'); + $invoice_item->notes = ctrans('texts.late_fee_added', ['date' => 'xyz']); + $invoice_item->quantity = 1; + $invoice_item->cost = 20; + + $invoice_items = $this->invoice->line_items; + $invoice_items[] = $invoice_item; + + $this->invoice->line_items = $invoice_items; + + $this->assertGreaterThan(1, count($this->invoice->line_items)); + + /**Refresh Invoice values*/ + $invoice = $this->invoice->calc()->getInvoice(); + + $this->assertGreaterThan(1, count($this->invoice->line_items)); + + } + public function testModelBehaviourInsideMap() { $i = Invoice::factory()->count(5) From bf2670635f781aacdc38b561e5377c64661e3b2f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 15:38:18 +1100 Subject: [PATCH 14/18] Fixes for tests --- app/Services/Invoice/AddGatewayFee.php | 1 - app/Services/Invoice/InvoiceService.php | 5 ++--- .../portal/ninja2020/gateways/gocardless/sepa/pay.blade.php | 4 +++- tests/Unit/LateFeeTest.php | 2 -- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 08666ad1f4a5..9716e558980f 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -52,7 +52,6 @@ class AddGatewayFee extends AbstractService $invoice_items = collect($invoice_items)->filter(function ($item) { return $item->type_id != '3'; }); - // })->toArray(); $this->invoice->line_items = $invoice_items; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 7aad51649f2b..c039078fc620 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -414,10 +414,9 @@ class InvoiceService })->toArray(); $this->invoice->line_items = array_values($items); - + $this->invoice = $this->invoice->calc()->getInvoice(); - // $this->deletePdf(); - $this->deleteEInvoice(); + $this->deleteEInvoice(); //@deprecated /* 24-03-2022 */ $new_balance = $this->invoice->balance; diff --git a/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay.blade.php b/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay.blade.php index 25b3c6a870fc..0732dcad478e 100644 --- a/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/gocardless/sepa/pay.blade.php @@ -38,7 +38,9 @@ @endcomponent @endif - @include('portal.ninja2020.gateways.includes.pay_now') + @if (count($tokens) > 0) + @include('portal.ninja2020.gateways.includes.pay_now') + @endif @endsection @push('footer') diff --git a/tests/Unit/LateFeeTest.php b/tests/Unit/LateFeeTest.php index caa9c953422c..b89fa0ff13d5 100644 --- a/tests/Unit/LateFeeTest.php +++ b/tests/Unit/LateFeeTest.php @@ -177,7 +177,6 @@ class LateFeeTest extends TestCase }); $invoices = Invoice::whereIn('id', $ids)->cursor()->map(function ($invoice){ - nlog("line item count = ".count($invoice->line_items)); $this->assertGreaterThan(0, count($invoice->line_items)); $invoice->service()->removeUnpaidGatewayFees(); @@ -188,7 +187,6 @@ class LateFeeTest extends TestCase }); $invoices->each(function ($invoice) { - nlog($invoice->line_items); $this->assertGreaterThan(0, count($invoice->line_items)); }); From 00d535a8b450c0db9bad79aa5f5548a005d24a98 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 16:25:44 +1100 Subject: [PATCH 15/18] Change from / to when attempting to access prop --- .../Traits/Notifications/UserNotifies.php | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index 35f065757b3d..153a9d65d21a 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -33,7 +33,7 @@ trait UserNotifies $notifiable_methods = []; $notifications = $company_user->notifications; - if ($invitation->company->is_disabled && + if ($company_user->company->is_disabled && is_array($notifications->email) || $company_user->trashed() || ! $company_user->user || @@ -43,7 +43,7 @@ trait UserNotifies //if a user owns this record or is assigned to it, they are attached the permission for notification. if ($invitation->{$entity_name}->user_id == $company_user->user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) { - // $required_permissions = $this->addSpecialUserPermissionForEntity($invitation->{$entity_name}, $required_permissions); + } else { $required_permissions = $this->removeSpecialUserPermissionForEntity($invitation->{$entity_name}, $required_permissions); } @@ -60,7 +60,7 @@ trait UserNotifies $notifiable_methods = []; $notifications = $company_user->notifications; - if ($entity->company->is_disabled || + if ($company_user->company->is_disabled || ! $notifications || $company_user->trashed() || ! $company_user->user || @@ -84,23 +84,6 @@ trait UserNotifies private function addSpecialUserPermissionForEntity($entity, array $required_permissions) :array { return array_merge($required_permissions, ['all_notifications', 'all_user_notifications']); - - // switch ($entity) { - // case $entity instanceof Payment || $entity instanceof Client: //we pass client also as this is the proxy for Payment Failures (ie, there is no payment) - // return array_merge($required_permissions, ['all_notifications', 'all_user_notifications', 'payment_failure_user', 'payment_success_user']); - // case $entity instanceof Invoice: - // return array_merge($required_permissions, ['all_notifications', 'all_user_notifications', 'invoice_created_user', 'invoice_sent_user', 'invoice_viewed_user', 'invoice_late_user']); - // case $entity instanceof Quote: - // return array_merge($required_permissions, ['all_notifications', 'all_user_notifications', 'quote_created_user', 'quote_sent_user', 'quote_viewed_user', 'quote_approved_user', 'quote_expired_user']); - // case $entity instanceof Credit: - // return array_merge($required_permissions, ['all_notifications', 'all_user_notifications', 'credit_created_user', 'credit_sent_user', 'credit_viewed_user']); - // case $entity instanceof PurchaseOrder: - // return array_merge($required_permissions, ['all_notifications', 'all_user_notifications', 'purchase_order_created_user', 'purchase_order_sent_user', 'purchase_order_viewed_user']); - // case $entity instanceof Product: - // return array_merge($required_permissions, ['all_notifications', 'all_user_notifications', 'inventory_user', 'inventory_all']); - // default: - // return []; - // } } private function removeSpecialUserPermissionForEntity($entity, $required_permissions) From 8210bce2bc52b0f4e69201ef315ebbdd67630b24 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 11 Oct 2023 20:01:28 +1100 Subject: [PATCH 16/18] catches for live previews --- app/Http/Controllers/PreviewController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index c99a4a400fe8..0f94c8e9ac1a 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -290,10 +290,14 @@ class PreviewController extends BaseController return $maker->getCompiledHTML(); } } catch(\Exception $e) { - // nlog($e->getMessage()); + DB::connection(config('database.default'))->rollBack(); - return; + if (DB::connection(config('database.default'))->transactionLevel() > 0) { + DB::connection(config('database.default'))->rollBack(); + } + + return response()->json(['message' => 'Error generating preview. Please retry again shortly.'], 400); } //if phantom js...... inject here.. From 10a8c9bd815381775dbd1f9a20e125db9f2e4396 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 12 Oct 2023 13:29:22 +1100 Subject: [PATCH 17/18] v5.7.29 --- VERSION.txt | 2 +- app/Services/Invoice/EInvoice/FacturaEInvoice.php | 7 ++++--- config/ninja.php | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 3d325733355f..fcd2fd579853 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.7.28 \ No newline at end of file +5.7.29 \ No newline at end of file diff --git a/app/Services/Invoice/EInvoice/FacturaEInvoice.php b/app/Services/Invoice/EInvoice/FacturaEInvoice.php index a11c6cc03226..4ec4ca779e65 100644 --- a/app/Services/Invoice/EInvoice/FacturaEInvoice.php +++ b/app/Services/Invoice/EInvoice/FacturaEInvoice.php @@ -468,7 +468,7 @@ class FacturaEInvoice extends AbstractService { $company = $this->invoice->company; - if($company->getSetting('classification')) + if($company->getSetting('classification') == 'individual') return $this->setIndividualSeller(); $seller = new FacturaeParty([ @@ -512,7 +512,7 @@ class FacturaEInvoice extends AbstractService $seller = new FacturaeParty([ "isLegalEntity" => false, "taxNumber" => $company->settings->vat_number, - "name" => $company->getSetting('classification') === 'individual' ? substr($company->owner()->present()->name(), 0, 40) : substr($company->present()->name(), 0, 40), + // "name" => $company->getSetting('classification') === 'individual' ? substr($company->owner()->present()->name(), 0, 40) : substr($company->present()->name(), 0, 40), "address" => substr($company->settings->address1, 0, 80), "postCode" => substr($this->invoice->client->postal_code, 0, 5), "town" => substr($company->settings->city, 0, 50), @@ -529,7 +529,8 @@ class FacturaEInvoice extends AbstractService "fax" => "", "website" => substr($company->settings->website, 0, 50), // "contactPeople" => substr($company->owner()->present()->name(), 0, 40), - "firstSurname" => $company->owner()->present()->firstName(), + "name" => $company->owner()->present()->firstName(), + // "firstSurname" => $company->owner()->present()->firstName(), "lastSurname" => $company->owner()->present()->lastName(), ]); diff --git a/config/ninja.php b/config/ninja.php index b9c170a48bf9..5c38ee2e3562 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,8 +15,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION','5.7.28'), - 'app_tag' => env('APP_TAG','5.7.28'), + 'app_version' => env('APP_VERSION','5.7.29'), + 'app_tag' => env('APP_TAG','5.7.29'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), From f86803739d59f371e33c715ffc40d4ad39e92d51 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 12 Oct 2023 13:30:42 +1100 Subject: [PATCH 18/18] Fixes for gocardless --- .../portal/ninja2020/gateways/gocardless/ach/pay.blade.php | 4 +++- .../ninja2020/gateways/gocardless/direct_debit/pay.blade.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/views/portal/ninja2020/gateways/gocardless/ach/pay.blade.php b/resources/views/portal/ninja2020/gateways/gocardless/ach/pay.blade.php index eb29b41515f5..aeb535ef3755 100644 --- a/resources/views/portal/ninja2020/gateways/gocardless/ach/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/gocardless/ach/pay.blade.php @@ -37,7 +37,9 @@ @endcomponent @endif - @include('portal.ninja2020.gateways.includes.pay_now') + @if (count($tokens) > 0) + @include('portal.ninja2020.gateways.includes.pay_now') + @endif @endsection @push('footer') diff --git a/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay.blade.php b/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay.blade.php index ac8071c3563b..75ff0ee4f077 100644 --- a/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/gocardless/direct_debit/pay.blade.php @@ -38,7 +38,9 @@ @endcomponent @endif - @include('portal.ninja2020.gateways.includes.pay_now') + @if (count($tokens) > 0) + @include('portal.ninja2020.gateways.includes.pay_now') + @endif @endsection @push('footer')