Exemplo n.º 1
0
 public static function bulkAssignRemove()
 {
     $checkIDs = $_REQUEST['ID'];
     $entityID = CRM_Utils_Type::escape($_REQUEST['entityID'], 'String');
     $action = CRM_Utils_Type::escape($_REQUEST['action'], 'String');
     foreach ($checkIDs as $key => $value) {
         if (substr($value, 0, 7) == "mark_x_" && $action == 'Assign' || substr($value, 0, 7) == "mark_y_" && $action == 'Remove') {
             $contributions = explode("_", $value);
             $cIDs[] = $contributions[2];
         }
     }
     $batchPID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $entityID, 'payment_instrument_id');
     $paymentInstrument = CRM_Core_OptionGroup::getLabel('payment_instrument', $batchPID);
     foreach ($cIDs as $key => $value) {
         $recordPID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $value, 'payment_instrument_id');
         if ($action == 'Remove' || $recordPID == $batchPID && $action == 'Assign' || !isset($batchPID)) {
             $params = array('entity_id' => $value, 'entity_table' => 'civicrm_financial_trxn', 'batch_id' => $entityID);
             if ($action == 'Assign') {
                 $updated = CRM_Batch_BAO_Batch::addBatchEntity($params);
             } else {
                 $updated = CRM_Batch_BAO_Batch::removeBatchEntity($params);
             }
         }
     }
     if ($updated) {
         $status = array('status' => 'record-updated-success');
     } else {
         $status = array('status' => ts("This batch is configured to include only transactions using %1 payment method. If you want to include other transactions, please edit the batch first and modify the Payment Method.", array(1 => $paymentInstrument)));
     }
     CRM_Utils_JSON::output($status);
 }