Example #1
0
    /**
     * Build the form object.
     *
     * @return void
     */
    public function buildQuickForm()
    {
        if ($this->_cdType) {
            return CRM_Custom_Form_CustomData::buildQuickForm($this);
        }
        $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
        $config = CRM_Core_Config::singleton();
        $this->assign('currency', $config->defaultCurrencySymbol);
        $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
        $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
        if (isset($invoicing)) {
            $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
        }
        // build price set form.
        $buildPriceSet = FALSE;
        if ($this->_priceSetId || !empty($_POST['price_set_id'])) {
            if (!empty($_POST['price_set_id'])) {
                $buildPriceSet = TRUE;
            }
            $getOnlyPriceSetElements = TRUE;
            if (!$this->_priceSetId) {
                $this->_priceSetId = $_POST['price_set_id'];
                $getOnlyPriceSetElements = FALSE;
            }
            $this->set('priceSetId', $this->_priceSetId);
            CRM_Price_BAO_PriceSet::buildPriceSet($this);
            $optionsMembershipTypes = array();
            foreach ($this->_priceSet['fields'] as $pField) {
                if (empty($pField['options'])) {
                    continue;
                }
                foreach ($pField['options'] as $opId => $opValues) {
                    $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
                }
            }
            $this->assign('autoRenewOption', CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId));
            $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
            $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet));
            // get only price set form elements.
            if ($getOnlyPriceSetElements) {
                return;
            }
        }
        // use to build form during form rule.
        $this->assign('buildPriceSet', $buildPriceSet);
        if ($this->_action & CRM_Core_Action::ADD) {
            $buildPriceSet = FALSE;
            $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
            if (!empty($priceSets)) {
                $buildPriceSet = TRUE;
            }
            if ($buildPriceSet) {
                $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
            }
            $this->assign('hasPriceSets', $buildPriceSet);
        }
        //need to assign custom data type and subtype to the template
        $this->assign('customDataType', 'Membership');
        $this->assign('customDataSubType', $this->_memType);
        $this->assign('entityID', $this->_id);
        if ($this->_action & CRM_Core_Action::DELETE) {
            $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '         ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
            return;
        }
        if ($this->_context == 'standalone') {
            $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
        }
        $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
        $dao = new CRM_Member_DAO_MembershipType();
        $dao->domain_id = CRM_Core_Config::domainID();
        $dao->find();
        // retrieve all memberships
        $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
        $allMembershipInfo = $membershipType = array();
        foreach ($allMemberships as $key => $values) {
            if (!empty($values['is_active'])) {
                $membershipType[$key] = CRM_Utils_Array::value('name', $values);
                if ($this->_mode && empty($values['minimum_fee'])) {
                    continue;
                } else {
                    $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
                    if (empty($selMemTypeOrg[$memberOfContactId])) {
                        $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                        $selOrgMemType[$memberOfContactId][0] = ts('- select -');
                    }
                    if (empty($selOrgMemType[$memberOfContactId][$key])) {
                        $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
                    }
                }
                // build membership info array, which is used when membership type is selected to:
                // - set the payment information block
                // - set the max related block
                $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'), 'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $values));
            }
        }
        $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
        // show organization by default, if only one organization in
        // the list
        if (count($selMemTypeOrg) == 2) {
            unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
        }
        //sort membership organization and type, CRM-6099
        natcasesort($selMemTypeOrg);
        foreach ($selOrgMemType as $index => $orgMembershipType) {
            natcasesort($orgMembershipType);
            $selOrgMemType[$index] = $orgMembershipType;
        }
        $memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value );");
        //build the form for auto renew.
        $recurProcessor = $autoRenew = array();
        if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) {
            $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), NULL, array('onclick' => "buildReceiptANDNotice( );"));
            if ($this->_mode) {
                //get the valid recurring processors.
                $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE;
                $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1');
                $recurProcessor = array_intersect_key($this->_processors, $recurring);
                $autoRenew = array();
                if (!empty($recurProcessor)) {
                    if (!empty($membershipType)) {
                        $sql = '
SELECT  id,
        auto_renew,
        duration_unit,
        duration_interval
 FROM   civicrm_membership_type
WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
                        $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql);
                        while ($recurMembershipTypes->fetch()) {
                            $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew;
                            foreach (array('id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) {
                                $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->{$fld};
                            }
                        }
                    }
                    $memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );");
                }
            }
        }
        $allowAutoRenew = FALSE;
        if ($this->_mode && !empty($recurProcessor)) {
            $allowAutoRenew = TRUE;
        }
        $this->assign('allowAutoRenew', $allowAutoRenew);
        $this->assign('autoRenewOptions', json_encode($autoRenew));
        $this->assign('recurProcessor', json_encode($recurProcessor));
        // for max_related: a little JS to show/hide & set default value
        $memTypeJs['onChange'] = "buildMaxRelated(this.value,true); " . $memTypeJs['onChange'];
        $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related'));
        $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
        $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
        $elements = array();
        if ($sel) {
            $elements[] = $sel;
        }
        $this->applyFilter('__ALL__', 'trim');
        if ($this->_action & CRM_Core_Action::ADD) {
            $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6));
        }
        $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
        $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
        $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
        if ($endDate) {
            $elements[] = $endDate;
        }
        $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
        //CRM-7362 --add campaigns.
        $campaignId = NULL;
        if ($this->_id) {
            $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
        }
        CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
        if (!$this->_mode) {
            $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
            $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
            if ($statusOverride) {
                $elements[] = $statusOverride;
            }
            $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
            $this->add('text', 'total_amount', ts('Amount'));
            $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
            $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
            $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
            $this->add('text', 'trxn_id', ts('Transaction ID'));
            $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
            $allowStatuses = array();
            $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
            if ($this->_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;
            }
            $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
            $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
        } else {
            //add field for amount to allow an amount to be entered that differs from minimum
            $this->add('text', 'total_amount', ts('Amount'));
        }
        $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType());
        //CRM-10223 - allow contribution to be recorded against different contact
        // causes a conflict in standalone mode so skip in standalone for now
        $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
        $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
        $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
        $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio', false);"));
        $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
        $this->add('textarea', 'receipt_text_signup', ts('Receipt Message'));
        // Retrieve the name and email of the contact - this will be the TO for receipt email
        if ($this->_contactID) {
            list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
            $this->assign('emailExists', $this->_memberEmail);
            $this->assign('displayName', $this->_memberDisplayName);
        }
        $isRecur = FALSE;
        if ($this->_action & CRM_Core_Action::UPDATE) {
            $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
            if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
                $isRecur = TRUE;
                if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                    $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
                }
                foreach ($elements as $elem) {
                    $elem->freeze();
                }
            }
        }
        $this->assign('isRecur', $isRecur);
        $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
        $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
        $this->assign('outBound_option', $mailingInfo['outBound_option']);
        parent::buildQuickForm();
    }
