Skip to content

Commit

Permalink
Merge pull request #1225 from Blair2004/v4.8.x
Browse files Browse the repository at this point in the history
V4.8.x
  • Loading branch information
nexopos authored Dec 22, 2022
2 parents 3d9ef9b + c6fe5fb commit 5327480
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 113 deletions.
7 changes: 7 additions & 0 deletions app/Console/Commands/ModuleSymlinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Services\ModulesService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class ModuleSymlinkCommand extends Command
{
Expand Down Expand Up @@ -36,6 +37,12 @@ public function handle()
} else {
$modules = $moduleService->get();

/**
* let's clear all existing links
*/
Storage::disk( 'ns' )->deleteDirectory( 'public/modules' );
Storage::disk( 'ns' )->makeDirectory( 'public/modules' );

$this->withProgressBar( $modules, function( $module ) use ( $moduleService ) {
$moduleService->createSymLink( $module[ 'namespace' ] );
});
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ResetCommand extends Command
*
* @var string
*/
protected $signature = 'ns:reset {--mode=soft} {--user=default}';
protected $signature = 'ns:reset {--mode=soft} {--user=default} {--with-sales} {--with-procurements}';

/**
* The console command description.
Expand Down Expand Up @@ -70,8 +70,8 @@ public function handle()
$this->initializeRole();
$this->demoService->run([
'mode' => 'grocery',
'create_sales' => true,
'create_procurements' => true,
'create_sales' => $this->option( 'with-sales' ) && $this->option( 'with-procurements' ) ? true : false,
'create_procurements' => $this->option( 'with-procurements' ) ? true : false,
]);
$this->info( __( 'The demo has been enabled.' ) );
break;
Expand Down
12 changes: 11 additions & 1 deletion app/Models/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

namespace App\Models;

use App\Traits\NsDependable;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Provider extends NsModel
{
use HasFactory;
use HasFactory, NsDependable;

protected $table = 'nexopos_' . 'providers';

protected $guarded = [];

protected $isDependencyFor = [
Procurement::class => [
'local_name' => 'name',
'local_index' => 'id',
'foreign_name' => 'code',
'foreign_index' => 'provider_id',
],
];

public function procurements()
{
return $this->hasMany( Procurement::class );
Expand Down
2 changes: 1 addition & 1 deletion app/Services/DemoCoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function createAccountingAccounts()
'account' => '008',
]);

ns()->option->set( 'ns_customer_debitting_cashflow_account', AccountType::account( '007' )->first()->id );
ns()->option->set( 'ns_customer_debitting_cashflow_account', AccountType::account( '008' )->first()->id );
}

public function createCustomers()
Expand Down
80 changes: 24 additions & 56 deletions app/Services/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public function setDefault( $options = [] ): void
{
Option::truncate();

$types = app()->make( OrdersService::class )->getTypeLabels();

$defaultOptions = [
'ns_registration_enabled' => false,
'ns_store_name' => 'NexoPOS 4.x',
'ns_pos_order_types' => [ 'takeaway', 'delivery' ],
'ns_pos_order_types' => array_keys( $types ),
];

$options = array_merge( $defaultOptions, $options );
Expand Down Expand Up @@ -103,38 +105,7 @@ public function set( $key, $value, $expiration = null )
* it will save the new value and update
* the option object.
*/
$foundOption = collect( $this->rawOptions )->map( function( $option, $index ) use ( $value, $key, $expiration ) {
if ( $key === $index ) {
$this->hasFound = true;

switch ( $value ) {
case is_array( $value ) :
$option->value = json_encode( $value );
break;
case empty( $value ) && ! (bool) preg_match( '/[0-9]{1,}/', $value ) :
$option->value = '';
break;
default:
$option->value = $value;
break;
}

$option->expire_on = $expiration;

/**
* this should be overridable
* from a user option or any
* extending this class
*/
$option = $this->beforeSave( $option );
$option->save();

return $option;
}

return false;
})
->filter();
$foundOption = collect( $this->rawOptions )->filter( fn( $option, $index ) => $index === $key );

/**
* if the option hasn't been found
Expand All @@ -143,33 +114,30 @@ public function set( $key, $value, $expiration = null )
*/
if ( $foundOption->isEmpty() ) {
$option = new Option;
$option->key = trim( strtolower( $key ) );
$option->array = false;

switch ( $value ) {
case is_array( $value ) :
$option->value = json_encode( $value );
break;
case empty( $value ) && ! (bool) preg_match( '/[0-9]{1,}/', $value ) :
$option->value = '';
break;
default:
$option->value = $value;
break;
}
} else {
$option = $foundOption->first();
}

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

/**
* this should be overridable
* from a user option or any
* extending this class
*/
$option = $this->beforeSave( $option );
$option->save();
if ( is_array( $value ) ) {
$option->value = json_encode( $value );
} else if ( empty( $value ) && ! (bool) preg_match( '/[0-9]{1,}/', $value ) ) {
$option->value = '';
} else {
$option = $foundOption->first();
$option->value = $value;
}

$option->expire_on = $expiration;

/**
* this should be overridable
* from a user option or any
* extending this class
*/
$option = $this->beforeSave( $option );
$option->save();

/**
* Let's save the new option
Expand Down
14 changes: 13 additions & 1 deletion app/Services/OrdersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,12 +1032,16 @@ private function __saveOrderProducts($order, $products)
$gross = 0;

$orderProducts = $products->map(function ($product) use (&$subTotal, &$taxes, &$order, &$gross) {

$previousQuantity = 0;

/**
* if the product id is provided
* then we can use that id as a reference.
*/
if ( isset( $product[ 'id' ] ) ) {
$orderProduct = OrderProduct::find( $product[ 'id' ] );
$previousQuantity = $orderProduct->quantity;
} else {
$orderProduct = new OrderProduct;
}
Expand Down Expand Up @@ -1113,7 +1117,15 @@ private function __saveOrderProducts($order, $products)
'total_price' => $orderProduct->total_price,
];

