AnsweredAssumed Answered

Logic Hooks, Math calculation problem??

Question asked by YellowTulips YellowTulips on Aug 6, 2015
Latest reply on Aug 7, 2015 by YellowTulips YellowTulips
Hello community members,

I am currently working on a redemption module and I am facing some issues with my Logic Hooks.

6.5.21 CE running on Local machine using Xampp, PHP Version 5.6.11

Code:
<?php
    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class RedemptionLogicHook
    {
        function after_save_method($bean, $event, $arguments)
        {
               $varContactId = $bean->contact_id_c;

               $QueryPoints = $GLOBALS['db'] -> query("
            SELECT 'points_c'
            FROM 'contacts_cstm'
            WHERE 'id_c' = '".$varContactId."'
            LIMIT 0,1;");

               $varProductId = $bean->produ_products_id_c;

               $QueryCost = $GLOBALS['db'] -> query("
            SELECT 'cost'
            FROM 'produ_products'
            WHERE 'id' = '".$varProductId."'
            LIMIT 0,1;");

               if ($QueryPoints >= $QueryCost)
               {
                    $ResultPoints = $QueryPoints - $QueryCost;
                    $queryResult = $GLOBALS['db'] -> query("
                UPDATE 'contacts_cstm'
                SET 'points_c' = '".$ResultPoints."'
                WHERE 'id_c' = '".$varContactId."';");            }
            }
    }
?>
         
Overview of what I am trying to accomplish here, Click to enlarge:



Example: I have an integer of 50 in 'points_c' and the 'cost' of item1 is 10, After saving my 'points_c' became 0 when it supposed to be 40.

I always end up with value 0 for 'points_c' in 'contacts_cstm'

I am not sure which part of the code is preventing me from getting the correct results I want, please help!

Any helpful tips would be appreciated, thank you in advanced!

Outcomes