1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 18:01:35 +02:00
invoiceninja/app/controllers/AccountController.php

872 lines
23 KiB
PHP
Raw Normal View History

2013-11-26 13:45:07 +01:00
<?php
2013-12-26 01:36:34 +01:00
use ninja\repositories\AccountRepository;
2014-04-12 20:55:40 +02:00
use ninja\mailers\UserMailer;
use ninja\mailers\ContactMailer;
2013-12-26 01:36:34 +01:00
2013-11-26 13:45:07 +01:00
class AccountController extends \BaseController {
2013-12-26 01:36:34 +01:00
protected $accountRepo;
2014-04-12 20:55:40 +02:00
protected $userMailer;
protected $contactMailer;
2013-12-26 01:36:34 +01:00
2014-04-12 20:55:40 +02:00
public function __construct(AccountRepository $accountRepo, UserMailer $userMailer, ContactMailer $contactMailer)
2013-12-26 01:36:34 +01:00
{
parent::__construct();
$this->accountRepo = $accountRepo;
2014-04-12 20:55:40 +02:00
$this->userMailer = $userMailer;
$this->contactMailer = $contactMailer;
2013-12-26 01:36:34 +01:00
}
2014-09-28 12:37:54 +02:00
public function install()
{
if (!Utils::isNinja() && !Schema::hasTable('accounts')) {
try {
Artisan::call('migrate');
Artisan::call('db:seed');
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}
}
return Redirect::to('/');
}
public function update()
{
if (!Utils::isNinja()) {
try {
Artisan::call('migrate');
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}
}
return Redirect::to('/');
}
public function reset()
{
2014-09-30 16:03:16 +02:00
/*
2014-09-28 12:37:54 +02:00
if (Utils::isNinjaDev()) {
Confide::logout();
try {
Artisan::call('migrate:reset');
Artisan::call('migrate');
Artisan::call('db:seed');
} catch (Exception $e) {
Response::make($e->getMessage(), 500);
}
}
2014-09-30 16:03:16 +02:00
*/
2014-09-28 12:37:54 +02:00
return Redirect::to('/');
}
2013-11-26 13:45:07 +01:00
public function getStarted()
{
2013-12-07 21:33:07 +01:00
if (Auth::check())
{
return Redirect::to('invoices/create');
}
2013-11-26 13:45:07 +01:00
2013-12-07 21:33:07 +01:00
$user = false;
2013-11-26 13:45:07 +01:00
$guestKey = Input::get('guest_key');
if ($guestKey)
{
$user = User::where('password', '=', $guestKey)->first();
2013-12-03 23:00:01 +01:00
if ($user && $user->registered)
2013-11-26 13:45:07 +01:00
{
return Redirect::to('/');
2013-11-26 13:45:07 +01:00
}
}
if (!$user)
{
2014-04-06 11:02:04 +02:00
$account = $this->accountRepo->create();
$user = $account->users()->first();
2014-01-15 15:01:24 +01:00
2013-12-07 19:45:00 +01:00
Session::forget(RECENTLY_VIEWED);
2013-11-26 13:45:07 +01:00
}
2013-12-03 23:00:01 +01:00
Auth::login($user, true);
2013-12-15 13:55:50 +01:00
Event::fire('user.login');
2014-05-11 20:24:30 +02:00
return Redirect::to('invoices/create');
2013-11-26 13:45:07 +01:00
}
2014-04-03 22:01:03 +02:00
public function enableProPlan()
2014-04-03 23:12:38 +02:00
{
2014-04-13 10:19:10 +02:00
$invoice = $this->accountRepo->enableProPlan();
2014-04-04 11:24:56 +02:00
2014-04-13 10:19:10 +02:00
if ($invoice)
2014-04-04 11:24:56 +02:00
{
2014-04-13 10:19:10 +02:00
$this->contactMailer->sendInvoice($invoice);
2014-04-04 11:24:56 +02:00
}
2014-04-12 20:55:40 +02:00
2014-04-13 10:19:10 +02:00
return RESULT_SUCCESS;
2014-04-03 22:01:03 +02:00
}
2014-02-18 22:56:18 +01:00
public function setTrashVisible($entityType, $visible)
{
2014-07-30 09:08:01 +02:00
Session::put("show_trash:{$entityType}", $visible == 'true');
2014-02-18 22:56:18 +01:00
return Redirect::to("{$entityType}s");
}
2013-12-26 01:36:34 +01:00
public function getSearchData()
{
$data = $this->accountRepo->getSearchData();
return Response::json($data);
}
2014-05-08 21:19:33 +02:00
public function showSection($section = ACCOUNT_DETAILS, $subSection = false)
2013-11-26 13:45:07 +01:00
{
if ($section == ACCOUNT_DETAILS)
2013-11-28 22:10:01 +01:00
{
2014-01-06 19:03:00 +01:00
$data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
2014-06-01 15:35:19 +02:00
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
2014-02-18 16:07:22 +01:00
'timezones' => Timezone::remember(DEFAULT_QUERY_CACHE)->orderBy('location')->get(),
'dateFormats' => DateFormat::remember(DEFAULT_QUERY_CACHE)->get(),
'datetimeFormats' => DatetimeFormat::remember(DEFAULT_QUERY_CACHE)->get(),
2014-03-19 23:00:56 +01:00
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'languages' => Language::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id,
2014-01-06 19:03:00 +01:00
];
2013-11-28 22:10:01 +01:00
2014-01-06 19:03:00 +01:00
return View::make('accounts.details', $data);
2013-11-26 13:45:07 +01:00
}
2014-02-18 16:07:22 +01:00
else if ($section == ACCOUNT_PAYMENTS)
2013-11-26 13:45:07 +01:00
{
2013-12-03 18:32:33 +01:00
$account = Account::with('account_gateways')->findOrFail(Auth::user()->account_id);
$accountGateway = null;
2013-11-28 22:10:01 +01:00
$config = null;
$configFields = null;
2014-07-17 22:44:34 +02:00
$selectedCards = 0;
if (count($account->account_gateways) > 0)
{
$accountGateway = $account->account_gateways[0];
2013-11-28 22:10:01 +01:00
$config = $accountGateway->config;
2014-06-30 00:11:31 +02:00
$selectedCards = $accountGateway->accepted_credit_cards;
$configFields = json_decode($config);
foreach($configFields as $configField => $value)
{
$configFields->$configField = str_repeat('*', strlen($value));
}
}
$recommendedGateways = Gateway::remember(DEFAULT_QUERY_CACHE)
->where('recommended', '=', '1')
->orderBy('sort_order')
->get();
$recommendedGatewayArray = array();
foreach($recommendedGateways as $recommendedGateway)
{
$arrayItem = array(
'value' => $recommendedGateway->id,
'other' => 'false',
'data-imageUrl' => asset($recommendedGateway->getLogoUrl()),
'data-siteUrl' => $recommendedGateway->site_url
);
$recommendedGatewayArray[$recommendedGateway->name] = $arrayItem;
}
2014-07-17 22:44:34 +02:00
$creditCardsArray = unserialize(CREDIT_CARDS);
$creditCards = [];
foreach($creditCardsArray as $card => $name)
{
2014-07-17 22:44:34 +02:00
if($selectedCards > 0 && ($selectedCards & $card) == $card)
$creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card']), 'checked' => 'checked'];
else
$creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card'])];
}
2014-04-18 10:57:31 +02:00
$otherItem = array(
'value' => 1000000,
'other' => 'true',
'data-imageUrl' => '',
'data-siteUrl' => ''
);
$recommendedGatewayArray['Other Options'] = $otherItem;
2014-07-17 22:44:34 +02:00
$data = [
'account' => $account,
'accountGateway' => $accountGateway,
'config' => $configFields,
'gateways' => Gateway::remember(DEFAULT_QUERY_CACHE)
->orderBy('name')
->get(),
'dropdownGateways' => Gateway::remember(DEFAULT_QUERY_CACHE)
->where('recommended', '=', '0')
->orderBy('name')
->get(),
'recommendedGateways' => $recommendedGatewayArray,
2014-07-17 22:44:34 +02:00
'creditCardTypes' => $creditCards,
];
2013-11-26 13:45:07 +01:00
foreach ($data['gateways'] as $gateway)
2013-11-26 13:45:07 +01:00
{
$paymentLibrary = $gateway->paymentlibrary;
2013-11-26 13:45:07 +01:00
$gateway->fields = $gateway->getFields();
if ($accountGateway && $accountGateway->gateway_id == $gateway->id)
{
$accountGateway->fields = $gateway->fields;
}
}
2014-02-18 16:07:22 +01:00
return View::make('accounts.payments', $data);
2013-11-26 13:45:07 +01:00
}
2014-02-18 16:07:22 +01:00
else if ($section == ACCOUNT_NOTIFICATIONS)
2013-11-26 13:45:07 +01:00
{
2014-02-18 16:07:22 +01:00
$data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
];
return View::make('accounts.notifications', $data);
2013-11-26 13:45:07 +01:00
}
2014-02-18 16:07:22 +01:00
else if ($section == ACCOUNT_IMPORT_EXPORT)
2013-11-26 13:45:07 +01:00
{
2014-02-18 16:07:22 +01:00
return View::make('accounts.import_export');
2013-11-26 13:45:07 +01:00
}
2014-04-29 22:46:40 +02:00
else if ($section == ACCOUNT_ADVANCED_SETTINGS)
2014-04-18 10:57:31 +02:00
{
$data = [
2014-05-09 15:28:20 +02:00
'account' => Auth::user()->account,
'feature' => $subSection
2014-04-18 10:57:31 +02:00
];
2014-05-08 21:19:33 +02:00
return View::make("accounts.{$subSection}", $data);
2014-04-18 10:57:31 +02:00
}
2014-04-23 22:30:54 +02:00
else if ($section == ACCOUNT_PRODUCTS)
{
$data = [
'account' => Auth::user()->account
];
return View::make('accounts.products', $data);
}
}
2014-05-22 20:29:29 +02:00
public function doSection($section = ACCOUNT_DETAILS, $subSection = false)
2013-11-26 13:45:07 +01:00
{
if ($section == ACCOUNT_DETAILS)
{
return AccountController::saveDetails();
}
2014-02-18 16:07:22 +01:00
else if ($section == ACCOUNT_PAYMENTS)
2013-11-26 13:45:07 +01:00
{
2014-02-18 16:07:22 +01:00
return AccountController::savePayments();
2013-11-26 13:45:07 +01:00
}
2014-02-18 16:07:22 +01:00
else if ($section == ACCOUNT_IMPORT_EXPORT)
2013-11-26 13:45:07 +01:00
{
return AccountController::importFile();
}
else if ($section == ACCOUNT_MAP)
{
return AccountController::mapFile();
}
2014-02-18 16:07:22 +01:00
else if ($section == ACCOUNT_NOTIFICATIONS)
{
return AccountController::saveNotifications();
}
2013-11-26 13:45:07 +01:00
else if ($section == ACCOUNT_EXPORT)
{
return AccountController::export();
}
2014-04-29 22:46:40 +02:00
else if ($section == ACCOUNT_ADVANCED_SETTINGS)
2014-04-18 10:57:31 +02:00
{
2014-05-08 21:19:33 +02:00
if ($subSection == ACCOUNT_CUSTOM_FIELDS)
{
return AccountController::saveCustomFields();
}
else if ($subSection == ACCOUNT_INVOICE_DESIGN)
{
return AccountController::saveInvoiceDesign();
}
2014-04-18 10:57:31 +02:00
}
2014-04-23 22:30:54 +02:00
else if ($section == ACCOUNT_PRODUCTS)
{
return AccountController::saveProducts();
}
}
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;
$account->save();
Session::flash('message', trans('texts.updated_settings'));
return Redirect::to('company/products');
2014-04-18 10:57:31 +02:00
}
2014-05-08 21:19:33 +02:00
private function saveCustomFields()
2014-04-18 10:57:31 +02:00
{
2014-05-22 20:29:29 +02:00
if (Auth::user()->account->isPro())
2014-05-08 21:19:33 +02:00
{
$account = Auth::user()->account;
2014-07-20 12:38:42 +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'));
$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;
2014-05-08 21:19:33 +02:00
$account->save();
Session::flash('message', trans('texts.updated_settings'));
}
2014-04-29 22:46:40 +02:00
2014-05-22 20:29:29 +02:00
return Redirect::to('company/advanced_settings/custom_fields');
2014-05-08 21:19:33 +02:00
}
2014-04-29 22:46:40 +02:00
2014-05-08 21:19:33 +02:00
private function saveInvoiceDesign()
{
2014-05-22 20:29:29 +02:00
if (Auth::user()->account->isPro())
2014-05-08 21:19:33 +02:00
{
$account = Auth::user()->account;
2014-07-20 12:38:42 +02:00
$account->hide_quantity = Input::get('hide_quantity') ? true : false;
$account->hide_paid_to_date = Input::get('hide_paid_to_date') ? true : false;
2014-05-08 21:19:33 +02:00
$account->primary_color = Input::get('primary_color');// ? Input::get('primary_color') : null;
$account->secondary_color = Input::get('secondary_color');// ? Input::get('secondary_color') : null;
$account->save();
2014-04-18 10:57:31 +02:00
2014-05-08 21:19:33 +02:00
Session::flash('message', trans('texts.updated_settings'));
}
2014-05-22 20:29:29 +02:00
return Redirect::to('company/advanced_settings/invoice_design');
2013-11-26 13:45:07 +01:00
}
private function export()
{
2014-04-01 12:30:43 +02:00
$output = fopen('php://output','w') or Utils::fatalError();
header('Content-Type:application/csv');
header('Content-Disposition:attachment;filename=export.csv');
2013-11-26 13:45:07 +01:00
2014-03-31 12:52:03 +02:00
$clients = Client::scope()->get();
2013-11-26 13:45:07 +01:00
AccountController::exportData($output, $clients->toArray());
2014-03-31 12:52:03 +02:00
$contacts = Contact::scope()->get();
AccountController::exportData($output, $contacts->toArray());
$invoices = Invoice::scope()->get();
AccountController::exportData($output, $invoices->toArray());
2013-11-26 13:45:07 +01:00
2014-03-31 12:52:03 +02:00
$invoiceItems = InvoiceItem::scope()->get();
AccountController::exportData($output, $invoiceItems->toArray());
2013-11-26 13:45:07 +01:00
2014-03-31 12:52:03 +02:00
$payments = Payment::scope()->get();
2013-11-26 13:45:07 +01:00
AccountController::exportData($output, $payments->toArray());
2014-03-31 12:52:03 +02:00
$credits = Credit::scope()->get();
2014-01-09 22:38:18 +01:00
AccountController::exportData($output, $credits->toArray());
2013-11-26 13:45:07 +01:00
fclose($output);
exit;
}
private function exportData($output, $data)
{
if (count($data) > 0)
{
fputcsv($output, array_keys($data[0]));
}
foreach($data as $record)
{
fputcsv($output, $record);
}
fwrite($output, "\n");
}
private function importFile()
{
$data = Session::get('data');
Session::forget('data');
$map = Input::get('map');
$count = 0;
$hasHeaders = Input::get('header_checkbox');
2014-01-22 10:11:33 +01:00
$countries = Country::remember(DEFAULT_QUERY_CACHE)->get();
2013-12-01 21:58:25 +01:00
$countryMap = [];
2014-01-22 10:11:33 +01:00
foreach ($countries as $country)
{
2013-12-01 21:58:25 +01:00
$countryMap[strtolower($country->name)] = $country->id;
}
2013-11-26 13:45:07 +01:00
foreach ($data as $row)
{
if ($hasHeaders)
{
$hasHeaders = false;
continue;
}
2013-12-05 16:23:24 +01:00
$client = Client::createNew();
$contact = Contact::createNew();
2014-01-22 10:11:33 +01:00
$contact->is_primary = true;
2014-07-27 22:31:41 +02:00
$contact->send_invoice = true;
2013-11-26 13:45:07 +01:00
$count++;
foreach ($row as $index => $value)
{
$field = $map[$index];
2013-12-07 19:45:00 +01:00
$value = trim($value);
2013-11-26 13:45:07 +01:00
2014-01-22 10:11:33 +01:00
if ($field == Client::$fieldName && !$client->name)
2013-11-26 13:45:07 +01:00
{
$client->name = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldPhone && !$client->work_phone)
2013-11-26 13:45:07 +01:00
{
$client->work_phone = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldAddress1 && !$client->address1)
2013-11-26 13:45:07 +01:00
{
$client->address1 = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldAddress2 && !$client->address2)
2013-11-26 13:45:07 +01:00
{
$client->address2 = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldCity && !$client->city)
2013-11-26 13:45:07 +01:00
{
$client->city = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldState && !$client->state)
2013-11-26 13:45:07 +01:00
{
$client->state = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldPostalCode && !$client->postal_code)
2013-11-26 13:45:07 +01:00
{
$client->postal_code = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldCountry && !$client->country_id)
2013-12-01 21:58:25 +01:00
{
$value = strtolower($value);
$client->country_id = isset($countryMap[$value]) ? $countryMap[$value] : null;
}
2014-01-22 10:11:33 +01:00
else if ($field == Client::$fieldNotes && !$client->private_notes)
2013-11-26 13:45:07 +01:00
{
2014-01-22 10:11:33 +01:00
$client->private_notes = $value;
2013-11-26 13:45:07 +01:00
}
2014-01-22 10:11:33 +01:00
else if ($field == Contact::$fieldFirstName && !$contact->first_name)
2013-11-26 13:45:07 +01:00
{
$contact->first_name = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Contact::$fieldLastName && !$contact->last_name)
2013-11-26 13:45:07 +01:00
{
$contact->last_name = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Contact::$fieldPhone && !$contact->phone)
2013-11-26 13:45:07 +01:00
{
$contact->phone = $value;
}
2014-01-22 10:11:33 +01:00
else if ($field == Contact::$fieldEmail && !$contact->email)
2013-11-26 13:45:07 +01:00
{
2014-02-09 16:38:50 +01:00
$contact->email = strtolower($value);
2013-11-26 13:45:07 +01:00
}
}
$client->save();
2013-11-26 22:45:10 +01:00
$client->contacts()->save($contact);
2014-07-27 22:31:41 +02:00
Activity::createClient($client, false);
2013-11-26 13:45:07 +01:00
}
2014-04-01 12:30:43 +02:00
$message = Utils::pluralize('created_client', $count);
2013-11-26 13:45:07 +01:00
Session::flash('message', $message);
return Redirect::to('clients');
}
private function mapFile()
2014-04-01 12:30:43 +02:00
{
2013-11-26 13:45:07 +01:00
$file = Input::file('file');
2014-04-01 12:30:43 +02:00
if ($file == null)
{
Session::flash('error', trans('texts.select_file'));
return Redirect::to('company/import_export');
}
2013-11-26 13:45:07 +01:00
$name = $file->getRealPath();
require_once(app_path().'/includes/parsecsv.lib.php');
$csv = new parseCSV();
$csv->heading = false;
$csv->auto($name);
2014-02-01 21:01:32 +01:00
2014-04-13 15:34:58 +02:00
if (count($csv->data) + Client::scope()->count() > Auth::user()->getMaxNumClients())
2014-02-01 21:01:32 +01:00
{
2014-07-27 22:31:41 +02:00
$message = trans('texts.limit_clients', ['count' => Auth::user()->getMaxNumClients()]);
2014-04-01 12:30:43 +02:00
Session::flash('error', $message);
2014-02-18 16:07:22 +01:00
return Redirect::to('company/import_export');
2014-02-01 21:01:32 +01:00
}
2013-11-26 13:45:07 +01:00
Session::put('data', $csv->data);
$headers = false;
$hasHeaders = false;
$mapped = array();
$columns = array('',
Client::$fieldName,
Client::$fieldPhone,
Client::$fieldAddress1,
Client::$fieldAddress2,
Client::$fieldCity,
Client::$fieldState,
Client::$fieldPostalCode,
2013-12-01 21:58:25 +01:00
Client::$fieldCountry,
2013-11-26 13:45:07 +01:00
Client::$fieldNotes,
Contact::$fieldFirstName,
Contact::$fieldLastName,
Contact::$fieldPhone,
Contact::$fieldEmail
);
if (count($csv->data) > 0)
{
$headers = $csv->data[0];
foreach ($headers as $title)
{
if (strpos(strtolower($title),'name') > 0)
{
$hasHeaders = true;
break;
}
}
for ($i=0; $i<count($headers); $i++)
{
$title = strtolower($headers[$i]);
$mapped[$i] = '';
if ($hasHeaders)
{
$map = array(
'first' => Contact::$fieldFirstName,
'last' => Contact::$fieldLastName,
'email' => Contact::$fieldEmail,
'mobile' => Contact::$fieldPhone,
'phone' => Client::$fieldPhone,
2013-12-05 21:25:20 +01:00
'name|organization' => Client::$fieldName,
2014-01-22 10:11:33 +01:00
'street|address|address1' => Client::$fieldAddress1,
'street2|address2' => Client::$fieldAddress2,
2013-11-26 13:45:07 +01:00
'city' => Client::$fieldCity,
2014-01-22 10:11:33 +01:00
'state|province' => Client::$fieldState,
2013-11-26 13:45:07 +01:00
'zip|postal|code' => Client::$fieldPostalCode,
2013-12-01 21:58:25 +01:00
'country' => Client::$fieldCountry,
2013-11-26 13:45:07 +01:00
'note' => Client::$fieldNotes,
);
foreach ($map as $search => $column)
{
foreach(explode("|", $search) as $string)
{
2014-01-22 10:11:33 +01:00
if (strpos($title, 'sec') === 0)
{
continue;
}
2013-11-26 13:45:07 +01:00
if (strpos($title, $string) !== false)
{
$mapped[$i] = $column;
break(2);
}
}
}
}
}
}
$data = array(
'data' => $csv->data,
'headers' => $headers,
'hasHeaders' => $hasHeaders,
'columns' => $columns,
'mapped' => $mapped
);
return View::make('accounts.import_map', $data);
}
2014-02-18 16:07:22 +01:00
private function saveNotifications()
{
2014-04-18 10:57:31 +02:00
$account = Auth::user()->account;
2014-02-18 16:07:22 +01:00
$account->invoice_terms = Input::get('invoice_terms');
$account->email_footer = Input::get('email_footer');
$account->save();
$user = Auth::user();
$user->notify_sent = Input::get('notify_sent');
$user->notify_viewed = Input::get('notify_viewed');
$user->notify_paid = Input::get('notify_paid');
$user->save();
2014-04-01 12:30:43 +02:00
Session::flash('message', trans('texts.updated_settings'));
2014-02-18 16:07:22 +01:00
return Redirect::to('company/notifications');
}
private function savePayments()
2014-06-23 22:31:21 +02:00
{
2013-11-26 13:45:07 +01:00
$rules = array();
$recommendedId = Input::get('recommendedGateway_id');
2013-11-26 13:45:07 +01:00
if ($gatewayId = $recommendedId == 1000000 ? Input::get('gateway_id') : $recommendedId)
{
2013-12-03 18:32:33 +01:00
$gateway = Gateway::findOrFail($gatewayId);
2014-07-17 22:44:34 +02:00
$paymentLibrary = $gateway->paymentlibrary;
$fields = $gateway->getFields();
2013-11-26 13:45:07 +01:00
foreach ($fields as $field => $details)
{
2014-03-18 22:25:54 +01:00
if (!in_array($field, ['testMode', 'developerMode', 'headerImageUrl', 'solutionType', 'landingPage', 'brandName']))
2013-11-26 13:45:07 +01:00
{
if(strtolower($gateway->name) == 'beanstream')
{
if(in_array($field, ['merchant_id', 'passCode']))
{
2014-07-17 22:44:34 +02:00
$rules[$gateway->id.'_'.$field] = 'required';
}
}
else
{
2014-07-17 22:44:34 +02:00
$rules[$gateway->id.'_'.$field] = 'required';
}
}
}
2013-11-26 13:45:07 +01:00
}
2014-06-23 22:31:21 +02:00
2014-07-17 22:44:34 +02:00
$creditcards = Input::get('creditCardTypes');
2013-11-26 13:45:07 +01:00
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
2014-03-10 07:10:08 +01:00
return Redirect::to('company/payments')
2013-11-26 13:45:07 +01:00
->withErrors($validator)
->withInput();
}
else
{
$account = Account::with('account_gateways')->findOrFail(Auth::user()->account_id);
2013-11-26 13:45:07 +01:00
if ($gatewayId)
{
2014-01-02 09:27:48 +01:00
$accountGateway = AccountGateway::createNew();
$accountGateway->gateway_id = $gatewayId;
$isMasked = false;
$config = new stdClass;
foreach ($fields as $field => $details)
{
2014-07-17 22:44:34 +02:00
$value = trim(Input::get($gateway->id.'_'.$field));
if ($value && $value === str_repeat('*', strlen($value)))
{
$isMasked = true;
2014-07-17 22:44:34 +02:00
}
$config->$field = $value;
2014-06-23 22:31:21 +02:00
}
$cardCount = 0;
if ($creditcards)
{
foreach($creditcards as $card => $value)
{
$cardCount += intval($value);
}
}
if ($isMasked && count($account->account_gateways))
{
$currentGateway = $account->account_gateways[0];
$currentGateway->accepted_credit_cards = $cardCount;
$currentGateway->save();
}
else
{
$accountGateway->config = json_encode($config);
$accountGateway->accepted_credit_cards = $cardCount;
2014-07-17 22:44:34 +02:00
$account->account_gateways()->delete();
$account->account_gateways()->save($accountGateway);
}
2013-11-26 13:45:07 +01:00
2014-07-17 22:44:34 +02:00
Session::flash('message', trans('texts.updated_settings'));
}
else
{
Session::flash('error', trans('validation.required', ['attribute' => 'gateway']));
}
2014-02-18 16:07:22 +01:00
return Redirect::to('company/payments');
2013-11-26 13:45:07 +01:00
}
}
private function saveDetails()
{
$rules = array(
'name' => 'required',
);
$user = Auth::user()->account->users()->first();
if (Auth::user()->id === $user->id)
{
$rules['email'] = 'email|required|unique:users,email,' . $user->id . ',id';
}
2013-11-26 13:45:07 +01:00
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
2014-02-18 16:07:22 +01:00
return Redirect::to('company/details')
2013-11-26 13:45:07 +01:00
->withErrors($validator)
->withInput();
}
else
{
2014-03-23 20:38:03 +01:00
$account = Auth::user()->account;
2013-12-07 19:45:00 +01:00
$account->name = trim(Input::get('name'));
2014-03-03 19:26:45 +01:00
$account->work_email = trim(Input::get('work_email'));
$account->work_phone = trim(Input::get('work_phone'));
2013-12-07 19:45:00 +01:00
$account->address1 = trim(Input::get('address1'));
$account->address2 = trim(Input::get('address2'));
$account->city = trim(Input::get('city'));
$account->state = trim(Input::get('state'));
$account->postal_code = trim(Input::get('postal_code'));
2014-03-03 19:26:45 +01:00
$account->country_id = Input::get('country_id') ? Input::get('country_id') : null;
2014-01-06 19:03:00 +01:00
$account->size_id = Input::get('size_id') ? Input::get('size_id') : null;
$account->industry_id = Input::get('industry_id') ? Input::get('industry_id') : null;
2014-02-18 16:07:22 +01: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;
2014-03-19 23:00:56 +01:00
$account->currency_id = Input::get('currency_id') ? Input::get('currency_id') : 1; // US Dollar
2014-03-27 13:25:31 +01:00
$account->language_id = Input::get('language_id') ? Input::get('language_id') : 1; // English
2013-11-26 13:45:07 +01:00
$account->save();
if (Auth::user()->id === $user->id)
{
$user->first_name = trim(Input::get('first_name'));
$user->last_name = trim(Input::get('last_name'));
$user->username = trim(Input::get('email'));
$user->email = trim(strtolower(Input::get('email')));
$user->phone = trim(Input::get('phone'));
$user->save();
}
2013-12-02 13:22:29 +01:00
2013-11-26 13:45:07 +01:00
/* Logo image file */
if ($file = Input::file('logo'))
{
$path = Input::file('logo')->getRealPath();
2014-03-18 19:55:50 +01:00
File::delete('logo/' . $account->account_key . '.jpg');
2014-05-22 20:29:29 +02:00
$image = Image::make($path)->resize(200, 120, true, false);
2014-06-16 00:13:31 +02:00
Image::canvas($image->width, $image->height, '#FFFFFF')->insert($image)->save($account->getLogoPath());
2013-11-26 13:45:07 +01:00
}
2014-02-18 16:07:22 +01:00
Event::fire('user.refresh');
2014-04-01 12:30:43 +02:00
Session::flash('message', trans('texts.updated_settings'));
2014-02-18 16:07:22 +01:00
return Redirect::to('company/details');
2013-11-26 13:45:07 +01:00
}
}
2013-12-03 18:32:33 +01:00
2014-03-18 19:55:50 +01:00
public function removeLogo() {
File::delete('logo/' . Auth::user()->account->account_key . '.jpg');
2014-04-01 12:30:43 +02:00
Session::flash('message', trans('texts.removed_logo'));
2014-03-18 19:55:50 +01:00
return Redirect::to('company/details');
}
2013-12-03 18:32:33 +01:00
public function checkEmail()
{
2014-01-06 19:03:00 +01:00
$email = User::withTrashed()->where('email', '=', Input::get('email'))->where('id', '<>', Auth::user()->id)->first();
2013-12-03 18:32:33 +01:00
2014-01-06 19:03:00 +01:00
if ($email)
{
2013-12-03 18:32:33 +01:00
return "taken";
2014-01-06 19:03:00 +01:00
}
2014-01-30 23:29:09 +01:00
else
{
2013-12-03 18:32:33 +01:00
return "available";
}
}
public function submitSignup()
{
$rules = array(
2014-01-01 00:50:13 +01:00
'new_first_name' => 'required',
'new_last_name' => 'required',
'new_password' => 'required|min:6',
2014-01-16 22:12:46 +01:00
'new_email' => 'email|required|unique:users,email,' . Auth::user()->id . ',id'
2013-12-03 18:32:33 +01:00
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
2014-01-30 23:29:09 +01:00
return '';
2013-12-03 18:32:33 +01:00
}
$user = Auth::user();
2013-12-24 22:27:36 +01:00
$user->first_name = trim(Input::get('new_first_name'));
$user->last_name = trim(Input::get('new_last_name'));
2014-02-09 16:38:50 +01:00
$user->email = trim(strtolower(Input::get('new_email')));
2014-03-10 22:55:56 +01:00
$user->username = $user->email;
2013-12-24 22:27:36 +01:00
$user->password = trim(Input::get('new_password'));
2014-01-13 20:22:43 +01:00
$user->password_confirmation = trim(Input::get('new_password'));
2013-12-03 18:32:33 +01:00
$user->registered = true;
2014-01-16 22:12:46 +01:00
$user->amend();
2013-12-03 18:32:33 +01:00
2014-04-12 20:55:40 +02:00
$this->userMailer->sendConfirmation($user);
2014-03-10 22:55:56 +01:00
2013-12-03 18:32:33 +01:00
$activities = Activity::scope()->get();
2014-01-01 00:50:13 +01:00
foreach ($activities as $activity)
{
2013-12-03 18:32:33 +01:00
$activity->message = str_replace('Guest', $user->getFullName(), $activity->message);
$activity->save();
}
2014-04-13 10:19:10 +02:00
if (Input::get('go_pro') == 'true')
{
Session::set(REQUESTED_PRO_PLAN, true);
}
2014-04-22 22:10:14 +02:00
Session::set(SESSION_COUNTER, -1);
2014-01-30 23:29:09 +01:00
return "{$user->first_name} {$user->last_name}";
2013-12-03 18:32:33 +01:00
}
2014-09-14 14:26:51 +02:00
public function cancelAccount()
{
$account = Auth::user()->account;
$account->forceDelete();
Confide::logout();
return Redirect::to('/')->with('clearGuestKey', true);
}
2013-11-26 13:45:07 +01:00
}