diff --git a/app/Import/Providers/BaseImport.php b/app/Import/Providers/BaseImport.php index 483993951309..6cb455352019 100644 --- a/app/Import/Providers/BaseImport.php +++ b/app/Import/Providers/BaseImport.php @@ -390,6 +390,7 @@ class BaseImport try { $invoice_data = $invoice_transformer->transform($raw_invoice); + $invoice_data['user_id'] = $this->company->owner()->id; $invoice_data['line_items'] = $this->cleanItems( $invoice_data['line_items'] ?? [] diff --git a/app/Services/Quickbooks/Models/QbClient.php b/app/Services/Quickbooks/Models/QbClient.php index b40a71c7eb85..9ea3f6d90bfe 100644 --- a/app/Services/Quickbooks/Models/QbClient.php +++ b/app/Services/Quickbooks/Models/QbClient.php @@ -83,6 +83,11 @@ class QbClient implements SyncInterface { } + public function sync(string $id, string $last_updated): void + { + + } + private function findClient(string $key): ?Client { $search = Client::query() diff --git a/tests/Feature/Import/Quickbooks/QuickbooksTest.php b/tests/Feature/Import/Quickbooks/QuickbooksTest.php index 5fa4862bcde0..d9f38c5dfb4f 100644 --- a/tests/Feature/Import/Quickbooks/QuickbooksTest.php +++ b/tests/Feature/Import/Quickbooks/QuickbooksTest.php @@ -41,16 +41,123 @@ class QuickbooksTest extends TestCase elseif(Company::whereNotNull('quickbooks')->count() == 0){ $this->markTestSkipped('No need to run this test on Travis'); } + + $this->makeTestData(); } - public function testCreateInvoiceInQb() + public function testCreateCustomerInQb() { - $c = Company::whereNotNull('quickbooks')->first(); $qb = new QuickbooksService($c); + + $customerData = [ + "DisplayName" => $this->client->present()->name(), // Required and must be unique + "PrimaryEmailAddr" => [ + "Address" => $this->client->present()->email(), + ], + "PrimaryPhone" => [ + "FreeFormNumber" => $this->client->present()->phone() + ], + "CompanyName" => $this->client->present()->name(), + "BillAddr" => [ + "Line1" => $this->client->address1 ?? '', + "City" => $this->client->city ?? '', + "CountrySubDivisionCode" => $this->client->state ?? '', + "PostalCode" => $this->client->postal_code ?? '', + "Country" => $this->client->country->iso_3166_3 + ], + "ShipAddr" => [ + "Line1" => $this->client->shipping_address1 ?? '', + "City" => $this->client->shipping_city ?? '', + "CountrySubDivisionCode" => $this->client->shipping_state ?? '', + "PostalCode" => $this->client->shipping_postal_code ?? '', + "Country" => $this->client->shipping_country->iso_3166_3 + ], + "GivenName" => $this->client->present()->first_name(), + "FamilyName" => $this->client->present()->last_name(), + "PrintOnCheckName" => $this->client->present()->primary_contact_name(), + "Notes" => $this->client->public_notes, + // "TaxIdentifier" => $this->client->vat_number ?? '', // Federal Employer Identification Number (EIN) + "BusinessNumber" => $this->client->id_number ?? '', + "Active" => $this->client->deleted_at ? false : true, + "V4IDPseudonym" => $this->client->client_hash, + "WebAddr" => $this->client->website ?? '', + ]; + + + $customer = \QuickBooksOnline\API\Facades\Customer::create($customerData); + + // $customer = $qb->sdk->createCustomer($customerData); + + $this->assertNotNull($customer); + + nlog($customer); + + + // Send the create request to QuickBooks + $resultingCustomerObj = $qb->sdk->Add($customer); + + // Check for errors + $error = $qb->sdk->getLastError(); + if ($error) { + $this->fail("The Customer could not be created: " . $error->getResponseBody()); + } + + nlog($resultingCustomerObj); + + } + + + // public function testCreateInvoiceInQb() + // { + + // $c = Company::whereNotNull('quickbooks')->first(); + + // $qb = new QuickbooksService($c); + + // //create QB customer + // //create ninja invoice + + // //create QB invoice + + // } + + + public function stubData() + { + + // Inside the create method + $lineItems = [ + [ + "Amount" => 100.00, + "DetailType" => "SalesItemLineDetail", + "SalesItemLineDetail" => [ + "ItemRef" => [ + "value" => "1", // Replace with actual Item ID from QuickBooks + "name" => "Services" + ] + ] + ] + ]; + + $invoiceData = [ + "Line" => $lineItems, + "CustomerRef" => [ + "value" => "1", // Replace with actual Customer ID from QuickBooks + ], + "BillEmail" => [ + "Address" => "customer@example.com" + ], + "DueDate" => "2023-12-31", + "TotalAmt" => 100.00, + "DocNumber" => "INV-001" + ]; + + $invoice = QbInvoice::create($invoiceData); + } }