Skip to content

Commit

Permalink
Merge pull request #1939 from Blair2004/v5.0.x
Browse files Browse the repository at this point in the history
V5.0.x
  • Loading branch information
Blair2004 authored Jun 13, 2024
2 parents f117fe5 + 85d4af1 commit a141d9f
Show file tree
Hide file tree
Showing 220 changed files with 9,658 additions and 8,785 deletions.
2 changes: 1 addition & 1 deletion app/Classes/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public static function fresh( $amount ): CurrencyService

public static function raw( $amount )
{
return ns()->currency->getRaw( $amount );
return ns()->currency->define( $amount )->toFloat();
}
}
5 changes: 5 additions & 0 deletions app/Console/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Services\Helper;
use App\Services\SetupService;
use Illuminate\Console\Command;

Expand Down Expand Up @@ -78,6 +79,10 @@ public function handle()
return $this->error( __( 'Unable to proceed, looks like the database can\'t be used.' ) );
}

if ( Helper::installed() ) {
return $this->error( __( 'NexoPOS is already installed.' ) );
}

$this->setupLanguage();
$this->setupStoreName();
$this->setupAdminUsername();
Expand Down
63 changes: 63 additions & 0 deletions app/Crud/UnitCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Crud;

use App\Classes\CrudForm;
use App\Classes\FormInput;
use App\Models\Unit;
use App\Models\UnitGroup;
use App\Services\CrudEntry;
Expand Down Expand Up @@ -125,6 +127,67 @@ public function isEnabled( $feature ): bool
*/
public function getForm( $entry = null )
{
return CrudForm::form(
main: FormInput::text(
label: __( 'Name' ),
name: 'name',
value: $entry->name ?? '',
description: __( 'Provide a name to the resource.' ),
validation: 'required',
),
tabs: CrudForm::tabs(
CrudForm::tab(
identifier: 'general',
label: __( 'General' ),
fields: CrudForm::fields(
FormInput::text(
label: __( 'Identifier' ),
name: 'identifier',
description: __( 'Provide a unique value for this unit. Might be composed from a name but shouldn\'t include space or special characters.' ),
validation: 'required|unique:' . Hook::filter( 'ns-table-name', 'nexopos_units' ) . ',identifier' . ( $entry !== null ? ',' . $entry->id : '' ),
value: $entry->identifier ?? '',
),
FormInput::media(
label: __( 'Preview URL' ),
name: 'preview_url',
description: __( 'Preview of the unit.' ),
value: $entry->preview_url ?? '',
),
FormInput::text(
label: __( 'Value' ),
name: 'value',
description: __( 'Define the value of the unit.' ),
validation: 'required|numeric',
value: $entry->value ?? '',
),
FormInput::searchSelect(
component: 'nsCrudForm',
props: UnitGroupCrud::getFormConfig(),
name: 'group_id',
validation: 'required',
options: Helper::toJsOptions( UnitGroup::get(), [ 'id', 'name' ] ),
label: __( 'Group' ),
description: __( 'Define to which group the unit should be assigned.' ),
value: $entry->group_id ?? '',
),
FormInput::switch(
name: 'base_unit',
validation: 'required',
options: Helper::kvToJsOptions( [ __( 'No' ), __( 'Yes' ) ] ),
label: __( 'Base Unit' ),
description: __( 'Determine if the unit is the base unit from the group.' ),
value: $entry ? ( $entry->base_unit ? 1 : 0 ) : 0,
),
FormInput::textarea(
label: __( 'Description' ),
name: 'description',
description: __( 'Provide a short description about the unit.' ),
value: $entry->description ?? '',
)
)
)
)
);
return [
'main' => [
'label' => __( 'Name' ),
Expand Down
2 changes: 1 addition & 1 deletion app/Exceptions/NotAllowedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function render( $request )
'title' => __( 'Not Allowed Action' ),
'message' => $this->getMessage(),
'back' => Helper::getValidPreviousUrl( $request ),
] );
], $this->getStatusCode() );
}

return JsonResponse::error(
Expand Down
4 changes: 2 additions & 2 deletions app/Exceptions/NotEnoughPermissionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function render( $request )
'title' => __( 'Not Enough Permissions' ),
'message' => $this->getMessage(),
'back' => Helper::getValidPreviousUrl( $request ),
] );
], 403 );
}

