diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php
index 2718eb1..4cdc486 100644
--- a/includes/Admin/Admin.php
+++ b/includes/Admin/Admin.php
@@ -1373,6 +1373,16 @@ class Admin {
+
+ |
+
+
+
+ |
+
|
|
diff --git a/includes/Repositories/CostRepository.php b/includes/Repositories/CostRepository.php
index 3c65246..a6fde31 100644
--- a/includes/Repositories/CostRepository.php
+++ b/includes/Repositories/CostRepository.php
@@ -93,11 +93,12 @@ class CostRepository extends AbstractRepository {
'distribution_type' => isset( $data['distribution_type'] ) ? $data['distribution_type'] : 'parcel',
'unit_amount' => isset( $data['unit_amount'] ) ? (float) $data['unit_amount'] : 0,
'total_cost' => (float) $data['total_cost'],
+ 'is_mandatory' => isset( $data['is_mandatory'] ) ? (int) (bool) $data['is_mandatory'] : 1,
'note' => $data['note'],
'updated_at' => $this->now(),
);
- $formats = array( '%d', '%s', '%s', '%f', '%f', '%s', '%s' );
+ $formats = array( '%d', '%s', '%s', '%f', '%f', '%d', '%s', '%s' );
$this->ensure_year( $payload['entry_year'] );
@@ -107,7 +108,7 @@ class CostRepository extends AbstractRepository {
}
$payload['created_at'] = $this->now();
- $this->wpdb->insert( $this->table, $payload, array( '%d', '%s', '%s', '%f', '%f', '%s', '%s', '%s' ) );
+ $this->wpdb->insert( $this->table, $payload, array( '%d', '%s', '%s', '%f', '%f', '%d', '%s', '%s', '%s' ) );
return $this->wpdb->insert_id;
}
diff --git a/includes/Schema.php b/includes/Schema.php
index 3925d2b..1d46e67 100644
--- a/includes/Schema.php
+++ b/includes/Schema.php
@@ -201,6 +201,7 @@ class Schema {
distribution_type VARCHAR(20) NOT NULL DEFAULT 'parcel',
unit_amount DECIMAL(12,2) NULL,
total_cost DECIMAL(12,2) NOT NULL DEFAULT 0.00,
+ is_mandatory TINYINT(1) NOT NULL DEFAULT 1,
note TEXT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
diff --git a/includes/Validator.php b/includes/Validator.php
index d4c9688..f0c1d02 100644
--- a/includes/Validator.php
+++ b/includes/Validator.php
@@ -259,6 +259,7 @@ class Validator {
$unit_amount = isset( $data['unit_amount'] ) ? str_replace( ',', '.', wp_unslash( $data['unit_amount'] ) ) : '';
$entry_year = $this->sanitize_cost_year( $data );
$distribution_type = sanitize_key( wp_unslash( isset( $data['distribution_type'] ) ? $data['distribution_type'] : 'parcel' ) );
+ $is_mandatory = isset( $data['is_mandatory'] ) ? (bool) $data['is_mandatory'] : true;
return array(
'entry_year' => $entry_year,
@@ -266,6 +267,7 @@ class Validator {
'distribution_type' => $distribution_type,
'unit_amount' => '' === trim( (string) $unit_amount ) ? '' : (float) $unit_amount,
'total_cost' => 0.0,
+ 'is_mandatory' => $is_mandatory,
'note' => sanitize_textarea_field( wp_unslash( isset( $data['note'] ) ? $data['note'] : '' ) ),
);
}