v.2.30
Добавлен расширенный отчет по реализации Добавлен монитор активности
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Base;
|
||||
use App\Component\Models\Cache;
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsActions;
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\ExchangeActions;
|
||||
@@ -17,8 +18,12 @@ use App\Component\Models\Reasons;
|
||||
use App\Component\Models\Report;
|
||||
use App\Component\Models\Settings;
|
||||
use App\Component\Models\Staff;
|
||||
use App\Component\Models\Terminal;
|
||||
use App\Component\Models\Units;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -29,65 +34,9 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
public function command($input, $output = null)
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$reportType = $input['type'];
|
||||
//merge, slice, move
|
||||
if (isset($reportType)) {
|
||||
//merge
|
||||
|
||||
if ($reportType == 'merge') {
|
||||
$code = Filesystem::GetCode($input['token']);
|
||||
$cache = Cache::get($code, 'shift', $input);
|
||||
@@ -174,12 +123,12 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
->where('action_type', 45)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->first();
|
||||
$start_order_place = data_decode($start_order_place['value']);
|
||||
$start_order_place = Base::data_decode($start_order_place['value']);
|
||||
$end_order_place = ExchangeActions::where('order_code', $merge_order)
|
||||
->where('action_type', 45)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->first();
|
||||
$end_order_place = data_decode($end_order_place['value']);
|
||||
$end_order_place = Base::data_decode($end_order_place['value']);
|
||||
$merged_order_items[] = array(
|
||||
'start_order' => $item['order_code'],
|
||||
'end_order' => $merge_order,
|
||||
@@ -206,7 +155,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
//slice
|
||||
|
||||
if ($reportType == 'slice') {
|
||||
$code = Filesystem::GetCode($input['token']);
|
||||
$cache = Cache::get($code, 'shift', $input);
|
||||
@@ -240,12 +189,12 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
->where('action_type', 45)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->first();
|
||||
$from_place = data_decode($from_place['value']);
|
||||
$from_place = Base::data_decode($from_place['value']);
|
||||
$to_place = ExchangeActions::where('order_code', $value)
|
||||
->where('action_type', 45)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->first();
|
||||
$to_place = data_decode($to_place['value']);
|
||||
$to_place = Base::data_decode($to_place['value']);
|
||||
$to_action = ExchangeActions::where('value', $codeOrder)
|
||||
->where('order_code', $value)
|
||||
->where('action_type', 34)
|
||||
@@ -311,10 +260,10 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
$time_from = date('d.m.Y H:i:s', strtotime($data_from['time']));
|
||||
$moved_order_data[] = array(
|
||||
'order' => $item['order_code'],
|
||||
'move_from' => data_decode($data_from['value']),
|
||||
'move_from' => Base::data_decode($data_from['value']),
|
||||
'move_from_staff' => $staff_name_from,
|
||||
'move_from_time' => $time_from,
|
||||
'move_to' => data_decode($item['value']),
|
||||
'move_to' => Base::data_decode($item['value']),
|
||||
'move_to_staff' => $staff_name_to,
|
||||
'move_to_time' => $time_to
|
||||
);
|
||||
@@ -447,6 +396,9 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
->sum('sale_price');
|
||||
$deletedSum = $deletedSum + $deletedOrdersSum;
|
||||
}
|
||||
if ($deletedSum === 0) {
|
||||
$deletedCount = 0;
|
||||
}
|
||||
$staff_data[] = array(
|
||||
'name' => $name,
|
||||
'code' => $code,
|
||||
@@ -580,6 +532,9 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
->whereIn('shift_id', $shifts)
|
||||
->sum('sale_price');
|
||||
}
|
||||
if ($deletedSum === 0) {
|
||||
$deletedCount = 0;
|
||||
}
|
||||
$staff_data[] = array(
|
||||
'name' => $name,
|
||||
'code' => $code,
|
||||
@@ -708,7 +663,29 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
->where('opened', '>', $start_date)
|
||||
->where('closed', '<', $end_date)
|
||||
->get();
|
||||
|
||||
$shifts_count = ExchangeShifts::select('id')
|
||||
->where('opened', '>', $start_date)
|
||||
->where('closed', '<', $end_date)
|
||||
->count();
|
||||
$shift_orders = [];
|
||||
$totalCount = $totalSum = 0;
|
||||
if ($shifts_count < 1) {
|
||||
if (Report::where('start_date', $start_date)->where('end_date', $end_date)->where('report_type', 'deleted')->count() < 1) {
|
||||
$report = new Report;
|
||||
$report->user_id = intval($input['admin_user_id']);
|
||||
$report->name = 'Отчет по удалениям';
|
||||
$report->shift_id = 0;
|
||||
$report->start_date = $start_date;
|
||||
$report->end_date = $end_date;
|
||||
$report->report_type = 'deleted';
|
||||
$report->save();
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Удаления отсутствуют',
|
||||
'totalCount' => 0
|
||||
];
|
||||
}
|
||||
foreach ($shifts as $shift) {
|
||||
$shift_id = $shift['id'];
|
||||
$actionsResult = ExchangeDeleted::select('order_code', 'menu_code', 'count', 'sale_price', 'item_id', 'shift_id')
|
||||
@@ -879,6 +856,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($input['start_date']) && isset($input['end_date'])) {
|
||||
$end_date = date('Y-m-d H:i:s', strtotime($input['end_date']));
|
||||
$start_date = date('Y-m-d H:i:s', strtotime($input['start_date']));
|
||||
@@ -1084,10 +1062,8 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
'total_count' => round($total_count, 2),
|
||||
'total_sum' => round($total_sum, 2)
|
||||
);
|
||||
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
return $cache;
|
||||
}
|
||||
|
||||
if (isset($input['start_date']) && isset($input['end_date'])) {
|
||||
$end_date = date('Y-m-d H:i:s', strtotime($input['end_date'] . ' 23:59:59'));
|
||||
$start_date = date('Y-m-d H:i:s', strtotime($input['start_date'] . ' 00:00:01'));
|
||||
@@ -1226,13 +1202,20 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
'total_count' => round($total_count, 2),
|
||||
'total_sum' => round($total_sum, 2)
|
||||
);
|
||||
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
return $cache;
|
||||
}
|
||||
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
if ($reportType == 'statistic') {
|
||||
$code = Filesystem::GetCode($input['token']);
|
||||
$cache = Cache::get($code, 'shift', $input);
|
||||
if ($cache) {
|
||||
return $cache;
|
||||
}
|
||||
if (isset($input['shift_id'])) {
|
||||
$shift_id = $input['shift_id'];
|
||||
$shift_time = ExchangeShifts::where('id', $shift_id)->first();
|
||||
@@ -1492,7 +1475,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
->where('shift_id', $shift_id)
|
||||
->sum('order_sum');
|
||||
}
|
||||
return [
|
||||
$return = array(
|
||||
'status' => 'success',
|
||||
'fiscal' => [
|
||||
'income_sum' => $checkout_sum,
|
||||
@@ -1543,7 +1526,11 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
'pay_echeck' => $pay_echeck_sum,
|
||||
'pay_delivery' => $pay_delivery_sum
|
||||
]
|
||||
];
|
||||
);
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
if (isset($input['start_date']) && isset($input['end_date'])) {
|
||||
@@ -1839,7 +1826,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
$report->save();
|
||||
}
|
||||
|
||||
return [
|
||||
$return = array(
|
||||
'status' => 'success',
|
||||
'fiscal' => [
|
||||
'income_sum' => $checkout_sum,
|
||||
@@ -1890,12 +1877,20 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
'pay_echeck' => $pay_echeck_sum,
|
||||
'pay_delivery' => $pay_delivery_sum
|
||||
]
|
||||
];
|
||||
|
||||
);
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
|
||||
if ($reportType == 'payment') {
|
||||
$code = Filesystem::GetCode($input['token']);
|
||||
$cache = Cache::get($code, 'shift', $input);
|
||||
if ($cache) {
|
||||
return $cache;
|
||||
}
|
||||
if (isset($input['shift_id'])) {
|
||||
$shift_id = $input['shift_id'];
|
||||
$shift_time = ExchangeShifts::where('id', $shift_id)->first();
|
||||
@@ -1946,13 +1941,13 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
if ($sum_payments == 0) {
|
||||
continue;
|
||||
}
|
||||
$cash_cof = round($order['cash'] / $sum_payments, 2);
|
||||
$credit_cof = round($order['credit'] / $sum_payments, 2);
|
||||
$presale_cof = round($order['presale'] / $sum_payments, 2);
|
||||
$self_cof = round($order['self'] / $sum_payments, 2);
|
||||
$clearing_cof = round($order['clearing'] / $sum_payments, 2);
|
||||
$online_cof = round($order_online / $sum_payments, 2);
|
||||
$emoney_cof = round($order_emoney / $sum_payments, 2);
|
||||
$cash_cof = $order['cash'] / $sum_payments;
|
||||
$credit_cof = $order['credit'] / $sum_payments;
|
||||
$presale_cof = $order['presale'] / $sum_payments;
|
||||
$self_cof = $order['self'] / $sum_payments;
|
||||
$clearing_cof = $order['clearing'] / $sum_payments;
|
||||
$online_cof = $order_online / $sum_payments;
|
||||
$emoney_cof = $order_emoney / $sum_payments;
|
||||
$items = ExchangeItems::where('shift_id', $shift_id)
|
||||
->where('order_code', $order['code'])
|
||||
->get();
|
||||
@@ -1982,11 +1977,14 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
'payments' => $item
|
||||
);
|
||||
}
|
||||
$return = [
|
||||
$return = array(
|
||||
'status' => 'success',
|
||||
'items' => $out
|
||||
];
|
||||
return $return;
|
||||
);
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
|
||||
}
|
||||
if (isset($input['start_date']) && isset($input['end_date'])) {
|
||||
@@ -2043,20 +2041,19 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
if ($sum_payments == 0) {
|
||||
continue;
|
||||
}
|
||||
$cash_cof = round($order['cash'] / $sum_payments, 2);
|
||||
$credit_cof = round($order['credit'] / $sum_payments, 2);
|
||||
$presale_cof = round($order['presale'] / $sum_payments, 2);
|
||||
$self_cof = round($order['self'] / $sum_payments, 2);
|
||||
$clearing_cof = round($order['clearing'] / $sum_payments, 2);
|
||||
$online_cof = round($order_online / $sum_payments, 2);
|
||||
$emoney_cof = round($order_emoney / $sum_payments, 2);
|
||||
$cash_cof = $order['cash'] / $sum_payments;
|
||||
$credit_cof = $order['credit'] / $sum_payments;
|
||||
$presale_cof = $order['presale'] / $sum_payments;
|
||||
$self_cof = $order['self'] / $sum_payments;
|
||||
$clearing_cof = $order['clearing'] / $sum_payments;
|
||||
$online_cof = $order_online / $sum_payments;
|
||||
$emoney_cof = $order_emoney / $sum_payments;
|
||||
$items = ExchangeItems::where('shift_id', $shift_id)
|
||||
->where('order_code', $order['code'])
|
||||
->get();
|
||||
foreach ($items as $item) {
|
||||
$sum = round(($item['count'] - $item['count_return']) * $item['sale_price'], 2);
|
||||
$printer_code = Dishes::GetPrinterCode($item['dishes_code']);
|
||||
Log::debug($printer_code);
|
||||
$report[$printer_code]['cash'] += round($sum * $cash_cof, 2);
|
||||
$report[$printer_code]['credit'] += round($sum * $credit_cof, 2);
|
||||
$report[$printer_code]['presale'] += round($sum * $presale_cof, 2);
|
||||
@@ -2081,11 +2078,339 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
|
||||
'payments' => $item
|
||||
);
|
||||
}
|
||||
$return = [
|
||||
$return = array(
|
||||
'status' => 'success',
|
||||
'items' => $out
|
||||
];
|
||||
return $return;
|
||||
);
|
||||
if (Report::where('start_date', $start_date)->where('end_date', $end_date)->where('report_type', 'payment')->count() < 1) {
|
||||
$report = new Report;
|
||||
$report->user_id = intval($input['admin_user_id']);
|
||||
$report->name = 'Отчет по отделам и видам оплат';
|
||||
$report->shift_id = 0;
|
||||
$report->start_date = $start_date;
|
||||
$report->end_date = $end_date;
|
||||
$report->report_type = 'payment';
|
||||
$report->save();
|
||||
}
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
|
||||
if ($reportType == "report_construct") {
|
||||
$code = Filesystem::GetCode($input['token']);
|
||||
$cache = Cache::get($code, 'shift', $input);
|
||||
if ($cache) {
|
||||
return $cache;
|
||||
}
|
||||
if (isset($input['shift_id'])) {
|
||||
$shift_id = $input['shift_id'];
|
||||
$shift_data = ExchangeShifts::where('id', $shift_id)->first();
|
||||
$close_actions = ExchangeActions::select('order_code')
|
||||
->where('shift_id', $shift_id)
|
||||
->groupBy('order_code')
|
||||
->get();
|
||||
$close_actions_count = ExchangeActions::select('order_code')
|
||||
->where('shift_id', $shift_id)
|
||||
->groupBy('order_code')
|
||||
->count();
|
||||
if ($close_actions_count < 1) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Заказы отсутствуют',
|
||||
];
|
||||
}
|
||||
$order_ids = [];
|
||||
foreach ($close_actions as $close_action) {
|
||||
$order_status = ExchangeOrders::getOrderStatus($close_action['order_code'], $shift_id);
|
||||
if ($order_status != 'Удален' && $order_status != 'Возвращен') {
|
||||
$order_ids[] = $close_action['order_code'];
|
||||
}
|
||||
}
|
||||
$items = ExchangeItems::selectRaw('code, menu_code, dishes_code, order_code, units_id, (count - count_return) as count, cof, real_price, sale_price, special_price, shift_id')
|
||||
->where('shift_id', $shift_id)
|
||||
->whereIn('order_code', $order_ids)
|
||||
->get();
|
||||
$collection = new Collection();
|
||||
foreach ($items as $item) {
|
||||
$order_cash_cof = $order_credit_cof = $order_presale_cof = $order_clearing_cof = 0;
|
||||
$order = ExchangeOrders::where('code', $item['order_code'])
|
||||
->where('shift_id', $shift_id)
|
||||
->first();
|
||||
$returned_order_order_sum = $returned_order_cash = $returned_order_credit = $returned_order_presale = $returned_order_clearing = 0;
|
||||
if ($order['is_returned'] > 0) {
|
||||
$returned_order_id = ExchangeOrders::getReturnedOrderId($item['order_code'], $shift_id);
|
||||
$returned_order = ExchangeOrders::where('code', $returned_order_id)
|
||||
->where('shift_id', $shift_id)
|
||||
->first();
|
||||
$returned_order_order_sum = abs($returned_order['order_sum']);
|
||||
$returned_order_cash = abs($returned_order['cash']);
|
||||
$returned_order_credit = abs($returned_order['credit']);
|
||||
$returned_order_presale = abs($returned_order['presale']);
|
||||
$returned_order_clearing = abs($returned_order['clearing']);
|
||||
}
|
||||
|
||||
$order_order_sum = $order['order_sum'] - $returned_order_order_sum;
|
||||
$order_cash = $order['cash'] - $returned_order_cash;
|
||||
$order_credit = $order['credit'] - $returned_order_credit;
|
||||
$order_presale = $order['presale'] - $returned_order_presale;
|
||||
$order_clearing = $order['clearing'] - $returned_order_clearing;
|
||||
if ($order['client_code'] != '') {
|
||||
$order_client_name = Client::getName($order['client_code']);
|
||||
} else {
|
||||
$order_client_name = '';
|
||||
}
|
||||
if ($order_order_sum > 0) {
|
||||
$order_cash_cof = $order_cash / $order_order_sum;
|
||||
$order_credit_cof = $order_credit / $order_order_sum;
|
||||
$order_presale_cof = $order_presale / $order_order_sum;
|
||||
$order_clearing_cof = $order_clearing / $order_order_sum;
|
||||
}
|
||||
|
||||
$create_actions = ExchangeActions::where('action_type', 2)
|
||||
->where('shift_id', $shift_id)
|
||||
->where('order_position', $item['code'])
|
||||
->get();
|
||||
$create_count = 0;
|
||||
|
||||
foreach ($create_actions as $create_action) {
|
||||
$create_count += Base::toFloat($create_action['value']);
|
||||
if ($create_count <= $item['count']) {
|
||||
$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;
|
||||
}
|
||||
$item_menu_code = $item['menu_code'];
|
||||
$item_dishes_code = $item['dishes_code'];
|
||||
$item_order_code = $item['order_code'];
|
||||
$item_units_id = $item['units_id'];
|
||||
$item_count = Base::toFloat($create_action['value']);
|
||||
$item_cof = $item['cof'];
|
||||
$item_real_price = $item['real_price'];
|
||||
$item_sale_price = $item['sale_price'];
|
||||
$item_special_price = $item['special_price'];
|
||||
$item_cash = $item_count * $item_sale_price * $order_cash_cof;
|
||||
$item_credit = $item_count * $item_sale_price * $order_credit_cof;
|
||||
$item_presale = $item_count * $item_sale_price * $order_presale_cof;
|
||||
$item_clearing = $item_count * $item_sale_price * $order_clearing_cof;
|
||||
$item_discount_sum = $item_real_price - $item_sale_price;
|
||||
$item_staff = Staff::getName($create_action['who']);
|
||||
$item_time = $create_action['time'];
|
||||
$item_printer = Printer::getName(Dishes::GetPrinterCode($item_menu_code));
|
||||
$item_work_place = Terminal::getNameByWorkGroup($create_action['work_group'], $create_action['work_code']);
|
||||
$items_array = array(
|
||||
'shift_id' => $shift_id,
|
||||
'work_place' => $item_work_place,
|
||||
'place_name' => Base::data_decode($order['place_name']),
|
||||
'table_name' => $order['table_name'],
|
||||
'printer_name' => $item_printer,
|
||||
'client_name' => $order_client_name,
|
||||
'staff_name' => $item_staff,
|
||||
'order_code' => $item_order_code,
|
||||
'item_time' => $item_time,
|
||||
'item_menu_code' => $item_menu_code,
|
||||
'item_dishes_code' => $item_dishes_code,
|
||||
'item_name' => Dishes::getName($item_menu_code),
|
||||
'item_units_id' => $item_units_id,
|
||||
'item_units_name' => Units::getName($item_units_id),
|
||||
'item_cof' => floatval($item_cof),
|
||||
'item_count' => $item_count,
|
||||
'item_real_price' => floatval($item_real_price),
|
||||
'item_sale_price' => floatval($item_sale_price),
|
||||
'item_special_price' => floatval($item_special_price),
|
||||
'item_cash' => $item_cash,
|
||||
'item_credit' => $item_credit,
|
||||
'item_presale' => $item_presale,
|
||||
'item_clearing' => $item_clearing,
|
||||
'item_discount_sum' => round($item_discount_sum, 2),
|
||||
'item_discount_value' => round($discount, 2),
|
||||
'order_opened' => $order['opened'],
|
||||
'order_closed' => $order['closed'],
|
||||
'order_check_number' => $order['check_number'],
|
||||
'shift_opened' => $shift_data['opened'],
|
||||
'shift_closed' => $shift_data['closed'],
|
||||
);
|
||||
$collection->push((object)$items_array);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$return = array(
|
||||
'status' => 'success',
|
||||
'data' => $collection
|
||||
);
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
if (isset($input['start_date']) && isset($input['end_date'])) {
|
||||
$end_date = date('Y-m-d H:i:s', strtotime($input['end_date'] . ' 23:59:59'));
|
||||
$start_date = date('Y-m-d H:i:s', strtotime($input['start_date'] . ' 00:00:01'));
|
||||
$shifts = ExchangeShifts::select('id', 'opened', 'closed')
|
||||
->where('opened', '>', $start_date)
|
||||
->where('closed', '<', $end_date)
|
||||
->get();
|
||||
$collection = new Collection();
|
||||
foreach ($shifts as $shift) {
|
||||
$shift_id = $shift['id'];
|
||||
$close_actions = ExchangeActions::select('order_code')
|
||||
->where('shift_id', $shift_id)
|
||||
->groupBy('order_code')
|
||||
->get();
|
||||
$close_actions_count = ExchangeActions::select('order_code')
|
||||
->where('shift_id', $shift_id)
|
||||
->groupBy('order_code')
|
||||
->count();
|
||||
if ($close_actions_count < 1) {
|
||||
continue;
|
||||
}
|
||||
$order_ids = [];
|
||||
foreach ($close_actions as $close_action) {
|
||||
$order_status = ExchangeOrders::getOrderStatus($close_action['order_code'], $shift_id);
|
||||
if ($order_status != 'Удален' && $order_status != 'Возвращен') {
|
||||
$order_ids[] = $close_action['order_code'];
|
||||
}
|
||||
}
|
||||
$items = ExchangeItems::selectRaw('code, menu_code, dishes_code, order_code, units_id, (count - count_return) as count, cof, real_price, sale_price, special_price, shift_id')
|
||||
->where('shift_id', $shift_id)
|
||||
->whereIn('order_code', $order_ids)
|
||||
->get();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$order_cash_cof = $order_credit_cof = $order_presale_cof = $order_clearing_cof = 0;
|
||||
$order = ExchangeOrders::where('code', $item['order_code'])
|
||||
->where('shift_id', $shift_id)
|
||||
->first();
|
||||
$returned_order_order_sum = $returned_order_cash = $returned_order_credit = $returned_order_presale = $returned_order_clearing = 0;
|
||||
if ($order['is_returned'] > 0) {
|
||||
$returned_order_id = ExchangeOrders::getReturnedOrderId($item['order_code'], $shift_id);
|
||||
$returned_order = ExchangeOrders::where('code', $returned_order_id)
|
||||
->where('shift_id', $shift_id)
|
||||
->first();
|
||||
$returned_order_order_sum = abs($returned_order['order_sum']);
|
||||
$returned_order_cash = abs($returned_order['cash']);
|
||||
$returned_order_credit = abs($returned_order['credit']);
|
||||
$returned_order_presale = abs($returned_order['presale']);
|
||||
$returned_order_clearing = abs($returned_order['clearing']);
|
||||
}
|
||||
|
||||
$order_order_sum = $order['order_sum'] - $returned_order_order_sum;
|
||||
$order_cash = $order['cash'] - $returned_order_cash;
|
||||
$order_credit = $order['credit'] - $returned_order_credit;
|
||||
$order_presale = $order['presale'] - $returned_order_presale;
|
||||
$order_clearing = $order['clearing'] - $returned_order_clearing;
|
||||
if ($order['client_code'] != '') {
|
||||
$order_client_name = Client::getName($order['client_code']);
|
||||
} else {
|
||||
$order_client_name = '';
|
||||
}
|
||||
if ($order_order_sum > 0) {
|
||||
$order_cash_cof = $order_cash / $order_order_sum;
|
||||
$order_credit_cof = $order_credit / $order_order_sum;
|
||||
$order_presale_cof = $order_presale / $order_order_sum;
|
||||
$order_clearing_cof = $order_clearing / $order_order_sum;
|
||||
}
|
||||
|
||||
$create_actions = ExchangeActions::where('action_type', 2)
|
||||
->where('shift_id', $shift_id)
|
||||
->where('order_position', $item['code'])
|
||||
->get();
|
||||
$create_count = 0;
|
||||
|
||||
foreach ($create_actions as $create_action) {
|
||||
$create_count += Base::toFloat($create_action['value']);
|
||||
if ($create_count <= $item['count']) {
|
||||
$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;
|
||||
}
|
||||
$item_menu_code = $item['menu_code'];
|
||||
$item_dishes_code = $item['dishes_code'];
|
||||
$item_order_code = $item['order_code'];
|
||||
$item_units_id = $item['units_id'];
|
||||
$item_count = Base::toFloat($create_action['value']);
|
||||
$item_cof = $item['cof'];
|
||||
$item_real_price = $item['real_price'];
|
||||
$item_sale_price = $item['sale_price'];
|
||||
$item_special_price = $item['special_price'];
|
||||
$item_cash = $item_count * $item_sale_price * $order_cash_cof;
|
||||
$item_credit = $item_count * $item_sale_price * $order_credit_cof;
|
||||
$item_presale = $item_count * $item_sale_price * $order_presale_cof;
|
||||
$item_clearing = $item_count * $item_sale_price * $order_clearing_cof;
|
||||
$item_discount_sum = $item_real_price - $item_sale_price;
|
||||
$item_staff = Staff::getName($create_action['who']);
|
||||
$item_time = $create_action['time'];
|
||||
$item_printer = Printer::getName(Dishes::GetPrinterCode($item_menu_code));
|
||||
$item_work_place = Terminal::getNameByWorkGroup($create_action['work_group'], $create_action['work_code']);
|
||||
$items_array = array(
|
||||
'shift_id' => $shift_id,
|
||||
'work_place' => $item_work_place,
|
||||
'place_name' => Base::data_decode($order['place_name']),
|
||||
'table_name' => $order['table_name'],
|
||||
'printer_name' => $item_printer,
|
||||
'client_name' => $order_client_name,
|
||||
'staff_name' => $item_staff,
|
||||
'order_code' => $item_order_code,
|
||||
'item_time' => $item_time,
|
||||
'item_menu_code' => $item_menu_code,
|
||||
'item_dishes_code' => $item_dishes_code,
|
||||
'item_name' => Dishes::getName($item_menu_code),
|
||||
'item_units_id' => $item_units_id,
|
||||
'item_units_name' => Units::getName($item_units_id),
|
||||
'item_cof' => floatval($item_cof),
|
||||
'item_count' => $item_count,
|
||||
'item_real_price' => floatval($item_real_price),
|
||||
'item_sale_price' => floatval($item_sale_price),
|
||||
'item_special_price' => floatval($item_special_price),
|
||||
'item_cash' => $item_cash,
|
||||
'item_credit' => $item_credit,
|
||||
'item_presale' => $item_presale,
|
||||
'item_clearing' => $item_clearing,
|
||||
'item_discount_sum' => round($item_discount_sum, 2),
|
||||
'item_discount_value' => round($discount, 2),
|
||||
'order_opened' => $order['opened'],
|
||||
'order_closed' => $order['closed'],
|
||||
'order_check_number' => $order['check_number'],
|
||||
'shift_opened' => $shift['opened'],
|
||||
'shift_closed' => $shift['closed'],
|
||||
);
|
||||
$collection->push((object)$items_array);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Report::where('start_date', $start_date)->where('end_date', $end_date)->where('report_type', 'reportRealisationConstruct')->count() < 1) {
|
||||
$report = new Report;
|
||||
$report->user_id = intval($input['admin_user_id']);
|
||||
$report->name = 'Расширенный отчет по реализации';
|
||||
$report->shift_id = 0;
|
||||
$report->start_date = $start_date;
|
||||
$report->end_date = $end_date;
|
||||
$report->report_type = 'reportRealisationConstruct';
|
||||
$report->save();
|
||||
}
|
||||
$return = array(
|
||||
'status' => 'success',
|
||||
'data' => $collection
|
||||
);
|
||||
if (!$cache) {
|
||||
$cache = Cache::store(strval($code), 'shift', $input, $return);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user