Files
admin-php-module/models/ExchangeOrders.php
miroman-afk 723e9a8768 v.2.25
Small fix
2022-12-22 12:52:42 +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 ExchangeOrders extends Model
{
protected $table = 'exchange_orders';
/**
* Get order info
*/
public static function getInfo($order_id, $shift_id)
{
$order = ExchangeOrders::where('code', $order_id)->where('shift_id', $shift_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 = 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 = 'В ожидании';
} 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['menu_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;
}
}