diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index b3bd13fad4..e67c0908f0 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -117,21 +117,21 @@ class AccountController extends BaseController if (Auth::user()->isPro() && ! Auth::user()->isTrial()) { return false; } - + $invitation = $this->accountRepo->enablePlan(); return $invitation->invitation_key; } - + public function changePlan() { $user = Auth::user(); $account = $user->account; - + $plan = Input::get('plan'); $term = Input::get('plan_term'); - + $planDetails = $account->getPlanDetails(false, false); - + $credit = 0; if ($planDetails) { if ($planDetails['plan'] == PLAN_PRO && $plan == PLAN_ENTERPRISE) { @@ -141,7 +141,7 @@ class AccountController extends BaseController $pending_monthly = true; $term = PLAN_TERM_YEARLY; } - + $new_plan = array( 'plan' => PLAN_ENTERPRISE, 'term' => $term, @@ -169,7 +169,7 @@ class AccountController extends BaseController // Downgrade $refund_deadline = clone $planDetails['started']; $refund_deadline->modify('+30 days'); - + if ($plan == PLAN_FREE && $refund_deadline >= date_create()) { // Refund $account->company->plan = null; @@ -179,10 +179,10 @@ class AccountController extends BaseController $account->company->plan_paid = null; $account->company->pending_plan = null; $account->company->pending_term = null; - + if ($account->company->payment) { $payment = $account->company->payment; - + $gateway = $this->paymentService->createGateway($payment->account_gateway); $refund = $gateway->refund(array( 'transactionReference' => $payment->transaction_reference, @@ -195,9 +195,9 @@ class AccountController extends BaseController } else { Session::flash('message', trans('texts.updated_plan')); } - + $account->company->save(); - + } else { $pending_change = array( 'plan' => $plan, @@ -205,18 +205,18 @@ class AccountController extends BaseController ); } } - + if (!empty($new_plan)) { $time_used = $planDetails['paid']->diff(date_create()); $days_used = $time_used->days; - + if ($time_used->invert) { // They paid in advance $days_used *= -1; } - + $days_total = $planDetails['paid']->diff($planDetails['expires'])->days; - + $percent_used = $days_used / $days_total; $old_plan_price = Account::$plan_prices[$planDetails['plan']][$planDetails['term']]; $credit = $old_plan_price * (1 - $percent_used); @@ -227,20 +227,20 @@ class AccountController extends BaseController 'term' => $term, ); } - + if (!empty($pending_change) && empty($new_plan)) { $account->company->pending_plan = $pending_change['plan']; $account->company->pending_term = $pending_change['term']; $account->company->save(); - + Session::flash('message', trans('texts.updated_plan')); } - + if (!empty($new_plan)) { $invitation = $this->accountRepo->enablePlan($new_plan['plan'], $new_plan['term'], $credit, !empty($pending_monthly)); return Redirect::to('view/'.$invitation->invitation_key); } - + return Redirect::to('/settings/'.ACCOUNT_MANAGEMENT, 301); } @@ -499,7 +499,7 @@ class AccountController extends BaseController $client->postal_code = trans('texts.postal_code'); $client->work_phone = trans('texts.work_phone'); $client->work_email = trans('texts.work_id'); - + $invoice->invoice_number = '0000'; $invoice->invoice_date = Utils::fromSqlDate(date('Y-m-d')); $invoice->account = json_decode($account->toJson()); @@ -517,7 +517,7 @@ class AccountController extends BaseController $invoiceItem->product_key = 'Item'; $document->base64 = 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAyAAD/7QAsUGhvdG9zaG9wIDMuMAA4QklNBCUAAAAAABAAAAAAAAAAAAAAAAAAAAAA/+4AIUFkb2JlAGTAAAAAAQMAEAMDBgkAAAW8AAALrQAAEWf/2wCEAAgGBgYGBggGBggMCAcIDA4KCAgKDhANDQ4NDRARDA4NDQ4MEQ8SExQTEg8YGBoaGBgjIiIiIycnJycnJycnJycBCQgICQoJCwkJCw4LDQsOEQ4ODg4REw0NDg0NExgRDw8PDxEYFhcUFBQXFhoaGBgaGiEhICEhJycnJycnJycnJ//CABEIAGQAlgMBIgACEQEDEQH/xADtAAABBQEBAAAAAAAAAAAAAAAAAQIDBAUGBwEBAAMBAQEAAAAAAAAAAAAAAAIDBAUBBhAAAQQCAQMDBQEAAAAAAAAAAgABAwQRBRIQIBMwIQYxIiMUFUARAAIBAgMFAwgHBwUBAAAAAAECAwARIRIEMUFRYROhIkIgcYGRsdFSIzDBMpKyFAVA4WJyM0MkUPGiU3OTEgABAgQBCQ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7U0YQobDxRja4mPhsgnSp/cLbjYA4K51OOKoU0zRiegjSEq4oFegvxGpy4QRr5JcRHqajXulVBqlghaxQnLR092G41E0g3djqcHWMXuExr0VmhZdW7FsLT+gynKYpXXjGV7wreJppoapXL7oQD0sBYvCAX4tIpESrHmFyooWQqCbMCN1vpBgtacBgtAYVZcF7afsYf9lQisQlRdvDkWyqGZBthXx7RPvKkUrlb5Q/CrdFT5neoWdIZSWgR/VBQwZ0nUGPeBAJdZvWE38qghbIlumjVcdMzdAL5o/BAVDYFa5xT2qVhDQIAA5pB+5aemryoxhX0jk3pALPvUXhzAK5y/XUnskCEqEqMLSHNUwwLAQBRotLMeIdlDn5FpRZUUm5R2ZJ7EpNZRMobAO5K5hOAUuBYHYG+8SddNHz0+EKEOCcKzlT1BZYb4uB90OpYUAVM2rcL3vCknNK+bjWGKs6bZa9oVhmRdpg/YWAAlUVJkcjdXD11Lgke0VcU2MbHfygaFKWEnTL5GJZzMyGuGMPMbSQlbPagPOZaKOHjusEyaLtXgeW3iK4+oDc4bNYnwcKiQaks/Caxh5wK7kdeZvb3LEJhAMqbKrhAqim522Qv5gPgqp9FxlL7mnZpXi3MxIMgDkG/ug65qHbsEF8zXvjwBFAU4jmwArRmKjV6XLdNd1TvoiF1X5vX/fMHBChWDvd+4paeJz4FDgzLjs70CdhHznQBjzv7Sxo8bd2NfcZmYNWs8RxQGYGe1+olGV9n7Z+0UPFyYwlYvmDNJctGQPGwnyQAWPv0haPhQ4abtsUxZfaFBalqvypK8pGizJpYO+aShBw+h2xgHf3CNeSAXzRnTRxS/szKo3P+IMAszsGE7iUiOwZy99tXZg3BCqz2L+qH0gU09RzxfaMDrstvwgKoDsPRrCLj7jcKSy6oH5pLZC0I+L/UPAvRNDQUa9oMU7aNedH3NWIKBWuO+m4lsAS60VfopKsCajNR6AT7l8D418EaQCisod0YIUK9U/PBh6loQegqKly/QfkBmNzMzM/i+jOk/9k='; - + $invoice->client = $client; $invoice->invoice_items = [$invoiceItem]; //$invoice->documents = $account->hasFeature(FEATURE_DOCUMENTS) ? [$document] : []; @@ -530,7 +530,7 @@ class AccountController extends BaseController $data['invoiceDesigns'] = InvoiceDesign::getDesigns(); $data['invoiceFonts'] = Cache::get('fonts'); $data['section'] = $section; - + $pageSizes = [ 'A0', 'A1', @@ -708,6 +708,13 @@ class AccountController extends BaseController private function saveClientPortal() { + $account = Auth::user()->account; + + $account->enable_client_portal = !!Input::get('enable_client_portal'); + $account->enable_client_portal_dashboard = !!Input::get('enable_client_portal_dashboard'); + $account->enable_portal_password = !!Input::get('enable_portal_password'); + $account->send_portal_password = !!Input::get('send_portal_password'); + // Only allowed for pro Invoice Ninja users or white labeled self-hosted users if (Auth::user()->account->hasFeature(FEATURE_CLIENT_PORTAL_CSS)) { $input_css = Input::get('client_view_css'); @@ -742,22 +749,16 @@ class AccountController extends BaseController $sanitized_css = $input_css; } - $account = Auth::user()->account; $account->client_view_css = $sanitized_css; - - $account->enable_client_portal = !!Input::get('enable_client_portal'); - $account->enable_client_portal_dashboard = !!Input::get('enable_client_portal_dashboard'); - $account->enable_portal_password = !!Input::get('enable_portal_password'); - $account->send_portal_password = !!Input::get('send_portal_password'); - - $account->save(); - - Session::flash('message', trans('texts.updated_settings')); } + $account->save(); + + Session::flash('message', trans('texts.updated_settings')); + return Redirect::to('settings/'.ACCOUNT_CLIENT_PORTAL); } - + private function saveEmailTemplates() { if (Auth::user()->account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) { @@ -1010,15 +1011,15 @@ class AccountController extends BaseController /* Logo image file */ if ($uploaded = Input::file('logo')) { $path = Input::file('logo')->getRealPath(); - + $disk = $account->getLogoDisk(); if ($account->hasLogo()) { $disk->delete($account->logo); } - + $extension = strtolower($uploaded->getClientOriginalExtension()); if(empty(Document::$types[$extension]) && !empty(Document::$extraExtensions[$extension])){ - $documentType = Document::$extraExtensions[$extension]; + $documentType = Document::$extraExtensions[$extension]; } else{ $documentType = $extension; @@ -1037,19 +1038,19 @@ class AccountController extends BaseController } else { if ($documentType != 'gif') { $account->logo = $account->account_key.'.'.$documentType; - + $imageSize = getimagesize($filePath); $account->logo_width = $imageSize[0]; $account->logo_height = $imageSize[1]; $account->logo_size = $size; - + // make sure image isn't interlaced if (extension_loaded('fileinfo')) { $image = Image::make($path); $image->interlace(false); $imageStr = (string) $image->encode($documentType); $disk->put($account->logo, $imageStr); - + $account->logo_size = strlen($imageStr); } else { $stream = fopen($filePath, 'r'); @@ -1062,12 +1063,12 @@ class AccountController extends BaseController $image->resize(200, 120, function ($constraint) { $constraint->aspectRatio(); }); - + $account->logo = $account->account_key.'.png'; $image = Image::canvas($image->width(), $image->height(), '#FFFFFF')->insert($image); $imageStr = (string) $image->encode('png'); $disk->put($account->logo, $imageStr); - + $account->logo_size = strlen($imageStr); $account->logo_width = $image->width(); $account->logo_height = $image->height(); @@ -1077,7 +1078,7 @@ class AccountController extends BaseController } } } - + $account->save(); } @@ -1147,7 +1148,7 @@ class AccountController extends BaseController $account = Auth::user()->account; if ($account->hasLogo()) { $account->getLogoDisk()->delete($account->logo); - + $account->logo = null; $account->logo_size = null; $account->logo_width = null; @@ -1252,7 +1253,7 @@ class AccountController extends BaseController $this->accountRepo->unlinkAccount($account); if ($account->company->accounts->count() == 1) { - $account->company->forceDelete(); + $account->company->forceDelete(); } $account->forceDelete(); @@ -1300,7 +1301,7 @@ class AccountController extends BaseController return Redirect::to("/settings/$section/", 301); } - + public function previewEmail(\App\Services\TemplateService $templateService) { $template = Input::get('template'); @@ -1308,29 +1309,29 @@ class AccountController extends BaseController ->invoices() ->withTrashed() ->first(); - + if ( ! $invoice) { return trans('texts.create_invoice_for_sample'); } - + $account = Auth::user()->account; - + // replace the variables with sample data $data = [ 'account' => $account, 'invoice' => $invoice, 'invitation' => $invoice->invitations->first(), 'client' => $invoice->client, - 'amount' => $invoice->amount + 'amount' => $invoice->amount ]; - - // create the email view + + // create the email view $view = 'emails.' . $account->getTemplateView(ENTITY_INVOICE) . '_html'; $data = array_merge($data, [ 'body' => $templateService->processVariables($template, $data), 'entityType' => ENTITY_INVOICE, ]); - + return Response::view($view, $data); } }