<?php include_once "header.php" ?>

<?php


// Initialize value
$statementyear = htmlspecialchars($_POST["statementyear"]);
if ($statementyear==""){
  $statementyear = "current";
  $prevcheck     = "";
  $currcheck     = "checked";
  $user->log($user_id, 6, "Current Year");  
} else if ($statementyear=="current"){
  $prevcheck     = "";
  $currcheck     = "checked";
  $user->log($user_id, 6, "Current Year");  
} else if ($statementyear=="previous"){
  $prevcheck     = "checked";
  $currcheck     = "";
  $user->log($user_id, 6, "Previous Year");
}

$user_id_withrank = trim(ew_RemoveXSS(ew_StripSlashes($_SESSION['ARMYNOWITHRANK'])));

//$user_id_withrank = '30099811';

// Open connection
if (!isset($conn)) $conn = ew_Connect();


// KIOSK 2
$sql = "SELECT *
          FROM [dbo].[LTAT_tbl_statementprevious]
         WHERE PersonnelID='$user_id_withrank'
       ";
$rs  = ew_Execute($sql);
if ($rs->RecordCount() > 0) {
  $rs->MoveFirst();
  $sData = "";
  while ($rs && !$rs->EOF) {
    $DividendMember = number_format(sprintf('%0.2f', $rs->fields['DividendMember']), 2);
    $DividendGov    = number_format(sprintf('%0.2f', $rs->fields['DividendGov']), 2);
    
    $rs->MoveNext();
  }
  //echo $sData;
  $rs->Close();
} else {
  $DividendMember  = 0;
  $DividendGov     = 0;
  //$this->setFailureMessage("No records are found.");
}


