From d89dc2e8271f001617b5f45dc68eeb07f329be36 Mon Sep 17 00:00:00 2001 From: steenrabol Date: Fri, 8 Jan 2016 19:01:00 +0100 Subject: [PATCH] Expenses --- app/Events/ExpenseWasArchived.php | 6 +- app/Events/ExpenseWasCreated.php | 5 +- app/Events/ExpenseWasUpdated.php | 21 +++ app/Http/Controllers/DashboardController.php | 8 ++ .../Controllers/ExpenseActivityController.php | 27 ++++ app/Http/Controllers/ExpenseController.php | 79 ++++++++++-- app/Http/Controllers/VendorController.php | 3 +- app/Http/Requests/UpdateExpenseRequest.php | 2 + app/Http/routes.php | 2 + app/Listeners/ExpenseActivityListener.php | 57 ++++++++ app/Listeners/VendorActivityListener.php | 8 +- app/Models/Expense.php | 23 +++- app/Models/ExpenseActivity.php | 7 +- app/Models/Vendor.php | 46 ++----- .../ExpenseActivityRepository.php | 35 ++--- app/Ninja/Repositories/ExpenseRepository.php | 87 ++++++------- app/Services/ExpenseActivityService.php | 62 +++++++++ app/Services/ExpenseService.php | 57 +++++--- ...016_01_06_155001_create_expenses_table.php | 4 +- resources/lang/en/texts.php | 15 +++ resources/views/dashboard.blade.php | 7 +- resources/views/expenses/edit.blade.php | 82 ++++++++++++ resources/views/expenses/show.blade.php | 122 ++++++++++++++++++ 23 files changed, 610 insertions(+), 155 deletions(-) create mode 100644 app/Events/ExpenseWasUpdated.php create mode 100644 app/Http/Controllers/ExpenseActivityController.php create mode 100644 app/Listeners/ExpenseActivityListener.php create mode 100644 app/Services/ExpenseActivityService.php create mode 100644 resources/views/expenses/edit.blade.php create mode 100644 resources/views/expenses/show.blade.php diff --git a/app/Events/ExpenseWasArchived.php b/app/Events/ExpenseWasArchived.php index fe27998d29c4..c993d5e09632 100644 --- a/app/Events/ExpenseWasArchived.php +++ b/app/Events/ExpenseWasArchived.php @@ -1,12 +1,10 @@ expense = $expense; + } +} diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 847afbf7d574..cbf04ef79099 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -7,6 +7,7 @@ use App\Models\Activity; use App\Models\Invoice; use App\Models\Payment; use App\Models\VendorActivity; +use App\Models\ExpenseActivity; class DashboardController extends BaseController { @@ -76,6 +77,12 @@ class DashboardController extends BaseController ->take(50) ->get(); + $expenseactivities = ExpenseActivity::where('expense_activities.account_id', '=', Auth::user()->account_id) + ->where('activity_type_id', '>', 0) + ->orderBy('created_at', 'desc') + ->take(50) + ->get(); + $pastDue = DB::table('invoices') ->leftJoin('clients', 'clients.id', '=', 'invoices.client_id') ->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id') @@ -150,6 +157,7 @@ class DashboardController extends BaseController 'title' => trans('texts.dashboard'), 'hasQuotes' => $hasQuotes, 'vendoractivities' => $vendoractivities, + 'expenseactivities' => $expenseactivities, ]; return View::make('dashboard', $data); diff --git a/app/Http/Controllers/ExpenseActivityController.php b/app/Http/Controllers/ExpenseActivityController.php new file mode 100644 index 000000000000..0993123129c5 --- /dev/null +++ b/app/Http/Controllers/ExpenseActivityController.php @@ -0,0 +1,27 @@ +activityService = $activityService; + } + + public function getDatatable($vendorPublicId) + { + return $this->activityService->getDatatable($vendorPublicId); + } +} diff --git a/app/Http/Controllers/ExpenseController.php b/app/Http/Controllers/ExpenseController.php index 72dc2a4073b7..033be0743117 100644 --- a/app/Http/Controllers/ExpenseController.php +++ b/app/Http/Controllers/ExpenseController.php @@ -1,5 +1,7 @@ ENTITY_EXPENSE, 'title' => trans('texts.expenses'), - 'sortCol' => '4', + 'sortCol' => '1', 'columns' => Utils::trans([ - 'checkbox', 'vendor', 'expense_amount', - 'expense_balance', 'expense_date', - 'private_notes', 'public_notes', - '' + 'is_invoiced', + 'should_be_invoiced', + 'expense' ]), )); } - public function getDatatable($vendorPublicId = null) + public function getDatatable($expensePublicId = null) { - return $this->expenseService->getDatatable($vendorPublicId, Input::get('sSearch')); + return $this->expenseService->getDatatable($expensePublicId, Input::get('sSearch')); } public function create($vendorPublicId = 0) { - $vendor = Vendor::scope($vendorPublicId)->with('vendorcontacts')->firstOrFail(); + if($vendorPublicId != 0) { + $vendor = Vendor::scope($vendorPublicId)->with('vendorcontacts')->firstOrFail(); + } else { + $vendor = null; + } $data = array( 'vendorPublicId' => Input::old('vendor') ? Input::old('vendor') : $vendorPublicId, 'expense' => null, 'method' => 'POST', 'url' => 'expenses', 'title' => trans('texts.new_expense'), - 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), + 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), + 'vendor' => $vendor, ); $data = array_merge($data, self::getViewModel()); @@ -86,11 +94,35 @@ class ExpenseController extends BaseController 'method' => 'PUT', 'url' => 'expenses/'.$publicId, 'title' => 'Edit Expense', - 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), ); + 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), + 'vendorPublicId' => $expense->vendor_id); - return View::make('expense.edit', $data); + $data = array_merge($data, self::getViewModel()); + + if (Auth::user()->account->isNinjaAccount()) { + if ($account = Account::whereId($client->public_id)->first()) { + $data['proPlanPaid'] = $account['pro_plan_paid']; + } + } + + return View::make('expenses.edit', $data); } + /** + * Update the specified resource in storage. + * + * @param int $id + * @return Response + */ + public function update(UpdateExpenseRequest $request) + { + $client = $this->expenseRepo->save($request->input()); + + Session::flash('message', trans('texts.updated_expense')); + + return redirect()->to('expenses'); + } + public function store(CreateExpenseRequest $request) { $expense = $this->expenseRepo->save($request->input()); @@ -129,5 +161,28 @@ class ExpenseController extends BaseController 'customLabel2' => Auth::user()->account->custom_vendor_label2, ]; } - + + public function show($publicId) + { + $expense = Expense::withTrashed()->scope($publicId)->firstOrFail(); + + if($expense) { + Utils::trackViewed($expense->getDisplayName(), 'expense'); + } + + $actionLinks = [ + ['label' => trans('texts.new_expense'), 'url' => '/expenses/create/'] + ]; + + $data = array( + 'actionLinks' => $actionLinks, + 'showBreadcrumbs' => false, + 'expense' => $expense, + 'credit' =>0, + 'vendor' => $expense->vendor, + 'title' => trans('texts.view_expense',['expense' => $expense->public_id]), + ); + + return View::make('expenses.show', $data); + } } diff --git a/app/Http/Controllers/VendorController.php b/app/Http/Controllers/VendorController.php index 94bd11768390..7fac33b1f840 100644 --- a/app/Http/Controllers/VendorController.php +++ b/app/Http/Controllers/VendorController.php @@ -56,7 +56,6 @@ class VendorController extends BaseController 'contact', 'email', 'date_created', - //'last_login', 'balance', '' ]), @@ -94,7 +93,7 @@ class VendorController extends BaseController Utils::trackViewed($vendor->getDisplayName(), 'vendor'); $actionLinks = [ - ['label' => trans('texts.new_expense'), 'url' => '/expenses/create/'.$vendor->public_id] + ['label' => trans('texts.new_vendor'), 'url' => '/vendors/create/'.$vendor->public_id] ]; $data = array( diff --git a/app/Http/Requests/UpdateExpenseRequest.php b/app/Http/Requests/UpdateExpenseRequest.php index 08555aaaaad4..9170e9df02ab 100644 --- a/app/Http/Requests/UpdateExpenseRequest.php +++ b/app/Http/Requests/UpdateExpenseRequest.php @@ -25,6 +25,8 @@ class UpdateExpenseRequest extends Request { return [ 'amount' => 'required|positive', + 'public_notes' => 'required', + 'expense_date' => 'required', ]; } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 707aacff12e9..5df598507212 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -283,8 +283,10 @@ if (!defined('CONTACT_EMAIL')) { define('ENTITY_PRODUCT', 'product'); define('ENTITY_ACTIVITY', 'activity'); define('ENTITY_VENDOR','vendor'); + define('ENTITY_VENDOR_ACTIVITY','vendor_activity'); define('ENTITY_EXPENSE', 'expense'); define('ENTITY_PAYMENT_TERM','payment_term'); + define('ENTITY_EXPENSE_ACTIVITY','expense_activity'); define('PERSON_CONTACT', 'contact'); define('PERSON_USER', 'user'); diff --git a/app/Listeners/ExpenseActivityListener.php b/app/Listeners/ExpenseActivityListener.php new file mode 100644 index 000000000000..5e3cf1d9e705 --- /dev/null +++ b/app/Listeners/ExpenseActivityListener.php @@ -0,0 +1,57 @@ +activityRepo = $activityRepo; + } + + // Expenses + public function createdExpense(ExpenseWasCreated $event) + { + $this->activityRepo->create( + $event->expense, + ACTIVITY_TYPE_CREATE_EXPENSE + ); + } + + public function deletedExpense(ExpenseWasDeleted $event) + { + $this->activityRepo->create( + $event->expense, + ACTIVITY_TYPE_DELETE_EXPENSE + ); + } + + public function archivedExpense(ExpenseWasArchived $event) + { + /* + if ($event->client->is_deleted) { + return; + } + */ + + $this->activityRepo->create( + $event->expense, + ACTIVITY_TYPE_ARCHIVE_EXPENSE + ); + } + + public function restoredExpense(ExpenseWasRestored $event) + { + $this->activityRepo->create( + $event->expense, + ACTIVITY_TYPE_RESTORE_EXPENSE + ); + } +} diff --git a/app/Listeners/VendorActivityListener.php b/app/Listeners/VendorActivityListener.php index 58b3725ec922..181b50feb8bb 100644 --- a/app/Listeners/VendorActivityListener.php +++ b/app/Listeners/VendorActivityListener.php @@ -29,19 +29,19 @@ class VendorActivityListener { $this->activityRepo->create( $event->vendor, - ACTIVITY_TYPE_DELETE_CLIENT + ACTIVITY_TYPE_DELETE_VENDOR ); } public function archivedVendor(VendorWasArchived $event) { - if ($event->client->is_deleted) { + if ($event->vendor->is_deleted) { return; } $this->activityRepo->create( $event->vendor, - ACTIVITY_TYPE_ARCHIVE_CLIENT + ACTIVITY_TYPE_ARCHIVE_VENDOR ); } @@ -49,7 +49,7 @@ class VendorActivityListener { $this->activityRepo->create( $event->vendor, - ACTIVITY_TYPE_RESTORE_CLIENT + ACTIVITY_TYPE_RESTORE_VENDOR ); } } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 675ad96bcbed..a666f558cf0b 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -3,6 +3,7 @@ use Laracasts\Presenter\PresentableTrait; use Illuminate\Database\Eloquent\SoftDeletes; use App\Events\ExpenseWasCreated; +use App\Events\ExpenseWasUpdated; class Expense extends EntityModel { @@ -13,6 +14,13 @@ class Expense extends EntityModel protected $dates = ['deleted_at']; protected $presenter = 'App\Ninja\Presenters\ExpensePresenter'; + protected $fillable = [ + 'amount', + 'amount_cur', + 'exchange_rate', + 'private_notes', + 'public_notes', + ]; public function account() { return $this->belongsTo('App\Models\Account'); @@ -30,9 +38,22 @@ class Expense extends EntityModel public function getName() { - return ''; + if($this->expense_number) + return $this->expense_number; + + return $this->public_id; + } + + public function getDisplayName() + { + return $this->getName(); } + public function getRoute() + { + return "/expenses/{$this->public_id}"; + } + public function getEntityType() { return ENTITY_EXPENSE; diff --git a/app/Models/ExpenseActivity.php b/app/Models/ExpenseActivity.php index ddd23ab13e75..bd72098518c1 100644 --- a/app/Models/ExpenseActivity.php +++ b/app/Models/ExpenseActivity.php @@ -46,13 +46,12 @@ class ExpenseActivity extends Eloquent { $isSystem = $this->is_system; $expense = $this->expense; - if($expense) { - $route = link_to($expense->getRoute(), $vendor->getDisplayName()); + if($expense) + { + $route = link_to($expense->getRoute(), $expense->getDisplayName()); } else { $route ='no expense id'; } - - $data = [ 'expense' => $route, diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 690c34eecb65..c228c636011b 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -8,16 +8,14 @@ use App\Events\VendorWasUpdated; use Laracasts\Presenter\PresentableTrait; use Illuminate\Database\Eloquent\SoftDeletes; -class Vendor extends EntityModel { - +class Vendor extends EntityModel +{ use PresentableTrait; use SoftDeletes; - protected $presenter = 'App\Ninja\Presenters\VendorPresenter'; - - protected $dates = ['deleted_at']; - - protected $fillable = [ + protected $presenter = 'App\Ninja\Presenters\VendorPresenter'; + protected $dates = ['deleted_at']; + protected $fillable = [ 'name', 'id_number', 'vat_number', @@ -39,15 +37,15 @@ class Vendor extends EntityModel { 'website', ]; - public static $fieldName = 'name'; - public static $fieldPhone = 'work_phone'; - public static $fieldAddress1 = 'address1'; - public static $fieldAddress2 = 'address2'; - public static $fieldCity = 'city'; - public static $fieldState = 'state'; - public static $fieldPostalCode = 'postal_code'; - public static $fieldNotes = 'notes'; - public static $fieldCountry = 'country'; + public static $fieldName = 'name'; + public static $fieldPhone = 'work_phone'; + public static $fieldAddress1 = 'address1'; + public static $fieldAddress2 = 'address2'; + public static $fieldCity = 'city'; + public static $fieldState = 'state'; + public static $fieldPostalCode = 'postal_code'; + public static $fieldNotes = 'notes'; + public static $fieldCountry = 'country'; public static function getImportColumns() { @@ -165,13 +163,11 @@ class Vendor extends EntityModel { return "/vendors/{$this->public_id}"; } - public function getTotalCredit() { return 0; } - public function getName() { return $this->name; @@ -231,7 +227,6 @@ class Vendor extends EntityModel { } } - public function getGatewayToken() { $this->account->load('account_gateways'); @@ -269,19 +264,6 @@ class Vendor extends EntityModel { return $this->account->currency_id ?: DEFAULT_CURRENCY; } - - /* - public function getCounter($isQuote) - { - return $isQuote ? $this->quote_number_counter : $this->invoice_number_counter; - } - */ - - public function markLoggedIn() - { - //$this->last_login = Carbon::now()->toDateTimeString(); - $this->save(); - } } Vendor::creating(function ($vendor) { diff --git a/app/Ninja/Repositories/ExpenseActivityRepository.php b/app/Ninja/Repositories/ExpenseActivityRepository.php index db4fcdd8b777..e1baed24c857 100644 --- a/app/Ninja/Repositories/ExpenseActivityRepository.php +++ b/app/Ninja/Repositories/ExpenseActivityRepository.php @@ -46,36 +46,19 @@ class ExpenseActivityRepository } - public function findByVendorId($vendorId) + public function findByExpenseId($expenseId) { return DB::table('expense_activities') - ->join('accounts', 'accounts.id', '=', 'vendor_activities.account_id') - ->join('users', 'users.id', '=', 'vendor_activities.user_id') - ->join('vendors', 'vendors.id', '=', 'vendor_activities.vendor_id') - ->leftJoin('vendor_contacts', 'vendor_contacts.vendor_id', '=', 'vendors.id') - ->where('vendors.id', '=', $vendorId) - ->where('vendor_contacts.is_primary', '=', 1) - ->whereNull('vendor_contacts.deleted_at') - ->select( - DB::raw('COALESCE(vendors.currency_id, accounts.currency_id) currency_id'), - DB::raw('COALESCE(vendors.country_id, accounts.country_id) country_id'), - 'vendor_activities.id', - 'vendor_activities.created_at', - 'vendor_activities.contact_id', - 'vendor_activities.activity_type_id', - 'vendor_activities.is_system', - 'vendor_activities.balance', - 'vendor_activities.adjustment', + ->join('accounts', 'accounts.id', '=', 'expense_activities.account_id') + ->join('users', 'users.id', '=', 'expense_activities.user_id') + ->join('expenses','expenses.public_id', '=', 'expense_activities.expense_id') + ->where('expense_activities.expense_id', '=', $expenseId) + ->select('*', 'users.first_name as user_first_name', 'users.last_name as user_last_name', 'users.email as user_email', - 'vendors.name as vendor_name', - 'vendors.public_id as vendor_public_id', - 'vendor_contacts.id as contact', - 'vendor_contacts.first_name as first_name', - 'vendor_contacts.last_name as last_name', - 'vendor_contacts.email as email' - - ); + 'expenses.amount' + ); + } } \ No newline at end of file diff --git a/app/Ninja/Repositories/ExpenseRepository.php b/app/Ninja/Repositories/ExpenseRepository.php index 5d87fea4d9d1..e35b7ae208a5 100644 --- a/app/Ninja/Repositories/ExpenseRepository.php +++ b/app/Ninja/Repositories/ExpenseRepository.php @@ -5,6 +5,7 @@ use Utils; use App\Models\Expense; use App\Models\Vendor; use App\Ninja\Repositories\BaseRepository; +use Session; class ExpenseRepository extends BaseRepository { @@ -25,62 +26,37 @@ class ExpenseRepository extends BaseRepository public function find($filter = null) { - /* - $query = DB::table('expenses') - ->join('accounts', 'accounts.id', '=', 'expenses.account_id') - ->join('vendors', 'vendors.id', '=', 'expenses.vendor_id') - ->join('vendor_contacts', 'vendor_contacts.vendor_id', '=', 'vendors.id') - ->where('vendors.account_id', '=', \Auth::user()->account_id) - ->where('vendors.deleted_at', '=', null) - ->where('vendor_contacts.deleted_at', '=', null) - ->where('vendor_contacts.is_primary', '=', true) - ->select( - DB::raw('COALESCE(vendors.currency_id, accounts.currency_id) currency_id'), - DB::raw('COALESCE(vendors.country_id, accounts.country_id) country_id'), - 'expenses.public_id', - 'vendors.name as vendor_name', - 'vendors.public_id as vendor_public_id', - 'expenses.amount', - 'expenses.balance', - 'expenses.expense_date', - 'vendor_contacts.first_name', - 'vendor_contacts.last_name', - 'vendor_contacts.email', - 'expenses.private_notes', - 'expenses.deleted_at', - 'expenses.is_deleted' - ); - */ $accountid = \Auth::user()->account_id; $query = DB::table('expenses') ->join('accounts', 'accounts.id', '=', 'expenses.account_id') - //->join('vendors', 'vendors.id', '=', 'expenses.vendor_id') ->where('expenses.account_id', '=', $accountid) ->where('expenses.deleted_at', '=', null) - ->select( - //DB::raw('COALESCE(vendors.currency_id, accounts.currency_id) currency_id'), - //DB::raw('COALESCE(vendors.country_id, accounts.country_id) country_id'), - 'expenses.public_id', - //'vendors.name as vendor_name', - //'vendors.public_id as vendor_public_id', + ->select('expenses.account_id', 'expenses.amount', - 'expenses.balance', - 'expenses.expense_date', - 'expenses.public_notes', + 'expenses.amount_cur', + 'expenses.currency_id', 'expenses.deleted_at', - 'expenses.is_deleted' - ); - + 'expenses.exchange_rate', + 'expenses.expense_date', + 'expenses.id', + 'expenses.is_deleted', + 'expenses.is_invoiced', + 'expenses.private_notes', + 'expenses.public_id', + 'expenses.public_notes', + 'expenses.should_be_invoiced', + 'expenses.vendor_id'); + if (!\Session::get('show_trash:expense')) { $query->where('expenses.deleted_at', '=', null); } -/* + if ($filter) { $query->where(function ($query) use ($filter) { - $query->where('vendors.name', 'like', '%'.$filter.'%'); + $query->where('expenses.public_notes', 'like', '%'.$filter.'%'); }); } -*/ + return $query; } @@ -94,26 +70,43 @@ class ExpenseRepository extends BaseRepository $expense = Expense::createNew(); } - // First auto fille + // First auto fill $expense->fill($input); // We can have an expense without a vendor if(isset($input['vendor'])) { - $expense->vendor_id = Vendor::getPrivateId($input['vendor']); + $expense->vendor_id = $input['vendor']; } $expense->expense_date = Utils::toSqlDate($input['expense_date']); $expense->amount = Utils::parseFloat($input['amount']); - if(isset($input['amountcur'])) - $expense->amountcur = Utils::parseFloat($input['amountcur']); + if(isset($input['amount_cur'])) + $expense->amount_cur = Utils::parseFloat($input['amount_cur']); - $expense->balance = Utils::parseFloat($input['amount']); $expense->private_notes = trim($input['private_notes']); + $expense->public_notes = trim($input['public_notes']); if(isset($input['exchange_rate'])) $expense->exchange_rate = Utils::parseFloat($input['exchange_rate']); + else + $expense->exchange_rate = 100; + + if($expense->exchange_rate == 0) + $expense->exchange_rate = 100; + + // set the currency + if(isset($input['currency_id'])) + $expense->currency_id = $input['currency_id']; + + if($expense->currency_id == 0) + $expense->currency_id = Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY); + + // Calculate the amount cur + $expense->amount_cur = ($expense->amount / 100) * $expense->exchange_rate; + + $expense->should_be_invoiced = isset($input['should_be_invoiced']) ? true : false; $expense->save(); return $expense; diff --git a/app/Services/ExpenseActivityService.php b/app/Services/ExpenseActivityService.php new file mode 100644 index 000000000000..bd75aac7d26a --- /dev/null +++ b/app/Services/ExpenseActivityService.php @@ -0,0 +1,62 @@ +activityRepo = $activityRepo; + $this->datatableService = $datatableService; + } + + public function getDatatable($expensePublicId = null) + { + $expenseId = Expense::getPrivateId($expensePublicId); + + $query = $this->activityRepo->findByExpenseId($expenseId); + + return $this->createDatatable(ENTITY_EXPENSE_ACTIVITY, $query); + } + + protected function getDatatableColumns($entityType, $hideExpense) + { + return [ + [ + 'expense_activities.id', + function ($model) { + return Utils::timestampToDateTimeString(strtotime($model->created_at)); + } + ], + [ + 'activity_type_id', + function ($model) { + $data = [ + 'expense' => link_to('/expenses/' . $model->public_id, trans('texts.view_expense',['expense' => $model->public_id])), + 'user' => $model->is_system ? '' . trans('texts.system') . '' : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), + ]; + + return trans("texts.activity_{$model->activity_type_id}", $data); + } + ], + [ + 'amount', + function ($model) { + return Utils::formatMoney($model->amount); + } + ], + [ + 'expense_date', + function ($model) { + return Utils::fromSqlDate($model->expense_date); + } + ] + ]; + } +} \ No newline at end of file diff --git a/app/Services/ExpenseService.php b/app/Services/ExpenseService.php index f316ecaabc99..a9203d9338fb 100644 --- a/app/Services/ExpenseService.php +++ b/app/Services/ExpenseService.php @@ -1,5 +1,6 @@ vendor_public_id ? link_to("vendors/{$model->vendor_public_id}", Utils::getVendorDisplayName($model)) : ''; + [ + 'vendor_id', + function ($model) + { + if($model->vendor_id) { + + $vendors = DB::table('vendors')->where('public_id', '=',$model->vendor_id)->select('id', 'public_id','name')->get(); + // should only be one! + $vendor = $vendors[0]; + + if($vendor) { + return link_to("vendors/{$vendor->public_id}", $vendor->name); + } + return 'no vendor: ' . $model->vendor_id; + } else { + return 'No vendor:' ; + } }, - ! $hideClient - ],*/ + ], [ 'amount', function ($model) { - return Utils::formatMoney($model->amount, false, false) . ''; - } - ], - [ - 'balance', - function ($model) { - return Utils::formatMoney($model->balance, false, false); + return Utils::formatMoney($model->amount, false, false); } ], [ @@ -64,11 +71,29 @@ class ExpenseService extends BaseService } ], [ - 'private_public', + 'public_notes', function ($model) { - return $model->public_notes; + return $model->public_notes != null ? $model->public_notes : ''; } - ] + ], + [ + 'is_invoiced', + function ($model) { + return $model->is_invoiced ? trans('texts.expense_is_invoiced') : trans('texts.expense_is_not_invoiced'); + } + ], + [ + 'should_be_invoiced', + function ($model) { + return $model->should_be_invoiced ? trans('texts.yes') : trans('texts.no'); + } + ], + [ + 'public_id', + function($model) { + return link_to("expenses/{$model->public_id}", trans('texts.view_expense', ['expense' => $model->public_id])); + } + ] ]; } /* diff --git a/database/migrations/2016_01_06_155001_create_expenses_table.php b/database/migrations/2016_01_06_155001_create_expenses_table.php index 9a8a654f041a..95d538b3a69d 100644 --- a/database/migrations/2016_01_06_155001_create_expenses_table.php +++ b/database/migrations/2016_01_06_155001_create_expenses_table.php @@ -27,11 +27,9 @@ class CreateExpensesTable extends Migration $table->boolean('is_deleted')->default(false); $table->decimal('amount', 13, 2); - $table->decimal('amountcur', 13, 2); + $table->decimal('amount_cur', 13, 2); $table->decimal('exchange_rate', 13, 2); - $table->decimal('balance', 13, 2); $table->date('expense_date')->nullable(); - $table->string('expense_number')->nullable(); $table->text('private_notes'); $table->text('public_notes'); $table->integer('currency_id',false, true)->nullable(); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index be1067c43a3c..120f46d5d6a1 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1015,6 +1015,7 @@ return array( 'white_label_purchase_link' => 'Purchase a white label license', // Expense / vendor + 'expense' => 'Expense', 'expenses' => 'Expenses', 'new_expense' => 'Create expense', 'vendors' => 'Vendors', @@ -1032,6 +1033,20 @@ return array( 'expense_date' => 'Expense date', 'expense_exchange_rate_100' => 'The amount for 100 in company currency', 'expense_should_be_invoiced' => 'Should this expense be invoiced?', + 'public_notes' => 'Public notes', + 'expense_amount_in_cur' => 'Expense amount in curency', + 'is_invoiced' => 'Is invoiced', + 'expense_is_not_invoiced' => 'Expense not invoiced', + 'expense_is_invoiced' => 'Expense invoiced', + 'yes' => 'Yes', + 'no' => 'No', + 'should_be_invoiced' => 'Should be invoiced', + 'view_expense' => 'View expense # :expense', + 'edit_expense' => 'Edit expense', + 'archive_expense' => 'Archive expense', + 'delete_expense' => 'Delete expense', + 'view_expense_num' => 'Expense # :expense', + 'updated_expense' => 'Expense updated', // Payment terms 'num_days' => 'Number of days', diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index b3f1042509f8..d678aa53669f 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -90,7 +90,12 @@ {!! $activity->getMessage() !!} @endforeach - + @foreach ($expenseactivities as $activity) +
  • + {{ Utils::timestampToDateString(strtotime($activity->created_at)) }}: + {!! $activity->getMessage() !!} +
  • + @endforeach diff --git a/resources/views/expenses/edit.blade.php b/resources/views/expenses/edit.blade.php new file mode 100644 index 000000000000..031551717fc9 --- /dev/null +++ b/resources/views/expenses/edit.blade.php @@ -0,0 +1,82 @@ +@extends('header') + +@section('content') + + {!! Former::open($url)->addClass('col-md-10 col-md-offset-1 warn-on-exit')->method($method)->rules(array( + 'public_notes' => 'required', + 'amount' => 'required', + 'expense_date' => 'required', + )) !!} + + @if ($expense) + {!! Former::populate($expense) !!} + {!! Former::hidden('public_id') !!} + @endif + + +
    +
    + +
    +
    + {!! Former::select('vendor')->addOption('', '')->addGroupClass('client-select') !!} + {!! Former::text('expense_date') + ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT)) + ->addGroupClass('expense_date')->label(trans('texts.expense_date')) + ->append('') !!} + {!! Former::text('amount')->label(trans('texts.expense_amount')) !!} + {!! Former::text('amount_cur')->label(trans('texts.expense_amount_in_cur')) !!} + {!! Former::select('currency_id')->addOption('','') + ->placeholder($account->currency ? $account->currency->name : '') + ->fromQuery($currencies, 'name', 'id') !!} + {!! Former::text('exchange_rate')->append(trans('texts.expense_exchange_rate_100')) !!} + {!! Former::textarea('private_notes') !!} + {!! Former::textarea('public_notes') !!} + {!! Former::checkbox('should_be_invoiced') !!} +
    +
    +
    +
    + +
    + {!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(URL::to('/credits'))->appendIcon(Icon::create('remove-circle')) !!} + {!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!} +
    + + {!! Former::close() !!} + + +@stop \ No newline at end of file diff --git a/resources/views/expenses/show.blade.php b/resources/views/expenses/show.blade.php new file mode 100644 index 000000000000..f8d83d97350b --- /dev/null +++ b/resources/views/expenses/show.blade.php @@ -0,0 +1,122 @@ +@extends('header') + +@section('head') + @parent +@stop + +@section('content') +
    + {!! Former::open('expenses/bulk')->addClass('mainForm') !!} +
    + {!! Former::text('action') !!} + {!! Former::text('public_id')->value($expense->public_id) !!} +
    + + @if ($expense->trashed()) + {!! Button::primary(trans('texts.restore_expense'))->withAttributes(['onclick' => 'onRestoreClick()']) !!} + @else + {!! DropdownButton::normal(trans('texts.edit_expense')) + ->withAttributes(['class'=>'normalDropDown']) + ->withContents([ + ['label' => trans('texts.archive_expense'), 'url' => "javascript:onArchiveClick()"], + ['label' => trans('texts.delete_expense'), 'url' => "javascript:onDeleteClick()"], + ] + )->split() !!} + + {!! DropdownButton::primary(trans('texts.new_expense')) + ->withAttributes(['class'=>'primaryDropDown']) + ->withContents($actionLinks)->split() !!} + @endif + {!! Former::close() !!} + +
    + +

    {{ trans('texts.view_expense_num', ['expense' => $expense->public_id]) }}

    +
    +
    +
    + +
    +

    {{ trans('texts.details') }}

    + +

    {{ $expense->public_notes }}

    +
    + +
    +

    {{ trans('texts.standing') }} + + + + + + + + + + @if ($credit > 0) + + + + + @endif +
    {{ trans('texts.expense_date') }}{{ Utils::fromSqlDate($expense->expense_date) }}
    {{ trans('texts.expense_amount') }}{{ Utils::formatMoney($expense->amount) }}
    {{ trans('texts.expense_amount_cur') }}{{ Utils::formatMoney($$expense->amount_cur, $expense->curency_id) }}
    +

    +
    +
    +
    +
    + + + +
    +
    + {!! Datatable::table() + ->addColumn( + trans('texts.date'), + trans('texts.message'), + trans('texts.balance'), + trans('texts.adjustment')) + ->setUrl(url('api/expenseactivities/'. $expense->public_id)) + ->setCustomValues('entityType', 'activity') + ->setOptions('sPaginationType', 'bootstrap') + ->setOptions('bFilter', false) + ->setOptions('aaSorting', [['0', 'desc']]) + ->render('datatable') !!} +
    +
    + + + +@stop