예제 #1
0
/**
 * Генерирует заявление асинхронно только в случае если его нет.
 */
function generateStatement($sbr_id)
{
    require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/pskb.php';
    $objResponse = new xajaxResponse();
    $sbr_id = __paramValue('int', $sbr_id);
    $sbr = sbr_meta::getInstance();
    if (!$sbr->initFromId($sbr_id)) {
        return $objResponse;
    }
    $pskb = new pskb($sbr);
    $lc = $pskb->getLC();
    if ($lc['ps_emp'] != onlinedengi::BANK_YL) {
        return $objResponse;
    }
    $sbr->getDocs();
    foreach ($sbr->docs as $doc) {
        if ($doc['type'] == sbr::DOCS_TYPE_STATEMENT) {
            $doc_file = new CFile($doc['file_id']);
            $doc_file->original_name = $doc['name'];
            $content_file = '<div class="b-layout__txt"><i class="b-icon b-icon_attach_pdf"></i> <a class="b-layout__link" href="' . WDCPREFIX . '/' . $doc_file->path . $doc_file->name . ' ">' . $doc_file->original_name . '</a>, ' . ConvertBtoMB($doc_file->size) . '</div>';
            $info_file = '<div class="b-layout__txt"><a class="b-layout__link" href="' . WDCPREFIX . '/' . $doc_file->path . $doc_file->name . '">Скачать файл</a></div>';
            $objResponse->assign('content_statement_doc', 'innerHTML', $content_file);
            $objResponse->assign('info_statement_doc', 'innerHTML', $info_file);
            return $objResponse;
        }
    }
    if ($doc_file = $sbr->stages[0]->generateStatement($doc_err, $lc)) {
        // формируем заявление на аккредитив
        $doc = array('file_id' => $doc_file->id, 'status' => sbr::DOCS_STATUS_SIGN, 'access_role' => sbr::DOCS_ACCESS_EMP, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_STATEMENT, 'subtype' => 1);
        $sbr->addDocR($doc);
        $doc_file->original_name = $sbr->post_doc['name'];
        $content_file = '<div class="b-layout__txt"><i class="b-icon b-icon_attach_pdf"></i> <a class="b-layout__link" href="' . WDCPREFIX . '/' . $doc_file->path . $doc_file->name . ' ">' . $doc_file->original_name . '</a>, ' . ConvertBtoMB($doc_file->size) . '</div>';
        $info_file = '<div class="b-layout__txt"><a class="b-layout__link" href="' . WDCPREFIX . '/' . $doc_file->path . $doc_file->name . '">Скачать файл</a></div>';
        $objResponse->assign('content_statement_doc', 'innerHTML', $content_file);
        $objResponse->assign('info_statement_doc', 'innerHTML', $info_file);
    }
    return $objResponse;
}
예제 #2
0
 /**
  * Совершает выплату юзеру по данному этапу СБР.
  * Выплата -- это отметка, что деньги реально выплачены.
  *
  * @param integer $user_id   ид. юзера, которому предназначается выплата.
  * @return boolean   успешно?
  */
 function payoutAgnt($user_id, pskb $pskb, pskb_lc $pskb_lc)
 {
     setlocale(LC_ALL, 'en_US.UTF-8');
     if (!$this->getPayouts($user_id)) {
         return false;
     }
     if ($this->payouts[$user_id]['completed']) {
         return false;
     }
     $account = new account();
     $account->GetInfo($user_id);
     $credit_sys = $this->payouts[$user_id]['credit_sys'];
     $lc = $pskb->getLC(true);
     $acc = $user_id == $this->sbr->emp_id ? $lc['accCust'] : $lc['accPerf'];
     switch ($credit_sys) {
         case exrates::BANK:
             $descr = "Безнал на счет: {$acc}";
             break;
         case exrates::YM:
             $descr = "Яндекс.Деньги на кошелек: {$acc}";
             break;
         case exrates::WMR:
             $descr = "WMR на кошелек: {$acc}";
             break;
         case exrates::WEBM:
             $descr = "Вывод на Веб-кошелек";
             break;
         case exrates::CARD:
             $descr = "Безнал на счет пластиковой карты";
             break;
         default:
             return !($this->error = 'Неверная валюта');
     }
     $this->sbr->getScheme();
     $percent = 1;
     if ($this->payouts[$user_id]['is_arbitrage'] == 't') {
         $this->getArbitrage();
         $percent = abs((int) ($user_id == $this->sbr->emp_id) - $this->arbitrage['frl_percent']);
     }
     $iex = $credit_sys . $this->sbr->cost_sys;
     if (!$this->exrates) {
         $this->sbr->getExrates();
     }
     $credit_sum = $this->payouts[$user_id]['credit_sum'];
     $debit_sum = round($credit_sum * $this->sbr->exrates[$iex], 2);
     $d_descr = 'Списание ' . ($percent == 1 ? '' : 100 * $percent . '% (арбитраж) ') . "резерва «Безопасной Сделки» (этап #{$this->id})";
     $sbr = sbr_meta::getInstanceLocal($user_id);
     $sbr->initFromId($this->data['sbr_id'], false, false);
     $comments = sbr_meta::view_cost($credit_sum, $credit_sys) . ', ' . $sbr->getContractNum();
     $d_comments = sbr_meta::view_cost($debit_sum, $this->sbr->cost_sys) . ', ' . $sbr->getContractNum();
     if (($debit_id = $account->CommitReserved($sbr->emp_id, $this->sbr->reserved_id, $d_descr, sbr::OP_DEBIT, $debit_sum, $d_comments)) && ($credit_id = $account->TransferReserved($user_id, $credit_sum, $credit_sys - 1, $descr, $errors, sbr::OP_CREDIT, $comments))) {
         $sql = "\n              UPDATE sbr_stages_payouts\n                 SET debit_id = {$debit_id},\n                     credit_id = {$credit_id},\n                     completed = now(),\n                     state = '{$pskb_lc->state}',\n                     \"stateReason\" = '{$pskb_lc->stateReason}',\n                     bank_completed = '{$pskb_lc->date}'\n               WHERE stage_id = {$this->id}\n                 AND user_id = {$user_id}\n\n                 AND completed IS NULL\n              RETURNING *\n            ";
         if ($res = pg_query(self::connect(), $sql)) {
             $this->payoutUpdateState($pskb_lc);
             $docs = array();
             $is_emp_arb = $this->status == sbr_stages::STATUS_ARBITRAGED && $this->arbitrage['resolved'] && floatval($this->arbitrage['frl_percent']) == 0;
             if ($this->sbr->scheme_type == sbr::SCHEME_LC && !$is_emp_arb) {
                 if ($doc_file = $this->generateEmpAgentReport($doc_err, $rep_num)) {
                     // отчет агента.
                     $docs[] = array('stage_id' => $this->id, 'file_id' => $doc_file->id, 'num' => $rep_num, 'status' => sbr::DOCS_STATUS_PUBL, 'access_role' => sbr::DOCS_ACCESS_EMP, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_AGENT_REP);
                     if ($doc_file = $this->generateEmpAct($doc_err, $doc_num, $rep_num)) {
                         // акт работодателя по агентской схеме (он же отчет об арбитраже, если был арбитраж).
                         $docs[] = array('stage_id' => $this->id, 'file_id' => $doc_file->id, 'num' => $doc_num, 'status' => sbr::DOCS_STATUS_PUBL, 'access_role' => sbr::DOCS_ACCESS_EMP, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_ACT);
                     }
                 }
             } elseif (($this->sbr->scheme_type == sbr::SCHEME_PDRD || $this->sbr->scheme_type == sbr::SCHEME_PDRD2) && !$is_emp_arb) {
                 if ($doc_file = $this->generateArbReportPdrdEmp($doc_err)) {
                     // отчет арбитража по договору подряда для работодателя.
                     $docs[] = array('stage_id' => $this->id, 'file_id' => $doc_file->id, 'status' => sbr::DOCS_STATUS_PUBL, 'access_role' => sbr::DOCS_ACCESS_EMP, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_ARB_REP);
                 }
             }
             if (count($docs)) {
                 foreach ($docs as $doc) {
                     $ok = $this->sbr->addDocR($doc);
                 }
             }
             $this->payouts[$user_id] = pg_fetch_assoc($res);
             return true;
         }
     }
     if ($debit_id && !$credit_id) {
         $account->Del($user_id, $debit_id);
     }
     return false;
 }