// KIOSK 2
if ($statementyear=="previous"){
  $sql = "SELECT  ContriStartBalanceMember+ContriStartDividendMember-ContriAdjStartBalanceMember-ContriAdjStartDividendMember AS BalanceMember1stJan
                 ,ContriStartBalanceGov+ContriStartDividendGov-ContriAdjStartBalanceGov-ContriAdjStartDividendGov             AS BalanceGov1stJan
                 ,*
            FROM [dbo].[LTAT_tbl_statementprevious]
           WHERE PersonnelID='$user_id_withrank'
         ";
} else {
  $sql = "SELECT  ContriStartBalanceMember+ContriStartDividendMember-ContriAdjStartBalanceMember-ContriAdjStartDividendMember AS BalanceMember1stJan
                 ,ContriStartBalanceGov+ContriStartDividendGov-ContriAdjStartBalanceGov-ContriAdjStartDividendGov             AS BalanceGov1stJan
                 ,*
            FROM [dbo].[LTAT_tbl_statementcurrent]
           WHERE PersonnelID='$user_id_withrank'
         ";
}
$rs  = ew_Execute($sql);
if ($rs->RecordCount() > 0) {
  $rs->MoveFirst();
  $sData = "";
  while ($rs && !$rs->EOF) {
    $PersonnelID                     = ltrim(substr($rs->fields['PersonnelID'], 0, -1), '0');
    $PersonnelName                   = addslashes($rs->fields['PersonnelName']);
    $StatusHousing                   = $rs->fields['StatusHousing'];    
    $DateOfBirth                     = date("d M Y", strtotime($rs->fields['DateOfBirth']));
    $ContriStartDate                 = date("d M Y", strtotime($rs->fields['ContriStartDate']));
    $StatementYear                   = $rs->fields['StatementYear'];
    $BalanceMember1stJan             = $rs->fields['BalanceMember1stJan'] ;
    $BalanceGov1stJan                = $rs->fields['BalanceGov1stJan']    ;    
    $ContriStartBalanceMember        = number_format(sprintf('%0.2f', $rs->fields['ContriStartBalanceMember']       ), 2);
    $ContriStartBalanceGov           = number_format(sprintf('%0.2f', $rs->fields['ContriStartBalanceGov']          ), 2);
    $ContriStartDividendMember       = number_format(sprintf('%0.2f', $rs->fields['ContriStartDividendMember']      ), 2);
    $ContriStartDividendGov          = number_format(sprintf('%0.2f', $rs->fields['ContriStartDividendGov']         ), 2);
    $ContriAdjStartBalanceMember     = number_format(sprintf('%0.2f', $rs->fields['ContriAdjStartBalanceMember']    ), 2);
    $ContriAdjStartBalanceGov        = number_format(sprintf('%0.2f', $rs->fields['ContriAdjStartBalanceGov']       ), 2);
    $ContriAdjStartDividendMember    = number_format(sprintf('%0.2f', $rs->fields['ContriAdjStartDividendMember']   ), 2);
    $ContriAdjStartDividendGov       = number_format(sprintf('%0.2f', $rs->fields['ContriAdjStartDividendGov']      ), 2);
    $HousingWithdrawalContriMember   = number_format(sprintf('%0.2f', $rs->fields['HousingWithdrawalContriMember']  ), 2);
    $HousingWithdrawalDividendMember = number_format(sprintf('%0.2f', $rs->fields['HousingWithdrawalDividendMember']), 2);
    $HousingDividendDebit            = number_format(sprintf('%0.2f', $rs->fields['HousingDividendDebit']           ), 2);
    $HousingDividendCredit           = number_format(sprintf('%0.2f', $rs->fields['HousingDividendCredit']          ), 2);
    $BonusMember                     = $rs->fields['BonusMember'];
    $BonusGov                        = $rs->fields['BonusGov'];
    $M01ContriMember                 = $rs->fields['M01ContriMember']           ;
    $M01ContriGov                    = $rs->fields['M01ContriGov']              ;
    $M01AdjustmentMember             = $rs->fields['M01AdjustmentMember']       ;
    $M01AdjustmentGov                = $rs->fields['M01AdjustmentGov']          ;
    $M01AdjustmentContriMember       = $rs->fields['M01AdjustmentContriMember'] ;
    $M01AdjustmentContriGov          = $rs->fields['M01AdjustmentContriGov']    ;
    $M02ContriMember                 = $rs->fields['M02ContriMember']           ;
    $M02ContriGov                    = $rs->fields['M02ContriGov']              ;
    $M02AdjustmentMember             = $rs->fields['M02AdjustmentMember']       ;
    $M02AdjustmentGov                = $rs->fields['M02AdjustmentGov']          ;
    $M02AdjustmentContriMember       = $rs->fields['M02AdjustmentContriMember'] ;
    $M02AdjustmentContriGov          = $rs->fields['M02AdjustmentContriGov']    ;
    $M03ContriMember                 = $rs->fields['M03ContriMember']           ;
    $M03ContriGov                    = $rs->fields['M03ContriGov']              ;
    $M03AdjustmentMember             = $rs->fields['M03AdjustmentMember']       ;
    $M03AdjustmentGov                = $rs->fields['M03AdjustmentGov']          ;
    $M03AdjustmentContriMember       = $rs->fields['M03AdjustmentContriMember'] ;
    $M03AdjustmentContriGov          = $rs->fields['M03AdjustmentContriGov']    ;
    $M04ContriMember                 = $rs->fields['M04ContriMember']           ;
    $M04ContriGov                    = $rs->fields['M04ContriGov']              ;
    $M04AdjustmentMember             = $rs->fields['M04AdjustmentMember']       ;
    $M04AdjustmentGov                = $rs->fields['M04AdjustmentGov']          ;
    $M04AdjustmentContriMember       = $rs->fields['M04AdjustmentContriMember'] ;
    $M04AdjustmentContriGov          = $rs->fields['M04AdjustmentContriGov']    ;
    $M05ContriMember                 = $rs->fields['M05ContriMember']           ;
    $M05ContriGov                    = $rs->fields['M05ContriGov']              ;
    $M05AdjustmentMember             = $rs->fields['M05AdjustmentMember']       ;
    $M05AdjustmentGov                = $rs->fields['M05AdjustmentGov']          ;
    $M05AdjustmentContriMember       = $rs->fields['M05AdjustmentContriMember'] ;
    $M05AdjustmentContriGov          = $rs->fields['M05AdjustmentContriGov']    ;
    $M06ContriMember                 = $rs->fields['M06ContriMember']           ;
    $M06ContriGov                    = $rs->fields['M06ContriGov']              ;
    $M06AdjustmentMember             = $rs->fields['M06AdjustmentMember']       ;
    $M06AdjustmentGov                = $rs->fields['M06AdjustmentGov']          ;
    $M06AdjustmentContriMember       = $rs->fields['M06AdjustmentContriMember'] ;
    $M06AdjustmentContriGov          = $rs->fields['M06AdjustmentContriGov']    ;
    $M07ContriMember                 = $rs->fields['M07ContriMember']           ;
    $M07ContriGov                    = $rs->fields['M07ContriGov']              ;
    $M07AdjustmentMember             = $rs->fields['M07AdjustmentMember']       ;
    $M07AdjustmentGov                = $rs->fields['M07AdjustmentGov']          ;
    $M07AdjustmentContriMember       = $rs->fields['M07AdjustmentContriMember'] ;
    $M07AdjustmentContriGov          = $rs->fields['M07AdjustmentContriGov']    ;
    $M08ContriMember                 = $rs->fields['M08ContriMember']           ;
    $M08ContriGov                    = $rs->fields['M08ContriGov']              ;
    $M08AdjustmentMember             = $rs->fields['M08AdjustmentMember']       ;
    $M08AdjustmentGov                = $rs->fields['M08AdjustmentGov']          ;
    $M08AdjustmentContriMember       = $rs->fields['M08AdjustmentContriMember'] ;
    $M08AdjustmentContriGov          = $rs->fields['M08AdjustmentContriGov']    ;
    $M09ContriMember                 = $rs->fields['M09ContriMember']           ;
    $M09ContriGov                    = $rs->fields['M09ContriGov']              ;
    $M09AdjustmentMember             = $rs->fields['M09AdjustmentMember']       ;
    $M09AdjustmentGov                = $rs->fields['M09AdjustmentGov']          ;
    $M09AdjustmentContriMember       = $rs->fields['M09AdjustmentContriMember'] ;
    $M09AdjustmentContriGov          = $rs->fields['M09AdjustmentContriGov']    ;
    $M10ContriMember                 = $rs->fields['M10ContriMember']           ;
    $M10ContriGov                    = $rs->fields['M10ContriGov']              ;
    $M10AdjustmentMember             = $rs->fields['M10AdjustmentMember']       ;
    $M10AdjustmentGov                = $rs->fields['M10AdjustmentGov']          ;
    $M10AdjustmentContriMember       = $rs->fields['M10AdjustmentContriMember'] ;
    $M10AdjustmentContriGov          = $rs->fields['M10AdjustmentContriGov']    ;
    $M11ContriMember                 = $rs->fields['M11ContriMember']           ;
    $M11ContriGov                    = $rs->fields['M11ContriGov']              ;
    $M11AdjustmentMember             = $rs->fields['M11AdjustmentMember']       ;
    $M11AdjustmentGov                = $rs->fields['M11AdjustmentGov']          ;
    $M11AdjustmentContriMember       = $rs->fields['M11AdjustmentContriMember'] ;
    $M11AdjustmentContriGov          = $rs->fields['M11AdjustmentContriGov']    ;
    $M12ContriMember                 = $rs->fields['M12ContriMember']           ;
    $M12ContriGov                    = $rs->fields['M12ContriGov']              ;
    $M12AdjustmentMember             = $rs->fields['M12AdjustmentMember']       ;
    $M12AdjustmentGov                = $rs->fields['M12AdjustmentGov']          ;
    $M12AdjustmentContriMember       = $rs->fields['M12AdjustmentContriMember'] ;
    $M12AdjustmentContriGov          = $rs->fields['M12AdjustmentContriGov']    ;
    $M00ContriMember                 = $rs->fields['M00ContriMember']           ;
    $M00ContriGov                    = $rs->fields['M00ContriGov']              ;
    $M00AdjustmentMember             = $rs->fields['M00AdjustmentMember']       ;
    $M00AdjustmentGov                = $rs->fields['M00AdjustmentGov']          ;
    $M00AdjustmentContriMember       = $rs->fields['M00AdjustmentContriMember'] ;
    $M00AdjustmentContriGov          = $rs->fields['M00AdjustmentContriGov']    ;
    $StatementMonth                  = $rs->fields['StatementMonth'];
    $StatementYear                   = $rs->fields['StatementYear'];
    $Waris1                          = addslashes($rs->fields['Waris1']);
    $Waris2                          = addslashes($rs->fields['Waris2']);
    $Waris3                          = addslashes($rs->fields['Waris3']);
    $Waris4                          = addslashes($rs->fields['Waris4']);
    $FPCode                          = $rs->fields['FPCode'];
    $Account1                        = $rs->fields['Account1'];
    $Account2                        = $rs->fields['Account2'];
    
    if ($statementyear=="previous"){
        $DividendMember = $rs->fields['DividendMember'];
        $DividendGov    = $rs->fields['DividendGov'];
    } else {
        $DividendMember = '0.00';
        $DividendGov    = '0.00';
    }
    
    

    $SumCarumanAhli      = $M01ContriMember + $M01AdjustmentMember +
                           $M02ContriMember + $M02AdjustmentMember +
                           $M03ContriMember + $M03AdjustmentMember +
                           $M04ContriMember + $M04AdjustmentMember +
                           $M05ContriMember + $$M05AdjustmentMember +
                           $M06ContriMember + $$M06AdjustmentMember +
                           $M07ContriMember + $M07AdjustmentMember +
                           $M08ContriMember + $M08AdjustmentMember +
                           $M09ContriMember + $M09AdjustmentMember +
                           $M10ContriMember + $$M10AdjustmentMember +
                           $M11ContriMember + $M11AdjustmentMember +
                           $M12ContriMember + $M12AdjustmentMember;

    $SumCarumanKerajaan = $M01ContriGov + $M01AdjustmentGov +
                          $M02ContriGov + $M02AdjustmentGov +
                          $M03ContriGov + $M03AdjustmentGov +
                          $M04ContriGov + $M04AdjustmentGov +
                          $M05ContriGov + $M05AdjustmentGov +
                          $M06ContriGov + $M06AdjustmentGov +
                          $M07ContriGov + $M07AdjustmentGov +
                          $M08ContriGov + $M08AdjustmentGov +
                          $M09ContriGov + $M09AdjustmentGov +
                          $M10ContriGov + $M10AdjustmentGov +
                          $M11ContriGov + $M11AdjustmentGov +
                          $M12ContriGov + $M12AdjustmentGov;

    $rs->MoveNext();
  }
  //echo $sData;
  $rs->Close();
} else {
  //$this->setFailureMessage("No records are found.");
}

