Skip to content

Commit 700830e

Browse files
authored
Merge pull request #2113 from Blair2004/v5.0.x-accounting
V5.0.x accounting
2 parents 1559d8e + 2f06172 commit 700830e

File tree

303 files changed

+5734
-25050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+5734
-25050
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ public/modules-lang/*
4141
!public/modules-lang/index.html
4242
public/mapping.json
4343
storage/module.zip
44-
tests/.coverage
44+
tests/.coverage*
4545
tests/database.sqlite
4646
tests/database.sqlite-journal
4747
tests/Post/*
4848
storage/snapshots/*.sql
4949
storage/temporary-files/*
5050
.idea
5151
public/hot
52-
tests/.coverage
5352
.phpunit.cache/test-results
5453
storage/dotenv-editor
5554
.cloud
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Casts;
4+
5+
use App\Services\CrudEntry;
6+
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
class AccountingCategoryCast implements CastsAttributes
10+
{
11+
/**
12+
* Cast the given value.
13+
*
14+
* @param array<string, mixed> $attributes
15+
*/
16+
public function get( Model | CrudEntry $model, string $key, mixed $value, array $attributes): mixed
17+
{
18+
$accounting = config( 'accounting.accounts' );
19+
20+
$accountReference = $accounting[ $value ] ?? null;
21+
22+
if ( $accountReference ) {
23+
return $accountReference[ 'label' ]();
24+
}
25+
26+
return $value;
27+
}
28+
29+
/**
30+
* Prepare the given value for storage.
31+
*
32+
* @param array<string, mixed> $attributes
33+
*/
34+
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
35+
{
36+
return $value;
37+
}
38+
}

app/Casts/TransactionOccurrenceCast.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Casts;
44

55
use App\Models\Transaction;
6+
use App\Services\CrudEntry;
67
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
78

89
class TransactionOccurrenceCast implements CastsAttributes
@@ -16,14 +17,40 @@ class TransactionOccurrenceCast implements CastsAttributes
1617
*/
1718
public function get( $model, string $key, $value, array $attributes )
1819
{
20+
if ( $model instanceof CrudEntry ) {
21+
if ( $model->getRawValue( 'type' ) === Transaction::TYPE_SCHEDULED ) {
22+
return sprintf(
23+
__( 'Scheduled for %s' ),
24+
ns()->date->getFormatted( $model->getRawValue( 'scheduled_date' ) )
25+
);
26+
}
27+
}
28+
29+
if ( $value === null ) {
30+
return __( 'No Occurrence' );
31+
}
32+
33+
if ( $value == 1 ) {
34+
$specificLabel = __( 'Every 1st of the month' );
35+
} else if ( $value == 2 ) {
36+
$specificLabel = __( 'Every 2nd of the month' );
37+
} else if ( $value == 3 ) {
38+
$specificLabel = __( 'Every 3rd of the month' );
39+
} else {
40+
$specificLabel = sprintf( __( 'Every %sth of the month' ), $value );
41+
}
42+
1943
return match ( $value ) {
20-
Transaction::OCCURRENCE_X_AFTER_MONTH_STARTS => __( 'Month Starts' ),
21-
Transaction::OCCURRENCE_MIDDLE_OF_MONTH => __( 'Month Middle' ),
22-
Transaction::OCCURRENCE_END_OF_MONTH => __( 'Month Ends' ),
23-
Transaction::OCCURRENCE_X_AFTER_MONTH_STARTS => __( 'X Days After Month Starts' ),
24-
Transaction::OCCURRENCE_X_BEFORE_MONTH_ENDS => __( 'X Days Before Month Ends' ),
25-
Transaction::OCCURRENCE_SPECIFIC_DAY => __( 'On Specific Day' ),
26-
default => __( 'Unknown Occurance' )
44+
Transaction::OCCURRENCE_START_OF_MONTH => __( 'Every start of the month' ),
45+
Transaction::OCCURRENCE_MIDDLE_OF_MONTH => __( 'Every middle month' ),
46+
Transaction::OCCURRENCE_END_OF_MONTH => __( 'Every end of month' ),
47+
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 ),
48+
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 ),
49+
Transaction::OCCURRENCE_SPECIFIC_DAY => $specificLabel,
50+
Transaction::OCCURRENCE_EVERY_X_DAYS => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s day' ), $model->occurrence_value ) : sprintf( __( 'Every %s days' ), $model->occurrence_value ),
51+
Transaction::OCCURRENCE_EVERY_X_HOURS => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s hour' ), $model->occurrence_value ) : sprintf( __( 'Every %s hours' ), $model->occurrence_value ),
52+
Transaction::OCCURRENCE_EVERY_X_MINUTES => $model->occurrence_value <= 1 ? sprintf( __( 'Every %s minute' ), $model->occurrence_value ) : sprintf( __( 'Every %s minutes' ), $model->occurrence_value ),
53+
default => sprintf( __( 'Unknown Occurance: %s' ), $value )
2754
};
2855
}
2956

app/Casts/TransactionTypeCast.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function get( $model, string $key, $value, array $attributes )
1818
{
1919
return match ( $value ) {
2020
Transaction::TYPE_DIRECT => __( 'Direct Transaction' ),
21+
Transaction::TYPE_INDIRECT => __( 'Indirect Transaction' ),
2122
Transaction::TYPE_RECURRING => __( 'Recurring Transaction' ),
2223
Transaction::TYPE_ENTITY => __( 'Entity Transaction' ),
2324
Transaction::TYPE_SCHEDULED => __( 'Scheduled Transaction' ),

app/Classes/CrudForm.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ public static function tabs( ...$args )
1616
} )->toArray();
1717
}
1818

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

