1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-30 05:07:11 +02:00

Merge pull request #5466 from turbo124/v5-stable

v5.1.47
This commit is contained in:
David Bomba 2021-04-18 21:17:45 +10:00 committed by GitHub
commit c6454aafc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 351352 additions and 348947 deletions

View File

@ -1 +1 @@
5.1.46 5.1.47

View File

@ -229,8 +229,8 @@ class CreateSingleAccount extends Command
'company_id' => $company->id, 'company_id' => $company->id,
'product_key' => 'enterprise_plan', 'product_key' => 'enterprise_plan',
'notes' => 'The Enterprise Plan', 'notes' => 'The Enterprise Plan',
'cost' => 10, 'cost' => 14,
'price' => 10, 'price' => 14,
'quantity' => 1, 'quantity' => 1,
]); ]);

View File

@ -388,20 +388,20 @@ class DemoMode extends Command
$invoice->line_items = $this->buildLineItems(rand(1, 10)); $invoice->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false; $invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) { // if (rand(0, 1)) {
$invoice->tax_name1 = 'GST'; // $invoice->tax_name1 = 'GST';
$invoice->tax_rate1 = 10.00; // $invoice->tax_rate1 = 10.00;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$invoice->tax_name2 = 'VAT'; // $invoice->tax_name2 = 'VAT';
$invoice->tax_rate2 = 17.50; // $invoice->tax_rate2 = 17.50;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$invoice->tax_name3 = 'CA Sales Tax'; // $invoice->tax_name3 = 'CA Sales Tax';
$invoice->tax_rate3 = 5; // $invoice->tax_rate3 = 5;
} // }
// $invoice->custom_value1 = $faker->date; // $invoice->custom_value1 = $faker->date;
// $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no'; // $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->line_items = $this->buildLineItems(rand(1, 10));
$invoice->uses_inclusive_taxes = false; $invoice->uses_inclusive_taxes = false;
if (rand(0, 1)) { // if (rand(0, 1)) {
$invoice->tax_name1 = 'GST'; // $invoice->tax_name1 = 'GST';
$invoice->tax_rate1 = 10.00; // $invoice->tax_rate1 = 10.00;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$invoice->tax_name2 = 'VAT'; // $invoice->tax_name2 = 'VAT';
$invoice->tax_rate2 = 17.50; // $invoice->tax_rate2 = 17.50;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$invoice->tax_name3 = 'CA Sales Tax'; // $invoice->tax_name3 = 'CA Sales Tax';
$invoice->tax_rate3 = 5; // $invoice->tax_rate3 = 5;
} // }
// $invoice->custom_value1 = $faker->date; // $invoice->custom_value1 = $faker->date;
// $invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no'; // $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->line_items = $this->buildLineItems(rand(1, 10));
$credit->uses_inclusive_taxes = false; $credit->uses_inclusive_taxes = false;
if (rand(0, 1)) { // if (rand(0, 1)) {
$credit->tax_name1 = 'GST'; // $credit->tax_name1 = 'GST';
$credit->tax_rate1 = 10.00; // $credit->tax_rate1 = 10.00;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$credit->tax_name2 = 'VAT'; // $credit->tax_name2 = 'VAT';
$credit->tax_rate2 = 17.50; // $credit->tax_rate2 = 17.50;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$credit->tax_name3 = 'CA Sales Tax'; // $credit->tax_name3 = 'CA Sales Tax';
$credit->tax_rate3 = 5; // $credit->tax_rate3 = 5;
} // }
$credit->save(); $credit->save();
@ -559,20 +559,20 @@ class DemoMode extends Command
$quote->line_items = $this->buildLineItems(rand(1, 10)); $quote->line_items = $this->buildLineItems(rand(1, 10));
$quote->uses_inclusive_taxes = false; $quote->uses_inclusive_taxes = false;
if (rand(0, 1)) { // if (rand(0, 1)) {
$quote->tax_name1 = 'GST'; // $quote->tax_name1 = 'GST';
$quote->tax_rate1 = 10.00; // $quote->tax_rate1 = 10.00;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$quote->tax_name2 = 'VAT'; // $quote->tax_name2 = 'VAT';
$quote->tax_rate2 = 17.50; // $quote->tax_rate2 = 17.50;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$quote->tax_name3 = 'CA Sales Tax'; // $quote->tax_name3 = 'CA Sales Tax';
$quote->tax_rate3 = 5; // $quote->tax_rate3 = 5;
} // }
$quote->save(); $quote->save();
@ -600,20 +600,20 @@ class DemoMode extends Command
$item->quantity = 1; $item->quantity = 1;
//$item->cost = 10; //$item->cost = 10;
if (rand(0, 1)) { // if (rand(0, 1)) {
$item->tax_name1 = 'GST'; // $item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00; // $item->tax_rate1 = 10.00;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$item->tax_name1 = 'VAT'; // $item->tax_name1 = 'VAT';
$item->tax_rate1 = 17.50; // $item->tax_rate1 = 17.50;
} // }
if (rand(0, 1)) { // if (rand(0, 1)) {
$item->tax_name1 = 'Sales Tax'; // $item->tax_name1 = 'Sales Tax';
$item->tax_rate1 = 5; // $item->tax_rate1 = 5;
} // }
$product = Product::all()->random(); $product = Product::all()->random();

