diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index f07037142b22..2c9d38196155 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -5,10 +5,10 @@ class DashboardController extends \BaseController { public function index() { // total_income, billed_clients, invoice_sent and active_clients - $select = DB::raw('SUM(DISTINCT clients.paid_to_date) total_income, - COUNT(DISTINCT CASE WHEN invoices.id IS NOT NULL THEN clients.id ELSE null END) billed_clients, + $select = DB::raw('COUNT(DISTINCT CASE WHEN invoices.id IS NOT NULL THEN clients.id ELSE null END) billed_clients, SUM(CASE WHEN invoices.invoice_status_id >= '.INVOICE_STATUS_SENT.' THEN 1 ELSE 0 END) invoices_sent, - COUNT(DISTINCT clients.id) active_clients'); + COUNT(DISTINCT clients.id) active_clients, + AVG(invoices.amount) as invoice_avg'); $metrics = DB::table('accounts') ->select($select) @@ -19,27 +19,35 @@ class DashboardController extends \BaseController { ->groupBy('accounts.id') ->first(); - $invoiceAvg = DB::table('invoices') - ->where('invoices.account_id', '=', Auth::user()->account_id) - ->where('invoices.deleted_at', '=', null) - ->avg('amount'); + $select = DB::raw('SUM(clients.paid_to_date) value'); + + $totalIncome = DB::table('accounts') + ->select($select) + ->leftJoin('clients', 'accounts.id', '=', 'clients.account_id') + ->where('accounts.id', '=', Auth::user()->account_id) + ->where('clients.deleted_at', '=', null) + ->groupBy('accounts.id') + ->first(); - $activities = Activity::where('activities.account_id', '=', Auth::user()->account_id) ->orderBy('created_at', 'desc')->take(6)->get(); - $pastDue = Invoice::scope()->where('due_date', '<', date('Y-m-d')) + $pastDue = Invoice::scope() + ->where('due_date', '<', date('Y-m-d')) + ->where('balance', '>', 0) ->orderBy('due_date', 'asc')->take(6)->get(); - $upcoming = Invoice::scope()->where('due_date', '>', date('Y-m-d')) + $upcoming = Invoice::scope() + ->where('due_date', '>', date('Y-m-d')) + ->where('balance', '>', 0) ->orderBy('due_date', 'asc')->take(6)->get(); $data = [ - 'totalIncome' => Utils::formatMoney($metrics->total_income, Session::get(SESSION_CURRENCY)), + 'totalIncome' => Utils::formatMoney($totalIncome->value, Session::get(SESSION_CURRENCY)), 'billedClients' => $metrics->billed_clients, 'invoicesSent' => $metrics->invoices_sent, 'activeClients' => $metrics->active_clients, - 'invoiceAvg' => Utils::formatMoney($invoiceAvg, Session::get(SESSION_CURRENCY)), + 'invoiceAvg' => Utils::formatMoney($metrics->invoice_avg, Session::get(SESSION_CURRENCY)), 'activities' => $activities, 'pastDue' => $pastDue, 'upcoming' => $upcoming diff --git a/app/views/credits/edit.blade.php b/app/views/credits/edit.blade.php index 938ddad253f7..b55a2038b191 100755 --- a/app/views/credits/edit.blade.php +++ b/app/views/credits/edit.blade.php @@ -18,7 +18,7 @@ {{ Former::select('client')->addOption('', '')->addGroupClass('client-select') }} {{ Former::text('amount') }} - {{ Former::text('credit_date')->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }} + {{ Former::text('credit_date')->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }} {{-- Former::select('currency_id')->addOption('','')->label('Currency') ->fromQuery($currencies, 'name', 'id')->select(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY)) --}} {{ Former::textarea('private_notes') }} diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index af3e090458c1..dbc224c04f30 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -62,13 +62,17 @@
- {{ Former::text('invoice_date')->data_bind("datePicker: invoice_date, valueUpdate: 'afterkeydown'")->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }} - {{ Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'")->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }} + {{ Former::text('invoice_date')->data_bind("datePicker: invoice_date, valueUpdate: 'afterkeydown'") + ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }} + {{ Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'") + ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }}
{{ Former::select('frequency_id')->label('How often')->options($frequencies)->data_bind("value: frequency_id") }} - {{ Former::text('start_date')->data_bind("datePicker: start_date, valueUpdate: 'afterkeydown'")->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }} - {{ Former::text('end_date')->data_bind("datePicker: end_date, valueUpdate: 'afterkeydown'")->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }} + {{ Former::text('start_date')->data_bind("datePicker: start_date, valueUpdate: 'afterkeydown'") + ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }} + {{ Former::text('end_date')->data_bind("datePicker: end_date, valueUpdate: 'afterkeydown'") + ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }}
@if ($invoice && $invoice->recurring_invoice_id)
@@ -76,7 +80,7 @@
@else
- {{ Former::checkbox('recurring')->text('Enable | Learn more')->data_bind("checked: is_recurring") + {{ Former::checkbox('recurring')->text('Enable    Learn more')->data_bind("checked: is_recurring") ->inlineHelp($invoice && $invoice->last_sent_date ? 'Last invoice sent ' . Utils::dateToString($invoice->last_sent_date) : '') }}
@endif @@ -92,7 +96,7 @@
@@ -118,7 +122,7 @@ - + @@ -137,10 +141,10 @@ - - + +
- +