diff --git a/app/Models/RegularContract.php b/app/Models/RegularContract.php index 44d0fc5..1c3f96c 100644 --- a/app/Models/RegularContract.php +++ b/app/Models/RegularContract.php @@ -4,18 +4,10 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; -/** - * 定期契約モデル - regular_contractテーブル(正式モデル) - * 旧UsingStatusContractの責務を置き換え - */ class RegularContract extends Model { protected $table = 'regular_contract'; protected $primaryKey = 'contract_id'; - public $timestamps = true; - - public const CREATED_AT = 'created_at'; - public const UPDATED_AT = 'updated_at'; protected $fillable = [ 'contract_qr_id', @@ -33,8 +25,6 @@ class RegularContract extends Model 'contract_reduction', 'contract_periods', 'contract_periode', - 'enable_months', - 'printable_date', 'contract_taxid', 'billing_amount', 'contract_payment_day', @@ -49,10 +39,8 @@ class RegularContract extends Model 'settlement_transaction_id', 'contract_seal_issue', 'seal_reissue_request', - 'update_flag', 'contract_permission', 'contract_cancel_flag', - '800m_flag', 'tag_qr_flag', 'tag_change_flag', 'park_position', @@ -60,17 +48,61 @@ class RegularContract extends Model 'contract_manual', 'contract_notice', 'contract_payment_number', + 'created_at', + 'updated_at' ]; - /** - * 料金設定 - */ - public function price() + public static function search($inputs) { - return $this->belongsTo(PriceA::class, 'price_parkplaceid', 'price_parkplaceid'); + $list = self::query(); + // Sort + if ($inputs['sort']) { + $list->orderBy($inputs['sort'], $inputs['sort_type']); + } + if ($inputs['isExport']){ + $list = $list->get(); + }else{ + $list = $list->paginate(\App\Utils::item_per_page); // Utilsクラスの定数を使用 + } + return $list; } -} - + public static function getByPk($pk) + { + return self::find($pk); + } + + public static function deleteByPk($arr) + { + return self::whereIn('contract_id', $arr)->delete(); + } + + //TODO 定期契約ID not found in database specs + //TODO 解約/契約不可フラグ not found in database specs + public function userName() + { + return $this->belongsTo(\App\Models\User::class,'user_id','user_seq')->first(); + } + public function getUserType() + { + return $this->belongsTo(\App\Models\Usertype::class,'user_categoryid','user_categoryid')->first(); + } + public function getPark() + { + return $this->belongsTo(\App\Models\Park::class,'park_id','park_id')->first(); + } + public function getPrice() + { + return $this->belongsTo(\App\Models\Price::class,'price_parkplaceid','price_parkplaceid')->first(); + } +// public function getSettlement() +// { +// return $this->belongsTo(SettlementTransaction::class,'settlement_transaction_id','settlement_transaction_id')->first(); +// } + public function getOpe() + { + return $this->belongsTo(\App\Models\Ope::class,'ope_id','ope_id')->first(); + } +} \ No newline at end of file