Skip to content

Commit

Permalink
Changelog:
Browse files Browse the repository at this point in the history
- Refactored: Crud files
- Updated: Prevent same unit and conversion unit to be assigned #1846
- Updated: CrudInput & CrudTable
- Fixed: password update issue
- Refactoring; Settings files
- Added: support for optionAttributes
- Added: support for custom column width
  • Loading branch information
Blair2004 committed Apr 8, 2024
1 parent 193780a commit 41cd457
Show file tree
Hide file tree
Showing 192 changed files with 1,908 additions and 1,802 deletions.
10 changes: 6 additions & 4 deletions app/Classes/CrudInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public static function date( $label, $name, $value = '', $validation = '', $desc
);
}

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

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

Expand Down
14 changes: 12 additions & 2 deletions app/Classes/CrudTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public static function columns( ...$args )
})->toArray();
}

public static function column( $label, $identifier, $sort = false, $attributes = [] )
public static function column( $label, $identifier, $sort = false, $attributes = [], $width = 'auto', $minWidth = 'auto', $maxWidth= 'auto', $direction = '' )
{
return compact( 'identifier', 'label', 'sort', 'attributes' );
return compact( 'identifier', 'label', 'sort', 'attributes', 'width', 'direction', 'maxWidth', 'minWidth' );
}

public static function attribute( $label, $column )
Expand All @@ -26,4 +26,14 @@ public static function attributes( ...$attributes )
{
return $attributes;
}

public static function labels( $list_title, $list_description, $no_entry, $create_new, $create_title, $create_description, $edit_title, $edit_description, $back_to_list )
{
return compact( 'list_title', 'list_description', 'no_entry', 'create_new', 'create_title', 'create_description', 'edit_title', 'edit_description', 'back_to_list' );
}

public static function links( $list, $create, $edit, $post, $put )
{
return compact( 'list', 'create', 'edit', 'post', 'put' );
}
}
259 changes: 125 additions & 134 deletions app/Crud/CouponCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Crud;

use App\Casts\NotDefinedCast;
use App\Classes\CrudForm;
use App\Classes\FormInput;
use App\Exceptions\NotAllowedException;
use App\Models\Coupon;
use App\Models\CouponCategory;
Expand All @@ -25,6 +27,16 @@

