示例#1
0
/**
 * Delete a pledge
 *
 * @param  array   $params           array included 'pledge_id' of pledge to delete
 *
 * @return boolean        true if success, else false
 * @static void
 * {@getfields pledge_delete}
 * @example PledgeDelete.php
 * @access public
 */
function civicrm_api3_pledge_delete($params)
{
    if (CRM_Pledge_BAO_Pledge::deletePledge($params['id'])) {
        return civicrm_api3_create_success(array('id' => $params['id']), $params, 'pledge', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete pledge');
    }
}
示例#2
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     $deletedPledges = 0;
     foreach ($this->_pledgeIds as $pledgeId) {
         if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeId)) {
             $deletedPledges++;
         }
     }
     $status = ts('Deleted Pledge(s): %1 (Total Selected: %2) ', array(1 => $deletedPledges, 2 => count($this->_pledgeIds)));
     CRM_Core_Session::setStatus($status, '', 'info');
 }
示例#3
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $deletedPledges = 0;
     require_once 'CRM/Pledge/BAO/Pledge.php';
     foreach ($this->_pledgeIds as $pledgeId) {
         if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeId)) {
             $deletedPledges++;
         }
     }
     $status = array(ts('Deleted Pledge(s): %1', array(1 => $deletedPledges)), ts('Total Selected Pledge(s): %1', array(1 => count($this->_pledgeIds))));
     CRM_Core_Session::setStatus($status);
 }
