}
                $pdf->SetFont($defaultfont, '', $defaultfontsize);
                $pdf->Cell($w[$i], $defaultfontheight, $col, '', 0, $align);
                $i++;
                //echo $col;
            }
            $pdf->Ln();
        }
    }
    //display summary for last row
    $ypos = $pdf->GetY();
    $pdf->Line($w[0], $ypos, $marginx + $w[0] + $w[1], $ypos);
    $summaryamt = changeNegativeNumberFormat($totalequity, 2);
    $pdf->Cell($w[0], $defaultfontheight, "", 0, 0, "R");
    $pdf->Cell($w[1], $defaultfontheight, $summaryamt, 0, 0, "R");
    $pdf->Ln();
    $pdf->Ln();
    $pdf->SetFont($defaultfont, 'B', $defaultfontsize + 1);
    $totaleq_lib = $totalequity + $totalliability;
    $pdf->Cell($w[0], $defaultfontheight, "Total Liability + Equity:", 0, 0, "L");
    $pdf->Cell($w[1], $defaultfontheight, changeNegativeNumberFormat($totaleq_lib, 2), "TB", 0, "R");
    $pdf->Ln();
    $pdf->Line($marginx + $w[0], $pdf->GetY() + 1, $marginx + $w[0] + $w[1] + $w[2], $pdf->GetY() + 1);
    $pdf->Ln();
    //$pdf->MultiCell(0,5,"$sql",1,"C");
    $pdf->Output("viewbalancesheet_singleperiod.pdf", "I");
    exit(1);
}
?>

    $pdf->Line($marginx + $w[0] + $w[1] + 2, $ypos, $marginx + $w[0] + $w[1] + $w[2], $ypos);
    //			$pdf->Line($w[0],$ypos,$marginx+$w[0]+$w[1],$ypos);
    $summaryamt1 = changeNegativeNumberFormat($totalexpenses1, 2);
    $summaryamt2 = changeNegativeNumberFormat($totalexpenses2, 2);
    $pdf->Cell($w[0], $defaultfontheight, "", 0, 0, "R");
    $pdf->Cell($w[1], $defaultfontheight, $summaryamt1, 0, 0, "R");
    $pdf->Cell($w[2], $defaultfontheight, $summaryamt2, 0, 0, "R");
    $pdf->Ln();
    $pdf->Ln();
    $pdf->SetFont($defaultfont, 'B', $defaultfontsize + 1);
    $netprofit1 = $grossprofit1 - $totalexpenses1 + -1 * $totalotherincome1;
    $netprofit2 = $grossprofit2 - $totalexpenses2 + -1 * $totalotherincome2;
    //($totalotherincome)*(-1) -
    if ($netprofit < 0) {
        $pdf->Cell($w[0], $defaultfontheight, "Net Loss", 0, 0, "L");
        $pdf->Cell($w[1], $defaultfontheight, "" . changeNegativeNumberFormat($netprofit1, 2) . "", "TB", 0, "R");
        $pdf->Cell($w[2], $defaultfontheight, "" . changeNegativeNumberFormat($netprofit2, 2) . "", "TB", 0, "R");
    } else {
        $pdf->Cell($w[0], $defaultfontheight, "Net Profit", 0, 0, "L");
        $pdf->Cell($w[1], $defaultfontheight, changeNegativeNumberFormat($netprofit1, 2), "TB", 0, "R");
        $pdf->Cell($w[2], $defaultfontheight, changeNegativeNumberFormat($netprofit2, 2), "TB", 0, "R");
    }
    $pdf->Ln();
    $pdf->Line($marginx + $w[0], $pdf->GetY() + 1, $marginx + $w[0] + $w[1] + $w[2], $pdf->GetY() + 1);
    //$pdf->MultiCell(0,5,"$sql",1,"C");
    $pdf->Output("viewincomestatement_singlecol.pdf", "I");
    exit(1);
}
?>

 }
 echo "</tr>";
 //$pdf->Cell($w[1],$defaultfontheight,$summaryamt,0,0,"R");
 //$summaryamt=changeNegativeNumberFormat($totalexpenses2,2);
 //$pdf->Cell($w[2],$defaultfontheight,$summaryamt,0,0,"R");
 //$pdf->Ln();
 //$pdf->Ln();
 //$pdf->SetFont($defaultfont,'B',$defaultfontsize+1);
 for ($k = 0; $k < $m; $k++) {
     $netprofit[$k] = $grossprofit[$k] + $totalotherincome[$k] * -1 - $totalexpenses[$k];
 }
 for ($k = 0; $k < $m; $k++) {
     if ($netprofit[$k] >= 0) {
         $displaynp[$k] = changeNegativeNumberFormat($netprofit[$k], 2);
     } else {
         $displaynp[$k] = changeNegativeNumberFormat($netprofit[$k], 2);
     }
 }
 echo "<tr>";
 echo "<td>---------</td>";
 for ($k = 0; $k < $m; $k++) {
     echo "<td style='text-align:right'>------</td>";
 }
 echo "</tr>";
 echo "<tr>";
 echo "<td style='text-align: Right'><B>Net Profit (Loss)</B></td>";
 for ($k = 0; $k < $m; $k++) {
     echo "<td style='text-align:right'><B>" . $displaynp[$k] . "</B></td>";
 }
 echo "</tr>";
 //$pdf->Cell($w[0],$defaultfontheight,"Net Profit (Loss)",0,0,"L");
            foreach ($data as $col) {
                if ($i == 0) {
                    $align = 'L';
                } else {
                    $align = 'R';
                }
                $pdf->SetFont($defaultfont, '', $defaultfontsize);
                $pdf->Cell($w[$i], $defaultfontheight, $col, '', 0, $align);
                $i++;
            }
            $pdf->Ln();
        }
    }
    //display summary for last row
    $retainearning1 = $totalasset1 + $totalliability1 + $totalequity1;
    $retainearning2 = $totalasset2 + $totalliability2 + $totalequity2;
    $summaryamt1 = changeNegativeNumberFormat($retainearning1, 2);
    $summaryamt2 = changeNegativeNumberFormat($retainearning2, 2);
    $pdf->Cell($w[0], $defaultfontheight, "  " . "Retain Earning/(Loss)", 0, 0, "L");
    $pdf->Cell($w[1], $defaultfontheight, $summaryamt1, 0, 0, "R");
    $pdf->Cell($w[1], $defaultfontheight, $summaryamt2, 0, 0, "R");
    $pdf->Ln();
    $pdf->SetFont($defaultfont, 'B', $defaultfontsize + 1);
    $pdf->Cell($w[0], $defaultfontheight, "Total ", 0, 0, "L");
    $pdf->Cell($w[1], $defaultfontheight, "" . changeNegativeNumberFormat($totalasset1, 2) . "", "TB", 0, "R");
    $pdf->Cell($w[2], $defaultfontheight, "" . changeNegativeNumberFormat($totalasset2, 2) . "", "TB", 0, "R");
    $pdf->Line($marginx + $w[0], $pdf->GetY() + 6, $marginx + $w[0] + $w[1] + $w[2], $pdf->GetY() + 6);
    //$pdf->MultiCell(0,5,"$sql",1,"C");
    $pdf->Output("viewbalancesheet_singlecol.pdf", "I");
    exit(1);
}
     echo "</tr>";
     echo "<tr>";
     echo "<td style='text-align: right'><b>Total</b></td>";
     for ($k = 0; $k < $m; $k++) {
         echo "<td style='text-align:right'><b>" . $summaryamt[$k] . "</b></td>";
     }
     echo "</tr>";
     echo "<tr><td>&nbsp;</td></tr><tr>";
     //$pdf->Cell($w[1],$defaultfontheight,$summaryamt,0,0,"R");
     //$summaryamt=changeNegativeNumberFormat($totalasset2,2);
     //$pdf->Cell($w[2],$defaultfontheight,$summaryamt,0,0,"R");
     break;
 case "6L":
     $summaryamt = array();
     for ($k = 0; $k < $m; $k++) {
         $summaryamt[$k] = changeNegativeNumberFormat($totalliability[$k] * -1, 2);
     }
     echo "<tr>";
     echo "<td>---------</td>";
     for ($k = 0; $k < $m; $k++) {
         echo "<td style='text-align:right'>------</td>";
     }
     echo "</tr>";
     echo "<tr>";
     echo "<td>Total Liabilities</td>";
     for ($k = 0; $k < $m; $k++) {
         echo "<td style='text-align:right'>" . $summaryamt[$k] . "</td>";
     }
     echo "</tr>";
     echo "</tr>";
     echo "<tr>";