resolved conflicts'

This commit is contained in:
David Bomba 2021-03-18 12:00:01 +11:00
commit 9ca9736de6
37 changed files with 205 additions and 83 deletions

View File

@ -1 +1 @@
5.1.26
5.1.27

View File

@ -142,11 +142,11 @@ class ActivityController extends BaseController
$pdf = $this->makePdf(null, null, $backup->html_backup);
if (isset($activity->invoice_id)) {
$filename = $activity->invoice->number.'.pdf';
$filename = $activity->invoice->numberFormatter().'.pdf';
} elseif (isset($activity->quote_id)) {
$filename = $activity->quote->number.'.pdf';
$filename = $activity->quote->numberFormatter().'.pdf';
} elseif (isset($activity->credit_id)) {
$filename = $activity->credit->number.'.pdf';
$filename = $activity->credit->numberFormatter().'.pdf';
} else {
$filename = 'backup.pdf';
}

View File

@ -29,6 +29,7 @@ use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Illuminate\View\View;
@ -237,11 +238,18 @@ class PaymentController extends Controller
->get();
}
$hash_data = ['invoices' => $payable_invoices->toArray(), 'credits' => $credit_totals];
if ($request->query('hash')) {
$hash_data['billing_context'] = Cache::get($request->query('hash'));
}
$payment_hash = new PaymentHash;
$payment_hash->hash = Str::random(128);
$payment_hash->data = ['invoices' => $payable_invoices->toArray(), 'credits' => $credit_totals];
$payment_hash->data = $hash_data;
$payment_hash->fee_total = $fee_totals;
$payment_hash->fee_invoice_id = $first_invoice->id;
$payment_hash->save();
$totals = [

View File

@ -1,4 +1,13 @@
<?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\Http\Livewire;
@ -114,6 +123,8 @@ class BillingPortalPurchase extends Component
public function handleBeforePaymentEvents()
{
//stubs
$data = [
'client_id' => $this->contact->client->id,
'date' => now()->format('Y-m-d'),
@ -142,6 +153,8 @@ class BillingPortalPurchase extends Component
$this->emit('beforePaymentEventsCompleted');
}
//this isn't managed here - this is taken care of in the BS
public function applyCouponCode()
{
dd('Applying coupon code: ' . $this->coupon);

View File

@ -25,6 +25,7 @@ use App\Models\RecurringInvoiceInvitation;
use App\Services\PdfMaker\Design as PdfDesignModel;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
use App\Utils\HostedPDF\NinjaPdf;
use App\Utils\HtmlEngine;
use App\Utils\Ninja;
use App\Utils\PhantomJS\Phantom;
@ -115,7 +116,7 @@ class CreateEntityPdf implements ShouldQueue
$entity_design_id = 'invoice_design_id';
}
$file_path = $path.$this->entity->number.'.pdf';
$file_path = $path.$this->entity->numberFormatter().'.pdf';
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
@ -160,7 +161,13 @@ class CreateEntityPdf implements ShouldQueue
$pdf = null;
try {
if(config('ninja.invoiceninja_hosted_pdf_generation')){
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
}
else {
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
}
} catch (\Exception $e) {
nlog(print_r($e->getMessage(), 1));
}

View File

@ -186,6 +186,15 @@ class BaseModel extends Model
*/
public function getFileName($extension = 'pdf')
{
return $this->number.'.'.$extension;
return $this->numberFormatter().'.'.$extension;
}
public function numberFormatter()
{
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $this->number);
// Remove any runs of periods (thanks falstro!)
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
return $formatted_number;
}
}

View File

@ -73,5 +73,4 @@ class BillingSubscription extends BaseModel
{
return $this->belongsTo(Product::class);
}
}

View File

