SET @has_judul_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'judul_snapshot'
);
SET @sql_judul_snapshot := IF(
  @has_judul_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN judul_snapshot VARCHAR(255) NULL AFTER review_snapshot_json',
  'SELECT 1'
);
PREPARE stmt_judul_snapshot FROM @sql_judul_snapshot;
EXECUTE stmt_judul_snapshot;
DEALLOCATE PREPARE stmt_judul_snapshot;

SET @has_customer_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'customer_snapshot'
);
SET @sql_customer_snapshot := IF(
  @has_customer_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN customer_snapshot VARCHAR(255) NULL AFTER judul_snapshot',
  'SELECT 1'
);
PREPARE stmt_customer_snapshot FROM @sql_customer_snapshot;
EXECUTE stmt_customer_snapshot;
DEALLOCATE PREPARE stmt_customer_snapshot;

SET @has_tipe_hitung_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'tipe_hitung_snapshot'
);
SET @sql_tipe_hitung_snapshot := IF(
  @has_tipe_hitung_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN tipe_hitung_snapshot VARCHAR(40) NULL AFTER customer_snapshot',
  'SELECT 1'
);
PREPARE stmt_tipe_hitung_snapshot FROM @sql_tipe_hitung_snapshot;
EXECUTE stmt_tipe_hitung_snapshot;
DEALLOCATE PREPARE stmt_tipe_hitung_snapshot;

SET @has_ply_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'ply_snapshot'
);
SET @sql_ply_snapshot := IF(
  @has_ply_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN ply_snapshot INT UNSIGNED NULL AFTER tipe_hitung_snapshot',
  'SELECT 1'
);
PREPARE stmt_ply_snapshot FROM @sql_ply_snapshot;
EXECUTE stmt_ply_snapshot;
DEALLOCATE PREPARE stmt_ply_snapshot;

SET @has_warna_design_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'warna_design_snapshot'
);
SET @sql_warna_design_snapshot := IF(
  @has_warna_design_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN warna_design_snapshot INT UNSIGNED NULL AFTER ply_snapshot',
  'SELECT 1'
);
PREPARE stmt_warna_design_snapshot FROM @sql_warna_design_snapshot;
EXECUTE stmt_warna_design_snapshot;
DEALLOCATE PREPARE stmt_warna_design_snapshot;

SET @has_sheet_per_buku_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'sheet_per_buku_snapshot'
);
SET @sql_sheet_per_buku_snapshot := IF(
  @has_sheet_per_buku_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN sheet_per_buku_snapshot INT UNSIGNED NULL AFTER warna_design_snapshot',
  'SELECT 1'
);
PREPARE stmt_sheet_per_buku_snapshot FROM @sql_sheet_per_buku_snapshot;
EXECUTE stmt_sheet_per_buku_snapshot;
DEALLOCATE PREPARE stmt_sheet_per_buku_snapshot;

SET @has_isi_lembar_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'isi_lembar_snapshot'
);
SET @sql_isi_lembar_snapshot := IF(
  @has_isi_lembar_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN isi_lembar_snapshot INT UNSIGNED NULL AFTER sheet_per_buku_snapshot',
  'SELECT 1'
);
PREPARE stmt_isi_lembar_snapshot FROM @sql_isi_lembar_snapshot;
EXECUTE stmt_isi_lembar_snapshot;
DEALLOCATE PREPARE stmt_isi_lembar_snapshot;

SET @has_margin_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'margin_snapshot'
);
SET @sql_margin_snapshot := IF(
  @has_margin_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN margin_snapshot DECIMAL(10,2) NULL AFTER isi_lembar_snapshot',
  'SELECT 1'
);
PREPARE stmt_margin_snapshot FROM @sql_margin_snapshot;
EXECUTE stmt_margin_snapshot;
DEALLOCATE PREPARE stmt_margin_snapshot;

