diff --git a/.gitignore b/.gitignore
index 577cb99..4215dec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ vendor/
build.zip
places.xml
*.log
+*.log
diff --git a/Logs/04.02.2022_00.23.38.log b/Logs/04.02.2022_00.23.38.log
deleted file mode 100644
index dfb600f..0000000
--- a/Logs/04.02.2022_00.23.38.log
+++ /dev/null
@@ -1 +0,0 @@
-{"status":"success","version":"2.13","file":"http:\/\/portal.hrc.by\/uploads\/modules\/v1\/2.13\/build.zip","name":"v1"}
diff --git a/commands/GETBot.php b/commands/GETBot.php
index d4b90a6..bae1f23 100644
--- a/commands/GETBot.php
+++ b/commands/GETBot.php
@@ -4,7 +4,7 @@ namespace App\Commands;
use App\Component\Models\Dishes;
use App\Component\Models\Folders;
-use App\Component\Models\OrderBot;
+use App\Component\Models\OrderBotStorage;
use App\Component\Models\Settings;
use App\Component\Models\Tasks;
use App\Console\Commands\HRCCommand;
@@ -25,11 +25,11 @@ class GETBot extends HRCCommand implements HRCCommandInterface
Folders::where('is_bot_export', '=', 0)
->update(['is_bot_export' => 1]);
}
- $ordersinfo = Tasks::where('method', 'orderinfo')
+ $orders_info = Tasks::where('method', 'orderinfo')
->get();
$delete_params = ['closed', 'deleted'];
- foreach ($ordersinfo as $more) {
- $order = OrderBot::where('id', intval($more['more']))
+ foreach ($orders_info as $more) {
+ $order = OrderBotStorage::where('id', intval($more['more']))
->whereIn('status', $delete_params)
->get();
foreach ($order as $value) {
diff --git a/commands/GETClearCache.php b/commands/GETClearCache.php
new file mode 100644
index 0000000..ea39782
--- /dev/null
+++ b/commands/GETClearCache.php
@@ -0,0 +1,30 @@
+ 'success',
+ ];
+ }
+ if (!isset($input['folder'])) {
+ Filesystem::ClearFolder(self::cacheFolder . $code . '/');
+ return [
+ 'status' => 'success',
+ ];
+ }
+ }
+}
\ No newline at end of file
diff --git a/commands/GETClientInfo.php b/commands/GETClientInfo.php
index 921c3a1..2893a25 100644
--- a/commands/GETClientInfo.php
+++ b/commands/GETClientInfo.php
@@ -30,6 +30,22 @@ class GETClientInfo extends HRCCommand implements HRCCommandInterface
$orders_sum_current = ShiftOnlineOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->sum('full_sum');
$orders_count = $orders_count_exchange + $orders_count_current;
$orders_sum = $orders_sum_exchange + $orders_sum_current;
+ $barcode = Client::getBarcode($client_guid);
+ if ($client['is_special_price'] == 0) {
+ $special_price = false;
+ } else {
+ $special_price = true;
+ }
+ if ($client['is_employee'] == 0) {
+ $employee = false;
+ } else {
+ $employee = true;
+ }
+ if ($client['is_block'] == 0) {
+ $is_block = false;
+ } else {
+ $is_block = true;
+ }
$result = array(
'id' => $client['id'],
'name' => $client['name'],
@@ -41,6 +57,10 @@ class GETClientInfo extends HRCCommand implements HRCCommandInterface
'order_sum' => round($orders_sum, 2),
'presale' => $presale,
'bonus' => intval($bonus),
+ 'barcode' => $barcode,
+ 'special_price' => $special_price,
+ 'employee' => $employee,
+ 'is_block' => $is_block,
)
);
return [
diff --git a/commands/GETClientOrders.php b/commands/GETClientOrders.php
index 399e9ca..bb8e321 100644
--- a/commands/GETClientOrders.php
+++ b/commands/GETClientOrders.php
@@ -35,6 +35,7 @@ class GETClientOrders extends HRCCommand implements HRCCommandInterface
return [
'status' => 'success',
'orders' => $orders,
+ 'count' => count($orders)
];
} else {
return [
diff --git a/commands/GETClients.php b/commands/GETClients.php
index 42d9c84..830bb70 100644
--- a/commands/GETClients.php
+++ b/commands/GETClients.php
@@ -3,17 +3,9 @@
namespace App\Commands;
use App\Component\Models\Client;
-use App\Component\Models\ClientsAddress;
-use App\Component\Models\ClientsBarcode;
-use App\Component\Models\ClientsBonus;
-use App\Component\Models\ClientsEmail;
use App\Component\Models\ClientsGroup;
-use App\Component\Models\ClientsPhone;
-use App\Component\Models\ClientsPresale;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
-use Carbon\Carbon;
-use Illuminate\Support\Facades\Log;
class GETClients extends HRCCommand implements HRCCommandInterface
{
@@ -21,99 +13,6 @@ class GETClients extends HRCCommand implements HRCCommandInterface
public function command($input, $output = null)
{
- if (isset($input['type']) && $input['type'] == 'loyalty') {
- $last_update = Carbon::createFromTimestampUTC($input['last_update'])->timezone('Europe/Minsk');
- $phones = ClientsPhone::where('updated_at', '>=', $last_update)->get();
- $addresses = ClientsAddress::where('updated_at', '>=', $last_update)->get();
- $barcodes = ClientsBarcode::where('updated_at', '>=', $last_update)->get();
- $emails = ClientsEmail::where('updated_at', '>=', $last_update)->get();
- $presales = ClientsPresale::where('updated_at', '>=', $last_update)->get();
- $bonuses = ClientsBonus::where('updated_at', '>=', $last_update)->get();
- $clients = Client::where('updated_at', '>=', $last_update)->get();
- $info = [];
- foreach ($phones as $phone) {
- $info[] = $phone['client_guid'];
- }
- foreach ($addresses as $address) {
- $info[] = $address['client_guid'];
- }
- foreach ($barcodes as $barcode) {
- $info[] = $barcode['client_guid'];
- }
- foreach ($emails as $email) {
- $info[] = $email['client_guid'];
- }
- foreach ($presales as $presale) {
- $info[] = $presale['client_guid'];
- }
- foreach ($bonuses as $bonus) {
- $info[] = $bonus['client_guid'];
- }
- foreach ($clients as $client) {
- $info[] = $client['user_code'];
- }
- $guides = array_values(array_unique($info));
- $email = $phone = $client = [];
- foreach ($guides as $guid) {
- $email_address = Client::getEmail($guid);
- $phone_number = Client::getPhone($guid);
- $client_info = Client::where('user_code', $guid)->first();
- $email[] = array(
- 'email' => $email_address
- );
- $phone[] = array(
- 'phone' => $phone_number
- );
- $badge[] = array(
- 'name' => 'Test',
- 'code' => 1
- );
- $bonus_dishes[] = array(
- 'code' => ''
- );
- if (ClientsBonus::getBonus($guid) > 0) {
- $bonus_info[] = array(
- 'amount' => ClientsBonus::getBonus($guid),
- 'dishes' => $bonus_dishes
- );
- } else {
- $bonus_info[] = array(
- 'amount' => ClientsBonus::getBonus($guid)
- );
- }
-
- $group_info = ClientsGroup::where('code', $client_info['group_id'])->first();
- $client[] = array(
- 'id' => $client_info['id'],
- 'name' => $client_info['name'],
- 'guid' => $guid,
- 'presale' => ClientsPresale::getPresale($guid),
- 'bonuses' => $bonus_info,
- 'barcode' => Client::getBarcode($guid),
- 'group_id' => $client_info['group_id'],
- 'emails' => $email,
- 'phones' => $phone,
- 'badges' => $badge
- );
- $groups[] = $group_info['code'];
- $email = $phone = $badge = $bonus_dishes = $bonus_info = [];
- }
- $groups_guides = array_values(array_unique($groups));
- foreach ($groups_guides as $group) {
- $group_info = ClientsGroup::where('code', $group)->first();
- $groups_info[] = array(
- 'id' => $group_info['id'],
- 'name' => $group_info['name'],
- 'guid' => $group_info['code'],
- );
- }
-
- return [
- 'status' => 'success',
- 'clients' => $client,
- 'groups' => $groups_info,
- ];
- }
if (ClientsGroup::where('code', '0')->count() == 0) {
$group = new ClientsGroup([
'code' => '0',
@@ -145,12 +44,33 @@ class GETClients extends HRCCommand implements HRCCommandInterface
$phone = Client::getPhone($client['user_code']);
$email = Client::getEmail($client['user_code']);
$address = Client::getAddress($client['user_code']);
+ $barcode = Client::getBarcode($client['user_code']);
+ if ($client['is_special_price'] == 0) {
+ $special_price = false;
+ } else {
+ $special_price = true;
+ }
+ if ($client['is_employee'] == 0) {
+ $employee = false;
+ } else {
+ $employee = true;
+ }
+ if ($client['is_block'] == 0) {
+ $is_block = false;
+ } else {
+ $is_block = true;
+ }
$out[] = array(
'id' => $client['id'],
'name' => $client['name'],
'phone' => $phone,
'email' => $email,
'address' => $address,
+ 'barcode' => $barcode,
+ 'special_price' => $special_price,
+ 'employee' => $employee,
+ 'is_block' => $is_block,
+
);
}
return [
diff --git a/commands/GETCompanyClients.php b/commands/GETCompanyClients.php
new file mode 100644
index 0000000..d195ba8
--- /dev/null
+++ b/commands/GETCompanyClients.php
@@ -0,0 +1,95 @@
+subHours(3);
+ $last_update = $dt->format('Y-m-d H:i:s');
+ $clients = Client::select('id', 'name', 'user_code', 'group_id', 'last_change', 'updated_at')
+ ->where('updated_at', '>', $last_update)
+ ->get();
+ if (count($clients) < 1) {
+ return [
+ 'status' => 'success',
+ 'clients' => [],
+ 'groups' => [],
+ ];
+ }
+ foreach ($clients as $client) {
+ $email_address = Client::getEmail($client['user_code']);
+ $phone_number = Client::getPhone($client['user_code']);
+ $email[] = array(
+ 'email' => $email_address
+ );
+ $phone[] = array(
+ 'phone' => $phone_number
+ );
+ $badge[] = array(
+ 'name' => 'Test',
+ 'code' => 1
+ );
+ $bonus_dishes[] = array(
+ 'code' => ''
+ );
+ if (ClientsBonus::getBonus($client['user_code']) > 0) {
+ $bonus_info[] = array(
+ 'amount' => ClientsBonus::getBonus($client['user_code']),
+ 'dishes' => $bonus_dishes
+ );
+ } else {
+ $bonus_info = array(
+ 'amount' => ClientsBonus::getBonus($client['user_code']),
+ 'dishes' => []
+ );
+ }
+ $group_info = ClientsGroup::where('code', $client['group_id'])->first();
+ $clients_info[] = array(
+ 'id' => $client['id'],
+ 'name' => $client['name'],
+ 'guid' => $client['user_code'],
+ 'presale' => ClientsPresale::getPresale($client['user_code']),
+ 'bonuses' => $bonus_info,
+ 'barcode' => Client::getBarcode($client['user_code']),
+ 'group_id' => ClientsGroup::getID($client['group_id']),
+ 'emails' => $email,
+ 'phones' => $phone,
+ 'badges' => []
+ );
+ $groups[] = $group_info['code'];
+ $email = $phone = $badge = $bonus_dishes = $bonus_info = [];
+ }
+ $groups_guides = array_values(array_unique($groups));
+ foreach ($groups_guides as $group) {
+ $group_info = ClientsGroup::where('code', $group)->first();
+ $groups_info[] = array(
+ 'id' => $group_info['id'],
+ 'name' => $group_info['name'],
+ 'guid' => $group_info['code'],
+ );
+ }
+
+ return [
+ 'status' => 'success',
+ 'clients' => $clients_info,
+ 'groups' => $groups_info,
+ ];
+ }
+}
\ No newline at end of file
diff --git a/commands/GETDashboard.php b/commands/GETDashboard.php
new file mode 100644
index 0000000..b3a99b8
--- /dev/null
+++ b/commands/GETDashboard.php
@@ -0,0 +1,256 @@
+ 'success',
+ 'message' => 'Проверьте введенные данные'
+ ];
+ }
+ $items = $input['items'];
+ } else {
+ $items = false;
+ }
+ if (isset($input['type'])) {
+ $type = $input['type'];
+ } else {
+ $type = false;
+ }
+ $method = $input['method'];
+ } else {
+ return [
+ 'status' => 'success',
+ 'message' => 'Проверьте введенные данные'
+ ];
+ }
+
+
+ if ($method == "deleted") {
+ $count = ShiftOnlineDeleted::count();
+ if ($count < 1) {
+ $count = 0;
+ }
+ $sum = ShiftOnlineDeleted::selectRaw('SUM(count * sale_price) as sum')->first();
+ if (isset($sum) && !is_null($sum['sum'])) {
+ $sum = $sum['sum'];
+ } else {
+ $sum = 0;
+ }
+ if ($more) {
+ $deleted_items = ShiftOnlineDeleted::select('order_code')
+ ->selectRaw('SUM(count * sale_price) as sum')
+ ->groupBy('order_code')
+ ->get();
+ if ($count > 0) {
+ foreach ($deleted_items as $deleted_item) {
+ $order = ShiftOnlineOrders::select('opened', 'closed')
+ ->where('code', $deleted_item['order_code'])
+ ->first();
+ $closed = $order['closed'];
+ if ($closed == '0000-00-00 00:00:00') {
+ $closed = '30.12.1899';
+ }
+ $orders[] = array(
+ 'number' => $deleted_item['order_code'],
+ 'opened' => $order['opened'],
+ 'closed' => $closed,
+ 'deleted_sum' => round($deleted_item['sum'], 2)
+ );
+ }
+ } else {
+ $orders = [];
+ }
+ return [
+ 'status' => 'success',
+ 'title' => 'Подробнее об удаленных',
+ 'total_sum' => round($sum, 2),
+ 'total_count' => $count,
+ 'deleted_orders' => $orders
+ ];
+ }
+ if ($items) {
+ $all_sum = $all_count = 0;
+ $deleted_items = ShiftOnlineDeleted::where('order_code', $order_id)
+ ->get();
+ if ($count > 0) {
+ foreach ($deleted_items as $deleted_item) {
+ $order = ShiftOnlineActions::where('order_code', $deleted_item['order_code'])
+ ->where('type_action', 5)
+ ->first();
+ $out_items[] = array(
+ 'dish' => Dishes::getName($deleted_item['menu_code']),
+ 'time' => $order['time'],
+ 'reason' => Reasons::getName($order['reason']),
+ 'count' => $deleted_item['count'],
+ 'sale_price' => $deleted_item['count'] * $deleted_item['sale_price'],
+ 'who_deleted' => Staff::getName($order['who'])
+ );
+ $all_sum += $deleted_item['count'] * $deleted_item['sale_price'];
+ $all_count += $deleted_item['count'];
+ }
+ } else {
+ $out_items = [];
+ }
+ return [
+ 'status' => 'success',
+ 'code' => $order_id,
+ 'all_sum' => round($all_sum, 2),
+ 'all_count' => round($all_count, 3),
+ 'items' => $out_items
+ ];
+ }
+ return [
+ 'status' => 'success',
+ 'sum' => round($sum, 2),
+ 'count' => $count
+ ];
+ }
+
+ if ($method == 'guests') {
+ if ($type == 'median') {
+ $data = [];
+ $orders = ShiftOnlineOrders::where('is_waited', 1)
+ ->where('is_deleted', 0)
+ ->get();
+ if (isset($orders)) {
+ foreach ($orders as $order) {
+ $originalTime = $order['opened'];
+ $newTime = Carbon::createFromFormat('Y-m-d H:i:s', $originalTime)->format('d.m.Y H:i:s');
+ $data[] = array(
+ 'time' => $newTime,
+ 'count' => $order['client_count']
+ );
+ }
+ }
+ return [
+ 'status' => 'success',
+ 'data' => $data
+ ];
+ }
+ if ($type == 'more') {
+ $clientsIDS = ShiftOnlineOrders::select('client_code')
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('who_open', '<>', 0)
+ ->where('client_code', '<>', '')
+ ->groupBy('client_code')
+ ->get();
+ $clientsOrdersCount = ShiftOnlineOrders::select('client_code')
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('who_open', '<>', 0)
+ ->where('client_code', '<>', '')
+ ->groupBy('client_code')
+ ->count();
+ if ($clientsOrdersCount > 0) {
+ foreach ($clientsIDS as $clientsID) {
+ $orders_info = ShiftOnlineOrders::where('client_code', $clientsID['client_code'])
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('who_open', '<>', 0)
+ ->get();
+
+ $clientName = Client::getName($clientsID['client_code']);
+ $clientOrder[$clientName] = [];
+ foreach ($orders_info as $order_info) {
+ if ($order_info['closed'] == '0000-00-00 00:00:00') {
+ $closed = false;
+ } else {
+ $closed = $order_info['closed'];
+ }
+ $order = array(
+ 'number' => $order_info['code'],
+ 'opened' => $order_info['opened'],
+ 'closed' => $closed,
+ 'sum' => $order_info['order_sum']
+ );
+ array_push($clientOrder[$clientName], $order);
+ }
+ }
+ foreach ($clientOrder as $key => $oInfo) {
+ $out[] = array(
+ 'name' => $key,
+ 'orders' => $oInfo
+ );
+ }
+ return [
+ 'status' => 'success',
+ 'title' => 'Подробнее о заказах гостей',
+ 'clients' => $out
+ ];
+ } else {
+ return [
+ 'status' => 'success',
+ 'title' => 'Подробнее о заказах гостей',
+ 'clients' => []
+ ];
+ }
+
+ }
+ $guests = $namedGuests = $totalSum = 0;
+ $orders = ShiftOnlineOrders::where('is_waited', 1)
+ ->where('is_deleted', 0)
+ ->get();
+ if (isset($orders)) {
+ foreach ($orders as $order) {
+ $guests += $order['client_count'];
+ $totalSum += $order['order_sum'];
+ if ($order['client_code'] != '') {
+ $namedGuests += 1;
+ }
+ }
+ }
+ return [
+ 'status' => 'success',
+ 'namedGuests' => $namedGuests,
+ 'guestsCount' => $guests,
+ 'totalSum' => round($totalSum, 2)
+ ];
+ }
+
+ if ($method == 'info') {
+ $response['status'] = 'success';
+ $response['exists'] = 'false';
+ $shifts = Shifts::first();
+ if (isset($shifts)) {
+ $response['exists'] = true;
+ $response['opened'] = $shifts['opened'];
+ $response['open'] = Staff::getName($shifts['who_open']);
+ $response['z_number'] = $shifts['z_number'];
+ if ($shifts['who_close'] > 0) {
+ $response['closed'] = $shifts['closed'];
+ $response['close'] = Staff::getName($shifts['who_close']);
+ }
+ }
+ return $response;
+ }
+ }
+}
\ No newline at end of file
diff --git a/commands/GETDataReport.php b/commands/GETDataReport.php
index 8d933fc..8593a40 100644
--- a/commands/GETDataReport.php
+++ b/commands/GETDataReport.php
@@ -2,17 +2,25 @@
namespace App\Commands;
+use App\Component\Models\Base;
+use App\Component\Models\Cache;
+use App\Component\Models\ClientsActions;
use App\Component\Models\Dishes;
use App\Component\Models\ExchangeActions;
use App\Component\Models\ExchangeDeleted;
use App\Component\Models\ExchangeItems;
use App\Component\Models\ExchangeOrders;
use App\Component\Models\ExchangeShifts;
+use App\Component\Models\Filesystem;
+use App\Component\Models\Printer;
use App\Component\Models\Reasons;
use App\Component\Models\Report;
+use App\Component\Models\Settings;
use App\Component\Models\Staff;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
class GETDataReport extends HRCCommand implements HRCCommandInterface
{
@@ -21,57 +29,6 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
public function command($input, $output = null)
{
- function validate_json($string)
- {
- // decode the JSON data
- $result = json_decode(utf8_encode($string), true, JSON_INVALID_UTF8_SUBSTITUTE);
-
- // switch and check possible JSON errors
- switch (json_last_error()) {
- case JSON_ERROR_NONE:
- $error = ''; // JSON is valid // No error has occurred
- break;
- case JSON_ERROR_DEPTH:
- $error = 'The maximum stack depth has been exceeded.';
- break;
- case JSON_ERROR_STATE_MISMATCH:
- $error = 'Invalid or malformed JSON.';
- break;
- case JSON_ERROR_CTRL_CHAR:
- $error = 'Control character error, possibly incorrectly encoded.';
- break;
- case JSON_ERROR_SYNTAX:
- $error = 'Syntax error, malformed JSON.';
- break;
- // PHP >= 5.3.3
- case JSON_ERROR_UTF8:
- $error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
- break;
- // PHP >= 5.5.0
- case JSON_ERROR_RECURSION:
- $error = 'One or more recursive references in the value to be encoded.';
- break;
- // PHP >= 5.5.0
- case JSON_ERROR_INF_OR_NAN:
- $error = 'One or more NAN or INF values in the value to be encoded.';
- break;
- case JSON_ERROR_UNSUPPORTED_TYPE:
- $error = 'A value of a type that cannot be encoded was given.';
- break;
- default:
- $error = 'Unknown JSON error occured.';
- break;
- }
-
- if ($error !== '') {
- // throw the Exception or exit // or whatever :)
- return false;
- }
-
- // everything is OK
- return true;
- }
-
function data_decode($data)
{
$alph = [
@@ -132,6 +89,11 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
if (isset($reportType)) {
//merge
if ($reportType == 'merge') {
+ $code = Filesystem::GetCode($input['token']);
+ $cache = Cache::get($code, 'shift', $input);
+ if ($cache) {
+ return $cache;
+ }
$merged_order_items = [];
$orders = ExchangeActions::select('order_code')
->where('shift_id', $input['shift_id'])
@@ -156,7 +118,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
$merge_trigger = 1;
$merge_items_before = $merge_items_after = $merge_items = $merge_order_item_before = $merge_order_item_after = $merged_items = [];
- if (validate_json($item_action['more'])) {
+ if (Base::validate_json($item_action['more'])) {
$merge_order_items = json_decode(utf8_encode($item_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE);
} else {
$merge_order_items = json_decode(utf8_encode(base64_decode($item_action['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE);
@@ -233,15 +195,24 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
}
}
}
- return [
+ $return = array(
'status' => 'success',
'shift_id' => $input['shift_id'],
'count' => count($merged_order_items),
'data' => $merged_order_items,
- ];
+ );
+ if (!$cache) {
+ $cache = Cache::store(strval($code), 'shift', $input, $return);
+ }
+ return $cache;
}
//slice
if ($reportType == 'slice') {
+ $code = Filesystem::GetCode($input['token']);
+ $cache = Cache::get($code, 'shift', $input);
+ if ($cache) {
+ return $cache;
+ }
$sliced_order_data = [];
$orders = ExchangeActions::select('order_code')
->where('shift_id', $input['shift_id'])
@@ -260,7 +231,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
foreach ($actions as $key => $action) {
$value = $action['value'];
$codeOrder = $action['order_code'];
- if (validate_json($action['more'])) {
+ if (Base::validate_json($action['more'])) {
$moved_items = json_decode(utf8_encode($action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE);
} else {
$moved_items = json_decode(utf8_encode(base64_decode($action['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE);
@@ -280,7 +251,7 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
->where('action_type', 34)
->where('shift_id', $input['shift_id'])
->first();
- if (validate_json($to_action['more'])) {
+ if (Base::validate_json($to_action['more'])) {
$start_data = json_decode(utf8_encode($to_action['more']), true, JSON_INVALID_UTF8_SUBSTITUTE);
} else {
$start_data = json_decode(utf8_encode(base64_decode($to_action['more'], TRUE)), true, JSON_INVALID_UTF8_SUBSTITUTE);
@@ -300,15 +271,24 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
}
}
}
- return [
+ $return = array(
'status' => 'success',
'shift_id' => $input['shift_id'],
'count' => $action_count,
'data' => $sliced_order_data,
- ];
+ );
+ if (!$cache) {
+ $cache = Cache::store(strval($code), 'shift', $input, $return);
+ }
+ return $cache;
}
if ($reportType == 'move') {
+ $code = Filesystem::GetCode($input['token']);
+ $cache = Cache::get($code, 'shift', $input);
+ if ($cache) {
+ return $cache;
+ }
$orders = ExchangeActions::select('order_code')
->where('shift_id', $input['shift_id'])
->groupBy('order_code')
@@ -341,14 +321,24 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
}
}
}
- return [
+ $return = array(
'status' => 'success',
'count' => count($moved_order_data),
'data' => $moved_order_data,
- ];
+ );
+ if (!$cache) {
+ $cache = Cache::store(strval($code), 'shift', $input, $return);
+ }
+ return $cache;
}
if ($reportType == 'staff') {
+ $work_code = Filesystem::GetCode($input['token']);
+ $cache = Cache::get($work_code, 'shift', $input);
+
+ if ($cache) {
+ return $cache;
+ }
if (isset($input['shift_id'])) {
$staff = $staff_data = [];
$countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0;
@@ -476,10 +466,6 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
'deleted_sum' => $deletedSum
);
}
- return [
- 'status' => 'success',
- 'staffs' => $staff_data,
- ];
}
if (isset($input['start_date']) && isset($input['end_date'])) {
$staff = $staff_data = $shifts = [];
@@ -613,161 +599,1287 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface
'deleted_sum' => $deletedSum
);
}
- return [
- 'status' => 'success',
- 'staffs' => $staff_data,
- ];
+
+ if (Report::where('start_date', $start_date)->where('end_date', $end_date)->where('report_type', 'staff')->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 = 'staff';
+ $report->save();
+ }
+ }
+ $return = array(
+ 'status' => 'success',
+ 'staffs' => $staff_data,
+ );
+
+ if (!$cache) {
+ $cache = Cache::store(strval($work_code), 'shift', $input, $return);
+ }
+ return $cache;
+ }
+
+ if ($reportType == 'deleted') {
+ $code = Filesystem::GetCode($input['token']);
+ $cache = Cache::get($code, 'shift', $input);
+ if ($cache) {
+ return $cache;
}
- }
- if ($reportType == 'deleted') {
- $total_count = $total_sum = 0;
- $deleted = [];
if (isset($input['shift_id'])) {
$shift_id = $input['shift_id'];
- $deleted_from_orders = ExchangeActions::select('order_code')
- ->where('action_type', 5)
+ $actionsResult = ExchangeDeleted::select('order_code', 'menu_code', 'count', 'sale_price', 'item_id')
+ ->with('deletedActions', function ($q) use ($shift_id) {
+ $q->where('shift_id', '=', $shift_id);
+ })
->where('shift_id', $shift_id)
- ->groupBy('order_code')
->get();
- foreach ($deleted_from_orders as $deleted_from_order) {
- $items = [];
- $order_id = $deleted_from_order['order_code'];
- $deleted_items = ExchangeDeleted::where('shift_id', $shift_id)
- ->where('order_code', $order_id)
- ->get();
- foreach ($deleted_items as $deleted_item) {
- $item_info = ExchangeActions::where('shift_id', $shift_id)
- ->where('order_code', $deleted_item['order_code'])
- ->where('action_type', 5)
- ->where('order_position', $deleted_item['item_id'])
- ->first();
- $time = $item_info['time'];
- $who = Staff::getName($item_info['who']);
- $reason = Reasons::getName($item_info['reason']);
- $approved = Staff::getName($item_info['more']);
- $item_count = $deleted_item['count'];
- $item_price = $deleted_item['sale_price'];
- $item_name = Dishes::getName($deleted_item['menu_code']);
- $total_count += $item_count;
- $total_sum += $item_count * $item_price;
- $items[] = array(
- 'dish_name' => $item_name,
+ $orders = ExchangeDeleted::select('order_code')
+ ->where('shift_id', $shift_id)
+ ->get();
+ $ordersCount = ExchangeDeleted::select('order_code')
+ ->where('shift_id', $shift_id)
+ ->count();
+ if ($ordersCount === 0) {
+ return [
+ 'status' => 'success',
+ 'message' => 'Удаления отсутствуют',
+ 'totalCount' => 0
+ ];
+ }
+ $totalCount = 0;
+ $totalSum = 0;
+ $items = [];
+ foreach ($orders as $order) {
+ $result[$order['order_code']]['items'] = [];
+ }
+
+ foreach ($actionsResult as $actionResult) {
+ foreach ($actionResult->deletedActions as $item) {
+ $count = round(Base::toFloat($item['value']), 2);
+ $who = Staff::getName(intval($item['who']));
+ $time = $item['time'];
+ $reason = Reasons::getName(intval($item['reason']));
+ $dish = Dishes::getName($actionResult['menu_code']);
+ $price = floatval($actionResult['sale_price']);
+ $total = round($count * $price, 2);
+ $totalCount += $count;
+ $totalSum += $total;
+ $result[$actionResult['order_code']]['items'][] = array(
'who' => $who,
- 'approved' => $approved,
- 'reason' => $reason,
'time' => $time,
- 'count' => $item_count,
- 'price' => $item_price,
- 'sum' => floatval($item_price * $item_count)
+ 'reason' => $reason,
+ 'dish' => $dish,
+ 'count' => $count,
+ 'price' => $price,
+ 'total' => $total
);
}
- $deleted[] = array(
- 'order_code' => $order_id,
- 'shift_id' => $shift_id,
- 'items' => $items
+ }
+
+ foreach ($result as $k => $repResult) {
+ $itemCount = $itemTotal = 0;
+ foreach ($repResult['items'] as $item) {
+ $itemCount += $item['count'];
+ $itemTotal += $item['total'];
+ }
+ $items[] = array(
+ 'order_id' => $k,
+ 'orderTotalCount' => $itemCount,
+ 'orderTotalSum' => $itemTotal,
+ 'items' => $repResult['items']
);
}
+ $return = array(
+ 'status' => 'success',
+ 'totalCount' => round($totalCount, 3),
+ 'totalSum' => round($totalSum, 2),
+ 'orders' => $items
+ );
}
+
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']));
- $deletedShifts = ExchangeActions::select('shift_id')
- ->where('action_type', 5)
- ->where('time', '>', $start_date)
- ->where('time', '<', $end_date)
- ->groupBy('shift_id')
+ $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')
+ ->where('opened', '>', $start_date)
+ ->where('closed', '<', $end_date)
->get();
- foreach ($deletedShifts as $deletedShift) {
- $shift_id = intval($deletedShift['shift_id']);
- $deleted_from_orders = ExchangeActions::select('order_code')
- ->where('action_type', 5)
+
+ foreach ($shifts as $shift) {
+ $shift_id = $shift['id'];
+ $actionsResult = ExchangeDeleted::select('order_code', 'menu_code', 'count', 'sale_price', 'item_id', 'shift_id')
+ ->with('deletedActions', function ($q) use ($shift_id) {
+ $q->where('shift_id', $shift_id);
+ })
->where('shift_id', $shift_id)
- ->groupBy('order_code')
->get();
- foreach ($deleted_from_orders as $deleted_from_order) {
- $items = [];
- $order_id = $deleted_from_order['order_code'];
- $deleted_items = ExchangeDeleted::where('shift_id', $shift_id)
- ->where('order_code', $order_id)
- ->get();
- foreach ($deleted_items as $deleted_item) {
- $item_info = ExchangeActions::where('shift_id', $shift_id)
- ->where('order_code', $deleted_item['order_code'])
- ->where('action_type', 5)
- ->where('order_position', $deleted_item['item_id'])
- ->first();
- $time = $item_info['time'];
- $who = Staff::getName($item_info['who']);
- $reason = Reasons::getName($item_info['reason']);
- $approved = Staff::getName($item_info['more']);
- $item_count = $deleted_item['count'];
- $item_price = $deleted_item['sale_price'];
- $item_name = Dishes::getName($deleted_item['menu_code']);
- $total_count += $item_count;
- $total_sum += $item_count * $item_price;
- $items[] = array(
- 'dish_name' => $item_name,
+ $orders = ExchangeDeleted::select('order_code', 'shift_id')
+ ->where('shift_id', $shift_id)
+ ->get();
+ $ordersCount = ExchangeDeleted::select('order_code', 'shift_id')
+ ->where('shift_id', $shift_id)
+ ->count();
+ if ($ordersCount < 1) {
+ continue;
+ }
+ $totalCount = 0;
+ $totalSum = 0;
+ $totalCountInShift = 0;
+ $totalSumInShift = 0;
+ foreach ($orders as $order) {
+ $result[$shift_id][$order['order_code']]['items'] = [];
+ }
+ $orders = [];
+ foreach ($actionsResult as $actionResult) {
+ foreach ($actionResult->deletedActions as $item) {
+ $count = round(Base::toFloat($item['value']), 2);
+ $who = Staff::getName(intval($item['who']));
+ $time = $item['time'];
+ $reason = Reasons::getName(intval($item['reason']));
+ $dish = Dishes::getName($actionResult['menu_code']);
+ $price = floatval($actionResult['sale_price']);
+ $total = round($count * $price, 2);
+ $totalCount += $count;
+ $totalSum += $total;
+ $totalCountInShift += $count;
+ $totalSumInShift += $total;
+ $result[$shift_id][$actionResult['order_code']]['items'][] = array(
'who' => $who,
- 'approved' => $approved,
- 'reason' => $reason,
'time' => $time,
- 'count' => $item_count,
- 'price' => $item_price,
- 'sum' => floatval($item_price * $item_count)
+ 'reason' => $reason,
+ 'dish' => $dish,
+ 'count' => $count,
+ 'price' => $price,
+ 'total' => $total
);
}
- $deleted[] = array(
- 'order_code' => $order_id,
- 'shift_id' => $shift_id,
- 'items' => $items
+ }
+ foreach ($result[$shift_id] as $m => $res) {
+ $itemCount = $itemSum = 0;
+ foreach ($res['items'] as $res_item) {
+ $itemCount += $res_item['count'];
+ $itemSum += $res_item['total'];
+ }
+ $orders[] = array(
+ 'order_id' => $m,
+ 'totalCount' => $itemCount,
+ 'totalSum' => $itemSum,
+ 'items' => $res['items']
);
}
+ $shift_orders[] = array(
+ 'shift_id' => $shift_id,
+ 'totalCount' => round($totalCountInShift, 3),
+ 'totalSum' => round($totalSumInShift, 2),
+ 'orders' => $orders
+ );
+
}
- $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();
+ $totalSum = $totalCount = 0;
+ foreach ($shift_orders as $shift_order) {
+ $totalSum += $shift_order['totalSum'];
+ $totalCount += $shift_order['totalCount'];
+ }
+
+ 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 = array(
+ 'status' => 'success',
+ 'totalCount' => round($totalCount, 3),
+ 'totalSum' => round($totalSum, 2),
+ 'orders' => $shift_orders
+ );
}
- return [
- 'status' => 'success',
- 'total_count' => strval($total_count),
- 'total_sum' => $total_sum,
- 'deleted' => $deleted
- ];
+
+
+ if (!$cache) {
+ $cache = Cache::store(strval($code), 'shift', $input, $return);
+ }
+ return $cache;
}
- if ($input['type'] == 'abc') {
+
+ if ($reportType == 'discounts') {
+ $code = Filesystem::GetCode($input['token']);
+ $cache = Cache::get($code, 'shift', $input);
+ if ($cache) {
+ return $cache;
+ }
+ if (isset($input['shift_id'])) {
+ $orders_info = [];
+ $orders = ExchangeOrders::select('shift_id', 'code', 'opened', 'closed', 'full_sum', 'order_sum', 'sale_sum')
+ ->where('shift_id', $input['shift_id'])
+ ->where('sale_sum', '>', 0)
+ ->where('is_closed', 1)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->get();
+ if (count($orders) < 1) {
+ return [
+ 'status' => 'success',
+ 'message' => 'Заказы со скидками отсутствуют',
+ 'shift_id' => $input['shift_id'],
+ 'orders_count' => count($orders),
+ 'orders_info' => $orders_info
+ ];
+ } else {
+ $orders_full_sum = $orders_sale_sum = $orders_order_sum = 0;
+ foreach ($orders as $k => $order) {
+ $item = ExchangeItems::whereColumn('real_price', '>', 'sale_price')
+ ->where('shift_id', $input['shift_id'])
+ ->where('order_code', $order['code'])
+ ->first();
+ if ($item['sale_price'] < 0.01 && $item['real_price'] > 0) {
+ $order_discount = 100;
+ } else {
+ $order_discount = round((100 - (100 * $item['sale_price'] / $item['real_price'])));
+ }
+ $orders_full_sum += $order['full_sum'];
+ $orders_sale_sum += $order['sale_sum'];
+ $orders_order_sum += $order['order_sum'];
+ $orders_info[$order_discount]['orders'][] = $order;
+ if (!isset($orders_info[$order_discount]['info'])) {
+ $orders_info[$order_discount]['info'] = array(
+ 'full_sum' => round($order['full_sum'], 2),
+ 'sale_sum' => round($order['sale_sum'], 2),
+ 'order_sum' => round($order['order_sum'], 2),
+ 'orders_count' => 1
+ );
+ } else {
+ $orders_info[$order_discount]['info']['full_sum'] = round(round($orders_info[$order_discount]['info']['full_sum'], 2) + round($order['full_sum'], 2), 2);
+ $orders_info[$order_discount]['info']['sale_sum'] = round(round($orders_info[$order_discount]['info']['sale_sum'], 2) + round($order['sale_sum'], 2), 2);
+ $orders_info[$order_discount]['info']['order_sum'] = round(round($orders_info[$order_discount]['info']['order_sum'], 2) + round($order['order_sum'], 2), 2);
+ $orders_info[$order_discount]['info']['orders_count']++;
+ }
+ }
+ $return = array(
+ 'status' => 'success',
+ 'message' => 'Заказы со скидками. Смена №' . $input['shift_id'],
+ 'shift_id' => $input['shift_id'],
+ 'orders_count' => count($orders),
+ 'orders_full_sum' => round($orders_full_sum, 2),
+ 'orders_sale_sum' => round($orders_sale_sum, 2),
+ 'orders_order_sum' => round($orders_order_sum, 2),
+ 'orders_info' => $orders_info,
+ );
+ 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']));
$start_date = date('Y-m-d H:i:s', strtotime($input['start_date']));
- $orders_shifts = ExchangeOrders::where('opened', '>=', $start_date)
- ->where('closed', '=<', $end_date)
+ $orders_info = [];
+ $orders = ExchangeOrders::select('shift_id', 'code', 'opened', 'closed', 'full_sum', 'order_sum', 'sale_sum')
+ ->where('opened', '>', $start_date)
+ ->where('closed', '<', $end_date)
+ ->where('sale_sum', '>', 0)
+ ->where('is_closed', 1)
->where('is_deleted', 0)
->where('is_returned', 0)
- ->where('is_closed', 1)
- ->groupBy('shift_id')
->get();
- $orders = ExchangeOrders::where('opened', '>=', $start_date)
- ->where('closed', '=<', $end_date)
+ if (count($orders) < 1) {
+ return [
+ 'status' => 'success',
+ 'message' => 'Заказы со скидками отсутствуют',
+ 'start_date' => $start_date,
+ 'end_date' => $end_date,
+ 'orders_count' => count($orders),
+ 'orders_info' => $orders_info
+ ];
+ } else {
+ $orders_full_sum = $orders_sale_sum = $orders_order_sum = 0;
+ foreach ($orders as $k => $order) {
+ $item = ExchangeItems::whereColumn('real_price', '>', 'sale_price')
+ ->where('shift_id', $order['shift_id'])
+ ->where('order_code', $order['code'])
+ ->first();
+ if ($item['sale_price'] < 0.01 && $item['real_price'] > 0) {
+ $order_discount = 100;
+ } else {
+ $order_discount = round((100 - (100 * $item['sale_price'] / $item['real_price'])));
+ }
+ $orders_full_sum += $order['full_sum'];
+ $orders_sale_sum += $order['sale_sum'];
+ $orders_order_sum += $order['order_sum'];
+ $orders_info[$order_discount]['orders'][] = $order;
+ if (!isset($orders_info[$order_discount]['info'])) {
+ $orders_info[$order_discount]['info'] = array(
+ 'full_sum' => round($order['full_sum'], 2),
+ 'sale_sum' => round($order['sale_sum'], 2),
+ 'order_sum' => round($order['order_sum'], 2),
+ 'orders_count' => 1
+ );
+ } else {
+ $orders_info[$order_discount]['info']['full_sum'] = round(round($orders_info[$order_discount]['info']['full_sum'], 2) + round($order['full_sum'], 2), 2);
+ $orders_info[$order_discount]['info']['sale_sum'] = round(round($orders_info[$order_discount]['info']['sale_sum'], 2) + round($order['sale_sum'], 2), 2);
+ $orders_info[$order_discount]['info']['order_sum'] = round(round($orders_info[$order_discount]['info']['order_sum'], 2) + round($order['order_sum'], 2), 2);
+ $orders_info[$order_discount]['info']['orders_count']++;
+ }
+ }
+ if (Report::where('start_date', $start_date)->where('end_date', $end_date)->where('report_type', 'discounts')->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 = 'discounts';
+ $report->save();
+ }
+
+ $return = array(
+ 'status' => 'success',
+ 'message' => 'Заказы со скидками',
+ 'orders_count' => count($orders),
+ 'orders_full_sum' => round($orders_full_sum, 2),
+ 'orders_sale_sum' => round($orders_sale_sum, 2),
+ 'orders_order_sum' => round($orders_order_sum, 2),
+ 'start_date' => $start_date,
+ 'end_date' => $end_date,
+ 'orders_info' => $orders_info
+ );
+ if (!$cache) {
+ $cache = Cache::store(strval($code), 'shift', $input, $return);
+ }
+ return $cache;
+ }
+ }
+ }
+
+ if ($reportType == 'realisation') {
+ $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'];
+ $printers = Printer::get();
+ foreach ($printers as $printer) {
+ $printer_total_count[$printer['code']] = $ret_printer_total_count[$printer['code']] = 0;
+ $printer_total_sum[$printer['code']] = $ret_printer_total_sum[$printer['code']] = 0;
+ $report[$printer['code']]['items'] = $ret_report[$printer['code']]['items'] = [];
+ }
+ $total_sum = $total_count = 0;
+ $report = $result = $ret_result = $ret_report_items = [];
+ $items = ExchangeItems::select('dishes_code')
+ ->selectRaw('SUM(count - count_return) as count')
+ ->selectRaw('SUM((count - count_return) * sale_price) as total')
+ ->selectRaw('SUM(count_return) as count_return')
+ ->selectRaw('SUM(count_return * sale_price) as count_return_total')
+ ->where('shift_id', $shift_id)
+ ->where('menu_code', '>', 0)
+ ->where('dishes_code', '>', 0)
+ ->where('real_price', '>=', 0)
+ ->where('sale_price', '>=', 0)
+ ->groupBy('dishes_code')
+ ->get();
+ foreach ($items as $k => $item) {
+ $printer_code = Dishes::GetPrinterCode($item['dishes_code']);
+ $printer_name = Printer::getName($printer_code);
+ $item_name = Dishes::getName($item['dishes_code']);
+ if ($item['count_return'] > 0) {
+ $ret_printer_total_count[$printer_code] += $item['count_return'];
+ $ret_printer_total_sum[$printer_code] += $item['count_return_total'];
+
+ $ret_report_items[$printer_code][] = array(
+ 'printer_code' => $printer_code,
+ 'code' => $item['dishes_code'],
+ 'name' => $item_name,
+ 'count' => round($item['count_return'], 3),
+ 'sum' => round($item['count_return_total'], 2)
+ );
+
+
+ $ret_report[$printer_code] = array(
+ 'code' => $printer_code,
+ 'name' => $printer_name,
+ 'count' => round($ret_printer_total_count[$printer_code], 3),
+ 'sum' => round($ret_printer_total_sum[$printer_code], 2)
+ );
+ $printer_total_count[$printer_code] += $item['count'];
+ $printer_total_sum[$printer_code] += $item['total'];
+ if ($item['count'] > 0) {
+ $report_items[$printer_code][] = array(
+ 'printer_code' => $printer_code,
+ 'code' => $item['dishes_code'],
+ 'name' => $item_name,
+ 'count' => round($item['count'], 3),
+ 'sum' => round($item['total'], 2)
+ );
+ }
+ $report[$printer_code] = array(
+ 'code' => $printer_code,
+ 'name' => $printer_name,
+ 'count' => round($printer_total_count[$printer_code], 3),
+ 'sum' => round($printer_total_sum[$printer_code], 2)
+ );
+ } else {
+ $printer_total_count[$printer_code] += $item['count'];
+ $printer_total_sum[$printer_code] += $item['total'];
+ $report_items[$printer_code][] = array(
+ 'printer_code' => $printer_code,
+ 'code' => $item['dishes_code'],
+ 'name' => $item_name,
+ 'count' => round($item['count'], 3),
+ 'sum' => round($item['total'], 2)
+ );
+ $report[$printer_code] = array(
+ 'code' => $printer_code,
+ 'name' => $printer_name,
+ 'count' => round($printer_total_count[$printer_code], 3),
+ 'sum' => round($printer_total_sum[$printer_code], 2)
+ );
+ }
+ $total_sum += $item['total'];
+ $total_count += $item['count'];
+ }
+
+ foreach ($report as $n => $rep_item) {
+ foreach ($report_items as $k => $report_item) {
+ if ($n == $k) {
+ $report[$n]['items'] = $report_items[$k];
+ }
+ }
+ }
+
+ foreach ($report as $item) {
+ array_push($result, $item);
+ }
+
+ foreach ($ret_report as $n => $ret_rep_item) {
+ foreach ($ret_report_items as $k => $ret_report_item) {
+ if ($n == $k) {
+ $ret_report[$n]['items'] = $ret_report_items[$k];
+ }
+ }
+ }
+
+ foreach ($ret_report as $ret_item) {
+ if (count($ret_item['items']) > 0) {
+ array_push($ret_result, $ret_item);
+ }
+ }
+
+ $return = array(
+ 'status' => 'success',
+ 'message' => 'Отчет по реализации',
+ 'printers' => $result,
+ 'ret_prints' => $ret_result,
+ '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'));
+ $shifts = ExchangeShifts::select('id')
+ ->where('opened', '>', $start_date)
+ ->where('closed', '<', $end_date)
+ ->get();
+ $shift_ids = [];
+ foreach ($shifts as $shift) {
+ array_push($shift_ids, $shift['id']);
+ }
+ $printers = Printer::get();
+ foreach ($printers as $printer) {
+ $printer_total_count[$printer['code']] = $ret_printer_total_count[$printer['code']] = 0;
+ $printer_total_sum[$printer['code']] = $ret_printer_total_sum[$printer['code']] = 0;
+ $report[$printer['code']]['items'] = $ret_report[$printer['code']]['items'] = [];
+ }
+
+ $total_sum = $total_count = 0;
+ $report = $result = $ret_result = $ret_report_items = [];
+ $items = ExchangeItems::select('dishes_code')
+ ->selectRaw('SUM(count - count_return) as count')
+ ->selectRaw('SUM((count - count_return) * sale_price) as total')
+ ->selectRaw('SUM(count_return) as count_return')
+ ->selectRaw('SUM(count_return * sale_price) as count_return_total')
+ ->whereIn('shift_id', $shift_ids)
+ ->where('menu_code', '>', 0)
+ ->where('dishes_code', '>', 0)
+ ->where('real_price', '>=', 0)
+ ->where('sale_price', '>=', 0)
+ ->groupBy('dishes_code')
+ ->get();
+ foreach ($items as $k => $item) {
+ $printer_code = Dishes::GetPrinterCode($item['dishes_code']);
+ $printer_name = Printer::getName($printer_code);
+ $item_name = Dishes::getName($item['dishes_code']);
+ if ($item['count_return'] > 0) {
+ $ret_printer_total_count[$printer_code] += $item['count_return'];
+ $ret_printer_total_sum[$printer_code] += $item['count_return_total'];
+
+ $ret_report_items[$printer_code][] = array(
+ 'printer_code' => $printer_code,
+ 'code' => $item['dishes_code'],
+ 'name' => $item_name,
+ 'count' => round($item['count_return'], 3),
+ 'sum' => round($item['count_return_total'], 2)
+ );
+
+
+ $ret_report[$printer_code] = array(
+ 'code' => $printer_code,
+ 'name' => $printer_name,
+ 'count' => round($ret_printer_total_count[$printer_code], 3),
+ 'sum' => round($ret_printer_total_sum[$printer_code], 2)
+ );
+ $printer_total_count[$printer_code] += $item['count'];
+ $printer_total_sum[$printer_code] += $item['total'];
+ if ($item['count'] > 0) {
+ $report_items[$printer_code][] = array(
+ 'printer_code' => $printer_code,
+ 'code' => $item['dishes_code'],
+ 'name' => $item_name,
+ 'count' => round($item['count'], 3),
+ 'sum' => round($item['total'], 2)
+ );
+ }
+ $report[$printer_code] = array(
+ 'code' => $printer_code,
+ 'name' => $printer_name,
+ 'count' => round($printer_total_count[$printer_code], 3),
+ 'sum' => round($printer_total_sum[$printer_code], 2)
+ );
+ } else {
+ $printer_total_count[$printer_code] += $item['count'];
+ $printer_total_sum[$printer_code] += $item['total'];
+ $report_items[$printer_code][] = array(
+ 'printer_code' => $printer_code,
+ 'code' => $item['dishes_code'],
+ 'name' => $item_name,
+ 'count' => round($item['count'], 3),
+ 'sum' => round($item['total'], 2)
+ );
+ $report[$printer_code] = array(
+ 'code' => $printer_code,
+ 'name' => $printer_name,
+ 'count' => round($printer_total_count[$printer_code], 3),
+ 'sum' => round($printer_total_sum[$printer_code], 2)
+ );
+ }
+ $total_sum += $item['total'];
+ $total_count += $item['count'];
+ }
+
+ foreach ($report as $n => $rep_item) {
+ foreach ($report_items as $k => $report_item) {
+ if ($n == $k) {
+ $report[$n]['items'] = $report_items[$k];
+ }
+ }
+ }
+
+ foreach ($report as $item) {
+ array_push($result, $item);
+ }
+
+ foreach ($ret_report as $n => $ret_rep_item) {
+ foreach ($ret_report_items as $k => $ret_report_item) {
+ if ($n == $k) {
+ $ret_report[$n]['items'] = $ret_report_items[$k];
+ }
+ }
+ }
+
+ foreach ($ret_report as $ret_item) {
+ if (count($ret_item['items']) > 0) {
+ array_push($ret_result, $ret_item);
+ }
+ }
+
+ if (Report::where('start_date', $start_date)->where('end_date', $end_date)->where('report_type', 'realisation')->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 = 'realisation';
+ $report->save();
+ }
+
+ $return = array(
+ 'status' => 'success',
+ 'message' => 'Отчет по реализации',
+ 'printers' => $result,
+ 'ret_prints' => $ret_result,
+ 'total_count' => round($total_count, 2),
+ 'total_sum' => round($total_sum, 2)
+ );
+
+ $cache = Cache::store(strval($code), 'shift', $input, $return);
+ return $cache;
+ }
+ }
+
+ if ($reportType == 'statistic') {
+ if (isset($input['shift_id'])) {
+ $shift_id = $input['shift_id'];
+ $shift_time = ExchangeShifts::where('id', $shift_id)->first();
+ $shift_start_time = $shift_time['opened'];
+ $shift_end_time = $shift_time['closed'];
+ //Checkout
+ $checkout_sum = 0;
+ $checkouts = ExchangeActions::where('shift_id', $shift_id)
+ ->where('action_type', 49)
+ ->get();
+ foreach ($checkouts as $checkout) {
+ $checkout_sum += Base::tofloat($checkout['value']);
+ }
+ //Cashout
+ $cashout_sum = 0;
+ $cashouts = ExchangeActions::where('shift_id', $shift_id)
+ ->where('action_type', 50)
+ ->get();
+ foreach ($cashouts as $cashout) {
+ $cashout_sum += Base::tofloat($cashout['value']);
+ }
+ //Orders
+ $orders_count = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
->where('is_deleted', 0)
- ->where('is_returned', 0)
- ->where('is_closed', 1)
+ ->where('shift_id', $shift_id)
+ ->count();
+ $orders_sum_ws = ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('full_sum');
+ $sales_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('sale_sum');
+ $orders_sum_full = ExchangeOrders::where('who_open', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->where('is_deleted', 0)
+ ->sum('order_sum');
+ $order_waited_count = ExchangeOrders::where('who_open', '>', 0)
+ ->where('who_close', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+ $order_waited_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('who_close', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ //Returns
+ $returned_items_count = ExchangeItems::where('count_return', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+
+ $returned_orders = ExchangeOrders::select('code')
+ ->where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_returned', 1)
+ ->where('shift_id', $shift_id)
->get();
- $revenue = 0;
- foreach ($orders_shifts as $orders_shift) {
- $shift_revenue = ExchangeShifts::where('shift_id', $orders_shift['shift_id'])
+ $returned_items_sum = 0;
+ foreach ($returned_orders as $returned_order) {
+ $returned_item = ExchangeItems::selectRaw('SUM(count_return * sale_price) as return_sum')
+ ->where('order_code', $returned_order['code'])
+ ->where('shift_id', $shift_id)
+ ->groupBy('order_code')
->first();
- $revenue += $shift_revenue['revenue'];
+ $returned_items_sum += floatval($returned_item['return_sum']);
+
}
- foreach ($orders as $order) {
- $order_items = ExchangeItems::where('order_code', $order['code'])
- ->where('shift_id', $order['shift_id'])
+ //Cancellations
+ $cancellations_count = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 1)
+ ->where('check_number', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+ $cancellations_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 1)
+ ->where('check_number', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ //Presales
+ $presales_income_count = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->whereIn('action_type', [11, 12, 13, 21])
+ ->count();
+ $presales_outcome_count = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->whereIn('action_type', [14, 15, 16])
+ ->count();
+ $presales_income_cash_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 11)
+ ->sum('action_value');
+ $presales_income_credit_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 12)
+ ->sum('action_value');
+ $presales_income_clearing_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 13)
+ ->sum('action_value');
+ $presales_income_discount_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 21)
+ ->sum('action_value');
+ $presales_outcome_cash_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 14)
+ ->sum('action_value');
+ $presales_outcome_credit_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 15)
+ ->sum('action_value');
+ $presales_outcome_clearing_sum = ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 16)
+ ->sum('action_value');
+ //Clients
+ $clients_count = $orders_count;
+ $clients_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ $one_client_count = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('clients_count');
+ $average_sum = round($clients_sum / $clients_count, 2);
+ $average_sum_one_guest = round($clients_sum / $one_client_count, 2);
+ //Pay methods
+ $pay_cash_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('cash', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('cash');
+ $pay_credit_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('credit', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('credit');
+ $pay_clearing_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('clearing', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('clearing');
+ $pay_self_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('self', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('self');
+ $pay_presale_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('presale', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('presale');
+
+ $pay_online_orders = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('check_number', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('shift_id', $shift_id)
+ ->get();
+ $pay_online_sum = 0;
+ foreach ($pay_online_orders as $pay_online_order) {
+ $count_online_open = ExchangeActions::where('shift_id', $shift_id)
+ ->where('order_code', $pay_online_order['code'])
+ ->where('action_type', 45)
+ ->where('more', '<>', '0')
+ ->count();
+ $count_online_close = ExchangeActions::where('shift_id', $shift_id)
+ ->where('order_code', $pay_online_order['code'])
+ ->where('action_type', 6)
+ ->count();
+ if ($count_online_open > 0 && $count_online_close > 0) {
+ $pay_online_sum += $pay_online_order['order_sum'];
+ }
+
+ }
+ $pay_another_sum = 0;
+ $pays_another = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ //->where('check_number', '>', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('shift_id', $shift_id)
+ ->get();
+ foreach ($pays_another as $pay_another) {
+ $exch_another = ExchangeActions::where('order_code', $pay_another['code'])
+ ->where('action_type', 51)
+ ->where('shift_id', $shift_id)
+ ->count();
+ if ($exch_another > 0) {
+ $pay_another_sum += $pay_another['order_sum'];
+ }
+ }
+
+ $pay_echeck_sum = $pay_delivery_sum = 0;
+ $settings = Settings::where('code', 10)
+ ->where('value', '1')
+ ->count();
+
+ if ($settings > 0) {
+ $pay_echeck_orders = ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_closed', 1)
+ ->where('check_number', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('table_name', '<>', '0')
+ ->where('shift_id', $shift_id)
+ ->get();
+ foreach ($pay_echeck_orders as $pay_echeck_order) {
+ $count_echeck_open = ExchangeActions::where('shift_id', $shift_id)
+ ->where('order_code', $pay_echeck_order['code'])
+ ->where('action_type', 6)
+ ->count();
+ if ($count_echeck_open == 0 && $pay_echeck_order['is_closed'] == 1) {
+ $pay_echeck_sum += $pay_echeck_order['order_sum'];
+ }
+ }
+
+ $pay_delivery_sum = ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_closed', 1)
+ ->where('check_number', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('table_name', '0')
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ }
+ return [
+ 'status' => 'success',
+ 'fiscal' => [
+ 'income_sum' => $checkout_sum,
+ 'outcome_sum' => $cashout_sum
+ ],
+ 'realisation' => [
+ 'orders_count' => $orders_count,
+ 'orders_sum_with_sales' => $orders_sum_full,
+ 'orders_sum_without_sales' => $orders_sum_ws,
+ 'sale_sum' => $sales_sum,
+ 'waited_orders_count' => $order_waited_count,
+ 'waited_orders_sum' => $order_waited_sum,
+
+ ],
+ 'returns' => [
+ 'returned_orders_count' => $returned_items_count,
+ 'returned_items_sum' => $returned_items_sum,
+ ],
+ 'cancellations' => [
+ 'cancellations_count' => $cancellations_count,
+ 'cancellations_sum' => Base::tofloat($cancellations_sum),
+ ],
+ 'statistic' => [
+ 'clients_count' => $clients_count,
+ 'clients_average_sum' => $average_sum,
+ 'clients_average_sum_one' => $average_sum_one_guest,
+ ],
+ 'presales' => [
+ 'presales_income_count' => $presales_income_count,
+ 'presales_outcome_count' => $presales_outcome_count,
+ 'presales_income_cash_sum' => $presales_income_cash_sum,
+ 'presales_income_credit_sum' => $presales_income_credit_sum,
+ 'presales_income_clearing_sum' => $presales_income_clearing_sum,
+ 'presales_income_discount_sum' => $presales_income_discount_sum,
+ 'presales_outcome_cash_sum' => $presales_outcome_cash_sum,
+ 'presales_outcome_credit_sum' => $presales_outcome_credit_sum,
+ 'presales_outcome_clearing_sum' => $presales_outcome_clearing_sum
+
+ ],
+ 'payments' => [
+ 'pay_cash' => $pay_cash_sum,
+ 'pay_credit' => $pay_credit_sum,
+ 'pay_clearing' => $pay_clearing_sum,
+ 'pay_self' => $pay_self_sum,
+ 'pay_presale' => $pay_presale_sum,
+ 'pay_online' => $pay_online_sum,
+ 'pay_another' => $pay_another_sum,
+ 'pay_echeck' => $pay_echeck_sum,
+ 'pay_delivery' => $pay_delivery_sum
+ ]
+ ];
+ }
+ 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')
+ ->where('opened', '>', $start_date)
+ ->where('closed', '<', $end_date)
+ ->get();
+ $checkout_sum = $clients_sum = $one_client_count = 0;
+ $orders_count = $order_waited_count = $order_waited_sum = 0;
+ $sales_sum = $orders_sum_ws = $orders_sum_full = 0;
+ $cashout_sum = 0;
+ $returned_items_sum = $returned_items_count = 0;
+ $cancellations_count = $cancellations_sum = 0;
+ $presales_income_count = $presales_outcome_count = 0;
+ $presales_income_cash_sum = $presales_income_credit_sum = $presales_income_clearing_sum = $presales_income_discount_sum = 0;
+ $presales_outcome_cash_sum = $presales_outcome_credit_sum = $presales_outcome_clearing_sum = 0;
+ $pay_cash_sum = $pay_clearing_sum = 0;
+ $pay_credit_sum = $pay_self_sum = 0;
+ $pay_presale_sum = $pay_another_sum = 0;
+ $pay_echeck_sum = 0;
+ $pay_delivery_sum = 0;
+ $pay_online_sum = 0;
+ foreach ($shifts as $shift) {
+ $shift_id = $shift['id'];
+ $shift_time = ExchangeShifts::where('id', $shift_id)->first();
+ $shift_start_time = $shift_time['opened'];
+ $shift_end_time = $shift_time['closed'];
+ //Checkout
+
+ $checkouts = ExchangeActions::where('shift_id', $shift_id)
+ ->where('action_type', 49)
->get();
+ foreach ($checkouts as $checkout) {
+ $checkout_sum += Base::tofloat($checkout['value']);
+ }
+ //Cashout
+
+ $cashouts = ExchangeActions::where('shift_id', $shift_id)
+ ->where('action_type', 50)
+ ->get();
+ foreach ($cashouts as $cashout) {
+ $cashout_sum += Base::tofloat($cashout['value']);
+ }
+ //Orders
+ $orders_count += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+ $orders_sum_ws += ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('full_sum');
+ $sales_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('sale_sum');
+ $orders_sum_full += ExchangeOrders::where('who_open', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->where('is_deleted', 0)
+ ->sum('order_sum');
+ $order_waited_count += ExchangeOrders::where('who_open', '>', 0)
+ ->where('who_close', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+ $order_waited_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('who_close', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ //Returns
+ $returned_items_count += ExchangeItems::where('count_return', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+
+ $returned_orders = ExchangeOrders::select('code')
+ ->where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_returned', 1)
+ ->where('shift_id', $shift_id)
+ ->get();
+
+ foreach ($returned_orders as $returned_order) {
+ $returned_item = ExchangeItems::selectRaw('SUM(count_return * sale_price) as return_sum')
+ ->where('order_code', $returned_order['code'])
+ ->where('shift_id', $shift_id)
+ ->groupBy('order_code')
+ ->first();
+ $returned_items_sum += floatval($returned_item['return_sum']);
+
+ }
+ //Cancellations
+ $cancellations_count += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 1)
+ ->where('check_number', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->count();
+ $cancellations_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 1)
+ ->where('check_number', '>', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ //Presales
+ $presales_income_count += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->whereIn('action_type', [11, 12, 13, 21])
+ ->count();
+ $presales_outcome_count += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->whereIn('action_type', [14, 15, 16])
+ ->count();
+ $presales_income_cash_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 11)
+ ->sum('action_value');
+ $presales_income_credit_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 12)
+ ->sum('action_value');
+ $presales_income_clearing_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 13)
+ ->sum('action_value');
+ $presales_income_discount_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 21)
+ ->sum('action_value');
+ $presales_outcome_cash_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 14)
+ ->sum('action_value');
+ $presales_outcome_credit_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 15)
+ ->sum('action_value');
+ $presales_outcome_clearing_sum += ClientsActions::where('created', '>', $shift_start_time)
+ ->where('created', '<', $shift_end_time)
+ ->where('action_type', 16)
+ ->sum('action_value');
+ //Clients
+ $clients_count = $orders_count;
+ $clients_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ $one_client_count += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>=', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('clients_count');
+ $average_sum = round($clients_sum / $clients_count, 2);
+ $average_sum_one_guest = round($clients_sum / $one_client_count, 2);
+ //Pay methods
+ $pay_cash_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('cash', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('cash');
+ $pay_credit_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('credit', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('credit');
+ $pay_clearing_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('clearing', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('clearing');
+ $pay_self_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('self', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('self');
+ $pay_presale_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('presale', '>', 0)
+ ->where('is_deleted', 0)
+ ->where('shift_id', $shift_id)
+ ->sum('presale');
+
+ $pay_online_orders = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ ->where('check_number', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('shift_id', $shift_id)
+ ->get();
+
+ foreach ($pay_online_orders as $pay_online_order) {
+ $count_online_open = ExchangeActions::where('shift_id', $shift_id)
+ ->where('order_code', $pay_online_order['code'])
+ ->where('action_type', 45)
+ ->where('more', '<>', '0')
+ ->count();
+ $count_online_close = ExchangeActions::where('shift_id', $shift_id)
+ ->where('order_code', $pay_online_order['code'])
+ ->where('action_type', 6)
+ ->count();
+ if ($count_online_open > 0 && $count_online_close > 0) {
+ $pay_online_sum += $pay_online_order['order_sum'];
+ }
+
+ }
+
+ $pays_another = ExchangeOrders::where('who_open', '>', 0)
+ ->where('order_sum', '>', 0)
+ //->where('check_number', '>', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('shift_id', $shift_id)
+ ->get();
+ foreach ($pays_another as $pay_another) {
+ $exch_another = ExchangeActions::where('order_code', $pay_another['code'])
+ ->where('action_type', 51)
+ ->where('shift_id', $shift_id)
+ ->count();
+ if ($exch_another > 0) {
+ $pay_another_sum += $pay_another['order_sum'];
+ }
+ }
+
+
+ $settings = Settings::where('code', 10)
+ ->where('value', '1')
+ ->count();
+
+ if ($settings > 0) {
+ $pay_echeck_orders = ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_closed', 1)
+ ->where('check_number', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('table_name', '<>', '0')
+ ->where('shift_id', $shift_id)
+ ->get();
+ foreach ($pay_echeck_orders as $pay_echeck_order) {
+ $count_echeck_open = ExchangeActions::where('shift_id', $shift_id)
+ ->where('order_code', $pay_echeck_order['code'])
+ ->where('action_type', 6)
+ ->count();
+ if ($count_echeck_open == 0 && $pay_echeck_order['is_closed'] == 1) {
+ $pay_echeck_sum += $pay_echeck_order['order_sum'];
+ }
+ }
+
+ $pay_delivery_sum += ExchangeOrders::where('who_open', '>', 0)
+ ->where('is_closed', 1)
+ ->where('check_number', 0)
+ ->where('cash', 0)
+ ->where('credit', 0)
+ ->where('clearing', 0)
+ ->where('presale', 0)
+ ->where('self', 0)
+ ->where('is_deleted', 0)
+ ->where('is_returned', 0)
+ ->where('table_name', '0')
+ ->where('shift_id', $shift_id)
+ ->sum('order_sum');
+ }
}
+ return [
+ 'status' => 'success',
+ 'fiscal' => [
+ 'income_sum' => $checkout_sum,
+ 'outcome_sum' => $cashout_sum
+ ],
+ 'realisation' => [
+ 'orders_count' => $orders_count,
+ 'orders_sum_with_sales' => $orders_sum_full,
+ 'orders_sum_without_sales' => $orders_sum_ws,
+ 'sale_sum' => $sales_sum,
+ 'waited_orders_count' => $order_waited_count,
+ 'waited_orders_sum' => $order_waited_sum,
+
+ ],
+ 'returns' => [
+ 'returned_orders_count' => $returned_items_count,
+ 'returned_items_sum' => $returned_items_sum,
+ ],
+ 'cancellations' => [
+ 'cancellations_count' => $cancellations_count,
+ 'cancellations_sum' => Base::tofloat($cancellations_sum),
+ ],
+ 'statistic' => [
+ 'clients_count' => $clients_count,
+ 'clients_average_sum' => $average_sum,
+ 'clients_average_sum_one' => $average_sum_one_guest,
+ ],
+ 'presales' => [
+ 'presales_income_count' => $presales_income_count,
+ 'presales_outcome_count' => $presales_outcome_count,
+ 'presales_income_cash_sum' => $presales_income_cash_sum,
+ 'presales_income_credit_sum' => $presales_income_credit_sum,
+ 'presales_income_clearing_sum' => $presales_income_clearing_sum,
+ 'presales_income_discount_sum' => $presales_income_discount_sum,
+ 'presales_outcome_cash_sum' => $presales_outcome_cash_sum,
+ 'presales_outcome_credit_sum' => $presales_outcome_credit_sum,
+ 'presales_outcome_clearing_sum' => $presales_outcome_clearing_sum
+
+ ],
+ 'payments' => [
+ 'pay_cash' => $pay_cash_sum,
+ 'pay_credit' => $pay_credit_sum,
+ 'pay_clearing' => $pay_clearing_sum,
+ 'pay_self' => $pay_self_sum,
+ 'pay_presale' => $pay_presale_sum,
+ 'pay_online' => $pay_online_sum,
+ 'pay_another' => $pay_another_sum,
+ 'pay_echeck' => $pay_echeck_sum,
+ 'pay_delivery' => $pay_delivery_sum
+ ]
+ ];
+
}
}
} else {
diff --git a/commands/GETHelloWorld.php b/commands/GETHelloWorld.php
deleted file mode 100644
index 25838e5..0000000
--- a/commands/GETHelloWorld.php
+++ /dev/null
@@ -1,20 +0,0 @@
- 'success',
- 'users' => $users,
- ];
- }
-}
\ No newline at end of file
diff --git a/commands/GETKeyInfo.php b/commands/GETKeyInfo.php
new file mode 100644
index 0000000..4575717
--- /dev/null
+++ b/commands/GETKeyInfo.php
@@ -0,0 +1,39 @@
+ 'success',
+ 'info' => $cache,
+ 'input' => $input
+ ];
+ }
+ $info_file = __DIR__ . "\\..\\..\\..\\info.ini";
+ $key_file = __DIR__ . "\\..\\..\\..\\Key.key";
+ $unn = parse_ini_file($info_file);
+ $unn = intval($unn['unn']);
+ $info = json_decode(HRCEncryptor::decrypt(file_get_contents($key_file), $unn), true);
+ if (!$cache) {
+ $cache = Cache::store(245817422, 'v1', $input, $info);
+ }
+ return [
+ 'status' => 'success',
+ 'info' => $cache,
+ 'input' => $input
+ ];
+ }
+}
\ No newline at end of file
diff --git a/commands/GETOutOrders.php b/commands/GETOutOrders.php
index dd1cdb3..77b0d8c 100644
--- a/commands/GETOutOrders.php
+++ b/commands/GETOutOrders.php
@@ -3,7 +3,7 @@
namespace App\Commands;
use App\Component\Models\ExchangeShifts;
-use App\Component\Models\OrderBot;
+use App\Component\Models\OrderBotStorage;
use App\Component\Models\Report;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
@@ -19,7 +19,7 @@ class GETOutOrders extends HRCCommand implements HRCCommandInterface {
$out = array('id' => $shift['id'], 'opened' => $shift['opened'], 'closed' => $shift['closed']);
}
}
- $orders = OrderBot::select('id', 'order', 'created_at')->where('created_at', '>', $out['opened'])->where('created_at', '<=', $out['closed'])->get();
+ $orders = OrderBotStorage::select('id', 'order', 'created_at')->where('created_at', '>', $out['opened'])->where('created_at', '<=', $out['closed'])->get();
$count_items = 0;
if (is_array($orders) || is_object($orders)) {
foreach ($orders as $order) {
@@ -73,7 +73,7 @@ class GETOutOrders extends HRCCommand implements HRCCommandInterface {
$end_t = strtotime($input['end_date']) - 1;
$start = date('Y-m-d H:i:s', $start_t);
$end = date('Y-m-d H:i:s', $end_t);
- $orders = OrderBot::select('id', 'order', 'created_at')->where('created_at', '>', $start)->where('created_at', '<=', $end)->get();
+ $orders = OrderBotStorage::select('id', 'order', 'created_at')->where('created_at', '>', $start)->where('created_at', '<=', $end)->get();
$count_items = 0;
if (is_array($orders) || is_object($orders)) {
foreach ($orders as $order) {
diff --git a/commands/GETReports.php b/commands/GETReports.php
index 3e75a04..d6cd664 100644
--- a/commands/GETReports.php
+++ b/commands/GETReports.php
@@ -10,7 +10,7 @@ class GETReports extends HRCCommand implements HRCCommandInterface {
protected $signature = 'getreports';
public function command($input, $output = null) {
- $reports = Report::all();
+ $reports = Report::select('id', 'name', 'report_type', 'start_date', 'end_date')->orderBy('id', 'desc')->get();
if ($reports) {
foreach ($reports as $key => $report) {
$data[] = array(
diff --git a/commands/GETSettings.php b/commands/GETSettings.php
index d0a04bb..8058510 100644
--- a/commands/GETSettings.php
+++ b/commands/GETSettings.php
@@ -3,6 +3,8 @@
namespace App\Commands;
use App\Component\Models\Settings;
+use App\Component\Commands\Methods\Cache;
+use App\Component\Models\Terminal;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
@@ -12,6 +14,34 @@ class GETSettings extends HRCCommand implements HRCCommandInterface
public function command($input, $output = null)
{
+
+ if (isset($input['method'])) {
+ $method = $input['method'];
+ if ($method == 'terminals') {
+ $out = [];
+ $terminals = Terminal::get();
+ foreach ($terminals as $terminal) {
+ if ($terminal['is_active'] === 1) {
+ $is_active = true;
+ } else {
+ $is_active = false;
+ }
+
+ $out[] = array(
+ 'work_code' => $terminal['work_code'],
+ 'work_group' => $terminal['work_group'],
+ 'soft' => $terminal['soft'],
+ 'is_active' => $is_active,
+ 'key' => $terminal['key'],
+ 'last_activity' => $terminal['last_activity'],
+ );
+ }
+ return [
+ 'status' => 'success',
+ 'terminals' => $out,
+ ];
+ }
+ }
if (isset($input['code'])) {
$setting = Settings::where('code', $input['code'])
->first();
diff --git a/commands/GETTopDishes.php b/commands/GETTopDishes.php
index edf4b7f..47d1bdf 100644
--- a/commands/GETTopDishes.php
+++ b/commands/GETTopDishes.php
@@ -3,7 +3,8 @@
namespace App\Commands;
use App\Component\Models\Dishes;
-use App\Component\Models\OnlineItems;
+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;
@@ -18,8 +19,21 @@ class GETTopDishes extends HRCCommand implements HRCCommandInterface {
} else {
$terminalKey = 0;
}
- $info = OnlineItems::where('menu_code', '>', 0)->get()->unique('menu_code');
- $count = OnlineItems::where('menu_code', '>', 0)->count();
+ $allOrders = ShiftOnlineOrders::select('code')
+ ->where('is_closed', 1)
+ ->where('is_returned', 0)
+ ->where('is_deleted', 0)
+ ->get();
+ 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;
@@ -29,18 +43,22 @@ class GETTopDishes extends HRCCommand implements HRCCommandInterface {
->where('legacy_code', '=', $item['dish_code'])
->where('is_history', '=', 0)
->first();
- $onlineDishInfo = OnlineItems::where('menu_code', '=', $item['menu_code'])
+ $onlineDishInfo = ShiftOnlineItems::where('menu_code', '=', $item['menu_code'])
->where('dish_code', '=', $item['dish_code'])
+ ->whereIn('order_code', $orders)
->first();
if ($dishInfo['name'] == '') {
$dishHistInfo = Dishes::where('code', '=', $item['menu_code'])
->where('legacy_code', '=', $item['dish_code'])
+ ->whereIn('order_code', $orders)
->first();
$dishName = $dishHistInfo['name'];
} else {
$dishName = $dishInfo['name'];
}
- $dishCount = OnlineItems::where('menu_code', '=', $item['menu_code'])->sum('count');
+ $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);
diff --git a/commands/POSTBonus.php b/commands/POSTBonus.php
index 8857bf4..aabe56b 100644
--- a/commands/POSTBonus.php
+++ b/commands/POSTBonus.php
@@ -2,9 +2,11 @@
namespace App\Commands;
+use App\Component\Models\Client;
use App\Component\Models\ClientsBonus;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
+use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class POSTBonus extends HRCCommand implements HRCCommandInterface
@@ -13,13 +15,17 @@ class POSTBonus extends HRCCommand implements HRCCommandInterface
public function command($input, $output = null)
{
- $client_guid = $input['client_id'];
+ $client_guid = $input['client_guid'];
$bonus_amount = abs($input['amount']);
- $staff_id = $input['who'];
+ $staff_id = $input['who_id'];
$bonus_time = $input['date_transaction'];
$type = $input['type'];
ClientsBonus::bonusReg($client_guid, $bonus_amount, $type);
ClientsBonus::bonusLog($client_guid, $bonus_amount, $bonus_time, $staff_id);
+ $client = Client::where('user_code', $client_guid)->first();
+ $client = Client::find($client['id']);
+ $client->updated_at = Carbon::createFromTimestampUTC($bonus_time)->timezone('Europe/Minsk');
+ $client->save();
if ($type == 'in') {
$message = 'Начислено ' . $bonus_amount . ' бонусов';
} elseif ($type == 'out') {
diff --git a/commands/POSTClient.php b/commands/POSTClient.php
index 372e561..36bef63 100644
--- a/commands/POSTClient.php
+++ b/commands/POSTClient.php
@@ -12,119 +12,295 @@ use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
use Illuminate\Support\Facades\Log;
-class POSTClient extends HRCCommand implements HRCCommandInterface {
- protected $signature = 'postclient';
+class POSTClient extends HRCCommand implements HRCCommandInterface
+{
+ protected $signature = 'postclient';
- public function command($input, $output = null) {
+ public function command($input, $output = null)
+ {
- if (isset($input['task']) && isset($input['id'])) {
- if ($input['task'] == 'update') {
- $phone = urldecode($input['phone']);
- $client = Client::find($input['id']);
- $client->name = urldecode($input['name']);
- $client->unloaded = 0;
- $clientGroup = ClientsGroup::where('id', $input['group_id'])->first();
- $client->group_id = urldecode($clientGroup['code']);
- $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
- if ($clientPhone) {
- $clientPhone = ClientsPhone::find($clientPhone['id']);
- if ($phone !== '' && $phone !== '+375 ( ) - -') {
- if (substr($phone, 0, 1) == '+') {
- $phoneData = urldecode($input['phone']);
- } else {
- $phoneData = urldecode($input['phone']);
- $clientPhone->phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
- }
- } else {
- $clientPhone->phone = '+375 ( ) - -';
- }
- $clientPhone->save();
- }
+ if (isset($input['task'])) {
+ if ($input['task'] == 'update') {
+ log::debug($input);
+ if (isset($input['id'])) {
+ $id = $input['id'];
+ } else if (isset($input['client_guid'])) {
+ $fClient = Client::where('user_code', $input['client_guid'])->first();
+ if (!isset($fClient)) {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Клиент не найден',
+ ];
+ }
+ $id = $fClient['id'];
+ } else {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Проверьте введенные данные',
+ ];
+ }
+ if (isset($input['group_id']) && !isset($input['group_guid'])) {
+ $group_id = $input['group_id'];
+ } else if (isset($input['group_guid']) && !isset($input['group_id'])) {
+ $fGroup = ClientsGroup::where('code', $input['group_guid'])->first();
+ if (!isset($fGroup)) {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Группа не найдена',
+ ];
+ }
+ $group_id = $fGroup['id'];
+ } else if (isset($input['group_id']) && isset($input['group_guid'])) {
+ $fGroup = ClientsGroup::where('code', $input['group_guid'])->first();
+ if (!isset($fGroup)) {
+ $fGroup = ClientsGroup::where('id', isset($input['group_id']))->first();
+ if (!isset($fGroup)) {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Группа не найдена',
+ ];
+ }
+ }
+ $group_id = $fGroup['id'];
+ } else {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Проверьте введенные данные',
+ ];
+ }
+ $client = Client::find($id);
+ $client->name = urldecode($input['name']);
+ $client->unloaded = 0;
+ $clientGroup = ClientsGroup::where('id', $group_id)->first();
+ $client->group_id = $clientGroup['code'];
- $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
- if ($clientEmail) {
- $clientEmail = ClientsEmail::find($clientEmail['id']);
- if ($input['email'] !== '') {
- $clientEmail->email = urldecode($input['email']);
- } else {
- $clientEmail->email = '';
- }
- $clientEmail->save();
- }
+ if (isset($input['phone'])) {
+ $phone = $input['phone'];
+ Log::debug($phone);
+ $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
+ Log::debug($clientPhone);
+ if (isset($clientPhone)) {
+ $clientPhone = ClientsPhone::find($clientPhone['id']);
+ if ($phone !== '' && $phone !== '+375 ( ) - -') {
+ if (substr($phone, 0, 1) == '+') {
+ $clientPhone->phone = '+375 (' . substr($phone, 4, 2) . ') ' . substr($phone, 6, 3) . '-' . substr($phone, 9, 2) . '-' . substr($phone, 11, 2);
+ log::debug('UPD Substr true: ' . $phone);
+ } else {
+ log::debug('UPD Substr false: ' . $phone);
+ $clientPhone->phone = '+375 (' . substr($phone, 0, 2) . ') ' . substr($phone, 2, 3) . '-' . substr($phone, 5, 2) . '-' . substr($phone, 7, 2);
+ }
+ } else {
+ $clientPhone->phone = '+375 ( ) - -';
+ }
+ } else {
+ $clientPhone = new ClientsPhone;
+ if ($phone !== '' && $phone !== '+375 ( ) - -') {
+ if (substr($phone, 0, 1) == '+') {
+ $clientPhone->phone = '+375 (' . substr($phone, 4, 2) . ') ' . substr($phone, 6, 3) . '-' . substr($phone, 9, 2) . '-' . substr($phone, 11, 2);
+ log::debug('CR Substr true: ' . $phone);
+ } else {
+ log::debug('CR Substr false: ' . $phone);
+ $clientPhone->phone = '+375 (' . substr($phone, 0, 2) . ') ' . substr($phone, 2, 3) . '-' . substr($phone, 5, 2) . '-' . substr($phone, 7, 2);
+ }
+ } else {
+ $clientPhone->phone = '+375 ( ) - -';
+ }
+ }
+ $clientPhone->client_guid = $client->user_code;
+ $clientPhone->save();
+ }
- $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
- if ($clientAddress) {
- $clientAddress = ClientsAddress::find($clientAddress['id']);
- if ($input['address'] !== '') {
- $clientAddress->address = urldecode($input['address']);
- } else {
- $clientAddress->address = '';
- }
- $clientAddress->save();
- }
+ if (isset($input['email'])) {
+ $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
+ if ($clientEmail) {
+ $clientEmail = ClientsEmail::find($clientEmail['id']);
+ if (isset($input['email']) && $input['email'] !== '') {
+ $clientEmail->email = urldecode($input['email']);
+ } else {
+ $clientEmail->email = '';
+ }
+ } else {
+ $clientEmail = new ClientsEmail;
+ $clientEmail->email = urldecode($input['email']);
+ }
+ $clientEmail->client_guid = $client->user_code;
+ $clientEmail->save();
+ } else {
+ $clientEmail = '';
+ }
- $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
- if ($clientBarcode) {
- $clientBarcode = ClientsBarcode::find($clientBarcode['id']);
- if ($input['barcode'] !== '') {
- $clientBarcode->code_id = urldecode($input['barcode']);
- } else {
- $clientBarcode->code_id = '';
- }
- $clientBarcode->save();
- }
+ if (isset($input['address'])) {
+ $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
+ if ($clientAddress) {
+ $clientAddress = ClientsAddress::find($clientAddress['id']);
+ if ($input['address'] !== '') {
+ $clientAddress->address = urldecode($input['address']);
+ } else {
+ $clientAddress->address = '';
+ }
+ } else {
+ $clientAddress = new ClientsAddress;
+ $clientAddress->address = urldecode($input['address']);
+ }
+ $clientAddress->client_guid = $client->user_code;
+ $clientAddress->save();
+ }
+ $clientBarcodeStart = 0;
+ $clientBarcodeEnd = 0;
+
+ if (isset($input['barcode'])) {
+ if ($input['barcode'] !== '') {
+ $client->barcode_type = 2;
+ $client->barcode_start = $clientBarcodeStart = urldecode($input['barcode']);
+ $client->barcode_end = $clientBarcodeEnd = urldecode($input['barcode']);
+ } else {
+ $client->barcode_type = 1;
+ $client->barcode_start = $clientBarcodeStart;
+ $client->barcode_end = $clientBarcodeEnd;
+ }
+ }
+
+
+ if (isset($input['is_special_price']) && $input['is_special_price'] == 'true') {
+ $specialPrice = 1;
+ } else {
+ $specialPrice = 0;
+ }
+ if (isset($input['is_employee']) && $input['is_employee'] == 'true') {
+ $employee = 1;
+ } else {
+ $employee = 0;
+ }
+ $client->is_special_price = $specialPrice;
+ $client->is_employee = $employee;
$client->save();
- return [
- 'status' => 'success',
- 'client' => $client,
- 'phone' => $clientPhone,
- 'email' => $clientEmail,
- 'address' => $clientAddress,
- 'barcode' => $clientBarcode,
- 'message' => 'Клиент обновлен',
- ];
- }
+ return [
+ 'status' => 'success',
+ 'client' => $client,
+ 'phone' => $clientPhone,
+ 'email' => $clientEmail,
+ 'address' => $clientAddress,
+ 'barcode' => $clientBarcodeStart,
+ 'message' => 'Клиент обновлен',
+ ];
+ }
- if ($input['task'] == 'delete') {
- $client = Client::find($input['id']);
- $clientGroup = ClientsGroup::where('code', $client->group_id)->first();
- $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
- $clientPhone = ClientsPhone::find($clientPhone['id']);
- $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
- $clientEmail = ClientsEmail::find($clientEmail['id']);
- $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
- $clientAddress = ClientsAddress::find($clientAddress['id']);
- $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
- $clientBarcode = ClientsBarcode::find($clientBarcode['id']);
- if ($clientPhone) {
- $clientPhone->delete();
- }
- if ($clientEmail) {
- $clientEmail->delete();
- }
- if ($clientAddress) {
- $clientAddress->delete();
- }
- if ($clientBarcode) {
- $clientBarcode->delete();
- }
- if ($client) {
- $client->delete();
- }
+ if ($input['task'] == 'delete') {
+ $client = Client::find($input['id']);
+ $clientGroup = ClientsGroup::where('code', $client->group_id)->first();
+ $clientPhone = ClientsPhone::where('client_guid', $client->user_code)->first();
+ $clientPhone = ClientsPhone::find($clientPhone['id']);
+ $clientEmail = ClientsEmail::where('client_guid', $client->user_code)->first();
+ $clientEmail = ClientsEmail::find($clientEmail['id']);
+ $clientAddress = ClientsAddress::where('client_guid', $client->user_code)->first();
+ $clientAddress = ClientsAddress::find($clientAddress['id']);
+ $clientBarcode = ClientsBarcode::where('client_guid', $client->user_code)->first();
+ $clientBarcode = ClientsBarcode::find($clientBarcode['id']);
+ if ($clientPhone) {
+ $clientPhone->delete();
+ }
+ if ($clientEmail) {
+ $clientEmail->delete();
+ }
+ if ($clientAddress) {
+ $clientAddress->delete();
+ }
+ if ($clientBarcode) {
+ $clientBarcode->delete();
+ }
+ if ($client) {
+ $client->delete();
+ }
- return [
- 'status' => 'success',
- 'message' => 'Клиент удален',
- 'currentGroup' => $clientGroup['id'],
- ];
- }
- } else {
- return [
- 'status' => 'success',
- 'error_message' => 'Проверьте введенные данные',
- ];
- }
- }
+ return [
+ 'status' => 'success',
+ 'message' => 'Клиент удален',
+ 'currentGroup' => $clientGroup['id'],
+ ];
+ }
+
+ if ($input['task'] == 'lock') {
+ if (isset($input['id'])) {
+ $id = $input['id'];
+ } else if (isset($input['client_guid'])) {
+ $fClient = Client::where('user_code', $input['client_guid'])->first();
+ if (!isset($fClient)) {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Клиент не найден',
+ ];
+ }
+ $id = $fClient['id'];
+ } else {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Проверьте введенные данные',
+ ];
+ }
+ $client = Client::find($id);
+ $clientGroup = ClientsGroup::where('code', $client->group_id)->first();
+ $client->is_block = 1;
+ $client->save();
+
+ return [
+ 'status' => 'success',
+ 'message' => 'Клиент заблокирован',
+ 'currentGroup' => $clientGroup['id'],
+ ];
+ }
+
+ if ($input['task'] == 'unlock') {
+ if (isset($input['id'])) {
+ $id = $input['id'];
+ } else if (isset($input['client_guid'])) {
+ $fClient = Client::where('user_code', $input['client_guid'])->first();
+ if (!isset($fClient)) {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Клиент не найден',
+ ];
+ }
+ $id = $fClient['id'];
+ } else {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Проверьте введенные данные',
+ ];
+ }
+ $client = Client::find($id);
+ $clientGroup = ClientsGroup::where('code', $client->group_id)->first();
+ $client->is_block = 0;
+ $client->save();
+
+ return [
+ 'status' => 'success',
+ 'message' => 'Клиент разблокирован',
+ 'currentGroup' => $clientGroup['id'],
+ ];
+ }
+
+ if ($input['task'] == 'search' && isset($input['name'])) {
+ $client = Client::where('name', 'like', '%' . urldecode($input['name']) . '%')->get();
+ if (count($client) > 0) {
+ $message = 'Клиенты найдены!';
+ } else {
+ $message = 'Клиенты с именем ' . urldecode($input['name']) . ' не найдены!';
+ }
+
+ return [
+ 'status' => 'success',
+ 'message' => $message,
+ 'clients' => $client
+ ];
+ }
+
+ } else {
+ return [
+ 'status' => 'success',
+ 'error_message' => 'Проверьте введенные данные',
+ ];
+ }
+ }
}
\ No newline at end of file
diff --git a/commands/POSTCreateClient.php b/commands/POSTCreateClient.php
index f3c3332..ce44f9b 100644
--- a/commands/POSTCreateClient.php
+++ b/commands/POSTCreateClient.php
@@ -30,11 +30,26 @@ class POSTCreateClient extends HRCCommand implements HRCCommandInterface {
}
$total = Client::where('name', '=', $input['name'])->count();
+ if (isset($input['client_guid'])) {
+ $check_guid = Client::where('user_code', $input['client_guid'])->count();
+ if ($check_guid > 0) {
+ return [
+ 'status' => 'success',
+ 'message' => 'Клиент уже существует'
+ ];
+ }
+ }
+ $client_code = Client::max('code') + 1;
if (isset($input['is_special_price']) && $input['is_special_price'] == 'true') {
$specialPrice = 1;
} else {
$specialPrice = 0;
}
+ if (isset($input['is_employee']) && $input['is_employee'] == 'true') {
+ $employee = 1;
+ } else {
+ $employee = 0;
+ }
$client = new Client;
if ($total >= 1) {
$total = $total + 1;
@@ -42,10 +57,17 @@ class POSTCreateClient extends HRCCommand implements HRCCommandInterface {
} else {
$client->name = urldecode($input['name']);
}
- $client->user_code = strtoupper(md5(time()));
+ if (!isset($input['client_guid'])) {
+ $client->user_code = strtoupper(md5(time()));
+ } else {
+ $client->user_code = $input['client_guid'];
+ }
+
+ $client->code = $client_code;
$client->group_id = $group['code'];
$client->is_special_price = $specialPrice;
-
+ $client->is_employee = $employee;
+ $client->last_change = date("Ymd");
$clientEmail = new ClientsEmail;
$clientEmail->email = urldecode($input['email']);
$clientEmail->client_guid = $client->user_code;
@@ -55,7 +77,7 @@ class POSTCreateClient extends HRCCommand implements HRCCommandInterface {
$clientAddress->client_guid = $client->user_code;
$clientPhone = new ClientsPhone;
- if ($input['phone'] !== '') {
+ if ($input['phone'] !== '' && isset($input['phone'])) {
$phoneData = urldecode($input['phone']);
$phone = '+375 (' . substr($phoneData, 0, 2) . ') ' . substr($phoneData, 2, 3) . '-' . substr($phoneData, 5, 2) . '-' . substr($phoneData, 7, 2);
} else {
@@ -65,7 +87,7 @@ class POSTCreateClient extends HRCCommand implements HRCCommandInterface {
$clientPhone->client_guid = $client->user_code;
if (isset($input['barcode']) && $input['barcode'] > 0) {
- $client->barcode_type = 1;
+ $client->barcode_type = 2;
$clientBarcode = new ClientsBarcode;
$clientBarcode->code_id = urldecode($input['barcode']);
$clientBarcode->name = '';
@@ -73,13 +95,15 @@ class POSTCreateClient extends HRCCommand implements HRCCommandInterface {
$clientBarcode->value = urldecode($input['barcode']);
$clientBarcode->block = 0;
$clientBarcode->symptom_block = 0;
+ $client->barcode_start = urldecode($input['barcode']);
+ $client->barcode_end = urldecode($input['barcode']);
$client->save();
$clientPhone->save();
$clientEmail->save();
$clientAddress->save();
$clientBarcode->save();
} else {
- $client->barcode_type = 0;
+ $client->barcode_type = 1;
$client->save();
$clientPhone->save();
$clientEmail->save();
diff --git a/commands/POSTOrder.php b/commands/POSTOrder.php
index e13289d..188955c 100644
--- a/commands/POSTOrder.php
+++ b/commands/POSTOrder.php
@@ -2,11 +2,16 @@
namespace App\Commands;
+use App\Component\Models\Base;
use App\Component\Models\Dishes;
+use App\Component\Models\OrderBot;
+use App\Component\Models\OrderBotStorage;
use App\Component\Models\OrderItems;
use App\Component\Models\Orders;
+use App\Component\Models\TerminalUpdate;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
+use Carbon\Carbon;
class POSTOrder extends HRCCommand implements HRCCommandInterface {
protected $signature = 'postorder';
@@ -97,6 +102,132 @@ class POSTOrder extends HRCCommand implements HRCCommandInterface {
];
}
+ if ($input['task'] == 'pay' && isset($input['info'])) {
+ $test_json = Base::validate_json(urldecode($input['info']));
+ if (!$test_json) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Ошибка обработки JSON',
+ ];
+ }
+ $order_info = json_decode(urldecode($input['info']), true);
+
+ if (isset($order_info['order_id'])) {
+ $order_id = intval($order_info['order_id']);
+ $order = OrderBotStorage::where('id', $order_id)->first();
+ if (!isset($order)) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Заказ с данным ID не найден',
+ ];
+ }
+ } else {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Отсутствует ID заказа',
+ ];
+ }
+
+ if (isset($order_info['transaction_id'])) {
+ $transaction_id = intval($order_info['transaction_id']);
+ $order_data = json_decode(base64_decode($order['order']), true);
+ if ($transaction_id != $order_data['id']) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'ID заказа не соответствует ID транзакции',
+ ];
+ }
+ } else {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Отсутствует ID транзакции',
+ ];
+ }
+
+ if (isset($order_info['time'])) {
+ $pay_time = $order_info['time'];
+ if ($pay_time < $order['created_at']) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Время создания заказа больше чем время оплаты',
+ ];
+ }
+ } else {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Отсутствует время оплаты заказа',
+ ];
+ }
+
+ if (isset($order_info['amount'])) {
+ $amount = floatval($order_info['amount']);
+ if ($amount != floatval($order_data['price'])) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Сумма оплаты не соответствует сумме заказа',
+ ];
+ }
+ } else {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Отсутствует сумма оплаты',
+ ];
+ }
+
+ if (isset($order_info['is_print'])) {
+ $is_print = $order_info['is_print'];
+ } else {
+ $is_print = false;
+ }
+
+ if (isset($order_info['is_closed'])) {
+ $is_closed = $order_info['is_closed'];
+ } else {
+ $is_closed = false;
+ }
+
+ if ($order['is_send'] === 0) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Заказ ещё не отправлен',
+ ];
+ } else {
+ $pay_task = array(
+ 'order_id' => $order_id,
+ 'transaction_id' => $transaction_id,
+ 'time' => $pay_time,
+ 'amount' => $amount,
+ 'is_print' => $is_print,
+ 'is_closed' => $is_closed
+ );
+ $todayDate = Carbon::now('Europe/Minsk')->format('Y-m-d H:i:m');
+ $bot_info = OrderBot::first();
+ $terminal_id = $bot_info['terminal_id'];
+ $check_order = TerminalUpdate::where('method', 'payorder')
+ ->where('more', base64_encode(json_encode($pay_task)))
+ ->count();
+ if ($check_order > 0) {
+ return [
+ 'status' => 'fail',
+ 'message' => 'Задача оплаты в обработке',
+ ];
+ }
+ $task = new TerminalUpdate;
+ $task->terminal_id = $terminal_id;
+ $task->next_at = $todayDate;
+ $task->method = 'payorder';
+ $task->period = 1;
+ $task->is_cycle = 0;
+ $task->more = base64_encode(json_encode($pay_task));
+ $task->save();
+ }
+
+ return [
+ 'status' => 'success',
+ 'message' => 'Информация об оплате отправлена',
+ ];
+ }
+
} else {
return [
'status' => 'success',
diff --git a/commands/POSTPresale.php b/commands/POSTPresale.php
index b59f37a..8e75917 100644
--- a/commands/POSTPresale.php
+++ b/commands/POSTPresale.php
@@ -2,9 +2,11 @@
namespace App\Commands;
+use App\Component\Models\Client;
use App\Component\Models\ClientsPresale;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
+use Carbon\Carbon;
class POSTPresale extends HRCCommand implements HRCCommandInterface
{
@@ -12,18 +14,19 @@ class POSTPresale extends HRCCommand implements HRCCommandInterface
public function command($input, $output = null)
{
- $client_guid = $input['client_id'];
+ $client_guid = $input['client_guid'];
$presale_amount = abs($input['amount']);
- $staff_id = $input['who'];
+ $staff_id = $input['who_id'];
$presale_time = $input['date_transaction'];
$type = $input['type'];
+ $action_type = intval($input['action_type']);
+ $code_order = intval($input['code_order']);
ClientsPresale::presaleReg($client_guid, $presale_amount, $type);
- ClientsPresale::presaleLog($client_guid, $presale_amount, $presale_time, $staff_id);
- if ($type == 'in') {
- $message = 'Внесен аванс на сумму ' . $presale_amount . ' BYN';
- } elseif ($type == 'out') {
- $message = 'Зачтен аванс на сумму ' . $presale_amount . ' BYN';
- }
+ $message = ClientsPresale::presaleLog($client_guid, $presale_amount, $presale_time, $staff_id, $action_type, $code_order);
+ $client = Client::where('user_code', $client_guid)->first();
+ $client = Client::find($client['id']);
+ $client->updated_at = Carbon::createFromTimestampUTC($presale_time)->timezone('Europe/Minsk');
+ $client->save();
$presale_result = ClientsPresale::getPresale($client_guid);
return [
'status' => 'success',
diff --git a/composer.json b/composer.json
index 5d6c909..59b241c 100644
--- a/composer.json
+++ b/composer.json
@@ -1,10 +1,12 @@
{
"name": "hrc-admin/hello-world",
- "version": "2.26",
+ "version": "2.27",
"require": {
"horeca/admin-php-module-core": "dev-master",
"guzzlehttp/guzzle": "^7.4",
- "phpmailer/phpmailer": "^6.6"
+ "phpmailer/phpmailer": "^6.6",
+ "ext-openssl": "*",
+ "ext-json": "*"
},
"repositories": [
{
diff --git a/composer.lock b/composer.lock
index 782e627..f723847 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "c03123a7ef4b356dbbe431d73497088d",
+ "content-hash": "a8af6b76ceb6599b09c480a9985c90b3",
"packages": [
{
"name": "brick/math",
@@ -5896,7 +5896,10 @@
},
"prefer-stable": false,
"prefer-lowest": false,
- "platform": [],
+ "platform": {
+ "ext-openssl": "*",
+ "ext-json": "*"
+ },
"platform-dev": [],
"plugin-api-version": "2.0.0"
}
diff --git a/database/migrations/2023_02_03_114923_add_order_id_column_in_clients_actions.php b/database/migrations/2023_02_03_114923_add_order_id_column_in_clients_actions.php
new file mode 100644
index 0000000..7469dc5
--- /dev/null
+++ b/database/migrations/2023_02_03_114923_add_order_id_column_in_clients_actions.php
@@ -0,0 +1,31 @@
+integer('order_id')->nullable();
+ });
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down() {
+ Schema::table('clients_actions', function (Blueprint $table) {
+ $table->dropColumn('order_id');
+ });
+ }
+}
diff --git a/database/migrations/2023_03_10_140748_update_core_interface_2_27.php b/database/migrations/2023_03_10_140748_update_core_interface_2_27.php
new file mode 100644
index 0000000..2f6b208
--- /dev/null
+++ b/database/migrations/2023_03_10_140748_update_core_interface_2_27.php
@@ -0,0 +1,70 @@
+