v.2.15
Discounts block update
This commit is contained in:
39
commands/GETDiscountItems.php
Normal file
39
commands/GETDiscountItems.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\ShiftOnlineItems;
|
||||
use App\Component\Models\ShiftOnlineOrders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETDiscountItems extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getdiscountitems';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$orderId = $input['order'] + 0;
|
||||
$items = [];
|
||||
$order = ShiftOnlineOrders::where('code', $orderId)->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
36
commands/GETMoreDiscount.php
Normal file
36
commands/GETMoreDiscount.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\ShiftOnlineOrders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETMoreDiscount extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getmorediscount';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$amountWithoutDiscount = 0;
|
||||
$totalSum = 0;
|
||||
$orderInfo = [];
|
||||
$orders = ShiftOnlineOrders::where('is_deleted', 0)
|
||||
->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
43
commands/GETOnlineDiscount.php
Normal file
43
commands/GETOnlineDiscount.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\ShiftOnlineItems;
|
||||
use App\Component\Models\ShiftOnlineOrders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETOnlineDiscount extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getonlinediscount';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$count = $totalSum = $discountSum = 0;
|
||||
$count = ShiftOnlineOrders::where('is_deleted', 0)
|
||||
->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user