Skip to content

Commit

Permalink
Merge pull request #254 from Blair2004/v4.4.x
Browse files Browse the repository at this point in the history
V4.4.x
  • Loading branch information
Blair2004 authored Aug 6, 2021
2 parents ec74f1c + e09eb20 commit d5ead66
Show file tree
Hide file tree
Showing 119 changed files with 2,857 additions and 1,106 deletions.
Empty file modified app/Console/Commands/ComputeDailyReportCommand.php
100644 → 100755
Empty file.
134 changes: 63 additions & 71 deletions app/Crud/ExpenseHistoryCrud.php → app/Crud/CashFlowHistoryCrud.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,56 @@
<?php
namespace App\Crud;

use App\Events\ExpenseHistoryBeforeDeleteEvent;
use Illuminate\Support\Facades\Auth;
use App\Events\CashFlowHistoryBeforeDeleteEvent;
use Illuminate\Http\Request;
use App\Services\CrudService;
use App\Services\Users;
use App\Exceptions\NotAllowedException;
use App\Models\Expense;
use App\Models\User;
use App\Models\CashFlow;
use TorMorten\Eventy\Facades\Events as Hook;
use Exception;
use App\Models\ExpenseHistory;

class ExpenseHistoryCrud extends CrudService
class CashFlowHistoryCrud extends CrudService
{
/**
* define the base table
* @param string
*/
protected $table = 'nexopos_expenses_history';
protected $table = 'nexopos_cash_flow';

/**
* default identifier
* @param string
*/
protected $identifier = 'expenses/history';
protected $identifier = 'cash-flow/history';

/**
* Define namespace
* @param string
*/
protected $namespace = 'ns.expenses-history';
protected $namespace = 'ns.cash-flow-history';

/**
* Model Used
* @param string
*/
protected $model = ExpenseHistory::class;
protected $model = CashFlow::class;

/**
* Define permissions
* @param array
*/
protected $permissions = [
'create' => false,
'read' => 'nexopos.read.expenses-history',
'create' => false, // 'nexopos.create.cash-flow-history',
'read' => 'nexopos.read.cash-flow-history',
'update' => false,
'delete' => 'nexopos.delete.expenses-history',
'delete' => 'nexopos.delete.cash-flow-history',
];

/**
* Adding relation
* @param array
*/
public $relations = [
[ 'nexopos_users as user', 'nexopos_expenses_history.author', '=', 'user.id' ]
[ 'nexopos_users as user', 'nexopos_cash_flow.author', '=', 'user.id' ]
];

/**
Expand Down Expand Up @@ -115,14 +110,14 @@ public function __construct()
public function getLabels()
{
return [
'list_title' => __( 'Expenses History List' ),
'list_description' => __( 'Display all Expenses History.' ),
'no_entry' => __( 'No Expense History has been registered' ),
'create_new' => __( 'Add a new Expense history' ),
'create_title' => __( 'Create a new Expense History' ),
'create_description' => __( 'Register a new Expense History and save it.' ),
'edit_title' => __( 'Edit Expense History' ),
'edit_description' => __( 'Modify Expense History.' ),
'list_title' => __( 'Cash Flow List' ),
'list_description' => __( 'Display all Cash Flow.' ),
'no_entry' => __( 'No Cash Flow has been registered' ),
'create_new' => __( 'Add a new Cash Flow' ),
'create_title' => __( 'Create a new Cash Flow' ),
'create_description' => __( 'Register a new Cash Flow and save it.' ),
'edit_title' => __( 'Edit Cash Flow' ),
'edit_description' => __( 'Modify Cash Flow.' ),
'back_to_list' => __( 'Return to Expenses Histories' ),
];
}
Expand All @@ -146,30 +141,15 @@ public function getForm( $entry = null )
return [
'main' => [
'label' => __( 'Name' ),
// 'name' => 'name',
// 'value' => $entry->name ?? '',
'name' => 'name',
'value' => $entry->name ?? '',
'description' => __( 'Provide a name to the resource.' )
],
'tabs' => [
'general' => [
'label' => __( 'General' ),
'fields' => [
[
'type' => 'text',
'name' => 'author',
'label' => __( 'Author' ),
'value' => $entry->author ?? '',
], [
'type' => 'text',
'name' => 'created_at',
'label' => __( 'Created At' ),
'value' => $entry->created_at ?? '',
], [
'type' => 'text',
'name' => 'expense_category_name',
'label' => __( 'Expense Category Name' ),
'value' => $entry->expense_category_name ?? '',
], [
'type' => 'text',
'name' => 'expense_id',
'label' => __( 'Expense ID' ),
Expand All @@ -179,22 +159,13 @@ public function getForm( $entry = null )
'name' => 'expense_name',
'label' => __( 'Expense Name' ),
'value' => $entry->expense_name ?? '',
], [
'type' => 'text',
'name' => 'id',
'label' => __( 'Id' ),
'value' => $entry->id ?? '',
], [
'type' => 'text',
'name' => 'updated_at',
'label' => __( 'Updated At' ),
'value' => $entry->updated_at ?? '',
], [
'type' => 'text',
'name' => 'value',
'label' => __( 'Value' ),
'value' => $entry->value ?? '',
], ]
],
]
]
]
];
Expand All @@ -215,7 +186,7 @@ public function filterPostInputs( $inputs )
* @param array of fields
* @return array of fields
*/
public function filterPutInputs( $inputs, ExpenseHistory $entry )
public function filterPutInputs( $inputs, CashFlow $entry )
{
return $inputs;
}
Expand Down Expand Up @@ -244,10 +215,10 @@ public function hook( $query )
/**
* After saving a record
* @param Request $request
* @param ExpenseHistory $entry
* @param CashFlow $entry
* @return void
*/
public function afterPost( $request, ExpenseHistory $entry )
public function afterPost( $request, CashFlow $entry )
{
return $request;
}
Expand Down Expand Up @@ -298,7 +269,7 @@ public function afterPut( $request, $entry )
* @return void
*/
public function beforeDelete( $namespace, $id, $model ) {
if ( $namespace == 'ns.expenses-history' ) {
if ( $namespace == 'ns.cash-flow-history' ) {
/**
* Perform an action before deleting an entry
* In case something wrong, this response can be returned
Expand All @@ -314,11 +285,11 @@ public function beforeDelete( $namespace, $id, $model ) {
throw new NotAllowedException;
}

if ( $model->status !== ExpenseHistory::STATUS_ACTIVE ) {
if ( $model->status !== CashFlow::STATUS_ACTIVE ) {
throw new NotAllowedException( __( 'This expense history does\'nt have a status that allow deletion.' ) );
}

event( new ExpenseHistoryBeforeDeleteEvent( ExpenseHistory::find( $model->id ) ) );
event( new CashFlowHistoryBeforeDeleteEvent( CashFlow::find( $model->id ) ) );

return [
'status' => 'success',
Expand All @@ -333,18 +304,18 @@ public function beforeDelete( $namespace, $id, $model ) {
*/
public function getColumns() {
return [
'expense_name' => [
'label' => __( 'Expense Name' ),
'name' => [
'label' => __( 'Name' ),
'$direction' => '',
'$sort' => false
],
'expense_category_name' => [
'label' => __( 'Category Name' ),
'value' => [
'label' => __( 'Value' ),
'$direction' => '',
'$sort' => false
],
'value' => [
'label' => __( 'Value' ),
'operation' => [
'label' => __( 'Operation' ),
'$direction' => '',
'$sort' => false
],
Expand All @@ -371,13 +342,34 @@ public function setActions( $entry, $namespace )
$entry->{ '$toggled' } = false;
$entry->{ '$id' } = $entry->id;

$entry->value = ns()->currency->define( $entry->value )->format();


switch( $entry->operation ) {
case CashFlow::OPERATION_CREDIT :
$entry->{ '$cssClass' } = 'bg-green-100 border-green-200 border text-sm';
break;
case CashFlow::OPERATION_DEBIT :
$entry->{ '$cssClass' } = 'bg-red-100 border-red-200 border text-sm';
break;
}

switch( $entry->operation ) {
case CashFlow::OPERATION_CREDIT :
$entry->operation = "<span class='bg-green-400 text-white rounded-full px-2 py-1 text-sm'>" . __( 'Credit' ) . '</span>';
break;
case CashFlow::OPERATION_DEBIT :
$entry->operation = "<span class='bg-red-400 text-white rounded-full px-2 py-1 text-sm'>" . __( 'Debit' ) . '</span>';
break;
}

// you can make changes here
$entry->{'$actions'} = [
[
'label' => __( 'Delete' ),
'namespace' => 'delete',
'type' => 'DELETE',
'url' => ns()->url( '/api/nexopos/v4/crud/ns.expenses-history/' . $entry->id ),
'url' => ns()->url( '/api/nexopos/v4/crud/ns.cash-flow-history/' . $entry->id ),
'confirm' => [
'message' => __( 'Would you like to delete this ?' ),
]
Expand Down Expand Up @@ -418,7 +410,7 @@ public function bulkAction( Request $request )

foreach ( $request->input( 'entries' ) as $id ) {
$entity = $this->model::find( $id );
if ( $entity instanceof ExpenseHistory ) {
if ( $entity instanceof CashFlow ) {
$entity->delete();
$status[ 'success' ]++;
} else {
Expand All @@ -438,11 +430,11 @@ public function bulkAction( Request $request )
public function getLinks()
{
return [
'list' => ns()->url( 'dashboard/' . 'expenses/history' ),
'create' => ns()->url( 'dashboard/' . 'expenses/history/create' ),
'edit' => ns()->url( 'dashboard/' . 'expenses/history/edit/' ),
'post' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.expenses-history' ),
'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.expenses-history/{id}' . '' ),
'list' => ns()->url( 'dashboard/' . 'cash-flow/history' ),
'create' => ns()->url( 'dashboard/' . 'cash-flow/history/create' ),
'edit' => ns()->url( 'dashboard/' . 'cash-flow/history/edit/' ),
'post' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.cash-flow-history' ),
'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.cash-flow-history/{id}' . '' ),
];
}

Expand Down
27 changes: 27 additions & 0 deletions app/Crud/ExpenseCategoryCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use TorMorten\Eventy\Facades\Events as Hook;
use Exception;
use App\Models\ExpenseCategory;
use App\Services\Helper;

class ExpenseCategoryCrud extends CrudService
{
Expand Down Expand Up @@ -122,6 +123,22 @@ public function getForm( $entry = null )
'label' => __( 'General' ),
'fields' => [
[
'type' => 'select',
'name' => 'operation',
'label' => __( 'Operation' ),
'description' => __( 'All entities attached to this category will either produce a "credit" or "debit" to the cash flow history.' ),
'options' => Helper::kvToJsOptions([
'credit' => __( 'Credit' ),
'debit' => __( 'Debit' )
]),
'value' => $entry->operation ?? '',
], [
'type' => 'text',
'name' => 'account',
'label' => __( 'Account' ),
'description' => __( 'Provide the accounting number for this category.' ),
'value' => $entry->account ?? '',
], [
'type' => 'textarea',
'name' => 'description',
'label' => __( 'Description' ),
Expand Down Expand Up @@ -251,6 +268,16 @@ public function getColumns() {
'$direction' => '',
'$sort' => false
],
'account' => [
'label' => __( 'Account' ),
'$direction' => '',
'$sort' => false
],
'operation' => [
'label' => __( 'Operation' ),
'$direction' => '',
'$sort' => false
],
'nexopos_users_username' => [
'label' => __( 'Author' ),
'$direction' => '',
Expand Down
20 changes: 15 additions & 5 deletions ...vents/ExpenseHistoryBeforeDeleteEvent.php → app/Events/CashFlowAfterCreatedEvent.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Events;

use App\Models\ExpenseHistory;
use App\Models\CashFlow;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
Expand All @@ -11,19 +11,29 @@
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ExpenseHistoryBeforeDeleteEvent
class CashFlowAfterCreatedEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $expenseHistory;
public $cashFlow;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct( ExpenseHistory $expenseHistory )
public function __construct( CashFlow $cashFlow )
{
$this->expenseHistory = $expenseHistory;
$this->cashFlow = $cashFlow;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
Loading

0 comments on commit d5ead66

Please sign in to comment.