Skip to content
Snippets Groups Projects
Unverified Commit fc46016c authored by DaveD's avatar DaveD Committed by GitHub
Browse files

Merge pull request #23870 from eileenmcnaughton/offline

#3694 - get preview working & tested for offline-contribution receipt
parents 36230955 8193ed74
No related branches found
No related tags found
No related merge requests found
<?php
use Civi\Api4\PriceField;
use Civi\Api4\PriceFieldValue;
use Civi\Api4\PriceSet;
use Civi\Api4\WorkflowMessage;
use Civi\WorkflowMessage\GenericWorkflowMessage;
use Civi\WorkflowMessage\WorkflowMessageExample;
......@@ -21,7 +24,7 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
yield [
'name' => 'workflow/' . $workflow . '/basic_eur',
'title' => ts('Completed Contribution') . ' : ' . 'EUR',
'tags' => ['preview'],
'tags' => $workflow === 'contribution_offline_receipt' ? ['phpunit', 'preview'] : ['preview'],
'workflow' => $workflow,
];
yield [
......@@ -31,6 +34,16 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
'workflow' => 'contribution_offline_receipt',
'currency' => 'CAD',
];
$priceSet = $this->getNonQuickConfigPriceSet();
if ($priceSet) {
yield [
'name' => 'workflow/' . $workflow . '/' . 'price_set_' . $priceSet['name'],
'title' => ts('Completed Contribution') . ' : ' . $priceSet['title'],
'tags' => ['preview'],
'workflow' => 'contribution_offline_receipt',
'is_show_line_items' => TRUE,
];
}
}
}
......@@ -47,6 +60,37 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
$messageTemplate = new $workFlow['class']();
$this->addExampleData($messageTemplate, $example);
$example['data'] = $this->toArray($messageTemplate);
switch ($example['workflow']) {
case 'contribution_online_receipt':
$example['asserts'] = [
'default' => [
['for' => 'subject', 'regex' => '/Receipt - FIXME Contribution Title - Barbara Johnson/'],
['for' => 'html', 'regex' => '/table id="crm-event_receipt"/'],
['for' => 'html', 'regex' => '/Dear Barb,/'],
],
];
break;
// This does not yet get hit - placeholder
case 'contribution_offline_receipt':
$example['asserts'] = [
'default' => [
['for' => 'subject', 'regex' => '/Contribution Receipt - Barbara Johnson/'],
['for' => 'text', 'regex' => '/Transaction ID: 123/'],
],
];
break;
// This does not yet get hit - placeholder
case 'contribution_invoice_receipt':
$example['asserts'] = [
'default' => [
['for' => 'subject', 'regex' => '/Invoice - Barbara Johnso/'],
['for' => 'html', 'regex' => '/Amount Paid/'],
],
];
break;
}
}
/**
......@@ -68,9 +112,68 @@ class CRM_Contribute_WorkflowMessage_Contribution_BasicContribution extends Work
}
$mockOrder = new CRM_Financial_BAO_Order();
$mockOrder->setTemplateContributionID(50);
$mockOrder->setPriceSetToDefault('contribution');
if (empty($example['is_show_line_items'])) {
$mockOrder->setPriceSetToDefault('contribution');
$mockOrder->setOverrideTotalAmount($contribution['total_amount']);
$mockOrder->setDefaultFinancialTypeID($contribution['financial_type_id']);
}
else {
$priceSet = $this->getNonQuickConfigPriceSet();
$mockOrder->setPriceSetID($priceSet['id']);
if ($priceSet['financial_type_id']) {
$mockOrder->setDefaultFinancialTypeID($priceSet['financial_type_id']);
}
}
foreach (PriceField::get()->addWhere('price_set_id', '=', $mockOrder->getPriceSetID())->execute() as $index => $priceField) {
$priceFieldValue = PriceFieldValue::get()->addWhere('price_field_id', '=', $priceField['id'])->execute()->first();
if (empty($example['is_show_line_items'])) {
$priceFieldValue['amount'] = $contribution['total_amount'];
$priceFieldValue['financial_type_id'] = $contribution['financial_type_id'];
}
$this->setLineItem($mockOrder, $priceField, $priceFieldValue, $index);
}
$contribution['total_amount'] = $mockOrder->getTotalAmount();
$contribution['tax_amount'] = $mockOrder->getTotalTaxAmount() ? round($mockOrder->getTotalTaxAmount(), 2) : 0;
$messageTemplate->setContribution($contribution);
$messageTemplate->setOrder($mockOrder);
$messageTemplate->setContribution($contribution);
}
/**
* Get a non-quick-config price set.
*
* @return array|null
* @throws \API_Exception
*/
private function getNonQuickConfigPriceSet(): ?array {
// Permission check defaults to true - likely implicitly OK but may need to be false.
return PriceSet::get()
->addWhere('is_quick_config', '=', FALSE)
->execute()
->first();
}
/**
* @param \CRM_Financial_BAO_Order $mockOrder
* @param $priceField
* @param array|null $priceFieldValue
* @param $index
*
* @throws \API_Exception
*/
private function setLineItem(CRM_Financial_BAO_Order $mockOrder, $priceField, ?array $priceFieldValue, $index): void {
$mockOrder->setLineItem([
'price_field_id' => $priceField['id'],
'price_field_id.label' => $priceField['label'],
'price_field_value_id' => $priceFieldValue['id'],
'qty' => $priceField['is_enter_qty'] ? 2 : 1,
'unit_price' => $priceFieldValue['amount'],
'line_total' => $priceField['is_enter_qty'] ? ($priceFieldValue['amount'] * 2) : $priceFieldValue['amount'],
'label' => $priceFieldValue['label'],
'financial_type_id' => $priceFieldValue['financial_type_id'],
'non_deductible_amount' => $priceFieldValue['non_deductible_amount'],
], $index);
}
}
......@@ -28,6 +28,30 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
*/
public $isShowTax;
/**
* Line items associated with the contribution.
*
* @var array
*
* @scope tplParams
*/
public $lineItems;
/**
* Tax rates paid.
*
* Generally this would look like
*
* ['10.00%' => 100]
*
* To indicate that $100 was changed for 10% tax.
*
* @var array
*
* @scope tplParams
*/
public $taxRateBreakdown;
/**
* @var CRM_Financial_BAO_Order
*/
......@@ -79,6 +103,49 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait {
return !$this->order->getPriceSetMetadata()['is_quick_config'];
}
/**
* Get the line items.
*
* @return array
*/
public function getLineItems(): array {
if (isset($this->lineItems)) {
return $this->lineItems;
}
$order = $this->getOrder();
if (!$order) {
// This would only be the case transitionally.
// Since this is a trait it is used by templates which don't (yet)
// always have the contribution ID available as well as migrated ones.
return [];
}
return $order->getLineItems();
}
/**
* Get the line items.
*
* @return array
*/
public function getTaxRateBreakdown(): array {
if (isset($this->taxRateBreakdown)) {
return $this->taxRateBreakdown;
}
$this->taxRateBreakdown = [];
foreach ($this->getLineItems() as $lineItem) {
$this->taxRateBreakdown[$lineItem['tax_rate']] = [
'amount' => $lineItem['tax_amount'] ?? 0,
'rate' => $lineItem['tax_rate'],
'percentage' => sprintf('%.2f', $lineItem['tax_rate']),
];
}
if (array_keys($this->taxRateBreakdown) === [0]) {
// If the only tax rate charged is 0% then no tax breakdown is returned.
$this->taxRateBreakdown = [];
}
return $this->taxRateBreakdown;
}
/**
* Set contribution object.
*
......
......@@ -293,6 +293,13 @@ class CRM_Financial_BAO_Order {
*/
protected $priceFieldMetadata = [];
/**
* Metadata for price field values.
*
* @var array
*/
protected $priceFieldValueMetadata = [];
/**
* Metadata for price sets.
*
......@@ -576,6 +583,22 @@ class CRM_Financial_BAO_Order {
return $this->getPriceFieldsMetadata()[$id];
}
/**
* Get the metadata for the given field value.
*
* @internal use in tested core code only.
*
* @param int $id
*
* @return array
*/
public function getPriceFieldValueSpec(int $id) :array {
if (!isset($this->priceFieldValueMetadata[$id])) {
$this->priceFieldValueMetadata[$id] = PriceFieldValue::get(FALSE)->addWhere('id', '=', $id)->execute()->first();
}
return $this->priceFieldValueMetadata[$id];
}
/**
* Get the metadata for the fields in the price set.
*
......@@ -832,6 +855,7 @@ class CRM_Financial_BAO_Order {
elseif ($taxRate) {
$lineItem['tax_amount'] = ($taxRate / 100) * $lineItem['line_total'];
}
$lineItem['title'] = $lineItem['label'];
}
return $lineItems;
}
......@@ -949,7 +973,8 @@ class CRM_Financial_BAO_Order {
$this->addTotalsToLineBasedOnOverrideTotal((int) $lineItem['financial_type_id'], $lineItem);
}
else {
$lineItem['tax_amount'] = ($this->getTaxRate($lineItem['financial_type_id']) / 100) * $lineItem['line_total'];
$lineItem['tax_rate'] = $this->getTaxRate($lineItem['financial_type_id']);
$lineItem['tax_amount'] = ($lineItem['tax_rate'] / 100) * $lineItem['line_total'];
}
if (!empty($lineItem['membership_type_id'])) {
$lineItem['entity_table'] = 'civicrm_membership';
......@@ -960,6 +985,32 @@ class CRM_Financial_BAO_Order {
if ($this->getPriceSetID() === $this->getDefaultPriceSetForComponent('contribution')) {
$this->fillDefaultContributionLine($lineItem);
}
if (empty($lineItem['label'])) {
$lineItem['label'] = PriceFieldValue::get(FALSE)->addWhere('id', '=', (int) $lineItem['price_field_value_id'])->addSelect('label')->execute()->first()['label'];
}
if (empty($lineItem['price_field_id']) && !empty($lineItem['membership_type_id'])) {
// We have to 'guess' the price field since the calling code hasn't
// passed it in (which it really should but ... history).
foreach ($this->priceFieldMetadata as $pricefield) {
foreach ($pricefield['options'] ?? [] as $option) {
if ((int) $option['membership_type_id'] === $lineItem['membership_type_id']) {
$lineItem['price_field_id'] = $pricefield['id'];
$lineItem['price_field_value_id'] = $option['id'];
}
}
}
}
if (empty($lineItem['title'])) {
// Title is used in output for workflow templates.
$htmlType = !empty($this->priceFieldMetadata) ? $this->getPriceFieldSpec($lineItem['price_field_id'])['html_type'] : NULL;
$lineItem['title'] = (!$htmlType || $htmlType === 'Text') ? $lineItem['label'] : $this->getPriceFieldSpec($lineItem['price_field_id'])['label'] . ' : ' . $lineItem['label'];
if (!empty($lineItem['price_field_value_id'])) {
$description = $this->priceFieldValueMetadata[$lineItem['price_field_value_id']]['description'] ?? '';
if ($description) {
$lineItem['title'] .= ' ' . CRM_Utils_String::ellipsify($description, 30);
}
}
}
$this->lineItems[$index] = $lineItem;
}
......@@ -1013,6 +1064,7 @@ class CRM_Financial_BAO_Order {
foreach ($field['options'] as $option) {
if ((int) $option['membership_type_id'] === (int) $lineItem['membership_type_id']) {
$lineItem['price_field_id'] = $field['id'];
$lineItem['price_field_id.label'] = $field['label'];
$lineItem['price_field_value_id'] = $option['id'];
$lineItem['qty'] = 1;
}
......@@ -1105,6 +1157,7 @@ class CRM_Financial_BAO_Order {
'entity_id',
'entity_table',
'price_field_id',
'price_field_id.label',
'price_field_id.price_set_id',
'price_field_value_id',
'financial_type_id',
......@@ -1149,6 +1202,7 @@ class CRM_Financial_BAO_Order {
$defaults = [
'qty' => 1,
'price_field_id' => $this->getDefaultPriceFieldID(),
'price_field_id.label' => $this->defaultPriceField['label'],
'price_field_value_id' => $this->getDefaultPriceFieldValueID(),
'entity_table' => 'civicrm_contribution',
'unit_price' => $lineItem['line_total'],
......
......@@ -14,7 +14,7 @@ class Euro5990 extends \Civi\Test\EntityExample {
$base = [
'id' => 50,
'contact_id' => 100,
'financial_type_id' => 'Member dues',
'financial_type_id' => 2,
'payment_instrument_id:label' => 'Debit Card',
'contribution_page_id' => 2,
'receive_date' => '2021-07-23 15:39:20',
......@@ -26,7 +26,6 @@ class Euro5990 extends \Civi\Test\EntityExample {
'total_amount' => 5990.99,
'fee_amount' => 0.99,
'net_amount' => 5990,
'tax_amount' => 60,
'currency' => 'EUR',
'source' => 'Online donation',
'amount_level' => 'premium purchased',
......
This diff is collapsed.
......@@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/
use Civi\Api4\PriceField;
use Civi\Api4\PriceSet;
/**
......@@ -23,7 +24,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
protected $_individualId;
protected $_contribution;
protected $_financialTypeId = 1;
protected $financialTypeID = 1;
protected $_entity = 'Contribution';
protected $_params;
protected $_ids = [];
......@@ -87,7 +88,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => $this->_financialTypeId,
'financial_type_id' => $this->financialTypeID,
'non_deductible_amount' => 10.00,
'fee_amount' => 5.00,
'net_amount' => 95.00,
......@@ -637,12 +638,20 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
/**
* Ensure that price field are shown during pay later/pending Contribution
*
* @dataProvider getBooleanDataProvider
*
* @param bool $isTaxed
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function testEmailReceiptOnPayLater(): void {
$donationFT = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name');
public function testEmailReceiptOnPayLater(bool $isTaxed): void {
$financialTypeID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name');
if ($isTaxed) {
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($financialTypeID);
}
$priceSetID = PriceSet::create(FALSE)->setValues([
'title' => 'Price Set abcd',
'is_active' => TRUE,
......@@ -666,14 +675,15 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
'is_active' => ['1' => 1, '2' => 1],
'price_set_id' => $priceSetID,
'is_enter_qty' => 1,
'financial_type_id' => $donationFT,
'financial_type_id' => $financialTypeID,
];
$priceField = CRM_Price_BAO_PriceField::create($paramsField);
$priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]);
$priceFieldID = PriceField::create()->setValues($paramsField)->execute()->first()['id'];
$priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceFieldID]);
$params = [
'total_amount' => 100,
'financial_type_id' => $donationFT,
'financial_type_id' => $financialTypeID,
'contact_id' => $this->_individualId,
'is_email_receipt' => TRUE,
'from_email_address' => 'test@test.com',
......@@ -683,23 +693,61 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
foreach ($priceFieldValue['values'] as $id => $price) {
if ($price['amount'] == 100) {
$params['price_' . $priceField->id] = [$id => 1];
$params['price_' . $priceFieldID] = [$id => 1];
}
}
$form = $this->getContributionForm($params);
$mut = new CiviMailUtils($this, TRUE);
$mailUtil = new CiviMailUtils($this, TRUE);
$form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetID));
$form->postProcess();
if ($isTaxed) {
$mailUtil->checkMailLog([
'Dear Anthony,
Below you will find a receipt for this contribution.
===========================================================
Contribution Information
===========================================================
Contributor: Mr. Anthony Anderson II
Financial Type: Donation
---------------------------------------------------------
Item Qty Each Subtotal Tax Rate Tax Amount Total
----------------------------------------------------------
Price Field 1 1 $100.00 $100.00 10.00 % $10.00 $110.00
$mut->checkMailLog([
'Financial Type: Donation
Amount before Tax : $100.00
Sales Tax 10.00% : $10.00
Total Tax Amount : $10.00
Total Amount : $110.00
Date Received: ' . date('m/d/Y') . '
Receipt Date: ' . date('m/d/Y') . '
Paid By: Check',
]);
}
else {
$mailUtil->checkMailLog([
'Dear Anthony,
Below you will find a receipt for this contribution.
===========================================================
Contribution Information
===========================================================
Contributor: Mr. Anthony Anderson II
Financial Type: Donation
---------------------------------------------------------
Item Qty Each Total
----------------------------------------------------------
Price Field - Price Field 1 1 $100.00 $100.00
',
]);
$mut->stop();
Price Field 1 1 $100.00 $100.00
Total Amount : $100.00
Date Received: ' . date('m/d/Y') . '
Receipt Date: ' . date('m/d/Y') . '
Paid By: Check',
],
['Amount before Tax', 'Tax Amount']);
}
}
/**
......@@ -1036,18 +1084,29 @@ Price Field - Price Field 1 1 $100.00 $100.00
*
* @dataProvider getThousandSeparators
*/
public function testSubmitSaleTax($thousandSeparator) {
public function testSubmitSaleTax(string $thousandSeparator): void {
$mailUtil = new CiviMailUtils($this, TRUE);
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->_financialTypeId);
$this->addTaxAccountToFinancialType($this->financialTypeID);
$this->submitContributionForm([
'total_amount' => $this->formatMoneyInput(1000.00),
'financial_type_id' => $this->_financialTypeId,
'financial_type_id' => $this->financialTypeID,
'contact_id' => $this->_individualId,
'payment_instrument_id' => $this->getPaymentInstrumentID('Check'),
'contribution_status_id' => 1,
'price_set_id' => 0,
'is_email_receipt' => 1,
'from_email_address' => 'demo@example.com',
]);
$mailUtil->checkAllMailLog([
'Total Tax Amount : $' . $this->formatMoneyInput(100),
'Total Amount : $' . $this->formatMoneyInput(1100),
'Paid By: Check',
], []);
$mailUtil->clearMessages();
$contribution = $this->callAPISuccessGetSingle('Contribution',
[
'contact_id' => $this->_individualId,
......@@ -1069,8 +1128,15 @@ Price Field - Price Field 1 1 $100.00 $100.00
'contact_id' => $this->_individualId,
'payment_instrument_id' => $this->getPaymentInstrumentID('Check'),
'contribution_status_id' => 1,
'is_email_receipt' => 1,
'from_email_address' => 'demo@example.com',
], $contribution['id']);
$mailUtil->checkAllMailLog([
'Total Tax Amount : $' . $this->formatMoneyInput(100),
'Total Amount : $' . $this->formatMoneyInput(1100),
'Paid By: Check',
], []);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
// Check if total amount is unchanged
$this->assertEquals(1100, $contribution['total_amount']);
......@@ -1084,7 +1150,7 @@ Price Field - Price Field 1 1 $100.00 $100.00
*/
public function testSubmitWithOutSaleTax(): void {
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->_financialTypeId);
$this->addTaxAccountToFinancialType($this->financialTypeID);
$this->submitContributionForm([
'total_amount' => 100,
'financial_type_id' => 3,
......@@ -1122,7 +1188,7 @@ Price Field - Price Field 1 1 $100.00 $100.00
public function testReSubmitSaleTax(string $thousandSeparator): void {
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->_financialTypeId);
$this->addTaxAccountToFinancialType($this->financialTypeID);
$contribution = $this->doInitialSubmit();
$this->assertEquals(11000, $contribution['total_amount']);
$this->assertEquals(1000, $contribution['tax_amount']);
......@@ -1182,7 +1248,7 @@ Price Field - Price Field 1 1 $100.00 $100.00
public function testReSubmitSaleTaxAlteredAmount(string $thousandSeparator): void {
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->_financialTypeId);
$this->addTaxAccountToFinancialType($this->financialTypeID);
$contribution = $this->doInitialSubmit();
$mut = new CiviMailUtils($this, TRUE);
......@@ -1244,7 +1310,7 @@ Price Field - Price Field 1 1 $100.00 $100.00
protected function doInitialSubmit() {
$this->submitContributionForm([
'total_amount' => $this->formatMoneyInput(10000),
'financial_type_id' => $this->_financialTypeId,
'financial_type_id' => $this->financialTypeID,
'receive_date' => '2015-04-21 00:00:00',
'contact_id' => $this->_individualId,
'payment_instrument_id' => $this->getPaymentInstrumentID('Check'),
......@@ -1700,7 +1766,7 @@ Price Field - Price Field 1 1 $100.00 $100.00
public function testOpeningWidgetAdminPage(): void {
$page_id = $this->callAPISuccess('ContributionPage', 'create', [
'title' => 'my page',
'financial_type_id' => $this->_financialTypeId,
'financial_type_id' => $this->financialTypeID,
'payment_processor' => $this->paymentProcessorID,
])['id'];
$_REQUEST = ['reset' => 1, 'action' => 'update', 'id' => $page_id];
......
......@@ -20,6 +20,7 @@
namespace api\v4\Entity;
use api\v4\Api4TestBase;
use Civi\Api4\ExampleData;
use Civi\Api4\WorkflowMessage;
use Civi\Test\TransactionalInterface;
......@@ -28,16 +29,21 @@ use Civi\Test\TransactionalInterface;
*/
class WorkflowMessageTest extends Api4TestBase implements TransactionalInterface {
public function testGet() {
$result = \Civi\Api4\WorkflowMessage::get(0)
/**
* Basic get test.
*
* @throws \API_Exception
*/
public function testGet(): void {
$result = WorkflowMessage::get(FALSE)
->addWhere('name', 'LIKE', 'case%')
->execute()
->indexBy('name');
$this->assertTrue(isset($result['case_activity']));
}
public function testRenderDefaultTemplate() {
$ex = \Civi\Api4\ExampleData::get(0)
public function testRenderDefaultTemplate(): void {
$ex = ExampleData::get(FALSE)
->addWhere('name', '=', 'workflow/case_activity/CaseModelExample')
->addSelect('data')
->addChain('render', WorkflowMessage::render()
......@@ -50,12 +56,12 @@ class WorkflowMessageTest extends Api4TestBase implements TransactionalInterface
}
public function testRenderCustomTemplate() {
$ex = \Civi\Api4\ExampleData::get(0)
$ex = ExampleData::get(0)
->addWhere('name', '=', 'workflow/case_activity/CaseModelExample')
->addSelect('data')
->execute()
->single();
$result = \Civi\Api4\WorkflowMessage::render(0)
$result = WorkflowMessage::render(0)
->setWorkflow('case_activity')
->setValues($ex['data']['modelProps'])
->setMessageTemplate([
......@@ -99,21 +105,25 @@ class WorkflowMessageTest extends Api4TestBase implements TransactionalInterface
}
/**
* Test examples render.
*
* Only examples tagged phpunit will be checked.
*
* @param string $name
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
* @dataProvider getRenderExamples
*/
public function testRenderExamples(string $name) {
$example = \Civi\Api4\ExampleData::get(0)
public function testRenderExamples(string $name): void {
$example = ExampleData::get(FALSE)
->addWhere('name', '=', $name)
->addSelect('name', 'file', 'data', 'asserts')
->execute()
->single();
$this->assertTrue(!empty($example['data']['modelProps']), sprintf('Example (%s) is tagged phpunit. It should have modelProps.', $example['name']));
$this->assertTrue(!empty($example['asserts']['default']), sprintf('Example (%s) is tagged phpunit. It should have assertions.', $example['name']));
$result = \Civi\Api4\WorkflowMessage::render(0)
$this->assertNotEmpty($example['data']['modelProps'], sprintf('Example (%s) is tagged phpunit. It should have modelProps.', $example['name']));
$this->assertNotEmpty($example['asserts']['default'], sprintf('Example (%s) is tagged phpunit. It should have assertions.', $example['name']));
$result = WorkflowMessage::render(FALSE)
->setWorkflow($example['data']['workflow'])
->setValues($example['data']['modelProps'])
->execute()
......
......@@ -55,8 +55,7 @@
{/if}
</tr>
{if !empty($lineItem) and empty($is_quick_config)}
{foreach from=$lineItem item=value key=priceset}
{if $isShowLineItems}
<tr>
<td colspan="2" {$valueStyle}>
<table> {* FIXME: style this table so that it looks like the text version (justification, etc.) *}
......@@ -64,34 +63,34 @@
<th>{ts}Item{/ts}</th>
<th>{ts}Qty{/ts}</th>
<th>{ts}Each{/ts}</th>
{if !empty($getTaxDetails)}
{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
<th>{ts}Subtotal{/ts}</th>
<th>{ts}Tax Rate{/ts}</th>
<th>{ts}Tax Amount{/ts}</th>
{/if}
<th>{ts}Total{/ts}</th>
</tr>
{foreach from=$value item=line}
{foreach from=$lineItems item=line}
<tr>
<td>
{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description}<div>{$line.description|truncate:30:"..."}</div>{/if}
{$line.title}
</td>
<td>
{$line.qty}
</td>
<td>
{$line.unit_price|crmMoney:$currency}
{$line.unit_price|crmMoney:'{contribution.currency}'}
</td>
{if !empty($getTaxDetails)}
{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
<td>
{$line.unit_price*$line.qty|crmMoney:$currency}
{$line.unit_price*$line.qty|crmMoney:'{contribution.currency}'}
</td>
{if $line.tax_rate || $line.tax_amount != ""}
<td>
{$line.tax_rate|string_format:"%.2f"}%
</td>
<td>
{$line.tax_amount|crmMoney:$currency}
{$line.tax_amount|crmMoney:'{contribution.currency}'}
</td>
{else}
<td></td>
......@@ -99,34 +98,29 @@
{/if}
{/if}
<td>
{$line.line_total+$line.tax_amount|crmMoney:$currency}
{$line.line_total+$line.tax_amount|crmMoney:'{contribution.currency}'}
</td>
</tr>
{/foreach}
</table>
</td>
</tr>
{/foreach}
{/if}
{if !empty($getTaxDetails) && !empty($dataArray)}
{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
<tr>
<td {$labelStyle}>
{ts} Amount before Tax : {/ts}
</td>
<td {$valueStyle}>
{$formValues.total_amount-$totalTaxAmount|crmMoney:$currency}
{$formValues.total_amount-$totalTaxAmount|crmMoney:'{contribution.currency}'}
</td>
</tr>
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0 || $value != ''}
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{else}
<td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
{foreach from=$taxRateBreakdown item=taxDetail key=taxRate}
<tr>
<td>&nbsp;{if $taxRate == 0}{ts}No{/ts} {$taxTerm}{else}{$taxTerm} {$taxDetail.percentage}%{/if}</td>
<td>&nbsp;{$taxDetail.amount|crmMoney:'{contribution.currency}'}</td>
</tr>
{/foreach}
{/if}
......
......@@ -12,37 +12,31 @@
{if '{contribution.financial_type_id}'}
{ts}Financial Type{/ts}: {contribution.financial_type_id:label}
{/if}
{if $lineItem}
{foreach from=$lineItem item=value key=priceset}
{if $isShowLineItems}
---------------------------------------------------------
{capture assign=ts_item}{ts}Item{/ts}{/capture}
{capture assign=ts_qty}{ts}Qty{/ts}{/capture}
{capture assign=ts_each}{ts}Each{/ts}{/capture}
{if !empty($getTaxDetails)}
{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
{capture assign=ts_subtotal}{ts}Subtotal{/ts}{/capture}
{capture assign=ts_taxRate}{ts}Tax Rate{/ts}{/capture}
{capture assign=ts_taxAmount}{ts}Tax Amount{/ts}{/capture}
{/if}
{capture assign=ts_total}{ts}Total{/ts}{/capture}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {if !empty($getTaxDetails)} {$ts_subtotal|string_format:"%10s"} {$ts_taxRate} {$ts_taxAmount|string_format:"%10s"} {/if} {$ts_total|string_format:"%10s"}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'} {$ts_subtotal|string_format:"%10s"} {$ts_taxRate} {$ts_taxAmount|string_format:"%10s"} {/if} {$ts_total|string_format:"%10s"}
----------------------------------------------------------
{foreach from=$value item=line}
{capture assign=ts_item}{if $line.html_type eq 'Text'}{$line.label}{else}{$line.field_title} - {$line.label}{/if} {if $line.description} {$line.description}{/if}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney:$currency|string_format:"%10s"} {if !empty($getTaxDetails)}{$line.unit_price*$line.qty|crmMoney:$currency|string_format:"%10s"} {if $line.tax_rate || $line.tax_amount != ""} {$line.tax_rate|string_format:"%.2f"} % {$line.tax_amount|crmMoney:$currency|string_format:"%10s"} {else} {/if} {/if} {$line.line_total+$line.tax_amount|crmMoney:$currency|string_format:"%10s"}
{/foreach}
{foreach from=$lineItems item=line}
{capture assign=ts_item}{$line.title}{/capture}{$ts_item|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney:'{contribution.currency}'|string_format:"%10s"} {if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}{$line.unit_price*$line.qty|crmMoney:'{contribution.currency}'|string_format:"%10s"} {if $line.tax_rate || $line.tax_amount != ""} {$line.tax_rate|string_format:"%.2f"} % {$line.tax_amount|crmMoney:'{contribution.currency}'|string_format:"%10s"} {else} {/if} {/if} {$line.line_total+$line.tax_amount|crmMoney:'{contribution.currency}'|string_format:"%10s"}
{/foreach}
{/if}
{if !empty($getTaxDetails) && !empty($dataArray)}
{ts}Amount before Tax{/ts} : {$formValues.total_amount-$totalTaxAmount|crmMoney:$currency}
{foreach from=$dataArray item=value key=priceset}
{if $priceset || $priceset == 0 || $value != ''}
{$taxTerm} {$priceset|string_format:"%.2f"}% : {$value|crmMoney:$currency}
{else}
{ts}No{/ts} {$taxTerm} : {$value|crmMoney:$currency}
{if $isShowTax && '{contribution.tax_amount|raw}' !== '0.00'}
{ts}Amount before Tax{/ts} : {$formValues.total_amount-$totalTaxAmount|crmMoney:$currency}
{/if}
{foreach from=$taxRateBreakdown item=taxDetail key=taxRate}
{if $taxRate == 0}{ts}No{/ts} {$taxTerm}{else}{$taxTerm} {$taxDetail.percentage}%{/if} : {$taxDetail.amount|crmMoney:'{contribution.currency}'}
{/foreach}
{/if}
{if $isShowTax}
{ts}Total Tax Amount{/ts} : {contribution.tax_amount}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment