forked from eeukolov/r-keeper_cost_loader_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.php
60 lines (45 loc) · 1.83 KB
/
script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require_once '_config.php';
require_once 'sh5.php';
require_once 'rk7.php';
require_once 'logger.php';
if (!file_exists('log')) {
mkdir('log', 0777, true);
}
logger('Запуск скрипта');
$sh5_report_json = get_report_RptPreCost();
$sh5_report_parsed = parse_report_RptPreCost($sh5_report_json);
$all_goods_json = proc_GoodsTree();
$all_goods = parse_GoodTree($all_goods_json);
$menu = get_menu();
if (empty($menu) or empty($sh5_report_parsed)) {
logger('Получено пустое меню либо отчет по себестоимости из SH5');
exit;
}
foreach ($sh5_report_parsed as $depart => $goods) {
foreach ($goods as $key => $good) {
$sh5_report_parsed[$depart][$key]['guid_sh'] = $all_goods[$good['rid']];
$sh5_report_parsed[$depart][$key]['guid_rk'] = guidXOR($all_goods[$good['rid']], SH5_GROUP_GUID);
}
$sh5_report_parsed[$depart] = array_column($sh5_report_parsed[$depart], 'cost', 'guid_rk');
}
logger('Формируем XML для записи цен в RK7');
$XML = new SimpleXMLElement("<RK7Query></RK7Query>");
$command = $XML->addChild('RK7Command');
$command->addAttribute('CMD', 'SetRefData');
$command->addAttribute('RefName', 'MenuItems');
$items = $command->addChild('Items');
foreach ($menu as $dish) {
if (!isset($sh5_report_parsed[DEPART_CATEGORY_COMPARISION[$dish['categ']]][$dish['guid']])) {
continue;
}
$item = $items->addChild('Item');
$item->addAttribute('GUIDString', $dish['guid']);
$item->addAttribute('PRICETYPES-' . RK7_COST_PRICE_TYPE_ID, ($sh5_report_parsed[DEPART_CATEGORY_COMPARISION[$dish['categ']]][$dish['guid']]) * 100);
}
Header('Content-type: text/xml');
$resultXML = postCURL_RK7($XML->asXML());
logger('Ответ:');
logger(formatXml($resultXML));
Header('Content-type: text/xml');
echo(formatXml($resultXML));