From 9508770f47a29622234fbbb88a2ed9b9a6b2e846 Mon Sep 17 00:00:00 2001 From: WShells <26513147+WebShells@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:48:01 +0300 Subject: [PATCH] Fix for Serialnumber & Discount Type ($discount_type) must be of type int ($serialnumber) must be of type string --- app/Controllers/Receivings.php | 2 +- app/Libraries/Receiving_lib.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Controllers/Receivings.php b/app/Controllers/Receivings.php index 7ba0114c1..fc8434618 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -193,7 +193,7 @@ class Receivings extends Secure_Controller $raw_receiving_quantity = prepare_decimal($this->request->getPost('receiving_quantity')); $description = $this->request->getPost('description', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: Duplicated code - $serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_FULL_SPECIAL_CHARS); + $serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? ''; $price = filter_var($raw_price, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $quantity = filter_var($raw_quantity, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $discount_type = $this->request->getPost('discount_type', FILTER_SANITIZE_NUMBER_INT); diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index 19a85e5d0..0ba824401 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -404,7 +404,7 @@ class Receiving_lib * @param float $receiving_quantity * @return bool */ - public function edit_item($line, string $description, string $serialnumber, float $quantity, float $discount, int $discount_type, float $price, float $receiving_quantity): bool + public function edit_item($line, string $description, string $serialnumber, float $quantity, float $discount, ?int $discount_type, float $price, float $receiving_quantity): bool { $items = $this->get_cart(); if(isset($items[$line])) @@ -416,7 +416,7 @@ class Receiving_lib $line['receiving_quantity'] = $receiving_quantity; $line['discount'] = $discount; - if(!is_null($discount_type)) //TODO: $discount_type is an int which means it will never be null and this if statement will always evaluate to true. + if(!is_null($discount_type)) { $line['discount_type'] = $discount_type; } @@ -526,7 +526,7 @@ class Receiving_lib * @param float $receiving_quantity * @return string */ - public function get_item_total(float $quantity, float $price, float $discount, int $discount_type, float $receiving_quantity): string + public function get_item_total(float $quantity, float $price, float $discount, ?int $discount_type, float $receiving_quantity): string { $extended_quantity = bcmul($quantity, $receiving_quantity); $total = bcmul($extended_quantity, $price);