Files
admin-php-module/commands/GETTopDishes.php
miroman-afk c4dc6e02a0 v.2.30
Добавлен расширенный отчет по реализации
Добавлен монитор активности
2023-08-03 11:05:15 +03:00

84 lines
2.7 KiB
PHP

<?php
namespace App\Commands;
use App\Component\Models\Dishes;
use App\Component\Models\ShiftOnlineItems;
use App\Component\Models\ShiftOnlineOrders;
use App\Component\Models\Terminal;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class GETTopDishes extends HRCCommand implements HRCCommandInterface {
protected $signature = 'gettopdishes';
public function command($input, $output = null) {
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first();
if ($terminal) {
$terminalKey = $terminal['key'];
} else {
$terminalKey = 0;
}
$allOrders = ShiftOnlineOrders::select('code')
->where('is_closed', 1)
->where('is_returned', 0)
->where('is_deleted', 0)
->get();
$orders = [];
foreach ($allOrders as $order) {
$orders[] = array($order['code']);
}
$info = ShiftOnlineItems::where('menu_code', '>', 0)
->whereIn('order_code', $orders)
->get()
->unique('menu_code');
$count = ShiftOnlineItems::where('menu_code', '>', 0)
->whereIn('order_code', $orders)
->count();
if ($count > 0) {
foreach ($info as $key => $value) {
$out[] = $value;
}
foreach ($out as $key => $item) {
$onlineDishInfo = ShiftOnlineItems::where('menu_code', '=', $item['menu_code'])
->where('dish_code', '=', $item['dish_code'])
->whereIn('order_code', $orders)
->first();
$dishName = Dishes::getName($item['dish_code']);
$dishCount = ShiftOnlineItems::where('menu_code', '=', $item['menu_code'])
->whereIn('order_code', $orders)
->sum('count');
$dishSum = $onlineDishInfo['real_price'] * $dishCount;
if ($dishSum > 0) {
$dishTotalCost = round(($onlineDishInfo['special_price'] * $dishCount), 2);
$dishPercent = round((100 - ((($dishSum - $dishTotalCost) * 100) / $dishSum)), 2);
$dishProfit = $dishSum - $dishTotalCost;
} else {
$dishTotalCost = 0;
$dishPercent = 0;
$dishProfit = 0;
}
$dishes[] = array('name' => $dishName, 'count' => $dishCount, 'sum' => $dishSum, 'totalCost' => $dishTotalCost, 'percentProffit' => $dishPercent, 'proffit' => $dishProfit);
}
for ($i = 0; $i < count($dishes); $i++) {
$sortkey[$i] = $dishes[$i]['count'];
}
arsort($sortkey);
foreach ($sortkey as $key => $key) {
$sorted[] = $dishes[$key];
}
$sorted = array_slice($sorted, 0, 10);
return [
'status' => 'success',
'dishes' => $sorted,
'terminal' => $terminalKey,
];
} else {
return [
'status' => 'success',
'dishes' => [],
'terminal' => $terminalKey,
];
}
}
}