@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notification;
use Laracasts\Presenter\PresentableTrait;
use Illuminate\Support\Facades\Cache;
class Company extends BaseModel
{
@ -342,12 +343,13 @@ class Company extends BaseModel
return null;
}
/**
* @return BelongsTo
*/
public function currency()
{
return $this->belongsTo(Currency::class);
$currencies = Cache::get('currencies');
return $currencies->filter(function ($item) {
return $item->id == $this->settings->currency_id;
})->first();
}
/**

View File

@ -248,9 +248,9 @@ class Credit extends BaseModel
public function pdf_file_path($invitation = null)
{
$storage_path = Storage::url($this->client->credit_filepath().$this->number.'.pdf');
$storage_path = Storage::url($this->client->credit_filepath().$this->numberFormatter().'.pdf');
if (Storage::exists($this->client->credit_filepath().$this->number.'.pdf')) {
if (Storage::exists($this->client->credit_filepath().$this->numberFormatter().'.pdf')) {
return $storage_path;
}

View File

@ -126,9 +126,9 @@ class CreditInvitation extends BaseModel
public function pdf_file_path()
{
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->number.'.pdf');
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->numberFormatter().'.pdf');
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->number.'.pdf')) {
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->numberFormatter().'.pdf')) {
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($this);
}

View File

@ -388,9 +388,9 @@ class Invoice extends BaseModel
$invitation = $this->invitations->first();
}
$storage_path = Storage::$type($this->client->invoice_filepath().$this->number.'.pdf');
$storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf');
if (! Storage::exists($this->client->invoice_filepath().$this->number.'.pdf')) {
if (! Storage::exists($this->client->invoice_filepath().$this->numberFormatter().'.pdf')) {
event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($invitation);
}

View File

@ -140,9 +140,9 @@ class InvoiceInvitation extends BaseModel
public function pdf_file_path()
{
$storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf');
$storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf');
if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf')) {
if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf')) {
event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($this);
}

View File

@ -208,11 +208,11 @@ class Quote extends BaseModel
$invitation = $this->invitations->first();
}
$storage_path = Storage::$type($this->client->quote_filepath().$this->number.'.pdf');
$storage_path = Storage::$type($this->client->quote_filepath().$this->numberFormatter().'.pdf');
nlog($storage_path);
if (! Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) {
if (! Storage::exists($this->client->quote_filepath().$this->numberFormatter().'.pdf')) {
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($invitation);
}

View File

@ -130,9 +130,9 @@ class QuoteInvitation extends BaseModel
public function pdf_file_path()
{
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->number.'.pdf');
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf');
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->number.'.pdf')) {
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf')) {
event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($this);
}

View File

@ -52,7 +52,7 @@ class InvoiceObserver
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
}
// UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath() . $invoice->number.'.pdf');
// UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath() . $invoice->numberFormatter().'.pdf');
}

View File

@ -30,6 +30,7 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\SystemLog;
use App\Services\BillingSubscription\BillingSubscriptionService;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SystemLogTrait;
@ -240,6 +241,8 @@ class BaseDriver extends AbstractPaymentDriver
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
BillingSubscriptionService::completePurchase($this->payment_hash);
return $payment->service()->applyNumber()->save();
}

View File

@ -37,6 +37,7 @@ class ClientContactRepository extends BaseRepository
});
$this->is_primary = true;
/* Set first record to primary - always */
$contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) {
$contact['is_primary'] = $this->is_primary;

View File

@ -15,12 +15,13 @@ use App\DataMapper\InvoiceItem;
use App\Factory\InvoiceFactory;
use App\Models\BillingSubscription;
use App\Models\ClientSubscription;
use App\Models\PaymentHash;
use App\Models\Product;
use App\Repositories\InvoiceRepository;
class BillingSubscriptionService
{
/** @var BillingSubscription */
private $billing_subscription;
public function __construct(BillingSubscription $billing_subscription)
@ -28,21 +29,29 @@ class BillingSubscriptionService
$this->billing_subscription = $billing_subscription;
}
public function createInvoice($data)
public function completePurchase(PaymentHash $payment_hash)
{
// create client subscription record
//
// create recurring invoice if is_recurring
//
// s
}
public function startTrial(array $data)
{
}
public function createInvoice($data): ?\App\Models\Invoice
{
$invoice_repo = new InvoiceRepository();
// $data = [
// 'client_id' =>,
// 'date' => Y-m-d,
// 'invitations' => [
// 'client_contact_id' => hashed_id
// ],
// 'line_items' => [],
// ];
$data['line_items'] = $this->createLineItems($data['quantity']);
$invoice = $invoice_repo->save($data, InvoiceFactory::create($this->billing_subscription->company_id, $this->billing_subscription->user_id));
/*
If trial_enabled -> return early
@ -56,11 +65,11 @@ class BillingSubscriptionService
2. What is the quantity? ie is this a multi seat product ( does this mean we need this value stored in the client sub?)
*/
return $invoice;
return $invoice_repo->save($data, InvoiceFactory::create($this->billing_subscription->company_id, $this->billing_subscription->user_id));
}
private function createLineItems($quantity)
private function createLineItems($quantity): array
{
$line_items = [];
@ -108,4 +117,14 @@ class BillingSubscriptionService
{
//scan for any notification we are required to send
}
public static function completePurchase(PaymentHash $payment_hash)
{
if (!property_exists($payment_hash, 'billing_context')) {
return;
}
// At this point we have some state carried from the billing page
// to this, available as $payment_hash->data->billing_context. Make something awesome ⭐
}
}

View File

@ -140,7 +140,7 @@ class CreditService
public function deletePdf()
{
UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->number.'.pdf');
UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->numberFormatter().'.pdf');
return $this;
}

View File

@ -38,7 +38,7 @@ class GetCreditPdf extends AbstractService
$path = $this->credit->client->credit_filepath();
$file_path = $path.$this->credit->number.'.pdf';
$file_path = $path.$this->credit->numberFormatter().'.pdf';
$disk = config('filesystems.default');

View File

@ -37,7 +37,7 @@ class GetInvoicePdf extends AbstractService
$path = $this->invoice->client->invoice_filepath();
$file_path = $path.$this->invoice->number.'.pdf';
$file_path = $path.$this->invoice->numberFormatter().'.pdf';
$disk = config('filesystems.default');

View File

@ -274,8 +274,8 @@ class InvoiceService
public function deletePdf()
{
//UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf');
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf');
//UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf');
Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf');
return $this;
}

View File

@ -36,7 +36,7 @@ class GetQuotePdf extends AbstractService
$path = $this->quote->client->quote_filepath();
$file_path = $path.$this->quote->number.'.pdf';
$file_path = $path.$this->quote->numberFormatter().'.pdf';
$disk = config('filesystems.default');

View File

@ -178,7 +178,7 @@ class QuoteService
public function deletePdf()
{
UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->number.'.pdf');
UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->numberFormatter().'.pdf');
return $this;
}

View File

@ -87,7 +87,7 @@ class RecurringService
public function deletePdf()
{
UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->number.'.pdf');
UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->numberFormatter().'.pdf');
return $this;
}

View File

@ -57,6 +57,7 @@ class BillingSubscriptionTransformer extends EntityTransformer
'plan_map' => (string)$billing_subscription->plan_map,
'refund_period' => (int)$billing_subscription->refund_period,
'webhook_configuration' => (string)$billing_subscription->webhook_configuration,
'purchase_page' => (string)route('client.subscription.purchase', $billing_subscription->hashed_id),
'is_deleted' => (bool)$billing_subscription->is_deleted,
'created_at' => (int)$billing_subscription->created_at,
'updated_at' => (int)$billing_subscription->updated_at,

View File

@ -0,0 +1,37 @@
<?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\Utils\HostedPDF;
use GuzzleHttp\RequestOptions;
class NinjaPdf
{
private $url = 'https://pdf.invoicing.co/api/';
public function build($html)
{
$client = new \GuzzleHttp\Client(['headers' =>
[
'X-Ninja-Token' => 'test_token_for_now',
]
]);
$response = $client->post($this->url,[
RequestOptions::JSON => ['html' => $html]
]);
return $response->getBody();
}
}

View File

