$services = $contract->get_linked_beans('oqc_service', 'oqc_Service');
                    foreach ($services as $service) {
                        if ($isUniqueServices && 'once' === $service->zeitbezug || !$isUniqueServices && 'once' != $service->zeitbezug) {
                            $productDeleted = true;
                            if (!empty($service->product_id)) {
                                $product = new oqc_Product();
                                if ($product->retrieve($service->product_id, true, true)) {
                                    //2.2RC1 do not retrieve deleted product here
                                    $productDeleted = false;
                                }
                                $updateable = !$product->is_latest && !$productDeleted;
                            } else {
                                $updateable = false;
                            }
                            //check if currency id is correct one
                            $jsonArray[] = array('Id' => $service->id, 'Position' => $service->position, 'Tax' => $service->oqc_vat === '' ? "default" : $service->oqc_vat, 'Name' => $service->name, 'Description' => html_entity_decode($service->description), 'Unit' => $service->unit, 'Price' => getFormattedCurrencyValue($service->price), 'Quantity' => $service->quantity, 'Recurrence' => $service->zeitbezug, 'ProductId' => $productDeleted ? '' : $service->product_id, 'Discount' => $service->discount_select, 'DiscountValue' => $service->discount_value, 'Updateable' => $updateable, 'isSumRow' => false, 'Currency' => $service->service_currency_id ? $service->service_currency_id : "-99");
                        }
                    }
                    // 1.7.7 Do json array reordering according position value
                    usort($jsonArray, 'compare_position');
                }
            }
        }
    }
}
if (array_key_exists('callback', $_REQUEST)) {
    require_once 'include/utils.php';
    $json = getJSONobj();
    echo $_REQUEST['callback'] . '(' . $json->encode(array('ResultSet' => $jsonArray)) . ')';
} else {
    require_once 'include/utils.php';
                        list($packaged_product_count, $packaged_product_id, $isUnique) = explode(':', $packaged_product_count_and_id);
                        $packaged_product = new oqc_Product();
                        if ($packaged_product->retrieve($packaged_product_id)) {
                            $currency_id = $packaged_product->currency_id != '' ? $packaged_product->currency_id : '-99';
                            //2.2RC1 send also currency id of the product, if not set, then default currency
                            // Convert price to default currency, if currency_id is set
                            if ($currency_id != '-99') {
                                $currency = new Currency();
                                $currency->retrieve($currency_id);
                                $packaged_product->price = $packaged_product->price / $currency->conversion_rate;
                                //		$packaged_product->price_recurring = $packaged_product->price_recurring / $currency->conversion_rate;
                            }
                            if ($packaged_product->deleted) {
                                $packaged_product->name .= '<br>' . $app_strings['LBL_OQC_PRODUCT_DELETE'];
                            }
                            if (!$packaged_product->active) {
                                $packaged_product->name .= '<br>' . $app_strings['LBL_OQC_PRODUCT_INACTIVE'];
                            }
                            $jsonArray[] = array('Tax' => $packaged_product->oqc_vat === '' ? "default" : $packaged_product->oqc_vat, 'Quantity' => $packaged_product_count, 'Name' => $packaged_product->name, 'Unit' => $packaged_product->unit, 'Price' => empty($packaged_product->is_recurring) ? getFormattedCurrencyValue($packaged_product->price) : '0.00', 'PriceRecurring' => empty($packaged_product->is_recurring) ? '0.00' : getFormattedCurrencyValue($packaged_product->price), 'CancellationPeriod' => $packaged_product->cancellationperiod, 'MonthsGuaranteed' => $packaged_product->monthsguaranteed, 'ProductId' => $packaged_product->deleted ? '' : $packaged_product_id, 'UpdatedVersionAvailable' => !$packaged_product->is_latest && !$packaged_product->deleted, 'IsUnique' => empty($packaged_product->is_recurring), 'Currency_id' => '-99');
                        }
                    }
                }
            }
        }
    }
}
require_once 'include/utils.php';
$json = getJSONobj();
header("Content-type: application/json");
echo $json->encode(array('ResultSet' => $jsonArray));
session_write_close();
 function as_plain_text()
 {
     global $locale;
     $default_currency = new Currency();
     $default_currency->retrieve($this->service_currency_id);
     $currencySymbol = $default_currency->symbol;
     $vatStr = 'VAT ' . floatval($this->oqc_vat) * 100;
     $formattedPrice = getFormattedCurrencyValue($this->price);
     $description = from_html($this->description);
     return "{$this->name} ({$description}), {$this->quantity} {$this->unit} {$currencySymbol} {$formattedPrice} Discount: {$this->discount_value} {$this->discount_select} " . $vatStr . ' %';
 }
if (array_key_exists('id', $_REQUEST)) {
    if (!defined('sugarEntry')) {
        define('sugarEntry', true);
    }
    chdir("..");
    require_once 'include/entryPoint.php';
    require_once 'include/oqc/common/common.php';
    // required for getFormattedCurrencyValue method
    require_once 'modules/oqc_Product/oqc_Product.php';
    require_once 'modules/Currencies/Currency.php';
    $id = $_REQUEST['id'];
    // the product id that we search in the packages
    $p = new oqc_Product();
    if ($p->retrieve($id)) {
        $latestVersion = $p->getLatestRevision();
        //2.2RC1 send also currency id of the product, if not set, then default currency
        // Convert price to default currency, if currency_id is set
        $currency_id = $latestVersion->currency_id != '' ? $latestVersion->currency_id : '-99';
        if ($currency_id != '-99') {
            $currency = new Currency();
            $currency->retrieve($currency_id);
            $latestVersion->price = $latestVersion->price / $currency->conversion_rate;
            //		$latestVersion->price_recurring = $latestVersion->price_recurring / $currency->conversion_rate;
        }
        $jsonArray = array('Tax' => $latestVersion->oqc_vat === '' ? "default" : $latestVersion->oqc_vat, 'Name' => $latestVersion->name, 'Unit' => $latestVersion->unit, 'Price' => empty($latestVersion->is_recurring) ? getFormattedCurrencyValue($latestVersion->price) : '0.00', 'PriceRecurring' => empty($latestVersion->is_recurring) ? '0.00' : getFormattedCurrencyValue($latestVersion->price), 'CancellationPeriod' => $latestVersion->cancellationperiod, 'MonthsGuaranteed' => $latestVersion->monthsguaranteed, 'ProductId' => $latestVersion->id, 'Description' => html_entity_decode($latestVersion->description, ENT_COMPAT, 'UTF-8'), 'Attachments' => $latestVersion->getTechnicalDescriptions(), 'Currency_id' => '-99', 'IsUnique' => empty($latestVersion->is_recurring));
    }
}
require_once 'include/utils.php';
$json = getJSONobj();
echo $json->encode($jsonArray);
session_write_close();