[ready-for-core-team-review]CRM-16189, added code to add recognition date on contribu...
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 5 Jul 2016 21:48:33 +0000 (03:18 +0530)
committercolemanw <coleman@civicrm.org>
Tue, 5 Jul 2016 21:48:33 +0000 (17:48 -0400)
* CRM-16189, added code to add recognition date on contribution form

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

* CRM-16189, added webtest

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

* --CRM-16189, changed the field from date picker to drop down and added validation rule

* --CRM-16189, updated function class

* CRM-16189, added Revenue recognition date on COntribution View form

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/ContributionView.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/ContributionView.tpl
tests/phpunit/WebTest/Contribute/OfflineContributionTest.php

index 933eca034dbdba55120882179762d6235fa65355..a6c6c0b4515ab462a9a98bc7926cb56f68b8b673 100644 (file)
@@ -454,7 +454,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
    * @return CRM_Contribute_BAO_Contribution
    */
   public static function create(&$params, $ids = array()) {
-    $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date');
+    $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date', 'revenue_recognition_date');
     foreach ($dateFields as $df) {
       if (isset($params[$df])) {
         $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]);
index dcac3e41455a4c4cf109db12f76de95651b13335..318b7f2290763bdeb1f7a22140a4eff0aab782c2 100644 (file)
@@ -749,6 +749,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       FALSE
     );
 
+    // CRM-16189, add Revenue Recognition Date
+    if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
+      $this->add('date', 'revenue_recognition_date', ts('Revenue Recognition Date'), CRM_Core_SelectValues::date(NULL, 'M Y', NULL, 5));
+    }
+
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
 
@@ -998,7 +1003,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
         $errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
       }
     }
-
+    if (!empty($fields['revenue_recognition_date'])
+      && count(array_filter($fields['revenue_recognition_date'])) == 1
+    ) {
+      $errors['revenue_recognition_date'] = ts('Month and Year are required field for Revenue Recognition.');
+    }
     $errors = array_merge($errors, $softErrors);
     return $errors;
   }
@@ -1631,7 +1640,14 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       if ($priceSetId) {
         $params['skipCleanMoney'] = 1;
       }