View File

@ -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();
}
} }
/** /**

View File

@ -22,6 +22,7 @@ class TaskStatusFactory
$task_status->company_id = $company_id; $task_status->company_id = $company_id;
$task_status->name = ''; $task_status->name = '';
$task_status->color = '#fff'; $task_status->color = '#fff';
$task_status->status_order = 9999;
return $task_status; return $task_status;
} }

View File

@ -23,6 +23,7 @@ use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentHash; use App\Models\PaymentHash;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\Services\Subscription\SubscriptionService;
use App\Utils\Number; use App\Utils\Number;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
@ -342,6 +343,12 @@ class PaymentController extends Controller
$payment = $payment->service()->applyCredits($payment_hash)->save(); $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)]); return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
} }

View File

@ -35,7 +35,6 @@ class SubscriptionPlanSwitchController extends Controller
$amount = $recurring_invoice->subscription $amount = $recurring_invoice->subscription
->service() ->service()
->calculateUpgradePrice($recurring_invoice, $target); ->calculateUpgradePrice($recurring_invoice, $target);
/** /**
* *
* Null value here is a proxy for * Null value here is a proxy for

View File

@ -592,7 +592,7 @@ class PaymentController extends BaseController
$this->payment_repo->restore($payment); $this->payment_repo->restore($payment);
if (! $bulk) { if (! $bulk) {
return $this->listResponse($payment); return $this->itemResponse($payment);
} }
break; break;
@ -600,7 +600,7 @@ class PaymentController extends BaseController
$this->payment_repo->archive($payment); $this->payment_repo->archive($payment);
if (! $bulk) { if (! $bulk) {
return $this->listResponse($payment); return $this->itemResponse($payment);
} }
// code... // code...
break; break;
@ -608,12 +608,24 @@ class PaymentController extends BaseController
$this->payment_repo->delete($payment); $this->payment_repo->delete($payment);
if (! $bulk) { if (! $bulk) {
return $this->listResponse($payment); return $this->itemResponse($payment);
} }
// code... // code...
break; break;
case 'email': case 'email':
//dispatch email to queue //dispatch email to queue
$payment->service()->sendEmail();
if (! $bulk) {
return $this->itemResponse($payment);
}
break;
case 'email_receipt':
$this->payment->service()->sendEmail();
if (! $bulk) {
return $this->itemResponse($payment);
}
break; break;
default: default:
@ -671,6 +683,8 @@ class PaymentController extends BaseController
{ {
$payment = $request->payment(); $payment = $request->payment();
// nlog($request->all());
$payment = $payment->refund($request->all()); $payment = $payment->refund($request->all());
return $this->itemResponse($payment); return $this->itemResponse($payment);

View File

@ -85,7 +85,7 @@ class SelfUpdateController extends BaseController
Artisan::call('clear-compiled'); Artisan::call('clear-compiled');
Artisan::call('cache:clear'); Artisan::call('cache:clear');
Artisan::call('debugbar:clear'); // Artisan::call('debugbar:clear');
Artisan::call('route:clear'); Artisan::call('route:clear');
Artisan::call('view:clear'); Artisan::call('view:clear');
Artisan::call('config:clear'); Artisan::call('config:clear');

View File

@ -19,11 +19,13 @@ use App\Http\Requests\Task\CreateTaskRequest;
use App\Http\Requests\Task\DestroyTaskRequest; use App\Http\Requests\Task\DestroyTaskRequest;
use App\Http\Requests\Task\EditTaskRequest; use App\Http\Requests\Task\EditTaskRequest;
use App\Http\Requests\Task\ShowTaskRequest; use App\Http\Requests\Task\ShowTaskRequest;
use App\Http\Requests\Task\SortTaskRequest;
use App\Http\Requests\Task\StoreTaskRequest; use App\Http\Requests\Task\StoreTaskRequest;
use App\Http\Requests\Task\UpdateTaskRequest; use App\Http\Requests\Task\UpdateTaskRequest;
use App\Http\Requests\Task\UploadTaskRequest; use App\Http\Requests\Task\UploadTaskRequest;
use App\Models\Account; use App\Models\Account;
use App\Models\Task; use App\Models\Task;
use App\Models\TaskStatus;
use App\Repositories\TaskRepository; use App\Repositories\TaskRepository;
use App\Transformers\TaskTransformer; use App\Transformers\TaskTransformer;
use App\Utils\Ninja; use App\Utils\Ninja;
@ -279,8 +281,8 @@ class TaskController extends BaseController
$task = $this->task_repo->save($request->all(), $task); $task = $this->task_repo->save($request->all(), $task);
// if($task->status_order != $old_task->status_order) if($task->status_order != $old_task->status_order)
// $this->task_repo->sortStatuses($old_task, $task); $this->task_repo->sortStatuses($old_task, $task);
event(new TaskWasUpdated($task, $task->company, Ninja::eventVars(auth()->user()->id))); event(new TaskWasUpdated($task, $task->company, Ninja::eventVars(auth()->user()->id)));
@ -579,4 +581,88 @@ class TaskController extends BaseController
return $this->itemResponse($task->fresh()); 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);
}
} }

View File

@ -8,6 +8,7 @@ use App\Http\Requests\TaskStatus\DestroyTaskStatusRequest;
use App\Http\Requests\TaskStatus\ShowTaskStatusRequest; use App\Http\Requests\TaskStatus\ShowTaskStatusRequest;
use App\Http\Requests\TaskStatus\StoreTaskStatusRequest; use App\Http\Requests\TaskStatus\StoreTaskStatusRequest;
use App\Http\Requests\TaskStatus\UpdateTaskStatusRequest; use App\Http\Requests\TaskStatus\UpdateTaskStatusRequest;
use App\Models\Task;
use App\Models\TaskStatus; use App\Models\TaskStatus;
use App\Repositories\TaskStatusRepository; use App\Repositories\TaskStatusRepository;
use App\Transformers\TaskStatusTransformer; use App\Transformers\TaskStatusTransformer;
@ -398,7 +399,8 @@ class TaskStatusController extends BaseController
*/ */
public function destroy(DestroyTaskStatusRequest $request, TaskStatus $task_status) public function destroy(DestroyTaskStatusRequest $request, TaskStatus $task_status)
{ {
$task_status->delete();
$this->task_status_repo->delete($task_status);
return $this->itemResponse($task_status->fresh()); return $this->itemResponse($task_status->fresh());
} }