$this->productService->stockAdjustment( ProductHistory::ACTION_SOLD, $history );
/**
* __deleteUntrackedProducts will delete all products that
* already exists and which are edited. We'll here only records
* products that doesn't exists yet.
*/
if ( $orderProduct->wasRecentlyCreated ) {
$this->productService->stockAdjustment( ProductHistory::ACTION_SOLD, $history );
}

}

event( new OrderProductAfterSavedEvent( $orderProduct, $order, $product ) );
Expand Down
15 changes: 9 additions & 6 deletions app/Services/ProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,17 @@ public function cancelPaymentForProcurement( Procurement $procurement )
{
$provider = Provider::find( $procurement->provider_id );

if ( $procurement->payment_status === 'paid' ) {
$provider->amount_paid -= $procurement->cost;
} else {
$provider->amount_due -= $procurement->cost;
if ( $provider instanceof Provider ) {

if ( $procurement->payment_status === 'paid' ) {
$provider->amount_paid -= $procurement->cost;
} else {
$provider->amount_due -= $procurement->cost;
}

$provider->save();
}

$provider->save();

return [
'status' => 'succecss',
'message' => __( 'The procurement payment has been deducted.' ),
Expand Down
2 changes: 2 additions & 0 deletions app/Services/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class Setup
{
public Options $options;

/**
* Attempt database and save db informations
*
Expand Down
2 changes: 1 addition & 1 deletion config/nexopos.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'version' => '4.8.10',
'version' => '4.8.11',
'languages' => [
'en' => 'English',
'fr' => 'Français',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="">{{ $product->name }} (x{{ $product->quantity }})</span>
<br>
<span class="text-xs text-gray-600">{{ $product->unit->name }}</span>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
use App\Models\Order;
use App\Classes\Hook;
use Illuminate\Support\Facades\View;
?>
<div class="w-full h-full">
<div class="w-full md:w-1/2 lg:w-1/3 shadow-lg bg-white p-2 mx-auto">
Expand Down Expand Up @@ -33,9 +35,8 @@
@foreach( Hook::filter( 'ns-receipt-products', $order->combinedProducts ) as $product )
<tr>
<td colspan="2" class="p-2 border-b border-gray-700">
<span class="">{{ $product->name }} (x{{ $product->quantity }})</span>
<br>
<span class="text-xs text-gray-600">{{ $product->unit->name }}</span>
<?php $productName = View::make( 'pages.dashboard.orders.templates._product-name', compact( 'product' ) );?>
<?php echo Hook::filter( 'ns-receipt-product-name', $productName->render(), $product );?>
</td>
<td class="p-2 border-b border-gray-800 text-right">{{ ns()->currency->define( $product->total_price ) }}</td>
</tr>
Expand Down
Loading

0 comments on commit 5327480

Please sign in to comment.