diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index 884bb7ea46b4d16c3bbe805821768ec01214b7a1..6f71084976a8be0b16198c36fc15af0abd2c4cb2 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -353,7 +353,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { * @param array $params associated array for params * @access public */ - static function getBatchCount(&$params) { + public static function getBatchCount(&$params) { $args = array(); $whereClause = self::whereClause($params, $args); $query = " SELECT COUNT(*) FROM civicrm_batch batch @@ -368,7 +368,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { * @param array $params associated array for params * @access public */ - function whereClause($params) { + public static function whereClause($params) { $clauses = array(); // Exclude data-entry batches if (empty($params['status_id'])) { diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index adf45db2dec837a9590c0a047fc2ad6ab0adfe2c..a1e4e091c3a85ac2784fc3d16c7fa772d5d60c34 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -259,7 +259,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { if (CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id']) && !CRM_Utils_Array::value($key, $params['soft_credit_amount'])) { $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount'); } - if (CRM_Utils_Array::value($key, $params['soft_credit_amount']) + if (!empty($params['soft_credit_amount']) && CRM_Utils_Array::value($key, $params['soft_credit_amount']) && CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value($key, $params['soft_credit_amount'])) > CRM_Utils_Rule::cleanMoney($value['total_amount'])) { $errors["soft_credit_amount[$key]"] = ts('Soft credit amount should not be greater than the total amount'); } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 6400f55640d773eadd8054bbd4a994d8a3f43894..36b01eb03914ff9b357ebd658e1a11df65514a5e 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -54,43 +54,43 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { /* * Display name of the member */ - protected $_memberDisplayName = null; + protected $_memberDisplayName = NULL; /* * email of the person paying for the membership (used for receipts) */ - protected $_memberEmail = null; + protected $_memberEmail = NULL; /* * Contact ID of the member */ - protected $_contactID = null; + protected $_contactID = NULL; /* * Display name of the person paying for the membership (used for receipts) */ - protected $_contributorDisplayName = null; + protected $_contributorDisplayName = NULL; - /* - * email of the person paying for the membership (used for receipts) - */ - protected $_contributorEmail = null; + /* + * email of the person paying for the membership (used for receipts) + */ + protected $_contributorEmail = NULL; /* * email of the person paying for the membership (used for receipts) */ - protected $_contributorContactID = null; + protected $_contributorContactID = NULL; - /* - * ID of the person the receipt is to go to - */ - protected $_receiptContactId = null; + /* + * ID of the person the receipt is to go to + */ + protected $_receiptContactId = NULL; /* * Keep a class variable for ALL membeshipID's so * postProcess hook function can do something with it */ - protected $_membershipIDs = array( ); + protected $_membershipIDs = array(); /** * An array to hold a list of datefields on the form @@ -262,7 +262,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $membershipStatus->free(); $passthru = array( 'typeorgs' => CRM_Member_BAO_MembershipType::getMembershipTypeOrganization(), - 'memtypes' => CRM_Member_BAO_MembershipType::getMembershipTypes(false), + 'memtypes' => CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE), 'statuses' => $statuses, ); $resources->addSetting(array('existingMems' => $passthru)); @@ -296,7 +296,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { } // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container - CRM_Utils_System::setTitle(ts('Membership for') . ' ' . $displayName); + CRM_Utils_System::setTitle(ts('Membership for') . ' ' . $displayName); } parent::preProcess(); } @@ -414,8 +414,13 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $fields[$name] = 1; } $names = array( - 'first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", - "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", + 'first_name', + 'middle_name', + 'last_name', + "street_address-{$this->_bltID}", + "city-{$this->_bltID}", + "postal_code-{$this->_bltID}", + "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}", ); foreach ($names as $name) { @@ -529,7 +534,8 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { if ($buildPriceSet) { $this->add('select', 'price_set_id', ts('Choose price set'), array( - '' => ts('Choose price set')) + $priceSets, + '' => ts('Choose price set') + ) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );") ); } @@ -572,8 +578,8 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this); $allMembershipInfo = $membershipType = array(); - foreach( $allMemberships as $key => $values ) { - if (CRM_Utils_Array::value('is_active', $values) ) { + foreach ($allMemberships as $key => $values) { + if (CRM_Utils_Array::value('is_active', $values)) { $membershipType[$key] = CRM_Utils_Array::value('name', $values); if ($this->_mode && !CRM_Utils_Array::value('minimum_fee', $values)) { continue; @@ -599,11 +605,11 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { // - 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' => 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), + '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), ); } } @@ -636,9 +642,9 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { if ($this->_mode) { //get the valid recurring processors. - $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); + $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $recurProcessor = array_intersect_assoc($this->_processors, $recurring); - $autoRenew = array(); + $autoRenew = array(); if (!empty($recurProcessor)) { if (!empty($membershipType)) { $sql = ' @@ -652,7 +658,11 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; while ($recurMembershipTypes->fetch()) { $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; foreach (array( - 'id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) { + 'id', + 'auto_renew', + 'duration_unit', + 'duration_interval' + ) as $fld) { $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->$fld; } } @@ -678,7 +688,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related') ); - $sel = &$this->addElement('hierselect', + $sel = & $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs @@ -749,7 +759,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach ($statusNames as $val => $name) { if (in_array($name, array( - 'In Progress', 'Overdue'))) { + 'In Progress', + 'Overdue' + )) + ) { continue; } $allowStatuses[$val] = $statuses[$val]; @@ -777,9 +790,9 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //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->add( 'select', 'honor_type_id', ts('Membership payment is : '), - array( '' => ts( '-') ) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id') ); - CRM_Contact_Form_NewContact::buildQuickForm($this,1, null, false,'contribution_'); + $this->add('select', 'honor_type_id', ts('Membership payment is : '), + array('' => ts('-')) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id')); + CRM_Contact_Form_NewContact::buildQuickForm($this, 1, NULL, FALSE, 'contribution_'); } $this->addElement('checkbox', @@ -805,7 +818,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if ($this->_contactID) { list($this->_memberDisplayName, $this->_memberEmail - ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); + ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('emailExists', $this->_memberEmail); $this->assign('displayName', $this->_memberDisplayName); @@ -1249,17 +1262,24 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']); //CRM-10223 - allow contribution to be recorded against different contact - if($this->_contributorContactID != $this->_contactID){ + if ($this->_contributorContactID != $this->_contactID) { $params['contribution_contact_id'] = $this->_contributorContactID; - if(CRM_Utils_Array::value('honor_type_id', $this->_params)){ + if (CRM_Utils_Array::value('honor_type_id', $this->_params)) { $params['honor_type_id'] = $this->_params['honor_type_id']; $params['honor_contact_id'] = $params['contact_id']; } } if (CRM_Utils_Array::value('record_contribution', $formValues)) { $recordContribution = array( - 'total_amount', 'honor_type_id','financial_type_id', 'payment_instrument_id', - 'trxn_id', 'contribution_status_id', 'check_number', 'campaign_id', 'receive_date', + 'total_amount', + 'honor_type_id', + 'financial_type_id', + 'payment_instrument_id', + 'trxn_id', + 'contribution_status_id', + 'check_number', + 'campaign_id', + 'receive_date', ); foreach ($recordContribution as $f) { @@ -1310,7 +1330,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; } if ($priceSetId && !$isQuickConfig) { - $params['financial_type_id'] = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceSet', + $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'financial_type_id' ); @@ -1347,7 +1367,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $fields["address_name-{$this->_bltID}"] = 1; //ensure we don't over-write the payer's email with the member's email - if($this->_contributorContactID == $this->_contactID) { + if ($this->_contributorContactID == $this->_contactID) { $fields["email-{$this->_bltID}"] = 1; } @@ -1389,8 +1409,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $paymentParams['contactID'] = $this->_contributorContactID; //CRM-10377 if payment is by an alternate contact then we need to set that person // as the contact in the payment params - if($this->_contributorContactID != $this->_contactID){ - if(CRM_Utils_Array::value('honor_type_id', $this->_params)){ + if ($this->_contributorContactID != $this->_contactID) { + if (CRM_Utils_Array::value('honor_type_id', $this->_params)) { $paymentParams['honor_contact_id'] = $this->_contactID; $paymentParams['honor_type_id'] = $this->_params['honor_type_id']; } @@ -1422,9 +1442,9 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; TRUE, FALSE ); - $paymentParams['contactID'] = $contactID; + $paymentParams['contactID'] = $contactID; $paymentParams['contributionID'] = $contribution->id; - $paymentParams['contributionTypeID'] = $contribution->financial_type_id; + $paymentParams['contributionTypeID'] = $contribution->financial_type_id; $paymentParams['contributionPageID'] = $contribution->contribution_page_id; $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id; $ids['contribution'] = $contribution->id; @@ -1449,7 +1469,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if ($params['total_amount'] > 0.0) { $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); - $result = &$payment->doDirectPayment($paymentParams); + $result = & $payment->doDirectPayment($paymentParams); } if (is_a($result, 'CRM_Core_Error')) { @@ -1463,8 +1483,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', - "reset=1&action=add&cid={$this->_contactID}&context=&mode={$this->_mode}" - )); + "reset=1&action=add&cid={$this->_contactID}&context=&mode={$this->_mode}" + )); } if ($result) { @@ -1530,10 +1550,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $result = CRM_Contribute_BAO_Contribution::transitionComponents($params, TRUE); if (!empty($result) && CRM_Utils_Array::value('contribution_id', $params)) { $lineItem = array(); - $lineItems = CRM_Price_BAO_LineItem::getLineItems($params['contribution_id'], 'contribution'); - $itemId = key($lineItems); - $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); - $fieldType = NULL; + $lineItems = CRM_Price_BAO_LineItem::getLineItems($params['contribution_id'], 'contribution'); + $itemId = key($lineItems); + $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); + $fieldType = NULL; if ($itemId && CRM_Utils_Array::value('price_field_id', $lineItems[$itemId])) { $fieldType = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'html_type'); } @@ -1555,9 +1575,11 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $endDate = $membership->end_date; $membershipStatues = CRM_Member_PseudoConstant::membershipStatus(); - if (!in_array($membership->status_id, array(array_search('Cancelled', $membershipStatues), - array_search('Expired', $membershipStatues), - ))) { + if (!in_array($membership->status_id, array( + array_search('Cancelled', $membershipStatues), + array_search('Expired', $membershipStatues), + )) + ) { $cancelled = FALSE; } } @@ -1587,8 +1609,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $membershipParams = array_merge($params, $membershipTypeValues[$memType]); if (CRM_Utils_Array::value('int_amount', $formValues)) { $init_amount = array(); - foreach($formValues as $key => $value){ - if (strstr($key,'txt-price')){ + foreach ($formValues as $key => $value) { + if (strstr($key, 'txt-price')) { $init_amount[$key] = $value; } } @@ -1621,10 +1643,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if (CRM_Utils_Array::value('send_receipt', $formValues)) { $receiptSend = TRUE; - $formValues['contact_id'] = $this->_contactID; + $formValues['contact_id'] = $this->_contactID; // send email receipt - $mailSend = self::emailReceipt( $this, $formValues, $membership ); + $mailSend = self::emailReceipt($this, $formValues, $membership); } if (($this->_action & CRM_Core_Action::UPDATE)) { @@ -1645,7 +1667,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $statusMsg = array(); foreach ($membershipTypes as $memType => $membershipType) { - $statusMsg[$memType] = ts('%1 membership for %2 has been added.', array(1 => $membershipType, 2 => $this->_memberDisplayName)); + $statusMsg[$memType] = ts('%1 membership for %2 has been added.', array( + 1 => $membershipType, + 2 => $this->_memberDisplayName + )); $membership = $createdMemberships[$memType]; $memEndDate = ($membership->end_date) ? $membership->end_date : $endDate; @@ -1677,19 +1702,19 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if ($this->_context == 'standalone') { if ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/member/add', - 'reset=1&action=add&context=standalone' - )); + 'reset=1&action=add&context=standalone' + )); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', - "reset=1&cid={$this->_contactID}&selectedChild=member" - )); + "reset=1&cid={$this->_contactID}&selectedChild=member" + )); } } elseif ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/membership', - "reset=1&action=add&context=membership&cid={$this->_contactID}" - )); + "reset=1&action=add&context=membership&cid={$this->_contactID}" + )); } } @@ -1697,13 +1722,13 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; * Function to send email receipt * * @param object $form form object - * @param array $values submitted values + * @param array $values submitted values * @param object $membership object * * @return boolean true if mail was sent successfully * @static */ - static function emailReceipt( &$form, &$formValues, &$membership ) { + static function emailReceipt(&$form, &$formValues, &$membership) { // retrieve 'from email id' for acknowledgement $receiptFrom = $formValues['from_email_address']; @@ -1714,8 +1739,9 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; // retrieve custom data $customFields = $customValues = array(); - if ( property_exists( $form, '_groupTree' ) - && !empty( $form->_groupTree ) ) { + if (property_exists($form, '_groupTree') + && !empty($form->_groupTree) + ) { foreach ($form->_groupTree as $groupID => $group) { if ($groupID == 'info') { continue; @@ -1781,23 +1807,23 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; } $form->assign('module', 'Membership'); - $form->assign('contactID', $formValues['contact_id'] ); + $form->assign('contactID', $formValues['contact_id']); $form->assign('membershipID', CRM_Utils_Array::value('membership_id', $form->_params, CRM_Utils_Array::value('membership_id', $form->_defaultValues))); - if ( CRM_Utils_Array::value('contribution_id', $formValues ) ) { - $form->assign( 'contributionID', $formValues['contribution_id'] ); + if (CRM_Utils_Array::value('contribution_id', $formValues)) { + $form->assign('contributionID', $formValues['contribution_id']); } - else { - $form->assign( 'contributionID', $form->_onlinePendingContributionId ); + elseif (isset($form->_onlinePendingContributionId)) { + $form->assign('contributionID', $form->_onlinePendingContributionId); } - if (CRM_Utils_Array::value('contribution_status_id', $formValues )) { + if (CRM_Utils_Array::value('contribution_status_id', $formValues)) { $form->assign('contributionStatusID', $formValues['contribution_status_id']); $form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name')); } - if ( CRM_Utils_Array::value( 'is_renew', $formValues ) ) { + if (CRM_Utils_Array::value('is_renew', $formValues)) { $form->assign('receiptType', 'membership renewal'); } else { @@ -1807,28 +1833,28 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $form->assign('formValues', $formValues); if (empty($lineItem)) { - $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y' ) ); - $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y' ) ); - $form->assign('membership_name', CRM_Member_PseudoConstant::membershipType( $membership->membership_type_id ) ); + $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y')); + $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y')); + $form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id)); } $form->assign('customValues', $customValues); $isBatchProcess = is_a($form, 'CRM_Batch_Form_Entry'); - if((empty($form->_contributorDisplayName) || empty($form->_contributorEmail)) || $isBatchProcess){ + if ((empty($form->_contributorDisplayName) || empty($form->_contributorEmail)) || $isBatchProcess) { // in this case the form is being called statically from the batch editing screen // having one class in the form layer call another statically is not greate // & we should aim to move this function to the BAO layer in future. // however, we can assume that the contact_id passed in by the batch // function will be the recipient - list( + list( $form->_contributorDisplayName, $form->_contributorEmail - ) = CRM_Contact_BAO_Contact_Location::getEmailDetails( - $formValues['contact_id'] - ); - if(empty($form->_receiptContactId) || $isBatchProcess){ - $form->_receiptContactId = $formValues['contact_id']; - } + ) = CRM_Contact_BAO_Contact_Location::getEmailDetails( + $formValues['contact_id'] + ); + if (empty($form->_receiptContactId) || $isBatchProcess) { + $form->_receiptContactId = $formValues['contact_id']; + } } list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate( @@ -1839,11 +1865,11 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; 'from' => $receiptFrom, 'toName' => $form->_contributorDisplayName, 'toEmail' => $form->_contributorEmail, - 'isTest' => (bool)($form->_action & CRM_Core_Action::PREVIEW) + 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW) ) ); - return true; + return TRUE; } }