1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Bug fixes

This commit is contained in:
Joshua Dwire 2016-03-17 10:11:14 -04:00
parent 2cd7228074
commit ec1bc6f2cf
6 changed files with 50 additions and 22 deletions

View File

@ -11,7 +11,9 @@ class DashboardController extends BaseController
{ {
public function index() public function index()
{ {
$view_all = !Auth::user()->hasPermission('view_all');
$user_id = Auth::user()->id;
// total_income, billed_clients, invoice_sent and active_clients // total_income, billed_clients, invoice_sent and active_clients
$select = DB::raw('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, SUM(CASE WHEN invoices.invoice_status_id >= '.INVOICE_STATUS_SENT.' THEN 1 ELSE 0 END) invoices_sent,
@ -24,8 +26,19 @@ class DashboardController extends BaseController
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false)
->where('invoices.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false)
->where('invoices.is_recurring', '=', false) ->where('invoices.is_recurring', '=', false)
->where('invoices.is_quote', '=', false) ->where('invoices.is_quote', '=', false);
->groupBy('accounts.id')
if(!$view_all){
$metrics = $metrics->where(function($query) use($user_id){
$query->where('invoices.user_id', '=', $user_id);
$query->orwhere(function($query) use($user_id){
$query->where('invoices.user_id', '=', null);
$query->where('clients.user_id', '=', $user_id);
});
});
}
$metrics = $metrics->groupBy('accounts.id')
->first(); ->first();
$select = DB::raw('SUM(clients.paid_to_date) as value, clients.currency_id as currency_id'); $select = DB::raw('SUM(clients.paid_to_date) as value, clients.currency_id as currency_id');
@ -33,8 +46,13 @@ class DashboardController extends BaseController
->select($select) ->select($select)
->leftJoin('clients', 'accounts.id', '=', 'clients.account_id') ->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')
->where('accounts.id', '=', Auth::user()->account_id) ->where('accounts.id', '=', Auth::user()->account_id)
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false);
->groupBy('accounts.id')
if(!$view_all){
$paidToDate = $paidToDate->where('clients.user_id', '=', $user_id);
}
$paidToDate = $paidToDate->groupBy('accounts.id')
->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END')) ->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END'))
->get(); ->get();
@ -47,8 +65,13 @@ class DashboardController extends BaseController
->where('clients.is_deleted', '=', false) ->where('clients.is_deleted', '=', false)
->where('invoices.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false)
->where('invoices.is_quote', '=', false) ->where('invoices.is_quote', '=', false)
->where('invoices.is_recurring', '=', false) ->where('invoices.is_recurring', '=', false);
->groupBy('accounts.id')
if(!$view_all){
$averageInvoice = $averageInvoice->where('invoices.user_id', '=', $user_id);
}
$averageInvoice = $averageInvoice->groupBy('accounts.id')
->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END')) ->groupBy(DB::raw('CASE WHEN clients.currency_id IS NULL THEN CASE WHEN accounts.currency_id IS NULL THEN 1 ELSE accounts.currency_id END ELSE clients.currency_id END'))
->get(); ->get();
@ -65,8 +88,7 @@ class DashboardController extends BaseController
$activities = Activity::where('activities.account_id', '=', Auth::user()->account_id) $activities = Activity::where('activities.account_id', '=', Auth::user()->account_id)
->where('activities.activity_type_id', '>', 0); ->where('activities.activity_type_id', '>', 0);
if(!Auth::user()->hasPermission('view_all')){ if(!$view_all){
$user_id = Auth::user()->id;
$activities = $activities->where('activities.user_id', '=', $user_id); $activities = $activities->where('activities.user_id', '=', $user_id);
} }
@ -89,8 +111,7 @@ class DashboardController extends BaseController
->where('contacts.is_primary', '=', true) ->where('contacts.is_primary', '=', true)
->where('invoices.due_date', '<', date('Y-m-d')); ->where('invoices.due_date', '<', date('Y-m-d'));
if(!Auth::user()->hasPermission('view_all')){ if(!$view_all){
$user_id = Auth::user()->id;
$pastDue = $pastDue->where('invoices.user_id', '=', $user_id); $pastDue = $pastDue->where('invoices.user_id', '=', $user_id);
} }
@ -114,8 +135,7 @@ class DashboardController extends BaseController
->where('invoices.due_date', '>=', date('Y-m-d')) ->where('invoices.due_date', '>=', date('Y-m-d'))
->orderBy('invoices.due_date', 'asc'); ->orderBy('invoices.due_date', 'asc');
if(!Auth::user()->hasPermission('view_all')){ if(!$view_all){
$user_id = Auth::user()->id;
$upcoming = $upcoming->where('invoices.user_id', '=', $user_id); $upcoming = $upcoming->where('invoices.user_id', '=', $user_id);
} }
@ -134,8 +154,7 @@ class DashboardController extends BaseController
->where('contacts.deleted_at', '=', null) ->where('contacts.deleted_at', '=', null)
->where('contacts.is_primary', '=', true); ->where('contacts.is_primary', '=', true);
if(!Auth::user()->hasPermission('view_all')){ if(!$view_all){
$user_id = Auth::user()->id;
$payments = $payments->where('payments.user_id', '=', $user_id); $payments = $payments->where('payments.user_id', '=', $user_id);
} }

View File

@ -165,6 +165,10 @@ class InvoiceController extends BaseController
$lastSent = ($invoice->is_recurring && $invoice->last_sent_date) ? $invoice->recurring_invoices->last() : null; $lastSent = ($invoice->is_recurring && $invoice->last_sent_date) ? $invoice->recurring_invoices->last() : null;
if(!Auth::user()->hasPermission('view_all')){
$clients = $clients->where('clients.user_id', '=', Auth::user()->id);
}
$data = array( $data = array(
'clients' => $clients->get(), 'clients' => $clients->get(),
'entityType' => $entityType, 'entityType' => $entityType,
@ -227,8 +231,13 @@ class InvoiceController extends BaseController
$invoice = $account->createInvoice($entityType, $clientId); $invoice = $account->createInvoice($entityType, $clientId);
$invoice->public_id = 0; $invoice->public_id = 0;
$clients = Client::scope()->with('contacts', 'country')->orderBy('name');
if(!Auth::user()->hasPermission('view_all')){
$clients = $clients->where('clients.user_id', '=', Auth::user()->id);
}
$data = [ $data = [
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'clients' => $clients->get(),
'entityType' => $invoice->getEntityType(), 'entityType' => $invoice->getEntityType(),
'invoice' => $invoice, 'invoice' => $invoice,
'method' => 'POST', 'method' => 'POST',

View File

@ -184,9 +184,7 @@ class TaskController extends BaseController
{ {
$action = Input::get('action'); $action = Input::get('action');
$input = $request->input(); if(!$this->checkUpdatePermission(array('public_id'=>$publicId)/* Hacky, but works */, $response)){
if(!$this->checkUpdatePermission($input, $response)){
return $response; return $response;
} }

View File

@ -2,6 +2,7 @@
use Utils; use Utils;
use URL; use URL;
use Auth;
use App\Services\BaseService; use App\Services\BaseService;
use App\Models\Client; use App\Models\Client;
use App\Models\Payment; use App\Models\Payment;
@ -34,7 +35,7 @@ class CreditService extends BaseService
$query = $this->creditRepo->find($clientPublicId, $search); $query = $this->creditRepo->find($clientPublicId, $search);
if(!Utils::hasPermission('view_all')){ if(!Utils::hasPermission('view_all')){
$query->where('expenses.user_id', '=', Auth::user()->id); $query->where('credits.user_id', '=', Auth::user()->id);
} }
return $this->createDatatable(ENTITY_CREDIT, $query, !$clientPublicId); return $this->createDatatable(ENTITY_CREDIT, $query, !$clientPublicId);

View File

@ -74,8 +74,8 @@
</div> </div>
<div style="display:none"> <div style="display:none">
@endif @endif
{!! Former::select('client')->addOption('', '')->data_bind("dropdown: client")->addClass('client-input')->addGroupClass('client_select closer-row') !!} {!! Former::select('client')->addOption('', '')->data_bind("dropdown: client")->addClass('client-input')->addGroupClass('client_select closer-row') !!}
<div class="form-group" style="margin-bottom: 8px"> <div class="form-group" style="margin-bottom: 8px">
<div class="col-lg-8 col-sm-8 col-lg-offset-4 col-sm-offset-4"> <div class="col-lg-8 col-sm-8 col-lg-offset-4 col-sm-offset-4">

View File

@ -65,6 +65,7 @@
$('#permissions_view_all').prop('disabled', adminChecked); $('#permissions_view_all').prop('disabled', adminChecked);
$('#permissions_create_all').prop('disabled', adminChecked); $('#permissions_create_all').prop('disabled', adminChecked);
$('#permissions_edit_all').prop('disabled', adminChecked || !viewChecked); $('#permissions_edit_all').prop('disabled', adminChecked || !viewChecked);
if(!viewChecked)$('#permissions_edit_all').prop('checked',false)
} }
fixCheckboxes(); fixCheckboxes();
@stop @stop