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
|
||||
WHERE paymentable_type = 'App\\Models\\Credit'
|
||||
AND paymentables.deleted_at is NULL
|
||||
AND payments.client_id = 85;
|
||||
") );
|
||||
AND payments.client_id = ?;
|
||||
"), [$client->id] );
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ class ImportMigrations extends Command
|
||||
$user = User::factory()->create([
|
||||
'account_id' => $account->id,
|
||||
'email' => Str::random(10) . "@example.com",
|
||||
'confirmation_code' => $this->createDbHash(config('database.default')),
|
||||
'confirmation_code' => $this->createDbHash($company->db),
|
||||
]);
|
||||
|
||||
CompanyToken::unguard();
|
||||
|
@ -65,6 +65,8 @@ class ContactRegisterController extends Controller
|
||||
|
||||
$client_contact->client_id = $client->id;
|
||||
$client_contact->is_primary = true;
|
||||
|
||||
if(array_key_exists('password', $data))
|
||||
$client_contact->password = Hash::make($data['password']);
|
||||
|
||||
$client_contact->save();
|
||||
|
@ -257,8 +257,8 @@ class BaseController extends Controller
|
||||
'company.groups' => function ($query) use ($updated_at, $user) {
|
||||
$query->where('updated_at', '>=', $updated_at)->with('documents');
|
||||
|
||||
if(!$user->isAdmin())
|
||||
$query->where('group_settings.user_id', $user->id);
|
||||
// if(!$user->isAdmin())
|
||||
// $query->where('group_settings.user_id', $user->id);
|
||||
},
|
||||
'company.invoices'=> function ($query) use ($updated_at, $user) {
|
||||
$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) {
|
||||
$query->where('created_at', '>=', $created_at)->with('documents');
|
||||
|
||||
if(!$user->isAdmin())
|
||||
$query->where('group_settings.user_id', $user->id);
|
||||
// if(!$user->isAdmin())
|
||||
// $query->where('group_settings.user_id', $user->id);
|
||||
},
|
||||
'company.invoices'=> function ($query) use ($created_at, $user) {
|
||||
$query->where('created_at', '>=', $created_at)->with('invitations', 'documents');
|
||||
|
@ -1024,7 +1024,7 @@ class CompanyImport implements ShouldQueue
|
||||
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");
|
||||
|
||||
$user_array = (array)$user;
|
||||
@ -1037,7 +1037,7 @@ class CompanyImport implements ShouldQueue
|
||||
$new_user = User::withTrashed()->firstOrNew(
|
||||
['email' => $user->email],
|
||||
$user_array,
|
||||
)->restore();
|
||||
);
|
||||
|
||||
$new_user->account_id = $this->account->id;
|
||||
$new_user->save(['timestamps' => false]);
|
||||
@ -1067,7 +1067,7 @@ class CompanyImport implements ShouldQueue
|
||||
$new_cu = CompanyUser::withTrashed()->firstOrNew(
|
||||
['user_id' => $user_id, 'company_id' => $this->company->id],
|
||||
$cu_array,
|
||||
)->restore();
|
||||
);
|
||||
|
||||
$new_cu->account_id = $this->account->id;
|
||||
$new_cu->save(['timestamps' => false]);
|
||||
@ -1078,8 +1078,6 @@ class CompanyImport implements ShouldQueue
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function transformDocumentId($id, $type)
|
||||
{
|
||||
switch ($type) {
|
||||
|
@ -171,7 +171,7 @@ class SendRecurring implements ShouldQueue
|
||||
$this->recurring_invoice->invitations->each(function ($recurring_invitation) use($invoice){
|
||||
|
||||
$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->client_contact_id = $recurring_invitation->client_contact_id;
|
||||
$ii->save();
|
||||
|
@ -60,7 +60,7 @@ class CreateUser
|
||||
$user->account_id = $this->account->id;
|
||||
$user->password = $this->request['password'] ? bcrypt($this->request['password']) : '';
|
||||
$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->email = $this->request['email']; //todo need to remove this in production
|
||||
$user->last_login = now();
|
||||
|
@ -43,7 +43,7 @@ class CreateQuoteInvitation implements ShouldQueue
|
||||
|
||||
if (! $invitation && $contact->send_credit) {
|
||||
$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->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
|
@ -233,7 +233,6 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
|
||||
}
|
||||
|
||||
|
||||
$payment = PaymentFactory::create($this->client->company->id, $this->client->user->id);
|
||||
$payment->client_id = $this->client->id;
|
||||
$payment->company_gateway_id = $this->company_gateway->id;
|
||||
@ -386,6 +385,9 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
} else
|
||||
$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;
|
||||
|
||||
$this->sendFailureMail($error);
|
||||
|
@ -277,7 +277,7 @@ class BaseRepository
|
||||
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
|
||||
$new_invitation->{$lcfirst_resource_id} = $model->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();
|
||||
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
|
||||
if (!$user->confirmation_code) {
|
||||
$user->confirmation_code = $this->createDbHash(config('database.default'));
|
||||
$user->confirmation_code = $this->createDbHash($company->db);
|
||||
}
|
||||
|
||||
$user->account_id = $account->id;
|
||||
|
@ -49,7 +49,7 @@ class CreateInvitations extends AbstractService
|
||||
|
||||
if (! $invitation) {
|
||||
$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->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
|
@ -51,7 +51,7 @@ class CreateInvitations extends AbstractService
|
||||
|
||||
if (! $invitation && $contact->send_email) {
|
||||
$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->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
@ -65,7 +65,7 @@ class CreateInvitations extends AbstractService
|
||||
$contact = $this->createBlankContact();
|
||||
|
||||
$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->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
|
@ -56,8 +56,15 @@ class HandleReversal extends AbstractService
|
||||
|
||||
$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;
|
||||
$total_paid -= $reversable_amount;
|
||||
|
||||
$payment->applied -= $reversable_amount;
|
||||
$payment->save();
|
||||
|
||||
$paymentable->amount = $paymentable->refunded;
|
||||
$paymentable->save();
|
||||
|
||||
@ -67,45 +74,45 @@ class HandleReversal extends AbstractService
|
||||
$notes = 'Credit for reversal of '.$this->invoice->number;
|
||||
$credit = false;
|
||||
|
||||
if ($total_paid > 0) {
|
||||
// if ($total_paid > 0) {
|
||||
|
||||
$credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||
$credit->client_id = $this->invoice->client_id;
|
||||
$credit->invoice_id = $this->invoice->id;
|
||||
$credit->date = now();
|
||||
// $credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||
// $credit->client_id = $this->invoice->client_id;
|
||||
// $credit->invoice_id = $this->invoice->id;
|
||||
// $credit->date = now();
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = (float) $total_paid;
|
||||
$item->notes = $notes;
|
||||
// $item = InvoiceItemFactory::create();
|
||||
// $item->quantity = 1;
|
||||
// $item->cost = (float) $total_paid;
|
||||
// $item->notes = $notes;
|
||||
|
||||
$line_items[] = $item;
|
||||
$credit->line_items = $line_items;
|
||||
$credit->save();
|
||||
// $line_items[] = $item;
|
||||
// $credit->line_items = $line_items;
|
||||
// $credit->save();
|
||||
|
||||
$credit_calc = new InvoiceSum($credit);
|
||||
$credit_calc->build();
|
||||
// $credit_calc = new InvoiceSum($credit);
|
||||
// $credit_calc->build();
|
||||
|
||||
$credit = $credit_calc->purgeTaxes()->getCredit();
|
||||
$credit->service()->markSent()->save();
|
||||
}
|
||||
// $credit = $credit_calc->purgeTaxes()->getCredit();
|
||||
// $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 ($paymentables->count() > 0 && $credit) {
|
||||
$payment = $paymentables->first()->payment;
|
||||
$payment->credits()->save($credit);
|
||||
// $payment = $paymentables->first()->payment;
|
||||
// $payment->credits()->save($credit);
|
||||
|
||||
$paymentable_credit = $payment->credits()
|
||||
->wherePaymentableType(Credit::class)
|
||||
->wherePaymentableId($credit->id)
|
||||
->first();
|
||||
// $paymentable_credit = $payment->credits()
|
||||
// ->wherePaymentableType(Credit::class)
|
||||
// ->wherePaymentableId($credit->id)
|
||||
// ->first();
|
||||
|
||||
//harvest the credit record and add in the amount for the credit.
|
||||
$paymentable_credit->pivot->amount = $total_paid;
|
||||
$paymentable_credit->pivot->save();
|
||||
// //harvest the credit record and add in the amount for the credit.
|
||||
// $paymentable_credit->pivot->amount = $total_paid;
|
||||
// $paymentable_credit->pivot->save();
|
||||
|
||||
$paymentable_credit->paid_to_date += $total_paid;
|
||||
$paymentable_credit->save();
|
||||
// $paymentable_credit->paid_to_date += $total_paid;
|
||||
// $paymentable_credit->save();
|
||||
}
|
||||
|
||||
/* Set invoice balance to 0 */
|
||||
@ -124,7 +131,7 @@ class HandleReversal extends AbstractService
|
||||
|
||||
$this->invoice->client->service()
|
||||
->updateBalance($balance_remaining * -1)
|
||||
->updatePaidToDate($total_paid * -1)
|
||||
// ->updatePaidToDate($total_paid * -1)
|
||||
->save();
|
||||
|
||||
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 */
|
||||
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;
|
||||
|
||||
|
@ -77,7 +77,7 @@ class ConvertQuote
|
||||
foreach($quote->invitations as $quote_invitation){
|
||||
|
||||
$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;
|
||||
|
||||
$invites[] = $ii;
|
||||
|
@ -50,7 +50,7 @@ class CreateInvitations
|
||||
|
||||
if (! $invitation && $contact->send_email) {
|
||||
$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->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
|
@ -51,7 +51,7 @@ class CreateRecurringInvitations extends AbstractService
|
||||
|
||||
if (! $invitation && $contact->send_email) {
|
||||
$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->client_contact_id = $contact->id;
|
||||
$ii->save();
|
||||
|
@ -216,7 +216,7 @@ Route::match(['get', 'post'], 'payment_notification_webhook/{company_key}/{compa
|
||||
->middleware(['guest'])
|
||||
->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('webcron', 'WebCronController@index');
|
||||
Route::post('api/v1/get_migration_account', 'HostedMigrationController@getAccount')->middleware('guest');
|
||||
|
Loading…
x
Reference in New Issue
Block a user