Sync code changes from Shipping Portal + Fix a problem related to activating 1688 service

This commit is contained in:
Dillon
2023-03-31 00:17:21 +08:00
parent eaf7ce4b67
commit 1f3e1d32a1
8 changed files with 77 additions and 42 deletions
+25 -2
View File
@@ -9,6 +9,8 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
class UpdatePerfexCRM implements ShouldQueue
{
@@ -17,17 +19,38 @@ class UpdatePerfexCRM implements ShouldQueue
/** @var UpdatePerfexCRMObject */
private $updatePerfexCRMObject;
/** @var UpdatePerfexCRMInvoice */
private $nextJob;
/** @var */
private $transaction;
/**
* UpdatePerfexCRM constructor.
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
* @param UpdatePerfexCRMInvoice $nextJob
* @param $transaction
*/
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject)
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, $nextJob)
{
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
$this->nextJob = $nextJob;
$this->transaction = $transaction;
}
public function handle()
{
(App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
$result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
/** @var UpdatePerfexCRMInvoice $nextJob*/
if($this->nextJob != null && $this->transaction != null){
$updatePerfexCRMInvoiceOject = new UpdatePerfexCRMInvoiceObject(
$this->updatePerfexCRMObject->getContactEmail(),
$this->updatePerfexCRMObject->getProjectName(),
$result->projectId,
$this->transaction,
true,
);
$this->nextJob::dispatch($updatePerfexCRMInvoiceOject);
}
}
}
+3 -12
View File
@@ -56,6 +56,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
$number = 'EXC-'.$number;
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $number);
Log::error(json_encode('UpdatePerfexCRMInvoice debug $number: '.$number));
if(is_null($invoice)){
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction, null, null, $this->updatePerfexCRMInvoiceObject->getIsPaid());
@@ -67,20 +68,10 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
//This only run when invoice already exist and the invoice does not have a PAID status
if($invoiceStatus != PerfexCRMInvoiceStatus::PAID){
//get project
$projectId = "";
$project = (App()->make(FetchesPerfexCRMProject::class))->execute($this->updatePerfexCRMInvoiceObject->getProjectName(), $customer->userid);
if(!is_null($project)){
$projectId = $project->id;
}
if($projectId == ""){
Log::error(json_encode('UpdatePerfexCRMInvoice debug: '.$this->updatePerfexCRMInvoiceObject->getProjectName()));
Log::error(json_encode($transaction->owner));
}
Log::error(json_encode('UpdatePerfexCRMInvoice debug $this->updatePerfexCRMInvoiceObject->getProjectId(): '.$this->updatePerfexCRMInvoiceObject->getProjectId()));
//update invoice
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $projectId);
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $this->updatePerfexCRMInvoiceObject->getProjectId());
}
}
+13 -6
View File
@@ -21,20 +21,25 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
/** @var UpdatePerfexCRMObject */
private $updatePerfexCRMObject;
/** @var */
private $nextJob;
/** @var UpdatePerfexCRM */
private $nextJob1;
/** @var UpdatePerfexCRMInvoice */
private $nextJob2;
/**
* UpdatePerfexCRMPrelude constructor.
* @param Transaction $transaction
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
* @param $nextJob
* @param UpdatePerfexCRM $nextJob1
* @param UpdatePerfexCRMInvoice $nextJob2
*/
public function __construct(Transaction $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob)
public function __construct(Transaction $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob1, $nextJob2)
{
$this->transaction = $transaction;
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
$this->nextJob = $nextJob;
$this->nextJob1 = $nextJob1;
$this->nextJob2 = $nextJob2;
}
public function handle()
@@ -73,7 +78,9 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
$result = $this->replacePlaceholders($this->updatePerfexCRMObject->getTasks(), $data);
$this->updatePerfexCRMObject->setTasks($result);
$this->nextJob::dispatch($this->updatePerfexCRMObject);
/** @var UpdatePerfexCRM $nextJob1 */
/** @var UpdatePerfexCRMInvoice $nextJob2 */
$this->nextJob1::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->nextJob2);
}
function replacePlaceholders($template, $data, $prefix = '')
@@ -20,12 +20,16 @@ class UpdatePerfexCRMInvoiceObject implements DataTransferObject
/** @var string */
private $projectName;
public function __construct(string $email, Transaction $transaction, bool $isPaid, string $projectName)
/** @var string */
private $projectId;
public function __construct(string $email, string $projectName, string $projectId, Transaction $transaction, bool $isPaid)
{
$this->email = $email;
$this->transaction = $transaction;
$this->isPaid = $isPaid;
$this->projectName = $projectName;
$this->projectId = $projectId;
}
/**
@@ -59,4 +63,12 @@ class UpdatePerfexCRMInvoiceObject implements DataTransferObject
{
return $this->projectName;
}
/**
* @return string
*/
public function getProjectId(): string
{
return $this->projectId;
}
}
@@ -37,7 +37,7 @@ class BookingToPerfexCRMProcessor
[],
[]
);
UpdatePerfexCRM::dispatch($updatePerfexCRMObject);
UpdatePerfexCRM::dispatch($updatePerfexCRMObject, null, null);
return true;
}
@@ -8,7 +8,6 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
use App\Classes\Jobs\UpdatePerfexCRMInvoice;
use App\Classes\Jobs\UpdatePerfexCRM;
use App\Classes\Jobs\UpdatePerfexCRMPrelude;
@@ -119,16 +118,8 @@ class TransactionToPerfexCRMProcessor
$tasks
);
UpdatePerfexCRMPrelude::dispatch($model, $updatePerfexCRMObject, UpdatePerfexCRM::class);
UpdatePerfexCRMPrelude::dispatch($model, $updatePerfexCRMObject, UpdatePerfexCRM::class, UpdatePerfexCRMInvoice::class);
}
$updatePerfexCRMInvoiceOject = new UpdatePerfexCRMInvoiceObject(
$contactEmail,
$model,
true,
$projectName
);
UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceOject);
}
else if($status == ApprovalStatus::PENDING_VERIFICATION){
if($model->type == TransactionType::PURCHASE_ORDER){
@@ -108,7 +108,8 @@ class UpdatePerfexCRMProcessor
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(UpdatePerfexCRMObject $updatePerfexCRMObject) {
$projectId = "";
// Customer has to exist first before Project can appear under it
// Check with Perfex CRM, if this user (email) was previously a lead, should automatically now become a customer
$crmCompany = $updatePerfexCRMObject->getCompanyName();
@@ -220,6 +221,9 @@ class UpdatePerfexCRMProcessor
// }
}
}
return true;
$payload = [];
$payload['projectId'] = $projectId;
return (object) $payload;
}
}
@@ -148,7 +148,8 @@
segment_id: ''
},
expanded: false,
failed: false
failed: false,
part: 0
}
},
methods: {
@@ -156,19 +157,19 @@
this.parameters = {
segment_id: 13
};
this.part = 1;
if(this.acknowledge){
this.submit(this.route('api.company.segment.assign', this.data.id), 'post', 'activateService', true, false);
}
location.reload();
// location.reload();
},
ServiceWaitingList(){
this.acknowledge = true;
this.parameters = {
segment_id: 14
};
this.part = 2;
this.submit(this.route('api.company.segment.assign', this.data.id), 'post', 'activateService', false, false)
},
failedRequierments(){
@@ -177,18 +178,24 @@
this.parameters = {
segment_id: 17
};
this.part = 3;
this.submit(this.route('api.company.segment.assign', this.data.id), 'post', 'activateService', false, false)
},
ServiceNotInterested(){
this.parameters = {
segment_id: 16
};
this.part = 4;
this.submit(this.route('api.company.segment.assign', this.data.id), 'post', 'activateService', true, false);
location.reload();
// location.reload();
},
successHandler(){
console.log('successful');
if(this.part == 1 || this.part == 4){
location.reload();
}
}
},
mixins: [componentHandler]
}
</script>
</script>