k-eggermont / laravel-quickbooks
Requires
- quickbooks/v3-php-sdk: ^5.0
This package is auto-updated.
Last update: 2024-09-26 03:22:12 UTC
README
PHP 包装器,用于连接 QuickBooks Online V3 REST API。
安装
composer require XX php artisan vendor:publish php artisan migrate
别忘了将 \Keggermont\LaravelQuickbooks\QuickbooksServiceProvider::class 添加到你的 config/app.php 文件中
配置
你可以编辑 config/quickbooks.php 文件来设置你的配置。你可以使用 playground 生成 accessToken、refreshToken、RealmID 等 .. ( https://developer.intuit.com/v2/ui#/playground )
可用的命令
你有一些可用的命令
php artisan quickbooks:import-accounts php artisan quickbooks:import-taxcodes php artisan quickbooks:refresh-objects
Import-Accounts
从 Quickbooks 导入数据到 quickbooks_accounts 表。有关账户的更多信息
Import-Taxcodes
从 Quickbooks 导入数据到 quickbooks_tax_rates 和 quickbooks_tax_codes 表。有关 TaxRate 和 TaxCode 的更多信息
- https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/taxcode
- https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/taxrate
Refresh-Objects
从 Quickbooks 导入对象数据(账单、采购订单、发票、贷项凭条)到 quickbooks_entities 表。有关对象的更多信息
- https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/bill
- https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/purchaseorder
- https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/invoice
- https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/creditmemo
如果没有变化,数据库将不会更新。在发票更改时,pdf 已下载到服务器(配置在 config/quickbooks.php 中)
实体
你可以访问 4 个新的实体(与 Eloquent 一起)
- Keggermont\LaravelQuickbooks\Entities\QuickbooksAccount
- Keggermont\LaravelQuickbooks\Entities\QuickbooksEntity
- Keggermont\LaravelQuickbooks\Entities\QuickbooksTaxCode
- Keggermont\LaravelQuickbooks\Entities\QuickbooksTaxRate
你可以使用 Eloquent 制作一些事件来监听更改。
使用的库
https://github.com/intuit/QuickBooks-V3-PHP-SDK
你可以通过
$Qb = Keggermont\LaravelQuickbooks\Helpers\Quickbooks::getInstance(); $dataService = $Qb->getDataService();
用于与 API 交互的示例代码
/* Dump all Invoices */ $Qb = Keggermont\LaravelQuickbooks\Helpers\Quickbooks::getInstance(); $dataService = $Qb->getDataService(); dump($dataService->query("SELECT * FROM Invoice") /* Dump an Customer Id */ dump($dataService->FindById("customer",1); /* Dump all Customers */ dump($dataService->FindAll("customer");
你可以在以下链接找到库的示例代码: https://github.com/IntuitDeveloper/SampleApp-CRUD-PHP
高级使用
使用 Quickbooks API 创建或更新数据的最佳实践是使用 Transformer。
首先,导入包 fractal
composer require league/fractal
现在你可以创建你的 Transformer,如下所示
# File: app/Transformers/QuickbooksCustomerTransformer.php namespace App\Transformers; use App\Customer; use League\Fractal\TransformerAbstract; class QuickbooksCustomerTransformer extends TransformerAbstract { /** * @param Customer $customer * @return array */ public function transform(Customer $customer) { // Append the display name for avoid Vendor/Customer duplication $displayName = $customer->name." (C)"; $billing_address = $customer->billing_address; $arr_methods = ["MONEY" => "1","CARD" => "3","WIRE" => "5"]; $arr_conditions = ["NET30" => "3", "NET15" => "2", "NET60" => "4", "DEFAULT" => "1"]; return [ "BillAddr" => [ "Line1" => $billing_address->address, "Line2" => $billing_address->address_line_2, "Line3" => null, "City" => $billing_address->city, "Country" => $billing_address->country, "CountrySubDivisionCode" => "FR", "PostalCode" => $billing_address->zip ], "GivenName" => $customer->owner->first_name, "FamilyName" => $customer->owner->name, "CompanyName" => $customer->name, "DisplayName" => $displayName, "SalesTermRef" => ["value" => $arr_conditions[strtoupper($customer->payment_condition)]], "PaymentMethodRef" => ["value" => $arr_methods[strtoupper($customer->payment_method)]], "Notes" => $customer->notes, "PrintOnCheckName" => $customer->name, "PrimaryPhone" => [ "FreeFormNumber" => $customer->owner->phone ], "PrimaryEmailAddr" => [ "Address" => $customer->owner->email ] ]; } }
现在你可以使用 Quickbooks 创建客户
use Keggermont\LaravelQuickbooks\Helpers\Quickbooks; use App\Transformers\QuickbooksCustomerTransformer; use QuickBooksOnline\API\Facades\Customer; $Qb = Quickbooks::getInstance(); $dataService = $Qb->getDataService(); $customerObj = App\Customer::firstOrFail(); $customerQuickbooks = (new QuickbooksCustomerTransformer)->transform($customerObj); $theResourceObj = Customer::create($customerQuickbooks); $resultingObj = $dataService->Add($theResourceObj);