Invoice Issuance Setup in 1C-Bitrix
An invoice is a document issued to a buyer (individual or legal entity) that contains payment details. In the B2B segment this is a mandatory step: the counterparty's accounting department must receive the invoice, approve it, and pay by bank transfer. In Bitrix, invoice issuance is a separate piece of functionality that can be implemented via the CRM module (Bitrix24), via custom site components, or through 1C integration.
Invoice from the Order Admin Page
The simplest option — generating an invoice based on an existing order. Add an "Issue Invoice" button to the order card:
// /bitrix/admin/sale_order_invoice.php
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_before.php';
\Bitrix\Main\Loader::includeModule('sale');
$orderId = (int)$_GET['ORDER_ID'];
$order = \Bitrix\Sale\Order::load($orderId);
if ($_POST['generate']) {
$generator = new InvoiceGenerator();
$pdfPath = $generator->generate($order);
// Send email with PDF
$mailer = new InvoiceMailer();
$mailer->send($order, $pdfPath);
// Save the invoice issuance fact to the order property
$order->setField('INVOICE_DATE', date('d.m.Y'));
$order->setField('INVOICE_NUMBER', generateInvoiceNumber($orderId));
$order->save();
LocalRedirect('/bitrix/admin/sale_order_detail.php?ID=' . $orderId . '&lang=ru');
}
Invoice Structure: Required Fields
According to accounting requirements, an invoice must contain:
- Number and issue date
- Seller details: name, Tax ID (INN/KPP), bank, current account, BIC
- Buyer details: name, Tax ID (INN/KPP), address
- List of goods/services with quantity, unit price, and total
- VAT (if applicable): rate and amount
- Total amount in words
- Signatures of the director and chief accountant
PDF Invoice Generation
use Mpdf\Mpdf;
class InvoiceGenerator
{
private array $sellerDetails;
public function __construct()
{
$this->sellerDetails = [
'name' => 'LLC "My Store"',
'inn' => '7701234567',
'kpp' => '770101001',
'address' => '115093, Moscow, Primernaya St., 1',
'bank' => 'Sberbank PJSC',
'bik' => '044525225',
'account' => '40702810938000000001',
'corr_account' => '30101810400000000225',
'director' => 'I.I. Ivanov',
'accountant' => 'A.A. Petrova',
];
}
public function generate(\Bitrix\Sale\Order $order, string $invoiceNumber): string
{
$mpdf = new Mpdf([
'format' => 'A4',
'orientation' => 'P',
'margin_top' => 15,
'margin_left' => 20,
'margin_right'=> 15,
]);
$mpdf->SetFont('dejavusans');
$buyer = $this->getBuyerDetails($order);
$items = $this->getOrderItems($order);
$totals = $this->calculateTotals($items);
$html = $this->renderInvoiceHtml([
'number' => $invoiceNumber,
'date' => date('d.m.Y'),
'seller' => $this->sellerDetails,
'buyer' => $buyer,
'items' => $items,
'totals' => $totals,
'in_words' => $this->amountInWords($totals['total']),
]);
$mpdf->WriteHTML($html);
$uploadDir = '/upload/invoices/';
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . $uploadDir)) {
mkdir($_SERVER['DOCUMENT_ROOT'] . $uploadDir, 0755, true);
}
$filename = 'invoice_' . $order->getId() . '_' . date('Ymd') . '.pdf';
$fullPath = $_SERVER['DOCUMENT_ROOT'] . $uploadDir . $filename;
$mpdf->Output($fullPath, 'F');
return $uploadDir . $filename;
}
private function getOrderItems(\Bitrix\Sale\Order $order): array
{
$items = [];
$num = 1;
foreach ($order->getBasket()->getOrderableItems() as $item) {
$price = $item->getBasePrice();
$qty = $item->getQuantity();
$items[] = [
'num' => $num++,
'name' => $item->getField('NAME'),
'unit' => 'pcs.',
'qty' => $qty,
'price' => $price,
'total' => $price * $qty,
'vat' => 0, // or calculate from the item's VAT rate
];
}
return $items;
}
}
Invoice Numbering
The invoice number must be unique. Recommended format: INV-YYYY-NNNN (year + sequence number):
function generateInvoiceNumber(): string
{
$year = date('Y');
$counter = (int)COption::GetOptionInt('my_module', 'invoice_counter_' . $year, 0) + 1;
COption::SetOptionInt('my_module', 'invoice_counter_' . $year, $counter);
return 'INV-' . $year . '-' . str_pad($counter, 4, '0', STR_PAD_LEFT);
}
Sending the Invoice by Email
$event = new \Bitrix\Main\Mail\Event([
'EVENT_NAME' => 'ORDER_INVOICE',
'TO_EMAIL' => $buyerEmail,
'ATTACHMENTS' => [
[
'path' => $_SERVER['DOCUMENT_ROOT'] . $pdfPath,
'name' => 'Invoice_' . $invoiceNumber . '.pdf',
],
],
'FIELDS' => [
'INVOICE_NUMBER' => $invoiceNumber,
'ORDER_ID' => $orderId,
'BUYER_NAME' => $buyerName,
'AMOUNT' => $totalAmount,
],
]);
\Bitrix\Main\Mail\Event::send($event);
Timeline
| Task | Duration |
|---|---|
| PDF invoice generator (mPDF/TCPDF) | 1–2 days |
| Numbering, invoice template | 0.5 day |
| Admin button + email delivery | 0.5 day |







