| @@ -0,0 +1,33 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\WebController; | |||||
| use Illuminate\Http\JsonResponse; | |||||
| use Illuminate\Http\Request; | |||||
| class ParkingCertificateOrderController extends WebController | |||||
| { | |||||
| public function name(): string | |||||
| { | |||||
| return "駐車証明証発行申請"; | |||||
| } | |||||
| public function description(): string | |||||
| { | |||||
| return "駐車証明証発行依頼を登録する"; | |||||
| } | |||||
| public function __construct(protected ParkingCertificateOrderParams $param) | |||||
| { | |||||
| parent::__construct(); | |||||
| $this->middleware('auth:sanctum'); | |||||
| } | |||||
| protected function run(Request $request): JsonResponse | |||||
| { | |||||
| return $this->successResponse(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,18 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\BaseParam; | |||||
| /** | |||||
| * @property string $seasonTicketContractRecordNo | |||||
| */ | |||||
| class ParkingCertificateOrderParams extends BaseParam | |||||
| { | |||||
| public function rules(): array | |||||
| { | |||||
| return [ | |||||
| 'season_ticket_contract_record_no' => $this->str(), | |||||
| ]; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,33 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\WebController; | |||||
| use Illuminate\Http\JsonResponse; | |||||
| use Illuminate\Http\Request; | |||||
| class StickerReOrderController extends WebController | |||||
| { | |||||
| public function name(): string | |||||
| { | |||||
| return "シール再発行依頼"; | |||||
| } | |||||
| public function description(): string | |||||
| { | |||||
| return "シール再発行依頼を登録する"; | |||||
| } | |||||
| public function __construct(protected StickerReOrderParams $param) | |||||
| { | |||||
| parent::__construct(); | |||||
| $this->middleware('auth:sanctum'); | |||||
| } | |||||
| protected function run(Request $request): JsonResponse | |||||
| { | |||||
| return $this->successResponse(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\BaseParam; | |||||
| use App\Kintone\Models\GeneralApplication; | |||||
| /** | |||||
| * @property string $seasonTicketContractRecordNo | |||||
| */ | |||||
| class StickerReOrderParams extends BaseParam | |||||
| { | |||||
| public function rules(): array | |||||
| { | |||||
| return [ | |||||
| 'season_ticket_contract_record_no' => $this->str(), | |||||
| ]; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,50 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\WebController; | |||||
| use App\Kintone\Models\Customer; | |||||
| use App\Kintone\Models\GeneralApplication; | |||||
| use App\Logic\GeneralApplicationManager; | |||||
| use Auth; | |||||
| use Illuminate\Http\JsonResponse; | |||||
| use Illuminate\Http\Request; | |||||
| class TerminationOrderController extends WebController | |||||
| { | |||||
| public function name(): string | |||||
| { | |||||
| return "定期契約解約申請"; | |||||
| } | |||||
| public function description(): string | |||||
| { | |||||
| return "定期契約解約依頼を登録する"; | |||||
| } | |||||
| public function __construct(protected TerminationOrderParams $param, private GeneralApplicationManager $manager) | |||||
| { | |||||
| parent::__construct(); | |||||
| $this->middleware('auth:sanctum'); | |||||
| } | |||||
| protected function run(Request $request): JsonResponse | |||||
| { | |||||
| $param = $this->param; | |||||
| $customer = Customer::getSelf(); | |||||
| $attr = [ | |||||
| GeneralApplication::FIELD_SEASON_TICKET_CONTRACT_RECORD_NO => $param->seasonTicketContractRecordNo, | |||||
| GeneralApplication::FIELD_TERMINATE_DATE => $param->date, | |||||
| GeneralApplication::FIELD_MEMO => $param->memo, | |||||
| ]; | |||||
| $this->manager->forTerminate($attr) | |||||
| ->setCustomer($customer) | |||||
| ->register(); | |||||
| return $this->successResponse(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\BaseParam; | |||||
| use App\Kintone\Models\DropDown\GeneralApplicationType; | |||||
| use Illuminate\Validation\Rules\Enum; | |||||
| /** | |||||
| * @property string $seasonTicketContractRecordNo | |||||
| * @property string $date | |||||
| * @property ?string $memo | |||||
| */ | |||||
| class TerminationOrderParams extends BaseParam | |||||
| { | |||||
| public function rules(): array | |||||
| { | |||||
| return [ | |||||
| 'season_ticket_contract_record_no' => $this->str(), | |||||
| 'date' => $this->date(), | |||||
| 'memo' => $this->str(true), | |||||
| ]; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,33 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\WebController; | |||||
| use Illuminate\Http\JsonResponse; | |||||
| use Illuminate\Http\Request; | |||||
| class UpdateVehicleInfoOrderController extends WebController | |||||
| { | |||||
| public function name(): string | |||||
| { | |||||
| return "車両情報変更申請"; | |||||
| } | |||||
| public function description(): string | |||||
| { | |||||
| return "車両情報変更依頼を登録する"; | |||||
| } | |||||
| public function __construct(protected UpdateVehicleInfoOrderParams $param) | |||||
| { | |||||
| parent::__construct(); | |||||
| $this->middleware('auth:sanctum'); | |||||
| } | |||||
| protected function run(Request $request): JsonResponse | |||||
| { | |||||
| return $this->successResponse(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,18 @@ | |||||
| <?php | |||||
| namespace App\Http\Controllers\Web\SeasonTicketContract; | |||||
| use App\Http\Controllers\Web\BaseParam; | |||||
| /** | |||||
| * @property string $seasonTicketContractRecordNo | |||||
| */ | |||||
| class UpdateVehicleInfoOrderParams extends BaseParam | |||||
| { | |||||
| public function rules(): array | |||||
| { | |||||
| return [ | |||||
| 'season_ticket_contract_record_no' => $this->str(), | |||||
| ]; | |||||
| } | |||||
| } | |||||
| @@ -185,17 +185,21 @@ class KintoneAccess | |||||
| */ | */ | ||||
| public function create(KintoneModel &$model) | public function create(KintoneModel &$model) | ||||
| { | { | ||||
| $response = Http::withHeaders([ | |||||
| "X-Cybozu-API-Token" => $this->apiToken, | |||||
| ])->post($this->getRecordUrl(), [ | |||||
| $sendData = [ | |||||
| "app" => $this->appId, | "app" => $this->appId, | ||||
| "record" => $model->getApiLayout(), | "record" => $model->getApiLayout(), | ||||
| ]); | |||||
| ]; | |||||
| $response = Http::withHeaders([ | |||||
| "X-Cybozu-API-Token" => $this->apiToken, | |||||
| ])->post($this->getRecordUrl(), $sendData); | |||||
| if ($response->failed()) { | if ($response->failed()) { | ||||
| $e = $response->toException(); | $e = $response->toException(); | ||||
| if ($e instanceof Exception) { | if ($e instanceof Exception) { | ||||
| Log::error($e->getMessage()); | Log::error($e->getMessage()); | ||||
| Log::error($response->body()); | |||||
| Log::error($sendData); | |||||
| throw $e; | throw $e; | ||||
| } | } | ||||
| } | } | ||||
| @@ -2,6 +2,8 @@ | |||||
| namespace App\Kintone\Models; | namespace App\Kintone\Models; | ||||
| use Illuminate\Support\Facades\Auth; | |||||
| /** | /** | ||||
| * アプリ名 顧客マスタ | * アプリ名 顧客マスタ | ||||
| */ | */ | ||||
| @@ -11,13 +13,17 @@ class Customer extends KintoneModel | |||||
| const FIELD_CUSTOMER_CODE = "CustomerCode"; | const FIELD_CUSTOMER_CODE = "CustomerCode"; | ||||
| const FIELD_CUSTOMER_NAME = "CustomerName"; | const FIELD_CUSTOMER_NAME = "CustomerName"; | ||||
| const FIELD_CUSTOMER_NAME_KANA = "顧客名カナ"; | |||||
| const FIELD_EMAIL = "メールアドレス"; | const FIELD_EMAIL = "メールアドレス"; | ||||
| const FIELD_PHONE_NUMBER = "電話番号"; | |||||
| protected const FIELDS = [ | protected const FIELDS = [ | ||||
| ...parent::FIELDS, | ...parent::FIELDS, | ||||
| self::FIELD_CUSTOMER_CODE => FieldType::NUMBER, | self::FIELD_CUSTOMER_CODE => FieldType::NUMBER, | ||||
| self::FIELD_CUSTOMER_NAME => FieldType::SINGLE_LINE_TEXT, | self::FIELD_CUSTOMER_NAME => FieldType::SINGLE_LINE_TEXT, | ||||
| self::FIELD_CUSTOMER_NAME_KANA => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_EMAIL => FieldType::LINK, | self::FIELD_EMAIL => FieldType::LINK, | ||||
| self::FIELD_PHONE_NUMBER => FieldType::LINK, | |||||
| ]; | ]; | ||||
| protected const FIELD_NAMES = [ | protected const FIELD_NAMES = [ | ||||
| @@ -25,4 +31,9 @@ class Customer extends KintoneModel | |||||
| self::FIELD_CUSTOMER_NAME => 'customer_name', | self::FIELD_CUSTOMER_NAME => 'customer_name', | ||||
| self::FIELD_EMAIL => 'email', | self::FIELD_EMAIL => 'email', | ||||
| ]; | ]; | ||||
| public static function getSelf(): static | |||||
| { | |||||
| return static::getAccess()->find(Auth::user()->kintone_id); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,44 @@ | |||||
| <?php | |||||
| namespace App\Kintone\Models; | |||||
| /** | |||||
| * アプリ名 各種申請 | |||||
| */ | |||||
| class GeneralApplication extends KintoneModel | |||||
| { | |||||
| const CONFIG_KEY = "KINTONE_APP_GENERAL_APPLICATION"; | |||||
| const FIELD_APPLICATION_TYPE = "申込内容"; | |||||
| const FIELD_APPLICATIONJ_STATUS = "status"; | |||||
| const FIELD_SEASON_TICKET_CONTRACT_RECORD_NO = "契約番号"; | |||||
| const FIELD_CUSTOMER_NAME = "氏名"; | |||||
| const FIELD_CUSTOMER_NAME_KANA = "フリガナ"; | |||||
| const FIELD_CUSTOMER_EMAIL = "メールアドレス"; | |||||
| const FIELD_CUSTOMER_PHONE_NUMBER = "電話番号"; | |||||
| const FIELD_TERMINATE_DATE = "解約希望日"; | |||||
| const FIELD_VEHICLE_NO = "変更後車両番号"; | |||||
| const FIELD_REGISTER_NO = "変更後防犯登録番号"; | |||||
| const FIELD_MEMO = "備考"; | |||||
| const FIELD_APPLICATION_DATETIME = "受付日時"; | |||||
| protected const FIELDS = [ | |||||
| ...parent::FIELDS, | |||||
| self::FIELD_APPLICATION_TYPE => FieldType::DROP_DOWN, | |||||
| self::FIELD_APPLICATIONJ_STATUS => FieldType::DROP_DOWN, | |||||
| self::FIELD_SEASON_TICKET_CONTRACT_RECORD_NO => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_CUSTOMER_NAME => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_CUSTOMER_NAME_KANA => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_CUSTOMER_EMAIL => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_CUSTOMER_PHONE_NUMBER => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_TERMINATE_DATE => FieldType::DATE, | |||||
| self::FIELD_VEHICLE_NO => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_REGISTER_NO => FieldType::SINGLE_LINE_TEXT, | |||||
| self::FIELD_MEMO => FieldType::MULTI_LINE_TEXT, | |||||
| self::FIELD_APPLICATION_DATETIME => FieldType::DATETIME, | |||||
| ]; | |||||
| protected const FIELD_NAMES = [ | |||||
| ...parent::FIELD_NAMES, | |||||
| ]; | |||||
| } | |||||
| @@ -118,8 +118,7 @@ abstract class KintoneModel | |||||
| private function setData(string $path, FieldType $type, $value) | private function setData(string $path, FieldType $type, $value) | ||||
| { | { | ||||
| data_set($this->data, $path, $value); | |||||
| return $this; | return $this; | ||||
| // if ( | // if ( | ||||
| @@ -224,7 +223,18 @@ abstract class KintoneModel | |||||
| $path = sprintf("%s.value", $fieldCode); | $path = sprintf("%s.value", $fieldCode); | ||||
| if ($type === FieldType::DATETIME) { | if ($type === FieldType::DATETIME) { | ||||
| data_set($ret, $path, $this->getDate($fieldCode)->toIso8601ZuluString()); | |||||
| $data = $this->getDate($fieldCode); | |||||
| if ($data) { | |||||
| data_set($ret, $path, $data->toIso8601ZuluString()); | |||||
| } | |||||
| continue; | |||||
| } | |||||
| if ($type === FieldType::DATE) { | |||||
| $data = $this->getDate($fieldCode); | |||||
| if ($data) { | |||||
| data_set($ret, $path, $data->format("Y-m-d")); | |||||
| data_set($ret, $path, $data->toDateString()); | |||||
| } | |||||
| continue; | continue; | ||||
| } | } | ||||
| data_set($ret, $path, data_get($this->data, $fieldCode)); | data_set($ret, $path, data_get($this->data, $fieldCode)); | ||||
| @@ -235,7 +245,6 @@ abstract class KintoneModel | |||||
| public function get(string $key) | public function get(string $key) | ||||
| { | { | ||||
| $a = json_decode(json_encode($this->data), true); | |||||
| return data_get($this->data, $key); | return data_get($this->data, $key); | ||||
| } | } | ||||
| @@ -259,6 +268,11 @@ abstract class KintoneModel | |||||
| return $this->get($key); | return $this->get($key); | ||||
| } | } | ||||
| public function setRecordId(string $id): static | |||||
| { | |||||
| $this->recordId = $id; | |||||
| return $this; | |||||
| } | |||||
| public function getRecordId(): ?string | public function getRecordId(): ?string | ||||
| { | { | ||||
| return $this->recordId; | return $this->recordId; | ||||
| @@ -1,27 +0,0 @@ | |||||
| <?php | |||||
| namespace App\Kintone\Models; | |||||
| class Small extends KintoneModel | |||||
| { | |||||
| const FIELD_NAME = "名前"; | |||||
| const FIELD_AGE = "年齢"; | |||||
| protected array $fields = [ | |||||
| self::FIELD_NAME => FieldType::STRING, | |||||
| self::FIELD_AGE => FieldType::STRING, | |||||
| ]; | |||||
| protected function setModelData(array $data): bool | |||||
| { | |||||
| return true; | |||||
| } | |||||
| protected function toArrayModel(): array | |||||
| { | |||||
| return []; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,81 @@ | |||||
| <?php | |||||
| namespace App\Logic; | |||||
| use App\Features\InstanceAble; | |||||
| use App\Kintone\Models\Customer; | |||||
| use App\Kintone\Models\GeneralApplication; | |||||
| use App\Util\DateUtil; | |||||
| use Illuminate\Support\Carbon; | |||||
| use LogicException; | |||||
| class GeneralApplicationManager | |||||
| { | |||||
| use InstanceAble; | |||||
| private Customer|null $customer = null; | |||||
| public function __construct(private GeneralApplication $model) | |||||
| { | |||||
| } | |||||
| public function setCustomer(Customer $customer): static | |||||
| { | |||||
| $this->customer = $customer; | |||||
| return $this; | |||||
| } | |||||
| public function forTerminate(array $attr): static | |||||
| { | |||||
| $terminateDate = data_get($attr, GeneralApplication::FIELD_TERMINATE_DATE); | |||||
| if (!($terminateDate instanceof Carbon)) throw new LogicException("解約予定日不正"); | |||||
| $this->model->set(GeneralApplication::FIELD_TERMINATE_DATE, $terminateDate); | |||||
| return $this->setType("解約申請") | |||||
| ->setMemo($attr); | |||||
| } | |||||
| public function forParkingCertificate(array $attr = []): static | |||||
| { | |||||
| return $this->setType("車庫証明発行申請") | |||||
| ->setMemo($attr); | |||||
| } | |||||
| public function register() | |||||
| { | |||||
| if ($this->customer === null) { | |||||
| throw new LogicException("顧客NULL"); | |||||
| } | |||||
| if (!$this->model->getStr(GeneralApplication::FIELD_APPLICATION_TYPE)) { | |||||
| throw new LogicException("申請タイプ未設定"); | |||||
| } | |||||
| $this->model->set(GeneralApplication::FIELD_APPLICATION_DATETIME, DateUtil::now()); | |||||
| $this->model->set(GeneralApplication::FIELD_APPLICATIONJ_STATUS, "申込"); | |||||
| $this->model->set(GeneralApplication::FIELD_CUSTOMER_EMAIL, $this->customer->get(Customer::FIELD_EMAIL)); | |||||
| $this->model->set(GeneralApplication::FIELD_CUSTOMER_NAME, $this->customer->get(Customer::FIELD_CUSTOMER_NAME)); | |||||
| $this->model->set(GeneralApplication::FIELD_CUSTOMER_NAME_KANA, $this->customer->get(Customer::FIELD_CUSTOMER_NAME_KANA)); | |||||
| $this->model->set(GeneralApplication::FIELD_CUSTOMER_PHONE_NUMBER, $this->customer->get(Customer::FIELD_PHONE_NUMBER)); | |||||
| $access = $this->model->getAccess(); | |||||
| $access->create($this->model); | |||||
| } | |||||
| private function setType(string $type): static | |||||
| { | |||||
| $this->model->set(GeneralApplication::FIELD_APPLICATION_TYPE, $type); | |||||
| return $this; | |||||
| } | |||||
| private function setMemo(array $attr): static | |||||
| { | |||||
| $memo = data_get($attr, GeneralApplication::FIELD_MEMO); | |||||
| if ($memo) { | |||||
| $this->model->set(GeneralApplication::FIELD_MEMO, $memo); | |||||
| } | |||||
| return $this; | |||||
| } | |||||
| } | |||||
| @@ -30,6 +30,7 @@ return [ | |||||
| ...App\Kintone\Models\ParkingRoom::setConfig(), | ...App\Kintone\Models\ParkingRoom::setConfig(), | ||||
| ...App\Kintone\Models\SeasonTicketContract::setConfig(), | ...App\Kintone\Models\SeasonTicketContract::setConfig(), | ||||
| ...App\Kintone\Models\PaymentPlan::setConfig(), | ...App\Kintone\Models\PaymentPlan::setConfig(), | ||||
| ...App\Kintone\Models\GeneralApplication::setConfig(), | |||||
| ], | ], | ||||
| ]; | ]; | ||||
| @@ -20,3 +20,7 @@ RouteHelper::get('/me', App\Http\Controllers\Web\Auth\MeController::class); | |||||
| RouteHelper::get('/season-ticket-contracts', App\Http\Controllers\Web\SeasonTicketContract\SeasonTicketContractsController::class); | RouteHelper::get('/season-ticket-contracts', App\Http\Controllers\Web\SeasonTicketContract\SeasonTicketContractsController::class); | ||||
| RouteHelper::get('/season-ticket-contract/payment-plans', App\Http\Controllers\Web\SeasonTicketContract\PaymentPlansController::class); | RouteHelper::get('/season-ticket-contract/payment-plans', App\Http\Controllers\Web\SeasonTicketContract\PaymentPlansController::class); | ||||
| RouteHelper::post('/season-ticket-contract/sticker-re-order', App\Http\Controllers\Web\SeasonTicketContract\StickerReOrderController::class); | |||||
| RouteHelper::post('/season-ticket-contract/parking-certificate-order', App\Http\Controllers\Web\SeasonTicketContract\ParkingCertificateOrderController::class); | |||||
| RouteHelper::post('/season-ticket-contract/termination-order', App\Http\Controllers\Web\SeasonTicketContract\TerminationOrderController::class); | |||||
| RouteHelper::post('/season-ticket-contract/update-vehicle-info-order', App\Http\Controllers\Web\SeasonTicketContract\UpdateVehicleInfoOrderController::class); | |||||
| @@ -0,0 +1,31 @@ | |||||
| <?php | |||||
| namespace Tests\Feature\Logic; | |||||
| use App\Kintone\Models\Customer; | |||||
| use App\Kintone\Models\GeneralApplication; | |||||
| use App\Logic\GeneralApplicationManager; | |||||
| use App\Util\DateUtil; | |||||
| use Tests\TestCase; | |||||
| class GeneralApplicationManagerTest extends TestCase | |||||
| { | |||||
| public function test_terminate(): void | |||||
| { | |||||
| $customer = Customer::getAccess()->find(8689); | |||||
| $manager = GeneralApplicationManager::instance(); | |||||
| $attr = [ | |||||
| GeneralApplication::FIELD_TERMINATE_DATE => DateUtil::parse("2050/12/31"), | |||||
| GeneralApplication::FIELD_MEMO => "test data\nです", | |||||
| ]; | |||||
| $manager->forTerminate($attr) | |||||
| ->setCustomer($customer) | |||||
| ->register(); | |||||
| $this->assertTrue(true); | |||||
| } | |||||
| } | |||||