View File

@ -11,11 +11,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Utils\Ninja;
use App\Utils\TemplateEngine; use App\Utils\TemplateEngine;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml; use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\MakesTemplateData; use App\Utils\Traits\MakesTemplateData;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
class TemplateController extends BaseController class TemplateController extends BaseController
{ {

View File

@ -330,9 +330,9 @@ class BillingPortalPurchase extends Component
$is_eligible = $this->subscription->service()->isEligible($this->contact); $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'] = true;
$this->steps['not_eligible_message'] = $is_eligible['exception']; $this->steps['not_eligible_message'] = $is_eligible['exception']['message'];
$this->steps['show_loading_bar'] = false; $this->steps['show_loading_bar'] = false;
return; return;

View File

@ -25,7 +25,7 @@ class RecurringInvoiceCancellation extends Component
public function processCancellation() public function processCancellation()
{ {
if ($this->invoice->subscription) { 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]); return redirect()->route('client.recurring_invoices.request_cancellation', ['recurring_invoice' => $this->invoice->hashed_id]);

View File

@ -82,6 +82,7 @@ class SubscriptionPlanSwitch extends Component
public function handleBeforePaymentEvents(): void public function handleBeforePaymentEvents(): void
{ {
$this->state['show_loading_bar'] = true; $this->state['show_loading_bar'] = true;
$this->state['invoice'] = $this->target->service()->createChangePlanInvoice([ $this->state['invoice'] = $this->target->service()->createChangePlanInvoice([
@ -121,6 +122,18 @@ class SubscriptionPlanSwitch extends Component
$this->handleBeforePaymentEvents(); $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() public function render()
{ {
return render('components.livewire.subscription-plan-switch'); return render('components.livewire.subscription-plan-switch');

View File

@ -51,7 +51,7 @@ class StoreInvoiceRequest extends Request
$rules['invitations.*.client_contact_id'] = 'distinct'; $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())]; $rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];

View File

@ -56,7 +56,7 @@ class UpdateSubscriptionRequest extends Request
'allow_plan_changes' => ['sometimes'], 'allow_plan_changes' => ['sometimes'],
'refund_period' => ['sometimes'], 'refund_period' => ['sometimes'],
'webhook_configuration' => ['array'], 'webhook_configuration' => ['array'],
'name' => ['required', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)->ignore($this->subscription->id)] 'name' => ['sometimes', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)->ignore($this->subscription->id)]
]; ];
return $this->globalRules($rules); return $this->globalRules($rules);

View 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 [];
}
}

View File

@ -45,10 +45,10 @@ class CreateCompanyTaskStatuses
public function handle() public function handle()
{ {
$task_statuses = [ $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.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()], ['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()], ['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()], ['name' => ctrans('texts.done'), 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'created_at' => now(), 'updated_at' => now(), 'status_order' => 4],
]; ];

View File

@ -674,6 +674,8 @@ class Import implements ShouldQueue
$resource['invitations'][$key]['user_id'] = $modified['user_id']; $resource['invitations'][$key]['user_id'] = $modified['user_id'];
$resource['invitations'][$key]['company_id'] = $this->company->id; $resource['invitations'][$key]['company_id'] = $this->company->id;
unset($resource['invitations'][$key]['recurring_invoice_id']); unset($resource['invitations'][$key]['recurring_invoice_id']);
unset($resource['invitations'][$key]['id']);
} }
$modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']); $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]['user_id'] = $modified['user_id'];
$resource['invitations'][$key]['company_id'] = $this->company->id; $resource['invitations'][$key]['company_id'] = $this->company->id;
unset($resource['invitations'][$key]['invoice_id']); unset($resource['invitations'][$key]['invoice_id']);
unset($resource['invitations'][$key]['id']);
} }
$modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']); $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]['user_id'] = $modified['user_id'];
$resource['invitations'][$key]['company_id'] = $this->company->id; $resource['invitations'][$key]['company_id'] = $this->company->id;
unset($resource['invitations'][$key]['invoice_id']); unset($resource['invitations'][$key]['invoice_id']);
unset($resource['invitations'][$key]['id']);
} }
$modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']); $modified['invitations'] = $this->deDuplicateInvitations($resource['invitations']);

