Skip to content

Commit 7899217

Browse files
committed
Merge branch 'master' of https://github.com/blair2004/NexoPOS
2 parents 808f3aa + 5f242a2 commit 7899217

File tree

288 files changed

+5876
-3170
lines changed

Some content is hidden

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

288 files changed

+5876
-3170
lines changed

app/Console/Commands/DoctorCommand.php

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class DoctorCommand extends Command
2323
{--fix-domains}
2424
{--fix-orphan-orders-products}
2525
{--fix-transactions-orders}
26+
{--set-unit-visibility=}
27+
{--products=}
2628
{--fix-duplicate-options}';
2729

2830
/**
@@ -93,6 +95,13 @@ public function handle()
9395
return $doctorService->clearTemporaryFiles();
9496
}
9597

98+
if ( $this->option( 'set-unit-visibility' ) ) {
99+
return $doctorService->setUnitVisibility(
100+
products: $this->option( 'products' ),
101+
visibility: $this->option( 'set-unit-visibility' )
102+
);
103+
}
104+
96105
if ($this->option('fix-orders-products')) {
97106
$products = OrderProduct::where('total_purchase_price', 0)->get();
98107

app/Crud/CustomerCouponHistoryCrud.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getLabels(): array
166166
/**
167167
* Defines the forms used to create and update entries.
168168
*/
169-
public function getForm(?OrderCoupon $entry = null): array
169+
public function getForm(OrderCoupon $entry = null): array
170170
{
171171
return [
172172
// ...

app/Crud/CustomerCrud.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function hook($query): void
179179
* @param object/null
180180
* @return array of field
181181
*/
182-
public function getForm(?Customer $entry = null)
182+
public function getForm(Customer $entry = null)
183183
{
184184
return [
185185
'main' => [

app/Fields/DirectTransactionFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DirectTransactionFields extends FieldsService
1212
{
1313
protected static $identifier = Transaction::TYPE_DIRECT;
1414

15-
public function __construct(?Transaction $transaction = null)
15+
public function __construct(Transaction $transaction = null)
1616
{
1717
$this->fields = Hook::filter('ns-direct-transactions-fields', [
1818
[

app/Fields/EntityTransactionFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EntityTransactionFields extends FieldsService
1313
{
1414
protected static $identifier = Transaction::TYPE_ENTITY;
1515

16-
public function __construct(?Transaction $transaction = null)
16+
public function __construct(Transaction $transaction = null)
1717
{
1818
$this->fields = Hook::filter('ns-direct-transactions-fields', [
1919
[

app/Fields/ProcurementFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ProcurementFields extends FieldsService
99
{
1010
protected static $identifier = 'ns.procurement-fields';
1111

12-
public function get(?Procurement $model = null)
12+
public function get(Procurement $model = null)
1313
{
1414
$name = new \stdClass;
1515
$name->name = 'name';

app/Fields/ReccurringTransactionFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ReccurringTransactionFields extends FieldsService
1212
{
1313
protected static $identifier = Transaction::TYPE_RECURRING;
1414

15-
public function __construct(?Transaction $transaction = null)
15+
public function __construct(Transaction $transaction = null)
1616
{
1717
$this->fields = Hook::filter('ns-direct-transactions-fields', [
1818
[

app/Fields/ResetFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ResetFields extends FieldsService
1111
{
1212
protected static $identifier = 'ns.reset';
1313

14-
public function get(?Unit $model = null)
14+
public function get(Unit $model = null)
1515
{
1616
$this->fields = [
1717
[

app/Fields/ScheduledTransactionFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ScheduledTransactionFields extends FieldsService
1212
{
1313
protected static $identifier = Transaction::TYPE_SCHEDULED;
1414

15-
public function __construct(?Transaction $transaction = null)
15+
public function __construct(Transaction $transaction = null)
1616
{
1717
$this->fields = Hook::filter('ns-scheduled-transactions-fields', [
1818
[

app/Fields/UnitsFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class UnitsFields extends FieldsService
1010
{
1111
protected static $identifier = 'ns.units-fields';
1212

13-
public function get(?Unit $model = null)
13+
public function get(Unit $model = null)
1414
{
1515
$name = new \stdClass;
1616
$name->name = 'name';

app/Fields/UnitsGroupsFields.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class UnitsGroupsFields extends FieldsService
99
{
1010
protected static $identifier = 'ns.units-group-fields';
1111

12-
public function get(?UnitGroup $model = null)
12+
public function get(UnitGroup $model = null)
1313
{
1414
$name = new \stdClass;
1515
$name->name = 'name';

app/Http/Controllers/Dashboard/OrdersController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function deleteOrderProduct($orderId, $productId)
136136
return $this->ordersService->deleteOrderProduct($order, $productId);
137137
}
138138

139-
public function getOrders(?Order $id = null)
139+
public function getOrders(Order $id = null)
140140
{
141141
if ($id instanceof Order) {
142142
$id->load('customer');

app/Services/CoreService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function routeName(string $name): string
7171
* Returns a filtred URL to which
7272
* apply the filter "ns-url" hook.
7373
*/
74-
public function url(?string $url = null): string
74+
public function url(string $url = null): string
7575
{
7676
return url(Hook::filter('ns-url', $url));
7777
}

app/Services/CrudService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ public function getTabsRelations(): array
10921092
return $this->tabsRelations;
10931093
}
10941094

1095-
public static function table(array $config = [], ?string $title = null, ?string $description = null, ?string $src = null, ?string $createUrl = null, ?array $queryParams = null): ContractView
1095+
public static function table(array $config = [], string $title = null, string $description = null, string $src = null, string $createUrl = null, array $queryParams = null): ContractView
10961096
{
10971097
$className = get_called_class();
10981098
$instance = new $className;

app/Services/CurrencyService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function get()
196196
/**
197197
* return a raw value for the provided number
198198
*/
199-
public function getRaw(float|null|BigDecimal $value = null): float
199+
public function getRaw(float|BigDecimal $value = null): float
200200
{
201201
if ($value === null) {
202202
return $this->value->dividedBy(1, $this->decimal_precision, RoundingMode::HALF_UP)->toFloat();

app/Services/CustomerService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ public function updateCustomerOwedAmount(Customer $customer)
653653
* @param array $group
654654
* @return array $response
655655
*/
656-
public function createGroup($fields, ?CustomerGroup $group = null)
656+
public function createGroup($fields, CustomerGroup $group = null)
657657
{
658658
if ($group === null) {
659659
$group = CustomerGroup::where('name', $fields[ 'name' ])->first();

app/Services/DoctorService.php

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\Option;
99
use App\Models\Order;
1010
use App\Models\OrderProduct;
11+
use App\Models\ProductUnitQuantity;
1112
use App\Models\Role;
1213
use App\Models\TransactionHistory;
1314
use App\Models\User;
@@ -265,4 +266,27 @@ public function clearBrokenModuleLinks(): array
265266
),
266267
];
267268
}
269+
270+
public function setUnitVisibility( string $products, bool $visibility)
271+
{
272+
$products = explode(',', $products);
273+
274+
if ( $products[ 0 ] === 'all' ) {
275+
$products = ProductUnitQuantity::get()->pluck('product_id');
276+
}
277+
278+
$this->command->info(sprintf(
279+
__('%s products will be updated'),
280+
count($products)
281+
));
282+
283+
$this->command->withProgressBar($products, function ($product) use ( $visibility ) {
284+
$product = ProductUnitQuantity::where('product_id', $product)->first();
285+
286+
if ( $product instanceof ProductUnitQuantity ) {
287+
$product->visible = $visibility;
288+
$product->save();
289+
}
290+
});
291+
}
268292
}

app/Services/ModulesService.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function loadModuleFile(string $namespace, string $file): mixed
8282
*
8383
* @param string path to load
8484
*/
85-
public function load(?string $dir = null): void
85+
public function load(string $dir = null): void
8686
{
8787
/**
8888
* If we're not loading a specific module directory
@@ -332,7 +332,7 @@ public function triggerServiceProviders(array $config, string $method, string|bo
332332
* Will check for a specific module or all the module
333333
* enabled if there is a dependency error.
334334
*/
335-
public function dependenciesCheck(?array $module = null): void
335+
public function dependenciesCheck(array $module = null): void
336336
{
337337
if ($module === null) {
338338
collect($this->getEnabled())->each(function ($module) {

app/Services/NotificationService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class NotificationService
3333
/**
3434
* @param array $config [ 'title', 'url', 'identifier', 'source', 'dismissable', 'description' ]
3535
*/
36-
public function create(string|array $title, string $description = '', string $url = '#', ?string $identifier = null, string $source = 'system', bool $dismissable = true)
36+
public function create(string|array $title, string $description = '', string $url = '#', string $identifier = null, string $source = 'system', bool $dismissable = true)
3737
{
3838
if (is_array($title)) {
3939
extract($title);

app/Services/Options.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function beforeSave(Option $option)
190190
/**
191191
* Get options
192192
**/
193-
public function get(?string $key = null, mixed $default = null)
193+
public function get(string $key = null, mixed $default = null)
194194
{
195195
if ($key === null) {
196196
return $this->rawOptions;

app/Services/OrdersService.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct(
8484
* @param Order|null $order (optional)
8585
* @return array
8686
*/
87-
public function create($fields, ?Order $order = null)
87+
public function create($fields, Order $order = null)
8888
{
8989
$isNew = ! $order instanceof Order;
9090
$customer = $this->__customerIsDefined($fields);
@@ -1223,7 +1223,7 @@ private function __buildOrderProducts($products)
12231223
/**
12241224
* @return SupportCollection $items
12251225
*/
1226-
private function __checkProductStock(SupportCollection $items, ?Order $order = null)
1226+
private function __checkProductStock(SupportCollection $items, Order $order = null)
12271227
{
12281228
$session_identifier = Str::random('10');
12291229

@@ -1303,7 +1303,7 @@ private function __checkProductStock(SupportCollection $items, ?Order $order = n
13031303
* @param array Order Product
13041304
* @return array Order Product (updated)
13051305
*/
1306-
public function __buildOrderProduct(array $orderProduct, ?ProductUnitQuantity $productUnitQuantity = null, ?Product $product = null)
1306+
public function __buildOrderProduct(array $orderProduct, ProductUnitQuantity $productUnitQuantity = null, Product $product = null)
13071307
{
13081308
/**
13091309
* This will calculate the product default field
@@ -1394,7 +1394,7 @@ public function checkQuantityAvailability($product, $productUnitQuantity, $order
13941394
}
13951395
}
13961396

1397-
public function computeProduct($fields, ?Product $product = null, ?ProductUnitQuantity $productUnitQuantity = null)
1397+
public function computeProduct($fields, Product $product = null, ProductUnitQuantity $productUnitQuantity = null)
13981398
{
13991399
$sale_price = ($fields[ 'unit_price' ] ?? $productUnitQuantity->sale_price);
14001400

app/Services/ProductCategoryService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getUsingName($name)
4545
* @param array details
4646
* @return array
4747
*/
48-
public function create($data, ?ProductCategory $productCategory = null)
48+
public function create($data, ProductCategory $productCategory = null)
4949
{
5050
$category = $productCategory === null ? new ProductCategory : $productCategory;
5151
$category->author = Auth::id();

app/Services/ProductService.php

+31-6
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ private function handleStockAdjustmentsForGroupedProducts(
11941194
$orderProductQuantity,
11951195
Product $product,
11961196
Unit $parentUnit,
1197-
?OrderProduct $orderProduct = null): EloquentCollection
1197+
OrderProduct $orderProduct = null): EloquentCollection
11981198
{
11991199
$product->load('sub_items');
12001200

@@ -1386,20 +1386,45 @@ private function handleStockAdjustmentRegularProducts($action, $quantity, $produ
13861386
} elseif (
13871387
in_array($action, [ ProductHistory::ACTION_SET ])
13881388
) {
1389-
$this->setQuantity($product_id, $unit_id, $quantity);
1389+
$currentQuantity = $this->getQuantity(
1390+
product_id: $product_id,
1391+
unit_id: $unit_id
1392+
);
1393+
1394+
if ($currentQuantity < $quantity) {
1395+
$action = ProductHistory::ACTION_ADDED;
1396+
$adjustQuantity = $quantity - $currentQuantity;
1397+
1398+
$this->increaseUnitQuantities(
1399+
product_id: $product_id,
1400+
unit_id: $unit_id,
1401+
quantity: $adjustQuantity,
1402+
oldQuantity: $currentQuantity
1403+
);
1404+
} elseif ($currentQuantity > $quantity) {
1405+
$action = ProductHistory::ACTION_REMOVED;
1406+
$adjustQuantity = $currentQuantity - $quantity;
1407+
1408+
$this->reduceUnitQuantities(
1409+
product_id: $product_id,
1410+
unit_id: $unit_id,
1411+
quantity: $adjustQuantity,
1412+
oldQuantity: $currentQuantity
1413+
);
1414+
}
13901415

13911416
return $this->recordStockHistory(
13921417
product_id: $product_id,
13931418
action: $action,
13941419
unit_id: $unit_id,
13951420
unit_price: $unit_price,
1396-
quantity: $quantity,
1421+
quantity: $adjustQuantity,
13971422
total_price: $total_price,
13981423
procurement_product_id: $procurementProduct?->id ?: null,
13991424
procurement_id: $procurementProduct->procurement_id ?? null,
14001425
order_id: isset($orderProduct) ? $orderProduct->order_id : null,
14011426
order_product_id: isset($orderProduct) ? $orderProduct->id : null,
1402-
old_quantity: $oldQuantity,
1427+
old_quantity: $currentQuantity,
14031428
new_quantity: $quantity
14041429
);
14051430
}
@@ -1670,7 +1695,7 @@ public function deleteAllProducts()
16701695
* Will return the last purchase price
16711696
* defined for the provided product
16721697
*/
1673-
public function getLastPurchasePrice(?Product $product, Unit $unit, ?string $before = null): float|int
1698+
public function getLastPurchasePrice(?Product $product, Unit $unit, string $before = null): float|int
16741699
{
16751700
if ($product instanceof Product) {
16761701
$request = ProcurementProduct::where('product_id', $product->id)
@@ -1836,7 +1861,7 @@ public function generateProductBarcode(Product $product)
18361861
* Convert quantity from a source unit ($from) to a destination unit ($to)
18371862
* using the provided quantity and product.
18381863
*/
1839-
public function convertUnitQuantities(Product $product, Unit $from, float $quantity, Unit $to, ?ProcurementProduct $procurementProduct = null): array
1864+
public function convertUnitQuantities(Product $product, Unit $from, float $quantity, Unit $to, ProcurementProduct $procurementProduct = null): array
18401865
{
18411866
if ($product->stock_management !== Product::STOCK_MANAGEMENT_ENABLED) {
18421867
throw new NotAllowedException(__('You cannot convert unit on a product having stock management disabled.'));

app/Services/TaxService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function getTaxesComputed(string $tax_type, array $rates, float $value):
313313
* compute the tax added to a
314314
* product using a defined tax group id and type.
315315
*/
316-
public function computeTax(ProductUnitQuantity $unitQuantity, ?int $tax_group_id, ?string $tax_type = null): void
316+
public function computeTax(ProductUnitQuantity $unitQuantity, ?int $tax_group_id, string $tax_type = null): void
317317
{
318318
$taxGroup = TaxGroup::find($tax_group_id);
319319

app/Services/TransactionService.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function edit($id, $fields)
9797
*
9898
* @throws NotFoundException
9999
*/
100-
public function get(?int $id = null): Collection|Transaction
100+
public function get(int $id = null): Collection|Transaction
101101
{
102102
if ($id === null) {
103103
return Transaction::get();
@@ -134,7 +134,7 @@ public function delete($id)
134134
* Retreive a specific account type
135135
* or all account type
136136
*/
137-
public function getTransactionAccountByID(?int $id = null)
137+
public function getTransactionAccountByID(int $id = null)
138138
{
139139
if ($id !== null) {
140140
$account = TransactionAccount::find($id);
@@ -355,7 +355,7 @@ public function recordTransactionHistory($transaction)
355355
*
356356
* @return array of process results.
357357
*/
358-
public function handleRecurringTransactions(?Carbon $date = null)
358+
public function handleRecurringTransactions(Carbon $date = null)
359359
{
360360
if ($date === null) {
361361
$date = $this->dateService->copy();

0 commit comments

Comments
 (0)