Skip to content

Commit

Permalink
Modular scanning pt. 2, discount types
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Theuninck committed Oct 28, 2010
1 parent b45b625 commit 2fc5139
Show file tree
Hide file tree
Showing 13 changed files with 715 additions and 110 deletions.
47 changes: 47 additions & 0 deletions pos/is4c-nf/documentation/developer/howto-scanning.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,52 @@ <h3>Example</h3>
}
</pre>
<hr />
<h3>Discount Types</h3>
Calculating discounts and pricing is done based on opdata.products.discounttype.
This column is an integer, and simply hard-coding checks for a specific value is
bound to eventually conflict with another location's usage. Discount Type modules
are are a simple solution. Each store can specify an array of modules in their
configuration and opdata.products.discounttype maps into that array. Then it
doesn't matter if discounttype==4 means something different at WFC than it does
at the Wedge.
<p />
All Discount Type objects should subclass DiscountType (lib/Scanning/DiscountType.php)
and implement the following method:
<ul>
<li>priceInfo(array $row, integer $quantity) - given the $row from opdata.products,
this method should return a keyed array with four entries: regPrice, unitPrice,
discount, and memDiscount. These entries correspond with columns of the same
name in translog.localtemptrans.</li>
</ul>
There are four additional, optional methods that may be define as needed:
<ul>
<li>addDiscountLine() - if you want to add an informational "YOU SAVED" line
to the transaction, do so here.</li>
<li>isSale() - returns true if this is the discount type for "normal" pricing.
Parent version return false.</li>
<li>isMemberOnly() - returns true if the sale is only applicable to members.
Parent version return false.</li>
<li>isStaffOnly() - returns true is the sale is only applicable to staff.
Parent version return false.</li>
</ul>
<h3>Example</h3>
Here's a simple sale (see actual implementation for optional methods):
<pre>
class EveryoneSale extends DiscountType {

function priceInfo($row, $quantity){
$ret = array(
'regPrice' => $row['normal_price'],
'unitPrice' => $row['special_price'],
'memDiscount' => 0
);

$ret['discount'] = ($ret['regPrice'] - $ret['unitPrice']) * $quantity;

return $ret;
}
}
</pre>
<hr />
</body>
</html>
57 changes: 57 additions & 0 deletions pos/is4c-nf/install/scanning.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,63 @@
?>
</select><br />
<hr />
Discount type modules control how sale prices
are calculated.<br />
<b>Number of Discounts</b>:
<?php
if (isset($_REQUEST['DT_COUNT']) && is_numeric($_REQUEST['DT_COUNT'])) $IS4C_LOCAL->set('DiscountTypeCount',$_REQUEST['DT_COUNT']);
if ($IS4C_LOCAL->get("DiscountTypeCount") == "") $IS4C_LOCAL->set("DiscountTypeCount",5);
if ($IS4C_LOCAL->get("DiscountTypeCount") <= 0) $IS4C_LOCAL->set("DiscountTypeCount",1);
printf("<input type=text size=4 name=DT_COUNT value=\"%d\" />",
$IS4C_LOCAL->get('DiscountTypeCount'));
confsave('DiscountTypeCount',$IS4C_LOCAL->get('DiscountTypeCount'));
?>
<br /><b>Discount Module Mapping</b>:<br />
<?php
if (isset($_REQUEST['DT_MODS'])) $IS4C_LOCAL->set('DiscountTypeClasses',$_REQUEST['DT_MODS']);
if (!is_array($IS4C_LOCAL->get('DiscountTypeClasses'))){
$IS4C_LOCAL->set('DiscountTypeClasses',
array(
'NormalPricing',
'EveryoneSale',
'MemberSale',
'CaseDiscount',
'StaffSale'
));
}
$discounts = array();
$dh = opendir('../lib/Scanning/DiscountTypes');
while(False !== ($f = readdir($dh))){
if ($f == "." || $f == "..")
continue;
if (substr($f,-4) == ".php"){
$discounts[] = rtrim($f,".php");
}
}
$dt_conf = $IS4C_LOCAL->get("DiscountTypeClasses");
for($i=0;$i<$IS4C_LOCAL->get('DiscountTypeCount');$i++){
echo "[$i] => ";
echo "<select name=DT_MODS[]>";
foreach($discounts as $d) {
echo "<option";
if (isset($dt_conf[$i]) && $dt_conf[$i] == $d)
echo " selected";
echo ">$d</option>";
}
echo "</select><br />";
}
$saveStr = "array(";
$tmp_count = 0;
foreach($IS4C_LOCAL->get("DiscountTypeClasses") as $r){
$saveStr .= "'".$r."',";
if ($tmp_count == $IS4C_LOCAL->get("DiscountTypeCount")-1)
break;
$tmp_count++;
}
$saveStr = rtrim($saveStr,",").")";
confsave('DiscountTypeClasses',$saveStr);
?>
<hr />
<input type=submit value="Save Changes" />
</form>
</body>
Expand Down
56 changes: 56 additions & 0 deletions pos/is4c-nf/lib/Scanning/DiscountType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*******************************************************************************
Copyright 2010 Whole Foods Co-op
This file is part of IS4C.
IS4C is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
IS4C is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
in the file license.txt along with IS4C; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************************/

