cihansenturk/foribaapi

适配解决方案 efatura api。

1.0.0 2024-07-11 15:17 UTC

This package is auto-updated.

Last update: 2024-09-11 15:41:00 UTC


README

ProConnect Ünlem Bilişim Tanıtım

您可以使用ProConnect与您所需的集成器和系统协同工作。通过查看API 文档,在不更改构建的情况下开始使用您选择的集成器。

有关更多信息,请访问Ünlem Bilişim 网站。

Foriba 电子发票和电子归档 SDK

Foriba 电子发票和电子归档 PHP SDK。使用 PHP 发送电子归档和电子发票指南。

内容

安装

composer require unlembilisim/foribaapi:dev-master

或者

下载 ZIP 文件以开始使用。

require 'vendor/autoload.php';

将文件包含到您的系统中,以开始使用电子发票和电子归档服务。

需求

  • GuzzleHttp
  • ZipArchive
  • PHP 7.0 或更高版本。

电子发票

用于发送新一代电子发票的类;

use Bulut\FITApi\FITInvoiceService;
$service = new \Bulut\FITApi\FITInvoiceService(['username'=> 'WS_KULLANICIADI', 'password'=>'WS_SIFRE'], true);
// Son parametre, servis TEST ortamında ise true yapabilirsiniz veya boş bırakabilirsiniz

查询已注册用户电子发票

$userListRequest = new \Bulut\InvoiceService\GetUserList();
$userListRequest->setIdentifier("SORGULAYAN_PK");
$userListRequest->setVKNTCKN("SORGULAYAN_VKN_TCKN");
$userListRequest->setRole("PK/GB");
$userListRequest->setFilterVKNTCKN("SORGULANAN_VKN_TCKN");
$list = $service->GetUserListRequest($userListRequest);

将以列表形式返回已注册用户列表。有关函数的详细信息,请参阅 Foriba 网络服务文档。

查询电子发票收/发发票

$getUblRequest = new \Bulut\InvoiceService\GetUblList();
$getUblRequest->setIdentifier("SORGULAYAN_PK"); // veya GB
$getUblRequest->setVKNTCKN("SORGULAYAN_VKN_TCKN"); 
$getUblRequest->setDocType("INVOICE"); // veya ENVOLOPE
$getUblRequest->setType("INBOUND"); // veya OUTBOUND
$getUblRequest->setFromDate("yyyy-MM-dd");
$getUblRequest->setToDate(getSession("yyyy-MM-dd"));
$getUblRequest->setFromDateSpecified(true);
$getUblRequest->setToDateSpecified(true);
$list = $service->GetUblListRequest($getUblRequest);

用于列出收件箱中收到的发票的函数。有关函数参数的详细信息,请参阅 Foriba 电子发票文档。

电子发票,收/发发票 PDF 或 HTML 下载。

$getInvoiceRequest = new \Bulut\InvoiceService\GetInvoiceView();
$getInvoiceRequest->setUUID("FATURA_UUID");
$getInvoiceRequest->setIdentifier("SORGULAYAN_PK"); // veya GB
$getInvoiceRequest->setVKNTCKN("SORGULAYAN_VKN_TCKN"); // veya GB
$getInvoiceRequest->setType("INVOICE"); // ENVOLOPE
$getInvoiceRequest->setDocType("PDF"); // veya PDF, PDF_DEFAULT, HTML
$data = $service->GetInvoiceViewRequest($getInvoiceRequest);

提供所选发票的 PDF 或 HTML 输出的函数。有关参数的详细信息,请参阅 Foriba 电子发票文档。

电子发票收/发发票 UBL 下载。

$getUblRequest = new \Bulut\InvoiceService\GetUbl();
$getUblRequest->setIdentifier("SORGULAYAN_PK"); // veya GB
$getUblRequest->setVKNTCKN("SORGULAYAN_VKN_TCKN");
$getUblRequest->setDocType("INVOICE"); // veya ENVOLOPE
$getUblRequest->setType("UBL"); // UBL
$getUblRequest->setUUID("FATURA_UUID");
$getUblRequest->setParameters("DOC_DATA");
$data = $service->GetUblRequest($getUblRequest);

提供所选发票的 UBL 输出的函数。有关参数的详细信息,请参阅 Foriba 电子发票文档。

电子发票封套查询

$getEnvelopeRequest = new \Bulut\InvoiceService\GetEnvelopeStatus();
$getEnvelopeRequest->setIdentifier("SORGULAYAN_PK"); // veya GB
$getEnvelopeRequest->setVKNTCKN("SORGULAYAN_VKN_TCKN");
$getEnvelopeRequest->setUUID("ZARF_UUID");
$getEnvelopeRequest->setParameters("DOC_DATA"); // ek parametre
$data = $service->GetEnvelopeStatusRequest($getEnvelopeRequest);

用于查询所选封套的状态等详情的函数。有关详细信息,请参阅 foriba 文档。

电子发票应用响应 UBL 创建(示例)

$appResp = new \Bulut\eFaturaUBL\ApplicationResponse();
$appResp->UBLVersion = "2.1";
$appResp->CustomizationID = "TR1.2";
$appResp->ProfileID = "TICARIFATURA";
$appResp->ID = \Bulut\eFaturaUBL\XMLHelper::CreateGUID();
$appResp->UUID = $UUID;
$appResp->IssueDate = date('Y-m-d', strtotime($tarih));

// SenderParty
$senderParty = new \Bulut\eFaturaUBL\SenderParty();

$senderParty_Identification = new \Bulut\eFaturaUBL\PartyIdentification();
$senderParty_Identification->ID = ['val'=> "GONDERICI_TCKN_VKN", 'attrs' => ['schemaID="TCKN"']];
$senderParty->PartyIdentification = $senderParty_Identification;

