diff --git a/app/Filters/QuoteFilters.php b/app/Filters/QuoteFilters.php index 9942ee909c29..5446c0532da7 100644 --- a/app/Filters/QuoteFilters.php +++ b/app/Filters/QuoteFilters.php @@ -80,7 +80,13 @@ class QuoteFilters extends QueryFilters if (in_array('expired', $status_parameters)) { $this->builder->where('status_id', Quote::STATUS_SENT) - ->where('due_date', '<=', now()->toDateString()); + ->where('due_date', '>=', now()->toDateString()); + } + + if (in_array('upcoming', $status_parameters)) { + $this->builder->where('status_id', Quote::STATUS_SENT) + ->where('due_date', '<=', now()->toDateString()) + ->orderBy('due_date', 'DESC'); } return $this->builder; diff --git a/app/Http/Controllers/BankIntegrationController.php b/app/Http/Controllers/BankIntegrationController.php index 774aa97057e8..aaa2ed88b5fe 100644 --- a/app/Http/Controllers/BankIntegrationController.php +++ b/app/Http/Controllers/BankIntegrationController.php @@ -687,7 +687,7 @@ class BankIntegrationController extends BaseController auth()->user()->account->bank_integrations->each(function ($bank_integration) { - ProcessBankTransactions::dispatchSync(auth()->user()->account->bank_integration_account_id, $bank_integration); + (new ProcessBankTransactions(auth()->user()->account->bank_integration_account_id, $bank_integration))->handle(); }); diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index bab495c2bfd6..cd4e255b43e8 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -195,6 +195,7 @@ class BillingPortalPurchasev2 extends Component public $login; public $float_amount_total; public $payment_started = false; + public $valid_coupon = false; public function mount() { @@ -308,10 +309,14 @@ class BillingPortalPurchasev2 extends Component public function handleCoupon() { - if($this->coupon == $this->subscription->promo_code) + if($this->coupon == $this->subscription->promo_code) { $this->buildBundle(); - else + $this->valid_coupon = true; + } + else{ $this->discount = 0; + $this->valid_coupon = false; + } } @@ -332,6 +337,9 @@ class BillingPortalPurchasev2 extends Component $total = $p->price * $qty; $this->bundle->push([ + 'description' => $p->notes, + 'product_key' => $p->product_key, + 'unit_cost' => $p->price, 'product' => nl2br(substr($p->notes, 0, 50)), 'price' => Number::formatMoney($total, $this->subscription->company).' / '. RecurringInvoice::frequencyForKey($this->subscription->frequency_id), 'total' => $total, @@ -348,6 +356,9 @@ class BillingPortalPurchasev2 extends Component $total = $p->price * $qty; $this->bundle->push([ + 'description' => $p->notes, + 'product_key' => $p->product_key, + 'unit_cost' => $p->price, 'product' => nl2br(substr($p->notes, 0, 50)), 'price' => Number::formatMoney($total, $this->subscription->company), 'total' => $total, @@ -375,6 +386,9 @@ class BillingPortalPurchasev2 extends Component $this->bundle->push([ + 'description' => $p->notes, + 'product_key' => $p->product_key, + 'unit_cost' => $p->price, 'product' => nl2br(substr($p->notes, 0, 50)), 'price' => Number::formatMoney($total, $this->subscription->company).' / '. RecurringInvoice::frequencyForKey($this->subscription->frequency_id), 'total' => $total, @@ -398,6 +412,9 @@ class BillingPortalPurchasev2 extends Component return; $this->bundle->push([ + 'description' => $p->notes, + 'product_key' => $p->product_key, + 'unit_cost' => $p->price, 'product' => nl2br(substr($p->notes, 0, 50)), 'price' => Number::formatMoney($total, $this->subscription->company), 'total' => $total, @@ -503,19 +520,19 @@ class BillingPortalPurchasev2 extends Component { $this->payment_started = true; - // $data = [ - // 'client_id' => $this->contact->client->id, - // 'date' => now()->format('Y-m-d'), - // 'invitations' => [[ - // 'key' => '', - // 'client_contact_id' => $this->contact->hashed_id, - // ]], - // 'user_input_promo_code' => $this->coupon, - // 'coupon' => empty($this->subscription->promo_code) ? '' : $this->coupon, - // // 'quantity' => $this->quantity, - // ]; + $data = [ + 'client_id' => $this->contact->client->id, + 'date' => now()->format('Y-m-d'), + 'invitations' => [[ + 'key' => '', + 'client_contact_id' => $this->contact->hashed_id, + ]], + 'user_input_promo_code' => $this->coupon, + 'coupon' => empty($this->subscription->promo_code) ? '' : $this->coupon, + // 'quantity' => $this->quantity, + ]; - // $is_eligible = $this->subscription->service()->isEligible($this->contact); + $is_eligible = $this->subscription->service()->isEligible($this->contact); // if (is_array($is_eligible) && $is_eligible['message'] != 'Success') { // $this->steps['not_eligible'] = true; @@ -525,14 +542,14 @@ class BillingPortalPurchasev2 extends Component // return; // } - // $this->invoice = $this->subscription - // ->service() - // ->createInvoice($data, $this->quantity) - // ->service() - // ->markSent() - // ->fillDefaults() - // ->adjustInventory() - // ->save(); + $this->invoice = $this->subscription + ->service() + ->createInvoiceV2($this->bundle, $this->contact->client_id, $this->valid_coupon) + ->service() + // ->markSent() + ->fillDefaults() + ->adjustInventory() + ->save(); // Cache::put($this->hash, [ // 'subscription_id' => $this->subscription->id, diff --git a/app/Import/Providers/Csv.php b/app/Import/Providers/Csv.php index 4da3dad96184..aee88900489b 100644 --- a/app/Import/Providers/Csv.php +++ b/app/Import/Providers/Csv.php @@ -110,7 +110,7 @@ class Csv extends BaseImport implements ImportInterface nlog("bank matching co id = {$this->company->id}"); - BankMatchingService::dispatchSync($this->company->id, $this->company->db); + (new BankMatchingService($this->company->id, $this->company->db))->handle(); } diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 7e060e532c85..ca2ef2178f14 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -426,14 +426,14 @@ class NinjaMailerJob implements ShouldQueue private function logMailError($errors, $recipient_object) { - SystemLogger::dispatchSync( + (new SystemLogger( $errors, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SEND, SystemLog::TYPE_FAILURE, $recipient_object, $this->nmo->company - ); + ))->handle(); $job_failure = new EmailFailure($this->nmo->company->company_key); $job_failure->string_metric5 = 'failed_email'; diff --git a/app/Jobs/Ninja/BankTransactionSync.php b/app/Jobs/Ninja/BankTransactionSync.php index 8afeb82aabd1..7699d951bb36 100644 --- a/app/Jobs/Ninja/BankTransactionSync.php +++ b/app/Jobs/Ninja/BankTransactionSync.php @@ -60,7 +60,7 @@ class BankTransactionSync implements ShouldQueue $account->bank_integrations()->where('auto_sync', true)->cursor()->each(function ($bank_integration) use ($account){ - ProcessBankTransactions::dispatchSync($account->bank_integration_account_id, $bank_integration); + (new ProcessBankTransactions($account->bank_integration_account_id, $bank_integration))->handle(); }); diff --git a/app/Jobs/PostMark/ProcessPostmarkWebhook.php b/app/Jobs/PostMark/ProcessPostmarkWebhook.php index 5567d9536103..cca82d47aa2b 100644 --- a/app/Jobs/PostMark/ProcessPostmarkWebhook.php +++ b/app/Jobs/PostMark/ProcessPostmarkWebhook.php @@ -142,13 +142,13 @@ class ProcessPostmarkWebhook implements ShouldQueue $this->invitation->opened_date = now(); $this->invitation->save(); - SystemLogger::dispatchSync($this->request, + (new SystemLogger($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_OPENED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company - ); + ))->handle(); } @@ -171,13 +171,13 @@ class ProcessPostmarkWebhook implements ShouldQueue $this->invitation->email_status = 'delivered'; $this->invitation->save(); - SystemLogger::dispatchSync($this->request, + (new SystemLogger($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_DELIVERY, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company - ); + ))->handle(); } // { @@ -219,7 +219,7 @@ class ProcessPostmarkWebhook implements ShouldQueue LightLogs::create($bounce)->send(); - SystemLogger::dispatchSync($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company); + (new SystemLogger($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company))->handle(); // if(config('ninja.notification.slack')) // $this->invitation->company->notification(new EmailBounceNotification($this->invitation->company->account))->ninja(); @@ -265,7 +265,7 @@ class ProcessPostmarkWebhook implements ShouldQueue LightLogs::create($spam)->send(); - SystemLogger::dispatchSync($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company); + (new SystemLogger($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company))->handle(); if(config('ninja.notification.slack')) $this->invitation->company->notification(new EmailSpamNotification($this->invitation->company->account))->ninja(); diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index 045eab8afd72..d04cc2a1d050 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -127,7 +127,7 @@ class RecurringService if($this->recurring_entity instanceof RecurringInvoice && $this->recurring_entity->status_id == RecurringInvoice::STATUS_DRAFT){ $this->start()->save(); - SendRecurring::dispatchSync($this->recurring_entity, $this->recurring_entity->company->db); + (new SendRecurring($this->recurring_entity, $this->recurring_entity->company->db))->handle(); } $this->recurring_entity = $this->recurring_entity->fresh(); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index f4256b6399aa..fbcef3d595f0 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -704,6 +704,41 @@ class SubscriptionService } + public function createInvoiceV2($bundle, $client_id, $valid_coupon = false) + { + + $invoice_repo = new InvoiceRepository(); + $subscription_repo = new SubscriptionRepository(); + + $invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id); + $invoice->subscription_id = $this->subscription->id; + $invoice->client_id = $client_id; + + $line_items = $bundle->map(function ($item){ + + $line_item = new InvoiceItem; + $line_item->product_key = $item['product_key']; + $line_item->quantity = $item['qty']; + $line_item->cost = $item['unit_cost']; + $line_item->notes = $item['description']; + + return $line_item; + + })->toArray(); + +nlog($line_items); + + $invoice->line_items = $line_items; + + if($valid_coupon){ + $invoice->discount = $this->subscription->promo_discount; + $invoice->is_amount_discount = $this->subscription->is_amount_discount; + } + + return $invoice_repo->save([], $invoice); + + } + /** * Generates the first invoice when a subscription is purchased * diff --git a/lang/en/texts.php b/lang/en/texts.php index a92f17bb603f..ed0b75459202 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4898,6 +4898,8 @@ $LANG = array( 'otp_code_message' => 'Enter the code emailed.', 'otp_code_subject' => 'Your one time passcode code', 'otp_code_body' => 'Your one time passcode is :code', + 'delete_tax_rate' => 'Delete Tax Rate', + 'restore_tax_rate' => 'Restore Tax Rate', ); return $LANG; diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php index 6c03ece2f88f..2c0aae8c4c20 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php @@ -7,8 +7,31 @@ {{ $subscription->name }} -