public static function encode($value)
 {
     //convert to string
     $value = MyDecimal::format($value, ",", ".") . "";
     $strlen = strlen($value);
     foreach (range(0, $strlen - 1) as $count) {
         if ($value[$count] == "." or $value[$count] == ",") {
             continue;
         }
         $value[$count] = self::$code[$value[$count]];
     }
     return $value;
 }
</td>
  </tr>
  <?php 
    }
}
?>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$invoice->accountids['account_id_salesincome']]);
?>
</td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$invoice->accountids['account_id_cash_on_hand']]);
?>
</td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$invoice->accountids['account_id_inchecks']]);
?>
</td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$invoice->accountids['account_id_receivables']]);
?>
</td>
    <td></td>
  </tr>
</table>

</td>
  </tr>
  <?php 
    }
}
?>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$purchase->accountids['account_id_merchandiseexpense']]);
?>
</td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$purchase->accountids['account_id_cash_on_hand']]);
?>
</td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$purchase->accountids['account_id_outchecks']]);
?>
</td>
    <td align=right><?php 
echo MyDecimal::format($totalsbyaccount[$purchase->accountids['account_id_payables']]);
?>
</td>
    <td></td>
  </tr>
</table>

$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 8, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
$pdf->write(0, MyDateTime::frommysql($form->getObject()->getDate())->toshortdate(), '', false, '', true, 0, false, false, 0, 0);
$contents = array();
$contents[] = array("Cash Sales: ", MyDecimal::format($cashsales), " ", "Cheque Sales: ", MyDecimal::format($chequesales), " ", "Credit Sales: ", MyDecimal::format($creditsales), " ", "Total Sales: ", MyDecimal::format($cashsales + $chequesales + $creditsales));
$contents[] = array("Other Cash: ", MyDecimal::format($cashother), " ", "Other Cheque: ", MyDecimal::format($chequeother), " ", "Other Credit: ", MyDecimal::format($creditother), " ", "Total Other: ", MyDecimal::format($cashother + $chequeother + $creditother));
$contents[] = array("Total Cash: ", MyDecimal::format($cashtotal), " ", "Total Cheque: ", MyDecimal::format($chequetotal), " ", "Total Credit: ", MyDecimal::format($credittotal), " ", "Total: ", MyDecimal::format($total));
$contents[] = array("Less Deductions: ", MyDecimal::format($deducttotal * -1), " ", " ", " ", " ", " ", " ", " ", " ", " ");
$contents[] = array("Total Cash: ", MyDecimal::format($cashtotal - $deducttotal), " ", " ", " ", " ", " ", " ", " ", " ", " ");
$widths = array(30, 30, 20, 30, 30, 20, 30, 30, 20, 30, 30);
$height = 1;
foreach ($contents as $content) {
    $pdf->MultiCell($widths[0], $height, $content[0], 0, 'L', 0, 0, '', '', true);
    $pdf->MultiCell($widths[1], $height, $content[1], 0, 'R', 0, 0, '', '', true);
    $pdf->MultiCell($widths[2], $height, $content[2], 0, 'C', 0, 0, '', '', true);
    $pdf->MultiCell($widths[3], $height, $content[3], 0, 'L', 0, 0, '', '', true);
    $pdf->MultiCell($widths[4], $height, $content[4], 0, 'R', 0, 0, '', '', true);
    $pdf->MultiCell($widths[5], $height, $content[5], 0, 'C', 0, 0, '', '', true);
    $pdf->MultiCell($widths[6], $height, $content[6], 0, 'L', 0, 0, '', '', true);
    $pdf->MultiCell($widths[7], $height, $content[7], 0, 'R', 0, 0, '', '', true);
    $pdf->MultiCell($widths[8], $height, $content[8], 0, 'C', 0, 0, '', '', true);
    $pdf->MultiCell($widths[9], $height, $content[9], 0, 'L', 0, 0, '', '', true);
    $pdf->MultiCell($widths[10], $height, $content[10], 0, 'R', 0, 1, '', '', true);
}
</td>
    <td><?php 
    echo link_to($product->getName(), "product/view?id=" . $product->getId());
    ?>
