Skip to content

Commit

Permalink
Merge pull request #1411 from Blair2004/v4.8.x
Browse files Browse the repository at this point in the history
V4.8.x
  • Loading branch information
Blair2004 committed Apr 3, 2023
2 parents 7e51e77 + 6dfb0d7 commit 67a6460
Show file tree
Hide file tree
Showing 54 changed files with 1,448 additions and 680 deletions.
2 changes: 1 addition & 1 deletion app/Crud/CustomerAccountCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function __construct()
public function hook( $query ): void
{
$query->orderBy( 'id', 'desc' );
$query->where( 'nexopos_customers_account_history.customer_id', request()->query( 'customer_id' ) );
$query->where( Hook::filter( 'ns-model-table', 'nexopos_customers_account_history.customer_id' ), request()->query( 'customer_id' ) );
}

public function addFooterSummary( CrudBeforeExportEvent $event )
Expand Down
24 changes: 12 additions & 12 deletions app/Crud/ExpenseCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ public function getForm( $entry = null )
'value' => 'x_after_month_starts',
],
],
'name' => 'occurence',
'name' => 'occurrence',
'label' => __( 'Occurrence' ),
'description' => __( 'Define how often this expenses occurs' ),
'value' => $entry->occurence ?? '',
'value' => $entry->occurrence ?? '',
], [
'type' => 'text',
'name' => 'occurence_value',
'name' => 'occurrence_value',
'label' => __( 'Occurrence Value' ),
'description' => __( 'Must be used in case of X days after month starts and X days before month ends.' ),
'value' => $entry->occurence_value ?? '',
'value' => $entry->occurrence_value ?? '',
], [
'type' => 'textarea',
'name' => 'description',
Expand Down Expand Up @@ -406,7 +406,7 @@ public function getColumns()
'$direction' => '',
'$sort' => false,
],
'occurence' => [
'occurrence' => [
'label' => __( 'Occurrence' ),
'$direction' => '',
'$sort' => false,
Expand All @@ -432,18 +432,18 @@ public function setActions( CrudEntry $entry, $namespace )
$entry->value = (string) ns()->currency->value( $entry->value );
$entry->recurring = (bool) $entry->recurring ? __( 'Yes' ) : __( 'No' );

switch ( $entry->occurence ) {
case 'month_start' : $entry->occurence = __( 'Month Starts' );
switch ( $entry->occurrence ) {
case 'month_start' : $entry->occurrence = __( 'Month Starts' );
break;
case 'month_mid' : $entry->occurence = __( 'Month Middle' );
case 'month_mid' : $entry->occurrence = __( 'Month Middle' );
break;
case 'month_end' : $entry->occurence = __( 'Month Ends' );
case 'month_end' : $entry->occurrence = __( 'Month Ends' );
break;
case 'x_after_month_starts' : $entry->occurence = __( 'X Days Before Month Starts' );
case 'x_after_month_starts' : $entry->occurrence = __( 'X Days Before Month Starts' );
break;
case 'x_before_month_ends' : $entry->occurence = __( 'X Days Before Month Ends' );
case 'x_before_month_ends' : $entry->occurrence = __( 'X Days Before Month Ends' );
break;
default: $entry->occurence = __( 'Unknown Occurrence' );
default: $entry->occurrence = __( 'Unknown Occurrence' );
break;
}

Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/Dashboard/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ public function orderInvoice( Order $order )

$order->products = Hook::filter( 'ns-receipt-products', $order->products );

$order->paymentStatus = $this->ordersService->getPaymentLabel( $order->payment_status );
$order->deliveryStatus = $this->ordersService->getPaymentLabel( $order->delivery_status );

return $this->view( 'pages.dashboard.orders.templates.invoice', [
'order' => $order,
'options' => $optionsService->get(),
Expand All @@ -244,7 +247,7 @@ public function orderInvoice( Order $order )

public function orderRefundReceipt( OrderRefund $refund )
{
$refund->load( 'order.customer', 'order.refundedProducts', 'order.refund.author', 'order.shipping_address', 'order.billing_address', 'order.user' );
$refund->load( 'order.customer', 'order.refundedProducts', 'order.refunds.author', 'order.shipping_address', 'order.billing_address', 'order.user' );
$refund->load( 'refunded_products.product', 'refunded_products.unit' );

$refund->refunded_products = Hook::filter( 'ns-refund-receipt-products', $refund->refunded_products );
Expand Down
8 changes: 0 additions & 8 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ public function user()
return $this->hasOne( User::class, 'id', 'author' );
}

/**
* @deprecated
*/
public function refund()
{
return $this->hasMany( OrderRefund::class, 'order_id', 'id' );
}

public function refunds()
{
return $this->hasMany( OrderRefund::class, 'order_id', 'id' );
Expand Down
4 changes: 2 additions & 2 deletions app/Models/OrderProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function product()
return $this->hasOne( Product::class, 'id', 'product_id' );
}

public function refunded_product()
public function refunded_products()
{
return $this->hasOne(
return $this->hasMany(
related: OrderProductRefund::class,
foreignKey: 'order_product_id',
localKey: 'id'
Expand Down
25 changes: 17 additions & 8 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Classes\Hook;
use App\Events\ModulesBootedEvent;
use App\Models\Order;
use App\Models\OrderProductRefund;
use App\Models\Permission;
use App\Services\BarcodeService;
use App\Services\CashRegistersService;
Expand Down Expand Up @@ -197,14 +198,15 @@ public function register()

$this->app->bind( OrdersService::class, function( $app ) {
return new OrdersService(
$app->make( CustomerService::class ),
$app->make( ProductService::class ),
$app->make( UnitService::class ),
$app->make( DateService::class ),
$app->make( CurrencyService::class ),
$app->make( Options::class ),
$app->make( TaxService::class ),
$app->make( ReportService::class ),
customerService: $app->make( CustomerService::class ),
productService: $app->make( ProductService::class ),
unitService: $app->make( UnitService::class ),
dateService: $app->make( DateService::class ),
currencyService: $app->make( CurrencyService::class ),
optionsService: $app->make( Options::class ),
taxService: $app->make( TaxService::class ),
reportService: $app->make( ReportService::class ),
mathService: $app->make( MathService::class ),
);
});

Expand Down Expand Up @@ -287,5 +289,12 @@ protected function loadConfiguration()
->mapWithKeys( fn( $type ) => [ $type[ 'identifier' ] => $type[ 'label' ] ])
->toArray(),
]);

config([
'nexopos.orders.products.refunds' => [
OrderProductRefund::CONDITION_DAMAGED => __( 'Damaged' ),
OrderProductRefund::CONDITION_UNSPOILED => __( 'Good Condition' ),
]
]);
}
}
25 changes: 25 additions & 0 deletions app/Services/DemoCoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ public function prepareDefaultUnitSystem()
}
}

public function createBaseSettings()
{
$orderTypes = app()->make( OrdersService::class )->getTypeLabels();

/**
* @var Options $optionService
*/
$optionService = app()->make( Options::class );

$optionService->set(
'ns_pos_order_types',
array_values( $orderTypes )
);

$optionService->set(
'ns_currency_symbol',
'$'
);

$optionService->set(
'ns_currency_iso',
'USD'
);
}

public function createAccountingAccounts()
{
/**
Expand Down
1 change: 1 addition & 0 deletions app/Services/DemoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function run( $data )
*/
extract( $data );

$this->createBaseSettings();
$this->prepareDefaultUnitSystem();
$this->createCustomers();
$this->createAccountingAccounts();
Expand Down
6 changes: 3 additions & 3 deletions app/Services/ExpenseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function handleRecurringExpenses()
->active()
->get()
->map( function( $expense ) {
switch ( $expense->occurence ) {
switch ( $expense->occurrence ) {
case 'month_starts':
$expenseScheduledDate = Carbon::parse( $this->dateService->copy()->startOfMonth() );
break;
Expand All @@ -427,10 +427,10 @@ public function handleRecurringExpenses()
$expenseScheduledDate = Carbon::parse( $this->dateService->copy()->endOfMonth() );
break;
case 'x_before_month_ends':
$expenseScheduledDate = Carbon::parse( $this->dateService->copy()->endOfMonth()->subDays( $expense->occurence_value ) );
$expenseScheduledDate = Carbon::parse( $this->dateService->copy()->endOfMonth()->subDays( $expense->occurrence_value ) );
break;
case 'x_after_month_starts':
$expenseScheduledDate = Carbon::parse( $this->dateService->copy()->startOfMonth()->addDays( $expense->occurence_value ) );
$expenseScheduledDate = Carbon::parse( $this->dateService->copy()->startOfMonth()->addDays( $expense->occurrence_value ) );
break;
}

Expand Down
8 changes: 7 additions & 1 deletion app/Services/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public function build()
**/
public function set( $key, $value, $expiration = null )
{
/**
* We rather like to remove unecessary spaces. That might
* cause unwanted behaviors.
*/
$key = trim( strtolower( $key ) );

/**
* if an option has been found,
* it will save the new value and update
Expand All @@ -118,7 +124,7 @@ public function set( $key, $value, $expiration = null )
$option = $foundOption->first();
}

$option->key = trim( strtolower( $key ) );
$option->key = $key;
$option->array = false;

if ( is_array( $value ) ) {
Expand Down

0 comments on commit 67a6460

Please sign in to comment.