bp/app/Helpers/crm_deals_helper.php

42 lines
1.1 KiB
PHP

<?php
/**
* Конвертирует HEX цвет в RGBA
*/
if (!function_exists('hex2rgba')) {
function hex2rgba(string $color, float $opacity = 1): string
{
$color = ltrim($color, '#');
if (strlen($color) === 3) {
$color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
}
$hex = [hexdec($color[0] . $color[1]), hexdec($color[2] . $color[3]), hexdec($color[4] . $color[5])];
return 'rgba(' . implode(', ', $hex) . ', ' . $opacity . ')';
}
}
/**
* Форматировать сумму в валюте
*/
if (!function_exists('format_currency')) {
function format_currency(float $amount, string $currency = 'RUB'): string
{
$locale = locale_get_default() ?: 'ru_RU';
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
return $formatter->formatCurrency($amount, $currency);
}
}
/**
* Получить текущую организацию
*/
function current_organization_id(): ?int
{
$session = session();
$orgId = $session->get('active_org_id');
return $orgId ? (int) $orgId : null;
}