mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +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)
|
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');
|
self::$endpoint = Config::get('services.karat.endpoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function doRequest($command)
|
private static function doRequest($body)
|
||||||
{
|
{
|
||||||
$response = Http::timeout(60)
|
$response = Http::timeout(60)
|
||||||
->withOptions([
|
->withOptions([
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'verify' => false,
|
'verify' => false,
|
||||||
])->withBasicAuth(self::$username, self::$password)
|
])->withBasicAuth(self::$username, self::$password)
|
||||||
->post(self::$endpoint, [
|
->post(self::$endpoint, $body);
|
||||||
'command' => $command,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $response->json();
|
return $response->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getUsers()
|
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()
|
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()
|
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;
|
namespace App\Services\Karat;
|
||||||
|
|
||||||
|
use App\Models\Timesheet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
@@ -129,5 +130,19 @@ class KaratService
|
|||||||
\App\Models\Project::whereIn('code', $codesInDbThatAreNotInKaratAnymore)->delete();
|
\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