- |.$locale->text('Payments').qq| |
+ | . $locale->text('Payments') . qq| |
|;
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AP_paid);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate AP_paid);
- }
+ if ($form->{currency} eq $form->{defaultcurrency}) {
+ @column_index = qw(datepaid source memo paid AP_paid);
+ } else {
+ @column_index = qw(datepaid source memo paid exchangerate AP_paid);
+ }
- $column_data{datepaid} = "".$locale->text('Date')." | ";
- $column_data{paid} = "".$locale->text('Amount')." | ";
- $column_data{exchangerate} = "".$locale->text('Exch')." | ";
- $column_data{AP_paid} = "".$locale->text('Account')." | ";
- $column_data{source} = "".$locale->text('Source')." | ";
- $column_data{memo} = "".$locale->text('Memo')." | ";
+ $column_data{datepaid} = "" . $locale->text('Date') . " | ";
+ $column_data{paid} = "" . $locale->text('Amount') . " | ";
+ $column_data{exchangerate} = "" . $locale->text('Exch') . " | ";
+ $column_data{AP_paid} = "" . $locale->text('Account') . " | ";
+ $column_data{source} = "" . $locale->text('Source') . " | ";
+ $column_data{memo} = "" . $locale->text('Memo') . " | ";
- print qq|
+ print qq|
|;
- map { print "$column_data{$_}\n" } @column_index;
- print qq|
+ map { print "$column_data{$_}\n" } @column_index;
+ print qq|
|;
- $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
+ my @triggers = ();
+ $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
+ for $i (1 .. $form->{paidaccounts}) {
- print qq|
+ print qq|
|;
- $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
- $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
-
- # format amounts
- $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
- $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
+ $form->{"selectAP_paid_$i"} =~
+ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
- $exchangerate = qq| |;
- if ($form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{"forex_$i"}) {
- $exchangerate = qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
- } else {
- $exchangerate = qq|{"exchangerate_$i"}>|;
- }
+ # format amounts
+ if ($form->{"paid_$i"}) {
+ $form->{"paid_$i"} =
+ $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ }
+ $form->{"exchangerate_$i"} =
+ $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+
+ $exchangerate = qq| |;
+ if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{"forex_$i"}) {
+ $exchangerate =
+ qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+ } else {
+ $exchangerate =
+ qq|{"exchangerate_$i"}>|;
}
- $exchangerate .= qq|
+ }
+ $exchangerate .= qq|
{"forex_$i"}>
|;
- $column_data{"paid_$i"} = qq|{"paid_$i"}> | |;
- $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
- $column_data{"AP_paid_$i"} = qq| | |;
- $column_data{"datepaid_$i"} = qq|{"datepaid_$i"}> | |;
- $column_data{"source_$i"} = qq|{"source_$i"}> | |;
- $column_data{"memo_$i"} = qq|{"memo_$i"}> | |;
+ $column_data{"paid_$i"} =
+ qq| | |;
+ $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
+ $column_data{"AP_paid_$i"} =
+ qq| | |;
+ $column_data{"datepaid_$i"} =
+ qq|
+ | |;
+ $column_data{"source_$i"} =
+ qq|{"source_$i"}> | |;
+ $column_data{"memo_$i"} =
+ qq|{"memo_$i"}> | |;
+
+ map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
- map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
-
- print qq|
+ print qq|
|;
- }
-
- print qq|
+ push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
+ }
+
+ print qq|
{oldinvtotal}>
{paidaccounts}>
@@ -618,52 +792,55 @@ print qq|
|;
- $invdate = $form->datetonum($form->{invdate}, \%myconfig);
+ $invdate = $form->datetonum($form->{invdate}, \%myconfig);
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
-
+
if ($form->{id}) {
- print qq|
-|;
+ my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
- if (!$form->{revtrans}) {
- if (!$form->{locked}) {
- print qq|
-
-
+ print qq|
|;
- }
- }
-
- if ($invdate > $closedto) {
- print qq|
-
-
+ print qq|
+| if ($show_storno);
+ if ($form->{radier}) {
+ print qq|
+
|;
- }
-
- } else {
- if ($invdate > $closedto) {
- print qq|
- |;
- }
}
+ print qq|
+|;
- if ($form->{menubar}) {
- require "$form->{path}/menu.pl";
- &menubar;
}
-
-print qq|
-{rowcount}>
+ print qq||;
-
+ if (!$form->{id} && ($invdate > $closedto)) {
+ print qq| | .
+ NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
+ '-class' => 'submit'));
+ }
-{path}>
-{login}>
-{password}>
+ print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
+ $form->hide_form(qw(rowcount callback draft_id draft_description login password));
-
+ # button for saving history
+ if($form->{id} ne "") {
+ print qq|
+ |;
+ }
+ # /button for saving history
+
+print qq|
@@ -672,92 +849,117 @@ print qq|
$lxdebug->leave_sub();
}
-
-
sub update {
$lxdebug->enter_sub();
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
-
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+ qw(exchangerate creditlimit creditremaining);
+
&check_name(vendor);
- &check_project;
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{invdate}, 'sell'
+ )));
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell')));
-
-
for $i (1 .. $form->{paidaccounts}) {
if ($form->{"paid_$i"}) {
- map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
-
- $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell')));
+ map {
+ $form->{"${_}_$i"} =
+ $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
+ } qw(paid exchangerate);
+
+ $form->{"exchangerate_$i"} = $exchangerate
+ if (
+ $form->{"forex_$i"} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell'
+ )));
}
}
-
- $i = $form->{rowcount};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
- if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
+ $i = $form->{rowcount};
+ $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
+
+ if ( ($form->{"partnumber_$i"} eq "")
+ && ($form->{"description_$i"} eq "")
+ && ($form->{"partsgroup_$i"} eq "")) {
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
&check_form;
-
+
} else {
-
+
IR->retrieve_item(\%myconfig, \%$form);
my $rows = scalar @{ $form->{item_list} };
if ($rows) {
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
-
+ $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
+
if ($rows > 1) {
-
- &select_item;
- exit;
-
+
+ &select_item;
+ exit;
+
} else {
+
# override sellprice if there is one entered
- $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+ $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
- map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
-
- map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
+ map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
+ qw(partnumber description unit);
+
+ map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
+ keys %{ $form->{item_list}[0] };
+
+ $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
+
+ ($dec) = ($s =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
- $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
-
- ($dec) = ($s =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
-
if ($sellprice) {
- $form->{"sellprice_$i"} = $sellprice;
- } else {
- # if there is an exchange rate adjust sellprice
- $form->{"sellprice_$i"} /= $exchangerate;
- }
-
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
- $form->{creditremaining} -= $amount;
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"sellprice_$i"} = $sellprice;
+ } else {
+
+ # if there is an exchange rate adjust sellprice
+ $form->{"sellprice_$i"} /= $exchangerate;
+ }
+
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} *
+ (1 - $form->{"discount_$i"} / 100);
+ $form->{creditremaining} -= $amount;
+ $form->{"sellprice_$i"} =
+ $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces);
+ $form->{"qty_$i"} =
+ $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
}
&display_form;
} else {
+
# ok, so this is a new part
# ask if it is a part or service item
- if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
- $form->{rowcount}--;
- $form->{"discount_$i"} = "";
- &display_form;
- } else {
-
- $form->{"id_$i"} = 0;
- $form->{"unit_$i"} = $locale->text('ea');
+ if ( $form->{"partsgroup_$i"}
+ && ($form->{"partsnumber_$i"} eq "")
+ && ($form->{"description_$i"} eq "")) {
+ $form->{rowcount}--;
+ $form->{"discount_$i"} = "";
+ &display_form;
+ } else {
- &new_item;
+ $form->{"id_$i"} = 0;
+ $form->{"unit_$i"} = $locale->text('ea');
+
+ &new_item;
}
}
@@ -765,14 +967,97 @@ sub update {
$lxdebug->leave_sub();
}
+sub storno {
+ $lxdebug->enter_sub();
+ if ($form->{storno}) {
+ $form->error($locale->text('Cannot storno storno invoice!'));
+ }
+
+ if (IS->has_storno(\%myconfig, $form, "ap")) {
+ $form->error($locale->text("Invoice has already been storno'd!"));
+ }
+
+ invoice_links();
+ prepare_invoice();
+ relink_accounts();
+
+ # saving the history
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "CANCELED";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+
+ $form->{storno_id} = $form->{id};
+ $form->{storno} = 1;
+ $form->{id} = "";
+ $form->{invnumber} = "Storno zu " . $form->{invnumber};
+ $form->{rowcount}++;
+ &post();
+ $lxdebug->leave_sub();
+
+}
+
+sub use_as_template {
+ $lxdebug->enter_sub();
+
+ 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);
+ $form->{paidaccounts} = 1;
+ $form->{rowcount}--;
+ $form->{invdate} = $form->current_date(\%myconfig);
+ &display_form;
+
+ $lxdebug->leave_sub();
+}
+
+sub post_payment {
+ $lxdebug->enter_sub();
+ for $i (1 .. $form->{paidaccounts}) {
+ if ($form->{"paid_$i"}) {
+ $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+
+ $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
+
+ $form->error($locale->text('Cannot post payment for a closed period!'))
+ if ($datepaid <= $closedto);
+
+ if ($form->{currency} ne $form->{defaultcurrency}) {
+ $form->{"exchangerate_$i"} = $form->{exchangerate}
+ if ($invdate == $datepaid);
+ $form->isblank("exchangerate_$i",
+ $locale->text('Exchangerate for payment missing!'));
+ }
+ }
+ }
+
+ ($form->{AP}) = split /--/, $form->{AP};
+ ($form->{AP_paid}) = split /--/, $form->{AP_paid};
+ if (IR->post_payment(\%myconfig, \%$form)){
+
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ # saving the history
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "PAYMENT POSTED";
+ $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
+ $form->save_history($form->dbconnect(\%myconfig));
+ # /saving the history
+ $form->redirect($locale->text(' Payment posted!'));
+ }
+ }
+ $form->error($locale->text('Cannot post payment!'));
+
+
+ $lxdebug->leave_sub();
+}
sub post {
$lxdebug->enter_sub();
$form->isblank("invdate", $locale->text('Invoice Date missing!'));
- $form->isblank("vendor", $locale->text('Vendor missing!'));
-
+ $form->isblank("vendor", $locale->text('Vendor missing!'));
+
# if the vendor changed get new values
if (&check_name(vendor)) {
&update;
@@ -782,46 +1067,62 @@ sub post {
&validate_items;
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
- $invdate = $form->datetonum($form->{invdate}, \%myconfig);
+ $invdate = $form->datetonum($form->{invdate}, \%myconfig);
- $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto);
+ $form->error($locale->text('Cannot post invoice for a closed period!'))
+ if ($invdate <= $closedto);
+
+ $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
+ if ($form->{currency} ne $form->{defaultcurrency});
- $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
+ if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
$datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
-
- $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
-
+
+ $form->error($locale->text('Cannot post payment for a closed period!'))
+ if ($datepaid <= $closedto);
+
if ($form->{currency} ne $form->{defaultcurrency}) {
- $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
- $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
+ $form->{"exchangerate_$i"} = $form->{exchangerate}
+ if ($invdate == $datepaid);
+ $form->isblank("exchangerate_$i",
+ $locale->text('Exchangerate for payment missing!'));
}
}
}
-
-
- ($form->{AP}) = split /--/, $form->{AP};
+
+ ($form->{AP}) = split /--/, $form->{AP};
($form->{AP_paid}) = split /--/, $form->{AP_paid};
-
+
$form->{id} = 0 if $form->{postasnew};
- $form->redirect($locale->text('Invoice')." $form->{invnumber} ".$locale->text('posted!')) if (IR->post_invoice(\%myconfig, \%$form));
+
+ relink_accounts();
+ if (IR->post_invoice(\%myconfig, \%$form)){
+ # saving the history
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "POSTED";
+ #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+ remove_draft() if $form->{remove_draft};
+ $form->redirect( $locale->text('Invoice')
+ . " $form->{invnumber} "
+ . $locale->text('posted!'));
+ }
$form->error($locale->text('Cannot post invoice!'));
-
+
$lxdebug->leave_sub();
}
-
-
sub delete {
$lxdebug->enter_sub();
$form->header;
-
print qq|
@@ -837,27 +1138,33 @@ sub delete {
}
print qq|
-|.$locale->text('Confirm!').qq|
+| . $locale->text('Confirm!') . qq|
-|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber}
+|
+ . $locale->text('Are you sure you want to delete Invoice Number')
+ . qq| $form->{invnumber}
-
+
|;
-
$lxdebug->leave_sub();
}
-
-
sub yes {
$lxdebug->enter_sub();
-
- $form->redirect($locale->text('Invoice deleted!')) if (IR->delete_invoice(\%myconfig, \%$form));
+ if (IR->delete_invoice(\%myconfig, \%$form)) {
+ # saving the history
+ if(!exists $form->{addition}) {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "DELETED";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+ $form->redirect($locale->text('Invoice deleted!'));
+ }
$form->error($locale->text('Cannot delete invoice!'));
$lxdebug->leave_sub();
}
-
-
|