@@ -10,6 +10,7 @@ class AddRefundSourcesAndPayouts extends Migration
|
||||
{
|
||||
$this->ensureRefundSourceColumns();
|
||||
$this->ensureRefundPayoutsTable();
|
||||
$this->ensureRefundPayoutSchoolYearColumn();
|
||||
$this->ensureRefundPayoutFingerprintColumns();
|
||||
$this->backfillRefundSources();
|
||||
$this->backfillLegacyPayouts();
|
||||
@@ -67,6 +68,7 @@ class AddRefundSourcesAndPayouts extends Migration
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
|
||||
'refund_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => false],
|
||||
'school_year' => ['type' => 'VARCHAR', 'constraint' => 9, 'null' => false],
|
||||
'amount_cents' => ['type' => 'INT', 'constraint' => 11, 'null' => false],
|
||||
'currency' => ['type' => 'CHAR', 'constraint' => 3, 'null' => false, 'default' => 'USD'],
|
||||
'payout_type' => ['type' => 'VARCHAR', 'constraint' => 30, 'null' => false, 'default' => 'cash_out'],
|
||||
@@ -94,6 +96,35 @@ class AddRefundSourcesAndPayouts extends Migration
|
||||
$this->forge->createTable('refund_payouts', true);
|
||||
}
|
||||
|
||||
private function ensureRefundPayoutSchoolYearColumn(): void
|
||||
{
|
||||
if (!$this->db->tableExists('refund_payouts')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->db->fieldExists('school_year', 'refund_payouts')) {
|
||||
$this->forge->addColumn('refund_payouts', [
|
||||
'school_year' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 9,
|
||||
'null' => true,
|
||||
'after' => 'refund_id',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->db->tableExists('refunds')) {
|
||||
$this->db->query(
|
||||
"UPDATE refund_payouts rp
|
||||
INNER JOIN refunds r ON r.id = rp.refund_id
|
||||
SET rp.school_year = r.school_year
|
||||
WHERE rp.school_year IS NULL OR TRIM(rp.school_year) = ''"
|
||||
);
|
||||
}
|
||||
|
||||
$this->db->query("ALTER TABLE refund_payouts MODIFY school_year VARCHAR(9) NOT NULL");
|
||||
}
|
||||
|
||||
private function ensureRefundPayoutFingerprintColumns(): void
|
||||
{
|
||||
if (!$this->db->tableExists('refund_payouts')) {
|
||||
@@ -161,7 +192,7 @@ class AddRefundSourcesAndPayouts extends Migration
|
||||
}
|
||||
|
||||
$refunds = $this->db->table('refunds')
|
||||
->select('id, refund_paid_amount, currency, refund_method, check_nbr, check_file, refunded_at, updated_by, created_at, updated_at')
|
||||
->select('id, refund_paid_amount, currency, refund_method, check_nbr, check_file, school_year, refunded_at, updated_by, created_at, updated_at')
|
||||
->where('refund_paid_amount >', 0)
|
||||
->get()
|
||||
->getResultArray();
|
||||
@@ -182,6 +213,7 @@ class AddRefundSourcesAndPayouts extends Migration
|
||||
|
||||
$this->db->table('refund_payouts')->insert([
|
||||
'refund_id' => $refundId,
|
||||
'school_year' => (string)($refund['school_year'] ?? ''),
|
||||
'amount_cents' => (int) round(((float) ($refund['refund_paid_amount'] ?? 0)) * 100),
|
||||
'currency' => (string) ($refund['currency'] ?? 'USD') ?: 'USD',
|
||||
'payout_type' => 'cash_out',
|
||||
|
||||
Reference in New Issue
Block a user