コード例 #1
0
 function generatexml($id)
 {
     $xml = "";
     $template = CRM_Core_Smarty::singleton();
     $this->get((int) $id);
     $template->assign("file", $this->toArray());
     $txgroup = new CRM_Sepa_BAO_SEPATransactionGroup();
     $txgroup->sdd_file_id = $this->id;
     $txgroup->find();
     $total = 0;
     $nbtransactions = 0;
     $fileFormats = array();
     while ($txgroup->fetch()) {
         $xml .= $txgroup->generateXML();
         $total += $txgroup->total;
         $nbtransactions += $txgroup->nbtransactions;
         $fileFormats[] = $txgroup->fileFormat;
     }
     if (count(array_unique($fileFormats)) > 1) {
         throw new Exception('Creditors with mismatching File Formats cannot be mixed in same File');
     } else {
         $fileFormatName = CRM_Utils_SepaOptionGroupTools::sanitizeFileFormat(reset($fileFormats));
     }
     $template->assign("file", $this->toArray());
     $template->assign("total", $total);
     $template->assign("nbtransactions", $nbtransactions);
     $head = $template->fetch('../formats/' . $fileFormatName . '/transaction-header.tpl');
     $footer = $template->fetch('../formats/' . $fileFormatName . '/transaction-footer.tpl');
     return $head . $xml . $footer;
 }
コード例 #2
0
function civicrm_api3_sepa_alternative_batching_createxml($params)
{
    $override = isset($params['override']) ? $params['override'] : false;
    $result = CRM_Sepa_BAO_SEPATransactionGroup::createFile((int) $params['txgroup_id'], $override);
    if (is_numeric($result)) {
        // this was succesfull -> load the sepa file
        return civicrm_api('SepaSddFile', 'getsingle', array('id' => $result, 'version' => 3));
    } else {
        // there was an error:
        civicrm_api3_create_error($result);
    }
}
コード例 #3
0
 /**
  * Test update of recurring payments after a deferred submission
  *
  * @author Björn Endres
  * @see https://github.com/Project60/sepa_dd/issues/190
  */
 public function testRCURGracePeriod_190()
 {
     $rcur_notice = 6;
     CRM_Sepa_Logic_Settings::setSetting('batching.RCUR.notice', $rcur_notice);
     CRM_Sepa_Logic_Settings::setSetting('batching.RCUR.grace', 2 * $rcur_notice);
     $contactId = $this->individualCreate();
     $collection_date = strtotime("+1 days");
     $deferred_collection_date = strtotime("+{$rcur_notice} days");
     // count the existing contributions
     $count = $this->callAPISuccess("Contribution", "getcount", array('version' => 3));
     // create a mandate, that's already late
     $parameters = array('version' => 3, 'type' => 'RCUR', 'status' => 'RCUR', 'contact_id' => $contactId, 'financial_type_id' => 1, 'amount' => '6.66', 'start_date' => date('YmdHis'), 'date' => date('YmdHis'), 'cycle_day' => date('d', $collection_date), 'frequency_interval' => 1, 'frequency_unit' => 'month', 'iban' => "BE68844010370034", 'bic' => "TESTTEST", 'creditor_id' => $this->getCreditor(), 'is_enabled' => 1);
     $this->callAPISuccess("SepaMandate", "createfull", $parameters);
     // batch it
     $this->callAPISuccess("SepaAlternativeBatching", "update", array("type" => "RCUR", 'version' => 3));
     // check contributions count again
     $newcount = $this->callAPISuccess("Contribution", "getcount", array('version' => 3));
     $this->assertEquals($count + 1, $newcount, "A contribution should have been created!");
     // adjust collection date, close the group and thus modify the contribution's receive date
     $txgroup = $this->callAPISuccess("SepaTransactionGroup", "getsingle", array('version' => 3));
     CRM_Sepa_BAO_SEPATransactionGroup::adjustCollectionDate($txgroup['id'], date('Y-m-d', $deferred_collection_date));
     CRM_Sepa_Logic_Group::close($txgroup['id']);
     // batch again
     $this->callAPISuccess("SepaAlternativeBatching", "update", array("type" => "RCUR", 'version' => 3));
     // verify, that NO new contribution is created
     $newcount = $this->callAPISuccess("Contribution", "getcount", array('version' => 3));
     $this->assertEquals($count + 1, $newcount, "Yet another contribution has been created. Issue #190 still active!");
 }
