dcodegroup / laravel-xero-timesheet-sync
此软件包为您的应用程序到Xero同步时间表提供标准Xero功能。
0.1.11
2023-12-11 05:09 UTC
Requires
- php: ^8.0
- dcodegroup/laravel-timesheets: ^0.1
- dcodegroup/laravel-xero-employee: ^0.1
- dcodegroup/laravel-xero-oauth: ^1.0
- dcodegroup/laravel-xero-payroll-au: ^0.1
- laravel/framework: ^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- laravel/pint: ^1.0
README
此软件包为您的应用程序到Xero同步时间表提供标准Xero功能。
安装
您可以通过Composer安装此软件包。
composer require dcodegroup/laravel-xero-timesheet-sync
然后运行安装命令。
php artsian laravel-xero-timesheet-sync:install
这将发布配置文件和迁移文件。
然后运行迁移。
php artsian migrate
这将向时间表表添加以下字段并创建两个新表。
timesheets --- can_include_in_xero_sync tinyint(1) DEFAULT=0 units double(8,2) xero_timesheet_id unsignedbigint(255) FK >- xero_timesheets.id xero_timesheets --- id bigint(20) PK IDENTITY xerotimeable_type varchar(255) xerotimeable_id unsignedbigint xero_timesheet_guid varchar(50) NULL # The identifier returned from xero xero_employee_id varchar(50) NULL # may be redundant becuase its on the user that should be the polymporphic field. But saves a lookup status varchar(50) NULL DEFAULT=DRAFT start_date date stop_date date hours double(8,2) synced_at timestamp NULL deleted_at timestamp NULL created_at timestamp NULL updated_at timestamp NULL xero_timesheets_lines --- id bigint(20) PK IDENTITY xero_timesheet_id unsignedbigint(255) FK >- xero_timesheets.id xero-earnings_rate_id date date units double(8,2) units_override double(8,2) deleted_at timestamp NULL created_at timestamp NULL updated_at timestamp NULL
配置
大多数配置都已设置为合理的默认值。但是,您可以在config/laravel-xero-timesheet-sync.php
中审查配置文件并根据需要调整。
您需要将此字段添加到时间表模型中的可填充数组。如果您正在扩展基础时间表模型,则不需要此操作,因为它有保护数组[]。
/** * The attributes that are mass assignable. * * @var string[] */ protected $fillable = [ 'can_include_in_xero_sync', 'units', 'xero_timesheet_id' ... ];
建议您还将can_include_in_xero_sync
作为布尔字段在Timesheet
模型中进行类型转换。
/** * The attributes that should be cast. * * @var array */ //protected $casts = [ // 'can_include_in_xero_sync' => 'boolean', // ... //]; /** * Merge casts with the existing */ public function getCasts(): array { return parent::getCasts() + [ 'can_include_in_xero_sync' => 'boolean', ]; }
您应该在Timesheet::class
模型中添加接口。
use Dcodegroup\LaravelXeroTimesheetSync\Contracts\SyncsTimesheetsToXero; class Timesheet extends BaseTimesheet implements SyncsTimesheetsToXero {
您应该在时间表模型中添加以下特质。
class Timesheet extends Authenticatable { use XeroTimesheetable;
您需要实现这些方法
为了使时间表行可用于/用于发送到Xero,需要将timesheets.can_include_in_xero_sync
标记/设置为true或值1。这需要在本地应用程序级别实现。
在XeroTimesheetable.php
特质中提供了三个辅助方法。
public function includeInXeroSync() { $this->update(['can_include_in_xero_sync', true]); } public function excludeFromXeroSync() { $this->update(['can_include_in_xero_sync', false]); } public function toggleIncludeInXeroSync() { $this->can_include_in_xero_sync = !$this->can_include_in_xero_sync; $this->save(); }
路由
此软件包暴露以下路由
+--------+----------+-----------------------------+-----------------------------+-------------------------------------------------------------------------------------+----------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------+-----------------------------+-------------------------------------------------------------------------------------+----------------------------------+
| | GET|HEAD | xero-timesheet-sync/preview | xero_timesheet_sync.preview | Dcodegroup\LaravelXeroTimesheetSync\Http\Controllers\XeroTimesheetPreviewController | web |
| | | | | | App\Http\Middleware\Authenticate |
| | GET|HEAD | xero-timesheet-sync/summary | xero_timesheet_sync.summary | Dcodegroup\LaravelXeroTimesheetSync\Http\Controllers\XeroTimesheetSummaryController | web |
| | | | | | App\Http\Middleware\Authenticate |
+--------+----------+-----------------------------+-----------------------------+-------------------------------------------------------------------------------------+----------------------------------+
软件包暴露了一些路由,允许您预览用户的时间表
您还可以查看一段时间内时间表的总览
工作
命令
有一个命令可以运行,通过Laravel计划任务从dcodegroup/laravel-xero-payroll-au
更新Xero配置
php artsian laravel-xero-timesheet-sync:update-xero-configuration-data
您应将其添加到app/Console/Kernel.php
文件中,每天运行一次。如果需要,可以使用--force标志更频繁地运行。
/** * Define the application's command schedule. * * @param Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->command('laravel-xero-timesheet-sync:update-xero-configuration-data')->daily(); ... }