mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:07:33 -05:00 
			
		
		
		
	Add task to check company size
This commit is contained in:
		
							parent
							
								
									b14ac451c4
								
							
						
					
					
						commit
						b9c860bfc3
					
				@ -14,6 +14,7 @@ namespace App\Console;
 | 
			
		||||
use App\Jobs\Cron\RecurringInvoicesCron;
 | 
			
		||||
use App\Jobs\Ninja\AdjustEmailQuota;
 | 
			
		||||
use App\Jobs\Ninja\CheckDbStatus;
 | 
			
		||||
use App\Jobs\Ninja\CompanySizeCheck;
 | 
			
		||||
use App\Jobs\Util\ReminderJob;
 | 
			
		||||
use App\Jobs\Util\SendFailedEmails;
 | 
			
		||||
use App\Jobs\Util\UpdateExchangeRates;
 | 
			
		||||
@ -47,6 +48,8 @@ class Kernel extends ConsoleKernel
 | 
			
		||||
 | 
			
		||||
        $schedule->job(new ReminderJob)->daily();
 | 
			
		||||
 | 
			
		||||
        $schedule->job(new CompanySizeCheck)->daily();
 | 
			
		||||
 | 
			
		||||
        $schedule->job(new UpdateExchangeRates)->daily();
 | 
			
		||||
        
 | 
			
		||||
        /* Run hosted specific jobs */
 | 
			
		||||
 | 
			
		||||
@ -293,7 +293,7 @@ class BaseController extends Controller
 | 
			
		||||
         * Thresholds for displaying large account on first load
 | 
			
		||||
         */
 | 
			
		||||
        if (request()->has('first_load') && request()->input('first_load') == 'true') {
 | 
			
		||||
            if (auth()->user()->getCompany()->invoices->count() > 1000 || auth()->user()->getCompany()->products->count() > 1000 || auth()->user()->getCompany()->clients->count() > 1000) {
 | 
			
		||||
            if (auth()->user()->getCompany()->is_large) {
 | 
			
		||||
                $data = $mini_load;
 | 
			
		||||
            } else {
 | 
			
		||||
                $data = $first_load;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										77
									
								
								app/Jobs/Ninja/CompanySizeCheck.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								app/Jobs/Ninja/CompanySizeCheck.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,77 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Invoice Ninja (https://invoiceninja.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://opensource.org/licenses/AAL
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App\Jobs\Ninja;
 | 
			
		||||
 | 
			
		||||
use App\Helpers\Email\InvoiceEmail;
 | 
			
		||||
use App\Jobs\Invoice\EmailInvoice;
 | 
			
		||||
use App\Libraries\MultiDB;
 | 
			
		||||
use App\Models\Account;
 | 
			
		||||
use App\Models\Company;
 | 
			
		||||
use Illuminate\Bus\Queueable;
 | 
			
		||||
use Illuminate\Contracts\Queue\ShouldQueue;
 | 
			
		||||
use Illuminate\Foundation\Bus\Dispatchable;
 | 
			
		||||
use Illuminate\Queue\InteractsWithQueue;
 | 
			
		||||
use Illuminate\Queue\SerializesModels;
 | 
			
		||||
 | 
			
		||||
class CompanySizeCheck implements ShouldQueue
 | 
			
		||||
{
 | 
			
		||||
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new job instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute the job.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        if (! config('ninja.db.multi_db_enabled')) {
 | 
			
		||||
            $this->check();
 | 
			
		||||
        } else {
 | 
			
		||||
            //multiDB environment, need to
 | 
			
		||||
            foreach (MultiDB::$dbs as $db) {
 | 
			
		||||
 | 
			
		||||
                MultiDB::setDB($db);
 | 
			
		||||
 | 
			
		||||
                $this->check();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function check()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    	Company::cursor()->each(function ($company)
 | 
			
		||||
    	{
 | 
			
		||||
 | 
			
		||||
    		if($company->invoices->count() > 1000 || $company->products->count() > 1000 || $company->clients->count() > 1000)
 | 
			
		||||
    		{
 | 
			
		||||
    			$company->is_large = true;
 | 
			
		||||
    			$company->save();
 | 
			
		||||
    		}
 | 
			
		||||
 | 
			
		||||
    	});
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -27,6 +27,8 @@ class Gateway extends StaticModel
 | 
			
		||||
        'fields' => 'json',
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    protected $dateFormat = 'Y-m-d H:i:s.u';
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @return mixed
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,30 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
use Illuminate\Database\Migrations\Migration;
 | 
			
		||||
use Illuminate\Database\Schema\Blueprint;
 | 
			
		||||
use Illuminate\Support\Facades\Schema;
 | 
			
		||||
 | 
			
		||||
class CompanyTooLargeAttribute extends Migration
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Run the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function up()
 | 
			
		||||
    {
 | 
			
		||||
        Schema::table('companies', function (Blueprint $table) {
 | 
			
		||||
            $table->boolean('is_large')->default(0);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reverse the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function down()
 | 
			
		||||
    {
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user