Revision 566fcc06
Von Jan Büren vor fast 2 Jahren hinzugefügt
SL/AR.pm | ||
---|---|---|
70 | 70 |
my @values; |
71 | 71 |
|
72 | 72 |
my $dbh = $provided_dbh || SL::DB->client->dbh; |
73 |
$form->{defaultcurrency} = $form->get_default_currency($myconfig); |
|
74 | 73 |
|
75 |
# set exchangerate |
|
76 |
$form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 : |
|
77 |
( $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy') || |
|
78 |
$form->parse_amount($myconfig, $form->{exchangerate}) ); |
|
74 |
$form->{defaultcurrency} = $form->get_default_currency($myconfig); |
|
75 |
# check default or record exchangerate |
|
76 |
if ($form->{currency} eq $form->{defaultcurrency}) { |
|
77 |
$form->{exchangerate} = 1; |
|
78 |
} else { |
|
79 |
$exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy'); |
|
80 |
$form->{exchangerate} = $form->parse_amount($myconfig, $form->{exchangerate}, 5); |
|
81 |
|
|
82 |
# if default exchangerate is not defined, define one |
|
83 |
unless ($exchangerate) { |
|
84 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0); |
|
85 |
# delete records exchangerate -> if user sets new invdate for record |
|
86 |
$query = qq|UPDATE ar set exchangerate = NULL where id = ?|; |
|
87 |
do_query($form, $dbh, $query, $form->{"id"}); |
|
88 |
} |
|
89 |
# update record exchangerate, if the default is set and differs from current |
|
90 |
if ($exchangerate && ($form->{exchangerate} != $exchangerate)) { |
|
91 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, |
|
92 |
$form->{exchangerate}, 0, $form->{id}, 'ar'); |
|
93 |
} |
|
94 |
} |
|
79 | 95 |
|
80 | 96 |
# get the charts selected |
81 | 97 |
$form->{AR_amounts}{"amount_$_"} = $form->{"AR_amount_chart_id_$_"} for (1 .. $form->{rowcount}); |
... | ... | |
104 | 120 |
|
105 | 121 |
$form->get_employee($dbh) unless $form->{employee_id}; |
106 | 122 |
|
107 |
# if we have an id delete old records else make one |
|
108 |
if (!$payments_only) { |
|
109 |
if ($form->{id}) { |
|
110 |
# delete detail records |
|
111 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ?|; |
|
112 |
do_query($form, $dbh, $query, $form->{id}); |
|
113 | 123 |
|
114 |
} else { |
|
115 |
$query = qq|SELECT nextval('glid')|; |
|
116 |
($form->{id}) = selectrow_query($form, $dbh, $query); |
|
117 |
$query = qq|INSERT INTO ar (id, invnumber, employee_id, currency_id, taxzone_id) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE name=?), (SELECT taxzone_id FROM customer WHERE id = ?))|; |
|
118 |
do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency}, $form->{customer_id}); |
|
119 |
if (!$form->{invnumber}) { |
|
120 |
my $trans_number = SL::TransNumber->new(type => 'invoice', dbh => $dbh, number => $form->{partnumber}, id => $form->{id}); |
|
121 |
$form->{invnumber} = $trans_number->create_unique; |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 | 124 |
|
126 | 125 |
# amount for AR account |
127 | 126 |
$form->{receivables} = $form->round_amount($form->{amount}, 2) * -1; |
128 | 127 |
|
129 |
# update exchangerate |
|
130 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0) |
|
131 |
if ($form->{currency} ne $form->{defaultcurrency}) && !$form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'buy'); |
|
132 |
|
|
133 | 128 |
if (!$payments_only) { |
134 | 129 |
$query = |
135 | 130 |
qq|UPDATE ar set |
Auch abrufbar als: Unified diff
Beleg-Wechselkurs speichern, falls gesetzt und abweichend vom Tageskurs
Für alle 4 Buchungsmaske - Etwas zuviel in dem Commit, da die
form->id schon vorhanden sein muss und ich die Aufteilung an 2
Stellen von _post_invoice|post für das Holen und Setzen auf eine
reduzieren wollte.