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

Merge pull request #5275 from turbo124/v5-develop

Subscriptions
This commit is contained in:
David Bomba 2021-03-29 21:19:48 +11:00 committed by GitHub
commit 7c417f6ced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 7 deletions

View File

@ -16,6 +16,7 @@ use App\Http\ValidationRules\Quote\UniqueQuoteNumberRule;
use App\Models\Quote;
use App\Utils\Traits\CleanLineItems;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class StoreQuoteRequest extends Request
{
@ -48,7 +49,9 @@ class StoreQuoteRequest extends Request
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
$rules['number'] = new UniqueQuoteNumberRule($this->all());
$rules['number'] = ['nullable',Rule::unique('quotes')->where('company_id', auth()->user()->company()->id)];
// $rules['number'] = new UniqueQuoteNumberRule($this->all());
$rules['line_items'] = 'array';
return $rules;

View File

@ -67,6 +67,7 @@ class SubscriptionService
public function startTrial(array $data)
{
// Redirects from here work just fine. Livewire will respect it.
$client_contact = ClientContact::find($data['contact_id']);
if(!$this->subscription->trial_enabled)
return new \Exception("Trials are disabled for this product");
@ -76,20 +77,22 @@ class SubscriptionService
$subscription_repo = new SubscriptionRepository();
$recurring_invoice = RecurringInvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
$recurring_invoice->client_id = $client_contact->client_id;
$recurring_invoice->line_items = $subscription_repo->generateLineItems($this->subscription, true);
$recurring_invoice->subscription_id = $this->subscription->id;
$recurring_invoice->frequency_id = $this->subscription->frequency_id;
$recurring_invoice->date = now();
$recurring_invoice->next_send_date = now()->addSeconds($this->subscription->trial_duration)->addDays(1);
$recurring_invoice->next_send_date = now()->addSeconds($this->subscription->trial_duration);
$recurring_invoice->remaining_cycles = -1;
$recurring_invoice->backup = 'is_trial';
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
if(array_key_exists('coupon', $data) && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
{
$recurring_invoice->discount = $this->subscription->promo_discount;
$recurring_invoice->is_amount_discount = $this->subscription->is_amount_discount;
}
$recurring_invoice = $recurring_invoice_repo->save($data, $invoice);
$recurring_invoice = $recurring_invoice_repo->save($data, $recurring_invoice);
/* Start the recurring service */
$recurring_invoice->service()
@ -102,7 +105,7 @@ class SubscriptionService
if(strlen($this->subscription->webhook_configuration->post_purchase_url) >=1)
return redirect($this->subscription->webhook_configuration->post_purchase_url);
return redirect('/client/subscription/'.$cs->hashed_id);
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
}
public function createInvoice($data): ?\App\Models\Invoice

View File

@ -139,6 +139,7 @@ class RecurringInvoiceTransformer extends EntityTransformer
'auto_bill_enabled' => (bool) $invoice->auto_bill_enabled,
'due_date_days' => (string) $invoice->due_date_days ?: '',
'paid_to_date' => (float) $invoice->paid_to_date,
'subscription_id' => (string)$this->encodePrimaryKey($invoice->subscription_id),
];
}
}

View File

@ -160,8 +160,8 @@ class HtmlEngine
$data['$invoice.subtotal'] = &$data['$subtotal'];
if ($this->entity->partial > 0) {
$data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')];
$data['$balance_due_raw'] = ['value' => $this->entity->partial, 'label' => ctrans('texts.partial_due')];
$data['$balance_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')];
$data['$balance_due_raw'] = ['value' => $this->entity->partial, 'label' => ctrans('texts.balance_due')];
} else {
$data['$balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')];
$data['$balance_due_raw'] = ['value' => $this->entity->balance, 'label' => ctrans('texts.balance_due')];

View File

@ -17,6 +17,10 @@ class AddPriceColumnToSubscriptionsTable extends Migration
$table->decimal('price', 20, 6)->default(0);
$table->decimal('promo_price', 20, 6)->default(0);
});
Schema::table('recurring_invoices', function (Blueprint $table) {
$table->unsignedInteger('subscription_id')->nullable();
});
}
/**