-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.php
More file actions
273 lines (214 loc) · 7.18 KB
/
Copy pathbundle.php
File metadata and controls
273 lines (214 loc) · 7.18 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/**
* @copyright Copyright (C) 2009 - 2009 Ready Bytes Software Labs Pvt. Ltd. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* @package Payplans
* @contact chris.zietlow@morris.com
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
* Payplans Bundle Plugin
*
* @author Chris Zietlow
*/
class plgPayplansBundle extends XiPlugin
{
/**
* loader function, used to load apps, stylesheets, and javascript
* @return boolean
*/
public function onPayplansSystemStart()
{
$db = JFactory::getDbo();
$tables_list = $db->getTableList();
$app = JFactory::getApplication();
$prefix = $app->getCfg('dbprefix');
$tables = array('z_test');
// $db->getTableCreate($tables);
if (!in_array($prefix. 'bundle', $tables_list)) {
$db->getTableCreate($tables);
}
//add bundle app path to app loader
$appPath = dirname(__FILE__).DS.'bundle'.DS.'app';
PayplansHelperApp::addAppsPath($appPath);
//Add style sheet for input fields
$document = &JFactory::getDocument();
$css = JURI::base() . 'plugins' . DS . 'payplans' .
DS .'bundle' . DS . 'bundle' . DS . 'app' . DS . 'bundle' . DS . 'bundle.css';
$document->addStyleSheet($css);
$document->addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
$document->addScript('http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js');
return true;
}
/**
* Hooks invoice before view is rendered.
*
* @param XiView $view
* @param unknown $task
* @return multitype:string
*/
public function onPayplansViewBeforeRender(XiView $view, $task)
{
if($view instanceof PayplanssiteViewSubscription && $task == 'display')
{
$tmpl = 'subscription_edit';
$itemId = $view->getModel()->getId();
$invoice = PayplansApi::getInvoice($itemId);
$invoiceId = $invoice->getId();
$subscriptionApp = new PayplansAppBundle();
$db = JFactory::getDBO();
$tables = $db->getTableList();
$query = $db->getQuery(true);
$query
->select(array('*'))
->from('#__bundle')
->where("invoice_id = 211");
$db->setQuery($query);
$results = $db->loadObjectList();
return $subscriptionApp->renderWidget($results, $tmpl);
}
if(($view instanceof PayplanssiteViewInvoice && $task == 'confirm') || ($view instanceof PayplansadminViewInvoice && $task == 'edit'))
{
$tmpl = 'orderconfirm';
$itemId = $view->getModel()->getId();
$invoice = PayplansApi::getInvoice($itemId);
$payplans_js_src = PayplansHelperUtils::pathFS2URL(dirname(__FILE__).DS. 'bundle' . DS . 'app' . DS . 'bundle' . DS . 'bundle.js');
$this->_assign('payplans_js_src', $payplans_js_src);
$this->_assign('invoice_id', $invoice->getId());
return $this->_render($tmpl);
}
return false;
}
/**
* custom pricing update trigger. Is triggered via ajax call from bundle.js
* @param int $invoiceId
* Invoice id used for querying the invoice whose price will be updated.
*/
//#TODO change fix amount to variable amount set during instantiation of app
public function onPayplansInvoiceUpdatePricing($invoiceId, $familyChildren, $familyAdults) {
//prevent a signed number being passed.
// if ($familyChildren < 0) {
// $familyChildren = 0;
// }
// if ($familyAdult < 0) {
// $familyAdult = 0;
// }
$invoice = PayplansApi::getInvoice($invoiceId);
$amount = ($familyMembers * 75.00) + ($familyMembers * 120.00);
$modifier = PayplansModifier::getInstance();
$modifier->set('message', 'Applying additional cost here')
->set('invoice_id', $invoiceId)
->set('user_id', $invoice->getBuyer())
->set('type', 'bundle')
->set('amount', $amount)
->set('reference', 'bundle')
->set('percentage', false)
->set('frequency', PayplansModifier::FREQUENCY_EACH_TIME)
->set('serial', PayplansModifier::FIXED_NON_TAXABLE)
->save();
$invoice->refresh()->save();
}
/**
* Adds child family members to the invoice object.
*
* @param int $invoiceId
* the invoice_id used to reference the invoice
* @param string $familyName
* name of the family member
* @param string $dob
* date choosen by jquery ui datepicker
* @param enum $sex
* (M male, F female) Sex of the family member
* @param int $age
* the age of the family member
*/
//#TODO create table on install on app (#__payplans_bundle)
//#TODO update #__bundle to #__payplans_bundle (see above)
public function onPayplansInvoiceAddChildren($invoiceId, $familyName, $dob, $sex, $age) {
$invoice = PayplansApi::getInvoice($invoiceId);
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
->select(array('*'))
->from('#__bundle')
->where("invoice_id = '$invoiceId'")
->where("family_name ='$familyName'")
->where("dob = '$dob'")
->where("sex = '$sex'")
->where("age = '$age'");
$db->setQuery($query);
try {
$result = $db->loadObjectList();
} catch (Exception $e) {
$invoice->setParam('Error', $e->getMessage(). " on line" . $e->getLine());
}
//logic check fails
if (count($result) > 0){
$invoice->setParam('Error', "A record for that family member already exists.");
} else {
$familyMember = new stdClass();
$familyMember->invoice_id = $invoiceId;
$familyMember->family_name = $familyName;
$familyMember->dob = $dob;
$familyMember->sex = $sex;
$familyMember->age = $age;
JFactory::getDBO()->insertObject('#__bundle', $familyMember);
}
$numberOfChildren = $invoice->getParam('familyChildren');
$invoice->setParam('familyChildren', $numberOfChildren++);
//update the invoice object
$invoice->refresh()->save();
}
/**
* Adds Adult family members to the invoice object.
*
* @param int $invoiceId
* the invoice_id used to reference the invoice
* @param string $familyName
* name of the family member
* @param string $dob
* date choosen by jquery ui datepicker
* @param enum $sex
* sex of family member. either M or F
* @param int $age
* the age of the family member
*/
//#TODO create table on install on app (#__payplans_bundle)
//#TODO update #__bundle to #__payplans_bundle (see above)
public function onPayplansInvoiceAddAdult($invoiceId, $familyName, $dob, $sex, $age) {
$invoice = PayplansApi::getInvoice($invoiceId);
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
->select(array('*'))
->from('#__bundle')
->where("invoice_id = '$invoice_id'")
->where("family_name ='$familyName'")
->where("dob = '$dob'")
->where("sex = '$sex'")
->where("age = '$age'")
->order('id');
$db->setQuery($query);
try {
$result = $db->loadObjectList();
} catch (Exception $e) {
$invoice->setParam('Error', $e->getMessage(). " on line" . $e->getLine());
}
if (count($result) > 0){
$invoice->setParam('Error', "A record for that family member already exists");
} else {
$familyMember = new stdClass();
$familyMember->invoice_id = $invoiceId;
$familyMember->family_name = $familyName;
$familyMember->dob = $dob;
$familyMember->sex = $sex;
$familyMember->age = $age;
JFactory::getDBO()->insertObject('#__bundle', $familyMember);
}
$numberOfAdults = $invoice->getParam('familyAdults');
$invoice->setParam('familyAdults', $numberOfAdults++);
//update the invoice object
$invoice->refresh()->save();
}
}