Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions CRM/EasyBatch/BAO/EasyBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static function retrieve($params) {
public static function getEasyBatches(
$paymentProcessorID = NULL,
$returnColumn = 'title',
$isAuto = TRUE
$isAuto = TRUE,
$cardTypeID = NULL
) {
$status = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open');
$easyBatches = array();
Expand All @@ -84,6 +85,9 @@ public static function getEasyBatches(
else {
$where[] = "e.payment_processor_id IS NULL";
}
if ($cardTypeID) {
$where[] = "e.card_type_id = {$cardTypeID}";
}
$sql = "SELECT b.id, {$returnColumn}
FROM civicrm_batch b
LEFT JOIN civicrm_easybatch_entity e ON b.id = e.batch_id
Expand Down Expand Up @@ -145,6 +149,7 @@ public static function addTransactionsToBatch($batchId, $financialTrxnId, $findC
return FALSE;
}
else {
$tx->commit();
return TRUE;
}
}
Expand All @@ -166,7 +171,12 @@ public static function addTransactionsToAutoBatch($financialTrxn) {
&& Civi::settings()->get("pp_auto_financial_batch_{$financialTrxn->payment_processor_id}")
) {
$findCardType = (bool) Civi::settings()->get("pp_cc_financial_batch_{$financialTrxn->payment_processor_id}");
$batches = CRM_EasyBatch_BAO_EasyBatch::getEasyBatches($financialTrxn->payment_processor_id);
if ($findCardType) {
$batches = CRM_EasyBatch_BAO_EasyBatch::getEasyBatches($financialTrxn->payment_processor_id, 'title', TRUE, $financialTrxn->card_type_id);
}
else {
$batches = CRM_EasyBatch_BAO_EasyBatch::getEasyBatches($financialTrxn->payment_processor_id);
}
$financialEasyBatchId = key($batches);
}
}
Expand Down Expand Up @@ -222,10 +232,10 @@ public static function createAutoFinancialBatch(

//check if batch is still open
if ($paymentProcessorID) {
$batches = self::getEasyBatches($paymentProcessorID);
$batches = self::getEasyBatches($paymentProcessorID, 'title', TRUE, $cardTypeID);
}
else {
$batches = self::getEasyBatches(NULL, 'contact_id');
$batches = self::getEasyBatches(NULL, 'contact_id', TRUE, $cardTypeID);
$batches = array_search($contactId, $batches);
}

Expand Down
9 changes: 9 additions & 0 deletions schema/EasyBatchEntity.entityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,14 @@
'input_type' => 'Select Date',
'description' => E::ts('Date for the transactions to be included in the batch.'),
],
'card_type_id' => [
'title' => E::ts('Card Type'),
'sql_type' => 'int unsigned',
'input_type' => 'Select',
'unique_name' => 'easy_batch_entity_card_type_id',
'pseudoconstant' => [
'option_group_name' => 'accept_creditcard',
],
],
],
];