function writeSponChargeList($lNumCharges, &$charges)
{
    //---------------------------------------------------------------------
    //
    //---------------------------------------------------------------------
    global $genumDateFormat;
    if ($lNumCharges > 0) {
        foreach ($charges as $clsC) {
            $lAutoGenID = $clsC->lAutoGenID;
            if (is_null($lAutoGenID)) {
                $strAutoGen = 'n/a';
                $strAGTAlign = 'center';
            } else {
                $strAutoGen = strLinkView_SponsorAutoCharge($lAutoGenID, 'View autogen report', true) . ' ' . str_pad($lAutoGenID, 5, '0', STR_PAD_LEFT) . ' for ' . date('F Y', $clsC->dteAutoCharge);
                $strAGTAlign = 'left';
            }
            echoT('
             <tr>
                <td class="enpRpt" style="text-align: center;">' . strLinkView_SponsorCharge($clsC->lKeyID, 'View charge record', true) . ' ' . str_pad($clsC->lKeyID, 5, '0', STR_PAD_LEFT) . '
                </td>

                <td class="enpRpt">' . date($genumDateFormat, $clsC->dteCharge) . '
                </td>

                <td class="enpRpt" style="text-align: right;">' . $clsC->strACOCurSym . ' ' . number_format($clsC->curChargeAmnt, 2) . ' ' . $clsC->strACOFlagImg . '
                </td>

                <td class="enpRpt" style="text-align: ' . $strAGTAlign . ';">' . $strAutoGen . '
                </td>
             </tr>
         ');
        }
    }
}
function showChargeRec($clsRpt, $cRec, $lSponID, $lChargeID)
{
    //---------------------------------------------------------------------
    //
    //---------------------------------------------------------------------
    global $genumDateFormat;
    openBlock('Charge Record', strLinkEdit_SponChargeRec($lSponID, $lChargeID, 'Edit Charge Record', true) . '&nbsp;&nbsp;&nbsp;' . strLinkAdd_SponsorCharges($lSponID, 'Add new charge', true) . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . strLinkRem_SponsorCharge($lSponID, $lChargeID, 'Remove charge', true, true));
    echoT($clsRpt->openReport() . $clsRpt->openRow() . $clsRpt->writeLabel('Charge ID:') . $clsRpt->writeCell(str_pad($lChargeID, 5, '0', STR_PAD_LEFT)) . $clsRpt->closeRow());
    $lAutoChargeID = $cRec->lAutoGenID;
    if (is_null($lAutoChargeID)) {
        $strAutoCell = 'n/a';
    } else {
        $strAutoCell = strLinkView_SponsorAutoCharge($lAutoChargeID, 'View auto-charge entry', true) . '&nbsp;' . str_pad($lAutoChargeID, 5, '0', STR_PAD_LEFT);
    }
    echoT($clsRpt->openRow() . $clsRpt->writeLabel('AutoGen ID:') . $clsRpt->writeCell($strAutoCell) . $clsRpt->closeRow() . $clsRpt->openRow() . $clsRpt->writeLabel('Amount:') . $clsRpt->writeCell($cRec->strCurSymbol . ' ' . number_format($cRec->curChargeAmnt, 2) . ' ' . $cRec->strFlagImage) . $clsRpt->closeRow() . $clsRpt->openRow() . $clsRpt->writeLabel('Date of charge:') . $clsRpt->writeCell(date($genumDateFormat, $cRec->dteCharge)) . $clsRpt->closeRow() . $clsRpt->closeReport());
    closeBlock();
}
 function strSponMonthChargeReport(&$sRpt, &$displayData, $lStartRec, $lRecsPerPage)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $genumDateFormat;
     $strOut = '';
     $strLimit = " LIMIT {$lStartRec}, {$lRecsPerPage} ";
     $this->sponIncomeViaMonthVars($sRpt, $lYear, $lMonth, $lACOID);
     $cACO = new madmin_aco();
     $cACO->loadCountries(false, true, true, $lACOID);
     $cCountry = $cACO->countries[0];
     $strOut = '<table class="enpView">
         <tr>
            <td class="enpViewLabel" colspan="2" style="text-align: left; font-size: 13pt;">
               Sponsorship Charges
            </td>
         </tr>
         <tr>
            <td class="enpViewLabel">
               Accounting Country:
            </td>
            <td class="enpView">' . $cCountry->strName . ' ' . $cCountry->strCurrencySymbol . ' ' . $cCountry->strFlagImg . '
            </td>
         </tr>
         <tr>
            <td class="enpViewLabel">
               Month:
            </td>
            <td class="enpView">' . strXlateMonth($lMonth) . ' ' . $lYear . '
            </td>
         </tr>
      </table>';
     $sqlStr = "SELECT\n            spc_lKeyID, spc_lSponsorshipID,\n            spc_dteCharge,\n\n            spc_lAutoGenID, spc_lAutoGenACOID, spc_curAutoGenCommitAmnt,\n            spc_curChargeAmnt, spc_lACOID, spc_strNotes,\n            sp_lForeignID,\n            spon.pe_bBiz AS bSponBiz, spon.pe_strLName AS strSponLName, spon.pe_strFName AS strSponFName\n         FROM sponsor_charges\n            INNER JOIN sponsor               ON spc_lSponsorshipID=sp_lKeyID\n            INNER JOIN people_names AS spon  ON sp_lForeignID=spon.pe_lKeyID\n\n         WHERE NOT spc_bRetired\n            AND spc_lACOID={$lACOID}\n            AND MONTH(spc_dteCharge)={$lMonth}\n            AND YEAR (spc_dteCharge)={$lYear}\n            AND spc_lSponsorshipID IS NOT NULL\n         ORDER BY spc_dteCharge, spc_lKeyID\n         {$strLimit};";
     $query = $this->db->query($sqlStr);
     $lNumRows = $query->num_rows();
     if ($lNumRows > 0) {
         $strOut .= '
         <table class="enpRptC">
            <tr>
               <td class="enpRptLabel">
                  Charge ID
               </td>
               <td class="enpRptLabel">
                  Sponsor ID
               </td>
               <td class="enpRptLabel">
                  Amount
               </td>
               <td class="enpRptLabel">
                  Date
               </td>
               <td class="enpRptLabel">
                  Autocharge ID
               </td>
               <td class="enpRptLabel">
                  People/Biz ID
               </td>
               <td class="enpRptLabel">
                  Sponsor
               </td>
            </tr>';
         foreach ($query->result() as $row) {
             $lChargeID = $row->spc_lKeyID;
             $lSponsorID = $row->spc_lSponsorshipID;
             $lSponsorFID = $row->sp_lForeignID;
             $lAutoGenID = $row->spc_lAutoGenID;
             if (is_null($lAutoGenID)) {
                 $strAutoGen = 'n/a';
             } else {
                 $strAutoGen = strLinkView_SponsorAutoCharge($lAutoGenID, 'View Auto-Charge Log', true) . '&nbsp;' . str_pad($lAutoGenID, 5, '0', STR_PAD_LEFT);
             }
             // chargbe ID
             $strOut .= '
             <tr>
                <td class="enpRpt" style="text-align: center;">' . strLinkView_SponsorCharge($lChargeID, 'View charge record', true) . '&nbsp;' . str_pad($lChargeID, 5, '0', STR_PAD_LEFT) . '
                </td>';
             // sponsor ID
             $strOut .= '
                <td class="enpRpt" style="text-align: center;">' . strLinkView_Sponsorship($lSponsorID, 'View sponsorship record', true) . '&nbsp;' . str_pad($lSponsorID, 5, '0', STR_PAD_LEFT) . '
                </td>';
             // Amount
             $strOut .= '
                <td class="enpRpt" style="text-align: right; padding-left: 14px;">' . number_format($row->spc_curChargeAmnt, 2) . '
                </td>';
             // Date
             $strOut .= '
                <td class="enpRpt" style="text-align: right;">' . date($genumDateFormat, dteMySQLDate2Unix($row->spc_dteCharge)) . '
                </td>';
             // Autogen ID
             $strOut .= '
                <td class="enpRpt" style="text-align: center;">' . $strAutoGen . '
                </td>';
             // People/Biz ID
             if ($row->bSponBiz) {
                 $strLink = strLinkView_BizRecord($lSponsorFID, 'View business record', true) . '&nbsp;' . str_pad($lSponsorFID, 5, '0', STR_PAD_LEFT);
             } else {
                 $strLink = strLinkView_PeopleRecord($lSponsorFID, 'View people record', true) . '&nbsp;' . str_pad($lSponsorFID, 5, '0', STR_PAD_LEFT);
             }
             $strOut .= '
                <td class="enpRpt" style="text-align: center;">' . $strLink . '
                </td>';
             // Sponsor
             if ($row->bSponBiz) {
                 $strName = htmlspecialchars($row->strSponLName) . ' (business)';
             } else {
                 $strName = htmlspecialchars($row->strSponLName . ', ' . $row->strSponFName);
             }
             $strOut .= '
                <td class="enpRpt" >' . $strName . '
                </td>';
             $strOut . '
             </tr>';
         }
         $strOut .= '</table>';
     } else {
         $strOut .= '<br><br><i>There are no records that match your search criteria</i><br>';
     }
     return $strOut;
 }
