1

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

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

这是我的代码:

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) 个产品。

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

4

1 回答 1

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

希望这对其他人有帮助。

于 2016-02-06T20:07:05.660 回答