CRM-13973 : worked on fee selection change UI and meta data changes
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 16 Jan 2014 12:41:29 +0000 (18:11 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 16 Jan 2014 12:41:29 +0000 (18:11 +0530)
CRM/Event/Form/ParticipantFeeSelection.php
CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl
templates/CRM/Event/Form/ParticipantFeeSelection.tpl
xml/templates/civicrm_data.tpl

index b87e850ef9ed5a183626e0a64af549e65c7afe40..467bcdd3d47981edb8c08374c72d9cdacf9b7f4b 100644 (file)
  */
 
 /**
- * This form records additional payments needed when
+ * This form used for changing / updating fee selections for the events
  * event/contribution is partially paid
  *
  */
 class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
-  /**
-   * related component whose financial payment is being processed
-   *
-   * @var string
-   * @public
-   */
-  protected $_component = NULL;
 
   protected $_contactId = NULL;
 
@@ -65,15 +58,14 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
 
   public $_values = NULL;
 
-  public $_isPaidEvent = NULL;
-
   public $_participantId = NULL;
 
   public function preProcess() {
     $this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
-    $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     $this->_eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'event_id');
+    $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId);
+
     $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id');
     if ($this->_contributionId) {
       $this->_isPaidEvent = TRUE;
@@ -82,6 +74,8 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
 
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
     $this->assign('displayName', $this->_contributorDisplayName);
+    $this->assign('email', $this->_contributorEmail);
+
     //set the payment mode - _mode property is defined in parent class
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
 
@@ -121,6 +115,14 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
   }
 
   public function buildQuickForm() {
+    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
+
+    $statuses = CRM_Event_PseudoConstant::participantStatus();
+    CRM_Core_Resources::singleton()->addSetting(array(
+        'partiallyPaid' => array_search('Partially paid', $statuses),
+        'pendingRefund' => array_search('Pending refund', $statuses),
+      ));
+
     $config = CRM_Core_Config::singleton();
     $this->assign('currencySymbol',  $config->defaultCurrencySymbol);
 
@@ -148,12 +150,31 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
       TRUE
     );
 
+    $this->addElement('checkbox',
+      'send_receipt',
+      ts('Send Confirmation?'), NULL,
+      array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);")
+    );
+
+    $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
+
+    $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
+
+    $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
+    $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
+
     $buttons[] = array(
       'type' => 'upload',
       'name' => ts('Save'),
       'isDefault' => TRUE,
     );
 
