本文整理汇总了PHP中CRM_Price_BAO_LineItem::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Price_BAO_LineItem::create方法的具体用法?PHP CRM_Price_BAO_LineItem::create怎么用?PHP CRM_Price_BAO_LineItem::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Price_BAO_LineItem
的用法示例。
在下文中一共展示了CRM_Price_BAO_LineItem::create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processPriceSet
/**
* Process price set and line items.
*
* @param int $membershipId
* @param array $lineItem
*/
public function processPriceSet($membershipId, $lineItem)
{
//FIXME : need to move this too
if (!$membershipId || !is_array($lineItem) || CRM_Utils_System::isNull($lineItem)) {
return;
}
foreach ($lineItem as $priceSetId => $values) {
if (!$priceSetId) {
continue;
}
foreach ($values as $line) {
$line['entity_table'] = 'civicrm_membership';
$line['entity_id'] = $membershipId;
CRM_Price_BAO_LineItem::create($line);
}
}
}
示例2: processPriceSet
/**
* Process price set and line items.
*
* @param int $entityId
* @param array $lineItem
* Line item array.
* @param object $contributionDetails
* @param string $entityTable
* Entity table.
*
* @param bool $update
*
* @return void
*/
public static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
{
if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
return;
}
foreach ($lineItem as $priceSetId => $values) {
if (!$priceSetId) {
continue;
}
foreach ($values as $line) {
$line['entity_table'] = $entityTable;
if (empty($line['entity_id'])) {
$line['entity_id'] = $entityId;
}
if (!empty($line['membership_type_id'])) {
$line['entity_table'] = 'civicrm_membership';
}
if (!empty($contributionDetails->id)) {
$line['contribution_id'] = $contributionDetails->id;
if ($line['entity_table'] == 'civicrm_contribution') {
$line['entity_id'] = $contributionDetails->id;
}
}
// if financial type is not set and if price field value is NOT NULL
// get financial type id of price field value
if (!empty($line['price_field_value_id']) && empty($line['financial_type_id'])) {
$line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
}
$lineItems = CRM_Price_BAO_LineItem::create($line);
if (!$update && $contributionDetails) {
CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
if (isset($line['tax_amount'])) {
CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails, TRUE);
}
}
}
}
}
示例3: changeFeeSelections
/**
* @param array $params
* @param int $participantId
* @param int $contributionId
* @param $feeBlock
* @param array $lineItems
* @param $paidAmount
* @param int $priceSetId
*/
public static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId)
{
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
$previousLineItems = CRM_Price_BAO_LineItem::getLineItems($participantId, 'participant');
CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItems);
// get the submitted
foreach ($feeBlock as $id => $values) {
CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
$submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
}
if (!empty($submittedLineItems)) {
$insertLines = $submittedLineItems;
$submittedFieldValueIds = array_keys($submittedLineItems);
$updateLines = array();
foreach ($previousLineItems as $id => $previousLineItem) {
// check through the submitted items if the previousItem exists,
// if found in submitted items, do not use it for new item creations
if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
// if submitted line items are existing don't fire INSERT query
unset($insertLines[$previousLineItem['price_field_value_id']]);
// for updating the line items i.e. use-case - once deselect-option selecting again
if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] || $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] == 0 && $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'] == 1 || $previousLineItem['qty'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['qty']) {
$updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
$updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
}
}
}
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
}
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nSET li.qty = 0,\n li.line_total = 0.00,\n li.tax_amount = NULL\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id NOT IN ({$submittedFieldValues}))\n";
CRM_Core_DAO::executeQuery($updateLineItem);
// gathering necessary info to record negative (deselected) financial_item
$updateFinancialItem = "\n SELECT fi.*, SUM(fi.amount) as differenceAmt, price_field_value_id, financial_type_id, tax_amount\n FROM civicrm_financial_item fi LEFT JOIN civicrm_line_item li ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})\nGROUP BY li.entity_table, li.entity_id, price_field_value_id, fi.id\n";
$updateFinancialItemInfoDAO = CRM_Core_DAO::executeQuery($updateFinancialItem);
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId, 'DESC', TRUE);
$trxnId['id'] = $trxn['financialTrxnId'];
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$updateFinancialItemInfoValues = array();
$financialItemsArray = array();
while ($updateFinancialItemInfoDAO->fetch()) {
$updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO;
$updateFinancialItemInfoValues['transaction_date'] = date('YmdHis');
// the below params are not needed
unset($updateFinancialItemInfoValues['id']);
unset($updateFinancialItemInfoValues['created_date']);
// if not submitted and difference is not 0 make it negative
if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
// INSERT negative financial_items
$updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
if ($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']) {
$updateFinancialItemInfoValues['tax']['amount'] = -$previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount'];
$updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
if ($updateFinancialItemInfoValues['financial_type_id']) {
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateFinancialItemInfoValues['financial_type_id']);
}
}
// INSERT negative financial_items for tax amount
$financialItemsArray[] = $updateFinancialItemInfoValues;
} elseif (in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] == 0) {
$updateFinancialItemInfoValues['amount'] = $updateFinancialItemInfoValues['amount'];
// INSERT financial_items for tax amount
if ($updateFinancialItemInfoValues['entity_id'] == $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['id'] && isset($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'])) {
$updateFinancialItemInfoValues['tax']['amount'] = $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'];
$updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
if ($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']) {
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']);
}
}
$financialItemsArray[] = $updateFinancialItemInfoValues;
}
}
} elseif (empty($submittedFields) && empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li\n INNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\n SET li.qty = 0,\n li.line_total = 0.00,\n li.tax_amount = NULL\n WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})";
CRM_Core_DAO::executeQuery($updateLineItem);
}
$amountLevel = array();
$totalParticipant = $participantCount = 0;
if (!empty($updateLines)) {
foreach ($updateLines as $valueId => $vals) {
$taxAmount = "NULL";
if (isset($vals['tax_amount'])) {
$taxAmount = $vals['tax_amount'];
}
$amountLevel[] = $vals['label'] . ' - ' . (double) $vals['qty'];
if (isset($vals['participant_count'])) {
$participantCount = $vals['participant_count'];
//.........这里部分代码省略.........
示例4: processPriceSet
/**
* Function to process price set and line items.
* @param int $contributionId contribution id
* @param array $lineItem line item array
* @param object $contributionDetails
* @param decimal $initAmount amount
* @param string $entityTable entity table
*
* @access public
* @return void
* @static
*/
static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
{
if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
return;
}
foreach ($lineItem as $priceSetId => $values) {
if (!$priceSetId) {
continue;
}
foreach ($values as $line) {
$line['entity_table'] = $entityTable;
$line['entity_id'] = $entityId;
// if financial type is not set and if price field value is NOT NULL
// get financial type id of price field value
if (CRM_Utils_Array::value('price_field_value_id', $line) && !CRM_Utils_Array::value('financial_type_id', $line)) {
$line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
}
$lineItems = CRM_Price_BAO_LineItem::create($line);
if (!$update && $contributionDetails) {
CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
}
}
}
}
示例5: postProcess
//.........这里部分代码省略.........
//modify params according to parameter used in create
//participant method (addParticipant)
$params['participant_status_id'] = $params['status_id'];
$params['participant_role_id'] = $params['role_id'];
$params['participant_register_date'] = $params['register_date'];
$params['participant_source'] = $params['source'];
require_once 'CRM/Core/BAO/PaymentProcessor.php';
$this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
require_once "CRM/Contact/BAO/Contact.php";
$now = date('YmdHis');
$fields = array();
// set email for primary location.
$fields["email-Primary"] = 1;
$params["email-Primary"] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
$params['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
$params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
$params["address_name-{$this->_bltID}"] = trim($params["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}", $params)) {
$params[$name] = $params["billing_{$name}"];
$params['preserveDBName'] = true;
}
}
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, null, null, $ctype);
}
// build custom data getFields array
$customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('role_id', $params), $this->_roleCustomDataTypeID);
$customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', false, false, null, null, true));
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_participantId, 'Participant');
if ($this->_mode) {
// 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'] = $params['fee_amount'];
$this->_params['amount_level'] = $params['amount_level'];
$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, 'Event', $this->_paymentProcessor, $this);
$result =& $payment->doDirectPayment($paymentParams);
if (is_a($result, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
示例6: postProcess
//.........这里部分代码省略.........
} else {
if (CRM_Utils_Array::value('is_pay_later', $value) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') {
if ($value['amount'] != 0) {
$pending = true;
//get the participant statuses.
require_once 'CRM/Event/PseudoConstant.php';
$pendingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Pending'");
$status = CRM_Utils_Array::value('is_pay_later', $value) ? 'Pending from pay later' : 'Pending from incomplete transaction';
$value['participant_status_id'] = array_search($status, $pendingStatuses);
}
} else {
if ($this->_contributeMode == 'express' && CRM_Utils_Array::value('is_primary', $value)) {
$result =& $payment->doExpressCheckout($value);
} else {
if (CRM_Utils_Array::value('is_primary', $value)) {
require_once 'CRM/Core/Payment/Form.php';
CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, true);
$result =& $payment->doDirectPayment($value);
}
}
}
}
if (is_a($result, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
}
if ($result) {
$value = array_merge($value, $result);
}
$value['receive_date'] = $now;
if ($this->_allowConfirmation) {
$value['participant_register_date'] = $this->_values['participant']['register_date'];
}
$createContrib = $value['amount'] != 0 ? true : false;
// force to create zero amount contribution, CRM-5095
if (!$createContrib && $value['amount'] == 0 && $this->_priceSetId && $this->_lineItem) {
$createContrib = true;
}
if ($createContrib && CRM_Utils_Array::value('is_primary', $value) && !$this->_allowWaitlist && !$this->_requireApproval) {
// if paid event add a contribution record
//if primary participant contributing additional amount
//append (multiple participants) to its fee level. CRM-4196.
$isAdditionalAmount = false;
if (count($params) > 1) {
$isAdditionalAmount = true;
}
//passing contribution id is already registered.
$contribution =& self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount);
$value['contributionID'] = $contribution->id;
$value['contributionTypeID'] = $contribution->contribution_type_id;
$value['receive_date'] = $contribution->receive_date;
$value['trxn_id'] = $contribution->trxn_id;
$value['contributionID'] = $contribution->id;
$value['contributionTypeID'] = $contribution->contribution_type_id;
}
$value['contactID'] = $contactID;
$value['eventID'] = $this->_eventId;
$value['item_name'] = $value['description'];
}
//CRM-4453.
if (CRM_Utils_Array::value('is_primary', $value)) {
$primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value);
}
if (!CRM_Utils_Array::value('currencyID', $value)) {
$value['currencyID'] = $primaryCurrencyID;
}
示例7: testCreate
/**
* check method create()
*/
function testCreate()
{
$firstName = 'Shane';
$lastName = 'Whatson';
$params = array('first_name' => $firstName, 'last_name' => $lastName, 'contact_type' => 'Individual');
$contact = CRM_Contact_BAO_Contact::add($params);
$price = 100.0;
$cParams = array('contact_id' => $contact->id, 'total_amount' => $price, 'financial_type_id' => 1, 'is_active' => 1, 'skipLineItem' => 1);
$defaults = array();
$contribution = CRM_Contribute_BAO_Contribution::add($cParams, $defaults);
$lParams = array('entity_id' => $contribution->id, 'entity_table' => 'civicrm_contribution', 'price_field_id' => 1, 'qty' => 1, 'label' => 'Contribution Amount', 'unit_price' => $price, 'line_total' => $price, 'price_field_value_id' => 1, 'financial_type_id' => 1);
$lineItem = CRM_Price_BAO_LineItem::create($lParams);
$fParams = array('contact_id' => $contact->id, 'description' => 'Contribution Amount', 'amount' => $price, 'financial_account_id' => 1, 'status_id' => 1, 'transaction_date' => date('YmdHis'), 'entity_id' => $lineItem->id, 'entity_table' => 'civicrm_line_item');
CRM_Financial_BAO_FinancialItem::create($fParams);
$entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
$entityTrxn->entity_table = 'civicrm_contribution';
$entityTrxn->entity_id = $contribution->id;
$entityTrxn->amount = $price;
if ($entityTrxn->find(TRUE)) {
$entityId = $entityTrxn->entity_id;
}
$result = $this->assertDBNotNull('CRM_Financial_DAO_FinancialItem', $lineItem->id, 'amount', 'entity_id', 'Database check on added financial item record.');
$this->assertEquals($result, $price, 'Verify Amount for Financial Item');
$entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $entityId, 'amount', 'entity_id', 'Database check on added entity financial trxn record.');
$this->assertEquals($entityResult, $price, 'Verify Amount for Financial Item');
}
示例8: processPriceSet
/**
* Function to process price set and line items.
*
* @access public
* @return None
*/
function processPriceSet($contributionId, $lineItem)
{
if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
return;
}
require_once 'CRM/Price/BAO/Set.php';
require_once 'CRM/Price/BAO/LineItem.php';
foreach ($lineItem as $priceSetId => $values) {
if (!$priceSetId) {
continue;
}
foreach ($values as $line) {
$line['entity_table'] = 'civicrm_contribution';
$line['entity_id'] = $contributionId;
CRM_Price_BAO_LineItem::create($line);
}
CRM_Price_BAO_Set::addTo('civicrm_contribution', $contributionId, $priceSetId);
}
}
示例9: changeFeeSelections
/**
* @param $params
* @param $participantId
* @param $contributionId
* @param $feeBlock
* @param $lineItems
* @param $paidAmount
* @param $priceSetId
*/
static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId)
{
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);
$previousLineItems = CRM_Price_BAO_LineItem::getLineItems($participantId, 'participant');
CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItems);
// get the submitted
foreach ($feeBlock as $id => $values) {
CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
$submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
}
$insertLines = $submittedLineItems;
$submittedFieldValueIds = array_keys($submittedLineItems);
$updateLines = array();
foreach ($previousLineItems as $id => $previousLineItem) {
// check through the submitted items if the previousItem exists,
// if found in submitted items, do not use it for new item creations
if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
// if submitted line items are existing don't fire INSERT query
unset($insertLines[$previousLineItem['price_field_value_id']]);
// for updating the line items i.e. use-case - once deselect-option selecting again
if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) {
$updateLines[$previousLineItem['price_field_value_id']]['qty'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'];
$updateLines[$previousLineItem['price_field_value_id']]['line_total'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'];
}
}
}
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nSET li.qty = 0,\n li.line_total = 0.00\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id NOT IN ({$submittedFieldValues}))\n";
CRM_Core_DAO::executeQuery($updateLineItem);
// gathering necessary info to record negative (deselected) financial_item
$updateFinancialItem = "\n SELECT fi.*, SUM(fi.amount) as differenceAmt, price_field_value_id\n FROM civicrm_financial_item fi LEFT JOIN civicrm_line_item li ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})\nGROUP BY li.entity_table, li.entity_id, price_field_value_id\n";
$updateFinancialItemInfoDAO = CRM_Core_DAO::executeQuery($updateFinancialItem);
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId, 'ASC', TRUE);
$trxnId['id'] = $trxn['financialTrxnId'];
$updateFinancialItemInfoValues = array();
while ($updateFinancialItemInfoDAO->fetch()) {
$updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO;
$updateFinancialItemInfoValues['transaction_date'] = date('YmdHis');
// the below params are not needed
unset($updateFinancialItemInfoValues['id']);
unset($updateFinancialItemInfoValues['created_date']);
// if not submitted and difference is not 0 make it negative
if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
// INSERT negative financial_items
$updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
} elseif (in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] == 0) {
$updateFinancialItemInfoValues['amount'] = $updateFinancialItemInfoValues['amount'];
CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
}
}
}
if (!empty($updateLines)) {
foreach ($updateLines as $valueId => $vals) {
$updateLineItem = "\nUPDATE civicrm_line_item li\nSET li.qty = {$vals['qty']},\n li.line_total = {$vals['line_total']}\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id = {$valueId})\n";
CRM_Core_DAO::executeQuery($updateLineItem);
}
}
// insert new 'adjusted amount' transaction entry and update contribution entry.
// ensure entity_financial_trxn table has a linking of it.
// insert new line items
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineObj = CRM_Price_BAO_LineItem::create($lineParams);
}
// the recordAdjustedAmt code would execute over here
$ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
if (count($ids) > 1) {
$total = 0;
foreach ($ids as $val) {
$total += CRM_Price_BAO_LineItem::getLineTotal($val, 'civicrm_participant');
}
$updatedAmount = $total;
} else {
$updatedAmount = $params['amount'];
}
self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId);
$fetchCon = array('id' => $contributionId);
$updatedContribution = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
// insert financial items
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
// insert financial items
// ensure entity_financial_trxn table has a linking of it.
//.........这里部分代码省略.........
示例10: postProcess
/**
* Process transfer - first add the new participant to the event, then cancel
* source participant - send confirmation email to transferee
*/
public function postProcess()
{
//For transfer, process form to allow selection of transferree
$params = $this->controller->exportValues($this->_name);
//cancel 'from' participant row
$query = "select contact_id from civicrm_email where email = '" . $params['email'] . "'";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$contact_id = $dao->contact_id;
}
$from_participant = $params = array();
$query = "select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = " . $this->_from_participant_id;
$dao = CRM_Core_DAO::executeQuery($query);
$value_to = array();
while ($dao->fetch()) {
$value_to['role_id'] = $dao->role_id;
$value_to['source'] = $dao->source;
$value_to['fee_level'] = $dao->fee_level;
$value_to['is_test'] = $dao->is_test;
$value_to['is_pay_later'] = $dao->is_pay_later;
$value_to['fee_amount'] = $dao->fee_amount;
}
$value_to['contact_id'] = $contact_id;
$value_to['event_id'] = $this->_event_id;
$value_to['status_id'] = 1;
$value_to['register_date'] = date("Y-m-d");
//first create the new participant row -don't set registered_by yet or email won't be sent
$participant = CRM_Event_BAO_Participant::create($value_to);
//send a confirmation email to the new participant
$this->participantTransfer($participant);
//now update registered_by_id
$query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})";
$params = array(1 => array($this->_from_participant_id, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
//copy line items to new participant
$line_items = CRM_Price_BAO_LineItem::getLineItems($this->_from_participant_id);
foreach ($line_items as $item) {
$item['entity_id'] = $participant->id;
$item['id'] = NULL;
$item['entity_table'] = "civicrm_participant";
$new_item = CRM_Price_BAO_LineItem::create($item);
}
//now cancel the from participant record, leaving the original line-item(s)
$value_from = array();
$value_from['id'] = $this->_from_participant_id;
$tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
$value_from['status_id'] = $tansferId;
$value_from['transferred_to_contact_id'] = $contact_id;
$contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id);
$display_name = current($contact_details);
$this->assign('to_participant', $display_name);
CRM_Event_BAO_Participant::create($value_from);
$this->sendCancellation();
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $displayName));
$statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $email));
CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success');
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
CRM_Utils_System::redirect($url);
}
示例11: processPriceSet
/**
* Function to process price set and line items.
*
* @access public
*
* @return None
*/
function processPriceSet($contributionId, $lineItem, $entityTable = 'civicrm_contribution')
{
if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
return;
}
foreach ($lineItem as $priceSetId => $values) {
if (!$priceSetId) {
continue;
}
foreach ($values as $line) {
$line['entity_table'] = $entityTable;
$line['entity_id'] = $contributionId;
CRM_Price_BAO_LineItem::create($line);
}
}
}
示例12: updateAmountAndFeeLevel
/**
* Update price option label in line_item, civicrm_contribution and civicrm_participant.
*
* @param int $id - id of the price_field_value
* @param string $prevLabel
* @param string $newLabel
*
*/
public static function updateAmountAndFeeLevel($id, $prevLabel, $newLabel)
{
// update price field label in line item.
$lineItem = new CRM_Price_DAO_LineItem();
$lineItem->price_field_value_id = $id;
$lineItem->label = $prevLabel;
$lineItem->find();
while ($lineItem->fetch()) {
$lineItemParams['id'] = $lineItem->id;
$lineItemParams['label'] = $newLabel;
CRM_Price_BAO_LineItem::create($lineItemParams);
// update amount and fee level in civicrm_contribution and civicrm_participant
$params = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'), 2 => array(CRM_Core_DAO::VALUE_SEPARATOR . $newLabel . ' -', 'String'));
// Update contribution
if (!empty($lineItem->contribution_id)) {
CRM_Core_DAO::executeQuery("UPDATE `civicrm_contribution` SET `amount_level` = REPLACE(amount_level, %1, %2) WHERE id = {$lineItem->contribution_id}", $params);
}
// Update participant
if ($lineItem->entity_table == 'civicrm_participant') {
CRM_Core_DAO::executeQuery("UPDATE `civicrm_participant` SET `fee_level` = REPLACE(fee_level, %1, %2) WHERE id = {$lineItem->entity_id}", $params);
}
}
}
示例13: task_4_2_alpha1_convertParticipants
/**
* (Queue Task Callback)
*
* Find any participant records and create corresponding line-item
* records.
*
* @param $startId int, the first/lowest participant ID to convert
* @param $endId int, the last/highest participant ID to convert
*/
static function task_4_2_alpha1_convertParticipants(CRM_Queue_TaskContext $ctx, $startId, $endId)
{
$upgrade = new CRM_Upgrade_Form();
//create lineitems for participant in edge cases using default price set for contribution.
$query = "\nSELECT cp.id as participant_id, cp.fee_amount, cp.fee_level,ce.is_monetary,\n cpse.price_set_id, cpf.id as price_field_id, cpfv.id as price_field_value_id\nFROM civicrm_participant cp\nLEFT JOIN civicrm_line_item cli ON cli.entity_id=cp.id and cli.entity_table = 'civicrm_participant'\nLEFT JOIN civicrm_event ce ON ce.id=cp.event_id\nLEFT JOIN civicrm_price_set_entity cpse ON cp.event_id = cpse.entity_id and cpse.entity_table = 'civicrm_event'\nLEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cpse.price_set_id\nLEFT JOIN civicrm_price_field_value cpfv ON cpfv.price_field_id = cpf.id AND cpfv.label = cp.fee_level\nWHERE (cp.id BETWEEN %1 AND %2)\nAND cli.entity_id IS NULL AND cp.fee_amount IS NOT NULL";
$sqlParams = array(1 => array($startId, 'Integer'), 2 => array($endId, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
if ($dao->N) {
$defaultPriceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_contribution_amount', 'id', 'name');
$priceSets = current(CRM_Price_BAO_Set::getSetDetail($defaultPriceSetId));
$fieldID = key($priceSets['fields']);
}
while ($dao->fetch()) {
$lineParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $dao->participant_id, 'label' => $dao->fee_level ? $dao->fee_level : ts('Default'), 'qty' => 1, 'unit_price' => $dao->fee_amount, 'line_total' => $dao->fee_amount, 'participant_count' => 1);
if ($dao->is_monetary && $dao->price_field_id) {
$lineParams += array('price_field_id' => $dao->price_field_id, 'price_field_value_id' => $dao->price_field_value_id);
$priceSetId = $dao->price_set_id;
} else {
$lineParams['price_field_id'] = $fieldID;
$priceSetId = $defaultPriceSetId;
}
CRM_Price_BAO_LineItem::create($lineParams);
}
return TRUE;
}
示例14: changeFeeSelections
static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId)
{
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);
$fetchCon = array('id' => $contributionId);
$contributionObj = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
$previousLineItems = CRM_Price_BAO_LineItem::getLineItems($participantId, 'participant');
CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItems);
// get the submitted
foreach ($feeBlock as $id => $values) {
CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
$submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
}
$insertLines = $submittedLineItems;
$submittedFieldValueIds = array_keys($submittedLineItems);
foreach ($previousLineItems as $id => $previousLineItem) {
// check through the submitted items if the previousItem exists,
// if found in submitted items, do not use it for new item creations
if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
unset($insertLines[$previousLineItem['price_field_value_id']]);
}
}
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
// if previous line item is not submitted in selection, update the line total and QTY to '0'
$updateLineItem = "\nUPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nINNER JOIN civicrm_entity_financial_trxn eft\n ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item')\nSET li.qty = 0,\n li.line_total = 0.00,\n fi.amount = 0.00,\n eft.amount = 0.00\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id NOT IN ({$submittedFieldValues}) OR price_field_id NOT IN ({$submittedFields}))\n";
CRM_Core_DAO::executeQuery($updateLineItem);
}
// insert new line items
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineObj = CRM_Price_BAO_LineItem::create($lineParams);
// insert financial items
// ensure entity_financial_trxn table has a linking of it.
$prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $contributionObj);
}
// insert new 'adjusted amount' transaction entry and update contribution entry.
// ensure entity_financial_trxn table has a linking of it.
$updatedAmount = $params['amount'];
$balanceAmt = $updatedAmount - $paidAmount;
if ($balanceAmt) {
if ($balanceAmt > 0) {
$contributionStatusVal = $partiallyPaidStatusId;
} elseif ($balanceAmt < 0) {
$contributionStatusVal = $pendngRefundStatusId;
}
// update contribution status and total amount without trigger financial code
// as this is handled in current BAO function used for change selection
$updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
$updatedContributionDAO->id = $contributionId;
$updatedContributionDAO->contribution_status_id = $contributionStatusVal;
$updatedContributionDAO->total_amount = $updatedAmount;
$updatedContributionDAO->save();
/*
* adjusted amount financial_trxn creation,
* adjusted amount line_item creation,
* adjusted amount financial_item creations,
* adjusted amount enitity_financial_trxn creation
*/
$updatedContribution = CRM_Contribute_BAO_Contribution::getValues(array('id' => $contributionId), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
$prevTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
$fetchPrevTrxn['id'] = $prevTrxnId['financialTrxnId'];
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($updatedContribution->financial_type_id, $relationTypeId);
$adjustedTrxnValues = array('from_financial_account_id' => NULL, 'to_financial_account_id' => $toFinancialAccount, 'trxn_date' => date('YmdHis'), 'total_amount' => $balanceAmt, 'currency' => $updatedContribution->currency, 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'), 'payment_instrument_id' => $updatedContribution->payment_instrument_id, 'contribution_id' => $updatedContribution->id);
$adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
// record line item
$adjustPaymentLineParams = array('total_amount' => $updatedAmount, 'financial_type_id' => $updatedContribution->financial_type_id);
$setId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
CRM_Price_BAO_LineItem::getLineItemArray($adjustPaymentLineParams);
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$defaultPriceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($setId));
$fieldID = key($defaultPriceSet['fields']);
$adjustPaymentLineParams['line_item'][$setId][$fieldID]['entity_id'] = $updatedContribution->id;
$adjustPaymentLineParams['line_item'][$setId][$fieldID]['entity_table'] = 'civicrm_contribution';
$adjustPaymentLine = CRM_Price_BAO_LineItem::create($adjustPaymentLineParams['line_item'][$setId][$fieldID]);
// record financial item
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$itemStatus = NULL;
if ($updatedContribution->contribution_status_id == array_search('Pending refund', $contributionStatuses)) {
$itemStatus = array_search('Paid', $financialItemStatus);
} elseif ($updatedContribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) {
$itemStatus = array_search('Partially paid', $financialItemStatus);
}
$params = array('transaction_date' => CRM_Utils_Date::isoToMysql($updatedContribution->receive_date), 'contact_id' => $updatedContribution->contact_id, 'amount' => $balanceAmt, 'currency' => $updatedContribution->currency, 'entity_table' => 'civicrm_line_item', 'entity_id' => $adjustPaymentLine->id, 'description' => ($adjustPaymentLine->qty != 1 ? $lineItem->qty . ' of ' : '') . ' ' . $adjustPaymentLine->label, 'status_id' => $itemStatus, 'financial_account_id' => $prevItem->financial_account_id);
CRM_Financial_BAO_FinancialItem::create($params, NULL, array('id' => $adjustedTrxn->id));
}
//activity creation$contributionStatuses
self::addActivityForSelection($participantId, 'Change Registration');
}