fatihsafa / efatura
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ^6.5
- kwn/number-to-words: ^1.9
- mpdf/mpdf: ^8.0
- ramsey/uuid: ^2.9
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-19 05:38:40 UTC
README
此库通过PHP实现通过电子档案创建、编辑、签名等操作,完全免费且正在积极开发中。
🚩安装
使用自己的数据进行测试
https://earsivportal.efatura.gov.tr/intragiris.html
使用测试账户进行测试
https://earsivportaltest.efatura.gov.tr/login.jsp
包安装
composer require furkankadioglu/efatura
🚩功能
- 开启和结束eArşiv会话。
- 创建发票。
- 在两个日期之间搜索发票。
- 显示菜单列表。
- 显示发票详细信息。
- 使用土耳其语或英语选项创建发票模型。
- 签名/批准发票。
- 以HTML格式输出发票。
- 获取发票下载地址。
- 取消发票。
- 搜索现有发票。
- 提取用户信息。(您公司的基本信息)
- 更新用户信息。
- 通过短信验证和批准发票。
- 以PDF格式输出发票。
🚩示例
入口
通过创建一个client将通用结构引入我们的项目中。
use furkankadioglu\eFatura\InvoiceManager; $client = new InvoiceManager();
您可以使用chain函数定义入口信息,这对于生产环境是有效的。
// Production environment $client->setUsername("XXX")->setPassword("YYY"); // VEYA $client->setCredentials("XXX", "YYY");
以下是如何在测试模式下运行,没有公司信息的情况下自动进行测试登录。接下来的所有操作将通过测试账户进行。
// Test Environment $client->setDebugMode(true)->setTestCredentials();
如果您想查看信息
$client->getCredentials();
定义信息后,登录并获取token(没有此操作无法进行下一步):
$client->connect();
发票管理
以下是如何列出发票:
// Tüm faturaları listele $client->getInvoicesFromAPI("01/01/2020", "08/02/2020");
如果您想创建新发票,有几个选项,对于习惯了英文的人来说有两种不同的方法,我们先从土耳其语开始。
以下是一个创建发票的示例:
$fatura_detaylari = [ "belgeNumarasi" => "", // Zorunlu değil "faturaTarihi" => "08/02/2020", "saat" => "09:07:48", "paraBirimi" => "TRY", "dovzTLkur" => "0", "faturaTipi" => "SATIS", "vknTckn" => "11111111111", "aliciUnvan" => "FURKAN KADIOGLU", "aliciAdi" => "FURKAN", "aliciSoyadi" => "KADIOGLU", "binaAdi" => "", // Zorunlu değil "binaNo" => "", // Zorunlu değil "kapiNo" => "", // Zorunlu değil "kasabaKoy" => "", // Zorunlu değil "vergiDairesi" => "MALTEPE", "ulke" => "Türkiye", "bulvarcaddesokak" => "DENEME SK. DENEME MAH.", "mahalleSemtIlce" => "", // Zorunlu değil "sehir" => " ", "postaKodu" => "", // Zorunlu değil "tel" => "", // Zorunlu değil "fax" => "", // Zorunlu değil "eposta" => "", // Zorunlu değil "websitesi" => "", // Zorunlu değil "iadeTable" => [], // Zorunlu değil "ozelMatrahTutari" => "0", // Zorunlu değil "ozelMatrahOrani" => 0, // Zorunlu değil "ozelMatrahVergiTutari" => "0", // Zorunlu değil "vergiCesidi" => " ", // Zorunlu değil "malHizmetTable" => [], "tip" => "İskonto", "matrah" => 100, "malhizmetToplamTutari" => 100, "toplamIskonto" => "0", "hesaplanankdv" => 18, "vergilerToplami" => 18, "vergilerDahilToplamTutar" => 118, "odenecekTutar" => 118, "not" => "xxx", // Zorunlu değil "siparisNumarasi" => "", // Zorunlu değil "siparisTarihi" => "", // Zorunlu değil "irsaliyeNumarasi" => "", // Zorunlu değil "irsaliyeTarihi" => "", // Zorunlu değil "fisNo" => "", // Zorunlu değil "fisTarihi" => "", // Zorunlu değil "fisSaati" => " ", // Zorunlu değil "fisTipi" => " ", // Zorunlu değil "zRaporNo" => "", // Zorunlu değil "okcSeriNo" => "" // Zorunlu değil ];
创建发票当然不够,还需要输入产品或服务,情况如下。
$fatura_detaylari["malHizmetTable"][] = [ "malHizmet" => "Yazılım Geliştirme", "miktar" => 28, "birim" => "DAY", "birimFiyat" => "3", "fiyat" => "84", "iskontoArttm" => "İskonto", "iskontoOrani" => 0, "iskontoTutari" => "0", "iskontoNedeni" => "", "malHizmetTutari" => "99", "kdvOrani" => 18, "kdvTutari" => "15.12", "vergininKdvTutari" => "0" ];
由于变量是土耳其语,我们使用了< strong>mapWithTurkishKeys函数。
use furkankadioglu\eFatura\Invoice; $inv = new Invoice(); $inv->mapWithTurkishKeys($fatura_detaylari); // Key yapısı türkçe 🇹🇷 // VEYA $inv->mapWithEnglishKeys($invoice_details); // Key yapısı ingilizce 🇺🇸
然后我们需要将其注册到InvoiceManager中。如下所示:
$client->setInvoice($inv);
然后我们创建草稿。
$client->createDraftBasicInvoice();
用户信息
这部分是您公司在eArşiv中注册的信息。您可以获取和更新这些信息。
👉同时,这些信息也满足了您在创建发票时所需的大量数据需求。
$userInformations = $client->getUserInformationsData();
此操作会返回一个UserInformations类。您可以使用set和get方法更改类中的所有数据。
// Sadece vknTckn değiştirilemez. $userInformations = $userInformations->setUnvan("FRKN Yazılım")->setApartmanNo("4"); $apartmanNo = $userInformations->getApartmanNo(); // 4
此外,如果您想批量获取这些数据,可以采用以下用法,该函数在Invoice类中也有效
$userInformations->export(); // Array olarak tüm değişkenleri döndürür.
此外,您也可以自己创建此类,并以数组的形式提供数据。然后我们以如下方式发送到服务器:
$client->setUserInformations($userInformations); // Manager'a tanımla. $client->sendUserInformationsData(); // Sunucuya gönder.
🚩功能特性
(下载/批准/HTML输出/取消等)
批准
$client->signDraftInvoice();
获取HTML输出
$client->getInvoiceHTML();
获取PDF输出
$client->getInvoicePDF();
获取下载链接
$client->getDownloadURL();
取消发票
$client->cancelInvoice();
进行SMS验证
$client->sendSMSVerification($telefon); // Operasyon id döndürür.
批准SMS验证
$client->verifySMSCode($kod, $operasyonId);
获取个人或组织信息
$client->getCompanyInfo($TCKimlikNoVeyaVergiNo);
登出并关闭会话
$client->logOutFromAPI();
搜索现有发票
$oldInvoice = new Invoice(); $oldInvoice->setUuid("e8277cfa-4ac9-11ea-a5b5-acde48001122"); $client->setInvoice($oldInvoice)->getInvoiceFromAPI(); // {"faturaUuid":"8a4423bc-4aca-11ea-8c30-acde48001122","faturaTarihi":"09\/02\/2020"...
🚩替代用法
缩写用法
可能有点长。😂当然,chain方法让我们的生活变得更简单。让我们一行完成工作
$client->setDebugMode(true) // Test urlsine geçtik ->setTestCredentials() // Test bilgilerini aldık ->connect() // Bilgilerle birlikte sunucuya bağlanıp token aldık. ->setInvoice($inv) // Faturamızı sınıfa tanımladık (Invoice sınıfı kullanılmalı) ->createDraftBasicInvoice() // Taslak faturamızı oluşturduk ->getDownloadURL(); // İndirme adresini aldık // https://earsivportaltest.efatura.gov.tr/earsiv-services/download?token=b8b6c261c511a9b2757279c0111b538a2f02d98ae2df6205448d002687cab8cf74ce04d187bf0c6ce839dee40a6a8aad003aa6d5946ba02a0942ceb10bde327f&ettn=85933f42-4ab1-11ea-922e-acde48001122&belgeTip=FATURA&onayDurumu=Onaylandı&cmd=downloadResource
常量变量
由于存在多种不同的数据类型,且事先未知可能会出现问题,因此还提供了所需的一些固定选项。所有变量名称都与eArşiv中显示的完全一致。您可以从示例中看到一些。
use furkankadioglu\eFatura\Models\Country; use furkankadioglu\eFatura\Models\CurrencyType; use furkankadioglu\eFatura\Models\InvoiceType; use furkankadioglu\eFatura\Models\UnitType; $gunBirim = UnitType::GUN; // DAY $turkLirasi = CurrencyType::TURK_LIRASI; // TRY $satisFaturasi = InvoiceType::SATIS; // SATIŞ $gurcistanUlkesi = Country::GURCISTAN; // Gürcistan
修改主结构
use furkankadioglu\eFatura\Invoice; $inv = new Invoice(); $invoice_details = [ "uuid" => $uuid, "documentNumber" => $documentNumber, "date" => $date, "time" => $time, "currency" => $currency, "currencyRate" => $currencyRate, "invoiceType" => $invoiceType, "taxOrIdentityNumber" => $taxOrIdentityNumber, "invoiceAcceptorTitle" => $invoiceAcceptorTitle, "invoiceAcceptorName" => $invoiceAcceptorName, "invoiceAcceptorLastName" => $invoiceAcceptorLastName, "buildingName" => $buildingName, "buildingNumber" => $buildingNumber, "doorNumber" => $doorNumber, "town" => $town, "taxAdministration" => $taxAdministration, "country" => $country, "avenueStreet" => $avenueStreet, "district" => $district, "city" => $city, "postNumber" => $postNumber, "telephoneNumber" => $telephoneNumber, "faxNumber" => $faxNumber, "email" => $email, "website" => $website, "refundTable" => $refundTable, "specialBaseAmount" => $specialBaseAmount, "specialBasePercent" => $specialBasePercent, "specialBaseTaxAmount" => $specialBaseTaxAmount, "taxType" => $taxType, "itemOrServiceList" => $itemOrServiceList, "type" => $type, "base" => $base, "itemOrServiceTotalPrice" => $itemOrServiceTotalPrice, "totalDiscount" => $totalDiscount, "calculatedVAT" => $calculatedVAT, "taxTotalPrice" => $taxTotalPrice, "includedTaxesTotalPrice" => $includedTaxesTotalPrice, "paymentPrice" => $paymentPrice, "note" => $note, "orderNumber" => $orderNumber, "orderData" => $orderData, "waybillNumber" => $waybillNumber, "waybillDate" => $waybillDate, "receiptNumber" => $receiptNumber, "voucherDate" => $voucherDate, "voucherTime" => $voucherTime, "voucherType" => $voucherType, "zReportNumber" => $zReportNumber, "okcSerialNumber" => $okcSerialNumber ]; $inv->mapWithEnglishKeys($invoice_details); // Key yapısı ingilizce
您可以像这样进行映射,也可以单独使用getter/setter方法,您可以调整任何想要的数据。
$inv->setUuid("Buraya kendi fatura idniz") ->setCountry("Türkiye") ->getCurrencyRate(); // TRY
批量数据导入和导出
我们可以批量添加或删除发票数据中的变量值,如下所示。
$inv = new Invoice($data); // data arrayinden keylere göre tüm verileri alır. $inv->export(); // tüm verileri çıkartır.
🚩其他主题
执行测试
composer test
更多示例
您可以从这里找到更多示例。
警告
🚨 此包用于创建需缴税的文件,不承担任何责任。在您确信自己的行为之前,建议使用debugMode以测试数据运行。
此外
该项目基于Fatih Kadir Akın的fatura.js项目,并将其调整为PHP语言。同时感谢Arda Kılıçdağı。