コード例 #4
0
 function run()
 {
     if (isset($_REQUEST['group_id'])) {
         if (isset($_REQUEST['status']) && ($_REQUEST['status'] == "missed" || $_REQUEST['status'] == "invalid" || $_REQUEST['status'] == "closed")) {
             $this->assign('status', $_REQUEST['status']);
         } else {
             $_REQUEST['status'] = "";
         }
         $group_id = (int) $_REQUEST['group_id'];
         $this->assign('txgid', $group_id);
         // LOAD/CREATE THE TXFILE
         $group = civicrm_api('SepaTransactionGroup', 'getsingle', array('version' => 3, 'id' => $group_id));
         if (isset($group['is_error']) && $group['is_error']) {
             CRM_Core_Session::setStatus("Cannot load group #{$group_id}.<br/>Error was: " . $group['error_message'], ts('Error'), 'error');
         } else {
             $this->assign('txgroup', $group);
             // check whether this is a group created by a test creditor
             $creditor = civicrm_api('SepaCreditor', 'getsingle', array('version' => 3, 'id' => $group['sdd_creditor_id']));
             if (isset($creditor['is_error']) && $creditor['is_error']) {
                 CRM_Core_Session::setStatus("Cannot load creditor.<br/>Error was: " . $creditor['error_message'], ts('Error'), 'error');
             } else {
                 $isTestGroup = isset($creditor['category']) && $creditor['category'] == "TEST";
                 $this->assign('is_test_group', $isTestGroup);
                 if ($_REQUEST['status'] == "") {
                     // first adjust group's collection date if requested
                     if (!empty($_REQUEST['adjust'])) {
                         $result = CRM_Sepa_BAO_SEPATransactionGroup::adjustCollectionDate($group_id, $_REQUEST['adjust']);
                         if (is_string($result)) {
                             // that's an error -> stop here!
                             die($result);
                         } else {
                             // that went well, so result should be the update group data
                             $group = $result;
                         }
                     }
                     // delete old txfile
                     if (!empty($group['sdd_file_id'])) {
                         $result = civicrm_api('SepaSddFile', 'delete', array('id' => $group['sdd_file_id'], 'version' => 3));
                         if (isset($result['is_error']) && $result['is_error']) {
                             CRM_Core_Session::setStatus("Cannot delete file #" . $group['sdd_file_id'] . ".<br/>Error was: " . $result['error_message'], ts('Error'), 'error');
                         }
                     }
                     $xmlfile = civicrm_api('SepaAlternativeBatching', 'createxml', array('txgroup_id' => $group_id, 'override' => True, 'version' => 3));
                     if (isset($xmlfile['is_error']) && $xmlfile['is_error']) {
                         CRM_Core_Session::setStatus("Cannot load for group #" . $group_id . ".<br/>Error was: " . $xmlfile['error_message'], ts('Error'), 'error');
                     } else {
                         $file_id = $xmlfile['id'];
                         $this->assign('file_link', CRM_Utils_System::url('civicrm/sepa/xml', "id={$file_id}"));
                         $this->assign('file_name', $xmlfile['filename']);
                     }
                 }
                 if ($_REQUEST['status'] == "closed" && !$isTestGroup) {
                     // CLOSE THE GROUP:
                     $result = civicrm_api('SepaAlternativeBatching', 'close', array('version' => 3, 'txgroup_id' => $group_id));
                     if ($result['is_error']) {
                         CRM_Core_Session::setStatus("Cannot close group #{$group_id}.<br/>Error was: " . $result['error_message'], ts('Error'), 'error');
                     }
                 }
             }
         }
     }
     parent::run();
 }
コード例 #5
0
 function run()
 {
     if (empty($_REQUEST['group_id'])) {
         $this->assign('status', 'error');
     } else {
         $group_id = (int) $_REQUEST['group_id'];
         $this->assign('txgid', $group_id);
         $txgroup = civicrm_api('SepaTransactionGroup', 'getsingle', array('id' => $group_id, 'version' => 3));
         if (empty($txgroup['is_error'])) {
             $txgroup['status_label'] = CRM_Core_OptionGroup::optionLabel('batch_status', $txgroup['status_id']);
             $txgroup['status_name'] = CRM_Core_OptionGroup::getValue('batch_status', $txgroup['status_id'], 'value', 'String', 'name');
             $this->assign('txgroup', $txgroup);
         } else {
             $_REQUEST['confirmed'] = 'error';
             // skip the parts below
         }
         if (empty($_REQUEST['confirmed'])) {
             // gather information to display
             $PENDING = (int) CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name');
             $INPROGRESS = (int) CRM_Core_OptionGroup::getValue('contribution_status', 'In Progress', 'name');
             $stats = array('busy' => 0, 'open' => 0, 'other' => 0, 'total' => 0);
             $status2contributions = $this->contributionStats($group_id);
             foreach ($status2contributions as $contribution_status_id => $contributions) {
                 foreach ($contributions as $contribution_id) {
                     $stats['total'] += 1;
                     if ($contribution_status_id == $PENDING) {
                         $stats['open'] += 1;
                     } elseif ($contribution_status_id == $INPROGRESS) {
                         $stats['busy'] += 1;
                     } else {
                         $stats['other'] += 1;
                     }
                 }
             }
             $this->assign('stats', $stats);
             $this->assign('status', 'unconfirmed');
             $this->assign('submit_url', CRM_Utils_System::url('civicrm/sepa/deletegroup'));
         } elseif ($_REQUEST['confirmed'] == 'yes') {
             // delete the group
             $this->assign('status', 'done');
             $delete_contributions_mode = $_REQUEST['delete_contents'];
             $deleted_ok = array();
             $deleted_error = array();
             $result = CRM_Sepa_BAO_SEPATransactionGroup::deleteGroup($group_id, $delete_contributions_mode);
             if (is_string($result)) {
                 // a very basic error happened
                 $this->assign('error', $result);
             } else {
                 // do some stats on the result
                 $deleted_total = count($result);
                 foreach ($result as $contribution_id => $message) {
                     if ($message == 'ok') {
                         array_push($deleted_ok, $contribution_id);
                     } else {
                         array_push($deleted_error, $contribution_id);
                     }
                 }
                 $this->assign('deleted_result', $result);
                 $this->assign('deleted_ok', $deleted_ok);
                 $this->assign('deleted_error', $deleted_error);
             }
         } elseif ($_REQUEST['confirmed'] == 'error') {
             $this->assign('status', 'error');
         } else {
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/sepa'));
         }
     }
     parent::run();
 }