/
batch.php
290 lines (238 loc) · 12.8 KB
/
batch.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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
require(dirname(__FILE__) . '/../../includes/prepend.inc.php');
QApplication::Authenticate(null, array(PermissionType::AccessStewardship));
class ViewStewardshipBatchForm extends ChmsForm {
protected $strPageTitle = 'Stewardship - View Batch - ';
protected $intNavSectionId = ChmsForm::NavSectionStewardship;
public $objBatch;
public $objStack;
public $pnlBatchTitle;
public $pnlStacks;
public $pnlContent;
public $dtgContributions;
public $pxyDeleteContribution;
public $pxyDeleteStack;
protected function Form_Create() {
$this->objBatch = StewardshipBatch::Load(QApplication::PathInfo(0));
if (!$this->objBatch) QApplication::Redirect('/stewardship/');
$this->strPageTitle .= $this->objBatch->DateEntered->ToString('MMM D YYYY') . ' :: Batch ' . $this->objBatch->BatchLabel;
$this->pnlBatchTitle = new QPanel($this);
$this->pnlBatchTitle->Template = dirname(__FILE__) . '/pnlBatchTitle.tpl.php';
$this->pnlBatchTitle->CssClass = 'section sectionBatchInfo';
$this->pnlStacks = new QPanel($this);
$this->pnlStacks->TagName = 'ul';
$this->pnlStacks->CssClass = 'subnavSide subnavSideStewardship';
$this->pnlStacks->AutoRenderChildren = true;
$this->pnlContent = new QPanel($this);
$this->pnlContent->CssClass = 'stewardshipContent';
$this->pnlContent->AutoRenderChildren = true;
$this->dtgContributions = new StewardshipContributionDataGrid($this, 'dtgContributions');
$this->dtgContributions->SetDataBinder('dtgContributions_Bind');
$this->dtgContributions->HtmlBefore = '<div id="dtgContributionsDiv" class="section" style="width: 340px; height: 500px; overflow: auto; float: left; margin-right: 10px;">';
$this->dtgContributions->HtmlAfter = '</div>';
$this->dtgContributions->AddColumn(new QDataGridColumn('Contributor', '<?= $_FORM->RenderName($_ITEM); ?>', 'HtmlEntities=false', 'Width=160px'));
$this->dtgContributions->AddColumn(new QDataGridColumn('Number', '<?= $_FORM->RenderNumber($_ITEM); ?>', 'HtmlEntities=false', 'Width=60px'));
$this->dtgContributions->AddColumn(new QDataGridColumn('Amount', '<?= $_FORM->RenderAmount($_ITEM); ?>', 'HtmlEntities=false', 'Width=80px'));
$this->pxyDeleteContribution = new QControlProxy($this);
if ($this->objBatch->StewardshipBatchStatusTypeId != StewardshipBatchStatusType::NewBatch) {
$this->pxyDeleteContribution->AddAction(new QClickEvent(), new QConfirmAction('Are you SURE you want to DELETE this contribution? This will require you to re-post the stack with updates.'));
} else {
$this->pxyDeleteContribution->AddAction(new QClickEvent(), new QConfirmAction('Are you SURE you want to DELETE this contribution?'));
}
$this->pxyDeleteContribution->AddAction(new QClickEvent(), new QAjaxAction('pxyDeleteContribution_Click'));
$this->pxyDeleteContribution->AddAction(new QClickEvent(), new QTerminateAction());
$this->pxyDeleteStack = new QControlProxy($this);
$this->pnlStacks_Refresh();
$this->SetUrlHashProcessor('Form_ProcessHash');
}
public function RenderName(StewardshipContribution $objContribution) {
$strToReturn = $objContribution->Person->LinkHtml;
return $strToReturn;
}
public function RenderNumber(StewardshipContribution $objContribution) {
if (strlen($objContribution->Source) > 7)
return QApplication::HtmlEntities(substr($objContribution->Source, 0, 5) . '...');
else
return QApplication::HtmlEntities($objContribution->Source);
}
public function RenderAmount(StewardshipContribution $objContribution) {
$strToReturn = '<div class="stewardshipAmount">' . QApplication::DisplayCurrencyHtml($objContribution->TotalAmount, true);
if ($objContribution->NonDeductibleFlag) {
$strToReturn .= '<br/><span class="deductibility">ND</span>';
}
$strToReturn .= '</div>';
$strToReturn .= '<div class="stewardshipActionBackground"> </div>';
$strToReturn .= '<div class="stewardshipAction">';
if ($objContribution->CountStewardshipPostLineItems() > 0)
$strToReturn .= '<a href="#" onclick="alert("Cannot delete this transaction because it has already been posted."); return false;"><img src="/assets/images/icons/cross_disabled.png" title="Cannot Delete, Already Posted"/></a>';
else
$strToReturn .= sprintf('<a href="#" %s><img src="/assets/images/icons/cross.png" title="Delete Contribution"/></a>', $this->pxyDeleteContribution->RenderAsEvents($objContribution->Id, false));
$strToReturn .= sprintf('<a href="#%s/edit_contribution/%s"><img src="/assets/images/icons/pencil.png" title="Edit Contribution"/></a>', $this->objStack->StackNumber, $objContribution->Id);
$strToReturn .= sprintf('<a href="#%s/view_contribution/%s"><img src="/assets/images/icons/magnifier.png" title="View Details"/></a>', $this->objStack->StackNumber, $objContribution->Id);
$strToReturn .= '</div>';
return $strToReturn;
}
public function dtgContributions_Refresh() {
$this->dtgContributions->Refresh();
$this->dtgContributions->Visible = ($this->objStack) ? true : false;
if ($this->objStack) {
if ($this->objBatch->StewardshipBatchStatusTypeId == StewardshipBatchStatusType::NewBatch) {
$this->pxyDeleteStack->RemoveAllActions(QClickEvent::EventName);
if ($this->objBatch->CountStewardshipStacks() == 1) {
$strMessage = 'Are you SURE you want to delete this SINGLE stack? Doing so will also delete the batch altogether.';
} else {
$strMessage = 'Are you SURE you want to delete Stack #' . $this->objStack->StackNumber . '?';
}
$this->pxyDeleteStack->AddAction(new QClickEvent(), new QConfirmAction($strMessage));
$this->pxyDeleteStack->AddAction(new QClickEvent(), new QAjaxAction('pxyDeleteStack_Click'));
$this->pxyDeleteStack->AddAction(new QClickEvent(), new QTerminateAction());
$this->dtgContributions->NoDataHtml = sprintf('<p>Start <strong>Stack #%s</strong> and begin entering contributions.</p><div class="buttonBar"><a href="#" %s class="delete">Delete Stack</div>',
$this->objStack->StackNumber, $this->pxyDeleteStack->RenderAsEvents(null, false));
} else {
$this->dtgContributions->NoDataHtml = sprintf('<p>Start <strong>Stack #%s</strong> and begin entering contributions.</p>', $this->objStack->StackNumber);
}
} else {
$this->dtgContributions->NoDataHtml = null;
}
}
public function pxyDeleteStack_Click($strFormId, $strControlId, $strParameter) {
if ($this->objStack && !$this->objStack->CountStewardshipContributions()) {
$this->objStack->Delete();
if ($this->objBatch->CountStewardshipStacks()) {
$this->objBatch->RefreshStackNumbering();
$this->pnlStacks_Refresh(true);
$this->pnlBatchTitle->Refresh();
$this->objBatch->RefreshReportedTotalAmount();
QApplication::ExecuteJavaScript(sprintf('document.location="/stewardship/batch.php/%s";', $this->objBatch->Id));
} else {
$this->objBatch->Delete();
$dttDateEntered = $this->objBatch->DateEntered;
StewardshipBatch::RefreshBatchLettering($dttDateEntered);
QApplication::Redirect('/stewardship/');
}
}
}
public function dtgContributions_Bind() {
if ($this->objStack) {
$objCondition = QQ::Equal(QQN::StewardshipContribution()->StewardshipStackId, $this->objStack->Id);
$this->dtgContributions->MetaDataBinder($objCondition, QQ::OrderBy(QQN::StewardshipContribution()->Id));
}
}
public function pxyDeleteContribution_Click($strFormId, $strControlId, $strParameter) {
$objContribution = StewardshipContribution::Load($strParameter);
if (!$objContribution || ($objContribution->StewardshipStackId != $this->objStack->Id) || ($objContribution->StewardshipBatchId != $this->objBatch->Id)) {
return;
}
$objContribution->DeleteAllStewardshipContributionAmounts();
$objContribution->Delete();
$this->objStack->RefreshActualTotalAmount();
$this->objBatch->RefreshActualTotalAmount(false);
$this->objBatch->RefreshStatus();
$this->pnlStack_Refresh($this->objStack);
$this->pnlBatchTitle->Refresh();
$this->dtgContributions->Refresh();
QApplication::ExecuteJavaScript(sprintf('document.location="#%s";', $this->objStack->StackNumber));
}
public function Form_ProcessHash() {
// /stewardship/batch.php/X#Y/verb/Z
// X = Batch ID
// Y = Stack # (*NOT* Stack ID)
// Cleanup and Tokenize UrlHash Contents
$strUrlHash = trim(strtolower($this->strUrlHash));
$strUrlHashTokens = explode('/', $strUrlHash);
// Get Values
$intStackNumber = $strUrlHashTokens[0];
$strCommand = (array_key_exists(1, $strUrlHashTokens)) ? $strUrlHashTokens[1] : null;
$strUrlHashArgument = (array_key_exists(2, $strUrlHashTokens)) ? $strUrlHashTokens[2] : null;
$strUrlHashArgument2 = (array_key_exists(3, $strUrlHashTokens)) ? $strUrlHashTokens[3] : null;
$strUrlHashArgument3 = (array_key_exists(4, $strUrlHashTokens)) ? $strUrlHashTokens[4] : null;
// Did we switch the stack?
if (!$this->objStack || ($this->objStack->StackNumber != $intStackNumber)) {
// Save the "Old" Stack (if applicable)
$objOldStack = null;
if ($this->objStack) $objOldStack = $this->objStack;
// Set the "New" stack (and validate!)
if ($intStackNumber) {
$this->objStack = StewardshipStack::LoadByStewardshipBatchIdStackNumber($this->objBatch->Id, $intStackNumber);
if (!$this->objStack) QApplication::Redirect('/stewardship/');
} else {
$this->objStack = null;
}
// Refresh teh DataGrid and Stack in the stacklist
$this->dtgContributions_Refresh();
if ($this->objStack) $this->pnlStack_Refresh($this->objStack);
if ($objOldStack) $this->pnlStack_Refresh($objOldStack);
$this->pnlContent->CssClass = ($this->objStack) ? 'stewardshipContent' : null;
}
$this->pnlContent->RemoveChildControls(true);
// Setup the Command
if (!$strCommand) $strCommand = 'view';
$strClassName = sprintf('CpStewardship_%s', QString::ConvertToCamelCase($strCommand));
if (class_exists($strClassName, true)) {
new $strClassName($this->pnlContent, 'content', $this->objBatch, $this->objStack, $strUrlHashArgument, $strUrlHashArgument2, $strUrlHashArgument3);
QApplication::ExecuteJavaScript('ScrollToBottom();');
} else {
QApplication::Redirect('#1');
}
}
public function pnlStacks_Refresh($blnClearChildren = false) {
if ($blnClearChildren) {
$this->pnlStacks->RemoveChildControls(true);
$this->pnlStacks->Refresh();
}
$objStackArray = $this->objBatch->GetStewardshipStackArray(QQ::OrderBy(QQN::StewardshipStack()->StackNumber));
$pnlStack = null;
$blnFirst = true;
foreach ($objStackArray as $objStack) {
$strControlId = 'pnlStack' . $objStack->Id;
$pnlStack = $this->GetControl($strControlId);
if (!$pnlStack) {
$pnlStack = new QPanel($this->pnlStacks, $strControlId);
$pnlStack->TagName = 'li';
}
if ($blnFirst) {
$strClassName = 'first';
$blnFirst = false;
} else {
$strClassName = null;
}
$pnlStack->CssClass = $strClassName;
$this->pnlStack_Refresh($objStack);
}
// Last
if ($pnlStack) $pnlStack->CssClass .= ' last';
}
public function pnlStack_Refresh(StewardshipStack $objStack) {
$strControlId = 'pnlStack' . $objStack->Id;
$pnlStack = $this->GetControl($strControlId);
if (!$pnlStack) return;
$strClassName = null;
if ($this->objStack && ($this->objStack->Id == $objStack->Id)) {
$strClassName = 'selected';
// Since there are so many calculated values in the HTML, we'll store the template as a
// sprintf-formatted string (e.g. with a bunch of %s) as a textfile and use sprintf to manually set the text of the
// pnlStack, instead of doing a full fledged QPanel template
if ($objStack->ReportedTotalAmount) {
$strSprintfTemplate = file_get_contents(dirname(__FILE__) . '/pnlStack_WithReportedAmount.txt');
$pnlStack->Text = sprintf($strSprintfTemplate, $objStack->StackNumber, $strClassName, $objStack->StackNumber,
number_format($objStack->ItemCount, 0),
QApplication::DisplayCurrency($objStack->ActualTotalAmount),
QApplication::DisplayCurrency($objStack->ReportedTotalAmount),
QApplication::DisplayCurrencyHtml($objStack->ActualTotalAmount - $objStack->ReportedTotalAmount));
} else {
$strSprintfTemplate = file_get_contents(dirname(__FILE__) . '/pnlStack_WithoutReportedAmount.txt');
$pnlStack->Text = sprintf($strSprintfTemplate, $objStack->StackNumber, $strClassName, $objStack->StackNumber,
number_format($objStack->ItemCount, 0),
QApplication::DisplayCurrency($objStack->ActualTotalAmount));
}
// For "Unselected"
} else {
$strSprintfTemplate = file_get_contents(dirname(__FILE__) . '/pnlStack_Unselected.txt');
$pnlStack->Text = sprintf($strSprintfTemplate, $objStack->StackNumber, $strClassName, $objStack->StackNumber,
number_format($objStack->ItemCount, 0),
QApplication::DisplayCurrency($objStack->ActualTotalAmount));
}
}
}
ViewStewardshipBatchForm::Run('ViewStewardshipBatchForm');
?>