$SumCarumanAhli     = $BalanceMember1stJan + $SumCarumanAhli     + $DividendMember;
$SumCarumanKerajaan = $BalanceGov1stJan    + $SumCarumanKerajaan + $DividendGov;

$HousingRemark = 'Ya';
$HajiRemark    = 'Ya';


// KIOSK 3 - Withdrawal
$sql = "SELECT  StatusWithdrawal
               ,ChequeWithdrawalDate
               ,TotalPayment
          FROM [dbo].[LTAT_tbl_withdrawal]
         WHERE PersonnelID='$user_id_withrank'
       ";
$rs  = ew_Execute($sql);
if ($rs->RecordCount() > 0) {
  $rs->MoveFirst();
  $sData = "";
  while ($rs && !$rs->EOF) {
    $StatusWithdrawal = $rs->fields['StatusWithdrawal'];  // 01-Persaraan, 02-Perumahan, 03-Haji
    
    if ($StatusWithdrawal=='02'){
      $HousingRemark               = 'Tidak';
      $HousingChequeWithdrawalDate = date("Y-m-d", strtotime($rs->fields['ChequeWithdrawalDate']));
      $HousingWithdrawalAmount     = $rs->fields['TotalPayment'];
    }
    
    if ($StatusWithdrawal=='03'){
      $HajiRemark = 'Tidak'; 
    }

    $rs->MoveNext();
  }

  //echo $sData;
  $rs->Close();
}  