$senderParty_Name = new \Bulut\eFaturaUBL\PartyName();
$senderParty_Name->Name = "Orhan Gazi Başlı";
$senderParty->PartyName = $senderParty_Name;

$senderParty_PostalAddress = new \Bulut\eFaturaUBL\PostalAddress();
$senderParty_PostalAddress->CitySubdivisionName = "Aşık Veysel";
$senderParty_PostalAddress->CityName = "Kayseri";

$senderParty_PostalAddress_Country = new \Bulut\eFaturaUBL\Country();
$senderParty_PostalAddress_Country->Name = "Türkiye";
$senderParty_PostalAddress->Country = $senderParty_PostalAddress_Country;
$senderParty->PostalAddress = $senderParty_PostalAddress;
$appResp->SenderParty = $senderParty;

// ReceiverParty
$receiverParty = new \Bulut\eFaturaUBL\SenderParty();

$receiverParty_Identification = new \Bulut\eFaturaUBL\PartyIdentification();
$receiverParty_Identification->ID = ['val'=> "ALICI_TCKN_VKN", 'attrs' => ['schemaID="TCKN"']];
$receiverParty->PartyIdentification = $receiverParty_Identification;

$receiverParty_Name = new \Bulut\eFaturaUBL\PartyName();
$receiverParty_Name->Name = "Orhan Gazi Başlı";
$receiverParty->PartyName = $receiverParty_Name;

$receiverParty_PostalAddress = new \Bulut\eFaturaUBL\PostalAddress();
$receiverParty_PostalAddress->CitySubdivisionName = "Aşık Veysel";
$receiverParty_PostalAddress->CityName = "Kayseri";

$receiverParty_PostalAddress_Country = new \Bulut\eFaturaUBL\Country();
$receiverParty_PostalAddress_Country->Name = "Türkiye";
$receiverParty_PostalAddress->Country = $receiverParty_PostalAddress_Country;
$receiverParty->PostalAddress = $receiverParty_PostalAddress;
$appResp->ReceiverParty= $receiverParty;



$documentResponse = new \Bulut\eFaturaUBL\DocumentResponse();

$documentResponse_Response = new \Bulut\eFaturaUBL\Response();
$documentResponse_Response->ReferenceID = "12345";
$documentResponse_Response->ResponseCode = "KABUL";
$documentResponse->Response = $documentResponse_Response;

$documentResponse_DocumentReference = new \Bulut\eFaturaUBL\DocumentReference();
$documentResponse_DocumentReference->ID = $UUID;
$documentResponse_DocumentReference->DocumentType = "FATURA";
$documentResponse_DocumentReference->DocumentTypeCode = "FATURA";
$documentResponse_DocumentReference->IssueDate = "BELGE_TARIHI"; // Y-m-d
$documentResponse->DocumentReference = $documentResponse_DocumentReference;

$appResp->DocumentResponse = $documentResponse;

$xmlHelper = new \Bulut\eFaturaUBL\XMLHelper($appResp);
$xml = $xmlHelper->getApplicationResponseXML();

这是一个示例电子发票 KABUL 应用响应。示例中使用的字段和名称根据 GIB 和 Foriba 标准创建。有关字段含义和结构的详细信息,请参阅 GIB 和 Foriba 文档。

需要注意的一点是,在 SDK 中,对于 xml 文件需要使用属性的地方,我们使用 ARRAY 作为属性使用,并显示为 key => value。例如:

['val'=> "ALICI_VEYA_GONDERICI_TCKN", 'attrs' => ['schemaID="TCKN"']]

在示例中,我们设置了收件人的 TCKN 值。对于企业示例;

 ['val'=> "ALICI_VEYA_GONDERICI_VKN", 'attrs' => ['schemaID="VKN"']]

attrs 参数设置为 ARRAY,可以添加多个属性。

有关字段的详细信息,请参阅 GIB 或 Foriba 文档。

电子发票 UBL 创建(示例)

$docRefences = [];

$uuid = \Bulut\eFaturaUBL\XMLHelper::CreateGUID();

$invoice = new \Bulut\eFaturaUBL\Invoice();
$invoice->UBLVersionID = "2.1"; //uluslararası fatura standardı 2.1
$invoice->CustomizationID = "TR1.2"; //fakat GİB UBLTR olarak isimlendirdiği Türkiye'ye özgü 1.2 efatura formatını kullanıyor.
$invoice->ProfileID = "TICARIFATURA"; //ticari ve temel olarak iki çeşittir. ticari faturalarda sistem yanıtı(application response) döner.
#$invoice->ID = "FIT2017000000021"; //Eğer fatura ID FIT tarafından oluşacak ise, ID alanı boş, CUST_INV_ID alanı dolu gelmelidir. Eğer kullanıcı firma tarafından oluşacak ise, ID alanı dolu CUST_INV_ID alanı boş olarak gönderilmeli.
$invoice->CopyIndicator = "false"; //kopyası mı, asıl süret mi olduğu belirlenir
$invoice->UUID = $uuid; //fatura UUID
$invoice->IssueDate = "FATURA_TARIHI"; //Y-m-d fatura tarihi
$invoice->InvoiceTypeCode = "SATIS"; //gönderilecek fatura çeşidi, satış, iade vs.
$invoice->Note = ["Test not"]; //isteğe bağlı not alanı
$invoice->DocumentCurrencyCode = "TRY"; //efatura para birimi
$invoice->LineCountNumeric = 1;  //fatura kalemlerinin sayısı

//Fatura ID otomatik oluşacak ise bu alanı göndermelisiniz.
$invoice_Document_Refence = new \Bulut\eFaturaUBL\DocumentReference();
$invoice_Document_Refence->ID = \Bulut\eFaturaUBL\XMLHelper::CreateGUID();
$invoice_Document_Refence->IssueDate = date('Y-m-d', strtotime($tarih));
$invoice_Document_Refence->DocumentTypeCode = "CUST_INV_ID";
$docRefences[] = $invoice_Document_Refence;


