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

时间:2016-01-17 08:29:21

标签: sugarcrm sugarbean

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

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

这是我的代码:

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]

每个退货行仅售出数量(1)产品。

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

1 个答案:

答案 0 :(得分:1)

好的我明白了!!!!

这是Custom / Module / Opportunities / Views /

中的File 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();
  }
}
?>

希望这会有所帮助。