mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-28 00:43:58 +00:00
Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into customer-profile-update
This commit is contained in:
@@ -16,27 +16,17 @@ class CreatePerfexCRMInvoice implements ShouldQueue
|
||||
/** @var $transaction*/
|
||||
private $transaction;
|
||||
|
||||
/** @var $purchaseOrder*/
|
||||
private $purchaseOrder;
|
||||
|
||||
/** @var $supplier*/
|
||||
private $supplier;
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMInvoice constructor.
|
||||
* @param $transaction
|
||||
* @param $purchaseOrder
|
||||
* @param $supplier
|
||||
*/
|
||||
public function __construct($transaction, $purchaseOrder, $supplier)
|
||||
public function __construct($transaction)
|
||||
{
|
||||
$this->transaction = $transaction;
|
||||
$this->purchaseOrder = $purchaseOrder;
|
||||
$this->supplier = $supplier;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
(App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($this->transaction, $this->purchaseOrder, $this->supplier);
|
||||
(App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($this->transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObje
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\FetchPerfexCRMInvoiceObject;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Logical\Boolean;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
|
||||
class UpdatePerfexCRM implements ShouldQueue
|
||||
{
|
||||
@@ -44,7 +45,7 @@ class UpdatePerfexCRM implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
//To use invoice as a reference to decide whether more tasks should be created
|
||||
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceId());
|
||||
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice());
|
||||
|
||||
$result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
|
||||
if($this->transaction != null && $this->shouldCreateInvoice){
|
||||
@@ -59,12 +60,11 @@ class UpdatePerfexCRM implements ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
private function getInvoiceId(){
|
||||
private function getInvoiceIdOrCreateInvoice(){
|
||||
if($this->transaction != null){
|
||||
$fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$this->transaction,
|
||||
true
|
||||
$this->transaction
|
||||
);
|
||||
$invoiceId = (App()->make(FetchPerfexCRMInvoiceProcessor::class))->execute($fetchPerfexCRMInvoiceObject);
|
||||
return $invoiceId;
|
||||
|
||||
@@ -60,7 +60,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $number: '.$number));
|
||||
|
||||
if(is_null($invoice)){
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction, null, null, $this->updatePerfexCRMInvoiceObject->getIsPaid());
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction);
|
||||
if ($result) {
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
|
||||
@@ -13,15 +13,11 @@ class FetchPerfexCRMInvoiceObject implements DataTransferObject
|
||||
/** @var Transaction */
|
||||
private $transaction;
|
||||
|
||||
/** @var bool */
|
||||
private $isPaid;
|
||||
|
||||
|
||||
public function __construct(string $email, Transaction $transaction, bool $isPaid)
|
||||
public function __construct(string $email, Transaction $transaction)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->transaction = $transaction;
|
||||
$this->isPaid = $isPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,12 +35,4 @@ class FetchPerfexCRMInvoiceObject implements DataTransferObject
|
||||
{
|
||||
return $this->transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsPaid(): bool
|
||||
{
|
||||
return $this->isPaid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,23 +59,16 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
|
||||
/**
|
||||
* @param $transaction
|
||||
* @param $purchaseOrder
|
||||
* @param $supplier
|
||||
* @return null|object
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute($transaction, $purchaseOrder, $supplier) {
|
||||
public function execute($transaction) {
|
||||
$booking = $transaction->booking;
|
||||
|
||||
if(is_null($supplier)){
|
||||
$supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]);
|
||||
}
|
||||
if(is_null($purchaseOrder)){
|
||||
$purchaseOrder = $booking->transactions()
|
||||
$supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]);
|
||||
$purchaseOrder = $booking->transactions()
|
||||
->where('type', TransactionType::PURCHASE_ORDER)
|
||||
->complete()
|
||||
->first();
|
||||
}
|
||||
|
||||
$clientId = "";
|
||||
$number = $transaction->bill_no;
|
||||
@@ -120,7 +113,6 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
$bookingMarking = $transaction->owner->marking;
|
||||
$serviceTypeName = $transaction->owner->company->services()->where('id', $transaction->owner->service_id)->first()->name;
|
||||
$projectName = 'Exchange | '.$serviceTypeName.' | '.$bookingMarking;
|
||||
Log::error('CreatePerfexCRMInvoiceProcessor debug:'.json_encode($transaction));
|
||||
Log::error('$projectName: '.$projectName);
|
||||
return $email;
|
||||
}
|
||||
@@ -229,26 +221,6 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
);
|
||||
|
||||
$result = $this->createsPerfexCRMInvoice->execute($invoicePerfexCRMObject);
|
||||
|
||||
//cief todo: When invoices need to be regenerated, need to ensure payment do not get double created
|
||||
|
||||
// if(!is_null($result))
|
||||
// {
|
||||
// if($result->payload['id']){
|
||||
// $invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject(
|
||||
// $result->payload['id'],
|
||||
// $total,
|
||||
// $date,
|
||||
// 1,
|
||||
// "",
|
||||
// ""
|
||||
// );
|
||||
// $this->createsPerfexCRMInvoicePayment->execute($invoicePaymentPerfexCRMObject);
|
||||
// }
|
||||
// }
|
||||
//else: logs will record the following:
|
||||
//"status":false,"error":{"number":"The Invoice number is already in use"},"message":"<p>The Invoice number is already in use<\/p>"}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,20 +25,7 @@ class CreatePerfexCRMTaskProcessor
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) {
|
||||
$this->createsPerfexCRMTask->execute(
|
||||
$createTaskPerfexCRMObject->getName(),
|
||||
$createTaskPerfexCRMObject->getDescription(),
|
||||
$createTaskPerfexCRMObject->getLeadId(),
|
||||
$createTaskPerfexCRMObject->getMilestoneId(),
|
||||
$createTaskPerfexCRMObject->getProjectId(),
|
||||
$createTaskPerfexCRMObject->getReference(),
|
||||
$createTaskPerfexCRMObject->getOnTaskCompletion(),
|
||||
$createTaskPerfexCRMObject->getDepartment(),
|
||||
$createTaskPerfexCRMObject->getStatus(),
|
||||
$createTaskPerfexCRMObject->getPriority(),
|
||||
$createTaskPerfexCRMObject->getDuedate(),
|
||||
$createTaskPerfexCRMObject->getInvoiceId(),
|
||||
);
|
||||
$this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,13 +56,12 @@ class FetchPerfexCRMInvoiceProcessor
|
||||
|
||||
$number = 'EXC-'.$number;
|
||||
$invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number);
|
||||
Log::error(json_encode('FetchPerfexCRMInvoiceProcessor debug $number: '.$number));
|
||||
if(is_null($invoice)){
|
||||
$result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null, $fetchPerfexCRMInvoiceObject->getIsPaid());
|
||||
$result = $this->createPerfexCRMInvoiceProcessor->execute($transaction);
|
||||
if ($result) {
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
$log['message'] = 'FetchPerfexCRMInvoiceProcessor failed';
|
||||
$log['message'] = 'FetchPerfexCRMInvoiceProcessor failed for transaction > bill_no: '.$number;
|
||||
Helper::debugLogger($log);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ class TransactionToPerfexCRMProcessorV2
|
||||
$projectName = 'Exchange | ' . $bookingInfo['serviceTypeName'] . ' | ' . $bookingInfo['bookingMarking'];
|
||||
$tasks = $this->defineTasks($model, $status);
|
||||
|
||||
Log::error("TransactionToPerfexCRMProcessorV2 status: ".$status." - for project name: ".$projectName);
|
||||
|
||||
if(count($tasks) > 0) {
|
||||
$updatePerfexCRMObject = new UpdatePerfexCRMObject(
|
||||
$bookingInfo['companyName'],
|
||||
|
||||
@@ -15,8 +15,8 @@ use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMTask;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMProject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
@@ -203,12 +203,22 @@ class UpdatePerfexCRMProcessor
|
||||
}
|
||||
|
||||
// Get existing or create task
|
||||
$taskName = $tasks[$count]['name'];;
|
||||
if($updatePerfexCRMObject->getInvoiceId() != 0){
|
||||
$taskName = $tasks[$count]['name'];
|
||||
$taskReference = $tasks[$count]['reference'];
|
||||
$taskOnTaskCompletion = $tasks[$count]['on_task_completion'];
|
||||
$taskIsAllowMultiple = $tasks[$count]['is_allow_multiple'];
|
||||
$taskIsOnTaskCompletionUpdate = $tasks[$count]['is_on_task_completion_update'];
|
||||
if($updatePerfexCRMObject->getInvoiceId() != 0 && $taskIsAllowMultiple){
|
||||
$taskName = $taskName." (".$updatePerfexCRMObject->getInvoiceId().")";
|
||||
$taskReference = $taskReference."_".$updatePerfexCRMObject->getInvoiceId();
|
||||
if($taskOnTaskCompletion && $taskIsOnTaskCompletionUpdate){
|
||||
$taskOnTaskCompletion = $taskOnTaskCompletion."_".$updatePerfexCRMObject->getInvoiceId();
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->fetchesPerfexCRMTask->execute($taskName, $milestoneId, 'project', $projectId, $updatePerfexCRMObject->getInvoiceId());
|
||||
// Log::info("UpdatePerfexCRMProcessor task: ".json_encode($taskStatus)." , ".json_encode($result));
|
||||
// Log::error("UpdatePerfexCRMProcessor task: ".$taskName." , ".json_encode($result));
|
||||
Log::error("UpdatePerfexCRMProcessor task: ".$taskName);
|
||||
|
||||
if(isset($result->payload)){
|
||||
//&& $result->payload[0]['status'] == PerfexCRMTaskStatus::NOT_STARTED
|
||||
@@ -219,13 +229,23 @@ class UpdatePerfexCRMProcessor
|
||||
}
|
||||
}
|
||||
else{
|
||||
$result = $this->createsPerfexCRMTask->execute($taskName, $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus, $tasks[$count]['priority'], $tasks[$count]['duedate'], $updatePerfexCRMObject->getInvoiceId());
|
||||
$createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject(
|
||||
"",
|
||||
$taskName,
|
||||
$tasks[$count]['description'],
|
||||
"",
|
||||
$projectId,
|
||||
$milestoneId,
|
||||
$taskReference,
|
||||
$taskOnTaskCompletion,
|
||||
$taskStatus,
|
||||
$tasks[$count]['department'],
|
||||
$tasks[$count]['priority'],
|
||||
$tasks[$count]['duedate'],
|
||||
$updatePerfexCRMObject->getInvoiceId()
|
||||
);
|
||||
$result = $this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject);
|
||||
}
|
||||
|
||||
//cief todo: to evaluate if this is still needed
|
||||
// if(is_null($result)){
|
||||
// break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,70 +6,46 @@ use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
|
||||
class CreatesPerfexCRMTask
|
||||
{
|
||||
/**
|
||||
* @param string $taskName
|
||||
* @param string $taskDescription
|
||||
* @param string $leadId
|
||||
* @param string $milestoneId
|
||||
* @param string $projectId
|
||||
* @param string $reference
|
||||
* @param string $on_task_completion
|
||||
* @param string $department
|
||||
* @param string $status
|
||||
* @param string $priority
|
||||
* @param string $duedate
|
||||
* @param int $invoiceId
|
||||
* @param CreateTaskPerfexCRMObject $createTaskPerfexCRMObject
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $taskName, string $taskDescription, string $leadId, string $milestoneId, string $projectId, string $reference, string $on_task_completion, string $department, string $status, string $priority, string $duedate, int $invoiceId) {
|
||||
public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) {
|
||||
try{
|
||||
$custom_fields = [];
|
||||
if($department != ""){
|
||||
if($createTaskPerfexCRMObject->getDepartment() != ""){
|
||||
$custom_fields = [
|
||||
"tasks" => [
|
||||
PerfexCRMCustomFields::TASKS_DEPARTMENT => $department
|
||||
PerfexCRMCustomFields::TASKS_DEPARTMENT => $createTaskPerfexCRMObject->getDepartment()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $taskName,
|
||||
'description' => $taskDescription,
|
||||
'milestone' => $milestoneId,
|
||||
'name' => $createTaskPerfexCRMObject->getName(),
|
||||
'description' => $createTaskPerfexCRMObject->getDescription(),
|
||||
'milestone' => $createTaskPerfexCRMObject->getMilestoneId(),
|
||||
'startdate' => date('Y-m-d'),
|
||||
'rel_type' => 'project',
|
||||
'rel_id' => $projectId,
|
||||
'status' => $status,
|
||||
'rel_id' => $createTaskPerfexCRMObject->getProjectId(),
|
||||
'status' => $createTaskPerfexCRMObject->getStatus(),
|
||||
'is_system_created' => 1,
|
||||
'reference' => $reference,
|
||||
'on_task_completion' => $on_task_completion,
|
||||
'reference' => $createTaskPerfexCRMObject->getReference(),
|
||||
'on_task_completion' => $createTaskPerfexCRMObject->getOnTaskCompletion(),
|
||||
'custom_fields' => $custom_fields,
|
||||
'priority' => $priority,
|
||||
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
|
||||
'invoice_id' => $invoiceId,
|
||||
'priority' => $createTaskPerfexCRMObject->getPriority(),
|
||||
'duedate' => date('Y-m-d', strtotime('+' . $createTaskPerfexCRMObject->getDuedate() . ' days')),
|
||||
'invoice_id' => $createTaskPerfexCRMObject->getInvoiceId(),
|
||||
];
|
||||
|
||||
if($leadId != '') {
|
||||
$data = [
|
||||
'name' => $taskName,
|
||||
'description' => $taskDescription,
|
||||
'milestone' => $milestoneId,
|
||||
'startdate' => date('Y-m-d'),
|
||||
'rel_type' => 'lead',
|
||||
'rel_id' => $leadId,
|
||||
'status' => $status,
|
||||
'is_system_created' => 1,
|
||||
'reference' => $reference,
|
||||
'on_task_completion' => $on_task_completion,
|
||||
'custom_fields' => $custom_fields,
|
||||
'priority' => $priority,
|
||||
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
|
||||
'invoice_id' => 0
|
||||
];
|
||||
if($createTaskPerfexCRMObject->getLeadId() != '') {
|
||||
$data['rel_type'] = 'lead';
|
||||
$data['rel_id'] = $createTaskPerfexCRMObject->getLeadId();
|
||||
}
|
||||
|
||||
$response = Http::asForm()->withHeaders([
|
||||
|
||||
@@ -64,7 +64,6 @@ class UpdatesPerfexCRMInvoice
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
dd(json_encode($exception));
|
||||
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ class PerfexCRMTasks
|
||||
'department' => '',
|
||||
'status' => PerfexCRMTaskStatus::COMPLETED,
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
|
||||
public const TASK_1_DAY_TRANSFER_1 = [
|
||||
@@ -27,7 +29,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1_DAY_TRANSFER_2 = [
|
||||
'name' => 'Approve Payment',
|
||||
@@ -47,7 +51,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_1_DAY_TRANSFER_3 = [
|
||||
'name' => 'Issue Exchange Autocount Invoince',
|
||||
@@ -65,7 +71,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1_DAY_TRANSFER_3_1 = [
|
||||
'name' => 'Issue Exchange Autocount OR',
|
||||
@@ -76,7 +84,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1_DAY_TRANSFER_4 = [
|
||||
'name' => 'Knockoff Invoice',
|
||||
@@ -94,7 +104,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1_DAY_TRANSFER_5 = [
|
||||
'name' => 'Order Placed in White Form',
|
||||
@@ -114,7 +126,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_1_DAY_TRANSFER_6 = [
|
||||
'name' => 'Upload China Bank Slip',
|
||||
@@ -132,7 +146,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
|
||||
public const TASK_3_DAY_TRANSFER_1 = [
|
||||
@@ -151,7 +167,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_3_DAY_TRANSFER_2 = [
|
||||
'name' => 'Approve Payment',
|
||||
@@ -164,7 +182,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_3_DAY_TRANSFER_3 = [
|
||||
'name' => 'Issue Exchange Autocount Invoince',
|
||||
@@ -182,7 +202,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_3_DAY_TRANSFER_3_1 = [
|
||||
'name' => 'Issue Exchange Autocount OR',
|
||||
@@ -193,7 +215,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_3_DAY_TRANSFER_4 = [
|
||||
'name' => 'Knockoff Invoice',
|
||||
@@ -211,7 +235,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_3_DAY_TRANSFER_5 = [
|
||||
'name' => 'Order Placed in White Form',
|
||||
@@ -231,7 +257,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_3_DAY_TRANSFER_6 = [
|
||||
'name' => 'Upload China Bank Slip',
|
||||
@@ -249,7 +277,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
|
||||
|
||||
@@ -270,7 +300,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_2 = [
|
||||
'name' => 'Approve Payment',
|
||||
@@ -290,7 +322,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_3 = [
|
||||
'name' => 'Issue Exchange Autocount Invoice',
|
||||
@@ -308,7 +342,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_3_1 = [
|
||||
'name' => 'Issue Exchange Autocount OR',
|
||||
@@ -320,7 +356,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_4 = [
|
||||
'name' => 'Knockoff Invoice',
|
||||
@@ -338,7 +376,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_5 = [
|
||||
'name' => 'Order Placed in White Form',
|
||||
@@ -357,7 +397,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_6 = [
|
||||
'name' => 'Send White Form to Operation Department',
|
||||
@@ -375,7 +417,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_7 = [
|
||||
'name' => 'Authorize Customer\'s 1688 Account',
|
||||
@@ -395,7 +439,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_1688_PAYMENT_8 = [
|
||||
'name' => 'Make Payment for Customer 1688 Order',
|
||||
@@ -410,7 +456,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::HIGH,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_1688_PAYMENT_9 = [
|
||||
'name' => 'Upload China Bank Slip',
|
||||
@@ -422,7 +470,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => true
|
||||
];
|
||||
public const TASK_1688_PAYMENT_10 = [
|
||||
'name' => 'Upload 1688 Purchase Order PDF',
|
||||
@@ -434,7 +484,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::MEDIUM,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => true,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_11 = [
|
||||
'name' => 'Fill Up Purchase Order',
|
||||
@@ -446,7 +498,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::LOW,
|
||||
'duedate' => 7
|
||||
'duedate' => 7,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_12 = [
|
||||
'name' => 'Approve Purchase Order',
|
||||
@@ -458,7 +512,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::LOW,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
public const TASK_1688_PAYMENT_13 = [
|
||||
'name' => 'Complete Order bookkeeping',
|
||||
@@ -476,7 +532,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
|
||||
|
||||
@@ -497,7 +555,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::LOW,
|
||||
'duedate' => 1
|
||||
'duedate' => 1,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
|
||||
public const TASK_PURCHASE_ORDER_2 = [
|
||||
@@ -510,7 +570,9 @@ class PerfexCRMTasks
|
||||
'department' => 'Accounts',
|
||||
'status' => '',
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
|
||||
|
||||
@@ -530,6 +592,8 @@ class PerfexCRMTasks
|
||||
'department' => 'Operations',
|
||||
'status' => PerfexCRMTaskStatus::IN_PROGRESS,
|
||||
'priority' => PerfexCRMTaskPriority::DEFAULT,
|
||||
'duedate' => 0
|
||||
'duedate' => 0,
|
||||
'is_allow_multiple' => false,
|
||||
'is_on_task_completion_update' => false
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Booking;
|
||||
|
||||
class DeleteOrderCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'make-refunded-booking-expired {bookings_reference}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Change refunded booking status to expired';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$bookings_reference = $this->argument('bookings_reference');
|
||||
$bookings_reference = explode(',', $bookings_reference);
|
||||
|
||||
$start = new Carbon();
|
||||
$this->logOutput('Process started');
|
||||
|
||||
foreach ($bookings_reference as $reference) {
|
||||
$booking = Booking::where('marking', $reference)->first();
|
||||
|
||||
if (!$booking) {
|
||||
$this->logOutput('Booking not found: ' . $reference);
|
||||
} else {
|
||||
$booking->status = ApprovalStatus::EXPIRED;
|
||||
$booking->save();
|
||||
$this->logOutput('Booking deleted: ' . $reference);
|
||||
}
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
|
||||
$this->logOutput('Process ended. ElapsedTime: ' . $elapsedTime);
|
||||
}
|
||||
|
||||
public function logOutput($text)
|
||||
{
|
||||
if (is_array($text)) {
|
||||
$text = implode(', ', $text);
|
||||
}
|
||||
|
||||
$this->info(Carbon::now() . ' : ' . $text);
|
||||
|
||||
$filePath = storage_path('logs/delete-orders.log');
|
||||
$textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL;
|
||||
file_put_contents($filePath, $textToAppend, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@
|
||||
<br>
|
||||
<br>
|
||||
<table class="line-table" style="overflow: wrap" autosize="1">
|
||||
<!-- Table Header -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%">No</th>
|
||||
@@ -81,34 +82,37 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$subtotal = 0;
|
||||
$voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null;
|
||||
$voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0;
|
||||
$currencyRate = $transaction->currency_rate;
|
||||
$subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate);
|
||||
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
|
||||
$displayedSubtotal = 0;
|
||||
@endphp
|
||||
|
||||
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
|
||||
@php
|
||||
$exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5);
|
||||
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
|
||||
$displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2);
|
||||
$displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
|
||||
@endphp
|
||||
<tr>
|
||||
<td width="5%" class="center top">{{ $key + 1 }}</td>
|
||||
<td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
|
||||
<td class="description">{{ $transaction_detail->product_name }}</td>
|
||||
<td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
|
||||
<td width="15%" class="center top">
|
||||
@php
|
||||
$unitPrice = $transaction_detail->price / $currencyRate;
|
||||
@endphp
|
||||
{{ number_format($unitPrice, 2) }}
|
||||
{{ number_format($exactUnitPrice, 2) }}
|
||||
</td>
|
||||
<td width="20%" class="right top">
|
||||
@php
|
||||
$itemTotal = $unitPrice * $transaction_detail->quantity;
|
||||
$subtotal += $itemTotal;
|
||||
@endphp
|
||||
{{ number_format($itemTotal, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@php
|
||||
$voucherDiscount = getDoVoucherDiscount($voucher_redemption);
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||
@endphp
|
||||
<tr class="subtotal">
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Subtotal</td>
|
||||
@@ -117,27 +121,17 @@
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Service Charges</td>
|
||||
<td class="right">
|
||||
{{ number_format($transaction->service_charge, 2) }}
|
||||
</td>
|
||||
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
|
||||
</tr>
|
||||
|
||||
@if($voucher_redemption)
|
||||
<tr class="voucher">
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Voucher ({{ $voucher_redemption->voucher->code }})</td>
|
||||
<td class="right middle">-{{ $voucherDiscount }}</td>
|
||||
<td class="right middle">-{{ number_format($voucherDiscount, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Adjustment</td>
|
||||
<td class="right">
|
||||
@php
|
||||
$adjustment = $transaction->amount - $subtotal;
|
||||
@endphp
|
||||
{{ number_format($adjustment, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@if($transaction->tax > 0)
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
@@ -145,13 +139,21 @@
|
||||
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
|
||||
@endphp
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Adjustment</td>
|
||||
<td class="right middle">{{ roundUpDo($discrepancy,2) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Total</td>
|
||||
<td class="total right middle">
|
||||
@php
|
||||
$total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount;
|
||||
@endphp
|
||||
{{ number_format($total, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -165,4 +167,28 @@
|
||||
</tr>
|
||||
</table>
|
||||
</htmlpagefooter>
|
||||
@php
|
||||
function calculateDoSubtotal($po_order_transaction, $currencyRate) {
|
||||
$subtotal = "0";
|
||||
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
|
||||
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
|
||||
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
|
||||
$subtotal = bcadd($subtotal, $itemTotal, 5);
|
||||
}
|
||||
return $subtotal;
|
||||
}
|
||||
|
||||
function getDoVoucherDiscount($voucher_redemption) {
|
||||
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
}
|
||||
function roundUpDo($number, $decimals) {
|
||||
$factor = pow(10, $decimals);
|
||||
if ($number > 0) {
|
||||
return ceil($number * $factor) / $factor;
|
||||
} else {
|
||||
return floor($number * $factor) / $factor;
|
||||
}
|
||||
}
|
||||
|
||||
@endphp
|
||||
@endsection
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
@extends('layouts.base_pdf')
|
||||
|
||||
@section('inner_content')
|
||||
|
||||
<br>
|
||||
<htmlpageheader name="page-header">
|
||||
<br><br>
|
||||
<div class="separator"><strong><i>{{ $transaction->bill_no }}</i></strong></div>
|
||||
</htmlpageheader>
|
||||
|
||||
<table>
|
||||
<!-- Header Section -->
|
||||
<tr>
|
||||
<td class="header-logo">
|
||||
<img src="{{ asset('images/ri_1.png') }}" alt="logo" id="logo" class="logo">
|
||||
</td>
|
||||
<td class="header-cief-address">
|
||||
<span class="company-name">
|
||||
<strong>
|
||||
CIEF WORLDWIDE SDN BHD
|
||||
</strong>
|
||||
</span>
|
||||
<span class="company-name"><strong>CIEF WORLDWIDE SDN BHD</strong></span>
|
||||
<span class="company-reg">(1134596-M)</span><br>
|
||||
No. 72-3, Jalan Jalil 1,<br>
|
||||
The Earth Bukit Jalil,<br>
|
||||
@@ -23,14 +23,8 @@
|
||||
Tel: 03-8082 1252
|
||||
</td>
|
||||
<td class="header-details">
|
||||
<div class="title">
|
||||
<strong>
|
||||
Invoice
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div class="title"><strong>Invoice</strong></div>
|
||||
<div class="number">EI#: {{ $transaction->bill_no }}</div>
|
||||
|
||||
<div class="ref">Ref# {{ $po_order_transaction->booking->marking }}</div>
|
||||
<div class="date">Date: {{ $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->booking->created_at }}</div>
|
||||
<div> </div>
|
||||
@@ -38,37 +32,34 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" class="bill-to">
|
||||
<span class="sub-title">
|
||||
Bill To
|
||||
</span>
|
||||
<span class="sub-title">Bill To</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" class="address">
|
||||
<div class="label">
|
||||
{{ $supplier->name }}
|
||||
</div>
|
||||
<div class="label">{{ $supplier->name }}</div>
|
||||
@php
|
||||
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
|
||||
@endphp
|
||||
<div class="address">
|
||||
@php
|
||||
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
|
||||
@endphp
|
||||
{{ $billingAddress->street_one }}
|
||||
{{ $billingAddress->street_two }} ,
|
||||
{{ $billingAddress->street_two }},
|
||||
{{ $billingAddress->district()->first()->name }},
|
||||
{{ $billingAddress->postcode }}
|
||||
{{ $billingAddress->state()->first()->name }},
|
||||
{{ $billingAddress->country()->first()->name }}
|
||||
</div>
|
||||
<div>
|
||||
Phone: {{ $supplier->contacts()->first()->phone }}
|
||||
</div>
|
||||
<div>Phone: {{ $supplier->contacts()->first()->phone }}</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<!-- Invoice Table -->
|
||||
<table class="line-table" style="overflow: wrap" autosize="1">
|
||||
<!-- Table Header -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%">No</th>
|
||||
@@ -81,35 +72,37 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$subtotal = 0;
|
||||
$voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null;
|
||||
|
||||
$voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0;
|
||||
$currencyRate = $transaction->currency_rate;
|
||||
$subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate);
|
||||
$voucherDiscount = getVoucherDiscount($voucher_redemption);
|
||||
$displayedSubtotal = 0;
|
||||
@endphp
|
||||
|
||||
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
|
||||
@php
|
||||
$exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5);
|
||||
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
|
||||
$displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2);
|
||||
$displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
|
||||
@endphp
|
||||
<tr>
|
||||
<td width="5%" class="center top">{{ $key + 1 }}</td>
|
||||
<td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
|
||||
<td class="description">{{ $transaction_detail->product_name }}</td>
|
||||
<td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
|
||||
<td width="15%" class="center top">
|
||||
@php
|
||||
$unitPrice = $transaction_detail->price / $currencyRate;
|
||||
@endphp
|
||||
{{ number_format($unitPrice, 2) }}
|
||||
{{ number_format($exactUnitPrice, 2) }}
|
||||
</td>
|
||||
<td width="20%" class="right top">
|
||||
@php
|
||||
$itemTotal = $unitPrice * $transaction_detail->quantity;
|
||||
$subtotal += $itemTotal;
|
||||
@endphp
|
||||
{{ number_format($itemTotal, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@php
|
||||
$voucherDiscount = getVoucherDiscount($voucher_redemption);
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||
@endphp
|
||||
<tr class="subtotal">
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Subtotal</td>
|
||||
@@ -120,23 +113,15 @@
|
||||
<td class="right">Service Charges</td>
|
||||
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
|
||||
</tr>
|
||||
|
||||
@if($voucher_redemption)
|
||||
<tr class="voucher">
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Voucher ({{ $voucher_redemption->voucher->code }})</td>
|
||||
<td class="right middle">-{{ $voucherDiscount }}</td>
|
||||
<td class="right middle">-{{ number_format($voucherDiscount, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Adjustment</td>
|
||||
<td class="right">
|
||||
@php
|
||||
$adjustment = $transaction->amount - $subtotal;
|
||||
@endphp
|
||||
{{ number_format($adjustment, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@if($transaction->tax > 0)
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
@@ -144,24 +129,59 @@
|
||||
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
|
||||
@endphp
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Adjustment</td>
|
||||
<td class="right middle">{{ roundUp($discrepancy,2) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Total</td>
|
||||
<td class="total right middle">
|
||||
@php
|
||||
$total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount;
|
||||
@endphp
|
||||
{{ number_format($total, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<htmlpagefooter name="page-footer">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="text-align: right; ">This is generated by computer. No signature required.</td>
|
||||
<td style="text-align: right; ">Page {PAGENO} of {nbpg}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</htmlpagefooter>
|
||||
<br>
|
||||
<div class="note">
|
||||
<strong>Note:</strong> All items purchased are subject to our Terms & Conditions. Please refer to our official website for more information.
|
||||
</div>
|
||||
<br><br>
|
||||
<div class="bank-info">
|
||||
Please transfer the payment to:<br>
|
||||
Bank: Maybank Berhad<br>
|
||||
Account Name: CIEF Worldwide Sdn Bhd<br>
|
||||
Account No: 564892103405<br>
|
||||
</div>
|
||||
@php
|
||||
function calculateSubtotal($po_order_transaction, $currencyRate) {
|
||||
$subtotal = "0";
|
||||
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
|
||||
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
|
||||
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
|
||||
$subtotal = bcadd($subtotal, $itemTotal, 5);
|
||||
}
|
||||
return $subtotal;
|
||||
}
|
||||
|
||||
function getVoucherDiscount($voucher_redemption) {
|
||||
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
}
|
||||
function roundUp($number, $decimals) {
|
||||
$factor = pow(10, $decimals);
|
||||
if ($number > 0) {
|
||||
return ceil($number * $factor) / $factor;
|
||||
} else {
|
||||
return floor($number * $factor) / $factor;
|
||||
}
|
||||
}
|
||||
|
||||
@endphp
|
||||
@endsection
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<br>
|
||||
|
||||
<table class="line-table" style="overflow: wrap" autosize="1">
|
||||
<!-- Table Header -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%">No</th>
|
||||
@@ -89,34 +90,37 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$subtotal = 0;
|
||||
$voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null;
|
||||
$voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0;
|
||||
$currencyRate = $transaction->currency_rate;
|
||||
$subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate);
|
||||
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
|
||||
$displayedSubtotal = 0;
|
||||
@endphp
|
||||
|
||||
@foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail)
|
||||
@php
|
||||
$exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5);
|
||||
$itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5);
|
||||
$displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2);
|
||||
$displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2);
|
||||
@endphp
|
||||
<tr>
|
||||
<td width="5%" class="center top">{{ $key + 1 }}</td>
|
||||
<td class="stock-code top" width="10%">{{ $transaction_detail->product_code }}</td>
|
||||
<td class="description">{{ $transaction_detail->product_name }}</td>
|
||||
<td width="10%" class="center top">{{ $transaction_detail->quantity }}</td>
|
||||
<td width="15%" class="center top">
|
||||
@php
|
||||
$unitPrice = $transaction_detail->price / $currencyRate;
|
||||
@endphp
|
||||
{{ number_format($unitPrice, 2) }}
|
||||
{{ number_format($exactUnitPrice, 2) }}
|
||||
</td>
|
||||
<td width="20%" class="right top">
|
||||
@php
|
||||
$itemTotal = $unitPrice * $transaction_detail->quantity;
|
||||
$subtotal += $itemTotal;
|
||||
@endphp
|
||||
{{ number_format($itemTotal, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@php
|
||||
$voucherDiscount = getPoVoucherDiscount($voucher_redemption);
|
||||
$subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract
|
||||
@endphp
|
||||
<tr class="subtotal">
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Subtotal</td>
|
||||
@@ -125,27 +129,17 @@
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Service Charges</td>
|
||||
<td class="right">
|
||||
{{ number_format($transaction->service_charge, 2) }}
|
||||
</td>
|
||||
<td class="right">{{ number_format($transaction->service_charge, 2) }}</td>
|
||||
</tr>
|
||||
|
||||
@if($voucher_redemption)
|
||||
<tr class="voucher">
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Voucher ({{ $voucher_redemption->voucher->code }})</td>
|
||||
<td class="right middle">-{{ $voucherDiscount }}</td>
|
||||
<td class="right middle">-{{ number_format($voucherDiscount, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
<td class="right">Adjustment</td>
|
||||
<td class="right">
|
||||
@php
|
||||
$adjustment = $transaction->amount - $subtotal;
|
||||
@endphp
|
||||
{{ number_format($adjustment, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@if($transaction->tax > 0)
|
||||
<tr class="billingcharges">
|
||||
<td colspan="4"></td>
|
||||
@@ -153,13 +147,21 @@
|
||||
<td class="right">{{ number_format($transaction->tax, 2) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2);
|
||||
$expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5);
|
||||
$discrepancy = bcsub($displayedTotal, $expectedTotal, 5);
|
||||
$total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision
|
||||
@endphp
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Adjustment</td>
|
||||
<td class="right middle">{{ roundUpPo($discrepancy,2) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"></td>
|
||||
<td class="right middle">Total</td>
|
||||
<td class="total right middle">
|
||||
@php
|
||||
$total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount;
|
||||
@endphp
|
||||
{{ number_format($total, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -173,4 +175,28 @@
|
||||
</tr>
|
||||
</table>
|
||||
</htmlpagefooter>
|
||||
@php
|
||||
function calculatePoSubtotal($po_order_transaction, $currencyRate) {
|
||||
$subtotal = "0";
|
||||
foreach ($po_order_transaction->transactionDetails as $transaction_detail) {
|
||||
$unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5);
|
||||
$itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5);
|
||||
$subtotal = bcadd($subtotal, $itemTotal, 5);
|
||||
}
|
||||
return $subtotal;
|
||||
}
|
||||
|
||||
function getPoVoucherDiscount($voucher_redemption) {
|
||||
return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0";
|
||||
}
|
||||
function roundUpPo($number, $decimals) {
|
||||
$factor = pow(10, $decimals);
|
||||
if ($number > 0) {
|
||||
return ceil($number * $factor) / $factor;
|
||||
} else {
|
||||
return floor($number * $factor) / $factor;
|
||||
}
|
||||
}
|
||||
|
||||
@endphp
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user