如何通过循环获得小计。使用 SugarCRM CE 6.5.13

How can I get a subtotal by looping. Using SugarCRM CE 6.5.13

我正在尝试从为所选机会返回的行中获取总数。

选择机会后,他们购买的每个产品都会列出其价格。我正在尝试使用每个购买产品的价格来获得利用该机会进行的所有销售的小计。

这是我的代码:

function total(&$focus, $event, $arguments)
{
    $total = 0;
    foreach ($this->bean->Product_Sales['sales_price_c'] as $entry) {
        $total += unformat_number($entry['sales_price_c']);
    }
    $this->bean->ss->assign('total_sales_c', format_number($total));
}

如何返回行的示例:

[Product_Name_Field] [Product_Price_Field] [Sales_Person_Field] [Etc_Field]

每个返回行仅售出 qty(1) 件产品。

我做错了什么?
提前致谢。

好的,我明白了!!!!

这是 Custom/Module/Opportunities/Views/

中的文件 view.detail.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/MVC/View/views/view.detail.php');

class OpportunitiesViewDetail extends ViewDetail {

  function OpportunitiesViewDetail(){
  parent::ViewDetail();
  }

  function display() {
$account = new Opportunity();//var = new ModuleName() in singular form
$account->retrieve($_REQUEST['record']);//This grabs the record
$contacts = $account->get_linked_beans('opportunities_op_ps_product_sales_1','Contact');
//this uses the get_linked_beans(Param 1 is the linked var name found in the vardefs ,Param 2 is the name of the object you are creating. The name can be anything you like.)

// loop through the created associations to get fields.
foreach ( $contacts as $contact ) {
    $total += $contact->sales_price_c;//add the value of each sale to the variable
}
//populate the field you want with the value in the $total var
echo "
       <script>
    var total = '$total';
       $(document).ready(function(){
    $('#total_sales_c').after(total); });
       </script>";

  parent::display();
  }
}
?>

希望这对其他人有所帮助。