class CouponCrud extends CrudService
{
/**
* Define the autoload status
*/
const AUTOLOAD = true;

/**
* Define the identifier
*/
const IDENTIFIER = 'ns.coupons';

/**
* define the base table
*
Expand Down Expand Up @@ -165,149 +177,128 @@ public function isEnabled( $feature ): bool
*/
public function getForm( $entry = null )
{
return [
'main' => [
'label' => __( 'Name' ),
'name' => 'name',
'value' => $entry->name ?? '',
'validation' => 'required',
'description' => __( 'Provide a name to the resource.' ),
],
'tabs' => [
'general' => [
'label' => __( 'General' ),
'active' => false,
'fields' => [
[
'type' => 'text',
'name' => 'code',
'label' => __( 'Coupon Code' ),
'validation' => [
return CrudForm::form(
main: FormInput::text(
label: __( 'Name' ),
name: 'name',
value: $entry->name ?? '',
validation: 'required',
description: __( 'Provide a name to the resource.' ),
),
tabs: CrudForm::tabs(
CrudForm::tab(
identifier: 'general',
label: __( 'General' ),
fields: CrudForm::fields(
FormInput::text(
label: __( 'Coupon Code' ),
name: 'code',
validation: [
'required',
Rule::unique( 'nexopos_coupons', 'code' )->ignore( $entry !== null ? $entry->id : 0 ),
],
'description' => __( 'Might be used while printing the coupon.' ),
'value' => $entry->code ?? '',
], [
'type' => 'select',
'name' => 'type',
'validation' => 'required',
'options' => Helper::kvToJsOptions( [
description: __( 'Might be used while printing the coupon.' ),
value: $entry->code ?? '',
),
FormInput::select(
name: 'type',
validation: 'required',
options: Helper::kvToJsOptions( [
'percentage_discount' => __( 'Percentage Discount' ),
'flat_discount' => __( 'Flat Discount' ),
] ),
'label' => __( 'Type' ),
'value' => $entry->type ?? '',
'description' => __( 'Define which type of discount apply to the current coupon.' ),
], [
'type' => 'text',
'name' => 'discount_value',
'label' => __( 'Discount Value' ),
'description' => __( 'Define the percentage or flat value.' ),
'value' => $entry->discount_value ?? '',
], [
'type' => 'datetime',
'name' => 'valid_until',
'label' => __( 'Valid Until' ),
'description' => __( 'Determine Until When the coupon is valid.' ),
'value' => $entry->valid_until ?? '',
], [
'type' => 'number',
'name' => 'minimum_cart_value',
'label' => __( 'Minimum Cart Value' ),
'description' => __( 'What is the minimum value of the cart to make this coupon eligible.' ),
'value' => $entry->minimum_cart_value ?? '',
], [
'type' => 'text',
'name' => 'maximum_cart_value',
'label' => __( 'Maximum Cart Value' ),
'description' => __( 'The value above which the current coupon can\'t apply.' ),
'value' => $entry->maximum_cart_value ?? '',
], [
'type' => 'datetimepicker',
'name' => 'valid_hours_start',
'label' => __( 'Valid Hours Start' ),
'description' => __( 'Define form which hour during the day the coupons is valid.' ),
'value' => $entry->valid_hours_start ?? '',
], [
'type' => 'datetimepicker',
'name' => 'valid_hours_end',
'label' => __( 'Valid Hours End' ),
'description' => __( 'Define to which hour during the day the coupons end stop valid.' ),
'value' => $entry->valid_hours_end ?? '',
], [
'type' => 'number',
'name' => 'limit_usage',
'label' => __( 'Limit Usage' ),
'description' => __( 'Define how many time a coupons can be redeemed.' ),
'value' => $entry->limit_usage ?? '',
],
],
],
'selected_products' => [
'label' => __( 'Products' ),
'active' => true,
'fields' => [
[
'type' => 'multiselect',
'name' => 'products',
'options' => Helper::toJsOptions( Product::get(), [ 'id', 'name' ] ),
'label' => __( 'Select Products' ),
'value' => $entry instanceof Coupon ? $entry->products->map( fn( $product ) => $product->product_id )->toArray() : [],
'description' => __( 'The following products will be required to be present on the cart, in order for this coupon to be valid.' ),
],
],
],
'selected_categories' => [
'label' => __( 'Categories' ),
'active' => false,
'fields' => [
[
'type' => 'multiselect',
'name' => 'categories',
'options' => Helper::toJsOptions( ProductCategory::get(), [ 'id', 'name' ] ),
'label' => __( 'Select Categories' ),
'value' => $entry instanceof Coupon ? $entry->categories->map( fn( $category ) => $category->category_id )->toArray() : [],
'description' => __( 'The products assigned to one of these categories should be on the cart, in order for this coupon to be valid.' ),
],
],
],
'selected_groups' => [
'label' => __( 'Customer Groups' ),
'active' => false,
'fields' => [
[
'type' => 'multiselect',
'name' => 'groups',
'options' => CustomerGroup::get( [ 'name', 'id' ] )->map( fn( $group ) => [
label: __( 'Type' ),
value: $entry->type ?? '',
description: __( 'Define which type of discount apply to the current coupon.' ),
),
FormInput::text(
label: __( 'Discount Value' ),
name: 'discount_value',
description: __( 'Define the percentage or flat value.' ),
value: $entry->discount_value ?? '',
),
FormInput::datetime(
label: __( 'Valid Until' ),
name: 'valid_until',
description: __( 'Determine Until When the coupon is valid.' ),
value: $entry->valid_until ?? '',
),
FormInput::number(
label: __( 'Minimum Cart Value' ),
name: 'minimum_cart_value',
description: __( 'What is the minimum value of the cart to make this coupon eligible.' ),
value: $entry->minimum_cart_value ?? '',
),
FormInput::text(
label: __( 'Maximum Cart Value' ),
name: 'maximum_cart_value',
description: __( 'The value above which the current coupon can\'t apply.' ),
value: $entry->maximum_cart_value ?? '',
),
FormInput::datetime(
label: __( 'Valid Hours Start' ),
name: 'valid_hours_start',
description: __( 'Define form which hour during the day the coupons is valid.' ),
value: $entry->valid_hours_start ?? '',
),
FormInput::datetime(
label: __( 'Valid Hours End' ),
name: 'valid_hours_end',
description: __( 'Define to which hour during the day the coupons end stop valid.' ),
value: $entry->valid_hours_end ?? '',
),
FormInput::number(
label: __( 'Limit Usage' ),
name: 'limit_usage',
description: __( 'Define how many time a coupons can be redeemed.' ),
value: $entry->limit_usage ?? '',
),
)
),
CrudForm::tab(
identifier: 'selected_products',
label: __( 'Products' ),
fields: CrudForm::fields(
FormInput::multiselect(
name: 'products',
options: Helper::toJsOptions( Product::get(), [ 'id', 'name' ] ),
label: __( 'Select Products' ),
value: $entry instanceof Coupon ? $entry->products->map( fn( $product ) => $product->product_id )->toArray() : [],
description: __( 'The following products will be required to be present on the cart, in order for this coupon to be valid.' ),
),
)
),
CrudForm::tab(
identifier: 'selected_categories',
label: __( 'Categories' ),
fields: CrudForm::fields(
FormInput::multiselect(
name: 'categories',
options: Helper::toJsOptions( ProductCategory::get(), [ 'id', 'name' ] ),
label: __( 'Select Categories' ),
value: $entry instanceof Coupon ? $entry->categories->map( fn( $category ) => $category->category_id )->toArray() : [],
description: __( 'The products assigned to one of these categories should be on the cart, in order for this coupon to be valid.' ),
),
)
),
CrudForm::tab(
identifier: 'selected_groups',
label: __( 'Customer Groups' ),
fields: CrudForm::fields(
FormInput::multiselect(
name: 'groups',
options: CustomerGroup::get( [ 'name', 'id' ] )->map( fn( $group ) => [
'label' => $group->name,
'value' => $group->id,
] ),
'label' => __( 'Assigned To Customer Group' ),
'description' => __( 'Only the customers who belongs to the selected groups will be able to use the coupon.' ),
'value' => $entry instanceof Coupon ? $entry->groups->map( fn( $group ) => $group->group_id )->toArray() : [],
],
],
],
'selected_customers' => [
'label' => __( 'Customers' ),
'active' => false,
'fields' => [
[
'type' => 'multiselect',
'name' => 'customers',
'options' => Customer::get( [ 'first_name', 'id' ] )->map( fn( $customer ) => [
'label' => $customer->first_name,
'value' => $customer->id,
] ),
'label' => __( 'Assigned To Customers' ),
'description' => __( 'Only the customers selected will be ale to use the coupon.' ),
'value' => $entry instanceof Coupon ? $entry->customers->map( fn( $customer ) => $customer->customer_id )->toArray() : [],
],
],
],
],
];
label: __( 'Assigned To Customer Group' ),
description: __( 'Only the customers who belongs to the selected groups will be able to use the coupon.' ),
value: $entry instanceof Coupon ? $entry->groups->map( fn( $group ) => $group->group_id )->toArray() : [],
),
)
),
)
);
}

/**
Expand Down

0 comments on commit 41cd457

Please sign in to comment.