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

行が返される方法の例:

[製品名フィールド] [製品価格フィールド] [販売担当者フィールド] [その他フィールド]

返された行ごとに数量 (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 に答える