diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 42f657fb415f..34744782fa82 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -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}"); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index c6f9ab71ff2a..5327459eb90a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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 */ diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 5e90ad1ed17a..2c4ff1fc26e8 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -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; diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index c800d3a02f84..750a76476ea7 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -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; + } } diff --git a/app/Jobs/Ninja/CompanySizeCheck.php b/app/Jobs/Ninja/CompanySizeCheck.php new file mode 100644 index 000000000000..3b06d793ea83 --- /dev/null +++ b/app/Jobs/Ninja/CompanySizeCheck.php @@ -0,0 +1,77 @@ +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(); + } + + }); + + } + +} diff --git a/app/Jobs/Util/PreviewPdf.php b/app/Jobs/Util/PreviewPdf.php index ebd57aa71b72..298bb61ca5ea 100644 --- a/app/Jobs/Util/PreviewPdf.php +++ b/app/Jobs/Util/PreviewPdf.php @@ -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; } } diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 1132d59e3588..56825e801481 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -27,6 +27,8 @@ class Gateway extends StaticModel 'fields' => 'json', ]; + protected $dateFormat = 'Y-m-d H:i:s.u'; + /** * @return mixed */ diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 11b29c370693..f4ad8fbb23f2 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -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 diff --git a/database/migrations/2020_07_05_084934_company_too_large_attribute.php b/database/migrations/2020_07_05_084934_company_too_large_attribute.php new file mode 100644 index 000000000000..a87cdbec2fa0 --- /dev/null +++ b/database/migrations/2020_07_05_084934_company_too_large_attribute.php @@ -0,0 +1,30 @@ +boolean('is_large')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}