INFRA-132 - Put space after flow-control (if/switch/for/foreach/while)
[civicrm-core.git] / CRM / Event / Form / EventFees.php
index af23d5fb53df9c44846a2ad44855a657a0d4e6e3..c5fe459e518976d74f7b844ecda4f22a24206a80 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
  *
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
 class CRM_Event_Form_EventFees {
 
   /**
-   * Function to set variables up before form is built
+   * Set variables up before form is built
+   *
+   * @param CRM_Core_Form $form
    *
    * @return void
-   * @access public
    */
-  static function preProcess(&$form) {
+  public static function preProcess(&$form) {
     //as when call come from register.php
     if (!$form->_eventId) {
       $form->_eventId = CRM_Utils_Request::retrieve('eventId', 'Positive', $form);
@@ -69,11 +70,12 @@ class CRM_Event_Form_EventFees {
    * This function sets the default values for the form in edit/view mode
    * the default values are retrieved from the database
    *
-   * @access public
+   *
+   * @param CRM_Core_Form $form
    *
    * @return void
    */
-  static function setDefaultValues(&$form) {
+  public static function setDefaultValues(&$form) {
     $defaults = array();
 
     if ($form->_eventId) {
@@ -124,7 +126,7 @@ class CRM_Event_Form_EventFees {
     if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) {
       $defaults[$form->_pId]['record_contribution'] = 1;
     }
-    
+
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
       $defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
@@ -143,9 +145,6 @@ class CRM_Event_Form_EventFees {
       $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
       $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
 
-      // now fix all state country selectors, set correct state based on country
-      CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults[$form->_pId]);
-
       //             // hack to simplify credit card entry for testing
       //             $defaults[$form->_pId]['credit_card_type']     = 'Visa';
       //             $defaults[$form->_pId]['credit_card_number']   = '4807731747657838';
@@ -153,7 +152,6 @@ class CRM_Event_Form_EventFees {
       //             $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
 
-
     // if user has selected discount use that to set default
     if (isset($form->_discountId)) {
       $defaults[$form->_pId]['discount_id'] = $form->_discountId;
@@ -180,10 +178,9 @@ class CRM_Event_Form_EventFees {
 
     if (($form->_action == CRM_Core_Action::ADD) && $form->_eventId && $discountId) {
       // this case is for add mode, where we show discount automatically
-        $defaults[$form->_pId]['discount_id'] = $discountId;
+      $defaults[$form->_pId]['discount_id'] = $discountId;
     }
 
-
     if ($priceSetId) {
       // get price set default values, CRM-4090
       if (in_array(get_class($form),
@@ -236,8 +233,8 @@ class CRM_Event_Form_EventFees {
     if ($contriId = $form->get('onlinePendingContributionId')) {
       $contribution = new CRM_Contribute_DAO_Contribution();
       $contribution->id = $contriId;
-      $contribution->find( true );
-      foreach( array('financial_type_id', 'payment_instrument_id','contribution_status_id', 'receive_date', 'total_amount' ) as $f ) {
+      $contribution->find( TRUE );
+      foreach (array('financial_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount' ) as $f ) {
         if ($f == 'receive_date') {
           list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->$f);
         }
@@ -252,11 +249,14 @@ class CRM_Event_Form_EventFees {
   /**
    * This function sets the default values for price set.
    *
-   * @access public
+   *
+   * @param int $participantID
+   * @param int $eventID
+   * @param bool $includeQtyZero
    *
    * @return void
    */
-  static function setDefaultPriceSet($participantID, $eventID = NULL, $includeQtyZero = TRUE) {
+  public static function setDefaultPriceSet($participantID, $eventID = NULL, $includeQtyZero = TRUE) {
     $defaults = array();
     if (!$eventID && $participantID) {
       $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'event_id');
@@ -334,12 +334,13 @@ SELECT  id, html_type
   }
 
   /**
-   * Function to build the form
+   * Build the form object
+   *
+   * @param CRM_Core_Form $form
    *
    * @return void
-   * @access public
    */
-  static function buildQuickForm(&$form) {
+  public static function buildQuickForm(&$form) {
     if ($form->_eventId) {
       $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
       if ($form->_isPaidEvent) {
@@ -370,8 +371,17 @@ SELECT  id, html_type
       CRM_Event_Form_Registration::initEventFee($form, $event['id']);
       CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
       $lineItem = array();
+      $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
+      $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
+      $totalTaxAmount = 0;
       if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
         $lineItem[] = $form->_values['line_items'];
+        foreach ($form->_values['line_items'] as $key => $value) {
+          $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
+        }
+      }
+      if ($invoicing) {
+        $form->assign('totalTaxAmount', $totalTaxAmount);
       }
       $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
       $discounts = array();
@@ -394,7 +404,7 @@ SELECT  id, html_type
         }
       }
       if ($form->_mode) {
-        CRM_Core_Payment_Form::buildCreditCard($form, TRUE);
+        CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE);
       }
       elseif (!$form->_mode) {
         $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL,
@@ -424,30 +434,30 @@ SELECT  id, html_type
           $form->assign('showTransactionId', TRUE);
         }
 
-        $allowStatuses = array();
-        $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
-        if ($form->get('onlinePendingContributionId')) {
-          $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
-          foreach ($statusNames as $val => $name) {
-            if (in_array($name, array(
-              'In Progress', 'Overdue'))) {
-              continue;
-            }
-            $allowStatuses[$val] = $statuses[$val];
-          }
-        }
-        else {
-          $allowStatuses = $statuses;
+        $status = CRM_Contribute_PseudoConstant::contributionStatus();
+
+        // CRM-14417 suppressing contribution statuses that are NOT relevant to new participant registrations
+        $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
+        foreach (array(
+                   'Cancelled',
+                   'Failed',
+                   'In Progress',
+                   'Overdue',
+                   'Refunded',
+                   'Pending refund',
+                 ) as $suppress) {
+          unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
+
         $form->add('select', 'contribution_status_id',
-          ts('Payment Status'), $allowStatuses
+          ts('Payment Status'), $status
         );
 
         $form->add('text', 'check_number', ts('Check Number'),
           CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')
         );
 
-        $form->add('text', 'total_amount', ts('Total Amount'),
+        $form->add('text', 'total_amount', ts('Amount'),
           CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount')
         );
       }
@@ -490,4 +500,3 @@ SELECT  id, html_type
     $form->assign('hasPayment', $form->_paymentId);
   }
 }
-