-
+      $params['revenue_recognition_date'] = NULL;
+      if (!empty($formValues['revenue_recognition_date'])
+        && count(array_filter($formValues['revenue_recognition_date'])) == 2
+      ) {
+        $params['revenue_recognition_date'] = CRM_Utils_Date::processDate(
+          '01-' . implode('-', $formValues['revenue_recognition_date'])
+        );
+      }
       $dates = array(
         'receive_date',
         'receipt_date',
@@ -1639,7 +1655,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       );
 
       foreach ($dates as $d) {
-        $params[$d] = CRM_Utils_Date::processDate($formValues[$d], $formValues[$d . '_time'], TRUE);
+        if (isset($formValues[$d])) {
+          $params[$d] = CRM_Utils_Date::processDate($formValues[$d], CRM_Utils_Array::value($d . '_time', $formValues), TRUE);
+        }
       }
 
       if (!empty($formValues['is_email_receipt'])) {
index 860ad317a4972f94b7756980d9d67966e89abbb1..9a5a63b0e54b18ad8d9fafb6a48f6c2f37312847 100644 (file)
@@ -175,6 +175,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
+    $this->assign('isDeferred', CRM_Utils_Array::value('deferred_revenue_enabled', $invoiceSettings));
     if ($invoicing && isset($values['tax_amount'])) {
       $this->assign('totalTaxAmount', $values['tax_amount']);
     }
index d9dc0c0f267ce7df1d109e1e1db1f51750a4e387..7a7ac144574ca99e284593596bfd75fd233017a9 100644 (file)
         </td>
       </tr>
     {/if}
-
+    {if $form.revenue_recognition_date}
+      <tr class="crm-contribution-form-block-revenue_recognition_date">
+        <td class="label">{$form.revenue_recognition_date.label}</td>
+        <td>{$form.revenue_recognition_date.html}</td>
+      </tr>
+    {/if}
   </table>
 
   {include file='CRM/Core/BillingBlockWrapper.tpl'}
index 6c2b6d5fbd89c7f747e0d5bd7e3b71b7ab42ac5b..52cc51e32f6a0f583b7be46642a6444c7afe40bb 100644 (file)
       <td>{$net_amount|crmMoney:$currency}</td>
     </tr>
   {/if}
-
+  {if $isDeferred AND $revenue_recognition_date}
+    <tr>
+      <td class="label">{ts}Revenue Recognition Date{/ts}</td>
+      <td>{$revenue_recognition_date|crmDate:"%B, %Y"}</td>
+    </tr>
+  {/if}
   <tr>
     <td class="label">{ts}Received{/ts}</td>
     <td>{if $receive_date}{$receive_date|crmDate}{else}({ts}not available{/ts}){/if}</td>
index 1c7b2fc447ee463bfbcf9bbcfb8f44511efefb63..81e3400ccd2d0fcc6f47c2ecd2935ce92988ea13 100644 (file)
@@ -96,6 +96,10 @@ class WebTest_Contribute_OfflineContributionTest extends CiviSeleniumTestCase {
 
     // total amount
     $this->type("total_amount", "100");
+    // revenue recognition date (CRM-16189)
+    if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
+      $this->webtestFillDate('revenue_recognition_date', 'now+4');
+    }
 
     // select payment instrument type = Check and enter chk number
     $this->select("payment_instrument_id", "value=4");
@@ -463,4 +467,105 @@ class WebTest_Contribute_OfflineContributionTest extends CiviSeleniumTestCase {
     $this->assertElementContainsText("xpath=//table[@id='info']/tbody/tr[2]/td[1]", "£ 100.00");
   }
 
+  public function testRevenueRecognitionDateAdd() {
+    $this->webtestLogin();
+    $this->openCiviPage("admin/setting/preferences/contribute", "reset=1");
+    $this->waitForElementPresent("_qf_Contribute_next");
+    $this->click('deferred_revenue_enabled');
+    $this->click('_qf_Contribute_next');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+
+    // Create a contact to be used as soft creditor
+    $softCreditFname = substr(sha1(rand()), 0, 7);
+    $softCreditLname = substr(sha1(rand()), 0, 7);
+    $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
+
+    //financial account for check
+    $this->openCiviPage("admin/options/payment_instrument", "reset=1");
+    $financialAccount = $this->getText("xpath=//div[@id='payment_instrument']/table/tbody//tr/td[1]/div[text()='Check']/../../td[3]");
+
+    // Add new Financial Account
+    $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
+    $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
+    $financialAccountDescription = "{$financialAccountTitle} Description";
+    $accountingCode = 1033;
+    $financialAccountType = 'Asset';
+    $taxDeductible = FALSE;
+    $isActive = FALSE;
+    $isTax = TRUE;
+    $taxRate = 9;
+    $isDefault = FALSE;
+
+    //Add new organisation
+    if ($orgName) {
+      $this->webtestAddOrganization($orgName);
+    }
+
+    $this->_testAddFinancialAccount($financialAccountTitle,
+      $financialAccountDescription,
+      $accountingCode,
+      $orgName,
+      $financialAccountType,
+      $taxDeductible,
+      $isActive,
+      $isTax,
+      $taxRate,
+      $isDefault
+    );
+
+    $firstName = 'John' . substr(sha1(rand()), 0, 7);
+    $lastName = 'Dsouza' . substr(sha1(rand()), 0, 7);
+    $this->webtestAddContact($firstName, $lastName);
+
+    $this->waitForElementPresent("css=li#tab_contribute a");
+    $this->click("css=li#tab_contribute a");
+    $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)");
+    $this->clickLink("link=Record Contribution (Check, Cash, EFT ...)", "_qf_Contribution_cancel-bottom", FALSE);
+
+    // select financial type
+    $this->select("financial_type_id", "value=1");
+
+    // fill in Received Date
+    $this->webtestFillDate('receive_date');
+
+    // source
+    $this->type("source", "Mailer 1");
+
+    // total amount
+    $this->type("total_amount", "100");
+
+    // revenue recognition date (CRM-16189)
+    $this->webtestFillDate('revenue_recognition_date', 'now');
+
+    // select payment instrument type = Check and enter chk number
+    $this->select("payment_instrument_id", "value=4");
+    $this->waitForElementPresent("check_number");
+    $this->type("check_number", "check #1041");
+
+    $this->type("trxn_id", "P20901X1" . rand(100, 10000));
+
+    //Additional Detail section
+    $this->click("AdditionalDetail");
+    $this->waitForElementPresent("thankyou_date");
+
+    $this->type("note", "This is a test note.");
+    $this->type("non_deductible_amount", "10.00");
+    $this->type("fee_amount", "0");
+    $this->type("net_amount", "0");
+    $this->type("invoice_id", time());
+    $this->webtestFillDate('thankyou_date');
+
+    // Clicking save.
+    $this->click("_qf_Contribution_upload");
+
+    // verify if Contribution is created
+    $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='Edit']");
+
+    //click through to the Contribution edit screen
+    $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='Edit']");
+    $this->waitForElementPresent("_qf_Contribution_cancel");
+    $val = $this->getValue("xpath=//input[@id='revenue_recognition_date']");
+    $this->assertEquals(date('m/d/Y'), $val);
+  }
+
 }