1. Go to this page and download the library: Download l2ernestoo/facturalesgt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
l2ernestoo / facturalesgt example snippets
use Lc\Fel\Models\FelBranchSetting;
use Lc\Fel\Models\FelCompany;
use Lc\Fel\Models\FelCompanyCredential;
$company = FelCompany::create([
'name' => 'Mi Empresa, S.A.',
'nit' => '1234567',
'regime' => 'general', // general, pequeno_contribuyente, etc.
'certifier' => 'guatefacturas',
'mode' => 'test', // test o prod
'default_document_type' => 'FACT',
'show_pos_switch' => true,
'auto_mark_pos_switch' => true,
'monthly_dte_limit' => 1000,
]);
FelCompanyCredential::create([
'fel_company_id' => $company->id,
'user' => 'USUARIO_FEL',
'password' => 'PASSWORD_FEL',
'basic_user' => 'BASIC_USER',
'basic_password' => 'BASIC_PASSWORD',
'url_test' => 'https://dte.guatefacturas.com/webservices63/feltestSB/Guatefac',
'url_prod' => 'https://dte.guatefacturas.com/webservices63/fel/Guatefac',
'machine_id' => '1',
]);
FelBranchSetting::create([
'fel_company_id' => $company->id,
'branch_source_id' => 1, // ID de la sucursal en tu app
'fiscal_name' => 'Sucursal Principal',
'address' => 'Ciudad',
'establishment_code' => '1',
'is_active' => true,
]);
namespace App\Services\Fel;
use App\Models\Order;
use Lc\Fel\Contracts\FelSourceMapperInterface;
use Lc\Fel\Data\FelBranchData;
use Lc\Fel\Data\FelCompanyData;
use Lc\Fel\Data\FelDocumentData;
use Lc\Fel\Data\FelItemData;
use Lc\Fel\Data\FelReceiverData;
use Lc\Fel\Repositories\DatabaseFelConfigRepository;
class OrderFelMapper implements FelSourceMapperInterface
{
public function __construct(
private readonly DatabaseFelConfigRepository $config,
) {
}
public function map(mixed $source, array $options = []): FelDocumentData
{
/** @var Order $source */
$company = $this->config->company($options['company_id'] ?? null);
$branch = $this->config->branchSetting($source->branch_id, $company?->id);
return new FelDocumentData(
documentType: $options['document_type'] ?? $company->default_document_type,
reference: 'ORD-' . $source->id,
date: now(),
company: new FelCompanyData(
id: $company->id,
name: $company->name,
nit: $company->nit,
regime: $company->regime,
certifier: $company->certifier,
mode: $company->mode,
monthlyDteLimit: $company->monthly_dte_limit,
),
branch: new FelBranchData(
id: $branch->id,
sourceBranchId: $branch->branch_source_id,
companyId: $company->id,
name: $branch->fiscal_name,
address: $branch->address,
establishmentCode: $branch->establishment_code,
logoPath: $branch->logo_path,
),
receiver: new FelReceiverData(
nit: $options['nit'] ?? 'CF',
name: $options['name'] ?? 'Consumidor Final',
address: $options['address'] ?? 'Ciudad',
),
items: $source->items->map(fn ($item) => new FelItemData(
code: (string) $item->product_id,
description: $item->product->name,
quantity: (float) $item->quantity,
unitPrice: (float) $item->price,
measure: '1',
discount: 0,
metadata: ['source_item_id' => $item->id],
))->all(),
total: (float) $source->total,
sourceType: Order::class,
sourceId: $source->id,
options: $options,
);
}
}