- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/invoice/compatible/helper.php
- Класс: Bitrix\Crm\Invoice\Compatible\Helper
- Вызов: Helper::payOrder
static function payOrder($id, $paid)
{
/** @global \CUser $USER */
/** @global \CMain $APPLICATION */
global $USER, $APPLICATION;
$id = (int)$id;
$paid = (($paid != 'Y') ? 'N' : 'Y');
if ($id <= 0)
{
$APPLICATION->ThrowException(Loc::getMessage('CRM_INVOICE_COMPAT_HELPER_NO_INVOICE_ID'));
return false;
}
$fields = self::getById($id);
if (!$fields)
{
$APPLICATION->ThrowException(Loc::getMessage('CRM_INVOICE_COMPAT_HELPER_NO_INVOICE', ['#ID#', $id]));
return false;
}
if ($fields['PAYED'] == $paid)
{
$APPLICATION->ThrowException(Loc::getMessage('CRM_INVOICE_COMPAT_HELPER_DUB_PAY', ['#ID#', $id]));
return false;
}
$arFields = array(
'PAYED' => $paid,
'=DATE_PAYED' => Main\Application::getConnection()->getSqlHelper()->getCurrentDateTimeFunction(),
'EMP_PAYED_ID' => (intval($USER->GetID()) > 0 ? intval($USER->GetID()) : false),
'SUM_PAID' => 0
);
/** @var Sale\Result $r */
$r = Invoice::pay($id, $arFields);
if (!$r->isSuccess())
{
$APPLICATION->ThrowException(
Loc::getMessage(
"CRM_INVOICE_COMPAT_HELPER_PAY_ERROR",
["#MESSAGE#" => implode(' ', $r->getErrorMessages())]
)
);
return false;
}
return true;
}