mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 06:20:21 +00:00
Merge branch 'main' of https://bitbucket.org/studiotem/jandl-taskmanager-app
This commit is contained in:
commit
53b00789d8
4 files changed
+85
-8
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;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ class SendNewTaskEmailNotification implements ShouldQueue
|
||||
*/
|
||||
public function handle(SubTaskCreated $event)
|
||||
{
|
||||
//Mail::to( $event->subtask->user->email )->send( new NewTask( $event->subtask ) );
|
||||
// Mail::to( $event->subtask->user->email )->send( new NewTask( $event->subtask ) );
|
||||
Mail::to( 'feher@studiotem.com' )->send( new NewTask( $event->subtask ) );
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user