示例#4
0
文件: Delete.php 项目: kidaa30/yes
 /**
  * Process the form after the input has been submitted and validated.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $deleted = $failed = 0;
     foreach ($this->_pledgeIds as $pledgeId) {
         if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeId)) {
             $deleted++;
         } else {
             $failed++;
         }
     }
     if ($deleted) {
         $msg = ts('%count pledge deleted.', array('plural' => '%count pledges deleted.', 'count' => $deleted));
         CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
     }
     if ($failed) {
         CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error');
     }
 }
示例#5
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Pledge_BAO_Pledge::deletePledge($this->_id);
         return;
     }
     // get the submitted form values.
     $formValues = $this->controller->exportValues($this->_name);
     // set the contact, when contact is selected
     if (!empty($formValues['contact_id'])) {
         $this->_contactID = $formValues['contact_id'];
     }
     $session = CRM_Core_Session::singleton();
     // get All Payments status types.
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $fields = array('frequency_unit', 'frequency_interval', 'frequency_day', 'installments', 'financial_type_id', 'initial_reminder_day', 'max_reminders', 'additional_reminder_day', 'contribution_page_id', 'campaign_id');
     foreach ($fields as $f) {
         $params[$f] = CRM_Utils_Array::value($f, $formValues);
     }
     // defaults status is "Pending".
     // if update get status.
     if ($this->_id) {
         $params['pledge_status_id'] = $params['status_id'] = $this->_values['status_id'];
     } else {
         $params['pledge_status_id'] = $params['status_id'] = array_search('Pending', $paymentStatusTypes);
     }
     // format amount
     $params['amount'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('amount', $formValues));
     $params['currency'] = CRM_Utils_Array::value('currency', $formValues);
     $params['original_installment_amount'] = $params['amount'] / $params['installments'];
     $dates = array('create_date', 'start_date', 'acknowledge_date', 'cancel_date');
     foreach ($dates as $d) {
         if ($this->_id && !$this->_isPending && !empty($this->_values[$d])) {
             if ($d == 'start_date') {
                 $params['scheduled_date'] = CRM_Utils_Date::processDate($this->_values[$d]);
             }
             $params[$d] = CRM_Utils_Date::processDate($this->_values[$d]);
         } elseif (!empty($formValues[$d]) && !CRM_Utils_System::isNull($formValues[$d])) {
             if ($d == 'start_date') {
                 $params['scheduled_date'] = CRM_Utils_Date::processDate($formValues[$d]);
             }
             $params[$d] = CRM_Utils_Date::processDate($formValues[$d]);
         } else {
             $params[$d] = 'null';
         }
     }
     if (!empty($formValues['is_acknowledge'])) {
         $params['acknowledge_date'] = date('Y-m-d');
     }
     // assign id only in update mode
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $params['contact_id'] = $this->_contactID;
     // format custom data
     if (!empty($formValues['hidden_custom'])) {
         $params['hidden_custom'] = 1;
         $customFields = CRM_Core_BAO_CustomField::getFields('Pledge');
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $this->_id, 'Pledge');
     }
     // handle pending pledge.
     $params['is_pledge_pending'] = $this->_isPending;
     // create pledge record.
     $pledge = CRM_Pledge_BAO_Pledge::create($params);
     $statusMsg = NULL;
     if ($pledge->id) {
         // set the status msg.
         if ($this->_action & CRM_Core_Action::ADD) {
             $statusMsg = ts('Pledge has been recorded and the payment schedule has been created.<br />');
         } elseif ($this->_action & CRM_Core_Action::UPDATE) {
             $statusMsg = ts('Pledge has been updated.<br />');
         }
     }
     // handle Acknowledgment.
     if (!empty($formValues['is_acknowledge']) && $pledge->id) {
         // calculate scheduled amount.
         $params['scheduled_amount'] = round($params['amount'] / $params['installments']);
         $params['total_pledge_amount'] = $params['amount'];
         // get some required pledge values in params.
         $params['id'] = $pledge->id;
         $params['acknowledge_date'] = $pledge->acknowledge_date;
         $params['is_test'] = $pledge->is_test;
         $params['currency'] = $pledge->currency;
         // retrieve 'from email id' for acknowledgement
         $params['from_email_id'] = $formValues['from_email_address'];
         $this->paymentId = NULL;
         // send Acknowledgment mail.
         CRM_Pledge_BAO_Pledge::sendAcknowledgment($this, $params);
         if (!isset($this->userEmail)) {
             list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         }
         $statusMsg .= ' ' . ts("An acknowledgment email has been sent to %1.<br />", array(1 => $this->userEmail));
         // build the payment urls.
         if ($this->paymentId) {
             $urlParams = "reset=1&action=add&cid={$this->_contactID}&ppid={$this->paymentId}&context=pledge";
             $contribURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
             $urlParams .= "&mode=live";
             $creditURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
             // check if we can process credit card payment.
             $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
             if (count($processors) > 0) {
                 $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a> OR <a href='%2'>submit a credit card payment</a>.", array(1 => $contribURL, 2 => $creditURL));
             } else {
                 $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a>.", array(1 => $contribURL));
             }
         }
     }
     CRM_Core_Session::setStatus($statusMsg, ts('Payment Due'), 'info');
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=pledge"));
         }
     } elseif ($buttonName == $this->getButtonName('upload', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/pledge', "reset=1&action=add&context=pledge&cid={$this->_contactID}"));
     }
 }
 /**
  *  Pass Zero Id for a payment deletion for one pledge
  */
 function testDeletePaymentsZeroId()
 {
     $payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment');
     $paymentid = CRM_Pledge_BAO_PledgePayment::deletePayments(0);
     $result = CRM_Pledge_BAO_Pledge::deletePledge($payment->pledge_id);
 }
/**
 * Delete a pledge
 *
 * @param  array   $params           array included 'pledge_id' of pledge to delete
 *
 * @return boolean        true if success, else false
 * @static void
 * @access public
 */
function civicrm_pledge_delete(&$params)
{
    if (!empty($params['id'])) {
        //handle field name or unique db name
        $params['pledge_id'] = $params['id'];
    }
    $pledgeID = CRM_Utils_Array::value('pledge_id', $params);
    if (!$pledgeID) {
        return civicrm_create_error('Could not find pledge_id in input parameters');
    }
    require_once 'CRM/Pledge/BAO/Pledge.php';
    if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeID)) {
        return civicrm_create_success();
    } else {
        return civicrm_create_error('Could not delete pledge');
    }
}