2431
public static function fields( ...$args )
2532
{
2633
return collect( $args )->filter()->toArray();
2734
}
35+
36+
public static function tabFooter( $extraComponents = [] )
37+
{
38+
return compact( 'extraComponents' );
39+
}
2840
}

app/Classes/CrudInput.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ public static function date( $label, $name, $value = '', $validation = '', $desc
8686
);
8787
}
8888

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

94-
public static function searchSelect( $label, $name, $value = '', $options = [], $validation = '', $description = '', $disabled = false, $component = '', $props = [] )
94+
public static function searchSelect( $label, $name, $value = '', $options = [], $validation = '', $description = '', $disabled = false, $component = '', $props = [], $refresh = false )
9595
{
9696
return self::select(
9797
label: $label,
@@ -102,10 +102,17 @@ public static function searchSelect( $label, $name, $value = '', $options = [],
102102
value: $value,
103103
type: 'search-select',
104104
component: $component,
105-
props: $props
105+
props: $props,
106+
disabled: $disabled,
107+
refresh: $refresh
106108
);
107109
}
108110

111+
public static function refreshConfig( string $url, string $watch, array $data = [] )
112+
{
113+
return compact( 'url', 'watch', 'data' );
114+
}
115+
109116
public static function textarea( $label, $name, $value = '', $validation = '', $description = '', $disabled = false )
110117
{
111118
return self::text(
@@ -240,17 +247,11 @@ public static function daterange( $label, $name, $value = '', $validation = '',
240247
);
241248
}
242249

243-
public static function custom( $label, $name, $type, $value = '', $validation = '', $description = '', $disabled = false, $options = [] )
250+
public static function custom( $label, $component )
244251
{
245-
return self::select(
246-
label: $label,
247-
name: $name,
248-
validation: $validation,
249-
description: $description,
250-
disabled: $disabled,
251-
options: $options,
252-
type: $type,
253-
value: $value
254-
);
252+
return [
253+
'label' => $label,
254+
'component' => $component
255+
];
255256
}
256257
}

app/Classes/Notice.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
namespace App\Classes;
3+
4+
class Notice
5+
{
6+
public static function info( $title, $description )
7+
{
8+
$color = 'info';
9+
10+
return compact( 'title', 'description', 'color' );
11+
}
12+
13+
public static function warning( $title, $description )
14+
{
15+
$color = 'warning';
16+
17+
return compact( 'title', 'description', 'color' );
18+
}
19+
20+
public static function error( $title, $description )
21+
{
22+
$color = 'error';
23+
24+
return compact( 'title', 'description', 'color' );
25+
}
26+
27+
public static function success( $title, $description )
28+
{
29+
$color = 'success';
30+
31+
return compact( 'title', 'description', 'color' );
32+
}
33+
}

app/Crud/CustomerAccountCrud.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Classes\CrudTable;
66
use App\Events\CrudBeforeExportEvent;
77
use App\Exceptions\NotAllowedException;
8+
use App\Models\Customer;
89
use App\Models\CustomerAccountHistory;
910
use App\Models\User;
1011
use App\Services\CrudEntry;
@@ -582,10 +583,18 @@ public function bulkAction( Request $request )
582583
*/
583584
public function getLinks(): array
584585
{
586+
$customer = request()->route( 'customer' );
587+
588+
if ( $customer instanceof Customer ) {
589+
$customerId = $customer->id;
590+
} else {
591+
$customerId = request()->query( 'customer_id' );
592+
}
593+
585594
return [
586-
'list' => ns()->url( 'dashboard/' . 'customers/' . '/account-history' ),
587-
'create' => ns()->url( 'dashboard/' . 'customers/' . '/account-history/create' ),
588-
'edit' => ns()->url( 'dashboard/' . 'customers/' . '/account-history/edit/' ),
595+
'list' => ns()->url( 'dashboard/' . 'customers/' . $customerId . '/account-history' ),
596+
'create' => ns()->url( 'dashboard/' . 'customers/' . $customerId . '/account-history/create' ),
597+
'edit' => ns()->url( 'dashboard/' . 'customers/' . $customerId . '/account-history/edit/' ),
589598
'post' => ns()->url( 'api/crud/' . 'ns.customers-account-history' ),
590599
'put' => ns()->url( 'api/crud/' . 'ns.customers-account-history/{id}' ),
591600
];

app/Crud/ProductCrud.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,13 @@ public function beforeDelete( $namespace, $id, $model )
676676
public function getColumns(): array
677677
{
678678
return [
679-
'type' => [
680-
'label' => __( 'Type' ),
679+
'name' => [
680+
'label' => __( 'Name' ),
681681
'$direction' => '',
682682
'$sort' => false,
683683
],
684-
'name' => [
685-
'label' => __( 'Name' ),
684+
'type' => [
685+
'label' => __( 'Type' ),
686686
'$direction' => '',
687687
'width' => '150px',
688688
'$sort' => false,

app/Crud/RegisterCrud.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public function getLinks(): array
450450
return [
451451
'list' => ns()->url( 'dashboard/' . 'cash-registers' ),
452452
'create' => ns()->url( 'dashboard/' . 'cash-registers/create' ),
453-
'edit' => ns()->url( 'dashboard/' . 'cash-registers/edit/' ),
453+
'edit' => ns()->url( 'dashboard/' . 'cash-registers/edit/{id}' ),
454454
'post' => ns()->url( 'api/crud/' . self::IDENTIFIER ),
455455
'put' => ns()->url( 'api/crud/' . self::IDENTIFIER . '/{id}' . '' ),
456456
];

0 commit comments

Comments
 (0)