Projekt

Allgemein

Profil

Herunterladen (12,5 KB) Statistiken
| Zweig: | Markierung: | Revision:
#=====================================================================
# LX-Office ERP
# Copyright (C) 2004
# Based on SQL-Ledger Version 2.1.9
# Web http://www.lx-office.org
#
#=====================================================================
# SQL-Ledger Accounting
# Copyright (c) 2002
#
# Author: Dieter Simader
# Email: dsimader@sql-ledger.org
# Web: http://www.sql-ledger.org
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1335, USA.
#======================================================================
#
# Payment module
#
#======================================================================

use SL::CP;
use SL::IS;
use SL::IR;
use SL::AR;
use SL::AP;
use Data::Dumper;
use SL::Locale::String qw(t8);
use strict;
#use warnings;

require "bin/mozilla/common.pl";

our ($form, %myconfig, $lxdebug, $locale, $auth);

1;

# end of main

sub payment {
$lxdebug->enter_sub();

$auth->assert('cash');

my (@curr);

$form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
$form->{arap} = lc $form->{ARAP};

CP->paymentaccounts(\%myconfig, \%$form);

# Standard Konto für Umlaufvermögen
my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
# Entsprechend präventiv die Auswahlliste für Kontonummer
# auch mit value= zusammenbauen (s.a. oben bugfix 1771)
# Wichtig: Auch das Template anpassen, damit hidden input korrekt die "
# escaped.
$form->{selectaccount} = "";
$form->{"select$form->{ARAP}"} = "";

map { $form->{selectaccount} .= "<option value=\"$_->{accno}--$_->{description}\">$_->{accno}--$_->{description}</option>\n";
$form->{account} = "$_->{accno}--$_->{description}" if ($_->{accno} eq $accno_arap) } @{ $form->{PR}{"$form->{ARAP}_paid"} };

# currencies
# oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
# der aktualisierung der form auch nicht mitübernommen. das konzept
# old_$FOO habe ich auch noch nicht verstanden ...
# Ok. Wenn currency übernommen werden, dann in callback-string über-
# geben und hier reinparsen, oder besser multibox oder html auslagern?
# Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
# Wofür macht das Sinn?
@curr = $form->get_all_currencies();
$form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
$form->get_default_currency(\%myconfig);

# Entsprechend präventiv die Auswahlliste für Währungen
# auch mit value= zusammenbauen (s.a. oben bugfix 1771)
$form->{selectcurrency} = "";
map { $form->{selectcurrency} .= "<option value=\"$_\">$_</option>\n" } @curr;


&form_header;
&form_footer;

$lxdebug->leave_sub();
}

sub form_header {
$lxdebug->enter_sub;

$auth->assert('cash');

$::request->layout->add_javascripts("kivi.CustomerVendor.js");

my ($arap, $exchangerate);

if (!$form->{ $form->{vc} . '_id' }) {
map { $form->{"addr$_"} = "" } (1 .. 4);
}

# bugfix 1771
# geändert von <option>asdf--2929
# nach:
# <option value="asdf--2929">asdf--2929</option>
# offen: $form->{ARAP} kann raus?
for my $item ("account", "currency", $form->{ARAP}) {
$form->{$item} = H($form->{$item});
$form->{"select$item"} =~ s/ selected//;
$form->{"select$item"} =~ s/option value="\Q$form->{$item}\E">\Q$form->{$item}\E/option selected value="$form->{$item}">$form->{$item}/;
}

$form->{openinvoices} = 1;

# $locale->text('AR')
# $locale->text('AP')

setup_cp_form_action_bar(can_post => !!$form->{rowcount});

$::form->{title} = t8('Receipt');
$form->header;

$arap = lc $form->{ARAP};

print $::form->parse_html_template('cp/form_header', {
is_customer => $form->{vc} eq 'customer',
is_receipt => $form->{type} eq 'receipt',
arap => $arap,
});

$lxdebug->leave_sub;
}

sub list_invoices {
$::lxdebug->enter_sub;
$::auth->assert('cash');

my @columns = qw(amount due paid invnumber id transdate checked);
my (@invoices, %total);
for my $i (1 .. $::form->{rowcount}) {
push @invoices, +{ map { $_ => $::form->{"$_\_$i"} } @columns };
$total{$_} += $invoices[-1]{$_} = $::form->parse_amount(\%::myconfig, $invoices[-1]{$_}) for qw(amount due paid);
}

print $::form->parse_html_template('cp/invoices', {
invoices => \@invoices,
totals => \%total,
});

$::lxdebug->leave_sub;
}

sub form_footer {
$::lxdebug->enter_sub;
$::auth->assert('cash');

print $::form->parse_html_template('cp/form_footer');

$::lxdebug->leave_sub;
}

sub update {
$lxdebug->enter_sub();

$auth->assert('cash');

my ($buysell, $updated, $exchangerate, $amount);

if ($form->{vc} eq 'customer') {
$buysell = "buy";
} else {
$buysell = "sell";
}

# search by invoicenumber,
if ($form->{invnumber}) {
$form->{open} ='Y'; # only open invoices
if ($form->{ARAP} eq 'AR'){
# ar_transactions automatically searches by $form->{customer_id} or else
# $form->{customer} if available, and these variables will always be set
# so we have to empty these values first
$form->{customer_id} = '';
$form->{customer} = '';
AR->ar_transactions(\%myconfig, \%$form);

# if you search for invoice '11' ar_transactions will also match invoices
# 112, 211, ... due to the LIKE

# so there is now an extra loop that tries to match the invoice number
# exactly among all returned results, and then passes the customer_id instead of the name
# because the name may not be unique

my $found_exact_invnumber_match = 0