Example #1
0
 /**
   Load values from subtotals view into session.
   Essentially refreshes totals in the session.
 */
 public static function getsubtotals()
 {
     $query = "SELECT * FROM subtotals";
     $connection = self::tDataConnect();
     $result = $connection->query($query);
     $row = $connection->fetch_array($result);
     // reset a few variables
     if (!$row || $row["LastID"] == 0) {
         CoreLocal::set("ttlflag", 0);
         CoreLocal::set("fntlflag", 0);
         self::setglobalflags(0);
     }
     // LastID => MAX(localtemptrans.trans_id) or zero table is empty
     CoreLocal::set("LastID", !$row || !isset($row['LastID']) ? 0 : (double) $row["LastID"]);
     // card_no => MAX(localtemptrans.card_no)
     $cn = !$row || !isset($row['card_no']) ? "0" : trim($row["card_no"]);
     if ($cn != "0" || CoreLocal::get("memberID") == "") {
         CoreLocal::set("memberID", $cn);
     }
     // runningTotal => SUM(localtemptrans.total)
     CoreLocal::set("runningTotal", !$row || !isset($row['runningTotal']) ? 0 : (double) $row["runningTotal"]);
     // complicated, but replaced by taxView & LineItemTaxes() method
     CoreLocal::set("taxTotal", !$row || !isset($row['taxTotal']) ? 0 : (double) $row["taxTotal"]);
     // discountTTL => SUM(localtemptrans.total) where discounttype=1
     // probably not necessary
     CoreLocal::set("discounttotal", !$row || !isset($row['discountTTL']) ? 0 : (double) $row["discountTTL"]);
     // tenderTotal => SUM(localtemptrans.total) where trans_type=T
     CoreLocal::set("tenderTotal", !$row || !isset($row['tenderTotal']) ? 0 : (double) $row["tenderTotal"]);
     // memSpecial => SUM(localtemptrans.total) where discounttype=2,3
     CoreLocal::set("memSpecial", !$row || !isset($row['memSpecial']) ? 0 : (double) $row["memSpecial"]);
     // staffSpecial => SUM(localtemptrans.total) where discounttype=4
     CoreLocal::set("staffSpecial", !$row || !isset($row['staffSpecial']) ? 0 : (double) $row["staffSpecial"]);
     if (CoreLocal::get('member_subtotal') !== 0 && CoreLocal::get('member_subtotal') !== '0') {
         // percentDiscount => MAX(localtemptrans.percentDiscount)
         CoreLocal::set("percentDiscount", !$row || !isset($row['percentDiscount']) ? 0 : (double) $row["percentDiscount"]);
     }
     // transDiscount => lttsummary.discountableTTL * lttsummary.percentDiscount
     CoreLocal::set("transDiscount", !$row || !isset($row['transDiscount']) ? 0 : (double) $row["transDiscount"]);
     // complicated, but replaced by taxView & LineItemTaxes() method
     CoreLocal::set("fsTaxExempt", !$row || !isset($row['fsTaxExempt']) ? 0 : (double) $row["fsTaxExempt"]);
     // foodstamp total net percentdiscount minus previous foodstamp tenders
     CoreLocal::set("fsEligible", !$row || !isset($row['fsEligible']) ? 0 : (double) $row["fsEligible"]);
     // chargeTotal => hardcoded to localtemptrans.trans_subtype MI or CX
     CoreLocal::set("chargeTotal", !$row || !isset($row['chargeTotal']) ? 0 : (double) $row["chargeTotal"]);
     // paymentTotal => hardcoded to localtemptrans.department = 990
     CoreLocal::set("paymentTotal", !$row || !isset($row['paymentTotal']) ? 0 : (double) $row["paymentTotal"]);
     CoreLocal::set("memChargeTotal", CoreLocal::get("chargeTotal") + CoreLocal::get("paymentTotal"));
     // discountableTotal => SUM(localtemptrans.total) where discountable > 0
     CoreLocal::set("discountableTotal", !$row || !isset($row['discountableTotal']) ? 0 : (double) $row["discountableTotal"]);
     // localTotal => SUM(localtemptrans.total) where numflag=1
     CoreLocal::set("localTotal", !$row || !isset($row['localTotal']) ? 0 : (double) $row["localTotal"]);
     // voidTotal => SUM(localtemptrans.total) where trans_status=V
     CoreLocal::set("voidTotal", !$row || !isset($row['voidTotal']) ? 0 : (double) $row["voidTotal"]);
     /**
       9May14 Andy
       I belive this query is equivalent to the
       old subtotals => lttsubtotals => lttsummary
       I've omitted tax since those are already calculated
       separately. A few conditions here should obviously
       be more configurable, but first I want to get
       rid of or simply the old nested views
     
       fsEligible is the complicated one. That's:
       1. Total foodstampable items
       2. Minus transaction-level discount on those items
       3. Minus any foodstamp tenders already applied.
          localtemptrans.total is negative on tenders
          so the query uses an addition sign but in 
          effect it's subracting.
     */
     $replacementQ = "\n        SELECT\n            CASE WHEN MAX(trans_id) IS NULL THEN 0 ELSE MAX(trans_id) END AS LastID,\n            MAX(card_no) AS card_no,\n            SUM(total) AS runningTotal,\n            SUM(CASE WHEN discounttype=1 THEN total ELSE 0 END) AS discountTTL,\n            SUM(CASE WHEN discounttype IN (2,3) THEN total ELSE 0 END) AS staffSpecial,\n            SUM(CASE WHEN discounttype=4 THEN total ELSE 0 END) AS discountTTL,\n            SUM(CASE WHEN trans_type='T' THEN total ELSE 0 END) AS tenderTotal,\n            MAX(percentDiscount) AS percentDiscount,\n            SUM(CASE WHEN discountable=0 THEN 0 ELSE total END) as discountableTotal,\n            SUM(CASE WHEN discountable=0 THEN 0 ELSE total END) * (MAX(percentDiscount)/100.00) AS transDiscount,\n            SUM(CASE WHEN trans_subtype IN ('MI', 'CX') THEN total ELSE 0 END) AS chargeTotal,\n            SUM(CASE WHEN department=990 THEN total ELSE 0 END) as paymentTotal,\n            SUM(CASE WHEN numflag=1 THEN total ELSE 0 END) as localTotal,\n            SUM(CASE WHEN trans_status='V' THEN total ELSE 0 END) as voidTotal,\n            (\n                SUM(CASE WHEN foodstamp=1 THEN total ELSE 0 END) \n                -\n                ((MAX(percentDiscount)/100.00)\n                * SUM(CASE WHEN foodstamp=1 AND discountable=1 THEN total ELSE 0 END))\n                +\n                SUM(CASE WHEN trans_subtype IN ('EF','FS') THEN total ELSE 0 END)\n            ) AS fsEligble\n        FROM localtemptrans AS l\n        WHERE trans_type <> 'L'\n    ";
     /* ENABLED LIVE 15Aug2013
            Calculate taxes & exemptions separately from
            the subtotals view.
     
            Adding the exemption amount back on is a bit
            silly but the goal for the moment is to keep
            this function behaving the same. Once the subtotals
            view is deprecated we can revisit how these two
            session variables should behave.
         */
     $taxes = Database::LineItemTaxes();
     $taxTTL = 0.0;
     $exemptTTL = 0.0;
     foreach ($taxes as $tax) {
         $taxTTL += $tax['amount'];
         $exemptTTL += $tax['exempt'];
     }
     CoreLocal::set('taxTotal', number_format($taxTTL, 2));
     CoreLocal::set('fsTaxExempt', number_format(-1 * $exemptTTL, 2));
     if (CoreLocal::get("TaxExempt") == 1) {
         CoreLocal::set("taxable", 0);
         CoreLocal::set("taxTotal", 0);
         CoreLocal::set("fsTaxable", 0);
         CoreLocal::set("fsTaxExempt", 0);
     }
     CoreLocal::set("subtotal", number_format(CoreLocal::get("runningTotal") - CoreLocal::get("transDiscount"), 2));
     /* using a string for amtdue behaves strangely for
      * values > 1000, so use floating point */
     CoreLocal::set("amtdue", (double) round(CoreLocal::get("runningTotal") - CoreLocal::get("transDiscount") + CoreLocal::get("taxTotal"), 2));
     /**
       If FS eligible amount is greater than the current transaction total
       and total is positive, limit the eligible amount to the current total.
       This may not be technically correct but the resulting change causes a lot
       of headaches depending what kind of change is allowed for earlier tenders,
       if change is allowed for those tenders at all.
     
       The other case is a refund to FS. Over-tendering on a refund doesn't make
       any sense.
     */
     if (CoreLocal::get("fsEligible") > CoreLocal::get("subtotal") && CoreLocal::get('subtotal') >= -0.005) {
         CoreLocal::set("fsEligible", CoreLocal::get("subtotal"));
     } elseif (CoreLocal::get("fsEligible") < CoreLocal::get("subtotal") && CoreLocal::get('subtotal') < 0) {
         CoreLocal::set("fsEligible", CoreLocal::get("subtotal"));
     }
 }