if ($StatusHousing=="50" || $StatusHousing=="00"){
  $HousingRemark = "Tidak";
}





?>



<script type="text/javascript" src="plugins/jspdf/jspdf.debug.js"></script>
<script type="text/javascript" src="plugins/jspdf/standard_fonts_metrics.js"></script>
<script type="text/javascript" src="plugins/jspdf/split_text_to_size.js"></script>
<script type="text/javascript" src="plugins/jspdf-autotable/jspdf.plugin.autotable.js"></script>

<script type="text/javascript">
      //function demoTwoPageDocument() {
      //  var doc = new jsPDF();
      //  doc.text(20, 20, 'Hello world!');
      //  doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
      //  doc.addPage();
      //  doc.text(20, 20, 'Do you like that?');

      //  var data = doc.output('datauristring')
      //  $('iframe').attr('src', data)

        // Save the PDF
        //doc.save('Test.pdf');
      //}
function GeneratePDF(outputmethod) {
    /////////////////////////////////////////
    // Additional function for text alignment
    // Usage: pdf.textEx('Example text', xPosition, yPosition, 'right', 'middle');
    /////////////////////////////////////////
    var splitRegex = /\r\n|\r|\n/g;
    jsPDF.API.textEx = function (text, x, y, hAlign, vAlign) {
        var fontSize = this.internal.getFontSize() / this.internal.scaleFactor;

        // As defined in jsPDF source code
        var lineHeightProportion = 1.15;

        var splittedText = null;
        var lineCount = 1;
        if (vAlign === 'middle' || vAlign === 'bottom' || hAlign === 'center' || hAlign === 'right') {
            splittedText = typeof text === 'string' ? text.split(splitRegex) : text;

            lineCount = splittedText.length || 1;
        }

        // Align the top
        y += fontSize * (2 - lineHeightProportion);

        if (vAlign === 'middle')
            y -= (lineCount / 2) * fontSize;
        else if (vAlign === 'bottom')
            y -= lineCount * fontSize;

        if (hAlign === 'center' || hAlign === 'right') {
            var alignSize = fontSize;
            if (hAlign === 'center')
                alignSize *= 0.5;

            if (lineCount > 1) {
                for (var iLine = 0; iLine < splittedText.length; iLine++) {
                    this.text(splittedText[iLine], x - this.getStringUnitWidth(splittedText[iLine]) * alignSize, y);
                    y += fontSize;
                }
                return this;
            }
            x -= this.getStringUnitWidth(text) * alignSize;
        }

        this.text(text, x, y);
        return this;
    };
    /////////////////////////////////////////
    // end of text alignment function
    /////////////////////////////////////////


    if (outputmethod === undefined) {
          outputmethod = 'display';
    }

    var doc = new jsPDF('p', 'pt');
    //doc.text("From HTML", 40, 50);
    //var test = doc.autoTableEndPosY().toString();
    //doc.text(test,40,50);

    doc.setFontSize(20);
    doc.setTextColor(40);
    doc.setFontStyle('bold');
    doc.text('LEMBAGA TABUNG ANGKATAN TENTERA',90,40)
    doc.setFontSize(13);
    doc.setTextColor(40);
    doc.setFontStyle('normal');
    doc.text('PENYATA CARUMAN AHLI',180,80);
    doc.setFontSize(13);
    doc.text('TAHUN',450,80);
    doc.rect(500,65,55,20); //tahun text box
    doc.text('<?php echo $StatementYear ?>',510,80); // to fill in
    doc.setFontSize(10);
    doc.text('No. Tentera: <?php echo $PersonnelID ?>',40,100);
    doc.text('Tarikh Lahir:                  <?php echo $DateOfBirth ?>',350,100);
    doc.text("Nama:          <?php echo $PersonnelName ?>",40,120);
    doc.text('Tarikh Mula Mencarum: <?php echo $ContriStartDate ?>',350,120);


    // set background fill. Must set first before drawing lines
    doc.setFillColor('0.85');
    doc.rect(40, 440, 515, 40, 'F');
    doc.rect(215, 180, 340, 20, 'F');

    // table header
    doc.line(215, 160, 555, 160); // 2nd and 3rd col horizontal line 1
    doc.line(215, 180, 555, 180); // 2nd and 3rd col horizontal line 2



    // draw table layout
    doc.line(40,140,555,140); //top most horizontal line
    doc.line(40,200,555,200);
    doc.line(40,220,555,220);
    doc.line(40,240,555,240);
    doc.line(40,260,555,260);
    doc.line(40,280,555,280);
    doc.line(40,300,555,300);
    doc.line(40,320,555,320);
    doc.line(40,340,555,340);
    doc.line(40,360,555,360);
    doc.line(40,380,555,380);
    doc.line(40,400,555,400);
    doc.line(40,420,555,420);
    doc.line(40,440,555,440);
    doc.line(40,460,555,460);
    doc.line(40,480,555,480); //bottom most horizontal line
    doc.line(40,500,385,500); // bottom Akaun 1 horizontal line
    doc.line(40,520,385,520); // bottom Akaun 2 horizontal line

    doc.line(40,140,40,520);   // left most vertical line
    doc.line(215,140,215,520); // vertical line 2
    doc.line(300,180,300,440); // vertical line 3
    doc.line(385,140,385,520); // vertical line 4
    doc.line(470,180,470,440); // vertical line 5
    doc.line(555,140,555,480); // right most vertical line

    // table header text
    doc.setFontStyle('bold');
    doc.text('Baki Pada 1 Januari',45,  175);
    doc.text('AHLI (RM)',          275, 155);
    doc.text('KERAJAAN (RM)',      435, 155);
    doc.text('Caruman',            235, 195);
    doc.text('Pelarasan',          320, 195);
    doc.text('Caruman',            405, 195);
    doc.text('Pelarasan',          490, 195);

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $BalanceMember1stJan), 2); ?>', 300, 170, 'center', 'middle'); // to fill in |
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $BalanceGov1stJan), 2);    ?>', 470, 170, 'center', 'middle'); // to fill in

    // body month text
    doc.setFontStyle('normal');
    doc.text('JANUARI',               45, 215);
    doc.text('FEBRUARI',              45, 235);
    doc.text('MAC',                   45, 255);
    doc.text('APRIL',                 45, 275);
    doc.text('MEI',                   45, 295);
    doc.text('JUN',                   45, 315);
    doc.text('JULAI',                 45, 335);
    doc.text('OGOS',                  45, 355);
    doc.text('SEPTEMBER',             45, 375);
    doc.text('OKTOBER',               45, 395);
    doc.text('NOVEMBER',              45, 415);
    doc.text('DISEMBER',              45, 435);
    doc.setFontStyle('bold');
    doc.text('Jumlah Dividen',        45, 455);
    doc.text('Baki Semasa',           45, 475);
    doc.setFontStyle('normal');
    doc.text('Akaun 1 (60%)',         45, 495);
    doc.text('Akaun 2 (40%)',         45, 515);

    // body content value
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M01ContriMember), 2); ?>', 295, 215, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M02ContriMember), 2); ?>', 295, 235, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M03ContriMember), 2); ?>', 295, 255, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M04ContriMember), 2); ?>', 295, 275, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M05ContriMember), 2); ?>', 295, 295, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M06ContriMember), 2); ?>', 295, 315, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M07ContriMember), 2); ?>', 295, 335, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M08ContriMember), 2); ?>', 295, 355, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M09ContriMember), 2); ?>', 295, 375, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M10ContriMember), 2); ?>', 295, 395, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M11ContriMember), 2); ?>', 295, 415, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M12ContriMember), 2); ?>', 295, 435, 'right', 'bottom');

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M01AdjustmentMember), 2); ?>', 380, 215, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M02AdjustmentMember), 2); ?>', 380, 235, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M03AdjustmentMember), 2); ?>', 380, 255, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M04AdjustmentMember), 2); ?>', 380, 275, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M05AdjustmentMember), 2); ?>', 380, 295, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M06AdjustmentMember), 2); ?>', 380, 315, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M07AdjustmentMember), 2); ?>', 380, 335, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M08AdjustmentMember), 2); ?>', 380, 355, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M09AdjustmentMember), 2); ?>', 380, 375, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M10AdjustmentMember), 2); ?>', 380, 395, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M11AdjustmentMember), 2); ?>', 380, 415, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M12AdjustmentMember), 2); ?>', 380, 435, 'right', 'bottom');

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M01ContriGov), 2); ?>', 465, 215, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M02ContriGov), 2); ?>', 465, 235, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M03ContriGov), 2); ?>', 465, 255, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M04ContriGov), 2); ?>', 465, 275, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M05ContriGov), 2); ?>', 465, 295, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M06ContriGov), 2); ?>', 465, 315, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M07ContriGov), 2); ?>', 465, 335, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M08ContriGov), 2); ?>', 465, 355, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M09ContriGov), 2); ?>', 465, 375, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M10ContriGov), 2); ?>', 465, 395, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M11ContriGov), 2); ?>', 465, 415, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M12ContriGov), 2); ?>', 465, 435, 'right', 'bottom');

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M01AdjustmentGov), 2); ?>', 550, 215, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M02AdjustmentGov), 2); ?>', 550, 235, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M03AdjustmentGov), 2); ?>', 550, 255, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M04AdjustmentGov), 2); ?>', 550, 275, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M05AdjustmentGov), 2); ?>', 550, 295, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M06AdjustmentGov), 2); ?>', 550, 315, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M07AdjustmentGov), 2); ?>', 550, 335, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M08AdjustmentGov), 2); ?>', 550, 355, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M09AdjustmentGov), 2); ?>', 550, 375, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M10AdjustmentGov), 2); ?>', 550, 395, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M11AdjustmentGov), 2); ?>', 550, 415, 'right', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $M12AdjustmentGov), 2); ?>', 550, 435, 'right', 'bottom');

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $DividendMember), 2); ?>', 295, 455, 'center', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $DividendGov), 2); ?>',    465, 455, 'center', 'bottom');

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $SumCarumanAhli), 2); ?>',     295, 475, 'center', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $SumCarumanKerajaan), 2); ?>', 465, 475, 'center', 'bottom');

    doc.textEx('<?php echo number_format(sprintf('%0.2f', $Account1), 2); ?>', 295, 495, 'center', 'bottom');
    doc.textEx('<?php echo number_format(sprintf('%0.2f', $Account2), 2); ?>', 295, 515, 'center', 'bottom');




    // waris
    doc.rect(40, 550, 515, 100);
    doc.text('Maklumat Waris:', 45, 565);
    doc.text('1.', 75,  595);
    doc.text('2.', 75,  615);
    doc.text('3.', 300, 595);
    doc.text('4.', 300, 615);
    doc.line(85,598,255,598);  // waris #1 line
    doc.line(310,598,480,598); // waris #3 line
    doc.line(85,618,255,618);  // waris #2 line
    doc.line(310,618,480,618); // waris #4 line

    doc.text('<?php echo $Waris1 ?>', 85, 595);
    doc.text('<?php echo $Waris2 ?>', 85, 615);
    doc.text('<?php echo $Waris3 ?>', 310, 595);
    doc.text('<?php echo $Waris4 ?>', 310, 615);

    doc.setFontSize(10);
    doc.setFontStyle('italic');
    doc.text('Sebarang perubahan pada nama waris akan dikemaskini dalam tempoh 24 jam.',90,635);
    doc.setFontStyle('normal');
    doc.text('Adakah anda layak untuk skin pengeluaran caruman bagi pembelian harta tak alih? <Ya/Tidak> _______________',40,670);
    doc.text('Pengeluaran Perumahan Telah Dibuat Pada:__________________ Jumlah Pengeluaran: RM _________________',40,690);
    doc.text('Adakah anda layak untuk pengeluaran haji? <Ya/Tidak> _________________',40,710);

    doc.text('<?php echo $HousingRemark; ?>', 480, 670);
    doc.text('<?php echo $HousingChequeWithdrawalDate; ?>', 250, 690);
    doc.text('<?php echo sprintf('%0.2f', $HousingWithdrawalAmount); ?>', 480, 690);
    doc.text('<?php echo $HajiRemark; ?>', 300, 710);


    doc.setFontSize(7);
    doc.setFontStyle('italic');
    doc.text('Penyata ini adalah cetakan computer, tiada tandatangan diperlukan',180,750);

    doc.setFontSize(8);
    doc.setFontStyle('normal');
    doc.text('Tingkat Bawah, Bangunan LTAT, Jalan Bukit Bintang, Peti Surat 11542, 50748 Kuala Lumpur',40,820);
    doc.text('Hotline LTAT: 1 300 88 5825   Fax: 21637988   Laman Web: www.ltat.org.my',40,830);

    //doc.textEx('Kiosk ID: K001', 555, 820, 'right', 'middle');
    doc.textEx('Tarikh Cetak: '+<?php echo "'".date('d/m/Y')."'"; ?>, 555, 830, 'right', 'middle');





    //doc.rect(40, doc.autoTableEndPosY() + 60, doc.internal.pageSize.width - 80, 20); // empty square
    //doc.setLineWidth(2);

    //var columns = [
    //               {title: "month",             dataKey: "month"},
    //               {title: "carumanahli",       dataKey: "carumanahli"},
    //               {title: "pelarasanahli",     dataKey: "pelarasanahli"},
    //               {title: "carumankerajaan",   dataKey: "carumankerajaan"},
    //               {title: "pelarasankerajaan", dataKey: "pelarasankerajaan"}
    //              ];


    //var res = doc.autoTableHtmlToJson(document.getElementById("basic-table"));
    //doc.autoTable(columns, res.data, {startY: doc.autoTableEndPosY() + 220,
    //                                      theme: 'grid',
    //                                      styles: {lineColor:0},
    //                                      drawHeaderRow: function() {
    //                                                       // Don't draw header row
    //                                                       return false;
    //                                                     },
    //                                      columnStyles: {month: {columnWidth: 175}}
    //                                     }
    //    );
    //return doc;

    if (outputmethod=='display'){
      document.getElementById("penyataframe").src = doc.output('datauristring');
    } else if (outputmethod=='print'){
      doc.autoPrint();
      window.open(doc.output('bloburl'), '_blank');
      //doc.output('dataurlnewwindow');
    } else {
      document.getElementById("penyataframe").src = doc.output('datauristring');
    }

	//var pdf = new jsPDF('p', 'pt', 'letter')
  //pdf.text(20, 20, 'LEMBAGA TABUNG ANGKATAN TENTERA');

  //var data = pdf.output('datauristring')
  //$('iframe').attr('src', data)
}

