* @author Brady Miller * @copyright Copyright (c) 2010-2016 Rod Roark * @copyright Copyright (c) 2017-2019 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ require_once("../globals.php"); require_once("$srcdir/patient.inc"); use OpenEMR\Common\Acl\AclMain; use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Common\Twig\TwigContainer; use OpenEMR\Core\Header; if (!empty($_POST)) { if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) { CsrfUtils::csrfNotVerified(); } } function bucks($amount) { if ($amount != 0) { return oeFormatMoney($amount); } return ''; } 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']; } elseif (!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']; } } } } elseif (!empty($row['xfer_inventory_id']) || $xfer) { $ttype = xl('Transfer'); } elseif ($row['fee'] != 0) { $ttype = xl('Purchase'); } else { $ttype = xl('Adjustment'); } if ($form_action == 'export') { echo csvEscape(oeFormatShortDate($row['sale_date'])) . ','; echo csvEscape($ttype) . ','; echo csvEscape($row['name']) . ','; echo csvEscape($row['lot_number']) . ','; echo csvEscape($row['warehouse']) . ','; echo csvEscape($dpname) . ','; echo csvEscape(0 - $row['quantity']) . ','; echo csvEscape(bucks($row['fee'])) . ','; echo csvEscape($row['billed']) . ','; echo csvEscape($row['notes']) . "\n"; } else { $bgcolor = (++$encount & 1) ? "#ddddff" : "#ffdddd"; ?> getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Inventory Transactions")]); exit; } // this is "" or "submit" or "export". $form_action = $_POST['form_action']; $form_from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d'); $form_to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d'); $form_trans_type = isset($_POST['form_trans_type']) ? $_POST['form_trans_type'] : '0'; $encount = 0; if ($form_action == 'export') { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=inventory_transactions.csv"); header("Content-Description: File Transfer"); // CSV headers: echo csvEscape(xl('Date')) . ','; echo csvEscape(xl('Transaction')) . ','; echo csvEscape(xl('Product')) . ','; echo csvEscape(xl('Lot')) . ','; echo csvEscape(xl('Warehouse')) . ','; echo csvEscape(xl('Who')) . ','; echo csvEscape(xl('Qty')) . ','; echo csvEscape(xl('Amount')) . ','; echo csvEscape(xl('Billed')) . ','; echo csvEscape(xl('Notes')) . "\n"; } else { // end export ?> <?php echo xlt('Inventory Transactions'); ?>

: : :
= ? AND s.sale_date <= ? "; if ($form_trans_type == 2) { // purchase/return $query .= "AND s.pid = 0 AND s.distributor_id = 0 AND s.xfer_inventory_id = 0 AND s.fee != 0 "; } elseif ($form_trans_type == 4) { // transfer $query .= "AND s.xfer_inventory_id != 0 "; } elseif ($form_trans_type == 5) { // adjustment $query .= "AND s.pid = 0 AND s.distributor_id = 0 AND s.xfer_inventory_id = 0 AND s.fee = 0 "; } elseif ($form_trans_type == 6) { // distribution $query .= "AND s.distributor_id != 0 "; } elseif ($form_trans_type == 1) { // sale $query .= "AND s.pid != 0 "; } $query .= "ORDER BY s.sale_date, s.sale_id"; // $res = sqlStatement($query, array($from_date, $to_date)); while ($row = sqlFetchArray($res)) { thisLineItem($row); } // Grand totals line. if ($form_action != 'export') { // if submit ?>