/**
 * Оплата из буфера.
 *
 * @param type  $type
 * @param array $data (prof_id)
 *
 * @return type
 */
function quickPaymentFrlbindupBuffer($type, $data)
{
    $is_error = true;
    $uid = get_uid(false);
    $objResponse =& new xajaxResponse();
    $prof_id = (int) @$data['prof_id'];
    $is_spec = (bool) @$data['is_spec'];
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/buffer.php';
    $buffer = new buffer();
    $buffer_sum = $buffer->getSum();
    $freelancer_binds = new freelancer_binds();
    $is_binded = $freelancer_binds->isUserBinded($uid, $prof_id, $is_spec);
    $price = $freelancer_binds->getPriceUp($prof_id, $is_spec, $uid);
    if ($is_binded && $buffer_sum >= $price) {
        $bill = new billing($uid);
        $option = array('prof_id' => $prof_id);
        //Покупаем услугу смоимостью 0 рублей при любом заначении ЛС
        $ok = $bill->addServiceAndPayZero(freelancer_binds::OP_CODE_UP_BUFFER, $option);
        if ($ok) {
            $is_error = false;
            $buffer->setUsedSum($price);
            $objResponse->script('window.location.reload();');
        }
    }
    // Показываем предупреждение в случае ошибки
    if ($is_error) {
        $objResponse->script("\n            var qp = window.quick_payment_factory.getQuickPayment('frlbindup');\n            if(qp) qp.show_error('Возникла ошибка при поднятии закрепления в каталоге!');\n        ");
    }
    return $objResponse;
}
/**
 * Оплата из буфера
 * @param type $type
 * @param array $data (prof_id)
 * @return type
 */
function quickPaymentTservicebindupBuffer($type, $data)
{
    $is_error = true;
    $uid = get_uid(false);
    $objResponse =& new xajaxResponse();
    $kind = (int) @$data['kind'];
    $tservice_id = (int) @$data['tservice_text_db_id'];
    $prof_id = (int) @$data['prof_id'];
    $is_spec = $kind == tservices_binds::KIND_SPEC;
    $tservices_binds = new tservices_binds($kind);
    $bind = $tservices_binds->getItem($uid, $tservice_id, $prof_id);
    require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/buffer.php";
    $buffer = new buffer();
    $buffer_sum = $buffer->getSum();
    $price = $tservices_binds->getPrice(true, $uid, $prof_id);
    if ($bind && $buffer_sum >= $price) {
        $bill = new billing($uid);
        $ok = $bill->addServiceAndPayFromAccount(tservices_binds::OP_CODE_UP_BUFFER, array('bind_id' => $bind['id']));
        if ($ok) {
            $is_error = false;
            $buffer->setUsedSum($price);
            $objResponse->script("window.location.reload();");
        }
    }
    // Показываем предупреждение в случае ошибки
    if ($is_error) {
        $idx = quickPaymentPopupTservicebindup::getPopupId($tservice_id);
        $objResponse->script("\n            var qp = window.quick_payment_factory.getQuickPaymentById('tservicebindup', '" . $idx . "');\n            if(qp) qp.show_error('Возникла ошибка при поднятии закрепления услуги!');\n        ");
    }
    return $objResponse;
}