Добавлен расширенный отчет по реализации
Добавлен монитор активности
This commit is contained in:
miroman-afk
2023-08-03 11:05:15 +03:00
parent 19ad7d1c8a
commit c4dc6e02a0
93 changed files with 13328 additions and 1122 deletions

View File

@@ -2,6 +2,8 @@
namespace App\Component\Models;
use Illuminate\Support\Facades\Log;
class Base
{
public static function tofloat($num) {
@@ -70,4 +72,90 @@ class Base
// everything is OK
return true;
}
public static 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;
}
}
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;
}
public static function customBase64Decode($data) {
$base64 = $data;
$base64 = str_replace(array('\r\n', '\r', '\n'), '', $base64);
$base64 = str_replace(' ', '', $base64);
$decoded = base64_decode($base64);
$decoded = mb_convert_encoding($decoded, 'UTF-8');
log::debug(self::ascii2hex($decoded));
return $decoded;
}
public static function ascii2hex($ascii) {
$hex = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex.=$byte." ";
}
return $hex;
}
public static function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && self::in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
}

View File

@@ -51,7 +51,7 @@ class Client extends Model
public static function getBarcode($guid)
{
$barcode = Client::where('user_code', $guid)->first();
$barcode = self::where('user_code', $guid)->first();
if (isset($barcode)) {
$barcode = $barcode['barcode_start'];
} else {
@@ -62,7 +62,7 @@ class Client extends Model
public static function getID($guid)
{
$id = Client::where('client_guid', $guid)->first();
$id = self::where('client_guid', $guid)->first();
if (isset($id)) {
$id = $id['id'];
} else {
@@ -73,7 +73,7 @@ class Client extends Model
public static function getName($guid)
{
$client_name = Client::where('user_code', $guid)
$client_name = self::where('user_code', $guid)
->first();
if (isset($client_name)) {
$client_name = $client_name['name'];

View File

@@ -8,7 +8,7 @@ class ClientsGroup extends Model {
protected $table = 'client_groups';
public static function getID($guid) {
$id = ClientsGroup::where('code', $guid)->first();
$id = self::where('code', $guid)->first();
if (isset($id)) {
$id = $id['id'];
} else {

View File

@@ -15,7 +15,7 @@ class ClientsPresale extends Model
*/
public static function getPresale($guid)
{
$presale = ClientsPresale::where('client_guid', $guid)->first();
$presale = self::where('client_guid', $guid)->first();
if (isset($presale)) {
$presale = $presale['value'];
} else {
@@ -29,14 +29,14 @@ class ClientsPresale extends Model
*/
public static function presaleReg($guid, $value, $type)
{
$presale_value = ClientsPresale::where('client_guid', $guid)->first();
$presale_value = self::where('client_guid', $guid)->first();
if ($type == 'in') {
ClientsPresale::updateOrCreate(
self::updateOrCreate(
['client_guid' => $guid],
['value' => $presale_value['value'] + $value]
);
} elseif ($type == 'out') {
ClientsPresale::updateOrCreate(
self::updateOrCreate(
['client_guid' => $guid],
['value' => $presale_value['value'] - $value]
);

View File

@@ -14,11 +14,11 @@ class Dishes extends Model {
protected $guarded = [];
public static function getName($data) {
$dish_name = Dishes::where('code', $data)->where('is_history', 0)->first();
$dish_name = self::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();
$dish_name = self::where('code', $data)->where('is_history', 1)->first();
if ($dish_name) {
$dish_name = $dish_name['name'];
} else {
@@ -26,11 +26,11 @@ class Dishes extends Model {
}
}
if ($dish_name == 'Связанный товар удален') {
$dish_name = Dishes::where('legacy_code', $data)->where('is_history', 0)->first();
$dish_name = self::where('legacy_code', $data)->where('is_history', 0)->first();
if ($dish_name) {
$dish_name = $dish_name['name'];
} else {
$dish_name = Dishes::where('legacy_code', $data)->where('is_history', 1)->first();
$dish_name = self::where('legacy_code', $data)->where('is_history', 1)->first();
if ($dish_name) {
$dish_name = $dish_name['name'];
} else {
@@ -42,12 +42,12 @@ class Dishes extends Model {
}
public static function isReal($data) {
$dish_isReal = Dishes::where('code', $data)->where('is_history', 0)->first();
$dish_isReal = self::where('code', $data)->where('is_history', 0)->first();
$isReal = 0;
if ($dish_isReal) {
$isReal = intval($dish_isReal['real_count']);
} else {
$dish_isReal = Dishes::where('code', $data)->where('is_history', 1)->first();
$dish_isReal = self::where('code', $data)->where('is_history', 1)->first();
if ($dish_isReal) {
$isReal = intval($dish_isReal['real_count']);
} else {
@@ -57,13 +57,29 @@ class Dishes extends Model {
return $isReal;
}
public static function getSpecialPrice($menu_code) {
$dish_special_price = self::where('code', $menu_code)->where('is_history', 0)->first();
$special_price = 0;
if ($dish_special_price) {
$special_price = round($dish_special_price['real_cosht'], 2);
} else {
$dish_special_price = self::where('code', $menu_code)->where('is_history', 1)->first();
if ($dish_special_price) {
$special_price = round($dish_special_price['real_cosht']);
} else {
$special_price = 0;
}
}
return $special_price;
}
public static function isServing($data) {
$dish_isServing = Dishes::where('code', $data)->where('is_history', 0)->first();
$dish_isServing = self::where('code', $data)->where('is_history', 0)->first();
$isServing = 0;
if ($dish_isServing) {
$isServing = intval($dish_isServing['is_serving']);
} else {
$dish_isServing = Dishes::where('code', $data)->where('is_history', 1)->first();
$dish_isServing = self::where('code', $data)->where('is_history', 1)->first();
if ($dish_isServing) {
$isServing = intval($dish_isServing['is_serving']);
} else {
@@ -74,11 +90,11 @@ class Dishes extends Model {
}
public static function GetPrinterCode($data) {
$dish = Dishes::where('legacy_code', $data)->where('is_history', 0)->first();
$dish = self::where('legacy_code', $data)->where('is_history', 0)->first();
if ($dish) {
$printer_code = $dish['printer_code'];
} else {
$dish = Dishes::where('legacy_code', $data)->where('is_history', 1)->first();
$dish = self::where('legacy_code', $data)->where('is_history', 1)->first();
if ($dish) {
$printer_code = $dish['printer_code'];
} else {
@@ -86,11 +102,11 @@ class Dishes extends Model {
}
}
if ($printer_code == 0) {
$dish = Dishes::where('code', $data)->where('is_history', 0)->first();
$dish = self::where('code', $data)->where('is_history', 0)->first();
if ($dish) {
$printer_code = $dish['printer_code'];
} else {
$dish = Dishes::where('code', $data)->where('is_history', 1)->first();
$dish = self::where('code', $data)->where('is_history', 1)->first();
if ($dish) {
$printer_code = $dish['printer_code'];
} else {

View File

@@ -4,6 +4,33 @@ namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
class ExchangeItems extends Model {
protected $table = 'exchange_items';
class ExchangeItems extends Model
{
protected $table = 'exchange_items';
/**
* Получить информацию о действиях добавления позиции.
*/
public function create_info()
{
return $this->hasMany(ExchangeActions::class, 'order_position', 'code')
->where('exchange_actions.action_type', '=', 2);
}
/**
* Получить информацию о действиях удаления позиции.
*/
public function delete_info()
{
return $this->hasMany(ExchangeActions::class, 'order_position', 'code')
->where('exchange_actions.action_type', '=', 5);
}
/**
* Получить информацию о заказе.
*/
public function order()
{
return $this->hasOne(ExchangeOrders::class, 'code', 'order_code');
}
}

View File

@@ -3,37 +3,243 @@
namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
class ExchangeOrders extends Model
{
protected $table = 'exchange_orders';
public static function getReturnedItems($order_id, $shift_id)
{
$action = ExchangeActions::where('order_code', $order_id)
->where('shift_id', $shift_id)
->where('action_type', 17)
->orderBy('time', 'desc')
->first();
$returned_order_id = intval($action['value']);
$start_order_items = ExchangeActions::where('order_code', $returned_order_id)
->where('shift_id', $shift_id)
->where('action_type', 2)
->get();
$start_order_info = $cancel_order_info = [];
foreach ($start_order_items as $start_order_item) {
$item = ExchangeItems::where('order_code', $returned_order_id)
->where('shift_id', $shift_id)
->where('menu_code', intval($start_order_item['more']))
->first();
$start_order_info[] = array(
'code' => intval($start_order_item['more']),
'count' => floatval($start_order_item['value']),
'sale_price' => $item['sale_price'],
'special_price' => $item['special_price']
);
}
$canceled_order_items_count = ExchangeActions::where('order_code', $returned_order_id)
->where('shift_id', $shift_id)
->where('action_type', 22)
->count();
if ($canceled_order_items_count > 0) {
$canceled_order_items = ExchangeActions::selectRaw('SUM(value * 1) AS count, order_position')
->where('shift_id', $shift_id)
->where('order_code', $returned_order_id)
->where('action_type', 22)
->groupBy('order_position')
->get();
foreach ($canceled_order_items as $canceled_order_item) {
$item = ExchangeItems::where('order_code', $returned_order_id)
->where('shift_id', $shift_id)
->where('menu_code', $canceled_order_item['order_position'])
->first();
$cancel_order_info[] = array(
'code' => $canceled_order_item['order_position'],
'count' => $canceled_order_item['count'],
'sale_price' => $item['sale_price'],
'special_price' => $item['special_price']
);
}
foreach ($start_order_info as $start_order) {
foreach ($cancel_order_info as $cancel_order) {
if ($start_order['code'] == $cancel_order['code']) {
$start_order['count'] = $start_order['count'] - $cancel_order['count'];
}
}
$item = ExchangeItems::where('order_code', $returned_order_id)
->where('shift_id', $shift_id)
->where('menu_code', $start_order['code'])
->first();
$end_order[] = array(
'code' => $start_order['code'],
'count' => $start_order['count'],
'sale_price' => $item['sale_price'],
'special_price' => $item['special_price']
);
}
} else {
$end_order = $start_order_info;
}
return $end_order;
}
/**
* Get order status
*/
public static function getOrderStatus($order_id, $shift_id)
{
$order_status = '';
$order = self::where('code', $order_id)
->where('shift_id', $shift_id)
->first();
$order_online = 0;
$count_online_open = ExchangeActions::where('order_code', $order['code'])
->where('shift_id', $shift_id)
->where('action_type', 45)
->where('more', '<>', '0')
->count();
$count_online_close = ExchangeActions::where('order_code', $order['code'])
->where('shift_id', $shift_id)
->where('action_type', 6)
->count();
if ($count_online_open > 0 && $count_online_close > 0) {
$order_online = $order['order_sum'];
}
$order_double = 0;
$count_double_is_close = self::where('code', $order['code'])
->where('shift_id', $shift_id)
->where('is_closed', 1)
->where('is_deleted', 0)
->where('is_returned', 0)
->count();
$count_double_close = ExchangeActions::where('order_code', $order['code'])
->where('shift_id', $shift_id)
->where('action_type', 6)
->count();
if ($count_double_is_close > 0 && $count_double_close < 1) {
$order_double = $order['order_sum'];
}
if ($order['is_returned'] > 0) {
$action = ExchangeActions::where('order_code', $order_id)
->where('shift_id', $shift_id)
->where('action_type', 17)
->orderBy('time', 'desc')
->first();
$returned_order_id = intval($action['value']);
$canceled_order_items_count = ExchangeActions::where('order_code', $returned_order_id)
->where('shift_id', $shift_id)
->where('action_type', 22)
->count();
if ($canceled_order_items_count > 0) {
$order_status = 'Возвращен частично';
} else {
$order_status = 'Возвращен';
}
} elseif ($order['is_deleted'] > 0 && $order['check_number'] < 1) {
$order_status = 'Удален';
} elseif ($order['is_deleted'] > 0 && $order['check_number'] > 0) {
$order_status = 'Аннулирован';
} elseif ($order['is_waited'] > 0 && $order['is_closed'] < 1 && $order['place_name'] != "ДОСТАВКА") {
$order_status = 'В ожидании';
} elseif ($order_online > 0) {
$order_status = 'Оплачен онлайн';
} elseif ($order_double > 0) {
$order_status = 'Оплачен(*)';
} elseif ($order['place_name'] == "ДОСТАВКА") {
$order_status = 'Доставка';
} else {
$order_status = 'Оплачен';
}
return $order_status;
}
/**
* Get returned order id
*/
public static function getReturnedOrderId($order_id, $shift_id)
{
$order = self::where('code', $order_id)
->where('shift_id', $shift_id)
->first();
if ($order['is_returned'] > 0) {
$action = ExchangeActions::where('order_code', $order_id)
->where('action_type', 17)
->first();
$returned_order_id = intval($action['value']);
}
return $returned_order_id;
}
/**
* Get order info
*/
public static function getInfo($order_id, $shift_id)
{
$order = ExchangeOrders::where('code', $order_id)->where('shift_id', $shift_id)->first();
$order = self::where('code', $order_id)
->where('shift_id', $shift_id)
->first();
Log::debug($order_id . ' ' . $shift_id);
$open_time = $order['opened'];
$close_time = $order['closed'];
$who_open = Staff::getName($order['who_open']);
$who_close = Staff::getName($order['who_close']);
$items = ExchangeItems::where('order_code', $order_id)->where('dishes_code', '<>', 0)->where('shift_id', $shift_id)->get();
$order_status = '';
if ($order['is_deleted'] > 0) {
$order_status = 'Удален';
} elseif ($order['is_returned'] > 0) {
$order_status = 'Возвращен';
} elseif ($order['is_waited'] > 0 && $order['is_closed'] < 1) {
$order_status = 'В ожидании';
if ($order['closed'] == '0000-00-00 00:00:00') {
$close_time = false;
} else {
$order_status = 'Оплачен';
$close_time = $order['closed'];
}
$who_open = Staff::getName($order['who_open']);
if ($order['who_close'] == 0) {
$who_close = false;
} else {
$who_close = Staff::getName($order['who_close']);
}
$order_client_count = $order['clients_count'];
$items = ExchangeItems::where('order_code', $order_id)
->where('shift_id', $shift_id)
->where('parent_id', 0)
->get();
$deleted_items = ExchangeDeleted::where('order_code', $order_id)
->where('shift_id', $shift_id)
->get();
$order_status = self::getOrderStatus($order_id, $shift_id);
$returned_items = [];
$returned_method = false;
$returned_sum = $returned_count = 0;
$deleted_sum = $deleted_count = 0;
if ($order_status == "Возвращен" || $order_status == "Возвращен частично") {
$returned_items = self::getReturnedItems($order['code'], $shift_id);
foreach ($returned_items as $returned_item) {
$returned_sum += round(abs($returned_item['sale_price']) * $returned_item['count'], 2);
$returned_count += $returned_item['count'];
}
$returned_id = self::getReturnedOrderId($order_id, $shift_id);
$returned_at = self::where('code', $returned_id)
->where('shift_id', $shift_id)
->first();
$returned_method = array(
'cash' => abs($returned_at['cash']),
'credit' => abs($returned_at['credit']),
);
}
$order_cash = $order['cash'];
$order_credit = $order['credit'];
$order_clearing = $order['clearing'];
$order_presale = $order['presale'];
$order_self = $order['self'];
$order_online = 0;
$count_online_open = ExchangeActions::where('order_code', $order['code'])
->where('shift_id', $shift_id)
->where('action_type', 45)
->where('more', '<>', '0')
->count();
$count_online_close = ExchangeActions::where('order_code', $order['code'])
->where('shift_id', $shift_id)
->where('action_type', 6)
->count();
if ($count_online_open > 0 && $count_online_close > 0) {
$order_online = $order['order_sum'];
}
$order_info = [];
$amount = $full_price = 0;
foreach ($items as $key => $item) {
@@ -47,34 +253,117 @@ class ExchangeOrders extends Model
}
$order_info[] = array(
'id' => $key + 1,
'code' => $item['menu_code'],
'name' => Dishes::getName($item['menu_code']),
'count' => $item['count'],
'price' => $item['real_price'],
'sale_price' => $item['sale_price'],
'cof' => $item['cof'],
'count' => floatval($item['count']),
'returned_count' => 0,
'returned_sum' => 0,
'deleted_count' => 0,
'deleted_sum' => 0,
'price' => round($item['real_price'], 2),
'sale_price' => round($item['sale_price'], 2),
'special_price' => round($item['special_price'], 2),
'cof' => round($item['cof'], 2),
'unit' => Units::getName($item['units_id']),
'amount' => round($item['sale_price'] * $item['count'], 2),
'discount' => round($discount)
'discount' => round($discount),
'total_count' => floatval($item['count']),
'profit' => floatval($item['count']) * round($item['sale_price'], 2) - floatval($item['count']) * round($item['special_price'], 2)
);
foreach ($deleted_items as $deleted_item) {
if ($item['menu_code'] == $deleted_item['menu_code']) {
$order_info[$key]['deleted_count'] = $deleted_item['count'];
$order_info[$key]['total_count'] = $order_info[$key]['total_count'] - $deleted_item['count'];
$order_info[$key]['deleted_sum'] = abs($deleted_item['sale_price']) * $deleted_item['count'];
$order_info[$key]['profit'] = $order_info[$key]['total_count'] * round($item['sale_price'], 2) - $order_info[$key]['total_count'] * round($item['special_price'], 2);
$deleted_count += $deleted_item['count'];
$deleted_sum += abs($deleted_item['sale_price']) * $deleted_item['count'];
}
}
$amount += round($item['sale_price'] * $item['count'], 2);
$full_price += round($realPrice,2);
$full_price += round($realPrice, 2);
if ($order_status == "Возвращен" || $order_status == "Возвращен частично") {
foreach ($returned_items as $returned_item) {
if ($item['menu_code'] == $returned_item['code']) {
$order_info[$key]['returned_count'] = $returned_item['count'];
$order_info[$key]['total_count'] = $order_info[$key]['total_count'] - $returned_item['count'];
$order_info[$key]['profit'] = $order_info[$key]['total_count'] * round($item['sale_price'], 2) - $order_info[$key]['total_count'] * round($item['special_price'], 2);
$order_info[$key]['returned_sum'] = abs($returned_item['sale_price']) * $returned_item['count'];
$order_info[$key]['amount'] = round($item['sale_price'] * $item['count'], 2) - (abs($returned_item['sale_price']) * $returned_item['count']);
}
}
}
}
$order = [];
$order[] = array(
$key = count($order_info);
$items_code = [];
foreach ($order_info as $order_info_item) {
$items_code[] = $order_info_item['code'];
}
foreach ($deleted_items as $deleted_item) {
if (in_array($deleted_item['menu_code'], $items_code)) {
break;
} else {
$key++;
$realPrice = $deleted_item['real_price'] * $deleted_item['count'] * $deleted_item['cof'];
$salePrice = $deleted_item['sale_price'] * $deleted_item['count'];
if ($realPrice > 0) {
$discount = $salePrice / $realPrice;
$discount = (1 - $discount) * 100;
} else {
$discount = 0;
}
$order_info[] = array(
'id' => $key,
'code' => $deleted_item['menu_code'],
'name' => Dishes::getName($deleted_item['menu_code']),
'count' => 0,
'returned_count' => 0,
'returned_sum' => 0,
'deleted_count' => floatval($deleted_item['count']),
'deleted_sum' => abs($deleted_item['sale_price']) * $deleted_item['count'],
'price' => round($deleted_item['real_price'], 2),
'sale_price' => round($deleted_item['sale_price'], 2),
'special_price' => Dishes::getSpecialPrice($deleted_item['menu_code']),
'cof' => 1,
'unit' => Units::getName($deleted_item['units_id']),
'amount' => 0,
'discount' => round($discount),
'total_count' => 0,
'profit' => 0
);
$deleted_count += floatval($deleted_item['count']);
$deleted_sum += abs($deleted_item['sale_price']) * $deleted_item['count'];
}
}
$order = array(
'order_id' => $order_id,
'place' => Base::data_decode($order['place_name']),
'table' => $order['table_name'],
'opened' => $open_time,
'closed' => $close_time,
'who_open' => $who_open,
'who_close' => $who_close,
'order_status' => $order_status,
'client_count' => $order_client_count,
'amount' => $amount,
'full_price' => $full_price,
'cash' => $order_cash,
'credit' => $order_credit,
'clearing' => $order_clearing,
'self' => $order_self,
'online' => $order_online,
'presale' => $order_presale,
'items' => $order_info
'items' => $order_info,
'returned_items' => $returned_items,
'returned_count' => $returned_count,
'returned_sum' => $returned_sum,
'returned_method' => $returned_method,
'deleted_count' => $deleted_count,
'deleted_sum' => $deleted_sum
);
return $order;
}

View File

@@ -3,12 +3,22 @@
namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Places extends Model {
protected $table = 'places';
public $timestamps = false;
public static function getName($data) {
$places = Places::where('id', $data)->first();
/**
* Get the tables for the place.
*/
public function tables(): HasMany
{
return $this->hasMany(Tables::class, 'place_id');
}
public static function getName($id) {
$places = self::where('id', $id)->first();
if ($places) {
$place_name = $places['name'];
} else {
@@ -18,5 +28,16 @@ class Places extends Model {
return $place_name;
}
public static function getID($name) {
$places = self::where('name', $name)->first();
if ($places) {
$place_id = $places['id'];
} else {
$place_id = 0;
}
return $place_id;
}
}

View File

@@ -14,11 +14,11 @@ class Printer extends Model {
protected $guarded = [];
public static function getName($data) {
$printer_name = Printer::where('code', $data)->where('is_history', 0)->first();
$printer_name = self::where('code', $data)->where('is_history', 0)->first();
if ($printer_name) {
$printer_name = $printer_name['name'];
} else {
$printer_name = Printer::where('code', $data)->where('is_history', 1)->first();
$printer_name = self::where('code', $data)->where('is_history', 1)->first();
if ($printer_name) {
$printer_name = $printer_name['name'];
} else {

View File

@@ -8,11 +8,11 @@ class Reasons extends Model {
protected $table = 'reasons';
public static function getName($data) {
$reason_name = Reasons::where('code', intval($data))->where('is_history', 0)->first();
$reason_name = self::where('code', intval($data))->where('is_history', 0)->first();
if ($reason_name) {
$reason_name = $reason_name['name'];
} else {
$reason_name = Reasons::where('code', intval($data))->where('is_history', 1)->first();
$reason_name = self::where('code', intval($data))->where('is_history', 1)->first();
if ($reason_name) {
$reason_name = $reason_name['name'];
} else {

View File

@@ -8,8 +8,8 @@ class Right extends Model {
protected $table = 'rights';
public static function add($code, $name) {
if (Right::where('code', $code)->count() == 0) {
$right = new Right([
if (self::where('code', $code)->count() == 0) {
$right = new self([
'code' => $code,
'name' => $name,
]);

View File

@@ -6,4 +6,15 @@ use Illuminate\Database\Eloquent\Model;
class Settings extends Model {
protected $table = 'settings';
public static function getValue($code) {
$value = self::where('code', $code)->first();
if ($value) {
$value = intval($value['value']);
} else {
$value = 0;
}
return $value;
}
}

View File

@@ -6,4 +6,107 @@ use Illuminate\Database\Eloquent\Model;
class ShiftOnlineActions extends Model {
protected $table = 'shift_online_actions';
/**
* Get preCheck count
*/
public static function getPreCheckCount($order_id)
{
$count = self::where('order_code', intval($order_id))
->where('type_action', 21)
->count();
return $count;
}
/**
* Get preCheck count before edit
*/
public static function isPrintedBeforeEdit($order_id)
{
$actions = self::where('order_code', intval($order_id))
->orderBy('time', 'ASC')
->get();
$infos = [];
$delete_trigger = false;
foreach ($actions as $action) {
if ($action['type_action'] == 21 || $action['type_action'] == 5) {
$infos[] = array(
'action' => $action['type_action'],
'time' => $action['time']
);
}
}
foreach ($infos as $key => $info) {
if (isset($infos[$key+1])) {
if ($info['action'] == 21 && $infos[$key+1]['action'] == 5) {
$delete_trigger = true;
}
}
}
return $delete_trigger;
}
/**
* Check merge
*/
public static function hasMerge($order_id)
{
$count = self::where('order_code', intval($order_id))
->where('type_action', 31)
->count();
if ($count > 0) {
$result = true;
} else {
$result = false;
}
return $result;
}
/**
* Check slice
*/
public static function hasSlice($order_id)
{
$count = self::where('order_code', intval($order_id))
->where('type_action', 35)
->count();
if ($count > 0) {
$result = true;
} else {
$result = false;
}
return $result;
}
/**
* Check move
*/
public static function hasMove($order_id)
{
$count = self::where('order_code', intval($order_id))
->where('type_action', 39)
->count();
if ($count > 0) {
$result = true;
} else {
$result = false;
}
return $result;
}
/**
* Check delete
*/
public static function hasDelete($order_id)
{
$count = self::where('order_code', intval($order_id))
->where('type_action', 5)
->count();
if ($count > 0) {
$result = true;
} else {
$result = false;
}
return $result;
}
}

View File

@@ -3,83 +3,338 @@
namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
class ShiftOnlineOrders extends Model
{
protected $table = 'shift_online_orders';
public static function getReturnedItems($order_id)
{
$action = ShiftOnlineActions::where('order_code', $order_id)
->where('type_action', 17)
->orderBy('time', 'desc')
->first();
$returned_order_id = intval($action['value']);
$start_order_items = ShiftOnlineActions::where('order_code', $returned_order_id)
->where('type_action', 2)
->get();
$start_order_info = $cancel_order_info = [];
foreach ($start_order_items as $start_order_item) {
$item = ShiftOnlineItems::where('order_code', $returned_order_id)
->where('menu_code', intval($start_order_item['more']))
->first();
$start_order_info[] = array(
'code' => intval($start_order_item['more']),
'count' => floatval($start_order_item['value']),
'sale_price' => $item['sale_price'],
'special_price' => $item['special_price']
);
}
$canceled_order_items_count = ShiftOnlineActions::where('order_code', $returned_order_id)
->where('type_action', 22)
->count();
if ($canceled_order_items_count > 0) {
$canceled_order_items = ShiftOnlineActions::selectRaw('SUM(value * 1) AS count, order_position')
->where('order_code', $returned_order_id)
->where('type_action', 22)
->groupBy('order_position')
->get();
foreach ($canceled_order_items as $canceled_order_item) {
$item = ShiftOnlineItems::where('order_code', $returned_order_id)
->where('menu_code', $canceled_order_item['order_position'])
->first();
$cancel_order_info[] = array(
'code' => $canceled_order_item['order_position'],
'count' => $canceled_order_item['count'],
'sale_price' => $item['sale_price'],
'special_price' => $item['special_price']
);
}
foreach ($start_order_info as $start_order) {
foreach ($cancel_order_info as $cancel_order) {
if ($start_order['code'] == $cancel_order['code']) {
$start_order['count'] = $start_order['count'] - $cancel_order['count'];
}
}
$item = ShiftOnlineItems::where('order_code', $returned_order_id)
->where('menu_code', $start_order['code'])
->first();
$end_order[] = array(
'code' => $start_order['code'],
'count' => $start_order['count'],
'sale_price' => $item['sale_price'],
'special_price' => $item['special_price']
);
}
} else {
$end_order = $start_order_info;
}
return $end_order;
}
/**
* Get order status
*/
public static function getOrderStatus($order_id)
{
$order_status = '';
$order = self::where('code', $order_id)->first();
$order_online = 0;
$count_online_open = ShiftOnlineActions::where('order_code', $order['code'])
->where('type_action', 45)
->where('more', '<>', '0')
->count();
$count_online_close = ShiftOnlineActions::where('order_code', $order['code'])
->where('type_action', 6)
->count();
if ($count_online_open > 0 && $count_online_close > 0) {
$order_online = $order['order_sum'];
}
$order_double = 0;
$count_double_is_close = self::where('code', $order['code'])
->where('is_closed', 1)
->where('is_deleted', 0)
->where('is_returned', 0)
->count();
$count_double_close = ShiftOnlineActions::where('order_code', $order['code'])
->where('type_action', 6)
->count();
if ($count_double_is_close > 0 && $count_double_close < 1) {
$order_double = $order['order_sum'];
}
if ($order['is_returned'] > 0) {
$action = ShiftOnlineActions::where('order_code', $order_id)
->where('type_action', 17)
->orderBy('time', 'desc')
->first();
$returned_order_id = intval($action['value']);
$canceled_order_items_count = ShiftOnlineActions::where('order_code', $returned_order_id)
->where('type_action', 22)
->count();
if ($canceled_order_items_count > 0) {
$order_status = 'Возвращен частично';
} else {
$order_status = 'Возвращен';
}
} elseif ($order['is_deleted'] > 0 && $order['check_number'] < 1) {
$order_status = 'Удален';
} elseif ($order['is_deleted'] > 0 && $order['check_number'] > 0) {
$order_status = 'Аннулирован';
} elseif ($order['is_waited'] > 0 && $order['is_closed'] < 1 && $order['place_name'] != "ДОСТАВКА") {
$order_status = 'В ожидании';
} elseif ($order_online > 0) {
$order_status = 'Оплачен онлайн';
} elseif ($order_double > 0) {
$order_status = 'Оплачен(*)';
} elseif ($order['place_name'] == "ДОСТАВКА") {
$order_status = 'Доставка';
} else {
$order_status = 'Оплачен';
}
return $order_status;
}
/**
* Get returned order id
*/
public static function getReturnedOrderId($order_id)
{
$order = self::where('code', $order_id)->first();
if ($order['is_returned'] > 0) {
$action = ShiftOnlineActions::where('order_code', $order_id)
->where('type_action', 17)
->first();
$returned_order_id = intval($action['value']);
}
return $returned_order_id;
}
/**
* Get order info
*/
public static function getInfo($order_id)
{
$order = ShiftOnlineOrders::where('code', $order_id)->first();
$order = self::where('code', $order_id)->first();
$open_time = $order['opened'];
$close_time = $order['closed'];
if ($order['closed'] == '0000-00-00 00:00:00') {
$close_time = false;
} else {
$close_time = $order['closed'];
}
$who_open = Staff::getName($order['who_open']);
if ($order['who_close'] == 0) {
$who_close = '';
$who_close = false;
} else {
$who_close = Staff::getName($order['who_close']);
}
$order_client_count = $order['client_count'];
$items = ShiftOnlineItems::where('order_code', $order_id)->where('modificator_code', 0)->get();
$order_status = '';
if ($order['is_deleted'] > 0) {
$order_status = 'Удален';
} elseif ($order['is_returned'] > 0) {
$order_status = 'Возвращен';
} elseif ($order['is_waited'] > 0 && $order['is_closed'] < 1) {
$order_status = 'В ожидании';
} else {
$order_status = 'Оплачен';
$deleted_items = ShiftOnlineDeleted::where('order_code', $order_id)->get();
$order_status = self::getOrderStatus($order_id);
$returned_items = [];
$returned_method = false;
$returned_sum = $returned_count = 0;
$deleted_sum = $deleted_count = 0;
if ($order_status == "Возвращен" || $order_status == "Возвращен частично") {
$returned_items = self::getReturnedItems($order['code']);
foreach ($returned_items as $returned_item) {
$returned_sum += round(abs($returned_item['sale_price']) * $returned_item['count'], 2);
$returned_count += $returned_item['count'];
}
$returned_id = self::getReturnedOrderId($order_id);
$returned_at = self::where('code', $returned_id)->first();
$returned_method = array(
'cash' => abs($returned_at['cash']),
'credit' => abs($returned_at['credit']),
);
}
$order_cash = $order['cash'];
$order_credit = $order['credit'];
$order_clearing = $order['clearing'];
$order_presale = $order['presale'];
$order_self = $order['self'];
$order_online = 0;
$count_online_open = ShiftOnlineActions::where('order_code', $order['code'])
->where('type_action', 45)
->where('more', '<>', '0')
->count();
$count_online_close = ShiftOnlineActions::where('order_code', $order['code'])
->where('type_action', 6)
->count();
if ($count_online_open > 0 && $count_online_close > 0) {
$order_online = $order['order_sum'];
}
$order_info = [];
$amount = $full_price = 0;
foreach ($items as $key => $item) {
$realPrice = $item['real_price'] * $item['count'] * $item['cof'];
$salePrice = $item['sale_price'] * $item['count'];
if ($realPrice > 0) {
$discount = $salePrice / $realPrice;
$discount = (1 - $discount) * 100;
} else {
$discount = 0;
foreach ($items as $key => $item) {
$realPrice = $item['real_price'] * $item['count'] * $item['cof'];
$salePrice = $item['sale_price'] * $item['count'];
if ($realPrice > 0) {
$discount = $salePrice / $realPrice;
$discount = (1 - $discount) * 100;
} else {
$discount = 0;
}
$order_info[] = array(
'id' => $key + 1,
'code' => $item['menu_code'],
'name' => Dishes::getName($item['menu_code']),
'count' => floatval($item['count']),
'returned_count' => 0,
'returned_sum' => 0,
'deleted_count' => 0,
'deleted_sum' => 0,
'price' => round($item['real_price'], 2),
'sale_price' => round($item['sale_price'], 2),
'special_price' => round($item['special_price'], 2),
'cof' => round($item['cof'], 2),
'unit' => Units::getName($item['units_id']),
'amount' => round($item['sale_price'] * $item['count'], 2),
'discount' => round($discount),
'total_count' => floatval($item['count']),
'profit' => floatval($item['count']) * round($item['sale_price'], 2) - floatval($item['count']) * round($item['special_price'], 2)
);
foreach ($deleted_items as $deleted_item) {
if ($item['menu_code'] == $deleted_item['menu_code']) {
$order_info[$key]['deleted_count'] = $deleted_item['count'];
$order_info[$key]['total_count'] = $order_info[$key]['total_count'] - $deleted_item['count'];
$order_info[$key]['deleted_sum'] = abs($deleted_item['sale_price']) * $deleted_item['count'];
$order_info[$key]['profit'] = $order_info[$key]['total_count'] * round($item['sale_price'], 2) - $order_info[$key]['total_count'] * round($item['special_price'], 2);
$deleted_count += $deleted_item['count'];
$deleted_sum += abs($deleted_item['sale_price']) * $deleted_item['count'];
}
}
$amount += round($item['sale_price'] * $item['count'], 2);
$full_price += round($realPrice, 2);
if ($order_status == "Возвращен" || $order_status == "Возвращен частично") {
foreach ($returned_items as $returned_item) {
if ($item['menu_code'] == $returned_item['code']) {
$order_info[$key]['returned_count'] = $returned_item['count'];
$order_info[$key]['total_count'] = $order_info[$key]['total_count'] - $returned_item['count'];
$order_info[$key]['profit'] = $order_info[$key]['total_count'] * round($item['sale_price'], 2) - $order_info[$key]['total_count'] * round($item['special_price'], 2);
$order_info[$key]['returned_sum'] = abs($returned_item['sale_price']) * $returned_item['count'];
$order_info[$key]['amount'] = round($item['sale_price'] * $item['count'], 2) - (abs($returned_item['sale_price']) * $returned_item['count']);
}
}
}
}
$order_info[] = array(
'id' => $key + 1,
'name' => Dishes::getName($item['dish_code']),
'count' => $item['count'],
'price' => $item['real_price'],
'sale_price' => $item['sale_price'],
'cof' => $item['cof'],
'unit' => Units::getName($item['units_id']),
'amount' => round($item['sale_price'] * $item['count'], 2),
'discount' => round($discount)
);
$amount += round($item['sale_price'] * $item['count'], 2);
$full_price += round($realPrice,2);
$key = count($order_info);
$items_code = [];
foreach ($order_info as $order_info_item) {
$items_code[] = $order_info_item['code'];
}
$order = [];
$order[] = array(
foreach ($deleted_items as $deleted_item) {
if (in_array($deleted_item['menu_code'], $items_code)) {
break;
} else {
$key++;
$realPrice = $deleted_item['real_price'] * $deleted_item['count'] * $deleted_item['cof'];
$salePrice = $deleted_item['sale_price'] * $deleted_item['count'];
if ($realPrice > 0) {
$discount = $salePrice / $realPrice;
$discount = (1 - $discount) * 100;
} else {
$discount = 0;
}
$order_info[] = array(
'id' => $key,
'code' => $deleted_item['menu_code'],
'name' => Dishes::getName($deleted_item['menu_code']),
'count' => 0,
'returned_count' => 0,
'returned_sum' => 0,
'deleted_count' => floatval($deleted_item['count']),
'deleted_sum' => abs($deleted_item['sale_price']) * $deleted_item['count'],
'price' => round($deleted_item['real_price'], 2),
'sale_price' => round($deleted_item['sale_price'], 2),
'special_price' => Dishes::getSpecialPrice($deleted_item['menu_code']),
'cof' => 1,
'unit' => Units::getName($deleted_item['units_id']),
'amount' => 0,
'discount' => round($discount),
'total_count' => 0,
'profit' => 0
);
$deleted_count += floatval($deleted_item['count']);
$deleted_sum += abs($deleted_item['sale_price']) * $deleted_item['count'];
}
}
$order = array(
'order_id' => $order_id,
'place' => $order['place_name'],
'table' => $order['table_name'],
'opened' => $open_time,
'closed' => $close_time,
'who_open' => $who_open,
'who_close' => $who_close,
'order_status' => $order_status,
'client_count' => $order_client_count,
'amount' => $amount,
'full_price' => $full_price,
'cash' => $order_cash,
'credit' => $order_credit,
'clearing' => $order_clearing,
'self' => $order_self,
'online' => $order_online,
'presale' => $order_presale,
'items' => $order_info
'items' => $order_info,
'returned_items' => $returned_items,
'returned_count' => $returned_count,
'returned_sum' => $returned_sum,
'returned_method' => $returned_method,
'deleted_count' => $deleted_count,
'deleted_sum' => $deleted_sum
);
return $order;
}

View File

@@ -10,13 +10,13 @@ class Staff extends Model
public static function getName($data)
{
$staff_name = Staff::where('code', intval($data))
$staff_name = self::where('code', intval($data))
->where('is_history', 0)
->first();
if ($staff_name) {
$staff_name = $staff_name['name'];
} else {
$staff_name = Staff::where('code', intval($data))
$staff_name = self::where('code', intval($data))
->where('is_history', 1)
->first();
if ($staff_name) {

View File

@@ -8,8 +8,8 @@ class StaffRights extends Model {
protected $table = 'staff_rights';
public static function add($code, $name) {
if (StaffRights::where('code', $code)->count() == 0) {
$staffRight = new StaffRights([
if (self::where('code', $code)->count() == 0) {
$staffRight = new self([
'code' => $code,
'name' => $name,
]);

View File

@@ -14,8 +14,8 @@ class Subscriber extends Model {
$code = strtolower($destination_module . '_' . $destination_method . '_after_' . $source_module . '_' . $source_method);
if (Subscriber::where('code', $code)->count() == 0) {
$subscriber = new Subscriber([
if (self::where('code', $code)->count() == 0) {
$subscriber = new self([
'code' => $code,
'destination_module' => strtolower($destination_module),
'destination_method' => strtolower($destination_method),

View File

@@ -7,10 +7,11 @@ use Illuminate\Database\Eloquent\Model;
class Tables extends Model
{
protected $table = 'place_tables';
public $timestamps = false;
public static function getName($id)
{
$table = Tables::where('id', $id)->first();
$table = self::where('id', $id)->first();
if ($table) {
$table_name = $table['name'];
} else {

View File

@@ -6,4 +6,29 @@ use Illuminate\Database\Eloquent\Model;
class Terminal extends Model {
protected $table = 'terminals';
public static function getNameById($id): string
{
$terminal_name = self::where('id', intval($id))
->first();
if ($terminal_name) {
$terminal_name = $terminal_name['name'];
} else {
$terminal_name = 'Наименование рабочего места отсутствует';
}
return $terminal_name;
}
public static function getNameByWorkGroup($group_id, $group_code): string
{
$terminal_name = self::where('work_group', intval($group_id))
->where('work_code', intval($group_code))
->first();
if ($terminal_name) {
$terminal_name = $terminal_name['name'];
} else {
$terminal_name = 'Наименование рабочего места отсутствует';
}
return $terminal_name;
}
}

View File

@@ -17,7 +17,7 @@ class Units extends Model
public static function getName($data)
{
$unit_in_list = UnitsList::where('id', $data)->first();
$unit_name = Units::where('id', $unit_in_list['unit_id'])->first();
$unit_name = self::where('id', $unit_in_list['unit_id'])->first();
if ($unit_name) {
$unit_name = $unit_name['name'];
} else {