From dcd0e72d1fe17c5340a2217fb0e25abd0685c812 Mon Sep 17 00:00:00 2001 From: miroman-afk <74014189+miroman-afk@users.noreply.github.com> Date: Thu, 22 Sep 2022 16:34:02 +0300 Subject: [PATCH] v.2.22 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Редактор карты зала Электронные заказы Отчет по удалениям --- .gitignore | 1 + commands/GETDataReport.php | 1016 +++++++++-------- commands/GETDiscountItems.php | 3 + commands/GETOrder.php | 87 +- commands/GETOrderHistory.php | 52 +- commands/GETRoomMap.php | 51 + commands/GETRoomMapFile.php | 101 ++ commands/POSTOrderItem.php | 4 +- commands/POSTRoomMap.php | 221 ++++ composer.json | 2 +- ...08_03_132213_add_columns_to_order_item.php | 35 + ...and_item_price_in_order_items_to_float.php | 39 + ..._update_total_price_in_orders_to_float.php | 31 + .../2022_08_08_120748_create_places_table.php | 35 + ...08_08_130748_create_place_tables_table.php | 67 ++ ...022_09_22_140748_update_core_interface.php | 64 ++ database/seeders/AddStaffRights.php | 33 + database/seeders/AddUserRights.php | 33 + forUpdate/toDirectives/angular-drag-resize.js | 187 +++ forUpdate/toDirectives/context-menu.js | 144 +++ forUpdate/toWebApp/index.html | 121 ++ models/Dishes.php | 31 + models/Places.php | 22 + models/Reasons.php | 24 + models/Staff.php | 15 + models/StaffRights.php | 19 + models/Tables.php | 22 + module.ini | 4 +- web/controllers/orders.js | 23 +- web/controllers/reports.js | 2 +- web/controllers/roommap.js | 235 ++++ web/controllers/shifts.js | 2 +- web/menu_min.js | 11 +- web/routes_min.js | 8 + web/views/orders/createnewclient.html | 6 +- web/views/orders/edit.html | 14 +- web/views/orders/orders.html | 3 + web/views/orders/selectitemcount.html | 40 +- web/views/orders/selectmenuitem — old.html | 104 -- web/views/orders/selectmenuitem.html | 89 +- web/views/reports/items/deleted.html | 11 +- web/views/roommap/index.html | 126 ++ web/views/roommap/items/edit.html | 70 ++ 43 files changed, 2481 insertions(+), 727 deletions(-) create mode 100644 commands/GETRoomMap.php create mode 100644 commands/GETRoomMapFile.php create mode 100644 commands/POSTRoomMap.php create mode 100644 database/migrations/2022_08_03_132213_add_columns_to_order_item.php create mode 100644 database/migrations/2022_08_03_154519_update_item_count_and_item_price_in_order_items_to_float.php create mode 100644 database/migrations/2022_08_03_154923_update_total_price_in_orders_to_float.php create mode 100644 database/migrations/2022_08_08_120748_create_places_table.php create mode 100644 database/migrations/2022_08_08_130748_create_place_tables_table.php create mode 100644 database/migrations/2022_09_22_140748_update_core_interface.php create mode 100644 database/seeders/AddStaffRights.php create mode 100644 database/seeders/AddUserRights.php create mode 100644 forUpdate/toDirectives/angular-drag-resize.js create mode 100644 forUpdate/toDirectives/context-menu.js create mode 100644 forUpdate/toWebApp/index.html create mode 100644 models/Places.php create mode 100644 models/Reasons.php create mode 100644 models/StaffRights.php create mode 100644 models/Tables.php create mode 100644 web/controllers/roommap.js delete mode 100644 web/views/orders/selectmenuitem — old.html create mode 100644 web/views/roommap/index.html create mode 100644 web/views/roommap/items/edit.html diff --git a/.gitignore b/.gitignore index 8fcd0f5..7ee39a6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ temp/ vendor/ build.zip +places.xml diff --git a/commands/GETDataReport.php b/commands/GETDataReport.php index 987b003..3fbc8bb 100644 --- a/commands/GETDataReport.php +++ b/commands/GETDataReport.php @@ -2,18 +2,23 @@ namespace App\Commands; +use App\Component\Models\Dishes; use App\Component\Models\ExchangeActions; use App\Component\Models\ExchangeDeleted; use App\Component\Models\ExchangeOrders; use App\Component\Models\ExchangeShifts; +use App\Component\Models\Reasons; +use App\Component\Models\Report; use App\Component\Models\Staff; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class GETDataReport extends HRCCommand implements HRCCommandInterface { - protected $signature = 'getdatareport'; +class GETDataReport extends HRCCommand implements HRCCommandInterface +{ + protected $signature = 'getdatareport'; - public function command($input, $output = null) { + public function command($input, $output = null) + { function validate_json($string) { @@ -66,490 +71,567 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface { return true; } - function data_decode($data) { - $alph = [ - "А", "Б", "В", "Г", "Д", - "Е", "Ё", "Ж", "З", "И", - "Й", "К", "Л", "М", "Н", - "О", "П", "Р", "С", "Т", - "У", "Ф", "Х", "Ц", "Ч", - "Ш", "Щ", "Ъ", "Ы", "Ь", - "Э", "Ю", "Я", - "а", "б", "в", "г", "д", - "е", "ё", "ж", "з", "и", - "й", "к", "л", "м", "н", - "о", "п", "р", "с", "т", - "у", "ф", "х", "ц", "ч", - "ш", "щ", "ъ", "ы", "ь", - "э", "ю", "я", - ]; + function data_decode($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; - } - } + 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) { + 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; - } + if ($after_conv) { + $retval = mb_convert_encoding($data, "CP1251", "UTF-8"); + } elseif ($before_conv) { + $retval = $data; + } else { + $retval = $data; + } + return $retval; + } - function staffName($data) { - $staff_name = Staff::where('code', $data)->where('is_history', 0)->first(); - if ($staff_name) { - $staff_name = $staff_name['name']; - } else { - $staff_name = Staff::where('code', $data)->where('is_history', 1)->first(); - if ($staff_name) { - $staff_name = $staff_name['name']; - } else { - $staff_name = 'Связанный персонал не найден'; - } - } - return $staff_name; - } + function staffName($data) + { + $staff_name = Staff::where('code', $data)->where('is_history', 0)->first(); + if ($staff_name) { + $staff_name = $staff_name['name']; + } else { + $staff_name = Staff::where('code', $data)->where('is_history', 1)->first(); + if ($staff_name) { + $staff_name = $staff_name['name']; + } else { + $staff_name = 'Связанный персонал не найден'; + } + } + return $staff_name; + } - $reportType = $input['type']; - //merge, slice, move - if (isset($reportType)) { - //merge - if ($reportType == 'merge') { - $merged_order_items = []; - $orders = ExchangeActions::select('order_code')->where('shift_id', $input['shift_id'])->groupBy('order_code')->get(); - foreach ($orders as $key => $order) { - $actions = ExchangeActions::where('order_code', $order['order_code'])->where('shift_id', $input['shift_id'])->orderBy('time', 'asc')->get(); - foreach ($actions as $key => $item) { - if ($item['action_type'] == 31) { - $merge_order = $item['value']; - $item_actions = ExchangeActions::where('order_code', $item['value'] + 0) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 32) - ->get(); - foreach ($item_actions as $key => $item_action) { - 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 = []; - if (validate_json($item['more'])) { + $reportType = $input['type']; + //merge, slice, move + if (isset($reportType)) { + //merge + if ($reportType == 'merge') { + $merged_order_items = []; + $orders = ExchangeActions::select('order_code')->where('shift_id', $input['shift_id'])->groupBy('order_code')->get(); + foreach ($orders as $key => $order) { + $actions = ExchangeActions::where('order_code', $order['order_code'])->where('shift_id', $input['shift_id'])->orderBy('time', 'asc')->get(); + foreach ($actions as $key => $item) { + if ($item['action_type'] == 31) { + $merge_order = intval($item['value']); + $item_actions = ExchangeActions::where('order_code', $merge_order) + ->where('shift_id', intval($input['shift_id'])) + ->where('action_type', 32) + ->get(); + + foreach ($item_actions as $key => $item_action) { + 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 = []; + + if (validate_json($item_action['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) { - $merge_items_before[] = array('id' => $key + 1, - 'code' => $merge_order_item_before['id'], - 'name' => $merge_order_item_before['name'], - 'count' => $merge_order_item_before['count'], - 'sale_price' => $merge_order_item_before['sale_price']); - } - foreach ($merge_order_items_after as $key => $merge_order_item_after) { - $merge_items_after[] = array('id' => $key + 1, - 'code' => $merge_order_item_after['id'], - 'name' => $merge_order_item_after['name'], - 'count' => $merge_order_item_after['count'], - 'sale_price' => $merge_order_item_after['sale_price']); - } - foreach ($merge_order_items_after as $key => $merge_order_item_after) { - if (!in_array(array('id' => $key + 1, - 'code' => $merge_order_item_after['id'], - 'name' => $merge_order_item_after['name'], - 'count' => $merge_order_item_after['count'], - 'sale_price' => $merge_order_item_after['sale_price']), $merge_items_before, true)) { - $merged_items[] = array('code' => $merge_order_item_after['id'], - 'name' => $merge_order_item_after['name'], - 'count' => $merge_order_item_after['count'], - 'sale_price' => $merge_order_item_after['sale_price']); - } - } - foreach ($merged_items as $key => $merged_item) { - $merge_items[] = array('id' => $key + 1, - 'code' => $merged_item['code'], - 'name' => $merged_item['name'], - 'count' => $merged_item['count'], - 'sale_price' => $merged_item['sale_price']); - } - $staff_name = staffName($item['who']); - $start_order_place = ExchangeActions::where('order_code', $item['order_code'])->where('action_type', 45)->where('shift_id', $input['shift_id'])->first(); - $start_order_place = data_decode($start_order_place['value']); - $end_order_place = ExchangeActions::where('order_code', $merge_order + 0)->where('action_type', 45)->where('shift_id', $input['shift_id'])->first(); - $end_order_place = data_decode($end_order_place['value']); - $merged_order_items[] = array('start_order' => $item['order_code'], 'end_order' => $merge_order + 0, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'start_order_place' => $start_order_place, 'end_order_place' => $end_order_place, 'merge_order_items' => $merge_order_items, 'items' => $merge_items); - } - } - } - } - } - return [ - 'status' => 'success', - 'shift_id' => $input['shift_id'], - 'count' => count($merged_order_items), - 'data' => $merged_order_items, - ]; - } - //slice - if ($reportType == 'slice') { - $sliced_order_data = []; - $orders = ExchangeActions::select('order_code')->where('shift_id', $input['shift_id'])->groupBy('order_code')->get(); - $action_count = ExchangeActions::where('shift_id', $input['shift_id'])->where('action_type', 35)->count(); - if ($action_count > 0) { - foreach ($orders as $key => $order) { - $actions = ExchangeActions::where('order_code', $order['order_code'])->where('shift_id', $input['shift_id'])->where('action_type', 35)->orderBy('time', 'asc')->get(); - foreach ($actions as $key => $action) { - $value = $action['value']; - $codeOrder = $action['order_code']; + $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) { + $merge_items_before[] = array('id' => $key + 1, + 'code' => $merge_order_item_before['id'], + 'name' => $merge_order_item_before['name'], + 'count' => $merge_order_item_before['count'], + 'sale_price' => $merge_order_item_before['sale_price']); + } + foreach ($merge_order_items_after as $key => $merge_order_item_after) { + $merge_items_after[] = array('id' => $key + 1, + 'code' => $merge_order_item_after['id'], + 'name' => $merge_order_item_after['name'], + 'count' => $merge_order_item_after['count'], + 'sale_price' => $merge_order_item_after['sale_price']); + } + foreach ($merge_order_items_after as $key => $merge_order_item_after) { + if (!in_array(array('id' => $key + 1, + 'code' => $merge_order_item_after['id'], + 'name' => $merge_order_item_after['name'], + 'count' => $merge_order_item_after['count'], + 'sale_price' => $merge_order_item_after['sale_price']), $merge_items_before, true)) { + $merged_items[] = array('code' => $merge_order_item_after['id'], + 'name' => $merge_order_item_after['name'], + 'count' => $merge_order_item_after['count'], + 'sale_price' => $merge_order_item_after['sale_price']); + } + } + foreach ($merged_items as $key => $merged_item) { + $merge_items[] = array('id' => $key + 1, + 'code' => $merged_item['code'], + 'name' => $merged_item['name'], + 'count' => $merged_item['count'], + 'sale_price' => $merged_item['sale_price']); + } + $staff_name = staffName($item['who']); + $start_order_place = ExchangeActions::where('order_code', $item['order_code'])->where('action_type', 45)->where('shift_id', $input['shift_id'])->first(); + $start_order_place = data_decode($start_order_place['value']); + $end_order_place = ExchangeActions::where('order_code', $merge_order + 0)->where('action_type', 45)->where('shift_id', $input['shift_id'])->first(); + $end_order_place = data_decode($end_order_place['value']); + $merged_order_items[] = array('start_order' => $item['order_code'], 'end_order' => $merge_order + 0, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'start_order_place' => $start_order_place, 'end_order_place' => $end_order_place, 'merge_order_items' => $merge_order_items, 'items' => $merge_items); + } + } + } + } + } + return [ + 'status' => 'success', + 'shift_id' => $input['shift_id'], + 'count' => count($merged_order_items), + 'data' => $merged_order_items, + ]; + } + //slice + if ($reportType == 'slice') { + $sliced_order_data = []; + $orders = ExchangeActions::select('order_code')->where('shift_id', $input['shift_id'])->groupBy('order_code')->get(); + $action_count = ExchangeActions::where('shift_id', $input['shift_id'])->where('action_type', 35)->count(); + if ($action_count > 0) { + foreach ($orders as $key => $order) { + $actions = ExchangeActions::where('order_code', $order['order_code'])->where('shift_id', $input['shift_id'])->where('action_type', 35)->orderBy('time', 'asc')->get(); + foreach ($actions as $key => $action) { + $value = $action['value']; + $codeOrder = $action['order_code']; 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(); + $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(); 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); - } - } - } - return [ - 'status' => 'success', - 'shift_id' => $input['shift_id'], - 'count' => $action_count, - 'data' => $sliced_order_data, - ]; - } + $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); + } + } + } + return [ + 'status' => 'success', + 'shift_id' => $input['shift_id'], + 'count' => $action_count, + 'data' => $sliced_order_data, + ]; + } - if ($reportType == 'move') { - $orders = ExchangeActions::select('order_code')->where('shift_id', $input['shift_id'])->groupBy('order_code')->get(); - foreach ($orders as $key => $order) { - $actions = ExchangeActions::where('order_code', $order['order_code'])->where('shift_id', $input['shift_id'])->orderBy('time', 'asc')->get(); - foreach ($actions as $key => $item) { - if ($item['action_type'] == 39) { - $staff_name_to = staffName($item['who']); - $time_to = date('d.m.Y H:i:s', strtotime($item['time'])); - $data_from = ExchangeActions::where('order_code', $item['order_code'])->where('shift_id', $input['shift_id'])->where('action_type', 45)->first(); - $staff_name_from = staffName($data_from['who']); - $time_from = date('d.m.Y H:i:s', strtotime($data_from['time'])); - $moved_order_data[] = array('order' => $item['order_code'], 'move_from' => data_decode($data_from['value']), 'move_from_staff' => $staff_name_from, 'move_from_time' => $time_from, 'move_to' => data_decode($item['value']), 'move_to_staff' => $staff_name_to, 'move_to_time' => $time_to); - } - } - } - return [ - 'status' => 'success', - 'count' => count($moved_order_data), - 'data' => $moved_order_data, - ]; - } - if ($reportType == 'staff') { - if (isset($input['shift_id'])) { - $staff = $staff_data = []; - $countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0; - $openedOrders = ExchangeOrders::select('who_open') - ->where('shift_id', $input['shift_id']) - ->where('who_open', '>', 0) - ->groupBy('who_open') - ->get(); - $closedOrders = ExchangeOrders::select('who_close') - ->where('shift_id', $input['shift_id']) - ->where('who_close', '>', 0) - ->groupBy('who_close') - ->get(); - foreach ($openedOrders as $key => $openedOrder) { - array_push($staff, $openedOrder['who_open']); - } - foreach ($closedOrders as $key => $closedOrder) { - array_push($staff, $closedOrder['who_close']); - } - $staff = array_unique($staff); - foreach ($staff as $key => $value) { - $staffId = $value + 0; - $name = staffName($staffId); - $code = $staffId; - $countOpened = ExchangeOrders::where('who_open', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->count(); - $countClosed = ExchangeOrders::where('who_close', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->count(); - $sumOpened = ExchangeOrders::where('who_open', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->sum('order_sum'); - $sumClosed = ExchangeOrders::where('who_close', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->sum('order_sum'); - $inputCount = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 49) - ->count(); - $inputSum = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 49) - ->sum('value'); - $outputCount = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 50) - ->count(); - $outputSum = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 50) - ->sum('value'); - $annulCount = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 43) - ->count(); - $annulOrders = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 43) - ->get(); - foreach ($annulOrders as $key => $annulOrder) { - $annulOrderSum = ExchangeOrders::where('code', $annulOrder['order_code']) - ->where('shift_id', $input['shift_id']) - ->first(); - $annulSum = $annulSum + $annulOrderSum['order_sum']; - } - $returnCount = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 19) - ->count(); - $returnOrders = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 19) - ->get(); - foreach ($returnOrders as $key => $returnOrder) { - $returnOrderSum = ExchangeOrders::where('code', $returnOrder['order_code']) - ->where('shift_id', $input['shift_id']) - ->first(); - $returnSum = $returnSum + abs($returnOrderSum['order_sum']); - } - $deletedCount = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 8) - ->where('reason', '>', 0) - ->count(); - $deletedOrders = ExchangeActions::where('who', $staffId) - ->where('shift_id', $input['shift_id']) - ->where('action_type', 8) - ->where('reason', '>', 0) - ->get(); - foreach ($deletedOrders as $key => $deletedOrder) { - $deletedOrdersSum = ExchangeDeleted::where('order_code', $deletedOrder['order_code']) - ->where('shift_id', $input['shift_id']) - ->sum('sale_price'); - $deletedSum = $deletedSum + $deletedOrdersSum; - } - $staff_data[] = array( - 'name' => $name, - 'code' => $code + 0, - 'opened_count' => $countOpened + 0, - 'closed_count' => $countClosed, - 'opened_sum' => $sumOpened + 0, - 'closed_sum' => $sumClosed + 0, - 'input_count' => $inputCount, - 'output_count' => $outputCount, - 'input_sum' => $inputSum, - 'output_sum' => $outputSum, - 'annul_count' => $annulCount, - 'annul_sum' => $annulSum, - 'return_count' => $returnCount, - 'return_sum' => round($returnSum, 2), - 'deleted_count' => $deletedCount, - 'deleted_sum' => $deletedSum); - } - return [ - 'status' => 'success', - 'staffs' => $staff_data, - ]; - } - if (isset($input['start_date']) && isset($input['end_date'])) { - $staff = $staff_data = $shifts = []; - $countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0; - $end_date = date('Y-m-d H:i:s', strtotime($input['end_date'])); - $start_date = date('Y-m-d H:i:s', strtotime($input['start_date'])); - $shiftIds = ExchangeShifts::where('opened', '>', $start_date) - ->where('opened', '<', $end_date) - ->get(); - foreach ($shiftIds as $key => $shiftId) { - array_push($shifts, $shiftId['id']); - } - $openedOrders = ExchangeOrders::select('who_open') - ->whereIn('shift_id', $shifts) - ->where('who_open', '>', 0) - ->groupBy('who_open') - ->get(); - $closedOrders = ExchangeOrders::select('who_close') - ->whereIn('shift_id', $shifts) - ->where('who_close', '>', 0) - ->groupBy('who_close') - ->get(); - foreach ($openedOrders as $key => $openedOrder) { - array_push($staff, $openedOrder['who_open']); - } - foreach ($closedOrders as $key => $closedOrder) { - array_push($staff, $closedOrder['who_close']); - } - $staff = array_unique($staff); - foreach ($staff as $key => $value) { - $staffId = $value + 0; - $name = staffName($staffId); - $code = $staffId; - $countOpened = ExchangeOrders::where('who_open', $staffId) - ->whereIn('shift_id', $shifts) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->count(); - $countClosed = ExchangeOrders::where('who_close', $staffId) - ->whereIn('shift_id', $shifts) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->count(); - $sumOpened = ExchangeOrders::where('who_open', $staffId) - ->whereIn('shift_id', $shifts) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->sum('order_sum'); - $sumClosed = ExchangeOrders::where('who_close', $staffId) - ->whereIn('shift_id', $shifts) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->sum('order_sum'); - $inputCount = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 49) - ->count(); - $inputSum = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 49) - ->sum('value'); - $outputCount = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 50) - ->count(); - $outputSum = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 50) - ->sum('value'); - $annulCount = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 43) - ->count(); - $annulOrders = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 43) - ->get(); - foreach ($annulOrders as $key => $annulOrder) { - $annulSum = $annulSum + ExchangeOrders::where('code', $annulOrder['order_code']) - ->whereIn('shift_id', $shifts) - ->sum('order_sum'); - } - $returnCount = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 19) - ->count(); - $returnOrders = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 19) - ->get(); - foreach ($returnOrders as $key => $returnOrder) { - $returnSum = $returnSum + abs(ExchangeOrders::where('code', $returnOrder['order_code']) - ->whereIn('shift_id', $shifts) - ->sum('order_sum')); - } - $deletedCount = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 8) - ->where('reason', '>', 0) - ->count(); - $deletedOrders = ExchangeActions::where('who', $staffId) - ->whereIn('shift_id', $shifts) - ->where('action_type', 8) - ->where('reason', '>', 0) - ->get(); - foreach ($deletedOrders as $key => $deletedOrder) { - $deletedSum = $deletedSum + ExchangeDeleted::where('order_code', $deletedOrder['order_code']) - ->whereIn('shift_id', $shifts) - ->sum('sale_price'); - } - $staff_data[] = array( - 'name' => $name, - 'code' => $code + 0, - 'opened_count' => $countOpened + 0, - 'closed_count' => $countClosed, - 'opened_sum' => $sumOpened + 0, - 'closed_sum' => $sumClosed + 0, - 'input_count' => $inputCount, - 'output_count' => $outputCount, - 'input_sum' => $inputSum, - 'output_sum' => $outputSum, - 'annul_count' => $annulCount, - 'annul_sum' => $annulSum, - 'return_count' => $returnCount, - 'return_sum' => round($returnSum, 2), - 'deleted_count' => $deletedCount, - 'deleted_sum' => $deletedSum); - } - return [ - 'status' => 'success', - 'staffs' => $staff_data, - ]; - } + if ($reportType == 'move') { + $orders = ExchangeActions::select('order_code')->where('shift_id', $input['shift_id'])->groupBy('order_code')->get(); + foreach ($orders as $key => $order) { + $actions = ExchangeActions::where('order_code', $order['order_code'])->where('shift_id', $input['shift_id'])->orderBy('time', 'asc')->get(); + foreach ($actions as $key => $item) { + $moved_order_data = []; + if ($item['action_type'] == 39) { + $staff_name_to = staffName($item['who']); + $time_to = date('d.m.Y H:i:s', strtotime($item['time'])); + $data_from = ExchangeActions::where('order_code', $item['order_code'])->where('shift_id', $input['shift_id'])->where('action_type', 45)->first(); + $staff_name_from = staffName($data_from['who']); + $time_from = date('d.m.Y H:i:s', strtotime($data_from['time'])); + $moved_order_data[] = array('order' => $item['order_code'], 'move_from' => data_decode($data_from['value']), 'move_from_staff' => $staff_name_from, 'move_from_time' => $time_from, 'move_to' => data_decode($item['value']), 'move_to_staff' => $staff_name_to, 'move_to_time' => $time_to); + } + } + } + return [ + 'status' => 'success', + 'count' => count($moved_order_data), + 'data' => $moved_order_data, + ]; + } - } - } else { - return [ - 'status' => 'success', - 'error_message' => 'Проверьте введенные данные', - ]; - } - } + if ($reportType == 'staff') { + if (isset($input['shift_id'])) { + $staff = $staff_data = []; + $countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0; + $openedOrders = ExchangeOrders::select('who_open') + ->where('shift_id', $input['shift_id']) + ->where('who_open', '>', 0) + ->groupBy('who_open') + ->get(); + $closedOrders = ExchangeOrders::select('who_close') + ->where('shift_id', $input['shift_id']) + ->where('who_close', '>', 0) + ->groupBy('who_close') + ->get(); + foreach ($openedOrders as $key => $openedOrder) { + array_push($staff, $openedOrder['who_open']); + } + foreach ($closedOrders as $key => $closedOrder) { + array_push($staff, $closedOrder['who_close']); + } + $staff = array_unique($staff); + foreach ($staff as $key => $value) { + $staffId = $value + 0; + $name = staffName($staffId); + $code = $staffId; + $countOpened = ExchangeOrders::where('who_open', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->count(); + $countClosed = ExchangeOrders::where('who_close', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->count(); + $sumOpened = ExchangeOrders::where('who_open', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->sum('order_sum'); + $sumClosed = ExchangeOrders::where('who_close', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->sum('order_sum'); + $inputCount = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 49) + ->count(); + $inputSum = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 49) + ->sum('value'); + $outputCount = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 50) + ->count(); + $outputSum = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 50) + ->sum('value'); + $annulCount = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 43) + ->count(); + $annulOrders = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 43) + ->get(); + foreach ($annulOrders as $key => $annulOrder) { + $annulOrderSum = ExchangeOrders::where('code', $annulOrder['order_code']) + ->where('shift_id', $input['shift_id']) + ->first(); + $annulSum = $annulSum + $annulOrderSum['order_sum']; + } + $returnCount = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 19) + ->count(); + $returnOrders = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 19) + ->get(); + foreach ($returnOrders as $key => $returnOrder) { + $returnOrderSum = ExchangeOrders::where('code', $returnOrder['order_code']) + ->where('shift_id', $input['shift_id']) + ->first(); + $returnSum = $returnSum + abs($returnOrderSum['order_sum']); + } + $deletedCount = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 8) + ->where('reason', '>', 0) + ->count(); + $deletedOrders = ExchangeActions::where('who', $staffId) + ->where('shift_id', $input['shift_id']) + ->where('action_type', 8) + ->where('reason', '>', 0) + ->get(); + foreach ($deletedOrders as $key => $deletedOrder) { + $deletedOrdersSum = ExchangeDeleted::where('order_code', $deletedOrder['order_code']) + ->where('shift_id', $input['shift_id']) + ->sum('sale_price'); + $deletedSum = $deletedSum + $deletedOrdersSum; + } + $staff_data[] = array( + 'name' => $name, + 'code' => $code + 0, + 'opened_count' => $countOpened + 0, + 'closed_count' => $countClosed, + 'opened_sum' => $sumOpened + 0, + 'closed_sum' => $sumClosed + 0, + 'input_count' => $inputCount, + 'output_count' => $outputCount, + 'input_sum' => $inputSum, + 'output_sum' => $outputSum, + 'annul_count' => $annulCount, + 'annul_sum' => $annulSum, + 'return_count' => $returnCount, + 'return_sum' => round($returnSum, 2), + 'deleted_count' => $deletedCount, + 'deleted_sum' => $deletedSum); + } + return [ + 'status' => 'success', + 'staffs' => $staff_data, + ]; + } + if (isset($input['start_date']) && isset($input['end_date'])) { + $staff = $staff_data = $shifts = []; + $countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0; + $end_date = date('Y-m-d H:i:s', strtotime($input['end_date'])); + $start_date = date('Y-m-d H:i:s', strtotime($input['start_date'])); + $shiftIds = ExchangeShifts::where('opened', '>', $start_date) + ->where('opened', '<', $end_date) + ->get(); + foreach ($shiftIds as $key => $shiftId) { + array_push($shifts, $shiftId['id']); + } + $openedOrders = ExchangeOrders::select('who_open') + ->whereIn('shift_id', $shifts) + ->where('who_open', '>', 0) + ->groupBy('who_open') + ->get(); + $closedOrders = ExchangeOrders::select('who_close') + ->whereIn('shift_id', $shifts) + ->where('who_close', '>', 0) + ->groupBy('who_close') + ->get(); + foreach ($openedOrders as $key => $openedOrder) { + array_push($staff, $openedOrder['who_open']); + } + foreach ($closedOrders as $key => $closedOrder) { + array_push($staff, $closedOrder['who_close']); + } + $staff = array_unique($staff); + foreach ($staff as $key => $value) { + $staffId = $value + 0; + $name = staffName($staffId); + $code = $staffId; + $countOpened = ExchangeOrders::where('who_open', $staffId) + ->whereIn('shift_id', $shifts) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->count(); + $countClosed = ExchangeOrders::where('who_close', $staffId) + ->whereIn('shift_id', $shifts) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->count(); + $sumOpened = ExchangeOrders::where('who_open', $staffId) + ->whereIn('shift_id', $shifts) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->sum('order_sum'); + $sumClosed = ExchangeOrders::where('who_close', $staffId) + ->whereIn('shift_id', $shifts) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->sum('order_sum'); + $inputCount = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 49) + ->count(); + $inputSum = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 49) + ->sum('value'); + $outputCount = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 50) + ->count(); + $outputSum = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 50) + ->sum('value'); + $annulCount = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 43) + ->count(); + $annulOrders = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 43) + ->get(); + foreach ($annulOrders as $key => $annulOrder) { + $annulSum = $annulSum + ExchangeOrders::where('code', $annulOrder['order_code']) + ->whereIn('shift_id', $shifts) + ->sum('order_sum'); + } + $returnCount = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 19) + ->count(); + $returnOrders = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 19) + ->get(); + foreach ($returnOrders as $key => $returnOrder) { + $returnSum = $returnSum + abs(ExchangeOrders::where('code', $returnOrder['order_code']) + ->whereIn('shift_id', $shifts) + ->sum('order_sum')); + } + $deletedCount = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 8) + ->where('reason', '>', 0) + ->count(); + $deletedOrders = ExchangeActions::where('who', $staffId) + ->whereIn('shift_id', $shifts) + ->where('action_type', 8) + ->where('reason', '>', 0) + ->get(); + foreach ($deletedOrders as $key => $deletedOrder) { + $deletedSum = $deletedSum + ExchangeDeleted::where('order_code', $deletedOrder['order_code']) + ->whereIn('shift_id', $shifts) + ->sum('sale_price'); + } + $staff_data[] = array( + 'name' => $name, + 'code' => intval($code), + 'opened_count' => intval($countOpened), + 'closed_count' => intval($countClosed), + 'opened_sum' => floatval($sumOpened), + 'closed_sum' => floatval($sumClosed), + 'input_count' => $inputCount, + 'output_count' => $outputCount, + 'input_sum' => $inputSum, + 'output_sum' => $outputSum, + 'annul_count' => $annulCount, + 'annul_sum' => $annulSum, + 'return_count' => $returnCount, + 'return_sum' => round($returnSum, 2), + 'deleted_count' => $deletedCount, + 'deleted_sum' => $deletedSum); + } + return [ + 'status' => 'success', + 'staffs' => $staff_data, + ]; + } + + } + if ($reportType == 'deleted') { + $total_count = $total_sum = 0; + $deleted = []; + if (isset($input['shift_id'])) { + $shift_id = $input['shift_id']; + $deleted_from_orders = ExchangeActions::select('order_code')->where('action_type', 5)->where('shift_id', $shift_id)->groupBy('order_code')->get(); + foreach ($deleted_from_orders as $deleted_from_order) { + $items = []; + $order_id = $deleted_from_order['order_code']; + //$count = ExchangeActions::where('action_type', 5)->where('shift_id', $shift_id)->where('order_code', $deleted_from_order['order_code'])->count(); + $deleted_items = ExchangeDeleted::where('shift_id', $shift_id)->where('order_code', $order_id)->get(); + foreach ($deleted_items as $deleted_item) { + $item_info = ExchangeActions::where('shift_id', $shift_id)->where('order_code', $deleted_item['order_code'])->where('action_type', 5)->where('order_position', $deleted_item['item_id'])->first(); + $time = $item_info['time']; + $who = Staff::getName($item_info['who']); + $reason = Reasons::getName($item_info['reason']); + $approved = Staff::getName($item_info['more']); + $item_count = $deleted_item['count']; + $item_price = $deleted_item['sale_price']; + $item_name = Dishes::getName($deleted_item['menu_code']); + $total_count += $item_count; + $total_sum += $item_count * $item_price; + $items[] = array('dish_name' => $item_name, 'who' => $who, 'approved' => $approved, 'reason' => $reason, 'time' => $time, 'count' => $item_count, 'price' => $item_price, 'sum' => floatval($item_price * $item_count)); + } + $deleted[] = array('order_code' => $order_id, 'shift_id' => $shift_id, 'items' => $items); + } + } + if (isset($input['start_date']) && isset($input['end_date'])) { + $end_date = date('Y-m-d H:i:s', strtotime($input['end_date'])); + $start_date = date('Y-m-d H:i:s', strtotime($input['start_date'])); + $deletedShifts = ExchangeActions::select('shift_id')->where('action_type', 5)->where('time', '>', $start_date)->where('time', '<', $end_date)->groupBy('shift_id')->get(); + foreach ($deletedShifts as $deletedShift) { + $shift_id = intval($deletedShift['shift_id']); + $deleted_from_orders = ExchangeActions::select('order_code')->where('action_type', 5)->where('shift_id', $shift_id)->groupBy('order_code')->get(); + foreach ($deleted_from_orders as $deleted_from_order) { + $items = []; + $order_id = $deleted_from_order['order_code']; + $deleted_items = ExchangeDeleted::where('shift_id', $shift_id)->where('order_code', $order_id)->get(); + foreach ($deleted_items as $deleted_item) { + $item_info = ExchangeActions::where('shift_id', $shift_id)->where('order_code', $deleted_item['order_code'])->where('action_type', 5)->where('order_position', $deleted_item['item_id'])->first(); + $time = $item_info['time']; + $who = Staff::getName($item_info['who']); + $reason = Reasons::getName($item_info['reason']); + $approved = Staff::getName($item_info['more']); + $item_count = $deleted_item['count']; + $item_price = $deleted_item['sale_price']; + $item_name = Dishes::getName($deleted_item['menu_code']); + $total_count += $item_count; + $total_sum += $item_count * $item_price; + $items[] = array('dish_name' => $item_name, 'who' => $who, 'approved' => $approved, 'reason' => $reason, 'time' => $time, 'count' => $item_count, 'price' => $item_price, 'sum' => floatval($item_price * $item_count)); + } + $deleted[] = array('order_code' => $order_id, 'shift_id' => $shift_id, 'items' => $items); + } + } + $report = new Report; + $report->user_id = intval($input['admin_user_id']); + $report->name = 'Отчет по удалениям'; + $report->shift_id = 0; + $report->start_date = $start_date; + $report->end_date = $end_date; + $report->report_type = 'deleted'; + $report->save(); + } + return [ + 'status' => 'success', + 'total_count' => strval($total_count), + 'total_sum' => $total_sum, + 'deleted' => $deleted + ]; + } + } else { + return [ + 'status' => 'success', + 'error_message' => 'Проверьте введенные данные', + ]; + } + } } \ No newline at end of file diff --git a/commands/GETDiscountItems.php b/commands/GETDiscountItems.php index 833ec03..77a158d 100644 --- a/commands/GETDiscountItems.php +++ b/commands/GETDiscountItems.php @@ -26,6 +26,9 @@ class GETDiscountItems extends HRCCommand implements HRCCommandInterface { $discount = 0; } $dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first(); + if (!isset($dish)) { + $dish = Dishes::where('legacy_code', $item['dish_code'])->where('is_history', 0)->first(); + } $items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2)); } diff --git a/commands/GETOrder.php b/commands/GETOrder.php index ae19da9..4662d5e 100644 --- a/commands/GETOrder.php +++ b/commands/GETOrder.php @@ -18,42 +18,43 @@ class GETOrder extends HRCCommand implements HRCCommandInterface { if (isset($input['task'])) { if ($input['task'] == 'single' && isset($input['order_id'])) { - $order = Orders::where('id', '=', $input['order_id'])->first(); + $order = Orders::where('id', intval($input['order_id']))->first(); - if (isset($order->client_id) && $order->client_id !== null && $order->client_id !== '') { - $client = Client::where('user_code', '=', $order->client_id)->first(); - $client = $client->name; - $client_phone = ClientsPhone::where('client_guid', '=', $order->client_id)->first(); - $client_phone = $client_phone->phone; - $client_address = ClientsAddress::where('client_guid', '=', $order->client_id)->first(); - $client_address = $client_address->address; + if (isset($order['client_id']) && $order['client_id'] !== null && $order['client_id'] !== '') { + $client = Client::where('user_code', $order['client_id'])->first(); + $client = $client['name']; + $client_phone = ClientsPhone::where('client_guid', $order['client_id'])->first(); + $client_phone = $client_phone['phone']; + $client_address = ClientsAddress::where('client_guid', $order['client_id'])->first(); + $client_address = $client_address['address']; } else { $client = ''; $client_phone = ''; $client_address = ''; } - $orderItems = OrderItems::where('order_id', '=', $order->id)->whereNull('modifier_id')->get(); + $orderItems = OrderItems::where('order_id', $order['id'])->whereNull('modifier_id')->get(); if (isset($orderItems)) { foreach ($orderItems as $key => $item) { - $itemName = Dishes::where('code', '=', $item->item_id)->first(); - $itemName = $itemName->name; - $itemModifiers = OrderItems::where('order_id', '=', $order->id)->where('parent_id', '=', $item->id)->whereNotNull('modifier_id')->get(); + $itemName = Dishes::getName($item['item_id']); + $is_real = Dishes::isReal($item['item_id']); + $itemModifiers = OrderItems::where('order_id', $order['id'])->where('parent_id', $item['id'])->whereNotNull('modifier_id')->get(); if (isset($itemModifiers)) { foreach ($itemModifiers as $key => $itemModifier) { - $modifier = Modifier::where('code', '=', $itemModifier->modifier_id)->first(); - if ($modifier->dish_code == 0 && $modifier->unit_id == 0) { - $modOut[] = array('id' => $modifier->code, 'name' => $modifier->name, 'price' => '*'); + $modifier = Modifier::where('code', $itemModifier['modifier_id'])->first(); + if ($modifier['dish_code'] == 0 && $modifier['unit_id'] == 0) { + $modOut[] = array('id' => $modifier['code'], 'name' => $modifier['name'], 'price' => '*'); } } } - $output[] = array('id' => $item->id, + $output[] = array('id' => $item['id'], 'num' => $key + 1, - 'order_id' => $item->order_id, - 'item_id' => $item->item_id, + 'order_id' => $item['order_id'], + 'item_id' => $item['item_id'], 'item_name' => $itemName, - 'item_count' => $item->item_count, - 'item_price' => $item->item_price, + 'item_count' => round($item['item_count'], 3), + 'item_price' => round($item['item_price'], 2), + 'is_real' => $is_real, ); } } else { @@ -62,27 +63,41 @@ class GETOrder extends HRCCommand implements HRCCommandInterface { return [ 'status' => 'success', - 'message' => 'Заказ №' . $order->id, + 'message' => 'Заказ №' . $order['id'], 'order' => $order, 'orderItems' => $output, 'client_name' => $client, 'client_phone' => $client_phone, 'client_address' => $client_address, - 'totalCount' => $order->total_count, - 'totalPrice' => $order->total_price, + 'totalCount' => $order['total_count'], + 'totalPrice' => round($order['total_price'], 2), ]; } if ($input['task'] == 'list') { $orders = Orders::all(); foreach ($orders as $key => $order) { - $client = Client::where('user_code', '=', $order->client_id)->first(); - $client_phone = ClientsPhone::where('client_guid', '=', $order->client_id)->first(); - $client_address = ClientsAddress::where('client_guid', '=', $order->client_id)->first(); + $client = Client::where('user_code', $order['client_id'])->first(); + $client_phone = ClientsPhone::where('client_guid', $order['client_id'])->first(); + $client_address = ClientsAddress::where('client_guid', $order['client_id'])->first(); if (isset($client)) { - $output[] = array('id' => $order->id, 'client_name' => $client->name, 'client_phone' => $client_phone->phone, 'client_address' => $client_address->address, 'total_count' => $order->total_count, 'total_price' => $order->total_price, 'is_send' => $order->is_send); + $output[] = array('id' => $order['id'], + 'client_name' => $client['name'], + 'client_phone' => $client_phone['phone'], + 'client_address' => $client_address['address'], + 'total_count' => $order['total_count'], + 'total_price' => $order['total_price'], + 'is_send' => $order['is_send'] + ); } else { - $output[] = array('id' => $order->id, 'client_name' => '', 'client_phone' => '', 'client_address' => '', 'total_count' => $order->total_count, 'total_price' => $order->total_price, 'is_send' => $order->is_send); + $output[] = array('id' => $order['id'], + 'client_name' => '', + 'client_phone' => '', + 'client_address' => '', + 'total_count' => $order['total_count'], + 'total_price' => $order['total_price'], + 'is_send' => $order['is_send'] + ); } } return [ @@ -98,12 +113,16 @@ class GETOrder extends HRCCommand implements HRCCommandInterface { $clients = ClientsPhone::where('phone', '=', $phone)->get(); if (isset($clients)) { foreach ($clients as $key => $client) { - $client_name = Client::where('user_code', '=', $client->client_guid)->first(); - $client_name = $client_name->name; - $client_address = ClientsAddress::where('client_guid', '=', $client->client_guid)->first(); - $client_phone = $client->phone; - $client_guid = $client->client_guid; - $output[] = array('guid' => $client_guid, 'name' => $client_name, 'phone' => $client_phone, 'address' => $client_address->address); + $client_name = Client::where('user_code', $client['client_guid'])->first(); + $client_name = $client_name['name']; + $client_address = ClientsAddress::where('client_guid', $client['client_guid'])->first(); + $client_phone = $client['phone']; + $client_guid = $client['client_guid']; + $output[] = array('guid' => $client_guid, + 'name' => $client_name, + 'phone' => $client_phone, + 'address' => $client_address['address'] + ); } } diff --git a/commands/GETOrderHistory.php b/commands/GETOrderHistory.php index 275aecf..2f121ee 100644 --- a/commands/GETOrderHistory.php +++ b/commands/GETOrderHistory.php @@ -78,35 +78,6 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { return true; } - function dishName($data) { - $dish_name = Dishes::where('code', $data)->where('is_history', 0)->first(); - if ($dish_name) { - $dish_name = $dish_name['name']; - } else { - $dish_name = Dishes::where('code', $data)->where('is_history', 1)->first(); - if ($dish_name) { - $dish_name = $dish_name['name']; - } else { - $dish_name = 'Связанный товар удален'; - } - } - return $dish_name; - } - - function staffName($data) { - $staff_name = Staff::where('code', $data)->where('is_history', 0)->first(); - if ($staff_name) { - $staff_name = $staff_name['name']; - } else { - $staff_name = Staff::where('code', $data)->where('is_history', 1)->first(); - if ($staff_name) { - $staff_name = $staff_name['name']; - } else { - $staff_name = 'Связанный персонал не найден'; - } - } - return $staff_name; - } function data_decode($data) { $alph = [ @@ -166,7 +137,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { foreach ($order as $key => $item) { $action_type = ActionTypes::where('type_id', $item['type_action'])->first(); $action_name = $action_type['name']; - $staff_name = staffName($item['who']); + $staff_name = Staff::getName($item['who']); if ($item['type_action'] == 1) { $action_name = 'Заказ создан'; @@ -181,7 +152,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { } else { $unit_name = 'шт'; } - $dish = dishName($item['more']); + $dish = Dishes::getName($item['more']); $action_name = $action_name . ': ' . $dish . ' в количестве ' . $item['value'] . ' ' . $unit_name; } @@ -195,7 +166,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { $unit_name = 'шт'; } - $dish = dishName($shiftOnlineDeletedItem['dishes_code']); + $dish = Dishes::getName($shiftOnlineDeletedItem['dishes_code']); $action_name = $action_name . ': ' . $dish . ' в количестве ' . $item['value'] . ' ' . $unit_name; } @@ -220,7 +191,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { } if ($item['type_action'] == 22) { - $dish = dishName($item['order_position']); + $dish = Dishes::getName($item['order_position']); $action_name = 'Отменена позиции: ' . $dish . ' в количестве ' . $item['value']; } @@ -263,13 +234,12 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { } 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) { $slice_items[] = array('id' => $key + 1, 'name' => $slice_order_item['name'], 'count' => $slice_order_item['count']); } - $staff_name = staffName($item['who']); + $staff_name = Staff::getName($item['who']); $sliced_order_items[] = array('order' => $slice_order, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'items' => $slice_items); $slice_trigger = 1; } @@ -282,16 +252,18 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { ->where('type_action', 32) ->get(); foreach ($item_actions as $key => $item_action) { - if ($item_action['more']) { + if ($item_action['more'] != '') { $merge_items_before = $merge_items_after = $merge_items = $merge_order_item_before = $merge_order_item_after = $merged_items = []; - if (json_validate($item['more'])) { + if (json_validate($item_action['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(base64_decode($item_action['more']), true); } + //$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) { $merge_items_before[] = array('id' => $key + 1, 'code' => $merge_order_item_before['id'], @@ -320,7 +292,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { 'name' => $merged_item['name'], 'count' => $merged_item['count']); } - $staff_name = staffName($item['who']); + $staff_name = Staff::getName($item['who']); $merged_order_items[] = array('order' => $merge_order, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'items' => $merge_items); $merge_trigger = 1; } @@ -332,7 +304,7 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { ->where('type_action', 39) ->get(); foreach ($order_data as $key => $data) { - $staff_name = staffName($data['who']); + $staff_name = Staff::getName($data['who']); $moved_order_data[] = array('staff_name' => $staff_name, 'time' => date('d.m.Y H:i:s', strtotime($data['time'])), 'data' => data_decode($data['value'])); $move_trigger = 1; } diff --git a/commands/GETRoomMap.php b/commands/GETRoomMap.php new file mode 100644 index 0000000..81887b5 --- /dev/null +++ b/commands/GETRoomMap.php @@ -0,0 +1,51 @@ + 'success', + 'places' => $places, + ]; + } + if ($input['type'] == 'place' && isset($input['id'])) { + $place_name = Places::getName($input['id']); + $tables = Tables::where('place_id', $input['id'])->get(); + return [ + 'status' => 'success', + 'place_id' => $input['id'], + 'place' => $place_name, + 'tables' => $tables, + ]; + } + if ($input['type'] == 'full') { + $places = Places::all(); + foreach ($places as $place) { + $tables = Tables::where('place_id', $place['id'])->get(); + $roommap[] = array('place_id' => $place['id'], 'place_name' => $place['name'], 'tables' => $tables); + } + return [ + 'status' => 'success', + 'roommap' => $roommap, + ]; + } + } else { + return [ + 'status' => 'success', + 'message' => 'Ошибка данных запроса', + ]; + } + } +} \ No newline at end of file diff --git a/commands/GETRoomMapFile.php b/commands/GETRoomMapFile.php new file mode 100644 index 0000000..1752f14 --- /dev/null +++ b/commands/GETRoomMapFile.php @@ -0,0 +1,101 @@ +where('is_active', '=', 1)->first(); + $files = []; + $dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\places\\"; + Http::post('https://portal.hrc.by/api/cloud/folder', [ + 'code' => $terminal['key'], + 'folder' => 'places', + '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=places'); + if (count($response_files->json()['files']) > 0) { + foreach ($response_files->json()['files'] as $response) { + $filename = $response['filename']; + $basename = $response['basename']; + $files[$response['timestamp']] = array('filename' => $filename, 'basename' => $basename); + } + 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=/places/' . $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); + foreach ($files as $file) { + Http::delete('https://portal.hrc.by/api/cloud/file', [ + 'code' => $terminal['key'], + 'name' => $file['basename'], + 'folder' => 'places', + 'project_code' => 'hrc', + 'api' => '2.0', + ]); + } + $places_file = $dirname . $basename; + } else { + return ['status' => 'success', + 'message' => 'Файлы не найдены' + ]; + } + $objXmlDocument = simplexml_load_file($places_file); + $objJsonDocument = json_encode($objXmlDocument); + $xmlPlaces = json_decode($objJsonDocument, TRUE); + + Schema::disableForeignKeyConstraints(); + DB::table('place_tables')->truncate(); + DB::table('places')->truncate(); + Schema::enableForeignKeyConstraints(); + + foreach ($xmlPlaces['Place'] as $xmlPlace) { + $place_name = $xmlPlace['@attributes']['name']; + $newPlace = new Places; + $newPlace->name = $place_name; + $newPlace->save(); + foreach ($xmlPlace['Table'] as $table) { + $newTable = new Tables; + $newTable->name = $table['@attributes']['text']; + $newTable->table_id = intval($table['@attributes']['number']); + $newTable->place_id = $newPlace['id']; + $newTable->width = $table['@attributes']['width']; + $newTable->height = $table['@attributes']['height']; + $newTable->x = $table['@attributes']['y']; + $newTable->y = $table['@attributes']['x']; + $newTable->save(); + } + } + return [ + 'status' => 'success', + 'places' => $xmlPlaces + ]; + } +} \ No newline at end of file diff --git a/commands/POSTOrderItem.php b/commands/POSTOrderItem.php index 5e51a34..45c6e73 100644 --- a/commands/POSTOrderItem.php +++ b/commands/POSTOrderItem.php @@ -65,10 +65,10 @@ class POSTOrderItem extends HRCCommand implements HRCCommandInterface { $totalCount = 0; $totalPrice = 0; foreach ($orderItems as $key => $item) { - $totalCount = $totalCount + $item->item_count; + //$totalCount = $totalCount + $item->item_count; $totalPrice = $totalPrice + $item->item_count * $item->item_price; } - $order->total_count = $totalCount; + $order->total_count = count($orderItems); $order->total_price = $totalPrice; $order->save(); return [ diff --git a/commands/POSTRoomMap.php b/commands/POSTRoomMap.php new file mode 100644 index 0000000..79c6187 --- /dev/null +++ b/commands/POSTRoomMap.php @@ -0,0 +1,221 @@ +id = $max_id + 1; + $place->name = urldecode($input['name']); + $place->save(); + return [ + 'status' => 'success', + 'message' => 'Зал успешно добавлен', + 'place' => $place + ]; + } + + if ($input['action'] == 'update' && isset($input['id']) && isset($input['name'])) { + $place = Places::find($input['id']); + $place->name = urldecode($input['name']); + $place->save(); + return [ + 'status' => 'success', + 'message' => 'Зал успешно обновлен', + 'place' => $place + ]; + } + + if ($input['action'] == 'delete' && isset($input['id'])) { + $place = Places::find($input['id']); + $place->delete(); + return [ + 'status' => 'success', + 'message' => 'Зал успешно удален' + ]; + } + + if ($input['action'] == 'saveplaces' && isset($input['places'])) { + DB::statement("SET foreign_key_checks=0"); + Tables::truncate(); + Places::truncate(); + DB::statement("SET foreign_key_checks=1"); + $input['places'] = json_decode(urldecode($input['places']), TRUE); + + foreach ($input['places'] as $place_items) { + $place_name = urldecode($place_items['place_name']); + $newPlace = new Places; + $newPlace->name = $place_name; + $newPlace->save(); + foreach ($place_items['tables'] as $table_item) { + $table_id = $table_item['table_id']; + $table_place_id = $place_items['place_id']; + $table_name = urldecode($table_item['name']); + $table_width = $table_item['width']; + $table_height = $table_item['height']; + $table_x = $table_item['x']; + $table_y = $table_item['y']; + $newTable = new Tables; + $newTable->name = $table_name; + $newTable->table_id = $table_id; + $newTable->place_id = $table_place_id; + $newTable->width = $table_width; + $newTable->height = $table_height; + $newTable->x = $table_x; + $newTable->y = $table_y; + $newTable->save(); + } + + } + $places = Places::all(); + foreach ($places as $place) { + $tables = Tables::where('place_id', $place['id'])->get(); + $roommap[] = array('place_id' => $place['id'], 'place_name' => $place['name'], 'tables' => $tables); + } + return [ + 'status' => 'success', + 'message' => 'Карта успешно обновлена', + 'roommap' => $roommap, + ]; + } + + return [ + 'status' => 'success', + 'error_message' => 'Проверьте введенные данные', + ]; + + } + + if (isset($input['type']) && $input['type'] == 'table') { + if ($input['action'] == 'create' && + isset($input['place_id']) && + isset($input['table_id']) && + isset($input['name']) && + isset($input['width']) && + isset($input['height']) && + isset($input['x']) && + isset($input['y'])) { + $table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->where('name', $input['name'])->first(); + if (isset($table)) { + return [ + 'status' => 'success', + 'error_message' => 'Стол уже существует', + ]; + } + $table_id = $input['table_id']; + $table_place_id = $input['place_id']; + $table_name = urldecode($input['name']); + $table_width = $input['width']; + $table_height = $input['height']; + $table_x = $input['x']; + $table_y = $input['y']; + $newTable = new Tables; + $newTable->name = $table_name; + $newTable->table_id = $table_id; + $newTable->place_id = $table_place_id; + $newTable->width = $table_width; + $newTable->height = $table_height; + $newTable->x = $table_x; + $newTable->y = $table_y; + $newTable->save(); + return [ + 'status' => 'success', + 'message' => 'Стол успешно добавлен', + 'table' => $newTable + ]; + } + + if ($input['action'] == 'update' && + isset($input['place_id']) && + isset($input['table_id']) && + isset($input['name']) && + isset($input['width']) && + isset($input['height']) && + isset($input['x']) && + isset($input['y'])) { + $table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->first(); + $table_id = $input['table_id']; + $table_place_id = $input['place_id']; + $table_name = urldecode($input['name']); + $table_width = $input['width']; + $table_height = $input['height']; + $table_x = $input['x']; + $table_y = $input['y']; + $table = Tables::find($table['id']); + $table->name = $table_name; + $table->table_id = $table_id; + $table->place_id = $table_place_id; + $table->width = $table_width; + $table->height = $table_height; + $table->x = $table_x; + $table->y = $table_y; + $table->save(); + return [ + 'status' => 'success', + 'message' => 'Стол успешно обновлен', + 'table' => $table + ]; + } + + if ($input['action'] == 'delete' && + isset($input['place_id']) && + isset($input['table_id'])) { + $table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->first(); + $table = Tables::find($table['id']); + $table->delete(); + } + + if ($input['action'] == 'savetables' && isset($input['tables']) && isset($input['place_id'])) { + $input['tables'] = json_decode(urldecode($input['tables']), TRUE); + $tables = Tables::where('place_id', intval($input['place_id']))->get(); + + foreach ($tables as $table) { + $del_table = Tables::find($table['id']); + $del_table->delete(); + } + foreach ($input['tables'] as $item) { + $table_id = $item['table_id']; + $table_place_id = $item['place_id']; + $table_name = urldecode($item['name']); + $table_width = $item['width']; + $table_height = $item['height']; + $table_x = $item['x']; + $table_y = $item['y']; + $newTable = new Tables; + $newTable->name = $table_name; + $newTable->table_id = $table_id; + $newTable->place_id = $table_place_id; + $newTable->width = $table_width; + $newTable->height = $table_height; + $newTable->x = $table_x; + $newTable->y = $table_y; + $newTable->save(); + } + return [ + 'status' => 'success', + 'message' => 'Зал успешно обновлен' + ]; + } + + } + return [ + 'status' => 'success', + 'error_message' => 'Проверьте введенные данные', + ]; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 8a6f847..3d6f4e6 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "hrc-admin/hello-world", - "version": "2.21", + "version": "2.22", "require": { "horeca/admin-php-module-core": "dev-master", "guzzlehttp/guzzle": "^7.4" diff --git a/database/migrations/2022_08_03_132213_add_columns_to_order_item.php b/database/migrations/2022_08_03_132213_add_columns_to_order_item.php new file mode 100644 index 0000000..8dc25de --- /dev/null +++ b/database/migrations/2022_08_03_132213_add_columns_to_order_item.php @@ -0,0 +1,35 @@ +tinyInteger('is_deleted')->nullable()->default(0); + }); + } + + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::table('order_items', function (Blueprint $table) { + $table->dropColumn('is_deleted'); + }); + + } +} diff --git a/database/migrations/2022_08_03_154519_update_item_count_and_item_price_in_order_items_to_float.php b/database/migrations/2022_08_03_154519_update_item_count_and_item_price_in_order_items_to_float.php new file mode 100644 index 0000000..d3fa979 --- /dev/null +++ b/database/migrations/2022_08_03_154519_update_item_count_and_item_price_in_order_items_to_float.php @@ -0,0 +1,39 @@ +decimal('item_price', $precision = 16, $scale = 3)->nullable(); + }); + } + if (!Schema::hasColumn('order_items', 'item_count')) { + Schema::table('order_items', function (Blueprint $table) { + $table->decimal('item_count', $precision = 16, $scale = 2)->nullable(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::table('order_items', function (Blueprint $table) { + $table->integer('item_price')->nullable()->change(); + }); + Schema::table('order_items', function (Blueprint $table) { + $table->integer('item_count')->nullable()->change(); + }); + } +} diff --git a/database/migrations/2022_08_03_154923_update_total_price_in_orders_to_float.php b/database/migrations/2022_08_03_154923_update_total_price_in_orders_to_float.php new file mode 100644 index 0000000..8f6df2c --- /dev/null +++ b/database/migrations/2022_08_03_154923_update_total_price_in_orders_to_float.php @@ -0,0 +1,31 @@ +decimal('total_price', $precision = 16, $scale = 2)->nullable(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::table('orders', function (Blueprint $table) { + $table->integer('total_price')->nullable()->change(); + }); + } +} diff --git a/database/migrations/2022_08_08_120748_create_places_table.php b/database/migrations/2022_08_08_120748_create_places_table.php new file mode 100644 index 0000000..80c32a8 --- /dev/null +++ b/database/migrations/2022_08_08_120748_create_places_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->string('name'); + $table->integer('place_id'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('places'); + } +} diff --git a/database/migrations/2022_08_08_130748_create_place_tables_table.php b/database/migrations/2022_08_08_130748_create_place_tables_table.php new file mode 100644 index 0000000..1564292 --- /dev/null +++ b/database/migrations/2022_08_08_130748_create_place_tables_table.php @@ -0,0 +1,67 @@ +bigIncrements('id'); + $table->bigInteger('place_id')->unsigned(); + $table->foreign('place_id')->references('id')->on('places')->onDelete('cascade'); + $table->string('name'); + $table->timestamps(); + }); + } + if (!Schema::hasColumn('place_tables', 'table_id')) { + Schema::table('place_tables', function (Blueprint $table) { + $table->integer('table_id')->nullable(); + }); + } + if (!Schema::hasColumn('place_tables', 'width')) { + Schema::table('place_tables', function (Blueprint $table) { + $table->decimal('width', $precision = 10, $scale = 6)->nullable(); + }); + } + if (!Schema::hasColumn('place_tables', 'height')) { + Schema::table('place_tables', function (Blueprint $table) { + $table->decimal('height', $precision = 10, $scale = 6)->nullable(); + }); + } + if (!Schema::hasColumn('place_tables', 'x')) { + Schema::table('place_tables', function (Blueprint $table) { + $table->decimal('x', $precision = 10, $scale = 6)->nullable(); + }); + } + if (!Schema::hasColumn('place_tables', 'y')) { + Schema::table('place_tables', function (Blueprint $table) { + $table->decimal('y', $precision = 10, $scale = 6)->nullable(); + }); + } + if (!Schema::hasColumn('place_tables', 'type')) { + Schema::table('place_tables', function (Blueprint $table) { + $table->integer('type')->nullable(); + }); + } + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('place_tables'); + } +} diff --git a/database/migrations/2022_09_22_140748_update_core_interface.php b/database/migrations/2022_09_22_140748_update_core_interface.php new file mode 100644 index 0000000..0ae9f4a --- /dev/null +++ b/database/migrations/2022_09_22_140748_update_core_interface.php @@ -0,0 +1,64 @@ +count() == 0) { + Right::add('clean', 'Обрезка базы'); + } + if (Right::where('code', 'marketplace')->count() == 0) { + Right::add('marketplace', 'Маркетплейс'); + } + if (Right::where('code', 'update')->count() == 0) { + Right::add('update', 'Обновления'); + } + if (Right::where('code', 'roommap')->count() == 0) { + Right::add('roommap', 'Карта залов'); + } + if (Right::where('code', 'eorders')->count() == 0) { + Right::add('eorders', 'Онлайн заказы'); + } + } +} diff --git a/database/seeders/AddUserRights.php b/database/seeders/AddUserRights.php new file mode 100644 index 0000000..7abb312 --- /dev/null +++ b/database/seeders/AddUserRights.php @@ -0,0 +1,33 @@ +count() == 0) { + StaffRights::add('RIGHT_57', 'Доставка'); + } + if (StaffRights::where('code', 'RIGHT_58')->count() == 0) { + StaffRights::add('RIGHT_58', 'Электронный чек'); + } + if (StaffRights::where('code', 'RIGHT_59')->count() == 0) { + StaffRights::add('RIGHT_59', 'Отображение заказов в журнале'); + } + if (StaffRights::where('code', 'RIGHT_60')->count() == 0) { + StaffRights::add('RIGHT_60', 'Отображение отчетов смены'); + } + if (StaffRights::where('code', 'RIGHT_61')->count() == 0) { + StaffRights::add('RIGHT_61', 'Печать копии чека из журнала заказов'); + } + } +} diff --git a/forUpdate/toDirectives/angular-drag-resize.js b/forUpdate/toDirectives/angular-drag-resize.js new file mode 100644 index 0000000..5775d01 --- /dev/null +++ b/forUpdate/toDirectives/angular-drag-resize.js @@ -0,0 +1,187 @@ +(function () { + 'use strict'; + angular.module('angular.drag.resize', []) + .provider('adrConfig', function adrConfigProvider() { + //defaults + var defaultConfig = { + iconPosition: [0, 0], + mode: 'all', + modes: ['all', 'horizontal', 'vertical'] + }; + var config = angular.extend({}, defaultConfig); + this.$get = [function () { + return { + iconPosition: config.iconPosition, + mode: config.mode, + modes: config.modes + }; + }]; + }) + .directive('resize', ['adrConfig', '$document', function (adrConfig, $document) { + return { + restrict: 'A', + link: function (scope, element, attr) { + var dimension = {}; + var iconPosition = adrConfig.iconPosition; + var mode = attr.resize && adrConfig.modes.indexOf(attr.resize) > -1 ? attr.resize : adrConfig.mode; + var position = {}; + var doc = {}; + var el = {}; + //create button for resizing + var btn = document.createElement("span"); + btn.style.width = '15px'; + btn.style.height = '15px'; + btn.innerHTML = + "" + ; + btn.style.bottom = iconPosition[0] + 6 + 'px'; + btn.style.right = iconPosition[1] + 5 + 'px'; + btn.style.position = 'absolute'; + btn.style.visibility = 'hidden'; + if (mode == 'horizontal') { + btn.style.cursor = 'ew-resize'; + } else if (mode == 'vertical') { + btn.style.cursor = 'ns-resize'; + } else { + btn.style.cursor = 'nwse-resize'; + } + //bind resize function to button; + btn.onmousedown = function ($event) { + switch ($event.which) { + case 1: + $event.stopImmediatePropagation(); + doc.left = element[0].parentNode.parentNode.getBoundingClientRect().left; + doc.top = element[0].parentNode.parentNode.getBoundingClientRect().top; + doc.bottom = element[0].parentNode.parentNode.getBoundingClientRect().bottom; + doc.right = element[0].parentNode.parentNode.getBoundingClientRect().right; + el.width = element[0].getBoundingClientRect().width; + el.height = element[0].getBoundingClientRect().height; + console.log('doc.left: ' + doc.left); + console.log('doc.top: ' + doc.top); + console.log('doc.bottom: ' + doc.bottom); + console.log('doc.right: ' + doc.right); + position.x = $event.clientX; + position.y = $event.clientY; + dimension.width = element.prop('offsetWidth'); + dimension.height = element.prop('offsetHeight'); + console.log('dimension.width: ' + dimension.width); + console.log('dimension.height: ' + dimension.height); + $document.bind('mousemove', mousemove); + $document.bind('mouseup', mouseup); + return false; + break; + } + }; + + function mousemove($event) { + switch ($event.which) { + case 1: + + + if ($event.clientX < doc.right && $event.clientY < doc.bottom) { + var deltaWidth = dimension.width - (position.x - $event.clientX); + var deltaHeight = dimension.height - (position.y - $event.clientY); + } else { + var deltaWidth = el.width; + var deltaHeight = el.height; + } +/* console.log('deltaWidth: ' + deltaWidth); + console.log('deltaHeight: ' + deltaHeight); + console.log('position.x: ' + position.x); + console.log('position.y: ' + position.y);*/ + var newDimensions = {}; + if (mode == 'horizontal') { + newDimensions = { + width: deltaWidth + 'px' + }; + } else if (mode == 'vertical') { + newDimensions = { + height: deltaHeight + 'px' + }; + } else { + newDimensions = { + width: deltaWidth + 'px', + height: deltaHeight + 'px' + }; + } + element.css(newDimensions); + return false; + break; + } + } + + function mouseup() { + $document.unbind('mousemove', mousemove); + $document.unbind('mouseup', mouseup); + } + + element.append(btn); + //show button on hover + element.bind('mouseover', function () { + btn.style.visibility = 'visible'; + }); + element.bind('mouseout', function () { + btn.style.visibility = 'hidden'; + }); + } + }; + }]) + .directive('draggable', ['$document', function ($document) { + return { + restrict: 'A', + link: function (scope, element) { + var position = {}; + var doc = {}; + + element.bind('mousedown', function ($event) { + switch ($event.which) { + case 1: + element.css({position: 'fixed'}); + doc.left = element[0].parentNode.parentNode.getBoundingClientRect().left; + doc.top = element[0].parentNode.parentNode.getBoundingClientRect().top; + doc.bottom = element[0].parentNode.parentNode.getBoundingClientRect().bottom; + doc.right = element[0].parentNode.parentNode.getBoundingClientRect().right; + position.x = element[0].getBoundingClientRect().left; + position.y = element[0].getBoundingClientRect().top; + position.initialMouseX = $event.clientX; + position.initialMouseY = $event.clientY; + $document.bind('mousemove', mousemove); + $document.bind('mouseup', mouseup); + return false; + break; + } + }); + + function mousemove($event) { + switch ($event.which) { + case 1: + var dx = $event.clientX - position.initialMouseX; + var dy = $event.clientY - position.initialMouseY; + var posdy = position.y + dy; + var posdx = position.x + dx; + + if (posdy > doc.top && posdx > doc.left && (posdx + element[0].getBoundingClientRect().width) < doc.right && (posdy + element[0].getBoundingClientRect().height) < doc.bottom) { + element.css({ + top: posdy + 'px', + left: posdx + 'px' + }); + } else { + element.css({ + top: position.y + 'px', + left: position.x + 'px' + }); + } + + return false; + break; + } + } + + function mouseup() { + $document.unbind('mousemove', mousemove); + $document.unbind('mouseup', mouseup); + } + } + }; + }]); +})(); \ No newline at end of file diff --git a/forUpdate/toDirectives/context-menu.js b/forUpdate/toDirectives/context-menu.js new file mode 100644 index 0000000..e921d1b --- /dev/null +++ b/forUpdate/toDirectives/context-menu.js @@ -0,0 +1,144 @@ +/** + * ng-context-menu - v1.1.0 - An AngularJS directive to display a context menu + * when a right-click event is triggered + * + * @author Ian Kennington Walter (http://ianvonwalter.com) + */ +(function(angular) { + 'use strict'; + + angular + .module('ng-context-menu', []) + .factory('ContextMenuService', function() { + return { + element: null, + menuElement: null + }; + }) + .directive('contextMenu', [ + '$document', + 'ContextMenuService', + function($document, ContextMenuService) { + return { + restrict: 'A', + scope: { + 'callback': '&contextMenu', + 'disabled': '&contextMenuDisabled', + 'closeCallback': '&contextMenuClose', + 'marginBottom': '@contextMenuMarginBottom', + 'marginLeft': '@contextMenuMarginLeft' + }, + link: function($scope, $element, $attrs) { + var opened = false; + + function open(event, menuElement) { + menuElement.addClass('open'); + + var doc = $document[0].documentElement; + var docLeft = (window.pageXOffset || doc.scrollLeft) - + (doc.clientLeft || 0), + docTop = (window.pageYOffset || doc.scrollTop) - + (doc.clientTop || 0), + elementWidth = menuElement[0].scrollWidth, + elementHeight = menuElement[0].scrollHeight; + var pageX; + var pageY; + // browser compatibility fix for the click location + if (event.pageX || event.pageY) { + // use pageX and pageY when available (modern browsers) + pageX = event.pageX; + pageY = event.pageY; + } else { + // calculate pageX and pageY when they do not exist + // (IE8 and generated events in later versions of IE) + var docBody = $document[0].body; + pageX = event.clientX + docBody.scrollLeft + doc.scrollLeft; + pageY = event.clientY + docBody.scrollTop + doc.scrollTop; + } + var docWidth = doc.clientWidth + docLeft, + docHeight = doc.clientHeight + docTop, + totalWidth = elementWidth + pageX, + totalHeight = elementHeight + pageY, + left = Math.max(pageX - docLeft, 0), + top = Math.max(pageY - docTop, 0); + + if (totalWidth > docWidth) { + var marginLeft = $scope.marginLeft || 0; + left = left - (totalWidth - docWidth) - marginLeft; + } + + if (totalHeight > docHeight) { + var marginBottom = $scope.marginBottom || 0; + top = top - (totalHeight - docHeight) - marginBottom; + } + + menuElement.css('top', top + 'px'); + menuElement.css('left', left + 'px'); + opened = true; + } + + function close(menuElement) { + menuElement.removeClass('open'); + + if (opened) { + $scope.closeCallback(); + } + + opened = false; + } + + $element.bind('contextmenu', function(event) { + if (!$scope.disabled()) { + if (ContextMenuService.menuElement !== null) { + close(ContextMenuService.menuElement); + } + ContextMenuService.menuElement = angular.element( + document.getElementById($attrs.target) + ); + ContextMenuService.element = event.target; + + event.preventDefault(); + event.stopPropagation(); + $scope.$apply(function() { + $scope.callback({ $event: event }); + }); + $scope.$apply(function() { + open(event, ContextMenuService.menuElement); + }); + } + }); + + function handleKeyUpEvent(event) { + if (opened && event.keyCode === 27) { + $scope.$apply(function() { + close(ContextMenuService.menuElement); + }); + } + } + + function handleClickEvent(event) { + if (opened && + (event.button !== 2 || + event.target !== ContextMenuService.element)) { + $scope.$apply(function() { + close(ContextMenuService.menuElement); + }); + } + } + + $document.bind('keyup', handleKeyUpEvent); + // Firefox treats a right-click as a click and a contextmenu event + // while other browsers just treat it as a contextmenu event + $document.bind('click', handleClickEvent); + $document.bind('contextmenu', handleClickEvent); + + $scope.$on('$destroy', function() { + $document.unbind('keyup', handleKeyUpEvent); + $document.unbind('click', handleClickEvent); + $document.unbind('contextmenu', handleClickEvent); + }); + } + }; + } + ]); +})(angular); \ No newline at end of file diff --git a/forUpdate/toWebApp/index.html b/forUpdate/toWebApp/index.html new file mode 100644 index 0000000..3301f2c --- /dev/null +++ b/forUpdate/toWebApp/index.html @@ -0,0 +1,121 @@ + + + +
+ +