2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2017-11-06 10:58:53 +01:00
|
|
|
use App\Events\SubdomainWasUpdated;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Events\UserSettingsChanged;
|
|
|
|
use App\Events\UserSignedUp;
|
|
|
|
use App\Http\Requests\SaveClientPortalSettings;
|
|
|
|
use App\Http\Requests\SaveEmailSettings;
|
|
|
|
use App\Http\Requests\UpdateAccountRequest;
|
|
|
|
use App\Models\Account;
|
2016-05-14 23:23:20 +02:00
|
|
|
use App\Models\AccountGateway;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Models\Affiliate;
|
|
|
|
use App\Models\Document;
|
|
|
|
use App\Models\Gateway;
|
2016-09-15 12:41:09 +02:00
|
|
|
use App\Models\GatewayType;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\InvoiceDesign;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\PaymentTerm;
|
|
|
|
use App\Models\Product;
|
|
|
|
use App\Models\TaxRate;
|
|
|
|
use App\Models\User;
|
2017-09-02 21:03:45 +02:00
|
|
|
use App\Models\AccountEmailSettings;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Ninja\Mailers\ContactMailer;
|
|
|
|
use App\Ninja\Mailers\UserMailer;
|
|
|
|
use App\Ninja\Repositories\AccountRepository;
|
|
|
|
use App\Ninja\Repositories\ReferralRepository;
|
|
|
|
use App\Services\AuthService;
|
|
|
|
use App\Services\PaymentService;
|
2016-07-03 18:11:58 +02:00
|
|
|
use App\Services\TemplateService;
|
2015-03-26 07:24:02 +01:00
|
|
|
use Auth;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Cache;
|
2015-04-06 07:45:27 +02:00
|
|
|
use File;
|
|
|
|
use Image;
|
2015-03-26 07:24:02 +01:00
|
|
|
use Input;
|
|
|
|
use Redirect;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Request;
|
|
|
|
use Response;
|
2015-03-26 07:24:02 +01:00
|
|
|
use Session;
|
2017-01-30 20:40:43 +01:00
|
|
|
use stdClass;
|
2017-03-20 15:02:59 +01:00
|
|
|
use Exception;
|
2017-01-30 20:40:43 +01:00
|
|
|
use URL;
|
2015-03-26 07:24:02 +01:00
|
|
|
use Utils;
|
2017-01-30 20:40:43 +01:00
|
|
|
|
2015-04-01 21:57:02 +02:00
|
|
|
use Validator;
|
2015-04-06 07:45:27 +02:00
|
|
|
use View;
|
2017-01-12 12:52:37 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class AccountController.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-03-26 07:24:02 +01:00
|
|
|
class AccountController extends BaseController
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var AccountRepository
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
protected $accountRepo;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var UserMailer
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
protected $userMailer;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ContactMailer
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
protected $contactMailer;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ReferralRepository
|
|
|
|
*/
|
2015-11-01 19:21:11 +01:00
|
|
|
protected $referralRepository;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PaymentService
|
|
|
|
*/
|
2016-04-17 00:34:39 +02:00
|
|
|
protected $paymentService;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* AccountController constructor.
|
|
|
|
*
|
2017-01-30 20:40:43 +01:00
|
|
|
* @param AccountRepository $accountRepo
|
|
|
|
* @param UserMailer $userMailer
|
|
|
|
* @param ContactMailer $contactMailer
|
2016-07-03 18:11:58 +02:00
|
|
|
* @param ReferralRepository $referralRepository
|
2017-01-30 20:40:43 +01:00
|
|
|
* @param PaymentService $paymentService
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AccountRepository $accountRepo,
|
|
|
|
UserMailer $userMailer,
|
|
|
|
ContactMailer $contactMailer,
|
|
|
|
ReferralRepository $referralRepository,
|
|
|
|
PaymentService $paymentService
|
2017-01-30 17:05:31 +01:00
|
|
|
) {
|
2015-03-16 22:45:25 +01:00
|
|
|
$this->accountRepo = $accountRepo;
|
|
|
|
$this->userMailer = $userMailer;
|
|
|
|
$this->contactMailer = $contactMailer;
|
2015-11-01 19:21:11 +01:00
|
|
|
$this->referralRepository = $referralRepository;
|
2016-04-17 00:34:39 +02:00
|
|
|
$this->paymentService = $paymentService;
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function getStarted()
|
|
|
|
{
|
2015-07-30 16:44:47 +02:00
|
|
|
$user = false;
|
2018-02-14 13:33:05 +01:00
|
|
|
$account = false;
|
2015-07-30 16:44:47 +02:00
|
|
|
$guestKey = Input::get('guest_key'); // local storage key to login until registered
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
if (Auth::check()) {
|
|
|
|
return Redirect::to('invoices/create');
|
|
|
|
}
|
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
if (! Utils::isNinja() && Account::count() > 0) {
|
2015-06-16 21:35:35 +02:00
|
|
|
return Redirect::to('/login');
|
|
|
|
}
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
if ($guestKey) {
|
2015-03-16 22:45:25 +01:00
|
|
|
$user = User::where('password', '=', $guestKey)->first();
|
|
|
|
|
|
|
|
if ($user && $user->registered) {
|
|
|
|
return Redirect::to('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $user) {
|
2015-03-16 22:45:25 +01:00
|
|
|
$account = $this->accountRepo->create();
|
|
|
|
$user = $account->users()->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
Auth::login($user, true);
|
2016-03-08 22:22:59 +01:00
|
|
|
event(new UserSignedUp());
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2018-02-15 22:05:19 +01:00
|
|
|
if ($account && $account->language_id && $account->language_id != DEFAULT_LANGUAGE) {
|
2018-02-14 13:33:05 +01:00
|
|
|
$link = link_to('/invoices/create?lang=en', 'click here');
|
|
|
|
$message = sprintf('Your account language has been set automatically, %s to change to English', $link);
|
|
|
|
Session::flash('warning', $message);
|
|
|
|
}
|
|
|
|
|
2017-06-01 20:05:01 +02:00
|
|
|
$redirectTo = Input::get('redirect_to') ? SITE_URL . '/' . ltrim(Input::get('redirect_to'), '/') : 'invoices/create';
|
2015-08-12 21:16:02 +02:00
|
|
|
return Redirect::to($redirectTo)->with('sign_up', Input::get('sign_up'));
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2017-01-30 17:05:31 +01:00
|
|
|
public function changePlan()
|
|
|
|
{
|
2016-07-14 11:46:00 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
$account = $user->account;
|
|
|
|
$company = $account->company;
|
|
|
|
|
|
|
|
$plan = Input::get('plan');
|
|
|
|
$term = Input::get('plan_term');
|
|
|
|
$numUsers = Input::get('num_users');
|
|
|
|
|
2016-10-16 15:38:04 +02:00
|
|
|
if ($plan != PLAN_ENTERPRISE) {
|
2017-01-30 17:05:31 +01:00
|
|
|
$numUsers = 1;
|
2016-10-16 15:38:04 +02:00
|
|
|
}
|
|
|
|
|
2016-07-14 11:46:00 +02:00
|
|
|
$planDetails = $account->getPlanDetails(false, false);
|
|
|
|
|
|
|
|
$newPlan = [
|
|
|
|
'plan' => $plan,
|
|
|
|
'term' => $term,
|
|
|
|
'num_users' => $numUsers,
|
|
|
|
];
|
|
|
|
$newPlan['price'] = Utils::getPlanPrice($newPlan);
|
|
|
|
$credit = 0;
|
|
|
|
|
2017-03-28 13:28:25 +02:00
|
|
|
if ($plan == PLAN_FREE && $company->processRefund(Auth::user())) {
|
|
|
|
Session::flash('warning', trans('texts.plan_refunded'));
|
2016-07-14 11:46:00 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 10:39:07 +02:00
|
|
|
if ($company->payment && ! empty($planDetails['paid']) && $plan != PLAN_FREE) {
|
2016-07-14 11:46:00 +02:00
|
|
|
$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;
|
2018-02-14 19:08:48 +01:00
|
|
|
$credit = round(floatval($company->payment->amount) * (1 - $percent_used), 2);
|
2016-07-14 11:46:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($newPlan['price'] > $credit) {
|
|
|
|
$invitation = $this->accountRepo->enablePlan($newPlan, $credit);
|
2017-08-13 17:05:56 +02:00
|
|
|
return Redirect::to('view/' . $invitation->invitation_key);
|
2016-07-14 11:46:00 +02:00
|
|
|
} else {
|
2016-12-14 15:19:16 +01:00
|
|
|
if ($plan == PLAN_FREE) {
|
|
|
|
$company->discount = 0;
|
|
|
|
} else {
|
2016-07-14 21:58:48 +02:00
|
|
|
$company->plan_term = $term;
|
|
|
|
$company->plan_price = $newPlan['price'];
|
|
|
|
$company->num_users = $numUsers;
|
|
|
|
$company->plan_expires = date_create()->modify($term == PLAN_TERM_MONTHLY ? '+1 month' : '+1 year')->format('Y-m-d');
|
|
|
|
}
|
|
|
|
|
2017-01-04 12:20:56 +01:00
|
|
|
$company->trial_plan = null;
|
2016-07-14 11:46:00 +02:00
|
|
|
$company->plan = $plan;
|
2016-07-14 21:58:48 +02:00
|
|
|
$company->save();
|
|
|
|
|
2017-03-28 13:28:25 +02:00
|
|
|
Session::flash('message', trans('texts.updated_plan'));
|
|
|
|
|
2016-07-14 21:58:48 +02:00
|
|
|
return Redirect::to('settings/account_management');
|
2016-07-14 11:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $entityType
|
|
|
|
* @param $visible
|
2017-01-30 20:49:42 +01:00
|
|
|
* @param mixed $filter
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-11-18 14:31:43 +01:00
|
|
|
public function setEntityFilter($entityType, $filter = '')
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2016-11-18 14:31:43 +01:00
|
|
|
if ($filter == 'true') {
|
|
|
|
$filter = '';
|
|
|
|
}
|
|
|
|
|
2016-11-20 15:08:36 +01:00
|
|
|
// separate state and status filters
|
|
|
|
$filters = explode(',', $filter);
|
|
|
|
$stateFilter = [];
|
|
|
|
$statusFilter = [];
|
|
|
|
foreach ($filters as $filter) {
|
|
|
|
if (in_array($filter, \App\Models\EntityModel::$statuses)) {
|
|
|
|
$stateFilter[] = $filter;
|
|
|
|
} else {
|
|
|
|
$statusFilter[] = $filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
Session::put("entity_state_filter:{$entityType}", implode(',', $stateFilter));
|
|
|
|
Session::put("entity_status_filter:{$entityType}", implode(',', $statusFilter));
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-02-18 19:14:48 +01:00
|
|
|
return RESULT_SUCCESS;
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function getSearchData()
|
|
|
|
{
|
2016-05-08 20:29:49 +02:00
|
|
|
$data = $this->accountRepo->getSearchData(Auth::user());
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
return Response::json($data);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param bool $section
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
public function showSection($section = false)
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2017-01-30 17:05:31 +01:00
|
|
|
if (! Auth::user()->is_admin) {
|
2016-08-23 22:20:03 +02:00
|
|
|
return Redirect::to('/settings/user_details');
|
|
|
|
}
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $section) {
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('/settings/'.ACCOUNT_COMPANY_DETAILS, 301);
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
2015-10-11 16:41:09 +02:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
if ($section == ACCOUNT_COMPANY_DETAILS) {
|
|
|
|
return self::showCompanyDetails();
|
|
|
|
} elseif ($section == ACCOUNT_LOCALIZATION) {
|
|
|
|
return self::showLocalization();
|
|
|
|
} elseif ($section == ACCOUNT_PAYMENTS) {
|
|
|
|
return self::showOnlinePayments();
|
2016-01-20 00:07:31 +01:00
|
|
|
} elseif ($section == ACCOUNT_BANKS) {
|
|
|
|
return self::showBankAccounts();
|
2015-10-22 20:48:12 +02:00
|
|
|
} elseif ($section == ACCOUNT_INVOICE_SETTINGS) {
|
|
|
|
return self::showInvoiceSettings();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section == ACCOUNT_IMPORT_EXPORT) {
|
|
|
|
return View::make('accounts.import_export', ['title' => trans('texts.import_export')]);
|
2016-04-16 16:58:53 +02:00
|
|
|
} elseif ($section == ACCOUNT_MANAGEMENT) {
|
|
|
|
return self::showAccountManagement();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section == ACCOUNT_INVOICE_DESIGN || $section == ACCOUNT_CUSTOMIZE_DESIGN) {
|
|
|
|
return self::showInvoiceDesign($section);
|
2016-01-03 20:10:20 +01:00
|
|
|
} elseif ($section == ACCOUNT_CLIENT_PORTAL) {
|
2016-02-29 22:46:27 +01:00
|
|
|
return self::showClientPortal();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_TEMPLATES_AND_REMINDERS) {
|
|
|
|
return self::showTemplates();
|
|
|
|
} elseif ($section === ACCOUNT_PRODUCTS) {
|
|
|
|
return self::showProducts();
|
2015-10-21 13:11:08 +02:00
|
|
|
} elseif ($section === ACCOUNT_TAX_RATES) {
|
|
|
|
return self::showTaxRates();
|
2016-01-07 20:39:51 +01:00
|
|
|
} elseif ($section === ACCOUNT_PAYMENT_TERMS) {
|
|
|
|
return self::showPaymentTerms();
|
2015-11-04 14:57:59 +01:00
|
|
|
} elseif ($section === ACCOUNT_SYSTEM_SETTINGS) {
|
|
|
|
return self::showSystemSettings();
|
2015-10-14 16:15:39 +02:00
|
|
|
} else {
|
2015-03-16 22:45:25 +01:00
|
|
|
$data = [
|
|
|
|
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
2015-10-14 16:15:39 +02:00
|
|
|
'title' => trans("texts.{$section}"),
|
2016-01-03 20:10:20 +01:00
|
|
|
'section' => $section,
|
2015-03-16 22:45:25 +01:00
|
|
|
];
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
return View::make("accounts.{$section}", $data);
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-11-04 14:57:59 +01:00
|
|
|
private function showSystemSettings()
|
|
|
|
{
|
|
|
|
if (Utils::isNinjaProd()) {
|
|
|
|
return Redirect::to('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
2016-07-03 18:11:58 +02:00
|
|
|
'title' => trans('texts.system_settings'),
|
2015-11-04 14:57:59 +01:00
|
|
|
'section' => ACCOUNT_SYSTEM_SETTINGS,
|
|
|
|
];
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
return View::make('accounts.system_settings', $data);
|
2015-11-04 14:57:59 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-22 20:48:12 +02:00
|
|
|
private function showInvoiceSettings()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
|
|
|
$recurringHours = [];
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
for ($i = 0; $i < 24; $i++) {
|
2015-10-22 20:48:12 +02:00
|
|
|
if ($account->military_time) {
|
|
|
|
$format = 'H:i';
|
|
|
|
} else {
|
|
|
|
$format = 'g:i a';
|
|
|
|
}
|
|
|
|
$recurringHours[$i] = date($format, strtotime("{$i}:00"));
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
2016-07-03 18:11:58 +02:00
|
|
|
'title' => trans('texts.invoice_settings'),
|
2015-10-22 20:48:12 +02:00
|
|
|
'section' => ACCOUNT_INVOICE_SETTINGS,
|
2016-01-03 20:10:20 +01:00
|
|
|
'recurringHours' => $recurringHours,
|
2015-10-22 20:48:12 +02:00
|
|
|
];
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
return View::make('accounts.invoice_settings', $data);
|
2015-10-22 20:48:12 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function showCompanyDetails()
|
|
|
|
{
|
2015-11-16 19:02:04 +01:00
|
|
|
// check that logo is less than the max file size
|
|
|
|
$account = Auth::user()->account;
|
2015-11-29 21:13:50 +01:00
|
|
|
if ($account->isLogoTooLarge()) {
|
2016-01-03 20:10:20 +01:00
|
|
|
Session::flash('warning', trans('texts.logo_too_large', ['size' => $account->getLogoSize().'KB']));
|
2015-11-16 19:02:04 +01:00
|
|
|
}
|
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$data = [
|
|
|
|
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
|
|
|
'sizes' => Cache::get('sizes'),
|
|
|
|
'title' => trans('texts.company_details'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.details', $data);
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-04-16 16:58:53 +02:00
|
|
|
private function showAccountManagement()
|
|
|
|
{
|
2016-04-17 00:34:39 +02:00
|
|
|
$account = Auth::user()->account;
|
2017-06-13 20:53:54 +02:00
|
|
|
$planDetails = $account->getPlanDetails(true);
|
|
|
|
$portalLink = false;
|
|
|
|
|
2017-07-20 18:59:33 +02:00
|
|
|
if (Utils::isNinja() && $planDetails && $ninjaClient = $this->accountRepo->getNinjaClient($account)) {
|
2017-06-13 20:53:54 +02:00
|
|
|
$contact = $ninjaClient->getPrimaryContact();
|
|
|
|
$portalLink = $contact->link;
|
|
|
|
}
|
|
|
|
|
2016-04-16 16:58:53 +02:00
|
|
|
$data = [
|
2016-04-17 00:34:39 +02:00
|
|
|
'account' => $account,
|
2017-06-13 20:53:54 +02:00
|
|
|
'portalLink' => $portalLink,
|
|
|
|
'planDetails' => $planDetails,
|
2016-04-17 00:34:39 +02:00
|
|
|
'title' => trans('texts.account_management'),
|
2016-04-16 16:58:53 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.management', $data);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-03-16 00:08:00 +01:00
|
|
|
public function showUserDetails()
|
2015-10-14 16:15:39 +02:00
|
|
|
{
|
2018-01-11 10:54:33 +01:00
|
|
|
if (! auth()->user()->registered) {
|
|
|
|
return redirect('/')->withError(trans('texts.sign_up_to_save'));
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$oauthLoginUrls = [];
|
|
|
|
foreach (AuthService::$providers as $provider) {
|
2016-04-13 11:57:03 +02:00
|
|
|
$oauthLoginUrls[] = ['label' => $provider, 'url' => URL::to('/auth/'.strtolower($provider))];
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$data = [
|
|
|
|
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
|
|
|
'title' => trans('texts.user_details'),
|
|
|
|
'user' => Auth::user(),
|
|
|
|
'oauthProviderName' => AuthService::getProviderName(Auth::user()->oauth_provider_id),
|
|
|
|
'oauthLoginUrls' => $oauthLoginUrls,
|
2017-05-14 11:11:38 +02:00
|
|
|
'referralCounts' => $this->referralRepository->getCounts(Auth::user()->referral_code),
|
2015-10-14 16:15:39 +02:00
|
|
|
];
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
return View::make('accounts.user_details', $data);
|
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function showLocalization()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
|
|
|
|
'timezones' => Cache::get('timezones'),
|
|
|
|
'dateFormats' => Cache::get('dateFormats'),
|
|
|
|
'datetimeFormats' => Cache::get('datetimeFormats'),
|
|
|
|
'title' => trans('texts.localization'),
|
2016-07-04 16:20:22 +02:00
|
|
|
'weekdays' => Utils::getTranslatedWeekdayNames(),
|
2016-10-31 10:11:30 +01:00
|
|
|
'months' => Utils::getMonthOptions(),
|
2015-10-14 16:15:39 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.localization', $data);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-01-20 00:07:31 +01:00
|
|
|
private function showBankAccounts()
|
|
|
|
{
|
2017-10-15 11:38:18 +02:00
|
|
|
$account = auth()->user()->account;
|
|
|
|
|
2016-05-15 12:58:11 +02:00
|
|
|
return View::make('accounts.banks', [
|
2016-07-11 19:08:43 +02:00
|
|
|
'title' => trans('texts.bank_accounts'),
|
|
|
|
'advanced' => ! Auth::user()->hasFeature(FEATURE_EXPENSES),
|
2017-10-15 11:38:18 +02:00
|
|
|
'warnPaymentGateway' => ! $account->account_gateways->count(),
|
2016-05-15 12:58:11 +02:00
|
|
|
]);
|
2016-01-20 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function showOnlinePayments()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
|
|
|
$account->load('account_gateways');
|
2018-01-16 14:48:56 +01:00
|
|
|
$count = $account->account_gateways->count();
|
2016-08-08 20:21:43 +02:00
|
|
|
$trashedCount = AccountGateway::scope()->withTrashed()->count();
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-11-29 21:13:50 +01:00
|
|
|
if ($accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) {
|
2016-01-03 20:10:20 +01:00
|
|
|
if (! $accountGateway->getPublishableStripeKey()) {
|
2017-06-29 16:17:33 +02:00
|
|
|
Session::now('warning', trans('texts.missing_publishable_key'));
|
2015-11-29 21:13:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 10:19:00 +02:00
|
|
|
$tokenBillingOptions = [];
|
|
|
|
for ($i = 1; $i <= 4; $i++) {
|
|
|
|
$tokenBillingOptions[$i] = trans("texts.token_billing_{$i}");
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
2017-03-26 10:19:00 +02:00
|
|
|
|
|
|
|
return View::make('accounts.payments', [
|
|
|
|
'showAdd' => $count < count(Gateway::$alternate) + 1,
|
|
|
|
'title' => trans('texts.online_payments'),
|
|
|
|
'tokenBillingOptions' => $tokenBillingOptions,
|
|
|
|
'currency' => Utils::getFromCache(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY), 'currencies'),
|
|
|
|
'taxRates' => TaxRate::scope()->whereIsInclusive(false)->orderBy('rate')->get(['public_id', 'name', 'rate']),
|
|
|
|
'account' => $account,
|
|
|
|
]);
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function showProducts()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'account' => Auth::user()->account,
|
|
|
|
'title' => trans('texts.product_library'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.products', $data);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-21 13:11:08 +02:00
|
|
|
private function showTaxRates()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'account' => Auth::user()->account,
|
|
|
|
'title' => trans('texts.tax_rates'),
|
2017-05-17 11:18:48 +02:00
|
|
|
'taxRates' => TaxRate::scope()->whereIsInclusive(false)->get(),
|
2017-12-03 14:16:09 +01:00
|
|
|
'countInvoices' => Invoice::scope()->withTrashed()->count(),
|
2017-12-04 22:30:04 +01:00
|
|
|
'hasInclusiveTaxRates' => TaxRate::scope()->whereIsInclusive(true)->count() ? true : false,
|
2015-10-21 13:11:08 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.tax_rates', $data);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-01-07 20:39:51 +01:00
|
|
|
private function showPaymentTerms()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'account' => Auth::user()->account,
|
|
|
|
'title' => trans('texts.payment_terms'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return View::make('accounts.payment_terms', $data);
|
|
|
|
}
|
2016-01-19 14:01:19 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $section
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function showInvoiceDesign($section)
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account->load('country');
|
|
|
|
$invoice = new stdClass();
|
|
|
|
$client = new stdClass();
|
|
|
|
$contact = new stdClass();
|
|
|
|
$invoiceItem = new stdClass();
|
2016-03-23 23:40:42 +01:00
|
|
|
$document = new stdClass();
|
2015-10-14 16:15:39 +02:00
|
|
|
|
|
|
|
$client->name = 'Sample Client';
|
2016-12-19 19:30:27 +01:00
|
|
|
$client->address1 = '10 Main St.';
|
|
|
|
$client->city = 'New York';
|
|
|
|
$client->state = 'NY';
|
|
|
|
$client->postal_code = '10000';
|
|
|
|
$client->work_phone = '(212) 555-0000';
|
|
|
|
$client->work_email = 'sample@example.com';
|
2017-04-26 08:28:40 +02:00
|
|
|
$client->balance = 100;
|
2017-12-20 15:39:58 +01:00
|
|
|
$client->vat_number = $account->vat_number ? '1234567890' : '';
|
|
|
|
$client->id_number = $account->id_number ? '1234567890' : '';
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2018-02-14 22:07:30 +01:00
|
|
|
if ($account->custom_client_label1) {
|
|
|
|
$client->custom_value1 = '0000';
|
|
|
|
}
|
|
|
|
if ($account->custom_client_label2) {
|
|
|
|
$client->custom_value2 = '0000';
|
|
|
|
}
|
|
|
|
|
2015-10-23 13:55:18 +02:00
|
|
|
$invoice->invoice_number = '0000';
|
2015-10-14 16:15:39 +02:00
|
|
|
$invoice->invoice_date = Utils::fromSqlDate(date('Y-m-d'));
|
|
|
|
$invoice->account = json_decode($account->toJson());
|
|
|
|
$invoice->amount = $invoice->balance = 100;
|
|
|
|
|
2018-02-14 22:07:30 +01:00
|
|
|
if ($account->custom_invoice_text_label1) {
|
|
|
|
$invoice->custom_text_value1 = '0000';
|
|
|
|
}
|
|
|
|
if ($account->custom_invoice_text_label2) {
|
|
|
|
$invoice->custom_text_value2 = '0000';
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$invoice->terms = trim($account->invoice_terms);
|
|
|
|
$invoice->invoice_footer = trim($account->invoice_footer);
|
|
|
|
|
2016-09-05 14:28:59 +02:00
|
|
|
$contact->first_name = 'Test';
|
|
|
|
$contact->last_name = 'Contact';
|
2015-10-14 16:15:39 +02:00
|
|
|
$contact->email = 'contact@gmail.com';
|
|
|
|
$client->contacts = [$contact];
|
|
|
|
|
|
|
|
$invoiceItem->cost = 100;
|
|
|
|
$invoiceItem->qty = 1;
|
|
|
|
$invoiceItem->notes = 'Notes';
|
|
|
|
$invoiceItem->product_key = 'Item';
|
2018-02-14 22:07:30 +01:00
|
|
|
$invoiceItem->discount = 10;
|
|
|
|
$invoiceItem->tax_name1 = 'Tax';
|
|
|
|
$invoiceItem->tax_rate1 = 10;
|
|
|
|
|
|
|
|
if ($account->custom_invoice_item_label1) {
|
|
|
|
$invoiceItem->custom_value1 = '0000';
|
|
|
|
}
|
|
|
|
if ($account->custom_invoice_item_label2) {
|
|
|
|
$invoiceItem->custom_value2 = '0000';
|
|
|
|
}
|
2015-10-14 16:15:39 +02:00
|
|
|
|
2016-03-23 23:40:42 +01:00
|
|
|
$document->base64 = 'data:image/jpeg;base64,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
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$invoice->client = $client;
|
|
|
|
$invoice->invoice_items = [$invoiceItem];
|
2016-04-19 04:35:18 +02:00
|
|
|
//$invoice->documents = $account->hasFeature(FEATURE_DOCUMENTS) ? [$document] : [];
|
2016-04-13 20:50:54 +02:00
|
|
|
$invoice->documents = [];
|
2016-01-19 14:01:19 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$data['account'] = $account;
|
|
|
|
$data['invoice'] = $invoice;
|
|
|
|
$data['invoiceLabels'] = json_decode($account->invoice_labels) ?: [];
|
|
|
|
$data['title'] = trans('texts.invoice_design');
|
|
|
|
$data['invoiceDesigns'] = InvoiceDesign::getDesigns();
|
2016-01-07 08:08:30 +01:00
|
|
|
$data['invoiceFonts'] = Cache::get('fonts');
|
2015-10-14 16:15:39 +02:00
|
|
|
$data['section'] = $section;
|
2016-09-02 16:53:16 +02:00
|
|
|
$data['pageSizes'] = array_combine(InvoiceDesign::$pageSizes, InvoiceDesign::$pageSizes);
|
2016-01-19 14:01:19 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$design = false;
|
|
|
|
foreach ($data['invoiceDesigns'] as $item) {
|
|
|
|
if ($item->id == $account->invoice_design_id) {
|
|
|
|
$design = $item->javascript;
|
|
|
|
break;
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
if ($section == ACCOUNT_CUSTOMIZE_DESIGN) {
|
2017-06-01 18:13:13 +02:00
|
|
|
if ($custom = $account->getCustomDesign(request()->design_id)) {
|
|
|
|
$data['customDesign'] = $custom;
|
|
|
|
} else {
|
|
|
|
$data['customDesign'] = $design;
|
|
|
|
}
|
2016-02-25 19:34:23 +01:00
|
|
|
|
|
|
|
// sample invoice to help determine variables
|
|
|
|
$invoice = Invoice::scope()
|
2016-05-26 16:56:54 +02:00
|
|
|
->invoiceType(INVOICE_TYPE_STANDARD)
|
2016-02-25 19:34:23 +01:00
|
|
|
->with('client', 'account')
|
|
|
|
->where('is_recurring', '=', false)
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($invoice) {
|
|
|
|
$invoice->hidePrivateFields();
|
|
|
|
unset($invoice->account);
|
|
|
|
unset($invoice->invoice_items);
|
|
|
|
unset($invoice->client->contacts);
|
|
|
|
$data['sampleInvoice'] = $invoice;
|
|
|
|
}
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
return View::make("accounts.{$section}", $data);
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-02-29 22:46:27 +01:00
|
|
|
private function showClientPortal()
|
2015-12-30 19:11:51 +01:00
|
|
|
{
|
|
|
|
$account = Auth::user()->account->load('country');
|
|
|
|
$css = $account->client_view_css ? $account->client_view_css : '';
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
if (Utils::isNinja() && $css) {
|
2015-12-30 19:11:51 +01:00
|
|
|
// Unescape the CSS for display purposes
|
|
|
|
$css = str_replace(
|
2016-07-03 18:11:58 +02:00
|
|
|
['\3C ', '\3E ', '\26 '],
|
|
|
|
['<', '>', '&'],
|
2015-12-30 19:11:51 +01:00
|
|
|
$css
|
|
|
|
);
|
|
|
|
}
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2016-12-04 10:47:58 +01:00
|
|
|
$types = [
|
|
|
|
GATEWAY_TYPE_CREDIT_CARD,
|
|
|
|
GATEWAY_TYPE_BANK_TRANSFER,
|
|
|
|
GATEWAY_TYPE_PAYPAL,
|
|
|
|
GATEWAY_TYPE_BITCOIN,
|
2017-01-30 20:40:43 +01:00
|
|
|
GATEWAY_TYPE_DWOLLA,
|
2016-12-04 10:47:58 +01:00
|
|
|
];
|
2016-07-12 22:46:41 +02:00
|
|
|
$options = [];
|
|
|
|
foreach ($types as $type) {
|
|
|
|
if ($account->getGatewayByType($type)) {
|
2016-12-04 10:47:58 +01:00
|
|
|
$alias = GatewayType::getAliasFromId($type);
|
|
|
|
$options[$alias] = trans("texts.{$alias}");
|
2016-07-12 22:46:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 19:11:51 +01:00
|
|
|
$data = [
|
|
|
|
'client_view_css' => $css,
|
2016-02-29 22:46:27 +01:00
|
|
|
'enable_portal_password' => $account->enable_portal_password,
|
|
|
|
'send_portal_password' => $account->send_portal_password,
|
2016-07-03 18:11:58 +02:00
|
|
|
'title' => trans('texts.client_portal'),
|
2016-01-03 20:10:20 +01:00
|
|
|
'section' => ACCOUNT_CLIENT_PORTAL,
|
2016-03-01 08:36:37 +01:00
|
|
|
'account' => $account,
|
2016-07-12 22:46:41 +02:00
|
|
|
'products' => Product::scope()->orderBy('product_key')->get(),
|
|
|
|
'gateway_types' => $options,
|
2015-12-30 19:11:51 +01:00
|
|
|
];
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
return View::make('accounts.client_portal', $data);
|
2015-12-30 19:11:51 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function showTemplates()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account->load('country');
|
|
|
|
$data['account'] = $account;
|
|
|
|
$data['templates'] = [];
|
|
|
|
$data['defaultTemplates'] = [];
|
2017-09-02 21:03:45 +02:00
|
|
|
foreach (AccountEmailSettings::$templates as $type) {
|
2015-10-14 16:15:39 +02:00
|
|
|
$data['templates'][$type] = [
|
|
|
|
'subject' => $account->getEmailSubject($type),
|
|
|
|
'template' => $account->getEmailTemplate($type),
|
|
|
|
];
|
|
|
|
$data['defaultTemplates'][$type] = [
|
|
|
|
'subject' => $account->getDefaultEmailSubject($type),
|
|
|
|
'template' => $account->getDefaultEmailTemplate($type),
|
|
|
|
];
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
2015-10-14 16:15:39 +02:00
|
|
|
$data['title'] = trans('texts.email_templates');
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
return View::make('accounts.templates_and_reminders', $data);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $section
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-10-31 10:11:30 +01:00
|
|
|
public function doSection($section)
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2016-10-31 10:11:30 +01:00
|
|
|
if ($section === ACCOUNT_LOCALIZATION) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveLocalization();
|
2016-05-25 16:36:40 +02:00
|
|
|
} elseif ($section == ACCOUNT_PAYMENTS) {
|
|
|
|
return self::saveOnlinePayments();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_NOTIFICATIONS) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveNotifications();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_EXPORT) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::export();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_INVOICE_SETTINGS) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveInvoiceSettings();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_INVOICE_DESIGN) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveInvoiceDesign();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_CUSTOMIZE_DESIGN) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveCustomizeDesign();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_TEMPLATES_AND_REMINDERS) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveEmailTemplates();
|
2015-10-14 16:15:39 +02:00
|
|
|
} elseif ($section === ACCOUNT_PRODUCTS) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveProducts();
|
2015-10-21 13:11:08 +02:00
|
|
|
} elseif ($section === ACCOUNT_TAX_RATES) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveTaxRates();
|
2016-01-07 20:39:51 +01:00
|
|
|
} elseif ($section === ACCOUNT_PAYMENT_TERMS) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::savePaymetTerms();
|
2016-10-27 10:57:51 +02:00
|
|
|
} elseif ($section === ACCOUNT_MANAGEMENT) {
|
2017-01-30 20:40:43 +01:00
|
|
|
return self::saveAccountManagement();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 10:57:51 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
private function saveAccountManagement()
|
|
|
|
{
|
2016-12-01 20:39:00 +01:00
|
|
|
$user = Auth::user();
|
|
|
|
$account = $user->account;
|
2016-10-27 10:57:51 +02:00
|
|
|
$modules = Input::get('modules');
|
|
|
|
|
2016-12-01 20:39:00 +01:00
|
|
|
$user->force_pdfjs = Input::get('force_pdfjs') ? true : false;
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$account->live_preview = Input::get('live_preview') ? true : false;
|
|
|
|
|
|
|
|
// Automatically disable live preview when using a large font
|
2017-01-30 17:05:31 +01:00
|
|
|
$fonts = Cache::get('fonts')->filter(function ($font) use ($account) {
|
2016-12-01 20:39:00 +01:00
|
|
|
if ($font->google_font) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-30 20:40:43 +01:00
|
|
|
|
2016-12-01 20:39:00 +01:00
|
|
|
return $font->id == $account->header_font_id || $font->id == $account->body_font_id;
|
|
|
|
});
|
2018-01-16 14:48:56 +01:00
|
|
|
if ($account->live_preview && $fonts->count()) {
|
2016-12-01 20:39:00 +01:00
|
|
|
$account->live_preview = false;
|
|
|
|
Session::flash('warning', trans('texts.live_preview_disabled'));
|
|
|
|
}
|
|
|
|
|
2016-10-27 10:57:51 +02:00
|
|
|
$account->enabled_modules = $modules ? array_sum($modules) : 0;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_MANAGEMENT);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-01-03 20:10:20 +01:00
|
|
|
private function saveCustomizeDesign()
|
|
|
|
{
|
2017-06-01 18:13:13 +02:00
|
|
|
$designId = intval(Input::get('design_id')) ?: CUSTOM_DESIGN1;
|
|
|
|
$field = 'custom_design' . ($designId - 10);
|
|
|
|
|
2016-04-19 04:35:18 +02:00
|
|
|
if (Auth::user()->account->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN)) {
|
2015-07-21 20:51:56 +02:00
|
|
|
$account = Auth::user()->account;
|
2017-06-01 18:13:13 +02:00
|
|
|
if (! $account->custom_design1) {
|
|
|
|
$account->invoice_design_id = CUSTOM_DESIGN1;
|
|
|
|
}
|
|
|
|
$account->$field = Input::get('custom_design');
|
2015-07-21 20:51:56 +02:00
|
|
|
$account->save();
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
}
|
|
|
|
|
2017-06-01 18:13:13 +02:00
|
|
|
return Redirect::to('settings/' . ACCOUNT_CUSTOMIZE_DESIGN . '?design_id=' . $designId);
|
2015-07-21 20:51:56 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2017-01-12 12:52:37 +01:00
|
|
|
public function saveClientPortalSettings(SaveClientPortalSettings $request)
|
2016-01-03 20:10:20 +01:00
|
|
|
{
|
2017-01-12 12:52:37 +01:00
|
|
|
$account = $request->user()->account;
|
2017-11-06 10:58:53 +01:00
|
|
|
|
2017-11-15 13:51:02 +01:00
|
|
|
// check subdomain is unique in the lookup tables
|
|
|
|
if (request()->subdomain) {
|
|
|
|
if (! \App\Models\LookupAccount::validateField('subdomain', request()->subdomain, $account)) {
|
|
|
|
return Redirect::to('settings/' . ACCOUNT_CLIENT_PORTAL)
|
|
|
|
->withError(trans('texts.subdomain_taken'))
|
|
|
|
->withInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($account->subdomain !== $request->subdomain) {
|
2017-11-06 10:58:53 +01:00
|
|
|
event(new SubdomainWasUpdated($account));
|
2017-11-15 13:51:02 +01:00
|
|
|
}
|
2017-11-06 10:58:53 +01:00
|
|
|
|
2017-01-12 12:52:37 +01:00
|
|
|
$account->fill($request->all());
|
2017-02-16 04:27:41 +01:00
|
|
|
$account->client_view_css = $request->client_view_css;
|
|
|
|
$account->subdomain = $request->subdomain;
|
2017-01-12 14:12:02 +01:00
|
|
|
$account->iframe_url = $request->iframe_url;
|
2017-01-12 12:52:37 +01:00
|
|
|
$account->save();
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2017-01-12 12:52:37 +01:00
|
|
|
return redirect('settings/' . ACCOUNT_CLIENT_PORTAL)
|
|
|
|
->with('message', trans('texts.updated_settings'));
|
|
|
|
}
|
2016-03-04 03:57:15 +01:00
|
|
|
|
2017-01-12 12:52:37 +01:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function saveEmailSettings(SaveEmailSettings $request)
|
|
|
|
{
|
|
|
|
$account = $request->user()->account;
|
2017-04-01 22:51:58 +02:00
|
|
|
$account->fill($request->all());
|
2016-05-12 19:26:36 +02:00
|
|
|
$account->save();
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2017-03-31 17:02:56 +02:00
|
|
|
$settings = $account->account_email_settings;
|
2017-04-01 22:51:58 +02:00
|
|
|
$settings->fill($request->all());
|
2017-03-31 17:02:56 +02:00
|
|
|
$settings->save();
|
|
|
|
|
2017-01-12 12:52:37 +01:00
|
|
|
return redirect('settings/' . ACCOUNT_EMAIL_SETTINGS)
|
|
|
|
->with('message', trans('texts.updated_settings'));
|
2015-12-30 19:11:51 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
private function saveEmailTemplates()
|
|
|
|
{
|
2016-04-19 04:35:18 +02:00
|
|
|
if (Auth::user()->account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) {
|
2015-03-16 22:45:25 +01:00
|
|
|
$account = Auth::user()->account;
|
|
|
|
|
2017-09-02 21:03:45 +02:00
|
|
|
foreach (AccountEmailSettings::$templates as $type) {
|
2015-09-17 21:01:06 +02:00
|
|
|
$subjectField = "email_subject_{$type}";
|
2015-09-20 23:05:02 +02:00
|
|
|
$subject = Input::get($subjectField, $account->getEmailSubject($type));
|
2017-03-31 17:02:56 +02:00
|
|
|
$account->account_email_settings->$subjectField = ($subject == $account->getDefaultEmailSubject($type) ? null : $subject);
|
2015-09-17 21:01:06 +02:00
|
|
|
|
|
|
|
$bodyField = "email_template_{$type}";
|
2015-09-20 23:05:02 +02:00
|
|
|
$body = Input::get($bodyField, $account->getEmailTemplate($type));
|
2017-03-31 17:02:56 +02:00
|
|
|
$account->account_email_settings->$bodyField = ($body == $account->getDefaultEmailTemplate($type) ? null : $body);
|
2015-09-17 21:01:06 +02:00
|
|
|
}
|
|
|
|
|
2017-09-02 21:03:45 +02:00
|
|
|
foreach ([TEMPLATE_REMINDER1, TEMPLATE_REMINDER2, TEMPLATE_REMINDER3] as $type) {
|
2015-09-17 21:01:06 +02:00
|
|
|
$enableField = "enable_{$type}";
|
|
|
|
$account->$enableField = Input::get($enableField) ? true : false;
|
2017-02-02 21:07:17 +01:00
|
|
|
$account->{"num_days_{$type}"} = Input::get("num_days_{$type}");
|
|
|
|
$account->{"field_{$type}"} = Input::get("field_{$type}");
|
|
|
|
$account->{"direction_{$type}"} = Input::get("field_{$type}") == REMINDER_FIELD_INVOICE_DATE ? REMINDER_DIRECTION_AFTER : Input::get("direction_{$type}");
|
2017-07-18 20:15:51 +02:00
|
|
|
|
|
|
|
$number = preg_replace('/[^0-9]/', '', $type);
|
|
|
|
$account->account_email_settings->{"late_fee{$number}_amount"} = Input::get("late_fee{$number}_amount");
|
|
|
|
$account->account_email_settings->{"late_fee{$number}_percent"} = Input::get("late_fee{$number}_percent");
|
2015-09-17 21:01:06 +02:00
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-12-25 20:46:59 +01:00
|
|
|
$account->enable_reminder4 = Input::get('enable_reminder4') ? true : false;
|
|
|
|
$account->account_email_settings->frequency_id_reminder4 = Input::get('frequency_id_reminder4');
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
$account->save();
|
2017-03-31 17:02:56 +02:00
|
|
|
$account->account_email_settings->save();
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
}
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_TEMPLATES_AND_REMINDERS);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-10-21 13:11:08 +02:00
|
|
|
private function saveTaxRates()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
2016-05-29 11:26:02 +02:00
|
|
|
$account->fill(Input::all());
|
2015-10-21 13:11:08 +02:00
|
|
|
$account->save();
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_TAX_RATES);
|
2015-10-21 13:11:08 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
private function saveProducts()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
|
|
|
|
|
|
|
$account->fill_products = Input::get('fill_products') ? true : false;
|
|
|
|
$account->update_products = Input::get('update_products') ? true : false;
|
2017-12-21 09:28:44 +01:00
|
|
|
$account->convert_products = Input::get('convert_products') ? true : false;
|
2015-03-16 22:45:25 +01:00
|
|
|
$account->save();
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_PRODUCTS);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-12-15 21:25:12 +01:00
|
|
|
private function saveInvoiceSettings()
|
|
|
|
{
|
2016-04-19 04:35:18 +02:00
|
|
|
if (Auth::user()->account->hasFeature(FEATURE_INVOICE_SETTINGS)) {
|
2017-01-03 20:48:40 +01:00
|
|
|
$rules = [];
|
|
|
|
foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_CLIENT] as $entityType) {
|
|
|
|
if (Input::get("{$entityType}_number_type") == 'pattern') {
|
|
|
|
$rules["{$entityType}_number_pattern"] = 'has_counter';
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 10:31:15 +02:00
|
|
|
if (Input::get('credit_number_enabled')) {
|
|
|
|
$rules['credit_number_prefix'] = 'required_without:credit_number_pattern';
|
|
|
|
$rules['credit_number_pattern'] = 'required_without:credit_number_prefix';
|
|
|
|
}
|
2015-12-15 21:25:12 +01:00
|
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_INVOICE_SETTINGS)
|
2015-12-15 21:25:12 +01:00
|
|
|
->withErrors($validator)
|
|
|
|
->withInput();
|
|
|
|
} else {
|
|
|
|
$account = Auth::user()->account;
|
2015-09-10 19:50:09 +02:00
|
|
|
$account->custom_label1 = trim(Input::get('custom_label1'));
|
|
|
|
$account->custom_value1 = trim(Input::get('custom_value1'));
|
|
|
|
$account->custom_label2 = trim(Input::get('custom_label2'));
|
|
|
|
$account->custom_value2 = trim(Input::get('custom_value2'));
|
|
|
|
$account->custom_client_label1 = trim(Input::get('custom_client_label1'));
|
|
|
|
$account->custom_client_label2 = trim(Input::get('custom_client_label2'));
|
2017-04-16 13:31:14 +02:00
|
|
|
$account->custom_contact_label1 = trim(Input::get('custom_contact_label1'));
|
|
|
|
$account->custom_contact_label2 = trim(Input::get('custom_contact_label2'));
|
2015-09-10 19:50:09 +02:00
|
|
|
$account->custom_invoice_label1 = trim(Input::get('custom_invoice_label1'));
|
|
|
|
$account->custom_invoice_label2 = trim(Input::get('custom_invoice_label2'));
|
|
|
|
$account->custom_invoice_taxes1 = Input::get('custom_invoice_taxes1') ? true : false;
|
|
|
|
$account->custom_invoice_taxes2 = Input::get('custom_invoice_taxes2') ? true : false;
|
2015-10-11 16:41:09 +02:00
|
|
|
$account->custom_invoice_text_label1 = trim(Input::get('custom_invoice_text_label1'));
|
|
|
|
$account->custom_invoice_text_label2 = trim(Input::get('custom_invoice_text_label2'));
|
2016-02-28 12:59:52 +01:00
|
|
|
$account->custom_invoice_item_label1 = trim(Input::get('custom_invoice_item_label1'));
|
|
|
|
$account->custom_invoice_item_label2 = trim(Input::get('custom_invoice_item_label2'));
|
2015-09-10 19:50:09 +02:00
|
|
|
|
2016-04-19 13:26:42 +02:00
|
|
|
$account->invoice_number_padding = Input::get('invoice_number_padding');
|
2015-09-10 19:50:09 +02:00
|
|
|
$account->invoice_number_counter = Input::get('invoice_number_counter');
|
|
|
|
$account->quote_number_prefix = Input::get('quote_number_prefix');
|
|
|
|
$account->share_counter = Input::get('share_counter') ? true : false;
|
2015-10-29 15:42:05 +01:00
|
|
|
$account->invoice_terms = Input::get('invoice_terms');
|
|
|
|
$account->invoice_footer = Input::get('invoice_footer');
|
|
|
|
$account->quote_terms = Input::get('quote_terms');
|
2016-01-20 09:41:57 +01:00
|
|
|
$account->auto_convert_quote = Input::get('auto_convert_quote');
|
2016-02-28 19:36:11 +01:00
|
|
|
$account->recurring_invoice_number_prefix = Input::get('recurring_invoice_number_prefix');
|
2015-10-22 20:48:12 +02:00
|
|
|
|
2017-01-03 20:48:40 +01:00
|
|
|
$account->client_number_prefix = trim(Input::get('client_number_prefix'));
|
|
|
|
$account->client_number_pattern = trim(Input::get('client_number_pattern'));
|
|
|
|
$account->client_number_counter = Input::get('client_number_counter');
|
2017-06-27 21:07:10 +02:00
|
|
|
$account->credit_number_counter = Input::get('credit_number_counter');
|
|
|
|
$account->credit_number_prefix = trim(Input::get('credit_number_prefix'));
|
|
|
|
$account->credit_number_pattern = trim(Input::get('credit_number_pattern'));
|
2017-03-23 10:39:44 +01:00
|
|
|
$account->reset_counter_frequency_id = Input::get('reset_counter_frequency_id');
|
|
|
|
$account->reset_counter_date = $account->reset_counter_frequency_id ? Utils::toSqlDate(Input::get('reset_counter_date')) : null;
|
2017-01-03 20:48:40 +01:00
|
|
|
|
2015-10-22 20:48:12 +02:00
|
|
|
if (Input::has('recurring_hour')) {
|
|
|
|
$account->recurring_hour = Input::get('recurring_hour');
|
|
|
|
}
|
2015-09-10 19:50:09 +02:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $account->share_counter) {
|
2015-09-10 19:50:09 +02:00
|
|
|
$account->quote_number_counter = Input::get('quote_number_counter');
|
|
|
|
}
|
|
|
|
|
2017-01-03 20:48:40 +01:00
|
|
|
foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_CLIENT] as $entityType) {
|
|
|
|
if (Input::get("{$entityType}_number_type") == 'prefix') {
|
|
|
|
$account->{"{$entityType}_number_prefix"} = trim(Input::get("{$entityType}_number_prefix"));
|
|
|
|
$account->{"{$entityType}_number_pattern"} = null;
|
|
|
|
} else {
|
|
|
|
$account->{"{$entityType}_number_pattern"} = trim(Input::get("{$entityType}_number_pattern"));
|
|
|
|
$account->{"{$entityType}_number_prefix"} = null;
|
|
|
|
}
|
2015-10-22 20:48:12 +02:00
|
|
|
}
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $account->share_counter
|
2016-01-31 16:39:31 +01:00
|
|
|
&& $account->invoice_number_prefix == $account->quote_number_prefix
|
|
|
|
&& $account->invoice_number_pattern == $account->quote_number_pattern) {
|
2015-09-10 19:50:09 +02:00
|
|
|
Session::flash('error', trans('texts.invalid_counter'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_INVOICE_SETTINGS)->withInput();
|
2015-09-10 19:50:09 +02:00
|
|
|
} else {
|
|
|
|
$account->save();
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_INVOICE_SETTINGS);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
private function saveInvoiceDesign()
|
|
|
|
{
|
2016-04-19 04:35:18 +02:00
|
|
|
if (Auth::user()->account->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN)) {
|
2015-03-16 22:45:25 +01:00
|
|
|
$account = Auth::user()->account;
|
|
|
|
$account->hide_quantity = Input::get('hide_quantity') ? true : false;
|
|
|
|
$account->hide_paid_to_date = Input::get('hide_paid_to_date') ? true : false;
|
2016-01-31 22:42:20 +01:00
|
|
|
$account->all_pages_header = Input::get('all_pages_header') ? true : false;
|
|
|
|
$account->all_pages_footer = Input::get('all_pages_footer') ? true : false;
|
2016-03-23 23:40:42 +01:00
|
|
|
$account->invoice_embed_documents = Input::get('invoice_embed_documents') ? true : false;
|
2016-01-07 08:19:57 +01:00
|
|
|
$account->header_font_id = Input::get('header_font_id');
|
|
|
|
$account->body_font_id = Input::get('body_font_id');
|
2015-03-16 22:45:25 +01:00
|
|
|
$account->primary_color = Input::get('primary_color');
|
|
|
|
$account->secondary_color = Input::get('secondary_color');
|
2015-09-07 11:07:55 +02:00
|
|
|
$account->invoice_design_id = Input::get('invoice_design_id');
|
2017-06-01 18:13:13 +02:00
|
|
|
$account->quote_design_id = Input::get('quote_design_id');
|
2016-04-19 09:51:57 +02:00
|
|
|
$account->font_size = intval(Input::get('font_size'));
|
|
|
|
$account->page_size = Input::get('page_size');
|
2016-04-19 13:12:02 +02:00
|
|
|
|
2015-05-27 22:20:35 +02:00
|
|
|
$labels = [];
|
2017-06-21 10:07:59 +02:00
|
|
|
foreach (Account::$customLabels as $field) {
|
2015-11-21 22:10:26 +01:00
|
|
|
$labels[$field] = Input::get("labels_{$field}");
|
2015-05-27 22:20:35 +02:00
|
|
|
}
|
|
|
|
$account->invoice_labels = json_encode($labels);
|
2016-09-05 14:28:59 +02:00
|
|
|
$account->invoice_fields = Input::get('invoice_fields_json');
|
2015-05-27 22:20:35 +02:00
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
$account->save();
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
}
|
|
|
|
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_INVOICE_DESIGN);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
private function saveNotifications()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
$user->notify_sent = Input::get('notify_sent');
|
|
|
|
$user->notify_viewed = Input::get('notify_viewed');
|
|
|
|
$user->notify_paid = Input::get('notify_paid');
|
2015-04-13 14:00:31 +02:00
|
|
|
$user->notify_approved = Input::get('notify_approved');
|
2015-03-16 22:45:25 +01:00
|
|
|
$user->save();
|
|
|
|
|
2017-06-05 15:31:28 +02:00
|
|
|
$account = $user->account;
|
|
|
|
$account->fill(request()->all());
|
|
|
|
$account->save();
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_NOTIFICATIONS);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param UpdateAccountRequest $request
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-02-03 13:41:40 +01:00
|
|
|
public function updateDetails(UpdateAccountRequest $request)
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2016-02-03 13:41:40 +01:00
|
|
|
$account = Auth::user()->account;
|
|
|
|
$this->accountRepo->save($request->input(), $account);
|
|
|
|
|
|
|
|
/* Logo image file */
|
2016-04-17 01:14:43 +02:00
|
|
|
if ($uploaded = Input::file('logo')) {
|
2016-02-03 13:41:40 +01:00
|
|
|
$path = Input::file('logo')->getRealPath();
|
2016-04-17 01:14:43 +02:00
|
|
|
$disk = $account->getLogoDisk();
|
|
|
|
$extension = strtolower($uploaded->getClientOriginalExtension());
|
2017-04-27 20:57:47 +02:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (empty(Document::$types[$extension]) && ! empty(Document::$extraExtensions[$extension])) {
|
2016-05-12 19:26:36 +02:00
|
|
|
$documentType = Document::$extraExtensions[$extension];
|
2017-01-30 17:05:31 +01:00
|
|
|
} else {
|
2016-04-17 01:14:43 +02:00
|
|
|
$documentType = $extension;
|
|
|
|
}
|
2016-02-03 13:41:40 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! in_array($documentType, ['jpeg', 'png', 'gif'])) {
|
2016-04-17 01:14:43 +02:00
|
|
|
Session::flash('warning', 'Unsupported file type');
|
2016-02-03 13:41:40 +01:00
|
|
|
} else {
|
2016-04-17 01:14:43 +02:00
|
|
|
$documentTypeData = Document::$types[$documentType];
|
|
|
|
|
|
|
|
$filePath = $uploaded->path();
|
|
|
|
$size = filesize($filePath);
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if ($size / 1000 > MAX_DOCUMENT_SIZE) {
|
2017-04-27 20:57:47 +02:00
|
|
|
Session::flash('error', trans('texts.logo_warning_too_large'));
|
2015-03-16 22:45:25 +01:00
|
|
|
} else {
|
2016-04-17 01:14:43 +02:00
|
|
|
if ($documentType != 'gif') {
|
|
|
|
$account->logo = $account->account_key.'.'.$documentType;
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2017-03-20 15:02:59 +01:00
|
|
|
try {
|
|
|
|
$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 {
|
2017-04-27 20:57:47 +02:00
|
|
|
if (Utils::isInterlaced($filePath)) {
|
|
|
|
$account->clearLogo();
|
|
|
|
Session::flash('error', trans('texts.logo_warning_invalid'));
|
|
|
|
} else {
|
|
|
|
$stream = fopen($filePath, 'r');
|
|
|
|
$disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
|
|
|
|
fclose($stream);
|
|
|
|
}
|
2017-03-20 15:02:59 +01:00
|
|
|
}
|
|
|
|
} catch (Exception $exception) {
|
2017-04-27 20:57:47 +02:00
|
|
|
$account->clearLogo();
|
|
|
|
Session::flash('error', trans('texts.logo_warning_invalid'));
|
2016-04-17 01:14:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (extension_loaded('fileinfo')) {
|
|
|
|
$account->logo = $account->account_key.'.png';
|
2017-04-21 09:05:15 +02:00
|
|
|
$image = Image::make($path);
|
2016-04-17 01:14:43 +02:00
|
|
|
$image = Image::canvas($image->width(), $image->height(), '#FFFFFF')->insert($image);
|
|
|
|
$imageStr = (string) $image->encode('png');
|
|
|
|
$disk->put($account->logo, $imageStr);
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2016-04-17 01:14:43 +02:00
|
|
|
$account->logo_size = strlen($imageStr);
|
|
|
|
$account->logo_width = $image->width();
|
|
|
|
$account->logo_height = $image->height();
|
|
|
|
} else {
|
2017-04-27 20:57:47 +02:00
|
|
|
Session::flash('error', trans('texts.logo_warning_fileinfo'));
|
2016-04-17 01:14:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
2016-02-03 13:41:40 +01:00
|
|
|
}
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2016-04-17 01:14:43 +02:00
|
|
|
$account->save();
|
2016-02-03 13:41:40 +01:00
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-02-03 13:41:40 +01:00
|
|
|
event(new UserSettingsChanged());
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-02-03 13:41:40 +01:00
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2016-02-03 13:41:40 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_COMPANY_DETAILS);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-16 00:08:00 +01:00
|
|
|
public function saveUserDetails()
|
2015-10-14 16:15:39 +02:00
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/** @var \App\Models\User $user */
|
2015-10-14 16:15:39 +02:00
|
|
|
$user = Auth::user();
|
2017-05-01 20:46:31 +02:00
|
|
|
$email = trim(strtolower(Input::get('email')));
|
|
|
|
|
2017-05-15 15:49:58 +02:00
|
|
|
if (! \App\Models\LookupUser::validateField('email', $email, $user)) {
|
2017-05-01 20:46:31 +02:00
|
|
|
return Redirect::to('settings/' . ACCOUNT_USER_DETAILS)
|
|
|
|
->withError(trans('texts.email_taken'))
|
|
|
|
->withInput();
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$rules = ['email' => 'email|required|unique:users,email,'.$user->id.',id'];
|
2017-11-01 20:22:29 +01:00
|
|
|
|
|
|
|
if ($user->google_2fa_secret) {
|
|
|
|
$rules['phone'] = 'required';
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_USER_DETAILS)
|
2015-10-14 16:15:39 +02:00
|
|
|
->withErrors($validator)
|
|
|
|
->withInput();
|
|
|
|
} else {
|
|
|
|
$user->first_name = trim(Input::get('first_name'));
|
|
|
|
$user->last_name = trim(Input::get('last_name'));
|
2017-05-01 20:46:31 +02:00
|
|
|
$user->username = $email;
|
|
|
|
$user->email = $email;
|
2015-10-14 16:15:39 +02:00
|
|
|
$user->phone = trim(Input::get('phone'));
|
2017-06-19 13:19:25 +02:00
|
|
|
$user->dark_mode = Input::get('dark_mode');
|
2015-10-14 16:15:39 +02:00
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
if (! Auth::user()->is_admin) {
|
2017-01-08 16:43:56 +01:00
|
|
|
$user->notify_sent = Input::get('notify_sent');
|
|
|
|
$user->notify_viewed = Input::get('notify_viewed');
|
|
|
|
$user->notify_paid = Input::get('notify_paid');
|
|
|
|
$user->notify_approved = Input::get('notify_approved');
|
|
|
|
}
|
|
|
|
|
2017-11-01 20:22:29 +01:00
|
|
|
if ($user->google_2fa_secret && ! Input::get('enable_two_factor')) {
|
|
|
|
$user->google_2fa_secret = null;
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
if (Utils::isNinja()) {
|
2017-01-30 20:40:43 +01:00
|
|
|
if (Input::get('referral_code') && ! $user->referral_code) {
|
2017-05-14 11:11:38 +02:00
|
|
|
$user->referral_code = strtolower(str_random(RANDOM_KEY_LENGTH));
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
2015-11-16 19:02:04 +01:00
|
|
|
event(new UserSettingsChanged());
|
2015-10-14 16:15:39 +02:00
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_USER_DETAILS);
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
private function saveLocalization()
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/** @var \App\Models\Account $account */
|
2015-10-14 16:15:39 +02:00
|
|
|
$account = Auth::user()->account;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
2015-10-14 16:15:39 +02:00
|
|
|
$account->timezone_id = Input::get('timezone_id') ? Input::get('timezone_id') : null;
|
|
|
|
$account->date_format_id = Input::get('date_format_id') ? Input::get('date_format_id') : null;
|
|
|
|
$account->datetime_format_id = Input::get('datetime_format_id') ? Input::get('datetime_format_id') : null;
|
|
|
|
$account->currency_id = Input::get('currency_id') ? Input::get('currency_id') : 1; // US Dollar
|
|
|
|
$account->language_id = Input::get('language_id') ? Input::get('language_id') : 1; // English
|
|
|
|
$account->military_time = Input::get('military_time') ? true : false;
|
2016-02-04 15:19:49 +01:00
|
|
|
$account->show_currency_code = Input::get('show_currency_code') ? true : false;
|
2016-07-04 16:20:22 +02:00
|
|
|
$account->start_of_week = Input::get('start_of_week') ? Input::get('start_of_week') : 0;
|
2016-10-31 10:11:30 +01:00
|
|
|
$account->financial_year_start = Input::get('financial_year_start') ? Input::get('financial_year_start') : null;
|
2015-10-14 16:15:39 +02:00
|
|
|
$account->save();
|
|
|
|
|
2015-11-16 19:02:04 +01:00
|
|
|
event(new UserSettingsChanged());
|
2015-10-14 16:15:39 +02:00
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_LOCALIZATION);
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-05-25 16:36:40 +02:00
|
|
|
private function saveOnlinePayments()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
|
|
|
$account->token_billing_type_id = Input::get('token_billing_type_id');
|
|
|
|
$account->auto_bill_on_due_date = boolval(Input::get('auto_bill_on_due_date'));
|
2017-03-26 09:37:32 +02:00
|
|
|
$account->gateway_fee_enabled = boolval(Input::get('gateway_fee_enabled'));
|
2017-03-16 17:25:46 +01:00
|
|
|
|
2016-05-25 16:36:40 +02:00
|
|
|
$account->save();
|
|
|
|
|
|
|
|
event(new UserSettingsChanged());
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_settings'));
|
|
|
|
|
|
|
|
return Redirect::to('settings/'.ACCOUNT_PAYMENTS);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function removeLogo()
|
|
|
|
{
|
2016-04-17 01:14:43 +02:00
|
|
|
$account = Auth::user()->account;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-02-16 11:13:26 +01:00
|
|
|
if (! Utils::isNinjaProd() && $account->hasLogo()) {
|
|
|
|
$account->getLogoDisk()->delete($account->logo);
|
2016-04-17 01:14:43 +02:00
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-02-16 11:13:26 +01:00
|
|
|
$account->logo = null;
|
|
|
|
$account->logo_size = null;
|
|
|
|
$account->logo_width = null;
|
|
|
|
$account->logo_height = null;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.removed_logo'));
|
|
|
|
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('settings/'.ACCOUNT_COMPANY_DETAILS);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function checkEmail()
|
|
|
|
{
|
2017-05-01 20:46:31 +02:00
|
|
|
$email = trim(strtolower(Input::get('email')));
|
|
|
|
$user = Auth::user();
|
|
|
|
|
2017-05-15 15:49:58 +02:00
|
|
|
if (! \App\Models\LookupUser::validateField('email', $email, $user)) {
|
2017-05-01 20:46:31 +02:00
|
|
|
return 'taken';
|
|
|
|
}
|
|
|
|
|
|
|
|
$email = User::withTrashed()->where('email', '=', $email)
|
|
|
|
->where('id', '<>', $user->registered ? 0 : $user->id)
|
2016-07-03 18:11:58 +02:00
|
|
|
->first();
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
if ($email) {
|
2016-07-03 18:11:58 +02:00
|
|
|
return 'taken';
|
2015-03-16 22:45:25 +01:00
|
|
|
} else {
|
2016-07-03 18:11:58 +02:00
|
|
|
return 'available';
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function submitSignup()
|
|
|
|
{
|
2017-03-24 12:51:24 +01:00
|
|
|
$user = Auth::user();
|
|
|
|
$account = $user->account;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
$rules = [
|
2015-03-16 22:45:25 +01:00
|
|
|
'new_first_name' => 'required',
|
|
|
|
'new_last_name' => 'required',
|
|
|
|
'new_password' => 'required|min:6',
|
2017-03-24 12:51:24 +01:00
|
|
|
'new_email' => 'email|required|unique:users,email',
|
2016-07-03 18:11:58 +02:00
|
|
|
];
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
if (! $user->registered) {
|
|
|
|
$rules['new_email'] .= ',' . Auth::user()->id . ',id';
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
$firstName = trim(Input::get('new_first_name'));
|
|
|
|
$lastName = trim(Input::get('new_last_name'));
|
|
|
|
$email = trim(strtolower(Input::get('new_email')));
|
|
|
|
$password = trim(Input::get('new_password'));
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-05-15 15:49:58 +02:00
|
|
|
if (! \App\Models\LookupUser::validateField('email', $email, $user)) {
|
2017-05-01 20:46:31 +02:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
if ($user->registered) {
|
|
|
|
$newAccount = $this->accountRepo->create($firstName, $lastName, $email, $password, $account->company);
|
|
|
|
$newUser = $newAccount->users()->first();
|
|
|
|
$users = $this->accountRepo->associateAccounts($user->id, $newUser->id);
|
2016-02-11 16:12:27 +01:00
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
Session::flash('message', trans('texts.created_new_company'));
|
|
|
|
Session::put(SESSION_USER_ACCOUNTS, $users);
|
|
|
|
Auth::loginUsingId($newUser->id);
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
} else {
|
|
|
|
$user->first_name = $firstName;
|
|
|
|
$user->last_name = $lastName;
|
|
|
|
$user->email = $email;
|
|
|
|
$user->username = $user->email;
|
|
|
|
$user->password = bcrypt($password);
|
|
|
|
$user->registered = true;
|
|
|
|
$user->save();
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2017-03-24 12:51:24 +01:00
|
|
|
$user->account->startTrial(PLAN_PRO);
|
|
|
|
|
|
|
|
if (Input::get('go_pro') == 'true') {
|
|
|
|
Session::set(REQUESTED_PRO_PLAN, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "{$user->first_name} {$user->last_name}";
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function doRegister()
|
|
|
|
{
|
|
|
|
$affiliate = Affiliate::where('affiliate_key', '=', SELF_HOST_AFFILIATE_KEY)->first();
|
2015-06-12 10:39:53 +02:00
|
|
|
$email = trim(Input::get('email'));
|
2016-01-03 20:10:20 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $email || $email == TEST_USERNAME) {
|
2015-09-25 11:57:40 +02:00
|
|
|
return RESULT_FAILURE;
|
2015-06-12 10:39:53 +02:00
|
|
|
}
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
$license = new License();
|
|
|
|
$license->first_name = Input::get('first_name');
|
|
|
|
$license->last_name = Input::get('last_name');
|
2015-06-12 10:39:53 +02:00
|
|
|
$license->email = $email;
|
2015-03-16 22:45:25 +01:00
|
|
|
$license->transaction_reference = Request::getClientIp();
|
|
|
|
$license->license_key = Utils::generateLicense();
|
|
|
|
$license->affiliate_id = $affiliate->id;
|
|
|
|
$license->product_id = PRODUCT_SELF_HOST;
|
|
|
|
$license->is_claimed = 1;
|
|
|
|
$license->save();
|
|
|
|
|
2015-09-25 11:57:40 +02:00
|
|
|
return RESULT_SUCCESS;
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-28 16:51:31 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function purgeData()
|
|
|
|
{
|
|
|
|
$this->dispatch(new \App\Jobs\PurgeAccountData());
|
|
|
|
|
|
|
|
return redirect('/settings/account_management')->withMessage(trans('texts.purge_successful'));
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function cancelAccount()
|
|
|
|
{
|
|
|
|
if ($reason = trim(Input::get('reason'))) {
|
|
|
|
$email = Auth::user()->email;
|
|
|
|
$name = Auth::user()->getDisplayName();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'text' => $reason,
|
|
|
|
];
|
|
|
|
|
2016-02-17 16:50:01 +01:00
|
|
|
$subject = 'Invoice Ninja - Canceled Account';
|
|
|
|
|
2017-03-07 09:27:14 +01:00
|
|
|
$this->userMailer->sendTo(env('CONTACT_EMAIL', CONTACT_EMAIL), $email, $name, $subject, 'contact', $data);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2015-10-18 09:30:28 +02:00
|
|
|
$user = Auth::user();
|
2015-03-16 22:45:25 +01:00
|
|
|
$account = Auth::user()->account;
|
2017-09-03 17:36:40 +02:00
|
|
|
|
2015-10-18 09:30:28 +02:00
|
|
|
\Log::info("Canceled Account: {$account->name} - {$user->email}");
|
2017-09-03 17:36:40 +02:00
|
|
|
$type = $account->hasMultipleAccounts() ? 'company' : 'account';
|
|
|
|
$subject = trans("texts.deleted_{$type}");
|
|
|
|
$message = trans("texts.deleted_{$type}_details", ['account' => $account->getDisplayName()]);
|
|
|
|
$this->userMailer->sendMessage($user, $subject, $message);
|
2015-10-18 09:30:28 +02:00
|
|
|
|
2017-05-16 10:02:40 +02:00
|
|
|
$refunded = false;
|
|
|
|
if (! $account->hasMultipleAccounts()) {
|
|
|
|
$company = $account->company;
|
|
|
|
$refunded = $company->processRefund(Auth::user());
|
2017-12-01 11:58:02 +01:00
|
|
|
|
|
|
|
$ninjaClient = $this->accountRepo->getNinjaClient($account);
|
|
|
|
$ninjaClient->delete();
|
2017-05-16 10:02:40 +02:00
|
|
|
}
|
2017-03-28 13:28:25 +02:00
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
Document::scope()->each(function ($item, $key) {
|
2016-05-26 19:48:27 +02:00
|
|
|
$item->delete();
|
|
|
|
});
|
|
|
|
|
2015-07-07 22:08:16 +02:00
|
|
|
$this->accountRepo->unlinkAccount($account);
|
2017-05-16 10:02:40 +02:00
|
|
|
$account->forceDelete();
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-03-29 14:37:42 +02:00
|
|
|
Auth::logout();
|
2015-06-16 21:35:35 +02:00
|
|
|
Session::flush();
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2017-03-28 13:28:25 +02:00
|
|
|
if ($refunded) {
|
|
|
|
Session::flash('warning', trans('texts.plan_refunded'));
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
return Redirect::to('/')->with('clearGuestKey', true);
|
|
|
|
}
|
2015-04-13 14:49:40 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-04-13 14:49:40 +02:00
|
|
|
public function resendConfirmation()
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/** @var \App\Models\User $user */
|
2015-04-13 14:49:40 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
$this->userMailer->sendConfirmation($user);
|
|
|
|
|
2016-01-03 20:10:20 +01:00
|
|
|
return Redirect::to('/settings/'.ACCOUNT_USER_DETAILS)->with('message', trans('texts.confirmation_resent'));
|
2015-10-14 16:15:39 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $section
|
|
|
|
* @param bool $subSection
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-10-14 16:15:39 +02:00
|
|
|
public function redirectLegacy($section, $subSection = false)
|
|
|
|
{
|
|
|
|
if ($section === 'details') {
|
|
|
|
$section = ACCOUNT_COMPANY_DETAILS;
|
|
|
|
} elseif ($section === 'payments') {
|
|
|
|
$section = ACCOUNT_PAYMENTS;
|
|
|
|
} elseif ($section === 'advanced_settings') {
|
|
|
|
$section = $subSection;
|
|
|
|
if ($section === 'token_management') {
|
|
|
|
$section = ACCOUNT_API_TOKENS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! in_array($section, array_merge(Account::$basicSettings, Account::$advancedSettings))) {
|
2015-10-14 16:15:39 +02:00
|
|
|
$section = ACCOUNT_COMPANY_DETAILS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Redirect::to("/settings/$section/", 301);
|
2015-04-13 14:49:40 +02:00
|
|
|
}
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param TemplateService $templateService
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function previewEmail(TemplateService $templateService)
|
2016-05-05 16:46:22 +02:00
|
|
|
{
|
|
|
|
$template = Input::get('template');
|
2017-03-20 12:18:58 +01:00
|
|
|
$invitation = \App\Models\Invitation::scope()
|
|
|
|
->with('invoice.client.contacts')
|
|
|
|
->first();
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2017-03-20 12:18:58 +01:00
|
|
|
if (! $invitation) {
|
2016-05-05 18:25:26 +02:00
|
|
|
return trans('texts.create_invoice_for_sample');
|
|
|
|
}
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2016-07-21 14:35:23 +02:00
|
|
|
/** @var \App\Models\Account $account */
|
2016-05-05 16:46:22 +02:00
|
|
|
$account = Auth::user()->account;
|
2017-03-20 12:18:58 +01:00
|
|
|
$invoice = $invitation->invoice;
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2016-05-05 16:46:22 +02:00
|
|
|
// replace the variables with sample data
|
|
|
|
$data = [
|
|
|
|
'account' => $account,
|
|
|
|
'invoice' => $invoice,
|
2016-06-05 20:05:11 +02:00
|
|
|
'invitation' => $invitation,
|
|
|
|
'link' => $invitation->getLink(),
|
2016-05-05 16:46:22 +02:00
|
|
|
'client' => $invoice->client,
|
2017-01-30 20:40:43 +01:00
|
|
|
'amount' => $invoice->amount,
|
2016-05-05 16:46:22 +02:00
|
|
|
];
|
2016-05-12 19:26:36 +02:00
|
|
|
|
|
|
|
// create the email view
|
2016-05-05 16:51:52 +02:00
|
|
|
$view = 'emails.' . $account->getTemplateView(ENTITY_INVOICE) . '_html';
|
2016-05-05 16:46:22 +02:00
|
|
|
$data = array_merge($data, [
|
|
|
|
'body' => $templateService->processVariables($template, $data),
|
|
|
|
'entityType' => ENTITY_INVOICE,
|
|
|
|
]);
|
2016-05-12 19:26:36 +02:00
|
|
|
|
2016-05-05 16:46:22 +02:00
|
|
|
return Response::view($view, $data);
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|