v.2.15
Обновление отчета по персоналу
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\ExchangeActions;
|
||||
use App\Component\Models\ExchangeDeleted;
|
||||
use App\Component\Models\ExchangeOrders;
|
||||
use App\Component\Models\ExchangeShifts;
|
||||
use App\Component\Models\Staff;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
@@ -81,9 +84,8 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface {
|
||||
}
|
||||
|
||||
$reportType = $input['type'];
|
||||
$shiftNumber = $input['shift_id'];
|
||||
//merge, slice, move
|
||||
if (isset($reportType) && isset($shiftNumber)) {
|
||||
if (isset($reportType)) {
|
||||
//merge
|
||||
if ($reportType == 'merge') {
|
||||
$merged_order_items = [];
|
||||
@@ -208,6 +210,276 @@ class GETDataReport extends HRCCommand implements HRCCommandInterface {
|
||||
'data' => $moved_order_data,
|
||||
];
|
||||
}
|
||||
if ($reportType == 'staff') {
|
||||
if (isset($input['shift_id'])) {
|
||||
$staff = $staff_data = [];
|
||||
$countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0;
|
||||
$openedOrders = ExchangeOrders::select('who_open')
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('who_open', '>', 0)
|
||||
->groupBy('who_open')
|
||||
->get();
|
||||
$closedOrders = ExchangeOrders::select('who_close')
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('who_close', '>', 0)
|
||||
->groupBy('who_close')
|
||||
->get();
|
||||
foreach ($openedOrders as $key => $openedOrder) {
|
||||
array_push($staff, $openedOrder['who_open']);
|
||||
}
|
||||
foreach ($closedOrders as $key => $closedOrder) {
|
||||
array_push($staff, $closedOrder['who_close']);
|
||||
}
|
||||
$staff = array_unique($staff);
|
||||
foreach ($staff as $key => $value) {
|
||||
$staffId = $value + 0;
|
||||
$name = staffName($staffId);
|
||||
$code = $staffId;
|
||||
$countOpened = ExchangeOrders::where('who_open', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->count();
|
||||
$countClosed = ExchangeOrders::where('who_close', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->count();
|
||||
$sumOpened = ExchangeOrders::where('who_open', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->sum('order_sum');
|
||||
$sumClosed = ExchangeOrders::where('who_close', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->sum('order_sum');
|
||||
$inputCount = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 49)
|
||||
->count();
|
||||
$inputSum = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 49)
|
||||
->sum('value');
|
||||
$outputCount = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 50)
|
||||
->count();
|
||||
$outputSum = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 50)
|
||||
->sum('value');
|
||||
$annulCount = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 43)
|
||||
->count();
|
||||
$annulOrders = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 43)
|
||||
->get();
|
||||
foreach ($annulOrders as $key => $annulOrder) {
|
||||
$annulOrderSum = ExchangeOrders::where('code', $annulOrder['order_code'])
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->first();
|
||||
$annulSum = $annulSum + $annulOrderSum['order_sum'];
|
||||
}
|
||||
$returnCount = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 19)
|
||||
->count();
|
||||
$returnOrders = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 19)
|
||||
->get();
|
||||
foreach ($returnOrders as $key => $returnOrder) {
|
||||
$returnOrderSum = ExchangeOrders::where('code', $returnOrder['order_code'])
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->first();
|
||||
$returnSum = $returnSum + abs($returnOrderSum['order_sum']);
|
||||
}
|
||||
$deletedCount = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 8)
|
||||
->where('reason', '>', 0)
|
||||
->count();
|
||||
$deletedOrders = ExchangeActions::where('who', $staffId)
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->where('action_type', 8)
|
||||
->where('reason', '>', 0)
|
||||
->get();
|
||||
foreach ($deletedOrders as $key => $deletedOrder) {
|
||||
$deletedOrdersSum = ExchangeDeleted::where('order_code', $deletedOrder['order_code'])
|
||||
->where('shift_id', $input['shift_id'])
|
||||
->sum('sale_price');
|
||||
$deletedSum = $deletedSum + $deletedOrdersSum;
|
||||
}
|
||||
$staff_data[] = array(
|
||||
'name' => $name,
|
||||
'code' => $code + 0,
|
||||
'opened_count' => $countOpened + 0,
|
||||
'closed_count' => $countClosed,
|
||||
'opened_sum' => $sumOpened + 0,
|
||||
'closed_sum' => $sumClosed + 0,
|
||||
'input_count' => $inputCount,
|
||||
'output_count' => $outputCount,
|
||||
'input_sum' => $inputSum,
|
||||
'output_sum' => $outputSum,
|
||||
'annul_count' => $annulCount,
|
||||
'annul_sum' => $annulSum,
|
||||
'return_count' => $returnCount,
|
||||
'return_sum' => round($returnSum, 2),
|
||||
'deleted_count' => $deletedCount,
|
||||
'deleted_sum' => $deletedSum);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'staffs' => $staff_data,
|
||||
];
|
||||
}
|
||||
if (isset($input['start_date']) && isset($input['end_date'])) {
|
||||
$staff = $staff_data = $shifts = [];
|
||||
$countOpened = $countClosed = $sumOpened = $sumClosed = $inputCount = $inputSum = $outputCount = $outputSum = $annulCount = $annulSum = $returnCount = $returnSum = $deletedCount = $deletedSum = 0;
|
||||
$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']));
|
||||
$shiftIds = ExchangeShifts::where('opened', '>', $start_date)
|
||||
->where('opened', '<', $end_date)
|
||||
->get();
|
||||
foreach ($shiftIds as $key => $shiftId) {
|
||||
array_push($shifts, $shiftId['id']);
|
||||
}
|
||||
$openedOrders = ExchangeOrders::select('who_open')
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('who_open', '>', 0)
|
||||
->groupBy('who_open')
|
||||
->get();
|
||||
$closedOrders = ExchangeOrders::select('who_close')
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('who_close', '>', 0)
|
||||
->groupBy('who_close')
|
||||
->get();
|
||||
foreach ($openedOrders as $key => $openedOrder) {
|
||||
array_push($staff, $openedOrder['who_open']);
|
||||
}
|
||||
foreach ($closedOrders as $key => $closedOrder) {
|
||||
array_push($staff, $closedOrder['who_close']);
|
||||
}
|
||||
$staff = array_unique($staff);
|
||||
foreach ($staff as $key => $value) {
|
||||
$staffId = $value + 0;
|
||||
$name = staffName($staffId);
|
||||
$code = $staffId;
|
||||
$countOpened = ExchangeOrders::where('who_open', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->count();
|
||||
$countClosed = ExchangeOrders::where('who_close', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->count();
|
||||
$sumOpened = ExchangeOrders::where('who_open', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->sum('order_sum');
|
||||
$sumClosed = ExchangeOrders::where('who_close', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('order_sum', '>', 0)
|
||||
->sum('order_sum');
|
||||
$inputCount = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 49)
|
||||
->count();
|
||||
$inputSum = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 49)
|
||||
->sum('value');
|
||||
$outputCount = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 50)
|
||||
->count();
|
||||
$outputSum = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 50)
|
||||
->sum('value');
|
||||
$annulCount = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 43)
|
||||
->count();
|
||||
$annulOrders = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 43)
|
||||
->get();
|
||||
foreach ($annulOrders as $key => $annulOrder) {
|
||||
$annulSum = $annulSum + ExchangeOrders::where('code', $annulOrder['order_code'])
|
||||
->whereIn('shift_id', $shifts)
|
||||
->sum('order_sum');
|
||||
}
|
||||
$returnCount = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 19)
|
||||
->count();
|
||||
$returnOrders = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 19)
|
||||
->get();
|
||||
foreach ($returnOrders as $key => $returnOrder) {
|
||||
$returnSum = $returnSum + abs(ExchangeOrders::where('code', $returnOrder['order_code'])
|
||||
->whereIn('shift_id', $shifts)
|
||||
->sum('order_sum'));
|
||||
}
|
||||
$deletedCount = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 8)
|
||||
->where('reason', '>', 0)
|
||||
->count();
|
||||
$deletedOrders = ExchangeActions::where('who', $staffId)
|
||||
->whereIn('shift_id', $shifts)
|
||||
->where('action_type', 8)
|
||||
->where('reason', '>', 0)
|
||||
->get();
|
||||
foreach ($deletedOrders as $key => $deletedOrder) {
|
||||
$deletedSum = $deletedSum + ExchangeDeleted::where('order_code', $deletedOrder['order_code'])
|
||||
->whereIn('shift_id', $shifts)
|
||||
->sum('sale_price');
|
||||
}
|
||||
$staff_data[] = array(
|
||||
'name' => $name,
|
||||
'code' => $code + 0,
|
||||
'opened_count' => $countOpened + 0,
|
||||
'closed_count' => $countClosed,
|
||||
'opened_sum' => $sumOpened + 0,
|
||||
'closed_sum' => $sumClosed + 0,
|
||||
'input_count' => $inputCount,
|
||||
'output_count' => $outputCount,
|
||||
'input_sum' => $inputSum,
|
||||
'output_sum' => $outputSum,
|
||||
'annul_count' => $annulCount,
|
||||
'annul_sum' => $annulSum,
|
||||
'return_count' => $returnCount,
|
||||
'return_sum' => round($returnSum, 2),
|
||||
'deleted_count' => $deletedCount,
|
||||
'deleted_sum' => $deletedSum);
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'staffs' => $staff_data,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
|
||||
Reference in New Issue
Block a user