mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #6180 from turbo124/v5-develop
Minor fixes for check data
This commit is contained in:
commit
c120dedaa5
@ -16,19 +16,21 @@ use App\Factory\ClientContactFactory;
|
|||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\CompanyLedger;
|
use App\Models\CompanyLedger;
|
||||||
use App\Models\Contact;
|
use App\Models\Contact;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\InvoiceInvitation;
|
use App\Models\InvoiceInvitation;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Models\Paymentable;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use DB;
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Mail;
|
use Mail;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@ -98,6 +100,7 @@ class CheckData extends Command
|
|||||||
$this->checkInvoiceBalances();
|
$this->checkInvoiceBalances();
|
||||||
$this->checkInvoicePayments();
|
$this->checkInvoicePayments();
|
||||||
$this->checkPaidToDates();
|
$this->checkPaidToDates();
|
||||||
|
// $this->checkPaidToCompanyDates();
|
||||||
$this->checkClientBalances();
|
$this->checkClientBalances();
|
||||||
$this->checkContacts();
|
$this->checkContacts();
|
||||||
$this->checkCompanyData();
|
$this->checkCompanyData();
|
||||||
@ -311,6 +314,36 @@ class CheckData extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private function checkPaidToCompanyDates()
|
||||||
|
// {
|
||||||
|
// Company::cursor()->each(function ($company){
|
||||||
|
|
||||||
|
// $payments = Payment::where('is_deleted', 0)
|
||||||
|
// ->where('company_id', $company->id)
|
||||||
|
// ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])
|
||||||
|
// ->pluck('id');
|
||||||
|
|
||||||
|
// $unapplied = Payment::where('is_deleted', 0)
|
||||||
|
// ->where('company_id', $company->id)
|
||||||
|
// ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||||
|
// ->sum(\DB::Raw('amount - applied'));
|
||||||
|
|
||||||
|
// $paymentables = Paymentable::whereIn('payment_id', $payments)->sum(\DB::Raw('amount - refunded'));
|
||||||
|
|
||||||
|
// $client_paid_to_date = Client::where('company_id', $company->id)->where('is_deleted', 0)->withTrashed()->sum('paid_to_date');
|
||||||
|
|
||||||
|
// $total_payments = $paymentables + $unapplied;
|
||||||
|
|
||||||
|
// if (round($total_payments, 2) != round($client_paid_to_date, 2)) {
|
||||||
|
// $this->wrong_paid_to_dates++;
|
||||||
|
|
||||||
|
// $this->logMessage($company->present()->name.' id = # '.$company->id." - Paid to date does not match Client Paid To Date = {$client_paid_to_date} - Invoice Payments = {$total_payments}");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
private function checkPaidToDates()
|
private function checkPaidToDates()
|
||||||
{
|
{
|
||||||
$this->wrong_paid_to_dates = 0;
|
$this->wrong_paid_to_dates = 0;
|
||||||
@ -337,12 +370,10 @@ class CheckData extends Command
|
|||||||
//commented IN 27/06/2021 - sums ALL client payments AND the unapplied amounts to match the client paid to date
|
//commented IN 27/06/2021 - sums ALL client payments AND the unapplied amounts to match the client paid to date
|
||||||
$p = Payment::where('client_id', $client->id)
|
$p = Payment::where('client_id', $client->id)
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]);
|
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||||
|
->sum(DB::Raw('amount - applied'));
|
||||||
|
|
||||||
$total_amount = $p->sum('amount');
|
$total_invoice_payments += $p;
|
||||||
$total_applied = $p->sum('applied');
|
|
||||||
|
|
||||||
$total_invoice_payments += ($total_amount - $total_applied);
|
|
||||||
|
|
||||||
// 10/02/21
|
// 10/02/21
|
||||||
foreach ($client->payments as $payment) {
|
foreach ($client->payments as $payment) {
|
||||||
|
@ -30,6 +30,7 @@ use App\Http\Middleware\QueryLogging;
|
|||||||
use App\Http\Middleware\RedirectIfAuthenticated;
|
use App\Http\Middleware\RedirectIfAuthenticated;
|
||||||
use App\Http\Middleware\SetDb;
|
use App\Http\Middleware\SetDb;
|
||||||
use App\Http\Middleware\SetDbByCompanyKey;
|
use App\Http\Middleware\SetDbByCompanyKey;
|
||||||
|
use App\Http\Middleware\SetDocumentDb;
|
||||||
use App\Http\Middleware\SetDomainNameDb;
|
use App\Http\Middleware\SetDomainNameDb;
|
||||||
use App\Http\Middleware\SetEmailDb;
|
use App\Http\Middleware\SetEmailDb;
|
||||||
use App\Http\Middleware\SetInviteDb;
|
use App\Http\Middleware\SetInviteDb;
|
||||||
@ -158,6 +159,7 @@ class Kernel extends HttpKernel
|
|||||||
'contact_key_login' => ContactKeyLogin::class,
|
'contact_key_login' => ContactKeyLogin::class,
|
||||||
'check_client_existence' => CheckClientExistence::class,
|
'check_client_existence' => CheckClientExistence::class,
|
||||||
'user_verified' => UserVerified::class,
|
'user_verified' => UserVerified::class,
|
||||||
|
'document_db' => SetDocumentDb::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
44
app/Http/Middleware/SetDocumentDb.php
Normal file
44
app/Http/Middleware/SetDocumentDb.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?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 App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
class SetDocumentDb
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$error = [
|
||||||
|
'message' => 'Document not set or not found',
|
||||||
|
'errors' => new stdClass,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($request->has('document_hash') && config('ninja.db.multi_db_enabled')) {
|
||||||
|
|
||||||
|
if (! MultiDB::documentFindAndSetDb($request->input('document_hash')))
|
||||||
|
return response()->json($error, 400);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
@ -206,6 +206,24 @@ class MultiDB
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function documentFindAndSetDb($hash) : bool
|
||||||
|
{
|
||||||
|
$current_db = config('database.default');
|
||||||
|
|
||||||
|
//multi-db active
|
||||||
|
foreach (self::$dbs as $db) {
|
||||||
|
|
||||||
|
if (Document::on($db)->where('hash', $hash)->count() >= 1){
|
||||||
|
self::setDb($db);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
self::setDB($current_db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static function findAndSetDb($token) :bool
|
public static function findAndSetDb($token) :bool
|
||||||
{
|
{
|
||||||
$current_db = config('database.default');
|
$current_db = config('database.default');
|
||||||
|
@ -23,7 +23,7 @@ Route::get('tmp_pdf/{hash}', 'ClientPortal\TempRouteController@index')->name('tm
|
|||||||
|
|
||||||
Route::get('client/key_login/{contact_key}', 'ClientPortal\ContactHashLoginController@login')->name('client.contact_login')->middleware(['domain_db','contact_key_login']);
|
Route::get('client/key_login/{contact_key}', 'ClientPortal\ContactHashLoginController@login')->name('client.contact_login')->middleware(['domain_db','contact_key_login']);
|
||||||
Route::get('client/magic_link/{magic_link}', 'ClientPortal\ContactHashLoginController@magicLink')->name('client.contact_magic_link')->middleware(['domain_db','contact_key_login']);
|
Route::get('client/magic_link/{magic_link}', 'ClientPortal\ContactHashLoginController@magicLink')->name('client.contact_magic_link')->middleware(['domain_db','contact_key_login']);
|
||||||
Route::get('documents/{document_hash}', 'ClientPortal\DocumentController@publicDownload')->name('documents.public_download');
|
Route::get('documents/{document_hash}', 'ClientPortal\DocumentController@publicDownload')->name('documents.public_download')->middleware(['document_db']);
|
||||||
Route::get('error', 'ClientPortal\ContactHashLoginController@errorPage')->name('client.error');
|
Route::get('error', 'ClientPortal\ContactHashLoginController@errorPage')->name('client.error');
|
||||||
|
|
||||||
Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence','domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () {
|
Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence','domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user