1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #8497 from turbo124/v5-develop

v5.5.114
This commit is contained in:
David Bomba 2023-05-04 11:22:10 +10:00 committed by GitHub
commit 7d88645e38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 421 additions and 1046 deletions

View File

@ -65,8 +65,9 @@ jobs:
- name: Build project - name: Build project
run: | run: |
zip -r ./invoiceninja.zip .* -x "../*" zip -r /home/runner/work/invoiceninja/invoiceninja.zip .* -x "../*"
shopt -s dotglob
tar --exclude='public/storage' --exclude='.htaccess' --exclude='invoiceninja.zip' -zcvf /home/runner/work/invoiceninja/invoiceninja.tar *
- name: Release - name: Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
@ -74,4 +75,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
files: | files: |
invoiceninja.zip /home/runner/work/invoiceninja/invoiceninja.tar
/home/runner/work/invoiceninja/invoiceninja.zip

View File

@ -1 +1 @@
5.5.113 5.5.114

View File

@ -114,6 +114,23 @@ class InvoiceFilters extends QueryFilters
}); });
} }
/**
* @return Builder
* @throws RuntimeException
*/
public function status_id(string $status = ''): Builder
{
if (strlen($status) == 0) {
return $this->builder;
}
return $this->builder->whereIn('status_id', explode(",", $status));
}
/** /**
* @return Builder * @return Builder
* @throws RuntimeException * @throws RuntimeException

View File

@ -24,6 +24,7 @@ use App\Models\CompanyToken;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Libraries\OAuth\OAuth; use App\Libraries\OAuth\OAuth;
use App\Events\User\UserLoggedIn; use App\Events\User\UserLoggedIn;
use Illuminate\Http\JsonResponse;
use PragmaRX\Google2FA\Google2FA; use PragmaRX\Google2FA\Google2FA;
use App\Jobs\Account\CreateAccount; use App\Jobs\Account\CreateAccount;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -32,6 +33,7 @@ use Illuminate\Support\Facades\Cache;
use Turbo124\Beacon\Facades\LightLogs; use Turbo124\Beacon\Facades\LightLogs;
use App\Http\Controllers\BaseController; use App\Http\Controllers\BaseController;
use App\Jobs\Company\CreateCompanyToken; use App\Jobs\Company\CreateCompanyToken;
use Illuminate\Support\Facades\Response;
use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Facades\Socialite;
use App\Http\Requests\Login\LoginRequest; use App\Http\Requests\Login\LoginRequest;
use App\Libraries\OAuth\Providers\Google; use App\Libraries\OAuth\Providers\Google;
@ -109,6 +111,7 @@ class LoginController extends BaseController
->increment() ->increment()
->batch(); ->batch();
/** @var \App\Models\User $user */
$user = $this->guard()->user(); $user = $this->guard()->user();
//2FA //2FA
@ -136,6 +139,7 @@ class LoginController extends BaseController
$user = $user->fresh(); $user = $user->fresh();
} }
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -168,7 +172,7 @@ class LoginController extends BaseController
* Refreshes the data feed with the current Company User. * Refreshes the data feed with the current Company User.
* *
* @param Request $request * @param Request $request
* @return CompanyUser Refresh Feed. * @return Response|JsonResponse
*/ */
public function refresh(Request $request) public function refresh(Request $request)
{ {
@ -271,6 +275,7 @@ class LoginController extends BaseController
Auth::login($existing_user, true); Auth::login($existing_user, true);
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -290,12 +295,16 @@ class LoginController extends BaseController
} }
Auth::login($existing_login_user, true); Auth::login($existing_login_user, true);
/** @var \App\Models\User $user */
auth()->user()->update([ $user = auth()->user();
$user->update([
'oauth_user_id' => $user->id, 'oauth_user_id' => $user->id,
'oauth_provider_id' => $provider, 'oauth_provider_id' => $provider,
]); ]);
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -333,9 +342,14 @@ class LoginController extends BaseController
$account = (new CreateAccount($new_account, request()->getClientIp()))->handle(); $account = (new CreateAccount($new_account, request()->getClientIp()))->handle();
Auth::login($account->default_company->owner(), true); Auth::login($account->default_company->owner(), true);
auth()->user()->email_verified_at = now();
auth()->user()->save();
/** @var \App\Models\User $user */
$user = auth()->user();
$user->email_verified_at = now();
$user->save();
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -363,26 +377,23 @@ class LoginController extends BaseController
$set_company = $cu->first()->company; $set_company = $cu->first()->company;
} }
auth()->user()->setCompany($set_company); /** @var \App\Models\User $user */
$user = auth()->user();
$this->setLoginCache(auth()->user()); $user->setCompany($set_company);
$this->setLoginCache($user);
$truth = app()->make(TruthSource::class); $truth = app()->make(TruthSource::class);
$truth->setCompanyUser($cu->first()); $truth->setCompanyUser($cu->first());
$truth->setUser(auth()->user()); $truth->setUser($user);
$truth->setCompany($set_company); $truth->setCompany($set_company);
if ($cu->count() == 0) { $cu->first()->account->companies->each(function ($company) use ($cu) {
return $cu; if ($company->tokens()->where('is_system', true)->count() == 0) {
} (new CreateCompanyToken($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')))->handle();
}
if (auth()->user()->company_users()->count() != auth()->user()->tokens()->distinct('company_id')->count()) { });
auth()->user()->companies->each(function ($company) {
if (!CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $company->id)->where('is_system', true)->exists()) {
(new CreateCompanyToken($company, auth()->user(), 'Google_O_Auth'))->handle();
}
});
}
$truth->setCompanyToken(CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $set_company->id)->first()); $truth->setCompanyToken(CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $set_company->id)->first());
@ -457,10 +468,17 @@ class LoginController extends BaseController
return response()->json(['message' => 'Unable to authenticate this user'], 400); return response()->json(['message' => 'Unable to authenticate this user'], 400);
} }
/**
* send login response to oauthed users
*
* @param \App\Models\User $existing_user
* @return Response | JsonResponse
*/
private function existingOauthUser($existing_user) private function existingOauthUser($existing_user)
{ {
Auth::login($existing_user, true); Auth::login($existing_user, true);
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -476,11 +494,16 @@ class LoginController extends BaseController
private function existingLoginUser($oauth_user_id, $provider) private function existingLoginUser($oauth_user_id, $provider)
{ {
auth()->user()->update([
/** @var \App\Models\User $user */
$user = auth()->user();
$user->update([
'oauth_user_id' => $oauth_user_id, 'oauth_user_id' => $oauth_user_id,
'oauth_provider_id' => $provider, 'oauth_provider_id' => $provider,
]); ]);
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -579,9 +602,14 @@ class LoginController extends BaseController
} }
Auth::login($account->default_company->owner(), true); Auth::login($account->default_company->owner(), true);
auth()->user()->email_verified_at = now();
auth()->user()->save();
/** @var \App\Models\User $user */
$user = auth()->user();
$user->email_verified_at = now();
$user->save();
/** @var \App\Models\CompanyUser $cu */
$cu = $this->hydrateCompanyUser(); $cu = $this->hydrateCompanyUser();
if ($cu->count() == 0) { if ($cu->count() == 0) {
@ -694,8 +722,6 @@ class LoginController extends BaseController
'email' => $socialite_user->getEmail(), 'email' => $socialite_user->getEmail(),
'oauth_user_id' => $socialite_user->getId(), 'oauth_user_id' => $socialite_user->getId(),
'oauth_provider_id' => $provider, 'oauth_provider_id' => $provider,
// 'oauth_user_token' => $oauth_user_token,
// 'oauth_user_refresh_token' => $socialite_user->accessTokenResponseBody['refresh_token'],
'oauth_user_token_expiry' => $oauth_expiry, 'oauth_user_token_expiry' => $oauth_expiry,
]; ];

View File

@ -60,7 +60,7 @@ class InvoiceController extends Controller
$invitation->markViewed(); $invitation->markViewed();
event(new InvitationWasViewed($invoice, $invitation, $invoice->company, Ninja::eventVars())); event(new InvitationWasViewed($invoice, $invitation, $invoice->company, Ninja::eventVars()));
event(new InvoiceWasViewed($invitation, $invitation->company, Ninja::eventVars())); event(new InvoiceWasViewed($invitation, $invoice->company, Ninja::eventVars()));
} }
$data = [ $data = [

View File

@ -177,8 +177,10 @@ class NinjaPlanController extends Controller
->increment() ->increment()
->queue(); ->queue();
$old_recurring = RecurringInvoice::where('company_id', config('ninja.ninja_default_company_id'))
$old_recurring = RecurringInvoice::where('company_id', config('ninja.ninja_default_company_id'))->where('client_id', $client->id)->first(); ->where('client_id', $client->id)
->where('id', '!=', $recurring_invoice->id)
->first();
if ($old_recurring) { if ($old_recurring) {
$old_recurring->service()->stop()->save(); $old_recurring->service()->stop()->save();

View File

@ -12,7 +12,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Exceptions\FilePermissionsFailure; use App\Exceptions\FilePermissionsFailure;
use App\Models\Client;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Traits\AppSetup; use App\Utils\Traits\AppSetup;
use App\Utils\Traits\ClientGroupSettingsSaver; use App\Utils\Traits\ClientGroupSettingsSaver;
@ -26,6 +25,10 @@ class SelfUpdateController extends BaseController
use ClientGroupSettingsSaver; use ClientGroupSettingsSaver;
use AppSetup; use AppSetup;
// private bool $use_zip = false;
private string $filename = 'invoiceninja.tar';
private array $purge_file_list = [ private array $purge_file_list = [
'bootstrap/cache/compiled.php', 'bootstrap/cache/compiled.php',
'bootstrap/cache/config.php', 'bootstrap/cache/config.php',
@ -39,35 +42,6 @@ class SelfUpdateController extends BaseController
{ {
} }
/**
* @OA\Post(
* path="/api/v1/self-update",
* operationId="selfUpdate",
* tags={"update"},
* summary="Performs a system update",
* description="Performs a system update",
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
* @OA\Parameter(ref="#/components/parameters/X-API-PASSWORD"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="Success/failure response"
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function update() public function update()
{ {
set_time_limit(0); set_time_limit(0);
@ -87,7 +61,8 @@ class SelfUpdateController extends BaseController
nlog('copying release file'); nlog('copying release file');
if (copy($this->getDownloadUrl(), storage_path('app/invoiceninja.zip'))) { // if (copy($this->getDownloadUrl(), storage_path('app/invoiceninja.zip'))) {
if (copy($this->getDownloadUrl(), storage_path("app/{$this->filename}"))) {
nlog('Copied file from URL'); nlog('Copied file from URL');
} else { } else {
return response()->json(['message' => 'Download not yet available. Please try again shortly.'], 410); return response()->json(['message' => 'Download not yet available. Please try again shortly.'], 410);
@ -95,27 +70,21 @@ class SelfUpdateController extends BaseController
nlog('Finished copying'); nlog('Finished copying');
$file = Storage::disk('local')->path('invoiceninja.zip'); // if($this->use_zip) {
$file = Storage::disk('local')->path($this->filename);
nlog('Extracting zip'); nlog('Extracting tar');
$zipFile = new \PhpZip\ZipFile(); $phar = new \PharData($file);
$phar->extractTo(base_path(), null, true);
$zipFile->openFile($file); nlog('Finished extracting files');
$zipFile->deleteFromName(".htaccess"); unlink($file);
// }
$zipFile->rewrite(); // else {
// $this->extractUsingZip();
$zipFile->extractTo(base_path()); // }
$zipFile->close();
$zipFile = null;
nlog('Finished extracting files');
unlink($file);
nlog('Deleted release zip file'); nlog('Deleted release zip file');
@ -141,40 +110,24 @@ class SelfUpdateController extends BaseController
return response()->json(['message' => 'Update completed'], 200); return response()->json(['message' => 'Update completed'], 200);
} }
private function deleteDirectory($dir) // private function extractUsingZip()
{ // {
if (! file_exists($dir)) {
return true;
}
if (! is_dir($dir) || is_link($dir)) { // $file = Storage::disk('local')->path($this->filename);
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (! $this->deleteDirectory($dir.'/'.$item)) {
if (! $this->deleteDirectory($dir.'/'.$item)) {
return false;
}
}
}
return rmdir($dir); // nlog('Extracting zip');
}
private function postHookUpdate() // $zipFile = new \PhpZip\ZipFile();
{ // $zipFile->openFile($file);
if (config('ninja.app_version') == '5.3.82') { // $zipFile->deleteFromName(".htaccess");
Client::withTrashed()->cursor()->each(function ($client) { // $zipFile->rewrite();
$entity_settings = $this->checkSettingType($client->settings); // $zipFile->extractTo(base_path());
$entity_settings->md5 = md5(time()); // $zipFile->close();
$client->settings = $entity_settings; // $zipFile = null;
$client->save();
}); // unlink($file);
}
} // }
private function clearCacheDir() private function clearCacheDir()
{ {
@ -197,10 +150,10 @@ class SelfUpdateController extends BaseController
} }
if ($file->isFile() && ! $file->isWritable()) { if ($file->isFile() && ! $file->isWritable()) {
nlog("Cannot update system because {$file->getFileName()} is not writable"); nlog("Cannot update system because {$file->getFileName()} is not writable");
throw new FilePermissionsFailure("Cannot update system because {$file->getFileName()} is not writable"); throw new FilePermissionsFailure("Cannot update system because {$file->getFileName()} is not writable");
return false;
} }
} }
@ -218,6 +171,10 @@ class SelfUpdateController extends BaseController
{ {
$version = $this->checkVersion(); $version = $this->checkVersion();
return "https://github.com/invoiceninja/invoiceninja/releases/download/v{$version}/invoiceninja.zip"; // if(request()->has('zip'))
// return "https://github.com/invoiceninja/invoiceninja/releases/download/v{$version}/invoiceninja.zip";
return "https://github.com/invoiceninja/invoiceninja/releases/download/v{$version}/invoiceninja.tar";
} }
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -428,6 +428,7 @@ class BaseImport
foreach ($invoices as $raw_invoice) { foreach ($invoices as $raw_invoice) {
try { try {
$invoice_data = $invoice_transformer->transform($raw_invoice); $invoice_data = $invoice_transformer->transform($raw_invoice);
$invoice_data['user_id'] = $this->company->owner()->id;
$invoice_data['line_items'] = $this->cleanItems( $invoice_data['line_items'] = $this->cleanItems(
$invoice_data['line_items'] ?? [] $invoice_data['line_items'] ?? []

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * client Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. client Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -2,9 +2,9 @@
/** /**
* Invoice Ninja (https://clientninja.com). * Invoice Ninja (https://clientninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -2,9 +2,9 @@
/** /**
* Invoice Ninja (https://clientninja.com). * Invoice Ninja (https://clientninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -2,9 +2,9 @@
/** /**
* Invoice Ninja (https://clientninja.com). * Invoice Ninja (https://clientninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -2,7 +2,7 @@
/** /**
* Invoice Ninja (https://invoiceninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://clientninja.com)
* *

View File

@ -2,9 +2,9 @@
/** /**
* Invoice Ninja (https://clientninja.com). * Invoice Ninja (https://clientninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -2,9 +2,9 @@
/** /**
* Invoice Ninja (https://clientninja.com). * Invoice Ninja (https://clientninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* client Ninja (https://clientninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/clientninja/clientninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. client Ninja LLC (https://clientninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -81,8 +81,6 @@ class CreateAccount
$sp794f3f->account_sms_verified = false; $sp794f3f->account_sms_verified = false;
} }
// $sp794f3f->trial_started = now();
// $sp794f3f->trial_plan = 'pro';
} }
$sp794f3f->save(); $sp794f3f->save();

View File

@ -11,10 +11,11 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use Illuminate\Foundation\Bus\Dispatchable; use App\Libraries\MultiDB;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Bus\Dispatchable;
class AutoBillCron class AutoBillCron
{ {
@ -45,6 +46,8 @@ class AutoBillCron
/* Get all invoices where the send date is less than NOW + 30 minutes() */ /* Get all invoices where the send date is less than NOW + 30 minutes() */
info('Performing Autobilling '.Carbon::now()->format('Y-m-d h:i:s')); info('Performing Autobilling '.Carbon::now()->format('Y-m-d h:i:s'));
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now()) $auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])

View File

@ -11,13 +11,14 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Factory\RecurringExpenseToExpenseFactory;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use Illuminate\Support\Carbon;
use App\Models\RecurringExpense; use App\Models\RecurringExpense;
use App\Models\RecurringInvoice; use App\Models\RecurringInvoice;
use Illuminate\Support\Facades\Auth;
use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\GeneratesCounter;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon; use App\Factory\RecurringExpenseToExpenseFactory;
class RecurringExpensesCron class RecurringExpensesCron
{ {
@ -45,6 +46,8 @@ class RecurringExpensesCron
/* Get all expenses where the send date is less than NOW + 30 minutes() */ /* Get all expenses where the send date is less than NOW + 30 minutes() */
nlog('Sending recurring expenses '.Carbon::now()->format('Y-m-d h:i:s')); nlog('Sending recurring expenses '.Carbon::now()->format('Y-m-d h:i:s'));
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$recurring_expenses = RecurringExpense::where('next_send_date', '<=', now()->toDateTimeString()) $recurring_expenses = RecurringExpense::where('next_send_date', '<=', now()->toDateTimeString())
->whereNotNull('next_send_date') ->whereNotNull('next_send_date')

View File

@ -11,12 +11,13 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Jobs\RecurringInvoice\SendRecurring;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\RecurringInvoice; use App\Libraries\MultiDB;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use App\Models\RecurringInvoice;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Jobs\RecurringInvoice\SendRecurring;
class RecurringInvoicesCron class RecurringInvoicesCron
{ {
@ -44,6 +45,8 @@ class RecurringInvoicesCron
$start = Carbon::now()->format('Y-m-d h:i:s'); $start = Carbon::now()->format('Y-m-d h:i:s');
nlog('Sending recurring invoices '.$start); nlog('Sending recurring invoices '.$start);
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$recurring_invoices = RecurringInvoice::where('status_id', RecurringInvoice::STATUS_ACTIVE) $recurring_invoices = RecurringInvoice::where('status_id', RecurringInvoice::STATUS_ACTIVE)
->where('is_deleted', false) ->where('is_deleted', false)

View File

@ -11,8 +11,9 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Libraries\MultiDB;
use Illuminate\Support\Facades\Auth;
use App\Utils\Traits\SubscriptionHooker; use App\Utils\Traits\SubscriptionHooker;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@ -39,6 +40,8 @@ class SubscriptionCron
{ {
nlog('Subscription Cron'); nlog('Subscription Cron');
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$invoices = Invoice::where('is_deleted', 0) $invoices = Invoice::where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])

View File

@ -13,6 +13,7 @@ namespace App\Jobs\Cron;
use App\Models\Project; use App\Models\Project;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
class UpdateCalculatedFields class UpdateCalculatedFields
@ -37,6 +38,8 @@ class UpdateCalculatedFields
{ {
nlog("Updating calculated fields"); nlog("Updating calculated fields");
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Project::with('tasks')->where('updated_at', '>', now()->subHours(2)) Project::with('tasks')->where('updated_at', '>', now()->subHours(2))

View File

@ -11,13 +11,14 @@
namespace App\Jobs\Ninja; namespace App\Jobs\Ninja;
use App\Libraries\MultiDB;
use App\Models\Scheduler; use App\Models\Scheduler;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
//@rebuild it //@rebuild it
class TaskScheduler implements ShouldQueue class TaskScheduler implements ShouldQueue
@ -42,6 +43,8 @@ class TaskScheduler implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Scheduler::with('company') Scheduler::with('company')
->where('is_paused', false) ->where('is_paused', false)

View File

@ -19,6 +19,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;
class CleanStaleInvoiceOrder implements ShouldQueue class CleanStaleInvoiceOrder implements ShouldQueue
{ {
@ -39,6 +40,8 @@ class CleanStaleInvoiceOrder implements ShouldQueue
{ {
nlog("Cleaning Stale Invoices:"); nlog("Cleaning Stale Invoices:");
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Invoice::query() Invoice::query()
->withTrashed() ->withTrashed()

View File

@ -11,23 +11,22 @@
namespace App\Jobs\Util; namespace App\Jobs\Util;
use App\Utils\Ninja;
use App\Models\Invoice;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Carbon;
use App\DataMapper\InvoiceItem; use App\DataMapper\InvoiceItem;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
use App\Jobs\Entity\EmailEntity; use App\Jobs\Entity\EmailEntity;
use App\Jobs\Ninja\TransactionLog;
use App\Libraries\MultiDB;
use App\Models\Invoice;
use App\Models\TransactionEvent;
use App\Utils\Ninja;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use Illuminate\Support\Facades\App;
use App\Utils\Traits\MakesReminders; use App\Utils\Traits\MakesReminders;
use Illuminate\Bus\Queueable; use Illuminate\Support\Facades\Auth;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
class ReminderJob implements ShouldQueue class ReminderJob implements ShouldQueue
{ {
@ -53,6 +52,8 @@ class ReminderJob implements ShouldQueue
{ {
set_time_limit(0); set_time_limit(0);
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
nlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s')); nlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s'));

View File

@ -310,7 +310,24 @@ class MultiDB
self::setDB($current_db); self::setDB($current_db);
return false; return null;
}
public static function findAndSetDbByShopifyName($shopify_name) :?Company
{
$current_db = config('database.default');
foreach (self::$dbs as $db) {
if ($company = Company::on($db)->with('tokens')->where('shopify_name', $shopify_name)->first()) {
self::setDb($db);
return $company;
}
}
self::setDB($current_db);
return null;
} }
public static function findAndSetDbByAccountKey($account_key) :bool public static function findAndSetDbByAccountKey($account_key) :bool
@ -413,7 +430,7 @@ class MultiDB
self::setDB($current_db); self::setDB($current_db);
return false; return null;
} }
public static function findAndSetDbByDomain($query_array) public static function findAndSetDbByDomain($query_array)

View File

@ -57,7 +57,6 @@ class ClientStatement extends Mailable
with: [ with: [
'text_body' => $this->data['body'], 'text_body' => $this->data['body'],
'body' => $this->data['body'], 'body' => $this->data['body'],
'whitelabel' => $this->data['whitelabel'],
'settings' => $this->data['settings'], 'settings' => $this->data['settings'],
'whitelabel' => $this->data['whitelabel'], 'whitelabel' => $this->data['whitelabel'],
'logo' => $this->data['logo'], 'logo' => $this->data['logo'],

View File

@ -203,6 +203,7 @@ class User extends Authenticatable implements MustVerifyEmail
'custom_value3', 'custom_value3',
'custom_value4', 'custom_value4',
'is_deleted', 'is_deleted',
'shopify_user_id',
// 'oauth_user_token', // 'oauth_user_token',
// 'oauth_user_refresh_token', // 'oauth_user_refresh_token',
]; ];

View File

@ -39,8 +39,15 @@ class ACH implements MethodInterface
public function authorizeView(array $data) public function authorizeView(array $data)
{ {
$data['gateway'] = $this->braintree; try {
$data['client_token'] = $this->braintree->gateway->clientToken()->generate(); $data['gateway'] = $this->braintree;
$data['client_token'] = $this->braintree->gateway->clientToken()->generate();
}
catch(\Exception $e){
throw new PaymentFailed("Unable to generate client token, check your Braintree credentials. Error: " . $e->getMessage(), 500);
}
return render('gateways.braintree.ach.authorize', $data); return render('gateways.braintree.ach.authorize', $data);
} }

View File

@ -119,6 +119,7 @@ class AppServiceProvider extends ServiceProvider
ParallelTesting::setUpTestDatabase(function ($database, $token) { ParallelTesting::setUpTestDatabase(function ($database, $token) {
Artisan::call('db:seed'); Artisan::call('db:seed');
}); });
} }
public function register(): void public function register(): void

View File

@ -16,7 +16,6 @@ use App\Models\Credit;
use App\Models\Payment; use App\Models\Payment;
use App\Services\Email\Email; use App\Services\Email\Email;
use App\Services\Email\EmailObject; use App\Services\Email\EmailObject;
use App\Services\Email\EmailService;
use App\Utils\Number; use App\Utils\Number;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use Illuminate\Mail\Mailables\Address; use Illuminate\Mail\Mailables\Address;
@ -168,9 +167,6 @@ class ClientService
$this->client_start_date = $this->translateDate($options['start_date'], $this->client->date_format(), $this->client->locale()); $this->client_start_date = $this->translateDate($options['start_date'], $this->client->date_format(), $this->client->locale());
$this->client_end_date = $this->translateDate($options['end_date'], $this->client->date_format(), $this->client->locale()); $this->client_end_date = $this->translateDate($options['end_date'], $this->client->date_format(), $this->client->locale());
// $email_service = new EmailService($this->buildStatementMailableData($pdf), $this->client->company);
// $email_service->send();
$email_object = $this->buildStatementMailableData($pdf); $email_object = $this->buildStatementMailableData($pdf);
Email::dispatch($email_object, $this->client->company); Email::dispatch($email_object, $this->client->company);
} }

View File

@ -245,17 +245,17 @@ class Statement
switch ($status) { switch ($status) {
case 'all': case 'all':
return [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]; return [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID];
break;
case 'paid': case 'paid':
return [Invoice::STATUS_PAID]; return [Invoice::STATUS_PAID];
break;
case 'unpaid': case 'unpaid':
return [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]; return [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL];
break;
default: default:
return [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]; return [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID];
break;
} }
} }

View File

@ -23,13 +23,11 @@ use App\Jobs\Invoice\CreateUbl;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Jobs\Entity\CreateRawPdf; use App\Jobs\Entity\CreateRawPdf;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use App\Jobs\Invoice\CreateEInvoice;
use Illuminate\Mail\Mailables\Address; use Illuminate\Mail\Mailables\Address;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\DataMapper\EmailTemplateDefaults; use App\DataMapper\EmailTemplateDefaults;
use League\CommonMark\CommonMarkConverter; use League\CommonMark\CommonMarkConverter;
use App\Jobs\Vendor\CreatePurchaseOrderPdf; use App\Jobs\Vendor\CreatePurchaseOrderPdf;
use App\Services\Invoice\GetInvoiceXInvoice;
class EmailDefaults class EmailDefaults
{ {

View File

@ -1,502 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Email;
use App\DataMapper\Analytics\EmailFailure;
use App\DataMapper\Analytics\EmailSuccess;
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
use App\Events\Payment\PaymentWasEmailedAndFailed;
use App\Jobs\Util\SystemLogger;
use App\Libraries\Google\Google;
use App\Libraries\MultiDB;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Models\Payment;
use App\Models\SystemLog;
use App\Models\User;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
use Turbo124\Beacon\Facades\LightLogs;
//@deprecated v5.5.83
class EmailMailer implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash;
public $tries = 4; //number of retries
public $deleteWhenMissingModels = true;
public $override;
private $mailer;
protected $client_postmark_secret = false;
protected $client_mailgun_secret = false;
protected $client_mailgun_domain = false;
public function __construct(public EmailService $email_service, public Mailable $email_mailable)
{
}
public function backoff()
{
return [10, 30, 60, 240];
}
public function handle(): void
{
MultiDB::setDb($this->email_service->company->db);
/* Perform final checks */
if ($this->email_service->preFlightChecksFail()) {
return;
}
/* Boot the required driver*/
$this->setMailDriver();
/* Init the mailer*/
$mailer = Mail::mailer($this->mailer);
/* Additional configuration if using a client third party mailer */
if ($this->client_postmark_secret) {
$mailer->postmark_config($this->client_postmark_secret);
}
if ($this->client_mailgun_secret) {
$mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain);
}
/* Attempt the send! */
try {
nlog("Using mailer => ". $this->mailer. " ". now()->toDateTimeString());
$mailer->send($this->email_mailable);
Cache::increment("email_quota".$this->email_service->company->account->key);
LightLogs::create(new EmailSuccess($this->email_service->company->company_key))
->send();
} catch (\Exception | \RuntimeException | \Google\Service\Exception $e) {
nlog("Mailer failed with {$e->getMessage()}");
$message = $e->getMessage();
/**
* Post mark buries the proper message in a a guzzle response
* this merges a text string with a json object
* need to harvest the ->Message property using the following
*/
if ($e instanceof ClientException) { //postmark specific failure
$response = $e->getResponse();
$message_body = json_decode($response->getBody()->getContents());
if ($message_body && property_exists($message_body, 'Message')) {
$message = $message_body->Message;
nlog($message);
}
$this->fail();
$this->cleanUpMailers();
return;
}
//only report once, not on all tries
if ($this->attempts() == $this->tries) {
/* If the is an entity attached to the message send a failure mailer */
$this->entityEmailFailed($message);
/* Don't send postmark failures to Sentry */
if (Ninja::isHosted() && (!$e instanceof ClientException)) {
app('sentry')->captureException($e);
}
}
/* Releasing immediately does not add in the backoff */
sleep(rand(0, 3));
$this->release($this->backoff()[$this->attempts()-1]);
$message = null;
}
$this->cleanUpMailers();
}
/**
* Entity notification when an email fails to send
*
* @todo - rewrite this
* @param string $message
* @return void
*/
private function entityEmailFailed($message)
{
if (!$this->email_service->email_object->entity_id) {
return;
}
switch ($this->email_service->email_object->entity_class) {
case Invoice::class:
$invitation = InvoiceInvitation::withTrashed()->find($this->email_service->email_object->entity_id);
if ($invitation) {
event(new InvoiceWasEmailedAndFailed($invitation, $this->email_service->company, $message, $this->email_service->email_object->reminder_template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
}
break;
case Payment::class:
$payment = Payment::withTrashed()->find($this->email_service->email_object->entity_id);
if ($payment) {
event(new PaymentWasEmailedAndFailed($payment, $this->email_service->company, $message, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
}
break;
default:
# code...
break;
}
if ($this->email_service->email_object->client_contact instanceof ClientContact) {
$this->logMailError($message, $this->email_service->email_object->client_contact);
}
}
/**
* Sets the mail driver to use and applies any specific configuration
* the the mailable
*/
private function setMailDriver(): self
{
switch ($this->email_service->email_object->settings->email_sending_method) {
case 'default':
$this->mailer = config('mail.default');
break;
case 'gmail':
$this->mailer = 'gmail';
$this->setGmailMailer();
return $this;
case 'office365':
$this->mailer = 'office365';
$this->setOfficeMailer();
return $this;
case 'client_postmark':
$this->mailer = 'postmark';
$this->setPostmarkMailer();
return $this;
case 'client_mailgun':
$this->mailer = 'mailgun';
$this->setMailgunMailer();
return $this;
default:
break;
}
if (Ninja::isSelfHost()) {
$this->setSelfHostMultiMailer();
}
return $this;
}
/**
* Allows configuration of multiple mailers
* per company for use by self hosted users
*/
private function setSelfHostMultiMailer(): void
{
if (env($this->email_service->company->id . '_MAIL_HOST')) {
config([
'mail.mailers.smtp' => [
'transport' => 'smtp',
'host' => env($this->email_service->company->id . '_MAIL_HOST'),
'port' => env($this->email_service->company->id . '_MAIL_PORT'),
'username' => env($this->email_service->company->id . '_MAIL_USERNAME'),
'password' => env($this->email_service->company->id . '_MAIL_PASSWORD'),
],
]);
if (env($this->email_service->company->id . '_MAIL_FROM_ADDRESS')) {
$this->email_mailable
->from(env($this->email_service->company->id . '_MAIL_FROM_ADDRESS', env('MAIL_FROM_ADDRESS')), env($this->email_service->company->id . '_MAIL_FROM_NAME', env('MAIL_FROM_NAME')));
}
}
}
/**
* Ensure we discard any data that is not required
*
* @return void
*/
private function cleanUpMailers(): void
{
$this->client_postmark_secret = false;
$this->client_mailgun_secret = false;
$this->client_mailgun_domain = false;
//always dump the drivers to prevent reuse
app('mail.manager')->forgetMailers();
}
/**
* Check to ensure no cross account
* emails can be sent.
*
* @param User $user
*/
private function checkValidSendingUser($user)
{
/* Always ensure the user is set on the correct account */
if ($user->account_id != $this->email_service->company->account_id) {
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
}
/**
* Resolves the sending user
* when configuring the Mailer
* on behalf of the client
*
* @return User $user
*/
private function resolveSendingUser(): ?User
{
$sending_user = $this->email_service->email_object->settings->gmail_sending_user_id;
if ($sending_user == "0") {
$user = $this->email_service->company->owner();
} else {
$user = User::find($this->decodePrimaryKey($sending_user));
}
return $user;
}
/**
* Configures Mailgun using client supplied secret
* as the Mailer
*/
private function setMailgunMailer()
{
if (strlen($this->email_service->email_object->settings->mailgun_secret) > 2 && strlen($this->email_service->email_object->settings->mailgun_domain) > 2) {
$this->client_mailgun_secret = $this->email_service->email_object->settings->mailgun_secret;
$this->client_mailgun_domain = $this->email_service->email_object->settings->mailgun_domain;
} else {
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
$user = $this->resolveSendingUser();
$sending_email = (isset($this->email_service->email_object->settings->custom_sending_email) && stripos($this->email_service->email_object->settings->custom_sending_email, "@")) ? $this->email_service->email_object->settings->custom_sending_email : $user->email;
$sending_user = (isset($this->email_service->email_object->settings->email_from_name) && strlen($this->email_service->email_object->settings->email_from_name) > 2) ? $this->email_service->email_object->settings->email_from_name : $user->name();
$this->email_mailable
->from($sending_email, $sending_user);
}
/**
* Configures Postmark using client supplied secret
* as the Mailer
*/
private function setPostmarkMailer()
{
if (strlen($this->email_service->email_object->settings->postmark_secret) > 2) {
$this->client_postmark_secret = $this->email_service->email_object->settings->postmark_secret;
} else {
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
$user = $this->resolveSendingUser();
$sending_email = (isset($this->email_service->email_object->settings->custom_sending_email) && stripos($this->email_service->email_object->settings->custom_sending_email, "@")) ? $this->email_service->email_object->settings->custom_sending_email : $user->email;
$sending_user = (isset($this->email_service->email_object->settings->email_from_name) && strlen($this->email_service->email_object->settings->email_from_name) > 2) ? $this->email_service->email_object->settings->email_from_name : $user->name();
$this->email_mailable
->from($sending_email, $sending_user);
}
/**
* Configures Microsoft via Oauth
* as the Mailer
*/
private function setOfficeMailer()
{
$user = $this->resolveSendingUser();
$this->checkValidSendingUser($user);
nlog("Sending via {$user->name()}");
$token = $this->refreshOfficeToken($user);
if ($token) {
$user->oauth_user_token = $token;
$user->save();
} else {
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
$this->email_mailable
->from($user->email, $user->name())
->withSymfonyMessage(function ($message) use ($token) {
$message->getHeaders()->addTextHeader('gmailtoken', $token);
});
}
/**
* Configures GMail via Oauth
* as the Mailer
*/
private function setGmailMailer()
{
$user = $this->resolveSendingUser();
$this->checkValidSendingUser($user);
nlog("Sending via {$user->name()}");
$google = (new Google())->init();
try {
if ($google->getClient()->isAccessTokenExpired()) {
$google->refreshToken($user);
$user = $user->fresh();
}
$google->getClient()->setAccessToken(json_encode($user->oauth_user_token));
} catch(\Exception $e) {
$this->logMailError('Gmail Token Invalid', $this->email_service->company->clients()->first());
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
/**
* If the user doesn't have a valid token, notify them
*/
if (!$user->oauth_user_token) {
$this->email_service->company->account->gmailCredentialNotification();
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
/*
* Now that our token is refreshed and valid we can boot the
* mail driver at runtime and also set the token which will persist
* just for this request.
*/
$token = $user->oauth_user_token->access_token;
if (!$token) {
$this->email_service->company->account->gmailCredentialNotification();
$this->email_service->email_object->settings->email_sending_method = 'default';
return $this->setMailDriver();
}
$this->email_mailable
->from($user->email, $user->name())
->withSymfonyMessage(function ($message) use ($token) {
$message->getHeaders()->addTextHeader('gmailtoken', $token);
});
}
/**
* Logs any errors to the SystemLog
*
* @param string $errors
* @param App\Models\User | App\Models\Client $recipient_object
* @return void
*/
private function logMailError($errors, $recipient_object) :void
{
(new SystemLogger(
$errors,
SystemLog::CATEGORY_MAIL,
SystemLog::EVENT_MAIL_SEND,
SystemLog::TYPE_FAILURE,
$recipient_object,
$this->email_service->company
))->handle();
$job_failure = new EmailFailure($this->email_service->company->company_key);
$job_failure->string_metric5 = 'failed_email';
$job_failure->string_metric6 = substr($errors, 0, 150);
LightLogs::create($job_failure)
->send();
$job_failure = null;
}
/**
* Attempts to refresh the Microsoft refreshToken
*
* @param App\Models\User
* @return mixed
*/
private function refreshOfficeToken(User $user): mixed
{
$expiry = $user->oauth_user_token_expiry ?: now()->subDay();
if ($expiry->lt(now())) {
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => config('ninja.o365.client_id') ,
'client_secret' => config('ninja.o365.client_secret') ,
'scope' => 'email Mail.Send offline_access profile User.Read openid',
'grant_type' => 'refresh_token',
'refresh_token' => $user->oauth_user_refresh_token
],
])->getBody()->getContents());
if ($token) {
$user->oauth_user_refresh_token = property_exists($token, 'refresh_token') ? $token->refresh_token : $user->oauth_user_refresh_token;
$user->oauth_user_token = $token->access_token;
$user->oauth_user_token_expiry = now()->addSeconds($token->expires_in);
$user->save();
return $token->access_token;
}
return false;
}
return $user->oauth_user_token;
}
public function failed($exception = null)
{
}
}

View File

@ -1,163 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Email;
use App\Models\Company;
use App\Utils\Ninja;
use Illuminate\Mail\Mailable;
class EmailService
{
/**
* Used to flag whether we force send the email regardless
*
* @var bool $override;
*/
protected bool $override;
public Mailable $mailable;
public function __construct(public EmailObject $email_object, public Company $company)
{
}
/**
* Sends the email via a dispatched job
* @param boolean $override Whether the email should send regardless
* @return void
*/
public function send($override = false) :void
{
$this->override = $override;
$this->setDefaults()
->updateMailable()
->email();
}
public function sendNow($force = false) :void
{
$this->setDefaults()
->updateMailable()
->email($force);
}
private function email($force = false): void
{
if ($force) {
(new EmailMailer($this, $this->mailable))->handle();
} else {
EmailMailer::dispatch($this, $this->mailable)->delay(2);
}
}
private function setDefaults(): self
{
$defaults = new EmailDefaults($this, $this->email_object);
$defaults->run();
return $this;
}
private function updateMailable()
{
$this->mailable = new EmailMailable($this->email_object);
return $this;
}
/**
* On the hosted platform we scan all outbound email for
* spam. This sequence processes the filters we use on all
* emails.
*
* @return bool
*/
public function preFlightChecksFail(): bool
{
/* If we are migrating data we don't want to fire any emails */
if ($this->company->is_disabled && !$this->override) {
return true;
}
if (Ninja::isSelfHost()) {
return false;
}
/* To handle spam users we drop all emails from flagged accounts */
if ($this->company->account && $this->company->account->is_flagged) {
return true;
}
/* On the hosted platform we set default contacts a @example.com email address - we shouldn't send emails to these types of addresses */
if ($this->hasInValidEmails()) {
return true;
}
/* GMail users are uncapped */
if (in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun'])) {
return false;
}
/* On the hosted platform, if the user is over the email quotas, we do not send the email. */
if ($this->company->account && $this->company->account->emailQuotaExceeded()) {
return true;
}
/* If the account is verified, we allow emails to flow */
if ($this->company->account && $this->company->account->is_verified_account) {
//11-01-2022
/* Continue to analyse verified accounts in case they later start sending poor quality emails*/
// if(class_exists(\Modules\Admin\Jobs\Account\EmailQuality::class))
// (new \Modules\Admin\Jobs\Account\EmailQuality($this->nmo, $this->company))->run();
return false;
}
/* On the hosted platform if the user has not verified their account we fail here - but still check what they are trying to send! */
if ($this->company->account && !$this->company->account->account_sms_verified) {
if (class_exists(\Modules\Admin\Jobs\Account\EmailFilter::class)) {
return (new \Modules\Admin\Jobs\Account\EmailFilter($this->email_object, $this->company))->run();
}
return true;
}
/* On the hosted platform we actively scan all outbound emails to ensure outbound email quality remains high */
if (class_exists(\Modules\Admin\Jobs\Account\EmailFilter::class)) {
return (new \Modules\Admin\Jobs\Account\EmailFilter($this->email_object, $this->company))->run();
}
return false;
}
private function hasInValidEmails(): bool
{
foreach ($this->email_object->to as $address_object) {
if (strpos($address_object->address, '@example.com') !== false) {
return true;
}
if (!str_contains($address_object->address, "@")) {
return true;
}
if ($address_object->address == " ") {
return true;
}
}
return false;
}
}

View File

@ -81,6 +81,7 @@
"sentry/sentry-laravel": "^3", "sentry/sentry-laravel": "^3",
"setasign/fpdf": "^1.8", "setasign/fpdf": "^1.8",
"setasign/fpdi": "^2.3", "setasign/fpdi": "^2.3",
"shopify/shopify-api": "^4.3",
"socialiteproviders/apple": "^5.2", "socialiteproviders/apple": "^5.2",
"socialiteproviders/microsoft": "^4.1", "socialiteproviders/microsoft": "^4.1",
"sprain/swiss-qr-bill": "^3.2", "sprain/swiss-qr-bill": "^3.2",

65
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "8c21eb3ea2c2baeecb223d5fdbc8423c", "content-hash": "c5abc776f4fd59ba436de99f6c401429",
"packages": [ "packages": [
{ {
"name": "adrienrn/php-mimetyper", "name": "adrienrn/php-mimetyper",
@ -9342,6 +9342,69 @@
], ],
"time": "2023-02-09T10:38:43+00:00" "time": "2023-02-09T10:38:43+00:00"
}, },
{
"name": "shopify/shopify-api",
"version": "v4.3.0",
"source": {
"type": "git",
"url": "https://github.com/Shopify/shopify-api-php.git",
"reference": "80cde593a69acb9b9095235fa8f7748e9389294c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Shopify/shopify-api-php/zipball/80cde593a69acb9b9095235fa8f7748e9389294c",
"reference": "80cde593a69acb9b9095235fa8f7748e9389294c",
"shasum": ""
},
"require": {
"doctrine/inflector": "^2.0",
"ext-json": "*",
"firebase/php-jwt": "^5.2 || ^6.2",
"guzzlehttp/guzzle": "^7.0",
"php": "^7.4 || ^8.0 || ^8.1",
"psr/http-client": "^1.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"ramsey/uuid": "^4.1"
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.6"
},
"type": "library",
"autoload": {
"psr-4": {
"Shopify\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Shopify Inc.",
"email": "dev-tools-education@shopify.com"
}
],
"description": "Shopify API Library for PHP",
"keywords": [
"Storefront API",
"admin api",
"app",
"graphql",
"jwt",
"node",
"rest",
"shopify",
"webhook"
],
"support": {
"issues": "https://github.com/Shopify/shopify-api-php/issues",
"source": "https://github.com/Shopify/shopify-api-php/tree/v4.3.0"
},
"time": "2023-04-12T15:42:26+00:00"
},
{ {
"name": "smalot/pdfparser", "name": "smalot/pdfparser",
"version": "v0.19.0", "version": "v0.19.0",

View File

@ -15,8 +15,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '5.5.113', 'app_version' => '5.5.114',
'app_tag' => '5.5.113', 'app_tag' => '5.5.114',
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''), 'api_secret' => env('API_SECRET', ''),
@ -215,4 +215,8 @@ return [
], ],
'licenses' => env('LICENSES',false), 'licenses' => env('LICENSES',false),
'google_application_credentials' => env("GOOGLE_APPLICATION_CREDENTIALS", false), 'google_application_credentials' => env("GOOGLE_APPLICATION_CREDENTIALS", false),
'shopify' => [
'client_id' => env('SHOPIFY_CLIENT_ID', null),
'client_secret' => env('SHOPIFY_CLIENT_SECRET', null),
],
]; ];

View File

@ -0,0 +1,50 @@
<?php
use App\Models\Company;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Company::query()->cursor()->each(function ($company) {
$settings = $company->settings;
if(!property_exists($settings, 'enable_e_invoice')) {
$company->saveSettings((array)$company->settings, $company);
}
});
Schema::table('users', function (Illuminate\Database\Schema\Blueprint $table) {
$table->unsignedBigInteger('shopify_user_id')->index()->nullable();
});
Schema::table('companies', function(Illuminate\Database\Schema\Blueprint $table){
$table->string('shopify_name')->index()->nullable();
$table->string('shopify_access_token')->index()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};

View File

@ -5068,6 +5068,18 @@ $LANG = array(
'tax_exempt' => 'Tax Exempt', 'tax_exempt' => 'Tax Exempt',
'late_fee_added_locked_invoice' => 'Late fee for invoice :invoice added on :date', 'late_fee_added_locked_invoice' => 'Late fee for invoice :invoice added on :date',
'lang_Khmer' => 'Khmer', 'lang_Khmer' => 'Khmer',
'routing_id' => 'Routing ID',
'enable_e_invoice' => 'Enable E-Invoice',
'e_invoice_type' => 'E-Invoice Type',
'reduced_tax' => 'Reduced Tax',
'override_tax' => 'Override Tax',
'zero_rated' => 'Zero Rated',
'reverse_tax' => 'Reverse Tax',
'updated_tax_category' => 'Successfully updated the tax category',
'updated_tax_categories' => 'Successfully updated the tax categories',
'set_tax_category' => 'Set Tax Category',
'payment_manual' => 'Payment Manual',
'expense_payment_type' => 'Expense Payment Type',
); );

View File

@ -123,7 +123,7 @@
<div> <div>
<dl> <dl>
@foreach($payment->invoices as $invoice) @foreach($payment->invoices as $invoice)
@if(!$invoice->is_proforma) @if(!$invoice->is_proforma && !$invoice->is_deleted)
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.invoice_number') }} {{ ctrans('texts.invoice_number') }}

View File

@ -1,164 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Feature\Email;
use App\Services\Email\EmailObject;
use App\Services\Email\EmailService;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Support\Facades\Cache;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Services\Email\EmailService
*/
class EmailServiceTest extends TestCase
{
use MakesHash;
use GeneratesCounter;
use MockAccountData;
public EmailService $email_service;
public EmailObject $email_object;
protected function setUp() :void
{
parent::setUp();
if (!class_exists(\Modules\Admin\Jobs\Account\EmailFilter::class)) {
$this->markTestSkipped('Skipped :: test not needed in this environment');
}
$this->makeTestData();
$this->email_object = new EmailObject();
$this->email_object->to = [new Address("testing@gmail.com", "Cool Name")];
$this->email_object->attachments = [];
$this->email_object->settings = $this->client->getMergedSettings();
$this->email_object->company = $this->client->company;
$this->email_object->client = $this->client;
$this->email_object->email_template_subject = 'email_subject_statement';
$this->email_object->email_template_body = 'email_template_statement';
$this->email_object->variables = [
'$client' => $this->client->present()->name(),
'$start_date' => '2022-01-01',
'$end_date' => '2023-01-01',
];
$this->email_service = new EmailService($this->email_object, $this->company);
}
public function testScanEmailsAttemptedFromVerifiedAccounts()
{
$email_filter = new \Modules\Admin\Jobs\Account\EmailFilter($this->email_object, $this->client->company);
Cache::put($this->account->key, 1);
config(['ninja.environment' => 'hosted']);
$this->account->account_sms_verified = true;
$this->account->is_verified_account = false;
$this->account->save();
$this->assertFalse($this->email_service->preFlightChecksFail());
collect($email_filter->getSpamKeywords())->each(function ($spam_subject) {
$this->email_object->subject = $spam_subject;
$this->assertTrue($this->email_service->preFlightChecksFail());
});
}
public function scanEmailsAttemptedFromUnverifiedAccounts()
{
config(['ninja.environment' => 'hosted']);
Cache::put($this->account->key, 1);
$this->account->account_sms_verified = false;
$this->account->save();
$this->assertTrue($this->email_service->preFlightChecksFail());
}
public function testVerifiedAccountsSkipFilters()
{
config(['ninja.environment' => 'hosted']);
Cache::put($this->account->key, 1);
$this->account->is_verified_account = true;
$this->account->save();
$this->assertFalse($this->email_service->preFlightChecksFail());
}
public function testFlaggedInvalidEmailsPrevented()
{
config(['ninja.environment' => 'hosted']);
Cache::put($this->account->key, 1);
$this->email_object->to = [new Address("user@example.com", "Cool Name")];
$this->assertTrue($this->email_service->preFlightChecksFail());
collect([
'user@example.com',
'',
'bademail',
'domain.com',
])->each(function ($email) {
$this->email_object->to = [new Address($email, "Cool Name")];
$this->assertTrue($this->email_service->preFlightChecksFail());
});
}
public function testFlaggedAccountsPrevented()
{
Cache::put($this->account->key, 1);
config(['ninja.environment' => 'hosted']);
$this->account->is_flagged = true;
$this->account->save();
$this->assertTrue($this->email_service->preFlightChecksFail());
}
public function testPreFlightChecksHosted()
{
Cache::put($this->account->key, 1);
config(['ninja.environment' => 'hosted']);
$this->assertFalse($this->email_service->preFlightChecksFail());
}
public function testPreFlightChecksSelfHost()
{
Cache::put($this->account->key, 1);
config(['ninja.environment' => 'selfhost']);
$this->assertFalse($this->email_service->preFlightChecksFail());
}
}

View File

@ -20,6 +20,7 @@ use App\Models\Company;
use App\Models\Expense; use App\Models\Expense;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\User; use App\Models\User;
use App\Utils\Traits\AppSetup;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\TestCase; use Tests\TestCase;
@ -31,6 +32,7 @@ use Tests\TestCase;
class ProductSalesReportTest extends TestCase class ProductSalesReportTest extends TestCase
{ {
use MakesHash; use MakesHash;
use AppSetup;
public $faker; public $faker;
@ -45,6 +47,8 @@ class ProductSalesReportTest extends TestCase
); );
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
$this->buildCache(true);
} }
public $company; public $company;
@ -132,7 +136,6 @@ class ProductSalesReportTest extends TestCase
{ {
$this->buildData(); $this->buildData();
$this->payload = [ $this->payload = [
'start_date' => '2000-01-01', 'start_date' => '2000-01-01',
'end_date' => '2030-01-11', 'end_date' => '2030-01-11',

View File

@ -33,6 +33,8 @@ class InvoiceTest extends TestCase
use DatabaseTransactions; use DatabaseTransactions;
use MockAccountData; use MockAccountData;
public $faker;
protected function setUp() :void protected function setUp() :void
{ {
parent::setUp(); parent::setUp();
@ -47,6 +49,24 @@ class InvoiceTest extends TestCase
} }
public function testInvoiceGetPaidReversedInvoice()
{
$this->invoice->service()->handleReversal()->save();
$this->assertEquals(6, $this->invoice->fresh()->status_id);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?status_id=6', )
->assertStatus(200);
$arr = $response->json();
$this->assertCount(1, $arr['data']);
}
public function testInvoiceGetPaidInvoices() public function testInvoiceGetPaidInvoices()
{ {
$response = $this->withHeaders([ $response = $this->withHeaders([

View File

@ -35,6 +35,10 @@ class PdfCreatorTest extends TestCase
$this->withoutMiddleware( $this->withoutMiddleware(
ThrottleRequests::class ThrottleRequests::class
); );
if(config('ninja.testvars.travis'))
$this->markTestSkipped();
} }
// public function testCreditPdfCreated() // public function testCreditPdfCreated()

View File

@ -36,6 +36,9 @@ class PdfServiceTest extends TestCase
public function testPdfGeneration() public function testPdfGeneration()
{ {
if(config('ninja.testvars.travis'))
$this->markTestSkipped();
$invitation = $this->invoice->invitations->first(); $invitation = $this->invoice->invitations->first();
$service = (new PdfService($invitation))->boot(); $service = (new PdfService($invitation))->boot();