$invoice->AdditionalDocumentReference = $docRefences;

$invoice_AccountSupplierParty = new \Bulut\eFaturaUBL\AccountingSupplierParty();
$invoice_AccountSupplierParty_Party = new \Bulut\eFaturaUBL\Party();
$invoice_AccountSupplierParty_Party->WebsiteURI = "http://unlembilisim.com";

$invoice_AccountSupplierParty_Party_Identifi = new \Bulut\eFaturaUBL\PartyIdentification();
$invoice_AccountSupplierParty_Party_Identifi->ID = ['val'=> '12345678901', 'attrs' => ['schemeID="VKN"']];
$invoice_AccountSupplierParty_Party->PartyIdentification = $invoice_AccountSupplierParty_Party_Identifi;

$invoice_AccountSupplierParty_Party_Name = new \Bulut\eFaturaUBL\PartyName();
$invoice_AccountSupplierParty_Party_Name->Name = "Orhan Gazi Başlı";
$invoice_AccountSupplierParty_Party->PartyName = $invoice_AccountSupplierParty_Party_Name;

$invoice_AccountSupplierParty_Party_Person = new \Bulut\eFaturaUBL\Person();
$invoice_AccountSupplierParty_Party_Person->FirstName = "Orhan Gazi";
$invoice_AccountSupplierParty_Party_Person->FamilyName = "Başlı";
$invoice_AccountSupplierParty_Party->Person = $invoice_AccountSupplierParty_Party_Person;


$invoice_AccountSupplierParty_Party_PostalAdd = new \Bulut\eFaturaUBL\PostalAddress();
$invoice_AccountSupplierParty_Party_PostalAdd->Room = "kapi no";
$invoice_AccountSupplierParty_Party_PostalAdd->StreetName = "cadde";
$invoice_AccountSupplierParty_Party_PostalAdd->BuildingName = "bina";
$invoice_AccountSupplierParty_Party_PostalAdd->BuildingNumber = "bina no";
$invoice_AccountSupplierParty_Party_PostalAdd->CitySubdivisionName = "mahalle";
$invoice_AccountSupplierParty_Party_PostalAdd->CityName = "şehir";
$invoice_AccountSupplierParty_Party_PostalAdd->PostalZone = "posta kodu";
$invoice_AccountSupplierParty_Party_PostalAdd->Region = "asd";

$invoice_AccountSupplierParty_Party_PostalAdd_Country = new \Bulut\eFaturaUBL\Country();
$invoice_AccountSupplierParty_Party_PostalAdd_Country->Name = "Türkiye";

$invoice_AccountSupplierParty_Party_PostalAdd->Country = $invoice_AccountSupplierParty_Party_PostalAdd_Country;
$invoice_AccountSupplierParty_Party->PostalAddress = $invoice_AccountSupplierParty_Party_PostalAdd;

$invoice_AccountSupplierParty_Party_TaxSchema = new \Bulut\eFaturaUBL\PartyTaxScheme();
$invoice_AccountSupplierParty_Party_TaxSchema_Schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_AccountSupplierParty_Party_TaxSchema_Schema->Name = "erciyes";
$invoice_AccountSupplierParty_Party_TaxSchema->TaxScheme = $invoice_AccountSupplierParty_Party_TaxSchema_Schema;
$invoice_AccountSupplierParty_Party->PartyTaxScheme = $invoice_AccountSupplierParty_Party_TaxSchema;

$invoice_AccountSupplierParty_Party_Contact = new \Bulut\eFaturaUBL\Contact();
$invoice_AccountSupplierParty_Party_Contact->Telephone = "telef";
$invoice_AccountSupplierParty_Party_Contact->Telefax = "Telefax";
$invoice_AccountSupplierParty_Party_Contact->ElectronicMail = "ElectronicMail";
$invoice_AccountSupplierParty_Party->Contact = $invoice_AccountSupplierParty_Party_Contact;

$invoice_AccountSupplierParty->Party = $invoice_AccountSupplierParty_Party;

$invoice->AccountingSupplierParty = $invoice_AccountSupplierParty;


//Customer

$invoice_AccountCustomerParty = new \Bulut\eFaturaUBL\AccountingCustomerParty();
$invoice_AccountCustomerParty_Party = new \Bulut\eFaturaUBL\Party();
$invoice_AccountCustomerParty_Party->WebsiteURI = "http://unlembilisim.com";

$invoice_AccountCustomerParty_Party_Identifi = new \Bulut\eFaturaUBL\PartyIdentification();
$invoice_AccountCustomerParty_Party_Identifi->ID = ['val'=> "12345678901", 'attrs' => ['schemeID="VKN"']];
$invoice_AccountCustomerParty_Party->PartyIdentification = $invoice_AccountCustomerParty_Party_Identifi;

$invoice_AccountCustomerParty_Party_Name = new \Bulut\eFaturaUBL\PartyName();
$invoice_AccountCustomerParty_Party_Name->Name = "GIB";
$invoice_AccountCustomerParty_Party->PartyName = $invoice_AccountCustomerParty_Party_Name;

$invoice_AccountCustomerParty_Party_PostalAdd = new \Bulut\eFaturaUBL\PostalAddress();
$invoice_AccountCustomerParty_Party_PostalAdd->Room = "kapi no";
$invoice_AccountCustomerParty_Party_PostalAdd->StreetName = "cadde";
$invoice_AccountCustomerParty_Party_PostalAdd->BuildingName = "bina";
$invoice_AccountCustomerParty_Party_PostalAdd->BuildingNumber = "bina no";
$invoice_AccountCustomerParty_Party_PostalAdd->CitySubdivisionName = "mahalle";
$invoice_AccountCustomerParty_Party_PostalAdd->CityName = "şehir";
$invoice_AccountCustomerParty_Party_PostalAdd->PostalZone = "posta kodu";
$invoice_AccountCustomerParty_Party_PostalAdd->Region = "asd";

