Skip to content

Commit

Permalink
Merge pull request #2114 from Blair2004/v5.0.x
Browse files Browse the repository at this point in the history
V5.0.x
  • Loading branch information
Blair2004 authored Oct 19, 2024
2 parents 66d25fa + b34bdf4 commit 11998f1
Show file tree
Hide file tree
Showing 303 changed files with 5,735 additions and 25,050 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ public/modules-lang/*
!public/modules-lang/index.html
public/mapping.json
storage/module.zip
tests/.coverage
tests/.coverage*
tests/database.sqlite
tests/database.sqlite-journal
tests/Post/*
storage/snapshots/*.sql
storage/temporary-files/*
.idea
public/hot
tests/.coverage
.phpunit.cache/test-results
storage/dotenv-editor
.cloud
38 changes: 38 additions & 0 deletions app/Casts/AccountingCategoryCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Casts;

use App\Services\CrudEntry;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

class AccountingCategoryCast implements CastsAttributes
{
/**
* Cast the given value.
*
* @param array<string, mixed> $attributes
*/
public function get( Model | CrudEntry $model, string $key, mixed $value, array $attributes): mixed
{
$accounting = config( 'accounting.accounts' );

$accountReference = $accounting[ $value ] ?? null;

if ( $accountReference ) {
return $accountReference[ 'label' ]();
}

return $value;
}

/**
* Prepare the given value for storage.
*
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}
}
41 changes: 34 additions & 7 deletions app/Casts/TransactionOccurrenceCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Casts;

use App\Models\Transaction;
use App\Services\CrudEntry;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class TransactionOccurrenceCast implements CastsAttributes
Expand All @@ -16,14 +17,40 @@ class TransactionOccurrenceCast implements CastsAttributes
*/
public function get( $model, string $key, $value, array $attributes )
{
if ( $model instanceof CrudEntry ) {
if ( $model->getRawValue( 'type' ) === Transaction::TYPE_SCHEDULED ) {
return sprintf(
__( 'Scheduled for %s' ),
ns()->date->getFormatted( $model->getRawValue( 'scheduled_date' ) )
);
}
}

if ( $value === null ) {
return __( 'No Occurrence' );
}

if ( $value == 1 ) {
$specificLabel = __( 'Every 1st of the month' );
} else if ( $value == 2 ) {
$specificLabel = __( 'Every 2nd of the month' );
} else if ( $value == 3 ) {
$specificLabel = __( 'Every 3rd of the month' );
} else {
$specificLabel = sprintf( __( 'Every %sth of the month' ), $value );
}

return match ( $value ) {
Transaction::OCCURRENCE_X_AFTER_MONTH_STARTS => __( 'Month Starts' ),
Transaction::OCCURRENCE_MIDDLE_OF_MONTH => __( 'Month Middle' ),
Transaction::OCCURRENCE_END_OF_MONTH => __( 'Month Ends' ),
Transaction::OCCURRENCE_X_AFTER_MONTH_STARTS => __( 'X Days After Month Starts' ),
Transaction::OCCURRENCE_X_BEFORE_MONTH_ENDS => __( 'X Days Before Month Ends' ),
Transaction::OCCURRENCE_SPECIFIC_DAY => __( 'On Specific Day' ),
default => __( 'Unknown Occurance' )
Transaction::OCCURRENCE_START_OF_MONTH => __( 'Every start of the month' ),
Transaction::OCCURRENCE_MIDDLE_OF_MONTH => __( 'Every middle month' ),
Transaction::OCCURRENCE_END_OF_MONTH => __( 'Every end of month' ),
Transaction::OCCURRENCE_X_AFTER_MONTH_STARTS => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s day after month starts' ), $model->occurrence_value ) : sprintf( __( 'Every %s days after month starts' ), $model->occurrence_value ),
Transaction::OCCURRENCE_X_BEFORE_MONTH_ENDS => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s Days before month ends' ) ) : sprintf( __( 'Every %s Days before month ends' ), $model->occurrence_value ),
Transaction::OCCURRENCE_SPECIFIC_DAY => $specificLabel,
Transaction::OCCURRENCE_EVERY_X_DAYS => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s day' ), $model->occurrence_value ) : sprintf( __( 'Every %s days' ), $model->occurrence_value ),
Transaction::OCCURRENCE_EVERY_X_HOURS => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s hour' ), $model->occurrence_value ) : sprintf( __( 'Every %s hours' ), $model->occurrence_value ),
Transaction::OCCURRENCE_EVERY_X_MINUTES => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s minute' ), $model->occurrence_value ) : sprintf( __( 'Every %s minutes' ), $model->occurrence_value ),
default => sprintf( __( 'Unknown Occurance: %s' ), $value )
};
}