+    $buttons[] = array(
+      'type' => 'upload',
+      'name' => ts('Save and Record Payment'),
+      'subName' => 'new'
+    );
+
     $buttons[] = array(
       'type' => 'cancel',
       'name' => ts('Cancel'),
@@ -170,7 +191,14 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
 
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
-  }
+    $session = CRM_Core_Session::singleton();
+    $buttonName = $this->controller->getButtonName();
+    if ($buttonName == $this->getButtonName('upload', 'new')) {
+      $session->replaceUserContext(CRM_Utils_System::url('civicrm/payment/add',
+          "reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}"
+        ));
+    }
+ }
 
   static function emailReceipt(&$form, &$params) {
     // email receipt sending
index 64b3c36c821e27c8c1879cf2dee8ea3e88fb37b9..dd73c9825c9964e8ee1c08d052d23ef88ecdca5a 100644 (file)
@@ -129,4 +129,5 @@ INSERT INTO
    `civicrm_option_value` (`option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, {localize field='description'}`description`{/localize}, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`)
 VALUES
    (@option_group_id_act, {localize}'{ts escape="sql"}Payment{/ts}'{/localize}, @option_group_id_act_val+1, 'Payment', NULL, 1, NULL, @option_group_id_act_wt+1, {localize}'{ts escape="sql"}Additional payment recorded for event or membership fee.{/ts}'{/localize}, 0, 1, 1, @contributeCompId, NULL),
-   (@option_group_id_act, {localize}'{ts escape="sql"}Refund{/ts}'{/localize}, @option_group_id_act_val+2, 'Refund', NULL, 1, NULL, @option_group_id_act_wt+2, {localize}'{ts escape="sql"}Refund recorded for event or membership fee.{/ts}'{/localize}, 0, 1, 1, @contributeCompId, NULL);
\ No newline at end of file
+   (@option_group_id_act, {localize}'{ts escape="sql"}Refund{/ts}'{/localize}, @option_group_id_act_val+2, 'Refund', NULL, 1, NULL, @option_group_id_act_wt+2, {localize}'{ts escape="sql"}Refund recorded for event or membership fee.{/ts}'{/localize}, 0, 1, 1, @contributeCompId, NULL),
+   (@option_group_id_act, {localize}'{ts escape="sql"}Change Registration{/ts}'{/localize}, @option_group_id_act_val+3, 'Change Registration', NULL, 1, NULL, @option_group_id_act_wt+3, {localize}'{ts escape="sql"}Changes to an existing event registration.{/ts}'{/localize}, 0, 1, 1, @eventCompId, NULL);
\ No newline at end of file
index 731047a6259a51d2e6ef440634e4022b7e8fdc38..8e13facf3d9e4bc7693f1fbf6b53ea879fa8d7ae 100644 (file)
@@ -57,6 +57,11 @@ function populatebalanceFee() {
 
 <div class="crm-block crm-form-block crm-payment-form-block">
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+  {if !$email}
+  <div class="messages status no-popup">
+    <div class="icon inform-icon"></div>&nbsp;{ts}You will not be able to send an automatic email receipt for this payment because there is no email address recorded for this contact. If you want a receipt to be sent when this payment is recorded, click Cancel and then click Edit from the Summary tab to add an email address before recording the payment.{/ts}
+  </div>
+  {/if}
   <table class="form-layout">    
     <tr>
       <td class="font-size12pt label"><strong>{ts}Participant{/ts}</strong></td><td class="font-size12pt"><strong>{$displayName}</strong></td>
@@ -90,19 +95,88 @@ function populatebalanceFee() {
          <div class='label'>{ts}Total Paid{/ts}</div>
          <div class='content'><a class='action-item' href='{crmURL p="civicrm/payment/view" q="action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'>{$paymentInfo.paid|crmMoney}<br/>>> view payments</a>
          </div>
-         <div class='label'><strong>{ts}Balance Owed{/ts}</strong></div><div id='balance-fee' class='content'></div>
+         <div class='label'><strong>{ts}Balance Owed{/ts}</strong></div><div class='content'><strong id='balance-fee'></strong></div>
           </div>
        {include file='CRM/Price/Form/Calculate.tpl' currencySymbol=$currencySymbol noCalcValueDisplay='false' displayOveride='true'}
        {/if}    
       </table>
     </fieldset>
   {/if}
+{if $email}
+    <fieldset id="email-receipt"><legend>{ts}Participant Confirmation{/ts}</legend>
+      <table class="form-layout" style="width:auto;">
+       <tr class="crm-event-eventfees-form-block-send_receipt">
+          <td class="label">{ts}Send Confirmation{/ts}</td>
+          <td>{$form.send_receipt.html}<br>
+             <span class="description">{ts 1=$email'}Automatically email a confirmation to %1?{/ts}</span>
+          </td>
+       </tr>
+       <tr id="from-email" class="crm-event-eventfees-form-block-from_email_address">
+         <td class="label">{$form.from_email_address.label}</td>
+         <td>{$form.from_email_address.html} {help id ="id-from_email" file="CRM/Contact/Form/Task/Email.hlp"}</td>
+       </tr>
+       <tr id='notice' class="crm-event-eventfees-form-block-receipt_text">
+         <td class="label">{$form.receipt_text.label}</td>
+         <td><span class="description">
+             {ts}Enter a message you want included at the beginning of the confirmation email. EXAMPLE: 'We have made the changes you requested to your registration.'{/ts}
+             </span><br />
+             {$form.receipt_text.html|crmAddClass:huge}
+         </td>
+       </tr>
+      </table>
+    </fieldset>
+{/if}
+    <fieldset>
+      <table class="form-layout">
+        <tr class="crm-participant-form-block-note">
+          <td class="label">{$form.note.label}</td><td>{$form.note.html}</td>
+        </tr>
+      </table>
+    </fieldset>
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
+{if $email}
+{include file="CRM/common/showHideByFieldValue.tpl"
+    trigger_field_id    ="send_receipt"
+    trigger_value       =""
+    target_element_id   ="notice"
+    target_element_type ="table-row"
+    field_type          ="radio"
+    invert              = 0
+}
+{include file="CRM/common/showHideByFieldValue.tpl"
+    trigger_field_id    ="send_receipt"
+    trigger_value       =""
+    target_element_id   ="from-email"
+    target_element_type ="table-row"
+    field_type          ="radio"
+    invert              = 0
+}
+{/if}
 {literal}
 <script type='text/javascript'>
 cj(function($){
-  cj('.total_amount-section').remove();
+  cj('.total_amount-section').remove(); 
+
+cj('#ParticipantFeeSelection').submit(function(e) {
+  var statusId = cj('#status_id').val();
+  var statusLabel = cj('#status_id option:selected').text(); 
+  var balanceFee = cj('#balance-fee').text();
+  balanceFee = parseFloat(balanceFee.replace(/[^0-9-.]/g, ''));
+  
+  if (balanceFee > 0 && statusId != CRM.partiallyPaid) {
+    var result = confirm('Balance is owing for the updated selections. Expected participant status is \'Partially paid\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries.');
+    if (result == false) {
+      e.preventDefault();
+    }
+  }
+  else if (balanceFee < 0 && statusId != CRM.pendingRefund) {
+    var result = confirm('Balance is overpaid for the updated selections. Expected participant status is \'Pending refund\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries');
+    if (result == false) {
+      e.preventDefault();
+    }
+  }
+});
 });
 </script>
 {/literal}
\ No newline at end of file
index 1074a31358c48c5e53c3382742a30390cf52c927..32d724edb14a20c4d167520012876883dd2d944f 100644 (file)
@@ -368,6 +368,9 @@ VALUES
    (@option_group_id_act, '{ts escape="sql"}Payment{/ts}', 46, 'Payment', NULL, 1, NULL, 46, '{ts escape="sql"}Additional payment recorded for event or membership fee.{/ts}', 0, 1, 1, @contributeCompId, NULL),
    (@option_group_id_act, '{ts escape="sql"}Refund{/ts}', 47, 'Refund', NULL, 1, NULL, 47, '{ts escape="sql"}Refund recorded for event or membership fee.{/ts}', 0, 1, 1, @contributeCompId, NULL),
 
+ -- for selection changes
+   (@option_group_id_act, '{ts escape="sql"}Change Registration{/ts}', 48, 'Change Registration', NULL, 1, NULL, 48, '{ts escape="sql"}Changes to an existing event registration.{/ts}', 0, 1, 1, @eventCompId, NULL),
+
    (@option_group_id_gender, '{ts escape="sql"}Female{/ts}',      1, 'Female',      NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL),
    (@option_group_id_gender, '{ts escape="sql"}Male{/ts}',        2, 'Male',        NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL),
    (@option_group_id_gender, '{ts escape="sql"}Transgender{/ts}', 3, 'Transgender', NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL),