From b593de9f83bc83d6303d6ff1f715bb7f5b2bfb9b Mon Sep 17 00:00:00 2001 From: objecttothis Date: Tue, 16 Apr 2024 16:16:56 +0400 Subject: [PATCH] Receivings Bugfixes - Fixed incorrect variable name - Return empty string on null - Added return types for mixed return functions Signed-off-by: objecttothis --- app/Libraries/Receiving_lib.php | 4 ++-- app/Models/Item_quantity.php | 8 ++++---- app/Models/Receiving.php | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index aead88c5c..19a85e5d0 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -172,9 +172,9 @@ class Receiving_lib /** * @return string|null */ - public function get_reference(): ?string + public function get_reference(): string { - return $this->session->get('recv_reference'); + return $this->session->get('recv_reference') ?? ''; } /** diff --git a/app/Models/Item_quantity.php b/app/Models/Item_quantity.php index 0a44294ba..f80734db0 100644 --- a/app/Models/Item_quantity.php +++ b/app/Models/Item_quantity.php @@ -56,10 +56,10 @@ class Item_quantity extends Model /** * @param int $item_id * @param int $location_id - * @return array|object|stdClass|null + * @return array|Item_quantity|null */ - public function get_item_quantity(int $item_id, int $location_id) - { + public function get_item_quantity(int $item_id, int $location_id): array|Item_quantity|StdClass|null + { $builder = $this->db->table('item_quantities'); $builder->where('item_id', $item_id); $builder->where('location_id', $location_id); @@ -68,7 +68,7 @@ class Item_quantity extends Model if(empty($result)) { //Get empty base parent object, as $item_id is NOT an item - $result = new stdClass(); + $result = model(Item_quantity::class); //Get all the fields from items table (TODO: to be reviewed) foreach($this->db->getFieldNames('item_quantities') as $field) diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index d772f0274..0f99b6f14 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -138,7 +138,7 @@ class Receiving extends Model foreach($items as $line => $item_data) { $config = config(OSPOS::class)->settings; - $cur_item_info = $item->get_info($item['item_id']); + $cur_item_info = $item->get_info($item_data['item_id']); $receivings_items_data = [ 'receiving_id' => $receiving_id, @@ -166,9 +166,9 @@ class Receiving extends Model } //Update stock quantity - $item_quantity = $item_quantity->get_item_quantity($item['item_id'], $item['item_location']); + $item_quantity_value = $item_quantity->get_item_quantity($item_data['item_id'], $item_data['item_location']); $item_quantity->save_value([ - 'quantity' => $item_quantity->quantity + $items_received, + 'quantity' => $item_quantity_value->quantity + $items_received, 'item_id' => $item_data['item_id'], 'location_id' => $item_data['item_location']], $item_data['item_id'], @@ -180,7 +180,7 @@ class Receiving extends Model 'trans_date' => date('Y-m-d H:i:s'), 'trans_items' => $item_data['item_id'], 'trans_user' => $employee_id, - 'trans_location' => $item['item_location'], + 'trans_location' => $item_data['item_location'], 'trans_comment' => $recv_remarks, 'trans_inventory' => $items_received ];