diff --git a/be/app/Console/Commands/SyncTimesheetsToKarat.php b/be/app/Console/Commands/SyncTimesheetsToKarat.php new file mode 100644 index 0000000..d9d1036 --- /dev/null +++ b/be/app/Console/Commands/SyncTimesheetsToKarat.php @@ -0,0 +1,37 @@ +syncTimesheets(); + + return Command::SUCCESS; + } +} diff --git a/be/app/Listeners/SendNewTaskEmailNotification.php b/be/app/Listeners/SendNewTaskEmailNotification.php index 858d983..9c173e8 100644 --- a/be/app/Listeners/SendNewTaskEmailNotification.php +++ b/be/app/Listeners/SendNewTaskEmailNotification.php @@ -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 ) ); } } diff --git a/be/app/Services/Karat/Api.php b/be/app/Services/Karat/Api.php index a976d18..dce8a46 100644 --- a/be/app/Services/Karat/Api.php +++ b/be/app/Services/Karat/Api.php @@ -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); } } diff --git a/be/app/Services/Karat/KaratService.php b/be/app/Services/Karat/KaratService.php index b06f4e3..b2b5e49 100644 --- a/be/app/Services/Karat/KaratService.php +++ b/be/app/Services/Karat/KaratService.php @@ -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(); + } }