if (!$res->isSuccess()) {
                 $strError .= Loc::getMessage("SALE_DSE_ERROR_ADD_DELIVERY") . "<br>" . implode("<br>", $res->getErrorMessages());
             } else {
                 $ID = $res->getId();
                 Services\Manager::onAfterAdd($ID, $fields);
             }
         }
         if ($ID > 0) {
             //stores
             unset($res);
             if (isset($_POST["STORES_SHOW"]) && $_POST["STORES_SHOW"] == "Y" && isset($_POST["STORES"]["PARAMS"]["STORES"])) {
                 $res = ExtraServices\Manager::saveStores($ID, Bitrix\Sale\Delivery\ExtraServices\Store::getStoresIdsFromParams($_POST["STORES"]["PARAMS"]));
             } else {
                 $storesFields = ExtraServices\Manager::getStoresFields($ID);
                 if (!empty($storesFields)) {
                     $res = Delivery\ExtraServices\Table::delete($storesFields["ID"]);
                 }
             }
             if ($res && !$res->isSuccess()) {
                 $strError .= implode("<br>\n", $res->getErrorMessages());
             }
         }
     }
 }
 if (strlen($strError) <= 0) {
     if (strlen($_POST["apply"]) > 0) {
         $paramsToKill = array("ID");
         if (!empty($_REQUEST["RESET_TARIF_SETTINGS"])) {
             $paramsToKill[] = "RESET_TARIF_SETTINGS";
         }
         $redirectUrl = $APPLICATION->GetCurPageParam("ID=" . $ID, $paramsToKill);
if ($saleModulePermissions < "W") {
    $APPLICATION->AuthForm(Loc::getMessage("SALE_ESDL_ACCESS_DENIED"));
}
/**
 * @var CDatabase $DB
 * @var CMain  $APPLICATION
 */
use Bitrix\Main\Localization\Loc;
use Bitrix\Sale\Delivery\ExtraServices;
use Bitrix\Sale\Delivery\Services;
Loc::loadMessages(__FILE__);
$ID = intval($_GET['ID']);
$strError = "";
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete_extra_service" && isset($_REQUEST["ES_ID"])) {
    if (intval($_REQUEST["ES_ID"] > 0)) {
        $res = ExtraServices\Table::delete(intval($_REQUEST["ES_ID"]));
        if (!$res->isSuccess()) {
            $strError .= Loc::getMessage("SALE_ESDE_ERROR_DELETE") . ' ' . implode("<br>\n", $res->getErrorMessages());
        }
    } else {
        $strError .= Loc::getMessage("SALE_ESDE_ERROR_ID");
    }
}
$tableId = 'table_delivery_extra_service';
$oSort = new \CAdminSorting($tableId);
$lAdmin = new \CAdminList($tableId, $oSort);
$res = \Bitrix\Sale\Delivery\ExtraServices\Table::getList(array('filter' => array('DELIVERY_ID' => $ID, '=CLASS_NAME' => ExtraServices\Manager::getClassesList()), 'select' => array('ID', 'CODE', 'NAME', 'DESCRIPTION', 'CLASS_NAME', 'RIGHTS', 'ACTIVE', 'SORT'), 'order' => array('SORT' => 'ASC', 'ID' => 'DESC')));
$data = $res->fetchAll();
$dbRes = new \CDBResult();
$dbRes->InitFromArray($data);
$dbRecords = new \CAdminResult($dbRes, $tableId);