return response()->json( [
'status' => 'error',
'message' => $this->getMessage(),
], 401 );
], 403 );
}
}
1 change: 1 addition & 0 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Middleware;

use App\Services\Helper;
use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
Expand Down
31 changes: 31 additions & 0 deletions app/Listeners/CommandFinishedListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Listeners;

use Illuminate\Console\Events\CommandFinished;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Cache;

class CommandFinishedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle( CommandFinished $event): void
{
/**
* because if we're running the reset from the command line
* we might not have this cache entry deleted. We'll delete it when the reset is done.
*/
Cache::delete( 'ns-core-installed' );
}
}
14 changes: 0 additions & 14 deletions app/Services/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ class Options
{
private $rawOptions = [];

private $options = [];

private $isUserOptions = false;

private $option;

private $user_id;

private $value;

private $hasFound;

private $removableIndex;

public string $tableName;

/**
Expand Down
34 changes: 17 additions & 17 deletions app/Services/OrdersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ public function __saveOrderTaxes( Order $order, $taxes ): float

foreach ( $taxes as $index => $tax ) {
$orderTax = new OrderTax;
$orderTax->tax_name = $tax[ 'tax_name' ];
$orderTax->tax_value = $response[ 'percentages' ][ $index ][ 'tax' ];
$orderTax->tax_name = $tax[ 'name' ];
$orderTax->tax_value = ( $response[ 'percentages' ][ $index ][ 'tax' ] ?? 0 );
$orderTax->rate = $tax[ 'rate' ];
$orderTax->tax_id = $tax[ 'tax_id' ];
$orderTax->order_id = $order->id;
Expand Down Expand Up @@ -918,9 +918,9 @@ private function __checkOrderPayments( $fields, ?Order $order, Customer $custome

$totalPayments = 0;

$subtotal = Currency::raw( collect( $fields[ 'products' ] )->map( function ( $product ) {
$subtotal = ns()->currency->define( collect( $fields[ 'products' ] )->map( function ( $product ) {
return floatval( $product['total_price'] );
} )->sum() );
} )->sum() )->toFloat();

$total = $this->currencyService->define(
$subtotal + $this->__getShippingFee( $fields )
Expand Down Expand Up @@ -1034,13 +1034,13 @@ protected function __computeOrderTotal( $data )
* increase the total with the
* shipping fees and subtract the discounts
*/
$order->total = Currency::fresh( $order->subtotal )
$order->total = Currency::define( $order->subtotal )
->additionateBy( $order->shipping )
->additionateBy(
( $order->tax_type === 'exclusive' ? $order->tax_value : 0 )
)
->subtractBy(
Currency::fresh( $order->total_coupons )
Currency::define( $order->total_coupons )
->additionateBy( $order->discount )
->toFloat()
)
Expand All @@ -1051,7 +1051,7 @@ protected function __computeOrderTotal( $data )
/**
* compute change
*/
$order->change = Currency::fresh( $order->tendered )
$order->change = Currency::define( $order->tendered )
->subtractBy( $order->total )
->toFloat();

Expand All @@ -1060,7 +1060,7 @@ protected function __computeOrderTotal( $data )
*
* @todo not accurate
*/
$order->total_without_tax = Currency::fresh( $order->subtotal )
$order->total_without_tax = Currency::define( $order->subtotal )
->subtractBy( $order->discount )
->subtractBy( $order->total_coupons )
->subtractBy( $order->tax_value )
Expand Down Expand Up @@ -1151,7 +1151,7 @@ private function __saveOrderProducts( $order, $products )

if ( $product[ 'product' ] instanceof Product ) {
$orderProduct->total_purchase_price = $this->currencyService->define(
$product[ 'total_purchase_price' ] ?? Currency::fresh( $this->productService->getCogs(
$product[ 'total_purchase_price' ] ?? Currency::define( $this->productService->getCogs(
product: $product[ 'product' ],
unit: $unit
) )
Expand Down Expand Up @@ -1454,8 +1454,8 @@ public function computeProduct( $fields, ?Product $product = null, ?ProductUnitQ
price: $sale_price
)
)
->multiplyBy( floatval( $fields[ 'quantity' ] ) )
->toFloat();
->multiplyBy( floatval( $fields[ 'quantity' ] ) )
->toFloat();
}

/**
Expand Down Expand Up @@ -1882,7 +1882,7 @@ public function refundSingleProduct( Order $order, OrderRefund $orderRefund, Ord

$productRefund->tax_value = $this->computeTaxFromOrderTaxes(
$order,
Currency::raw( $details[ 'unit_price' ] * $details[ 'quantity' ] ),
Currency::define( $details[ 'unit_price' ] )->multipliedBy( $details[ 'quantity' ] )->toFloat(),
ns()->option->get( 'ns_pos_tax_type' )
);

Expand Down Expand Up @@ -2146,11 +2146,11 @@ public function refreshOrder( Order $order )
/**
* let's refresh all the order values
*/
$order->subtotal = Currency::raw( $productTotal );
$order->subtotal = Currency::define( $productTotal )->toFloat();
$order->total_without_tax = $productPriceWithoutTax;
$order->total_with_tax = $productPriceWithTax;
$order->discount = $this->computeOrderDiscount( $order );
$order->total = Currency::fresh( $order->subtotal )
$order->total = Currency::define( $order->subtotal )
->additionateBy( $orderShipping )
->additionateBy(
( $order->tax_type === 'exclusive' ? $order->tax_value : 0 )
Expand All @@ -2162,7 +2162,7 @@ public function refreshOrder( Order $order )
)
->toFloat();

$order->change = Currency::fresh( $order->tendered )->subtractBy( $order->total )->toFloat();
$order->change = Currency::define( $order->tendered )->subtractBy( $order->total )->toFloat();

$refunds = $order->refunds;

Expand Down Expand Up @@ -2851,11 +2851,11 @@ public function createInstalment( Order $order, $fields )
{
$totalInstalment = $order->instalments->map( fn( $instalment ) => $instalment->amount )->sum();

if ( Currency::raw( $fields[ 'amount' ] ) <= 0 ) {
if ( Currency::define( $fields[ 'amount' ] )->toFloat() <= 0 ) {
throw new NotAllowedException( __( 'The defined amount is not valid.' ) );
}

if ( Currency::raw( $totalInstalment ) >= $order->total ) {
if ( Currency::define( $totalInstalment )->toFloat() >= $order->total ) {
throw new NotAllowedException( __( 'No further instalments is allowed for this order. The total instalment already covers the order total.' ) );
}

Expand Down
10 changes: 2 additions & 8 deletions app/Services/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ public function getFromTimeRange( $startDate, $endDate )
/**
* This return the year report
*
* @param string $year
* @param int $year
* @return array $reports
*/
public function getYearReportFor( $year )
public function getYearReportFor( int $year )
{
$date = $this->dateService->now();
$date->year = $year >= 2019 && $year <= 2099 ? $year : 2020; // validate the date
Expand Down Expand Up @@ -455,10 +455,6 @@ public function getProductSalesDiff( $startDate, $endDate, $sort )
$endDate = Carbon::parse( $endDate );
$diffInDays = Carbon::parse( $startDate )->diffInDays( $endDate );

$orderProductTable = Hook::filter( 'ns-model-table', 'nexopos_orders_products' );
$productsTable = Hook::filter( 'ns-model-table', 'nexopos_products' );
$unitstable = Hook::filter( 'ns-model-table', 'nexopos_units' );

if ( $diffInDays > 0 ) {
// check if it's the start and end of the month
$isStartOfMonth = Carbon::parse( $startDate )->startOfMonth()->isSameDay( $startDate );
Expand Down Expand Up @@ -553,8 +549,6 @@ private function getBestRecords( $previousDates, $sort )
{
$orderProductTable = Hook::filter( 'ns-model-table', 'nexopos_orders_products' );
$orderTable = Hook::filter( 'ns-model-table', 'nexopos_orders' );
$productsTable = Hook::filter( 'ns-model-table', 'nexopos_products' );
$unitstable = Hook::filter( 'ns-model-table', 'nexopos_units' );

switch ( $sort ) {
case 'using_quantity_asc':
Expand Down
5 changes: 5 additions & 0 deletions app/Services/SetupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ public function runMigration( $fields )
$this->options->setDefault();
$this->options->set( 'ns_store_language', $configuredLanguage );

/**
* clear all cache
*/
Artisan::call( 'cache:clear' );

/**
* From this moment, new permissions has been created.
* However Laravel gates aren't aware of them. We'll fix this here.
Expand Down
Loading

0 comments on commit a141d9f

Please sign in to comment.