예제 #3
0
 public function showInvoicedAgnt($account, $tpl = '')
 {
     $form_type = sbr::FT_JURI;
     $this->getInvoiceReqv($form_type);
     $contract_num = $this->getContractNum($this->id, $this->scheme_type);
     $rq = $this->getUserReqvs();
     $reqv = $rq[$form_type];
     $sbr_comm = $billCode = "Б-{$contract_num}";
     $pskb = new pskb($this);
     $lc = $pskb->getLC();
     $dvals = array('P' => pskb::$exrates_map[$lc['ps_emp']]);
     $tax_total = 0;
     foreach ($this->stages as $stage) {
         foreach ($this->scheme['taxes'][sbr::EMP] as $tax) {
             if ($tax['tax_code'] != 'TAX_FL') {
                 continue;
             }
             $tax_total += $stage->calcTax($tax, $dvals, $outsys);
             if (!floatval($tax_total)) {
                 continue;
             }
         }
     }
     $sum = $lc['sum'] + $tax_total;
     $ord_num = $lc['id'];
     // Заменяем данными по которым иницирован аккредитив
     $reqv['full_name'] = $lc['nameCust'];
     $reqv['phone'] = $lc['numCust'];
     $reqv['invoiced_time'] = $lc['created'];
     if ($tpl == 'print') {
         include $_SERVER['DOCUMENT_ROOT'] . '/engine/templates/bill/bill_transfer_agnt_print.tpl';
     } else {
         include $_SERVER['DOCUMENT_ROOT'] . '/engine/templates/bill/bill_transfer_agnt.tpl';
     }
 }
