Files
admin-php-module/models/ShiftOnlineOrders.php
miroman-afk d24bba305f v.2.24
1. POSTBonus in/out
2. POSTPresale in/out
3. Переработана форма гостя
2022-12-14 12:42:39 +03:00

81 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
class ShiftOnlineOrders extends Model
{
protected $table = 'shift_online_orders';
/**
* Get order info
*/
public static function getInfo($order_id)
{
$order = ShiftOnlineOrders::where('code', $order_id)->first();
$open_time = $order['opened'];
$close_time = $order['closed'];
$who_open = Staff::getName($order['who_open']);
$who_close = Staff::getName($order['who_close']);
$items = ShiftOnlineItems::where('order_code', $order_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 = 'В ожидании';
} else {
$order_status = 'Оплачен';
}
$order_cash = $order['cash'];
$order_credit = $order['credit'];
$order_clearing = $order['clearing'];
$order_presale = $order['presale'];
$order_self = $order['self'];
$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;
}
$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, 2)
);
$amount += round($item['sale_price'] * $item['count'], 2);
$full_price += round($realPrice,2);
}
$order = [];
$order[] = array(
'order_id' => $order_id,
'opened' => $open_time,
'closed' => $close_time,
'who_open' => $who_open,
'who_close' => $who_close,
'order_status' => $order_status,
'amount' => $amount,
'full_price' => $full_price,
'cash' => $order_cash,
'credit' => $order_credit,
'clearing' => $order_clearing,
'self' => $order_self,
'presale' => $order_presale,
'items' => $order_info
);
return $order;
}
}