mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge branch 'v5-develop' into v5-1304-emails
This commit is contained in:
commit
873fe6ce07
@ -1,6 +1,14 @@
|
||||
# Release notes
|
||||
|
||||
## [Unreleased (daily channel)](https://github.com/invoiceninja/invoiceninja/tree/v5-develop)
|
||||
## Fixed:
|
||||
- Refactor of e-mail templates
|
||||
- Client portal: Invoices & recurring invoices are now sorted by date (by default)
|
||||
|
||||
## Added:
|
||||
- Public notes of entities will now show in #footer section of designs (previously totals table).
|
||||
|
||||
## [v5.1.47-release](https://github.com/invoiceninja/invoiceninja/releases/tag/v5.1.47-release)
|
||||
|
||||
### Added:
|
||||
- Subscriptions are now going to show the frequency in the table (#5412)
|
||||
|
@ -1 +1 @@
|
||||
5.1.43
|
||||
5.1.47
|
@ -32,6 +32,7 @@ use App\Models\Expense;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
@ -227,9 +228,19 @@ class CreateSingleAccount extends Command
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'product_key' => 'enterprise_plan',
|
||||
'notes' => 'The Pro Plan',
|
||||
'cost' => 10,
|
||||
'price' => 10,
|
||||
'notes' => 'The Enterprise Plan',
|
||||
'cost' => 14,
|
||||
'price' => 14,
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
$p3 = Product::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'product_key' => 'free_plan',
|
||||
'notes' => 'The Free Plan',
|
||||
'cost' => 0,
|
||||
'price' => 0,
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
@ -245,6 +256,7 @@ class CreateSingleAccount extends Command
|
||||
$sub->recurring_product_ids = "{$p1->hashed_id}";
|
||||
$sub->webhook_configuration = $webhook_config;
|
||||
$sub->allow_plan_changes = true;
|
||||
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
|
||||
$sub->save();
|
||||
|
||||
$sub = SubscriptionFactory::create($company->id, $user->id);
|
||||
@ -253,6 +265,16 @@ class CreateSingleAccount extends Command
|
||||
$sub->recurring_product_ids = "{$p2->hashed_id}";
|
||||
$sub->webhook_configuration = $webhook_config;
|
||||
$sub->allow_plan_changes = true;
|
||||
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
|
||||
$sub->save();
|
||||
|
||||
$sub = SubscriptionFactory::create($company->id, $user->id);
|
||||
$sub->name = "Free Plan";
|
||||
$sub->group_id = $gs->id;
|
||||
$sub->recurring_product_ids = "{$p3->hashed_id}";
|
||||
$sub->webhook_configuration = $webhook_config;
|
||||
$sub->allow_plan_changes = true;
|
||||
$sub->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
|
||||
$sub->save();
|
||||
}
|
||||
|
||||
|
@ -388,20 +388,20 @@ class DemoMode extends Command
|
||||
$invoice->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name1 = 'GST';
|
||||
$invoice->tax_rate1 = 10.00;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice->tax_name1 = 'GST';
|
||||
// $invoice->tax_rate1 = 10.00;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name2 = 'VAT';
|
||||
$invoice->tax_rate2 = 17.50;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice->tax_name2 = 'VAT';
|
||||
// $invoice->tax_rate2 = 17.50;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name3 = 'CA Sales Tax';
|
||||
$invoice->tax_rate3 = 5;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice->tax_name3 = 'CA Sales Tax';
|
||||
// $invoice->tax_rate3 = 5;
|
||||
// }
|
||||
|
||||
// $invoice->custom_value1 = $faker->date;
|
||||
// $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
|
||||
@ -455,20 +455,20 @@ class DemoMode extends Command
|
||||
$invoice->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name1 = 'GST';
|
||||
$invoice->tax_rate1 = 10.00;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice->tax_name1 = 'GST';
|
||||
// $invoice->tax_rate1 = 10.00;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name2 = 'VAT';
|
||||
$invoice->tax_rate2 = 17.50;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice->tax_name2 = 'VAT';
|
||||
// $invoice->tax_rate2 = 17.50;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name3 = 'CA Sales Tax';
|
||||
$invoice->tax_rate3 = 5;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice->tax_name3 = 'CA Sales Tax';
|
||||
// $invoice->tax_rate3 = 5;
|
||||
// }
|
||||
|
||||
// $invoice->custom_value1 = $faker->date;
|
||||
// $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
|
||||
@ -504,20 +504,20 @@ class DemoMode extends Command
|
||||
$credit->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$credit->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$credit->tax_name1 = 'GST';
|
||||
$credit->tax_rate1 = 10.00;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $credit->tax_name1 = 'GST';
|
||||
// $credit->tax_rate1 = 10.00;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$credit->tax_name2 = 'VAT';
|
||||
$credit->tax_rate2 = 17.50;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $credit->tax_name2 = 'VAT';
|
||||
// $credit->tax_rate2 = 17.50;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$credit->tax_name3 = 'CA Sales Tax';
|
||||
$credit->tax_rate3 = 5;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $credit->tax_name3 = 'CA Sales Tax';
|
||||
// $credit->tax_rate3 = 5;
|
||||
// }
|
||||
|
||||
$credit->save();
|
||||
|
||||
@ -559,20 +559,20 @@ class DemoMode extends Command
|
||||
$quote->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$quote->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name1 = 'GST';
|
||||
$quote->tax_rate1 = 10.00;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $quote->tax_name1 = 'GST';
|
||||
// $quote->tax_rate1 = 10.00;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name2 = 'VAT';
|
||||
$quote->tax_rate2 = 17.50;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $quote->tax_name2 = 'VAT';
|
||||
// $quote->tax_rate2 = 17.50;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name3 = 'CA Sales Tax';
|
||||
$quote->tax_rate3 = 5;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $quote->tax_name3 = 'CA Sales Tax';
|
||||
// $quote->tax_rate3 = 5;
|
||||
// }
|
||||
|
||||
$quote->save();
|
||||
|
||||
@ -600,20 +600,20 @@ class DemoMode extends Command
|
||||
$item->quantity = 1;
|
||||
//$item->cost = 10;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'GST';
|
||||
$item->tax_rate1 = 10.00;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $item->tax_name1 = 'GST';
|
||||
// $item->tax_rate1 = 10.00;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'VAT';
|
||||
$item->tax_rate1 = 17.50;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $item->tax_name1 = 'VAT';
|
||||
// $item->tax_rate1 = 17.50;
|
||||
// }
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'Sales Tax';
|
||||
$item->tax_rate1 = 5;
|
||||
}
|
||||
// if (rand(0, 1)) {
|
||||
// $item->tax_name1 = 'Sales Tax';
|
||||
// $item->tax_rate1 = 5;
|
||||
// }
|
||||
|
||||
$product = Product::all()->random();
|
||||
|
||||
|
@ -68,6 +68,11 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
}
|
||||
|
||||
if(config('queue.default') == 'database' && Ninja::isSelfHost()) {
|
||||
$schedule->command('queue:work')->everyMinute()->withoutOverlapping();
|
||||
$schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ class TaskStatusFactory
|
||||
$task_status->company_id = $company_id;
|
||||
$task_status->name = '';
|
||||
$task_status->color = '#fff';
|
||||
$task_status->status_order = 9999;
|
||||
|
||||
return $task_status;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\SystemLog;
|
||||
use App\Services\Subscription\SubscriptionService;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -342,6 +343,12 @@ class PaymentController extends Controller
|
||||
|
||||
$payment = $payment->service()->applyCredits($payment_hash)->save();
|
||||
|
||||
if (property_exists($payment_hash->data, 'billing_context')) {
|
||||
$billing_subscription = \App\Models\Subscription::find($payment_hash->data->billing_context->subscription_id);
|
||||
|
||||
return (new SubscriptionService($billing_subscription))->completePurchase($payment_hash);
|
||||
}
|
||||
|
||||
return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ use App\Http\Requests\ClientPortal\Subscriptions\ShowPlanSwitchRequest;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SubscriptionPlanSwitchController extends Controller
|
||||
{
|
||||
@ -30,11 +31,10 @@ class SubscriptionPlanSwitchController extends Controller
|
||||
*/
|
||||
public function index(ShowPlanSwitchRequest $request, RecurringInvoice $recurring_invoice, Subscription $target)
|
||||
{
|
||||
|
||||
|
||||
$amount = $recurring_invoice->subscription
|
||||
->service()
|
||||
->calculateUpgradePrice($recurring_invoice, $target);
|
||||
|
||||
/**
|
||||
*
|
||||
* Null value here is a proxy for
|
||||
|
@ -592,7 +592,7 @@ class PaymentController extends BaseController
|
||||
$this->payment_repo->restore($payment);
|
||||
|
||||
if (! $bulk) {
|
||||
return $this->listResponse($payment);
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -600,7 +600,7 @@ class PaymentController extends BaseController
|
||||
$this->payment_repo->archive($payment);
|
||||
|
||||
if (! $bulk) {
|
||||
return $this->listResponse($payment);
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
// code...
|
||||
break;
|
||||
@ -608,14 +608,26 @@ class PaymentController extends BaseController
|
||||
$this->payment_repo->delete($payment);
|
||||
|
||||
if (! $bulk) {
|
||||
return $this->listResponse($payment);
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
// code...
|
||||
break;
|
||||
case 'email':
|
||||
//dispatch email to queue
|
||||
break;
|
||||
$payment->service()->sendEmail();
|
||||
|
||||
if (! $bulk) {
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
break;
|
||||
case 'email_receipt':
|
||||
$this->payment->service()->sendEmail();
|
||||
|
||||
if (! $bulk) {
|
||||
return $this->itemResponse($payment);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// code...
|
||||
break;
|
||||
@ -671,6 +683,8 @@ class PaymentController extends BaseController
|
||||
{
|
||||
$payment = $request->payment();
|
||||
|
||||
// nlog($request->all());
|
||||
|
||||
$payment = $payment->refund($request->all());
|
||||
|
||||
return $this->itemResponse($payment);
|
||||
|
@ -85,7 +85,7 @@ class SelfUpdateController extends BaseController
|
||||
|
||||
Artisan::call('clear-compiled');
|
||||
Artisan::call('cache:clear');
|
||||
Artisan::call('debugbar:clear');
|
||||
// Artisan::call('debugbar:clear');
|
||||
Artisan::call('route:clear');
|
||||
Artisan::call('view:clear');
|
||||
Artisan::call('config:clear');
|
||||
|
@ -19,11 +19,13 @@ use App\Http\Requests\Task\CreateTaskRequest;
|
||||
use App\Http\Requests\Task\DestroyTaskRequest;
|
||||
use App\Http\Requests\Task\EditTaskRequest;
|
||||
use App\Http\Requests\Task\ShowTaskRequest;
|
||||
use App\Http\Requests\Task\SortTaskRequest;
|
||||
use App\Http\Requests\Task\StoreTaskRequest;
|
||||
use App\Http\Requests\Task\UpdateTaskRequest;
|
||||
use App\Http\Requests\Task\UploadTaskRequest;
|
||||
use App\Models\Account;
|
||||
use App\Models\Task;
|
||||
use App\Models\TaskStatus;
|
||||
use App\Repositories\TaskRepository;
|
||||
use App\Transformers\TaskTransformer;
|
||||
use App\Utils\Ninja;
|
||||
@ -579,4 +581,88 @@ class TaskController extends BaseController
|
||||
return $this->itemResponse($task->fresh());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param StoreTaskRequest $request
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/api/v1/tasks/stort",
|
||||
* operationId="sortTasks",
|
||||
* tags={"tasks"},
|
||||
* summary="Sort tasks on KanBan",
|
||||
* description="Sorts tasks after drag and drop on the KanBan.",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns an Ok, 200 HTTP status",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function sort(SortTaskRequest $request)
|
||||
{
|
||||
|
||||
$task_statuses = $request->input('status_ids');
|
||||
$tasks = $request->input('task_ids');
|
||||
|
||||
collect($task_statuses)->each(function ($task_status_hashed_id, $key){
|
||||
|
||||
$task_status = TaskStatus::where('id', $this->decodePrimaryKey($task_status_hashed_id))
|
||||
->where('company_id', auth()->user()->company()->id)
|
||||
->first();
|
||||
|
||||
$task_status->status_order = $key;
|
||||
$task_status->save();
|
||||
|
||||
});
|
||||
|
||||
foreach($tasks as $key => $task_list)
|
||||
{
|
||||
|
||||
$sort_status_id = $this->decodePrimaryKey($key);
|
||||
|
||||
// nlog($task_list);
|
||||
|
||||
foreach ($task_list as $key => $task)
|
||||
{
|
||||
|
||||
// nlog($task);
|
||||
|
||||
$task_record = Task::where('id', $this->decodePrimaryKey($task))
|
||||
->where('company_id', auth()->user()->company()->id)
|
||||
->first();
|
||||
|
||||
// nlog($task_record->id);
|
||||
|
||||
$task_record->status_order = $key;
|
||||
$task_record->status_id = $sort_status_id;
|
||||
$task_record->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Ok'],200);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use App\Http\Requests\TaskStatus\DestroyTaskStatusRequest;
|
||||
use App\Http\Requests\TaskStatus\ShowTaskStatusRequest;
|
||||
use App\Http\Requests\TaskStatus\StoreTaskStatusRequest;
|
||||
use App\Http\Requests\TaskStatus\UpdateTaskStatusRequest;
|
||||
use App\Models\Task;
|
||||
use App\Models\TaskStatus;
|
||||
use App\Repositories\TaskStatusRepository;
|
||||
use App\Transformers\TaskStatusTransformer;
|
||||
@ -398,8 +399,9 @@ class TaskStatusController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyTaskStatusRequest $request, TaskStatus $task_status)
|
||||
{
|
||||
$task_status->delete();
|
||||
|
||||
$this->task_status_repo->delete($task_status);
|
||||
|
||||
return $this->itemResponse($task_status->fresh());
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,14 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\TemplateEngine;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use App\Utils\Traits\MakesTemplateData;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class TemplateController extends BaseController
|
||||
{
|
||||
@ -89,7 +92,7 @@ class TemplateController extends BaseController
|
||||
$subject = request()->has('subject') ? request()->input('subject') : '';
|
||||
$body = request()->has('body') ? request()->input('body') : '';
|
||||
$template = request()->has('template') ? request()->input('template') : '';
|
||||
|
||||
|
||||
$data = (new TemplateEngine($body, $subject, $entity, $entity_id, $template))->build();
|
||||
|
||||
return response()->json($data, 200);
|
||||
|
@ -112,6 +112,7 @@ class BillingPortalPurchase extends Component
|
||||
'show_loading_bar' => false,
|
||||
'not_eligible' => null,
|
||||
'not_eligible_message' => null,
|
||||
'payment_required' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -269,8 +270,11 @@ class BillingPortalPurchase extends Component
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->steps['fetched_payment_methods'] = true;
|
||||
|
||||
if((int)$this->subscription->price == 0)
|
||||
$this->steps['payment_required'] = false;
|
||||
else
|
||||
$this->steps['fetched_payment_methods'] = true;
|
||||
|
||||
$this->methods = $contact->client->service()->getPaymentMethods($this->price);
|
||||
|
||||
@ -326,9 +330,9 @@ class BillingPortalPurchase extends Component
|
||||
|
||||
$is_eligible = $this->subscription->service()->isEligible($this->contact);
|
||||
|
||||
if (is_array($is_eligible)) {
|
||||
if ($is_eligible['exception']['message'] != 'Success') {
|
||||
$this->steps['not_eligible'] = true;
|
||||
$this->steps['not_eligible_message'] = $is_eligible['exception'];
|
||||
$this->steps['not_eligible_message'] = $is_eligible['exception']['message'];
|
||||
$this->steps['show_loading_bar'] = false;
|
||||
|
||||
return;
|
||||
@ -339,6 +343,7 @@ class BillingPortalPurchase extends Component
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
'client_id' => $this->contact->client->id,
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'context' => 'purchase',
|
||||
now()->addMinutes(60)]
|
||||
);
|
||||
|
||||
@ -356,6 +361,30 @@ class BillingPortalPurchase extends Component
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
'quantity' => $this->quantity,
|
||||
'contact_id' => $this->contact->id,
|
||||
'client_id' => $this->contact->client->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function handlePaymentNotRequired()
|
||||
{
|
||||
|
||||
$is_eligible = $this->subscription->service()->isEligible($this->contact);
|
||||
|
||||
if ($is_eligible['status_code'] != 200) {
|
||||
$this->steps['not_eligible'] = true;
|
||||
$this->steps['not_eligible_message'] = $is_eligible['exception']['message'];
|
||||
$this->steps['show_loading_bar'] = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
return $this->subscription->service()->handleNoPaymentRequired([
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
'quantity' => $this->quantity,
|
||||
'contact_id' => $this->contact->id,
|
||||
'client_id' => $this->contact->client->id,
|
||||
'coupon' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ class InvoicesTable extends Component
|
||||
public function mount()
|
||||
{
|
||||
$this->sort_asc = false;
|
||||
|
||||
$this->sort_field = 'date';
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
@ -25,7 +25,7 @@ class RecurringInvoiceCancellation extends Component
|
||||
public function processCancellation()
|
||||
{
|
||||
if ($this->invoice->subscription) {
|
||||
return $this->invoice->subscription->service()->handleCancellation();
|
||||
return $this->invoice->subscription->service()->handleCancellation($this->invoice);
|
||||
}
|
||||
|
||||
return redirect()->route('client.recurring_invoices.request_cancellation', ['recurring_invoice' => $this->invoice->hashed_id]);
|
||||
|
@ -23,6 +23,13 @@ class RecurringInvoicesTable extends Component
|
||||
|
||||
public $per_page = 10;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->sort_asc = false;
|
||||
|
||||
$this->sort_field = 'date';
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$query = RecurringInvoice::query();
|
||||
|
@ -14,6 +14,7 @@ namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
@ -74,20 +75,32 @@ class SubscriptionPlanSwitch extends Component
|
||||
{
|
||||
$this->total = $this->amount;
|
||||
|
||||
$this->methods = $this->contact->client->service()->getPaymentMethods(100);
|
||||
$this->methods = $this->contact->client->service()->getPaymentMethods($this->amount);
|
||||
|
||||
$this->hash = Str::uuid()->toString();
|
||||
}
|
||||
|
||||
public function handleBeforePaymentEvents(): void
|
||||
{
|
||||
|
||||
$this->state['show_loading_bar'] = true;
|
||||
|
||||
$this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
]);
|
||||
$this->state['invoice'] = $this->target->service()->createChangePlanInvoice([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
'hash' => $this->hash,
|
||||
]);
|
||||
|
||||
Cache::put($this->hash, [
|
||||
'subscription_id' => $this->target->id,
|
||||
'target_id' => $this->target->id,
|
||||
'recurring_invoice' => $this->recurring_invoice->id,
|
||||
'client_id' => $this->recurring_invoice->client->id,
|
||||
'invoice_id' => $this->state['invoice']->id,
|
||||
'context' => 'change_plan',
|
||||
now()->addMinutes(60)]
|
||||
);
|
||||
|
||||
$this->state['payment_initialised'] = true;
|
||||
|
||||
@ -109,6 +122,18 @@ class SubscriptionPlanSwitch extends Component
|
||||
$this->handleBeforePaymentEvents();
|
||||
}
|
||||
|
||||
public function handlePaymentNotRequired()
|
||||
{
|
||||
|
||||
return $this->target->service()->createChangePlanCredit([
|
||||
'recurring_invoice' => $this->recurring_invoice,
|
||||
'subscription' => $this->subscription,
|
||||
'target' => $this->target,
|
||||
'hash' => $this->hash,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return render('components.livewire.subscription-plan-switch');
|
||||
|
@ -51,7 +51,7 @@ class StoreInvoiceRequest extends Request
|
||||
|
||||
$rules['invitations.*.client_contact_id'] = 'distinct';
|
||||
|
||||
$rules['number'] = ['nullable',Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)];
|
||||
$rules['number'] = ['nullable', Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)];
|
||||
|
||||
$rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];
|
||||
|
||||
|
@ -35,10 +35,11 @@ class StoreSubscriptionRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'product_id' => ['sometimes'],
|
||||
'product_ids' => ['sometimes'],
|
||||
'recurring_product_ids' => ['sometimes'],
|
||||
'assigned_user_id' => ['sometimes'],
|
||||
'is_recurring' => ['sometimes'],
|
||||
'frequency_id' => ['sometimes'],
|
||||
'frequency_id' => ['required_with:recurring_product_ids'],
|
||||
'auto_bill' => ['sometimes'],
|
||||
'promo_code' => ['sometimes'],
|
||||
'promo_discount' => ['sometimes'],
|
||||
|
@ -13,6 +13,7 @@ namespace App\Http\Requests\Subscription;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateSubscriptionRequest extends Request
|
||||
{
|
||||
@ -35,12 +36,32 @@ class UpdateSubscriptionRequest extends Request
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
//
|
||||
$rules = [
|
||||
'product_ids' => ['sometimes'],
|
||||
'recurring_product_ids' => ['sometimes'],
|
||||
'assigned_user_id' => ['sometimes'],
|
||||
'is_recurring' => ['sometimes'],
|
||||
'frequency_id' => ['required_with:recurring_product_ids'],
|
||||
'auto_bill' => ['sometimes'],
|
||||
'promo_code' => ['sometimes'],
|
||||
'promo_discount' => ['sometimes'],
|
||||
'is_amount_discount' => ['sometimes'],
|
||||
'allow_cancellation' => ['sometimes'],
|
||||
'per_set_enabled' => ['sometimes'],
|
||||
'min_seats_limit' => ['sometimes'],
|
||||
'max_seats_limit' => ['sometimes'],
|
||||
'trial_enabled' => ['sometimes'],
|
||||
'trial_duration' => ['sometimes'],
|
||||
'allow_query_overrides' => ['sometimes'],
|
||||
'allow_plan_changes' => ['sometimes'],
|
||||
'refund_period' => ['sometimes'],
|
||||
'webhook_configuration' => ['array'],
|
||||
'name' => ['sometimes', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)->ignore($this->subscription->id)]
|
||||
];
|
||||
|
||||
return $this->globalRules($rules);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
|
37
app/Http/Requests/Task/SortTaskRequest.php
Normal file
37
app/Http/Requests/Task/SortTaskRequest.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Quote Ninja (https://paymentninja.com).
|
||||
*
|
||||
* @link https://github.com/paymentninja/paymentninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Quote Ninja LLC (https://paymentninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\Task;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class SortTaskRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
|
||||
return true;
|
||||
// return auth()->user()->can('edit', $this->task);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -84,7 +84,7 @@ class ValidInvoicesRules implements Rule
|
||||
}
|
||||
else if($invoice['amount'] > $inv->balance) {
|
||||
|
||||
$this->error_msg = ctrans('texts.amount_greater_than_balance');
|
||||
$this->error_msg = ctrans('texts.amount_greater_than_balance_v5');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -45,10 +45,10 @@ class CreateCompanyTaskStatuses
|
||||
public function handle()
|
||||
{
|
||||
$task_statuses = [
|
||||
['name' => ctrans('texts.backlog'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now()],
|
||||
['name' => ctrans('texts.ready_to_do'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now()],
|
||||
['name' => ctrans('texts.in_progress'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now()],
|
||||
['name' => ctrans('texts.done'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now()],
|
||||
['name' => ctrans('texts.backlog'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now(), 'status_order' => 1],
|
||||
['name' => ctrans('texts.ready_to_do'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now(), 'status_order' => 2],
|
||||
['name' => ctrans('texts.in_progress'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now(), 'status_order' => 3],
|
||||
['name' => ctrans('texts.done'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now(), 'status_order' => 4],
|
||||
|
||||
];
|
||||
|
||||
|
@ -105,10 +105,10 @@ class NinjaMailerJob implements ShouldQueue
|
||||
|
||||
switch ($class) {
|
||||
case Invoice::class:
|
||||
event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->reminder_template, Ninja::eventVars(auth()->user()->id)));
|
||||
event(new InvoiceWasEmailedAndFailed($this->nmo->invitation, $this->nmo->company, $message, $this->nmo->reminder_template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
break;
|
||||
case Payment::class:
|
||||
event(new PaymentWasEmailedAndFailed($this->nmo->entity, $this->nmo->company, $message, Ninja::eventVars(auth()->user()->id)));
|
||||
event(new PaymentWasEmailedAndFailed($this->nmo->entity, $this->nmo->company, $message, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
break;
|
||||
default:
|
||||
# code...
|
||||
|
@ -674,6 +674,8 @@ class Import implements ShouldQueue
|
||||
$resource['invitations'][$key]['user_id'] = $modified['user_id'];
|
||||
$resource['invitations'][$key]['company_id'] = $this->company->id;
|
||||
unset($resource['invitations'][$key]['recurring_invoice_id']);
|
||||
unset($resource['invitations'][$key]['id']);
|
||||
|
||||
}
|
||||
|
||||
$modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']);
|
||||
@ -736,6 +738,7 @@ class Import implements ShouldQueue
|
||||
$resource['invitations'][$key]['user_id'] = $modified['user_id'];
|
||||
$resource['invitations'][$key]['company_id'] = $this->company->id;
|
||||
unset($resource['invitations'][$key]['invoice_id']);
|
||||
unset($resource['invitations'][$key]['id']);
|
||||
}
|
||||
|
||||
$modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']);
|
||||
@ -864,6 +867,7 @@ class Import implements ShouldQueue
|
||||
$resource['invitations'][$key]['user_id'] = $modified['user_id'];
|
||||
$resource['invitations'][$key]['company_id'] = $this->company->id;
|
||||
unset($resource['invitations'][$key]['invoice_id']);
|
||||
unset($resource['invitations'][$key]['id']);
|
||||
}
|
||||
|
||||
$modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']);
|
||||
|
@ -12,7 +12,10 @@
|
||||
namespace App\Mail\Engine;
|
||||
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class CreditEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -40,6 +43,9 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
App::forgetInstance('translator');
|
||||
Lang::replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
||||
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
} else {
|
||||
|
@ -14,7 +14,10 @@ namespace App\Mail\Engine;
|
||||
use App\DataMapper\EmailTemplateDefaults;
|
||||
use App\Models\Account;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class InvoiceEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -42,6 +45,10 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
App::forgetInstance('translator');
|
||||
Lang::replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
||||
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
} elseif (strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0) {
|
||||
|
@ -13,7 +13,10 @@ namespace App\Mail\Engine;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class QuoteEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -41,6 +44,9 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
|
||||
public function build()
|
||||
{
|
||||
App::forgetInstance('translator');
|
||||
Lang::replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
||||
|
||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||
$body_template = $this->template_data['body'];
|
||||
} else {
|
||||
|
@ -45,12 +45,29 @@ class Webhook extends BaseModel
|
||||
|
||||
public static $valid_events = [
|
||||
self::EVENT_CREATE_CLIENT,
|
||||
self::EVENT_CREATE_PAYMENT,
|
||||
self::EVENT_CREATE_QUOTE,
|
||||
self::EVENT_CREATE_INVOICE,
|
||||
self::EVENT_CREATE_QUOTE,
|
||||
self::EVENT_CREATE_PAYMENT,
|
||||
self::EVENT_CREATE_VENDOR,
|
||||
self::EVENT_UPDATE_QUOTE,
|
||||
self::EVENT_DELETE_QUOTE,
|
||||
self::EVENT_UPDATE_INVOICE,
|
||||
self::EVENT_DELETE_INVOICE,
|
||||
self::EVENT_UPDATE_CLIENT,
|
||||
self::EVENT_DELETE_CLIENT,
|
||||
self::EVENT_DELETE_PAYMENT,
|
||||
self::EVENT_UPDATE_VENDOR,
|
||||
self::EVENT_DELETE_VENDOR,
|
||||
self::EVENT_CREATE_EXPENSE,
|
||||
self::EVENT_UPDATE_EXPENSE,
|
||||
self::EVENT_DELETE_EXPENSE,
|
||||
self::EVENT_CREATE_TASK,
|
||||
self::EVENT_UPDATE_TASK,
|
||||
self::EVENT_DELETE_TASK,
|
||||
self::EVENT_APPROVE_QUOTE,
|
||||
self::EVENT_LATE_INVOICE,
|
||||
self::EVENT_EXPIRED_QUOTE,
|
||||
self::EVENT_REMIND_INVOICE,
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
|
@ -16,15 +16,20 @@ class MailServiceProvider extends MailProvider
|
||||
$this->registerIlluminateMailer();
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function registerIlluminateMailer()
|
||||
{
|
||||
// $this->app->singleton('mail.manager', function($app) {
|
||||
// return new GmailTransportManager($app);
|
||||
// });
|
||||
|
||||
$this->app->bind('mail.manager', function($app) {
|
||||
$this->app->singleton('mail.manager', function($app) {
|
||||
return new GmailTransportManager($app);
|
||||
});
|
||||
|
||||
// $this->app->bind('mail.manager', function($app) {
|
||||
// return new GmailTransportManager($app);
|
||||
// });
|
||||
|
||||
$this->app->bind('mailer', function ($app) {
|
||||
return $app->make('mail.manager')->mailer();
|
||||
@ -33,14 +38,22 @@ class MailServiceProvider extends MailProvider
|
||||
$this->app['mail.manager']->extend('postmark', function () {
|
||||
return new PostmarkTransport(
|
||||
$this->guzzle(config('postmark.guzzle', [])),
|
||||
config('postmark.secret', config('services.postmark.secret'))
|
||||
config('postmark.secret')
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected function guzzle(array $config): HttpClient
|
||||
{
|
||||
return new HttpClient($config);
|
||||
}
|
||||
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'mail.manager',
|
||||
'mailer' ];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,21 @@ class NinjaTranslationServiceProvider extends TranslationServiceProvider
|
||||
*
|
||||
*/
|
||||
|
||||
// $this->app->bind('translator', function($app) {
|
||||
|
||||
// $loader = $app['translation.loader'];
|
||||
// $locale = $app['config']['app.locale'];
|
||||
|
||||
// $trans = new NinjaTranslator($loader, $locale);
|
||||
|
||||
// $trans->setFallback($app['config']['app.fallback_locale']);
|
||||
|
||||
// return $trans;
|
||||
|
||||
// });
|
||||
|
||||
$this->app->singleton('translator', function ($app) {
|
||||
|
||||
$loader = $app['translation.loader'];
|
||||
$locale = $app['config']['app.locale'];
|
||||
|
||||
@ -42,6 +56,8 @@ class NinjaTranslationServiceProvider extends TranslationServiceProvider
|
||||
$trans->setFallback($app['config']['app.fallback_locale']);
|
||||
|
||||
return $trans;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -291,6 +291,10 @@ class BaseRepository
|
||||
/* Apply entity number */
|
||||
$model = $model->service()->applyNumber()->save();
|
||||
|
||||
/* Handle attempts where the deposit is greater than the amount/balance of the invoice */
|
||||
if((int)$model->balance != 0 && $model->partial > $model->amount)
|
||||
$model->partial = min($model->amount, $model->balance);
|
||||
|
||||
/* Update product details if necessary */
|
||||
if ($model->company->update_products)
|
||||
UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company);
|
||||
|
@ -155,7 +155,11 @@ class PaymentRepository extends BaseRepository {
|
||||
}
|
||||
|
||||
if ( ! $is_existing_payment && ! $this->import_mode ) {
|
||||
event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user()->id) ) );
|
||||
|
||||
if ($payment->client->getSetting('client_manual_payment_notification'))
|
||||
$payment->service()->sendEmail();
|
||||
|
||||
event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user()->id) ) );
|
||||
}
|
||||
|
||||
nlog("payment amount = {$payment->amount}");
|
||||
|
@ -11,9 +11,39 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Task;
|
||||
|
||||
/**
|
||||
* Class for task status repository.
|
||||
*/
|
||||
class TaskStatusRepository extends BaseRepository
|
||||
{
|
||||
|
||||
public function delete($task_status)
|
||||
{
|
||||
|
||||
Task::where('status_id', $task_status->id)
|
||||
->where('company_id', $task_status->company_id)
|
||||
->update(['status_id' => null]);
|
||||
|
||||
|
||||
parent::delete($task_status);
|
||||
|
||||
return $task_status;
|
||||
|
||||
}
|
||||
|
||||
public function archive($task_status)
|
||||
{
|
||||
|
||||
Task::where('status_id', $task_status->id)
|
||||
->where('company_id', $task_status->company_id)
|
||||
->update(['status_id' => null]);
|
||||
|
||||
|
||||
parent::archive($task_status);
|
||||
|
||||
return $task_status;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class ApplyPayment
|
||||
|
||||
if ((int)$this->invoice->balance == 0) {
|
||||
$this->invoice->service()->deletePdf();
|
||||
event(new InvoiceWasPaid($this->invoice, $payment, $this->payment->company, Ninja::eventVars(auth()->user()->id)));
|
||||
event(new InvoiceWasPaid($this->invoice, $this->payment, $this->payment->company, Ninja::eventVars(auth()->user()->id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -440,7 +440,6 @@ class Design extends BaseDesign
|
||||
|
||||
$elements = [
|
||||
['element' => 'div', 'properties' => ['style' => 'display: flex; flex-direction: column;'], 'elements' => [
|
||||
['element' => 'p', 'content' => strtr($_variables['values']['$entity.public_notes'], $_variables), 'properties' => ['data-ref' => 'total_table-public_notes', 'style' => 'text-align: left;']],
|
||||
['element' => 'p', 'content' => '', 'properties' => ['style' => 'text-align: left; display: flex; flex-direction: column;'], 'elements' => [
|
||||
['element' => 'span', 'content' => '$entity.terms_label: ', 'properties' => ['hidden' => $this->entityVariableCheck('$entity.terms'), 'data-ref' => 'total_table-terms-label', 'style' => 'font-weight: bold; text-align: left; margin-top: 1rem;']],
|
||||
['element' => 'span', 'content' => strtr($_variables['values']['$entity.terms'], $_variables), 'properties' => ['data-ref' => 'total_table-terms', 'style' => 'text-align: left;']],
|
||||
|
@ -34,9 +34,9 @@ class ConvertQuote
|
||||
public function run($quote)
|
||||
{
|
||||
$invoice = CloneQuoteToInvoiceFactory::create($quote, $quote->user_id);
|
||||
|
||||
$invoice->design_id = $this->client->getSetting('invoice_design_id');
|
||||
$invoice = $this->invoice_repo->save([], $invoice);
|
||||
|
||||
|
||||
$invoice->fresh();
|
||||
|
||||
$invoice->service()
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Services\Subscription;
|
||||
|
||||
use App\DataMapper\InvoiceItem;
|
||||
use App\Factory\CreditFactory;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceToRecurringInvoiceFactory;
|
||||
use App\Factory\RecurringInvoiceFactory;
|
||||
@ -26,9 +27,11 @@ use App\Models\Product;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\SystemLog;
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Repositories\RecurringInvoiceRepository;
|
||||
use App\Repositories\SubscriptionRepository;
|
||||
use App\Services\Subscription\ZeroCostProduct;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -61,6 +64,10 @@ class SubscriptionService
|
||||
throw new \Exception("Illegal entrypoint into method, payload must contain billing context");
|
||||
}
|
||||
|
||||
if($payment_hash->data->billing_context->context == 'change_plan') {
|
||||
return $this->handlePlanChange($payment_hash);
|
||||
}
|
||||
|
||||
// if we have a recurring product - then generate a recurring invoice
|
||||
if(strlen($this->subscription->recurring_product_ids) >=1){
|
||||
|
||||
@ -84,16 +91,15 @@ class SubscriptionService
|
||||
'invoice' => $this->encodePrimaryKey($payment_hash->fee_invoice_id),
|
||||
'client' => $recurring_invoice->client->hashed_id,
|
||||
'subscription' => $this->subscription->hashed_id,
|
||||
'contact' => auth('contact')->user()->hashed_id,
|
||||
];
|
||||
|
||||
$response = $this->triggerWebhook($context);
|
||||
|
||||
nlog($response);
|
||||
// nlog($response);
|
||||
|
||||
if(array_key_exists('post_purchase_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['post_purchase_url']) >=1)
|
||||
return redirect($this->subscription->webhook_configuration['post_purchase_url']);
|
||||
$this->handleRedirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
|
||||
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -109,10 +115,7 @@ class SubscriptionService
|
||||
//execute any webhooks
|
||||
$this->triggerWebhook($context);
|
||||
|
||||
if(array_key_exists('post_purchase_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['post_purchase_url']) >=1)
|
||||
return redirect($this->subscription->webhook_configuration['post_purchase_url']);
|
||||
|
||||
return redirect('/client/invoices/'.$this->encodePrimaryKey($payment_hash->fee_invoice_id));
|
||||
$this->handleRedirect('/client/invoices/'.$this->encodePrimaryKey($payment_hash->fee_invoice_id));
|
||||
|
||||
}
|
||||
}
|
||||
@ -129,7 +132,7 @@ class SubscriptionService
|
||||
];
|
||||
|
||||
$response = $this->triggerWebhook($context);
|
||||
nlog($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@ -176,13 +179,20 @@ class SubscriptionService
|
||||
//execute any webhooks
|
||||
$response = $this->triggerWebhook($context);
|
||||
|
||||
if(array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >=1){
|
||||
return redirect($this->subscription->webhook_configuration['return_url']);
|
||||
}
|
||||
|
||||
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
return $this->handleRedirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an upgrade price when moving between plans
|
||||
*
|
||||
* However we only allow people to move between plans
|
||||
* if their account is in good standing.
|
||||
*
|
||||
* @param RecurringInvoice $recurring_invoice
|
||||
* @param Subscription $target
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function calculateUpgradePrice(RecurringInvoice $recurring_invoice, Subscription $target) :?float
|
||||
{
|
||||
//calculate based on daily prices
|
||||
@ -196,16 +206,20 @@ class SubscriptionService
|
||||
->where('balance', '>', 0);
|
||||
|
||||
$outstanding_amounts = $outstanding->sum('balance');
|
||||
// $outstanding_invoices = $outstanding->get();
|
||||
$outstanding_invoices = $outstanding;
|
||||
|
||||
$outstanding_invoice = Invoice::where('subscription_id', $this->subscription->id)
|
||||
->where('client_id', $recurring_invoice->client_id)
|
||||
->where('is_deleted', 0)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
if ($outstanding->count() == 0){
|
||||
//nothing outstanding
|
||||
return $target->price;
|
||||
return $target->price - $this->calculateProRataRefund($outstanding_invoice);
|
||||
}
|
||||
elseif ($outstanding->count() == 1){
|
||||
//user has multiple amounts outstanding
|
||||
return $target->price - $this->calculateProRataRefund($outstanding->first());
|
||||
return $target->price - $this->calculateProRataRefund($outstanding_invoice);
|
||||
}
|
||||
elseif ($outstanding->count() > 1) {
|
||||
//user is changing plan mid frequency cycle
|
||||
@ -217,66 +231,353 @@ class SubscriptionService
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* We refund unused days left.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @return float
|
||||
*/
|
||||
private function calculateProRataRefund($invoice) :float
|
||||
{
|
||||
//determine the start date
|
||||
|
||||
$start_date = Carbon::parse($invoice->date);
|
||||
|
||||
$current_date = now();
|
||||
|
||||
$days_to_refund = $start_date->diffInDays($current_date);
|
||||
$days_of_subscription_used = $start_date->diffInDays($current_date);
|
||||
|
||||
$days_in_frequency = $this->getDaysInFrequency();
|
||||
|
||||
$pro_rata_refund = round(($days_to_refund/$days_in_frequency) * $invoice->amount ,2);
|
||||
|
||||
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
|
||||
|
||||
return $pro_rata_refund;
|
||||
|
||||
}
|
||||
|
||||
public function createChangePlanInvoice($data)
|
||||
/**
|
||||
* Returns refundable set of line items
|
||||
* transformed for direct injection into
|
||||
* the invoice
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @return array
|
||||
*/
|
||||
private function calculateProRataRefundItems($invoice, $is_credit = false) :array
|
||||
{
|
||||
//Data array structure
|
||||
/**
|
||||
* [
|
||||
* 'recurring_invoice' => RecurringInvoice::class,
|
||||
* 'subscription' => Subscription::class,
|
||||
* 'target' => Subscription::class
|
||||
* ]
|
||||
*/
|
||||
|
||||
$outstanding_invoice = $recurring_invoice->invoices()
|
||||
->where('is_deleted', 0)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||
->where('balance', '>', 0)
|
||||
->first();
|
||||
/* depending on whether we are creating an invoice or a credit*/
|
||||
$multiplier = $is_credit ? 1 : -1;
|
||||
|
||||
$start_date = Carbon::parse($invoice->date);
|
||||
|
||||
// we calculate the pro rata refund for this invoice.
|
||||
if($outstanding_invoice)
|
||||
$current_date = now();
|
||||
|
||||
$days_of_subscription_used = $start_date->diffInDays($current_date);
|
||||
|
||||
$days_in_frequency = $this->getDaysInFrequency();
|
||||
|
||||
$ratio = ($days_in_frequency - $days_of_subscription_used)/$days_in_frequency;
|
||||
|
||||
$line_items = [];
|
||||
|
||||
foreach($invoice->line_items as $item)
|
||||
{
|
||||
|
||||
if($item->product_key != ctrans('texts.refund'))
|
||||
{
|
||||
|
||||
$item->cost = ($item->cost*$ratio*$multiplier);
|
||||
$item->product_key = ctrans('texts.refund');
|
||||
$item->notes = ctrans('texts.refund') . ": ". $item->notes;
|
||||
|
||||
|
||||
$line_items[] = $item;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//logic
|
||||
|
||||
// Is the user paid up to date? ie are there any outstanding invoices for this subscription
|
||||
return $line_items;
|
||||
|
||||
// User in arrears.
|
||||
|
||||
|
||||
// User paid up to date (in credit!)
|
||||
|
||||
//generate credit amount.
|
||||
//
|
||||
//generate new billable amount
|
||||
//
|
||||
|
||||
//if billable amount is LESS than 0 -> generate a credit and pass through.
|
||||
//
|
||||
//if billable amoun is GREATER than 0 -> gener
|
||||
return Invoice::where('status_id', Invoice::STATUS_SENT)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* We only charge for the used days
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @return float
|
||||
*/
|
||||
private function calculateProRataCharge($invoice) :float
|
||||
{
|
||||
|
||||
$start_date = Carbon::parse($invoice->date);
|
||||
|
||||
$current_date = now();
|
||||
|
||||
$days_to_charge = $start_date->diffInDays($current_date);
|
||||
|
||||
$days_in_frequency = $this->getDaysInFrequency();
|
||||
|
||||
nlog("days to charge = {$days_to_charge} fays in frequency = {$days_in_frequency}");
|
||||
|
||||
$pro_rata_charge = round(($days_to_charge/$days_in_frequency) * $invoice->amount ,2);
|
||||
|
||||
nlog("pro rata charge = {$pro_rata_charge}");
|
||||
|
||||
return $pro_rata_charge;
|
||||
}
|
||||
|
||||
/**
|
||||
* When downgrading, we may need to create
|
||||
* a credit
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function createChangePlanCredit($data)
|
||||
{
|
||||
$recurring_invoice = $data['recurring_invoice'];
|
||||
$old_subscription = $data['subscription'];
|
||||
$target_subscription = $data['target'];
|
||||
|
||||
$pro_rata_charge_amount = 0;
|
||||
$pro_rata_refund_amount = 0;
|
||||
|
||||
$last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
|
||||
->where('client_id', $recurring_invoice->client_id)
|
||||
->where('is_deleted', 0)
|
||||
->withTrashed()
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
if($last_invoice->balance > 0)
|
||||
{
|
||||
$pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription);
|
||||
nlog("pro rata charge = {$pro_rata_charge_amount}");
|
||||
}
|
||||
else
|
||||
{
|
||||
$pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription) * -1;
|
||||
nlog("pro rata refund = {$pro_rata_refund_amount}");
|
||||
}
|
||||
|
||||
$total_payable = $pro_rata_refund_amount + $pro_rata_charge_amount + $this->subscription->price;
|
||||
|
||||
nlog("total payable = {$total_payable}");
|
||||
|
||||
$credit = $this->createCredit($last_invoice, $target_subscription);
|
||||
|
||||
$new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice);
|
||||
|
||||
$context = [
|
||||
'context' => 'change_plan',
|
||||
'recurring_invoice' => $new_recurring_invoice->hashed_id,
|
||||
'credit' => $credit->hashed_id,
|
||||
'client' => $new_recurring_invoice->client->hashed_id,
|
||||
'subscription' => $target_subscription->hashed_id,
|
||||
'contact' => auth('contact')->user()->hashed_id,
|
||||
];
|
||||
|
||||
$response = $this->triggerWebhook($context);
|
||||
|
||||
nlog($response);
|
||||
|
||||
return $this->handleRedirect('/client/credits/'.$credit->hashed_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* When changing plans, we need to generate a pro rata invoice
|
||||
*
|
||||
* @param array $data
|
||||
* @return Invoice
|
||||
*/
|
||||
public function createChangePlanInvoice($data)
|
||||
{
|
||||
$recurring_invoice = $data['recurring_invoice'];
|
||||
$old_subscription = $data['subscription'];
|
||||
$target_subscription = $data['target'];
|
||||
|
||||
$pro_rata_charge_amount = 0;
|
||||
$pro_rata_refund_amount = 0;
|
||||
|
||||
$last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
|
||||
->where('client_id', $recurring_invoice->client_id)
|
||||
->where('is_deleted', 0)
|
||||
->withTrashed()
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
if($last_invoice->balance > 0)
|
||||
{
|
||||
$pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription);
|
||||
nlog("pro rata charge = {$pro_rata_charge_amount}");
|
||||
}
|
||||
else
|
||||
{
|
||||
$pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription) * -1;
|
||||
nlog("pro rata refund = {$pro_rata_refund_amount}");
|
||||
}
|
||||
|
||||
$total_payable = $pro_rata_refund_amount + $pro_rata_charge_amount + $this->subscription->price;
|
||||
|
||||
return $this->proRataInvoice($last_invoice, $target_subscription);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from payment service on
|
||||
* return from a plan change
|
||||
*
|
||||
* @param PaymentHash $payment_hash
|
||||
*/
|
||||
private function handlePlanChange($payment_hash)
|
||||
{
|
||||
|
||||
$old_recurring_invoice = RecurringInvoice::find($payment_hash->data->billing_context->recurring_invoice);
|
||||
|
||||
$recurring_invoice = $this->createNewRecurringInvoice($old_recurring_invoice);
|
||||
|
||||
$context = [
|
||||
'context' => 'change_plan',
|
||||
'recurring_invoice' => $recurring_invoice->hashed_id,
|
||||
'invoice' => $this->encodePrimaryKey($payment_hash->fee_invoice_id),
|
||||
'client' => $recurring_invoice->client->hashed_id,
|
||||
'subscription' => $this->subscription->hashed_id,
|
||||
'contact' => auth('contact')->user()->hashed_id,
|
||||
];
|
||||
|
||||
|
||||
$response = $this->triggerWebhook($context);
|
||||
|
||||
nlog($response);
|
||||
|
||||
return $this->handleRedirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new recurring invoice when changing
|
||||
* plans
|
||||
*
|
||||
* @param RecurringInvoice $old_recurring_invoice
|
||||
* @return RecurringInvoice
|
||||
*/
|
||||
private function createNewRecurringInvoice($old_recurring_invoice) :RecurringInvoice
|
||||
{
|
||||
|
||||
$old_recurring_invoice->service()->stop()->save();
|
||||
|
||||
$recurring_invoice_repo = new RecurringInvoiceRepository();
|
||||
$recurring_invoice_repo->archive($old_recurring_invoice);
|
||||
|
||||
$recurring_invoice = $this->convertInvoiceToRecurring($old_recurring_invoice->client_id);
|
||||
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
|
||||
$recurring_invoice->next_send_date = now();
|
||||
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
||||
|
||||
/* Start the recurring service */
|
||||
$recurring_invoice->service()
|
||||
->start()
|
||||
->save();
|
||||
|
||||
return $recurring_invoice;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a plan change where no payment is required
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function handlePlanChangeNoPayment($data)
|
||||
{
|
||||
|
||||
$recurring_invoice = $this->createNewRecurringInvoice($data['recurring_invoice']);
|
||||
|
||||
$context = [
|
||||
'context' => 'change_plan',
|
||||
'recurring_invoice' => $recurring_invoice->hashed_id,
|
||||
'invoice' => $this->encodePrimaryKey($payment_hash->fee_invoice_id),
|
||||
'client' => $recurring_invoice->client->hashed_id,
|
||||
'subscription' => $this->subscription->hashed_id,
|
||||
'contact' => auth('contact')->user()->hashed_id,
|
||||
];
|
||||
|
||||
$response = $this->triggerWebhook($context);
|
||||
|
||||
// nlog($response);
|
||||
|
||||
return $this->handleRedirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a credit note if the plan change requires
|
||||
*
|
||||
* @param Invoice $last_invoice
|
||||
* @param Subscription $target
|
||||
* @return Credit
|
||||
*/
|
||||
private function createCredit($last_invoice, $target)
|
||||
{
|
||||
|
||||
$subscription_repo = new SubscriptionRepository();
|
||||
$credit_repo = new CreditRepository();
|
||||
|
||||
$credit = CreditFactory::create($this->subscription->company_id, $this->subscription->user_id);
|
||||
$credit->date = now()->format('Y-m-d');
|
||||
$credit->subscription_id = $this->subscription->id;
|
||||
|
||||
$line_items = $subscription_repo->generateLineItems($target);
|
||||
|
||||
$credit->line_items = array_merge($line_items, $this->calculateProRataRefundItems($last_invoice, true));
|
||||
|
||||
$data = [
|
||||
'client_id' => $last_invoice->client_id,
|
||||
'quantity' => 1,
|
||||
'date' => now()->format('Y-m-d'),
|
||||
];
|
||||
|
||||
return $credit_repo->save($data, $credit)->service()->markSent()->fillDefaults()->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* When changing plans we need to generate a pro rata
|
||||
* invoice which takes into account any credits.
|
||||
*
|
||||
* @param Invoice $last_invoice
|
||||
* @param Subscription $target
|
||||
* @return Invoice
|
||||
*/
|
||||
private function proRataInvoice($last_invoice, $target)
|
||||
{
|
||||
$subscription_repo = new SubscriptionRepository();
|
||||
$invoice_repo = new InvoiceRepository();
|
||||
|
||||
$invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id);
|
||||
$invoice->date = now()->format('Y-m-d');
|
||||
$invoice->subscription_id = $this->subscription->id;
|
||||
|
||||
$invoice->line_items = array_merge($subscription_repo->generateLineItems($target), $this->calculateProRataRefundItems($last_invoice));
|
||||
|
||||
$data = [
|
||||
'client_id' => $last_invoice->client_id,
|
||||
'quantity' => 1,
|
||||
'date' => now()->format('Y-m-d'),
|
||||
];
|
||||
|
||||
return $invoice_repo->save($data, $invoice)
|
||||
->service()
|
||||
->markSent()
|
||||
->fillDefaults()
|
||||
->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the first invoice when a subscription is purchased
|
||||
*
|
||||
* @param array $data
|
||||
* @return Invoice
|
||||
*/
|
||||
public function createInvoice($data): ?\App\Models\Invoice
|
||||
{
|
||||
|
||||
@ -297,8 +598,14 @@ class SubscriptionService
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function convertInvoiceToRecurring($client_id) :RecurringInvoice
|
||||
/**
|
||||
* Generates a recurring invoice based on
|
||||
* the specifications of the subscription
|
||||
*
|
||||
* @param int $client_id The Client Id
|
||||
* @return RecurringInvoice
|
||||
*/
|
||||
public function convertInvoiceToRecurring($client_id) :RecurringInvoice
|
||||
{
|
||||
|
||||
$subscription_repo = new SubscriptionRepository();
|
||||
@ -314,6 +621,11 @@ class SubscriptionService
|
||||
return $recurring_invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hit a 3rd party API if defined in the subscription
|
||||
*
|
||||
* @param array $context
|
||||
*/
|
||||
public function triggerWebhook($context)
|
||||
{
|
||||
/* If no webhooks have been set, then just return gracefully */
|
||||
@ -340,7 +652,8 @@ class SubscriptionService
|
||||
else {
|
||||
|
||||
$status = $response->getStatusCode();
|
||||
$response_body = $response->getBody();
|
||||
|
||||
//$response_body = $response->getReasonPhrase();
|
||||
$body = array_merge($body, ['status' => $status, 'response_body' => $response_body]);
|
||||
|
||||
}
|
||||
@ -400,62 +713,129 @@ class SubscriptionService
|
||||
->get();
|
||||
}
|
||||
|
||||
public function completePlanChange(PaymentHash $paymentHash)
|
||||
{
|
||||
// .. handle redirect, after upgrade redirects, etc..
|
||||
}
|
||||
|
||||
public function handleCancellation()
|
||||
{
|
||||
dd('Cancelling using SubscriptionService');
|
||||
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pro rata calculation between subscriptions.
|
||||
*
|
||||
* @param Subscription $current
|
||||
* @param Subscription $target
|
||||
* Handle the cancellation of a subscription
|
||||
*
|
||||
* @param RecurringInvoice $recurring_invoice
|
||||
*
|
||||
*/
|
||||
public function getPriceBetweenSubscriptions(Subscription $current, Subscription $target): int
|
||||
public function handleCancellation(RecurringInvoice $recurring_invoice)
|
||||
{
|
||||
// Calculate the pro rata. Return negative value if credits needed.
|
||||
|
||||
return 1;
|
||||
//only refund if they are in the refund window.
|
||||
$outstanding_invoice = Invoice::where('subscription_id', $this->subscription->id)
|
||||
->where('client_id', $recurring_invoice->client_id)
|
||||
->where('is_deleted', 0)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
$invoice_start_date = Carbon::parse($outstanding_invoice->date);
|
||||
$refund_end_date = $invoice_start_date->addSeconds($this->subscription->refund_period);
|
||||
|
||||
/* Stop the recurring invoice and archive */
|
||||
$recurring_invoice->service()->stop()->save();
|
||||
$recurring_invoice_repo = new RecurringInvoiceRepository();
|
||||
$recurring_invoice_repo->archive($recurring_invoice);
|
||||
|
||||
/* Refund only if we are in the window - and there is nothing outstanding on the invoice */
|
||||
if($refund_end_date->greaterThan(now()) && (int)$outstanding_invoice->balance == 0)
|
||||
{
|
||||
|
||||
if($outstanding_invoice->payments()->exists())
|
||||
{
|
||||
$payment = $outstanding_invoice->payments()->first();
|
||||
|
||||
$data = [
|
||||
'id' => $payment->id,
|
||||
'gateway_refund' => true,
|
||||
'send_email' => true,
|
||||
'invoices' => [
|
||||
['invoice_id' => $outstanding_invoice->id, 'amount' => $outstanding_invoice->amount],
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
$payment->refund($data);
|
||||
}
|
||||
}
|
||||
|
||||
$context = [
|
||||
'context' => 'cancellation',
|
||||
'subscription' => $this->subscription->hashed_id,
|
||||
'recurring_invoice' => $recurring_invoice->hashed_id,
|
||||
'client' => $recurring_invoice->client->hashed_id,
|
||||
'contact' => auth('contact')->user()->hashed_id,
|
||||
];
|
||||
|
||||
$this->triggerWebhook($context);
|
||||
|
||||
return $this->handleRedirect('client/subscriptions');
|
||||
|
||||
}
|
||||
|
||||
private function getDaysInFrequency()
|
||||
{
|
||||
|
||||
switch ($this->subscription->frequency_id) {
|
||||
case self::FREQUENCY_DAILY:
|
||||
case RecurringInvoice::FREQUENCY_DAILY:
|
||||
return 1;
|
||||
case self::FREQUENCY_WEEKLY:
|
||||
case RecurringInvoice::FREQUENCY_WEEKLY:
|
||||
return 7;
|
||||
case self::FREQUENCY_TWO_WEEKS:
|
||||
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
|
||||
return 14;
|
||||
case self::FREQUENCY_FOUR_WEEKS:
|
||||
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
|
||||
return now()->diffInDays(now()->addWeeks(4));
|
||||
case self::FREQUENCY_MONTHLY:
|
||||
case RecurringInvoice::FREQUENCY_MONTHLY:
|
||||
return now()->diffInDays(now()->addMonthNoOverflow());
|
||||
case self::FREQUENCY_TWO_MONTHS:
|
||||
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
|
||||
return now()->diffInDays(now()->addMonthNoOverflow(2));
|
||||
case self::FREQUENCY_THREE_MONTHS:
|
||||
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
|
||||
return now()->diffInDays(now()->addMonthNoOverflow(3));
|
||||
case self::FREQUENCY_FOUR_MONTHS:
|
||||
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
|
||||
return now()->diffInDays(now()->addMonthNoOverflow(4));
|
||||
case self::FREQUENCY_SIX_MONTHS:
|
||||
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
|
||||
return now()->diffInDays(now()->addMonthNoOverflow(6));
|
||||
case self::FREQUENCY_ANNUALLY:
|
||||
case RecurringInvoice::FREQUENCY_ANNUALLY:
|
||||
return now()->diffInDays(now()->addYear());
|
||||
case self::FREQUENCY_TWO_YEARS:
|
||||
case RecurringInvoice::FREQUENCY_TWO_YEARS:
|
||||
return now()->diffInDays(now()->addYears(2));
|
||||
case self::FREQUENCY_THREE_YEARS:
|
||||
case RecurringInvoice::FREQUENCY_THREE_YEARS:
|
||||
return now()->diffInDays(now()->addYears(3));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 'email' => $this->email ?? $this->contact->email,
|
||||
* 'quantity' => $this->quantity,
|
||||
* 'contact_id' => $this->contact->id,
|
||||
*/
|
||||
public function handleNoPaymentRequired(array $data)
|
||||
{
|
||||
|
||||
$context = (new ZeroCostProduct($this->subscription, $data))->run();
|
||||
|
||||
// Forward payload to webhook
|
||||
if(array_key_exists('context', $context))
|
||||
$response = $this->triggerWebhook($context);
|
||||
|
||||
// Hit the redirect
|
||||
return $this->handleRedirect($context['redirect_url']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles redirecting the user
|
||||
*/
|
||||
private function handleRedirect($default_redirect)
|
||||
{
|
||||
|
||||
if(array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >=1)
|
||||
return redirect($this->subscription->webhook_configuration['return_url']);
|
||||
|
||||
return redirect($default_redirect);
|
||||
}
|
||||
}
|
||||
|
84
app/Services/Subscription/ZeroCostProduct.php
Normal file
84
app/Services/Subscription/ZeroCostProduct.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Services\Subscription;
|
||||
|
||||
use App\Models\Subscription;
|
||||
use App\Repositories\RecurringInvoiceRepository;
|
||||
use App\Services\AbstractService;
|
||||
|
||||
class ZeroCostProduct extends AbstractService
|
||||
{
|
||||
private $subscription;
|
||||
|
||||
private $data;
|
||||
|
||||
/**
|
||||
$data = [
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
'quantity' => $this->quantity,
|
||||
'contact_id' => $this->contact->id,
|
||||
'client_id' => $this->contact->client->id,
|
||||
];
|
||||
*/
|
||||
public function __construct(Subscription $subscription, array $data)
|
||||
{
|
||||
$this->subscription = $subscription;
|
||||
|
||||
$this->data = $data;
|
||||
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
//create a zero dollar invoice.
|
||||
|
||||
$invoice = $this->subscription->service()->createInvoice($this->data);
|
||||
|
||||
$invoice->service()
|
||||
->markPaid()
|
||||
->save();
|
||||
|
||||
$redirect_url = "/client/invoices/{$invoice->hashed_id}";
|
||||
|
||||
//create a recurring zero dollar invoice attached to this subscription.
|
||||
|
||||
if(strlen($this->subscription->recurring_product_ids) >=1){
|
||||
|
||||
$recurring_invoice = $this->subscription->service()->convertInvoiceToRecurring($this->data['client_id']);
|
||||
$recurring_invoice_repo = new RecurringInvoiceRepository();
|
||||
|
||||
$recurring_invoice->next_send_date = now();
|
||||
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
|
||||
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
||||
|
||||
/* Start the recurring service */
|
||||
$recurring_invoice->service()
|
||||
->start()
|
||||
->save();
|
||||
|
||||
$context = [
|
||||
'context' => 'recurring_purchase',
|
||||
'recurring_invoice' => $recurring_invoice->hashed_id,
|
||||
'invoice' => $invoice->hashed_id,
|
||||
'client' => $recurring_invoice->client->hashed_id,
|
||||
'subscription' => $this->subscription->hashed_id,
|
||||
'contact' => auth('contact')->user()->hashed_id,
|
||||
'redirect_url' => "/client/recurring_invoices/{$recurring_invoice->hashed_id}",
|
||||
];
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
return ['redirect_url' => $redirect_url];
|
||||
}
|
||||
|
||||
}
|
@ -375,7 +375,7 @@ class HtmlEngine
|
||||
$data['$entity_footer'] = ['value' => $this->entity->footer, 'label' => ''];
|
||||
|
||||
$data['$page_size'] = ['value' => $this->settings->page_size, 'label' => ''];
|
||||
$data['$page_layout'] = ['value' => $this->settings->page_layout, 'label' => ''];
|
||||
$data['$page_layout'] = ['value' => property_exists($this->settings, 'page_layout') ? $this->settings->page_layout : 'Portrait', 'label' => ''];
|
||||
|
||||
$arrKeysLength = array_map('strlen', array_keys($data));
|
||||
array_multisort($arrKeysLength, SORT_DESC, $data);
|
||||
|
@ -17,10 +17,13 @@ use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use App\Utils\Traits\MakesTemplateData;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
|
||||
|
||||
@ -98,6 +101,9 @@ class TemplateEngine
|
||||
$this->settings = $this->settings_entity->settings;
|
||||
}
|
||||
|
||||
App::forgetInstance('translator');
|
||||
Lang::replace(Ninja::transformTranslations($this->settings));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -121,7 +127,7 @@ class TemplateEngine
|
||||
$this->body = EmailTemplateDefaults::getDefaultTemplate($this->template, $this->settings_entity->locale());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -40,11 +40,13 @@ trait SubscriptionHooker
|
||||
RequestOptions::JSON => ['body' => $body], RequestOptions::ALLOW_REDIRECTS => false
|
||||
]);
|
||||
|
||||
return $response;
|
||||
return array_merge($body, ['exception' => json_decode($response->getBody(),true), 'status_code' => $response->getStatusCode()]);
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
$body = array_merge($body, ['exception' => $e->getMessage()]);
|
||||
//;
|
||||
// dd($e);
|
||||
$body = array_merge($body, ['exception' => ['message' => $e->getMessage(), 'status_code' => 500]]);
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ return [
|
||||
'require_https' => env('REQUIRE_HTTPS', true),
|
||||
'app_url' => rtrim(env('APP_URL', ''), '/'),
|
||||
'app_domain' => env('APP_DOMAIN', ''),
|
||||
'app_version' => '5.1.43',
|
||||
'app_tag' => '5.1.43-release',
|
||||
'app_version' => '5.1.47',
|
||||
'app_tag' => '5.1.47-release',
|
||||
'minimum_client_version' => '5.0.16',
|
||||
'terms_version' => '1.0.1',
|
||||
'api_secret' => env('API_SECRET', false),
|
||||
|
@ -19,3 +19,8 @@
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
||||
</IfModule>
|
||||
|
||||
<IfModule mod_headers.c>
|
||||
# Blocks Search Engine Indexing
|
||||
Header set X-Robots-Tag "noindex, nofollow"
|
||||
</IfModule>
|
||||
|
4
public/flutter_service_worker.js
vendored
4
public/flutter_service_worker.js
vendored
@ -31,8 +31,8 @@ const RESOURCES = {
|
||||
"assets/assets/images/payment_types/paypal.png": "8e06c094c1871376dfea1da8088c29d1",
|
||||
"assets/assets/images/payment_types/maestro.png": "e533b92bfb50339fdbfa79e3dfe81f08",
|
||||
"assets/FontManifest.json": "cf3c681641169319e61b61bd0277378f",
|
||||
"main.dart.js": "589fe812bacbb3ceb0a5e0714f69a8cd",
|
||||
"version.json": "e021a7a1750aa3e7d1d89b51ac9837e9"
|
||||
"main.dart.js": "871343c03b10ac69cadb77e86ba9bc7c",
|
||||
"version.json": "b66865cd7c928a62b1b7809cad4d5f8c"
|
||||
};
|
||||
|
||||
// The application shell files that are downloaded before a service worker can
|
||||
|
239461
public/main.dart.js
vendored
239461
public/main.dart.js
vendored
File diff suppressed because one or more lines are too long
238303
public/main.foss.dart.js
vendored
238303
public/main.foss.dart.js
vendored
File diff suppressed because one or more lines are too long
233162
public/main.wasm.dart.js
vendored
233162
public/main.wasm.dart.js
vendored
File diff suppressed because one or more lines are too long
@ -1,2 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow:
|
||||
Disallow: /
|
||||
|
@ -1 +1 @@
|
||||
{"app_name":"invoiceninja_flutter","version":"5.0.45","build_number":"45"}
|
||||
{"app_name":"invoiceninja_flutter","version":"5.0.46","build_number":"46"}
|
@ -4209,6 +4209,8 @@ $LANG = array(
|
||||
'activity_82' => ':user archived subscription :subscription',
|
||||
'activity_83' => ':user deleted subscription :subscription',
|
||||
'activity_84' => ':user restored subscription :subscription',
|
||||
'amount_greater_than_balance_v5' => 'The amount is greater than the invoice balance. You cannot overpay an invoice.',
|
||||
'click_to_continue' => 'Click to continue',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -213,6 +213,11 @@
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
gap: 15px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
padding-top: 0.5rem
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -233,7 +238,9 @@
|
||||
<tr>
|
||||
<td class="page-footer-cell">
|
||||
<div class="footer-wrapper" id="footer">
|
||||
<div> <!-- #1 column --> </div>
|
||||
<div>
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
<div> <!-- #2 column --> </div>
|
||||
<div> <!-- #3 column --> </div>
|
||||
</div>
|
||||
|
@ -218,6 +218,10 @@
|
||||
text-align: right;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
padding-left: 1rem
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="header"></div>
|
||||
@ -252,4 +256,6 @@
|
||||
<table id="delivery-note-table" cellspacing="0"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
<div id="footer">
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
@ -186,6 +186,10 @@
|
||||
text-align: right;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
padding-left: 1rem
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="header"></div>
|
||||
@ -218,4 +222,6 @@
|
||||
<table id="delivery-note-table" cellspacing="0"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
<div id="footer">
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
@ -178,6 +178,10 @@
|
||||
text-align: right;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
padding-left: 1rem
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="header"></div>
|
||||
@ -216,4 +220,6 @@
|
||||
<table id="delivery-note-table" cellspacing="0"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
<div id="footer">
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
@ -172,6 +172,10 @@
|
||||
text-align: right;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
padding-left: 1rem
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="header"></div>
|
||||
@ -216,5 +220,7 @@
|
||||
<table id="delivery-note-table" cellspacing="0"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
<div id="footer">
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
||||
|
@ -257,4 +257,6 @@
|
||||
<table id="delivery-note-table" cellspacing="0"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
<div id="footer">
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
@ -222,6 +222,11 @@
|
||||
.page-content-cell {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 2rem
|
||||
}
|
||||
</style>
|
||||
|
||||
<table class="page-container">
|
||||
@ -242,7 +247,9 @@
|
||||
<div style="margin-top: 195px"></div>
|
||||
<div class="footer-wrapper" id="footer">
|
||||
<div class="footer-content">
|
||||
<div></div>
|
||||
<div>
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
<div id="company-details"></div>
|
||||
<div id="company-address"></div>
|
||||
</div>
|
||||
|
@ -150,6 +150,10 @@
|
||||
text-align: right;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
[data-ref="total_table-public_notes"] {
|
||||
padding-left: 1rem
|
||||
}
|
||||
</style>
|
||||
<div id="header"></div>
|
||||
|
||||
@ -180,4 +184,6 @@
|
||||
<table id="delivery-note-table" cellspacing="0"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
<div id="footer">
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
@ -94,7 +94,9 @@
|
||||
#product-table,
|
||||
#delivery-note-table,
|
||||
#task-table {
|
||||
padding: 3rem;
|
||||
padding-left: 3rem;
|
||||
padding-right: 3rem;
|
||||
margin-top: 3rem;
|
||||
/* margin-bottom: 200px; */
|
||||
min-width: 100%;
|
||||
table-layout: fixed;
|
||||
@ -220,17 +222,10 @@
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
min-width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
|
||||
margin-left: -10px;
|
||||
}
|
||||
|
||||
#footer > * {
|
||||
padding: 5px;
|
||||
[data-ref="total_table-public_notes"] {
|
||||
text-align: left;
|
||||
padding-left: 3rem;
|
||||
padding-right: 3rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -286,15 +281,6 @@
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
|
||||
|
||||
<div style="background-color: #00968B"><!-- 1 --></div>
|
||||
<div style="background-color: #1D756E"><!-- 2 --></div>
|
||||
<div style="background-color: #FCB600"><!-- 3 --></div>
|
||||
<div style="background-color: #BA932F"><!-- 4 --></div>
|
||||
<div style="background-color: #A72A4E"><!-- 5 --></div>
|
||||
<div style="background-color: #E20041"><!-- 6 --></div>
|
||||
<div style="background-color: #F8B300"><!-- 7 --></div>
|
||||
<div style="background-color: #009B8F"><!-- 8 --></div>
|
||||
<p data-ref="total_table-public_notes">$entity.public_notes</p>
|
||||
</div>
|
||||
|
||||
|
@ -135,6 +135,13 @@
|
||||
</svg>
|
||||
@endif
|
||||
</div>
|
||||
@elseif(!$steps['payment_required'])
|
||||
<form wire:submit.prevent="handlePaymentNotRequired" class="mt-8">
|
||||
@csrf
|
||||
<button class="px-3 py-2 border rounded mr-4 hover:border-blue-600">
|
||||
{{ ctrans('texts.click_to_continue') }}
|
||||
</button>
|
||||
</form>
|
||||
@elseif($steps['show_start_trial'])
|
||||
<form wire:submit.prevent="handleTrial" class="mt-8">
|
||||
@csrf
|
||||
|
@ -1,6 +1,9 @@
|
||||
<div class="grid grid-cols-12 gap-8 mt-8">
|
||||
<div class="col-span-12 md:col-span-5 md:col-start-4 px-4 py-5">
|
||||
<!-- Total price -->
|
||||
|
||||
@if($amount > 0)
|
||||
|
||||
<div class="relative mt-8">
|
||||
<div class="absolute inset-0 flex items-center">
|
||||
<div class="w-full border-t border-gray-300"></div>
|
||||
@ -15,7 +18,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if($state['invoice'])
|
||||
<form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}"
|
||||
method="post" id="payment-method-form">
|
||||
@csrf
|
||||
@ -32,7 +34,6 @@
|
||||
<input type="hidden" name="company_gateway_id" value="{{ $state['company_gateway_id'] }}"/>
|
||||
<input type="hidden" name="payment_method_id" value="{{ $state['payment_method_id'] }}"/>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
<!-- Payment methods -->
|
||||
<div class="mt-8 flex flex-col items-center">
|
||||
@ -61,5 +62,10 @@
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@elseif($amount < 0)
|
||||
<button wire:click="handlePaymentNotRequired"class="px-3 py-2 border rounded mr-4 hover:border-blue-600">
|
||||
{{ ctrans('texts.click_to_continue') }}
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -42,7 +42,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Payment box -->
|
||||
@livewire('subscription-plan-switch', compact('subscription', 'target', 'contact'))
|
||||
@livewire('subscription-plan-switch', compact('recurring_invoice', 'subscription', 'target', 'contact', 'amount'))
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
@ -140,6 +140,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
|
||||
Route::put('tasks/{task}/upload', 'TaskController@upload');
|
||||
Route::post('tasks/sort', 'TaskController@sort');
|
||||
|
||||
Route::resource('task_statuses', 'TaskStatusController'); // name = (task_statuses. index / create / show / update / destroy / edit
|
||||
Route::post('task_statuses/bulk', 'TaskStatusController@bulk')->name('task_statuses.bulk');
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\Subscription;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -20,6 +21,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -39,6 +41,8 @@ class SubscriptionApiTest extends TestCase
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
|
||||
Session::start();
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
@ -95,28 +99,23 @@ class SubscriptionApiTest extends TestCase
|
||||
|
||||
$response1 = $this
|
||||
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
|
||||
->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'name' => Str::random(5)])
|
||||
->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'name' => Str::random(5)])
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$response2 = $this
|
||||
// try {
|
||||
$response2 = $this
|
||||
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
|
||||
->put('/api/v1/subscriptions/' . $response1['data']['id'], ['allow_cancellation' => true])
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
// }catch(ValidationException $e) {
|
||||
// nlog($e->validator->getMessageBag());
|
||||
// }
|
||||
|
||||
$this->assertNotEquals($response1['data']['allow_cancellation'], $response2['data']['allow_cancellation']);
|
||||
}
|
||||
|
||||
/*
|
||||
TypeError : Argument 1 passed to App\Transformers\SubscriptionTransformer::transform() must be an instance of App\Models\Subscription, bool given, called in /var/www/html/vendor/league/fractal/src/Scope.php on line 407
|
||||
/var/www/html/app/Transformers/SubscriptionTransformer.php:35
|
||||
/var/www/html/vendor/league/fractal/src/Scope.php:407
|
||||
/var/www/html/vendor/league/fractal/src/Scope.php:349
|
||||
/var/www/html/vendor/league/fractal/src/Scope.php:235
|
||||
/var/www/html/app/Http/Controllers/BaseController.php:395
|
||||
/var/www/html/app/Http/Controllers/SubscriptionController.php:408
|
||||
*/
|
||||
public function testSubscriptionDeleted()
|
||||
{
|
||||
|
||||
|
@ -122,6 +122,23 @@ class TaskStatusApiTest extends TestCase
|
||||
$this->assertEquals(0, $arr['data'][0]['archived_at']);
|
||||
}
|
||||
|
||||
|
||||
public function testTaskStatusDeletedFromDELETEROute()
|
||||
{
|
||||
$data = [
|
||||
'ids' => [$this->encodePrimaryKey($this->task_status->id)],
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/task_statuses/'.$this->encodePrimaryKey($this->task_status->id));
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertTrue($arr['data']['is_deleted']);
|
||||
}
|
||||
|
||||
public function testTaskStatusDeleted()
|
||||
{
|
||||
$data = [
|
||||
|
@ -39,56 +39,56 @@ class TaskStatusSortOnUpdateTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testTasksSort()
|
||||
{
|
||||
// public function testTasksSort()
|
||||
// {
|
||||
|
||||
$project = Project::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'name' => 'Test Project',
|
||||
]);
|
||||
// $project = Project::factory()->create([
|
||||
// 'user_id' => $this->user->id,
|
||||
// 'company_id' => $this->company->id,
|
||||
// 'name' => 'Test Project',
|
||||
// ]);
|
||||
|
||||
for($x=0; $x<10; $x++)
|
||||
{
|
||||
$task = Task::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'project_id' => $project->id
|
||||
]);
|
||||
// for($x=0; $x<10; $x++)
|
||||
// {
|
||||
// $task = Task::factory()->create([
|
||||
// 'user_id' => $this->user->id,
|
||||
// 'company_id' => $this->company->id,
|
||||
// 'project_id' => $project->id
|
||||
// ]);
|
||||
|
||||
$task->status_id = TaskStatus::where('company_id', $this->company->id)->first()->id;
|
||||
$task->save();
|
||||
}
|
||||
// $task->status_id = TaskStatus::where('company_id', $this->company->id)->first()->id;
|
||||
// $task->save();
|
||||
// }
|
||||
|
||||
|
||||
$this->assertTrue($task->project()->exists());
|
||||
$this->assertEquals($task->project->tasks->count(), 10);
|
||||
// $this->assertTrue($task->project()->exists());
|
||||
// $this->assertEquals($task->project->tasks->count(), 10);
|
||||
|
||||
$task->status_order = 1;
|
||||
// $task->status_order = 1;
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/tasks/'.$this->encodePrimaryKey($task->id), $task->toArray());
|
||||
// $response = $this->withHeaders([
|
||||
// 'X-API-SECRET' => config('ninja.api_secret'),
|
||||
// 'X-API-TOKEN' => $this->token,
|
||||
// ])->put('/api/v1/tasks/'.$this->encodePrimaryKey($task->id), $task->toArray());
|
||||
|
||||
$response->assertStatus(200);
|
||||
// $response->assertStatus(200);
|
||||
|
||||
$this->assertEquals($task->fresh()->status_order, 1);
|
||||
// $this->assertEquals($task->fresh()->status_order, 1);
|
||||
|
||||
|
||||
$task->status_order = 10;
|
||||
// $task->status_order = 10;
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/tasks/'.$this->encodePrimaryKey($task->id), $task->toArray());
|
||||
// $response = $this->withHeaders([
|
||||
// 'X-API-SECRET' => config('ninja.api_secret'),
|
||||
// 'X-API-TOKEN' => $this->token,
|
||||
// ])->put('/api/v1/tasks/'.$this->encodePrimaryKey($task->id), $task->toArray());
|
||||
|
||||
$response->assertStatus(200);
|
||||
// $response->assertStatus(200);
|
||||
|
||||
nlog($task->fresh()->project->tasks->toArray());
|
||||
// nlog($task->fresh()->project->tasks->toArray());
|
||||
|
||||
$this->assertEquals($task->fresh()->status_order, 9);
|
||||
// $this->assertEquals($task->fresh()->status_order, 9);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user