return startMonth;
}
-function generateTitleString(titleObj) {
+const generateTitleString = (titleObj) => {
if (!titleObj || typeof titleObj !== 'object') return '';
const typeTitles = {
marketplace: 'Маркетплейс'
};
- let parts = [];
-
- for (const [typeKey, typeValue] of Object.entries(titleObj)) {
- if (!typeValue || typeof typeValue !== 'object') continue;
-
- let lines = Object.entries(typeValue)
- .map(([key, val]) => `- ${key.replace(/_/g, ' ')}: ${parseFloat(val).toFixed(2)}`);
-
- parts.push(`${typeTitles[typeKey] || typeKey}:\n${lines.join('\n')}`);
- }
+ const parts = Object.entries(titleObj)
+ .map(([typeKey, typeValue]) => {
+ const title = typeTitles[typeKey] || typeKey;
+ if (typeof typeValue === 'number') {
+ return `${title}: ${typeValue.toFixed(2)}`;
+ }
+ if (!typeValue || typeof typeValue !== 'object' || !typeValue[0]) return '';
+ const lines = Object.entries(typeValue[1]?.details || {})
+ .map(([key, val]) => `- ${key.replace(/_/g, ' ')}: ${parseFloat(val).toFixed(2)}`);
+ return `${title}: ${parseFloat(typeValue[0]).toFixed(2)}\n${lines.join('\n')}`;
+ })
+ .filter(Boolean);
return parts.join('\n\n');
-}
+};
\ No newline at end of file