function getSVNumbersHtml($focus, $name, $value, $view) { if ('EditView' != $view && 'DetailView' != $view) { return ""; // skip the rest of the method if another view calls this method } global $app_list_strings; global $sugar_config; $json = getJSONobj(); $svnumbersSmartyArray = $focus->getSVNumbersArray(); $svnumberQuicksearch = getSVNumberQuicksearch('svnumber', 'svnumber_id'); $smarty = new Sugar_Smarty(); $smarty->assign('sugarDateFormat', getSugarCrmLocale('datef')); //$smarty->assign('sugarDateFormat', $sugar_config['default_date_format']); $smarty->assign('sqsJavaScript', $svnumberQuicksearch); $smarty->assign('svnumbersArray', $svnumbersSmartyArray); $smarty->assign('languageStringsCommon', getLanguageStrings("common")); if ('DetailView' === $view) { // transfer ide into ajvascript code so that we can determine the urls in the ajax call $smarty->assign('id', $focus->id); // $smarty->assign('languageStringsDocuments', getLanguageStrings('Documents')); } $sep = get_number_seperators(); $smarty->assign('sugarDecimalSeperator', $sep[1]); return $smarty->fetch('include/oqc/ExternalContracts/SVNumbers.' . $view . '.html'); }
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 get_exportable_content($beans, $delimiter, $aggregate, $additional_info) { $content = ''; $sum = 0; if (count($beans) > 0) { $prevBean = $beans[0]; } $useComma = ',' === getSugarCrmLocale('default_decimal_seperator'); global $sugar_config; $lang = $sugar_config['default_language']; $mod_strings = return_module_language($lang, $this->module_dir); $sumLabel = $mod_strings['LBL_EXPORT_SUM']; foreach ($beans as $bean) { // if no column has been selected for aggregation aggreate will be false // then we must prevent $bean->$aggregate to be accessed because it will raise an error. if (FALSE !== $aggregate && $bean->{$aggregate} != $prevBean->{$aggregate}) { // only generate final cost sum line if we summed more than one line if ($sum != $prevBean->finalcosts) { // generate final cost sum $costLine = ''; $emptyFieldCount = array_search("finalcosts", $this->basic_field_names) + 1; $emptyFields = array_fill(0, $emptyFieldCount, ''); $emptyFields[0] = $sumLabel . ' ' . $prevBean->{$aggregate}; if ($useComma) { $sum = str_replace('.', ',', $sum); } if (strpos($sum, ',') !== FALSE) { $sum = substr($sum, 0, strpos($sum, ',') + 3); } $costLine .= implode("\"" . $delimiter . "\"", $emptyFields) . $sum; $costLine = "\"" . $costLine; $costLine .= "\"\r\n"; $content .= $costLine; } // insert a newline after each aggregation $content .= "\r\n"; $sum = 0; } $sum += $bean->finalcosts; if ($useComma) { $bean->finalcosts = str_replace('.', ',', $bean->finalcosts); } if (strpos($bean->finalcosts, ',') !== FALSE) { $bean->finalcosts = substr($bean->finalcosts, 0, strpos($bean->finalcosts, ',') + 3); } $lines = $bean->get_exportable_fields($additional_info); foreach ($lines as $lineArray) { foreach ($lineArray as &$value) { $value = preg_replace("/\"/", "\"\"", $value); } $line = implode("\"" . $delimiter . "\"", $lineArray); $line = "\"" . $line; $line .= "\"\r\n"; $content .= $line; } $prevBean = $bean; } // generate the costs summary line // only generate final cost sum line if we summed more than one line if ($sum != $prevBean->finalcosts) { // generate final cost sum at the end of the whole table $costLine = ''; $emptyFieldCount = array_search("finalcosts", $this->basic_field_names) + 1; $emptyFields = array_fill(0, $emptyFieldCount, ''); $emptyFields[0] = $sumLabel . ' ' . $prevBean->{$aggregate}; if ($useComma) { $sum = str_replace('.', ',', $sum); } if (strpos($sum, ',') !== FALSE) { $sum = substr($sum, 0, strpos($sum, ',') + 3); } $costLine .= implode("\"" . $delimiter . "\"", $emptyFields) . $sum; $costLine = "\"" . $costLine; $costLine .= "\"\r\n"; $content .= $costLine; } return $content; }