Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] - D9/10 - Fix ordering on payment table #955

Open
wants to merge 4 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion js/webform_civicrm_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@
var $lineItem = $('.line-item.' + item, '#wf-crm-billing-items');
if (!$lineItem.length) {
var oe = $('#wf-crm-billing-items tbody tr:first').hasClass('odd') ? ' even' : ' odd';
$('#wf-crm-billing-items tbody').prepend('<tr class="line-item ' + item + oe + '" data-amount="' + amount + '">' +
let newItem = $('<tr class="line-item ' + item + oe + '" data-amount="' + amount + '">' +
'<td>' + label + '</td>' +
'<td>' + CRM.formatMoney(amount) + '</td>' +
'</tr>');
newItem.insertBefore('#wf-crm-billing-total');
}
else {
var taxPara = 1;
Expand Down Expand Up @@ -98,8 +99,16 @@
function calculateLineItemAmount() {
var fieldKey = $(this).data('civicrmFieldKey'),
amount = getFieldAmount(fieldKey),
input = $(this).attr('type'),
label = $(this).closest('div.form-item').find('label').text() || Drupal.t('Contribution'),
lineKey = fieldKey.split('_').slice(0, 4).join('_');

if (input === 'radio' || input === 'checkbox') {
label = $(this).closest('fieldset.form-item').find('legend').text() || label;
}
if (typeof input === 'undefined' && $(this).is('fieldset')) {
label = $(this).find('legend').text() || label;
}
updateLineItem(lineKey, amount, label);
}

Expand Down
16 changes: 13 additions & 3 deletions src/WebformCivicrmPostProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ private function validateParticipants() {
'unit_price' => $p['fee_amount'] ?? 0,
'element' => "civicrm_{$c}_participant_{$n}_participant_{$id_and_type}",
'contact_label' => $participantName,
'fid' => "civicrm_{$c}_participant_{$n}_participant_fee_amount",
];
}
}
Expand Down Expand Up @@ -1687,16 +1688,18 @@ private function processGrants() {
*/
private function tallyLineItems() {
$submittedFormValues = $this->form_state->getUserInput();
$webform_elements = $this->node->getElementsDecodedAndFlattened();
// Contribution
$fid = 'civicrm_1_contribution_1_contribution_total_amount';
if (isset($this->enabled[$fid]) || $this->getData($fid) > 0) {
$this->line_items[] = [
'qty' => 1,
'unit_price' => $this->getData($fid),
'financial_type_id' => wf_crm_aval($this->data, 'contribution:1:contribution:1:financial_type_id'),
'label' => wf_crm_aval($this->node->getElementsDecodedAndFlattened(), $this->enabled[$fid] . ':#title', t('Contribution')),
'label' => wf_crm_aval($webform_elements, $this->enabled[$fid] . ':#title', t('Contribution')),
'element' => 'civicrm_1_contribution_1',
'entity_table' => 'civicrm_contribution',
'fid' => $fid,
];
}
// LineItems
Expand All @@ -1709,9 +1712,10 @@ private function tallyLineItems() {
'qty' => 1,
'unit_price' => $lineitem['line_total'],
'financial_type_id' => $lineitem['financial_type_id'],
'label' => wf_crm_aval($this->node->getElementsDecodedAndFlattened(), $this->enabled[$fid] . ':#title', t('Line Item')),
'label' => wf_crm_aval($webform_elements, $this->enabled[$fid] . ':#title', t('Line Item')),
'element' => "civicrm_1_lineitem_{$n}",
'entity_table' => 'civicrm_contribution',
'fid' => $fid,
];
}
}
Expand Down Expand Up @@ -1750,13 +1754,19 @@ private function tallyLineItems() {
if (empty($member_name)) {
$member_name = $this->utils->wf_crm_display_name($this->existing_contacts[$c]);
}
$fee_amount_id = "civicrm_{$c}_membership_{$n}_membership_fee_amount";
$membership_label = $this->getMembershipTypeField($type, 'name') . ": " . $member_name;
if (isset($this->enabled[$fee_amount_id])) {
$membership_label = wf_crm_aval($webform_elements, $this->enabled[$fee_amount_id] . ':#title', $membership_label);
}
$this->line_items[] = [
'qty' => $membership_item['num_terms'],
'unit_price' => $price,
'financial_type_id' => $membership_financialtype,
'label' => $this->getMembershipTypeField($type, 'name') . ": " . $member_name,
'label' => $membership_label,
'element' => "civicrm_{$c}_membership_{$n}",
'entity_table' => 'civicrm_membership',
'fid' => $fee_amount_id,
];
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/WebformCivicrmPreProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,25 @@ private function displayLineItems() {
}

$taxRates = \CRM_Core_PseudoConstant::getTaxRates();
foreach ($this->line_items as $item) {
// Ensure the display of line items respects
// the ordering set on the component page.
$displayLineItems = [];
foreach ($this->enabled as $fid => $v) {
foreach ($this->line_items as $k => $item) {
if (!empty($item['fid']) && $fid == $item['fid']) {
$displayLineItems[$k] = $item;
continue 2;
}
}
}
// Merge remaining values.
$displayLineItems = array_values(array_replace($displayLineItems, $this->line_items));
$submittedFormValues = $this->form_state->getUserInput();
foreach ($displayLineItems as $item) {
// Load the rows for only submitted items. Final page items will be displayed on the payment table using js.
if (!empty($submittedFormValues) && isset($item['fid']) && !isset($submittedFormValues[$item['fid']]) && isset($this->enabled[$item['fid']])) {
continue;
}
$total += $item['line_total'];
// Sales Tax integration
if (!empty($item['financial_type_id'])) {
Expand Down