View File

@ -12,7 +12,10 @@
namespace App\Mail\Engine; namespace App\Mail\Engine;
use App\Utils\HtmlEngine; use App\Utils\HtmlEngine;
use App\Utils\Ninja;
use App\Utils\Number; use App\Utils\Number;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
class CreditEmailEngine extends BaseEmailEngine class CreditEmailEngine extends BaseEmailEngine
{ {
@ -40,6 +43,9 @@ class CreditEmailEngine extends BaseEmailEngine
public function build() 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) { 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']; $body_template = $this->template_data['body'];
} else { } else {

View File

@ -14,7 +14,10 @@ namespace App\Mail\Engine;
use App\DataMapper\EmailTemplateDefaults; use App\DataMapper\EmailTemplateDefaults;
use App\Models\Account; use App\Models\Account;
use App\Utils\HtmlEngine; use App\Utils\HtmlEngine;
use App\Utils\Ninja;
use App\Utils\Number; use App\Utils\Number;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
class InvoiceEmailEngine extends BaseEmailEngine class InvoiceEmailEngine extends BaseEmailEngine
{ {
@ -42,6 +45,10 @@ class InvoiceEmailEngine extends BaseEmailEngine
public function build() 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) { 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']; $body_template = $this->template_data['body'];
} elseif (strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0) { } elseif (strlen($this->client->getSetting('email_template_'.$this->reminder_template)) > 0) {

View File

@ -13,7 +13,10 @@ namespace App\Mail\Engine;
use App\Models\Account; use App\Models\Account;
use App\Utils\HtmlEngine; use App\Utils\HtmlEngine;
use App\Utils\Ninja;
use App\Utils\Number; use App\Utils\Number;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
class QuoteEmailEngine extends BaseEmailEngine class QuoteEmailEngine extends BaseEmailEngine
{ {
@ -41,6 +44,9 @@ class QuoteEmailEngine extends BaseEmailEngine
public function build() 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) { 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']; $body_template = $this->template_data['body'];
} else { } else {

View File

@ -45,12 +45,29 @@ class Webhook extends BaseModel
public static $valid_events = [ public static $valid_events = [
self::EVENT_CREATE_CLIENT, self::EVENT_CREATE_CLIENT,
self::EVENT_CREATE_PAYMENT,
self::EVENT_CREATE_QUOTE,
self::EVENT_CREATE_INVOICE, self::EVENT_CREATE_INVOICE,
self::EVENT_CREATE_QUOTE,
self::EVENT_CREATE_PAYMENT,
self::EVENT_CREATE_VENDOR, 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_CREATE_EXPENSE,
self::EVENT_UPDATE_EXPENSE,
self::EVENT_DELETE_EXPENSE,
self::EVENT_CREATE_TASK, 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 = [ protected $fillable = [

View File

@ -16,16 +16,21 @@ class MailServiceProvider extends MailProvider
$this->registerIlluminateMailer(); $this->registerIlluminateMailer();
} }
public function boot()
{
}
protected function registerIlluminateMailer() protected function registerIlluminateMailer()
{ {
// $this->app->singleton('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); return new GmailTransportManager($app);
}); });
// $this->app->bind('mail.manager', function($app) {
// return new GmailTransportManager($app);
// });
$this->app->bind('mailer', function ($app) { $this->app->bind('mailer', function ($app) {
return $app->make('mail.manager')->mailer(); return $app->make('mail.manager')->mailer();
}); });
@ -33,14 +38,22 @@ class MailServiceProvider extends MailProvider
$this->app['mail.manager']->extend('postmark', function () { $this->app['mail.manager']->extend('postmark', function () {
return new PostmarkTransport( return new PostmarkTransport(
$this->guzzle(config('postmark.guzzle', [])), $this->guzzle(config('postmark.guzzle', [])),
config('postmark.secret', config('services.postmark.secret')) config('postmark.secret')
); );
}); });
} }
protected function guzzle(array $config): HttpClient protected function guzzle(array $config): HttpClient
{ {
return new HttpClient($config); return new HttpClient($config);
} }
public function provides()
{
return [
'mail.manager',
'mailer' ];
}
} }

View File

@ -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) { $this->app->singleton('translator', function ($app) {
$loader = $app['translation.loader']; $loader = $app['translation.loader'];
$locale = $app['config']['app.locale']; $locale = $app['config']['app.locale'];
@ -42,6 +56,8 @@ class NinjaTranslationServiceProvider extends TranslationServiceProvider
$trans->setFallback($app['config']['app.fallback_locale']); $trans->setFallback($app['config']['app.fallback_locale']);
return $trans; return $trans;
}); });
} }
} }