$invoice_AccountCustomerParty_Party_PostalAdd_Country = new \Bulut\eFaturaUBL\Country();
$invoice_AccountCustomerParty_Party_PostalAdd_Country->Name = "Türkiye";

$invoice_AccountCustomerParty_Party_PostalAdd->Country = $invoice_AccountCustomerParty_Party_PostalAdd_Country;
$invoice_AccountCustomerParty_Party->PostalAddress = $invoice_AccountCustomerParty_Party_PostalAdd;

$invoice_AccountCustomerParty_Party_TaxSchema = new \Bulut\eFaturaUBL\PartyTaxScheme();
$invoice_AccountCustomerParty_Party_TaxSchema_Schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_AccountCustomerParty_Party_TaxSchema_Schema->Name = "erciyes";
$invoice_AccountCustomerParty_Party_TaxSchema->TaxScheme = $invoice_AccountCustomerParty_Party_TaxSchema_Schema;
$invoice_AccountCustomerParty_Party->PartyTaxScheme = $invoice_AccountCustomerParty_Party_TaxSchema;

$invoice_AccountCustomerParty_Party_Contact = new \Bulut\eFaturaUBL\Contact();
$invoice_AccountCustomerParty_Party_Contact->Telephone = "telef";
$invoice_AccountCustomerParty_Party_Contact->Telefax = "Telefax";
$invoice_AccountCustomerParty_Party_Contact->ElectronicMail = "ElectronicMail";
$invoice_AccountCustomerParty_Party->Contact = $invoice_AccountCustomerParty_Party_Contact;

$invoice_AccountCustomerParty->Party = $invoice_AccountCustomerParty_Party;

$invoice->AccountingCustomerParty= $invoice_AccountCustomerParty;

$invoice_Allowence = new \Bulut\eFaturaUBL\AllowanceCharge();
$invoice_Allowence->ChargeIndicator = "false";
$invoice_Allowence->Amount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];
$invoice->AllowanceCharge = $invoice_Allowence;

$invoice_TaxTotal = new \Bulut\eFaturaUBL\TaxTotal();
$invoice_TaxTotal->TaxAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];

$invoice_TaxTotal_SubTotal = new \Bulut\eFaturaUBL\TaxSubtotal();
$invoice_TaxTotal_SubTotal->TaxableAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];
$invoice_TaxTotal_SubTotal->TaxAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];

$invoice_TaxTotal_SubTotal_Category = new \Bulut\eFaturaUBL\TaxCategory();
$invoice_TaxTotal_SubTotal_Category_Schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_TaxTotal_SubTotal_Category_Schema->Name = "KDV";
$invoice_TaxTotal_SubTotal_Category_Schema->TaxTypeCode = "0015";

$invoice_TaxTotal_SubTotal_Category->TaxScheme = $invoice_TaxTotal_SubTotal_Category_Schema;
$invoice_TaxTotal_SubTotal->TaxCategory = $invoice_TaxTotal_SubTotal_Category;
$invoice_TaxTotal->TaxSubtotal = $invoice_TaxTotal_SubTotal;

$invoice->TaxTotal = $invoice_TaxTotal;

$invoice_LegalMonetary = new \Bulut\eFaturaUBL\LegalMonetaryTotal();
$invoice_LegalMonetary->LineExtensionAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->TaxExclusiveAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->TaxInclusiveAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->AllowanceTotalAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->PayableAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];

$invoice->LegalMonetaryTotal = $invoice_LegalMonetary;

$invoice_line = new \Bulut\eFaturaUBL\InvoiceLine();
$invoice_line->ID = "1";
$invoice_line->InvoicedQuantity = ["val" => "1", 'attrs' => ['unitCode="CMT"']];
$invoice_line->LineExtensionAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];

$invoice_line_allowence = new \Bulut\eFaturaUBL\AllowanceCharge();
$invoice_line_allowence->ChargeIndicator = "false";
$invoice_line_allowence->MultiplierFactorNumeric = "0.01";
$invoice_line_allowence->Amount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];
$invoice_line_allowence->BaseAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_line->AllowanceCharge = $invoice_line_allowence;

$invoice_line_taxtotal = new \Bulut\eFaturaUBL\TaxTotal();
$invoice_line_taxtotal->TaxAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];;

$invoice_line_taxtotal_sub = new \Bulut\eFaturaUBL\TaxSubtotal();
$invoice_line_taxtotal_sub->TaxableAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];
$invoice_line_taxtotal_sub->TaxAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];
$invoice_line_taxtotal_sub->Percent = "18";

$invoice_line_taxtotal_sub_category = new \Bulut\eFaturaUBL\TaxCategory();
$invoice_line_taxtotal_sub_category_schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_line_taxtotal_sub_category_schema->Name = "KDV";
$invoice_line_taxtotal_sub_category_schema->TaxTypeCode = "0015";

$invoice_line_taxtotal_sub_category->TaxScheme = $invoice_line_taxtotal_sub_category_schema;
$invoice_line_taxtotal_sub->TaxCategory = $invoice_line_taxtotal_sub_category;

$invoice_line_taxtotal->TaxSubtotal = $invoice_line_taxtotal_sub;
$invoice_line->TaxTotal = $invoice_line_taxtotal;


$invoice_line_item = new \Bulut\eFaturaUBL\Item();
$invoice_line_item->Name = "Test Ürün";
$invoice_line->Item = $invoice_line_item;

$invoice_line_price = new \Bulut\eFaturaUBL\Price();
$invoice_line_price->PriceAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_line->Price = $invoice_line_price;

$invoice->InvoiceLine = [$invoice_line];

