update email template
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\ClientData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ClientWriter
|
||||
{
|
||||
/**
|
||||
* Upsert into `customers` keyed by `uuid` (WHMCS already assigns a uuid per client).
|
||||
*/
|
||||
public function write(ClientData $data): void
|
||||
{
|
||||
DB::table('customers')->updateOrInsert(
|
||||
['uuid' => $data->uuid],
|
||||
[
|
||||
'fullname' => $data->fullname,
|
||||
'company' => $data->company,
|
||||
'address' => $data->address,
|
||||
'state' => $data->state,
|
||||
'city' => $data->city,
|
||||
'saler' => $data->saler,
|
||||
'country' => $data->country,
|
||||
'phone' => $data->phone,
|
||||
'email' => $data->email,
|
||||
'password' => $data->password,
|
||||
'note' => $data->note,
|
||||
'credit' => $data->credit,
|
||||
'status' => $data->status,
|
||||
'email_marketing' => $data->emailMarketing,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\CustomerDomainData;
|
||||
use App\Integrations\Whmcs\Support\DnsDomainLinker;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CustomerDomainWriter
|
||||
{
|
||||
public function __construct(private DnsDomainLinker $dnsLinker)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips domains whose WHMCS client couldn't be resolved to a local customer.
|
||||
*/
|
||||
public function write(CustomerDomainData $data): bool
|
||||
{
|
||||
if ($data->customerId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::table('module_domain')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'name' => $data->name,
|
||||
'order_id' => $data->orderId,
|
||||
'first_payment' => $data->firstPayment,
|
||||
'module_dns_id' => 0,
|
||||
'next_payment' => $data->nextPayment,
|
||||
'next_due_date' => $data->nextDueDate,
|
||||
'next_invoice_date' => $data->nextInvoiceDate,
|
||||
'customer_id' => $data->customerId,
|
||||
'domain_type_id' => 0,
|
||||
'registrar_id' => $data->registrarId,
|
||||
'note' => $data->note,
|
||||
'status' => $data->status,
|
||||
]
|
||||
);
|
||||
|
||||
$this->dnsLinker->link($data->name, $data->customerId, $data->registrarId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\InvoiceData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InvoiceWriter
|
||||
{
|
||||
/**
|
||||
* Skips invoices whose WHMCS client couldn't be resolved to a local customer —
|
||||
* invoices.customer_id is NOT NULL, so there is nothing valid to insert.
|
||||
*/
|
||||
public function write(InvoiceData $data): void
|
||||
{
|
||||
if ($data->customerId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($data) {
|
||||
DB::table('invoices')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'invoice_number' => $data->invoiceNumber,
|
||||
'date' => $data->date,
|
||||
'customer_id' => $data->customerId,
|
||||
'order_id' => $data->orderId,
|
||||
'sub_total' => $data->subTotal,
|
||||
'discount_amount' => $data->discountAmount,
|
||||
'tax' => $data->tax,
|
||||
'total' => $data->total,
|
||||
'status' => $data->status,
|
||||
'payment_method' => $data->paymentMethod,
|
||||
'due_date' => $data->dueDate,
|
||||
'paid_at' => $data->paidAt,
|
||||
'note' => $data->note,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->createdAt,
|
||||
]
|
||||
);
|
||||
|
||||
$invoiceId = DB::table('invoices')->where('legacy_id', $data->legacyId)->value('id');
|
||||
|
||||
foreach ($data->items as $item) {
|
||||
DB::table('invoice_items')->updateOrInsert(
|
||||
['legacy_id' => $item->legacyId],
|
||||
[
|
||||
'invoice_id' => $invoiceId,
|
||||
'product_id' => $item->productId,
|
||||
'type' => $item->type,
|
||||
'description' => $item->description,
|
||||
'quantity' => 1,
|
||||
'unit_price' => $item->unitPrice,
|
||||
'total_price' => $item->totalPrice,
|
||||
]
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\OrderItemData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderItemWriter
|
||||
{
|
||||
/**
|
||||
* Skips items whose order couldn't be resolved — order_items.order_id is NOT NULL.
|
||||
* Requires whmcs:sync-orders to have already run.
|
||||
*/
|
||||
public function write(OrderItemData $data): bool
|
||||
{
|
||||
if ($data->orderId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::table('order_items')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'order_id' => $data->orderId,
|
||||
'product_id' => $data->productId,
|
||||
'product_pricing_id' => $data->productPricingId,
|
||||
'server_name' => $data->serverName,
|
||||
'domain_name' => $data->domainName,
|
||||
'billing_cycle' => $data->billingCycle,
|
||||
'months' => $data->months,
|
||||
'quantity' => $data->quantity,
|
||||
'price' => $data->price,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
]
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\OrderData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderWriter
|
||||
{
|
||||
public function write(OrderData $data): void
|
||||
{
|
||||
DB::table('orders')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'order_num' => $data->orderNum,
|
||||
'date' => $data->date,
|
||||
'customer_id' => $data->customerId,
|
||||
'sub_total' => $data->total,
|
||||
'total' => $data->total,
|
||||
'status' => $data->status,
|
||||
'payment_method' => $data->paymentMethod,
|
||||
'note' => $data->note,
|
||||
'client_ip' => $data->clientIp,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->createdAt,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\ProductAddonData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProductAddonWriter
|
||||
{
|
||||
public function write(ProductAddonData $data): void
|
||||
{
|
||||
DB::table('product_addon')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'code' => $data->code,
|
||||
'name' => $data->name,
|
||||
'type' => $data->type,
|
||||
'price' => $data->price,
|
||||
'status' => $data->status,
|
||||
'sort_order' => $data->sortOrder,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\ProductCategoryData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProductCategoryWriter
|
||||
{
|
||||
public function write(ProductCategoryData $data): void
|
||||
{
|
||||
DB::table('product_categories')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'type' => $data->type,
|
||||
'is_active' => $data->isActive,
|
||||
'sort_order' => $data->sortOrder,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\ProductData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ProductWriter
|
||||
{
|
||||
/**
|
||||
* Skips products whose category couldn't be resolved — products.product_categories_id is NOT NULL.
|
||||
*/
|
||||
public function write(ProductData $data): bool
|
||||
{
|
||||
if ($data->categoryId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($data) {
|
||||
$productType = DB::table('product_categories')->where('id', $data->categoryId)->value('type') ?? 'other';
|
||||
|
||||
DB::table('products')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'uuid' => DB::table('products')->where('legacy_id', $data->legacyId)->value('uuid') ?? (string) Str::uuid(),
|
||||
'product_type' => $productType,
|
||||
'product_categories_id' => $data->categoryId,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'short_description' => $data->shortDescription,
|
||||
'description' => $data->description,
|
||||
'stock' => $data->stock,
|
||||
'is_unlimited' => $data->isUnlimited,
|
||||
'setup_fee' => $data->setupFee,
|
||||
'is_active' => $data->isActive,
|
||||
'sort_order' => $data->sortOrder,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
]
|
||||
);
|
||||
|
||||
$productId = DB::table('products')->where('legacy_id', $data->legacyId)->value('id');
|
||||
|
||||
foreach ($data->pricings as $pricing) {
|
||||
DB::table('product_pricings')->updateOrInsert(
|
||||
['product_id' => $productId, 'billing_cycle' => $pricing['billing_cycle']],
|
||||
['price' => $pricing['price'], 'currency' => 'VND']
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Writers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\ServiceData;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ServiceWriter
|
||||
{
|
||||
/**
|
||||
* Skips services whose WHMCS client couldn't be resolved to a local customer —
|
||||
* services.customer_id is NOT NULL.
|
||||
*/
|
||||
public function write(ServiceData $data): bool
|
||||
{
|
||||
if ($data->customerId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::table('services')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'uuid' => DB::table('services')->where('legacy_id', $data->legacyId)->value('uuid') ?? (string) Str::uuid(),
|
||||
'customer_id' => $data->customerId,
|
||||
'product_id' => $data->productId,
|
||||
'legacy_product_id' => $data->legacyProductId,
|
||||
'order_item_id' => $data->orderItemId,
|
||||
'server_name' => $data->serverName,
|
||||
'status' => $data->status,
|
||||
'auto_renew' => $data->autoRenew,
|
||||
'started_at' => $data->startedAt,
|
||||
'expires_at' => $data->expiresAt,
|
||||
'cancelled_at' => $data->cancelledAt,
|
||||
'note' => $data->note,
|
||||
]
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user