View File

@ -291,6 +291,10 @@ class BaseRepository
/* Apply entity number */ /* Apply entity number */
$model = $model->service()->applyNumber()->save(); $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 */ /* Update product details if necessary */
if ($model->company->update_products) if ($model->company->update_products)
UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company); UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company);

View File

@ -155,6 +155,10 @@ class PaymentRepository extends BaseRepository {
} }
if ( ! $is_existing_payment && ! $this->import_mode ) { if ( ! $is_existing_payment && ! $this->import_mode ) {
if ($payment->client->getSetting('client_manual_payment_notification'))
$payment->service()->sendEmail();
event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user()->id) ) ); event( new PaymentWasCreated( $payment, $payment->company, Ninja::eventVars(auth()->user()->id) ) );
} }

View File

@ -11,9 +11,39 @@
namespace App\Repositories; namespace App\Repositories;
use App\Models\Task;
/** /**
* Class for task status repository. * Class for task status repository.
*/ */
class TaskStatusRepository extends BaseRepository 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;
}
} }

View File

@ -148,7 +148,7 @@ class ApplyPayment
if ((int)$this->invoice->balance == 0) { if ((int)$this->invoice->balance == 0) {
$this->invoice->service()->deletePdf(); $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)));
} }
} }
} }

View File

@ -34,7 +34,7 @@ class ConvertQuote
public function run($quote) public function run($quote)
{ {
$invoice = CloneQuoteToInvoiceFactory::create($quote, $quote->user_id); $invoice = CloneQuoteToInvoiceFactory::create($quote, $quote->user_id);
$invoice->design_id = $this->client->getSetting('invoice_design_id');
$invoice = $this->invoice_repo->save([], $invoice); $invoice = $this->invoice_repo->save([], $invoice);
$invoice->fresh(); $invoice->fresh();

View File

@ -12,6 +12,7 @@
namespace App\Services\Subscription; namespace App\Services\Subscription;
use App\DataMapper\InvoiceItem; use App\DataMapper\InvoiceItem;
use App\Factory\CreditFactory;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
use App\Factory\InvoiceToRecurringInvoiceFactory; use App\Factory\InvoiceToRecurringInvoiceFactory;
use App\Factory\RecurringInvoiceFactory; use App\Factory\RecurringInvoiceFactory;
@ -26,6 +27,7 @@ use App\Models\Product;
use App\Models\RecurringInvoice; use App\Models\RecurringInvoice;
use App\Models\Subscription; use App\Models\Subscription;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\Repositories\CreditRepository;
use App\Repositories\InvoiceRepository; use App\Repositories\InvoiceRepository;
use App\Repositories\RecurringInvoiceRepository; use App\Repositories\RecurringInvoiceRepository;
use App\Repositories\SubscriptionRepository; use App\Repositories\SubscriptionRepository;
@ -64,7 +66,7 @@ class SubscriptionService
if($payment_hash->data->billing_context->context == 'change_plan') { if($payment_hash->data->billing_context->context == 'change_plan') {
return $this->handlePlanChange($payment_hash); return $this->handlePlanChange($payment_hash);
}; }
// if we have a recurring product - then generate a recurring invoice // if we have a recurring product - then generate a recurring invoice
if(strlen($this->subscription->recurring_product_ids) >=1){ if(strlen($this->subscription->recurring_product_ids) >=1){
@ -130,7 +132,7 @@ class SubscriptionService
]; ];
$response = $this->triggerWebhook($context); $response = $this->triggerWebhook($context);
nlog($response);
return $response; return $response;
} }
@ -177,13 +179,20 @@ class SubscriptionService
//execute any webhooks //execute any webhooks
$response = $this->triggerWebhook($context); $response = $this->triggerWebhook($context);
if(array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >=1){ return $this->handleRedirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
return redirect($this->subscription->webhook_configuration['return_url']);
}
return redirect('/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 public function calculateUpgradePrice(RecurringInvoice $recurring_invoice, Subscription $target) :?float
{ {
//calculate based on daily prices //calculate based on daily prices
@ -197,16 +206,20 @@ class SubscriptionService
->where('balance', '>', 0); ->where('balance', '>', 0);
$outstanding_amounts = $outstanding->sum('balance'); $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){ if ($outstanding->count() == 0){
//nothing outstanding //nothing outstanding
return $target->price; return $target->price - $this->calculateProRataRefund($outstanding_invoice);
} }
elseif ($outstanding->count() == 1){ elseif ($outstanding->count() == 1){
//user has multiple amounts outstanding //user has multiple amounts outstanding
return $target->price - $this->calculateProRataRefund($outstanding->first()); return $target->price - $this->calculateProRataRefund($outstanding_invoice);
} }
elseif ($outstanding->count() > 1) { elseif ($outstanding->count() > 1) {
//user is changing plan mid frequency cycle //user is changing plan mid frequency cycle
@ -231,13 +244,59 @@ class SubscriptionService
$current_date = now(); $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(); $days_in_frequency = $this->getDaysInFrequency();
$pro_rata_refund = round((($days_in_frequency - $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; return $pro_rata_refund;
}
/**
* 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
{
/* depending on whether we are creating an invoice or a credit*/
$multiplier = $is_credit ? 1 : -1;
$start_date = Carbon::parse($invoice->date);
$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;
}
}
return $line_items;
} }
/** /**
@ -253,99 +312,163 @@ class SubscriptionService
$current_date = now(); $current_date = now();
$days_to_refund = $start_date->diffInDays($current_date); $days_to_charge = $start_date->diffInDays($current_date);
$days_in_frequency = $this->getDaysInFrequency(); $days_in_frequency = $this->getDaysInFrequency();
$pro_rata_refund = round(($days_to_refund/$days_in_frequency) * $invoice->amount ,2); nlog("days to charge = {$days_to_charge} fays in frequency = {$days_in_frequency}");
return $pro_rata_refund; $pro_rata_charge = round(($days_to_charge/$days_in_frequency) * $invoice->amount ,2);
nlog("pro rata charge = {$pro_rata_charge}");
return $pro_rata_charge;
} }
public function createChangePlanInvoice($data) /**
* When downgrading, we may need to create
* a credit
*
* @param array $data
*/
public function createChangePlanCredit($data)
{ {
$recurring_invoice = $data['recurring_invoice']; $recurring_invoice = $data['recurring_invoice'];
//Data array structure $old_subscription = $data['subscription'];
/** $target_subscription = $data['target'];
* [
* '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();
$pro_rata_charge_amount = 0; $pro_rata_charge_amount = 0;
$pro_rata_refund_amount = 0; $pro_rata_refund_amount = 0;
// // We calculate the pro rata charge for this invoice. $last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id)
// if($outstanding_invoice) ->where('client_id', $recurring_invoice->client_id)
// {
// }
$last_invoice = $recurring_invoice->invoices()
->where('is_deleted', 0) ->where('is_deleted', 0)
->withTrashed()
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->first(); ->first();
//$last_invoice may not be here! if($last_invoice->balance > 0)
if(!$last_invoice) {
$data = [
'client_id' => $recurring_invoice->client_id,
'coupon' => '',
];
return $this->createInvoice($data)->service()->markSent()->fillDefaults()->save();
}
else if($last_invoice->balance > 0)
{ {
$pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice); $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription);
nlog("pro rata charge = {$pro_rata_charge_amount}");
} }
else else
{ {
$pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice) * -1; $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; $total_payable = $pro_rata_refund_amount + $pro_rata_charge_amount + $this->subscription->price;
if($total_payable > 0) nlog("total payable = {$total_payable}");
{
return $this->proRataInvoice($pro_rata_refund_amount, $data['subscription'], $data['target']);
}
else
{
//create credit
}
$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);
return Invoice::where('status_id', Invoice::STATUS_SENT)->first();
} }
/** /**
* Response from payment service on return from a plan change * 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) private function handlePlanChange($payment_hash)
{ {
//payment has been made. $old_recurring_invoice = RecurringInvoice::find($payment_hash->data->billing_context->recurring_invoice);
//
//new subscription starts today - delete old recurring invoice.
$old_subscription_recurring_invoice = RecurringInvoice::find($payment_hash->data->billing_context->recurring_invoice); $recurring_invoice = $this->createNewRecurringInvoice($old_recurring_invoice);
$old_subscription_recurring_invoice->service()->stop()->save();
$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 = new RecurringInvoiceRepository();
$recurring_invoice_repo->archive($old_subscription_recurring_invoice); $recurring_invoice_repo->archive($old_recurring_invoice);
$recurring_invoice = $this->convertInvoiceToRecurring($payment_hash->payment->client_id); $recurring_invoice = $this->convertInvoiceToRecurring($old_recurring_invoice->client_id);
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice); $recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
$recurring_invoice->next_send_date = now(); $recurring_invoice->next_send_date = now();
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate(); $recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
@ -355,6 +478,20 @@ class SubscriptionService
->start() ->start()
->save(); ->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 = [
'context' => 'change_plan', 'context' => 'change_plan',
'recurring_invoice' => $recurring_invoice->hashed_id, 'recurring_invoice' => $recurring_invoice->hashed_id,
@ -366,54 +503,81 @@ class SubscriptionService
$response = $this->triggerWebhook($context); $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']);
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
}
public function handlePlanChangeNoPayment()
{
return $this->handleRedirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
} }
/** /**
* 'client_id' => 2, * Creates a credit note if the plan change requires
'date' => '2021-04-13', *
'invitations' => * @param Invoice $last_invoice
'user_input_promo_code' => NULL, * @param Subscription $target
'coupon' => '', * @return Credit
'quantity' => 1,
*/ */
private function proRataInvoice($refund_amount, $subscription, $target) private function createCredit($last_invoice, $target)
{ {
$subscription_repo = new SubscriptionRepository(); $subscription_repo = new SubscriptionRepository();
$invoice_repo = new InvoiceRepository(); $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); $line_items = $subscription_repo->generateLineItems($target);
$item = new InvoiceItem; $credit->line_items = array_merge($line_items, $this->calculateProRataRefundItems($last_invoice, true));
$item->quantity = 1;
$item->product_key = ctrans('texts.refund');
$item->notes = ctrans('texts.refund') . ":" .$subscription->name;
$item->cost = $refund_amount;
$line_items[] = $item;
$data = [ $data = [
'client_id' => $subscription->client_id, 'client_id' => $last_invoice->client_id,
'quantity' => 1, 'quantity' => 1,
'date' => now()->format('Y-m-d'), 'date' => now()->format('Y-m-d'),
]; ];
return $invoice_repo->save($data, $invoice)->service()->markSent()->fillDefaults()->save(); 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 public function createInvoice($data): ?\App\Models\Invoice
{ {
@ -434,7 +598,13 @@ class SubscriptionService
} }
/**
* 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 public function convertInvoiceToRecurring($client_id) :RecurringInvoice
{ {
@ -451,6 +621,11 @@ class SubscriptionService
return $recurring_invoice; return $recurring_invoice;
} }
/**
* Hit a 3rd party API if defined in the subscription
*
* @param array $context
*/
public function triggerWebhook($context) public function triggerWebhook($context)
{ {
/* If no webhooks have been set, then just return gracefully */ /* If no webhooks have been set, then just return gracefully */
@ -538,40 +713,93 @@ class SubscriptionService
->get(); ->get();
} }
public function handleCancellation() /**
* Handle the cancellation of a subscription
*
* @param RecurringInvoice $recurring_invoice
*
*/
public function handleCancellation(RecurringInvoice $recurring_invoice)
{ {
dd('Cancelling using SubscriptionService');
// .. //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() private function getDaysInFrequency()
{ {
switch ($this->subscription->frequency_id) { switch ($this->subscription->frequency_id) {
case self::FREQUENCY_DAILY: case RecurringInvoice::FREQUENCY_DAILY:
return 1; return 1;
case self::FREQUENCY_WEEKLY: case RecurringInvoice::FREQUENCY_WEEKLY:
return 7; return 7;
case self::FREQUENCY_TWO_WEEKS: case RecurringInvoice::FREQUENCY_TWO_WEEKS:
return 14; return 14;
case self::FREQUENCY_FOUR_WEEKS: case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
return now()->diffInDays(now()->addWeeks(4)); return now()->diffInDays(now()->addWeeks(4));
case self::FREQUENCY_MONTHLY: case RecurringInvoice::FREQUENCY_MONTHLY:
return now()->diffInDays(now()->addMonthNoOverflow()); return now()->diffInDays(now()->addMonthNoOverflow());
case self::FREQUENCY_TWO_MONTHS: case RecurringInvoice::FREQUENCY_TWO_MONTHS:
return now()->diffInDays(now()->addMonthNoOverflow(2)); return now()->diffInDays(now()->addMonthNoOverflow(2));
case self::FREQUENCY_THREE_MONTHS: case RecurringInvoice::FREQUENCY_THREE_MONTHS:
return now()->diffInDays(now()->addMonthNoOverflow(3)); return now()->diffInDays(now()->addMonthNoOverflow(3));
case self::FREQUENCY_FOUR_MONTHS: case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
return now()->diffInDays(now()->addMonthNoOverflow(4)); return now()->diffInDays(now()->addMonthNoOverflow(4));
case self::FREQUENCY_SIX_MONTHS: case RecurringInvoice::FREQUENCY_SIX_MONTHS:
return now()->diffInDays(now()->addMonthNoOverflow(6)); return now()->diffInDays(now()->addMonthNoOverflow(6));
case self::FREQUENCY_ANNUALLY: case RecurringInvoice::FREQUENCY_ANNUALLY:
return now()->diffInDays(now()->addYear()); return now()->diffInDays(now()->addYear());
case self::FREQUENCY_TWO_YEARS: case RecurringInvoice::FREQUENCY_TWO_YEARS:
return now()->diffInDays(now()->addYears(2)); return now()->diffInDays(now()->addYears(2));
case self::FREQUENCY_THREE_YEARS: case RecurringInvoice::FREQUENCY_THREE_YEARS:
return now()->diffInDays(now()->addYears(3)); return now()->diffInDays(now()->addYears(3));
default: default:
return 0; return 0;

View File

@ -16,10 +16,13 @@ use App\Models\Client;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\InvoiceInvitation; use App\Models\InvoiceInvitation;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml; use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\MakesTemplateData; use App\Utils\Traits\MakesTemplateData;
use DB; use DB;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;
use League\CommonMark\CommonMarkConverter; use League\CommonMark\CommonMarkConverter;
class TemplateEngine class TemplateEngine
@ -96,6 +99,9 @@ class TemplateEngine
$this->settings = $this->settings_entity->settings; $this->settings = $this->settings_entity->settings;
} }
App::forgetInstance('translator');
Lang::replace(Ninja::transformTranslations($this->settings));
return $this; return $this;
} }

View File

@ -14,8 +14,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', ''), 'app_domain' => env('APP_DOMAIN', ''),
'app_version' => '5.1.46', 'app_version' => '5.1.47',
'app_tag' => '5.1.46-release', 'app_tag' => '5.1.47-release',
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false), 'api_secret' => env('API_SECRET', false),

View File

@ -31,8 +31,8 @@ const RESOURCES = {
"assets/assets/images/payment_types/paypal.png": "8e06c094c1871376dfea1da8088c29d1", "assets/assets/images/payment_types/paypal.png": "8e06c094c1871376dfea1da8088c29d1",
"assets/assets/images/payment_types/maestro.png": "e533b92bfb50339fdbfa79e3dfe81f08", "assets/assets/images/payment_types/maestro.png": "e533b92bfb50339fdbfa79e3dfe81f08",
"assets/FontManifest.json": "cf3c681641169319e61b61bd0277378f", "assets/FontManifest.json": "cf3c681641169319e61b61bd0277378f",
"main.dart.js": "7387bc998747d4eda2e0fec919800d62", "main.dart.js": "c8128a36f8372b6a128afe89000b6038",
"version.json": "e021a7a1750aa3e7d1d89b51ac9837e9" "version.json": "b66865cd7c928a62b1b7809cad4d5f8c"
}; };
// The application shell files that are downloaded before a service worker can // The application shell files that are downloaded before a service worker can

234051
public/main.dart.js vendored

File diff suppressed because one or more lines are too long

230321
public/main.foss.dart.js vendored

File diff suppressed because one or more lines are too long

234932
public/main.wasm.dart.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"app_name":"invoiceninja_flutter","version":"5.0.45","build_number":"45"} {"app_name":"invoiceninja_flutter","version":"5.0.46","build_number":"46"}

View File

@ -1,6 +1,9 @@
<div class="grid grid-cols-12 gap-8 mt-8"> <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"> <div class="col-span-12 md:col-span-5 md:col-start-4 px-4 py-5">
<!-- Total price --> <!-- Total price -->
@if($amount > 0)
<div class="relative mt-8"> <div class="relative mt-8">
<div class="absolute inset-0 flex items-center"> <div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-gray-300"></div> <div class="w-full border-t border-gray-300"></div>
@ -15,7 +18,6 @@
</div> </div>
</div> </div>
@if($state['invoice'])
<form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}" <form action="{{ route('client.payments.process', ['hash' => $hash, 'sidebar' => 'hidden']) }}"
method="post" id="payment-method-form"> method="post" id="payment-method-form">
@csrf @csrf
@ -32,7 +34,6 @@
<input type="hidden" name="company_gateway_id" value="{{ $state['company_gateway_id'] }}"/> <input type="hidden" name="company_gateway_id" value="{{ $state['company_gateway_id'] }}"/>
<input type="hidden" name="payment_method_id" value="{{ $state['payment_method_id'] }}"/> <input type="hidden" name="payment_method_id" value="{{ $state['payment_method_id'] }}"/>
</form> </form>
@endif
<!-- Payment methods --> <!-- Payment methods -->
<div class="mt-8 flex flex-col items-center"> <div class="mt-8 flex flex-col items-center">
@ -61,5 +62,10 @@
@endif @endif
</div> </div>
</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>
</div> </div>

View File

@ -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::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk'); Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
Route::put('tasks/{task}/upload', 'TaskController@upload'); 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::resource('task_statuses', 'TaskStatusController'); // name = (task_statuses. index / create / show / update / destroy / edit
Route::post('task_statuses/bulk', 'TaskStatusController@bulk')->name('task_statuses.bulk'); Route::post('task_statuses/bulk', 'TaskStatusController@bulk')->name('task_statuses.bulk');

View File

@ -21,6 +21,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
@ -40,6 +41,8 @@ class SubscriptionApiTest extends TestCase
$this->makeTestData(); $this->makeTestData();
$this->withoutExceptionHandling();
Session::start(); Session::start();
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
@ -92,7 +95,6 @@ class SubscriptionApiTest extends TestCase
$product = Product::factory()->create([ $product = Product::factory()->create([
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
]); ]);
$response1 = $this $response1 = $this
@ -101,24 +103,19 @@ class SubscriptionApiTest extends TestCase
->assertStatus(200) ->assertStatus(200)
->json(); ->json();
// try {
$response2 = $this $response2 = $this
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token]) ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
->put('/api/v1/subscriptions/' . $response1['data']['id'], ['allow_cancellation' => true]) ->put('/api/v1/subscriptions/' . $response1['data']['id'], ['allow_cancellation' => true])
->assertStatus(200) ->assertStatus(200)
->json(); ->json();
// }catch(ValidationException $e) {
// nlog($e->validator->getMessageBag());
// }
$this->assertNotEquals($response1['data']['allow_cancellation'], $response2['data']['allow_cancellation']); $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() public function testSubscriptionDeleted()
{ {

View File

@ -122,6 +122,23 @@ class TaskStatusApiTest extends TestCase
$this->assertEquals(0, $arr['data'][0]['archived_at']); $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() public function testTaskStatusDeleted()
{ {
$data = [ $data = [