$xml = new \Bulut\eFaturaUBL\XMLHelper($invoice);

这是一个示例电子发票,我们将其创建并传递给 Foriba 服务以完成开票。需要注意的要点是,发票 UUID 和 XML 以 UUID 输出,您可以使用 UUID 跟踪发票,并将生成的 XML 传递给 Foriba 系统。有关字段细节,请参阅 GIB 和 Foriba 文档。

电子发票发送

$destination = 'temp/'.$uuid.'.zip';
    $zip = new ZipArchive();
    if($zip->open($destination,ZIPARCHIVE::CREATE) !== true) {
        return false;
    }

    $zip->addFromString($uuid.'.xml', $xml);
    $zip->close();


    $sendUblRequest = new \Bulut\InvoiceService\SendUBL();
    $sendUblRequest->setVKNTCKN("GONDERICI_VKN_TCKN");
    $sendUblRequest->setDocType("INVOICE"); // veya APP_RESP
    $sendUblRequest->setReceiverIdentifier("ALICI_PK");
    $sendUblRequest->setSenderIdentifier("GONDERICI_GB");
    $sendUblRequest->setDocData(base64_encode(file_get_contents($destination)));
    unlink($destination);

    $result = $service->SendUBLRequest($sendUblRequest);

这是我们用于将上面创建的 XML (UBL) 作为最终场景发送到 Foriba 服务的函数。这里需要注意的要点是,创建 ZIP 文件,确保创建的 ZIP 文件和发票 UUID 相同,并将 ZIP 文件 BASE64 编码后发送给 Foriba,并接收响应。

总的来说,我们需要通过查阅 Foriba 和 GIB 文档来注意,那里使用的名称和类与我们的一致。您可以通过创建 UBL 并获取响应来进行测试。

电子归档发票

电子档案账单与电子账单之间的区别在于,电子账单为非电子账单纳税人提供了一种通过电子或纸质方式输出结果的方法。

为了使用,我们需要启动服务类;

use \Bulut\FITApi\FITArchiveService;
$service = new \Bulut\FITApi\FITArchiveService(['username'=>'EARSIV_WS_Kullanici', 'password'=>'EARSIV_WS_Sifre'], true);

创建对象时,如果最后一个参数设置为true,则进入测试环境,如果不设置,则在实时环境中运行。

创建电子归档发票

 $docRefences = [];

$uuid = \Bulut\eFaturaUBL\XMLHelper::CreateGUID();

$invoice = new \Bulut\eFaturaUBL\Invoice();
$invoice->UBLVersionID = "2.1"; //uluslararası fatura standardı 2.1
$invoice->CustomizationID = "TR1.2"; //fakat GİB UBLTR olarak isimlendirdiği Türkiye'ye özgü 1.2 efatura formatını kullanıyor.
$invoice->ProfileID = "EARSIVFATURA"; //ticari ve temel olarak iki çeşittir. ticari faturalarda sistem yanıtı(application response) döner.
$invoice->ID = "FA02017000000021"; //Eğer fatura ID FIT tarafından oluşacak ise, ID alanı boş, CUST_INV_ID alanı dolu gelmelidir. Eğer kullanıcı firma tarafından oluşacak ise, ID alanı dolu CUST_INV_ID alanı boş olarak gönderilmeli.
$invoice->CopyIndicator = "false"; //kopyası mı, asıl süret mi olduğu belirlenir
$invoice->UUID = $uuid; //fatura UUID
$invoice->IssueDate = "Y-m-d"; //fatura tarihi
$invoice->IssueTime = date('H:i:s');
$invoice->InvoiceTypeCode = "SATIS"; //gönderilecek fatura çeşidi, satış, iade vs.
$invoice->DocumentCurrencyCode = "TRY"; //efatura para birimi
$invoice->LineCountNumeric = 1;  //fatura kalemlerinin sayısı
#$invoice->Note = ["Test not"]; //isteğe bağlı not alanı

//Fatura ID otomatik oluşacak ise bu alanı göndermelisiniz.
$invoice_Document_Refence = new \Bulut\eFaturaUBL\DocumentReference();
$invoice_Document_Refence->ID = \Bulut\eFaturaUBL\XMLHelper::CreateGUID();
$invoice_Document_Refence->IssueDate = "Y-m-d";
$invoice_Document_Refence->DocumentTypeCode = "CUST_INV_ID";
$docRefences[] = $invoice_Document_Refence;


//OUTPUT_TYPE
$invoice_Document_Refence1 = new \Bulut\eFaturaUBL\DocumentReference();
$invoice_Document_Refence1->ID = "0100";
$invoice_Document_Refence1->IssueDate = date('Y-m-d');
$invoice_Document_Refence1->DocumentTypeCode = "OUTPUT_TYPE";
$docRefences[] = $invoice_Document_Refence1;


//EREPSENDT
$invoice_Document_Refence2 = new \Bulut\eFaturaUBL\DocumentReference();
$invoice_Document_Refence2->ID = "KAGIT";
$invoice_Document_Refence2->IssueDate = date('Y-m-d');
$invoice_Document_Refence2->DocumentTypeCode = "EREPSENDT";
$docRefences[] = $invoice_Document_Refence2;


$invoice->AdditionalDocumentReference = $docRefences;

$invoice_signature = new \Bulut\eFaturaUBL\Signature();
$invoice_signature->ID = ['val' => "ALICI_VKN_TCKN", 'attrs' => ['schemeID = "VKN_TCKN"']];

$invoice_signature_party = new \Bulut\eFaturaUBL\SignatoryParty();

$invoice__signature_party_ident = new \Bulut\eFaturaUBL\PartyIdentification();
$invoice__signature_party_ident->ID = ['val' => "ALICI_VKN_TCKN", 'attrs' => ['schemeID = "VKN"']];
$invoice_signature_party->PartyIdentification = $invoice__signature_party_ident;

