better method to compare dates, ignore future year for multiyear payments

This commit is contained in:
mischa 2023-01-03 13:46:44 +01:00
parent 7e05e83022
commit 49fb992d75
5 changed files with 14 additions and 11 deletions

View File

@ -32,7 +32,7 @@ my $function = $ARGV[0] || "empty";
my $function_variable = $ARGV[1] || "empty";
# define the prices for the different components of the VM
my $base_price = '60';
my $base_price = '64';
my %memory_prices = ('2G' => '10', '4G' => '30', '8G' => '70');
my %hdd_prices = ('50G' => '50', '100G' => '100', '150G' => '150', '200G' => '200');
@ -183,10 +183,13 @@ if ($function =~ /notify/) {
my $month = strftime("%m", localtime);
for my $vm_name (sort keys %vms) {
if ($vms{$vm_name}{'donated'} =~ /(done|expire|sponsor|renewal)/) { delete $vms{$vm_name}; next; }
if ($vms{$vm_name}{'date'} =~ /$year\//) { delete $vms{$vm_name}; next; }
if ($vms{$vm_name}{'date'} !~ /\/$month\//) { delete $vms{$vm_name}; next; }
my ($_vm_year, $_vm_month, $_vm_day) = split('/', $vms{$vm_name}{'date'});
if ($_vm_year >= $year) { delete $vms{$vm_name}; next; }
if ($_vm_month != $month) { delete $vms{$vm_name}; next; }
if ($function =~ /(renewal|deprovision)/) {
if (defined $vms{$vm_name}{'subscription'} and $vms{$vm_name}{'subscription'} =~ /yes/) { delete $vms{$vm_name}; next; }
if (defined $vms{$vm_name}{'subscription'} and $vms{$vm_name}{'subscription'} ne "") { delete $vms{$vm_name}; next; }
}
if ($function =~ /subscription/) {
if (!defined $vms{$vm_name}{'subscription'} or $vms{$vm_name}{'subscription'} eq "" or $vms{$vm_name}{'subscription'} =~ /no/) { delete $vms{$vm_name}; next; }

View File

@ -1,7 +1,7 @@
mac="fe:e1:ab:dd:73:a4"
ip="192.168.1.1"
owner="testuser1"
date="2018/12/02"
date="2018/01/02"
payment="70"
donated=""
name="Test1 User"

View File

@ -1,4 +1,4 @@
date="2018/07/02"
date="2018/02/02"
payment="70"
subscription=""
donated=""

View File

@ -1,4 +1,4 @@
date="2020/07/21"
date="2020/01/21"
payment="60"
subscription="yes"
donated=""

View File

@ -1,7 +1,7 @@
date="2020/07/21"
payment="60"
subscription="no"
donated=""
date="2024/01/21"
payment="sponsor"
subscription=""
donated="sponsor"
name="Test3"
email="vm03@high5.nl"
sshkey="ssh-ed25519 AAAAC3NzDI1NTE5AaaaIK7lMIQ4L4GcOyclKj9WLQPnHrGuP5ExjxZVmvLn"