mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge pull request #3884 from turbo124/v2
Fixes for Checkdata script and PDF Previews
This commit is contained in:
commit
bbdfb86b99
@ -325,23 +325,17 @@ class CheckData extends Command
|
||||
|
||||
Client::withTrashed()->cursor()->each(function ($client) use($wrong_paid_to_dates){
|
||||
|
||||
$total_invoice_payments = 0;
|
||||
|
||||
$client->invoices->where('is_deleted', false)->each(function ($invoice) use($total_invoice_payments, $wrong_paid_to_dates){
|
||||
$total_invoice_payments = 0;
|
||||
|
||||
foreach($client->invoices->where('is_deleted', false) as $invoice)
|
||||
{
|
||||
$total_amount = $invoice->payments->sum('pivot.amount');
|
||||
$total_refund = $invoice->payments->sum('pivot.refunded');
|
||||
|
||||
info("Pivot = " . $total_amount . " - " . $total_refund);
|
||||
|
||||
$total_invoice_payments += ($total_amount - $total_refund);
|
||||
|
||||
info($total_invoice_payments);
|
||||
});
|
||||
|
||||
info($total_invoice_payments . " = ". $client->paid_to_date);
|
||||
|
||||
if($total_invoice_payments != $client->paid_to_date) {
|
||||
}
|
||||
|
||||
if(round($total_invoice_payments,2) != round($client->paid_to_date,2)) {
|
||||
$wrong_paid_to_dates++;
|
||||
|
||||
$this->logMessage($client->present()->name . " - " . $client->id . " - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_invoice_payments}");
|
||||
|
@ -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;
|
||||
|
@ -18,6 +18,7 @@ use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Jobs\Util\PreviewPdf;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PreviewController extends BaseController
|
||||
@ -155,7 +156,7 @@ class PreviewController extends BaseController
|
||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||
}
|
||||
|
||||
$designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
|
||||
$designer = new Designer($invoice, $design_object, auth()->user()->company()->settings->pdf_variables, lcfirst(request()->has('entity')));
|
||||
|
||||
$html = $this->generateEntityHtml($designer, $invoice, $contact);
|
||||
|
||||
@ -165,6 +166,9 @@ class PreviewController extends BaseController
|
||||
$contact->forceDelete();
|
||||
$client->forceDelete();
|
||||
|
||||
return response()->file($file_path, array('content-type' => 'application/pdf'));
|
||||
$response = Response::make($file_path, 200);
|
||||
$response->header('Content-Type', 'application/pdf');
|
||||
return $response;
|
||||
|
||||
}
|
||||
}
|
||||
|
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();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -33,14 +33,10 @@ use Spatie\Browsershot\Browsershot;
|
||||
|
||||
class PreviewPdf implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
|
||||
|
||||
public $invoice;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PdfMaker;
|
||||
|
||||
public $company;
|
||||
|
||||
public $contact;
|
||||
|
||||
private $disk;
|
||||
|
||||
public $design_string;
|
||||
@ -61,16 +57,8 @@ class PreviewPdf implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$path = $this->company->company_key;
|
||||
|
||||
//Storage::makeDirectory($path, 0755);
|
||||
return $this->makePdf(null, null, $this->design_string);
|
||||
|
||||
$file_path = $path . '/stream.pdf';
|
||||
|
||||
$pdf = $this->makePdf(null, null, $this->design_string);
|
||||
|
||||
$instance = Storage::disk('local')->put($file_path, $pdf);
|
||||
|
||||
return storage_path('app') .'/'. $file_path;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ class Gateway extends StaticModel
|
||||
'fields' => 'json',
|
||||
];
|
||||
|
||||
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -71,7 +71,8 @@ class DeletePayment
|
||||
|
||||
$paymentable_invoice->service()->updateBalance($paymentable_invoice->pivot->amount)->save();
|
||||
$paymentable_invoice->ledger()->updateInvoiceBalance($paymentable_invoice->pivot->amount)->save();
|
||||
|
||||
$paymentable_invoice->client->service()->updateBalance($paymentable_invoice->pivot->amount)->save();
|
||||
|
||||
if(floatval($paymentable_invoice->balance) == 0)
|
||||
$paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save();
|
||||
else
|
||||
|
@ -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