@ -11,6 +11,7 @@
namespace App\Utils;
use App\Models\Company;
use App\Models\Currency;
/**
@ -88,12 +89,12 @@ class Number
* Formats a given value based on the clients currency AND country.
*
* @param floatval $value The number to be formatted
* @param $client
* @param $entity
* @return string The formatted value
*/
public static function formatMoney($value, $client) :string
public static function formatMoney($value, $entity) :string
{
$currency = $client->currency();
$currency = $entity->currency();
$thousand = $currency->thousand_separator;
$decimal = $currency->decimal_separator;
@ -101,29 +102,38 @@ class Number
$code = $currency->code;
$swapSymbol = $currency->swap_currency_symbol;
// App\Models\Client::country() returns instance of BelongsTo.
// App\Models\Company::country() returns record for the country, that's why we check for the instance.
if ($entity instanceof Company) {
$country = $entity->country();
} else {
$country = $entity->country;
}
/* Country settings override client settings */
if (isset($client->country->thousand_separator) && strlen($client->country->thousand_separator) >= 1) {
$thousand = $client->country->thousand_separator;
if (isset($country->thousand_separator) && strlen($country->thousand_separator) >= 1) {
$thousand = $country->thousand_separator;
}
if (isset($client->country->decimal_separator) && strlen($client->country->decimal_separator) >= 1) {
$decimal = $client->country->decimal_separator;
if (isset($country->decimal_separator) && strlen($country->decimal_separator) >= 1) {
$decimal = $country->decimal_separator;
}
if (isset($client->country->swap_currency_symbol) && strlen($client->country->swap_currency_symbol) >= 1) {
$swapSymbol = $client->country->swap_currency_symbol;
if (isset($country->swap_currency_symbol) && strlen($country->swap_currency_symbol) >= 1) {
$swapSymbol = $country->swap_currency_symbol;
}
$value = number_format($value, $precision, $decimal, $thousand);
$symbol = $currency->symbol;
if ($client->getSetting('show_currency_code') === true && $currency->code == 'CHF') {
if ($entity->getSetting('show_currency_code') === true && $currency->code == 'CHF') {
return "{$code} {$value}";
} elseif ($client->getSetting('show_currency_code') === true) {
} elseif ($entity->getSetting('show_currency_code') === true) {
return "{$value} {$code}";
} elseif ($swapSymbol) {
return "{$value} ".trim($symbol);
} elseif ($client->getSetting('show_currency_code') === false) {
} elseif ($entity->getSetting('show_currency_code') === false) {
return "{$symbol}{$value}";
} else {
return self::formatValue($value, $currency);

View File

@ -76,7 +76,7 @@ class Phantom
$path = $entity_obj->client->recurring_invoice_filepath();
}
$file_path = $path.$entity_obj->number.'.pdf';
$file_path = $path.$entity_obj->numberFormatter().'.pdf';
$url = config('ninja.app_url').'/phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret');
info($url);
@ -91,8 +91,8 @@ class Phantom
$instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf);
nlog($instance);
nlog($file_path);
// nlog($instance);
// nlog($file_path);
return $file_path;
}

View File

@ -65,6 +65,7 @@
"predis/predis": "^1.1",
"sentry/sentry-laravel": "^2",
"stripe/stripe-php": "^7.50",
"symfony/http-client": "^5.2",
"turbo124/beacon": "^1.0",
"webpatser/laravel-countries": "dev-master#75992ad",
"wildbit/swiftmailer-postmark": "^3.3"

View File

@ -13,7 +13,7 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', ''),
'app_version' => '5.1.26',
'app_version' => '5.1.27',
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false),
@ -144,4 +144,5 @@ return [
'flutter_canvas_kit' => env('FLUTTER_CANVAS_KIT', false),
'webcron_secret' => env('WEBCRON_SECRET', false),
'disable_auto_update' => env('DISABLE_AUTO_UPDATE', false),
'invoiceninja_hosted_pdf_generation' => env('NINJA_HOSTED_PDF', false),
];

2
public/css/app.css vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"/js/app.js": "/js/app.js?id=696e8203d5e8e7cf5ff5",
"/css/app.css": "/css/app.css?id=745170b7d7a4dc7469f2",
"/css/app.css": "/css/app.css?id=e8d6d5e8cb60bc2f15b3",
"/js/clients/invoices/action-selectors.js": "/js/clients/invoices/action-selectors.js?id=a09bb529b8e1826f13b4",
"/js/clients/invoices/payment.js": "/js/clients/invoices/payment.js?id=8ce8955ba775ea5f47d1",
"/js/clients/linkify-urls.js": "/js/clients/linkify-urls.js?id=0dc8c34010d09195d2f7",

View File

@ -8,7 +8,9 @@
@include('portal.ninja2020.components.general.sidebar.mobile')
<!-- Static sidebar for desktop -->
@unless(request()->query('sidebar') === 'hidden')
@include('portal.ninja2020.components.general.sidebar.desktop')
@endunless
<div class="flex flex-col w-0 flex-1 overflow-hidden">
@include('portal.ninja2020.components.general.sidebar.header')

View File

@ -63,6 +63,8 @@
{{-- Feel free to push anything to header using @push('header') --}}
@stack('head')
@livewireStyles
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css" />
</head>
@ -77,6 +79,8 @@
@yield('body')
@livewireScripts
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js" data-cfasync="false"></script>
<script>
window.addEventListener("load", function(){

View File

@ -31,10 +31,13 @@
<div>
@yield('gateway_content')
</div>
@if(Request::isSecure())
<span class="block mx-4 mb-4 text-xs inline-flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-green-600"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
<span class="ml-1">Secure 256-bit encryption</span>
</span>
@endif
</div>
</div>
@endsection

View File

@ -76,6 +76,8 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence
Route::get('logout', 'Auth\ContactLoginController@logout')->name('logout');
});
Route::get('client/subscription/{billing_subscription}/purchase', 'ClientPortal\BillingSubscriptionPurchaseController@index')->name('client.subscription.purchase');
Route::group(['middleware' => ['invite_db'], 'prefix' => 'client', 'as' => 'client.'], function () {
/*Invitation catches*/
Route::get('recurring_invoice/{invitation_key}', 'ClientPortal\InvitationController@recurringRouter');