3namespace Sale\Handlers\PaySystem;
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\Request;
9use Bitrix\Sale\Payment;
10use Bitrix\Sale\PaySystem;
11use Bitrix\DocumentGenerator;
12use Bitrix\Crm\Integration;
14Loc::loadMessages(__FILE__);
20class OrderDocumentHandler
27 protected static function getDataProviderClass()
29 return Integration\DocumentGenerator\DataProvider\Order::class;
41 $result =
new PaySystem\ServiceResult();
42 if (!Main\Loader::includeModule(
'documentgenerator')
44 !Main\Loader::includeModule(
'crm')
52 $request = Main\Context::getCurrent()->getRequest();
55 $document = $this->getDocument(
$payment);
56 if ($document ===
null)
58 return new PaySystem\ServiceResult();
61 $documentInfo = $document->getFile()->getData();
62 $result->setData($documentInfo);
64 $params = array_merge($documentInfo, DocumentGenerator\Model\ExternalLinkTable::getPublicUrlsByDocumentId($document->ID));
69 if ($this->service->getField(
'NEW_WINDOW') ===
'Y')
76 $params[
'PAYSYSTEM_ID'] = $this->service->getField(
'ID');
81 if ($showTemplateResult->isSuccess())
83 $result->setTemplate($showTemplateResult->getTemplate());
87 $result->addErrors($showTemplateResult->getErrors());
93 private function getTemplate(Request
$request)
95 return $request->get(
'template') ??
'template';
117 if (!Main\Loader::includeModule(
'documentgenerator')
119 !Main\Loader::includeModule(
'crm')
125 $provider = static::getDataProviderClass();
126 $templateList = DocumentGenerator\Model\TemplateTable::getListByClassName(
$provider);
128 foreach ($templateList as $item)
147 $document = $this->getDocument(
$payment);
148 if ($document ===
null)
150 return new PaySystem\ServiceResult();
154 'DOCUMENT_ID' => $document->ID,
155 'MODULE_ID' =>
$params[
'MODULE_ID'],
156 'CALLBACK_CLASS' =>
$params[
'CALLBACK_CLASS'],
157 'CALLBACK_METHOD' =>
$params[
'CALLBACK_METHOD'],
160 Sale\DocumentGenerator\CallbackRegistry::add($callback);
162 return new PaySystem\ServiceResult();
172 protected function getDocument(Sale\Payment
$payment)
174 $dbRes = DocumentGenerator\Model\DocumentTable::getList([
175 'select' => [
'ID',
'UPDATE_TIME'],
177 '=PROVIDER' => static::getDataProviderClass(),
179 '=TEMPLATE_ID' => $this->service->getField(
'PS_MODE'),
181 'order' => [
'ID' =>
'DESC'],
188 $document = DocumentGenerator\Document::loadById(
$data[
'ID']);
191 $collection =
$payment->getCollection();
193 $order = $collection->getOrder();
194 if (
$data[
'UPDATE_TIME'] <
$order->getField(
'DATE_UPDATE'))
196 $document->update([]);
201 if (!$this->service->getField(
'PS_MODE'))
206 $template = DocumentGenerator\Template::loadById($this->service->getField(
'PS_MODE'));
211 $template->setSourceType(static::getDataProviderClass());
213 $document = DocumentGenerator\Document::createByTemplate(
$template,
$payment->getOrderId());
214 $document->setValues([
'DocumentTitle' => $this->getFileName(
$payment)]);
215 $document->getFile();
218 $document->enablePublicUrl();
228 protected function getFileName(Payment
$payment)
230 $today =
new Main\Type\Date();
231 return 'invoice_'.$this->getInvoiceNumber(
$payment).
'_'.str_replace([
'.',
'\\',
'/'],
'-' ,$today->toString());
238 protected function getInvoiceNumber(Payment
$payment)
240 return $payment->getField(
'ACCOUNT_NUMBER');
252 public function getContent(Payment
$payment)
274 public function getFile(Payment
$payment)
276 if (!Main\Loader::includeModule(
'documentgenerator'))
281 $document = $this->getDocument(
$payment);
282 if ($document ===
null)
287 $documentInfo = $document->getFile()->getData();
288 if (isset($documentInfo[
'pdfUrl']))
290 $fileId = DocumentGenerator\Model\FileTable::getBFileId($document->PDF_ID);
291 if ($fileId !==
false)
293 $fileArray = \CFile::GetFileArray($fileId);
312 public function isGenerated(Payment
$payment)
314 if (!Main\Loader::includeModule(
'documentgenerator'))
319 $document = $this->getDocument(
$payment);
320 if ($document ===
null)
325 $documentInfo = $document->getFile()->getData();
326 return isset($documentInfo[
'pdfUrl']);
if(!Loader::includeModule('messageservice')) $provider
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
static getHandlerModeList()
showTemplate(Payment $payment=null, $template='')
setExtraParams(array $values)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']