Expand Down
1 change: 1 addition & 0 deletions app/Casts/TransactionTypeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function get( $model, string $key, $value, array $attributes )
{
return match ( $value ) {
Transaction::TYPE_DIRECT => __( 'Direct Transaction' ),
Transaction::TYPE_INDIRECT => __( 'Indirect Transaction' ),
Transaction::TYPE_RECURRING => __( 'Recurring Transaction' ),
Transaction::TYPE_ENTITY => __( 'Entity Transaction' ),
Transaction::TYPE_SCHEDULED => __( 'Scheduled Transaction' ),
Expand Down
16 changes: 14 additions & 2 deletions app/Classes/CrudForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ public static function tabs( ...$args )
} )->toArray();
}

public static function tab( $identifier, $label, $fields )
/**
* @param string $identifier Provides a unique identifier for the tab
* @param string $label This is a visible name used to identify the tab
* @param array $fields Here are defined the fields that will be loaded on the tab
* @param array $notices You might display specific notices on the tab
* @param array $footer You can set a specfic feature that should be loaded at the footer
*/
public static function tab( $identifier, $label, $fields, $notices = [], $footer = [] )
{
return compact( 'label', 'fields', 'identifier' );
return compact( 'label', 'fields', 'identifier', 'notices', 'footer' );
}

public static function fields( ...$args )
{
return collect( $args )->filter()->toArray();
}

public static function tabFooter( $extraComponents = [] )
{
return compact( 'extraComponents' );
}
}
31 changes: 16 additions & 15 deletions app/Classes/CrudInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public static function date( $label, $name, $value = '', $validation = '', $desc
);
}

public static function select( $label, $name, $options, $value = '', $validation = '', $description = '', $disabled = false, $type = 'select', $component = '', $props = [] )
public static function select( $label, $name, $options, $value = '', $validation = '', $description = '', $disabled = false, $type = 'select', $component = '', $props = [], $refresh = false )
{
return compact( 'label', 'name', 'validation', 'options', 'value', 'description', 'disabled', 'type', 'component', 'props' );
return compact( 'label', 'name', 'validation', 'options', 'value', 'description', 'disabled', 'type', 'component', 'props', 'refresh' );
}

