static function postProcessStudent($pickupName, $studentID, $atSchoolMeeting = false) { static $_now = null; static $_date = null; if (!$_now) { $_now = CRM_Utils_Date::getToday(null, 'YmdHis'); } if (!$_date) { $_date = CRM_Utils_Date::getToday(null, 'Y-m-d'); } $atSchoolMeeting = $atSchoolMeeting ? '1' : '0'; $sql = "\nSELECT e.id, e.class\nFROM civicrm_value_extended_care_signout e\nWHERE entity_id = %1\nAND DATE(signin_time) = %2\nAND ( is_morning = 0 OR is_morning IS NULL )\n"; $params = array(1 => array($studentID, 'Integer'), 2 => array($_date, 'String')); $dao = CRM_Core_DAO::executeQuery($sql, $params); $params = array(1 => array($studentID, 'Integer'), 2 => array($pickupName, 'String'), 3 => array($_now, 'Timestamp'), 4 => array($atSchoolMeeting, 'Integer')); $class = null; if ($dao->fetch()) { $class = $dao->class; $sql = "\nUPDATE civicrm_value_extended_care_signout\nSET pickup_person_name = %2,\n signout_time = %3,\n at_school_meeting = %4\nWHERE id = %5\n"; $params[5] = array($dao->id, 'Integer'); } else { $sql = "\nINSERT INTO civicrm_value_extended_care_signout\n( entity_id, pickup_person_name, signout_time, at_school_meeting, is_morning )\nVALUES\n( %1, %2, %3, %4, 0 )\n"; } CRM_Core_DAO::executeQuery($sql, $params); return $class; }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues(&$form) { $defaults = array(); $defaults['start_date'] = array(); $defaults['start_date'] = CRM_Utils_Date::getToday($defaults['start_date'], 'm/d/Y'); return $defaults; }
function createDir() { require_once 'CRM/Utils/File.php'; // ensure that $this->_mailDir is a directory and is writable if (!is_dir($this->_mailDir) || !is_readable($this->_mailDir)) { echo "Could not read from {$this->_mailDir}\n"; exit; } $config =& CRM_Core_Config::singleton(); $dir = $config->uploadDir . DIRECTORY_SEPARATOR . 'mail'; $this->_processedDir = $dir . DIRECTORY_SEPARATOR . 'processed'; CRM_Utils_File::createDir($this->_processedDir); $this->_errorDir = $dir . DIRECTORY_SEPARATOR . 'error'; CRM_Utils_File::createDir($this->_errorDir); // create a date string YYYYMMDD require_once 'CRM/Utils/Date.php'; $date = CRM_Utils_Date::getToday(null, 'Ymd'); $this->_processedDir = $this->_processedDir . DIRECTORY_SEPARATOR . $date; CRM_Utils_File::createDir($this->_processedDir); $this->_errorDir = $this->_errorDir . DIRECTORY_SEPARATOR . $date; CRM_Utils_File::createDir($this->_errorDir); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect //what they have access to //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time) if (!CRM_Core_Permission::check(array('view all contacts', 'edit all contacts'))) { $this->showMembershipSummary = FALSE; $this->assign('membershipSummary', FALSE); return; } $this->assign('membershipSummary', TRUE); CRM_Utils_System::setTitle(ts('CiviMember')); $membershipSummary = array(); $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))); $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))); $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4)); $today = getdate(); $date = CRM_Utils_Date::getToday(); $isCurrentMonth = 0; // You can force the dashboard to display based upon a certain date $ym = CRM_Utils_Array::value('date', $_GET); if ($ym) { if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) { CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym))); } $isPreviousMonth = 0; $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon']; $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4))); $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4)); $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d'); $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2); } else { $ym = sprintf("%04d-%02d", $today['year'], $today['mon']); $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']); $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']); $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d'); $isCurrentMonth = 1; $isPreviousMonth = 1; } $monthStart = $ym . '-01'; $yearStart = substr($ym, 0, 4) . '-01-01'; $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); // added //$membership = new CRM_Member_BAO_Membership; foreach ($membershipTypes as $key => $value) { $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value); $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd)); //LCD also get summary stats for membership owners $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), 'name' => $value); $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), 'name' => $value); $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), 'name' => $value); $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), 'name' => $value); $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1)); //LCD end } // LCD debug //CRM_Core_Error::debug($membershipSummary); $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent(); $status = implode(',', $status); /* Disabled for lack of appropriate search The Membership search isn't able to properly filter by join or renewal events. Until that works properly, the subtotals shouldn't get links. foreach ($membershipSummary as $typeID => $details) { foreach ($details as $key => $value) { switch ($key) { case 'premonth': $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$preMonth&joinEnd=$preMonthEnd&start=$preMonth&end=$preMonthEnd"); $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$prePreMonthEnd&start=$preMonth&end=$preMonthEnd"); $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd"); break; case 'month': $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$monthStart&joinEnd=$ymd&start=$monthStart&end=$ymd"); $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preMonthStart&start=$monthStart&end=$ymd"); $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd"); break; case 'year': $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$yearStart&joinEnd=$ymd&start=$yearStart&end=$ymd"); $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preYearStart&start=$yearStart&end=$ymd"); $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd"); break; case 'current': $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID"); break; case 'total': if (!$isCurrentMonth) { $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID" ); } else { $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status" ); } break; //LCD add owner urls case 'premonth_owner': $membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd&owner=1"); break; case 'month_owner': $membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd&owner=1"); break; case 'year_owner': $membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd&owner=1"); break; case 'current_owner': $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1"); break; case 'total_owner': if (!$isCurrentMonth) { $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1"); } else { $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1"); } break; //LCD end } } } */ // Temporary replacement for current totals column foreach ($membershipSummary as $typeID => $details) { if (!$isCurrentMonth) { $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}"); $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}&owner=1"); } else { $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"); $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1"); } $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}"); $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&owner=1"); } $totalCount = array(); $newCountPreMonth = $newCountMonth = $newCountYear = 0; $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0; $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0; $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0; foreach ($membershipSummary as $key => $value) { $newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count']; $renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count']; $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count']; $newCountMonth = $newCountMonth + $value['month']['new']['count']; $renewCountMonth = $renewCountMonth + $value['month']['renew']['count']; $totalCountMonth = $totalCountMonth + $value['month']['total']['count']; $newCountYear = $newCountYear + $value['year']['new']['count']; $renewCountYear = $renewCountYear + $value['year']['renew']['count']; $totalCountYear = $totalCountYear + $value['year']['total']['count']; $totalCountCurrent = $totalCountCurrent + $value['current']['total']['count']; $totalCountTotal = $totalCountTotal + $value['total']['total']['count']; //LCD add owner values $totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count']; $totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count']; $totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count']; $totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count']; $totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count']; } $totalCount['premonth']['new'] = array('count' => $newCountPreMonth); $totalCount['premonth']['renew'] = array('count' => $renewCountPreMonth); $totalCount['premonth']['total'] = array('count' => $totalCountPreMonth); $totalCount['month']['new'] = array('count' => $newCountMonth); $totalCount['month']['renew'] = array('count' => $renewCountMonth); $totalCount['month']['total'] = array('count' => $totalCountMonth); $totalCount['year']['new'] = array('count' => $newCountYear); $totalCount['year']['renew'] = array('count' => $renewCountYear); $totalCount['year']['total'] = array('count' => $totalCountYear); $totalCount['current']['total'] = array('count' => $totalCountCurrent, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}")); $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}")); if (!$isCurrentMonth) { $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}")); } // Activity search also unable to handle owner vs. inherited //LCD add owner values $totalCount['premonth_owner']['premonth_owner'] = array('count' => $totalCountPreMonth_owner); $totalCount['month_owner']['month_owner'] = array('count' => $totalCountMonth_owner); $totalCount['year_owner']['year_owner'] = array('count' => $totalCountYear_owner); $totalCount['current_owner']['current_owner'] = array('count' => $totalCountCurrent_owner); $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner); if (!$isCurrentMonth) { $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner); } //LCD end $this->assign('membershipSummary', $membershipSummary); $this->assign('totalCount', $totalCount); $this->assign('month', date('F', $monthStartTs)); $this->assign('year', date('Y', $monthStartTs)); $this->assign('premonth', date('F', strtotime($preMonth))); $this->assign('currentMonth', date('F')); $this->assign('currentYear', date('Y')); $this->assign('isCurrent', $isCurrentMonth); $this->assign('preMonth', $isPreviousMonth); }
/** * Process form submission. * * This function is also accessed by a unit test. */ protected function submit() { $this->storeContactFields($this->_params); $this->beginPostProcess(); $now = CRM_Utils_Date::getToday(NULL, 'YmdHis'); $this->convertDateFieldsToMySQL($this->_params); $this->assign('receive_date', $this->_params['receive_date']); $this->processBillingAddress(); list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID')); $this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee')); $this->_membershipId = $this->_id; $customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($this->_params, $this->_id, 'Membership'); if (empty($this->_params['financial_type_id'])) { $this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id'); } $contributionRecurID = NULL; $this->assign('membershipID', $this->_id); $this->assign('contactID', $this->_contactID); $this->assign('module', 'Membership'); $this->assign('receiptType', 'membership renewal'); $this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency; $this->_params['invoice_id'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE)); if (!empty($this->_params['send_receipt'])) { $this->_params['receipt_date'] = $now; $this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($this->_params['receipt_date'])); } else { $this->_params['receipt_date'] = NULL; } if ($this->_mode) { $this->_params['register_date'] = $now; $this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for renewal"); $this->_params['amount'] = $this->_params['total_amount']; // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the passed params // so we copy stuff over to first_name etc. $paymentParams = $this->_params; if (!empty($this->_params['send_receipt'])) { $paymentParams['email'] = $this->_contributorEmail; } $paymentParams['contactID'] = $this->_contributorContactID; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE); $payment = $this->_paymentProcessor['object']; if (!empty($this->_params['auto_renew'])) { $contributionRecurParams = $this->processRecurringContribution($paymentParams); $contributionRecurID = $contributionRecurParams['contributionRecurID']; $paymentParams = array_merge($paymentParams, $contributionRecurParams); } $result = $payment->doPayment($paymentParams); $this->_params = array_merge($this->_params, $result); $this->_params['contribution_status_id'] = $result['payment_status_id']; $this->_params['trxn_id'] = $result['trxn_id']; $this->_params['payment_instrument_id'] = 1; $this->_params['is_test'] = $this->_mode == 'live' ? 0 : 1; $this->set('params', $this->_params); $this->assign('trxn_id', $result['trxn_id']); } $renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = CRM_Utils_Date::processDate($this->_params['renewal_date']) : NULL; // check for test membership. $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test'); // chk for renewal for multiple terms CRM-8750 $numRenewTerms = 1; if (is_numeric(CRM_Utils_Array::value('num_terms', $this->_params))) { $numRenewTerms = $this->_params['num_terms']; } //if contribution status is pending then set pay later $this->_params['is_pay_later'] = FALSE; if ($this->_params['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) { $this->_params['is_pay_later'] = 1; } // These variable sets prior to renewMembership may not be required for this form. They were in // a function this form shared with other forms. $membershipSource = NULL; if (!empty($this->_params['membership_source'])) { $membershipSource = $this->_params['membership_source']; } $isPending = $this->_params['contribution_status_id'] == 2 ? TRUE : FALSE; list($renewMembership) = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_params['membership_type_id'][1], $isTestMembership, $renewalDate, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId, $isPending, $contributionRecurID, $membershipSource, $this->_params['is_pay_later'], CRM_Utils_Array::value('campaign_id', $this->_params)); $this->endDate = CRM_Utils_Date::processDate($renewMembership->end_date); $this->membershipTypeName = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name'); if (!empty($this->_params['record_contribution']) || $this->_mode) { // set the source $this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})"; //create line items $lineItem = array(); $this->_params = $this->setPriceSetParameters($this->_params); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$this->_priceSetId]); //CRM-11529 for quick config backoffice transactions //when financial_type_id is passed in form, update the //line items with the financial type selected in form if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $this->_params)) { foreach ($lineItem[$this->_priceSetId] as &$li) { $li['financial_type_id'] = $submittedFinancialType; } } if (!empty($lineItem)) { $this->_params['lineItems'] = $lineItem; $this->_params['processPriceSet'] = TRUE; } //assign contribution contact id to the field expected by recordMembershipContribution if ($this->_contributorContactID != $this->_contactID) { $this->_params['contribution_contact_id'] = $this->_contributorContactID; if (!empty($this->_params['soft_credit_type_id'])) { $this->_params['soft_credit'] = array('soft_credit_type_id' => $this->_params['soft_credit_type_id'], 'contact_id' => $this->_contactID); } } $this->_params['contact_id'] = $this->_contactID; //recordMembershipContribution receives params as a reference & adds one variable. This is // not a great pattern & ideally it would not receive as a reference. We assign our params as a // temporary variable to avoid e-notice & to make it clear to future refactorer that // this function is NOT reliant on that var being set $temporaryParams = array_merge($this->_params, array('membership_id' => $renewMembership->id)); CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams); } if (!empty($this->_params['send_receipt'])) { $receiptFrom = $this->_params['from_email_address']; if (!empty($this->_params['payment_instrument_id'])) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $this->_params['paidBy'] = $paymentInstrument[$this->_params['payment_instrument_id']]; } //get the group Tree $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, FALSE, $this->_memType); // retrieve custom data $customFields = $customValues = $fo = array(); foreach ($this->_groupTree as $groupID => $group) { if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } } $members = array(array('member_id', '=', $this->_membershipId, 0, 0)); // check whether its a test drive if ($this->_mode == 'test') { $members[] = array('member_test', '=', 1, 0, 0); } CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members); $this->assign_by_ref('formValues', $this->_params); if (!empty($this->_params['contribution_id'])) { $this->assign('contributionID', $this->_params['contribution_id']); } $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id)); $this->assign('customValues', $customValues); $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date)); $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date)); if ($this->_mode) { // assign the address formatted up for display $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}"); $addressFields = array(); foreach ($addressParts as $part) { list($n) = explode('-', $part); if (isset($this->_params['billing_' . $part])) { $addressFields[$n] = $this->_params['billing_' . $part]; } } $this->assign('address', CRM_Utils_Address::format($addressFields)); $this->assign('contributeMode', 'direct'); $this->assign('isAmountzero', 0); $this->assign('is_pay_later', 0); $this->assign('isPrimary', 1); $this->assign('receipt_text_renewal', $this->_params['receipt_text']); if ($this->_mode == 'test') { $this->assign('action', '1024'); } } list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_receiptContactId, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test')); } }
/** * Method to fix membership status of stale membership * * This method first checks if the membership is stale. If it is, * then status will be updated based on existing start and end * dates and log will be added for the status change. * * @param array $currentMembership referance to the array * containing all values of * the current membership * @param array $changeToday array of month, day, year * values in case today needs * to be customised, null otherwise * * @return void * @static */ static function fixMembershipStatusBeforeRenew(&$currentMembership, $changeToday) { $today = CRM_Utils_Date::getToday($changeToday); require_once 'CRM/Member/BAO/MembershipStatus.php'; $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($currentMembership['start_date'], $currentMembership['end_date'], $currentMembership['join_date'], $today); if (empty($status) || empty($status['id'])) { CRM_Core_Error::fatal(ts('Oops, it looks like there is no valid membership status corresponding to the membership start and end dates for this membership. Contact the site administrator for assistance.')); } $currentMembership['today_date'] = $today; if ($status['id'] !== $currentMembership['status_id']) { $memberDAO = new CRM_Member_BAO_Membership(); $memberDAO->id = $currentMembership['id']; $memberDAO->find(true); $memberDAO->status_id = $status['id']; $memberDAO->join_date = CRM_Utils_Date::isoToMysql($memberDAO->join_date); $memberDAO->start_date = CRM_Utils_Date::isoToMysql($memberDAO->start_date); $memberDAO->end_date = CRM_Utils_Date::isoToMysql($memberDAO->end_date); $memberDAO->save(); CRM_Core_DAO::storeValues($memberDAO, $currentMembership); $memberDAO->free(); $currentMembership['is_current_member'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $currentMembership['status_id'], 'is_current_member'); $format = '%Y%m%d'; $logParams = array('membership_id' => $currentMembership['id'], 'status_id' => $status['id'], 'start_date' => CRM_Utils_Date::customFormat($currentMembership['start_date'], $format), 'end_date' => CRM_Utils_Date::customFormat($currentMembership['end_date'], $format), 'modified_id' => $currentMembership['contact_id'], 'modified_date' => CRM_Utils_Date::customFormat($currentMembership['today_date'], $format), 'renewal_reminder_date' => CRM_Utils_Date::customFormat($currentMembership['reminder_date'], $format)); $dontCare = null; require_once 'CRM/Member/BAO/MembershipLog.php'; CRM_Member_BAO_MembershipLog::add($logParams, $dontCare); } }
/** * Process the renewal form. * * * @return void */ public function postProcess() { $ids = array(); $config = CRM_Core_Config::singleton(); // get the submitted form values. $this->_params = $formValues = $this->controller->exportValues($this->_name); $this->storeContactFields($formValues); // use values from screen if ($formValues['membership_type_id'][1] != 0) { $defaults['receipt_text_renewal'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1], 'receipt_text_renewal'); } $now = CRM_Utils_Date::getToday(NULL, 'YmdHis'); $this->convertDateFieldsToMySQL($formValues); $this->assign('receive_date', $formValues['receive_date']); if (!empty($this->_params['send_receipt'])) { $formValues['receipt_date'] = $now; $this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($formValues['receipt_date'])); } else { $formValues['receipt_date'] = NULL; } if ($this->_mode) { $formValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee')); if (empty($formValues['financial_type_id'])) { $formValues['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id'); } $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode); $fields = array(); // set email for primary location. $fields['email-Primary'] = 1; $formValues['email-5'] = $formValues['email-Primary'] = $this->_contributorEmail; $formValues['register_date'] = $now; // now set the values for the billing location. foreach ($this->_fields as $name => $dontCare) { $fields[$name] = 1; } // also add location name to the array $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues); $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]); $fields["address_name-{$this->_bltID}"] = 1; $fields["email-{$this->_bltID}"] = 1; $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'); $nameFields = array('first_name', 'middle_name', 'last_name'); foreach ($nameFields as $name) { $fields[$name] = 1; if (array_key_exists("billing_{$name}", $formValues)) { $formValues[$name] = $formValues["billing_{$name}"]; $formValues['preserveDBName'] = TRUE; } } //here we are setting up the billing contact - if different from the member they are already created // but they will get billing details assigned CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contributorContactID, NULL, NULL, $ctype); // add all the additional payment params we need $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); $this->_params['description'] = ts('Office Credit Card Membership Renewal Contribution'); $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $formValues['total_amount']; $this->_params['currencyID'] = $config->defaultCurrency; $this->_params['payment_action'] = 'Sale'; $paymentParams['invoiceID'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE)); // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the passed params // so we copy stuff over to first_name etc. $paymentParams = $this->_params; if (!empty($this->_params['send_receipt'])) { $paymentParams['email'] = $this->_contributorEmail; } $paymentParams['contactID'] = $this->_contributorContactID; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE); $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); if (!empty($paymentParams['auto_renew'])) { $contributionRecurParams = $this->processRecurringContribution($paymentParams); $this->_params['contributionRecurID'] = $contributionRecurParams['contributionRecurID']; $paymentParams = array_merge($paymentParams, $contributionRecurParams); } $result = $payment->doDirectPayment($paymentParams); if (is_a($result, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}")); } if ($result) { $this->_params = array_merge($this->_params, $result); } $formValues['contribution_status_id'] = 1; $formValues['invoice_id'] = $this->_params['invoiceID']; $formValues['trxn_id'] = $result['trxn_id']; $formValues['payment_instrument_id'] = 1; $formValues['is_test'] = $this->_mode == 'live' ? 0 : 1; $this->set('params', $this->_params); $this->assign('trxn_id', $result['trxn_id']); } $renewalDate = NULL; if ($formValues['renewal_date']) { $this->set('renewalDate', CRM_Utils_Date::processDate($formValues['renewal_date'])); } $this->_membershipId = $this->_id; // membership type custom data $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $formValues['membership_type_id'][1]); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE)); $customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership'); // check for test membership. $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test'); // chk for renewal for multiple terms CRM-8750 $numRenewTerms = 1; if (is_numeric(CRM_Utils_Array::value('num_terms', $formValues))) { $numRenewTerms = $formValues['num_terms']; } //if contribution status is pending then set pay later if ($formValues['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) { $this->_params['is_pay_later'] = 1; } $renewMembership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($this->_contactID, $formValues['membership_type_id'][1], $isTestMembership, $this, NULL, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId); $endDate = CRM_Utils_Date::processDate($renewMembership->end_date); // Retrieve the name and email of the current user - this will be the FROM for the receipt email $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); $memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name'); if (!empty($formValues['record_contribution']) || $this->_mode) { // set the source $formValues['contribution_source'] = "{$memType} Membership: Offline membership renewal (by {$userName})"; //create line items $lineItem = array(); $priceSetId = NULL; CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]); //CRM-11529 for quick config backoffice transactions //when financial_type_id is passed in form, update the //line items with the financial type selected in form if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues)) { foreach ($lineItem[$priceSetId] as &$li) { $li['financial_type_id'] = $submittedFinancialType; } } $formValues['total_amount'] = CRM_Utils_Array::value('amount', $this->_params); if (!empty($lineItem)) { $formValues['lineItems'] = $lineItem; $formValues['processPriceSet'] = TRUE; } //assign contribution contact id to the field expected by recordMembershipContribution if ($this->_contributorContactID != $this->_contactID) { $formValues['contribution_contact_id'] = $this->_contributorContactID; if (!empty($this->_params['soft_credit_type_id'])) { $formValues['soft_credit'] = array('soft_credit_type_id' => $this->_params['soft_credit_type_id'], 'contact_id' => $this->_contactID); } } $formValues['contact_id'] = $this->_contactID; //recordMembershipContribution receives params as a reference & adds one variable. This is // not a great pattern & ideally it would not receive as a reference. We assign our params as a // temporary variable to avoid e-notice & to make it clear to future refactorer that // this function is NOT reliant on that var being set $temporaryParams = array_merge($formValues, array('membership_id' => $renewMembership->id)); CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams); } $receiptSend = FALSE; if (!empty($formValues['send_receipt'])) { $receiptSend = TRUE; $receiptFrom = $formValues['from_email_address']; if (!empty($formValues['payment_instrument_id'])) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']]; } //get the group Tree $this->_groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, FALSE, $this->_memType); // retrieve custom data $customFields = $customValues = $fo = array(); foreach ($this->_groupTree as $groupID => $group) { if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } } $members = array(array('member_id', '=', $this->_membershipId, 0, 0)); // check whether its a test drive if ($this->_mode == 'test') { $members[] = array('member_test', '=', 1, 0, 0); } CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members); $this->assign_by_ref('formValues', $formValues); if (!empty($formValues['contribution_id'])) { $this->assign('contributionID', $formValues['contribution_id']); } $this->assign('membershipID', $this->_id); $this->assign('contactID', $this->_contactID); $this->assign('module', 'Membership'); $this->assign('receiptType', 'membership renewal'); $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date)); $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date)); $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id)); $this->assign('customValues', $customValues); if ($this->_mode) { if (!empty($this->_params['billing_first_name'])) { $name = $this->_params['billing_first_name']; } if (!empty($this->_params['billing_middle_name'])) { $name .= " {$this->_params['billing_middle_name']}"; } if (!empty($this->_params['billing_last_name'])) { $name .= " {$this->_params['billing_last_name']}"; } $this->assign('billingName', $name); // assign the address formatted up for display $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}"); $addressFields = array(); foreach ($addressParts as $part) { list($n, $id) = explode('-', $part); if (isset($this->_params['billing_' . $part])) { $addressFields[$n] = $this->_params['billing_' . $part]; } } $this->assign('address', CRM_Utils_Address::format($addressFields)); $date = CRM_Utils_Date::format($this->_params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_exp_date', $date); $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number'])); $this->assign('credit_card_type', $this->_params['credit_card_type']); $this->assign('contributeMode', 'direct'); $this->assign('isAmountzero', 0); $this->assign('is_pay_later', 0); $this->assign('isPrimary', 1); if ($this->_mode == 'test') { $this->assign('action', '1024'); } } list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_receiptContactId, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test')); } $statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $memType, 2 => $this->_memberDisplayName)); if ($endDate) { $statusMsg .= ' ' . ts('The new membership End Date is %1.', array(1 => CRM_Utils_Date::customFormat(substr($endDate, 0, 8)))); } if ($receiptSend && $mailSend) { $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail)); } CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success'); }
protected function buildExtraDataDefaultQuickForm(CRM_Core_Form $form) { require_once 'CRM/Finance/BAO/BatchType.php'; require_once 'CRM/Finance/BAO/BankAccount.php'; require_once 'CRM/Contribute/PseudoConstant.php'; $form->add('text', 'batch_title', ts('Batch Title'), null, true); $form->add('textarea', 'description', ts('Description'), null, false); $emptySelect1[''] = '- select -'; $bankAccounts = CRM_Finance_BAO_BankAccount::getBankAccountsList($emptySelect1); $form->add('select', 'banking_account', ts('Bank Account'), $bankAccounts, true); //TODO: how to get this in civicrm default format? $current = CRM_Utils_Date::getToday(null, 'm/d/Y'); $form->addDate('banking_date', ts('Banking Date'), true, array('formatType' => 'activityDate', 'value' => $current)); $form->addElement('checkbox', 'exclude_from_posting', ts('Exclude from posting'), null, null); $emptySelect[''] = '- select -'; $contributionTypes = CRM_Finance_BAO_BatchType::getContributionTypesList($emptySelect); $form->add('select', 'contribution_type_id', ts('Contribution Type'), $contributionTypes, true); $el = $form->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), true); $el->setValue($this->getDefaultPaymentMethodId()); if (!in_array('campaign_id', $this->hideDefaultFields)) { $form->add('text', 'campaign_name', ts('Default Campaign Code'), array('class' => 'form text huge'), true); $form->add('hidden', 'campaign_id'); } if (!in_array('received_date', $this->hideDefaultFields)) { $form->addDate('received_date', ts('Received date'), true, array('formatType' => 'activityDate', 'value' => $current)); } //$form->add('select', 'contribution_type_id', ts('Contribution Type ID'), array(''=>ts( '- select -' )) + CRM_Contribute_PseudoConstant::contributionType( ), true ); //matusz: http://support.vedaconsulting.co.uk/issues/81 //$form->addDate( 'expected_posting_date', ts('Expected posting date'), true, array('formatType' => 'activityDate') ); $form->addFormRule(array($this, 'extraDataQuickFormRule')); }
/** * Function to process the renewal form * * @access public * @return None */ public function postProcess() { require_once 'CRM/Member/BAO/Membership.php'; require_once 'CRM/Member/BAO/MembershipType.php'; require_once 'CRM/Member/BAO/MembershipStatus.php'; // get the submitted form values. $this->_params = $formValues = $this->controller->exportValues($this->_name); $params = array(); $ids = array(); $config =& CRM_Core_Config::singleton(); $params['contact_id'] = $this->_contactID; if ($this->_mode) { $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'); $formValues['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'contribution_type_id'); require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode); require_once "CRM/Contact/BAO/Contact.php"; $now = CRM_Utils_Date::getToday($now, 'YmdHis'); $fields = array(); // set email for primary location. $fields["email-Primary"] = 1; $formValues["email-5"] = $formValues["email-Primary"] = $this->_contributorEmail; $formValues['register_date'] = $now; // now set the values for the billing location. foreach ($this->_fields as $name => $dontCare) { $fields[$name] = 1; } // also add location name to the array $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues); $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]); $fields["address_name-{$this->_bltID}"] = 1; $fields["email-{$this->_bltID}"] = 1; $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'); $nameFields = array('first_name', 'middle_name', 'last_name'); foreach ($nameFields as $name) { $fields[$name] = 1; if (array_key_exists("billing_{$name}", $formValues)) { $formValues[$name] = $formValues["billing_{$name}"]; $formValues['preserveDBName'] = true; } } $contactID = CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contactID, null, null, $ctype); // add all the additioanl payment params we need $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); $this->_params['year'] = $this->_params['credit_card_exp_date']['Y']; $this->_params['month'] = $this->_params['credit_card_exp_date']['M']; $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $formValues['total_amount']; $this->_params['currencyID'] = $config->defaultCurrency; $this->_params['payment_action'] = 'Sale'; $this->_params['invoiceID'] = md5(uniqid(rand(), true)); // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $paymentParams['email'] = $this->_contributorEmail; } require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true); $payment =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $this->_paymentProcessor, $this); $result =& $payment->doDirectPayment($paymentParams); if (is_a($result, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}")); } if ($result) { $this->_params = array_merge($this->_params, $result); } $formValues['contribution_status_id'] = 1; $formValues['receive_date'] = $now; $formValues['invoice_id'] = $this->_params['invoiceID']; $formValues['trxn_id'] = $result['trxn_id']; $formValues['payment_instrument_id'] = 1; $formValues['is_test'] = $this->_mode == 'live' ? 0 : 1; if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $formValues['receipt_date'] = $now; } else { $formValues['receipt_date'] = null; } $this->set('params', $this->_params); $this->assign('trxn_id', $result['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($formValues['receive_date'])); } $renewalDate = null; if ($formValues['renewal_date']) { $this->set('renewDate', CRM_Utils_Date::processDate($formValues['renewal_date'])); } $this->_membershipId = $this->_id; // check for test membership. $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test'); $renewMembership = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_memType, $isTestMembership, $this, null); $endDate = CRM_Utils_Date::processDate($renewMembership->end_date); require_once 'CRM/Contact/BAO/Contact/Location.php'; // Retrieve the name and email of the current user - this will be the FROM for the receipt email $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); $memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name'); if (CRM_Utils_Array::value('record_contribution', $formValues) || $this->_mode) { //building contribution params $contributionParams = array(); $config =& CRM_Core_Config::singleton(); $contributionParams['currency'] = $config->defaultCurrency; $contributionParams['contact_id'] = $params['contact_id']; $contributionParams['source'] = "{$memType} Membership: Offline membership renewal (by {$userName})"; $contributionParams['non_deductible_amount'] = 'null'; $contributionParams['receive_date'] = date('Y-m-d H:i:s'); $contributionParams['receipt_date'] = CRM_Utils_Array::value('send_receipt', $formValues) ? $contributionParams['receive_date'] : 'null'; $recordContribution = array('total_amount', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'invoice_id', 'check_number', 'is_test'); foreach ($recordContribution as $f) { $contributionParams[$f] = CRM_Utils_Array::value($f, $formValues); } require_once 'CRM/Contribute/BAO/Contribution.php'; $contribution =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); require_once 'CRM/Member/DAO/MembershipPayment.php'; $mpDAO =& new CRM_Member_DAO_MembershipPayment(); $mpDAO->membership_id = $renewMembership->id; $mpDAO->contribution_id = $contribution->id; $mpDAO->save(); if ($this->_mode) { $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $formValues['total_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $formValues['total_amount']), 'currency' => $config->defaultCurrency, 'payment_processor' => $this->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']); require_once 'CRM/Contribute/BAO/FinancialTrxn.php'; $trxn =& CRM_Contribute_BAO_FinancialTrxn::create($trxnParams); } } if (CRM_Utils_Array::value('send_receipt', $formValues)) { require_once 'CRM/Core/DAO.php'; CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipType', CRM_Utils_Array::value('membership_type_id', $params), 'receipt_text_renewal', $formValues['receipt_text_renewal']); } $receiptSend = false; if (CRM_Utils_Array::value('send_receipt', $formValues)) { $receiptSend = true; // Retrieve the name and email of the contact - this will be the TO for receipt email list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $receiptFrom = '"' . $userName . '" <' . $userEmail . '>'; $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']]; //get the group Tree $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, false, $this->_memType); // retrieve custom data require_once "CRM/Core/BAO/UFGroup.php"; $customFields = $customValues = $fo = array(); foreach ($this->_groupTree as $groupID => $group) { if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } } CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, false, array(array('member_id', '=', $renewMembership->id, 0, 0))); $this->assign_by_ref('formValues', $formValues); $this->assign('receive_date', $renewalDate); $this->assign('module', 'Membership'); $this->assign('receiptType', 'membership renewal'); $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date)); $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date)); $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id)); $this->assign('customValues', $customValues); if ($this->_mode) { if (CRM_Utils_Array::value('billing_first_name', $this->_params)) { $name = $this->_params['billing_first_name']; } if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) { $name .= " {$this->_params['billing_middle_name']}"; } if (CRM_Utils_Array::value('billing_last_name', $this->_params)) { $name .= " {$this->_params['billing_last_name']}"; } $this->assign('billingName', $name); // assign the address formatted up for display $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}"); $addressFields = array(); foreach ($addressParts as $part) { list($n, $id) = explode('-', $part); if (isset($this->_params['billing_' . $part])) { $addressFields[$n] = $this->_params['billing_' . $part]; } } require_once 'CRM/Utils/Address.php'; $this->assign('address', CRM_Utils_Address::format($addressFields)); $date = CRM_Utils_Date::format($this->_params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_exp_date', $date); $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number'])); $this->assign('credit_card_type', $this->_params['credit_card_type']); $this->assign('contributeMode', 'direct'); $this->assign('isAmountzero', 0); $this->assign('is_pay_later', 0); $this->assign('isPrimary', 1); if ($this->_mode == 'test') { $this->assign('action', '1024'); } } require_once 'CRM/Core/BAO/MessageTemplates.php'; list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_contactID, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test')); } $statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $memType, 2 => $this->_contributorDisplayName)); $endDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "end_date")); if ($endDate) { $statusMsg .= ' ' . ts('The new membership End Date is %1.', array(1 => $endDate)); } if ($receiptSend && $mailSend) { $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail)); } CRM_Core_Session::setStatus($statusMsg); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { require_once "CRM/Member/BAO/MembershipType.php"; require_once "CRM/Member/BAO/Membership.php"; CRM_Utils_System::setTitle(ts('CiviMember')); $membershipSummary = array(); $preMonth = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d'); $preMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d'); $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4)); $today = getdate(); $date = CRM_Utils_Date::getToday(); $isCurrentMonth = 0; if ($ym = CRM_Utils_Array::value('date', $_GET)) { if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) { CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym))); } $isPreviousMonth = 0; $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon']; $ymd = date('Ymd', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4))); $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4)); $current = CRM_Utils_Date::customFormat($date, '%Y%m%d'); } else { $ym = sprintf("%04d%02d", $today['year'], $today['mon']); $ymd = sprintf("%04d%02d%02d", $today['year'], $today['mon'], $today['mday']); $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']); $current = null; $isCurrentMonth = 1; $isPreviousMonth = 1; } $monthStart = $ym . '01'; $yearStart = substr($ym, 0, 4) . '0101'; $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(false); //$membership = new CRM_Member_BAO_Membership;//added foreach ($membershipTypes as $key => $value) { $membershipSummary[$key]['premonth'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['month'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['year'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['current'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value); $membershipSummary[$key]['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd)); } require_once "CRM/Member/BAO/MembershipStatus.php"; $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent(); $status = implode(',', $status); foreach ($membershipSummary as $typeID => $details) { foreach ($details as $key => $value) { switch ($key) { case 'premonth': $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}"); break; case 'month': $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}"); break; case 'year': $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}"); break; case 'current': $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}"); break; case 'total': if (!$isCurrentMonth) { $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}"); } else { $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"); } break; } } } $totalCount = array(); $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0; foreach ($membershipSummary as $key => $value) { $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['count']; $totalCountMonth = $totalCountMonth + $value['month']['count']; $totalCountYear = $totalCountYear + $value['year']['count']; $totalCountCurrent = $totalCountCurrent + $value['current']['count']; $totalCountTotal = $totalCountTotal + $value['total']['count']; } $totalCount['premonth'] = array("count" => $totalCountPreMonth, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}")); $totalCount['month'] = array("count" => $totalCountMonth, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}")); $totalCount['year'] = array("count" => $totalCountYear, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}")); $totalCount['current'] = array("count" => $totalCountCurrent, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}")); $totalCount['total'] = array("count" => $totalCountTotal, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}")); if (!$isCurrentMonth) { $totalCount['total'] = array("count" => $totalCountTotal, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}")); } $this->assign('membershipSummary', $membershipSummary); $this->assign('totalCount', $totalCount); $this->assign('month', date('F', $monthStartTs)); $this->assign('year', date('Y', $monthStartTs)); $this->assign('premonth', date('F', $preMonthYear)); $this->assign('currentMonth', date('F')); $this->assign('currentYear', date('Y')); $this->assign('isCurrent', $isCurrentMonth); $this->assign('preMonth', $isPreviousMonth); }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { CRM_Utils_System::setTitle(ts('CiviMember')); $membershipSummary = array(); $preMonth = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d'); $preMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d'); $prePreMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 2, 01, date("Y"))), '%Y%m%d'); $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4)); $today = getdate(); $date = CRM_Utils_Date::getToday(); $isCurrentMonth = 0; $ym = CRM_Utils_Array::value('date', $_GET); if ($ym) { if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) { CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym))); } $isPreviousMonth = 0; $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon']; $ymd = date('Ymd', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4))); $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4)); $current = CRM_Utils_Date::customFormat($date, '%Y%m%d'); } else { $ym = sprintf("%04d%02d", $today['year'], $today['mon']); $ymd = sprintf("%04d%02d%02d", $today['year'], $today['mon'], $today['mday']); $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']); $current = NULL; $isCurrentMonth = 1; $isPreviousMonth = 1; } $monthStart = $ym . '01'; $yearStart = substr($ym, 0, 4) . '0101'; // $preMonthStart is the day before $monthStart $preMonthStart = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, substr($ym, 4, 2) - 1, 01, substr($ym, 0, 4))), '%Y%m%d'); // $preYearStart is the day before $yearStart $preYearStart = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, 12, 31, substr($ym, 0, 4) - 1)), '%Y%m%d'); $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); // added //$membership = new CRM_Member_BAO_Membership; foreach ($membershipTypes as $key => $value) { $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value); $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value); $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value); $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value); $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd)); //LCD also get summary stats for membership owners $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), 'name' => $value); $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), 'name' => $value); $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), 'name' => $value); $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), 'name' => $value); $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1)); //LCD end } // LCD debug //CRM_Core_Error::debug($membershipSummary); $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent(); $status = implode(',', $status); foreach ($membershipSummary as $typeID => $details) { foreach ($details as $key => $value) { switch ($key) { case 'premonth': $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$preMonth}&joinEnd={$preMonthEnd}&start={$preMonth}&end={$preMonthEnd}"); $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$prePreMonthEnd}&start={$preMonth}&end={$preMonthEnd}"); $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}"); break; case 'month': $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$monthStart}&joinEnd={$ymd}&start={$monthStart}&end={$ymd}"); $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$preMonthStart}&start={$monthStart}&end={$ymd}"); $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}"); break; case 'year': $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$yearStart}&joinEnd={$ymd}&start={$yearStart}&end={$ymd}"); $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$preYearStart}&start={$yearStart}&end={$ymd}"); $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}"); break; case 'current': $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}"); break; case 'total': if (!$isCurrentMonth) { $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}"); } else { $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"); } break; //LCD add owner urls //LCD add owner urls case 'premonth_owner': $membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}&owner=1"); break; case 'month_owner': $membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}&owner=1"); break; case 'year_owner': $membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}&owner=1"); break; case 'current_owner': $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&owner=1"); break; case 'total_owner': if (!$isCurrentMonth) { $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}&owner=1"); } else { $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1"); } break; //LCD end } } } // LCD debug //CRM_Core_Error::debug($membershipSummary); $totalCount = array(); $newCountPreMonth = $newCountMonth = $newCountYear = 0; $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0; $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0; $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0; foreach ($membershipSummary as $key => $value) { $newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count']; $renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count']; $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count']; $newCountMonth = $newCountMonth + $value['month']['new']['count']; $renewCountMonth = $renewCountMonth + $value['month']['renew']['count']; $totalCountMonth = $totalCountMonth + $value['month']['total']['count']; $newCountYear = $newCountYear + $value['year']['new']['count']; $renewCountYear = $renewCountYear + $value['year']['renew']['count']; $totalCountYear = $totalCountYear + $value['year']['total']['count']; $totalCountCurrent = $totalCountCurrent + $value['current']['total']['count']; $totalCountTotal = $totalCountTotal + $value['total']['total']['count']; //LCD add owner values $totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count']; $totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count']; $totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count']; $totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count']; $totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count']; } $totalCount['premonth']['new'] = array('count' => $newCountPreMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&join={$preMonth}&joinEnd={$preMonthEnd}&start={$preMonth}&end={$preMonthEnd}")); $totalCount['premonth']['renew'] = array('count' => $renewCountPreMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&joinEnd={$prePreMonthEnd}&start={$preMonth}&end={$preMonthEnd}")); $totalCount['premonth']['total'] = array('count' => $totalCountPreMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}")); $totalCount['month']['new'] = array('count' => $newCountMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&join={$monthStart}&joinEnd={$ymd}&start={$monthStart}&end={$ymd}")); $totalCount['month']['renew'] = array('count' => $renewCountMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&joinEnd={$preMonthStart}&start={$monthStart}&end={$ymd}")); $totalCount['month']['total'] = array('count' => $totalCountMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}")); $totalCount['year']['new'] = array('count' => $newCountYear, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&join={$yearStart}&joinEnd={$ymd}&start={$yearStart}&end={$ymd}")); $totalCount['year']['renew'] = array('count' => $renewCountYear, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&joinEnd={$preYearStart}&start={$yearStart}&end={$ymd}")); $totalCount['year']['total'] = array('count' => $totalCountYear, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}")); $totalCount['current']['total'] = array('count' => $totalCountCurrent, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}")); $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}")); if (!$isCurrentMonth) { $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}")); } //LCD add owner values $totalCount['premonth_owner']['premonth_owner'] = array('count' => $totalCountPreMonth_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}&owner=1")); $totalCount['month_owner']['month_owner'] = array('count' => $totalCountMonth_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}&owner=1")); $totalCount['year_owner']['year_owner'] = array('count' => $totalCountYear_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}&owner=1")); $totalCount['current_owner']['current_owner'] = array('count' => $totalCountCurrent_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1")); $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1")); if (!$isCurrentMonth) { $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}&owner=1")); } //LCD end $this->assign('membershipSummary', $membershipSummary); $this->assign('totalCount', $totalCount); $this->assign('month', date('F', $monthStartTs)); $this->assign('year', date('Y', $monthStartTs)); $this->assign('premonth', date('F', $preMonthYear)); $this->assign('currentMonth', date('F')); $this->assign('currentYear', date('Y')); $this->assign('isCurrent', $isCurrentMonth); $this->assign('preMonth', $isPreviousMonth); }
static function isActive($code) { if (empty($code['active_on'])) { return TRUE; } $time = CRM_Utils_Date::getToday(null, 'Y-m-d H:i:s'); if (strtotime($time) > abs(strtotime($code['active_on']))) { return TRUE; } return FALSE; }
/** * Function to calculate start date and end date for renewal membership * * @param int $membershipId * * @return Array array fo the start date, end date and join date of the membership * @static */ function getRenewalDatesForMembershipType($membershipId, $changeToday = null) { require_once 'CRM/Member/BAO/Membership.php'; require_once 'CRM/Member/BAO/MembershipStatus.php'; $params = array('id' => $membershipId); $membership =& new CRM_Member_BAO_Membership(); //$membership->copyValues( $params ); $membership->id = $membershipId; $membership->find(true); $membershipDetails = CRM_Member_BAO_Membership::getValues($params, $values); $statusID = $membershipDetails[$membershipId]->status_id; $membershipTypeDetails = self::getMembershipTypeDetails($membershipDetails[$membershipId]->membership_type_id); $statusDetails = CRM_Member_BAO_MembershipStatus::getMembershipStatus($statusID); if ($statusDetails['is_current_member'] == 1) { $startDate = $membershipDetails[$membershipId]->start_date; $date = explode('-', $membershipDetails[$membershipId]->end_date); $logStartDate = date('Y-m-d', mktime(0, 0, 0, (double) $date[1], (double) ($date[2] + 1), (double) $date[0])); $date = explode('-', $logStartDate); $year = $date[0]; $month = $date[1]; $day = $date[2]; switch ($membershipTypeDetails['duration_unit']) { case 'year': $year = $year + $membershipTypeDetails['duration_interval']; break; case 'month': $month = $month + $membershipTypeDetails['duration_interval']; break; case 'day': $day = $day + $membershipTypeDetails['duration_interval']; break; } if ($membershipTypeDetails['duration_unit'] == 'lifetime') { $endDate = null; } else { $endDate = date('Y-m-d', mktime(0, 0, 0, $month, $day - 1, $year)); } $today = date('Y-m-d'); } else { $today = CRM_Utils_Date::getToday($changeToday); $rollover = false; if ($membershipTypeDetails['period_type'] == 'rolling') { $startDate = $logStartDate = $today; } else { if ($membershipTypeDetails['period_type'] == 'fixed') { // Renewing expired membership is two step process. // 1. Renew the start date // 2. Renew the end date // 1. $date = explode('-', $membershipDetails[$membershipId]->start_date); $yearValue = date('Y'); $startDate = $logStartDate = date('Y-m-d', mktime(0, 0, 0, (double) $date[1], (double) $date[2], $yearValue)); // before moving to the step 2, check if TODAY is in // rollover window. $rolloverDay = substr($membershipTypeDetails['fixed_period_rollover_day'], -2); $rolloverMonth = substr($membershipTypeDetails['fixed_period_rollover_day'], 0, -2); $fixedStartMonth = substr($membershipTypeDetails['fixed_period_start_day'], 0, -2); if ($rolloverMonth - $fixedStartMonth < 0) { $rolloverDate = date('Ymd', mktime(0, 0, 0, (double) $rolloverMonth, (double) $rolloverDay, $yearValue + 1)); } else { $rolloverDate = date('Ymd', mktime(0, 0, 0, (double) $rolloverMonth, (double) $rolloverDay, $yearValue)); } if (CRM_Utils_Date::isoToMysql($today) > $rolloverDate) { $rollover = true; } } } // 2. $date = explode('-', $startDate); $year = (double) $date[0]; $month = (double) $date[1]; $day = (double) $date[2]; switch ($membershipTypeDetails['duration_unit']) { case 'year': $year = $year + $membershipTypeDetails['duration_interval']; if ($rollover) { $year = $year + $membershipTypeDetails['duration_interval']; } break; case 'month': $month = $month + $membershipTypeDetails['duration_interval']; if ($rollover) { $month = $month + $membershipTypeDetails['duration_interval']; } break; case 'day': $day = $day + $membershipTypeDetails['duration_interval']; if ($rollover) { $day = $day + $membershipTypeDetails['duration_interval']; } break; } if ($membershipTypeDetails['duration_unit'] == 'lifetime') { $endDate = null; } else { $endDate = date('Y-m-d', mktime(0, 0, 0, $month, $day - 1, $year)); } } $membershipDates = array(); $membershipDates['today'] = CRM_Utils_Date::customFormat($today, '%Y%m%d'); $membershipDates['start_date'] = CRM_Utils_Date::customFormat($startDate, '%Y%m%d'); $membershipDates['end_date'] = CRM_Utils_Date::customFormat($endDate, '%Y%m%d'); if (CRM_Utils_Array::value("renewal_reminder_day", $membershipTypeDetails)) { $date = explode('-', $endDate); $year = $date[0]; $month = $date[1]; $day = $date[2]; $day = $day - $membershipTypeDetails["renewal_reminder_day"]; $reminderDate = date('Y-m-d', mktime(0, 0, 0, $month, $day - 1, $year)); $membershipDates['reminder_date'] = CRM_Utils_Date::customFormat($reminderDate, '%Y%m%d'); } $membershipDates['log_start_date'] = CRM_Utils_Date::customFormat($logStartDate, '%Y%m%d'); return $membershipDates; }
static function processSignOut($pickupName, $studentID, $atSchoolMeeting = false) { static $_now = null; static $_date = null; if (!$_now) { $_now = CRM_Utils_Date::getToday(null, 'YmdHis'); } if (!$_date) { $_date = CRM_Utils_Date::getToday(null, 'Y-m-d'); } if ($atSchoolMeeting === 'true') { $atSchoolMeeting = 1; } else { if ($atSchoolMeeting === 'false') { $atSchoolMeeting = 0; } } $atSchoolMeeting = $atSchoolMeeting ? '1' : '0'; $sql = "\nSELECT e.id, e.class, s.location\nFROM civicrm_value_extended_care_signout e\nINNER JOIN sfschool_extended_care_source s ON ( e.class = s.name )\nWHERE entity_id = %1\nAND signin_time LIKE '{$_date}%'\nAND ( is_morning = 0 OR is_morning IS NULL )\nAND s.day_of_week = DAYNAME( '{$_date}' )\n"; $params = array(1 => array($studentID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); $params = array(1 => array($studentID, 'Integer'), 2 => array($pickupName, 'String'), 3 => array($_now, 'Timestamp'), 4 => array($atSchoolMeeting, 'Integer')); $class = null; if ($dao->fetch()) { if ($dao->location) { $class = "{$dao->class} ({$dao->location})"; } else { $class = $dao->class; } $sql = "\nUPDATE civicrm_value_extended_care_signout\nSET pickup_person_name = %2,\n signout_time = %3,\n at_school_meeting = %4\nWHERE id = %5\n"; $params[5] = array($dao->id, 'Integer'); } else { $sql = "\nINSERT INTO civicrm_value_extended_care_signout\n( entity_id, pickup_person_name, signin_time, signout_time, at_school_meeting, is_morning )\nVALUES\n( %1, %2, %3, %3, %4, 0 )\n"; } CRM_Core_DAO::executeQuery($sql, $params); return $class; }
protected function migrateData() { CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS civicrm_hrpay_scale"); CRM_Core_DAO::executeQuery("\n CREATE TABLE IF NOT EXISTS `civicrm_hrpay_scale` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `pay_scale` VARCHAR(63) DEFAULT NULL,\n `pay_grade` VARCHAR(63) DEFAULT NULL,\n `currency` VARCHAR(63) DEFAULT NULL,\n `amount` DECIMAL(10,2) DEFAULT NULL,\n `periodicity` VARCHAR(63) DEFAULT NULL,\n `is_active` tinyint(4) DEFAULT '1',\n PRIMARY KEY(id)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1\n "); CRM_Core_DAO::executeQuery("\n INSERT INTO `civicrm_hrpay_scale` (`pay_scale`, `pay_grade`, `currency`, `amount`, `periodicity`, `is_active`) VALUES\n ('US', 'Senior', 'USD', 38000, 'Year', 1),\n ('US', 'Junior', 'USD', 24000, 'Year', 1),\n ('UK', 'Senior', 'GBP', 35000, 'Year', 1),\n ('UK', 'Junior', 'GBP', 22000, 'Year', 1),\n ('Not Applicable', NULL, NULL, NULL, NULL, 1)\n "); $tableExists = $this->checkTableExists(array('civicrm_hrjob', 'civicrm_hrjob_health', 'civicrm_hrjob_hour', 'civicrm_hrjob_leave', 'civicrm_hrjob_pay', 'civicrm_hrjob_pension', 'civicrm_hrjob_role', 'civicrm_value_job_summary_10')); if (!$tableExists['civicrm_hrjob']) { return false; } $hrJob = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob ORDER BY id ASC'); while ($hrJob->fetch()) { // Creating Job Contract: $insertContractQuery = 'INSERT INTO civicrm_hrjobcontract SET contact_id = %1, is_primary = %2'; $insertContractParams = array(1 => array($hrJob->contact_id, 'Integer'), 2 => array($hrJob->is_primary, 'Integer')); CRM_Core_DAO::executeQuery($insertContractQuery, $insertContractParams); $jobContractId = (int) CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); // Creating Job Contract Revision: $insertRevisionQuery = 'INSERT INTO civicrm_hrjobcontract_revision SET jobcontract_id = %1'; $insertRevisionParams = array(1 => array($jobContractId, 'Integer')); CRM_Core_DAO::executeQuery($insertRevisionQuery, $insertRevisionParams); $revisionId = (int) CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); // Populating data with existing HRJob entities: $this->populateTableWithEntity('civicrm_hrjobcontract_details', $hrJob, array('position' => 'String', 'title' => 'String', 'funding_notes' => 'String', 'contract_type' => 'String', 'period_start_date' => 'Date', 'period_end_date' => 'Date', 'notice_amount' => 'Float', 'notice_unit' => 'String', 'notice_amount_employee' => 'Float', 'notice_unit_employee' => 'String', 'location' => 'String'), $revisionId); $healthRevisionId = 0; if ($tableExists['civicrm_hrjob_health']) { $hrJobHealth = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob_health WHERE job_id = %1', array(1 => array($hrJob->id, 'Integer'))); while ($hrJobHealth->fetch()) { $this->populateTableWithEntity('civicrm_hrjobcontract_health', $hrJobHealth, array('provider' => 'Integer', 'plan_type' => 'String', 'description' => 'String', 'dependents' => 'String', 'provider_life_insurance' => 'Integer', 'plan_type_life_insurance' => 'String', 'description_life_insurance' => 'String', 'dependents_life_insurance' => 'String'), $revisionId); $healthRevisionId = $revisionId; } } $hourRevisionId = 0; if ($tableExists['civicrm_hrjob_hour']) { $hrJobHour = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob_hour WHERE job_id = %1', array(1 => array($hrJob->id, 'Integer'))); while ($hrJobHour->fetch()) { $this->populateTableWithEntity('civicrm_hrjobcontract_hour', $hrJobHour, array('hours_type' => 'String', 'hours_amount' => 'Float', 'hours_unit' => 'String', 'hours_fte' => 'Float', 'fte_num' => 'Integer', 'fte_denom' => 'Integer'), $revisionId); $hourRevisionId = $revisionId; } } // MULTIPLE $leaveRevisionId = 0; if ($tableExists['civicrm_hrjob_leave']) { $hrJobLeave = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob_leave WHERE job_id = %1', array(1 => array($hrJob->id, 'Integer'))); while ($hrJobLeave->fetch()) { $this->populateTableWithEntity('civicrm_hrjobcontract_leave', $hrJobLeave, array('leave_type' => 'Integer', 'leave_amount' => 'Integer'), $revisionId); $leaveRevisionId = $revisionId; } } $payRevisionId = 0; if ($tableExists['civicrm_hrjob_pay']) { $hrJobPay = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob_pay WHERE job_id = %1', array(1 => array($hrJob->id, 'Integer'))); while ($hrJobPay->fetch()) { $payScaleId = $this->getPayScaleId($hrJobPay->pay_scale); $hrJobPay->pay_scale = $payScaleId; $this->populateTableWithEntity('civicrm_hrjobcontract_pay', $hrJobPay, array('pay_scale' => 'String', 'is_paid' => 'Integer', 'pay_amount' => 'Float', 'pay_unit' => 'String', 'pay_currency' => 'String', 'pay_annualized_est' => 'Float', 'pay_is_auto_est' => 'Integer'), $revisionId); $payRevisionId = $revisionId; } } $pensionRevisionId = 0; if ($tableExists['civicrm_hrjob_pension']) { $hrJobPension = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob_pension WHERE job_id = %1', array(1 => array($hrJob->id, 'Integer'))); while ($hrJobPension->fetch()) { $this->populateTableWithEntity('civicrm_hrjobcontract_pension', $hrJobPension, array('is_enrolled' => 'Integer', 'ee_contrib_pct' => 'Float', 'er_contrib_pct' => 'Float', 'pension_type' => 'String', 'ee_contrib_abs' => 'Float', 'ee_evidence_note' => 'String'), $revisionId); $pensionRevisionId = $revisionId; } } // MULTIPLE $roleRevisionId = 0; if ($tableExists['civicrm_hrjob_role']) { $hrJobRole = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjob_role WHERE job_id = %1', array(1 => array($hrJob->id, 'Integer'))); while ($hrJobRole->fetch()) { $this->populateTableWithEntity('civicrm_hrjobcontract_role', $hrJobRole, array('title' => 'String', 'description' => 'String', 'hours' => 'Float', 'role_hours_unit' => 'String', 'region' => 'String', 'department' => 'String', 'level_type' => 'String', 'manager_contact_id' => 'Integer', 'functional_area' => 'String', 'organization' => 'String', 'cost_center' => 'String', 'funder' => 'String', 'percent_pay_funder' => 'String', 'percent_pay_role' => 'Integer', 'location' => 'String'), $revisionId); $roleRevisionId = $revisionId; } } // Creating entities entries with default values for non existing entities. if (!$healthRevisionId) { CRM_Core_DAO::executeQuery('INSERT INTO civicrm_hrjobcontract_health SET jobcontract_revision_id = %1', array(1 => array($revisionId, 'Integer'))); } if (!$hourRevisionId) { CRM_Core_DAO::executeQuery('INSERT INTO civicrm_hrjobcontract_hour SET jobcontract_revision_id = %1', array(1 => array($revisionId, 'Integer'))); } if (!$payRevisionId) { CRM_Core_DAO::executeQuery('INSERT INTO civicrm_hrjobcontract_pay SET jobcontract_revision_id = %1', array(1 => array($revisionId, 'Integer'))); } if (!$pensionRevisionId) { CRM_Core_DAO::executeQuery('INSERT INTO civicrm_hrjobcontract_pension SET jobcontract_revision_id = %1', array(1 => array($revisionId, 'Integer'))); } $effectiveDate = null; $periodStartDate = explode('-', $hrJob->period_start_date); if (count($periodStartDate) === 3) { $effectiveDate = array('month' => $periodStartDate[1], 'day' => $periodStartDate[2], 'year' => $periodStartDate[0]); } // Updating Revision: $updateRevisionQuery = 'UPDATE civicrm_hrjobcontract_revision SET ' . 'effective_date = %12,' . 'details_revision_id = %1,' . 'health_revision_id = %2,' . 'hour_revision_id = %3,' . 'leave_revision_id = %4,' . 'pay_revision_id = %5,' . 'pension_revision_id = %6,' . 'role_revision_id = %7,' . 'created_date = %8,' . 'modified_date = %9,' . 'status = %10' . ' WHERE id = %11'; $updateRevisionParams = array(1 => array($revisionId, 'Integer'), 2 => array($revisionId, 'Integer'), 3 => array($revisionId, 'Integer'), 4 => array($leaveRevisionId, 'Integer'), 5 => array($revisionId, 'Integer'), 6 => array($revisionId, 'Integer'), 7 => array($roleRevisionId, 'Integer'), 8 => array(CRM_Utils_Date::getToday(null, 'YmdHis'), 'Timestamp'), 9 => array(CRM_Utils_Date::getToday(null, 'YmdHis'), 'Timestamp'), 10 => array(1, 'Integer'), 11 => array($revisionId, 'Integer'), 12 => array(CRM_Utils_Date::getToday($effectiveDate, 'Ymd'), 'Timestamp')); CRM_Core_DAO::executeQuery($updateRevisionQuery, $updateRevisionParams); } // Migrating Job_Summary data: if ($tableExists['civicrm_value_job_summary_10']) { CRM_Core_DAO::executeQuery('INSERT INTO civicrm_value_jobcontract_summary_10 SELECT * FROM civicrm_value_job_summary_10'); } return true; }
/** * Function to create / update / delete membership for related contacts. * * This function will create/update/delete membership for related * contact based on 1) contact have active membership 2) that * membership is is extedned by the same relationship type to that * of the existing relationship. * * @param $contactId Int contact id * @param $params array array of values submitted by POST * @param $ids array array of ids * @param $action which action called this function * * @static * */ static function relatedMemberships($contactId, &$params, $ids, $action = CRM_Core_Action::ADD, $active = true) { // Check the end date and set the status of the relationship // accrodingly. $status = self::CURRENT; if (!empty($params['end_date']['Y']) && !empty($params['end_date']['M']) && !empty($params['end_date']['d'])) { $endDate = date('Ymd', mktime(0, 0, 0, $params['end_date']['M'], $params['end_date']['d'], $params['end_date']['Y'])); $today = CRM_Utils_Date::customFormat(CRM_Utils_Date::getToday(), '%Y%m%d'); if ($today > $endDate) { $status = self::PAST; } } if ($action & CRM_Core_Action::ADD && $status & self::PAST) { // if relationship is PAST and action is ADD, no qustion // of creating RELATED membership and return back to // calling method return; } $rel = explode("_", $params['relationship_type_id']); $relTypeId = $rel[0]; $relDirection = "_{$rel[1]}_{$rel[2]}"; $targetContact = array(); if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::DELETE) { $contact = $contactId; $targetContact = CRM_Utils_Array::value('contact_check', $params); } else { if ($action & CRM_Core_Action::UPDATE) { $contact = $ids['contact']; $targetContact = array($ids['contactTarget'] => 1); } } // Build the 'values' array for // 1. ContactA // 2. ContactB // This will allow us to check if either of the contacts in // relationship have active memberships. $values = array(); // 1. ContactA $values[$contact] = array('relatedContacts' => $targetContact, 'relationshipTypeId' => $relTypeId, 'relationshipTypeDirection' => $relDirection); // 2. ContactB if (!empty($targetContact)) { foreach ($targetContact as $cid => $donCare) { $values[$cid] = array('relatedContacts' => array($contact => 1), 'relationshipTypeId' => $relTypeId); $relTypeParams = array('id' => $relTypeId); $relTypeValues = array(); require_once 'CRM/Contact/BAO/RelationshipType.php'; CRM_Contact_BAO_RelationshipType::retrieve($relTypeParams, $relTypeValues); if (CRM_Utils_Array::value('name_a_b', $relTypeValues) == CRM_Utils_Array::value('name_b_a', $relTypeValues)) { $values[$cid]['relationshipTypeDirection'] = '_a_b'; } else { $values[$cid]['relationshipTypeDirection'] = $relDirection == '_a_b' ? '_b_a' : '_a_b'; } } } // Now get the active memberships for all the contacts. // If contact have any valid membership(s), then add it to // 'values' array. foreach ($values as $cid => $subValues) { $memParams = array('contact_id' => $cid); $memberships = array(); require_once 'CRM/Member/BAO/Membership.php'; CRM_Member_BAO_Membership::getValues($memParams, $memberships, $active); if (empty($memberships)) { continue; } $values[$cid]['memberships'] = $memberships; } // done with 'values' array. // Finally add / edit / delete memberships for the related contacts foreach ($values as $cid => $details) { if (!array_key_exists('memberships', $details)) { continue; } require_once 'CRM/Member/BAO/MembershipType.php'; foreach ($details['memberships'] as $membershipId => $membershipValues) { if ($action & CRM_Core_Action::DELETE) { // delete memberships of the related contacts. CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId); continue; } if ($action & CRM_Core_Action::UPDATE && $status & self::PAST && $membershipValues['owner_membership_id']) { // If relationship is PAST and action is UPDATE // then delete the RELATED membership CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipValues['owner_membership_id'], $membershipValues['membership_contact_id']); continue; } // add / edit the memberships for related // contacts. // Get the Membership Type Details. $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipValues['membership_type_id']); if ("{$details['relationshipTypeId']}{$details['relationshipTypeDirection']}" == CRM_Utils_Array::value('relationship_type_id', $membershipType) . "_" . CRM_Utils_Array::value('relationship_direction', $membershipType)) { // Check if relationship being created/updated is // similar to that of membership type's // relationship. $membershipValues['owner_membership_id'] = $membershipId; unset($membershipValues['id']); unset($membershipValues['membership_contact_id']); unset($membershipValues['contact_id']); unset($membershipValues['membership_id']); foreach ($details['relatedContacts'] as $relatedContactId => $donCare) { $membershipValues['contact_id'] = $relatedContactId; if ($action & CRM_Core_Action::UPDATE) { //delete the membership record for related //contact before creating new membership record. CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId); } CRM_Member_BAO_Membership::create($membershipValues, CRM_Core_DAO::$_nullArray); } } else { if ($action & CRM_Core_Action::UPDATE) { // if action is update and updated relationship do // not match with the existing // membership=>relationship then we need to // delete the membership record created for // previous relationship. CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $ids['contactTarget']); } } } } }