Exemplo n.º 1
0
 /**
   Apply action
   @return [boolean] true if the action
     completes successfully (or is not
     necessary at all) or [string] url
     to redirect to another page for
     further decisions/input.
 */
 public function apply()
 {
     $db = Database::pDataConnect();
     $repeat = CoreLocal::get('msgrepeat');
     $coupons = array();
     $hc_table = $db->table_definition('houseCoupons');
     if ($db->table_exists('autoCoupons')) {
         $autoR = $db->query('SELECT coupID, description FROM autoCoupons');
         while ($autoW = $db->fetch_row($autoR)) {
             $coupons[$autoW['coupID']] = $autoW['description'];
         }
     }
     if (isset($hc_table['description']) && isset($hc_table['auto'])) {
         $autoR = $db->query('SELECT coupID, description FROM houseCoupons WHERE auto=1');
         while ($autoW = $db->fetch_row($autoR)) {
             $coupons[$autoW['coupID']] = $autoW['description'];
         }
     }
     $hc = new HouseCoupon();
     $prefix = CoreLocal::get('houseCouponPrefix');
     if ($prefix == '') {
         $prefix = '00499999';
     }
     foreach ($coupons as $id => $description) {
         if ($hc->checkQualifications($id, true) !== true) {
             // member or transaction does not meet requirements
             // for auto-coupon purposes, this isn't really an
             // error. no feedback necessary
             continue;
         }
         // get value of coupon AND value
         // of any previous applications of this coupon
         $add = $hc->getValue($id);
         $upc = $prefix . str_pad($id, 5, '0', STR_PAD_LEFT);
         $upc = str_pad($upc, 13, '0', STR_PAD_LEFT);
         $current = $db->query('SELECT SUM(-total) AS ttl FROM ' . CoreLocal::get('tDatabase') . $db->sep() . 'localtemptrans
                        WHERE upc=\'' . $upc . '\'');
         $val = 0;
         if ($db->num_rows($current) > 0) {
             $currentW = $db->fetch_row($current);
             $val = $currentW['ttl'];
         }
         $next_val = $add['value'] - $val;
         if ($next_val == 0) {
             // no need to add another line item
             // previous one(s) sum to correct total
             continue;
         }
         TransRecord::addhousecoupon($upc, $add['department'], -1 * $next_val, $description);
     }
     CoreLocal::set('msgrepeat', $repeat);
     return true;
 }
Exemplo n.º 2
0
 public function parse($str)
 {
     $year = '20' . substr($str, 2, 2);
     $month = substr($str, 4, 2);
     $couponID = substr($str, -3);
     $expireTS = mktime(0, 0, 0, $month, 1, $year);
     $expireTS = strtotime(date('Y-m-t', $expireTS));
     $ret = $this->default_json();
     if (time() > $expireTS) {
         $ret['output'] = DisplayLib::boxMsg('Coupon is expired');
         return $ret;
     } else {
         $upc = '004' . '99999' . str_pad($couponID, 5, '0', STR_PAD_LEFT);
         $hc = new HouseCoupon();
         return $hc->handle($upc, $ret);
     }
 }
