master/detail custom export pdf

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
christ2000
User
Posts: 529

master/detail custom export pdf

Post by christ2000 »

hello i have this code on my list page - row_export detail table to export to pdf

function Row_Export($doc, $rs)
{
    global $Language;

    static $header_added = false;
    static $row_count = 0;
    static $coordinator_info_added = false;

    // Add the coordinator info if not already added
    if (!$coordinator_info_added) {
        // Retrieve the master table and its coordinator field
        $masterTable = $this->getCurrentMasterTable();
        $coordinator = 'Unknown';

        // Check if the master table and coordinator field exist
        if ($masterTable && $this->$masterTable->coordinator) {
            $coordinator = $this->$masterTable->coordinator->ViewValue;
        }

        // Add coordinator information before the table
        $coordinator_info = "<p><strong>Coordinator:</strong> " . $coordinator . "</p>";

        // Append coordinator info to the document
        $doc->Text .= $coordinator_info;

        // Log the coordinator information addition
        error_log("PDF Export Coordinator info added: " . $coordinator_info);

        // Set coordinator info added to true
        $coordinator_info_added = true;
    }

    // Add the header if not already added
    if (!$header_added) {
        $header = "
        <thead>
            <tr>
                <th>Meeting Date</th>
                <th>Duration (hours)</th>
                <th>Meeting Format</th>
                <th>Mode of Meeting</th>
                <th>Observed</th>
                <th>Supervisor</th>
            </tr>
        </thead>
        <tbody>";

        // Append header to document
        $doc->Text .= $header;

        // Log the header addition
        error_log("PDF Export Table Header added with: " . $header);

        // Set header added to true
        $header_added = true;
    }

    // Increment row count
    $row_count++;

    // Log message to check if Row_Export is triggered
    error_log("Row_Export triggered for record with meeting_date: " . $rs["meeting_date"] . ", meeting_duration: " . $rs["meeting_duration"] . ", meeting_format: " . $rs["meeting_format"] . ", mode_of_meeting: " . $rs["mode_of_meeting"] . ", observed: " . $rs["observed"] . ", supervisor: " . $rs["supervisor"]);

    // Check if all fields are correctly retrieved
    if (isset($rs["meeting_date"], $rs["meeting_duration"], $rs["meeting_format"], $rs["mode_of_meeting"], $rs["observed"], $rs["supervisor"])) {
        // Format the meeting_date as MM/DD/YYYY using fully qualified name \DateTime
        $date = \DateTime::createFromFormat('Y-m-d', $rs["meeting_date"]);
        $formatted_date = $date ? $date->format('m/d/Y') : $rs["meeting_date"];

        // Generate row content
        $row = "<tr>
            <td>" . $formatted_date . "</td>
            <td>" . $rs["meeting_duration"] . "</td>
            <td>" . $rs["meeting_format"] . "</td>
            <td>" . $rs["mode_of_meeting"] . "</td>
            <td>" . $rs["observed"] . "</td>
            <td>" . $rs["supervisor"] . "</td>
        </tr>";

        // Append row to document
        $doc->Text .= $row;

        // Log the appended row content
        error_log("Appended row content: " . $row);
    } else {
        // Log error if fields are not found
        error_log("Error: One or more fields not found in the recordset.");
    }

    // Check if it is the last row
    if ($row_count == $this->TotalRecords) {
        // Close the table body and the table
        $footer = "</tbody></table>";

        // Append footer to document
        $doc->Text .= $footer;

        // Log the table closure
        error_log("PDF Export Table closed with: " . $footer);
    }
}

the problem is all field from the detail table are printout perfect but the fields from the the master table are not show, i dont know it the wat i try to get the files are correct on my code


arbei
User
Posts: 9719

Post by arbei »

christ2000 wrote:

// Check if the master table and coordinator field exist
if ($masterTable && $this->$masterTable->coordinator) {
$coordinator = $this->$masterTable->coordinator->ViewValue;
}

It should not be $this->$masterTable.


christ2000
User
Posts: 529

Post by christ2000 »

solution was:
$contact_fullname = htmlspecialchars($GLOBALS["supevision_log"]->contact_fullname->ViewValue);


mobhar
User
Posts: 11905

Post by mobhar »

You may also use:

$contact_fullname = htmlspecialchars(Container("supevision_log")->contact_fullname->ViewValue);

Post Reply