$invoice__signature_party_postal = new \Bulut\eFaturaUBL\PostalAddress();
$invoice__signature_party_postal->StreetName = "deneme cad";
$invoice__signature_party_postal->BuildingName = "01";
$invoice__signature_party_postal->CitySubdivisionName = "ilce";
$invoice__signature_party_postal->CityName = "il";
$invoice__signature_party_postal->PostalZone = "34000";

$invoice__signature_party_postal_country = new \Bulut\eFaturaUBL\Country();
$invoice__signature_party_postal_country->Name = "TÜRKİYE";
$invoice__signature_party_postal->Country = $invoice__signature_party_postal_country;

$invoice_signature_party->PostalAddress = $invoice__signature_party_postal;
$invoice_signature->SignatoryParty = $invoice_signature_party;

$invoice_signature_digital = new \Bulut\eFaturaUBL\DigitalSignatureAttachment();
$invoice_signature_digital_ext = new \Bulut\eFaturaUBL\ExternalReference();
$invoice_signature_digital_ext->URI = "#Signature";
$invoice_signature_digital->ExternalReference = $invoice_signature_digital_ext;

$invoice_signature->DigitalSignatureAttachment = $invoice_signature_digital;

$invoice->Signature = $invoice_signature;



$invoice_AccountSupplierParty = new \Bulut\eFaturaUBL\AccountingSupplierParty();
$invoice_AccountSupplierParty_Party = new \Bulut\eFaturaUBL\Party();
$invoice_AccountSupplierParty_Party->WebsiteURI = "http://unlembilisim.com";

$invoice_AccountSupplierParty_Party_Identifi = new \Bulut\eFaturaUBL\PartyIdentification();
$invoice_AccountSupplierParty_Party_Identifi->ID = ['val'=> "GONDERICI_VKN_TCKN", 'attrs' => ['schemeID="TCKN"']];
$invoice_AccountSupplierParty_Party->PartyIdentification = $invoice_AccountSupplierParty_Party_Identifi;

$invoice_AccountSupplierParty_Party_Name = new \Bulut\eFaturaUBL\PartyName();
$invoice_AccountSupplierParty_Party_Name->Name = "Orhan Gazi Başlı";
$invoice_AccountSupplierParty_Party->PartyName = $invoice_AccountSupplierParty_Party_Name;

$invoice_AccountSupplierParty_Party_Person = new \Bulut\eFaturaUBL\Person();
$invoice_AccountSupplierParty_Party_Person->FirstName = "Orhan Gazi";
$invoice_AccountSupplierParty_Party_Person->FamilyName = "Başlı";
$invoice_AccountSupplierParty_Party->Person = $invoice_AccountSupplierParty_Party_Person;


$invoice_AccountSupplierParty_Party_PostalAdd = new \Bulut\eFaturaUBL\PostalAddress();
$invoice_AccountSupplierParty_Party_PostalAdd->Room = "kapi no";
$invoice_AccountSupplierParty_Party_PostalAdd->StreetName = "cadde";
$invoice_AccountSupplierParty_Party_PostalAdd->BuildingName = "bina";
$invoice_AccountSupplierParty_Party_PostalAdd->BuildingNumber = "bina no";
$invoice_AccountSupplierParty_Party_PostalAdd->CitySubdivisionName = "mahalle";
$invoice_AccountSupplierParty_Party_PostalAdd->CityName = "şehir";
$invoice_AccountSupplierParty_Party_PostalAdd->PostalZone = "posta kodu";
$invoice_AccountSupplierParty_Party_PostalAdd->Region = "asd";

$invoice_AccountSupplierParty_Party_PostalAdd_Country = new \Bulut\eFaturaUBL\Country();
$invoice_AccountSupplierParty_Party_PostalAdd_Country->Name = "Türkiye";

$invoice_AccountSupplierParty_Party_PostalAdd->Country = $invoice_AccountSupplierParty_Party_PostalAdd_Country;
$invoice_AccountSupplierParty_Party->PostalAddress = $invoice_AccountSupplierParty_Party_PostalAdd;

$invoice_AccountSupplierParty_Party_TaxSchema = new \Bulut\eFaturaUBL\PartyTaxScheme();
$invoice_AccountSupplierParty_Party_TaxSchema_Schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_AccountSupplierParty_Party_TaxSchema_Schema->Name = "erciyes";
$invoice_AccountSupplierParty_Party_TaxSchema->TaxScheme = $invoice_AccountSupplierParty_Party_TaxSchema_Schema;
$invoice_AccountSupplierParty_Party->PartyTaxScheme = $invoice_AccountSupplierParty_Party_TaxSchema;

$invoice_AccountSupplierParty_Party_Contact = new \Bulut\eFaturaUBL\Contact();
$invoice_AccountSupplierParty_Party_Contact->Telephone = "telef";
$invoice_AccountSupplierParty_Party_Contact->Telefax = "Telefax";
$invoice_AccountSupplierParty_Party_Contact->ElectronicMail = "ElectronicMail";
$invoice_AccountSupplierParty_Party->Contact = $invoice_AccountSupplierParty_Party_Contact;

$invoice_AccountSupplierParty->Party = $invoice_AccountSupplierParty_Party;

$invoice->AccountingSupplierParty = $invoice_AccountSupplierParty;


//Customer

$invoice_AccountCustomerParty = new \Bulut\eFaturaUBL\AccountingCustomerParty();
$invoice_AccountCustomerParty_Party = new \Bulut\eFaturaUBL\Party();
$invoice_AccountCustomerParty_Party->WebsiteURI = "http://unlembilisim.com";

$invoice_AccountCustomerParty_Party_Identifi = new \Bulut\eFaturaUBL\PartyIdentification();
$invoice_AccountCustomerParty_Party_Identifi->ID = ['val'=> $aliciVkn, 'attrs' => ['schemeID="TCKN"']];
$invoice_AccountCustomerParty_Party->PartyIdentification = $invoice_AccountCustomerParty_Party_Identifi;

