diff --git a/commands/GETDataReport.php b/commands/GETDataReport.php index 64e912b..987b003 100644 --- a/commands/GETDataReport.php +++ b/commands/GETDataReport.php @@ -14,6 +14,58 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface { protected $signature = 'getdatareport'; public function command($input, $output = null) { + + function validate_json($string) + { + // decode the JSON data + $result = json_decode(utf8_encode($string), true, JSON_INVALID_UTF8_SUBSTITUTE); + + // switch and check possible JSON errors + switch (json_last_error()) { + case JSON_ERROR_NONE: + $error = ''; // JSON is valid // No error has occurred + break; + case JSON_ERROR_DEPTH: + $error = 'The maximum stack depth has been exceeded.'; + break; + case JSON_ERROR_STATE_MISMATCH: + $error = 'Invalid or malformed JSON.'; + break; + case JSON_ERROR_CTRL_CHAR: + $error = 'Control character error, possibly incorrectly encoded.'; + break; + case JSON_ERROR_SYNTAX: + $error = 'Syntax error, malformed JSON.'; + break; + // PHP >= 5.3.3 + case JSON_ERROR_UTF8: + $error = 'Malformed UTF-8 characters, possibly incorrectly encoded.'; + break; + // PHP >= 5.5.0 + case JSON_ERROR_RECURSION: + $error = 'One or more recursive references in the value to be encoded.'; + break; + // PHP >= 5.5.0 + case JSON_ERROR_INF_OR_NAN: + $error = 'One or more NAN or INF values in the value to be encoded.'; + break; + case JSON_ERROR_UNSUPPORTED_TYPE: + $error = 'A value of a type that cannot be encoded was given.'; + break; + default: + $error = 'Unknown JSON error occured.'; + break; + } + + if ($error !== '') { + // throw the Exception or exit // or whatever :) + return false; + } + + // everything is OK + return true; + } + function data_decode($data) { $alph = [ "А", "Б", "В", "Г", "Д", @@ -103,7 +155,12 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface { if ($item_action['more']) { $merge_trigger = 1; $merge_items_before = $merge_items_after = $merge_items = $merge_order_item_before = $merge_order_item_after = $merged_items = []; - $merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + if (validate_json($item['more'])) { + $merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + } else { + $merge_order_items = json_decode(utf8_encode(base64_decode($item_action['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE); + } + $merge_order_items_before = $merge_order_items['before']['items']; $merge_order_items_after = $merge_order_items['after']['items']; foreach ($merge_order_items_before as $key => $merge_order_item_before) { @@ -168,13 +225,21 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface { foreach ($actions as $key => $action) { $value = $action['value']; $codeOrder = $action['order_code']; - $moved_items = json_decode(utf8_encode($action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + if (validate_json($action['more'])) { + $moved_items = json_decode(utf8_encode($action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + } else { + $moved_items = json_decode(utf8_encode(base64_decode($action['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE); + } $from_place = ExchangeActions::where('order_code', $codeOrder)->where('action_type', 45)->where('shift_id', $input['shift_id'])->first(); $from_place = data_decode($from_place['value']); $to_place = ExchangeActions::where('order_code', $value)->where('action_type', 45)->where('shift_id', $input['shift_id'])->first(); $to_place = data_decode($to_place['value']); $to_action = ExchangeActions::where('value', $codeOrder)->where('order_code', $value)->where('action_type', 34)->where('shift_id', $input['shift_id'])->first(); - $start_data = json_decode(utf8_encode($to_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + if (validate_json($to_action['more'])) { + $start_data = json_decode(utf8_encode($to_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + } else { + $start_data = json_decode(utf8_encode(base64_decode($to_action['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE); + } $staff_name = staffName($action['who']); $time = date('d.m.Y H:i:s', strtotime($action['time'])); $sliced_order_data[] = array('from_order' => $codeOrder, 'from_place' => $from_place, 'staff' => $staff_name, 'time' => $time, 'start_data' => $start_data, 'to_order' => $value, 'to_place' => $to_place, 'moved_items' => $moved_items); diff --git a/commands/GETImportMenu.php b/commands/GETImportMenu.php index 723ca70..7ab0182 100644 --- a/commands/GETImportMenu.php +++ b/commands/GETImportMenu.php @@ -2,229 +2,1060 @@ namespace App\Commands; +use App\Component\Models\Dishes; +use App\Component\Models\Folders; +use App\Component\Models\Menu; +use App\Component\Models\Modifier; +use App\Component\Models\ModifiersList; +use App\Component\Models\Printer; use App\Component\Models\Terminal; +use App\Component\Models\Units; +use App\Component\Models\UnitsList; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Http; -class GETImportMenu extends HRCCommand implements HRCCommandInterface { - protected $signature = 'getimportmenu'; +class GETImportMenu extends HRCCommand implements HRCCommandInterface +{ + protected $signature = 'getimportmenu'; - public function command($input, $output = null) { - $HRCPortalURL = 'https://portal.hrc.by/'; - $folder = 'menu'; - $terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first(); - $url = $HRCPortalURL . 'api/cloud/list?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&folder=' . $folder; - $search = curl_init(); + public function command($input, $output = null) + { + /* error_reporting(E_ERROR);*/ + function clearCache($dir) + { + $d = opendir($dir); + while (($entry = readdir($d)) !== false) { + if ($entry != "." && $entry != "..") { + if (is_dir($dir . "/" . $entry)) { + clearCache($dir . "/" . $entry); + } else { + unlink($dir . "/" . $entry); + } + } + } + closedir($d); + rmdir($dir); + } - curl_setopt_array($search, array( - CURLOPT_URL => $url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => false, - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - )); - $search_response = curl_exec($search); - curl_close($search); - $responses = json_decode($search_response, TRUE)['files']; + $terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first(); + $response_folder = Http::post('https://portal.hrc.by/api/cloud/folder', [ + 'code' => $terminal['key'], + 'folder' => 'menu', + 'project_code' => 'hrc', + 'api' => '2.0', + ]); + $response_files = Http::get('https://portal.hrc.by/api/cloud/list?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&folder=menu'); + $files = []; + $file = ''; + $dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\menu\\"; + /*{"status":"success","message":[{"size":"61671","mimetype":"application\/xml","timestamp":1655321649,"type":"file","path":"menu\/Menu_1_1.xml","dirname":"menu","basename":"Menu_1_1.xml","extension":"xml","filename":"Menu_1_1"}]}*/ + /* return ['status' => 'success', + 'json' => $response_files->json()['files'] + ];*/ + if (count($response_files->json()['files']) > 0) { + foreach ($response_files->json()['files'] as $response) { + $filename = $response['filename']; + $basename = $response['basename']; + $pieces = explode("_", $filename); + $workgroup = $pieces[1]; + $workcode = $pieces[2]; + $timestamp = 43028832314; + if (isset($pieces[3])) { + $timestamp = $pieces[3]; + } + if ($terminal['work_group'] == $workgroup && $terminal['work_code'] == $workcode) { + if ($timestamp <= time()) { + Log::debug('File timestamp: ' . $timestamp); + Log::debug('Current timestamp: ' . time()); + $files[$timestamp] = array('filename' => $filename, 'basename' => $basename, 'workgroup' => $workgroup, 'workcode' => $workcode); + } + } + } + if (count($files) == 0) { + return ['status' => 'success', + 'message' => 'Файлы не найдены' + ]; + } + $iMaxArrayIndex = max(array_keys($files)); + $basename = $files[$iMaxArrayIndex]['basename']; + $download_files = Http::get('https://portal.hrc.by/api/cloud/download?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&path=/menu/' . $basename); + $file = base64_decode($download_files->json()['content']); + if (!is_dir($dirname)) { + mkdir($dirname, 0755, 'w+'); + } + if (file_exists($dirname . $basename)) { + unlink($dirname . $basename); + } + $handle = fopen($dirname . $basename, 'w+'); + fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM + file_put_contents($dirname . $basename, $file); + fclose($handle); + $menu_file = $dirname . $basename; + foreach ($files as $index => $file) { + $delete_file = Http::delete('https://portal.hrc.by/api/cloud/file', [ + 'code' => $terminal['key'], + 'name' => $file['basename'], + 'folder' => 'menu', + 'project_code' => 'hrc', + 'api' => '2.0', + ]); + } + } else { + return ['status' => 'success', + 'message' => 'Файлы не найдены' + ]; + } - /*{"status":"success","message":[{"size":"61671","mimetype":"application\/xml","timestamp":1655321649,"type":"file","path":"menu\/Menu_1_1.xml","dirname":"menu","basename":"Menu_1_1.xml","extension":"xml","filename":"Menu_1_1"}]}*/ - foreach ($responses as $key => $response) { - $filename = $response['basename']; - //$path = '/backup/' . $filename . '.xml'; - $path = '/menu/' . $filename; - $download_url = $HRCPortalURL . 'api/cloud/download?api=2.0&project_code=hrc&code=' . $terminal['key'] . '&path=' . $path; - $download = curl_init(); + $objXmlDocument = simplexml_load_file($menu_file); + $objJsonDocument = json_encode($objXmlDocument); + $xmlmenu = json_decode($objJsonDocument, TRUE); + $GeneralSettings = $xmlmenu['GeneralSettings']['@attributes']; + $Printers = $xmlmenu['Printers']['Item']; + $ReportCategory = $xmlmenu['ReportCategory']['Item']; + $TypesMenu = $xmlmenu['TypesMenu']['Item']; + $Dishes = $xmlmenu['Dishes']['Item']; + $MenuItems = $xmlmenu['Menu']['Item']; + $Units_Dishes = $xmlmenu['Units_Dishes']['Item']; + if (isset($xmlmenu['Modifiers']['Item'])) { + $Modifiers = $xmlmenu['Modifiers']['Item']; + } - curl_setopt_array($download, array( - CURLOPT_URL => $download_url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => false, - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - )); - $download_response = curl_exec($download); - curl_close($download); - $file = json_decode($download_response, TRUE)['content']; - } - $dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\menu\\"; - if (!is_dir($dirname)) { - mkdir($dirname, 0755, 'w+'); - } - if (file_exists($dirname . $filename)) { - unlink($dirname . $filename); - } - $handle = fopen($dirname . $filename, 'w+'); - fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM - file_put_contents($dirname . $filename, base64_decode($file)); - fclose($handle); - $menu_file = $dirname . $filename; - $objXmlDocument = simplexml_load_file($menu_file); - $objJsonDocument = json_encode($objXmlDocument); - $xmlmenu = json_decode($objJsonDocument, TRUE); - $GeneralSettings = $xmlmenu['GeneralSettings']['@attributes']; - $Printers = $xmlmenu['Printers']['Item']; - $ReportCategory = $xmlmenu['ReportCategory']['Item']; - $TypesMenu = $xmlmenu['TypesMenu']['Item']; - $Dishes = $xmlmenu['Dishes']['Item']; - $MenuItems = $xmlmenu['Menu']['Item']; - $Units_Dishes = $xmlmenu['Units_Dishes']['Item']; - $Modifiers = $xmlmenu['Modifiers']['Item']; - //проверка целостности меню - $errors = []; - $error_counter = 0; - foreach ($MenuItems as $key => $MenuItem) { - $folder_trigger = $MenuItem['@attributes']['isGroop'] + 0; - if ($folder_trigger == 0) { - if ($MenuItem['@attributes']['CodePrinter'] == ' ' || $MenuItem['@attributes']['CodePrinter'] == '0') { - $error_counter = $error_counter + 1; - array_push($errors, 'Отсутствует место хранения у товара ' . $MenuItem['@attributes']['Name']); - } else { - $dish_code_printer = $MenuItem['@attributes']['CodePrinter'] + 0; - } - $dish_code = $MenuItem['@attributes']['Code'] + 0; - $printer_trigger = 0; - $units_trigger = 0; - foreach ($Printers as $key => $printer) { - $printer_code = $printer['@attributes']['Code'] + 0; - if ($printer_code == $dish_code_printer) { - $printer_trigger = $printer_trigger + 1; - } - } - if ($printer_trigger == 0) { - $error_counter = $error_counter + 1; - array_push($errors, 'Место хранения для товара ' . $MenuItem['@attributes']['Name'] . ' не найдено'); - } - foreach ($Units_Dishes as $key => $Unit) { - $unit_dish_code = $Unit['@attributes']['CodeDishes'] + 0; - if ($unit_dish_code == $dish_code) { - $units_trigger = $units_trigger + 1; - } - } - if ($units_trigger == 0) { - $error_counter = $error_counter + 1; - array_push($errors, 'Порционность для товара ' . $dish['@attributes']['Name'] . ' не найдена'); - } - } - } - //конец проверки целостности меню + //проверка целостности меню + $errors = []; + $error_counter = 0; + foreach ($MenuItems as $key => $MenuItem) { + $folder_trigger = intval($MenuItem['@attributes']['IsGroop']); + if ($folder_trigger == 0) { + $dish_printer_code = 0; + $dish_code = intval($MenuItem['@attributes']['CodeDishes']); + foreach ($Dishes as $key => $Dish) { + if ($dish_code == intval($Dish['@attributes']['Code'])) { + $dish_printer_code = intval($Dish['@attributes']['CodePrinter']); + } + } + if ($dish_printer_code == 0) { + $error_counter = $error_counter + 1; + array_push($errors, 'Отсутствует место хранения у товара ' . $MenuItem['@attributes']['Name']); + } + $printer_trigger = 0; + $units_trigger = 0; + foreach ($Printers as $key => $printer) { + $printer_code = intval($printer['@attributes']['Code']); + if ($printer_code == $dish_printer_code) { + $printer_trigger = $printer_trigger + 1; + } + } + if ($printer_trigger == 0) { + $error_counter = $error_counter + 1; + array_push($errors, 'Место хранения для товара ' . $MenuItem['@attributes']['Name'] . ' не найдено'); + } + foreach ($Units_Dishes as $key => $Unit) { + $unit_dish_code = intval($Unit['@attributes']['CodeDishes']); + if ($unit_dish_code == $dish_code) { + $units_trigger = $units_trigger + 1; + } + } + if ($units_trigger == 0) { + $error_counter = $error_counter + 1; + array_push($errors, 'Порционность для товара ' . $Dish['@attributes']['Name'] . ' не найдена'); + } + } + } + //конец проверки целостности меню + Log::debug('Menu parser errors count: ' . $error_counter); + if ($error_counter == 0) { - if ($error_counter == 0) { - //Menus, Folders, Dishes, Units, Printers, Report Categories, Modifiers + //Menus, Folders, Dishes, Units, Printers, Report Categories, Modifiers - //Start menu parser - $base_menus = Menu::where('is_history', 0)->get(); - foreach ($TypesMenu as $key => $Menu) { - $menu_code = $Menu['@attributes']['Code'] + 0; - $menu_name = $Menu['@attributes']['Name']; - foreach ($base_menus as $key => $base_menu) { - if ($base_menu['code'] == $menu_code) { - $old_menu = Menu::where('is_history', 0) - ->where('code', $base_menu['code']) - ->update(['is_history' => 1]); - } - $new_menu = Menu::upsert([ - ['name' => $menu_name, - 'application_id' => 1, - 'code' => $menu_code, - 'is_history' => 0, - 'is_export' => 1], - ], ['name'], - ['application_id'], - ['code'], - ['is_history'], - ['is_export'] - ); - } - } - //End menu parser + //Start menu parser + Log::debug('Start menu parser'); + $base_menus = Menu::where('is_history', 0)->get(); + $menu_count = Menu::where('is_history', 0)->count(); + if ($menu_count > 0) { + foreach ($base_menus as $key => $base_menu) { + if (count($TypesMenu) > 1) { + foreach ($TypesMenu as $key => $Menu) { + $menu_code = intval($Menu['@attributes']['Code']); + $menu_name = $Menu['@attributes']['Name']; + $create_menu_trigger = 1; + if ($base_menu['code'] == $menu_code && $base_menu['name'] != $menu_name) { + $old_menu = Menu::where('is_history', 0) + ->where('code', $base_menu['code']) + ->first(); + $updMenu = Menu::find($old_menu['id']); + $updMenu->is_history = 1; + $updMenu->save(); + } + if ($base_menu['name'] == $menu_name && $base_menu['code'] == $menu_code) { + $create_menu_trigger = 0; + } + if ($create_menu_trigger == 1) { + $new_menu = Menu::upsert([ + ['name' => $menu_name, + 'application_id' => 1, + 'code' => $menu_code, + 'is_history' => 0, + 'is_export' => 1], + ], ['name'], + ['application_id'], + ['code'], + ['is_history'], + ['is_export'] + ); + } + } + } else { + $menu_code = intval($TypesMenu['@attributes']['Code']); + $menu_name = $TypesMenu['@attributes']['Name']; + $create_menu_trigger = 1; + if ($base_menu['code'] == $menu_code && $base_menu['name'] != $menu_name) { + $old_menu = Menu::where('is_history', 0) + ->where('code', $base_menu['code']) + ->first(); + $updMenu = Menu::find($old_menu['id']); + $updMenu->is_history = 1; + $updMenu->save(); + } + if ($base_menu['name'] == $menu_name && $base_menu['code'] == $menu_code) { + $create_menu_trigger = 0; + } + if ($create_menu_trigger == 1) { + $new_menu = Menu::upsert([ + ['name' => $menu_name, + 'application_id' => 1, + 'code' => $menu_code, + 'is_history' => 0, + 'is_export' => 1], + ], ['name'], + ['application_id'], + ['code'], + ['is_history'], + ['is_export'] + ); + } + } + } + } else { + if (count($TypesMenu) > 1) { + foreach ($TypesMenu as $key => $Menu) { + $menu_code = intval($Menu['@attributes']['Code']); + $menu_name = $Menu['@attributes']['Name']; + $new_menu = Menu::upsert([ + ['name' => $menu_name, + 'application_id' => 1, + 'code' => $menu_code, + 'is_history' => 0, + 'is_export' => 1], + ], ['name'], + ['application_id'], + ['code'], + ['is_history'], + ['is_export'] + ); + } + } else { + $menu_code = intval($TypesMenu['@attributes']['Code']); + $menu_name = $TypesMenu['@attributes']['Name']; + $new_menu = Menu::upsert([ + ['name' => $menu_name, + 'application_id' => 1, + 'code' => $menu_code, + 'is_history' => 0, + 'is_export' => 1], + ], ['name'], + ['application_id'], + ['code'], + ['is_history'], + ['is_export'] + ); + } + } + Log::debug('End menu parser'); + //End menu parser - //Start folders parser - $base_folders = Folders::where('is_history', 0)->get(); - foreach ($MenuItems as $key => $MenuItem) { - $folder_code = $MenuItem['@attributes']['Code'] + 0; - $folder_name = $MenuItem['@attributes']['Name']; - $folder_complex = $MenuItem['@attributes']['Complex'] + 0; - $folder_menu_code = $MenuItem['@attributes']['CodeTypeMenu'] + 0; - $folder_trigger = $MenuItem['@attributes']['isGroop'] + 0; - if ($folder_trigger == 1) { - $folder_code_parent = $MenuItem['@attributes']['CodeParent'] + 0; - $create_folder_trigger = 1; - foreach ($base_folders as $key => $base_folder) { - if ($base_folder['code'] == $folder_code && $base_folder['name'] != $folder_name) { - $old_folder = Folders::where('is_history', 0) - ->where('code', $base_folder['code']) - ->update(['is_history' => 1]); - $create_folder_trigger = 1; - } - if ($base_folder['code'] == $folder_code && $base_folder['name'] == $folder_name) { - $create_folder_trigger = 0; - } - } - if ($create_folder_trigger == 1) { - $new_folder = Folders::upsert([ - ['name' => $folder_name, - 'parent_code' => $folder_code_parent, - 'menu_code' => $folder_menu_code, - 'code' => $folder_code, - 'color' => '', - 'is_history' => 0, - 'is_export' => 1, - 'is_complex' => $folder_complex, - 'is_migrate' => 0, - 'is_p_migrate' => 0, - 'show_on_display' => 0, - 'is_bot_export' => 0, - ], - ], ['name'], - ['parent_code'], - ['menu_code'], - ['code'], - ['color'], - ['is_history'], - ['is_export'], - ['is_complex'], - ['is_migrate'], - ['is_p_migrate'], - ['show_on_display'], - ['is_bot_export'] - ); - } - } - } - //End folders parser + //Start folders parser + Log::debug('Start folders parser'); + $base_folders = Folders::where('is_history', 0)->get(); + $folders_count = Folders::where('is_history', 0)->count(); + if ($folders_count > 0) { + foreach ($MenuItems as $key => $MenuItem) { + $folder_trigger = intval($MenuItem['@attributes']['IsGroop']); + if ($folder_trigger == 1) { + foreach ($base_folders as $key => $base_folder) { + $folder_code = intval($MenuItem['@attributes']['Code']); + $folder_name = $MenuItem['@attributes']['Name']; + $folder_menu_code = intval($MenuItem['@attributes']['CodeTypeMenu']); + $folder_complex = intval($MenuItem['@attributes']['Complex']); + $folder_code_parent = intval($MenuItem['@attributes']['CodeParent']); + $create_folder_trigger = 1; + if ($base_folder['code'] == $folder_code && $base_folder['name'] != $folder_name) { + $old_folder = Folders::where('is_history', 0) + ->where('code', $base_folder['code']) + ->first(); + $updFolder = Folders::find($old_folder['id']); + $updFolder->is_history = 1; + $updFolder->save(); + } + $found_folders = Folders::where('code', $folder_code)->where('name', $folder_name)->where('is_history', 0)->first(); + if (!isset($found_folders)) { + $new_folder = Folders::upsert([ + ['name' => $folder_name, + 'parent_code' => $folder_code_parent, + 'menu_code' => $folder_menu_code, + 'code' => $folder_code, + 'color' => '', + 'is_history' => 0, + 'is_export' => 1, + 'is_complex' => $folder_complex, + 'is_migrate' => 0, + 'is_p_migrate' => 0, + 'show_on_display' => 0, + 'is_bot_export' => 0, + ], + ], ['name'], + ['parent_code'], + ['menu_code'], + ['code'], + ['color'], + ['is_history'], + ['is_export'], + ['is_complex'], + ['is_migrate'], + ['is_p_migrate'], + ['show_on_display'], + ['is_bot_export'] + ); + } + } + } + } + } elseif ($folders_count == 0) { + foreach ($MenuItems as $key => $MenuItem) { + $folder_trigger = intval($MenuItem['@attributes']['IsGroop']); + if ($folder_trigger == 1) { + $folder_code = intval($MenuItem['@attributes']['Code']); + $folder_name = $MenuItem['@attributes']['Name']; + $folder_complex = intval($MenuItem['@attributes']['Complex']); + $folder_menu_code = intval($MenuItem['@attributes']['CodeTypeMenu']); + $folder_code_parent = intval($MenuItem['@attributes']['CodeParent']); + $new_folder = Folders::upsert([ + ['name' => $folder_name, + 'parent_code' => $folder_code_parent, + 'menu_code' => $folder_menu_code, + 'code' => $folder_code, + 'color' => '', + 'is_history' => 0, + 'is_export' => 1, + 'is_complex' => $folder_complex, + 'is_migrate' => 0, + 'is_p_migrate' => 0, + 'show_on_display' => 0, + 'is_bot_export' => 0, + ], + ], ['name'], + ['parent_code'], + ['menu_code'], + ['code'], + ['color'], + ['is_history'], + ['is_export'], + ['is_complex'], + ['is_migrate'], + ['is_p_migrate'], + ['show_on_display'], + ['is_bot_export'] + ); + } + } + } + Log::debug('End folders parser'); + //End folders parser - //Start Dishes - $base_dishes = Dishes::get(); - foreach ($MenuItems as $key => $MenuItem) { - $dish_code = $MenuItem['@attributes']['Code'] + 0; - $folder_trigger = $MenuItem['@attributes']['isGroop'] + 0; - if ($folder_trigger == 0) { - foreach ($base_dishes as $key => $base_dish) { - if ($base_dish['code'] == $dish_code) { + //Start printers parser + Log::debug('Start printers parser'); + $base_printers = Printer::where('is_history', 0)->get(); + $printers_count = Printer::where('is_history', 0)->count(); + if ($printers_count > 0) { + foreach ($Printers as $key => $Printer) { + foreach ($base_printers as $key => $base_printer) { + $printer_code = intval($Printer['@attributes']['Code']); + $printer_name = $Printer['@attributes']['Name']; + if ($base_printer['code'] == $printer_code && $base_printer['name'] != $printer_name) { + $old_printer = Printer::where('is_history', 0) + ->where('code', $base_printer['code']) + ->first(); + $updPrinter = Printer::find($old_printer['id']); + $updPrinter->is_history = 1; + $updPrinter->save(); + } + $found_printers = Printer::where('code', $printer_code)->where('name', $printer_name)->where('is_history', 0)->first(); + if (!isset($found_printers)) { + $new_printer = Printer::upsert([ + ['name' => $printer_name, + 'code' => $printer_code, + 'is_history' => 0, + 'is_export' => 1, + ], + ], ['name'], + ['is_history'], + ['is_export'] + ); + } + } + } + } elseif ($printers_count == 0) { + foreach ($Printers as $key => $Printer) { + $printer_code = intval($Printer['@attributes']['Code']); + $printer_name = $Printer['@attributes']['Name']; + $new_printer = Printer::upsert([ + ['name' => $printer_name, + 'code' => $printer_code, + 'is_history' => 0, + 'is_export' => 1, + ], + ], ['name'], + ['is_history'], + ['is_export'] + ); + } + } + Log::debug('End printers parser'); + //End printers parser - } - } - } - } - //End Dishes - } + //Start Dishes parser + Log::debug('Start dishes parser'); + $dishes_count = Dishes::where('is_history', 0)->count(); + if ($dishes_count > 0) { + Log::debug('Dishes in base: ' . $dishes_count); + foreach ($MenuItems as $MenuItem) { + if ($MenuItem['@attributes']['IsGroop'] == '0') { + //$dish_code = intval($MenuItem['@attributes']['Code']); + $dish_code = intval($MenuItem['@attributes']['CodeDishes']); + $dish_codeDishes = intval($MenuItem['@attributes']['CodeDishes']); + $dish_menu = intval($MenuItem['@attributes']['CodeTypeMenu']); + $dish_name = $MenuItem['@attributes']['Name']; + $dish_folder = intval($MenuItem['@attributes']['CodeParent']); + $dish_price = floatval($MenuItem['@attributes']['Price']); + $dish_special_price = floatval($MenuItem['@attributes']['Cost']); + $dish_real_counter = floatval($MenuItem['@attributes']['Fractional']); + $dish_printer_code = 0; + $dish_modifier = 0; + $dish_description = ''; + foreach ($Dishes as $key => $Dish) { + if ($Dish['@attributes']['isGroop'] == "0") { + $dishCode = intval($Dish['@attributes']['Code']); + if ($dish_codeDishes == $dishCode) { + $dish_printer_code = intval($Dish['@attributes']['CodePrinter']); + $dish_description = $Dish['@attributes']['DescriptionRus']; + } + } + } + if (isset($xmlmenu['Modifiers']['Item'])) { + foreach ($Modifiers as $key => $Modifier) { + if (isset($Modifier['@attributes']['CodeDishes'])) { + $modDishCode = intval($Modifier['@attributes']['CodeDishes']); + if ($dish_codeDishes == $modDishCode) { + $dish_modifier = 1; + } + } + } + } + $base_dish = Dishes::where('legacy_code', $dish_codeDishes) + ->where('code', $dish_code) + ->where('is_history', 0) + ->first(); + if (isset($base_dish)) { + if ($base_dish['legacy_code'] == $dish_codeDishes && ($base_dish['name'] != $dish_name || $base_dish['folder_code'] != $dish_folder || $base_dish['cosht'] != $dish_price || $base_dish['real_cosht'] != $dish_special_price || $base_dish['real_count'] != $dish_real_counter || $base_dish['printer_code'] != $dish_printer_code)) { + $old_dish = Dishes::where('is_history', 0) + ->where('legacy_code', $base_dish['legacy_code']) + ->where('code', $dish_code) + ->first(); + $updDish = Dishes::find($old_dish['id']); + $updDish->is_history = 1; + $updDish->save(); + Dishes::upsert([ + ['code' => $dish_code, + 'menu_code' => $dish_menu, + 'name' => $dish_name, + 'folder_code' => $dish_folder, + 'cosht' => $dish_price, + 'real_cosht' => $dish_special_price, + 'real_count' => $dish_real_counter, + 'printer_code' => $dish_printer_code, + 'legacy_code' => $dish_codeDishes, + 'is_serving' => 0, + 'color' => '', + 'is_history' => 0, + 'is_export' => 1, + 'is_modifier' => $dish_modifier, + 'barcode' => '', + 'image' => '', + 'description' => $dish_description, + 'is_migrate' => 0, + 'is_f_migrate' => 0, + 'show_on_display' => 0, + 'is_bot_export' => 0, + ], + ], ['code'], + ['menu_code'], + ['name'], + ['folder_code'], + ['cosht'], + ['real_cosht'], + ['real_count'], + ['printer_code'], + ['legacy_code'], + ['is_serving'], + ['color'], + ['is_history'], + ['is_export'], + ['is_modifier'], + ['barcode'], + ['is_migrate'], + ['is_f_migrate'], + ['show_on_display'], + ['is_bot_export'], + ); + } + } else { + Dishes::upsert([ + ['code' => $dish_code, + 'menu_code' => $dish_menu, + 'name' => $dish_name, + 'folder_code' => $dish_folder, + 'cosht' => $dish_price, + 'real_cosht' => $dish_special_price, + 'real_count' => $dish_real_counter, + 'printer_code' => $dish_printer_code, + 'legacy_code' => $dish_codeDishes, + 'is_serving' => 0, + 'color' => '', + 'is_history' => 0, + 'is_export' => 1, + 'is_modifier' => $dish_modifier, + 'barcode' => '', + 'image' => '', + 'description' => $dish_description, + 'is_migrate' => 0, + 'is_f_migrate' => 0, + 'show_on_display' => 0, + 'is_bot_export' => 0, + ], + ], ['code'], + ['menu_code'], + ['name'], + ['folder_code'], + ['cosht'], + ['real_cosht'], + ['real_count'], + ['printer_code'], + ['legacy_code'], + ['is_serving'], + ['color'], + ['is_history'], + ['is_export'], + ['is_modifier'], + ['barcode'], + ['is_migrate'], + ['is_f_migrate'], + ['show_on_display'], + ['is_bot_export'], + ); + } + } + } + } else { + Log::debug('Dishes in base: ' . $dishes_count); + foreach ($MenuItems as $key => $MenuItem) { + if ($MenuItem['@attributes']['IsGroop'] == '0') { + //$dish_code = intval($MenuItem['@attributes']['Code']); + $dish_code = intval($MenuItem['@attributes']['CodeDishes']); + $dish_codeDishes = intval($MenuItem['@attributes']['CodeDishes']); + $dish_menu = intval($MenuItem['@attributes']['CodeTypeMenu']); + $dish_name = $MenuItem['@attributes']['Name']; + $dish_folder = intval($MenuItem['@attributes']['CodeParent']); + $dish_price = floatval($MenuItem['@attributes']['Price']); + $dish_special_price = floatval($MenuItem['@attributes']['Cost']); + $dish_real_counter = floatval($MenuItem['@attributes']['Fractional']); + $dish_printer_code = 0; + $dish_modifier = 0; + $dish_description = ''; + foreach ($Dishes as $key => $Dish) { + if (isset($Dish['@attributes']['CodePrinter']) && $Dish['@attributes']['CodePrinter'] != ' ') { + if ($dish_codeDishes == intval($Dish['@attributes']['Code'])) { + $dish_printer_code = intval($Dish['@attributes']['CodePrinter']); + $dish_description = $Dish['@attributes']['DescriptionRus']; + } + } + } + if (isset($xmlmenu['Modifiers']['Item'])) { + foreach ($Modifiers as $key => $Modifier) { + if (isset($Modifier['@attributes']['CodeDishes'])) { + if ($dish_codeDishes == intval($Modifier['@attributes']['CodeDishes'])) { + $dish_modifier = 1; + } + } + } + } - /* $check_setting = Settings::where('code', 12)->first(); - $check_setting = $check_setting['value'] + 0; - if ($check_setting == 0) { + Dishes::upsert([ + ['code' => $dish_code, + 'menu_code' => $dish_menu, + 'name' => $dish_name, + 'folder_code' => $dish_folder, + 'cosht' => $dish_price, + 'real_cosht' => $dish_special_price, + 'real_count' => $dish_real_counter, + 'printer_code' => $dish_printer_code, + 'legacy_code' => $dish_codeDishes, + 'is_serving' => 0, + 'color' => '', + 'is_history' => 0, + 'is_export' => 1, + 'is_modifier' => $dish_modifier, + 'barcode' => '', + 'image' => '', + 'description' => $dish_description, + 'is_migrate' => 0, + 'is_f_migrate' => 0, + 'show_on_display' => 0, + 'is_bot_export' => 0, + ], + ], ['code'], + ['menu_code'], + ['name'], + ['folder_code'], + ['cosht'], + ['real_cosht'], + ['real_count'], + ['printer_code'], + ['legacy_code'], + ['is_serving'], + ['color'], + ['is_history'], + ['is_export'], + ['is_modifier'], + ['barcode'], + ['is_migrate'], + ['is_f_migrate'], + ['show_on_display'], + ['is_bot_export'], + ); + } + } + } - */ - return [ - 'status' => 'success', - 'error_counter' => $error_counter, - 'errors' => $errors, - ]; - } + Log::debug('End dishes parser'); + //End Dishes parser + + //Start units parser + Log::debug('Start units parser'); + $base_units = Units::where('is_history', 0)->get(); + $units_count = Units::where('is_history', 0)->count(); + UnitsList::truncate(); + if ($units_count > 0) { + foreach ($base_units as $key => $base_unit) { + foreach ($Units_Dishes as $key => $Unit_Dishes) { + $found_units = Units::where('name', $Unit_Dishes['@attributes']['Name']) + ->where('cof', floatval($Unit_Dishes['@attributes']['Coefficient'])) + ->where('is_history', 0) + ->first(); + if (!isset($found_units)) { + $new_unit = Units::upsert([ + ['menu_id' => 0, + 'cof' => floatval($Unit_Dishes['@attributes']['Coefficient']), + 'name' => $Unit_Dishes['@attributes']['Name'], + ], + ], ['menu_id'], + ['cof'], + ['name'], + ); + } + } + } + } else { + foreach ($Units_Dishes as $key => $Unit_Dishes) { + $found_units = Units::where('name', $Unit_Dishes['@attributes']['Name']) + ->where('cof', floatval($Unit_Dishes['@attributes']['Coefficient'])) + ->where('is_history', 0) + ->first(); + if (!isset($found_units)) { + $new_unit = Units::upsert([ + ['menu_id' => 0, + 'cof' => floatval($Unit_Dishes['@attributes']['Coefficient']), + 'name' => $Unit_Dishes['@attributes']['Name'], + ], + ], ['menu_id'], + ['cof'], + ['name'], + ); + } + } + } + foreach ($Units_Dishes as $key => $Unit_Dishes) { + $dish = Dishes::where('legacy_code', $Unit_Dishes['@attributes']['CodeDishes']) + ->where('is_history', 0) + ->first(); + $unit = Units::where('name', $Unit_Dishes['@attributes']['Name']) + ->where('cof', floatval($Unit_Dishes['@attributes']['Coefficient'])) + ->first(); + UnitsList::upsert([ + [ + 'unit_id' => $unit['id'], + 'dish_id' => $dish['id'] + ], + ], ['unit_id'], + ['dish_id'] + ); + + } + /*foreach ($MenuItems as $menuItem) { + if ($menuItem['@attributes']['IsGroop'] == '0') { + if (isset($menuItem['Units']['Item'])) { + $dish_id = Dishes::where('is_history', 0) + ->where('legacy_code', intval($menuItem['@attributes']['CodeDishes'])) + ->first(); + $dish_id = $dish_id['id']; + $legacy_code = intval($menuItem['@attributes']['CodeUnit']); + if (count($menuItem['Units']['Item']) > 1) { + Log::debug('Menu units count > 1'); + foreach ($menuItem['Units']['Item'] as $unit) { + //$id = intval($unit['@attributes']['Code']); + $id = intval($menuItem['Units']['Item']['@attributes']['Code']); + foreach ($Units_Dishes as $key => $Unit_Dishes) { + if ($Unit_Dishes['@attributes']['CodeDishes'] == $menuItem['@attributes']['CodeDishes']) { + $cof = floatval($Unit_Dishes['@attributes']['Coefficient']); + $unit_name = $Unit_Dishes['@attributes']['Name']; + $unit_id = Units::where('cof', $cof) + ->where('name', $unit_name) + ->first(); + } + } + $found_units_list = UnitsList::where('id', $id) + ->where('unit_id', $unit_id['id']) + ->where('dish_id', $dish_id) + ->where('legacy_code', $legacy_code) + ->first(); + if (!isset($found_units_list)) { + $new_unit_list = UnitsList::upsert([ + [ + 'id' => $id, + 'unit_id' => $unit_id['id'], + 'dish_id' => $dish_id, + 'legacy_code' => $legacy_code, + ], + ], ['id'], + ['unit_id'], + ['dish_id'], + ['legacy_code'], + ); + } + } + } else { + Log::debug('Menu units count < 1'); + $id = intval($menuItem['Units']['Item']['@attributes']['Code']); + foreach ($Units_Dishes as $key => $Unit_Dishes) { + if (intval($Unit_Dishes['@attributes']['CodeDishes']) == intval($menuItem['@attributes']['CodeDishes'])) { + $cof = floatval($Unit_Dishes['@attributes']['Coefficient']); + $unit_name = $Unit_Dishes['@attributes']['Name']; + $unit_id = Units::where('cof', $cof) + ->where('name', $unit_name) + ->first(); + } + } + $found_units_list = UnitsList::where('id', $id) + ->where('unit_id', $unit_id['id']) + ->where('dish_id', $dish_id) + ->where('legacy_code', $legacy_code) + ->first(); + if (!isset($found_units_list)) { + Log::debug('Menu units count < 1'); + $new_unit_list = UnitsList::upsert([ + [ + 'id' => $id, + 'unit_id' => $unit_id['id'], + 'dish_id' => $dish_id, + 'legacy_code' => $legacy_code, + ], + ], ['id'], + ['unit_id'], + ['dish_id'], + ['legacy_code'], + ); + } + } + } + } + }*/ + Log::debug('End units parser'); + //End units parser + + //Start modifiers parser + Log::debug('Start modifiers parser'); + if (isset($xmlmenu['Modifiers']['Item'])) { + $base_modifiers = Modifier::where('is_history', 0)->get(); + $modifiers_count = Modifier::where('is_history', 0)->count(); + $menuCode = Menu::where('is_history', 0)->first(); + ModifiersList::truncate(); + if ($modifiers_count > 0) { + foreach ($base_modifiers as $key => $base_modifier) { + foreach ($Modifiers as $modifier) { + if ($modifier['@attributes']['IsGroop'] == '0') { + $modifier_code = intval($modifier['@attributes']['Code']); + $modifier_name = $modifier['@attributes']['Name']; + $modifier_required = 0; + foreach ($Modifiers as $groupModifier) { + if ($groupModifier['@attributes']['IsGroop'] == '1') { + if ($modifier['@attributes']['CodeParent'] == $groupModifier['@attributes']['Code']) { + $modifier_required = intval($groupModifier['@attributes']['SignRequired']); + } + } + } + if (!isset($modifier['@attributes']['Price'])) { + if ($base_modifier['code'] == $modifier_code && $base_modifier['name'] != $modifier_name) { + $old_FreeModifier = Modifier::where('is_history', 0) + ->where('code', $base_modifier['code']) + ->first(); + $updFreeModifier = Modifier::find($old_FreeModifier['id']); + $updFreeModifier->is_history = 1; + $updFreeModifier->save(); + } + if ($base_modifier['code'] == $modifier_code && $base_modifier['is_required'] != $modifier_required) { + $old_FreeModifier = Modifier::where('is_history', 0) + ->where('code', $base_modifier['code']) + ->first(); + $updFreeModifier = Modifier::find($old_FreeModifier['id']); + $updFreeModifier->is_history = 1; + $updFreeModifier->save(); + } + $findFreeModifier = Modifier::where('is_history', 0) + ->where('code', $modifier_code) + ->where('name', $modifier_name) + ->first(); + if (!isset($findFreeModifier)) { + $newFreeModifier = Modifier::upsert([ + ['name' => $modifier_name, + 'code' => $modifier_code, + 'dish_code' => 0, + 'menu_code' => $menuCode['code'], + 'is_export' => 1, + 'unit_id' => 0, + 'is_required' => $modifier_required, + 'is_history' => 0, + ], + ], ['name'], + ['code'], + ['dish_code'], + ['menu_code'], + ['is_export'], + ['unit_id'], + ['is_required'], + ['is_history'], + ); + } + + } else { + foreach ($Modifiers as $key => $Modifier) { + foreach ($base_modifiers as $base_modifier) { + if (isset($Modifier['@attributes']['CodeDishes'])) { + $modifier_code = intval($Modifier['@attributes']['Code']); + $modifier_name = $Modifier['@attributes']['Name']; + $modifier_dish = intval($Modifier['@attributes']['CodeDishes']); + $modifier_required = 0; + foreach ($Modifiers as $groupModifier) { + if ($groupModifier['@attributes']['IsGroop'] == '1') { + if ($Modifier['@attributes']['CodeParent'] == $groupModifier['@attributes']['Code']) { + $modifier_required = intval($groupModifier['@attributes']['SignRequired']); + } + } + } + if ($base_modifier['code'] !== $modifier_code && $base_modifier['name'] !== $modifier_name) { + $old_PaidModifier = Modifier::where('is_history', 0) + ->where('code', $base_modifier['code']) + ->first(); + $updPaidModifier = Modifier::find($old_PaidModifier['id']); + $updPaidModifier->is_history = 1; + $updPaidModifier->save(); + } + if ($base_modifier['code'] !== $modifier_code && $base_modifier['name'] !== $modifier_name) { + $old_PaidModifier = Modifier::where('is_history', 0) + ->where('code', $base_modifier['code']) + ->first(); + $updPaidModifier = Modifier::find($old_PaidModifier['id']); + $updPaidModifier->is_history = 1; + $updPaidModifier->save(); + } + $modifier_dish_code = Dishes::where('is_history', 0) + ->where('legacy_code', $modifier_dish) + ->first(); //id + $modifier_unit_id = UnitsList::where('is_history', 0) + ->where('legacy_code', $modifier_dish) + ->first();//unit_id + $findPaidModifier = Modifier::where('is_history', 0) + ->where('code', $modifier_code) + ->where('name', $modifier_name) + ->where('dish_code', $modifier_dish_code['id']) + ->where('unit_id', $modifier_unit_id['unit_id']) + ->first(); + if (!isset($findPaidModifier)) { + $newPaidModifier = Modifier::upsert([ + ['name' => $modifier_name, + 'code' => $modifier_code, + 'dish_code' => $modifier_dish_code['id'], + 'menu_code' => $menuCode['code'], + 'is_export' => 1, + 'unit_id' => $modifier_unit_id['unit_id'], + 'is_required' => $modifier_required, + 'is_history' => 0, + ], + ], ['name'], + ['code'], + ['dish_code'], + ['menu_code'], + ['is_export'], + ['unit_id'], + ['is_required'], + ['is_history'], + ); + } + } + } + } + } + } + } + } + } + if ($modifiers_count == 0) { + foreach ($Modifiers as $Modifier) { + if ($Modifier['@attributes']['IsGroop'] == '0') { + $modifier_code = intval($Modifier['@attributes']['Code']); + $modifier_name = $Modifier['@attributes']['Name']; + $modifier_required = 0; + foreach ($Modifiers as $groupModifier) { + if ($groupModifier['@attributes']['IsGroop'] == '1') { + if ($Modifier['@attributes']['CodeParent'] == $groupModifier['@attributes']['Code']) { + $modifier_required = intval($groupModifier['@attributes']['SignRequired']); + } + } + } + if (!isset($Modifier['@attributes']['Price'])) { + $newFreeModifier = Modifier::upsert([ + ['name' => $modifier_name, + 'code' => $modifier_code, + 'dish_code' => 0, + 'menu_code' => $menuCode['code'], + 'is_export' => 1, + 'unit_id' => 0, + 'is_required' => $modifier_required, + 'is_history' => 0, + ], + ], ['name'], + ['code'], + ['dish_code'], + ['menu_code'], + ['is_export'], + ['unit_id'], + ['is_required'], + ['is_history'], + ); + } else { + $modifier_code = intval($Modifier['@attributes']['Code']); + $modifier_name = $Modifier['@attributes']['Name']; + $modifier_dish = intval($Modifier['@attributes']['CodeDishes']); + $modifier_required = 0; + foreach ($Modifiers as $groupModifier) { + if ($groupModifier['@attributes']['IsGroop'] == '1') { + if ($Modifier['@attributes']['CodeParent'] == $groupModifier['@attributes']['Code']) { + $modifier_required = intval($groupModifier['@attributes']['SignRequired']); + } + } + } + $modifier_dish_code = Dishes::where('is_history', 0) + ->where('legacy_code', $modifier_dish) + ->first(); //id + $modifier_unit_id = UnitsList::where('is_history', 0) + ->where('legacy_code', $modifier_dish) + ->first();//unit_id + $newPaidModifier = Modifier::upsert([ + ['name' => $modifier_name, + 'code' => $modifier_code, + 'dish_code' => $modifier_dish_code['id'], + 'menu_code' => $menuCode['code'], + 'is_export' => 1, + 'unit_id' => $modifier_unit_id['unit_id'], + 'is_required' => $modifier_required, + 'is_history' => 0, + ], + ], ['name'], + ['code'], + ['dish_code'], + ['menu_code'], + ['is_export'], + ['unit_id'], + ['is_required'], + ['is_history'], + ); + } + } + } + } + foreach ($MenuItems as $menuItem) { + if (isset($menuItem['Modifiers'])) { + if ($menuItem['@attributes']['IsGroop'] == '0') { + if (count($menuItem['Modifiers']['Item']) > 1) { + $modifier_dish_id = Dishes::where('is_history', 0) + ->where('code', intval($menuItem['@attributes']['Code'])) + ->first(); + $modifier_dish_id = $modifier_dish_id['id']; + foreach ($menuItem['Modifiers']['Item'] as $modifier) { + $modifier_id = Modifier::where('is_history', 0) + ->where('code', intval($modifier['@attributes']['Code'])) + ->first(); + $modifier_id = $modifier_id['id']; + $newModifierList = ModifiersList::upsert([ + ['modifier_id' => $modifier_id, + 'dish_id' => $modifier_dish_id, + ], + ], ['modifier_id'], + ['dish_id'], + ); + } + } else { + $modifier_dish_id = Dishes::where('is_history', 0) + ->where('code', intval($menuItem['@attributes']['Code'])) + ->first(); + $modifier_dish_id = $modifier_dish_id['id']; + $modifier_id = Modifier::where('is_history', 0) + ->where('code', intval($menuItem['Modifiers']['Item']['@attributes']['Code'])) + ->first(); + $modifier_id = $modifier_id['id']; + $newModifierList = ModifiersList::upsert([ + ['modifier_id' => $modifier_id, + 'dish_id' => $modifier_dish_id, + ], + ], ['modifier_id'], + ['dish_id'], + ); + } + } + } + } + } + Log::debug('End modifiers parser'); + //End modifiers parser + } + + return ['status' => 'success', + 'error_counter' => $error_counter, + 'errors' => $errors, + 'json' => $xmlmenu + ]; + } } \ No newline at end of file diff --git a/commands/GETOrderHistory.php b/commands/GETOrderHistory.php index dfade6e..275aecf 100644 --- a/commands/GETOrderHistory.php +++ b/commands/GETOrderHistory.php @@ -12,6 +12,7 @@ use App\Component\Models\Units; use App\Component\Models\UnitsList; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; +use Illuminate\Support\Facades\Log; class GETOrderHistory extends HRCCommand implements HRCCommandInterface { protected $signature = 'getorderhistory'; @@ -26,6 +27,57 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { $merge_trigger = 0; $move_trigger = 0; + function json_validate($string) + { + // decode the JSON data + $result = json_decode(utf8_encode($string), true, JSON_INVALID_UTF8_SUBSTITUTE); + + // switch and check possible JSON errors + switch (json_last_error()) { + case JSON_ERROR_NONE: + $error = ''; // JSON is valid // No error has occurred + break; + case JSON_ERROR_DEPTH: + $error = 'The maximum stack depth has been exceeded.'; + break; + case JSON_ERROR_STATE_MISMATCH: + $error = 'Invalid or malformed JSON.'; + break; + case JSON_ERROR_CTRL_CHAR: + $error = 'Control character error, possibly incorrectly encoded.'; + break; + case JSON_ERROR_SYNTAX: + $error = 'Syntax error, malformed JSON.'; + break; + // PHP >= 5.3.3 + case JSON_ERROR_UTF8: + $error = 'Malformed UTF-8 characters, possibly incorrectly encoded.'; + break; + // PHP >= 5.5.0 + case JSON_ERROR_RECURSION: + $error = 'One or more recursive references in the value to be encoded.'; + break; + // PHP >= 5.5.0 + case JSON_ERROR_INF_OR_NAN: + $error = 'One or more NAN or INF values in the value to be encoded.'; + break; + case JSON_ERROR_UNSUPPORTED_TYPE: + $error = 'A value of a type that cannot be encoded was given.'; + break; + default: + $error = 'Unknown JSON error occured.'; + break; + } + + if ($error !== '') { + // throw the Exception or exit // or whatever :) + return false; + } + + // everything is OK + return true; + } + function dishName($data) { $dish_name = Dishes::where('code', $data)->where('is_history', 0)->first(); if ($dish_name) { @@ -206,7 +258,12 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { $action_name = $action_name . ': ' . $item['value']; $slice_items = []; if ($item['more']) { - $slice_order_items = json_decode(utf8_encode($item['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + if (json_validate($item['more'])) { + $slice_order_items = json_decode(utf8_encode($item['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + } else { + $slice_order_items = json_decode(utf8_encode(base64_decode($item['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE); + } + //$slice_order_items = json_decode(utf8_encode($item['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); $slice_order_items = $slice_order_items['items']; $slice_order = $item['value']; foreach ($slice_order_items as $key => $slice_order_item) { @@ -227,7 +284,12 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { foreach ($item_actions as $key => $item_action) { if ($item_action['more']) { $merge_items_before = $merge_items_after = $merge_items = $merge_order_item_before = $merge_order_item_after = $merged_items = []; - $merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + if (json_validate($item['more'])) { + $merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); + } else { + $merge_order_items = json_decode(utf8_encode(base64_decode($item_action['more'])), true, JSON_INVALID_UTF8_SUBSTITUTE); + } + //$merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE); $merge_order_items_before = $merge_order_items['before']['items']; $merge_order_items_after = $merge_order_items['after']['items']; foreach ($merge_order_items_before as $key => $merge_order_item_before) { diff --git a/commands/POSTClient.php b/commands/POSTClient.php index 7722c96..372e561 100644 --- a/commands/POSTClient.php +++ b/commands/POSTClient.php @@ -10,6 +10,7 @@ use App\Component\Models\ClientsGroup; use App\Component\Models\ClientsPhone; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; +use Illuminate\Support\Facades\Log; class POSTClient extends HRCCommand implements HRCCommandInterface { protected $signature = 'postclient'; @@ -18,18 +19,17 @@ class POSTClient extends HRCCommand implements HRCCommandInterface { if (isset($input['task']) && isset($input['id'])) { if ($input['task'] == 'update') { + $phone = urldecode($input['phone']); $client = Client::find($input['id']); $client->name = urldecode($input['name']); $client->unloaded = 0; - - $clientGroup = ClientsGroup::find($input['group_id']); + $clientGroup = ClientsGroup::where('id', $input['group_id'])->first(); $client->group_id = urldecode($clientGroup['code']); - $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first(); if ($clientPhone) { $clientPhone = ClientsPhone::find($clientPhone['id']); - if ($input['phone'] !== '') { - if (substr($input['phone'], 0, 1) == '+') { + if ($phone !== '' && $phone !== '+375 ( ) - -') { + if (substr($phone, 0, 1) == '+') { $phoneData = urldecode($input['phone']); } else { $phoneData = urldecode($input['phone']); @@ -74,8 +74,7 @@ class POSTClient extends HRCCommand implements HRCCommandInterface { $clientBarcode->save(); } - $client->save(); - $clientGroup->save(); + $client->save(); return [ 'status' => 'success', diff --git a/commands/POSTClientGroup.php b/commands/POSTClientGroup.php index 83fc412..8d24cef 100644 --- a/commands/POSTClientGroup.php +++ b/commands/POSTClientGroup.php @@ -15,7 +15,7 @@ class POSTClientGroup extends HRCCommand implements HRCCommandInterface { if (isset($input['task']) && isset($input['id'])) { if ($input['task'] == 'update') { $group = ClientsGroup::find($input['id']); - $group->name = $input['name']; + $group->name = urldecode($input['name']); $group->save(); return [ diff --git a/commands/POSTRestoreShift.php b/commands/POSTRestoreShift.php index 1e1a0d4..2c8909e 100644 --- a/commands/POSTRestoreShift.php +++ b/commands/POSTRestoreShift.php @@ -15,6 +15,7 @@ use App\Component\Models\Shifts; use App\Component\Models\TerminalUpdate; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; +use Illuminate\Support\Facades\Log; class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { protected $signature = 'postrestoreshift'; @@ -37,45 +38,65 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { } $shift_id = $input['shift_id']; $cache_dir = __DIR__ . "\\..\\..\\..\\Cache\\"; - dirDel($cache_dir); + $nowTime = time(); $update = true; - $alph = [ - "А", - "Б", - "В", - "Г", - "Д", - "Е", - "Ё", - "Ж", - "З", - "И", - "Й", - "К", - "Л", - "М", - "Н", - "О", - "П", - "Р", - "С", - "Т", - "У", - "Ф", - "Х", - "Ц", - "Ч", - "Ш", - "Щ", - "Ъ", - "Ы", - "Ь", - "Э", - "Ю", - "Я", - ]; + + function decode_text($data) { + $alph = [ + "А", "Б", "В", "Г", "Д", + "Е", "Ё", "Ж", "З", "И", + "Й", "К", "Л", "М", "Н", + "О", "П", "Р", "С", "Т", + "У", "Ф", "Х", "Ц", "Ч", + "Ш", "Щ", "Ъ", "Ы", "Ь", + "Э", "Ю", "Я", + "а", "б", "в", "г", "д", + "е", "ё", "ж", "з", "и", + "й", "к", "л", "м", "н", + "о", "п", "р", "с", "т", + "у", "ф", "х", "ц", "ч", + "ш", "щ", "ъ", "ы", "ь", + "э", "ю", "я", + ]; + + foreach ($alph as $key => $letter) { + $haystack = mb_convert_encoding($data, "CP1251", "UTF-8"); + $needle = $letter; + $pos = strripos($haystack, $needle); + if ($pos === false) { + $after_conv = false; + } else { + $after_conv = true; + break; + } + } + + if (!$after_conv) { + foreach ($alph as $key => $letter) { + $haystack = $data; + $needle = $letter; + $pos = strripos($haystack, $needle); + if ($pos === false) { + $before_conv = false; + } else { + $before_conv = true; + break; + } + } + } + + if ($after_conv) { + $retval = mb_convert_encoding($data, "CP1251", "UTF-8"); + } elseif ($before_conv) { + $retval = $data; + } else { + $retval = $data; + } + return $retval; + } + $exchange_shifts = ExchangeShifts::where('id', '=', $shift_id)->first(); $exchange_orders = ExchangeOrders::where('shift_id', '=', $shift_id)->get(); $exchange_items = ExchangeItems::where('shift_id', '=', $shift_id)->get(); @@ -109,6 +130,7 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { //clear shift_online_orders ShiftOnlineOrders::truncate(); + Log::debug('ShiftOnlineOrders cleaned'); foreach ($exchange_orders as $key => $exchange_order) { $shift_online_order = new ShiftOnlineOrders; $shift_online_order->cash = $exchange_order["cash"]; @@ -141,45 +163,8 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { $shift_online_order->opened = $exchange_order["opened"]; $shift_online_order->order_sum = $exchange_order["order_sum"]; $shift_online_order->params_code = $exchange_order["params_id"]; - - $place_name_bd = $exchange_order["place_name"]; - $place_name_d = mb_convert_encoding($place_name_bd, "CP1251", "UTF-8"); - - foreach ($alph as $key => $letter) { - $haystack = $place_name_d; - $needle = $letter; - $pos = strripos($haystack, $needle); - if ($pos === false) { - $after_conv = false; - } else { - $after_conv = true; - break; - } - } - - if (!$after_conv) { - foreach ($alph as $key => $letter) { - $haystack = $place_name_bd; - $needle = $letter; - $pos = strripos($haystack, $needle); - if ($pos === false) { - $before_conv = false; - } else { - $before_conv = true; - break; - } - } - } - - if ($after_conv) { - $place_name_decoded = $place_name_d; - } elseif ($before_conv) { - $place_name_decoded = $place_name_bd; - } else { - $place_name_decoded = $place_name_bd; - } - - $shift_online_order->place_name = $place_name_decoded; + $shift_online_order->place_name = mb_convert_encoding(decode_text($exchange_order["place_name"]), 'UTF-8', 'UTF-8'); + log::debug(decode_text($exchange_order["place_name"])); $shift_online_order->presale = $exchange_order["presale"]; $shift_online_order->sale_sum = $exchange_order["sale_sum"]; $shift_online_order->self = $exchange_order["self"]; @@ -193,6 +178,7 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { } ShiftOnlineItems::truncate(); + Log::debug('ShiftOnlineItems cleaned'); foreach ($exchange_items as $key => $exchange_item) { $shift_online_item = new ShiftOnlineItems; $shift_online_item->code = $exchange_item["code"]; @@ -218,6 +204,7 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { } ShiftOnlineActions::truncate(); + Log::debug('ShiftOnlineActions cleaned'); foreach ($exchange_actions as $key => $exchange_action) { $shift_online_action = new ShiftOnlineActions; $shift_online_action->type_action = $exchange_action["action_type"]; @@ -235,6 +222,7 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { } ShiftOnlineDeleted::truncate(); + Log::debug('ShiftOnlineDeleted cleaned'); foreach ($exchange_deleted as $key => $exchange_deleted_item) { $shift_online_deleted_item = new ShiftOnlineDeleted; $shift_online_deleted_item->code = $exchange_deleted_item["code"]; @@ -253,6 +241,7 @@ class POSTRestoreShift extends HRCCommand implements HRCCommandInterface { $exc_time = time(); $diff_time = $exc_time - $nowTime; $terminal_online = TerminalUpdate::where('method', 'online')->where('terminal_id', $exchange_shifts['terminal_id'])->first(); + dirDel($cache_dir); return [ 'status' => 'success', 'message' => 'Данные автоматически синхронизируются с POS-системой ' . $terminal_online['next_at'], diff --git a/composer.json b/composer.json index 353c661..8a6f847 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,9 @@ { "name": "hrc-admin/hello-world", - "version": "2.19", + "version": "2.21", "require": { - "horeca/admin-php-module-core": "dev-master" + "horeca/admin-php-module-core": "dev-master", + "guzzlehttp/guzzle": "^7.4" }, "repositories": [ { @@ -10,4 +11,4 @@ "url": "https://git.hrc.by/horeca/admin-php-module-core" } ] -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index bfcc9ad..0ff5c77 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bc6a3225c331314f6774aa596a35b169", + "content-hash": "12bbb4dae295b5fc8e876ec17a6ff017", "packages": [ { "name": "brick/math", @@ -810,6 +810,329 @@ ], "time": "2020-04-13T13:17:36+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "7.4.5", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5", + "guzzlehttp/psr7": "^1.9 || ^2.4", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-curl": "*", + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.4-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.4.5" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2022-06-20T22:16:13+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "1.5.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.5.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2021-10-22T20:56:57+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "13388f00956b1503577598873fffb5ae994b5737" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/13388f00956b1503577598873fffb5ae994b5737", + "reference": "13388f00956b1503577598873fffb5ae994b5737", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.4.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2022-06-20T21:43:11+00:00" + }, { "name": "horeca/admin-php-module-core", "version": "dev-master", @@ -2869,6 +3192,166 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "psr/log", "version": "1.1.3", @@ -2970,6 +3453,50 @@ }, "time": "2017-10-23T01:57:42+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "ramsey/collection", "version": "1.1.3", diff --git a/database/migrations/2022_06_24_002213_add_columns_to_units_list_and_units.php b/database/migrations/2022_06_24_002213_add_columns_to_units_list_and_units.php new file mode 100644 index 0000000..9873a06 --- /dev/null +++ b/database/migrations/2022_06_24_002213_add_columns_to_units_list_and_units.php @@ -0,0 +1,43 @@ +tinyInteger('is_history')->nullable()->default(0); + }); + } + + if (!Schema::hasColumn('modifiers', 'is_history')) { + Schema::table('modifiers', function (Blueprint $table) { + $table->tinyInteger('is_history')->nullable()->default(0); + }); + } + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::table('units', function (Blueprint $table) { + $table->dropColumn('is_history'); + }); + Schema::table('modifiers', function (Blueprint $table) { + $table->dropColumn('is_history'); + }); + + } +} diff --git a/models/ModifiersList.php b/models/ModifiersList.php new file mode 100644 index 0000000..839d96c --- /dev/null +++ b/models/ModifiersList.php @@ -0,0 +1,15 @@ +