Stock - Stock movement Qty Sum per product

Hello,
Hello ,
Pls like i stated earlier, walking around finding out the qty that was sold or moved in the course of selling is to be determined. i found a way around it, but it has a shortcoming which i dont know if anyone is willing to help resolve.

I went to Products tab, selected stock movement and filtered using date criteria and under direction i selected “stock decrease”. This gave the result we were looking for as we could do so per location (already created under list of warehouses).

The challenge now is it brings out each transaction as it should be anyways to track the movement, so we want a situation where the qty of products are tied to each product. See example below:

if the movement thru sales(Stock Decrease) for Product Blue Pen is done by 3 different customers, it will return -
Product Customer Qty
Blue pen Charles - 35
Blue pen Tony - 15
Blue pen Nelly - 50

We now ant to create another Stock movement file say (stockmovementsummary.php) with the same function but now grouped by product under the selected location under review. This means we select the location we want to consider from the warehouse list, select stock movement tab if we want to see the detail movement by each stock decrease or select stockmovementsummary tab if we want to see the sum of qty moved grouped by product. See below example from the above example: If you notice, customer was exempted…

Product Qty
Blue Pen - 100

We have access to the code file (movement_list.php) we need to change the query that generates the individual transaction to now generate the group by action, by so doing we have the 1st and the 2nd.

Any assistance? Find attached the file that generates the stock movement output
product/stock/movement_list.php

Possible code that can give the solution

$sql = "SELECT p.ref as product_ref, SUM(m.value) as total_quantity_moved";
$sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
$sql .= " JOIN ".MAIN_DB_PREFIX."product as p ON m.fk_product = p.rowid";
$sql .= " GROUP BY p.ref";

// Execute the new SQL query
$resql = $db->query($sql);
if ($resql) {
    $num = $db->num_rows($resql);
    $i = 0;
    while ($i < $num) {
        $obj = $db->fetch_object($resql);
        // Output the product reference and the total quantity moved
        echo 'Product: ' . $obj->product_ref . ' - Total Quantity Moved: ' . $obj->total_quantity_moved . '<br>';
        $i++;
    }
}

Pls kindly assist

Thank you

Hello @ksar, @Sven ,

Please from the above, can you render a guide as to achieve this?