Commit 8688a70f authored by ErikHommel's avatar ErikHommel
Browse files

action updatecallassignment for issue 7982 - tm mindwize import

parent 4b808d0d
......@@ -2,6 +2,7 @@
namespace Civi\Aivlspecificactions\Actions;
use \Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Condition\ParametersMatch;
use Civi\ActionProvider\Exception\ExecutionException;
use \Civi\ActionProvider\Exception\InvalidParameterException;
use Civi\ActionProvider\Parameter\OptionGroupByNameSpecification;
......@@ -30,9 +31,17 @@ class UpdateCallAssignment extends AbstractAction {
$specs = new SpecificationBag();
$specs->addSpecification(new Specification('activity_id', 'Integer', E::ts('Activity ID'), TRUE, NULL));
$specs->addSpecification(new Specification('result_code', 'String', E::ts('Result Code'), TRUE, NULL));
$specs->addSpecification(new Specification('result_description', 'String', E::ts("Result Description"), FALSE, NULL));
$specs->addSpecification(new Specification('call_date', 'Date', E::ts('Call Date'), FALSE, NULL));
$specs->addSpecification(new Specification('result_upload_date', 'Date', E::ts('Result Upload Date'), FALSE, NULL));
$specs->addSpecification(new Specification('call_agent', 'String', E::ts('Call Agent'), FALSE, NULL));
$specs->addSpecification(new Specification('result_reason_no', 'String', E::ts('Reason No'), FALSE, NULL));
$specs->addSpecification(new Specification('campaign_name', 'String', E::ts('TM Campaign Name'), FALSE, NULL));
$specs->addSpecification(new Specification('new_mandate_code', 'String', E::ts('New Mandate Code'), FALSE, NULL));
$specs->addSpecification(new Specification('new_amount', 'Money', E::ts('New Amount'), FALSE, NULL));
$specs->addSpecification(new Specification('new_frequency', 'String', E::ts('New Frequency'), FALSE, NULL));
$specs->addSpecification(new Specification('new_iban', 'String', E::ts('New IBAN'), FALSE, NULL));
$specs->addSpecification(new Specification('new_start_date', 'Date', E::ts('New Mandate Start Date'), FALSE, NULL));
return $specs;
}
......@@ -40,9 +49,7 @@ class UpdateCallAssignment extends AbstractAction {
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
$specs = new SpecificationBag();
$specs->addSpecification(new OptionGroupByNameSpecification('activity_type_id', 'activity_type', E::ts('Activity Type For TM Call Assignment'), TRUE));
return $specs;
return new SpecificationBag();
}
/**
......@@ -58,20 +65,245 @@ class UpdateCallAssignment extends AbstractAction {
if ($activityId) {
// set params for parameters
$activityParams = $this->setCallAssignmentParams($parameterBag);
// set status to completed if result code is correct
$this->setCompletedIfNeeded($activityParams);
// update call assignment activity
$this->updateCallAssignment($activityParams);
if (!empty($activityParams)) {
// update call assignment activity
$this->updateCallAssignment($activityParams);
}
$output->setParameter('activity_id', (int) $activityId);
}
}
/**
* Method to update the call assignment activity
*
* @param $activityParams
* @throws ExecutionException
*/
private function updateCallAssignment($activityParams) {
try {
civicrm_api3('Activity', 'create', $activityParams);
}
catch (\CiviCRM_API3_Exception $ex) {
throw new ExecutionException(E::ts("Could not update call assignment activity, error from ")
. "API Activity create: " . $ex->getMessage());
}
}
/**
* Method to set the parameters for the call assignment
* @param ParameterBagInterface $parameterBag
* @return array
* @throws ExecutionException
*/
private function setCallAssignmentParams(ParameterBagInterface $parameterBag) {
$result = ['id' => $parameterBag->getParameter('activity_id')];
// get the result code from parameters and store
$callAssignmentParams = [];
$this->setResultCode($parameterBag, $callAssignmentParams);
$this->setCallDate($parameterBag, $callAssignmentParams);
$this->setResultUploadDate($parameterBag, $callAssignmentParams);
$this->setResultAgent($parameterBag, $callAssignmentParams);
$this->setResultReasonNo($parameterBag, $callAssignmentParams);
$this->setActivityStatus($parameterBag, $callAssignmentParams);
$this->setCampaignName($parameterBag, $callAssignmentParams);
$this->setNewMandateCode($parameterBag, $callAssignmentParams);
$this->setNewAmount($parameterBag, $callAssignmentParams);
$this->setNewFrequency($parameterBag, $callAssignmentParams);
$this->setNewIban($parameterBag, $callAssignmentParams);
$this->setNewStartDate($parameterBag, $callAssignmentParams);
if (!empty($callAssignmentParams)) {
$callAssignmentParams['id'] = $parameterBag->getParameter('activity_id');
}
return $callAssignmentParams;
}
/**
* Method to set new mandate start date in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
* @throws \Exception
*/
private function setNewStartDate(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$startDate = $parameterBag->getParameter('new_start_date');
if ($startDate) {
try {
$newDate = new \DateTime($startDate);
$startDataCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultStartDateCustomFieldId();
$callAssignmentParams[$startDataCustomField] = $newDate->format('Y-m-d');
}
catch (Exception $ex) {
}
}
}
/**
* Method to set new iban in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setNewIban(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$iban = $parameterBag->getParameter('new_iban');
if ($iban) {
$ibanCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultIbanCustomFieldId();
$callAssignmentParams[$ibanCustomField] = $iban;
}
}
/**
* Method to set new frequency unit and interval in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setNewFrequency(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$interval = $parameterBag->getParameter('new_frequency');
if ($interval) {
$unitCustomFieldId = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultFreqUnitCustomFieldId();
$intervalCustomFieldId = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultFreqIntervalCustomFieldId();
$callAssignmentParams[$unitCustomFieldId] = "maand";
$callAssignmentParams[$intervalCustomFieldId] = $interval;
}
}
/**
* Method to set new amount in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setNewAmount(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$amount = $parameterBag->getParameter('new_amount');
if ($amount) {
$amountCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultAmountCustomFieldId();
$callAssignmentParams[$amountCustomField] = $amount;
}
}
/**
* Method to set new mandate code in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setNewMandateCode(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$mandateCode = $parameterBag->getParameter('new_mandate_code');
if ($mandateCode) {
$mandateCodeCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultMandateCodeNewCustomFieldId();
$callAssignmentParams[$mandateCodeCustomField] = $mandateCode;
}
}
/**
* Method to set campaign name in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setCampaignName(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$campaignName = $parameterBag->getParameter('campaign_name');
if ($campaignName) {
$campaignNameCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaAgencyReferenceCustomFieldId();
$callAssignmentParams[$campaignNameCustomField] = $campaignName;
}
}
/**
* Method to set activity completed if correct result code
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setActivityStatus(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$completedResultCodes = ["42", "60", "64", "71", "79"];
$resultCode = $parameterBag->getParameter('result_code');
if (in_array($resultCode, $completedResultCodes)) {
$callAssignmentParams['status_id'] = \Civi::service('aivlgeneric')->getCompletedActivityStatusId();
}
}
/**
* Method to set the result reason no in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setResultReasonNo(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$reason = $parameterBag->getParameter('result_reason_no');
if ($reason) {
$reasonCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultReasonNoCustomFieldId();
$callAssignmentParams[$reasonCustomField] = $reason;
}
}
/**
* Method to set the result agent in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setResultAgent(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$agent = $parameterBag->getParameter('call_agent');
if ($agent) {
$agentCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultAgentCustomFieldId();
$callAssignmentParams[$agentCustomField] = $agent;
}
}
/**
* Method to set the result upload date in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
* @throws \Exception
*/
private function setResultUploadDate(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$resultUploadDate = $parameterBag->getParameter('result_upload_date');
if ($resultUploadDate) {
try {
$newDate = new \DateTime($resultUploadDate);
$uploadDataCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultUploadDateCustomFieldId();
$callAssignmentParams[$uploadDataCustomField] = $newDate->format('Y-m-d H:i:s');
}
catch (Exception $ex) {
}
}
}
/**
* Method to set the call date in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
* @throws ExecutionException
*/
private function setCallDate(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$callDate = $parameterBag->getParameter('call_date');
if ($callDate) {
try {
$newDate = new \DateTime($callDate);
$callDataCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaCallDateCustomFieldId();
$callAssignmentParams[$callDataCustomField] = $newDate->format('Y-m-d H:i:s');
}
catch (Exception $ex) {
}
}
}
/**
* Method to set the result code in call assignment parameters
*
* @param ParameterBagInterface $parameterBag
* @param $callAssignmentParams
*/
private function setResultCode(ParameterBagInterface $parameterBag, &$callAssignmentParams) {
$resultCode = $parameterBag->getParameter('result_code');
if ($resultCode) {
$resultCodeCustomField = "custom_" . \Civi::service('aivlgeneric')->getTmCaResultCodeCustomFieldId();
$resultDescription = $parameterBag->getParameter('result_description');
if ($resultDescription) {
$resultCode .= " - " . $resultDescription;
}
$callAssignmentParams[$resultCodeCustomField] = $resultCode;
}
return $result;
}
......
......@@ -27,6 +27,8 @@ class CompilerPass implements CompilerPassInterface {
['GetEmailPrefs', 'Civi\Aivlspecificactions\Actions\GetEmailPrefs', E::ts('Get AIVL Email Preferences'), []]);
$actionProviderDefinition->addMethodCall('addAction',
['SetEmailPrefs', 'Civi\Aivlspecificactions\Actions\SetEmailPrefs', E::ts('Set AIVL Email Preferences'), []]);
$actionProviderDefinition->addMethodCall('addAction',
['UpdateCallAssignment', 'Civi\Aivlspecificactions\Actions\UpdateCallAssignment', E::ts('Update AIVL TM Call Assignment'), []]);
}
}
}
......@@ -14,8 +14,8 @@
<url desc="Support">https://civicoop.org</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-05-27</releaseDate>
<version>1.15</version>
<releaseDate>2021-06-17</releaseDate>
<version>1.16</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment