-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoopCredTender.php
169 lines (145 loc) · 5.83 KB
/
CoopCredTender.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/*******************************************************************************
Copyright 2012 Whole Foods Co-op
This file is part of IT CORE.
IT CORE 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.
IT CORE 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 IT CORE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************************/
/**
@class CoopCredTender
Tender module for Coop Cred accounts
Used for purchases under all Coop Cred programs.
*/
class CoopCredTender extends TenderModule
{
/**
Singleton database connection
*/
protected $conn = null;
/**
Check for errors
@return True or an error message string
*/
public function errorCheck()
{
global $CORE_LOCAL;
$this->conn = CoopCredLib::ccDataConnect();
if ($this->conn === False) {
return "Error: ccDataConnect() failed.";
}
$programOK = CoopCredLib::programOK($this->tender_code, $this->conn);
if ($programOK !== True) {
return DisplayLib::boxMsg("$programOK");
}
$subtotals = CoopCredLib::getCCredSubtotals($this->tender_code, $this->conn);
if ($subtotals !== True) {
return DisplayLib::boxMsg("$subtotals");
}
$pc = $CORE_LOCAL->get("CCredProgramCode");
//$pc = $CORE_LOCAL->get("programCode");
/* For Refunding the total without entering the exact amount
* i.e. with QA alone.
*/
if ($this->amount == '' && $this->DefaultTotal() < 0) {
$this->amount = $this->DefaultTotal();
}
/* No Available Balance.
*/
if ($CORE_LOCAL->get("{$pc}availBal") < 0) {
return DisplayLib::boxMsg(
_("Member")." #".$CORE_LOCAL->get("memberID").' '.
_("does not have enough Coop Cred in ") .
'<b>'. $CORE_LOCAL->get("{$pc}programName"). '</b>' .
_(" to cover this purchase."));
}
/* Tender more than Available Balance
* the amount remaining less the amount of this type already tendered
* in the current transaction.
* I think availBal already includes memChargeTotal.
*/
if ((abs($CORE_LOCAL->get("{$pc}memChargeTotal"))+$this->amount) >=
($CORE_LOCAL->get("{$pc}availBal") + 0.005)
) {
$memChargeCommitted = $CORE_LOCAL->get("{$pc}availBal") +
$CORE_LOCAL->get("{$pc}memChargeTotal");
return DisplayLib::xboxMsg(
_("The amount of Coop Cred you have in ").
'<b>'. $CORE_LOCAL->get("{$pc}programName"). '</b>' .
_(" is only \$") .
number_format($memChargeCommitted,2) .
'.');
}
/* Tender more than Amount Due.
*/
if(MiscLib::truncate2($CORE_LOCAL->get("amtdue")) <
MiscLib::truncate2($this->amount)
) {
return DisplayLib::xboxMsg(
_("The amount of Coop Cred tendered may not exceed the Amount Due."));
}
/* Add the tender to those used in this transaction.
*/
if ($CORE_LOCAL->get('CCredTendersUsed') == '') {
$CORE_LOCAL->set('CCredTendersUsed', array(
"$this->tender_code" => $CORE_LOCAL->get("CCredProgramID")
));
} else {
$tu = $CORE_LOCAL->get('CCredTendersUsed');
if (!array_key_exists("$this->tender_code", $tu)) {
$tu["$this->tender_code"] = $CORE_LOCAL->get("CCredProgramID");
$CORE_LOCAL->set('CCredTendersUsed',$tu);
}
}
return true;
// errorCheck()
}
/**
What to do if the tender code entered alone,
implying "pay for all of amount due with this tender"
@return a URL to redirect
*/
public function defaultPrompt()
{
global $CORE_LOCAL;
$amt = $this->DefaultTotal();
/* Make it as though the amount due preceded the tender code
* in the regular input box.
*/
$CORE_LOCAL->set('strEntered', (100*$amt).$this->tender_code);
// Don't (autoconfirm=1) ask for OK. Just apply the tender.
return MiscLib::base_url().'gui-modules/boxMsg2.php?autoconfirm=0';
}
/**
Set up state and redirect if needed
@return True or a URL to redirect
*/
public function preReqCheck()
{
global $CORE_LOCAL;
$pref = CoreState::getCustomerPref('store_charge_see_id');
if ($pref == 'yes') {
if ($CORE_LOCAL->get('msgrepeat') == 0) {
$CORE_LOCAL->set("boxMsg",("<BR>please verify member ID</B>" .
"<BR>press [enter] to continue" .
"<P><FONT size='-1'>[clear] to cancel</FONT>"));
$CORE_LOCAL->set('lastRepeat', 'storeChargeSeeID');
return MiscLib::base_url().'gui-modules/boxMsg2.php?quiet=1';
} else if ($CORE_LOCAL->get('msgrepeat') == 1 &&
$CORE_LOCAL->get('lastRepeat') == 'storeChargeSeeID') {
$CORE_LOCAL->set('msgrepeat', 0);
$CORE_LOCAL->set('lastRepeat', '');
}
}
return true;
}
// CoopCredTender class
}