class DiscountType {

var $savedRow;
var $savedInfo;

function priceInfo($row,$quantity=1){
return array(
"regPrice"=>0,
"unitPrice"=>0,
"discount"=>0,
"memDiscount"=>0
);
}

function addDiscountLine(){

}

function isSale(){
return false;
}

function isMemberOnly(){
return false;
}

function isStaffOnly(){
return false;
}

}

?>
74 changes: 74 additions & 0 deletions pos/is4c-nf/lib/Scanning/DiscountTypes/CaseDiscount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*******************************************************************************
Copyright 2010 Whole Foods Co-op
This file is part of IS4C.
IS4C is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
IS4C is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
in the file license.txt along with IS4C; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************************/
$IS4C_PATH = isset($IS4C_PATH)?$IS4C_PATH:"";
if (empty($IS4C_PATH)){ while(!file_exists($IS4C_PATH."is4c.css")) $IS4C_PATH .= "../"; }

if (!class_exists('DiscountType')) include($IS4C_PATH.'lib/Scanning/DiscountType.php');
if (!isset($IS4C_LOCAL)) include($IS4C_PATH."lib/LocalStorage/conf.php");

if (!function_exists('addcdnotify')) include($IS4C_PATH.'lib/additem.php');

class CaseDiscount extends DiscountType {

function priceInfo($row,$quantity=1){
global $IS4C_LOCAL;
$ret = array();

$ret["regPrice"] = $row['normal_price'];
$ret["unitPrice"] = $row['normal_price'];
$ret['discount'] = 0;
$ret['memDiscount'] = 0;

if ($IS4C_LOCAL->get("casediscount") > 0 && $IS4C_LOCAL->get("casediscount") <= 100) {
$casediscount = (100 - $IS4C_LOCAL->get("casediscount"))/100;
$ret['unitPrice'] = $casediscount * $ret['unitPrice'];
$ret['regPrice'] = $ret['unitPrice'];
$IS4C_LOCAL->set("casediscount",0);
}


$this->savedRow = $row;
$this->savedInfo = $ret;
return $ret;
}

function addDiscountLine(){
global $IS4C_LOCAL;
addcdnotify();
}

function isSale(){
return false;
}

function isMemberOnly(){
return false;
}

function isStaffOnly(){
return false;
}

}

?>
81 changes: 81 additions & 0 deletions pos/is4c-nf/lib/Scanning/DiscountTypes/EveryoneSale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*******************************************************************************
Copyright 2010 Whole Foods Co-op
This file is part of IS4C.
IS4C is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
IS4C is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
in the file license.txt along with IS4C; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************************/
$IS4C_PATH = isset($IS4C_PATH)?$IS4C_PATH:"";
if (empty($IS4C_PATH)){ while(!file_exists($IS4C_PATH."is4c.css")) $IS4C_PATH .= "../"; }

if (!class_exists('DiscountType')) include($IS4C_PATH.'lib/Scanning/DiscountType.php');
if (!isset($IS4C_LOCAL)) include($IS4C_PATH."lib/LocalStorage/conf.php");

if (!function_exists('adddiscount')) include($IS4C_PATH.'lib/additem.php');

class EveryoneSale extends DiscountType {

function priceInfo($row,$quantity=1){
$ret = array();

$ret["regPrice"] = $row['normal_price'];
$ret["unitPrice"] = $row['special_price'];

/* if not by weight, just use the sticker price
(for scaled items, the UPC parse module
calculates a weight estimate and sets a quantity
so normal_price can be used. This could be done
for all items, but typically the deli doesn't
keep good track of whether their items are
marked scale correctly since it only matters when an
item goes on sale
*/
if (isset($row['stickerprice']) && $row['scale'] == 0){
$ret['regPrice'] = $row['stickerprice'];
}

$ret['discount'] = ($ret['regPrice'] - $row['special_price']) * $quantity;
$ret['memDiscount'] = 0;

$this->savedRow = $row;
$this->savedInfo = $ret;
return $ret;
}

function addDiscountLine(){
global $IS4C_LOCAL;
$IS4C_LOCAL->set("voided",2);
adddiscount($this->savedInfo['discount'],
$this->savedRow['department']);
}

function isSale(){
return true;
}

function isMemberOnly(){
return false;
}

function isStaffOnly(){
return false;
}

}

?>
Loading

0 comments on commit 2fc5139

Please sign in to comment.