v.2.2 Update

Top dishes block update
This commit is contained in:
miroman-afk
2021-11-18 10:59:38 +03:00
parent 276576f007
commit 1a7808f75b
6 changed files with 185 additions and 12 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Commands;
use App\Component\Models\ClientsGroup;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class GETClientGroup extends HRCCommand implements HRCCommandInterface {
protected $signature = 'getclientgroup';
public function command($input, $output = null) {
if (ClientsGroup::where('code', '0')->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,
];
}
}

89
commands/POSTClient.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
namespace App\Commands;
use App\Component\Models\Client;
use App\Component\Models\ClientsAddress;
use App\Component\Models\ClientsBarcode;
use App\Component\Models\ClientsEmail;
use App\Component\Models\ClientsGroup;
use App\Component\Models\ClientsPhone;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class POSTClient extends HRCCommand implements HRCCommandInterface {
protected $signature = 'postclient';
public function command($input, $output = null) {
if (isset($input['task']) && isset($input['id'])) {
if ($input['task'] == 'update') {
$client = Client::find($input['id']);
$client->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' => 'Проверьте введенные данные',
];
}
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Commands;
use App\Component\Models\Client;
use App\Component\Models\ClientsGroup;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class POSTClientGroup extends HRCCommand implements HRCCommandInterface {
protected $signature = 'postclientgroup';
public function command($input, $output = null) {
if (isset($input['task']) && isset($input['id'])) {
if ($input['task'] == 'update') {
$group = ClientsGroup::find($input['id']);
$group->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' => 'Проверьте введенные данные',
];
}
}
}

View File

@@ -19,20 +19,18 @@ class TopDishes extends HRCCommand implements HRCCommandInterface {
$out[] = $value; $out[] = $value;
} }
foreach ($out as $key => $item) { foreach ($out as $key => $item) {
$dishInfo = Dishes::select('name') $dishInfo = Dishes::where('code', '=', $item['menu_code'])
->where('code', '=', $item['menu_code'])
->where('legacy_code', '=', $item['dish_code']) ->where('legacy_code', '=', $item['dish_code'])
->where('is_history', '=', 0) ->where('is_history', '=', 0)
->get(); ->first();
$onlineDishInfo = OnlineItems::select('real_price', 'sale_price', 'special_price') $onlineDishInfo = OnlineItems::where('menu_code', '=', $item['menu_code'])
->where('menu_code', '=', $item['menu_code'])
->where('dish_code', '=', $item['dish_code']) ->where('dish_code', '=', $item['dish_code'])
->get(); ->first();
$dishName = $dishInfo[0]->name; $dishName = $dishInfo['name'];
$dishCount = OnlineItems::where('menu_code', '=', $item['menu_code'])->sum('count'); $dishCount = OnlineItems::where('menu_code', '=', $item['menu_code'])->sum('count');
$dishSum = $onlineDishInfo[0]->real_price * $dishCount; $dishSum = $onlineDishInfo['real_price'] * $dishCount;
if ($dishSum > 0) { 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); $dishPercent = round((100 - ((($dishSum - $dishTotalCost) * 100) / $dishSum)), 2);
$dishProfit = $dishSum - $dishTotalCost; $dishProfit = $dishSum - $dishTotalCost;
} else { } else {

View File

@@ -1,6 +1,6 @@
{ {
"name": "hrc-admin/hello-world", "name": "hrc-admin/hello-world",
"version": "2.1", "version": "2.2",
"require": { "require": {
"horeca/admin-php-module-core": "dev-master" "horeca/admin-php-module-core": "dev-master"
}, },

View File

@@ -1,5 +1,5 @@
[info] [info]
name=V1 name=V1
version=2.1 version=2.2
[build] [build]
version=2.1 version=2.2