Merge branch 'dillon/39-crm-changes' into development

This commit is contained in:
Dillon
2023-08-04 23:17:42 +08:00
6 changed files with 45 additions and 92 deletions
+8 -9
View File
@@ -26,28 +26,28 @@ class UpdatePerfexCRM implements ShouldQueue
private $transaction;
/** @var Boolean|null */
private $shouldCreateInvoice;
private $shouldCreateInvoiceWithPayment;
/**
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
* @param $transaction
* @param bool|null $shouldCreateInvoice
* @param bool|null $shouldCreateInvoiceWithPayment
*/
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoice = false)
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoiceWithPayment = false)
{
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
$this->transaction = $transaction;
$this->shouldCreateInvoice = $shouldCreateInvoice;
$this->shouldCreateInvoiceWithPayment = $shouldCreateInvoiceWithPayment;
}
public function handle()
{
//To use invoice as a reference to decide whether more tasks should be created
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceId());
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice());
$result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
if($this->transaction != null && $this->shouldCreateInvoice){
if($this->transaction != null && $this->shouldCreateInvoiceWithPayment){
$updatePerfexCRMInvoiceObject = new UpdatePerfexCRMInvoiceObject(
$this->updatePerfexCRMObject->getContactEmail(),
$this->updatePerfexCRMObject->getProjectName(),
@@ -59,12 +59,11 @@ class UpdatePerfexCRM implements ShouldQueue
}
}
private function getInvoiceId(){
private function getInvoiceIdOrCreateInvoice(){
if($this->transaction != null){
$fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject(
$this->updatePerfexCRMObject->getContactEmail(),
$this->transaction,
true
$this->transaction
);
$invoiceId = (App()->make(FetchPerfexCRMInvoiceProcessor::class))->execute($fetchPerfexCRMInvoiceObject);
return $invoiceId;
@@ -13,15 +13,11 @@ class FetchPerfexCRMInvoiceObject implements DataTransferObject
/** @var Transaction */
private $transaction;
/** @var bool */
private $isPaid;
public function __construct(string $email, Transaction $transaction, bool $isPaid)
public function __construct(string $email, Transaction $transaction)
{
$this->email = $email;
$this->transaction = $transaction;
$this->isPaid = $isPaid;
}
/**
@@ -39,12 +35,4 @@ class FetchPerfexCRMInvoiceObject implements DataTransferObject
{
return $this->transaction;
}
/**
* @return bool
*/
public function getIsPaid(): bool
{
return $this->isPaid;
}
}
@@ -228,26 +228,6 @@ class CreatePerfexCRMInvoiceProcessor
);
$result = $this->createsPerfexCRMInvoice->execute($invoicePerfexCRMObject);
//cief todo: When invoices need to be regenerated, need to ensure payment do not get double created
// if(!is_null($result))
// {
// if($result->payload['id']){
// $invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject(
// $result->payload['id'],
// $total,
// $date,
// 1,
// "",
// ""
// );
// $this->createsPerfexCRMInvoicePayment->execute($invoicePaymentPerfexCRMObject);
// }
// }
//else: logs will record the following:
//"status":false,"error":{"number":"The Invoice number is already in use"},"message":"<p>The Invoice number is already in use<\/p>"}
return $result;
}
}
@@ -57,7 +57,7 @@ class FetchPerfexCRMInvoiceProcessor
$number = 'EXC-'.$number;
$invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number);
if(is_null($invoice)){
$result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null, $fetchPerfexCRMInvoiceObject->getIsPaid());
$result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null);
if ($result) {
$invoiceId = $result->payload['id'];
} else {
@@ -15,8 +15,8 @@ use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMTask;
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMCustomer;
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMProject;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
use Illuminate\Support\Facades\Http;
@@ -219,13 +219,23 @@ class UpdatePerfexCRMProcessor
}
}
else{
$result = $this->createsPerfexCRMTask->execute($taskName, $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus, $tasks[$count]['priority'], $tasks[$count]['duedate'], $updatePerfexCRMObject->getInvoiceId());
$createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject(
"",
$taskName,
$tasks[$count]['description'],
"",
$projectId,
$milestoneId,
$tasks[$count]['reference'],
$tasks[$count]['on_task_completion'],
$taskStatus,
$tasks[$count]['department'],
$tasks[$count]['priority'],
$tasks[$count]['duedate'],
$updatePerfexCRMObject->getInvoiceId()
);
$result = $this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject);
}
//cief todo: to evaluate if this is still needed
// if(is_null($result)){
// break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously
// }
}
}
@@ -6,70 +6,46 @@ use Illuminate\Support\Facades\Http;
use App\Classes\Exceptions\MalformedRequestException;
use Illuminate\Support\Facades\Log;
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
class CreatesPerfexCRMTask
{
/**
* @param string $taskName
* @param string $taskDescription
* @param string $leadId
* @param string $milestoneId
* @param string $projectId
* @param string $reference
* @param string $on_task_completion
* @param string $department
* @param string $status
* @param string $priority
* @param string $duedate
* @param int $invoiceId
* @param CreateTaskPerfexCRMObject $createTaskPerfexCRMObject
* @return null|object
* @throws MalformedRequestException
*/
public function execute(string $taskName, string $taskDescription, string $leadId, string $milestoneId, string $projectId, string $reference, string $on_task_completion, string $department, string $status, string $priority, string $duedate, int $invoiceId) {
public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) {
try{
$custom_fields = [];
if($department != ""){
if($createTaskPerfexCRMObject->getDepartment() != ""){
$custom_fields = [
"tasks" => [
PerfexCRMCustomFields::TASKS_DEPARTMENT => $department
PerfexCRMCustomFields::TASKS_DEPARTMENT => $createTaskPerfexCRMObject->getDepartment()
]
];
}
$data = [
'name' => $taskName,
'description' => $taskDescription,
'milestone' => $milestoneId,
'name' => $createTaskPerfexCRMObject->getName(),
'description' => $createTaskPerfexCRMObject->getDescription(),
'milestone' => $createTaskPerfexCRMObject->getMilestoneId(),
'startdate' => date('Y-m-d'),
'rel_type' => 'project',
'rel_id' => $projectId,
'status' => $status,
'rel_id' => $createTaskPerfexCRMObject->getProjectId(),
'status' => $createTaskPerfexCRMObject->getStatus(),
'is_system_created' => 1,
'reference' => $reference,
'on_task_completion' => $on_task_completion,
'reference' => $createTaskPerfexCRMObject->getReference(),
'on_task_completion' => $createTaskPerfexCRMObject->getOnTaskCompletion(),
'custom_fields' => $custom_fields,
'priority' => $priority,
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
'invoice_id' => $invoiceId,
'priority' => $createTaskPerfexCRMObject->getPriority(),
'duedate' => date('Y-m-d', strtotime('+' . $createTaskPerfexCRMObject->getDuedate() . ' days')),
'invoice_id' => $createTaskPerfexCRMObject->getInvoiceId(),
];
if($leadId != '') {
$data = [
'name' => $taskName,
'description' => $taskDescription,
'milestone' => $milestoneId,
'startdate' => date('Y-m-d'),
'rel_type' => 'lead',
'rel_id' => $leadId,
'status' => $status,
'is_system_created' => 1,
'reference' => $reference,
'on_task_completion' => $on_task_completion,
'custom_fields' => $custom_fields,
'priority' => $priority,
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
'invoice_id' => 0
];
if($createTaskPerfexCRMObject->getLeadId() != '') {
$data['rel_type'] = 'lead';
$data['rel_id'] = $createTaskPerfexCRMObject->getLeadId();
}
$response = Http::asForm()->withHeaders([