public function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE); $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); $this->_formType = CRM_Utils_Array::value('formType', $_GET); $enitityType = NULL; if ($this->_component == 'event') { $enitityType = 'participant'; $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id'); } $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id'); $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId); $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $enitityType); $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component); $this->_amtPaid = $paymentDetails['paid']; $this->_amtTotal = $paymentDetails['total']; if (!empty($paymentInfo['refund_due'])) { $paymentAmt = $this->_refund = $paymentInfo['refund_due']; $this->_paymentType = 'refund'; } elseif (!empty($paymentInfo['amount_owed'])) { $paymentAmt = $this->_owed = $paymentInfo['amount_owed']; $this->_paymentType = 'owed'; } else { CRM_Core_Error::fatal(ts('No payment information found for this record')); } //set the payment mode - _mode property is defined in parent class $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); if (!empty($this->_mode) && $this->_paymentType == 'refund') { CRM_Core_Error::fatal(ts('Credit card payment is not for Refund payments use')); } list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); if (!$this->_refund) { $this->assignProcessors(); // also check for billing information // get the billing location type $this->assignBillingType(); } $this->assign('contributionMode', $this->_mode); $this->assign('contactId', $this->_contactId); $this->assign('component', $this->_component); $this->assign('id', $this->_id); $this->assign('paymentType', $this->_paymentType); $this->assign('paymentAmt', abs($paymentAmt)); $this->_paymentProcessor = array('billing_mode' => 1); $title = $this->_refund ? "Refund for {$this->_contributorDisplayName}" : "Payment from {$this->_contributorDisplayName}"; if ($title) { CRM_Utils_System::setTitle(ts('%1', array(1 => $title))); } }
/** * Get list of payments displayed by Contribute_Page_PaymentInfo. * * @param int $id * @param $component * @param bool $getTrxnInfo * @param bool $usingLineTotal * * @return mixed */ public static function getPaymentInfo($id, $component, $getTrxnInfo = FALSE, $usingLineTotal = FALSE) { if ($component == 'event') { $entity = 'participant'; $entityTable = 'civicrm_participant'; $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id'); if (!$contributionId) { if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $id, 'registered_by_id')) { $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id'); $id = $primaryParticipantId; } if (!$contributionId) { return; } } } $total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); $baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL; $isBalance = NULL; if ($baseTrxnId) { $isBalance = TRUE; } else { $baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId); $baseTrxnId = $baseTrxnId['financialTrxnId']; $isBalance = FALSE; } if (!CRM_Utils_Array::value('total_amount', $total) || $usingLineTotal) { // for additional participants if ($entityTable == 'civicrm_participant') { $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); $total = 0; foreach ($ids as $val) { $total += CRM_Price_BAO_LineItem::getLineTotal($val, $entityTable); } } else { $total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable); } } else { $baseTrxnId = $total['trxn_id']; $total = $total['total_amount']; } $paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total); $contributionIsPayLater = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'is_pay_later'); $feeRelationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' ")); $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'financial_type_id'); $feeFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $feeRelationTypeId); if ($paymentBalance == 0 && $contributionIsPayLater) { $paymentBalance = $total; } $info['total'] = $total; $info['paid'] = $total - $paymentBalance; $info['balance'] = $paymentBalance; $info['id'] = $id; $info['component'] = $component; $info['payLater'] = $contributionIsPayLater; $rows = array(); if ($getTrxnInfo && $baseTrxnId) { // Need to exclude fee trxn rows so filter out rows where TO FINANCIAL ACCOUNT is expense account $sql = "\nSELECT ft.total_amount, con.financial_type_id, ft.payment_instrument_id, ft.trxn_date, ft.trxn_id, ft.status_id, ft.check_number\nFROM civicrm_contribution con\n LEFT JOIN civicrm_entity_financial_trxn eft ON (eft.entity_id = con.id AND eft.entity_table = 'civicrm_contribution')\n INNER JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id AND ft.to_financial_account_id != {$feeFinancialAccount}\nWHERE con.id = {$contributionId}\n"; // conditioned WHERE clause if ($isBalance) { // if balance trxn exists don't include details of it in transaction info $sql .= " AND ft.id != {$baseTrxnId} "; } $resultDAO = CRM_Core_DAO::executeQuery($sql); $statuses = CRM_Contribute_PseudoConstant::contributionStatus(); $financialTypes = CRM_Contribute_PseudoConstant::financialType(); while ($resultDAO->fetch()) { $paidByLabel = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id); $paidByName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id); $val = array('total_amount' => $resultDAO->total_amount, 'financial_type' => $financialTypes[$resultDAO->financial_type_id], 'payment_instrument' => $paidByLabel, 'receive_date' => $resultDAO->trxn_date, 'trxn_id' => $resultDAO->trxn_id, 'status' => $statuses[$resultDAO->status_id]); if ($paidByName == 'Check') { $val['check_number'] = $resultDAO->check_number; } $rows[] = $val; } $info['transaction'] = $rows; } return $info; }
public function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE); $this->_view = CRM_Utils_Request::retrieve('view', 'String', $this, FALSE); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); $this->assign('component', $this->_component); $this->assign('id', $this->_id); $this->assign('suppressPaymentFormButtons', $this->isBeingCalledFromSelectorContext()); if ($this->_view == 'transaction' && $this->_action & CRM_Core_Action::BROWSE) { $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, TRUE); $transactionRows = $paymentInfo['transaction']; $title = ts('View Payment'); if ($this->_component == 'event') { $info = CRM_Event_BAO_Participant::participantDetails($this->_id); $title .= " - {$info['title']}"; } CRM_Utils_System::setTitle($title); $this->assign('transaction', TRUE); $this->assign('rows', $transactionRows); return; } $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); $this->_formType = CRM_Utils_Array::value('formType', $_GET); $enitityType = NULL; if ($this->_component == 'event') { $enitityType = 'participant'; $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id'); } $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id'); $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId); $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $enitityType); $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE); $this->_amtPaid = $paymentDetails['paid']; $this->_amtTotal = $paymentDetails['total']; if (!empty($paymentInfo['refund_due'])) { $paymentAmt = $this->_refund = $paymentInfo['refund_due']; $this->_paymentType = 'refund'; } elseif (!empty($paymentInfo['amount_owed'])) { $paymentAmt = $this->_owed = $paymentInfo['amount_owed']; $this->_paymentType = 'owed'; } else { CRM_Core_Error::fatal(ts('No payment information found for this record')); } //set the payment mode - _mode property is defined in parent class $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); if (!empty($this->_mode) && $this->_paymentType == 'refund') { CRM_Core_Error::fatal(ts('Credit card payment is not for Refund payments use')); } list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); $this->assignPaymentRelatedVariables(); $this->assign('contributionMode', $this->_mode); $this->assign('contactId', $this->_contactId); $this->assign('paymentType', $this->_paymentType); $this->assign('paymentAmt', abs($paymentAmt)); $this->setPageTitle($this->_refund ? ts('Refund') : ts('Payment')); }
function getPaymentInfo($id, $component, $getTrxnInfo = FALSE) { if ($component == 'event') { $entity = 'participant'; $entityTable = 'civicrm_participant'; $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id'); } $total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); $baseTrxnId = NULL; if (empty($total)) { $total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable); } else { $baseTrxnId = $total['trxn_id']; $total = $total['total_amount']; } $paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total); $info['total'] = $total; $info['paid'] = $total - $paymentBalance; $info['balance'] = $paymentBalance; $info['id'] = $id; $info['component'] = $component; $rows = array(); if ($getTrxnInfo && $baseTrxnId) { $sql = "\nSELECT ft.total_amount, con.financial_type_id, ft.payment_instrument_id, ft.trxn_date, ft.trxn_id, ft.status_id\nFROM civicrm_contribution con\n LEFT JOIN civicrm_entity_financial_trxn eft ON (eft.entity_id = con.id AND eft.entity_table = 'civicrm_contribution')\n LEFT JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id\nWHERE ft.id != {$baseTrxnId} AND con.id = {$contributionId}\n"; $resultDAO = CRM_Core_DAO::executeQuery($sql); while ($resultDAO->fetch()) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $statuses = CRM_Contribute_PseudoConstant::contributionStatus(); $financialTypes = CRM_Contribute_PseudoConstant::financialType(); $rows[] = array('total_amount' => $resultDAO->total_amount, 'financial_type' => $financialTypes[$resultDAO->financial_type_id], 'payment_instrument' => $paymentInstrument[$resultDAO->payment_instrument_id], 'receive_date' => $resultDAO->trxn_date, 'trxn_id' => $resultDAO->trxn_id, 'status' => $statuses[$resultDAO->status_id]); } $info['transaction'] = $rows; } return $info; }