예제 #4
0
     $RT = $sbr->getRatingSum($sbr->cost, sbr_meta::FRL_PERCENT_TAX);
     $stages_ids = array_map(create_function('$a', 'return $a->data["id"];'), $sbr->stages);
     break;
 case 'Stage':
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php";
     $inner = 'stage.php';
     $stage_id = __paramInit('int', 'id', 'id');
     if (!($stage = $sbr->initFromStage($stage_id))) {
         break;
     }
     if ($stage->sbr->status == sbr::STATUS_CLOSED && $action != 'msg-add') {
         $action = "";
     }
     //TODO Сомнительный момент
     $pskb = new pskb($sbr);
     $lc = $pskb->getLC();
     // код для страницы помощи
     $g_help_id = 219;
     if ($stage->data['lc_state'] == pskb::STATE_PASSED) {
         $g_help_id = 217;
     }
     $is_filled = explode(',', preg_replace('/[}{]/', '', $sbr->user_reqvs['is_filled']));
     $isReqvsFilled[sbr::FT_PHYS] = $is_filled[sbr::FT_PHYS - 1] == 't';
     $isReqvsFilled[sbr::FT_JURI] = $is_filled[sbr::FT_JURI - 1] == 't';
     $attachedfiles = new attachedfiles($_POST['attachedfiles_session']);
     $comment_files = array();
     $feedback_sent = isset($_SESSION["thnx_block{$stage_id}"]);
     if ($feedback_sent) {
         unset($_SESSION["thnx_block{$stage_id}"]);
     }
     if ($action == 'frl_refund') {