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 writeAutoChargeRow($clsACInfo)
{
    //---------------------------------------------------------------------
    //
    //---------------------------------------------------------------------
    $lCID = $clsACInfo->lKeyID;
    $lSponID = $clsACInfo->lSponsorshipID;
    $bBiz = $clsACInfo->bBiz;
    $lFID = $clsACInfo->lForeignID;
    $lClientID = $clsACInfo->lClientID;
    if (is_null($lClientID)) {
        $strClientRow = 'n/a';
    } else {
        $strClientRow = strLinkView_ClientRecord($lClientID, 'View Client', true) . ' ' . str_pad($lClientID, 5, '0', STR_PAD_LEFT) . ' ' . $clsACInfo->strClientSafeNameFL . ' / ' . htmlspecialchars($clsACInfo->strLocation);
    }
    if ($bBiz) {
        $strFLink = strLinkView_BizRecord($lFID, 'View business record', true);
    } else {
        $strFLink = strLinkView_PeopleRecord($lFID, 'View people record', true);
    }
    echoT('
      <tr>
         <td class="enpRpt" style="text-align:center">' . strLinkView_SponsorCharge($lCID, 'View charge record', true) . '&nbsp;' . str_pad($lCID, 5, '0', STR_PAD_LEFT) . '
         </td>');
    echoT('
         <td class="enpRpt" style="text-align:center">' . strLinkView_Sponsorship($lSponID, 'View sponsorship record', true) . '&nbsp;' . str_pad($lSponID, 5, '0', STR_PAD_LEFT) . '
         </td>');
    //------------------------------
    // sponsor
    //------------------------------
    echoT('
         <td class="enpRpt">' . $strFLink . '&nbsp;' . $clsACInfo->strSponSafeNameFL . '
         </td>');
    //------------------------------
    // charge
    //------------------------------
    echoT('
         <td class="enpRpt" style="text-align: right;">' . $clsACInfo->strCurSymbol . '&nbsp;' . number_format($clsACInfo->curChargeAmnt, 2) . '&nbsp;' . $clsACInfo->strFlagImage . '
         </td>');
    //------------------------------
    // client
    //------------------------------
    echoT('
         <td class="enpRpt">' . $strClientRow . '
         </td>');
    echoT('
      </tr>');
}
 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;
 }