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

如何通过循环得到小计。使用SugarCRM CE 6.5.13,sugarcrm,sugarbean,Sugarcrm,Sugarbean,我正在尝试从所选opportunity返回的行中获取总计 选择opportunity时,会列出他们购买的每种产品及其价格。我试图使用每个购买的产品的价格来获得利用该机会进行的所有销售的小计 以下是我的代码: 函数总数(&$focus、$event、$arguments) { $total=0; foreach($this->bean->Product\u Sales['Sales\u price\u c']作为$entry){ $total+=未格式化编号($entry['sales\U pri

我正在尝试从所选opportunity返回的行中获取总计

选择opportunity时,会列出他们购买的每种产品及其价格。我试图使用每个购买的产品的价格来获得利用该机会进行的所有销售的小计

以下是我的代码:

函数总数(&$focus、$event、$arguments)
{
$total=0;
foreach($this->bean->Product\u Sales['Sales\u price\u c']作为$entry){
$total+=未格式化编号($entry['sales\U price\U c']);
}
$this->bean->ss->assign('total_sales_c',format_number($total));
}
如何返回行的示例:

[产品名称字段][产品价格字段][销售人员字段][等字段]

每个退货行仅销售数量(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();
  }
}
?>

使用该代码会得到什么结果?您需要考虑“数量”吗?我正在尝试计算所有购买的产品的总价值,但装载的opportunity除外。到目前为止我还没有成功,你已经说过了。想试着回答我的问题吗?数量是每种产品的金额。此代码不起作用。每个返回的行只有一个产品销售。请通过xdebug检查变量$this->bean中的内容,或将其内容打印到sugarcrm.log中,例如:$GLOBALS['log']->fatal(“ProductSales”).json_encode($this->bean));把这个贴在这里,我们可以帮你