| @@ -10,6 +10,7 @@ use App\Exceptions\ExclusiveException; | |||||
| use App\Features\InstanceAble; | use App\Features\InstanceAble; | ||||
| use App\Features\LoginUser; | use App\Features\LoginUser; | ||||
| use App\Models\ReceiptIssuingOrder; | use App\Models\ReceiptIssuingOrder; | ||||
| use App\Models\ReceiptIssuingOrderSeqNumber; | |||||
| use App\Models\User; | use App\Models\User; | ||||
| use App\Util\DateUtil; | use App\Util\DateUtil; | ||||
| use Illuminate\Support\Carbon; | use Illuminate\Support\Carbon; | ||||
| @@ -200,10 +201,29 @@ abstract class ReceiptIssuingOrderManager | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function fillSeqNumber(): static | |||||
| { | |||||
| if ($this->order->seq_number !== null) { | |||||
| return $this; | |||||
| } | |||||
| $seq = ReceiptIssuingOrderSeqNumber::lockForUpdate()->first(); | |||||
| if (!($seq instanceof ReceiptIssuingOrderSeqNumber)) { | |||||
| throw new AppCommonException("通番取得失敗"); | |||||
| } | |||||
| $seq->seq_number++; | |||||
| $this->order->seq_number = $seq->seq_number; | |||||
| $seq->save(); | |||||
| return $this; | |||||
| } | |||||
| protected function save(): static | protected function save(): static | ||||
| { | { | ||||
| $this->setStatus() | $this->setStatus() | ||||
| ->updateCheck(); | |||||
| ->updateCheck() | |||||
| ->fillSeqNumber(); | |||||
| $this->order->save(); | $this->order->save(); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| @@ -55,6 +55,7 @@ class ReceiptIssuingOrder extends AppModel | |||||
| const COL_NAME_ACCEPT_PRIVACY_POLICY = "accept_privacy_policy"; | const COL_NAME_ACCEPT_PRIVACY_POLICY = "accept_privacy_policy"; | ||||
| const COL_NAME_ACCEPT_CORRECT_ENTRY = "accept_correct_entry"; | const COL_NAME_ACCEPT_CORRECT_ENTRY = "accept_correct_entry"; | ||||
| const COL_NAME_ACCEPT_SITE_POLICY = "accept_site_policy"; | const COL_NAME_ACCEPT_SITE_POLICY = "accept_site_policy"; | ||||
| const COL_NAME_SEQ_NUMBER = "seq_number"; | |||||
| protected $casts = [ | protected $casts = [ | ||||
| self::COL_NAME_ORDER_DATETIME => 'datetime', | self::COL_NAME_ORDER_DATETIME => 'datetime', | ||||
| @@ -0,0 +1,21 @@ | |||||
| <?php | |||||
| namespace App\Models; | |||||
| class ReceiptIssuingOrderSeqNumber extends AppModel | |||||
| { | |||||
| const COL_NAME_CONTRACT_ID = ColumnName::CONTRACT_ID; | |||||
| const COL_NAME_SEQ_NUMBER = "seq_number"; | |||||
| public function getModelName(): string | |||||
| { | |||||
| return "領収証発行依頼通番管理"; | |||||
| } | |||||
| public function getHistory(): ?HistoryModel | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,38 @@ | |||||
| <?php | |||||
| use Illuminate\Database\Migrations\Migration; | |||||
| use Illuminate\Database\Schema\Blueprint; | |||||
| use Illuminate\Support\Facades\Schema; | |||||
| return new class extends Migration | |||||
| { | |||||
| /** | |||||
| * Run the migrations. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function up() | |||||
| { | |||||
| Schema::table('receipt_issuing_orders', function (Blueprint $table) { | |||||
| $table->bigInteger("seq_number", false, true)->nullable()->comment("通番"); | |||||
| }); | |||||
| Schema::table('receipt_issuing_order_histories', function (Blueprint $table) { | |||||
| $table->bigInteger("seq_number", false, true)->nullable()->comment("通番"); | |||||
| }); | |||||
| } | |||||
| /** | |||||
| * Reverse the migrations. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function down() | |||||
| { | |||||
| Schema::table('receipt_issuing_orders', function (Blueprint $table) { | |||||
| $table->dropColumn("seq_number"); | |||||
| }); | |||||
| Schema::table('receipt_issuing_order_histories', function (Blueprint $table) { | |||||
| $table->dropColumn("seq_number"); | |||||
| }); | |||||
| } | |||||
| }; | |||||
| @@ -0,0 +1,43 @@ | |||||
| <?php | |||||
| use App\Models\ReceiptIssuingOrderSeqNumber; | |||||
| use App\Util\MigrationHelper; | |||||
| use Illuminate\Database\Migrations\Migration; | |||||
| use Illuminate\Database\Schema\Blueprint; | |||||
| use Illuminate\Support\Facades\Schema; | |||||
| return new class extends Migration | |||||
| { | |||||
| /** | |||||
| * Run the migrations. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function up() | |||||
| { | |||||
| MigrationHelper::createTable('receipt_issuing_order_seq_numbers', $this->schema()); | |||||
| ReceiptIssuingOrderSeqNumber::create([ | |||||
| ReceiptIssuingOrderSeqNumber::COL_NAME_SEQ_NUMBER => 0, | |||||
| ]); | |||||
| } | |||||
| /** | |||||
| * Reverse the migrations. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function down() | |||||
| { | |||||
| Schema::dropIfExists('receipt_issuing_order_seq_numbers'); | |||||
| } | |||||
| private function schema() | |||||
| { | |||||
| return function (Blueprint $table, MigrationHelper $helper) { | |||||
| $helper->baseColumn(); | |||||
| $table->string('seq_number')->comment("通番"); | |||||
| }; | |||||
| } | |||||
| }; | |||||