diff --git a/app/Http/Controllers/Auth/ContactRegisterController.php b/app/Http/Controllers/Auth/ContactRegisterController.php index 8efb6647ea66..409acffdd07d 100644 --- a/app/Http/Controllers/Auth/ContactRegisterController.php +++ b/app/Http/Controllers/Auth/ContactRegisterController.php @@ -58,7 +58,7 @@ class ContactRegisterController extends Controller Auth::guard('contact')->loginUsingId($client_contact->id, true); - return redirect()->intended('client.dashboard'); + return redirect()->intended(route('client.dashboard')); } private function getClient(array $data) diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index 3be67e4858e0..fa091fe9219f 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -15,6 +15,7 @@ use App\DataMapper\ClientSettings; use App\Factory\ClientFactory; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; +use App\Jobs\Subscription\CleanStaleInvoiceOrder; use App\Libraries\MultiDB; use App\Mail\ContactPasswordlessLogin; use App\Mail\Subscription\OtpCode; @@ -533,6 +534,8 @@ class BillingPortalPurchasev2 extends Component ->adjustInventory() ->save(); + CleanStaleInvoiceOrder::dispatch($this->invoice->id, $this->company->db)->delay(600); + Cache::put($this->hash, [ 'subscription_id' => $this->subscription->id, 'email' => $this->email ?? $this->contact->email, diff --git a/app/Jobs/Subscription/CleanStaleInvoiceOrder.php b/app/Jobs/Subscription/CleanStaleInvoiceOrder.php new file mode 100644 index 000000000000..63b35cc3c56c --- /dev/null +++ b/app/Jobs/Subscription/CleanStaleInvoiceOrder.php @@ -0,0 +1,55 @@ +db); + + $invoice = Invoice::withTrashed()->find($this->invoice_id); + + if($invoice->is_proforma){ + $invoice->is_proforma = false; + $repo->delete($invoice); + } + + } + + public function failed($exception = null) + { + } +} diff --git a/app/Models/Company.php b/app/Models/Company.php index 36daf77e02a4..7864220ca00d 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -129,6 +129,7 @@ class Company extends BaseModel 'invoice_task_lock', 'convert_payment_currency', 'convert_expense_currency', + 'notify_vendor_when_paid', ]; protected $hidden = [ @@ -138,6 +139,7 @@ class Company extends BaseModel ]; protected $casts = [ + 'is_proforma' => 'bool', 'country_id' => 'string', 'custom_fields' => 'object', 'settings' => 'object', diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 5c79eb531a0a..e17e3f648518 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -325,15 +325,6 @@ class BaseDriver extends AbstractPaymentDriver $invoice->service()->toggleFeesPaid()->save(); } - $transaction = [ - 'invoice' => $invoice->transaction_event(), - 'payment' => [], - 'client' => $invoice->client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::INVOICE_FEE_APPLIED, $transaction, $invoice->company->db); }); } diff --git a/app/Services/Invoice/ApplyNumber.php b/app/Services/Invoice/ApplyNumber.php index d71faf7c73ae..b3e9ec9279b2 100644 --- a/app/Services/Invoice/ApplyNumber.php +++ b/app/Services/Invoice/ApplyNumber.php @@ -42,9 +42,11 @@ class ApplyNumber extends AbstractService switch ($this->client->getSetting('counter_number_applied')) { case 'when_saved': + nlog("when saved"); $this->trySaving(); break; case 'when_sent': + nlog("when sent"); if ($this->invoice->status_id == Invoice::STATUS_SENT) { $this->trySaving(); } diff --git a/app/Services/Invoice/MarkInvoiceDeleted.php b/app/Services/Invoice/MarkInvoiceDeleted.php index e317c403ade6..4555c86d97e4 100644 --- a/app/Services/Invoice/MarkInvoiceDeleted.php +++ b/app/Services/Invoice/MarkInvoiceDeleted.php @@ -82,9 +82,6 @@ class MarkInvoiceDeleted extends AbstractService { //if total payments = adjustment amount - that means we need to delete the payments as well. -nlog($this->adjustment_amount); -nlog($this->total_payments); - if ($this->adjustment_amount == $this->total_payments) $this->invoice->payments()->update(['payments.deleted_at' => now(), 'payments.is_deleted' => true]); diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index f3cb3debfe6a..0d16ec72e14e 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -80,11 +80,19 @@ class UpdateInvoicePayment ->clearPartial() ->updateStatus() ->touchPdf() + ->workFlow() ->save(); - $invoice->service() - ->workFlow() - ->save(); + if($invoice->is_proforma) + { + $invoice->number = ''; + $invoice->is_proforma = false; + + $invoice->service() + ->applyNumber() + ->save(); + } + /* Updates the company ledger */ $this->payment @@ -101,17 +109,6 @@ class UpdateInvoicePayment $this->payment->applied += $paid_amount; - $transaction = [ - 'invoice' => $invoice->transaction_event(), - 'payment' => $this->payment->transaction_event(), - 'client' => $client->transaction_event(), - 'credit' => [], - 'metadata' => [], - ]; - - // TransactionLog::dispatch(TransactionEvent::GATEWAY_PAYMENT_MADE, $transaction, $invoice->company->db); - - }); /* Remove the event updater from within the loop to prevent race conditions */ diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 8410dfe5a6bf..31626de248c6 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -714,7 +714,8 @@ class SubscriptionService $invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id); $invoice->subscription_id = $this->subscription->id; $invoice->client_id = $client_id; - + $invoice->is_proforma = true; + $invoice->number = ctrans('texts.subscription') . "_" . now()->format('Y-m-d') . "_" . rand(0,100000); $line_items = $bundle->map(function ($item){ $line_item = new InvoiceItem; diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 8ee24b227783..2f20c5300617 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -193,6 +193,7 @@ class CompanyTransformer extends EntityTransformer 'invoice_task_lock' => (bool) $company->invoice_task_lock, 'convert_payment_currency' => (bool) $company->convert_payment_currency, 'convert_expense_currency' => (bool) $company->convert_expense_currency, + 'notify_vendor_when_paid' => (bool) $company->notify_vendor_when_paid, ]; } diff --git a/database/migrations/2022_12_20_063038_set_proforma_invoice_type.php b/database/migrations/2022_12_20_063038_set_proforma_invoice_type.php new file mode 100644 index 000000000000..28dae37d58a9 --- /dev/null +++ b/database/migrations/2022_12_20_063038_set_proforma_invoice_type.php @@ -0,0 +1,38 @@ +boolean('notify_vendor_when_paid')->default(false); + }); + + Schema::table('invoices', function (Blueprint $table) + { + $table->boolean('is_proforma')->default(false); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; diff --git a/resources/views/portal/ninja2020/generic/subscription_blocked.blade.php b/resources/views/portal/ninja2020/generic/subscription_blocked.blade.php new file mode 100644 index 000000000000..103fbdb75abe --- /dev/null +++ b/resources/views/portal/ninja2020/generic/subscription_blocked.blade.php @@ -0,0 +1,31 @@ +@extends('portal.ninja2020.layout.clean') +@section('meta_title', ctrans('texts.error')) + +@section('body') + +
{{ ctrans('texts.subscription_blocked') }}
+