function thisLineItem($product_id, $warehouse_id, $patient_id, $encounter_id, $rowprod, $rowwh, $transdate, $qtys, $irnumber = '') { global $warehouse, $product, $secqtys, $priqtys, $grandqtys; global $whleft, $prodleft; // left 2 columns, blank where repeated global $last_warehouse_id, $last_product_id, $product_first; global $form_action; $invnumber = empty($irnumber) ? $patient_id ? "{$patient_id}.{$encounter_id}" : "" : $irnumber; // Product name for this detail line item. if (empty($rowprod)) { $rowprod = 'Unnamed Product'; } // Warehouse name for this line item. if (empty($rowwh)) { $rowwh = 'None'; } // If new warehouse or product... if ($warehouse_id != $last_warehouse_id || $product_id != $last_product_id) { // If there was anything to total... if ($product_first && $last_warehouse_id != '~' || !$product_first && $last_product_id) { $secei = getEndInventory($last_product_id, $last_warehouse_id); // Print second-column totals. if ($form_action == 'export') { // Export: if (!$_POST['form_details']) { if ($product_first) { echo '"' . esc4Export($product) . '"'; echo ',"' . esc4Export($warehouse) . '"'; } else { echo '"' . esc4Export($warehouse) . '"'; echo ',"' . esc4Export($product) . '"'; } echo ',"' . ($secei - $secqtys[0] - $secqtys[1] - $secqtys[2] - $secqtys[3] - $secqtys[4]) . '"'; // start inventory echo ',"' . $secqtys[0] . '"'; // sales echo ',"' . $secqtys[1] . '"'; // distributions echo ',"' . $secqtys[2] . '"'; // purchases echo ',"' . $secqtys[3] . '"'; // transfers echo ',"' . $secqtys[4] . '"'; // adjustments echo ',"' . $secei . '"'; // end inventory echo "\n"; } } else { // Not export: ?> <tr bgcolor="#ddddff"> <?php if ($product_first) { ?> <td class="detail"> <?php echo htmlspecialchars($prodleft); $prodleft = " "; ?> </td> <td class="detail" colspan='3'> <?php if ($_POST['form_details']) { echo htmlspecialchars(xl('Total for')) . ' '; } echo htmlspecialchars($warehouse); ?> </td> <?php } else { ?> <td class="detail"> <?php echo htmlspecialchars($whleft); $whleft = " "; ?> </td> <td class="detail" colspan='3'> <?php if ($_POST['form_details']) { echo htmlspecialchars(xl('Total for')) . ' '; } echo htmlspecialchars($product); ?> </td> <?php } ?> <td class="dehead" align="right"> <?php echo $secei - $secqtys[0] - $secqtys[1] - $secqtys[2] - $secqtys[3] - $secqtys[4]; ?> </td> <td class="dehead" align="right"> <?php echo $secqtys[0]; ?> </td> <td class="dehead" align="right"> <?php echo $secqtys[1]; ?> </td> <td class="dehead" align="right"> <?php echo $secqtys[2]; ?> </td> <td class="dehead" align="right"> <?php echo $secqtys[3]; ?> </td> <td class="dehead" align="right"> <?php echo $secqtys[4]; ?> </td> <td class="dehead" align="right"> <?php echo $secei; ?> </td> </tr> <?php } // End not csv export } $secqtys = array(0, 0, 0, 0, 0); if ($product_first) { $whleft = $warehouse = $rowwh; $last_warehouse_id = $warehouse_id; } else { $prodleft = $product = $rowprod; $last_product_id = $product_id; } } // If first column is changing, time for its totals. if ($product_first && $product_id != $last_product_id || !$product_first && $warehouse_id != $last_warehouse_id) { if ($product_first && $last_product_id || !$product_first && $last_warehouse_id != '~') { $priei = $product_first ? getEndInventory($last_product_id) : getEndInventory(0, $last_warehouse_id); // Print first column total. if ($form_action != 'export') { ?> <tr bgcolor="#ffdddd"> <td class="detail"> </td> <td class="detail" colspan="3"> <?php echo htmlspecialchars(xl('Total for')) . ' '; echo htmlspecialchars($product_first ? $product : $warehouse); ?> </td> <td class="dehead" align="right"> <?php echo $priei - $priqtys[0] - $priqtys[1] - $priqtys[2] - $priqtys[3] - $priqtys[4]; ?> </td> <td class="dehead" align="right"> <?php echo $priqtys[0]; ?> </td> <td class="dehead" align="right"> <?php echo $priqtys[1]; ?> </td> <td class="dehead" align="right"> <?php echo $priqtys[2]; ?> </td> <td class="dehead" align="right"> <?php echo $priqtys[3]; ?> </td> <td class="dehead" align="right"> <?php echo $priqtys[4]; ?> </td> <td class="dehead" align="right"> <?php echo $priei; ?> </td> </tr> <?php } // End not csv export } $priqtys = array(0, 0, 0, 0, 0); if ($product_first) { $prodleft = $product = $rowprod; $last_product_id = $product_id; } else { $whleft = $warehouse = $rowwh; $last_warehouse_id = $warehouse_id; } } // Detail line. if ($_POST['form_details'] && $product_id && $qtys[0] + $qtys[1] + $qtys[2] + $qtys[3] + $qtys[4]) { if ($form_action == 'export') { if ($product_first) { echo '"' . esc4Export($product) . '"'; echo ',"' . esc4Export($warehouse) . '"'; } else { echo '"' . esc4Export($warehouse) . '"'; echo ',"' . esc4Export($product) . '"'; } echo ',"' . oeFormatShortDate($transdate) . '"'; echo ',"' . esc4Export($invnumber) . '"'; echo ',"' . $qtys[0] . '"'; // sales echo ',"' . $qtys[1] . '"'; // distributions echo ',"' . $qtys[2] . '"'; // purchases echo ',"' . $qtys[3] . '"'; // transfers echo ',"' . $qtys[4] . '"'; // adjustments echo "\n"; } else { ?> <tr> <?php if ($product_first) { ?> <td class="detail"> <?php echo htmlspecialchars($prodleft); $prodleft = " "; ?> </td> <td class="detail"> <?php echo htmlspecialchars($whleft); $whleft = " "; ?> </td> <?php } else { ?> <td class="detail"> <?php echo htmlspecialchars($whleft); $whleft = " "; ?> </td> <td class="detail"> <?php echo htmlspecialchars($prodleft); $prodleft = " "; ?> </td> <?php } ?> <td class="dehead"> <?php echo oeFormatShortDate($transdate); ?> </td> <td class="detail"> <?php echo htmlspecialchars($invnumber); ?> </td> <td class="detail"> </td> <td class="dehead" align="right"> <?php echo $qtys[0]; ?> </td> <td class="dehead" align="right"> <?php echo $qtys[1]; ?> </td> <td class="dehead" align="right"> <?php echo $qtys[2]; ?> </td> <td class="dehead" align="right"> <?php echo $qtys[3]; ?> </td> <td class="dehead" align="right"> <?php echo $qtys[4]; ?> </td> <td class="detail"> </td> </tr> <?php } // End not csv export } // end details for ($i = 0; $i < 5; ++$i) { $secqtys[$i] += $qtys[$i]; $priqtys[$i] += $qtys[$i]; $grandqtys[$i] += $qtys[$i]; } }
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']) ? ' ' : '*'; ?> </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); } }