Esempio n. 1
0
 /**
  * Set default values.
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = $this->_values;
     // Set defaults for pledge payment.
     if ($this->_ppID) {
         $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
         $defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues);
         $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues);
         $defaults['option_type'] = 1;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     $defaults['frequency_interval'] = 1;
     $defaults['frequency_unit'] = 'month';
     // Set soft credit defaults.
     CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
     if ($this->_mode) {
         $config = CRM_Core_Config::singleton();
         // Set default country from config if no country set.
         if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
     }
     if ($this->_id) {
         $this->_contactID = $defaults['contact_id'];
     }
     // Set $newCredit variable in template to control whether link to credit card mode is included.
     $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
     // Fix the display of the monetary value, CRM-4038.
     if (isset($defaults['total_amount'])) {
         if (!empty($defaults['tax_amount'])) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
                 $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'] - $defaults['tax_amount'], NULL, '%a');
             }
         } else {
             $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
         }
     }
     if (isset($defaults['non_deductible_amount'])) {
         $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a');
     }
     if (isset($defaults['fee_amount'])) {
         $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a');
     }
     if (isset($defaults['net_amount'])) {
         $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
     }
     if ($this->_contributionType) {
         $defaults['financial_type_id'] = $this->_contributionType;
     }
     if (empty($defaults['payment_instrument_id'])) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if (!empty($defaults['is_test'])) {
         $this->assign('is_test', TRUE);
     }
     $this->assign('showOption', TRUE);
     // For Premium section.
     if ($this->_premiumID) {
         $this->assign('showOption', FALSE);
         $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
         if (!$options) {
             $this->assign('showOption', TRUE);
         }
         $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
         if ($options_key) {
             $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
         } else {
             $defaults['product_name'] = array($this->_productDAO->product_id);
         }
         if ($this->_productDAO->fulfilled_date) {
             list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
         }
     }
     if (isset($this->userEmail)) {
         $this->assign('email', $this->userEmail);
     }
     if (!empty($defaults['is_pay_later'])) {
         $this->assign('is_pay_later', TRUE);
     }
     $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
     $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
     foreach ($dates as $key) {
         if (!empty($defaults[$key])) {
             list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime');
         }
     }
     if (!$this->_id && empty($defaults['receive_date'])) {
         list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
     }
     $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults)));
     $currency = CRM_Utils_Array::value('currency', $defaults);
     $this->assign('currency', $currency);
     // Hack to get currency info to the js layer. CRM-11440.
     CRM_Utils_Money::format(1);
     $this->assign('currencySymbol', CRM_Utils_Array::value($currency, CRM_Utils_Money::$_currencySymbols));
     $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults));
     // Inherit campaign from pledge.
     if ($this->_ppID && !empty($this->_pledgeValues['campaign_id'])) {
         $defaults['campaign_id'] = $this->_pledgeValues['campaign_id'];
     }
     $this->_defaults = $defaults;
     return $defaults;
 }
Esempio n. 2
0
 function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = $this->_values;
     //set defaults for pledge payment.
     if ($this->_ppID) {
         $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
         $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues);
         $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues);
         $defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues);
         $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues);
         $defaults['option_type'] = 1;
     }
     $fields = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     // set soft credit defaults
     CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
     if ($this->_mode) {
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
         // now fix all state country selectors, set correct state based on country
         CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     }
     if ($this->_id) {
         $this->_contactID = $defaults['contact_id'];
     }
     // Set $newCredit variable in template to control whether link to credit card mode is included
     CRM_Core_Payment::allowBackofficeCreditCard($this);
     // fix the display of the monetary value, CRM-4038
     if (isset($defaults['total_amount'])) {
         $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
     }
     if (isset($defaults['non_deductible_amount'])) {
         $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a');
     }
     if (isset($defaults['fee_amount'])) {
         $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a');
     }
     if (isset($defaults['net_amount'])) {
         $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
     }
     if ($this->_contributionType) {
         $defaults['financial_type_id'] = $this->_contributionType;
     }
     if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if (CRM_Utils_Array::value('is_test', $defaults)) {
         $this->assign('is_test', TRUE);
     }
     if (isset($defaults['honor_contact_id'])) {
         $honorDefault = $ids = array();
         $this->_honorID = $defaults['honor_contact_id'];
         $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
         $idParams = array('id' => $defaults['honor_contact_id'], 'contact_id' => $defaults['honor_contact_id']);
         CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids);
         $defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault);
         $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault);
         $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault);
         $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]);
         $defaults['honor_type'] = $honorType[$defaults['honor_type_id']];
     }
     $this->assign('showOption', TRUE);
     // for Premium section
     if ($this->_premiumID) {
         $this->assign('showOption', FALSE);
         $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
         if (!$options) {
             $this->assign('showOption', TRUE);
         }
         $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
         if ($options_key) {
             $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
         } else {
             $defaults['product_name'] = array($this->_productDAO->product_id);
         }
         if ($this->_productDAO->fulfilled_date) {
             list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
         }
     }
     if (isset($this->userEmail)) {
         $this->assign('email', $this->userEmail);
     }
     if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
         $this->assign('is_pay_later', TRUE);
     }
     $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
     $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
     foreach ($dates as $key) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime');
         }
     }
     if (!$this->_id && !CRM_Utils_Array::value('receive_date', $defaults)) {
         list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
     }
     $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults)));
     $currency = CRM_Utils_Array::value('currency', $defaults);
     $this->assign('currency', $currency);
     // Hack to get currency info to the js layer. CRM-11440
     CRM_Utils_Money::format(1);
     $this->assign('currencySymbol', CRM_Utils_Array::value($currency, CRM_Utils_Money::$_currencySymbols));
     $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults));
     //inherit campaign from pledge.
     if ($this->_ppID && CRM_Utils_Array::value('campaign_id', $this->_pledgeValues)) {
         $defaults['campaign_id'] = $this->_pledgeValues['campaign_id'];
     }
     $this->_defaults = $defaults;
     return $defaults;
 }