Calculated Column Not Working

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Calculated Column Not Working

Post by AEmpeno » 2021-03-25 15:52

Hello,

Will someone please help me. So, I have this page where users can print the order summary, and on the page, it has all the order items. But for some reason, the last column is not showing the right calculation. Please see the attached pic.

/* grant access to all users who have access to the orders table */
$sales_from = get_sql_from('sales');
if(!$sales_from) exit(error_message('Access denied!', false));

/* get po */
$sales_id = intval($_REQUEST['SalesID']);
if(!$sales_id) exit(error_message('Invalid Sales ID!', false));

/* retrieve orders info */
$sales_info = get_sql_fields('sales');
$res = sql("select {$sales_info} from {$sales_from} and SalesID={$sales_id}", $eo);
if(!($sale = db_fetch_assoc($res))) exit(error_message('Sales not found!', false));

//var_dump($sale);

/* retrieve salesdetails info */
$items = array();
$weight_total = 0;
$item_fields = get_sql_fields('salesdetails');
$item_from = get_sql_from('salesdetails');
$res = sql("select {$item_fields} from {$item_from} and salesdetails.SalesID={$sales_id}", $eo);
while($row = db_fetch_assoc($res)){
$row['Weight'] = str_replace('$', '', $row['NosUnits']) * $row['WU'] ;
$items[] = $row;
$jars_total += $row['Weight'];
}

<tbody>
<?php foreach($items as $i => $item){ ?>
<tr>
<td class="text-center"><?php echo ($i + 1); ?></td>
<td><?php echo $item['LotCode']; ?></td>
<td class="text-right"><?php echo $item['NosUnits']; ?></td>
<td class="text-right"><?php echo $item['WU']; ?></td>
<td class="text-right"><?php echo number_format($item['Weight'], 2); ?></td>
</tr>
<?php } ?>
</tbody>
Attachments
ordersum.png
ordersum.png (179.71 KiB) Viewed 1272 times

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: Calculated Column Not Working

Post by landinialejandro » 2021-03-26 18:33

hi! the problem is the number format.
Instead of multiplying 15000 * 25, you are multiplying 15 * 25. I think I would have to convert string values to numbers.
Use intval() or floatval()
or get de values without format: use * instead {$sales_info}
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Re: Calculated Column Not Working

Post by AEmpeno » 2021-04-01 14:28

Thanks, landinialejandro! I will def try this out. :D

Post Reply