-Add delete reports
This commit is contained in:
miroman-afk
2022-02-01 02:47:25 +03:00
parent 5497b611ef
commit 5b1c774259
8 changed files with 106 additions and 25 deletions

35
commands/GETReports.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Commands;
use App\Component\Models\Report;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
class GETReports extends HRCCommand implements HRCCommandInterface {
protected $signature = 'getreports';
public function command($input, $output = null) {
$reports = Report::all();
if ($reports) {
foreach ($reports as $key => $report) {
$data[] = array(
'id' => $report['id'],
'name' => $report['name'],
'type' => $report['report_type'],
'start_date' => date('d.m.Y', strtotime($report['start_date'])),
'end_date' => date('d.m.Y', strtotime($report['end_date'])),
);
}
return [
'status' => 'success',
'reports' => $data,
];
} else {
return [
'status' => 'success',
'reports' => [],
];
}
}
}

View File

@@ -15,7 +15,6 @@ class GETSettings extends HRCCommand implements HRCCommandInterface {
if ($setting) {
return [
'status' => 'success',
'name' => $setting['name'],
'code' => $setting['code'],
'value' => $setting['value'],
];

View File

@@ -7,6 +7,7 @@ use App\Component\Models\ExchangeDeleted;
use App\Component\Models\ExchangeItems;
use App\Component\Models\ExchangeOrders;
use App\Component\Models\ExchangeShifts;
use App\Component\Models\Report;
use App\Console\Commands\HRCCommand;
use App\Console\Commands\HRCCommandInterface;
@@ -26,28 +27,16 @@ class POSTDeleteData extends HRCCommand implements HRCCommandInterface {
$exchange_shift->delete();
}
if ($exchange_orders) {
foreach ($exchange_orders as $key => $exchange_order) {
$order = ExchangeOrders::find($exchange_order['id']);
$order->delete();
}
$exchange_orders = ExchangeOrders::where('shift_id', '=', $input['shift_id'])->delete();
}
if ($exchange_items) {
foreach ($exchange_items as $key => $exchange_item) {
$item = ExchangeItems::find($exchange_item['id']);
$item->delete();
}
$exchange_items = ExchangeItems::where('shift_id', '=', $input['shift_id'])->delete();
}
if ($exchange_actions) {
foreach ($exchange_actions as $key => $exchange_action) {
$action = ExchangeActions::find($exchange_action['id']);
$action->delete();
}
$exchange_actions = ExchangeActions::where('shift_id', '=', $input['shift_id'])->delete();
}
if ($exchange_deleted) {
foreach ($exchange_deleted as $key => $exchange_delete) {
$delete = ExchangeDeleted::find($exchange_delete['id']);
$delete->delete();
}
$exchange_deleted = ExchangeDeleted::where('shift_id', '=', $input['shift_id'])->delete();
}
function dirDel($dir) {
$d = opendir($dir);
@@ -76,6 +65,27 @@ class POSTDeleteData extends HRCCommand implements HRCCommandInterface {
'message' => 'Check input data',
];
}
} elseif ($input['value'] == 'delete_report') {
if ($input['report_id']) {
$report = Report::where('id', $input['report_id'])->first();
if ($report) {
$report = Report::where('id', $input['report_id'])->delete();
return [
'status' => 'success',
'message' => 'Данные удалены',
];
} else {
return [
'status' => 'error',
'message' => 'Report not found',
];
}
} else {
return [
'status' => 'error',
'message' => 'Check input data',
];
}
} else {
return [
'status' => 'error',