async function generate_pdf(imgs, type) { if (typeof custom_pdf_generation === 'function') { return custom_pdf_generation(type) } async function ask_pdf_photo_mode() { return new Promise(resolve => { if (!pp.interface?.root?.$refs?.pdf_photo_mode_modal) { resolve('auto'); return; } pp.interface.root.$refs.pdf_photo_mode_modal.show_modal(resolve); }); } async function ask_make_photo(photos_left) { return new Promise(resolve => { if (!pp.interface?.root?.$refs?.make_photo_modal) { resolve('go_to_spec'); return; } pp.interface.root.$refs.make_photo_modal.show_modal(resolve, photos_left); }); } let photos = []; if (constructor_settings.own_photo_pdf && !imgs) { let photo_mode = await ask_pdf_photo_mode(); if (photo_mode === 'custom_photos') { for (let i = 5; i > 0; i--) { let make_photo = await ask_make_photo(i); if (make_photo === 'make_photo') { photos.push(get_image()); } else if (make_photo === 'go_to_spec') { break; } else { return; } } } else if (photo_mode !== 'auto') { return; } } dControls.clear_selected(); await check_pdf_lib() let md = sc.get_specs(true); // core_v2: get_specs_v2() → { sum, all, … }. Первое ядро: convert_specs() без sum/all — PDF ожидает v2-форму. if (!md || typeof md !== 'object') { md = {sum: {}, all: {module: {}}}; } else { if (md.sum == null || typeof md.sum !== 'object') { md.sum = {}; } if (md.all == null || typeof md.all !== 'object') { md.all = {module: {}}; } else if (md.all.module == null || typeof md.all.module !== 'object') { md.all.module = {}; } } let p_width = global_options.pdf.width; let p_height = global_options.pdf.height; let img_size_offset_x = global_options.pdf.img_size_offset_x let img_size_offset_y = global_options.pdf.img_size_offset_y let img_pos_x = global_options.pdf.img_pos_x let img_pos_y = global_options.pdf.img_pos_y let img_size_multi = global_options.pdf.img_size_multi let logo; let logo_el = $('.client_logo img')[0]; if (logo_el !== undefined && logo_el.src !== undefined) { try { logo = logo_to_base64(logo_el); } catch (e) { } } let modules = get_modules(); let shelves = get_shelves(); let styles = { tableHeader: { bold: false, fontSize: 12 } }; let tables_layout = { hLineWidth: function (i, node) { return 0.1; }, vLineWidth: function (i, node) { return 0.1; }, hLineColor: function (i, node) { return 'gray'; }, vLineColor: function (i, node) { return 'gray'; }, paddingLeft: function (i, node) { return 6; }, paddingRight: function (i, node) { return 6; }, paddingTop: function (i, node) { return 3; }, paddingBottom: function (i, node) { return 3; }, }; let dd = { pageSize: 'A4', pageOrientation: 'landscape', // pageMargins: [85, 56, 42, 56], pageMargins: [pdf_settings.lm, pdf_settings.tm, pdf_settings.rm, pdf_settings.bm], footer: function (currentPage, pageCount) { return { columns: [ { width: '*', text: $('.client_data').html().trim(), alignment: 'left', margin: [85, 0, 0, 0] }, { width: 92, text: currentPage.toString() + ' ' + lang['pages_of'] + ' ' + pageCount, alignment: 'right', margin: [0, 0, 42, 0] }, ], } }, content: [], styles: styles, defaultStyle: { fontSize: 10, bold: false } }; if (logo) { dd.header = { image: logo, opacity: 0.3, fit: [100, 100], margin: [0, 0, 42, 0], absolutePosition: {x: 15, y: 10}, alignment: 'right' } } let images = {}; if (!imgs) { images = get_images({ width: p_width * img_size_multi, height: p_height * img_size_multi }); } else { images = imgs; } if (photos.length) { photos.forEach(item => { dd.content.push({ image: item, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); }); } else if (images.common_view) { dd.content.push({ image: images.common_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (pdf_settings.german == true) { if (images.front_view_color) { dd.content.push({ image: images.front_view_color, fit: [p_width - 30, p_height - 30], absolutePosition: {x: img_pos_x, y: img_pos_y}, alignment: 'center', margin: [0, 0, 0, 0], pageBreak: 'after', }); } if (images.back_view_color) { dd.content.push({ image: images.back_view_color, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.left_view_color) { dd.content.push({ image: images.left_view_color, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.right_view_color) { dd.content.push({ image: images.right_view_color, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } } if (images.edges_view) { dd.content.push({ image: images.edges_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.comms_only_view) { dd.content.push({ image: images.comms_only_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.top_view) { dd.content.push({ image: images.top_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (pdf_settings.german == true) { if (images.tabletop_view) { dd.content.push({ image: images.tabletop_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } } if (images.front_view) { dd.content.push({ image: images.front_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.back_view) { dd.content.push({ image: images.back_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.left_view) { dd.content.push({ image: images.left_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } if (images.right_view) { dd.content.push({ image: images.right_view, fit: [p_width - img_size_offset_x, p_height - img_size_offset_y], absolutePosition: {x: img_pos_x, y: img_pos_y}, margin: [0, 0, 0, 0], pageBreak: 'after' }); } let tfc_tmp; let top_facades_material; let bottom_facades_material; let top_corpus_material; let bottom_corpus_material; if (pdf_settings.force_top_bottom_materials === true || pdf_settings.add_material_to_module_name === true) { if (project_settings.selected_materials.top.facades !== undefined) { top_facades_material = objectFindByKey(materials_catalog.items, 'id', project_settings.selected_materials.top.facades); } else { tfc_tmp = objectFindByKey(ct, 'id', project_settings.materials.top.facades[0]); if (tfc_tmp.items.length) { top_facades_material = tfc_tmp.items[0]; } else { top_facades_material = tfc_tmp.categories[0].items[0]; } } if (project_settings.selected_materials.bottom.facades !== undefined) { bottom_facades_material = objectFindByKey(materials_catalog.items, 'id', project_settings.selected_materials.bottom.facades); } else { tfc_tmp = objectFindByKey(ct, 'id', project_settings.materials.bottom.facades[0]); if (tfc_tmp.items.length) { bottom_facades_material = tfc_tmp.items[0]; } else { bottom_facades_material = tfc_tmp.categories[0].items[0]; } } top_corpus_material = objectFindByKey(materials_catalog.items, 'id', project_settings.selected_materials.top.corpus); bottom_corpus_material = objectFindByKey(materials_catalog.items, 'id', project_settings.selected_materials.bottom.corpus); } dd.content.push({ text: lang['general_information'] + '\n\n', style: 'tableHeader', bold: true, alignment: 'center' }); if (project_settings.name !== undefined) { dd.content.push({ text: lang['kitchen_model'] + ': ' + project_settings.name + '\n\n' }); } if (pdf_settings.force_top_bottom_materials === true) { dd.content.push({ text: lang['top_facades'] + ': ' + top_facades_material.name, }); dd.content.push({ text: lang['bottom_facades'] + ': ' + bottom_facades_material.name + '\n\n', }); dd.content.push({ text: lang['corpus_top'] + ': ' + top_corpus_material.name, }); dd.content.push({ text: lang['corpus_bottom'] + ': ' + bottom_corpus_material.name + '\n\n', }); } console.log(md); let show_price = custom_settings.info_show_price == undefined ? (constructor_settings.price_enabled == undefined ? true : Boolean(constructor_settings.price_enabled)) : custom_settings.info_show_price; let show_icons = constructor_settings.specs_icons == undefined ? true : constructor_settings.specs_icons; const specSumKeys = typeof specSumKeysOrderedForExport === 'function' ? specSumKeysOrderedForExport(md.sum) : Object.keys(md.sum || {}); for (let ski = 0; ski < specSumKeys.length; ski++) { const key = specSumKeys[ski]; const item = md.sum[key]; console.log(key, item); let tabledata = []; let widths = show_price ? ['auto', '*', 'auto', 'auto', 'auto', 'auto'] : ['auto', '*', 'auto', 'auto', 'auto']; if (key == 'wall') { let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['wall_header'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.key_name, (obj.variant_name || obj.material_name), (obj.variant_code || obj.material_code), obj.width + 'x' + obj.height + ' мм', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'butts') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['thickness'], style: 'tableHeader' }, { text: lang['width'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' } ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['edge'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.thickness + ' мм', obj.height + ' мм', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'butts_facade') { let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['facade'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' } ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['facades_edge'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.mat_name, obj.facade_name, round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: show_price ? ['auto', '*', 'auto', 'auto'] : ['auto', '*', 'auto'], // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'facade') { const sizeHeader = Object.values(item).some(obj => obj.show_size); let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, ] if (sizeHeader) { header_row.push({ text: lang['sizes'], style: 'tableHeader' }); } header_row.push({text: lang['count_short'], style: 'tableHeader'}); if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['facades'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.mat_name, obj.name, obj.mat_code || obj.code, ) if (sizeHeader) { row.push( obj.show_size ? round_decimals_2(obj.size.x) + 'x' + round_decimals_2(obj.size.y) + ' мм' : '' ); } row.push( round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type] ); if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } let dynamicWidths = ['auto', '*', 'auto']; if (sizeHeader) { dynamicWidths.push('auto'); } dynamicWidths.push('auto'); if (show_price) { dynamicWidths.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: dynamicWidths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol_facade') { let header_row = [ {text: lang['title'], style: 'tableHeader'}, {text: lang['code'], style: 'tableHeader'}, {text: lang['cokol_spec_height'], style: 'tableHeader'}, {text: lang['cokol_spec_total_length'], style: 'tableHeader'}, {text: lang['common_sizes'], style: 'tableHeader'}, ]; if (show_price) { header_row.push({text: lang['price'], style: 'tableHeader'}); } tabledata.push(header_row); dd.content.push({ text: lang['cokol_facade_linked'] + ':' + '\n\n', style: 'tableHeader', }); for (const [i_key, obj] of Object.entries(item)) { let row = []; row.push( obj.name, obj.mat_code || obj.code, obj.height + ' ' + lang['mm'], round_cokol_decimals(obj.total_length_m) + ' ' + lang['units_m'], round_cokol_decimals(obj.total_width) + ' ' + lang['units_m2'], ); if (show_price) { row.push({ text: format_price(obj.total_price), alignment: 'right', }); } // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row); } const dynamicWidths = ['*', 'auto', 'auto', 'auto', 'auto']; if (show_price) { dynamicWidths.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: dynamicWidths, body: tabledata, }, layout: tables_layout, }, { text: '\n\n', }, ); } if (key == 'facade_glass') { const sizeHeader = Object.values(item).some(obj => obj.show_size); let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, ]; if (sizeHeader) { header_row.push({ text: lang['sizes'], style: 'tableHeader' }); } header_row.push({text: lang['count_short'], style: 'tableHeader'}); if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['glass_materials'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { let row = []; row.push( obj.mat_name, obj.mat_code || obj.code, ); if (sizeHeader) { row.push( obj.show_size ? obj.width + 'x' + obj.height + ' мм' : '' ); } row.push( round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type] ); if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row); } let dynamicWidths = ['*', 'auto']; if (sizeHeader) { dynamicWidths.push('auto'); } dynamicWidths.push('auto'); if (show_price) { dynamicWidths.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: dynamicWidths, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'tabletop') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['tabletop'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', (obj.price_type === 'm' || obj.price_type === 'm2' || obj.price_type === 'm3') ? round_decimals_3(obj.total_width) + ' ' + lang['units_' + obj.price_type] : round_decimals_3(obj.total_width_m) + ' ' + lang['units_' + 'm'], round_decimals_3(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'bort') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['tabletop_plints'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', (obj.price_type === 'm' || obj.price_type === 'm2' || obj.price_type === 'm3') ? round_decimals_3(obj.total_width) + ' ' + lang['units_' + obj.price_type] : round_decimals_3(obj.total_width_m) + ' ' + lang['units_' + 'm'], round_decimals_3(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'bort_acc') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ]; if (show_price) { header_row.push({ text: lang['price'], style: 'tableHeader' }); } tabledata.push(header_row); dd.content.push({ text: (lang['bort_acc'] || 'Комплектующие плинтуса') + ':\n\n', style: 'tableHeader' }); for (const obj of Object.values(item)) { let row = []; const pdf_safe_name = ('' + (obj.name || '')) .replace(/\u00A0/g, ' ') .replace(/\u25CF/g, '\u2022'); row.push( pdf_safe_name, obj.code, round_decimals_2(obj.total_count != null ? obj.total_count : obj.count) + ' ' + lang['units_' + (obj.price_type || 'p')], ); if (show_price) { row.push({ text: (obj.is_compound_header && (parseFloat(obj.total_price) || 0) <= 0) ? (lang['compound'] || 'Составная') : format_price(obj.total_price != null ? obj.total_price : (obj.price * (obj.count || 1))), alignment: 'right' }); } // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row); } let widths_item_bort_acc = []; for (let ii = 0; ii < header_row.length; ii++) { ii === 0 ? widths_item_bort_acc.push('*') : widths_item_bort_acc.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: widths_item_bort_acc, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['cokol'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', format_cokol_spec_common_size(obj, lang), ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } let widths_item_cokol = []; for (let ii = 0; ii < header_row.length; ii++) { ii === 0 ? widths_item_cokol.push('*') : widths_item_cokol.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: widths_item_cokol, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol_cuts') { let header_row = [ {text: lang['title'], style: 'tableHeader'}, {text: lang['code'], style: 'tableHeader'}, {text: lang['sizes'], style: 'tableHeader'}, {text: lang['count_short'], style: 'tableHeader'}, ]; tabledata = [header_row]; dd.content.push({ text: (lang['cokol_cuts'] || 'Разрезы цоколей') + ':' + '\n\n', style: 'tableHeader' }); for (const obj of Object.values(item)) { tabledata.push([ obj.name, obj.code, obj.size_x + 'x' + obj.size_z + ' мм', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ]); } dd.content.push( { table: { headerRows: 1, widths: ['*', 'auto', 'auto', 'auto'], body: tabledata, }, layout: tables_layout }, {text: '\n\n'} ); } if (key == 'cokol_top') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['cokol_top'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', (obj.price_type === 'm' || obj.price_type === 'm2') ? round_cokol_decimals(obj.total_width) + ' ' + lang['units_' + obj.price_type] : round_cokol_decimals(obj.total_width_m) + ' ' + lang['units_' + 'm'], round_cokol_decimals(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol_side_acc') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ]; if (show_price) { header_row.push({ text: lang['price'], style: 'tableHeader' }); } tabledata.push(header_row); dd.content.push({ text: (lang['cokol_side_acc'] || 'Комплектующие для цоколя') + ':\n\n', style: 'tableHeader' }); for (const obj of Object.values(item)) { let row = []; const pdf_safe_name = ('' + (obj.name || '')) .replace(/\u00A0/g, ' ') .replace(/\u25CF/g, '\u2022'); row.push( pdf_safe_name, obj.code, (obj.price_type === 'p' ? (obj.total_count != null ? obj.total_count : obj.count) : round_cokol_decimals(obj.total_count != null ? obj.total_count : obj.count)) + ' ' + lang['units_' + (obj.price_type || 'p')], ); if (show_price) { row.push({ text: format_price(obj.total_price != null ? obj.total_price : (obj.price * (obj.count || 1))), alignment: 'right' }); } // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row); } let widths_item = []; for (let ii = 0; ii < header_row.length; ii++) { ii === 0 ? widths_item.push('*') : widths_item.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: widths_item, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cornice') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['cornice_width'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['cornice'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.total_width + ' м', obj.width + ' м', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'item') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['accessories_furniture'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] const pdf_safe_obj_name = ('' + (obj.name || '')) .replace(/\u00A0/g, ' ') .replace(/\u25CF/g, '\u2022'); row.push( obj.is_compound_header ? {text: pdf_safe_obj_name, bold: true} : pdf_safe_obj_name, obj.code, round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price) row.push({ text: (obj.is_compound_header && (parseFloat(obj.total_price) || 0) <= 0) ? (lang['compound'] || 'Составная') : format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } let widths_item = []; for (let ii = 0; ii < header_row.length; ii++) { ii == 0 ? widths_item.push('*') : widths_item.push('auto') } dd.content.push( { table: { headerRows: 1, widths: widths_item, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } // Модули коллекции с переопределённой ценой (позиции прайс-листа коллекции) if (key == 'collection_module') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['collection'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['collection_price_modules'] + ':' + '\n\n', style: 'tableHeader' }); for (const obj of Object.values(item)) { let row = [] row.push( obj.name, obj.code, obj.collection_name || '', round_decimals_2(obj.total_count), ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } let widths_item = []; for (let ii = 0; ii < header_row.length; ii++) { ii == 0 ? widths_item.push('*') : widths_item.push('auto') } dd.content.push( { table: { headerRows: 1, widths: widths_item, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'module' && Object.values(item).find((x) => x.price)) { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push( header_row ); dd.content.push({ text: lang['module'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { if (!(obj.price)) { continue; } console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, round_decimals_2(obj.total_count), ) if (show_price) row.push({ text: format_price(obj.total_price), alignment: 'right' }); // подпись коллекции/каталога: без неё разделённые строки выглядят одинаково apply_spec_scope_suffix_to_row(row, obj); tabledata.push(row) } let widths_item = []; for (let ii = 0; ii < header_row.length; ii++) { ii == 0 ? widths_item.push('*') : widths_item.push('auto') } dd.content.push( { table: { headerRows: 1, widths: widths_item, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } } if (project_settings.comments && project_settings.comments.length > 0) { dd.content.push( { text: lang['project_comments'] + ':', style: 'tableHeader' } ) for (let i = 0; i < project_settings.comments.length; i++) { dd.content.push( { text: project_settings.comments[i].text }, { text: '\n\n' } ) } } const servicesCartsBeforeTotal = get_services_carts_for_report(); for (let c = 0; c < servicesCartsBeforeTotal.length; c++) { const cart = servicesCartsBeforeTotal[c]; dd.content.push({ text: cart.label + '\n\n', style: 'tableHeader', bold: true, alignment: 'left' }); const tabledata = [[ {text: lang['title'] || 'Наименование', style: 'tableHeader'}, {text: lang['price'] || 'Цена', style: 'tableHeader'} ]]; let cartTotal = 0; for (const it of cart.items) { tabledata.push([it.name, {text: format_price(it.price), alignment: 'right'}]); cartTotal += it.price; } tabledata.push([{text: (lang['total_cost'] || 'Итого') + ':', style: 'tableHeader', bold: true}, {text: format_price(cartTotal), alignment: 'right', bold: true}]); dd.content.push( { table: { headerRows: 1, widths: ['*', 80], body: tabledata, }, layout: tables_layout }, {text: '\n\n'} ); } if (show_price && md.mode !== 'object') { const discount = parseFloat(project_settings.discount) || 0; const productWithDiscount = parseFloat(md.total_price) || 0; const productWithoutDiscount = parseFloat(md.total_price_without_discount) != null && md.total_price_without_discount !== undefined ? parseFloat(md.total_price_without_discount) : (discount > 0 ? productWithDiscount * 100 / (100 - discount) : productWithDiscount); const servicesTotal = parseFloat(md.total_services_price) || 0; const totalWithoutDiscount = productWithoutDiscount + servicesTotal; const totalWithDiscount = productWithDiscount + servicesTotal; const discountAmount = productWithoutDiscount - productWithDiscount; const labelTotal = (lang['total_cost'] || 'Общая стоимость'); if (discount > 0) { const labelWithoutDiscount = (lang['total_cost_project_without_discount'] || 'Общая стоимость без скидки'); const labelWithDiscount = (lang['total_cost_project_with_discount'] || 'Общая стоимость со скидкой'); dd.content.push({ text: labelWithoutDiscount + ': ' + format_price(totalWithoutDiscount) + '\n', style: 'tableHeader', bold: true, alignment: 'left' }); dd.content.push({ text: labelWithDiscount + ': ' + format_price(totalWithDiscount) + '\n', style: 'tableHeader', bold: true, alignment: 'left' }); dd.content.push({ text: (lang['discount_label'] || 'Скидка') + ': ' + discount + '% (' + format_price(discountAmount) + ')\n', alignment: 'left' }); if (servicesCartsBeforeTotal.length) { const discountNotAppliedTo = (lang['discount_not_applied_to'] || '* Скидка не распространяется на: ') + servicesCartsBeforeTotal.map(c => c.label).join(', '); dd.content.push({ text: discountNotAppliedTo + '\n\n', alignment: 'left' }); } else { dd.content.push({text: '\n'}); } } else { dd.content.push({ text: labelTotal + ': ' + format_price(totalWithDiscount) + '\n\n', style: 'tableHeader', bold: true, alignment: 'left' }); } } if (md.mode !== 'object') { for (const [i, obj] of Object.entries(md.all?.module ?? {})) { if (!obj.is_root || obj.element_type === "__cokol_plate") { continue; } let show_price2 = show_price && obj.show_price; console.log(i, obj); let widths = show_price2 ? ['auto', '*', 'auto', 'auto', 'auto', 'auto'] : ['auto', '*', 'auto', 'auto', 'auto']; dd.content.push({ text: lang['module'] + ': ' + obj.name + '\n\n', style: 'tableHeader', bold: true, alignment: 'left' }); if (show_icons && obj.icon && obj.icon !== '') { let img_module = await convert_image_to_base64(obj.icon); let size = await get_img_width(obj.icon); dd.content.push({ image: img_module, fit: [100, 100 / (size.width / size.height)], }); } for (const [key, item] of Object.entries(obj.ctx?.sum || {})) { let tabledata = []; if (key == 'wall') { let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['wall_header'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { let row = [] row.push( obj.key_name, (obj.variant_name || obj.material_name), (obj.variant_code || obj.material_code), obj.width + 'x' + obj.height + ' мм', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' }); } if (key == 'butts') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['thickness'], style: 'tableHeader' }, { text: lang['width'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' } ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['edge'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.thickness + ' мм', obj.height + ' мм', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'butts_facade') { let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['facade'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' } ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['facades_edge'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.mat_name, obj.facade_name, round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: show_price2 ? ['auto', '*', 'auto', 'auto'] : ['auto', '*', 'auto'], // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'facade') { const sizeHeader = Object.values(item).some(obj => obj.show_size); let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, ] if (sizeHeader) { header_row.push({ text: lang['sizes'], style: 'tableHeader' }); } header_row.push({text: lang['count_short'], style: 'tableHeader'}); if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['facades'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.mat_name, obj.name, obj.mat_code || obj.code, ) if (sizeHeader) { row.push( obj.show_size ? round_decimals_2(obj.size.x) + 'x' + round_decimals_2(obj.size.y) + ' мм' : '' ); } row.push( round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type] ); if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } let dynamicWidths = ['auto', '*', 'auto']; if (sizeHeader) { dynamicWidths.push('auto'); } dynamicWidths.push('auto'); if (show_price2) { dynamicWidths.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: dynamicWidths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol_facade') { let header_row = [ {text: lang['title'], style: 'tableHeader'}, {text: lang['code'], style: 'tableHeader'}, {text: lang['cokol_spec_height'], style: 'tableHeader'}, {text: lang['cokol_spec_total_length'], style: 'tableHeader'}, {text: lang['common_sizes'], style: 'tableHeader'}, ]; if (show_price2) { header_row.push({text: lang['price'], style: 'tableHeader'}); } tabledata.push(header_row); dd.content.push({ text: lang['cokol_facade_linked'] + ':' + '\n\n', style: 'tableHeader', }); for (const [i_key, obj] of Object.entries(item)) { let row = []; row.push( obj.name, obj.mat_code || obj.code, obj.height + ' ' + lang['mm'], round_cokol_decimals(obj.total_length_m) + ' ' + lang['units_m'], round_cokol_decimals(obj.total_width) + ' ' + lang['units_m2'], ); if (show_price2) { row.push({ text: format_price(obj.total_price), alignment: 'right', }); } tabledata.push(row); } const dynamicWidths = ['*', 'auto', 'auto', 'auto', 'auto']; if (show_price2) { dynamicWidths.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: dynamicWidths, body: tabledata, }, layout: tables_layout, }, { text: '\n\n', }, ); } if (key == 'facade_glass') { const sizeHeader = Object.values(item).some(obj => obj.show_size); let header_row = [ { text: lang['material'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, ]; if (sizeHeader) { header_row.push({ text: lang['sizes'], style: 'tableHeader' }); } header_row.push({text: lang['count_short'], style: 'tableHeader'}); if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['glass_materials'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { let row = []; row.push( obj.mat_name, obj.mat_code || obj.code, ); if (sizeHeader) { row.push( obj.show_size ? obj.width + 'x' + obj.height + ' мм' : '' ); } row.push( round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type] ); if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row); } let dynamicWidths = ['*', 'auto']; if (sizeHeader) { dynamicWidths.push('auto'); } dynamicWidths.push('auto'); if (show_price2) { dynamicWidths.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: dynamicWidths, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'tabletop') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['tabletop'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', (obj.price_type === 'm' || obj.price_type === 'm2' || obj.price_type === 'm3') ? round_decimals_2(obj.total_width) + ' ' + lang['units_' + obj.price_type] : round_decimals_2(obj.total_width_m) + ' ' + lang['units_' + 'm'], round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'bort') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['tabletop_plints'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', (obj.price_type === 'm' || obj.price_type === 'm2' || obj.price_type === 'm3') ? round_decimals_2(obj.total_width) + ' ' + lang['units_' + obj.price_type] : round_decimals_2(obj.total_width_m) + ' ' + lang['units_' + 'm'], round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'bort_acc') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ]; if (show_price2) { header_row.push({ text: lang['price'], style: 'tableHeader' }); } tabledata.push(header_row); dd.content.push({ text: (lang['bort_acc'] || 'Комплектующие плинтуса') + ':\n\n', style: 'tableHeader' }); for (const obj of Object.values(item)) { let row = []; const pdf_safe_name = ('' + (obj.name || '')) .replace(/\u00A0/g, ' ') .replace(/\u25CF/g, '\u2022'); row.push( pdf_safe_name, obj.code, round_decimals_2(obj.total_count != null ? obj.total_count : obj.count) + ' ' + lang['units_' + (obj.price_type || 'p')], ); if (show_price2) { row.push({ text: (obj.is_compound_header && (parseFloat(obj.total_price) || 0) <= 0) ? (lang['compound'] || 'Составная') : format_price(obj.total_price != null ? obj.total_price : (obj.price * (obj.count || 1))), alignment: 'right' }); } tabledata.push(row); } let widths_item_bort_acc2 = []; for (let ii = 0; ii < header_row.length; ii++) { ii === 0 ? widths_item_bort_acc2.push('*') : widths_item_bort_acc2.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: widths_item_bort_acc2, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['cokol'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', format_cokol_spec_common_size(obj, lang), ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } let widths_item_cokol2 = []; for (let ii = 0; ii < header_row.length; ii++) { ii === 0 ? widths_item_cokol2.push('*') : widths_item_cokol2.push('auto'); } dd.content.push( { table: { headerRows: 1, widths: widths_item_cokol2, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cokol_cuts') { let header_row = [ {text: lang['title'], style: 'tableHeader'}, {text: lang['code'], style: 'tableHeader'}, {text: lang['sizes'], style: 'tableHeader'}, {text: lang['count_short'], style: 'tableHeader'}, ]; tabledata = [header_row]; dd.content.push({ text: (lang['cokol_cuts'] || 'Разрезы цоколей') + ':' + '\n\n', style: 'tableHeader' }); for (const obj of Object.values(item)) { tabledata.push([ obj.name, obj.code, obj.size_x + 'x' + obj.size_z + ' мм', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ]); } dd.content.push( { table: { headerRows: 1, widths: ['*', 'auto', 'auto', 'auto'], body: tabledata, }, layout: tables_layout }, {text: '\n\n'} ); } if (key == 'cokol_top') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['sizes'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['cokol_top'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.width + 'x' + obj.height + ' мм', (obj.price_type === 'm' || obj.price_type === 'm2') ? round_cokol_decimals(obj.total_width) + ' ' + lang['units_' + obj.price_type] : round_cokol_decimals(obj.total_width_m) + ' ' + lang['units_' + 'm'], round_cokol_decimals(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'cornice') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['common_sizes'], style: 'tableHeader' }, { text: lang['cornice_width'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['cornice'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] row.push( obj.name, obj.code, obj.total_width + ' м', obj.width + ' м', round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } dd.content.push( { table: { headerRows: 1, widths: widths, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } if (key == 'item') { let header_row = [ { text: lang['title'], style: 'tableHeader' }, { text: lang['code'], style: 'tableHeader' }, { text: lang['count_short'], style: 'tableHeader' }, ] if (show_price2) header_row.push({ text: lang['price'], style: 'tableHeader' }); tabledata.push(header_row); dd.content.push({ text: lang['accessories_furniture'] + ':' + '\n\n', style: 'tableHeader' }); for (const [i_key, obj] of Object.entries(item)) { console.log(i_key, obj); let row = [] const pdf_safe_obj_name = ('' + (obj.name || '')) .replace(/\u00A0/g, ' ') .replace(/\u25CF/g, '\u2022'); row.push( obj.is_compound_header ? {text: pdf_safe_obj_name, bold: true} : pdf_safe_obj_name, obj.code, round_decimals_2(obj.total_count) + ' ' + lang['units_' + obj.price_type], ) if (show_price2) row.push({ text: (obj.is_compound_header && (parseFloat(obj.total_price) || 0) <= 0) ? (lang['compound'] || 'Составная') : format_price(obj.total_price), alignment: 'right' }); tabledata.push(row) } let widths_item = []; for (let ii = 0; ii < header_row.length; ii++) { ii == 0 ? widths_item.push('*') : widths_item.push('auto') } dd.content.push( { table: { headerRows: 1, widths: widths_item, // dontBreakRows: true, // keepWithHeaderRows: 1, body: tabledata, }, layout: tables_layout }, { text: '\n\n' } ); } } if (pdf_settings.report_modules_comments_list !== false) { if (obj.comments && String(obj.comments).trim() !== '') { dd.content.push({ text: lang['module_comments'] + ':', style: 'tableHeader', }); dd.content.push( { text: obj.comments, alignment: 'left' }, { text: '\n\n' } ); } } if (show_price2) dd.content.push( { text: lang['price_module'] + ': ' + format_price(obj.price) + '\n\n', style: 'tableHeader', bold: false, italics: true, alignment: 'left' }, { text: '\n', } ); } } if (typeof pdf_generation_callback === 'function') { pdf_generation_callback(dd) } if (!imgs) images = null; console.log(dd) const pdfDocGenerator = await pdfMake.createPdf(dd); switch (type) { case 'all': return { base64: new Promise(function (resolve, reject) { pdfDocGenerator.getDataUrl(function (dataUrl) { resolve(dataUrl); }); }), blob: new Promise(function (resolve, reject) { pdfDocGenerator.getBlob(function (blob) { resolve(blob); }); }) } case 'blob': return new Promise(function (resolve, reject) { pdfDocGenerator.getBlob(function (blob) { resolve(blob); }); }); default: return new Promise(function (resolve, reject) { pdfDocGenerator.getDataUrl(function (dataUrl) { resolve(dataUrl); }); }); } if (action === 'send') { return new Promise(function (resolve, reject) { pdfDocGenerator.getDataUrl(function (dataUrl) { resolve(dataUrl); }); }); } else if (action === 'blob') { return new Promise(function (resolve, reject) { pdfDocGenerator.getBlob(function (blob) { resolve(blob); }); }); } else if (action === 'new_tab') { pdfDocGenerator.getDataUrl((dataUrl) => { open_data_uri_window(dataUrl) }); } else if (action === 'download') { let date = new Date(); let str = '' + date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear() + '_' + date.getHours() + ':' + date.getMinutes() + '.pdf'; pdfDocGenerator.download(str); } }