<?php

global $genumDateFormat;
echoT('<br>You can automatically apply charges for all active sponsorship on a monthly basis.<br><br>');
echoT('<table>');
foreach ($autoCharges12Mo as $clsMoCharge) {
    if (is_null($clsMoCharge->lKeyID)) {
        $strLabel = '<i>Charges not applied</i>';
        $strLink = strLinkAdd_SponsorAutoCharges($clsMoCharge->lMonth, $clsMoCharge->lYear, 'Apply Charges', true, 'id="charge_' . $clsMoCharge->lYear . '_' . $clsMoCharge->lMonth . '"');
    } else {
        $strLabel = 'Charges applied on ' . date($genumDateFormat, $clsMoCharge->dteOrigin) . ' by ' . $clsMoCharge->strUserSafe;
        $strLink = strLinkView_SponsorAutoCharge($clsMoCharge->lKeyID, 'View autocharge entry', true);
    }
    echoT('<tr>');
    echoT('<td>' . $strLink . '</td>');
    echoT('<td>' . str_pad($clsMoCharge->lMonth, 2, '0', STR_PAD_LEFT) . '-' . $clsMoCharge->lYear . '</td>');
    echoT('<td>' . $strLabel . '</td>');
    echoT('</tr>');
}
echoT('</table>');