no message

This commit is contained in:
StudioTem committed 2023-04-05 08:37:20 +02:00
1 parent 356dd12566
commit 1f621a6bb4
4 files changed
+84 -7

No files matched your search

@@ -0,0 +1,37 @@
<?php
namespace App\Console\Commands;
use App\Services\Karat\KaratService;
use Illuminate\Console\Command;
class SyncTimesheetsToKarat extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'karat:sync-timesheets';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Syncing timesheets to Karat';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$karatService = new KaratService();
$karatService->syncTimesheets();
return Command::SUCCESS;
}
}
@@ -30,5 +30,6 @@ class SendNewTaskEmailNotification implements ShouldQueue
public function handle(SubTaskCreated $event)
{
// Mail::to( $event->subtask->user->email )->send( new NewTask( $event->subtask ) );
Mail::to( 'feher@studiotem.com' )->send( new NewTask( $event->subtask ) );
}
}
+31 -7
View File
@@ -27,32 +27,56 @@ class Api
self::$endpoint = Config::get('services.karat.endpoint');
}
private static function doRequest($command)
private static function doRequest($body)
{
$response = Http::timeout(60)
->withOptions([
'debug' => true,
'verify' => false,
])->withBasicAuth(self::$username, self::$password)
->post(self::$endpoint, [
'command' => $command,
]);
->post(self::$endpoint, $body);
return $response->json();
}
public static function getUsers()
{
return self::doRequest('TM_GET_USERS')['users'];
$body = [
'command' => 'TM_GET_USERS',
];
return self::doRequest($body)['users'];
}
public static function getClients()
{
return self::doRequest('TM_GET_CLIENTS')['clients'];
$body = [
'command' => 'TM_GET_CLIENTS',
];
return self::doRequest($body)['clients'];
}
public static function getProjects()
{
return self::doRequest('TM_GET_PROJECTS')['projects'];
$body = [
'command' => 'TM_GET_PROJECTS',
];
return self::doRequest($body)['projects'];
}
public static function setTimesheet($timesheet)
{
$body = [
'command' => 'TM_SET_vykaz',
'zakazka' => $timesheet->subtask->project->code,
'zdroj' => $timesheet->user->code,
'hodin' => $timesheet->time,
'datum' => $timesheet->created_at->format('Y-m-d'),
'task_mng' => $timesheet->id,
];
return self::doRequest($body);
}
}
+15
View File
@@ -2,6 +2,7 @@
namespace App\Services\Karat;
use App\Models\Timesheet;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Arr;
@@ -129,5 +130,19 @@ class KaratService
\App\Models\Project::whereIn('code', $codesInDbThatAreNotInKaratAnymore)->delete();
}
public function syncTimesheets() {
$notSyncedTimesheets = Timesheet::whereNull('synced_to_karat')->get();
$notSyncedTimesheets->each(function ($timesheet) {
$this->syncTimesheet($timesheet);
});
}
private function syncTimesheet(Timesheet $timesheet) {
$this->api->setTimesheet($timesheet);
$timesheet->synced_to_karat = true;
$timesheet->save();
}
}