$invoice_AccountCustomerParty_Party_Name = new \Bulut\eFaturaUBL\PartyName();
$invoice_AccountCustomerParty_Party_Name->Name = "GIB";
$invoice_AccountCustomerParty_Party->PartyName = $invoice_AccountCustomerParty_Party_Name;

$invoice_AccountCustomerParty_Party_Person = new \Bulut\eFaturaUBL\Person();
$invoice_AccountCustomerParty_Party_Person->FirstName = "Test";
$invoice_AccountCustomerParty_Party_Person->FamilyName = "Test";
$invoice_AccountCustomerParty_Party->Person = $invoice_AccountCustomerParty_Party_Person;



$invoice_AccountCustomerParty_Party_PostalAdd = new \Bulut\eFaturaUBL\PostalAddress();
$invoice_AccountCustomerParty_Party_PostalAdd->Room = "kapi no";
$invoice_AccountCustomerParty_Party_PostalAdd->StreetName = "cadde";
$invoice_AccountCustomerParty_Party_PostalAdd->BuildingName = "bina";
$invoice_AccountCustomerParty_Party_PostalAdd->BuildingNumber = "bina no";
$invoice_AccountCustomerParty_Party_PostalAdd->CitySubdivisionName = "mahalle";
$invoice_AccountCustomerParty_Party_PostalAdd->CityName = "şehir";
$invoice_AccountCustomerParty_Party_PostalAdd->PostalZone = "posta kodu";
$invoice_AccountCustomerParty_Party_PostalAdd->Region = "asd";

$invoice_AccountCustomerParty_Party_PostalAdd_Country = new \Bulut\eFaturaUBL\Country();
$invoice_AccountCustomerParty_Party_PostalAdd_Country->Name = "Türkiye";

$invoice_AccountCustomerParty_Party_PostalAdd->Country = $invoice_AccountCustomerParty_Party_PostalAdd_Country;
$invoice_AccountCustomerParty_Party->PostalAddress = $invoice_AccountCustomerParty_Party_PostalAdd;

$invoice_AccountCustomerParty_Party_TaxSchema = new \Bulut\eFaturaUBL\PartyTaxScheme();
$invoice_AccountCustomerParty_Party_TaxSchema_Schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_AccountCustomerParty_Party_TaxSchema_Schema->Name = "erciyes";
$invoice_AccountCustomerParty_Party_TaxSchema->TaxScheme = $invoice_AccountCustomerParty_Party_TaxSchema_Schema;
$invoice_AccountCustomerParty_Party->PartyTaxScheme = $invoice_AccountCustomerParty_Party_TaxSchema;

$invoice_AccountCustomerParty_Party_Contact = new \Bulut\eFaturaUBL\Contact();
$invoice_AccountCustomerParty_Party_Contact->Telephone = "telef";
$invoice_AccountCustomerParty_Party_Contact->Telefax = "Telefax";
$invoice_AccountCustomerParty_Party_Contact->ElectronicMail = "ElectronicMail";
$invoice_AccountCustomerParty_Party->Contact = $invoice_AccountCustomerParty_Party_Contact;

$invoice_AccountCustomerParty->Party = $invoice_AccountCustomerParty_Party;

$invoice->AccountingCustomerParty= $invoice_AccountCustomerParty;

$invoice_TaxTotal = new \Bulut\eFaturaUBL\TaxTotal();
$invoice_TaxTotal->TaxAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];

$invoice_TaxTotal_SubTotal = new \Bulut\eFaturaUBL\TaxSubtotal();
$invoice_TaxTotal_SubTotal->TaxableAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];
$invoice_TaxTotal_SubTotal->TaxAmount = ["val" => "0.01", 'attrs' => ['currencyID="TRY"']];

$invoice_TaxTotal_SubTotal_Category = new \Bulut\eFaturaUBL\TaxCategory();
$invoice_TaxTotal_SubTotal_Category_Schema = new \Bulut\eFaturaUBL\TaxScheme();
$invoice_TaxTotal_SubTotal_Category_Schema->Name = "KDV";
$invoice_TaxTotal_SubTotal_Category_Schema->TaxTypeCode = "0015";

$invoice_TaxTotal_SubTotal_Category->TaxScheme = $invoice_TaxTotal_SubTotal_Category_Schema;
$invoice_TaxTotal_SubTotal->TaxCategory = $invoice_TaxTotal_SubTotal_Category;
$invoice_TaxTotal->TaxSubtotal = $invoice_TaxTotal_SubTotal;

$invoice->TaxTotal = $invoice_TaxTotal;

$invoice_LegalMonetary = new \Bulut\eFaturaUBL\LegalMonetaryTotal();
$invoice_LegalMonetary->LineExtensionAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->TaxExclusiveAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->TaxInclusiveAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_LegalMonetary->PayableAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];

$invoice->LegalMonetaryTotal = $invoice_LegalMonetary;

$invoice_line = new \Bulut\eFaturaUBL\InvoiceLine();
$invoice_line->ID = "1";
$invoice_line->InvoicedQuantity = ["val" => "1", 'attrs' => ['unitCode="CMT"']];
$invoice_line->LineExtensionAmount = ["val" => "0.99", 'attrs' => ['currencyID="TRY"']];


$invoice_line_item = new \Bulut\eFaturaUBL\Item();
$invoice_line_item->Name = "Test Ürün";
$invoice_line->Item = $invoice_line_item;

$invoice_line_price = new \Bulut\eFaturaUBL\Price();
$invoice_line_price->PriceAmount = ["val" => "1", 'attrs' => ['currencyID="TRY"']];
$invoice_line->Price = $invoice_line_price;

$invoice->InvoiceLine = [$invoice_line];

