1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\PaySystem;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Request;
8use Bitrix\Main\Type;
9use Bitrix\Main\Type\Date;
10use Bitrix\Sale;
11use Bitrix\Sale\Payment;
12use Bitrix\Sale\PaySystem;
13use Bitrix\Currency;
14
15Loc::loadMessages(__FILE__);
20class BillHandler
22 implements PaySystem\IPdf
23{
33 public function initiatePay(Sale\Payment $payment, Request $request = null)
34 {
35 $template = 'template';
36
37 if (array_key_exists('pdf', $_REQUEST))
38 $template .= '_pdf';
39
40 $extraParams = $this->getPreparedParams($payment, $request);
42
43
44 return $this->showTemplate($payment, $template);
45 }
46
52 public function showTemplate(Sale\Payment $payment = null, $template = '')
53 {
54 \CCurrencyLang::disableUseHideZero();
55
56 return parent::showTemplate($payment, $template);
57 }
58
68 protected function getPreparedParams(Sale\Payment $payment, Request $request = null)
69 {
71 $paymentCollection = $payment->getCollection();
72
74 $order = $paymentCollection->getOrder();
75
77 'ACCOUNT_NUMBER' => (IsModuleInstalled('intranet')) ? $order->getField('ACCOUNT_NUMBER') : $payment->getField('ACCOUNT_NUMBER'),
78 'CURRENCY' => $payment->getField('CURRENCY'),
79 'DATE_BILL' => $payment->getField('DATE_BILL'),
80 'SUM' => Sale\PriceMaths::roundPrecision($order->getPrice()),
81 'SUM_PAID' => Sale\PriceMaths::roundPrecision($paymentCollection->getPaidSum()),
82 'DISCOUNT_PRICE' => Sale\PriceMaths::roundPrecision($order->getDiscountPrice())
83 );
84
85 $taxes = $order->getTax();
86 $extraParams['TAXES'] = $taxes->getTaxList();
87
89 $shipmentCollection = $order->getShipmentCollection();
90
92 foreach ($shipmentCollection as $shipment)
93 {
94 if (!$shipment->isSystem())
95 {
96 $extraParams['DELIVERY_NAME'] = $shipment->getDeliveryName();
97 $extraParams['DELIVERY_PRICE'] = $shipment->getPrice();
98 $extraParams['DELIVERY_VAT_RATE'] = $shipment->getVatRate();
99 break;
100 }
101 }
102
103 $basket = $order->getBasket();
104
105 $extraParams['BASKET_ITEMS'] = array();
106
107 $userColumns = $this->getBusinessValue($payment, 'USER_COLUMNS');
108 $ids = array();
109 if ($userColumns !== null)
110 {
111 $extraParams['USER_COLUMNS'] = array();
112 $userColumns = unserialize($userColumns, ['allowed_classes' => false]);
113 if ($userColumns)
114 {
115 foreach ($userColumns as $id => $columns)
116 {
117 $extraParams['USER_COLUMNS']['PROPERTY_'.$id] = array(
118 'NAME' => $columns['NAME'],
119 'SORT' => $columns['SORT']
120 );
121 $ids[] = $id;
122 }
123 }
124 }
125
126 $productProps = [];
128 foreach ($basket->getBasketItems() as $basketItem)
129 {
130 $productProps[$basketItem->getProductId()] = array();
131
132 $item = array(
133 'NAME' => $basketItem->getField("NAME"),
134 'IS_VAT_IN_PRICE' => $basketItem->isVatInPrice(),
135 'PRODUCT_ID' => $basketItem->getProductId(),
136 'PRICE' => $basketItem->getPrice(),
137 'VAT_RATE' => $basketItem->getVatRate(),
138 'QUANTITY' => $basketItem->getQuantity(),
139 'MEASURE_NAME' => $basketItem->getField("MEASURE_NAME"),
140 'CURRENCY' => $basketItem->getCurrency(),
141 );
142
143 $item['PROPS'] = array();
144 foreach ($basketItem->getPropertyCollection() as $basketPropertyItem)
145 {
146 $item['PROPS'][] = array(
147 'CODE' => $basketPropertyItem->getField('CODE'),
148 'NAME' => $basketPropertyItem->getField('NAME'),
149 'VALUE' => $basketPropertyItem->getField('VALUE')
150 );
151 }
152
153 $extraParams['BASKET_ITEMS'][$basketItem->getId()] = $item;
154 }
155
156 if ($ids && Loader::includeModule('crm') && Loader::includeModule('iblock'))
157 {
158 $productIdsByCatalogMap = [];
159 $dbRes = \CCrmProduct::GetList([], ['ID' => array_keys($productProps)], ['ID', 'CATALOG_ID']);
160 while ($data = $dbRes->Fetch())
161 {
162 $catalogId = isset($data['CATALOG_ID']) ? intval($data['CATALOG_ID']) : \CCrmCatalog::EnsureDefaultExists();
163 if (!isset($productIdsByCatalogMap[$catalogId]))
164 {
165 $productIdsByCatalogMap[$catalogId] = [];
166 }
167
168 $productIdsByCatalogMap[$catalogId][] = $data['ID'];
169 }
170
171 if ($productIdsByCatalogMap)
172 {
173 foreach ($productIdsByCatalogMap as $catalogId => $ids)
174 {
175 \CIBlockElement::GetPropertyValuesArray($productProps, $catalogId, array('ID' => $ids));
176 }
177 }
178
179 foreach ($extraParams['BASKET_ITEMS'] as $i => $row)
180 {
181 foreach ($productProps[$row['PRODUCT_ID']] as $property)
182 {
183 $extraParams['BASKET_ITEMS'][$i]['PROPERTY_'.$property['ID']] = $property['VALUE'];
184 }
185 }
186 }
187
188 return $extraParams;
189 }
190
194 public function getCurrencyList()
195 {
196 $currencyList = [];
197
198 if (Loader::includeModule('currency'))
199 {
200 $currencyIterator = Currency\CurrencyTable::getList([
201 'select' => ['CURRENCY'],
202 'cache' => ['ttl' => 86400],
203 ]);
204 while ($currency = $currencyIterator->fetch())
205 {
206 $currencyList[] = $currency['CURRENCY'];
207 }
208 }
209
210 return $currencyList;
211 }
212
216 public function isAffordPdf()
217 {
218 return true;
219 }
220
226 public function getDemoParams()
227 {
228 $data = array(
229 'ACCOUNT_NUMBER' => 'A1',
230 'PAYMENT_DATE_INSERT' => new Date(),
231 'DATE_INSERT' => new Date(),
232 'CURRENCY' => 'RUB',
233 'SUM' => 5900,
234 'SUM_PAID' => 0,
235 'TAXES' => array(
236 array(
237 'TAX_NAME' => Loc::getMessage('SALE_HPS_BILL_TAX'),
238 'IS_IN_PRICE' => 'Y',
239 'CODE' => 'VAT',
240 'VALUE_MONEY' => 900,
241 'VALUE' => 18.00,
242 'IS_PERCENT' => 'Y'
243 )
244 ),
245 'BASKET_ITEMS' => array(
246 array(
247 'NAME' => Loc::getMessage('SALE_HPS_BILL_BASKET_ITEM_NAME'),
248 'IS_VAT_IN_PRICE' => false,
249 'PRICE' => 5000,
250 'VAT_RATE' => 0.18,
251 'QUANTITY' => 1,
252 'MEASURE_NAME' => Loc::getMessage('SALE_HPS_BILL_BASKET_ITEM_MEASURE'),
253 'CURRENCY' => 'RUB'
254 )
255 ),
256 'SELLER_COMPANY_BANK_CITY' => Loc::getMessage('SALE_HPS_BILL_BANK_CITY'),
257 'SELLER_COMPANY_ADDRESS' => Loc::getMessage('SALE_HPS_BILL_BANK_ADDRESS'),
258 'SELLER_COMPANY_PHONE' => '+76589321451',
259 'SELLER_COMPANY_BANK_NAME' => Loc::getMessage('SALE_HPS_BILL_BANK_NAME'),
260 'SELLER_COMPANY_BANK_ACCOUNT' => '0000 0000 0000 0000 0000',
261 'SELLER_COMPANY_INN' => '000011112222',
262 'SELLER_COMPANY_KPP' => '123456789',
263 'SELLER_COMPANY_NAME' => Loc::getMessage('SALE_HPS_BILL_COMPANY_NAME'),
264 'SELLER_COMPANY_BANK_BIC' => '0123456',
265 'SELLER_COMPANY_BANK_ACCOUNT_CORR' => '1111 1111 1111 1111',
266 'BUYER_PERSON_COMPANY_NAME' => Loc::getMessage('SALE_HPS_BILL_BUYER_COMPANY_NAME'),
267 'BUYER_PERSON_COMPANY_INN' => '0123456789',
268 'BUYER_PERSON_COMPANY_PHONE' => '+79091234523',
269 'BUYER_PERSON_COMPANY_FAX' => '88002000600',
270 'BUYER_PERSON_COMPANY_ADDRESS' => Loc::getMessage('SALE_HPS_BILL_BUYER_COMPANY_ADDRESS'),
271 'BUYER_PERSON_COMPANY_NAME_CONTACT' => Loc::getMessage('SALE_HPS_BILL_BUYER_NAME_CONTACT'),
272 'SELLER_COMPANY_DIRECTOR_POSITION' => Loc::getMessage('SALE_HPS_BILL_DIRECTOR_POSITION'),
273 'SELLER_COMPANY_DIRECTOR_NAME' => Loc::getMessage('SALE_HPS_BILL_DIRECTOR_NAME'),
274 'SELLER_COMPANY_ACCOUNTANT_POSITION' => Loc::getMessage('SALE_HPS_BILL_ACCOUNTANT_POSITION'),
275 'SELLER_COMPANY_ACCOUNTANT_NAME' => Loc::getMessage('SALE_HPS_BILL_ACCOUNTANT_NAME'),
276 'SELLER_COMPANY_EMAIL' => 'my@company.com',
277 );
278
279 if (Loader::includeModule('crm') && Loader::includeModule('iblock'))
280 {
282 'IBLOCK_ID' => intval(\CCrmCatalog::EnsureDefaultExists()),
283 'CHECK_PERMISSIONS' => 'N',
284 '!PROPERTY_TYPE' => 'G'
285 );
286
287 $dbRes = \CIBlockProperty::GetList(array(), $arFilter);
288 while ($arRow = $dbRes->Fetch())
289 $data['BASKET_ITEMS'][0]['PROPERTY_'.$arRow['ID']] = 'test';
290 }
291
292 return $data;
293 }
294
303 public function getContent(Payment $payment)
304 {
305 $origRequest = $_REQUEST;
306
307 $_REQUEST['GET_CONTENT'] = 'Y';
308 $_REQUEST['pdf'] = 'Y';
309
310 $prevMode = $this->initiateMode;
311
312 $this->setInitiateMode(self::STRING);
313
314 $result = $this->initiatePay($payment, null);
315
316 if ($prevMode !== self::STRING)
317 {
318 $this->setInitiateMode(self::STREAM);
319 }
320
321 foreach (['pdf', 'GET_CONTENT'] as $key)
322 {
323 if (array_key_exists($key, $origRequest))
324 {
325 $_REQUEST[$key] = $origRequest[$key];
326 }
327 else
328 {
329 unset($_REQUEST[$key]);
330 }
331 }
332
333 return $result->getTemplate();
334 }
335
341 public function getFile(Payment $payment)
342 {
343 $order = $payment->getOrder();
344
345 $today = new Type\Date();
346 $fileName = 'invoice_'.$order->getField('ACCOUNT_NUMBER').'_'.str_replace(array('.', '\\', '/'), '-' ,$today->toString()).'.pdf';
347 $fileData = array(
348 'name' => $fileName,
349 'type' => 'application/pdf',
350 'content' => $this->getContent($payment),
351 'MODULE_ID' => 'sale'
352 );
353 $fileId = \CFile::SaveFile($fileData, 'sale');
354
355 return \CFile::GetFileArray($fileId);
356 }
357
362 public function isGenerated(Payment $payment)
363 {
364 return true;
365 }
366
367}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
getBusinessValue(Payment $payment=null, $code)
Определения baseservicehandler.php:184
$data['IS_AVAILABLE']
Определения .description.php:13
$template
Определения file_edit.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
IsModuleInstalled($module_id)
Определения tools.php:5301
$payment
Определения payment.php:14
$order
Определения payment.php:8
$paymentCollection
Определения payment.php:11
$fileName
Определения quickway.php:305
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
$currency
Определения template.php:266
$arFilter
Определения user_search.php:106
$taxes
Определения template_pdf.php:444
$dbRes
Определения yandex_detail.php:168