Exemplo n.º 3
0
 public function testHouseCoupons()
 {
     if (!class_exists('lttLib')) {
         include dirname(__FILE__) . '/lttLib.php';
     }
     /**
       TEST 1: minType M, discountType Q
     */
     lttLib::clear();
     $upc = new UPC();
     $upc->parse('0000000000111');
     $upc->parse('0000000000234');
     $hc = new HouseCoupon();
     $hc->handle('0049999900001', array());
     $record = lttLib::genericRecord();
     $record['upc'] = '0049999900001';
     $record['description'] = 'MIXED+QUANTITY';
     $record['trans_type'] = 'I';
     $record['trans_subtype'] = 'IC';
     $record['trans_status'] = 'C';
     $record['quantity'] = 1;
     $record['ItemQtty'] = 1;
     $record['unitPrice'] = -2.39;
     $record['total'] = -2.39;
     $record['regPrice'] = -2.39;
     $record['discountable'] = 1;
     lttLib::verifyRecord(3, $record, $this);
     /**
       TEST 2: no minimum, discountType %D 
     */
     lttLib::clear();
     $upc = new UPC();
     $upc->parse('0000000001009');
     $upc->parse('0000000001011');
     $hc = new HouseCoupon();
     $hc->handle('0049999900002', array());
     $record = lttLib::genericRecord();
     $record['upc'] = '0049999900002';
     $record['description'] = '%DEPARTMENT';
     $record['trans_type'] = 'I';
     $record['trans_subtype'] = 'IC';
     $record['trans_status'] = 'C';
     $record['quantity'] = 1;
     $record['ItemQtty'] = 1;
     $record['unitPrice'] = -0.75;
     $record['total'] = -0.75;
     $record['regPrice'] = -0.75;
     $record['discountable'] = 1;
     lttLib::verifyRecord(3, $record, $this);
     /**
       TEST 3: minimum D, discountType F 
     */
     lttLib::clear();
     $dept = new DeptKey();
     $dept->parse('2300DP10');
     $dept->parse('200DP10');
     $hc = new HouseCoupon();
     $hc->handle('0049999900003', array());
     $record = lttLib::genericRecord();
     $record['upc'] = '0049999900003';
     $record['description'] = '5OFF25DEPT';
     $record['trans_type'] = 'I';
     $record['trans_subtype'] = 'IC';
     $record['trans_status'] = 'C';
     $record['quantity'] = 1;
     $record['ItemQtty'] = 1;
     $record['unitPrice'] = -5.0;
     $record['total'] = -5.0;
     $record['regPrice'] = -5.0;
     $record['discountable'] = 1;
     lttLib::verifyRecord(3, $record, $this);
     /**
       TEST 4: minimum MX, discountType F 
     */
     lttLib::clear();
     $dept = new DeptKey();
     $dept->parse('900DP10');
     $upc = new UPC();
     $upc->parse('0000000000234');
     $hc = new HouseCoupon();
     $hc->handle('0049999900004', array());
     $record = lttLib::genericRecord();
     $record['upc'] = '0049999900004';
     $record['description'] = 'MIXCROSS';
     $record['trans_type'] = 'I';
     $record['trans_subtype'] = 'IC';
     $record['trans_status'] = 'C';
     $record['quantity'] = 1;
     $record['ItemQtty'] = 1;
     $record['unitPrice'] = -1.0;
     $record['total'] = -1.0;
     $record['regPrice'] = -1.0;
     $record['discountable'] = 1;
     lttLib::verifyRecord(3, $record, $this);
     /**
       TEST 5: minType Q, discountType PI 
     */
     lttLib::clear();
     $upc = new UPC();
     $upc->parse('0000000000111');
     $upc->parse('0000000000234');
     $hc = new HouseCoupon();
     $hc->handle('0049999900005', array());
     $record = lttLib::genericRecord();
     $record['upc'] = '0049999900005';
     $record['description'] = 'PERITEM';
     $record['trans_type'] = 'I';
     $record['trans_subtype'] = 'IC';
     $record['trans_status'] = 'C';
     $record['quantity'] = 1;
     $record['ItemQtty'] = 1;
     $record['unitPrice'] = -1.0;
     $record['total'] = -1.0;
     $record['regPrice'] = -1.0;
     $record['discountable'] = 1;
     lttLib::verifyRecord(3, $record, $this);
     /**
       TEST 6: dept qty minimum, discountType %D 
     */
     lttLib::clear();
     $upc = new UPC();
     $upc->parse('0000000001009');
     $upc->parse('0000000001011');
     $hc = new HouseCoupon();
     $hc->handle('0049999900006', array());
     $record = lttLib::genericRecord();
     $record['upc'] = '0049999900006';
     $record['description'] = 'DEPTQTY';
     $record['trans_type'] = 'I';
     $record['trans_subtype'] = 'IC';
     $record['trans_status'] = 'C';
     $record['quantity'] = 1;
     $record['ItemQtty'] = 1;
     $record['unitPrice'] = -0.75;
     $record['total'] = -0.75;
     $record['regPrice'] = -0.75;
     $record['discountable'] = 1;
     lttLib::verifyRecord(3, $record, $this);
     lttLib::clear();
 }