$xml = new \Bulut\eFaturaUBL\XMLHelper($invoice);

有关用于创建示例电子档案账单的参数和变量的说明,请参阅Foriba电子档案文档或GIB文档。

发送电子归档发票

    $destination = 'temp/'.$rand.'.zip';
    $rand = rand(1000,9999);
    $zip = new ZipArchive();
    if($zip->open($destination,ZIPARCHIVE::CREATE) !== true) {
        return false;
    }

    $zip->addFromString($uuid.'.xml', $xml);
    $zip->close();

    $sendUblRequest = new \Bulut\ArchiveService\SendInvoice();
    $sendUblRequest->setSenderID("GONDERICI_VKN_TCKN");
    $sendUblRequest->setHash(md5_file($destination));
    $sendUblRequest->setFileName($rand.'.zip');
    $sendUblRequest->setDocType("XML");
    $sendUblRequest->setBinaryData(base64_encode(file_get_contents($destination)));

    $custParam = new \Bulut\ArchiveService\CustomizationParam();
    $custParam->paramName = "BRANCH";
    $custParam->paramValue = "default";
    $sendUblRequest->setCustomizationParams([$custParam]);

    $respOut = new \Bulut\ArchiveService\responsiveOutput();
    $respOut->outputType = "PDF";
    $sendUblRequest->setResponsiveOutput($respOut);



    $result = $service->SendInvoiceRequest($sendUblRequest);

这是我们用于将创建的电子档案XML发送到Foriba系统的函数。

发送电子归档封套

$destination = 'temp/'.$rand.'.zip';
	$rand = rand(1000,9999);
    $zip = new ZipArchive();
    if($zip->open($destination,ZIPARCHIVE::CREATE) !== true) {
        return false;
    }

    $zip->addFromString($uuid.'.xml', $xml);
    $zip->close();


    $sendUblRequest = new \Bulut\ArchiveService\SendEnvelope();
    $sendUblRequest->setSenderID("GONDERICI_VKN_TCKN");
    $sendUblRequest->setHash(md5_file($destination));
    $sendUblRequest->setFileName($rand.'.zip');
    $sendUblRequest->setDocType("XML");
    $sendUblRequest->setBinaryData(base64_encode(file_get_contents($destination)));

    $custParam = new \Bulut\ArchiveService\CustomizationParam();
    $custParam->paramName = "BRANCH";
    $custParam->paramValue = "default";
    $sendUblRequest->setCustomizationParams([$custParam]);

    $result = $service->SendEnvelopeRequest($sendUblRequest);

有关详细信息,请参阅Foriba电子档案文档。

取消电子归档发票

$getDocument = new \Bulut\ArchiveService\InvoiceCancelInfoTypeList();

$getDocument->setInvoiceId("INVOICE_NUMBER");
$getDocument->setVkn("GONDERICI_VKN");
$getDocument->setBranch("GONDEREN_SUBE");
$getDocument->setTotalAmount("FATURA_TUTARI");
$getDocument->setCancelDate("Y-m-d");
$getDocument->setCustInvID("CUST_INV_ID");

$cancelService = new \Bulut\ArchiveService\CancelInvoice();
$cancelService->setInvoiceCancelInfoTypeList([$getDocument]);
$resutl = $service->CancelInvoiceRequest($cancelService);

通过填写必要字段,我们可以取消账单。您可以检查变量从Foriba文档中。

重新触发电子归档发票

$getDocument = new \Bulut\ArchiveService\RetriggerOperation();
$getDocument->setVKN("GONDERICI_VKN_TCKN");
$getDocument->setBranch("GONDERICI_SUBE");
$getDocument->setInvoiceID("FATURA_NUMARASI");
$getDocument->setInvoiceUUID("FATURA_UUID");

$cust = [];
$customParams = [];
foreach($customParams as $key => $val){
    $name = $val;
    if($name != ""){
        $custObj = new \Bulut\ArchiveService\CustomizationParam();
        $custObj->paramName = $name;
        $custObj->paramValue = $_POST['paramValue'][$key];
        $cust[] = $custObj;
    }
}
$getDocument->setCustomizationParams($cust);
$result = $service->GetRetriggerOperationRequest($getDocument);

要再次发送已发送的账单,请参阅Foriba文档中的CustomParameters函数。

电子归档已注册用户列表

$getDocument = new \Bulut\ArchiveService\GetUserList();
$getDocument->setVknTckn("GONDERICI_VKN_TCKN");
$result = $service->GetUserListRequest($getDocument);

以ZIP格式返回已注册用户列表。

下载电子归档发票查看

$getDocument = new \Bulut\ArchiveService\GetInvoiceDocument();
$getDocument->setUUID("FATURA_UUID");
$getDocument->setVkn("GONDERICI_VKN");
$getDocument->setInvoiceNumber("FATURA_NUMARASI");
$getDocument->setCustInvId("CUST_INV_ID");
$getDocument->setOutputType("CIKTI_TURU"); //xml, UBL

$result = $service->GetInvoiceDocumentRequest($getDocument);

通过调用此函数,您可以下载您已发送的账单的图像。

电子归档发票签名

$getDocument = new \Bulut\ArchiveService\GetSignedInvoice();
$getDocument->setUUID("FATURA_UUID");
$getDocument->setVkn("GONDERICI_VKN");
$getDocument->setInvoiceNumber("FATURA_NUMARASI");
$getDocument->setCustInvId("CUST_INV_ID");

$resutl = $service->GetSignedInvoiceRequest($getDocument);

通过调用此函数,您可以完成签名操作。

SDK中使用的所有函数和变量名称都适用于Foriba和GIB系统。通过检查Foriba和GIB文档,您可以轻松实现集成。

注意:此存储库不是官方的Sovos SDK存储库。

如果您遇到问题,可以联系Foriba或我。