1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Add financial year start setting for dashboard

This commit is contained in:
Hillel Coren 2016-10-31 11:11:30 +02:00
parent b39f2f4ba5
commit eca4d7ce6a
9 changed files with 68 additions and 28 deletions

View File

@ -429,6 +429,7 @@ class AccountController extends BaseController
'currencies' => Cache::get('currencies'),
'title' => trans('texts.localization'),
'weekdays' => Utils::getTranslatedWeekdayNames(),
'months' => Utils::getMonthOptions(),
];
return View::make('accounts.localization', $data);
@ -674,11 +675,9 @@ class AccountController extends BaseController
* @param $section
* @return \Illuminate\Http\RedirectResponse
*/
public function doSection($section = ACCOUNT_COMPANY_DETAILS)
public function doSection($section)
{
if ($section === ACCOUNT_COMPANY_DETAILS) {
return AccountController::saveDetails();
} elseif ($section === ACCOUNT_LOCALIZATION) {
if ($section === ACCOUNT_LOCALIZATION) {
return AccountController::saveLocalization();
} elseif ($section == ACCOUNT_PAYMENTS) {
return self::saveOnlinePayments();
@ -1225,6 +1224,7 @@ class AccountController extends BaseController
$account->military_time = Input::get('military_time') ? true : false;
$account->show_currency_code = Input::get('show_currency_code') ? true : false;
$account->start_of_week = Input::get('start_of_week') ? Input::get('start_of_week') : 0;
$account->financial_year_start = Input::get('financial_year_start') ? Input::get('financial_year_start') : null;
$account->save();
event(new UserSettingsChanged());

View File

@ -23,8 +23,8 @@ class DashboardApiController extends BaseAPIController
$dashboardRepo = $this->dashboardRepo;
$metrics = $dashboardRepo->totals($accountId, $userId, $viewAll);
$paidToDate = $dashboardRepo->paidToDate($accountId, $userId, $viewAll);
$averageInvoice = $dashboardRepo->averages($accountId, $userId, $viewAll);
$paidToDate = $dashboardRepo->paidToDate($account, $userId, $viewAll);
$averageInvoice = $dashboardRepo->averages($account, $userId, $viewAll);
$balances = $dashboardRepo->balances($accountId, $userId, $viewAll);
$activities = $dashboardRepo->activities($accountId, $userId, $viewAll);
$pastDue = $dashboardRepo->pastDue($accountId, $userId, $viewAll);

View File

@ -33,9 +33,9 @@ class DashboardController extends BaseController
$dashboardRepo = $this->dashboardRepo;
$metrics = $dashboardRepo->totals($accountId, $userId, $viewAll);
$paidToDate = $dashboardRepo->paidToDate($accountId, $userId, $viewAll);
$averageInvoice = $dashboardRepo->averages($accountId, $userId, $viewAll);
$balances = $dashboardRepo->balances($accountId, $userId, $viewAll);
$paidToDate = $dashboardRepo->paidToDate($account, $userId, $viewAll);
$averageInvoice = $dashboardRepo->averages($account, $userId, $viewAll);
$balances = $dashboardRepo->balances($accountId, $userId, $viewAll);
$activities = $dashboardRepo->activities($accountId, $userId, $viewAll);
$pastDue = $dashboardRepo->pastDue($accountId, $userId, $viewAll);
$upcoming = $dashboardRepo->upcoming($accountId, $userId, $viewAll);

View File

@ -75,6 +75,8 @@ class OnlinePaymentController extends BaseController
}
$invitation = $invitation->load('invoice.client.account.account_gateways.gateway');
$account = $invitation->account;
$account->loadLocalizationSettings($invitation->invoice->client);
if ( ! $gatewayTypeAlias) {
$gatewayTypeId = Session::get($invitation->id . 'gateway_type');
@ -84,7 +86,7 @@ class OnlinePaymentController extends BaseController
$gatewayTypeId = $gatewayTypeAlias;
}
$paymentDriver = $invitation->account->paymentDriver($invitation, $gatewayTypeId);
$paymentDriver = $account->paymentDriver($invitation, $gatewayTypeId);
try {
return $paymentDriver->startPurchase(Input::all(), $sourceId);

View File

@ -22,6 +22,9 @@ class Utils
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
];
public static $months = [
'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december',
];
public static function isRegistered()
{
@ -97,7 +100,7 @@ class Utils
if (Utils::isNinjaProd()) {
return false;
}
return \App\Models\Account::first()->hasFeature(FEATURE_WHITE_LABEL);
}
@ -649,12 +652,23 @@ class Utils
return Utils::getYear($offset);
}
}
public static function getMonthOptions()
{
$months = [];
for ($i=1; $i<=count(static::$months); $i++) {
$month = static::$months[$i-1];
$number = $i < 10 ? '0' . $i : $i;
$months["2000-{$number}-01"] = trans("texts.{$month}");
}
return $months;
}
private static function getMonth($offset)
{
$months = ['january', 'february', 'march', 'april', 'may', 'june',
'july', 'august', 'september', 'october', 'november', 'december', ];
$months = static::$months;
$month = intval(date('n')) - 1;
$month += $offset;

View File

@ -69,6 +69,7 @@ class Account extends Eloquent
'enable_second_tax_rate',
'include_item_taxes_inline',
'start_of_week',
'financial_year_start',
];
/**

View File

@ -175,29 +175,39 @@ class DashboardRepository
return $metrics->groupBy('accounts.id')->first();
}
public function paidToDate($accountId, $userId, $viewAll)
public function paidToDate($account, $userId, $viewAll)
{
$accountId = $account->id;
$select = DB::raw(
'SUM('.DB::getQueryGrammar()->wrap('clients.paid_to_date', true).') as value,'
'SUM('.DB::getQueryGrammar()->wrap('payments.amount', true).' - '.DB::getQueryGrammar()->wrap('payments.refunded', true).') as value,'
.DB::getQueryGrammar()->wrap('clients.currency_id', true).' as currency_id'
);
$paidToDate = DB::table('accounts')
$paidToDate = DB::table('payments')
->select($select)
->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')
->where('accounts.id', '=', $accountId)
->where('clients.is_deleted', '=', false);
->leftJoin('invoices', 'invoices.id', '=', 'payments.invoice_id')
->leftJoin('clients', 'clients.id', '=', 'invoices.client_id')
->where('payments.account_id', '=', $accountId)
->where('clients.is_deleted', '=', false)
->where('invoices.is_deleted', '=', false)
->whereNotIn('payments.payment_status_id', [PAYMENT_STATUS_VOIDED, PAYMENT_STATUS_FAILED]);
if (!$viewAll){
$paidToDate = $paidToDate->where('clients.user_id', '=', $userId);
$paidToDate->where('invoices.user_id', '=', $userId);
}
return $paidToDate->groupBy('accounts.id')
->groupBy(DB::raw('CASE WHEN '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' IS NULL THEN CASE WHEN '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' IS NULL THEN 1 ELSE '.DB::getQueryGrammar()->wrap('accounts.currency_id', true).' END ELSE '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' END'))
if ($account->financial_year_start) {
$yearStart = str_replace('2000', date('Y'), $account->financial_year_start);
$paidToDate->where('payments.payment_date', '>=', $yearStart);
}
return $paidToDate->groupBy('payments.account_id')
->groupBy(DB::raw('CASE WHEN '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' IS NULL THEN '.($account->currency_id ?: DEFAULT_CURRENCY).' ELSE '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' END'))
->get();
}
public function averages($accountId, $userId, $viewAll)
public function averages($account, $userId, $viewAll)
{
$accountId = $account->id;
$select = DB::raw(
'AVG('.DB::getQueryGrammar()->wrap('invoices.amount', true).') as invoice_avg, '
.DB::getQueryGrammar()->wrap('clients.currency_id', true).' as currency_id'
@ -213,7 +223,12 @@ class DashboardRepository
->where('invoices.is_recurring', '=', false);
if (!$viewAll){
$averageInvoice = $averageInvoice->where('invoices.user_id', '=', $userId);
$averageInvoice->where('invoices.user_id', '=', $userId);
}
if ($account->financial_year_start) {
$yearStart = str_replace('2000', date('Y'), $account->financial_year_start);
$averageInvoice->where('invoices.invoice_date', '>=', $yearStart);
}
return $averageInvoice->groupBy('accounts.id')

View File

@ -1369,7 +1369,7 @@ $LANG = array(
'failed_remove_payment_method' => 'Failed to remove the payment method',
'gateway_exists' => 'This gateway already exists',
'manual_entry' => 'Manual entry',
'start_of_week' => 'First day of the week',
'start_of_week' => 'First Day of the Week',
// Frequencies
'freq_weekly' => 'Weekly',
@ -2174,6 +2174,7 @@ $LANG = array(
'invalid_white_label_license' => 'The white label license is not valid',
'created_by' => 'Created by :name',
'modules' => 'Modules',
'financial_year_start' => 'First Month of the Year',
);

View File

@ -42,7 +42,7 @@
{!! Former::select('language_id')->addOption('','')
->fromQuery($languages, 'name', 'id')
->help(trans('texts.translate_app', ['link' => link_to(TRANSIFEX_URL, 'Transifex.com', ['target' => '_blank'])])) !!}
<br/>
<br/>&nbsp;<br/>
{!! Former::select('timezone_id')->addOption('','')
->fromQuery($timezones, 'location', 'id') !!}
@ -50,9 +50,16 @@
->fromQuery($dateFormats) !!}
{!! Former::select('datetime_format_id')->addOption('','')
->fromQuery($datetimeFormats) !!}
{!! Former::checkbox('military_time')->text(trans('texts.enable')) !!}
<br/>&nbsp;<br/>
{!! Former::select('start_of_week')->addOption('','')
->fromQuery($weekdays) !!}
{!! Former::checkbox('military_time')->text(trans('texts.enable')) !!}
{!! Former::select('financial_year_start')
->addOption('','')
->options($months) !!}
</div>
</div>