1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Refactor Livewire passing references

This commit is contained in:
David Bomba 2022-12-23 11:33:14 +11:00
parent 9e84f6c10f
commit d4356af782
9 changed files with 49 additions and 47 deletions

View File

@ -35,7 +35,7 @@ class SubscriptionPlanSwitchController extends Controller
->service()
->calculateUpgradePriceV2($recurring_invoice, $target);
nlog("upgrade amoutn = {$amount}");
nlog("payment amount = {$amount}");
/**
* Null value here is a proxy for
* denying the user a change plan option
@ -44,6 +44,9 @@ class SubscriptionPlanSwitchController extends Controller
render('subscriptions.denied');
}
$amount = max(0,$amount);
return render('subscriptions.switch', [
'subscription' => $recurring_invoice->subscription,
'recurring_invoice' => $recurring_invoice,

View File

@ -121,7 +121,7 @@ class BillingPortalPurchasev2 extends Component
*
* @var array
*/
public $request_data;
public $request_data = [];
/**
* Instance of company.
@ -130,7 +130,13 @@ class BillingPortalPurchasev2 extends Component
*/
public $company;
public $db;
/**
* Instance of company.
*
* @var string
*/
public string $db;
/**
* Campaign reference.

View File

@ -13,6 +13,7 @@
namespace App\Http\Livewire;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Models\Credit;
use App\Utils\Traits\WithSorting;
use Livewire\Component;
@ -23,26 +24,31 @@ class CreditsTable extends Component
use WithPagination;
use WithSorting;
public $per_page = 10;
public int $per_page = 10;
public $company;
public Company $company;
public string $db;
public int $company_id;
public function mount()
{
MultiDB::setDb($this->company->db);
MultiDB::setDb($this->db);
$this->company = Company::find($this->company_id);
}
public function render()
{
$query = Credit::query()
->where('client_id', auth()->guard('contact')->user()->client_id)
->where('company_id', $this->company->id)
->where('client_id', auth()->guard('contact')->user()->client_id)
->where('status_id', '<>', Credit::STATUS_DRAFT)
->where('is_deleted', 0)
->where(function ($query) {
$query->whereDate('due_date', '>=', now())
->orWhereNull('due_date');
//->orWhere('due_date', '=', '');
})
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->withTrashed()

View File

@ -14,6 +14,7 @@ namespace App\Http\Livewire;
use App\Libraries\MultiDB;
use App\Models\Client;
use App\Models\Company;
use App\Models\Credit;
use App\Models\Document;
use App\Models\Expense;
@ -31,21 +32,27 @@ class DocumentsTable extends Component
{
use WithPagination, WithSorting;
public $client;
public Company $company;
public $per_page = 10;
public Client $client;
public $company;
public int $client_id;
public int $per_page = 10;
public string $tab = 'documents';
public string $db;
protected $query;
public function mount($client)
public function mount()
{
MultiDB::setDb($this->company->db);
MultiDB::setDb($this->db);
$this->client = $client;
$this->client = Client::with('company')->find($this->client_id);
$this->company = $this->client->company;
$this->query = $this->documents();
}

View File

@ -100,6 +100,7 @@ class SubscriptionService
//update the invoice and attach to the recurring invoice!!!!!
$invoice = Invoice::find($payment_hash->fee_invoice_id);
$invoice->recurring_id = $recurring_invoice->id;
$invoice->is_proforma = false;
$invoice->save();
//execute any webhooks
@ -253,6 +254,7 @@ class SubscriptionService
}
nlog("{$target->price} - {$refund} - {$outstanding_credit}");
return $target->price - $refund - $outstanding_credit;
}
@ -346,7 +348,7 @@ class SubscriptionService
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
return $pro_rata_refund;
return max(0, $pro_rata_refund);
}
@ -472,6 +474,7 @@ class SubscriptionService
$pro_rata_charge_amount = 0;
$pro_rata_refund_amount = 0;
$is_credit = false;
$credit = false;
/* Get last invoice */
$last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
@ -483,9 +486,8 @@ class SubscriptionService
->orderBy('id', 'desc')
->first();
// $pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription);
$credit = $this->createCredit($last_invoice, $target_subscription, false);
if($this->calculateProRataRefundForSubscription($last_invoice) > 0)
$credit = $this->createCredit($last_invoice, $target_subscription, false);
$new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice);
@ -513,12 +515,7 @@ class SubscriptionService
$response = $this->triggerWebhook($context);
if($credit){
return '/client/invoices/'.$invoice->hashed_id;
}
else{
return '/client/invoices';
}
return '/client/recurring_invoices/'.$new_recurring_invoice->hashed_id;
}
@ -783,9 +780,6 @@ class SubscriptionService
$credit->discount = $last_invoice->discount;
$credit->is_amount_discount = $last_invoice->is_amount_discount;
// $line_items = $subscription_repo->generateLineItems($target, false, true);
// $credit->line_items = array_merge($line_items, $this->calculateProRataRefundItems($last_invoice, $last_invoice_is_credit));
$credit->line_items = $this->calculateProRataRefundItems($last_invoice, true);
$data = [
@ -816,6 +810,7 @@ class SubscriptionService
$invoice->subscription_id = $target->id;
$invoice->line_items = array_merge($subscription_repo->generateLineItems($target), $this->calculateProRataRefundItems($last_invoice));
$invoice->is_proforma = true;
$data = [
'client_id' => $client_id,
@ -848,6 +843,7 @@ class SubscriptionService
$invoice->subscription_id = $target->id;
$invoice->line_items = $subscription_repo->generateLineItems($target);
$invoice->is_proforma = true;
$data = [
'client_id' => $client_id,
@ -914,6 +910,7 @@ class SubscriptionService
$invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
$invoice->line_items = $subscription_repo->generateLineItems($this->subscription);
$invoice->subscription_id = $this->subscription->id;
$invoice->is_proforman = true;
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
{
@ -925,7 +922,6 @@ class SubscriptionService
$invoice->is_amount_discount = $this->subscription->is_amount_discount;
}
return $invoice_repo->save($data, $invoice);
}
@ -1247,8 +1243,6 @@ class SubscriptionService
});
return $this->handleRedirect('client/subscriptions');
}