public static function searchSelect( $label, $name, $value = '', $options = [], $validation = '', $description = '', $disabled = false, $component = '', $props = [] )
public static function searchSelect( $label, $name, $value = '', $options = [], $validation = '', $description = '', $disabled = false, $component = '', $props = [], $refresh = false )
{
return self::select(
label: $label,
Expand All @@ -102,10 +102,17 @@ public static function searchSelect( $label, $name, $value = '', $options = [],
value: $value,
type: 'search-select',
component: $component,
props: $props
props: $props,
disabled: $disabled,
refresh: $refresh
);
}

public static function refreshConfig( string $url, string $watch, array $data = [] )
{
return compact( 'url', 'watch', 'data' );
}

public static function textarea( $label, $name, $value = '', $validation = '', $description = '', $disabled = false )
{
return self::text(
Expand Down Expand Up @@ -240,17 +247,11 @@ public static function daterange( $label, $name, $value = '', $validation = '',
);
}

public static function custom( $label, $name, $type, $value = '', $validation = '', $description = '', $disabled = false, $options = [] )
public static function custom( $label, $component )
{
return self::select(
label: $label,
name: $name,
validation: $validation,
description: $description,
disabled: $disabled,
options: $options,
type: $type,
value: $value
);
return [
'label' => $label,
'component' => $component
];
}
}
33 changes: 33 additions & 0 deletions app/Classes/Notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace App\Classes;

class Notice
{
public static function info( $title, $description )
{
$color = 'info';

return compact( 'title', 'description', 'color' );
}

public static function warning( $title, $description )
{
$color = 'warning';

return compact( 'title', 'description', 'color' );
}

public static function error( $title, $description )
{
$color = 'error';

return compact( 'title', 'description', 'color' );
}

public static function success( $title, $description )
{
$color = 'success';

return compact( 'title', 'description', 'color' );
}
}
15 changes: 12 additions & 3 deletions app/Crud/CustomerAccountCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Classes\CrudTable;
use App\Events\CrudBeforeExportEvent;
use App\Exceptions\NotAllowedException;
use App\Models\Customer;
use App\Models\CustomerAccountHistory;
use App\Models\User;
use App\Services\CrudEntry;
Expand Down Expand Up @@ -582,10 +583,18 @@ public function bulkAction( Request $request )
*/
public function getLinks(): array
{
$customer = request()->route( 'customer' );

if ( $customer instanceof Customer ) {
$customerId = $customer->id;
} else {
$customerId = request()->query( 'customer_id' );
}

return [
'list' => ns()->url( 'dashboard/' . 'customers/' . '/account-history' ),
'create' => ns()->url( 'dashboard/' . 'customers/' . '/account-history/create' ),
'edit' => ns()->url( 'dashboard/' . 'customers/' . '/account-history/edit/' ),
'list' => ns()->url( 'dashboard/' . 'customers/' . $customerId . '/account-history' ),
'create' => ns()->url( 'dashboard/' . 'customers/' . $customerId . '/account-history/create' ),
'edit' => ns()->url( 'dashboard/' . 'customers/' . $customerId . '/account-history/edit/' ),
'post' => ns()->url( 'api/crud/' . 'ns.customers-account-history' ),
'put' => ns()->url( 'api/crud/' . 'ns.customers-account-history/{id}' ),
];
Expand Down
8 changes: 4 additions & 4 deletions app/Crud/ProductCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,13 @@ public function beforeDelete( $namespace, $id, $model )
public function getColumns(): array
{
return [
'type' => [
'label' => __( 'Type' ),
'name' => [
'label' => __( 'Name' ),
'$direction' => '',
'$sort' => false,
],
'name' => [
'label' => __( 'Name' ),
'type' => [
'label' => __( 'Type' ),
'$direction' => '',
'width' => '150px',
'$sort' => false,
Expand Down
2 changes: 1 addition & 1 deletion app/Crud/RegisterCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public function getLinks(): array
return [
'list' => ns()->url( 'dashboard/' . 'cash-registers' ),
'create' => ns()->url( 'dashboard/' . 'cash-registers/create' ),
'edit' => ns()->url( 'dashboard/' . 'cash-registers/edit/' ),
'edit' => ns()->url( 'dashboard/' . 'cash-registers/edit/{id}' ),
'post' => ns()->url( 'api/crud/' . self::IDENTIFIER ),
'put' => ns()->url( 'api/crud/' . self::IDENTIFIER . '/{id}' . '' ),
];
Expand Down
17 changes: 11 additions & 6 deletions app/Crud/RegisterHistoryCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public function getTableFooter( Output $output ): Output
public function setActions( CrudEntry $entry ): CrudEntry
{
switch ( $entry->action ) {
case RegisterHistory::ACTION_SALE:
case RegisterHistory::ACTION_ORDER_PAYMENT:
$entry->{ '$cssClass' } = 'success border';
break;
case RegisterHistory::ACTION_CASHING:
Expand All @@ -436,16 +436,21 @@ public function setActions( CrudEntry $entry ): CrudEntry
case RegisterHistory::ACTION_ACCOUNT_CHANGE:
$entry->{ '$cssClass' } = 'warning border';
break;
case RegisterHistory::ACTION_CASH_CHANGE:
$entry->{ '$cssClass' } = 'warning border';
break;
case RegisterHistory::ACTION_CLOSING:
case RegisterHistory::ACTION_ORDER_CHANGE:
$entry->{ '$cssClass' } = 'warning border';
break;
}

if ( $entry->action === RegisterHistory::ACTION_CLOSING && (float) $entry->balance_after != 0 ) {
$entry->{ '$cssClass' } = 'error border';
// $entry->{ '$cssClass' } = 'error border';
}

if ( $entry->action === RegisterHistory::ACTION_CLOSING && $entry->transaction_type === 'unchanged' ) {
$entry->{ '$cssClass' } = 'success border';
} else if ( $entry->action === RegisterHistory::ACTION_CLOSING && $entry->transaction_type === 'positive' ) {
$entry->{ '$cssClass' } = 'warning border';
} else if ( $entry->action === RegisterHistory::ACTION_CLOSING && $entry->transaction_type === 'negative' ) {
$entry->{ '$cssClass' } = 'warning border';
}

$entry->action(
Expand Down
Loading

0 comments on commit 11998f1

Please sign in to comment.