1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
This commit is contained in:
David Bomba 2024-09-24 07:22:53 +10:00
parent fa1a7937e6
commit 174a02b52a
5 changed files with 119 additions and 111 deletions

View File

@ -431,31 +431,31 @@ class BillingPortalPurchasev2 extends Component
* @throws PresenterException
* @throws InvalidArgumentException
*/
private function createClientContact()
{
$company = $this->subscription->company;
$user = $this->subscription->user;
$user->setCompany($company);
// private function createClientContact()
// {
// $company = $this->subscription->company;
// $user = $this->subscription->user;
// $user->setCompany($company);
$client_repo = new ClientRepository(new ClientContactRepository());
$data = [
'name' => '',
'group_settings_id' => $this->subscription->group_id,
'contacts' => [
['email' => $this->email],
],
'client_hash' => Str::random(40),
'settings' => ClientSettings::defaults(),
];
// $client_repo = new ClientRepository(new ClientContactRepository());
// $data = [
// 'name' => '',
// 'group_settings_id' => $this->subscription->group_id,
// 'contacts' => [
// ['email' => $this->email],
// ],
// 'client_hash' => Str::random(40),
// 'settings' => ClientSettings::defaults(),
// ];
$client = $client_repo->save($data, ClientFactory::create($company->id, $user->id));
// $client = $client_repo->save($data, ClientFactory::create($company->id, $user->id));
$this->contact = $client->fresh()->contacts()->first();
// $this->contact = $client->fresh()->contacts()->first();
Auth::guard('contact')->loginUsingId($this->contact->id, true);
// Auth::guard('contact')->loginUsingId($this->contact->id, true);
return $this;
}
// return $this;
// }
/**

View File

@ -451,7 +451,6 @@ class CreditCard implements LivewireMethodInterface
match($error_object->error->code) {
"UnfulfilledCondition" => $error_message = $error_object->error->details->messages[0] ?? $error_object->error->message ?? "Unknown error",
"GatewayError" => $error_message = $error_object->error->message,
"UnfulfilledCondition" => $error_message = $error_object->error->message,
"transaction_declined" => $error_message = $error_object->error->details[0]->status_code_description,
default => $error_message = $error_object->error->message ?? "Unknown error",
};

View File

@ -107,7 +107,7 @@ class Partner
{
$uri = "/partner/{$this->partner_number}/account/{$accountRegNo}";
return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::DELETE)->value)->object();
return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::DELETE)->value),[])->object();
}
/**
@ -138,7 +138,7 @@ class Partner
{
$uri = "/partner/{$this->partner_number}/account/{$accountRegNo}/peppol/{$peppolId}";
return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::DELETE)->value)->object();
return $this->qvalia->httpClient($uri, (\App\Enum\HttpVerb::DELETE)->value), [])->object();
}
}

View File

@ -109,8 +109,8 @@ class QuickbooksImport implements ShouldQueue
match($entity){
'client' => $this->qbs->client->syncToNinja($records),
'product' => $this->qbs->product->syncToNinja($records),
// 'invoice' => $this->syncQbToNinjaInvoices($records),
// 'sales' => $this->syncQbToNinjaInvoices($records),
'invoice' => $this->qbs->invoice->syncToNinja($records),
'sales' => $this->qbs->invoice->syncToNinja($records),
// 'vendor' => $this->syncQbToNinjaVendors($records),
// 'quote' => $this->syncInvoices($records),
// 'expense' => $this->syncQbToNinjaExpenses($records),
@ -122,91 +122,11 @@ class QuickbooksImport implements ShouldQueue
private function syncQbToNinjaInvoices($records): void
{
nlog("invoice sync ". count($records));
$invoice_transformer = new InvoiceTransformer($this->company);
foreach($records as $record)
{
nlog($record);
$ninja_invoice_data = $invoice_transformer->qbToNinja($record);
nlog($ninja_invoice_data);
$payment_ids = $ninja_invoice_data['payment_ids'] ?? [];
$client_id = $ninja_invoice_data['client_id'] ?? null;
if(is_null($client_id))
continue;
unset($ninja_invoice_data['payment_ids']);
if($invoice = $this->findInvoice($ninja_invoice_data))
{
$invoice->fill($ninja_invoice_data);
$invoice->saveQuietly();
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->createInvitations()->save();
foreach($payment_ids as $payment_id)
{
$payment = $this->qbs->sdk->FindById('Payment', $payment_id);
$payment_transformer = new PaymentTransformer($this->company);
$transformed = $payment_transformer->qbToNinja($payment);
$ninja_payment = $payment_transformer->buildPayment($payment);
$ninja_payment->service()->applyNumber()->save();
$paymentable = new \App\Models\Paymentable();
$paymentable->payment_id = $ninja_payment->id;
$paymentable->paymentable_id = $invoice->id;
$paymentable->paymentable_type = 'invoices';
$paymentable->amount = $transformed['applied'] + $ninja_payment->credits->sum('amount');
$paymentable->created_at = $ninja_payment->date; //@phpstan-ignore-line
$paymentable->save();
$invoice->service()->applyPayment($ninja_payment, $paymentable->amount);
}
if($record instanceof IPPSalesReceipt)
{
$invoice->service()->markPaid()->save();
}
}
$ninja_invoice_data = false;
}
}
private function findInvoice(array $ninja_invoice_data): ?Invoice
{
$search = Invoice::query()
->withTrashed()
->where('company_id', $this->company->id)
// ->where('number', $ninja_invoice_data['number']);
->where('sync->qb_id', $ninja_invoice_data['id']);
if($search->count() == 0) {
//new invoice
$invoice = InvoiceFactory::create($this->company->id, $this->company->owner()->id);
$invoice->client_id = $ninja_invoice_data['client_id'];
return $invoice;
} elseif($search->count() == 1) {
return $this->settings->invoice->update_record ? $search->first() : null;
}
return null;
}
private function syncQbToNinjaVendors(array $records): void
{

View File

@ -11,20 +11,109 @@
namespace App\Services\Quickbooks\Models;
use App\Models\Invoice;
use App\Factory\InvoiceFactory;
use App\Interfaces\SyncInterface;
use App\Services\Quickbooks\QuickbooksService;
use App\Services\Quickbooks\Transformers\InvoiceTransformer;
use App\Services\Quickbooks\Transformers\PaymentTransformer;
class QbInvoice
class QbInvoice implements SyncInterface
{
protected InvoiceTransformer $transformer;
public function __construct(public QuickbooksService $service)
{
$this->transformer = new InvoiceTransformer($this->service->company);
}
public function find(int $id)
public function find(int $id): mixed
{
return $this->service->sdk->FindById('Invoice', $id);
}
public function syncToNinja(array $records): void
{
foreach ($records as $record) {
$ninja_invoice_data = $this->transformer->qbToNinja($record);
$payment_ids = $ninja_invoice_data['payment_ids'] ?? [];
$client_id = $ninja_invoice_data['client_id'] ?? null;
if (is_null($client_id)) {
continue;
}
unset($ninja_invoice_data['payment_ids']);
if ($invoice = $this->findInvoice($ninja_invoice_data)) {
$invoice->fill($ninja_invoice_data);
$invoice->saveQuietly();
$invoice = $invoice->calc()->getInvoice()->service()->markSent()->createInvitations()->save();
foreach ($payment_ids as $payment_id) {
$payment = $this->service->sdk->FindById('Payment', $payment_id);
$payment_transformer = new PaymentTransformer($this->service->company);
$transformed = $payment_transformer->qbToNinja($payment);
$ninja_payment = $payment_transformer->buildPayment($payment);
$ninja_payment->service()->applyNumber()->save();
$paymentable = new \App\Models\Paymentable();
$paymentable->payment_id = $ninja_payment->id;
$paymentable->paymentable_id = $invoice->id;
$paymentable->paymentable_type = 'invoices';
$paymentable->amount = $transformed['applied'] + $ninja_payment->credits->sum('amount');
$paymentable->created_at = $ninja_payment->date; //@phpstan-ignore-line
$paymentable->save();
$invoice->service()->applyPayment($ninja_payment, $paymentable->amount);
}
if ($record instanceof IPPSalesReceipt) {
$invoice->service()->markPaid()->save();
}
}
$ninja_invoice_data = false;
}
}
public function syncToForeign(array $records): void
{
}
private function findInvoice(array $ninja_invoice_data): ?Invoice
{
$search = Invoice::query()
->withTrashed()
->where('company_id', $this->service->company->id)
->where('sync->qb_id', $ninja_invoice_data['id']);
if($search->count() == 0) {
$invoice = InvoiceFactory::create($this->service->company->id, $this->service->company->owner()->id);
$invoice->client_id = $ninja_invoice_data['client_id'];
return $invoice;
} elseif($search->count() == 1) {
return $this->service->settings->invoice->update_record ? $search->first() : null;
}
return null;
}
}