</td>
    <td align=right><?php 
    echo MyDecimal::format($product->getMaxsellprice() == "" ? 0 : $product->getMaxsellprice());
    ?>
</td>
    <td align=right><?php 
    echo MyDecimal::format($product->getMinsellprice() == "" ? 0 : $product->getMinsellprice());
    ?>
</td>
    <td align=right><?php 
    echo MyDecimal::format($product->getMaxbuyprice() == "" ? 0 : $product->getMaxbuyprice());
    ?>
</td>
    <td align=right><?php 
    echo MyDecimal::format($product->getMinbuyprice() == "" ? 0 : $product->getMinbuyprice());
    ?>
</td>
    <td align=right><?php 
    echo MyDecimal::format($product->getMinbuyprice() == 0 ? 0 : $product->getMinsellprice() / $product->getMinbuyprice());
    ?>
</td>
  </tr>
  <?php 
}
?>
</table>
echo $form->getObject()->getDate();
$datearray = explode("-", $form->getObject()->getDate());
?>


<br>Cash Purchases: <?php 
echo MyDecimal::format($cashtotal);
?>
<br>Cheque Purchases: <?php 
echo MyDecimal::format($chequetotal);
?>
<br>Credit Purchases: <?php 
echo MyDecimal::format($credittotal);
?>
<br>Total Purchases: <?php 
echo MyDecimal::format($total);
?>
<br><?php 
echo link_to("Print", "purchase/dsrpdf?purchase[date][year]=" . $datearray[0] . "&purchase[date][month]=" . $datearray[1] . "&purchase[date][day]=" . $datearray[2]);
?>


<br>
<br>
<table border=1>
  <tr>
    <td>Form</td>
    <td>Particulars</td>
    <td>Reference</td>
    <td>Code</td>
    <td>Item Description</td>
    ?>
</td>
    <!--td><input name="minsellprices[<?php 
    echo $product->getId();
    ?>
]" size=1 /></td-->
    <td align=right><font color=gray><?php 
    echo MyDecimal::format($product->getMaxbuyprice() == "" ? 0 : $product->getMaxbuyprice());
    ?>
</font></td>
    <!--td><input name="maxbuyprices[<?php 
    echo $product->getId();
    ?>
]" size=1 /></td-->
    <td align=right><font color=gray><?php 
    echo MyDecimal::format($product->getMinbuyprice() == "" ? 0 : $product->getMinbuyprice());
    ?>
</fontx></td>
    <!--td><input name="minbuyprices[<?php 
    echo $product->getId();
    ?>
]" size=1 /></td-->
    <td align=right><?php 
    if ($stock) {
        echo link_to($stock->getCurrentQty() > 0 ? $stock->getCurrentQty() : " - - ", "product/inventory?id=" . $product->getId());
    }
    ?>
</td>
    <td><?php 
    echo link_to("Edit", "product/edit?id=" . $product->getId());
    ?>
            echo "<td align=right>" . MyDecimal::format($invoice->getTotal()) . "</td>";
            echo "<td align=right>" . ($invoice->getStatus() != "Cancelled" ? MyDecimal::format($invoice->getCommissionTotal($employees[$empid])) : 0) . "</td>";
            echo "<td align=right>" . ($invoice->getStatus() != "Cancelled" ? MyDecimal::format($invoice->getCommission($employees[$empid])) : 0) . "</td>";
            echo "<td align=right>" . link_to("view", "invoice/view?id=" . $invoice->getId()) . "</td>";
            echo "<td >" . $statusesbydate[$invoiceindex] . "</td>";
            echo "</tr>";
        }
    }
    echo "</table>";
    //all pending records at the bottom
    echo "<table>";
    foreach ($employeedata as $invoiceindex => $invoice) {
        if ($invoice->getStatus() == "Pending" or $statusesbydate[$invoiceindex] != "Paid") {
            $count++;
            echo "<tr bgcolor=lightgreen>";
            echo "<td >" . $count . "</td>";
            echo "<td >" . $employees[$empid] . "</td>";
            echo "<td >" . $invoice->getInvno() . "</td>";
            echo "<td align=right>" . MyDecimal::format($invoice->getTotal()) . "</td>";
            echo "<td align=right>" . ($invoice->getStatus() != "Cancelled" ? MyDecimal::format($invoice->getCommissionTotal($employees[$empid])) : 0) . "</td>";
            echo "<td align=right>" . ($invoice->getStatus() != "Cancelled" ? MyDecimal::format($invoice->getCommission($employees[$empid])) : 0) . "</td>";
            echo "<td align=right>" . link_to("view", "invoice/view?id=" . $invoice->getId()) . "</td>";
            echo "<td >" . ($statusesbydate[$invoiceindex] ? $statusesbydate[$invoiceindex] : $invoice->getStatus()) . "</td>";
            echo "</tr>";
        }
    }
    echo "</table>";
}
?>

foreach ($stockentries as $detail) {
    ?>
  <tr>
    <td><?php 
    echo MyDateTime::frommysql($detail->getDate())->toshortdate();
    ?>
</td>
    <td align=right><?php 
    if ($detail->getQty() > 0) {
        echo MyDecimal::format($detail->getQty());
    }
    ?>
</td>
    <td align=right><?php 
    if ($detail->getQty() < 0) {
        echo MyDecimal::format($detail->getQty() * -1);
    }
    ?>
</td>
    <td align=right><?php 
    echo $detail->getBalance();
    ?>
</td>
    <td><?php 
    if ($detail->getRefClass() == "Invoicedetail") {
        $ref = $detail->getRef();
        echo link_to($ref->getInvoice(), "invoice/view?id=" . $ref->getInvoiceId());
    } else {
        if ($detail->getRefClass() == "Purchasedetail") {
            $ref = $detail->getRef();
            echo link_to($ref->getPurchase(), "purchase/view?id=" . $ref->getPurchaseId());
        $pdf->MultiCell($widths[2], $height, $content[2], 0, 'R', $content[6] == "Cancelled" ? 1 : 0, 0, '', '', true);
        $pdf->MultiCell($widths[3], $height, $content[3], 0, 'R', $content[6] == "Cancelled" ? 1 : 0, 0, '', '', true);
        $pdf->MultiCell($widths[4], $height, $content[4], 0, 'R', $content[6] == "Cancelled" ? 1 : 0, 0, '', '', true);
        $pdf->MultiCell($widths[5], $height, $content[5], 0, 'R', $content[6] == "Cancelled" ? 1 : 0, 0, '', '', true);
        $pdf->MultiCell($widths[6], $height, $content[6], 0, 'R', $content[6] == "Cancelled" ? 1 : 0, 1, '', '', true);
    }
    //pending is lightgreen
    $pdf->SetFillColor(127, 255, 127);
    //		$pdf->SetTextColor(128,0,0);
    //		$pdf->SetDrawColor(128, 0, 0);
    //display pending
    $contents = array();
    foreach ($employeedata as $invoice) {
        if ($invoice->getStatus() == "Pending") {
            $count++;
            $contents[] = array($count, MyDateTime::frommysql($invoice->getDate())->toshortdate(), $invoice, MyDecimal::format($invoice->getTotal()), MyDecimal::format($invoice->getCommissionTotal($employees[$empid])), MyDecimal::format($invoice->getCommission($employees[$empid])), $invoice->getStatus());
        }
    }
    $widths = array(10, 30, 35, 30, 30, 20, 20);
    $height = 1;
    foreach ($contents as $content) {
        $pdf->MultiCell($widths[0], $height, $content[0], 0, 'R', 1, 0, '', '', true);
        $pdf->MultiCell($widths[1], $height, $content[1], 0, 'R', 1, 0, '', '', true);
        $pdf->MultiCell($widths[2], $height, $content[2], 0, 'R', 1, 0, '', '', true);
        $pdf->MultiCell($widths[3], $height, $content[3], 0, 'R', 1, 0, '', '', true);
        $pdf->MultiCell($widths[4], $height, $content[4], 0, 'R', 1, 0, '', '', true);
        $pdf->MultiCell($widths[5], $height, $content[5], 0, 'R', 1, 0, '', '', true);
        $pdf->MultiCell($widths[6], $height, $content[6], 0, 'R', 1, 1, '', '', true);
    }
}
/*