SET @has_top_color_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'top_color_snapshot'
);
SET @sql_top_color_snapshot := IF(
  @has_top_color_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN top_color_snapshot VARCHAR(120) NULL AFTER margin_snapshot',
  'SELECT 1'
);
PREPARE stmt_top_color_snapshot FROM @sql_top_color_snapshot;
EXECUTE stmt_top_color_snapshot;
DEALLOCATE PREPARE stmt_top_color_snapshot;

SET @has_bottom_color_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'bottom_color_snapshot'
);
SET @sql_bottom_color_snapshot := IF(
  @has_bottom_color_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN bottom_color_snapshot VARCHAR(120) NULL AFTER top_color_snapshot',
  'SELECT 1'
);
PREPARE stmt_bottom_color_snapshot FROM @sql_bottom_color_snapshot;
EXECUTE stmt_bottom_color_snapshot;
DEALLOCATE PREPARE stmt_bottom_color_snapshot;

SET @has_layer_configuration_snapshot_json := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'layer_configuration_snapshot_json'
);
SET @sql_layer_configuration_snapshot_json := IF(
  @has_layer_configuration_snapshot_json = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN layer_configuration_snapshot_json LONGTEXT NULL AFTER bottom_color_snapshot',
  'SELECT 1'
);
PREPARE stmt_layer_configuration_snapshot_json FROM @sql_layer_configuration_snapshot_json;
EXECUTE stmt_layer_configuration_snapshot_json;
DEALLOCATE PREPARE stmt_layer_configuration_snapshot_json;

SET @has_total_modal_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'total_modal_snapshot'
);
SET @sql_total_modal_snapshot := IF(
  @has_total_modal_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN total_modal_snapshot DECIMAL(15,2) NULL AFTER layer_configuration_snapshot_json',
  'SELECT 1'
);
PREPARE stmt_total_modal_snapshot FROM @sql_total_modal_snapshot;
EXECUTE stmt_total_modal_snapshot;
DEALLOCATE PREPARE stmt_total_modal_snapshot;

SET @has_jual_per_buku_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'jual_per_buku_snapshot'
);
SET @sql_jual_per_buku_snapshot := IF(
  @has_jual_per_buku_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN jual_per_buku_snapshot DECIMAL(15,4) NULL AFTER total_modal_snapshot',
  'SELECT 1'
);
PREPARE stmt_jual_per_buku_snapshot FROM @sql_jual_per_buku_snapshot;
EXECUTE stmt_jual_per_buku_snapshot;
DEALLOCATE PREPARE stmt_jual_per_buku_snapshot;

SET @has_minimum_cetak_snapshot := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'minimum_cetak_snapshot'
);
SET @sql_minimum_cetak_snapshot := IF(
  @has_minimum_cetak_snapshot = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN minimum_cetak_snapshot INT UNSIGNED NULL AFTER jual_per_buku_snapshot',
  'SELECT 1'
);
PREPARE stmt_minimum_cetak_snapshot FROM @sql_minimum_cetak_snapshot;
EXECUTE stmt_minimum_cetak_snapshot;
DEALLOCATE PREPARE stmt_minimum_cetak_snapshot;

SET @has_breakdown_cost_snapshot_json := (
  SELECT COUNT(*) FROM information_schema.columns
  WHERE table_schema = DATABASE() AND table_name = 'calc_nota_records' AND column_name = 'breakdown_cost_snapshot_json'
);
SET @sql_breakdown_cost_snapshot_json := IF(
  @has_breakdown_cost_snapshot_json = 0,
  'ALTER TABLE calc_nota_records ADD COLUMN breakdown_cost_snapshot_json LONGTEXT NULL AFTER minimum_cetak_snapshot',
  'SELECT 1'
);
PREPARE stmt_breakdown_cost_snapshot_json FROM @sql_breakdown_cost_snapshot_json;
EXECUTE stmt_breakdown_cost_snapshot_json;
DEALLOCATE PREPARE stmt_breakdown_cost_snapshot_json;
