private function getExternalContractVariables($contract) { $contractData = $contract->toArray(); $contractData = sanatizeBeanArrayForLatex($contractData); $contact = new Contact(); if ($contact->retrieve($contract->clientcontact_id)) { $contractData['clientcontactperson'] = $contact->toArray(); } $contact = new Contact(); if ($contact->retrieve($contract->technicalcontact_id)) { $contractData['technicalcontactperson'] = $contact->toArray(); } $contact = new Contact(); if ($contact->retrieve($contract->contact_id)) { $contractData['contactperson'] = $contact->toArray(); } $account = new Account(); if ($account->retrieve($contract->account_id)) { $contractData['account'] = $account->toArray(); } global $timedate; $contractData['startdate'] = $timedate->to_display_date($contract->startdate); $contractData['minimumduration'] = $timedate->to_display_date($contract->minimumduration); global $app_list_strings; if ($contract->endperiod == 'other') { $contractData['endperiod'] = $timedate->to_display_date($contract->enddate); } else { $contractData['endperiod'] = $app_list_strings['endperiod_list'][$contract->endperiod]; } if ($contract->cancellationperiod == 'other') { $contractData['cancellationperiod'] = $timedate->to_display_date($contract->cancellationdate); } else { $contractData['cancellationperiod'] = $app_list_strings['cancellationperiod_list'][$contract->cancellationperiod]; } // show address linebreaks in pdf $contractData['deliveryaddress'] = preg_replace("/\n/", '\\newline ', $contract->deliveryaddress); $contractData['completionaddress'] = preg_replace("/\n/", '\\newline ', $contract->completionaddress); $contractData['svnumbers'] = $contract->getSVNumbersArray(); // TODO: abbreviation and type probably have to be converted in the future $contractMatters = explode('^,^', $contract->externalcontractmatter); foreach ($contractMatters as &$matter) { $matter = $app_list_strings['externalcontractmatter_list'][$matter]; } $contractData['externalcontractmatter'] = implode('\\newline ', $contractMatters); $previousCategory = ''; $costs = $contract->getCostsArray(); $months = getLanguageStringsPHP('months'); foreach ($costs as &$cost) { $cost['numberOfDetailedCosts'] = count($cost['detailedCosts']); if ($previousCategory == $cost['category']) { $previousCategory = $cost['category']; $cost['category'] = ''; // TODO @LION i guess that leaving the category field empty should to some kind of marking... please comment. } else { $previousCategory = $cost['category']; $cost['category'] = $app_list_strings['externalcontractmatter_list'][$cost['category']]; } if ('annually' === $cost['paymentinterval'] || 'once' === $cost['paymentinterval'] || 'other' === $cost['paymentinterval']) { $enddate = date_parse($contract->enddate); // if the payment interval of this cost is once, annually or other, there will be only one detailed cost row. // so it is correct to modify the first detailed cost item in the array. // set the month for this detailed cost row to the month of the enddate. $cost['detailedCosts'][0]['month'] = $enddate['month']; } // do translation now because paymentinterval will not be read from php code anymore. // so it can be in localized form from now on. $cost['paymentinterval'] = $app_list_strings['paymentinterval_list'][$cost['paymentinterval']]; foreach ($cost['detailedCosts'] as &$detailedCosts) { $detailedCosts['price'] = formatCurrencyForSmartyLatex($detailedCosts['price'], false); // format price for latex template (see #387) } } $positions = $contract->getPositionsArray(); foreach ($positions as &$position) { $position['type'] = $app_list_strings['externalcontractmatter_list'][$position['type']]; $position['price'] = formatCurrencyForSmartyLatex($position['price'], false); // format price for latex template (see #387) } // convert all currency values / prices before giving them to smarty $contractData['finalcosts'] = formatCurrencyForSmartyLatex($contractData['finalcosts'], true); return array('numberOfCosts' => count($costs), 'months' => $months, 'contract' => $contractData, 'costs' => $costs, 'positions' => $positions, 'currencySymbol' => currencySymbolToLatexEquivalent(getSugarCrmLocale('default_currency_symbol'))); }
function getPdfVariables($contract) { global $app_list_strings; global $locale; $serviceArrays = array(); $oneTimeServiceArrays = array(); $productArrays = array(); $oneTimeProductArrays = array(); $pdfDataArray = array(); $contractVariables = array(); $calculatedCosts = array(); $imagesExist = false; $sep = get_number_seperators(); $vat_default = floatval(str_replace($sep[1], '.', $app_list_strings['oqc_vat_list']['default'])) / 100; //Get contract variables $contractVariables = getContractVariables($contract); //Get service data for processing $services = $contract->get_linked_beans('oqc_service', 'oqc_Service'); if (!empty($services)) { usort($services, array('oqc_Service', 'oqc_service_compare_position')); foreach ($services as $service) { $serviceArray = $service->toArray(); $serviceArray = sanatizeBeanArrayForLatex($serviceArray); $product = getProductBean($service); if ($product) { $productArray = $product->toArray(); $productArray = sanatizeBeanArrayForLatex($productArray); } else { $productArray = array(); } if (!empty($service->description)) { // Rewrite description with Latex converter output. $convertor = new oqc_HtmlToLatexConverter(); $serviceArray['description'] = $convertor->html2latex('<html><head></head><body>' . from_html($service->description) . '</body></html>'); } elseif (!empty($product->description)) { $convertor = new oqc_HtmlToLatexConverter(); $productArray['description'] = $convertor->html2latex('<html><head></head><body>' . from_html($product->description) . '</body></html>'); } // translate $serviceArray['zeitbezug_translated'] = $app_list_strings['zeitbezug_list'][$serviceArray['zeitbezug']]; if ($app_list_strings['unit_list'][$serviceArray['unit']]) { $serviceArray['unit'] = $app_list_strings['unit_list'][$serviceArray['unit']]; } $calc_vat = $serviceArray['oqc_vat'] == 'default' ? $vat_default : ($serviceArray['oqc_vat'] !== '' ? $serviceArray['oqc_vat'] : $vat_default); $serviceArray['oqc_vat'] = $calc_vat * 100; $serviceArray['discounted_price'] = $service->getDiscountedPrice($calc_vat); $serviceArray['discounted_price_tax_free'] = $service->getDiscountedPriceTaxFree(); $serviceArray['image_url'] = false; if ($product) { if ($product->getImageFilenameUrl()) { if (WINDOWS) { $serviceArray['image_url'] = str_replace("\\", "/", '"' . getcwd() . '"/' . $product->getImageFilenameUrl()); } else { $serviceArray['image_url'] = str_replace("\\", "/", getcwd() . '/' . $product->getImageFilenameUrl()); } } } $serviceArray['has_image'] = $serviceArray['image_url'] !== FALSE; // convenient flag for access from latex template $serviceArray['startdate'] = $contract->startdate; $serviceArray['enddate'] = $contract->enddate; //$GLOBALS['log']->error('getPdfVariables: '. var_export($serviceArray['oqc_vat'],true)); if (!empty($serviceArray['service_currency_id'])) { $currency = new Currency(); //$currency_id = -99; $currency->retrieve($serviceArray['service_currency_id']); //Convert currency symbols to latex equivalents here $serviceArray['currency_symbol'] = $currency->symbol; $serviceArray['currency_symbol'] = str_replace("€", '\\euro{}', $serviceArray['currency_symbol']); $serviceArray['currency_symbol'] = str_replace('$', '\\$', $serviceArray['currency_symbol']); $serviceArray['currency_symbol'] = str_replace("£", '{\\pounds}', $serviceArray['currency_symbol']); $serviceArray['currency_symbol'] = str_replace("¥", '{Y\\hspace*{-1.4ex}--}', $serviceArray['currency_symbol']); } if (!$imagesExist && $serviceArray['has_image']) { $imagesExist = true; } if ($service->zeitbezug == 'once') { $oneTimeServiceArrays[] = $serviceArray; $oneTimeProductArrays[] = $productArray; } else { $serviceArrays[] = $serviceArray; $productArrays[] = $productArray; } } // merge data from products and services, prefering service data $serviceData = array_map('array_merge', $productArrays, $serviceArrays); $oneTimeServiceData = array_map('array_merge', $oneTimeProductArrays, $oneTimeServiceArrays); } $costsTotal = calculateTotalCosts($serviceData, false); $oneTimeCostsTotal = calculateTotalCosts($oneTimeServiceData); //$currency_symbol = $serviceData = array('imagesExist' => $imagesExist, 'services' => $serviceData, 'oneTimeServices' => $oneTimeServiceData); $pdfDataArray = array_merge($contractVariables, $serviceData, $costsTotal, $oneTimeCostsTotal); //$GLOBALS['log']->error('Services: variable transferred to pdf: '. var_export($pdfDataArray,true)); return $pdfDataArray; }