From 1a7808f75b1ce9e2e5be46e85d352b636c294fa4 Mon Sep 17 00:00:00 2001 From: miroman-afk <74014189+miroman-afk@users.noreply.github.com> Date: Thu, 18 Nov 2021 10:59:38 +0300 Subject: [PATCH] v.2.2 Update Top dishes block update --- commands/GETClientGroup.php | 28 ++++++++++++ commands/POSTClient.php | 89 ++++++++++++++++++++++++++++++++++++ commands/POSTClientGroup.php | 58 +++++++++++++++++++++++ commands/TopDishes.php | 16 +++---- composer.json | 2 +- module.ini | 4 +- 6 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 commands/GETClientGroup.php create mode 100644 commands/POSTClient.php create mode 100644 commands/POSTClientGroup.php diff --git a/commands/GETClientGroup.php b/commands/GETClientGroup.php new file mode 100644 index 0000000..8f0af6d --- /dev/null +++ b/commands/GETClientGroup.php @@ -0,0 +1,28 @@ +count() == 0) { + $group = new ClientsGroup; + $group->code = '0'; + $group->name = 'Без группы'; + $group->save(); + } + $client_groups = ClientsGroup::orderBy('code')->get(); + foreach ($client_groups as $client_group) { + $out[] = array('id' => $client_group['id'], 'name' => $client_group['name']); + } + return [ + 'status' => 'success', + 'groups' => $out, + ]; + } +} \ No newline at end of file diff --git a/commands/POSTClient.php b/commands/POSTClient.php new file mode 100644 index 0000000..c2e149d --- /dev/null +++ b/commands/POSTClient.php @@ -0,0 +1,89 @@ +name = urldecode($input['name']); + $client->unloaded = 0; + + $clientGroup = ClientsGroup::where('id', $input['group_id'])->first(); + $client->group_id = urldecode($clientGroup->code); + + $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first(); + if ($input['phone'] !== '') { + if (substr($input['phone'], 0, 1) == '+') { + $phoneData = urldecode($input['phone']); + } else { + $phoneData = urldecode($input['phone']); + $clientPhone->phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2); + } + } else { + $clientPhone->phone = ''; + } + + $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first(); + $clientEmail->email = urldecode($input['email']); + + $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first(); + $clientAddress->address = urldecode($input['address']); + + $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first(); + $clientBarcode->code_id = urldecode($input['barcode']); + + $client->save(); + $clientGroup->save(); + $clientPhone->save(); + $clientEmail->save(); + $clientAddress->save(); + $clientBarcode->save(); + return [ + 'status' => 'success', + 'client' => $client, + 'phone' => $clientPhone, + 'email' => $clientEmail, + 'address' => $clientAddress, + 'barcode' => $clientBarcode, + 'message' => 'Клиент обновлен', + ]; + } + + if ($input['task'] == 'delete') { + $client = Client::where('id', '=', $input['id'])->first(); + $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first(); + $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first(); + $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first(); + $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first(); + $clientPhone->delete(); + $clientEmail->delete(); + $clientAddress->delete(); + $clientBarcode->delete(); + $client->delete(); + return [ + 'status' => 'success', + 'message' => 'Клиент удален', + ]; + } + } else { + return [ + 'status' => 'success', + 'error_message' => 'Проверьте введенные данные', + ]; + } + } +} \ No newline at end of file diff --git a/commands/POSTClientGroup.php b/commands/POSTClientGroup.php new file mode 100644 index 0000000..83fc412 --- /dev/null +++ b/commands/POSTClientGroup.php @@ -0,0 +1,58 @@ +name = $input['name']; + $group->save(); + + return [ + 'status' => 'success', + 'group' => $group, + 'message' => 'Группа обновлена', + ]; + } + + if ($input['task'] == 'delete') { + $group = ClientsGroup::where('id', '=', $input['id'])->first(); + if ($group->code == '0') { + return [ + 'status' => 'success', + 'error_message' => 'Запрещено удаление группы по умолчанию', + ]; + } else { + $client_count = Client::where('group_id', '=', $group->code)->count(); + if ($client_count !== 0) { + return [ + 'status' => 'success', + 'error_message' => 'Разрешено удаление только пустых групп.', + ]; + } else { + $group->delete(); + return [ + 'status' => 'success', + 'message' => 'Группа удалена', + ]; + } + } + } + } else { + return [ + 'status' => 'success', + 'error_message' => 'Проверьте введенные данные', + ]; + } + } +} \ No newline at end of file diff --git a/commands/TopDishes.php b/commands/TopDishes.php index 96b7def..b040c2f 100644 --- a/commands/TopDishes.php +++ b/commands/TopDishes.php @@ -19,20 +19,18 @@ class TopDishes extends HRCCommand implements HRCCommandInterface { $out[] = $value; } foreach ($out as $key => $item) { - $dishInfo = Dishes::select('name') - ->where('code', '=', $item['menu_code']) + $dishInfo = Dishes::where('code', '=', $item['menu_code']) ->where('legacy_code', '=', $item['dish_code']) ->where('is_history', '=', 0) - ->get(); - $onlineDishInfo = OnlineItems::select('real_price', 'sale_price', 'special_price') - ->where('menu_code', '=', $item['menu_code']) + ->first(); + $onlineDishInfo = OnlineItems::where('menu_code', '=', $item['menu_code']) ->where('dish_code', '=', $item['dish_code']) - ->get(); - $dishName = $dishInfo[0]->name; + ->first(); + $dishName = $dishInfo['name']; $dishCount = OnlineItems::where('menu_code', '=', $item['menu_code'])->sum('count'); - $dishSum = $onlineDishInfo[0]->real_price * $dishCount; + $dishSum = $onlineDishInfo['real_price'] * $dishCount; if ($dishSum > 0) { - $dishTotalCost = round(($onlineDishInfo[0]->special_price * $dishCount), 2); + $dishTotalCost = round(($onlineDishInfo['special_price'] * $dishCount), 2); $dishPercent = round((100 - ((($dishSum - $dishTotalCost) * 100) / $dishSum)), 2); $dishProfit = $dishSum - $dishTotalCost; } else { diff --git a/composer.json b/composer.json index b8c850e..85bb73c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "hrc-admin/hello-world", - "version": "2.1", + "version": "2.2", "require": { "horeca/admin-php-module-core": "dev-master" }, diff --git a/module.ini b/module.ini index 68309a4..c5e1889 100644 --- a/module.ini +++ b/module.ini @@ -1,5 +1,5 @@ [info] name=V1 -version=2.1 +version=2.2 [build] -version=2.1 +version=2.2