QB imports

This commit is contained in:
David Bomba 2024-09-19 20:12:56 +10:00
parent 6afd7a8970
commit 92ba61be51
4 changed files with 21 additions and 9 deletions

View File

@ -40,6 +40,7 @@ class QuickbooksSettings implements Castable
'client' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],
'vendor' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],
'invoice' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],
'sales' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],
'quote' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],
'purchase_order' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],
'product' => ['sync' => true, 'update_record' => true, 'direction' => 'bidirectional'],

View File

@ -32,6 +32,7 @@ use App\Services\Quickbooks\Transformers\ClientTransformer;
use App\Services\Quickbooks\Transformers\InvoiceTransformer;
use App\Services\Quickbooks\Transformers\PaymentTransformer;
use App\Services\Quickbooks\Transformers\ProductTransformer;
use QuickBooksOnline\API\Data\IPPSalesReceipt;
class QuickbooksSync implements ShouldQueue
{
@ -47,6 +48,7 @@ class QuickbooksSync implements ShouldQueue
'quote' => 'Estimate',
'purchase_order' => 'PurchaseOrder',
'payment' => 'Payment',
'sales' => 'SalesReceipt',
];
private QuickbooksService $qbs;
@ -105,6 +107,7 @@ class QuickbooksSync implements ShouldQueue
'client' => $this->syncQbToNinjaClients($records),
'product' => $this->syncQbToNinjaProducts($records),
'invoice' => $this->syncQbToNinjaInvoices($records),
'sales' => $this->syncQbToNinjaInvoices($records),
// 'vendor' => $this->syncQbToNinjaClients($records),
// 'quote' => $this->syncInvoices($records),
// 'purchase_order' => $this->syncInvoices($records),
@ -115,6 +118,7 @@ class QuickbooksSync implements ShouldQueue
private function syncQbToNinjaInvoices($records): void
{
nlog("invoice sync ". count($records));
$invoice_transformer = new InvoiceTransformer($this->company);
foreach($records as $record)
@ -164,6 +168,11 @@ class QuickbooksSync implements ShouldQueue
}
if($record instanceof IPPSalesReceipt)
{
$invoice->service()->markPaid()->save();
}
}
$ninja_invoice_data = false;

View File

@ -21,7 +21,7 @@ class SdkWrapper
{
public const MAXRESULTS = 10000;
private $entities = ['Customer','Invoice','Item'];
private $entities = ['Customer','Invoice','Item','SalesReceipt'];
private OAuth2AccessToken $token;
@ -176,12 +176,18 @@ class SdkWrapper
$start = 0;
$limit = 1000;
try {
$total = $this->totalRecords($entity);
$total = min($max, $total);
nlog("total = {$total}");
// Step 3 & 4: Get chunks of records until the total required records are retrieved
do {
$limit = min(self::MAXRESULTS, $total - $start);
nlog("limit = {$limit}");
$recordsChunk = $this->queryData("select * from $entity", $start, $limit);
if(empty($recordsChunk)) {
break;
@ -189,6 +195,8 @@ class SdkWrapper
$records = array_merge($records, $recordsChunk);
$start += $limit;
nlog("start = {$start}");
} while ($start < $total);
if(empty($records)) {
throw new \Exception("No records retrieved!");
@ -198,7 +206,8 @@ class SdkWrapper
nlog("Fetch Quickbooks API Error: {$th->getMessage()}");
}
nlog($records);
// nlog($records);
return $records;
}
}

View File

@ -58,8 +58,6 @@ class InvoiceTransformer extends BaseTransformer
{
$payments = [];
nlog("get payments");
$qb_payments = data_get($qb_data, 'LinkedTxn', false);
if(!$qb_payments) {
@ -67,7 +65,6 @@ class InvoiceTransformer extends BaseTransformer
}
if(!is_array($qb_payments) && data_get($qb_payments, 'TxnType', false) == 'Payment'){
nlog([data_get($qb_payments, 'TxnId.value', false)]);
return [data_get($qb_payments, 'TxnId.value', false)];
}
@ -80,8 +77,6 @@ class InvoiceTransformer extends BaseTransformer
}
}
nlog($payments);
return $payments;
}
@ -102,8 +97,6 @@ class InvoiceTransformer extends BaseTransformer
$item->type_id = stripos(data_get($qb_item, 'ItemAccountRef.name') ?? '', 'Service') !== false ? '2' : '1';
$item->tax_id = data_get($qb_item, 'TaxCodeRef.value', '') == 'NON' ? Product::PRODUCT_TYPE_EXEMPT : $item->type_id;
$item->tax_rate1 = data_get($qb_item, 'TxnTaxDetail.TaxLine.TaxLineDetail.TaxPercent', 0);
// $item->tax_rate1 = data_get($qb_item, 'TaxLineDetail.TaxRateRef.TaxPercent', 0);
$item->tax_name1 = $item->tax_rate1 > 0 ? "Sales Tax" : "";
$items[] = (object)$item;
}