View File

@ -190,7 +190,7 @@ return [
'ninja_stripe_client_id' => env('NINJA_STRIPE_CLIENT_ID', null),
'ninja_default_company_id' => env('NINJA_COMPANY_ID', null),
'ninja_default_company_gateway_id' => env('NINJA_COMPANY_GATEWAY_ID', null),
'ninja_hosted_secret' => env('NINJA_HOSTED_SECRET', null),
'ninja_hosted_secret' => env('NINJA_HOSTED_SECRET', ''),
'ninja_hosted_header' =>env('NINJA_HEADER',''),
'internal_queue_enabled' => env('INTERNAL_QUEUE_ENABLED', true),
'ninja_apple_api_key' => env('APPLE_API_KEY', false),

View File

@ -13,6 +13,6 @@
@section('body')
<div class="flex flex-col">
@livewire('credits-table', ['company' => $company])
@livewire('credits-table', ['company_id' => $company->id, 'db' => $company->db])
</div>
@endsection

View File

@ -34,7 +34,6 @@
@include('portal.ninja2020.components.entity-documents', ['entity' => $credit])
@include('portal.ninja2020.components.pdf-viewer', ['entity' => $credit, 'invitation' => $invitation])
@endsection
@ -45,18 +44,5 @@
var clipboard = new ClipboardJS('.btn');
// clipboard.on('success', function(e) {
// console.info('Action:', e.action);
// console.info('Text:', e.text);
// console.info('Trigger:', e.trigger);
// e.clearSelection();
// });
// clipboard.on('error', function(e) {
// console.error('Action:', e.action);
// console.error('Trigger:', e.trigger);
// });
</script>
@endsection

View File

@ -14,5 +14,5 @@
@csrf
</form>
@livewire('documents-table', ['client' => $client, 'company' => $company])
@livewire('documents-table', ['client_id' => $client->id, 'db' => $company->db])
@endsection