This commit is contained in:
steenrabol 2016-01-08 19:01:00 +01:00
parent d8a501ed95
commit d89dc2e827
23 changed files with 610 additions and 155 deletions

View File

@ -1,12 +1,10 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class ExpenseWasArchived extends Event {
// Expenses
class ExpenseWasArchived extends Event
{
use SerializesModels;
public $expense;

View File

@ -1,11 +1,10 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class ExpenseWasCreated extends Event {
// Expenses
class ExpenseWasCreated extends Event
{
use SerializesModels;
public $expense;

View 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;
}
}

View File

@ -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);

View 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);
}
}

View File

@ -1,5 +1,7 @@
<?php namespace App\Http\Controllers;
use Debugbar;
use DB;
use Auth;
use Datatable;
use Utils;
@ -11,9 +13,11 @@ use Session;
use Redirect;
use Cache;
use App\Models\Vendor;
use App\Models\Expense;
use App\Services\ExpenseService;
use App\Ninja\Repositories\ExpenseRepository;
use App\Http\Requests\CreateExpenseRequest;
use App\Http\Requests\UpdateExpenseRequest;
class ExpenseController extends BaseController
{
@ -39,28 +43,31 @@ class ExpenseController extends BaseController
return View::make('list', array(
'entityType' => 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)
{
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,
@ -68,6 +75,7 @@ class ExpenseController extends BaseController
'url' => 'expenses',
'title' => trans('texts.new_expense'),
'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(),
'vendor' => $vendor,
);
$data = array_merge($data, self::getViewModel());
@ -86,9 +94,33 @@ 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)
@ -130,4 +162,27 @@ class ExpenseController extends BaseController
];
}
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);
}
}

View File

@ -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(

View File

@ -25,6 +25,8 @@ class UpdateExpenseRequest extends Request
{
return [
'amount' => 'required|positive',
'public_notes' => 'required',
'expense_date' => 'required',
];
}
}

View File

@ -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');

View 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
);
}
}

View File

@ -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
);
}
}

View File

@ -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,7 +38,20 @@ 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()

View File

@ -46,14 +46,13 @@ 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,
'user' => $isSystem ? '<i>' . trans('texts.system') . '</i>' : $user->getDisplayName(),

View File

@ -8,15 +8,13 @@ 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 = [
'name',
'id_number',
@ -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) {

View File

@ -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'
);
}
}

View File

@ -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;

View 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);
}
]
];
}
}

View File

@ -1,5 +1,6 @@
<?php namespace App\Services;
use DB;
use Utils;
use URL;
use App\Services\BaseService;
@ -38,23 +39,29 @@ class ExpenseService extends BaseService
protected function getDatatableColumns($entityType, $hideClient)
{
return [
/*[
'vendor_name',
function ($model) {
return $model->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) . '<span '.Utils::getEntityRowClass($model).'/>';
}
],
[
'balance',
function ($model) {
return Utils::formatMoney($model->balance, false, false);
return Utils::formatMoney($model->amount, false, false);
}
],
[
@ -64,9 +71,27 @@ 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]));
}
]
];

View File

@ -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();

View File

@ -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',

View File

@ -90,7 +90,12 @@
{!! $activity->getMessage() !!}
</li>
@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>
</div>
</div>

View 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

View 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