</script>

<!-- Full Width Column -->
<div class="content-wrapper">
    <div class="container">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Penyata Caruman
            <small>Semakan Penyata Caruman</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i class="active">Laman Utama</a></li>
            <li>Penyata</li>
            <!--
            <li><a href="#">Layout</a></li>
            <li class="active">Top Navigation</li>
            -->
          </ol>
        </section>    
    
        <!-- Main content -->
        <section class="content">
            <!-- Default box -->
            <div class="box box-primary">
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-12">
            
                            <form name="form-penyata" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

                            <div class="pull-left">
                                <div class="form-group">
                                    <label>
                                      <input class="square-green" name="statementyear" type="radio" id="previousyear" value="previous" onChange="this.form.submit();" <?php echo $prevcheck; ?> />
                                      Penyata Terdahulu
                                    </label>
                                    <label>
                                      <input class="square-green" name="statementyear" type="radio" id="currentyear"  value="current" onChange="this.form.submit();" <?php echo $currcheck; ?>/>
                                      Penyata Semasa
                                    </label>
                                </div>
                            </div>

                            <div class="pull-right">
                              <!--
                              <button onclick="javascript:GeneratePDF('display')">Paparkan Penyata</button>
                              <button onclick="javascript:GeneratePDF('print')">Cetak Penyata</button>
                              -->
                              <a class="btn btn-app" id="generatepdf" onclick="javascript:GeneratePDF('display')" style="display: none;><i class="fa fa-television"></i>Display</a>
                              <a class="btn btn-app" onclick="javascript:GeneratePDF('print')"><i class="fa fa-print"></i>Cetak</a>
                            </div>
                            <br><br><br>
                                <iframe id="penyataframe" name="penyataframe" src="" type="application/pdf" width="100%" height="1500" style="border:3px dotted"></iframe>

                        </div>
                        <!-- /.col -->
                    </div>
                    <!-- /.row -->
                </div>   
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.container -->
</div>
<!-- /.content-wrapper -->

</form>

<?php include_once "footer.php" ?>

<script>
  $("document").ready(function() {
      setTimeout(function() {
          $("#generatepdf").trigger('click');
      },5);
  });
    
  $(function () {
    //Flat red color scheme for iCheck
    $('input[type="checkbox"].square-green, input[type="radio"].square-green').iCheck({
      checkboxClass: 'icheckbox_square-green',
      radioClass: 'iradio_square-green'
    });  
    
    $('input[type="radio"].square-green').on('ifChecked', function (event) { $(event.target).trigger('change'); });
    
  });
</script>