Example #2
0
 /**
   Finish the current transaction
   @param $incomplete [boolean] optional, default false
 
   This method:
   1) Adds tax and discount lines if transaction is complete
      (i.e., $incomplete == false)
   2) Rotates data out of localtemptrans
   3) Advances trans_no variable to next available value
 
   This method replaces older ajax-end.php / end.php operations
   where the receipt was printed first and then steps 1-3
   above happened. This method should be called BEFORE printing
   a receipt. Receipts are now always printed via localtranstoday.
 */
 public static function finalizeTransaction($incomplete = false)
 {
     if (!$incomplete) {
         self::addtransDiscount();
         self::addTax();
         $taxes = Database::LineItemTaxes();
         foreach ($taxes as $tax) {
             if (CoreLocal::get('TaxExempt') == 1) {
                 $tax['amount'] = 0.0;
             }
             self::addLogRecord(array('upc' => 'TAXLINEITEM', 'description' => $tax['description'], 'numflag' => $tax['rate_id'], 'amount2' => $tax['amount']));
         }
         DiscountModule::lineItems();
     }
     if (Database::rotateTempData()) {
         // rotate data
         Database::clearTempTables();
     }
     // advance trans_no value
     Database::loadglobalvalues();
     $nextTransNo = Database::gettransno(CoreLocal::get('CashierNo'));
     CoreLocal::set('transno', $nextTransNo);
     Database::setglobalvalue('TransNo', $nextTransNo);
 }