mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Expenses
This commit is contained in:
parent
d8a501ed95
commit
d89dc2e827
@ -1,12 +1,10 @@
|
|||||||
<?php namespace App\Events;
|
<?php namespace App\Events;
|
||||||
|
|
||||||
use App\Events\Event;
|
use App\Events\Event;
|
||||||
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class ExpenseWasArchived extends Event {
|
class ExpenseWasArchived extends Event
|
||||||
|
{
|
||||||
// Expenses
|
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $expense;
|
public $expense;
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
<?php namespace App\Events;
|
<?php namespace App\Events;
|
||||||
|
|
||||||
use App\Events\Event;
|
use App\Events\Event;
|
||||||
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class ExpenseWasCreated extends Event {
|
class ExpenseWasCreated extends Event
|
||||||
// Expenses
|
{
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $expense;
|
public $expense;
|
||||||
|
21
app/Events/ExpenseWasUpdated.php
Normal file
21
app/Events/ExpenseWasUpdated.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php namespace App\Events;
|
||||||
|
|
||||||
|
use App\Events\Event;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class ExpenseWasUpdated extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
public $expense;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($expense)
|
||||||
|
{
|
||||||
|
$this->expense = $expense;
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ use App\Models\Activity;
|
|||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\VendorActivity;
|
use App\Models\VendorActivity;
|
||||||
|
use App\Models\ExpenseActivity;
|
||||||
|
|
||||||
class DashboardController extends BaseController
|
class DashboardController extends BaseController
|
||||||
{
|
{
|
||||||
@ -76,6 +77,12 @@ class DashboardController extends BaseController
|
|||||||
->take(50)
|
->take(50)
|
||||||
->get();
|
->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')
|
$pastDue = DB::table('invoices')
|
||||||
->leftJoin('clients', 'clients.id', '=', 'invoices.client_id')
|
->leftJoin('clients', 'clients.id', '=', 'invoices.client_id')
|
||||||
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
|
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||||
@ -150,6 +157,7 @@ class DashboardController extends BaseController
|
|||||||
'title' => trans('texts.dashboard'),
|
'title' => trans('texts.dashboard'),
|
||||||
'hasQuotes' => $hasQuotes,
|
'hasQuotes' => $hasQuotes,
|
||||||
'vendoractivities' => $vendoractivities,
|
'vendoractivities' => $vendoractivities,
|
||||||
|
'expenseactivities' => $expenseactivities,
|
||||||
];
|
];
|
||||||
|
|
||||||
return View::make('dashboard', $data);
|
return View::make('dashboard', $data);
|
||||||
|
27
app/Http/Controllers/ExpenseActivityController.php
Normal file
27
app/Http/Controllers/ExpenseActivityController.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php namespace App\Http\Controllers;
|
||||||
|
// vendor
|
||||||
|
use Auth;
|
||||||
|
use DB;
|
||||||
|
use Datatable;
|
||||||
|
use Utils;
|
||||||
|
use View;
|
||||||
|
use App\Models\Expense;
|
||||||
|
use App\Models\ExpenseActivity;
|
||||||
|
use App\Services\ExpenseActivityService;
|
||||||
|
|
||||||
|
class ExpenseActivityController extends BaseController
|
||||||
|
{
|
||||||
|
protected $activityService;
|
||||||
|
|
||||||
|
public function __construct(ExpenseActivityService $activityService)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->activityService = $activityService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDatatable($vendorPublicId)
|
||||||
|
{
|
||||||
|
return $this->activityService->getDatatable($vendorPublicId);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
<?php namespace App\Http\Controllers;
|
<?php namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Debugbar;
|
||||||
|
use DB;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Datatable;
|
use Datatable;
|
||||||
use Utils;
|
use Utils;
|
||||||
@ -11,9 +13,11 @@ use Session;
|
|||||||
use Redirect;
|
use Redirect;
|
||||||
use Cache;
|
use Cache;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
|
use App\Models\Expense;
|
||||||
use App\Services\ExpenseService;
|
use App\Services\ExpenseService;
|
||||||
use App\Ninja\Repositories\ExpenseRepository;
|
use App\Ninja\Repositories\ExpenseRepository;
|
||||||
use App\Http\Requests\CreateExpenseRequest;
|
use App\Http\Requests\CreateExpenseRequest;
|
||||||
|
use App\Http\Requests\UpdateExpenseRequest;
|
||||||
|
|
||||||
class ExpenseController extends BaseController
|
class ExpenseController extends BaseController
|
||||||
{
|
{
|
||||||
@ -39,35 +43,39 @@ class ExpenseController extends BaseController
|
|||||||
return View::make('list', array(
|
return View::make('list', array(
|
||||||
'entityType' => ENTITY_EXPENSE,
|
'entityType' => ENTITY_EXPENSE,
|
||||||
'title' => trans('texts.expenses'),
|
'title' => trans('texts.expenses'),
|
||||||
'sortCol' => '4',
|
'sortCol' => '1',
|
||||||
'columns' => Utils::trans([
|
'columns' => Utils::trans([
|
||||||
'checkbox',
|
|
||||||
'vendor',
|
'vendor',
|
||||||
'expense_amount',
|
'expense_amount',
|
||||||
'expense_balance',
|
|
||||||
'expense_date',
|
'expense_date',
|
||||||
'private_notes',
|
|
||||||
'public_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)
|
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(
|
$data = array(
|
||||||
'vendorPublicId' => Input::old('vendor') ? Input::old('vendor') : $vendorPublicId,
|
'vendorPublicId' => Input::old('vendor') ? Input::old('vendor') : $vendorPublicId,
|
||||||
'expense' => null,
|
'expense' => null,
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'url' => 'expenses',
|
'url' => 'expenses',
|
||||||
'title' => trans('texts.new_expense'),
|
'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());
|
$data = array_merge($data, self::getViewModel());
|
||||||
@ -86,11 +94,35 @@ class ExpenseController extends BaseController
|
|||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
'url' => 'expenses/'.$publicId,
|
'url' => 'expenses/'.$publicId,
|
||||||
'title' => 'Edit Expense',
|
'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)
|
public function store(CreateExpenseRequest $request)
|
||||||
{
|
{
|
||||||
$expense = $this->expenseRepo->save($request->input());
|
$expense = $this->expenseRepo->save($request->input());
|
||||||
@ -129,5 +161,28 @@ class ExpenseController extends BaseController
|
|||||||
'customLabel2' => Auth::user()->account->custom_vendor_label2,
|
'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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,6 @@ class VendorController extends BaseController
|
|||||||
'contact',
|
'contact',
|
||||||
'email',
|
'email',
|
||||||
'date_created',
|
'date_created',
|
||||||
//'last_login',
|
|
||||||
'balance',
|
'balance',
|
||||||
''
|
''
|
||||||
]),
|
]),
|
||||||
@ -94,7 +93,7 @@ class VendorController extends BaseController
|
|||||||
Utils::trackViewed($vendor->getDisplayName(), 'vendor');
|
Utils::trackViewed($vendor->getDisplayName(), 'vendor');
|
||||||
|
|
||||||
$actionLinks = [
|
$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(
|
$data = array(
|
||||||
|
@ -25,6 +25,8 @@ class UpdateExpenseRequest extends Request
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'amount' => 'required|positive',
|
'amount' => 'required|positive',
|
||||||
|
'public_notes' => 'required',
|
||||||
|
'expense_date' => 'required',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,8 +283,10 @@ if (!defined('CONTACT_EMAIL')) {
|
|||||||
define('ENTITY_PRODUCT', 'product');
|
define('ENTITY_PRODUCT', 'product');
|
||||||
define('ENTITY_ACTIVITY', 'activity');
|
define('ENTITY_ACTIVITY', 'activity');
|
||||||
define('ENTITY_VENDOR','vendor');
|
define('ENTITY_VENDOR','vendor');
|
||||||
|
define('ENTITY_VENDOR_ACTIVITY','vendor_activity');
|
||||||
define('ENTITY_EXPENSE', 'expense');
|
define('ENTITY_EXPENSE', 'expense');
|
||||||
define('ENTITY_PAYMENT_TERM','payment_term');
|
define('ENTITY_PAYMENT_TERM','payment_term');
|
||||||
|
define('ENTITY_EXPENSE_ACTIVITY','expense_activity');
|
||||||
|
|
||||||
define('PERSON_CONTACT', 'contact');
|
define('PERSON_CONTACT', 'contact');
|
||||||
define('PERSON_USER', 'user');
|
define('PERSON_USER', 'user');
|
||||||
|
57
app/Listeners/ExpenseActivityListener.php
Normal file
57
app/Listeners/ExpenseActivityListener.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php namespace app\Listeners;
|
||||||
|
|
||||||
|
use App\Events\ExpenseWasCreated;
|
||||||
|
use App\Events\ExpenseWasDeleted;
|
||||||
|
use App\Events\ExpenseWasArchived;
|
||||||
|
use App\Events\ExpenseWasRestored;
|
||||||
|
use App\Ninja\Repositories\ActivityRepository;
|
||||||
|
use App\Ninja\Repositories\ExpenseActivityRepository;
|
||||||
|
|
||||||
|
class ExpenseActivityListener
|
||||||
|
{
|
||||||
|
protected $activityRepo;
|
||||||
|
|
||||||
|
public function __construct(ExpenseActivityRepository $activityRepo)
|
||||||
|
{
|
||||||
|
$this->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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -29,19 +29,19 @@ class VendorActivityListener
|
|||||||
{
|
{
|
||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$event->vendor,
|
$event->vendor,
|
||||||
ACTIVITY_TYPE_DELETE_CLIENT
|
ACTIVITY_TYPE_DELETE_VENDOR
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function archivedVendor(VendorWasArchived $event)
|
public function archivedVendor(VendorWasArchived $event)
|
||||||
{
|
{
|
||||||
if ($event->client->is_deleted) {
|
if ($event->vendor->is_deleted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$event->vendor,
|
$event->vendor,
|
||||||
ACTIVITY_TYPE_ARCHIVE_CLIENT
|
ACTIVITY_TYPE_ARCHIVE_VENDOR
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ class VendorActivityListener
|
|||||||
{
|
{
|
||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$event->vendor,
|
$event->vendor,
|
||||||
ACTIVITY_TYPE_RESTORE_CLIENT
|
ACTIVITY_TYPE_RESTORE_VENDOR
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use Laracasts\Presenter\PresentableTrait;
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use App\Events\ExpenseWasCreated;
|
use App\Events\ExpenseWasCreated;
|
||||||
|
use App\Events\ExpenseWasUpdated;
|
||||||
|
|
||||||
class Expense extends EntityModel
|
class Expense extends EntityModel
|
||||||
{
|
{
|
||||||
@ -13,6 +14,13 @@ class Expense extends EntityModel
|
|||||||
protected $dates = ['deleted_at'];
|
protected $dates = ['deleted_at'];
|
||||||
protected $presenter = 'App\Ninja\Presenters\ExpensePresenter';
|
protected $presenter = 'App\Ninja\Presenters\ExpensePresenter';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'amount',
|
||||||
|
'amount_cur',
|
||||||
|
'exchange_rate',
|
||||||
|
'private_notes',
|
||||||
|
'public_notes',
|
||||||
|
];
|
||||||
public function account()
|
public function account()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Account');
|
return $this->belongsTo('App\Models\Account');
|
||||||
@ -30,9 +38,22 @@ class Expense extends EntityModel
|
|||||||
|
|
||||||
public function getName()
|
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()
|
public function getEntityType()
|
||||||
{
|
{
|
||||||
return ENTITY_EXPENSE;
|
return ENTITY_EXPENSE;
|
||||||
|
@ -46,13 +46,12 @@ class ExpenseActivity extends Eloquent {
|
|||||||
$isSystem = $this->is_system;
|
$isSystem = $this->is_system;
|
||||||
$expense = $this->expense;
|
$expense = $this->expense;
|
||||||
|
|
||||||
if($expense) {
|
if($expense)
|
||||||
$route = link_to($expense->getRoute(), $vendor->getDisplayName());
|
{
|
||||||
|
$route = link_to($expense->getRoute(), $expense->getDisplayName());
|
||||||
} else {
|
} else {
|
||||||
$route ='no expense id';
|
$route ='no expense id';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'expense' => $route,
|
'expense' => $route,
|
||||||
|
@ -8,16 +8,14 @@ use App\Events\VendorWasUpdated;
|
|||||||
use Laracasts\Presenter\PresentableTrait;
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
class Vendor extends EntityModel {
|
class Vendor extends EntityModel
|
||||||
|
{
|
||||||
use PresentableTrait;
|
use PresentableTrait;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $presenter = 'App\Ninja\Presenters\VendorPresenter';
|
protected $presenter = 'App\Ninja\Presenters\VendorPresenter';
|
||||||
|
protected $dates = ['deleted_at'];
|
||||||
protected $dates = ['deleted_at'];
|
protected $fillable = [
|
||||||
|
|
||||||
protected $fillable = [
|
|
||||||
'name',
|
'name',
|
||||||
'id_number',
|
'id_number',
|
||||||
'vat_number',
|
'vat_number',
|
||||||
@ -39,15 +37,15 @@ class Vendor extends EntityModel {
|
|||||||
'website',
|
'website',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static $fieldName = 'name';
|
public static $fieldName = 'name';
|
||||||
public static $fieldPhone = 'work_phone';
|
public static $fieldPhone = 'work_phone';
|
||||||
public static $fieldAddress1 = 'address1';
|
public static $fieldAddress1 = 'address1';
|
||||||
public static $fieldAddress2 = 'address2';
|
public static $fieldAddress2 = 'address2';
|
||||||
public static $fieldCity = 'city';
|
public static $fieldCity = 'city';
|
||||||
public static $fieldState = 'state';
|
public static $fieldState = 'state';
|
||||||
public static $fieldPostalCode = 'postal_code';
|
public static $fieldPostalCode = 'postal_code';
|
||||||
public static $fieldNotes = 'notes';
|
public static $fieldNotes = 'notes';
|
||||||
public static $fieldCountry = 'country';
|
public static $fieldCountry = 'country';
|
||||||
|
|
||||||
public static function getImportColumns()
|
public static function getImportColumns()
|
||||||
{
|
{
|
||||||
@ -165,13 +163,11 @@ class Vendor extends EntityModel {
|
|||||||
return "/vendors/{$this->public_id}";
|
return "/vendors/{$this->public_id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getTotalCredit()
|
public function getTotalCredit()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
@ -231,7 +227,6 @@ class Vendor extends EntityModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getGatewayToken()
|
public function getGatewayToken()
|
||||||
{
|
{
|
||||||
$this->account->load('account_gateways');
|
$this->account->load('account_gateways');
|
||||||
@ -269,19 +264,6 @@ class Vendor extends EntityModel {
|
|||||||
|
|
||||||
return $this->account->currency_id ?: DEFAULT_CURRENCY;
|
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) {
|
Vendor::creating(function ($vendor) {
|
||||||
|
@ -46,36 +46,19 @@ class ExpenseActivityRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function findByVendorId($vendorId)
|
public function findByExpenseId($expenseId)
|
||||||
{
|
{
|
||||||
return DB::table('expense_activities')
|
return DB::table('expense_activities')
|
||||||
->join('accounts', 'accounts.id', '=', 'vendor_activities.account_id')
|
->join('accounts', 'accounts.id', '=', 'expense_activities.account_id')
|
||||||
->join('users', 'users.id', '=', 'vendor_activities.user_id')
|
->join('users', 'users.id', '=', 'expense_activities.user_id')
|
||||||
->join('vendors', 'vendors.id', '=', 'vendor_activities.vendor_id')
|
->join('expenses','expenses.public_id', '=', 'expense_activities.expense_id')
|
||||||
->leftJoin('vendor_contacts', 'vendor_contacts.vendor_id', '=', 'vendors.id')
|
->where('expense_activities.expense_id', '=', $expenseId)
|
||||||
->where('vendors.id', '=', $vendorId)
|
->select('*',
|
||||||
->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',
|
|
||||||
'users.first_name as user_first_name',
|
'users.first_name as user_first_name',
|
||||||
'users.last_name as user_last_name',
|
'users.last_name as user_last_name',
|
||||||
'users.email as user_email',
|
'users.email as user_email',
|
||||||
'vendors.name as vendor_name',
|
'expenses.amount'
|
||||||
'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'
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ use Utils;
|
|||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
use App\Ninja\Repositories\BaseRepository;
|
use App\Ninja\Repositories\BaseRepository;
|
||||||
|
use Session;
|
||||||
|
|
||||||
class ExpenseRepository extends BaseRepository
|
class ExpenseRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
@ -25,62 +26,37 @@ class ExpenseRepository extends BaseRepository
|
|||||||
|
|
||||||
public function find($filter = null)
|
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;
|
$accountid = \Auth::user()->account_id;
|
||||||
$query = DB::table('expenses')
|
$query = DB::table('expenses')
|
||||||
->join('accounts', 'accounts.id', '=', 'expenses.account_id')
|
->join('accounts', 'accounts.id', '=', 'expenses.account_id')
|
||||||
//->join('vendors', 'vendors.id', '=', 'expenses.vendor_id')
|
|
||||||
->where('expenses.account_id', '=', $accountid)
|
->where('expenses.account_id', '=', $accountid)
|
||||||
->where('expenses.deleted_at', '=', null)
|
->where('expenses.deleted_at', '=', null)
|
||||||
->select(
|
->select('expenses.account_id',
|
||||||
//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.amount',
|
||||||
'expenses.balance',
|
'expenses.amount_cur',
|
||||||
'expenses.expense_date',
|
'expenses.currency_id',
|
||||||
'expenses.public_notes',
|
|
||||||
'expenses.deleted_at',
|
'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')) {
|
if (!\Session::get('show_trash:expense')) {
|
||||||
$query->where('expenses.deleted_at', '=', null);
|
$query->where('expenses.deleted_at', '=', null);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$query->where(function ($query) use ($filter) {
|
$query->where(function ($query) use ($filter) {
|
||||||
$query->where('vendors.name', 'like', '%'.$filter.'%');
|
$query->where('expenses.public_notes', 'like', '%'.$filter.'%');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,26 +70,43 @@ class ExpenseRepository extends BaseRepository
|
|||||||
$expense = Expense::createNew();
|
$expense = Expense::createNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
// First auto fille
|
// First auto fill
|
||||||
$expense->fill($input);
|
$expense->fill($input);
|
||||||
|
|
||||||
// We can have an expense without a vendor
|
// We can have an expense without a vendor
|
||||||
if(isset($input['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->expense_date = Utils::toSqlDate($input['expense_date']);
|
||||||
$expense->amount = Utils::parseFloat($input['amount']);
|
$expense->amount = Utils::parseFloat($input['amount']);
|
||||||
|
|
||||||
if(isset($input['amountcur']))
|
if(isset($input['amount_cur']))
|
||||||
$expense->amountcur = Utils::parseFloat($input['amountcur']);
|
$expense->amount_cur = Utils::parseFloat($input['amount_cur']);
|
||||||
|
|
||||||
$expense->balance = Utils::parseFloat($input['amount']);
|
|
||||||
$expense->private_notes = trim($input['private_notes']);
|
$expense->private_notes = trim($input['private_notes']);
|
||||||
|
$expense->public_notes = trim($input['public_notes']);
|
||||||
|
|
||||||
if(isset($input['exchange_rate']))
|
if(isset($input['exchange_rate']))
|
||||||
$expense->exchange_rate = Utils::parseFloat($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();
|
$expense->save();
|
||||||
|
|
||||||
return $expense;
|
return $expense;
|
||||||
|
62
app/Services/ExpenseActivityService.php
Normal file
62
app/Services/ExpenseActivityService.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php namespace App\Services;
|
||||||
|
|
||||||
|
use Utils;
|
||||||
|
use App\Models\Expense;
|
||||||
|
use App\Services\BaseService;
|
||||||
|
use App\Ninja\Repositories\ExpenseActivityRepository;
|
||||||
|
|
||||||
|
class ExpenseActivityService extends BaseService
|
||||||
|
{
|
||||||
|
protected $activityRepo;
|
||||||
|
protected $datatableService;
|
||||||
|
|
||||||
|
public function __construct(ExpenseActivityRepository $activityRepo, DatatableService $datatableService)
|
||||||
|
{
|
||||||
|
$this->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 ? '<i>' . trans('texts.system') . '</i>' : 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);
|
||||||
|
}
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
<?php namespace App\Services;
|
<?php namespace App\Services;
|
||||||
|
|
||||||
|
use DB;
|
||||||
use Utils;
|
use Utils;
|
||||||
use URL;
|
use URL;
|
||||||
use App\Services\BaseService;
|
use App\Services\BaseService;
|
||||||
@ -38,23 +39,29 @@ class ExpenseService extends BaseService
|
|||||||
protected function getDatatableColumns($entityType, $hideClient)
|
protected function getDatatableColumns($entityType, $hideClient)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
/*[
|
[
|
||||||
'vendor_name',
|
'vendor_id',
|
||||||
function ($model) {
|
function ($model)
|
||||||
return $model->vendor_public_id ? link_to("vendors/{$model->vendor_public_id}", Utils::getVendorDisplayName($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',
|
'amount',
|
||||||
function ($model) {
|
function ($model) {
|
||||||
return Utils::formatMoney($model->amount, false, false) . '<span '.Utils::getEntityRowClass($model).'/>';
|
return Utils::formatMoney($model->amount, false, false);
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'balance',
|
|
||||||
function ($model) {
|
|
||||||
return Utils::formatMoney($model->balance, false, false);
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -64,11 +71,29 @@ class ExpenseService extends BaseService
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'private_public',
|
'public_notes',
|
||||||
function ($model) {
|
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]));
|
||||||
|
}
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -27,11 +27,9 @@ class CreateExpensesTable extends Migration
|
|||||||
|
|
||||||
$table->boolean('is_deleted')->default(false);
|
$table->boolean('is_deleted')->default(false);
|
||||||
$table->decimal('amount', 13, 2);
|
$table->decimal('amount', 13, 2);
|
||||||
$table->decimal('amountcur', 13, 2);
|
$table->decimal('amount_cur', 13, 2);
|
||||||
$table->decimal('exchange_rate', 13, 2);
|
$table->decimal('exchange_rate', 13, 2);
|
||||||
$table->decimal('balance', 13, 2);
|
|
||||||
$table->date('expense_date')->nullable();
|
$table->date('expense_date')->nullable();
|
||||||
$table->string('expense_number')->nullable();
|
|
||||||
$table->text('private_notes');
|
$table->text('private_notes');
|
||||||
$table->text('public_notes');
|
$table->text('public_notes');
|
||||||
$table->integer('currency_id',false, true)->nullable();
|
$table->integer('currency_id',false, true)->nullable();
|
||||||
|
@ -1015,6 +1015,7 @@ return array(
|
|||||||
'white_label_purchase_link' => 'Purchase a white label license',
|
'white_label_purchase_link' => 'Purchase a white label license',
|
||||||
|
|
||||||
// Expense / vendor
|
// Expense / vendor
|
||||||
|
'expense' => 'Expense',
|
||||||
'expenses' => 'Expenses',
|
'expenses' => 'Expenses',
|
||||||
'new_expense' => 'Create expense',
|
'new_expense' => 'Create expense',
|
||||||
'vendors' => 'Vendors',
|
'vendors' => 'Vendors',
|
||||||
@ -1032,6 +1033,20 @@ return array(
|
|||||||
'expense_date' => 'Expense date',
|
'expense_date' => 'Expense date',
|
||||||
'expense_exchange_rate_100' => 'The amount for 100 in company currency',
|
'expense_exchange_rate_100' => 'The amount for 100 in company currency',
|
||||||
'expense_should_be_invoiced' => 'Should this expense be invoiced?',
|
'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
|
// Payment terms
|
||||||
'num_days' => 'Number of days',
|
'num_days' => 'Number of days',
|
||||||
|
@ -90,7 +90,12 @@
|
|||||||
{!! $activity->getMessage() !!}
|
{!! $activity->getMessage() !!}
|
||||||
</li>
|
</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
@foreach ($expenseactivities as $activity)
|
||||||
|
<li class="list-group-item">
|
||||||
|
<span style="color:#888;font-style:italic">{{ Utils::timestampToDateString(strtotime($activity->created_at)) }}:</span>
|
||||||
|
{!! $activity->getMessage() !!}
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
82
resources/views/expenses/edit.blade.php
Normal file
82
resources/views/expenses/edit.blade.php
Normal file
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-10 col-md-offset-1">
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
{!! 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('<i class="glyphicon glyphicon-calendar"></i>') !!}
|
||||||
|
{!! 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') !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<center class="buttons">
|
||||||
|
{!! 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')) !!}
|
||||||
|
</center>
|
||||||
|
|
||||||
|
{!! Former::close() !!}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
|
||||||
|
var vendors = {!! $vendors !!};
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
var $vendorSelect = $('select#vendor');
|
||||||
|
for (var i = 0; i < vendors.length; i++) {
|
||||||
|
var vendor = vendors[i];
|
||||||
|
$vendorSelect.append(new Option(getVendorDisplayName(vendor), vendor.public_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ({{ $vendorPublicId ? 'true' : 'false' }}) {
|
||||||
|
$vendorSelect.val({{ $vendorPublicId }});
|
||||||
|
}
|
||||||
|
|
||||||
|
$vendorSelect.combobox();
|
||||||
|
|
||||||
|
$('#currency_id').combobox();
|
||||||
|
$('#expense_date').datepicker('update', new Date());
|
||||||
|
|
||||||
|
@if (!$vendorPublicId)
|
||||||
|
$('.vendor-select input.form-control').focus();
|
||||||
|
@else
|
||||||
|
$('#amount').focus();
|
||||||
|
@endif
|
||||||
|
|
||||||
|
$('.expense_date .input-group-addon').click(function() {
|
||||||
|
toggleDatePicker('expense_date');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
@stop
|
122
resources/views/expenses/show.blade.php
Normal file
122
resources/views/expenses/show.blade.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
@extends('header')
|
||||||
|
|
||||||
|
@section('head')
|
||||||
|
@parent
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="pull-right">
|
||||||
|
{!! Former::open('expenses/bulk')->addClass('mainForm') !!}
|
||||||
|
<div style="display:none">
|
||||||
|
{!! Former::text('action') !!}
|
||||||
|
{!! Former::text('public_id')->value($expense->public_id) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@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() !!}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>{{ trans('texts.view_expense_num', ['expense' => $expense->public_id]) }}</h2>
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
<h3>{{ trans('texts.details') }}</h3>
|
||||||
|
|
||||||
|
<p>{{ $expense->public_notes }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h3>{{ trans('texts.standing') }}
|
||||||
|
<table class="table" style="width:100%">
|
||||||
|
<tr>
|
||||||
|
<td><small>{{ trans('texts.expense_date') }}</small></td>
|
||||||
|
<td style="text-align: right">{{ Utils::fromSqlDate($expense->expense_date) }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><small>{{ trans('texts.expense_amount') }}</small></td>
|
||||||
|
<td style="text-align: right">{{ Utils::formatMoney($expense->amount) }}</td>
|
||||||
|
</tr>
|
||||||
|
@if ($credit > 0)
|
||||||
|
<tr>
|
||||||
|
<td><small>{{ trans('texts.expense_amount_cur') }}</small></td>
|
||||||
|
<td style="text-align: right">{{ Utils::formatMoney($$expense->amount_cur, $expense->curency_id) }}</td>
|
||||||
|
</tr>
|
||||||
|
@endif
|
||||||
|
</table>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="nav nav-tabs nav-justified">
|
||||||
|
{!! HTML::tab_link('#activity', trans('texts.activity'), true) !!}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane active" id="activity">
|
||||||
|
{!! 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') !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var loadedTabs = {};
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$('.normalDropDown:not(.dropdown-toggle)').click(function() {
|
||||||
|
window.location = '{{ URL::to('expenses/' . $expense->public_id . '/edit') }}';
|
||||||
|
});
|
||||||
|
$('.primaryDropDown:not(.dropdown-toggle)').click(function() {
|
||||||
|
window.location = '{{ URL::to('expenses/create/' . $expense->public_id ) }}';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function onArchiveClick() {
|
||||||
|
$('#action').val('archive');
|
||||||
|
$('.mainForm').submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRestoreClick() {
|
||||||
|
$('#action').val('restore');
|
||||||
|
$('.mainForm').submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDeleteClick() {
|
||||||
|
if (confirm("{!! trans('texts.are_you_sure') !!}")) {
|
||||||
|
$('#action').val('delete');
|
||||||
|
$('.mainForm').submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
@stop
|
Loading…
x
Reference in New Issue
Block a user