2015-11-23 82 views
1

我已在自定義模塊上創建計算字段。所以基本上,這個模塊總計了每個銷售所做的所有發票總計。計算字段是分配給用戶的所有發票的總和。我已經對細節視圖及其工作進行了計算。現在,我想在計算器上顯示計算的字段。這裏是我的截圖:在SuiteCRM Dashlet上顯示計算字段

dashlet

正如你可以看到,目前的銷售欄爲空白。它應該填寫顯示銷售名稱的發票總額的整數值。我已經使用suitecrm studio &模塊構建器創建了模塊,字段和佈局。我如何在計算器上顯示計算的字段?

這裏是顯示詳細信息頁面上計算字段的功能和它已經工作,但是它不上dashlet或ListView工作:

public function preDisplay(){ 
    //$this->bean contains all the information on the Case 
    //use that information to grab the related account bean, something like: 
    //date format still error here 

    $a = new AOS_Invoices(); 
    $validFromFormatted = date_create_from_format('m/d/Y', $this->bean->valid_from); 
    $validToFormatted = date_create_from_format('m/d/Y', $this->bean->valid_through); 
    $arr = $a->get_full_list(null,'(aos_invoices.assigned_user_id = \''.$this->bean->user_id_c.'\' and invoice_date between \''.date_format($validFromFormatted,'Y-m-d').'\' and \''.date_format($validToFormatted,'Y-m-d').'\')'); 


    $sum = 0; 
    foreach($arr as $key=>$value){ 
     if(isset($value->total_amount)) 
      $sum += $value->total_amount; 
    } 

    $this->bean->current_sales = $sum; 
    parent::preDisplay(); 
} 

回答

1

而是創建自定義dashlet的。您可以改爲創建報告。添加您想要顯示的字段。添加總金額字段,然後設置總功能。您可以按銷售名稱進行分組。

在您的主屏幕上,添加報表dashlet,選擇編輯按鈕,然後選擇剛纔創建的報表。

0

添加一個邏輯鉤子(before_save),它將在保存記錄時計算該字段,然後將其保存在同一個模塊中。

一旦你在同一個模塊中有字段,那麼就像正常字段一樣添加小方塊。

使用這種邏輯的優點:

  1. 降低住房頁面加載負荷,因爲有相當多的其它模塊,以及需要被加載。
  2. 沒有深入的定製,所以非常多的升級安全和友好。