public function addAgreementProductsCalculation(Costbook $costbook, $quantity, $frequency, $optId)
 {
     $tQty = 0;
     $opportunityProduct = new OpportunityProduct();
     $opportunityProduct->Quantity = (double) $quantity;
     $opportunityProduct->Frequency = (double) $frequency;
     $opportunityProduct->name = 'Love Name - ' . $costbook->id;
     //$opportunityProduct->Product = $costbook;
     $tQty = (double) $quantity;
     if ($opportunityProduct->Frequency > 0) {
         $tQty *= $opportunityProduct->Frequency;
     }
     //Labor Product calculation
     if ($costbook->costofgoodssold == 'Labor') {
         $currencies = Currency::getAll();
         $opportunityProduct->Total_MHR = round($costbook->costperunit * $tQty);
         if ($costbook->departmentreference != null) {
             $deptReference = DepartmentReference::GetById(intval($costbook->departmentreference));
             $burdenCost = new CurrencyValue();
             $burdenCost->value = round($deptReference->burdonCost * $tQty, 2);
             $burdenCost->currency = $currencies[0];
             $opportunityProduct->Burden_Cost = $burdenCost;
             $laborCost = new CurrencyValue();
             $laborCost->value = round($deptReference->laborCost * $tQty, 2);
             $laborCost->currency = $currencies[0];
             $opportunityProduct->Labor_Cost = $laborCost;
         }
     }
     $opportunityProduct->Category_GPM = 40;
     $totalDirectCost = new CurrencyValue();
     $totalDirectCost->value = round($opportunityProduct->Labor_Cost->value + $opportunityProduct->Burden_Cost->value, 2);
     $totalDirectCost->currency = $currencies[0];
     $opportunityProduct->Total_Direct_Cost = $totalDirectCost;
     $finalCost = new CurrencyValue();
     $finalCost->value = round($opportunityProduct->Total_Direct_Cost->value / (1 - $opportunityProduct->Category_GPM / 100), 2);
     $finalCost->currency = $currencies[0];
     $opportunityProduct->Final_Cost = $finalCost;
     $opportunityProduct->opportunity = $opportunity = Opportunity::GetById(intval($optId));
     $opportunityProduct->save();
 }