mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e5784b6ec | |||
| 8024865d5d |
@@ -55,7 +55,3 @@ EXCHANGE_URL=https://dev.exchange.cief-malaysia.com/
|
||||
MIX_EXCHANGE_URL="${EXCHANGE_URL}"
|
||||
|
||||
YD_API_CODE=''
|
||||
|
||||
PERFEXCRM_BASE_URL=""
|
||||
PERFEXCRM_API_KEY=""
|
||||
PERFEXCRM_IS_ENABLED="false"
|
||||
|
||||
@@ -15,7 +15,7 @@ class DoesNotHaveTransactionType implements Filter
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('transactions', function (Builder $query) use($value) {
|
||||
$query->where('type', $value)->whereIn('status', [0,1,2,3]);
|
||||
$query->where('type', $value);
|
||||
})->whereHas('containers', function ($query){
|
||||
return $query->whereDate('loading_date', '>=', Carbon::parse('20-09-2022'));
|
||||
});
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OwnerType implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('owner_type', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMLeadProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMLead;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMLead;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -30,12 +28,6 @@ class CreatePerfexCRMCustomer implements ShouldQueue
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$lead = (App()->make(FetchesPerfexCRMLead::class))->execute($this->createLeadPerfexCRMObject->getEmail());
|
||||
if(!is_null($lead)){
|
||||
(App()->make(UpdatesPerfexCRMLead::class))->execute($lead, $this->createLeadPerfexCRMObject->getCompanyReference());
|
||||
}
|
||||
else{
|
||||
(App()->make(CreatePerfexCRMLeadProcessor::class))->execute($this->createLeadPerfexCRMObject);
|
||||
}
|
||||
(App()->make(CreatePerfexCRMLeadProcessor::class))->execute($this->createLeadPerfexCRMObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMInvoiceProcessor;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Transaction;
|
||||
|
||||
class CreatePerfexCRMInvoice implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var Transaction $transaction*/
|
||||
private $transaction;
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMInvoice constructor.
|
||||
* @param Transaction $transaction
|
||||
*/
|
||||
public function __construct(Transaction $transaction)
|
||||
{
|
||||
$this->transaction = $transaction;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
(App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($this->transaction);
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMTaskProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMLead;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
|
||||
class CreatePerfexCRMSingleTask implements ShouldQueue
|
||||
{
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMInvoiceProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMInvoicePayment;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMInvoice;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMProject;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMInvoice;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoicePaymentPerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMInvoiceStatus;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoiceObject */
|
||||
private $updatePerfexCRMInvoiceObject;
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMSingleTask constructor.
|
||||
* @param UpdatePerfexCRMInvoiceObject $createTaskPerfexCRMObject
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject)
|
||||
{
|
||||
$this->updatePerfexCRMInvoiceObject = $updatePerfexCRMInvoiceObject;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//get the client id
|
||||
$customer = (App()->make(FetchesPerfexCRMCustomer::class))->execute($this->updatePerfexCRMInvoiceObject->getEmail());
|
||||
$transaction = $this->updatePerfexCRMInvoiceObject->getTransaction();
|
||||
|
||||
//get the invoice id
|
||||
$invoiceId = 0;
|
||||
$invoiceStatus = 0;
|
||||
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $transaction->owner->bill_no);
|
||||
|
||||
if(is_null($invoice)){
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction->owner, $this->updatePerfexCRMInvoiceObject->getIsPaid());
|
||||
$invoiceId = $result->payload['id'];
|
||||
}
|
||||
else{
|
||||
$invoiceId = $invoice->id;
|
||||
$invoiceStatus = $invoice->status;
|
||||
|
||||
//This only run when invoice already exist and the invoice does not have a PAID status
|
||||
if($invoiceStatus != PerfexCRMInvoiceStatus::PAID){
|
||||
//get project
|
||||
$projectId = "";
|
||||
$projectName = "";
|
||||
if($transaction->owner instanceof Transaction){
|
||||
$orderReference = $transaction->owner->owner->owner()->first()->reference;
|
||||
$packingListReference = $transaction->owner->owner->reference;
|
||||
$projectName = 'IZYIM | X1 Shipping | '.$orderReference.' | '.$packingListReference;
|
||||
$project = (App()->make(FetchesPerfexCRMProject::class))->execute($projectName, $customer->userid);
|
||||
if(!is_null($project)){
|
||||
$projectId = $project->id;
|
||||
}
|
||||
}
|
||||
|
||||
if($projectId == ""){
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug: '.$projectName));
|
||||
Log::error(json_encode($transaction->owner));
|
||||
}
|
||||
|
||||
//update invoice
|
||||
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $projectId);
|
||||
}
|
||||
}
|
||||
|
||||
//create invoice payment
|
||||
if($invoiceId != 0 && $invoiceStatus != PerfexCRMInvoiceStatus::PAID){
|
||||
|
||||
$date = Carbon::parse($transaction->created_at)->format('Y-m-d');
|
||||
|
||||
$invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject(
|
||||
$invoiceId,
|
||||
"$transaction->amount",
|
||||
$date,
|
||||
1,
|
||||
"",
|
||||
""
|
||||
);
|
||||
(App()->make(CreatesPerfexCRMInvoicePayment::class))->execute($invoicePaymentPerfexCRMObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,8 +161,7 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
$request->input('name'),
|
||||
$request->input('email'),
|
||||
$request->input('phone'),
|
||||
$request->input('type') === CompanyType::COMPANY_BUSINESS ? $request->input('company_name') : $request->input('name'),
|
||||
$connection->invitee_reference
|
||||
$request->input('type') === CompanyType::COMPANY_BUSINESS ? $request->input('company_name') : $request->input('name')
|
||||
);
|
||||
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
|
||||
}
|
||||
|
||||
@@ -68,19 +68,19 @@ class CreateBillingAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]);
|
||||
|
||||
$address = $this->fetchesAddress->execute(['id' => $request->input('billing_address_id')]);
|
||||
$billingAddressInputed = $this->fetchesAddress->execute(['id' => $request->input('billing_address_id')]);
|
||||
|
||||
if ($address->type !== AddressType::BILLING || $address->id !== $companyModule->addresses->where('type', AddressType::BILLING)->first()->id) {
|
||||
if ($billingAddressInputed->type !== AddressType::BILLING || $billingAddressInputed->id !== $companyModule->addresses->where('type', AddressType::BILLING)->first()->id) {
|
||||
// delete all current billing address
|
||||
Address::where('owner_type', CompanyModule::class)->where('owner_id', $request->input('company_module_id'))->where('type', AddressType::BILLING)->delete();
|
||||
|
||||
// create addrress
|
||||
$billingAddress = new AddressObject($address->street_one, $address->street_two, $address->country_id, $address->state_id, $address->district_id, $address->postcode, AddressType::BILLING, ApprovalStatus::APPROVED, $address->reference);
|
||||
// create new billing addrress
|
||||
$billingAddress = new AddressObject($billingAddressInputed->street_one, $billingAddressInputed->street_two, $billingAddressInputed->country_id, $billingAddressInputed->state_id, $billingAddressInputed->district_id, $billingAddressInputed->postcode, AddressType::BILLING, ApprovalStatus::APPROVED, $billingAddressInputed->reference);
|
||||
$this->canCreateAddress->passes($billingAddress);
|
||||
$this->createsAddress->execute($companyModule, $billingAddress);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new AddressResource($address));
|
||||
return $this->resourceResponse(new AddressResource($billingAddressInputed));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class CallbackBillplzLogic
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $status);
|
||||
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED);
|
||||
|
||||
if(($invoice->amount - $transaction->amount) < 0.01) {
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\CancelsOrder;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Services\FetchOwnerCompanyConnection;
|
||||
use App\Classes\Modules\Orders\Services\UpdateOwnerReference;
|
||||
use App\Http\Resources\OrderResource;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use App\Models\CompanyConnection;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ChangeOrderOwnerLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Changed order owner',
|
||||
'message' => 'You have successfully changed the owner'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var Marking $marking */
|
||||
private $marking;
|
||||
|
||||
/** @param UpdateOwnerReference $updateOwnerReference*/
|
||||
private $updateOwnerReference;
|
||||
private $fetchOwnerCompanyConnection;
|
||||
|
||||
public function __construct(UpdateOwnerReference $updateOwnerReference, FetchOwnerCompanyConnection $fetchOwnerCompanyConnection)
|
||||
{
|
||||
$this->updateOwnerReference = $updateOwnerReference;
|
||||
$this->fetchOwnerCompanyConnection = $fetchOwnerCompanyConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
protected function logic(Request $request): JsonResponse
|
||||
{
|
||||
$reference = $request->route('reference');
|
||||
|
||||
$packing = PackingList::where('reference', $reference)->get();
|
||||
|
||||
$companyConnection = $this->fetchOwnerCompanyConnection->execute($request->marking)->invitee->orders;
|
||||
|
||||
$order = $this->updateOwnerReference->execute($reference, $companyConnection);
|
||||
|
||||
return response()->json($packing,200);
|
||||
// return $this->resourceResponse(new PackingListResource($packing));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,14 +4,19 @@ namespace App\Classes\Modules\Orders\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\RequestValidationException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Addresses\Services\CreatesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\NewLeadTaskToPerfexCRMProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\CreateOrderProcessor;
|
||||
use App\Classes\Modules\Orders\Services\GeneratesOrderNumber;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\WarehouseReferences;
|
||||
use App\Http\Resources\OrderResource;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use App\Models\Address;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
@@ -40,8 +45,12 @@ class CreateOrderLogic extends AbstractControllerLogic
|
||||
/** @var GeneratesOrderNumber */
|
||||
private $generatesOrderNumber;
|
||||
|
||||
/** @var NewLeadTaskToPerfexCRMProcessor */
|
||||
private $newLeadTaskToPerfexCRMProcessor;
|
||||
/** @var CreatesAddress */
|
||||
private $createsAddress;
|
||||
|
||||
/** @var CanCreateAddress */
|
||||
private $canCreateAddress;
|
||||
|
||||
/**
|
||||
* CreateOrderLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
@@ -49,28 +58,45 @@ class CreateOrderLogic extends AbstractControllerLogic
|
||||
* @param CreateOrderProcessor $createOrderProcessor
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
* @param GeneratesOrderNumber $generatesOrderNumber
|
||||
* @param NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor
|
||||
* @param CreatesAddress $createsAddress
|
||||
* @param CanCreateAddress $canCreateAddress
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, FetchesAddress $fetchesAddress, CreateOrderProcessor $createOrderProcessor, FetchesCompanyModule $fetchesCompanyModule, GeneratesOrderNumber $generatesOrderNumber, NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor)
|
||||
public function __construct(FetchesCompany $fetchesCompany, FetchesAddress $fetchesAddress, CreateOrderProcessor $createOrderProcessor, FetchesCompanyModule $fetchesCompanyModule, GeneratesOrderNumber $generatesOrderNumber, CreatesAddress $createsAddress, CanCreateAddress $canCreateAddress)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->fetchesAddress = $fetchesAddress;
|
||||
$this->createOrderProcessor = $createOrderProcessor;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->generatesOrderNumber = $generatesOrderNumber;
|
||||
$this->newLeadTaskToPerfexCRMProcessor = $newLeadTaskToPerfexCRMProcessor;
|
||||
$this->createsAddress = $createsAddress;
|
||||
$this->canCreateAddress = $canCreateAddress;
|
||||
}
|
||||
|
||||
|
||||
public function logic(Request $request) : JsonResponse {
|
||||
|
||||
|
||||
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
|
||||
|
||||
$address = $this->fetchesAddress->execute(['id' => $request->input('address_id')]);
|
||||
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $request->input('warehouse_id')]);
|
||||
|
||||
if ($request->input('billing_address_id')) {
|
||||
$companyModule = $company->companyModules->first();
|
||||
$billingAddressInputed = $this->fetchesAddress->execute(['id' => $request->input('billing_address_id')]);
|
||||
|
||||
if ($billingAddressInputed->type !== AddressType::BILLING || $billingAddressInputed->id !== $companyModule->addresses->where('type', AddressType::BILLING)->first()->id) {
|
||||
// delete all current billing address
|
||||
Address::where('owner_type', CompanyModule::class)->where('owner_id', $request->input('company_module_id'))->where('type', AddressType::BILLING)->delete();
|
||||
|
||||
// create new billing addrress
|
||||
$billingAddress = new AddressObject($billingAddressInputed->street_one, $billingAddressInputed->street_two, $billingAddressInputed->country_id, $billingAddressInputed->state_id, $billingAddressInputed->district_id, $billingAddressInputed->postcode, AddressType::BILLING, ApprovalStatus::APPROVED, $billingAddressInputed->reference);
|
||||
$this->canCreateAddress->passes($billingAddress);
|
||||
$this->createsAddress->execute($companyModule, $billingAddress);
|
||||
}
|
||||
}
|
||||
|
||||
if(!in_array($company->companyModules()->importers()->first()->id, WarehouseReferences::YD_EXEMPT_LIST)){
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['reference' => $originWarehouse->reference === WarehouseReferences::VT_GUANG_ZHOU ? WarehouseReferences::YD_GUANG_ZHOU : WarehouseReferences::YD_YIWU]);
|
||||
}
|
||||
@@ -81,10 +107,6 @@ class CreateOrderLogic extends AbstractControllerLogic
|
||||
|
||||
$order = $this->createOrderProcessor->execute($company, $originWarehouse, $address, $this->generatesOrderNumber->execute());
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->newLeadTaskToPerfexCRMProcessor->execute($company);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new OrderResource($order));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanFetchOrder;
|
||||
use App\Http\Resources\BookingResource;
|
||||
use App\Http\Resources\OrderProfileResource;
|
||||
use App\Http\Resources\OrderResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -55,16 +54,8 @@ class FetchOrderLogic extends AbstractControllerLogic
|
||||
|
||||
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
|
||||
|
||||
$filter_array = (array)json_decode(($request->input('filters')));
|
||||
|
||||
if (isset($filter_array['display_without_parcel'])) {
|
||||
|
||||
if ($filter_array['display_without_parcel']) {
|
||||
return $this->collectionResponse(OrderProfileResource::collection($query));
|
||||
}
|
||||
}
|
||||
return $this->resourceResponse(new OrderResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\Services\ListsOrders;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanListOrders;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use App\Http\Resources\OrderProfileResource;
|
||||
use App\Http\Resources\OrderResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -48,14 +47,6 @@ class ListOrdersLogic extends AbstractControllerLogic
|
||||
|
||||
$query = $this->listsOrders->execute(array_merge($this->listsOrders->deserializeFilters($request->input('filters')), ['with_parcels' => true, 'type_in' => [OrderType::SHARED_CONTAINER, OrderType::DEDICATED_CONTAINER]]));
|
||||
|
||||
$filter_array = (array)json_decode(($request->input('filters')));
|
||||
|
||||
if (isset($filter_array['display_without_parcel'])) {
|
||||
if ($filter_array['display_without_parcel']) {
|
||||
return $this->collectionResponse(OrderProfileResource::collection($query));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->collectionResponse(OrderResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
||||
use App\Models\CompanyConnection;
|
||||
class FetchOwnerCompanyConnection extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(string $marking)
|
||||
{
|
||||
return CompanyConnection::Where('invitee_reference',$marking)->first();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class UpdateOwnerReference extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(string $reference, Object $owner)
|
||||
{
|
||||
foreach($owner as $owner) {
|
||||
PackingList::where('reference',$reference)->update(['owner_id' => $owner->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace App\Classes\Modules\PackingLists\Processors;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\Packable;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\PackingListToPerfexCRMProcessor;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
|
||||
@@ -26,20 +25,16 @@ class CreatePackingListProcessor
|
||||
/** @var CreatesPackingList */
|
||||
private $createsPackingList;
|
||||
|
||||
/** @var PackingListToPerfexCRMProcessor */
|
||||
private $packingListToPerfexCRMProcessor;
|
||||
|
||||
/**
|
||||
* CreatePackingListProcessor constructor.
|
||||
* @param CanCreatePackingList $canCreatePackingList
|
||||
* @param CreatesPackingList $createsPackingList
|
||||
* @param PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor
|
||||
*/
|
||||
public function __construct(CanCreatePackingList $canCreatePackingList, CreatesPackingList $createsPackingList, PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor)
|
||||
public function __construct(CanCreatePackingList $canCreatePackingList, CreatesPackingList $createsPackingList)
|
||||
{
|
||||
$this->canCreatePackingList = $canCreatePackingList;
|
||||
$this->createsPackingList = $createsPackingList;
|
||||
$this->packingListToPerfexCRMProcessor = $packingListToPerfexCRMProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,10 +59,6 @@ class CreatePackingListProcessor
|
||||
$object = new PackingListObject($object->getReference().'_01', $appointee_id, $type, ApprovalStatus::PENDING_SUBMISSION);
|
||||
$this->createsPackingList->execute($object, $packingList);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList);
|
||||
}
|
||||
|
||||
return $packingList;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,13 @@ class CreateLeadPerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $companyName;
|
||||
|
||||
/** @var string */
|
||||
private $companyReference;
|
||||
|
||||
public function __construct(string $name, string $email, string $phone, string $companyName, string $companyReference)
|
||||
public function __construct(string $name, string $email, string $phone, string $companyName)
|
||||
{
|
||||
|
||||
$this->name = $name;
|
||||
$this->email = $email;
|
||||
$this->phone = $phone;
|
||||
$this->companyName = $companyName;
|
||||
$this->companyReference = $companyReference;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,11 +60,4 @@ class CreateLeadPerfexCRMObject implements DataTransferObject
|
||||
return $this->companyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCompanyReference(): string
|
||||
{
|
||||
return $this->companyReference;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,8 @@ class CreateTaskPerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $status;
|
||||
|
||||
/** @var string */
|
||||
private $department;
|
||||
|
||||
public function __construct(string $email, string $name, string $description, string $leadId, string $projectId, string $milestoneId, string $reference, string $onTaskCompletion, string $status, string $department)
|
||||
public function __construct(string $email, string $name, string $description, string $leadId, string $projectId, string $milestoneId, string $reference, string $onTaskCompletion, string $status)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->name = $name;
|
||||
@@ -47,7 +45,6 @@ class CreateTaskPerfexCRMObject implements DataTransferObject
|
||||
$this->reference = $reference;
|
||||
$this->onTaskCompletion = $onTaskCompletion;
|
||||
$this->status = $status;
|
||||
$this->department = $department;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,11 +124,4 @@ class CreateTaskPerfexCRMObject implements DataTransferObject
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDepartment(): string
|
||||
{
|
||||
return $this->department;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@ class InitialPerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $projectName;
|
||||
|
||||
/** @var int */
|
||||
private $projectStatus;
|
||||
|
||||
/** @var array */
|
||||
private $milestoneNames;
|
||||
|
||||
@@ -35,7 +32,7 @@ class InitialPerfexCRMObject implements DataTransferObject
|
||||
private $taskNames;
|
||||
|
||||
|
||||
public function __construct(string $companyName, string $companyReference, string $contactName, string $contactEmail, string $bookingMarking, string $projectName, int $projectStatus, array $milestoneNames, array $taskNames)
|
||||
public function __construct(string $companyName, string $companyReference, string $contactName, string $contactEmail, string $bookingMarking, string $projectName, array $milestoneNames, array $taskNames)
|
||||
{
|
||||
|
||||
$this->companyName = $companyName;
|
||||
@@ -44,7 +41,6 @@ class InitialPerfexCRMObject implements DataTransferObject
|
||||
$this->contactEmail = $contactEmail;
|
||||
$this->bookingMarking = $bookingMarking;
|
||||
$this->projectName = $projectName;
|
||||
$this->projectStatus = $projectStatus;
|
||||
$this->milestoneNames = $milestoneNames;
|
||||
$this->taskNames = $taskNames;
|
||||
}
|
||||
@@ -97,14 +93,6 @@ class InitialPerfexCRMObject implements DataTransferObject
|
||||
return $this->projectName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectStatus(): int
|
||||
{
|
||||
return $this->projectStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class InvoicePerfexCRMObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
/** @var int */
|
||||
private $clientId;
|
||||
|
||||
/** @var string */
|
||||
@@ -56,9 +56,9 @@ class InvoicePerfexCRMObject implements DataTransferObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return int
|
||||
*/
|
||||
public function getClientId(): string
|
||||
public function getClientId(): int
|
||||
{
|
||||
return $this->clientId;
|
||||
}
|
||||
|
||||
+4
-4
@@ -14,7 +14,7 @@ class InvoiceSingleItemPerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
public $longDescription;
|
||||
|
||||
/** @var float */
|
||||
/** @var int */
|
||||
public $qty;
|
||||
|
||||
/** @var float */
|
||||
@@ -26,7 +26,7 @@ class InvoiceSingleItemPerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
public $unit;
|
||||
|
||||
public function __construct(string $description, string $longDescription, float $qty, float $rate, int $order, string $unit)
|
||||
public function __construct(string $description, string $longDescription, int $qty, float $rate, int $order, string $unit)
|
||||
{
|
||||
$this->description = $description;
|
||||
$this->longDescription = $longDescription;
|
||||
@@ -53,9 +53,9 @@ class InvoiceSingleItemPerfexCRMObject implements DataTransferObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
* @return int
|
||||
*/
|
||||
public function getQty(): float
|
||||
public function getQty(): int
|
||||
{
|
||||
return $this->qty;
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\DataTransferObjects;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\Transaction;
|
||||
|
||||
class UpdatePerfexCRMInvoiceObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $email;
|
||||
|
||||
/** @var Transaction */
|
||||
private $transaction;
|
||||
|
||||
/** @var bool */
|
||||
private $isPaid;
|
||||
|
||||
public function __construct(string $email, Transaction $transaction, bool $isPaid)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->transaction = $transaction;
|
||||
$this->isPaid = $isPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Transaction
|
||||
*/
|
||||
public function getTransaction(): Transaction
|
||||
{
|
||||
return $this->transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsPaid(): bool
|
||||
{
|
||||
return $this->isPaid;
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,6 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $companyReference;
|
||||
|
||||
/** @var string */
|
||||
private $contactName;
|
||||
|
||||
/** @var string */
|
||||
private $contactEmail;
|
||||
|
||||
@@ -25,28 +22,23 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $projectName;
|
||||
|
||||
/** @var int */
|
||||
private $projectStatus;
|
||||
/** @var string */
|
||||
private $milestoneName;
|
||||
|
||||
/** @var array */
|
||||
private $milestoneNames;
|
||||
|
||||
/** @var array */
|
||||
private $taskNames;
|
||||
/** @var string */
|
||||
private $taskName;
|
||||
|
||||
|
||||
public function __construct(string $companyName, string $companyReference, string $contactName, string $contactEmail, string $bookingMarking, string $projectName, int $projectStatus, array $milestoneNames, array $taskNames)
|
||||
public function __construct(string $companyName, string $companyReference, string $contactEmail, string $bookingMarking, string $projectName, string $milestoneName, string $taskName)
|
||||
{
|
||||
|
||||
$this->companyName = $companyName;
|
||||
$this->companyReference = $companyReference;
|
||||
$this->contactName = $contactName;
|
||||
$this->contactEmail = $contactEmail;
|
||||
$this->bookingMarking = $bookingMarking;
|
||||
$this->projectName = $projectName;
|
||||
$this->projectStatus = $projectStatus;
|
||||
$this->milestoneNames = $milestoneNames;
|
||||
$this->taskNames = $taskNames;
|
||||
$this->milestoneName = $milestoneName;
|
||||
$this->taskName = $taskName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,14 +57,6 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
return $this->companyReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContactName(): string
|
||||
{
|
||||
return $this->contactName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -98,26 +82,19 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectStatus(): int
|
||||
public function getMilestoneName(): string
|
||||
{
|
||||
return $this->projectStatus;
|
||||
return $this->milestoneName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public function getMilestoneNames(): array
|
||||
public function getTaskName(): string
|
||||
{
|
||||
return $this->milestoneNames;
|
||||
return $this->taskName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTaskNames(): array
|
||||
{
|
||||
return $this->taskNames;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,14 @@
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
use App\Models\Transaction;
|
||||
// use App\Classes\Modules\PerfexCRM\DataTransferObjects\ContactObject;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMInvoice;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMInvoicePayment;
|
||||
use App\Classes\Modules\PerfexCRM\Services\ConvertsPerfexCRMLeadToCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMProject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoicePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoicePaymentPerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoiceSingleItemPerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMCustomerProject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Models\PackingList;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreatePerfexCRMInvoiceProcessor
|
||||
{
|
||||
@@ -28,57 +23,42 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
/** @var ConvertsPerfexCRMLeadToCustomer */
|
||||
private $convertsPerfexCRMLeadToCustomer;
|
||||
|
||||
/** @var FetchesPerfexCRMProject */
|
||||
private $fetchesPerfexCRMProject;
|
||||
|
||||
/** @var CreatesPerfexCRMCustomerProject */
|
||||
private $createsPerfexCRMCustomerProject;
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMInvoiceProcessor constructor.
|
||||
* @param CreatesPerfexCRMInvoice $createsPerfexCRMInvoice
|
||||
*/
|
||||
public function __construct(CreatesPerfexCRMInvoice $createsPerfexCRMInvoice,
|
||||
CreatesPerfexCRMInvoicePayment $createsPerfexCRMInvoicePayment,
|
||||
ConvertsPerfexCRMLeadToCustomer $convertsPerfexCRMLeadToCustomer,
|
||||
FetchesPerfexCRMProject $fetchesPerfexCRMProject,
|
||||
CreatesPerfexCRMCustomerProject $createsPerfexCRMCustomerProject)
|
||||
ConvertsPerfexCRMLeadToCustomer $convertsPerfexCRMLeadToCustomer)
|
||||
{
|
||||
$this->createsPerfexCRMInvoice = $createsPerfexCRMInvoice;
|
||||
$this->createsPerfexCRMInvoicePayment = $createsPerfexCRMInvoicePayment;
|
||||
$this->convertsPerfexCRMLeadToCustomer = $convertsPerfexCRMLeadToCustomer;
|
||||
$this->fetchesPerfexCRMProject = $fetchesPerfexCRMProject;
|
||||
$this->createsPerfexCRMCustomerProject = $createsPerfexCRMCustomerProject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @param bool $isPaid, default: false
|
||||
* @param $transaction
|
||||
* @param $purchaseOrder
|
||||
* @param $supplier
|
||||
* @return null|object
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $transaction, bool $isPaid = false) {
|
||||
public function execute($transaction, $purchaseOrder, $supplier) {
|
||||
$clientId = "";
|
||||
$number = $transaction->bill_no;
|
||||
$prefix = "INV-";
|
||||
|
||||
//This will remove the prefix if prefix already exist in the string
|
||||
if (substr($number, 0, strlen($prefix)) == $prefix) {
|
||||
$number = substr($number, strlen($prefix));
|
||||
}
|
||||
|
||||
$date = Carbon::parse($transaction->created_at)->format('Y-m-d');
|
||||
$dueDate = Carbon::parse($transaction->created_at)->format('Y-m-d');
|
||||
$date = Carbon::parse($transaction->booking->created_at)->format('Y-m-d');
|
||||
$dueDate = Carbon::parse($transaction->booking->created_at)->format('Y-m-d');
|
||||
$currency = 1; //cief TODO: To look into Malaysia and Chinese currency
|
||||
$subTotal = 0.00;
|
||||
$total = 0.00;
|
||||
|
||||
$companyModule = $transaction->owner->owner->companyModule;
|
||||
$billingStreet = "";
|
||||
$addresses = $companyModule
|
||||
->addresses()
|
||||
->where('status', '=', \App\Classes\ValueObjects\Constants\ApprovalStatus::APPROVED)
|
||||
->where('type', '=', \App\Classes\ValueObjects\Constants\AddressType::BILLING)->first();
|
||||
$addresses = $supplier->addresses()->where('billing', '=', true)->first();
|
||||
|
||||
$billingStreet = $billingStreet.$addresses->street_one;
|
||||
$billingStreet = $billingStreet.$addresses->street_two.',';
|
||||
@@ -87,51 +67,40 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
$billingStreet = $billingStreet.$addresses->state()->first()->name.',';
|
||||
$billingStreet = $billingStreet.$addresses->country()->first()->name;
|
||||
|
||||
$projectId = "";
|
||||
$allowedPaymentModes = [];
|
||||
$invoiceItems = [];
|
||||
|
||||
$employee = $companyModule->employees()->first();
|
||||
$email = $employee->email;
|
||||
|
||||
$email = $supplier->employees()->first()->email;
|
||||
$email = 'dillon37@yahoo.com'; //cief TODO: To be updated to user actual email address
|
||||
$result = $this->convertsPerfexCRMLeadToCustomer->execute($email);
|
||||
if(isset($result->payload)){
|
||||
$clientId = $result->payload['client_id'];
|
||||
}
|
||||
|
||||
//get project
|
||||
$projectId = ""; //Project only exist in CRM if the customer already made payment
|
||||
$projectName = "";
|
||||
if($isPaid){
|
||||
if($transaction->owner instanceof PackingList){
|
||||
$orderReference = $transaction->owner->owner->reference;
|
||||
$packingListReference = $transaction->owner->reference;
|
||||
$projectName = 'IZYIM | X1 Shipping | '.$orderReference.' | '.$packingListReference;
|
||||
$project = $this->fetchesPerfexCRMProject->execute($projectName, $clientId);
|
||||
if(!is_null($project)){
|
||||
$projectId = $project->id;
|
||||
}
|
||||
else{
|
||||
$result = $this->createsPerfexCRMCustomerProject->execute($projectName, PerfexCRMProjectStatus::NOT_STARTED, $clientId);
|
||||
if(isset($result->payload)){ //Here means project creation successful
|
||||
$projectId = $result->payload['project_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($projectId == ""){
|
||||
Log::error(json_encode('CreatePerfexCRMInvoiceProcessor debug: '.$projectName));
|
||||
Log::error(json_encode($transaction->owner));
|
||||
}
|
||||
}
|
||||
|
||||
//newitems
|
||||
foreach ($transaction->transactionDetails as $key => $transaction_detail){
|
||||
foreach ($purchaseOrder->transactionDetails as $key => $transaction_detail){
|
||||
$order = $key + 1;
|
||||
$description = $transaction_detail->name;
|
||||
$stockCode = $transaction_detail->product_code;
|
||||
$description = $transaction_detail->product_name;
|
||||
$quantity = $transaction_detail->quantity;
|
||||
$unitPrice = $transaction_detail->price;
|
||||
$unitPrice = 0.00;
|
||||
if($transaction->booking()->first()->fix_currency_id !== 1)
|
||||
$unitPrice = (1/$transaction->currency_rate) * $transaction_detail->price;
|
||||
else
|
||||
$unitPrice = $transaction_detail->price;
|
||||
|
||||
$subTotal = $subTotal + $transaction_detail->amount;
|
||||
//$totalAmount = 0.00;
|
||||
if($transaction->booking()->first()->fix_currency_id !== 1){
|
||||
|
||||
//$totalAmount = (float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity;
|
||||
$subTotal += (1/$transaction->currency_rate) * $transaction_detail->price * $transaction_detail->quantity;
|
||||
}
|
||||
else
|
||||
{
|
||||
//$totalAmount = (float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity;
|
||||
$subTotal += $transaction_detail->price * $transaction_detail->quantity;
|
||||
}
|
||||
|
||||
//string $description, string $longDescription, int $qty, int $rate, int $order, string $unit
|
||||
$invoiceSingleItem = new InvoiceSingleItemPerfexCRMObject(
|
||||
@@ -145,11 +114,16 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
array_push($invoiceItems, $invoiceSingleItem);
|
||||
}
|
||||
|
||||
$total = $transaction->amount;
|
||||
if($transaction->booking()->first()->fix_currency_id !== 1){
|
||||
$total = ((1/$transaction->currency_rate) * $transaction->amount) + $transaction->service_charge + $transaction->tax;
|
||||
}
|
||||
else{
|
||||
$total = $transaction->amount + $transaction->service_charge + $transaction->tax;
|
||||
}
|
||||
|
||||
//This setting is similar to Setup > Leads > Sources, Setup > Leads > Statuses
|
||||
//Can be found at Finance > Payment Modes
|
||||
//cief TODO: To be updated, temporarily hardcoded allow payment modes
|
||||
array_push($allowedPaymentModes, 1, 2);
|
||||
|
||||
$invoicePerfexCRMObject = new InvoicePerfexCRMObject(
|
||||
$clientId,
|
||||
$number,
|
||||
@@ -166,7 +140,20 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
|
||||
$result = $this->createsPerfexCRMInvoice->execute($invoicePerfexCRMObject);
|
||||
|
||||
return $result;
|
||||
//If there is a checking whether an payment to an invoice need to be generated, do it here
|
||||
if(true && $result->payload['id']){
|
||||
$invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject(
|
||||
$result->payload['id'],
|
||||
$total,
|
||||
$date,
|
||||
1,
|
||||
"",
|
||||
""
|
||||
);
|
||||
$this->createsPerfexCRMInvoicePayment->execute($invoicePaymentPerfexCRMObject);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ class CreatePerfexCRMTaskProcessor
|
||||
$createTaskPerfexCRMObject->getProjectId(),
|
||||
$createTaskPerfexCRMObject->getReference(),
|
||||
$createTaskPerfexCRMObject->getOnTaskCompletion(),
|
||||
$createTaskPerfexCRMObject->getDepartment(),
|
||||
$createTaskPerfexCRMObject->getStatus(),
|
||||
);
|
||||
return true;
|
||||
|
||||
@@ -18,7 +18,7 @@ use App\Classes\Modules\PerfexCRM\DataTransferObjects\InitialPerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMMilestones;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMStatus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -149,7 +149,7 @@ class InitializePerfexCRMProcessor
|
||||
}
|
||||
|
||||
// Get existing or create project, project has to exist first before milestone can appear under it
|
||||
$result = $this->createsPerfexCRMCustomerProject->execute($initialPerfexCRMObject->getProjectName(), $initialPerfexCRMObject->getProjectStatus(), $crmClientId);
|
||||
$result = $this->createsPerfexCRMCustomerProject->execute($initialPerfexCRMObject->getProjectName(), $crmClientId);
|
||||
if(isset($result->payload)){ //Here means project creation successful
|
||||
$projectId = $result->payload['project_id'];
|
||||
}
|
||||
@@ -157,8 +157,8 @@ class InitializePerfexCRMProcessor
|
||||
$projectId = $this->fetchesPerfexCRMProject->execute($initialPerfexCRMObject->getProjectName(), $crmClientId)->id;
|
||||
}
|
||||
|
||||
$tasks = $initialPerfexCRMObject->getTaskNames();
|
||||
if(count($tasks) > 0){
|
||||
if(!is_null($result)){
|
||||
$tasks = $initialPerfexCRMObject->getTaskNames();
|
||||
|
||||
//Create tasks with milestone
|
||||
for($count=0; $count < count($tasks); $count++) {
|
||||
@@ -177,16 +177,13 @@ class InitializePerfexCRMProcessor
|
||||
}
|
||||
}
|
||||
|
||||
$taskStatus = PerfexCRMTaskStatus::NOT_STARTED;
|
||||
$taskStatus = PerfexCRMStatus::NOT_STARTED;
|
||||
if($tasks[$count]['status'] != ''){
|
||||
$taskStatus = $tasks[$count]['status'];
|
||||
}
|
||||
|
||||
// Get existing or create task
|
||||
$result = $this->createsPerfexCRMTask->execute($tasks[$count]['name'], $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'],$tasks[$count]['department'], $taskStatus);
|
||||
if(is_null($result)){
|
||||
break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously
|
||||
}
|
||||
$result = $this->createsPerfexCRMTask->execute($tasks[$count]['name'], $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $taskStatus);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -3,34 +3,28 @@
|
||||
namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMStatus;
|
||||
use App\Classes\Jobs\CreatePerfexCRMSingleTask;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Models\Company;
|
||||
|
||||
class NewLeadTaskToPerfexCRMProcessor
|
||||
{
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param None
|
||||
* @return true
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company)
|
||||
public function execute()
|
||||
{
|
||||
$companyModule = $company->companyModules()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
|
||||
$createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject(
|
||||
$contactEmail,
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['name'],
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['description'],
|
||||
"dillontest1@gmail.com",
|
||||
"test is the name of the task",
|
||||
"this is the description of the task",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['status'],
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['department']
|
||||
PerfexCRMStatus::NOT_STARTED
|
||||
);
|
||||
|
||||
CreatePerfexCRMSingleTask::dispatch($createTaskPerfexCRMObject);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Classes\Jobs\UpdatePerfexCRM;
|
||||
use App\Models\PackingList;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PackingListToPerfexCRMProcessor
|
||||
{
|
||||
/**
|
||||
* @param PackingList $packingList
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $packingList)
|
||||
{
|
||||
try {
|
||||
$order = $packingList->owner;
|
||||
$companyModule = $order->companyModule()->first();
|
||||
$connection = $companyModule->inviters()->withPivot('invitee_reference')->first();
|
||||
$companyName = $companyModule->name;
|
||||
$companyReference = $connection ? $connection->pivot->invitee_reference:'';
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
$contactName = $employee->name;
|
||||
|
||||
$orderReference = $packingList->owner->reference;
|
||||
$packingListReference = $packingList->reference;
|
||||
$projectName = 'IZYIM | X1 Shipping | '.$orderReference.' | '.$packingListReference;
|
||||
|
||||
$updatePerfexCRMObject = new UpdatePerfexCRMObject(
|
||||
$companyName,
|
||||
$companyReference,
|
||||
$contactName,
|
||||
$contactEmail,
|
||||
"",
|
||||
$projectName,
|
||||
PerfexCRMProjectStatus::NOT_STARTED,
|
||||
[],
|
||||
[
|
||||
PerfexCRMTasks::TASK_LOADED_CONTAINER_1,
|
||||
PerfexCRMTasks::TASK_LOADED_CONTAINER_2,
|
||||
]
|
||||
);
|
||||
UpdatePerfexCRM::dispatch($updatePerfexCRMObject);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
Log::error(json_encode('PackingListToPerfexCRMProcessor debug:'));
|
||||
Log::error(json_encode($packingList));
|
||||
Log::error($exception);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,14 @@ use App\Classes\Modules\PerfexCRM\Processors\InitializePerfexCRMProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Services\Init;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\InitialPerfexCRMObject;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMMilestones;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Jobs\UpdatePerfexCRMInvoice;
|
||||
use App\Classes\Jobs\UpdatePerfexCRM;
|
||||
use App\Models\Transaction;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Jobs\InitializePerfexCRM;
|
||||
use App\Classes\Jobs\UpdatePerfexCRM;
|
||||
|
||||
class TransactionToPerfexCRMProcessor
|
||||
{
|
||||
@@ -50,30 +49,28 @@ class TransactionToPerfexCRMProcessor
|
||||
*/
|
||||
public function execute(Transaction $model, int $status)
|
||||
{
|
||||
if($model->owner instanceof \App\Models\Transaction && $status == ApprovalStatus::APPROVED)
|
||||
{
|
||||
$packingList = $model->owner->owner;
|
||||
$order = $packingList->owner()->first();
|
||||
$companyModule = $order->companyModule()->first();
|
||||
if($model->owner instanceof \App\Models\Transaction && $status == ApprovalStatus::APPROVED){
|
||||
//dd(json_encode($packingList->owner()->first()->companyModule()->first()->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference));
|
||||
//dd(json_encode($model->owner->owner->owner()->first()->companyModule()->first()->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference));
|
||||
$companyModule = $model->owner->owner->owner()->first()->companyModule()->first();
|
||||
$companyName = $companyModule->name;
|
||||
$companyReference = $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
$contactName = $employee->name;
|
||||
|
||||
$orderReference = $order->reference;
|
||||
$packingListReference = $packingList->reference;
|
||||
$orderReference = $model->owner->owner->owner()->first()->reference;
|
||||
$packingListReference = $model->owner->owner->reference;
|
||||
$projectName = 'IZYIM | X1 Shipping | '.$orderReference.' | '.$packingListReference;
|
||||
|
||||
$bookingMarking = $packingList->id."-".$packingList->owner->id;
|
||||
$updatePerfexCRMObject = new UpdatePerfexCRMObject(
|
||||
$bookingMarking = $model->owner->owner->id."-".$model->owner->owner->owner->id;
|
||||
$initialPerfexCRMObject = new InitialPerfexCRMObject(
|
||||
$companyName,
|
||||
$companyReference,
|
||||
$contactName,
|
||||
$contactEmail,
|
||||
$bookingMarking,
|
||||
$projectName,
|
||||
PerfexCRMProjectStatus::IN_PROGRESS,
|
||||
[],
|
||||
[
|
||||
PerfexCRMTasks::TASK_1,
|
||||
@@ -84,16 +81,9 @@ class TransactionToPerfexCRMProcessor
|
||||
]
|
||||
);
|
||||
|
||||
UpdatePerfexCRM::dispatch($updatePerfexCRMObject);
|
||||
|
||||
$updatePerfexCRMInvoiceOject = new UpdatePerfexCRMInvoiceObject(
|
||||
$contactEmail,
|
||||
$model,
|
||||
true
|
||||
);
|
||||
UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceOject);
|
||||
//$this->initializePerfexCRMProcessor->execute($initialPerfexCRMObject);
|
||||
InitializePerfexCRM::dispatch($initialPerfexCRMObject);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,11 @@ use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMMilestone;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMTask;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMCustomerContact;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMProject;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMTask;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMStatus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -51,16 +49,11 @@ class UpdatePerfexCRMProcessor
|
||||
/** @var CreatesPerfexCRMCustomerContact */
|
||||
private $createsPerfexCRMCustomerContact;
|
||||
|
||||
/** @var UpdatesPerfexCRM */
|
||||
private $updatePerfexCRM;
|
||||
/** @var UpdatesPerfexCRMTask */
|
||||
private $updatesPerfexCRMTask;
|
||||
|
||||
/** @var UpdatesPerfexCRMCustomer */
|
||||
private $updatesPerfexCRMCustomer;
|
||||
|
||||
/** @var UpdatesPerfexCRMProject */
|
||||
private $updatesPerfexCRMProject;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param ConvertsPerfexCRMLeadToCustomer $convertsPerfexCRMLeadToCustomer
|
||||
* @param CreatesPerfexCRMCustomerProject $createsPerfexCRMCustomerProject
|
||||
* @param CreatesPerfexCRMMilestone $createsPerfexCRMMilestone
|
||||
@@ -70,20 +63,18 @@ class UpdatePerfexCRMProcessor
|
||||
* @param FetchesPerfexCRMTask $fetchesPerfexCRMTask
|
||||
* @param CreatesPerfexCRMCustomer $createsPerfexCRMCustomer
|
||||
* @param CreatesPerfexCRMCustomerContact $createsPerfexCRMCustomerContact
|
||||
* @param UpdatesPerfexCRMCustomer $updatesPerfexCRMCustomer
|
||||
* @param UpdatesPerfexCRMProject $updatesPerfexCRMProject
|
||||
* @param UpdatesPerfexCRMTask $updatesPerfexCRMTask
|
||||
*/
|
||||
public function __construct(ConvertsPerfexCRMLeadToCustomer $convertsPerfexCRMLeadToCustomer,
|
||||
CreatesPerfexCRMCustomerProject $createsPerfexCRMCustomerProject,
|
||||
CreatesPerfexCRMMilestone $createsPerfexCRMMilestone,
|
||||
CreatesPerfexCRMTask $createsPerfexCRMTask,
|
||||
FetchesPerfexCRMProject $fetchesPerfexCRMProject,
|
||||
FetchesPerfexCRMMilestone $fetchesPerfexCRMMilestone,
|
||||
FetchesPerfexCRMTask $fetchesPerfexCRMTask,
|
||||
CreatesPerfexCRMCustomer $createsPerfexCRMCustomer,
|
||||
CreatesPerfexCRMCustomerContact $createsPerfexCRMCustomerContact,
|
||||
UpdatesPerfexCRMCustomer $updatesPerfexCRMCustomer,
|
||||
UpdatesPerfexCRMProject $updatesPerfexCRMProject)
|
||||
CreatesPerfexCRMCustomerProject $createsPerfexCRMCustomerProject,
|
||||
CreatesPerfexCRMMilestone $createsPerfexCRMMilestone,
|
||||
CreatesPerfexCRMTask $createsPerfexCRMTask,
|
||||
FetchesPerfexCRMProject $fetchesPerfexCRMProject,
|
||||
FetchesPerfexCRMMilestone $fetchesPerfexCRMMilestone,
|
||||
FetchesPerfexCRMTask $fetchesPerfexCRMTask,
|
||||
CreatesPerfexCRMCustomer $createsPerfexCRMCustomer,
|
||||
CreatesPerfexCRMCustomerContact $createsPerfexCRMCustomerContact,
|
||||
UpdatesPerfexCRMTask $updatesPerfexCRMTask)
|
||||
{
|
||||
$this->convertsPerfexCRMLeadToCustomer = $convertsPerfexCRMLeadToCustomer;
|
||||
$this->createsPerfexCRMCustomerProject = $createsPerfexCRMCustomerProject;
|
||||
@@ -94,113 +85,55 @@ class UpdatePerfexCRMProcessor
|
||||
$this->fetchesPerfexCRMTask = $fetchesPerfexCRMTask;
|
||||
$this->createsPerfexCRMCustomer = $createsPerfexCRMCustomer;
|
||||
$this->createsPerfexCRMCustomerContact = $createsPerfexCRMCustomerContact;
|
||||
$this->updatesPerfexCRMCustomer = $updatesPerfexCRMCustomer;
|
||||
$this->updatesPerfexCRMProject = $updatesPerfexCRMProject;
|
||||
}
|
||||
$this->updatesPerfexCRMTask = $updatesPerfexCRMTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param PerfexCRMObject $perfexCRMObject
|
||||
* @return null|object
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(UpdatePerfexCRMObject $updatePerfexCRMObject) {
|
||||
public function execute(UpdatePerfexCRMObject $updatePerfexCRMObject) {
|
||||
|
||||
// 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();
|
||||
$result = $this->convertsPerfexCRMLeadToCustomer->execute($updatePerfexCRMObject->getContactEmail());
|
||||
if(isset($result->payload)){
|
||||
$crmClientId = $result->payload['client_id'];
|
||||
if (isset($result->payload['company'])) {
|
||||
$crmCompany = $result->payload['company'];
|
||||
}
|
||||
}
|
||||
else{
|
||||
//if reach this point, this means this user is not a official customer nor is a lead in crm
|
||||
//Create Customer has 2 parts: Create Company (client), Create Contact
|
||||
$result = $this->createsPerfexCRMCustomer->execute($crmCompany);
|
||||
if(is_null($result)){
|
||||
$crmCompany = $crmCompany." 2";
|
||||
$result = $this->createsPerfexCRMCustomer->execute($crmCompany);
|
||||
}
|
||||
|
||||
$crmClientId = $result->payload['clientId'];
|
||||
|
||||
$customerContactObject = new CustomerContactObject(
|
||||
$crmClientId,
|
||||
$updatePerfexCRMObject->getContactName(),
|
||||
$updatePerfexCRMObject->getContactName(),
|
||||
$updatePerfexCRMObject->getContactEmail(),
|
||||
"pU^T@sC#9Q",
|
||||
"on",
|
||||
"on"
|
||||
);
|
||||
$result = $this->createsPerfexCRMCustomerContact->execute($customerContactObject);
|
||||
}
|
||||
|
||||
//Update custom fields to identify company reference from exchange or shipping portal
|
||||
$value_exists = false;
|
||||
if (isset($result->payload['customfields'])) {
|
||||
foreach ($result->payload['customfields'] as $element) {
|
||||
if ($element['value'] === $updatePerfexCRMObject->getCompanyReference()) {
|
||||
$value_exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!$value_exists);
|
||||
{
|
||||
$result = $this->updatesPerfexCRMCustomer->execute($crmClientId, $crmCompany, $updatePerfexCRMObject->getCompanyReference());
|
||||
}
|
||||
|
||||
// Get existing or create project, project has to exist first before milestone can appear under it
|
||||
$result = $this->createsPerfexCRMCustomerProject->execute($updatePerfexCRMObject->getProjectName(), $updatePerfexCRMObject->getProjectStatus(), $crmClientId);
|
||||
if(isset($result->payload)){ //Here means project creation successful
|
||||
$projectId = $result->payload['project_id'];
|
||||
}
|
||||
else{
|
||||
$project = $this->fetchesPerfexCRMProject->execute($updatePerfexCRMObject->getProjectName(), $crmClientId);
|
||||
$projectId = $project->id;
|
||||
//if the project status is anything but PerfexCRMProjectStatus::NOT_STARTED, update the project
|
||||
if($updatePerfexCRMObject->getProjectStatus() != PerfexCRMProjectStatus::NOT_STARTED)
|
||||
{
|
||||
$this->updatesPerfexCRMProject->execute($project, $updatePerfexCRMObject->getProjectStatus());
|
||||
}
|
||||
}
|
||||
|
||||
$tasks = $updatePerfexCRMObject->getTaskNames();
|
||||
if(count($tasks) > 0){
|
||||
|
||||
//Create tasks with milestone
|
||||
for($count=0; $count < count($tasks); $count++) {
|
||||
$milestoneId = 0; //By default milestoneId is 0, having this set at individual task is optional
|
||||
if($tasks[$count]['milestone'] != "") //Create milestone only if it is defined
|
||||
{
|
||||
// Get existing or create milestone, milestone has to exist first before task can appear under it
|
||||
$result = $this->createsPerfexCRMMilestone->execute($tasks[$count]['milestone'], $projectId, $count);
|
||||
if(isset($result->payload)){
|
||||
$milestoneId = $result->payload['milestone_id'];
|
||||
}
|
||||
else{
|
||||
$milestone = $this->fetchesPerfexCRMMilestone->execute($tasks[$count]['milestone'], $projectId);
|
||||
$array = json_decode(json_encode($milestone), true);
|
||||
$milestoneId = $array[0]['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$taskStatus = PerfexCRMTaskStatus::NOT_STARTED;
|
||||
if($tasks[$count]['status'] != ''){
|
||||
$taskStatus = $tasks[$count]['status'];
|
||||
}
|
||||
|
||||
// Get existing or create task
|
||||
$result = $this->createsPerfexCRMTask->execute($tasks[$count]['name'], $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus);
|
||||
if(is_null($result)){
|
||||
break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously
|
||||
}
|
||||
}
|
||||
// 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
|
||||
$result = $this->convertsPerfexCRMLeadToCustomer->execute($updatePerfexCRMObject->getContactEmail());
|
||||
if(isset($result->payload)){
|
||||
$crmClientId = $result->payload['client_id'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get existing or create project, project has to exist first before milestone can appear under it
|
||||
$result = $this->createsPerfexCRMCustomerProject->execute($updatePerfexCRMObject->getProjectName(), $crmClientId);
|
||||
if(isset($result->payload)){
|
||||
$projectId = $result->payload['project_id'];
|
||||
}
|
||||
else{
|
||||
$projectId = $this->fetchesPerfexCRMProject->execute($updatePerfexCRMObject->getProjectName(), $crmClientId)->id;
|
||||
}
|
||||
|
||||
// Get existing or create milestone, milestone has to exist first before task can appear under it
|
||||
$result = $this->createsPerfexCRMMilestone->execute($updatePerfexCRMObject->getMilestoneName(), $projectId);
|
||||
if(isset($result->payload)){
|
||||
$milestoneId = $result->payload['milestone_id'];
|
||||
}
|
||||
else{
|
||||
$milestone = $this->fetchesPerfexCRMMilestone->execute($updatePerfexCRMObject->getMilestoneName(), $projectId);
|
||||
$array = json_decode(json_encode($milestone), true);
|
||||
$milestoneId = $array[0]['id'];
|
||||
}
|
||||
|
||||
// Get existing or create task
|
||||
$result = $this->createsPerfexCRMTask->execute($updatePerfexCRMObject->getTaskName(), $milestoneId, $projectId);
|
||||
if(isset($result->payload)){
|
||||
$taskId = $result->payload['task_id'];
|
||||
}
|
||||
else{
|
||||
$taskId = $this->fetchesPerfexCRMTask->execute($updatePerfexCRMObject->getTaskName(), $milestoneId)->id;
|
||||
}
|
||||
|
||||
$this->updatesPerfexCRMTask->execute($taskId, $updatePerfexCRMObject->getTaskName(), $milestoneId, $projectId, PerfexCRMStatus::COMPLETED);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class CreatesPerfexCRMCustomerProject
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $projectName, int $status, string $clientId) {
|
||||
public function execute(string $projectName, string $clientId) {
|
||||
try{
|
||||
$data = [
|
||||
'name' => $projectName,
|
||||
@@ -22,7 +22,7 @@ class CreatesPerfexCRMCustomerProject
|
||||
'billing_type' => 1,
|
||||
'clientid' => $clientId,
|
||||
'start_date' => date('Y-m-d'),
|
||||
'status' => $status
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$response = Http::asForm()->withHeaders([
|
||||
|
||||
@@ -22,8 +22,8 @@ class CreatesPerfexCRMInvoice
|
||||
'date' => $invoicePerfexCRMObject->getDate(),
|
||||
'duedate' => $invoicePerfexCRMObject->getDueDate(),
|
||||
'currency' => $invoicePerfexCRMObject->getCurrency(),
|
||||
'subtotal' => number_format($invoicePerfexCRMObject->getSubTotal(), 2, '.', ''),
|
||||
'total' => number_format($invoicePerfexCRMObject->getTotal(), 2, '.', ''),
|
||||
'subtotal' => $invoicePerfexCRMObject->getSubTotal(),
|
||||
'total' => $invoicePerfexCRMObject->getTotal(),
|
||||
'billing_street' => $invoicePerfexCRMObject->getBillingStreet(),
|
||||
'project_id' => $invoicePerfexCRMObject->getProjectId(),
|
||||
'allowed_payment_modes[0]' => 1,
|
||||
|
||||
@@ -18,7 +18,7 @@ class CreatesPerfexCRMInvoicePayment
|
||||
try{
|
||||
$data = [
|
||||
'invoiceid' => $invoicePaymentPerfexCRMObject->getInvoiceId(),
|
||||
'amount' => number_format($invoicePaymentPerfexCRMObject->getAmount(), 2, '.', ''),
|
||||
'amount' => $invoicePaymentPerfexCRMObject->getAmount(),
|
||||
'date' => $invoicePaymentPerfexCRMObject->getDate(),
|
||||
'paymentmode' => $invoicePaymentPerfexCRMObject->getPaymentMode(),
|
||||
'transactionid' => $invoicePaymentPerfexCRMObject->getTransactionId(),
|
||||
|
||||
@@ -16,20 +16,13 @@ class CreatesPerfexCRMLead
|
||||
*/
|
||||
public function execute(CreateLeadPerfexCRMObject $createLeadPerfexCRMObject) {
|
||||
try{
|
||||
$custom_fields = [
|
||||
"leads" => [
|
||||
4 => $createLeadPerfexCRMObject->getCompanyReference()
|
||||
]
|
||||
];
|
||||
|
||||
$data = [
|
||||
'name' => $createLeadPerfexCRMObject->getName(),
|
||||
'email' => $createLeadPerfexCRMObject->getEmail(),
|
||||
'phonenumber' => $createLeadPerfexCRMObject->getPhone(),
|
||||
'company' => $createLeadPerfexCRMObject->getCompanyName(),
|
||||
'source' => 2, //1: Exchange, 2: Shipping Portal
|
||||
'status' => 2, //2: Lead, 1: Customer
|
||||
'custom_fields' => $custom_fields
|
||||
'status' => 2 //2: Lead, 1: Customer
|
||||
];
|
||||
|
||||
$response = Http::asForm()->withHeaders([
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
|
||||
|
||||
class CreatesPerfexCRMTask
|
||||
{
|
||||
@@ -21,17 +20,8 @@ class CreatesPerfexCRMTask
|
||||
* @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 = "1") {
|
||||
public function execute(string $taskName, string $taskDescription, string $leadId, string $milestoneId, string $projectId, string $reference = '', string $on_task_completion = '', string $status = "1") {
|
||||
try{
|
||||
$custom_fields = [];
|
||||
if($department != ""){
|
||||
$custom_fields = [
|
||||
"tasks" => [
|
||||
PerfexCRMCustomFields::TASKS_DEPARTMENT => $department
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $taskName,
|
||||
'description' => $taskDescription,
|
||||
@@ -42,8 +32,7 @@ class CreatesPerfexCRMTask
|
||||
'status' => $status,
|
||||
'is_system_created' => 1,
|
||||
'reference' => $reference,
|
||||
'on_task_completion' => $on_task_completion,
|
||||
'custom_fields' => $custom_fields
|
||||
'on_task_completion' => $on_task_completion
|
||||
];
|
||||
|
||||
if($leadId != '') {
|
||||
@@ -57,8 +46,7 @@ class CreatesPerfexCRMTask
|
||||
'status' => $status,
|
||||
'is_system_created' => 1,
|
||||
'reference' => $reference,
|
||||
'on_task_completion' => $on_task_completion,
|
||||
'custom_fields' => $custom_fields
|
||||
'on_task_completion' => $on_task_completion
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchesPerfexCRMCustomer
|
||||
{
|
||||
/**
|
||||
* @param string $email
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $email) {
|
||||
try{
|
||||
$response = Http::withHeaders([
|
||||
'authtoken' => config('perfexcrm.api_key'),])
|
||||
->get(config('perfexcrm.base_url').'/api/customers/byemail/'.$email);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchesPerfexCRMInvoice
|
||||
{
|
||||
/**
|
||||
* @param string $clientId
|
||||
* @param string $invoicePrefix
|
||||
* @param string $invoiceNumber
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $clientId, string $invoicePrefix, string $invoiceNumber) {
|
||||
try{
|
||||
$response = Http::withHeaders([
|
||||
'authtoken' => config('perfexcrm.api_key'),])
|
||||
->get(config('perfexcrm.base_url').'/api/invoices/customsearch/'.$clientId.'/'.$invoicePrefix.'/'.$invoiceNumber);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
|
||||
|
||||
class UpdatesPerfexCRMCustomer
|
||||
{
|
||||
@@ -20,7 +19,7 @@ class UpdatesPerfexCRMCustomer
|
||||
try{
|
||||
$custom_fields = [
|
||||
"customers" => [
|
||||
PerfexCRMCustomFields::CUSTOMERS_SHIPPING_PORTAL_REFERENCE => $companyReference
|
||||
2 => $companyReference
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdatesPerfexCRMInvoice
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $invoice
|
||||
* @param string $projectId
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute($invoice, string $projectId) {
|
||||
try{
|
||||
// <p>The Invoice number field is required.<\/p>
|
||||
// <p>The Invoice date field is required.<\/p>
|
||||
// <p>The Currency field is required.<\/p>
|
||||
// <p>The Items field is required.<\/p>
|
||||
// <p>The Allow Payment Mode field is required.<\/p>
|
||||
// <p>The Billing Street field is required.<\/p>
|
||||
// <p>The Sub Total field is required.<\/p>
|
||||
// <p>The Total field is required.<\/p>
|
||||
|
||||
$newInvoiceItems = [];
|
||||
foreach ($invoice->items as $item) {
|
||||
$item['itemid'] = $item['id'];
|
||||
unset($item['id']);
|
||||
$item['order'] = $item['item_order'];
|
||||
unset($item['item_order']);
|
||||
array_push($newInvoiceItems,$item);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'number' => $invoice->number,
|
||||
'date' => $invoice->date,
|
||||
'duedate' => $invoice->date,
|
||||
'currency' => $invoice->currency,
|
||||
'subtotal' => $invoice->subtotal,
|
||||
'total' => $invoice->total,
|
||||
'billing_street' => $invoice->billing_street,
|
||||
'shipping_street' => $invoice->billing_street,
|
||||
'project_id' => $projectId,
|
||||
'items' => $newInvoiceItems,
|
||||
'allowed_payment_modes' => $invoice->allowed_payment_modes,
|
||||
];
|
||||
|
||||
$response = Http::asJson()->withHeaders([
|
||||
'authtoken' => config('perfexcrm.api_key')])
|
||||
->put(config('perfexcrm.base_url').'/api/invoices/'.$invoice->id, $data);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
|
||||
|
||||
class UpdatesPerfexCRMLead
|
||||
{
|
||||
/**
|
||||
* @param $lead
|
||||
* @param string $companyReference
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute($lead, string $companyReference) {
|
||||
try{
|
||||
$custom_fields = [
|
||||
"leads" => [
|
||||
PerfexCRMCustomFields::LEADS_SHIPPING_PORTAL_REFERENCE => $companyReference
|
||||
]
|
||||
];
|
||||
|
||||
$data = [
|
||||
'name' => $lead->name,
|
||||
'email' => $lead->email,
|
||||
'phonenumber' => $lead->phonenumber,
|
||||
'company' => $lead->company,
|
||||
'custom_fields' => $custom_fields,
|
||||
'source' => $lead->source,
|
||||
'status' => $lead->status,
|
||||
];
|
||||
|
||||
$response = Http::asJson()->withHeaders([
|
||||
'authtoken' => config('perfexcrm.api_key')])
|
||||
->put(config('perfexcrm.base_url').'/api/leads/'.$lead->id, $data);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdatesPerfexCRMProject
|
||||
{
|
||||
/**
|
||||
* @param $project
|
||||
* @param int $status
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute($project, int $status) {
|
||||
try{
|
||||
$data = [
|
||||
'name' => $project->name,
|
||||
'clientid' => $project->clientid,
|
||||
// 'rel_type' => 'customer',
|
||||
'billing_type' => 1,
|
||||
'start_date' => $project->start_date,
|
||||
'status' => $status
|
||||
];
|
||||
|
||||
$response = Http::asJson()->withHeaders([
|
||||
'authtoken' => config('perfexcrm.api_key')])
|
||||
->put(config('perfexcrm.base_url').'/api/projects/'.$project->id, $data);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
-8
@@ -16,7 +16,6 @@ use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Jobs\CreatePerfexCRMInvoice;
|
||||
|
||||
class ApproveShippingInvoiceTransactionProcessor
|
||||
{
|
||||
@@ -30,7 +29,6 @@ class ApproveShippingInvoiceTransactionProcessor
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
|
||||
/**
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param CreatesDocument $createsDocument
|
||||
@@ -74,12 +72,6 @@ class ApproveShippingInvoiceTransactionProcessor
|
||||
if(app()->environment(['production'])) {
|
||||
$user->notify(new InvoiceIssuedEmail($user, $packingList));
|
||||
}
|
||||
|
||||
// update perfex crm
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
CreatePerfexCRMInvoice::dispatch($invoice_transaction);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class PerfexCRMCustomFields {
|
||||
|
||||
public const CUSTOMERS_EXCHANGE_REFERENCE = 1;
|
||||
|
||||
public const CUSTOMERS_SHIPPING_PORTAL_REFERENCE = 2;
|
||||
|
||||
public const LEADS_EXCHANGE_REFERENCE = 3;
|
||||
|
||||
public const LEADS_SHIPPING_PORTAL_REFERENCE = 4;
|
||||
|
||||
public const TICKETS_CUSTOM_TAGS = 5;
|
||||
|
||||
public const TASKS_DEPARTMENT = 6;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class PerfexCRMInvoiceStatus {
|
||||
|
||||
public const UNPAID = 1;
|
||||
|
||||
public const PAID = 2;
|
||||
|
||||
public const PARTIALLY_PAID = 3;
|
||||
|
||||
public const OVERDUE = 4;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class PerfexCRMProjectStatus {
|
||||
|
||||
public const NOT_STARTED = 1;
|
||||
|
||||
public const IN_PROGRESS = 2;
|
||||
|
||||
public const ON_HOLD = 3;
|
||||
|
||||
public const FINISHED = 4;
|
||||
|
||||
public const CANCELLED = 5;
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class PerfexCRMTaskStatus {
|
||||
final class PerfexCRMStatus {
|
||||
|
||||
public const NOT_STARTED = 1;
|
||||
|
||||
@@ -11,7 +11,7 @@ final class PerfexCRMTaskStatus {
|
||||
public const TESTING = 3;
|
||||
|
||||
public const IN_PROGRESS = 4;
|
||||
|
||||
|
||||
public const COMPLETED = 5;
|
||||
|
||||
}
|
||||
@@ -4,17 +4,13 @@ namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
class PerfexCRMTasks
|
||||
{
|
||||
//IMPORTANT NOTE: TASK NAME MUST BE UNIQUE ACCORDING TO REL_TYPE
|
||||
//e.g. rel_type: lead, project
|
||||
|
||||
public const TASK_1 = [
|
||||
'name' => 'Customer Paid',
|
||||
'description' => '',
|
||||
'milestone' => 'MILESTONE 1 - Customer Paid',
|
||||
'reference' => '',
|
||||
'on_task_completion' => '',
|
||||
'department' => '',
|
||||
'status' => PerfexCRMTaskStatus::COMPLETED
|
||||
'status' => PerfexCRMStatus::COMPLETED
|
||||
];
|
||||
|
||||
public const TASK_POST_PAYMENT_1 = [
|
||||
@@ -30,8 +26,7 @@ class PerfexCRMTasks
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_POST_PAYMENT_1',
|
||||
'on_task_completion' => 'TASK_POST_PAYMENT_2',
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS
|
||||
'status' => PerfexCRMStatus::IN_PROGRESS
|
||||
];
|
||||
public const TASK_POST_PAYMENT_2 = [
|
||||
'name' => 'Approve Payment',
|
||||
@@ -46,7 +41,6 @@ class PerfexCRMTasks
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_POST_PAYMENT_2',
|
||||
'on_task_completion' => 'TASK_POST_PAYMENT_3',
|
||||
'department' => 'Accounts',
|
||||
'status' => ''
|
||||
];
|
||||
public const TASK_POST_PAYMENT_3 = [
|
||||
@@ -62,7 +56,6 @@ class PerfexCRMTasks
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_POST_PAYMENT_3',
|
||||
'on_task_completion' => 'TASK_POST_PAYMENT_4',
|
||||
'department' => 'Accounts',
|
||||
'status' => ''
|
||||
];
|
||||
public const TASK_POST_PAYMENT_4 = [
|
||||
@@ -78,54 +71,6 @@ class PerfexCRMTasks
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_POST_PAYMENT_4',
|
||||
'on_task_completion' => '',
|
||||
'department' => 'Accounts',
|
||||
'status' => ''
|
||||
];
|
||||
|
||||
public const TASK_LOADED_CONTAINER_1 = [
|
||||
'name' => 'Generate Shipping Invoices',
|
||||
'description' => '○ Purpose: -<br>
|
||||
○ Initial Status: In Progress<br>
|
||||
○ Deadline: Next day<br>
|
||||
○ Responsible department: Operation<br>
|
||||
○ Assignee: -<br>
|
||||
○ Next step: Approve Shipping Invoice change to in progress.<br>',
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_LOADED_CONTAINER_1',
|
||||
'on_task_completion' => 'TASK_LOADED_CONTAINER_2',
|
||||
'department' => 'Operations',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS
|
||||
];
|
||||
|
||||
public const TASK_LOADED_CONTAINER_2 = [
|
||||
'name' => 'Approve Shipping Invoices',
|
||||
'description' => '○ Purpose: -<br>
|
||||
○ Initial Status: Not Starteds<br>
|
||||
○ Deadline: Next day<br>
|
||||
○ Responsible department: Customer Services<br>
|
||||
○ Next step: -<br>',
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_LOADED_CONTAINER_2',
|
||||
'on_task_completion' => '',
|
||||
'department' => 'Customer Services',
|
||||
'status' => ''
|
||||
];
|
||||
|
||||
|
||||
public const TASK_IDENTIFICATION_1 = [
|
||||
'name' => 'Approve Identification Verification (Shipping)',
|
||||
'description' => '○ Purpose: To ensure the customer submit information matches the information in their identification document.<br>
|
||||
○ Initial Status: In Progress<br>
|
||||
○ Deadline: Same Day<br>
|
||||
○ Responsible department: Operation<br>
|
||||
○ Next step: None<br>
|
||||
○ Additional details: ** Any specific requirements or notes for the operation.**<br>
|
||||
○ Dependencies: None<br>
|
||||
○ Outcomes: Customer account identification is verified<br>',
|
||||
'milestone' => '',
|
||||
'reference' => 'TASK_IDENTIFICATION_1',
|
||||
'on_task_completion' => '',
|
||||
'department' => 'Operations',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class AuditBillplz extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'billplz:audit';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Audit Billplz';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$this->info(Carbon::now() . ' : Audit Billplz cron started.');
|
||||
$start = new Carbon();
|
||||
|
||||
$transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->get();
|
||||
$totalTransactions = count($transactions);
|
||||
$counter = 1;
|
||||
$totalAmount = 0;
|
||||
foreach ($transactions as $transaction){
|
||||
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
if($data['paid']){
|
||||
|
||||
} else {
|
||||
$totalAmount += $transaction->amount;
|
||||
$this->info($counter . ' of ' . $totalTransactions . '. Order: '. $transaction->owner->owner->owner->reference . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount);
|
||||
}
|
||||
}else{
|
||||
$this->info("billplz error</br>");
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
|
||||
$this->info(Carbon::now() . ' : Done Audit Billplz. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class debugBillplzFailedPayment extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'billplz-failed-payment:debug';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereNotIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->get();
|
||||
|
||||
$i = 0;
|
||||
$totalAmount = 0;
|
||||
foreach ($transactions as $transaction){
|
||||
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference);
|
||||
|
||||
// dd($response);
|
||||
|
||||
// dd($transaction->owner->owner->owner->reference);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
if($data['paid']){
|
||||
if (!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) {
|
||||
$this->returnLog('Paid transaction', $transaction);
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// $totalAmount += $transaction->amount;
|
||||
// $this->returnLog('Unpaid Transaction', $transaction);
|
||||
// }
|
||||
}else{
|
||||
$this->returnLog('billplz error', $transaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function returnLog($text, $transaction) {
|
||||
$approvalStatusArray = ApprovalStatus::APPROVAL_STATUS_ID;
|
||||
$this->info($text . ' - id: '. $transaction->id . '. Order Marking: '. $transaction->owner->owner->owner->reference . ' - Date: '.$transaction->created_at->format('d-m-Y').' - Amount: '. $transaction->amount . '. Current Status: ' . $approvalStatusArray[$transaction->status]);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Orders;
|
||||
|
||||
use App\Classes\Modules\Orders\ControllersLogic\ChangeOrderOwnerLogic;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CompanyConnection;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ChangeOrderOwnerController extends Controller
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ChangeOrderOwnerLogic $changeOrderOwnerLogic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, ChangeOrderOwnerLogic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderProfileResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reference' => $this->reference,
|
||||
'identifier' => $this->id,
|
||||
'reference_contract' => (int) $this->type,
|
||||
'type' => (int) $this->type,
|
||||
'status' => (int) $this->status,
|
||||
'company_module' => new CompanyModuleResource($this->companyModule),
|
||||
'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee),
|
||||
'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()),
|
||||
'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()),
|
||||
'invoices' => $this->whenLoaded('packingLists', function() {
|
||||
return TransactionResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->get());
|
||||
}),
|
||||
'remarks' => RemarkResource::collection($this->remarks),
|
||||
'created_at' => $this->created_at->format('d-m-Y')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ class OrderResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reference' => $this->reference,
|
||||
'identifier' => $this->id,
|
||||
'reference_contract' => (int) $this->type,
|
||||
'type' => (int) $this->type,
|
||||
'status' => (int) $this->status,
|
||||
|
||||
@@ -23,7 +23,7 @@ use PhpParser\Node\Expr\AssignOp\Mod;
|
||||
* Class CompanyModule
|
||||
* @package App\Models
|
||||
*
|
||||
* @property \App\Models\Company company_id
|
||||
* @property \App\Models\Company company_id
|
||||
* @property integer type
|
||||
* @property integer status
|
||||
*/
|
||||
|
||||
@@ -198,6 +198,9 @@
|
||||
},
|
||||
methods:{
|
||||
submitForm(){
|
||||
if (this.type) {
|
||||
this.parameters.type = this.type;
|
||||
}
|
||||
this.submit(this.data ? (this.route('api.address.update', this.data.id)) : (this.route('api.address.create')), this.data ? 'put' : 'post', 'addressList', true, true);
|
||||
},
|
||||
},
|
||||
|
||||
+2
-1
@@ -83,11 +83,12 @@
|
||||
billingAddressFilters: {
|
||||
per_page: 10,
|
||||
HasMorphCompanyModule: this.company_module_id,
|
||||
ownerType: 'App\\Models\\CompanyModule',
|
||||
type: 1
|
||||
},
|
||||
parameters : {
|
||||
company_module_id: this.company_module_id,
|
||||
billing_address_id: '',
|
||||
billing_address_id: null,
|
||||
},
|
||||
item:{
|
||||
id:null
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center" v-if="step === 2">
|
||||
<div class="row justify-content-center" v-if="step === 2 && !chooseBillingAddress">
|
||||
<div class="col col-md-10">
|
||||
<div class="row m-b-20">
|
||||
<div class="col">
|
||||
@@ -88,7 +88,7 @@
|
||||
</div>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col col-md-10">
|
||||
<list-component style="min-height: 50px;" section="addressList" :emptyListSection=false :endpoint="route('api.address.list')" :options="{per_page: 10, HasMorphCompanyModule: company.company_module.id}">
|
||||
<list-component style="min-height: 50px;" section="addressList" :emptyListSection=false :endpoint="route('api.address.list')" :options="{per_page: 10, HasMorphCompanyModule: company.company_module.id, type:2}">
|
||||
<template slot="list" slot-scope="{data}">
|
||||
<select-address-component :data="data" :value="parameters.address_id" v-model="parameters.address_id"></select-address-component>
|
||||
</template>
|
||||
@@ -119,7 +119,72 @@
|
||||
<button type="button" class="btn btn-lg btn-default b-rad-none" @click="step--">back</button>
|
||||
</div>
|
||||
<div class="col p-l-5">
|
||||
<button type="button" class="btn btn-lg btn-block btn-primary b-rad-none" @click="createOrder()" v-if="parameters.address_id">Create Order</button>
|
||||
<button type="button" class="btn btn-lg btn-block btn-primary b-rad-none" @click="createOrder()" v-if="parameters.address_id && company.company_module.billingAddress">Create Order</button>
|
||||
<button type="button" class="btn btn-lg btn-block btn-primary b-rad-none" @click=" chooseBillingAddress = !chooseBillingAddress" v-if="parameters.address_id && !company.company_module.billingAddress">Select Billing Address</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center" v-if="step === 2 && chooseBillingAddress">
|
||||
<div class="col col-md-10">
|
||||
<div class="row m-b-20">
|
||||
<div class="col">
|
||||
<div class="row m-b-20 text-info">
|
||||
<div class="col text-center">
|
||||
<h3>Please select the <b>Billing Address</b></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row b-rounded justify-content-center m-b-15" @click="updateBillingAddressFilters">
|
||||
<div class="col col-md-10 bg-master-lightest margin-auto padding-15">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col pointer d-flex justtify-content-center align-items-center">
|
||||
<i class="fa fs-30 fa-fw" :class="{'fa-square-o': !useDeliveryAddress, 'fa-check-square': useDeliveryAddress, 'text-primary':useDeliveryAddress}" ></i>
|
||||
<p class="m-b-0">Use Delivery Address</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center m-b-15" v-if="error">
|
||||
<div class="col-10">
|
||||
<small class="text-danger">{{error}}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col col-md-10">
|
||||
<list-component :key="currentKey" style="min-height: 50px;" section="addressList" :emptyListSection=false :endpoint="route('api.address.list')" :options="billingAddressFilters">
|
||||
<template slot="list" slot-scope="{data}">
|
||||
<select-address-component :data="data" :value="parameters.billing_address_id" v-model="parameters.billing_address_id"></select-address-component>
|
||||
</template>
|
||||
</list-component>
|
||||
<div class="row m-b-10 animate__animated animate__fadeInUpBig animate__delay-1 animate__fast">
|
||||
<div class="col b-a p-t-15 p-b-15 pointer" :class="{ 'b-primary': !parameters.billing_address_id, 'b-grey': parameters.billing_address_id}" @click="parameters.billing_address_id = null">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-auto p-r-0">
|
||||
<i class="fa fs-20 p-t-5" :class="{'fa-circle-o': parameters.billing_address_id, 'fa-check-circle': !parameters.billing_address_id, 'text-primary': !parameters.billing_address_id}"></i>
|
||||
</div>
|
||||
<div class="col-auto semi-bold">New Address</div>
|
||||
</div>
|
||||
<div class="row" v-show="!parameters.billing_address_id">
|
||||
<div class="col">
|
||||
<address-form-component :type="1" :id="company.company_module.id" section="addressList" @input="parameters.billing_address_id = $event"></address-form-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center animate__animated animate__fadeInUpBig animate__delay-1 animate__fast">
|
||||
<div class="col col-md-8 no-padding">
|
||||
<div class="row">
|
||||
<div class="col-auto p-r-5">
|
||||
<button type="button" class="btn btn-lg btn-default b-rad-none" @click="chooseBillingAddress = !chooseBillingAddress">back</button>
|
||||
</div>
|
||||
<div class="col p-l-5">
|
||||
<button type="button" class="btn btn-lg btn-block btn-primary b-rad-none" @click="createOrder()" v-if="parameters.billing_address_id">Create Order</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -172,11 +237,20 @@
|
||||
return {
|
||||
section: 'createOrderForm',
|
||||
step: 1,
|
||||
currentKey: 1,
|
||||
error: '',
|
||||
chooseBillingAddress: false,
|
||||
useDeliveryAddress: false,
|
||||
billingAddressFilters: {
|
||||
per_page: 10,
|
||||
HasMorphCompanyModule: this.company.company_module.id,
|
||||
type: 1
|
||||
},
|
||||
parameters : {
|
||||
warehouse_id: '',
|
||||
address_id: '',
|
||||
company_id: this.company.id,
|
||||
billing_address_id: '',
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -205,6 +279,21 @@
|
||||
alert(response.message)
|
||||
this.error = response.message;
|
||||
this.step--;
|
||||
},
|
||||
updateBillingAddressFilters(){
|
||||
if(this.useDeliveryAddress) {
|
||||
// if use delivery address
|
||||
this.billingAddressFilters = {
|
||||
per_page: 10,
|
||||
HasMorphCompanyModule: this.company.company_module.id,
|
||||
type: 1
|
||||
}
|
||||
this.parameters.billing_address_id = '';
|
||||
} else {
|
||||
this.billingAddressFilters = {per_page: 10, HasMorphCompanyModule: this.company.company_module.id};
|
||||
}
|
||||
this.useDeliveryAddress = !this.useDeliveryAddress;
|
||||
this.currentKey++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@
|
||||
<div class="col">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<list-component v-show="!$store.getters.isShowing('createOrderForm')" section="cancelledOrderListSection" :endpoint="route('api.order.list')" :options="item ? {per_page: 12, status_in: [4, 5, 6], company_module_id: item.company_module.id, with_packing_lists: true} : {per_page: 30, status_in: [4, 5, 6], with_packing_lists: true, display_without_parcel:true}" :columns=3>
|
||||
<list-component v-show="!$store.getters.isShowing('createOrderForm')" section="cancelledOrderListSection" :endpoint="route('api.order.list')" :options="item ? {per_page: 12, status_in: [4, 5, 6], company_module_id: item.company_module.id, with_packing_lists: true} : {per_page: 30, status_in: [4, 5, 6], with_packing_lists: true}" :columns=3>
|
||||
<template slot="list" slot-scope="{data}">
|
||||
<order-component :data="data"></order-component>
|
||||
</template>
|
||||
@@ -234,4 +234,4 @@
|
||||
export default {
|
||||
mixins: [componentHandler]
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -35,7 +35,7 @@ Route::group(['prefix' => 'account', 'namespace' => 'Accounts', 'as' => 'account
|
||||
});
|
||||
|
||||
Route::group(['middleware' => 'valid.token', 'prefix' => 'user', 'as' => 'user.'], function () {
|
||||
Route::get('/email/{email}', 'FetchUserByEmailController@fetch')->name('company');
|
||||
Route::get('/{email}', 'FetchUserByEmailController@fetch')->name('company');
|
||||
Route::post('/show', 'FetchUserController@fetch')->name('show');
|
||||
Route::get('/list', 'ListUsersController@list')->name('list');
|
||||
Route::put('/update/{id}', 'UpdateUserController@update')->name('update');
|
||||
|
||||
@@ -12,7 +12,6 @@ Route::group(['prefix' => 'order', 'as' => 'order.', 'namespace' => 'Orders'], f
|
||||
Route::post('/address/change/request', 'RequestChangeOrderAddressController@request')->name('address.change.request');
|
||||
Route::post('/update/{id}','UpdateOrderController@update')->name('reference.update');
|
||||
Route::put('/address/{id}/status/{status}', 'ApproveChangeOrderAddressController@approve')->name('address.status.update');
|
||||
Route::put('/update-marking/{reference}', 'ChangeOrderOwnerController@update')->name('orders.update.marking');
|
||||
|
||||
Route::post('/create-warehouse-packing-list', 'CreateWarehousePackingListController@create')->name('create.warehouse.packing_list');
|
||||
Route::post('/create-shipping-packing-list', 'CreateShippingPackingListController@create')->name('create.shipping.packing_list');
|
||||
|
||||
+31
-123
@@ -802,31 +802,40 @@ Route::get('/invoices/approve', function(Request $request){
|
||||
Route::get('/invoices/show-duplicated', function(Request $request){
|
||||
$transactionWithMultipleInvoice = DB::table('transactions')
|
||||
->where('type', TransactionType::SHIPPING_INVOICE)
|
||||
->where('status', '!=' , ApprovalStatus::EXPIRED)
|
||||
->where('status', '!=' , ApprovalStatus::COMPLETED)
|
||||
->where('deleted_at', null)
|
||||
->select('owner_id', DB::raw('count(*) as count'))
|
||||
->groupBy('owner_id')
|
||||
->having('count', '>', 1)
|
||||
->get();
|
||||
|
||||
echo 'Total Duplicates: ' . count($transactionWithMultipleInvoice) . '<br>';
|
||||
// delete invoice type suspended
|
||||
|
||||
echo '<table>';
|
||||
echo "<tr>";
|
||||
echo "<td style='border:1px solid'>owner_id</td>";
|
||||
echo "<td style='border:1px solid'>count</td>";
|
||||
echo "</tr>";
|
||||
|
||||
$duplicatedOrderId = [];
|
||||
$duplicatedOrderArray = [];
|
||||
foreach($transactionWithMultipleInvoice as $invoice) {
|
||||
$duplicatedOrderId[] = $invoice->owner_id;
|
||||
$duplicatedOrderArray[$invoice->owner_id] = $invoice->count;
|
||||
echo "<tr>";
|
||||
echo "<td style='border:1px solid'>$invoice->owner_id</td>";
|
||||
echo "<td style='border:1px solid'>$invoice->count</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
|
||||
$duplicatedInvoice = Transaction::whereIn('owner_id', $duplicatedOrderId)->orderByDesc('owner_id')->get();
|
||||
// dd($duplicatedInvoice);
|
||||
echo '<br>';
|
||||
echo '<table>';
|
||||
echo "<tr>";
|
||||
echo "<td style='border:1px solid'>Order Reference</td>";
|
||||
echo "<td style='border:1px solid'>Status</td>";
|
||||
echo "<td style='border:1px solid'>Invoice Owner ID</td>";
|
||||
echo "<td style='border:1px solid'>Amount</td>";
|
||||
echo "<td style='border:1px solid'>Count</td>";
|
||||
echo "<td style='border:1px solid'>Invoice Owner ID</td>";
|
||||
echo "</tr>";
|
||||
|
||||
foreach($duplicatedInvoice as $invoice) {
|
||||
@@ -836,16 +845,17 @@ Route::get('/invoices/show-duplicated', function(Request $request){
|
||||
echo "<td style='border:1px solid'>".ApprovalStatus::APPROVAL_STATUS_ID[$invoice->status]."</td>";
|
||||
echo "<td style='border:1px solid'>$invoice->owner_id</td>";
|
||||
echo "<td style='border:1px solid'>$invoice->amount</td>";
|
||||
echo "<td style='border:1px solid'>".$duplicatedOrderArray[$invoice->owner_id]."</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
});
|
||||
|
||||
|
||||
|
||||
Route::get('/invoices/delete-duplicated', function(Request $request){
|
||||
$duplicatedInvoices = DB::table('transactions')
|
||||
->where('type', TransactionType::SHIPPING_INVOICE)
|
||||
->where('status', '!=' , ApprovalStatus::EXPIRED)
|
||||
->where('status', '!=' , ApprovalStatus::COMPLETED)
|
||||
->where('deleted_at', null)
|
||||
->select('owner_id', DB::raw('count(*) as count'))
|
||||
->groupBy('owner_id')
|
||||
@@ -860,128 +870,26 @@ Route::get('/invoices/delete-duplicated', function(Request $request){
|
||||
|
||||
$paidInvoice = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::COMPLETED)->get();
|
||||
|
||||
// if have completed invoice (verified payment)
|
||||
$unpaidInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->orderBy('id', 'desc')->get();
|
||||
|
||||
if (count($paidInvoice)) {
|
||||
$packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::COMPLETED)->delete();
|
||||
continue;
|
||||
} else {
|
||||
dump($order->reference . ' -no');
|
||||
}
|
||||
|
||||
// if have unverified payment
|
||||
// $paymentHistory = $packingList->transactions()->whereHas('transactions', function($query){
|
||||
// return $query->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION ,ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]);
|
||||
// })->get();
|
||||
// if (count($paymentHistory)) {
|
||||
// $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('id', '!=', $paymentHistory->first()->id)->delete();
|
||||
// continue;
|
||||
// }
|
||||
// delete duplicated invoices
|
||||
$unpaidInvoicesIds = $unpaidInvoices->pluck('id')->toArray();
|
||||
array_shift($unpaidInvoicesIds);
|
||||
Transaction::whereIn('id', $unpaidInvoicesIds)->delete();
|
||||
|
||||
// // delete duplicated invoices
|
||||
// $unpaidInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->orderBy('id', 'desc')->get();
|
||||
// delete expired invoices
|
||||
$packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::EXPIRED)->delete();
|
||||
|
||||
// $unpaidInvoicesIds = $unpaidInvoices->pluck('id')->toArray();
|
||||
// array_shift($unpaidInvoicesIds);
|
||||
// Transaction::whereIn('id', $unpaidInvoicesIds)->delete();
|
||||
// delete suspended invoices
|
||||
$suspendedInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::SUSPENDED)->orderBy('id', 'desc')->get();
|
||||
$suspendedInvoicesIds = $suspendedInvoices->pluck('id')->toArray();
|
||||
array_shift($suspendedInvoicesIds);
|
||||
Transaction::whereIn('id', $suspendedInvoicesIds)->delete();
|
||||
|
||||
// // delete expired invoices
|
||||
// $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::EXPIRED)->delete();
|
||||
|
||||
// // delete suspended invoices
|
||||
// $suspendedInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::SUSPENDED)->orderBy('id', 'desc')->get();
|
||||
// $suspendedInvoicesIds = $suspendedInvoices->pluck('id')->toArray();
|
||||
// array_shift($suspendedInvoicesIds);
|
||||
// Transaction::whereIn('id', $suspendedInvoicesIds)->delete();
|
||||
}
|
||||
});
|
||||
|
||||
Route::get('/packing-lists/show-duplicated', function(Request $request){
|
||||
$results = PackingList::select('reference', 'type', DB::raw('count(*) as total'))
|
||||
->groupBy('reference', 'type')
|
||||
->having('total', '>', 1)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
echo '<table>';
|
||||
echo "<tr>";
|
||||
echo "<td style='border:1px solid'>reference</td>";
|
||||
echo "<td style='border:1px solid'>type</td>";
|
||||
echo "<td style='border:1px solid'>count</td>";
|
||||
echo "</tr>";
|
||||
|
||||
foreach($results as $result) {
|
||||
// dd($result);
|
||||
echo "<tr>";
|
||||
echo "<td style='border:1px solid'>" . $result['reference'] . "</td>";
|
||||
echo "<td style='border:1px solid'>" . $result['type'] . "</td>";
|
||||
echo "<td style='border:1px solid'>" . $result['total'] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo '</table>';
|
||||
});
|
||||
|
||||
Route::get('/packing-lists/delete-duplicated', function(Request $request){
|
||||
$results = PackingList::select('reference', 'type', DB::raw('count(*) as total'))
|
||||
->groupBy('reference', 'type')
|
||||
->having('total', '>', 1)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
foreach($results as $result) {
|
||||
$duplicatedPackingList = PackingList::where('reference', $result['reference'])->where('type', $result['type'])->orderBy('id', 'desc')->get();
|
||||
|
||||
// if packinglist has paid inivoice
|
||||
$paidPackinglist = PackingList::where('reference', $result['reference'])->where('type', $result['type'])->whereHas('transactions', function($query){
|
||||
return $query->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::COMPLETED);
|
||||
})->get();
|
||||
|
||||
if (count($paidPackinglist)) {
|
||||
// delete all the other packing list
|
||||
$paidPackinglistID = $paidPackinglist->first()->id;
|
||||
$duplicatedPackingList = PackingList::where('reference', $result['reference'])->where('type', $result['type'])->where('id', '!=', $paidPackinglistID)->get();
|
||||
// $duplicatedPackingList->delete();
|
||||
foreach ($duplicatedPackingList as $p) {
|
||||
$p->delete();
|
||||
dump('have paid packinglist, deleting id:' . $p->id);
|
||||
}
|
||||
} else {
|
||||
// delete all but left the latest packing list
|
||||
$firstItem = $duplicatedPackingList->shift();
|
||||
// dump('dont have paid packinglist, keep first and delete others');
|
||||
foreach ($duplicatedPackingList as $p) {
|
||||
$p->delete();
|
||||
dump('dont have paid packinglist, keep latest id:' . $firstItem->id . ', and deleting id:' . $p->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Route::get('/billplz/audit', function (Request $request) {
|
||||
$transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->get();
|
||||
$i = 0;
|
||||
$totalAmount = 0;
|
||||
foreach ($transactions as $transaction){
|
||||
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference);
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
if($data['paid']){
|
||||
|
||||
} else {
|
||||
|
||||
$transaction->status = ApprovalStatus::REJECTED;
|
||||
$transaction->save();
|
||||
|
||||
$invoice = $transaction->owner;
|
||||
$invoice->status = ApprovalStatus::APPROVED;
|
||||
|
||||
$totalAmount += $transaction->amount;
|
||||
echo 'Order: '. $transaction->owner->owner->owner->reference . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount . " </br></br>";
|
||||
}
|
||||
}else{
|
||||
echo "billplz error</br>";
|
||||
}
|
||||
}
|
||||
|
||||
echo 'Total: ' . $totalAmount;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user