EekBoek

 view release on metacpan or  search on metacpan

lib/EB/Tools/Schema.pm  view on Meta::CPAN

			last;
		    }
		}

		$btw_type .= "-" unless $btw_inex;
	    }
	    elsif ( $extra =~ m/$km{koppeling}=(\S+)/i ) {
		my $t = _xtr("scm:std:$1");
		error(__x("Rekening {id}: onbekende koppeling \"{std}\"",
			  id => $id, std => $1)."\n")
		  unless exists($std{$t});
		error(__x("Rekening {id}: extra koppeling voor \"{std}\"",
			  id => $id, std => $1)."\n")
		  if $std{$t};
		$std{$t} = $id;
	    }
	}
	if ( $btw_type ne 'n' ) {
	    error(__x("Rekening {id}: BTW koppeling '{ko}' met een {acc} is niet toegestaan",
		      id => $id, ko => ($km{omzet}, $km{kosten})[$btw_ko],
		      acc => ($km{omzetrekening}, $km{kostenrekening})[$kstomz])."\n")
	      if !$balres && defined($kstomz) && defined($btw_ko) && $btw_ko != $kstomz;
	    error(__x("Rekening {id}: BTW koppeling met neutrale resultaatrekening is niet toegestaan",
		      id => $id)."\n") unless defined($kstomz) || defined($btw_ko);
	    error(__x("Rekening {id}: BTW koppeling met een balansrekening vereist kosten/omzet specificatie",
		      id => $id)."\n")
	      if $balres && !defined($btw_ko);
	}
	$desc =~ s/\s+$//;
	$kstomz = $btw_ko unless defined($kstomz);
	$acc{$id} = [ $desc, $cvdi, $balres, $debcrd, $kstomz, $btw_type, $dcfixed ];
	1;
    }
    else {
	0;
    }
}

sub scan_balans {
    unshift(@_, 1);
    goto &scan_balres;
}

sub scan_result {
    unshift(@_, 0);
    goto &scan_balres;
}

sub scan_ignore { 1 }

sub load_schema1 {
    my ($rl) = shift;

    init_vars();
    my $scanner;		# current scanner

    %std = map { $_ => 0 }
      qw(btw_ok btw_vh winst crd deb btw_il btw_vl btw_ih btw_vp btw_ip btw_va btw_ia);
    while ( $_ = $rl->() ) {
	if ( /^\# \s*
	      content-type: \s*
              text (?: \s* \/ \s* plain)? \s* ; \s*
              charset \s* = \s* (\S+) \s* $/ix ) {
	    my $charset = lc($1);
	    if ( $charset =~ /^(?:utf-?8)$/i ) {
		next;
	    }
	    error(_T("Invoer moet Unicode (UTF-8) zijn.")."\n");
	}

	my $s = "".$_;
	eval {
	    $_ = decode('utf8', $s, 1);
	};
	if ( $@ ) {
	    warn("?".__x("Geen geldige UTF-8 tekens in regel {line} van de invoer",
			 line => $.)."\n".$s."\n");
	    warn($@);
	    $fail++;
	    next;
	}

	next if /^\s*#/;
	next unless /\S/;

	# Scanner selectie.
	if ( /^($km{balans}|$km{hdr_balans})/i ) {
	    $scanner = \&scan_ignore;
	    next;
	}
	if ( /^($km{result}|$km{hdr_resultaat})/i ) {
	    $scanner = \&scan_ignore;
	    next;
	}
	if ( /^($km{dagboeken}|$km{hdr_dagboeken})/i ) {
	    $scanner = \&scan_ignore;
	    next;
	}
	if ( /^$km{hdr_btwtarieven}/i ) {
	    $scanner = \&scan_btw;
	    next;
	}

	# Overige settings.
	if ( /^$km{hdr_verdichting}\s+(\d+)\s+(\d+)/i && $1 < $2 ) {
	    next;
	}

	# Anders: Scan.
	if ( $scanner ) {
	    chomp;
	    $scanner->() or
	      error(__x("Ongeldige invoer in schema bestand, regel {lno}:\n{line}",
			line => $_, lno => $.)."\n");
	    next;
	}

	error(__x("Ongeldige invoer in schema bestand, regel {lno}:\n{line}",
		  line => $_, lno => $.)."\n");

    }

    if ( @btw && !defined $btwmap{n} ) {
	$btw[0] = [ 0,  undef, _T("BTW 0%"), BTWTARIEF_NUL, 0, 1 ];
	$btwmap{n} = 0;
    }

}

sub load_schema2 {
    my ($rl) = shift;

    my $scanner;		# current scanner
    $max_hvd = 9;
    $max_vrd = 99;

    while ( $_ = $rl->() ) {
	if ( /^\# \s*
	      content-type: \s*
              text (?: \s* \/ \s* plain)? \s* ; \s*
              charset \s* = \s* (\S+) \s* $/ix ) {
	    my $charset = lc($1);
	    if ( $charset =~ /^(?:utf-?8)$/i ) {
		next;
	    }
	    error(_T("Invoer moet Unicode (UTF-8) zijn.")."\n");
	}

	my $s = "".$_;
	eval {
	    $_ = decode('utf8', $s, 1);
	};
	if ( $@ ) {
	    warn("?".__x("Geen geldige UTF-8 tekens in regel {line} van de invoer",
			 line => $.)."\n".$s."\n");
	    warn($@);
	    $fail++;
	    next;
	}

	next if /^\s*#/;
	next unless /\S/;

	# Scanner selectie.
	if ( /^($km{balans}|$km{hdr_balans})/i ) {
	    $scanner = \&scan_balans;
	    next;
	}
	if ( /^($km{result}|$km{hdr_resultaat})/i ) {
	    $scanner = \&scan_result;
	    next;
	}
	if ( /^($km{dagboeken}|$km{hdr_dagboeken})/i ) {
	    $scanner = \&scan_dagboeken;
	    next;
	}
	if ( /^$km{hdr_btwtarieven}/i ) {
	    $scanner = \&scan_ignore;
	    next;
	}

	# Overige settings.
	if ( /^$km{hdr_verdichting}\s+(\d+)\s+(\d+)/i && $1 < $2 ) {
	    $max_hvd = $1;
	    $max_vrd = $2;
	    next;
	}

	# Anders: Scan.
	if ( $scanner ) {
	    chomp;
	    $scanner->() or
	      error(__x("Ongeldige invoer in schema bestand, regel {lno}:\n{line}",
			line => $_, lno => $.)."\n");
	    next;
	}

	error(__x("Ongeldige invoer in schema bestand, regel {lno}:\n{line}",
		  line => $_, lno => $.)."\n");



( run in 0.496 second using v1.01-cache-2.11-cpan-524268b4103 )