*
*/
public static function addPayments($lineItems, $contributions) {
- foreach ($contributions as $k => $contribution) {
- if ($contribution->contribution_status_id != CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name')) {
- continue;
- }
// get financial trxn which is a payment
- $sql = "SELECT ft.id
+ $ftSql = "SELECT ft.id
FROM civicrm_financial_trxn ft
INNER JOIN civicrm_entity_financial_trxn eft ON eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution'
WHERE eft.entity_id = %1 AND ft.is_payment = 1";
- $ftId = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($contribution->id, 'Integer')));
- // get financial item
- $sql = "SELECT fi.id, li.price_field_value_id
+ $sql = "SELECT fi.id, li.price_field_value_id
FROM civicrm_financial_item fi
INNER JOIN civicrm_line_item li ON li.id = fi.entity_id
WHERE li.contribution_id = %1";
+
+ foreach ($contributions as $k => $contribution) {
+ if ($contribution->contribution_status_id != CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name')) {
+ continue;
+ }
+ $ftId = CRM_Core_DAO::singleValueQuery($ftSql, array(1 => array($contribution->id, 'Integer')));
+ // get financial item
$dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($contribution->id, 'Integer')));
while ($dao->fetch()) {
$ftIds[$dao->price_field_value_id] = $dao->id;