summaryrefslogtreecommitdiff
path: root/doc/plugins/editdiff
ModeNameSize
-rw-r--r--discussion.mdwn305logplain
slc"># This file contains source code included with or based on SQL-Ledger which
  • # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  • # under the GNU General Public License version 2 or, at your option, any later
  • # version. For a full list including contact information of contributors,
  • # maintainers, and copyright holders, see the CONTRIBUTORS file.
  • #
  • # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  • # Copyright (C) 2003
  • #
  • # Author: DWS Systems Inc.
  • # Web: http://www.sql-ledger.org
  • #
  • # Contributors:
  • #
  • #
  • #======================================================================
  • #
  • # This file has undergone whitespace cleanup.
  • #
  • #======================================================================
  • #
  • # Check and receipt printing payment module backend routines
  • # Number to text conversion routines are in
  • # locale/{countrycode}/Num2text
  • #
  • #======================================================================
  • package CP;
  • use LedgerSMB::Sysconfig;
  • sub new {
  • my ($type, $countrycode) = @_;
  • $self = {};
  • use LedgerSMB::Num2text;
  • use LedgerSMB::Locale;
  • $self->{'locale'} = LedgerSMB::Locale->get_handle($countrycode);
  • bless $self, $type;
  • }
  • sub paymentaccounts {
  • my ($self, $myconfig, $form) = @_;
  • my $dbh = $form->{dbh};
  • my $query = qq|SELECT accno, description, link
  • FROM chart
  • WHERE link LIKE ?
  • ORDER BY accno|;
  • my $sth = $dbh->prepare($query);
  • $sth->execute("%$form->{ARAP}%") || $form->dberror($query);
  • $form->{PR}{$form->{ARAP}} = ();
  • $form->{PR}{"$form->{ARAP}_paid"} = ();
  • while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
  • foreach my $item (split /:/, $ref->{link}) {
  • if ($item eq $form->{ARAP}) {
  • push @{ $form->{PR}{$form->{ARAP}} }, $ref;
  • }
  • if ($item eq "$form->{ARAP}_paid") {
  • push @{ $form->{PR}{"$form->{ARAP}_paid"} }, $ref;
  • }
  • }
  • }
  • $sth->finish;
  • # get currencies and closedto
  • $query = qq|
  • SELECT value, (SELECT value FROM defaults
  • WHERE setting_key = 'closedto'),
  • current_date
  • FROM defaults
  • WHERE setting_key = 'curr'|;
  • ($form->{currencies}, $form->{closedto}, $form->{datepaid}) = $dbh->selectrow_array($query);
  • if ($form->{payment} eq 'payments') {
  • # get language codes
  • $query = qq|SELECT *
  • FROM language
  • ORDER BY 2|;
  • $sth = $dbh->prepare($query);
  • $sth->execute || $self->dberror($query);
  • $form->{all_language} = ();
  • while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
  • push @{ $form->{all_language} }, $ref;
  • }
  • $sth->finish;
  • $form->all_departments($myconfig, $dbh, $form->{vc});
  • }
  • $dbh->commit;
  • }
  • sub get_openvc {
  • my ($self, $myconfig, $form) = @_;
  • my $dbh = $form->{dbh};
  • my $arap = ($form->{vc} eq 'customer') ? 'ar' : 'ap';
  • my $query = qq|SELECT count(*)
  • FROM $form->{vc} ct, $arap a
  • WHERE a.$form->{vc}_id = ct.id
  • AND a.amount != a.paid|;
  • my ($count) = $dbh->selectrow_array($query);
  • my $sth;
  • my $ref;
  • my $i = 0;
  • my $where = qq|WHERE a.$form->{vc}_id = ct.id
  • AND a.amount != a.paid|;
  • if ($form->{$form->{vc}}) {
  • my $var = $dbh->quote($form->like(lc $form->{$form->{vc}}));
  • $where .= " AND lower(name) LIKE $var";
  • }
  • # build selection list
  • $query = qq|SELECT DISTINCT ct.*
  • FROM $form->{vc} ct, $arap a
  • $where
  • ORDER BY name|;
  • $sth = $dbh->prepare($query);
  • $sth->execute || $form->dberror($query);
  • while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
  • $i++;
  • push @{ $form->{name_list} }, $ref;
  • }
  • $sth->finish;
  • $form->all_departments($myconfig, $dbh, $form->{vc});
  • # get language codes
  • $query = qq|SELECT *
  • FROM language
  • ORDER BY 2|;
  • $sth = $dbh->prepare($query);
  • $sth->execute || $self->dberror($query);
  • $form->{all_language} = ();
  • while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
  • push @{ $form->{all_language} }, $ref;
  • }
  • $sth->finish;
  • # get currency for first name
  • if (@{ $form->{name_list} }) {
  • # Chris T: I don't like this but it seems safe injection-wise
  • # Leaving it so we can change it when we go to a new system
  • $query = qq|SELECT curr
  • FROM $form->{vc}
  • WHERE id = $form->{name_list}->[0]->{id}|;
  • ($form->{currency}) = $dbh->selectrow_array($query);
  • $form->{currency} ||= $form->{defaultcurrency};
  • }
  • $dbh->commit;
  • $i;
  • }
  • sub get_openinvoices {
  • my ($self, $myconfig, $form) = @_;
  • my $null;
  • my $department_id;
  • # connect to database
  • my $dbh = $form->{dbh};
  • $vc_id = $dbh->quote($form->{"$form->{vc}_id"});
  • my $where = qq|WHERE a.$form->{vc}_id = $vc_id
  • AND a.amount != a.paid|;
  • $curr = $dbh->quote($form->{curr});
  • $where .= qq| AND a.curr = $curr| if $form->{currency};
  • my $sortorder = "transdate, invnumber";
  • my ($buysell);
  • if ($form->{vc} eq 'customer') {
  • $buysell = "buy";
  • } else {
  • $buysell = "sell";
  • }
  • if ($form->{payment} eq 'payments') {
  • $where = qq|WHERE a.amount != a.paid|;
  • $where .= qq| AND a.curr = $curr| if $form->{currency};
  • if ($form->{duedatefrom}) {
  • $where .= qq| AND a.duedate >=
  • |.$dbh->quote($form->{duedatefrom});
  • }
  • if ($form->{duedateto}) {
  • $where .= qq| AND a.duedate <= |.
  • $dbh->quote($form->{duedateto});
  • }
  • $sortorder = "name, transdate";
  • }
  • ($null, $department_id) = split /--/, $form->{department};
  • if ($department_id) {
  • $where .= qq| AND a.department_id = $department_id|;
  • }
  • my $query = qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid,
  • a.curr, c.name, a.$form->{vc}_id, c.language_code
  • FROM $form->{arap} a
  • JOIN $form->{vc} c ON (c.id = a.$form->{vc}_id)
  • $where
  • ORDER BY $sortorder|;
  • my $sth = $dbh->prepare($query);
  • $sth->execute || $form->dberror($query);
  • $query = qq|SELECT s.spoolfile
  • FROM status s
  • WHERE s.formname = '$form->{formname}'
  • AND s.trans_id = ?|;
  • my $vth = $dbh->prepare($query);
  • my $spoolfile;
  • while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
  • # if this is a foreign currency transaction get exchangerate
  • $ref->{exchangerate} =
  • $form->get_exchangerate($dbh,
  • $ref->{curr},
  • $ref->{transdate},
  • $buysell)
  • if ($form->{currency}
  • ne $form->{defaultcurrency});
  • $vth->execute($ref->{id});
  • $ref->{queue} = "";
  • while (($spoolfile) = $vth->fetchrow_array) {
  • $ref->{queued} .= "$form->{formname} $spoolfile ";
  • }
  • $vth->finish;
  • $ref->{queued} =~ s/ +$//g;
  • push @{ $form->{PR} }, $ref;
  • }
  • $sth->finish;
  • $dbh->commit;
  • }
  • sub post_payment {
  • my ($self, $myconfig, $form) = @_;