예제 #1
1
function endDoctor(&$docrow)
{
    global $grand_total_charges, $grand_total_copays, $grand_total_encounters;
    if (!$docrow['docname']) {
        return;
    }
    echo " <tr class='report_totals'>\n";
    echo "  <td colspan='5'>\n";
    echo "   &nbsp;" . xl('Totals for', '', '', ' ') . $docrow['docname'] . "\n";
    echo "  </td>\n";
    echo "  <td align='right'>\n";
    echo "   &nbsp;" . $docrow['encounters'] . "&nbsp;\n";
    echo "  </td>\n";
    echo "  <td align='right'>\n";
    echo "   &nbsp;";
    bucks($docrow['charges']);
    echo "&nbsp;\n";
    echo "  </td>\n";
    echo "  <td align='right'>\n";
    echo "   &nbsp;";
    bucks($docrow['copays']);
    echo "&nbsp;\n";
    echo "  </td>\n";
    echo "  <td colspan='2'>\n";
    echo "   &nbsp;\n";
    echo "  </td>\n";
    echo " </tr>\n";
    $grand_total_charges += $docrow['charges'];
    $grand_total_copays += $docrow['copays'];
    $grand_total_encounters += $docrow['encounters'];
    $docrow['charges'] = 0;
    $docrow['copays'] = 0;
    $docrow['encounters'] = 0;
}
예제 #2
0
function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept)
{
    $balance = bucks($charges - $ptpaid - $inspaid);
    $getfrompt = $duept > 0 ? $duept : 0;
    echo " <tr>\n";
    echo "  <td class='detail'>" . oeFormatShortDate($date) . "</td>\n";
    echo "  <td class='detail' align='right'>" . bucks($charges) . "</td>\n";
    echo "  <td class='detail' align='right'>" . bucks($ptpaid) . "</td>\n";
    echo "  <td class='detail' align='right'>" . bucks($inspaid) . "</td>\n";
    echo "  <td class='detail' align='right'>{$balance}</td>\n";
    echo "  <td class='detail' align='right'>" . bucks($duept) . "</td>\n";
    echo "  <td class='detail' align='right'><input type='text' name='{$iname}' " . "size='6' value='" . rawbucks($getfrompt) . "' onchange='calctotal()' " . "onkeyup='calctotal()' /></td>\n";
    echo " </tr>\n";
}
예제 #3
0
function endDoctor(&$docrow)
{
    global $grand_total_charges, $grand_total_copays, $grand_total_encounters;
    if (!$docrow['docname']) {
        return;
    }
    $xml_string .= "<rowtotal>";
    $xml_string .= "<practitioner>Totals for " . $docrow['docname'] . "</practitioner>";
    $xml_string .= "<visits>" . $docrow['encounters'] . "</visits>";
    $xml_string .= "<charges>" . bucks($docrow['charges']) . "</charges>";
    $xml_string .= "<copays>" . bucks($docrow['copays']) . "</copays>";
    $xml_string .= "</rowtotal>";
    $grand_total_charges += $docrow['charges'];
    $grand_total_copays += $docrow['copays'];
    $grand_total_encounters += $docrow['encounters'];
    $docrow['charges'] = 0;
    $docrow['copays'] = 0;
    $docrow['encounters'] = 0;
}
예제 #4
0
function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
{
    global $var_index;
    $var_index++;
    $balance = bucks($charges - $ptpaid - $inspaid);
    $balance = round($duept, 2) != 0 ? 0 : $balance;
    //if balance is due from patient, then insurance balance is displayed as zero
    $encounter = $encounter ? $encounter : '';
    echo " <tr id='tr_" . attr($var_index) . "' >\n";
    echo "  <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
    echo "  <td class='detail' id='" . attr($date) . "' align='center'>" . htmlspecialchars($encounter, ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='td_charges_{$var_index}' >" . htmlspecialchars(bucks($charges), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='td_inspaid_{$var_index}' >" . htmlspecialchars(bucks($inspaid * -1), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='td_ptpaid_{$var_index}' >" . htmlspecialchars(bucks($ptpaid * -1), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='td_patient_copay_{$var_index}' >" . htmlspecialchars(bucks($patcopay), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='td_copay_{$var_index}' >" . htmlspecialchars(bucks($copay), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='balance_{$var_index}'>" . htmlspecialchars(bucks($balance), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='center' id='duept_{$var_index}'>" . htmlspecialchars(bucks(round($duept, 2) * 1), ENT_QUOTES) . "</td>\n";
    echo "  <td class='detail' align='right'><input type='text' name='" . attr($iname) . "'  id='paying_" . attr($var_index) . "' " . " value='" . '' . "' onchange='coloring();calctotal()'  autocomplete='off' " . "onkeyup='calctotal()'  style='width:50px'/></td>\n";
    echo " </tr>\n";
}
예제 #5
0
">
   <?php 
        xl('Grand Totals', 'e');
        ?>
  </td>
  <td align="right">
   <?php 
        bucks($grandtotal1);
        ?>
  </td>
<?php 
        if ($form_procedures) {
            ?>
  <td align="right">
   <?php 
            bucks($grandtotal2);
            ?>
  </td>
<?php 
        }
        ?>
 </tr>

<?php 
    }
    if (!$INTEGRATED_AR) {
        SLClose();
    }
    ?>

</table>
예제 #6
0
  </td>
  <td class="detail" align="right">
   <?php 
            bucks($row['adjustments']);
            ?>
&nbsp;
  </td>
  <td class="detail" align="right">
   <?php 
            bucks($row['paid']);
            ?>
&nbsp;
  </td>
  <td class="detail" align="right">
   <?php 
            bucks($row['charges'] + $row['adjustments'] - $row['paid']);
            ?>
&nbsp;
  </td>
  <td class="detail" align="center">
   <?php 
            echo $duncount ? $duncount : "&nbsp;";
            ?>
  </td>
<?php 
            if (!$eracount) {
                ?>
  <td class="detail" align="left">
   <input type='checkbox' name='form_cb[<?php 
                echo $row['id'];
                ?>
예제 #7
0
function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transdate, $qty, $amount, $irnumber = '')
{
    global $product, $category, $producttotal, $productqty, $cattotal, $catqty, $grandtotal, $grandqty;
    global $productleft, $catleft;
    $invnumber = $irnumber ? $irnumber : "{$patient_id}.{$encounter_id}";
    $rowamount = sprintf('%01.2f', $amount);
    $patdata = sqlQuery("SELECT " . "p.fname, p.mname, p.lname, p.pubpid, p.DOB, " . "p.street, p.city, p.state, p.postal_code, " . "p.ss, p.sex, p.status, p.phone_home, " . "p.phone_biz, p.phone_cell, p.hipaa_notice " . "FROM patient_data AS p " . "WHERE p.pid = ? LIMIT 1", array($patient_id));
    $pat_name = $patdata['fname'] . ' ' . $patdata['mname'] . ' ' . $patdata['lname'];
    if (empty($rowcat)) {
        $rowcat = xl('None');
    }
    $rowproduct = $description;
    if (!$rowproduct) {
        $rowproduct = xl('Unknown');
    }
    if ($product != $rowproduct || $category != $rowcat) {
        if ($product) {
            // Print product total.
            if ($_POST['form_csvexport']) {
                if (!$_POST['form_details']) {
                    echo '"' . display_desc($category) . '",';
                    echo '"' . display_desc($product) . '",';
                    echo '"' . $productqty . '",';
                    echo '"';
                    bucks($producttotal);
                    echo '"' . "\n";
                }
            } else {
                ?>
 <tr bgcolor="#ddddff">
  <td class="detail">
   <?php 
                echo text(display_desc($catleft));
                $catleft = " ";
                ?>
  </td>
  <td class="detail" colspan="3">
   <?php 
                if ($_POST['form_details']) {
                    echo xlt('Total for') . ' ';
                }
                echo text(display_desc($product));
                ?>
  </td>
  <?php 
                if ($GLOBALS['sales_report_invoice'] == 0 || $GLOBALS['sales_report_invoice'] == 2) {
                    ?>
  <td>
  &nbsp;
  </td>
  <?php 
                }
                ?>
  <td align="right">
   &nbsp;
  </td>
  <td align="right">
   <?php 
                echo text($productqty);
                ?>
  </td>
  <td align="right">
   <?php 
                text(bucks($producttotal));
                ?>
  </td>
 </tr>
<?php 
            }
            // End not csv export
        }
        $producttotal = 0;
        $productqty = 0;
        $product = $rowproduct;
        $productleft = $product;
    }
    if ($category != $rowcat) {
        if ($category) {
            // Print category total.
            if (!$_POST['form_csvexport']) {
                ?>

 <tr bgcolor="#ffdddd">
  <td class="detail">
   &nbsp;
  </td>
  <td class="detail" colspan="3">
   <?php 
                echo xlt('Total for category') . ' ';
                echo text(display_desc($category));
                ?>
  </td>
  <?php 
                if ($GLOBALS['sales_report_invoice'] == 0 || $GLOBALS['sales_report_invoice'] == 2) {
                    ?>
  <td>
   &nbsp;
  </td>
  <?php 
                }
                ?>
  <td align="right">
   &nbsp;
  </td>
  <td align="right">
   <?php 
                echo text($catqty);
                ?>
  </td>
  <td align="right">
   <?php 
                text(bucks($cattotal));
                ?>
  </td>
 </tr>
<?php 
            }
            // End not csv export
        }
        $cattotal = 0;
        $catqty = 0;
        $category = $rowcat;
        $catleft = $category;
    }
    if ($_POST['form_details']) {
        if ($_POST['form_csvexport']) {
            echo '"' . display_desc($category) . '",';
            echo '"' . display_desc($product) . '",';
            echo '"' . oeFormatShortDate(display_desc($transdate)) . '",';
            if ($GLOBALS['sales_report_invoice'] == 1 || $GLOBALS['sales_report_invoice'] == 2) {
                echo '"' . $pat_name . '",';
            }
            if ($GLOBALS['sales_report_invoice'] == 0 || $GLOBALS['sales_report_invoice'] == 2) {
                echo '"' . display_desc($invnumber) . '",';
            }
            if ($GLOBALS['sales_report_invoice'] == 1) {
                echo '"' . $patient_id . '",';
            }
            // echo '"' . display_desc($invnumber) . '",';
            echo '"' . display_desc($qty) . '",';
            echo '"';
            bucks($rowamount);
            echo '"' . "\n";
        } else {
            ?>

 <tr>
  <td class="detail">
   <?php 
            echo text(display_desc($catleft));
            $catleft = " ";
            ?>
  </td>
  <td class="detail">
   <?php 
            echo text(display_desc($productleft));
            $productleft = " ";
            ?>
  </td>
  <td>
   <?php 
            echo text(oeFormatShortDate($transdate));
            ?>
  </td>
   <?php 
            if ($GLOBALS['sales_report_invoice'] == 0 || $GLOBALS['sales_report_invoice'] == 2) {
                ?>
  <td>
   &nbsp;
  </td>
   <?php 
            }
            if ($GLOBALS['sales_report_invoice'] == 1 || $GLOBALS['sales_report_invoice'] == 2) {
                ?>
  <td>
   <?php 
                echo text($pat_name);
                ?>
  </td>
   <?php 
            }
            ?>
  
  <td class="detail">
  <?php 
            if ($GLOBALS['sales_report_invoice'] == 0 || $GLOBALS['sales_report_invoice'] == 2) {
                ?>
   <a href='../patient_file/pos_checkout.php?ptid=<?php 
                echo attr($patient_id);
                ?>
&enc=<?php 
                echo attr($encounter_id);
                ?>
'>
   <?php 
                echo text($invnumber);
                ?>
</a>
   <?php 
            }
            if ($GLOBALS['sales_report_invoice'] == 1) {
                echo text($patient_id);
            }
            ?>
  </td>
  <?php 
            if ($GLOBALS['sales_report_invoice'] == 0) {
                ?>
  <td>
   &nbsp;
  </td>
  <?php 
            }
            ?>
  <td align="right">
   <?php 
            echo text($qty);
            ?>
  </td>
  <td align="right">
   <?php 
            text(bucks($rowamount));
            ?>
  </td>
 </tr>
<?php 
        }
        // End not csv export
    }
    // end details
    $producttotal += $rowamount;
    $cattotal += $rowamount;
    $grandtotal += $rowamount;
    $productqty += $qty;
    $catqty += $qty;
    $grandqty += $qty;
}
예제 #8
0
        echo "  <td class='text'>" . text($iter['code_text']) . "</td>\n";
        echo "  <td class='text'>" . text($iter['code_text_short']) . "</td>\n";
        if (related_codes_are_used()) {
            // Show related codes.
            echo "  <td class='text'>";
            $arel = explode(';', $iter['related_code']);
            foreach ($arel as $tmp) {
                list($reltype, $relcode) = explode(':', $tmp);
                $code_description = lookup_code_descriptions($reltype . ":" . $relcode);
                echo text($relcode) . ' ' . text(trim($code_description)) . '<br />';
            }
            echo "</td>\n";
        }
        $pres = sqlStatement("SELECT p.pr_price " . "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " . "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " . "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($iter['id']));
        while ($prow = sqlFetchArray($pres)) {
            echo "<td class='text' align='right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
        }
        if ($iter["code_external"] > 0) {
            echo "  <td align='right'><a class='link' href='javascript:submitModify(\"" . attr($iter['code_type_name']) . "\",\"" . attr($iter['code']) . "\",\"" . attr($iter['id']) . "\")'>[" . xlt('Modify') . "]</a></td>\n";
        } else {
            echo "  <td align='right'><a class='link' href='javascript:submitDelete(" . attr($iter['id']) . ")'>[" . xlt('Delete') . "]</a></td>\n";
            echo "  <td align='right'><a class='link' href='javascript:submitEdit(" . attr($iter['id']) . ")'>[" . xlt('Edit') . "]</a></td>\n";
        }
        echo " </tr>\n";
    }
}
?>

</table>

</center>
예제 #9
0
        xl('Totals', 'e');
        ?>
  </td>
  <td align='right'>
   <?php 
        echo bucks($total1);
        ?>
  </td>
  <td align='right'>
   <?php 
        echo bucks($total2);
        ?>
  </td>
  <td align='right'>
   <?php 
        echo bucks($total1 + $total2);
        ?>
  </td>
 </tr>

<?php 
    }
    ?>
</tbody>
</table>
</div> <!-- end of results -->
<?php 
} else {
    ?>
<div class='text'>
 	<?php 
function showLineItem($patient_id, $encounter_id, $memo, $transdate, $rowmethod, $rowpayamount, $rowadjamount, $payer_type = 0, $irnumber = '')
{
    global $paymethod, $paymethodleft, $methodpaytotal, $methodadjtotal, $grandpaytotal, $grandadjtotal, $showing_ppd;
    if (!$rowmethod) {
        $rowmethod = 'Unknown';
    }
    $invnumber = $irnumber ? $irnumber : "{$patient_id}.{$encounter_id}";
    if ($paymethod != $rowmethod) {
        if ($paymethod) {
            // Print method total.
            ?>

 <tr bgcolor="#ddddff">
  <td class="detail" colspan="<?php 
            echo $showing_ppd ? 7 : 4;
            ?>
">
   <?php 
            echo xl('Total for ') . $paymethod;
            ?>
  </td>
  <td align="right">
   <?php 
            bucks($methodadjtotal);
            ?>
  </td>
  <td align="right">
   <?php 
            bucks($methodpaytotal);
            ?>
  </td>
 </tr>
<?php 
        }
        $methodpaytotal = 0;
        $methodadjtotal = 0;
        $paymethod = $rowmethod;
        $paymethodleft = $paymethod;
    }
    if ($_POST['form_details']) {
        ?>

 <tr>
  <td class="detail">
   <?php 
        echo $paymethodleft;
        $paymethodleft = "&nbsp;";
        ?>
  </td>
  <td>
   <?php 
        echo oeFormatShortDate($transdate);
        ?>
  </td>
  <td class="detail">
   <?php 
        echo $invnumber;
        ?>
  </td>

<?php 
        if ($showing_ppd) {
            $pferow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date " . "FROM patient_data AS p, form_encounter AS fe WHERE " . "p.pid = '{$patient_id}' AND fe.pid = p.pid AND " . "fe.encounter = '{$encounter_id}' LIMIT 1");
            $dos = substr($pferow['date'], 0, 10);
            echo "  <td class='dehead'>\n";
            echo "   " . $pferow['lname'] . ", " . $pferow['fname'] . " " . $pferow['mname'];
            echo "  </td>\n";
            echo "  <td class='dehead'>\n";
            if ($payer_type) {
                $ptarr = array(1 => 'primary', 2 => 'secondary', 3 => 'tertiary');
                $insrow = getInsuranceDataByDate($patient_id, $dos, $ptarr[$payer_type], "policy_number");
                echo "   " . $insrow['policy_number'];
            }
            echo "  </td>\n";
            echo "  <td class='dehead'>\n";
            echo "   " . oeFormatShortDate($dos) . "\n";
            echo "  </td>\n";
        }
        ?>

  <td>
   <?php 
        echo $memo;
        ?>
  </td>
  <td align="right">
   <?php 
        bucks($rowadjamount);
        ?>
  </td>
  <td align="right">
   <?php 
        bucks($rowpayamount);
        ?>
  </td>
 </tr>
<?php 
    }
    $methodpaytotal += $rowpayamount;
    $grandpaytotal += $rowpayamount;
    $methodadjtotal += $rowadjamount;
    $grandadjtotal += $rowadjamount;
}
예제 #11
0
'>
  <td class="detail">
   <?php 
    echo $dispcode;
    $dispcode = "";
    ?>
  </td>
  <td class="detail" align="right">
   &nbsp;
  </td>
  <td class="detail" align="right">
   <input type="hidden" name="form_line[<?php 
    echo $code;
    ?>
][bal]" value="<?php 
    bucks($cdata['bal']);
    ?>
