App-GnuCash-MembershipUtils
view release on metacpan or search on metacpan
bin/gc-members-generate-invoices view on Meta::CPAN
}
my $schema;
($error, $schema) = open_gnucash(get_gnucash_filename($gOptions{file}, $config));
if ($error) {
printf STDERR "Error opening GnuCash file: %s\n", $error;
exit(1);
}
my $warning;
($error, $warning) = validate_accounts_in_config({
schema => $schema,
config => $config,
});
say STDERR $warning if ($warning);
if ($error) {
say STDERR $error;
exit(1);
}
my @members = get_all_members({
bin/gc-members-list view on Meta::CPAN
}
my $schema;
($error, $schema) = open_gnucash(get_gnucash_filename($gOptions{file}, $config));
if ($error) {
printf STDERR "Error opening GnuCahs file: %s\n", $error;
exit(1);
}
my $warning;
($error, $warning) = validate_accounts_in_config({
schema => $schema,
config => $config,
});
say STDERR $warning if ($warning);
if ($error) {
say STDERR $error;
exit(1);
}
lib/App/GnuCash/MembershipUtils.pm view on Meta::CPAN
use Carp qw( carp );
our @EXPORT_OK = qw(
db_accounts_to_hash
get_all_members
get_config
get_gnucash_filename
max_length
open_gnucash
title_case
validate_accounts_in_config
);
our %EXPORT_TAGS = (
all => [ @EXPORT_OK ],
config => [ qw(
get_config
get_gnucash_filename
validate_accounts_in_config
)],
db => [ qw(
db_accounts_to_hash
get_all_members
open_gnucash
)],
other => [qw(
max_length
title_case
)],
lib/App/GnuCash/MembershipUtils.pm view on Meta::CPAN
return ("filename '$filename' does not exist", undef) unless -f $filename;
$YAML::XS::ForbidDuplicateKeys = 1;
my $config = Load(scalar(read_file($filename)));
my @errors;
# Now we have a hash, let's make sure it has what we need
if (exists($config->{MembershipTypes})) {
if (exists($config->{MembershipTypes}{default})) {
my $error = _validate_membership_type_config($config->{MembershipTypes}{default}, 1);
if ($error) {
push(@errors, "The 'MembershipTypes.default' section $error");
}
if (my $others = $config->{MembershipTypes}{others}) {
my $idx;
for my $type (@$others) {
$idx++;
if (my $error = _validate_membership_type_config($type)) {
push(@errors, "The 'MembershipTypes.others' entry $idx $error");
}
}
}
} else {
push(@errors, "Missing 'MembershipTypes.default' section");
}
} else {
push(@errors, "Missing 'MembershipTypes' section");
}
lib/App/GnuCash/MembershipUtils.pm view on Meta::CPAN
);
while (my $account = $rs->next) {
my $full_name = $account->complete_name;
$accounts{$full_name} = { $account->get_columns };
}
return \%accounts;
}
=head2 validate_accounts_in_config($args)
my ($errors, $warnings) = validate_accounts_in_config($args);
warn $warnings if ($warnings);
die $errors if ($errors);
Accepts a HASHREF of C<$args> whose keys are as follows:
=over
=item config
=item schema
=back
Returns C<$errors> which is a string indicating fatal errors, and
C<$warnings> which is a non-fatal error.
=cut
sub validate_accounts_in_config {
my $args = shift;
my $schema = delete $args->{schema};
my $config = delete $args->{config};
my $debug = delete $args->{debug} // 0;
my $accounts = db_accounts_to_hash($schema);
my @errors;
my @warnings;
if (exists($config->{GnuCash})) {
my $config_account = $config->{GnuCash}{account};
lib/App/GnuCash/MembershipUtils.pm view on Meta::CPAN
);
}
} else {
_error_invalid_account(\@errors, "'GnuCash.account'");
}
} else {
push(@errors, "Missing 'GnuCash' section");
}
if (exists($config->{MembershipTypes})) {
if (exists($config->{MembershipTypes}{default})) {
my $error = _validate_membership_type_config($config->{MembershipTypes}{default}, 1);
if ($error) {
push(@errors, "The 'MembershipTypes.default' section $error");
} else {
my $config_account = $config->{MembershipTypes}{default}{account};
if (my $gc_account = $accounts->{$config_account}) {
if ($gc_account->{account_type} ne $EXPECTED_ITEM_ACCOUNT_TYPE) {
_warning_account_type(
\@warnings,
"'MembershipTypes.default.account'",
$gc_account,,
lib/App/GnuCash/MembershipUtils.pm view on Meta::CPAN
push(
@$errors,
sprintf(
"The %s account could not be found.",
$section,
)
);
}
sub _validate_membership_type_config {
my $config = shift // {};
my $default_type = shift // 0;
my @required_keys = qw( account amount name );
push(@required_keys, qw( match )) unless $default_type;
my @missing;
my $invalid_amount;
for my $key (@required_keys) {
if (exists($config->{$key}) && defined($config->{$key})) {
if ($key eq 'amount') {
( run in 1.683 second using v1.01-cache-2.11-cpan-beeb90c9504 )