Skip to content

Commit

Permalink
Fix Invoice class to not call validateData
Browse files Browse the repository at this point in the history
This avoids calling the BaseIPN validateData class from Invoice.php and calls the narrower
loadRelatedObjects to avoid having to change the code around it
  • Loading branch information
eileenmcnaughton committed Sep 5, 2020
1 parent 30bd3f9 commit e6f479e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
13 changes: 5 additions & 8 deletions CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
$pendingStatusId = CRM_Utils_Array::key('Pending', $contributionStatusID);

foreach ($invoiceElements['details'] as $contribID => $detail) {
$input = $ids = $objects = [];
$input = $ids = [];
if (in_array($detail['contact'], $invoiceElements['excludeContactIds'])) {
continue;
}
Expand All @@ -225,20 +225,17 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
$ids['participant'] = $detail['participant'] ?? NULL;
$ids['event'] = $detail['event'] ?? NULL;

if (!$invoiceElements['baseIPN']->validateData($input, $ids, $objects, FALSE)) {
CRM_Core_Error::statusBounce('Supplied data was not able to be validated');
}

$contribution = &$objects['contribution'];
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $contribID;
$contribution->fetch();
$contribution->loadRelatedObjects($input, $ids, TRUE);

$input['amount'] = $contribution->total_amount;
$input['invoice_id'] = $contribution->invoice_id;
$input['receive_date'] = $contribution->receive_date;
$input['contribution_status_id'] = $contribution->contribution_status_id;
$input['organization_name'] = $contribution->_relatedObjects['contact']->organization_name;

$objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);

// Fetch the billing address. getValues should prioritize the billing
// address, otherwise will return the primary address.
$billingAddress = [];
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function testInvoiceForDueDate() {

$this->assertNotContains('Due Date', $invoiceHTML[$result['id']]);
$this->assertNotContains('PAYMENT ADVICE', $invoiceHTML[$result['id']]);
$this->assertContains('Mr. Anthony Anderson II', $invoiceHTML[$result['id']]);

$this->assertContains('Due Date', $invoiceHTML[$contribution['id']]);
$this->assertContains('PAYMENT ADVICE', $invoiceHTML[$contribution['id']]);
Expand Down

0 comments on commit e6f479e

Please sign in to comment.