Example #2
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // build profiles first so that we can determine address fields etc
     // and then show copy address checkbox
     if (empty($this->_ccid)) {
         $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
         $this->buildCustom($this->_values['custom_post_id'], 'customPost');
         // CRM-18399: used by template to pass pre profile id as a url arg
         $this->assign('custom_pre_id', $this->_values['custom_pre_id']);
         $this->buildComponentForm($this->_id, $this);
     }
     // Build payment processor form
     CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
     $config = CRM_Core_Config::singleton();
     $contactID = $this->getContactID();
     if ($contactID) {
         $this->assign('contact_id', $contactID);
         $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID));
     }
     $this->applyFilter('__ALL__', 'trim');
     if (empty($this->_ccid)) {
         $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60, 'class' => 'email'), TRUE);
         $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email');
     } else {
         $this->addElement('hidden', "email-{$this->_bltID}", 1);
         $this->add('text', 'total_amount', ts('Total Amount'), array('readonly' => TRUE), FALSE);
     }
     $pps = array();
     //@todo - this should be replaced by a check as to whether billing fields are set
     $onlinePaymentProcessorEnabled = FALSE;
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $name) {
             if ($name['billing_mode'] == 1) {
                 $onlinePaymentProcessorEnabled = TRUE;
             }
             $pps[$key] = $name['name'];
         }
     }
     if (!empty($this->_values['is_pay_later'])) {
         $pps[0] = $this->_values['pay_later_text'];
     }
     if (count($pps) > 1) {
         $this->addRadio('payment_processor_id', ts('Payment Method'), $pps, NULL, " ");
     } elseif (!empty($pps)) {
         $key = array_keys($pps);
         $key = array_pop($key);
         $this->addElement('hidden', 'payment_processor_id', $key);
         if ($key === 0) {
             $this->assign('is_pay_later', $this->_values['is_pay_later']);
             $this->assign('pay_later_text', $this->_values['pay_later_text']);
         }
     }
     $contactID = $this->getContactID();
     if ($this->getContactID() === 0) {
         $this->addCidZeroOptions($onlinePaymentProcessorEnabled);
     }
     //build pledge block.
     $this->_useForMember = 0;
     //don't build membership block when pledge_id is passed
     if (empty($this->_values['pledge_id']) && empty($this->_ccid)) {
         $this->_separateMembershipPayment = FALSE;
         if (in_array('CiviMember', $config->enableComponents)) {
             $isTest = 0;
             if ($this->_action & CRM_Core_Action::PREVIEW) {
                 $isTest = 1;
             }
             if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) {
                 $this->_useForMember = 1;
                 $this->set('useForMember', $this->_useForMember);
             }
             $this->_separateMembershipPayment = $this->buildMembershipBlock($this->_membershipContactID, TRUE, NULL, FALSE, $isTest);
         }
         $this->set('separateMembershipPayment', $this->_separateMembershipPayment);
     }
     $this->assign('useForMember', $this->_useForMember);
     // If we configured price set for contribution page
     // we are not allow membership signup as well as any
     // other contribution amount field, CRM-5095
     if (isset($this->_priceSetId) && $this->_priceSetId) {
         $this->add('hidden', 'priceSetId', $this->_priceSetId);
         // build price set form.
         $this->set('priceSetId', $this->_priceSetId);
         if (empty($this->_ccid)) {
             CRM_Price_BAO_PriceSet::buildPriceSet($this);
         }
         if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id'])) {
             self::buildRecur($this);
         }
     }
     if ($this->_priceSetId && empty($this->_ccid)) {
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             $this->_useForMember = 0;
             $this->set('useForMember', $this->_useForMember);
         }
     }
     //we allow premium for pledge during pledge creation only.
     if (empty($this->_values['pledge_id']) && empty($this->_ccid)) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE);
     }
     //don't build pledge block when mid is passed
     if (!$this->_mid && empty($this->_ccid)) {
         $config = CRM_Core_Config::singleton();
         if (in_array('CiviPledge', $config->enableComponents) && !empty($this->_values['pledge_block_id'])) {
             CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this);
         }
     }
     //to create an cms user
     if (!$this->_contactID && empty($this->_ccid)) {
         $createCMSUser = FALSE;
         if ($this->_values['custom_pre_id']) {
             $profileID = $this->_values['custom_pre_id'];
             $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
         }
         if (!$createCMSUser && $this->_values['custom_post_id']) {
             if (!is_array($this->_values['custom_post_id'])) {
                 $profileIDs = array($this->_values['custom_post_id']);
             } else {
                 $profileIDs = $this->_values['custom_post_id'];
             }
             foreach ($profileIDs as $pid) {
                 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
                     $profileID = $pid;
                     $createCMSUser = TRUE;
                     break;
                 }
             }
         }
         if ($createCMSUser) {
             CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
         }
     }
     if ($this->_pcpId && empty($this->_ccid)) {
         if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) {
             $pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter));
             // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field.
             $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute');
             if (!empty($text)) {
                 $pcp_supporter_text .= ts("You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!");
             }
             $this->assign('pcpSupporterText', $pcp_supporter_text);
         }
         $prms = array('id' => $this->_pcpId);
         CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
         if ($pcpInfo['is_honor_roll']) {
             $this->assign('isHonor', TRUE);
             $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );"));
             $extraOption = array('onclick' => "return pcpAnonymous( );");
             $elements = array();
             $elements[] =& $this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
             $elements[] =& $this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
             $this->addGroup($elements, 'pcp_is_anonymous', NULL, '&nbsp;&nbsp;&nbsp;');
             $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
             $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
         }
     }
     if (empty($this->_values['fee']) && empty($this->_ccid)) {
         CRM_Core_Error::fatal(ts('This page does not have any price fields configured or you may not have permission for them. Please contact the site administrator for more details.'));
     }
     //we have to load confirm contribution button in template
     //when multiple payment processor as the user
     //can toggle with payment processor selection
     $billingModePaymentProcessors = 0;
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $key => $values) {
             if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) {
                 $billingModePaymentProcessors++;
             }
         }
     }
     if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) {
         $allAreBillingModeProcessors = TRUE;
     } else {
         $allAreBillingModeProcessors = FALSE;
     }
     if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) {
         $submitButton = array('type' => 'upload', 'name' => CRM_Utils_Array::value('is_confirm_enabled', $this->_values) ? ts('Confirm Contribution') : ts('Contribute'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE);
         // Add submit-once behavior when confirm page disabled
         if (empty($this->_values['is_confirm_enabled'])) {
             $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
         }
         //change button name for updating contribution
         if (!empty($this->_ccid)) {
             $submitButton['name'] = ts('Confirm Payment');
         }
         $this->addButtons(array($submitButton));
     }
     $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
 }
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_cdType) {
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         return;
     }
     $allPanes = array();
     // build price set form.
     $buildPriceSet = FALSE;
     if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id']))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $showAdditionalInfo = FALSE;
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     $ccPane = NULL;
     if ($this->_mode) {
         if (CRM_Utils_Array::value('payment_type', $this->_processors) & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
             $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
         } else {
             $ccPane = array(ts('Credit Card Information') => 'CreditCard');
         }
     }
     if (is_array($ccPane)) {
         $paneNames = array_merge($ccPane, $paneNames);
     }
     $buildRecurBlock = FALSE;
     foreach ($paneNames as $name => $type) {
         $urlParams = "snippet=4&formType={$type}";
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $open = 'false';
         if ($type == 'CreditCard' || $type == 'DirectDebit') {
             $open = 'true';
         }
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams), 'open' => $open, 'id' => $type);
         // see if we need to include this paneName in the current form
         if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) || CRM_Utils_Array::value("hidden_{$type}", $defaults)) {
             $showAdditionalInfo = TRUE;
             $allPanes[$name]['open'] = 'true';
         }
         if ($type == 'CreditCard') {
             $buildRecurBlock = TRUE;
             $this->add('hidden', 'hidden_CreditCard', 1);
             CRM_Core_Payment_Form::buildCreditCard($this, TRUE);
         } elseif ($type == 'DirectDebit') {
             $buildRecurBlock = TRUE;
             $this->add('hidden', 'hidden_DirectDebit', 1);
             CRM_Core_Payment_Form::buildDirectDebit($this, TRUE);
         } else {
             $additionalInfoFormFunction = 'build' . $type;
             CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this);
         }
     }
     if (empty($this->_recurPaymentProcessors)) {
         $buildRecurBlock = FALSE;
     }
     if ($buildRecurBlock) {
         CRM_Contribute_Form_Contribution_Main::buildRecur($this);
         $this->setDefaults(array('is_recur' => 0));
     }
     $this->assign('buildRecurBlock', $buildRecurBlock);
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->assign('showAdditionalInfo', $showAdditionalInfo);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), TRUE, array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );"));
     $paymentInstrument = FALSE;
     if (!$this->_mode) {
         $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
     }
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($this->_ppID) {
         foreach (array('Cancelled', 'Failed', 'In Progress') as $suppress) {
             unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
     } elseif (!$this->_ppID && $this->_id || !$this->_id) {
         $suppressFlag = FALSE;
         if ($this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
                 $suppressFlag = TRUE;
             }
         }
         if (!$suppressFlag) {
             foreach (array('Overdue', 'In Progress') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
         } else {
             unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
         }
     }
     if ($this->_id) {
         $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
         $name = CRM_Utils_Array::value($contributionStatus, $statusName);
         switch ($name) {
             case 'Completed':
             case 'Cancelled':
             case 'Refunded':
                 unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
                 break;
             case 'Pending':
             case 'In Progress':
                 unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
                 break;
             case 'Failed':
                 foreach (array('Pending', 'Refunded', 'Completed', 'In Progress', 'Cancelled') as $suppress) {
                     unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
                 }
                 break;
         }
     } else {
         unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE);
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
     $recurJs = NULL;
     if ($buildRecurBlock) {
         $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
     }
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
             if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if (!($this->_action & CRM_Core_Action::UPDATE)) {
             if ($this->_online || $this->_ppID) {
                 $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
                 $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
                 $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
                 $currencyFreeze = TRUE;
             }
         }
         $totalAmount = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
     // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
     if ($this->_id && $this->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         if ($totalAmount) {
             $totalAmount->freeze();
         }
         $checkNumber->freeze();
         $paymentInstrument->freeze();
         $trxnId->freeze();
         $financialType->freeze();
     }
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Example #4
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // FIXME: This probably needs to be done in preprocess
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE && CRM_Utils_Array::value('financial_type_id', $this->_values)) {
         $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
         CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit');
         if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     $allPanes = array();
     $recurJs = NULL;
     //tax rate from financialType
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currencies', json_encode(CRM_Core_OptionGroup::values('currencies_enabled')));
     // build price set form.
     $buildPriceSet = FALSE;
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     // display tax amount on edit contribution page
     if ($invoicing && $this->_action & CRM_Core_Action::UPDATE && isset($this->_values['tax_amount'])) {
         $this->assign('totalTaxAmount', $this->_values['tax_amount']);
     }
     if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id']))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     if ($this->_mode) {
         if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE) == TRUE) {
             if (!empty($this->_recurPaymentProcessors)) {
                 $buildRecurBlock = TRUE;
                 if ($this->_ppID) {
                     // ppID denotes a pledge payment.
                     foreach ($this->_paymentProcessors as $processor) {
                         if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) {
                             $buildRecurBlock = TRUE;
                             break;
                         }
                         $buildRecurBlock = FALSE;
                     }
                 }
                 if ($buildRecurBlock) {
                     CRM_Contribute_Form_Contribution_Main::buildRecur($this);
                     $this->setDefaults(array('is_recur' => 0));
                     $this->assign('buildRecurBlock', TRUE);
                     $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
                 }
             }
         }
     }
     foreach ($paneNames as $name => $type) {
         $allPanes[$name] = $this->generatePane($type, $defaults);
     }
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     // Check permissions for financial type first
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action);
     if (empty($financialTypes)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialTypes, TRUE, array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );"));
     $paymentInstrument = FALSE;
     if (!$this->_mode) {
         $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
     }
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($this->_ppID) {
         foreach (array('Cancelled', 'Failed', 'In Progress') as $suppress) {
             unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
     } elseif (!$this->_ppID && $this->_id || !$this->_id) {
         $suppressFlag = FALSE;
         if ($this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
                 $suppressFlag = TRUE;
             }
         }
         if (!$suppressFlag) {
             foreach (array('Overdue', 'In Progress') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
         } else {
             unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
         }
     }
     if ($this->_id) {
         $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
         $name = CRM_Utils_Array::value($contributionStatus, $statusName);
         switch ($name) {
             case 'Completed':
             case 'Cancelled':
             case 'Refunded':
                 unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
                 break;
             case 'Pending':
             case 'In Progress':
                 unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
                 break;
             case 'Failed':
                 foreach (array('Pending', 'Refunded', 'Completed', 'In Progress', 'Cancelled') as $suppress) {
                     unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
                 }
                 break;
         }
     } else {
         unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE);
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             // CRM-16451: set financial type of 'Price Set' in back office contribution
             // instead of selecting manually
             $financialTypeIds = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute', 'financial_type_id');
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value, " . json_encode($financialTypeIds) . ");"));
             if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if (!($this->_action & CRM_Core_Action::UPDATE)) {
             if ($this->_online || $this->_ppID) {
                 $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
                 $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
                 $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
                 $currencyFreeze = TRUE;
             }
         }
         $totalAmount = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
     // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
     if ($this->_id && $this->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         if ($totalAmount) {
             $totalAmount->freeze();
         }
         $checkNumber->freeze();
         $paymentInstrument->freeze();
         $trxnId->freeze();
         $financialType->freeze();
     }
     // if contribution is related to membership or participant freeze Financial Type, Amount
     if ($this->_id && isset($this->_values['tax_amount'])) {
         $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
         if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
             if ($totalAmount) {
                 $totalAmount->freeze();
             }
             $financialType->freeze();
             $this->assign('freezeFinancialType', TRUE);
         }
     }
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Example #5
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currency', CRM_Core_Config::singleton()->defaultCurrencySymbol);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if (isset($invoicing)) {
         $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
     }
     // build price set form.
     $buildPriceSet = FALSE;
     if ($this->_priceSetId || !empty($_POST['price_set_id'])) {
         if (!empty($_POST['price_set_id'])) {
             $buildPriceSet = TRUE;
         }
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         $optionsMembershipTypes = array();
         foreach ($this->_priceSet['fields'] as $pField) {
             if (empty($pField['options'])) {
                 continue;
             }
             foreach ($pField['options'] as $opId => $opValues) {
                 $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
             }
         }
         $this->assign('autoRenewOption', CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId));
         $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
         $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet));
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     if ($this->_action & CRM_Core_Action::ADD) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
         if (!empty($priceSets)) {
             $buildPriceSet = TRUE;
         }
         if ($buildPriceSet) {
             $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
         }
         $this->assign('hasPriceSets', $buildPriceSet);
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Membership');
     $this->assign('customDataSubType', $this->_memType);
     $this->assign('entityID', $this->_id);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
     // Throw status bounce when no Membership type or priceset is present
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && empty($this->allMembershipTypeDetails) && empty($priceSets)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     // retrieve all memberships
     $allMembershipInfo = array();
     foreach ($this->allMembershipTypeDetails as $key => $values) {
         if ($this->_mode && empty($values['minimum_fee'])) {
             continue;
         } else {
             $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
             if (empty($selMemTypeOrg[$memberOfContactId])) {
                 $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                 $selOrgMemType[$memberOfContactId][0] = ts('- select -');
             }
             if (empty($selOrgMemType[$memberOfContactId][$key])) {
                 $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
             }
         }
         $totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
         //CRM-18827 - override the default value if total_amount is submitted
         if (!empty($this->_submitValues['total_amount'])) {
             $totalAmount = $this->_submitValues['total_amount'];
         }
         // build membership info array, which is used when membership type is selected to:
         // - set the payment information block
         // - set the max related block
         $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $values));
     }
     $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
     // show organization by default, if only one organization in
     // the list
     if (count($selMemTypeOrg) == 2) {
         unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
     }
     //sort membership organization and type, CRM-6099
     natcasesort($selMemTypeOrg);
     foreach ($selOrgMemType as $index => $orgMembershipType) {
         natcasesort($orgMembershipType);
         $selOrgMemType[$index] = $orgMembershipType;
     }
     $memTypeJs = array('onChange' => "buildMaxRelated(this.value,true); CRM.buildCustomData('Membership', this.value);");
     if (!empty($this->_recurPaymentProcessors)) {
         $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . "buildAutoRenew(this.value, null, '{$this->_mode}');";
     }
     $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related'));
     $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
     $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
     $elements = array();
     if ($sel) {
         $elements[] = $sel;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::ADD) {
         $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6));
     }
     $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
     $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
     $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
     if ($endDate) {
         $elements[] = $endDate;
     }
     $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     if (!$this->_mode) {
         $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
         $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
         if ($statusOverride) {
             $elements[] = $statusOverride;
         }
         $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
         $this->add('text', 'total_amount', ts('Amount'));
         $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
         $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
         $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
         $this->add('text', 'trxn_id', ts('Transaction ID'));
         $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
         $allowStatuses = array();
         $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
         if ($this->_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;
         }
         $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
         $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
     } else {
         //add field for amount to allow an amount to be entered that differs from minimum
         $this->add('text', 'total_amount', ts('Amount'));
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action));
     $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
     $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
     $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
     $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showEmailOptions()"));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $this->add('textarea', 'receipt_text', ts('Receipt Message'));
     // Retrieve the name and email of the contact - this will be the TO for receipt email
     if ($this->_contactID) {
         list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('emailExists', $this->_memberEmail);
         $this->assign('displayName', $this->_memberDisplayName);
     }
     $isRecur = FALSE;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
         if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
             $isRecur = TRUE;
             if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                 $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
             }
             foreach ($elements as $elem) {
                 $elem->freeze();
             }
         }
     }
     $this->assign('isRecur', $isRecur);
     $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('isEmailEnabledForSite', $mailingInfo['outBound_option'] != 2);
     parent::buildQuickForm();
 }