">
   <input type="hidden" name="form_line[<?php 
    echo $code;
    ?>
][ins]" value="<?php 
    echo $cdata['ins'];
    ?>
">
   <?php 
    printf("%.2f", $cdata['bal']);
    ?>
&nbsp;
  </td>
  <td class="detail">
예제 #12
0
  </td>
  <td class="detail" align="right">
   <?php 
        bucks($row['adjustments']);
        ?>
&nbsp;
  </td>
  <td class="detail" align="right">
   <?php 
        bucks($row['payments'] - $row['copays']);
        ?>
&nbsp;
  </td>
  <td class="detail" align="right">
   <?php 
        bucks($balance);
        ?>
&nbsp;
  </td>
  <td class="detail" align="center">
   <?php 
        echo $duncount ? $duncount : "&nbsp;";
        ?>
  </td>
<?php 
        if (!$eracount) {
            ?>
  <td class="detail" align="left">
   <input type='checkbox' name='form_cb[<?php 
            echo $row['id'];
            ?>
예제 #13
0
  </td>
  <td class="detail" align="right">
   <?php 
    echo bucks($total_amount);
    ?>
&nbsp;
  </td>
  <td class="detail" align="right">
   <?php 
    echo bucks($total_paid);
    ?>
&nbsp;
  </td>
  <td class="detail" align="right">
   <?php 
    echo bucks($total_amount - $total_paid);
    ?>
&nbsp;
  </td>
 </tr>
<?php 
}
if (!$INTEGRATED_AR) {
    SLClose();
}
?>

</table>
</div>

</form>
예제 #14
0
function thisLineItem($row, $xfer = false)
{
    global $grandtotal, $grandqty, $encount, $form_action;
    $invnumber = '';
    $dpname = '';
    if (!empty($row['pid'])) {
        $ttype = xl('Sale');
        $dpname = $row['plname'];
        if (!empty($row['pfname'])) {
            $dpname .= ', ' . $row['pfname'];
            if (!empty($row['pmname'])) {
                $dpname .= ' ' . $row['pmname'];
            }
        }
        $invnumber = empty($row['invoice_refno']) ? "{$row['pid']}.{$row['encounter']}" : $row['invoice_refno'];
    } else {
        if (!empty($row['distributor_id'])) {
            $ttype = xl('Distribution');
            if (!empty($row['organization'])) {
                $dpname = $row['organization'];
            } else {
                $dpname = $row['dlname'];
                if (!empty($row['dfname'])) {
                    $dpname .= ', ' . $row['dfname'];
                    if (!empty($row['dmname'])) {
                        $dpname .= ' ' . $row['dmname'];
                    }
                }
            }
        } else {
            if (!empty($row['xfer_inventory_id']) || $xfer) {
                $ttype = xl('Transfer');
            } else {
                if ($row['fee'] != 0) {
                    $ttype = xl('Purchase');
                } else {
                    $ttype = xl('Adjustment');
                }
            }
        }
    }
    if ($form_action == 'export') {
        echo '"' . oeFormatShortDate($row['sale_date']) . '",';
        echo '"' . $ttype . '",';
        echo '"' . esc4Export($row['name']) . '",';
        echo '"' . esc4Export($row['lot_number']) . '",';
        echo '"' . esc4Export($row['warehouse']) . '",';
        echo '"' . esc4Export($dpname) . '",';
        echo '"' . (0 - $row['quantity']) . '",';
        echo '"' . bucks($row['fee']) . '",';
        echo '"' . $row['billed'] . '",';
        echo '"' . esc4Export($row['notes']) . '"' . "\n";
    } else {
        $bgcolor = ++$encount & 1 ? "#ddddff" : "#ffdddd";
        ?>

 <tr bgcolor="<?php 
        echo $bgcolor;
        ?>
">
  <td class="detail">
   <?php 
        echo htmlspecialchars(oeFormatShortDate($row['sale_date']));
        ?>
  </td>
  <td class="detail">
   <?php 
        echo htmlspecialchars($ttype);
        ?>
  </td>
  <td class="detail">
   <?php 
        echo htmlspecialchars($row['name']);
        ?>
  </td>
  <td class="detail">
   <?php 
        echo htmlspecialchars($row['lot_number']);
        ?>
  </td>
  <td class="detail">
   <?php 
        echo htmlspecialchars($row['warehouse']);
        ?>
  </td>
  <td class="detail">
   <?php 
        echo htmlspecialchars($dpname);
        ?>
  </td>
  <td class="detail" align="right">
   <?php 
        echo htmlspecialchars(0 - $row['quantity']);
        ?>
  </td>
  <td class="detail" align="right">
   <?php 
        echo htmlspecialchars(bucks($row['fee']));
        ?>
  </td>
  <td class="detail" align="center">
   <?php 
        echo empty($row['billed']) ? '&nbsp;' : '*';
        ?>
  </td>
  <td class="detail">
   <?php 
        echo htmlspecialchars($row['notes']);
        ?>
  </td>
 </tr>
<?php 
    }
    // End not csv export
    $grandtotal += $row['fee'];
    $grandqty -= $row['quantity'];
    // In the special case of a transfer, generate a second line item for
    // the source lot.
    if (!empty($row['xfer_inventory_id'])) {
        $row['xfer_inventory_id'] = 0;
        $row['lot_number'] = $row['lot_number_2'];
        $row['warehouse'] = $row['warehouse_2'];
        $row['quantity'] = 0 - $row['quantity'];
        $row['fee'] = 0 - $row['fee'];
        thisLineItem($row, true);
    }
}
예제 #15
0
function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transdate, $qty, $amount, $irnumber = '')
{
    global $product, $category, $producttotal, $productqty, $cattotal, $catqty, $grandtotal, $grandqty;
    global $productleft, $catleft;
    $invnumber = $irnumber ? $irnumber : "{$patient_id}.{$encounter_id}";
    $rowamount = sprintf('%01.2f', $amount);
    if (empty($rowcat)) {
        $rowcat = 'None';
    }
    $rowproduct = $description;
    if (!$rowproduct) {
        $rowproduct = 'Unknown';
    }
    if ($product != $rowproduct || $category != $rowcat) {
        if ($product) {
            // Print product total.
            if ($_POST['form_csvexport']) {
                if (!$_POST['form_details']) {
                    echo '"' . display_desc($category) . '",';
                    echo '"' . display_desc($product) . '",';
                    echo '"' . $productqty . '",';
                    echo '"';
                    bucks($producttotal);
                    echo '"' . "\n";
                }
            } else {
                ?>
 <tr bgcolor="#ddddff">
  <td class="detail">
   <?php 
                echo display_desc($catleft);
                $catleft = "&nbsp;";
                ?>
  </td>
  <td class="detail" colspan="3">
   <?php 
                if ($_POST['form_details']) {
                    echo xl('Total for') . ' ';
                }
                echo display_desc($product);
                ?>
  </td>
  <td align="right">
   <?php 
                echo $productqty;
                ?>
  </td>
  <td align="right">
   <?php 
                bucks($producttotal);
                ?>
  </td>
 </tr>
<?php 
            }
            // End not csv export
        }
        $producttotal = 0;
        $productqty = 0;
        $product = $rowproduct;
        $productleft = $product;
    }
    if ($category != $rowcat) {
        if ($category) {
            // Print category total.
            if (!$_POST['form_csvexport']) {
                ?>

 <tr bgcolor="#ffdddd">
  <td class="detail">
   &nbsp;
  </td>
  <td class="detail" colspan="3">
   <?php 
                echo xl('Total for category') . ' ';
                echo display_desc($category);
                ?>
  </td>
  <td align="right">
   <?php 
                echo $catqty;
                ?>
  </td>
  <td align="right">
   <?php 
                bucks($cattotal);
                ?>
  </td>
 </tr>
<?php 
            }
            // End not csv export
        }
        $cattotal = 0;
        $catqty = 0;
        $category = $rowcat;
        $catleft = $category;
    }
    if ($_POST['form_details']) {
        if ($_POST['form_csvexport']) {
            echo '"' . display_desc($category) . '",';
            echo '"' . display_desc($product) . '",';
            echo '"' . oeFormatShortDate(display_desc($transdate)) . '",';
            echo '"' . display_desc($invnumber) . '",';
            echo '"' . display_desc($qty) . '",';
            echo '"';
            bucks($rowamount);
            echo '"' . "\n";
        } else {
            ?>

 <tr>
  <td class="detail">
   <?php 
            echo display_desc($catleft);
            $catleft = "&nbsp;";
            ?>
  </td>
  <td class="detail">
   <?php 
            echo display_desc($productleft);
            $productleft = "&nbsp;";
            ?>
  </td>
  <td>
   <?php 
            echo oeFormatShortDate($transdate);
            ?>
  </td>
  <td class="detail">
   <a href='../patient_file/pos_checkout.php?ptid=<?php 
            echo $patient_id;
            ?>
&enc=<?php 
            echo $encounter_id;
            ?>
'>
   <?php 
            echo $invnumber;
            ?>
</a>
  </td>
  <td align="right">
   <?php 
            echo $qty;
            ?>
  </td>
  <td align="right">
   <?php 
            bucks($rowamount);
            ?>
  </td>
 </tr>
<?php 
        }
        // End not csv export
    }
    // end details
    $producttotal += $rowamount;
    $cattotal += $rowamount;
    $grandtotal += $rowamount;
    $productqty += $qty;
    $catqty += $qty;
    $grandqty += $qty;
}