# record payments and offsetting AP
for my $i (1 .. $form->{paidaccounts}) {
+ if ($form->{"acc_trans_id_$i"}
+ && $payments_only
+ && ($::lx_office_conf{features}->{payments_changeable} == 0)) {
+ next;
+ }
+
next if $form->{"paid_$i"} == 0;
my ($accno) = split /--/, $form->{"AP_paid_$i"};
}
# record payment
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, taxkey, project_id)
- VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?,
+ my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
+
+ $query =
+ qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id)
+ VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
@values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
- $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id);
+ $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id);
do_query($form, $dbh, $query, @values);
$exchangerate = 0;
$old_form = save_form();
# Delete all entries in acc_trans from prior payments.
- $self->_delete_payments($form, $dbh);
+ if ($::lx_office_conf{features}->{payments_changeable} != 0) {
+ $self->_delete_payments($form, $dbh);
+ }
# Save the new payments the user made before cleaning up $form.
- map { $payments{$_} = $form->{$_} } grep m/^datepaid_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^AP_paid_\d+$|^paidaccounts$/, keys %{ $form };
+ map { $payments{$_} = $form->{$_} } grep m/^datepaid_\d+$|^gldate_\d+$|^acc_trans_id_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^AP_paid_\d+$|^paidaccounts$/, keys %{ $form };
# Clean up $form so that old content won't tamper the results.
%keep_vars = map { $_, 1 } qw(login password id);
$form->{"AP_paid_$i"} =
"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+ $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
# reverse paid
$form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
$form->{"datepaid_$i"} =
$form->{acc_trans}{$key}->[$i - 1]->{transdate};
+ $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
$form->{"forex_$i"} = $form->{"exchangerate_$i"} =
$form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
for my $i (1 .. $form->{paidaccounts}) {
+ $form->{"changeable_$i"} = 1;
+ if ($::lx_office_conf{features}->{payments_changeable} == 0) {
+ # never
+ $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
+ } elsif ($::lx_office_conf{features}->{payments_changeable} == 2) {
+ # on the same day
+ $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
+ ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
+ }
+
$form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
if (!$form->{"AP_paid_$i"}) {
$form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
# Payments must not be recorded for the new storno invoice.
$form->{paidaccounts} = 0;
- map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
+ map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
$main::auth->assert('vendor_invoice_edit');
- map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
+ map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
$form->{paidaccounts} = 1;
$form->{rowcount}--;
$form->{invdate} = $form->current_date(\%myconfig);
[% FOREACH i = paid_indices %]
+ [% SET changeable = 'changeable_' _ i %]
+ [% SET acc_trans_id = 'acc_trans_id_' _ i %]
+ [% SET gldate = 'gldate_' _ i %]
[% SET datepaid = 'datepaid_' _ i %]
[% SET source = 'source_' _ i %]
[% SET memo = 'memo_' _ i %]
[% SET paid = 'paid_' _ i %]
+ [% SET AP_paid = 'AP_paid_' _ i %]
[% SET selectAP_paid_ref = 'selectAP_paid_' _ i %]
+ <input type=hidden name="acc_trans_id_[% i %]" value=[% $acc_trans_id %]>
+ <input type=hidden name="gldate_[% i %]" value=[% $gldate %]>
+
<tr>
<td align="center">
+ [% IF $changeable %]
<input id="datepaid_[% i %]" name="datepaid_[% i %]" size="11" title="[% dateformat %]" value="[% $datepaid %]">
<input type="button" name="datepaid_[% i %]" id="trigger_datepaid_[% i %]" value="?">
+ [% ELSE %]
+ <input type="hidden" name="datepaid_[% i %]" value="[% $datepaid %]">[% $datepaid %]
+ [% END %]
+ </td>
+ <td align=center>
+ [% IF $changeable %]
+ <input name="source_[% i %]" size="11" value="[% $source %]">
+ [% ELSE %]
+ <input type="hidden" name="source_[% i %]" value="[% $source %]">[% $source %]
+ [% END %]
+ </td>
+ <td align="center">
+ [% IF $changeable %]
+ <input name="memo_[% i %]" size="11" value="[% $memo %]">
+ [% ELSE %]
+ <input type="hidden" name="memo_[% i %]" value="[% $memo %]">[% $memo %]
+ [% END %]
+ </td>
+ <td align="center">
+ [% IF $changeable %]
+ <input name="paid_[% i %]" size="11" value="[% LxERP.format_amount($paid, 2, 1) %]">
+ [% ELSE %]
+ <input type="hidden" name="paid_[% i %]" value="[% LxERP.format_amount($paid, 2, 1) %]">
+ [% LxERP.format_amount($paid, 2, 1) %]
+ [% END %]
</td>
- <td align=center><input name="source_[% i %]" size="11" value="[% $source %]"></td>
- <td align="center"><input name="memo_[% i %]" size="11" value="[% $memo %]"></td>
- <td align="center"><input name="paid_[% i %]" size="11" value="[% LxERP.format_amount($paid, 2, 1) %]"></td>
+
[% IF show_exchangerate %]
<td align="center">
[% SET forex = 'forex_' _ i %]
<input type="hidden" name="exchangerate_[% i %]" value="[% LxERP.format_amount($exchangerate, 2) %]">
[% LxERP.format_amount(exchangerate, 2) %]
[% ELSE %]
+ [% IF $changeable %]
<input name="exchangerate_[% i %]" size="10" value="[% LxERP.format_amount($exchangerate, 2, 1) %]">
+ [% ELSE %]
+ <input type="hidden" name="exchangerate_[% i %]" value="[% LxERP.format_amount($exchangerate, 2, 1) %]">
+ [% LxERP.format_amount($exchangerate, 2, 1) %]
+ [% END %]
[% END %]
<input type="hidden" name="forex_[% i %]" value="[% $forex %]">;
</td>
[% END %]
- <td align="center"><select name="AP_paid_[% i %]">[% $selectAP_paid_ref %]</select></td>
+
+ <td align="center">
+ [% IF $changeable %]
+ <select name="AP_paid_[% i %]">[% $selectAP_paid_ref %]</select>
+ [% ELSE %]
+ <input type="hidden" name="AP_paid_[% i %]" value="[% $AP_paid %]">[% $AP_paid %]
+ [% END %]
+ </td>
</tr>
+ [% IF $changeable %]
<script type='text/javascript'>
Calendar.setup({ inputField : "datepaid_[% i %]", ifFormat :"[% myconfig_jsc_dateformat %]", align : "TR", button : "trigger_datepaid_[% i %]" });
$('input[name="paid_[% i %]"]').blur(function(){ check_right_number_format(this) });
$('#datepaid_[% i %]').blur(function(){ check_right_date_format(this) });
</script>
+ [% END %]
[% END # foreach %]