mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #6941 from turbo124/v5-develop
Allow groups to be seen by all users
This commit is contained in:
commit
0a84ddfd9b
@ -447,8 +447,8 @@ class CheckData extends Command
|
|||||||
payments.id = paymentables.payment_id
|
payments.id = paymentables.payment_id
|
||||||
WHERE paymentable_type = 'App\\Models\\Credit'
|
WHERE paymentable_type = 'App\\Models\\Credit'
|
||||||
AND paymentables.deleted_at is NULL
|
AND paymentables.deleted_at is NULL
|
||||||
AND payments.client_id = 85;
|
AND payments.client_id = ?;
|
||||||
") );
|
"), [$client->id] );
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class ImportMigrations extends Command
|
|||||||
$user = User::factory()->create([
|
$user = User::factory()->create([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'email' => Str::random(10) . "@example.com",
|
'email' => Str::random(10) . "@example.com",
|
||||||
'confirmation_code' => $this->createDbHash(config('database.default')),
|
'confirmation_code' => $this->createDbHash($company->db),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
CompanyToken::unguard();
|
CompanyToken::unguard();
|
||||||
|
@ -65,7 +65,9 @@ class ContactRegisterController extends Controller
|
|||||||
|
|
||||||
$client_contact->client_id = $client->id;
|
$client_contact->client_id = $client->id;
|
||||||
$client_contact->is_primary = true;
|
$client_contact->is_primary = true;
|
||||||
$client_contact->password = Hash::make($data['password']);
|
|
||||||
|
if(array_key_exists('password', $data))
|
||||||
|
$client_contact->password = Hash::make($data['password']);
|
||||||
|
|
||||||
$client_contact->save();
|
$client_contact->save();
|
||||||
|
|
||||||
|
@ -257,8 +257,8 @@ class BaseController extends Controller
|
|||||||
'company.groups' => function ($query) use ($updated_at, $user) {
|
'company.groups' => function ($query) use ($updated_at, $user) {
|
||||||
$query->where('updated_at', '>=', $updated_at)->with('documents');
|
$query->where('updated_at', '>=', $updated_at)->with('documents');
|
||||||
|
|
||||||
if(!$user->isAdmin())
|
// if(!$user->isAdmin())
|
||||||
$query->where('group_settings.user_id', $user->id);
|
// $query->where('group_settings.user_id', $user->id);
|
||||||
},
|
},
|
||||||
'company.invoices'=> function ($query) use ($updated_at, $user) {
|
'company.invoices'=> function ($query) use ($updated_at, $user) {
|
||||||
$query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents');
|
$query->where('updated_at', '>=', $updated_at)->with('invitations', 'documents');
|
||||||
@ -499,8 +499,8 @@ class BaseController extends Controller
|
|||||||
'company.groups' => function ($query) use ($created_at, $user) {
|
'company.groups' => function ($query) use ($created_at, $user) {
|
||||||
$query->where('created_at', '>=', $created_at)->with('documents');
|
$query->where('created_at', '>=', $created_at)->with('documents');
|
||||||
|
|
||||||
if(!$user->isAdmin())
|
// if(!$user->isAdmin())
|
||||||
$query->where('group_settings.user_id', $user->id);
|
// $query->where('group_settings.user_id', $user->id);
|
||||||
},
|
},
|
||||||
'company.invoices'=> function ($query) use ($created_at, $user) {
|
'company.invoices'=> function ($query) use ($created_at, $user) {
|
||||||
$query->where('created_at', '>=', $created_at)->with('invitations', 'documents');
|
$query->where('created_at', '>=', $created_at)->with('invitations', 'documents');
|
||||||
|
@ -1024,7 +1024,7 @@ class CompanyImport implements ShouldQueue
|
|||||||
foreach((object)$this->getObject("users") as $user)
|
foreach((object)$this->getObject("users") as $user)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(User::where('email', $user->email)->where('account_id', '!=', $this->account->id)->exists())
|
if(User::withTrashed()->where('email', $user->email)->where('account_id', '!=', $this->account->id)->exists())
|
||||||
throw new ImportCompanyFailed("{$user->email} is already in the system attached to a different account");
|
throw new ImportCompanyFailed("{$user->email} is already in the system attached to a different account");
|
||||||
|
|
||||||
$user_array = (array)$user;
|
$user_array = (array)$user;
|
||||||
@ -1037,7 +1037,7 @@ class CompanyImport implements ShouldQueue
|
|||||||
$new_user = User::withTrashed()->firstOrNew(
|
$new_user = User::withTrashed()->firstOrNew(
|
||||||
['email' => $user->email],
|
['email' => $user->email],
|
||||||
$user_array,
|
$user_array,
|
||||||
)->restore();
|
);
|
||||||
|
|
||||||
$new_user->account_id = $this->account->id;
|
$new_user->account_id = $this->account->id;
|
||||||
$new_user->save(['timestamps' => false]);
|
$new_user->save(['timestamps' => false]);
|
||||||
@ -1067,7 +1067,7 @@ class CompanyImport implements ShouldQueue
|
|||||||
$new_cu = CompanyUser::withTrashed()->firstOrNew(
|
$new_cu = CompanyUser::withTrashed()->firstOrNew(
|
||||||
['user_id' => $user_id, 'company_id' => $this->company->id],
|
['user_id' => $user_id, 'company_id' => $this->company->id],
|
||||||
$cu_array,
|
$cu_array,
|
||||||
)->restore();
|
);
|
||||||
|
|
||||||
$new_cu->account_id = $this->account->id;
|
$new_cu->account_id = $this->account->id;
|
||||||
$new_cu->save(['timestamps' => false]);
|
$new_cu->save(['timestamps' => false]);
|
||||||
@ -1078,8 +1078,6 @@ class CompanyImport implements ShouldQueue
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function transformDocumentId($id, $type)
|
private function transformDocumentId($id, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -171,7 +171,7 @@ class SendRecurring implements ShouldQueue
|
|||||||
$this->recurring_invoice->invitations->each(function ($recurring_invitation) use($invoice){
|
$this->recurring_invoice->invitations->each(function ($recurring_invitation) use($invoice){
|
||||||
|
|
||||||
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($invoice->company->db);
|
||||||
$ii->invoice_id = $invoice->id;
|
$ii->invoice_id = $invoice->id;
|
||||||
$ii->client_contact_id = $recurring_invitation->client_contact_id;
|
$ii->client_contact_id = $recurring_invitation->client_contact_id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
|
@ -60,7 +60,7 @@ class CreateUser
|
|||||||
$user->account_id = $this->account->id;
|
$user->account_id = $this->account->id;
|
||||||
$user->password = $this->request['password'] ? bcrypt($this->request['password']) : '';
|
$user->password = $this->request['password'] ? bcrypt($this->request['password']) : '';
|
||||||
$user->accepted_terms_version = config('ninja.terms_version');
|
$user->accepted_terms_version = config('ninja.terms_version');
|
||||||
$user->confirmation_code = $this->createDbHash(config('database.default'));
|
$user->confirmation_code = $this->createDbHash($this->company->db);
|
||||||
$user->fill($this->request);
|
$user->fill($this->request);
|
||||||
$user->email = $this->request['email']; //todo need to remove this in production
|
$user->email = $this->request['email']; //todo need to remove this in production
|
||||||
$user->last_login = now();
|
$user->last_login = now();
|
||||||
|
@ -43,7 +43,7 @@ class CreateQuoteInvitation implements ShouldQueue
|
|||||||
|
|
||||||
if (! $invitation && $contact->send_credit) {
|
if (! $invitation && $contact->send_credit) {
|
||||||
$ii = QuoteInvitationFactory::create($quote->company_id, $quote->user_id);
|
$ii = QuoteInvitationFactory::create($quote->company_id, $quote->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($quote->company->db);
|
||||||
$ii->quote_id = $quote->id;
|
$ii->quote_id = $quote->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
|
@ -233,7 +233,6 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$payment = PaymentFactory::create($this->client->company->id, $this->client->user->id);
|
$payment = PaymentFactory::create($this->client->company->id, $this->client->user->id);
|
||||||
$payment->client_id = $this->client->id;
|
$payment->client_id = $this->client->id;
|
||||||
$payment->company_gateway_id = $this->company_gateway->id;
|
$payment->company_gateway_id = $this->company_gateway->id;
|
||||||
@ -386,6 +385,9 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
} else
|
} else
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
|
|
||||||
|
if(!$this->payment_hash)
|
||||||
|
throw new PaymentFailed($error, $e->getCode());
|
||||||
|
|
||||||
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
||||||
|
|
||||||
$this->sendFailureMail($error);
|
$this->sendFailureMail($error);
|
||||||
|
@ -277,7 +277,7 @@ class BaseRepository
|
|||||||
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
|
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
|
||||||
$new_invitation->{$lcfirst_resource_id} = $model->id;
|
$new_invitation->{$lcfirst_resource_id} = $model->id;
|
||||||
$new_invitation->client_contact_id = $contact->id;
|
$new_invitation->client_contact_id = $contact->id;
|
||||||
$new_invitation->key = $this->createDbHash(config('database.default'));
|
$new_invitation->key = $this->createDbHash($model->company->db);
|
||||||
$new_invitation->save();
|
$new_invitation->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ class UserRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$user->confirmation_code) {
|
if (!$user->confirmation_code) {
|
||||||
$user->confirmation_code = $this->createDbHash(config('database.default'));
|
$user->confirmation_code = $this->createDbHash($company->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->account_id = $account->id;
|
$user->account_id = $account->id;
|
||||||
|
@ -49,7 +49,7 @@ class CreateInvitations extends AbstractService
|
|||||||
|
|
||||||
if (! $invitation) {
|
if (! $invitation) {
|
||||||
$ii = CreditInvitationFactory::create($this->credit->company_id, $this->credit->user_id);
|
$ii = CreditInvitationFactory::create($this->credit->company_id, $this->credit->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($this->credit->company->db);
|
||||||
$ii->credit_id = $this->credit->id;
|
$ii->credit_id = $this->credit->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
|
@ -51,7 +51,7 @@ class CreateInvitations extends AbstractService
|
|||||||
|
|
||||||
if (! $invitation && $contact->send_email) {
|
if (! $invitation && $contact->send_email) {
|
||||||
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($this->invoice->company->db);
|
||||||
$ii->invoice_id = $this->invoice->id;
|
$ii->invoice_id = $this->invoice->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
@ -65,7 +65,7 @@ class CreateInvitations extends AbstractService
|
|||||||
$contact = $this->createBlankContact();
|
$contact = $this->createBlankContact();
|
||||||
|
|
||||||
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($this->invoice->company->db);
|
||||||
$ii->invoice_id = $this->invoice->id;
|
$ii->invoice_id = $this->invoice->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
|
@ -56,8 +56,15 @@ class HandleReversal extends AbstractService
|
|||||||
|
|
||||||
$paymentables->each(function ($paymentable) use ($total_paid) {
|
$paymentables->each(function ($paymentable) use ($total_paid) {
|
||||||
|
|
||||||
|
//new concept - when reversing, we unwind the payments
|
||||||
|
$payment = Payment::find($paymentable->payment_id);
|
||||||
|
|
||||||
$reversable_amount = $paymentable->amount - $paymentable->refunded;
|
$reversable_amount = $paymentable->amount - $paymentable->refunded;
|
||||||
$total_paid -= $reversable_amount;
|
$total_paid -= $reversable_amount;
|
||||||
|
|
||||||
|
$payment->applied -= $reversable_amount;
|
||||||
|
$payment->save();
|
||||||
|
|
||||||
$paymentable->amount = $paymentable->refunded;
|
$paymentable->amount = $paymentable->refunded;
|
||||||
$paymentable->save();
|
$paymentable->save();
|
||||||
|
|
||||||
@ -67,45 +74,45 @@ class HandleReversal extends AbstractService
|
|||||||
$notes = 'Credit for reversal of '.$this->invoice->number;
|
$notes = 'Credit for reversal of '.$this->invoice->number;
|
||||||
$credit = false;
|
$credit = false;
|
||||||
|
|
||||||
if ($total_paid > 0) {
|
// if ($total_paid > 0) {
|
||||||
|
|
||||||
$credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
// $credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||||
$credit->client_id = $this->invoice->client_id;
|
// $credit->client_id = $this->invoice->client_id;
|
||||||
$credit->invoice_id = $this->invoice->id;
|
// $credit->invoice_id = $this->invoice->id;
|
||||||
$credit->date = now();
|
// $credit->date = now();
|
||||||
|
|
||||||
$item = InvoiceItemFactory::create();
|
// $item = InvoiceItemFactory::create();
|
||||||
$item->quantity = 1;
|
// $item->quantity = 1;
|
||||||
$item->cost = (float) $total_paid;
|
// $item->cost = (float) $total_paid;
|
||||||
$item->notes = $notes;
|
// $item->notes = $notes;
|
||||||
|
|
||||||
$line_items[] = $item;
|
// $line_items[] = $item;
|
||||||
$credit->line_items = $line_items;
|
// $credit->line_items = $line_items;
|
||||||
$credit->save();
|
// $credit->save();
|
||||||
|
|
||||||
$credit_calc = new InvoiceSum($credit);
|
// $credit_calc = new InvoiceSum($credit);
|
||||||
$credit_calc->build();
|
// $credit_calc->build();
|
||||||
|
|
||||||
$credit = $credit_calc->purgeTaxes()->getCredit();
|
// $credit = $credit_calc->purgeTaxes()->getCredit();
|
||||||
$credit->service()->markSent()->save();
|
// $credit->service()->markSent()->save();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*If there is a payment linked, then the credit needs to be linked back to that payment in case of refund*/
|
/*If there is a payment linked, then the credit needs to be linked back to that payment in case of refund*/
|
||||||
if ($paymentables->count() > 0 && $credit) {
|
if ($paymentables->count() > 0 && $credit) {
|
||||||
$payment = $paymentables->first()->payment;
|
// $payment = $paymentables->first()->payment;
|
||||||
$payment->credits()->save($credit);
|
// $payment->credits()->save($credit);
|
||||||
|
|
||||||
$paymentable_credit = $payment->credits()
|
// $paymentable_credit = $payment->credits()
|
||||||
->wherePaymentableType(Credit::class)
|
// ->wherePaymentableType(Credit::class)
|
||||||
->wherePaymentableId($credit->id)
|
// ->wherePaymentableId($credit->id)
|
||||||
->first();
|
// ->first();
|
||||||
|
|
||||||
//harvest the credit record and add in the amount for the credit.
|
// //harvest the credit record and add in the amount for the credit.
|
||||||
$paymentable_credit->pivot->amount = $total_paid;
|
// $paymentable_credit->pivot->amount = $total_paid;
|
||||||
$paymentable_credit->pivot->save();
|
// $paymentable_credit->pivot->save();
|
||||||
|
|
||||||
$paymentable_credit->paid_to_date += $total_paid;
|
// $paymentable_credit->paid_to_date += $total_paid;
|
||||||
$paymentable_credit->save();
|
// $paymentable_credit->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set invoice balance to 0 */
|
/* Set invoice balance to 0 */
|
||||||
@ -124,7 +131,7 @@ class HandleReversal extends AbstractService
|
|||||||
|
|
||||||
$this->invoice->client->service()
|
$this->invoice->client->service()
|
||||||
->updateBalance($balance_remaining * -1)
|
->updateBalance($balance_remaining * -1)
|
||||||
->updatePaidToDate($total_paid * -1)
|
// ->updatePaidToDate($total_paid * -1)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
event(new InvoiceWasReversed($this->invoice, $this->invoice->company, Ninja::eventVars()));
|
event(new InvoiceWasReversed($this->invoice, $this->invoice->company, Ninja::eventVars()));
|
||||||
|
@ -112,7 +112,7 @@ class PaymentService
|
|||||||
/* Iterate through the invoices and apply credits to them */
|
/* Iterate through the invoices and apply credits to them */
|
||||||
collect($payment_hash->invoices())->each(function ($payable_invoice) use ($payment_hash) {
|
collect($payment_hash->invoices())->each(function ($payable_invoice) use ($payment_hash) {
|
||||||
|
|
||||||
$invoice = Invoice::find($this->decodePrimaryKey($payable_invoice->invoice_id));
|
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($payable_invoice->invoice_id));
|
||||||
|
|
||||||
$amount = $payable_invoice->amount;
|
$amount = $payable_invoice->amount;
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class ConvertQuote
|
|||||||
foreach($quote->invitations as $quote_invitation){
|
foreach($quote->invitations as $quote_invitation){
|
||||||
|
|
||||||
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($invoice->company->db);
|
||||||
$ii->client_contact_id = $quote_invitation->client_contact_id;
|
$ii->client_contact_id = $quote_invitation->client_contact_id;
|
||||||
|
|
||||||
$invites[] = $ii;
|
$invites[] = $ii;
|
||||||
|
@ -50,7 +50,7 @@ class CreateInvitations
|
|||||||
|
|
||||||
if (! $invitation && $contact->send_email) {
|
if (! $invitation && $contact->send_email) {
|
||||||
$ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id);
|
$ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($this->quote->company->db);
|
||||||
$ii->quote_id = $this->quote->id;
|
$ii->quote_id = $this->quote->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
|
@ -51,7 +51,7 @@ class CreateRecurringInvitations extends AbstractService
|
|||||||
|
|
||||||
if (! $invitation && $contact->send_email) {
|
if (! $invitation && $contact->send_email) {
|
||||||
$ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id);
|
$ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id);
|
||||||
$ii->key = $this->createDbHash(config('database.default'));
|
$ii->key = $this->createDbHash($this->entity->company->db);
|
||||||
$ii->{$this->entity_id_name} = $this->entity->id;
|
$ii->{$this->entity_id_name} = $this->entity->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
|
@ -216,7 +216,7 @@ Route::match(['get', 'post'], 'payment_notification_webhook/{company_key}/{compa
|
|||||||
->middleware(['guest'])
|
->middleware(['guest'])
|
||||||
->name('payment_notification_webhook');
|
->name('payment_notification_webhook');
|
||||||
|
|
||||||
Route::post('api/v1/postmark_webhook', 'PostMarkController@webhook')->middleware(['throttle:5000,1']);
|
Route::post('api/v1/postmark_webhook', 'PostMarkController@webhook')->middleware(['throttle:10000,1']);
|
||||||
Route::get('token_hash_router', 'OneTimeTokenController@router');
|
Route::get('token_hash_router', 'OneTimeTokenController@router');
|
||||||
Route::get('webcron', 'WebCronController@index');
|
Route::get('webcron', 'WebCronController@index');
|
||||||
Route::post('api/v1/get_migration_account', 'HostedMigrationController@getAccount')->middleware('guest');
|
Route::post('api/v1/get_migration_account', 'HostedMigrationController@getAccount')->middleware('guest');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user