mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #6605 from turbo124/v5-develop
Add fixing of invitations into check data script
This commit is contained in:
commit
895bb18d17
@ -25,11 +25,11 @@ use App\Models\InvoiceInvitation;
|
|||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\Paymentable;
|
use App\Models\Paymentable;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use DB;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Mail;
|
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -103,6 +103,7 @@ class CheckData extends Command
|
|||||||
// $this->checkPaidToCompanyDates();
|
// $this->checkPaidToCompanyDates();
|
||||||
$this->checkClientBalances();
|
$this->checkClientBalances();
|
||||||
$this->checkContacts();
|
$this->checkContacts();
|
||||||
|
$this->checkEntityInvitations();
|
||||||
$this->checkCompanyData();
|
$this->checkCompanyData();
|
||||||
|
|
||||||
|
|
||||||
@ -307,13 +308,63 @@ class CheckData extends Command
|
|||||||
$invitation->company_id = $invoice->company_id;
|
$invitation->company_id = $invoice->company_id;
|
||||||
$invitation->user_id = $invoice->user_id;
|
$invitation->user_id = $invoice->user_id;
|
||||||
$invitation->invoice_id = $invoice->id;
|
$invitation->invoice_id = $invoice->id;
|
||||||
$invitation->contact_id = ClientContact::whereClientId($invoice->client_id)->whereIsPrimary(true)->first()->id;
|
$invitation->contact_id = ClientContact::whereClientId($invoice->client_id)->first()->id;
|
||||||
$invitation->invitation_key = str_random(config('ninja.key_length'));
|
$invitation->invitation_key = Str::random(config('ninja.key_length'));
|
||||||
$invitation->save();
|
$invitation->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function checkEntityInvitations()
|
||||||
|
{
|
||||||
|
|
||||||
|
$entities = ['invoice', 'quote', 'credit', 'recurring_invoice'];
|
||||||
|
|
||||||
|
foreach($entities as $entity)
|
||||||
|
{
|
||||||
|
$table = "{$entity}s";
|
||||||
|
$invitation_table = "{$entity}_invitations";
|
||||||
|
|
||||||
|
$entities = DB::table($table)
|
||||||
|
->leftJoin($invitation_table, function ($join) use($invitation_table, $table, $entity){
|
||||||
|
$join->on("{$invitation_table}.{$entity}_id", '=', "{$table}.id")
|
||||||
|
->whereNull("{$invitation_table}.deleted_at");
|
||||||
|
})
|
||||||
|
->groupBy("{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id")
|
||||||
|
->havingRaw("count({$invitation_table}.id) = 0")
|
||||||
|
->get(["{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id"]);
|
||||||
|
|
||||||
|
|
||||||
|
$this->logMessage($entities->count()." {$table} without any invitations");
|
||||||
|
|
||||||
|
if ($this->option('fix') == 'true')
|
||||||
|
$this->fixInvitations($entities, $entity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fixInvitations($entities, $entity)
|
||||||
|
{
|
||||||
|
$entity_key = "{$entity}_id";
|
||||||
|
|
||||||
|
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
||||||
|
|
||||||
|
foreach($entities as $entity)
|
||||||
|
{
|
||||||
|
$invitation = new $entity_obj();
|
||||||
|
$invitation->company_id = $entity->company_id;
|
||||||
|
$invitation->user_id = $entity->user_id;
|
||||||
|
$invitation->{$entity_key} = $entity->id;
|
||||||
|
$invitation->client_contact_id = ClientContact::whereClientId($entity->client_id)->first()->id;
|
||||||
|
$invitation->key = Str::random(config('ninja.key_length'));
|
||||||
|
$invitation->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// private function checkPaidToCompanyDates()
|
// private function checkPaidToCompanyDates()
|
||||||
// {
|
// {
|
||||||
// Company::cursor()->each(function ($company){
|
// Company::cursor()->each(function ($company){
|
||||||
|
@ -79,7 +79,7 @@ class DocumentController extends Controller
|
|||||||
$zip = new ZipStream(now() . '-documents.zip', $options);
|
$zip = new ZipStream(now() . '-documents.zip', $options);
|
||||||
|
|
||||||
foreach ($documents as $document) {
|
foreach ($documents as $document) {
|
||||||
$zip->addFileFromPath(basename($document->diskPath()), TempFile::path($document->diskPath()));
|
$zip->addFileFromPath(basename($document->diskPath()), TempFile::path($document->filePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->finish();
|
$zip->finish();
|
||||||
|
@ -121,18 +121,29 @@ class NinjaMailerJob implements ShouldQueue
|
|||||||
|
|
||||||
$message = $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
|
if($e instanceof ClientException) { //postmark specific failure
|
||||||
|
|
||||||
$response = $e->getResponse();
|
$response = $e->getResponse();
|
||||||
|
$message_body = json_decode($response->getBody()->getContents());
|
||||||
|
|
||||||
|
if(property_exists($message_body, 'Message')){
|
||||||
|
$message = $message_body->Message;
|
||||||
|
nlog($message);
|
||||||
|
}
|
||||||
|
|
||||||
nlog($response);
|
|
||||||
// $message = $response->Message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the is an entity attached to the message send a failure mailer */
|
||||||
if($this->nmo->entity)
|
if($this->nmo->entity)
|
||||||
$this->entityEmailFailed($message);
|
$this->entityEmailFailed($message);
|
||||||
|
|
||||||
if(Ninja::isHosted() && (!$e instanceof ClientException)) // Don't send postmark failures to Sentry
|
/* Don't send postmark failures to Sentry */
|
||||||
|
if(Ninja::isHosted() && (!$e instanceof ClientException))
|
||||||
app('sentry')->captureException($e);
|
app('sentry')->captureException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ class PaymentNotification implements ShouldQueue
|
|||||||
$client = $payment->client;
|
$client = $payment->client;
|
||||||
$amount = $payment->amount;
|
$amount = $payment->amount;
|
||||||
|
|
||||||
if ($invoice) {
|
if ($invoice && $invoice->line_items) {
|
||||||
$items = $invoice->line_items;
|
$items = $invoice->line_items;
|
||||||
$item = end($items)->product_key;
|
$item = end($items)->product_key;
|
||||||
$entity_number = $invoice->number;
|
$entity_number = $invoice->number;
|
||||||
|
@ -90,7 +90,7 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
'contacts.company',
|
'contacts.company',
|
||||||
// 'currency',
|
// 'currency',
|
||||||
// 'primary_contact',
|
// 'primary_contact',
|
||||||
// 'country',
|
'country',
|
||||||
// 'contacts',
|
// 'contacts',
|
||||||
// 'shipping_country',
|
// 'shipping_country',
|
||||||
// 'company',
|
// 'company',
|
||||||
@ -218,7 +218,7 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
|
|
||||||
public function assigned_user()
|
public function assigned_user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function country()
|
public function country()
|
||||||
|
@ -36,7 +36,7 @@ class CompanyLedger extends Model
|
|||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function company()
|
public function company()
|
||||||
|
@ -23,6 +23,8 @@ class CompanyToken extends BaseModel
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected $with = [
|
protected $with = [
|
||||||
|
'company',
|
||||||
|
'user'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $touches = [];
|
protected $touches = [];
|
||||||
|
@ -78,7 +78,7 @@ class CompanyUser extends Pivot
|
|||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function company()
|
public function company()
|
||||||
|
@ -120,7 +120,7 @@ class Credit extends BaseModel
|
|||||||
|
|
||||||
public function assigned_user()
|
public function assigned_user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function history()
|
public function history()
|
||||||
|
@ -84,7 +84,7 @@ class Expense extends BaseModel
|
|||||||
|
|
||||||
public function assigned_user()
|
public function assigned_user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function company()
|
public function company()
|
||||||
|
@ -52,7 +52,7 @@ class GroupSetting extends StaticModel
|
|||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clients()
|
public function clients()
|
||||||
|
@ -45,6 +45,11 @@ class Proposal extends BaseModel
|
|||||||
return $this->morphMany(Document::class, 'documentable');
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
|
}
|
||||||
|
|
||||||
public function assigned_user()
|
public function assigned_user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
||||||
|
@ -76,7 +76,7 @@ class Subscription extends BaseModel
|
|||||||
|
|
||||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextDateByInterval($date, $frequency_id)
|
public function nextDateByInterval($date, $frequency_id)
|
||||||
|
@ -66,7 +66,7 @@ class Task extends BaseModel
|
|||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function client()
|
public function client()
|
||||||
|
@ -82,7 +82,7 @@ class Vendor extends BaseModel
|
|||||||
|
|
||||||
public function assigned_user()
|
public function assigned_user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function contacts()
|
public function contacts()
|
||||||
|
@ -87,7 +87,7 @@ class Webhook extends BaseModel
|
|||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class)->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function company()
|
public function company()
|
||||||
|
@ -38,6 +38,7 @@ use App\Utils\Traits\MakesHash;
|
|||||||
use App\Utils\Traits\SubscriptionHooker;
|
use App\Utils\Traits\SubscriptionHooker;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use GuzzleHttp\RequestOptions;
|
use GuzzleHttp\RequestOptions;
|
||||||
|
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||||
|
|
||||||
class SubscriptionService
|
class SubscriptionService
|
||||||
{
|
{
|
||||||
@ -950,7 +951,12 @@ class SubscriptionService
|
|||||||
return redirect($default_redirect);
|
return redirect($default_redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function planPaid($invoice)
|
/**
|
||||||
|
* @param Invoice $invoice
|
||||||
|
* @return true
|
||||||
|
* @throws BindingResolutionException
|
||||||
|
*/
|
||||||
|
public function planPaid(Invoice $invoice)
|
||||||
{
|
{
|
||||||
$recurring_invoice_hashed_id = $invoice->recurring_invoice()->exists() ? $invoice->recurring_invoice->hashed_id : null;
|
$recurring_invoice_hashed_id = $invoice->recurring_invoice()->exists() ? $invoice->recurring_invoice->hashed_id : null;
|
||||||
|
|
||||||
@ -959,12 +965,14 @@ class SubscriptionService
|
|||||||
'subscription' => $this->subscription->hashed_id,
|
'subscription' => $this->subscription->hashed_id,
|
||||||
'recurring_invoice' => $recurring_invoice_hashed_id,
|
'recurring_invoice' => $recurring_invoice_hashed_id,
|
||||||
'client' => $invoice->client->hashed_id,
|
'client' => $invoice->client->hashed_id,
|
||||||
'contact' => $invoice->client->primary_contact()->first() ? $invoice->client->contacts->first() : false,
|
'contact' => $invoice->client->primary_contact()->first() ? $invoice->client->primary_contact()->first(): $invoice->client->contacts->first(),
|
||||||
'invoice' => $invoice->hashed_id,
|
'invoice' => $invoice->hashed_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->triggerWebhook($context);
|
$response = $this->triggerWebhook($context);
|
||||||
|
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,6 +208,7 @@ trait MockAccountData
|
|||||||
$this->cu = CompanyUserFactory::create($user->id, $this->company->id, $this->account->id);
|
$this->cu = CompanyUserFactory::create($user->id, $this->company->id, $this->account->id);
|
||||||
$this->cu->is_owner = true;
|
$this->cu->is_owner = true;
|
||||||
$this->cu->is_admin = true;
|
$this->cu->is_admin = true;
|
||||||
|
$this->cu->is_locked = false;
|
||||||
$this->cu->save();
|
$this->cu->save();
|
||||||
|
|
||||||
$this->token = \Illuminate\Support\Str::random(64);
|
$this->token = \Illuminate\Support\Str::random(64);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user