I have a table where are orders and table with orderrows and I need to fetch prices for both tables. I already have successfully fetched prices to orderrows, but I can't figure out how to sum up the row prices from $WMSOLPrices and add the value to variable $WMSOrderPrice. Any help? I know there are many other questions about the same problem, but I haven't got any help on those.
<?php
$WMSOrderLines = \WMS\Orders\OrdersDataMapper::getWMSLinesData($_REQUEST['id']);
$WMSOLPrices = array();
$WMSOrderPrice = 0; // how to add sum from orderrow prices to this variable?
$sql = 'select wo.id as wms_orders_id, wl.id as wms_lines_id, tca.row_price as price from tms_cost_allocation tca, wms_orders wo, wms_lines wl where wo.id = :wms_orders_id and wo.id = wl.wms_orders_id and wl.quantity_packed > 0 and wl.order_lines_id = tca.order_lines_id and tca.row_price > 0';
try {
$query = DBCon::get(true)->prepare($sql);
$query->bindValue(":wms_orders_id", $WMSOrder->id, PDO::PARAM_INT);
$query->execute();
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$WMSOLPrices[$row['wms_lines_id']] = $row;
}
}
catch (PDOException $e) {
ScriptNotification::logError("Exception while getting prices ",$e);
}
?>
<h1>Toimitustilaus</h1>
<h2>Toimitustilaus</h2>
<div style="padding-bottom: 10px;">
<table class="admin-table">
<thead class="admin-table-header">
<tr>
<th>Toimitustilaus</th>
<th>Rahtihinta</th>
</tr>
</thead>
<tbody class="admin-table-body">
<tr>
<td>
<?php echo $WMSOrder->id; ?>
<td>
<?php echo $WMSOrderPrice; ?>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Toimitustilauksen rivit</h2>
<div style="padding-bottom: 10px;">
<table class="admin-table">
<thead class="admin-table-header">
<tr>
<th>Toimitusrivi</th>
<th>Tilausrivi</th>
<th>Rivihinta</th>
</tr>
</thead>
<tbody class="admin-table-body">
<?php foreach($WMSOrderLines as $WMSLine) { ?>
<tr>
<td><?php echo $WMSLine->id; ?></td>
<td><?php echo $WMSLine->order_lines_id; ?></td>
<td><?php if(isset($WMSOLPrices[$WMSLine->id])) { echo $WMSOLPrices[$WMSLine->id]['price']; }?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
}`