From 2d148e3eb5ac10705581ca8c862a3a67b4b18c99 Mon Sep 17 00:00:00 2001 From: miroman-afk <74014189+miroman-afk@users.noreply.github.com> Date: Thu, 28 Apr 2022 23:55:53 +0300 Subject: [PATCH] v.2.15 Discounts block update --- commands/GETDiscountItems.php | 39 +++++++++++++++++ commands/GETMoreDiscount.php | 36 ++++++++++++++++ commands/GETOnlineDiscount.php | 43 +++++++++++++++++++ commands/GETOrderHistory.php | 26 ++++++++++- web/controllers/dashboard.js | 20 +++++++-- web/views/dashboard/dashboard.html | 16 +------ web/views/dashboard/items/items-discount.html | 4 +- web/views/dashboard/items/items-total.html | 5 +++ web/views/dashboard/items/more-discount.html | 2 +- 9 files changed, 169 insertions(+), 22 deletions(-) create mode 100644 commands/GETDiscountItems.php create mode 100644 commands/GETMoreDiscount.php create mode 100644 commands/GETOnlineDiscount.php diff --git a/commands/GETDiscountItems.php b/commands/GETDiscountItems.php new file mode 100644 index 0000000..833ec03 --- /dev/null +++ b/commands/GETDiscountItems.php @@ -0,0 +1,39 @@ +first(); + $onlineItems = ShiftOnlineItems::where('order_code', $order['code'])->where('modificator_code', 0)->get(); + foreach ($onlineItems as $key => $item) { + $realPrice = $item['real_price'] * $item['count'] * $item['cof']; + $salePrice = $item['sale_price'] * $item['count']; + if ($realPrice > 0) { + $discount = $salePrice / $realPrice; + $discount = (1 - $discount) * 100; + } else { + $discount = 0; + } + $dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first(); + $items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2)); + } + + return [ + 'status' => 'success', + 'title' => $order['code'], + 'total' => $order['order_sum'], + 'items' => $items, + ]; + } +} \ No newline at end of file diff --git a/commands/GETMoreDiscount.php b/commands/GETMoreDiscount.php new file mode 100644 index 0000000..6a43caf --- /dev/null +++ b/commands/GETMoreDiscount.php @@ -0,0 +1,36 @@ +where('is_returned', 0) + ->where('sale_sum', '>', 0) + ->get(); + if ($orders) { + foreach ($orders as $key => $order) { + $orderInfo[] = array('number' => $order['code'], 'full_sum' => $order['full_sum'], 'sale_sum' => $order['sale_sum'], 'order_sum' => $order['order_sum']); + $amountWithoutDiscount = $amountWithoutDiscount + $order['full_sum']; + $totalSum = $totalSum + $order['order_sum']; + } + } + + return [ + 'status' => 'success', + 'title' => 'Подробнее о заказах со скидками', + 'amount' => $amountWithoutDiscount, + 'total_sum' => $totalSum, + 'orders' => $orderInfo, + ]; + } +} \ No newline at end of file diff --git a/commands/GETOnlineDiscount.php b/commands/GETOnlineDiscount.php new file mode 100644 index 0000000..0915cf5 --- /dev/null +++ b/commands/GETOnlineDiscount.php @@ -0,0 +1,43 @@ +where('is_returned', 0) + ->where('sale_sum', '>', 0) + ->count(); + if ($count > 0) { + $totalSum = ShiftOnlineOrders::where('is_deleted', 0) + ->where('is_returned', 0) + ->where('sale_sum', '>', 0) + ->sum('order_sum'); + $orders = ShiftOnlineOrders::where('is_deleted', 0) + ->where('is_returned', 0)->get(); + foreach ($orders as $key => $order) { + $items = ShiftOnlineItems::where('order_code', $order['code'])->get(); + foreach ($items as $key => $item) { + $realPrice = $item['real_price'] * $item['count'] * $item['cof']; + $salePrice = $item['sale_price'] * $item['count']; + $discountSum = round(($discountSum + abs($salePrice - $realPrice)), 2); + } + } + } + + return [ + 'status' => 'success', + 'count' => $count, + 'sum' => $discountSum, + 'total_sum' => $totalSum, + ]; + } +} \ No newline at end of file diff --git a/commands/GETOrderHistory.php b/commands/GETOrderHistory.php index 93b67a7..ff75e8b 100644 --- a/commands/GETOrderHistory.php +++ b/commands/GETOrderHistory.php @@ -173,7 +173,18 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { foreach ($slice_order_items as $key => $slice_order_item) { $slice_items[] = array('id' => $key + 1, 'name' => $slice_order_item['name'], 'count' => $slice_order_item['count']); } - $sliced_order_items[] = array('order' => $slice_order, 'items' => $slice_items); + $staff_name = Staff::where('code', $item['who'])->where('is_history', 0)->first(); + if ($staff_name) { + $staff_name = $staff_name['name']; + } else { + $staff_name = Staff::where('code', $item['who'])->where('is_history', 1)->first(); + if ($staff_name) { + $staff_name = $staff_name['name']; + } else { + $staff_name = 'Связанный персонал не найден'; + } + } + $sliced_order_items[] = array('order' => $slice_order, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'items' => $slice_items); $slice_trigger = 1; } } @@ -219,7 +230,18 @@ class GETOrderHistory extends HRCCommand implements HRCCommandInterface { 'name' => $merged_item['name'], 'count' => $merged_item['count']); } - $merged_order_items[] = array('order' => $merge_order, 'items' => $merge_items); + $staff_name = Staff::where('code', $item['who'])->where('is_history', 0)->first(); + if ($staff_name) { + $staff_name = $staff_name['name']; + } else { + $staff_name = Staff::where('code', $item['who'])->where('is_history', 1)->first(); + if ($staff_name) { + $staff_name = $staff_name['name']; + } else { + $staff_name = 'Связанный персонал не найден'; + } + } + $merged_order_items[] = array('order' => $merge_order, 'time' => date('d.m.Y H:i:s', strtotime($item['time'])), 'staff' => $staff_name, 'items' => $merge_items); } } } diff --git a/web/controllers/dashboard.js b/web/controllers/dashboard.js index 2272bc0..285d1a4 100644 --- a/web/controllers/dashboard.js +++ b/web/controllers/dashboard.js @@ -392,7 +392,7 @@ $scope.deleted_sum = Math.roundNG(data.sum, -2); }); - smartRequest.get('dashboard/online/discount', function (data) { + smartRequest.get('v1/onlinediscount', function (data) { $scope.discounts = Math.roundNG(data.count, -2); $scope.discounts_sum = Math.roundNG(data.sum, -2); $scope.tot_disc_sum = Math.roundNG(data.total_sum, -2); @@ -555,7 +555,7 @@ $scope.deleted_sum = Math.roundNG(data.sum, -2); }); - smartRequest.get('dashboard/online/discount', function (data) { + smartRequest.get('v1/onlinediscount', function (data) { $scope.discounts = Math.roundNG(data.count, -2); $scope.discounts_sum = Math.roundNG(data.sum, -2); $scope.tot_disc_sum = Math.roundNG(data.total_sum, -2); @@ -715,6 +715,13 @@ }); }; + $scope.getMoreDiscount = function () { + smartRequest.get('v1/morediscount/', function (data) { + $scope.moreData = data; + $('#get-more-discount').modal(); + }); + }; + $scope.getItems = function (modal, order) { $('#get-more-' + modal).modal('toggle'); smartRequest.get('dashboard/' + modal + '/items?order=' + order.number, function (data) { @@ -723,6 +730,14 @@ }); }; + $scope.getItemsDiscount = function (order) { + $('#get-more-discount').modal('toggle'); + smartRequest.get('v1/discountitems?order=' + order.number, function (data) { + $scope.order = data; + $('#items-discount').modal('toggle'); + }); + }; + $scope.returnModal = function (name) { $('#items-' + name).on('hidden.bs.modal', function (event) { $('#get-more-' + name).modal('show'); @@ -735,7 +750,6 @@ $scope.order = data; smartRequest.get('v1/orderhistory?order_id=' + order.number, function (actions) { $scope.actions = actions; - console.log(actions); }); $('#items-total').modal('toggle'); }); diff --git a/web/views/dashboard/dashboard.html b/web/views/dashboard/dashboard.html index 3f65134..98ddd2a 100644 --- a/web/views/dashboard/dashboard.html +++ b/web/views/dashboard/dashboard.html @@ -143,7 +143,7 @@
Время разбиения: {{ sliced_order_item.time }}
+Пользователь: {{ sliced_order_item.staff }}
Товары перенесенные в заказ №{{ sliced_order_item.order }}
| {{ order.number }} | {{ order.full_sum | curr }} | {{ order.sale_sum | curr }} |