-
-
+
+
+ |
+ | . $locale->text('Transaction description') . qq| |
+ | . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq| |
+ |;
+#
+#
+#
+# |
+#
+print qq|
-
+ |
|
@@ -439,43 +814,25 @@ sub form_header {
|
-
+| .
$jsscript
-
+. qq|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-|;
-
- foreach $item (split / /, $form->{taxaccounts}) {
- print qq|
-
-
-
-|;
+| ;
+map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
+ qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2));
+print qq| |;
+map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
+ qw(message email subject cc bcc taxaccounts));
+print qq||;
+
+ foreach $item (split(/ /, $form->{taxaccounts})) {
+ map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
+ ("${item}_rate", "${item}_description", "${item}_taxnumber"));
}
$lxdebug->leave_sub();
}
-
-
sub form_footer {
$lxdebug->enter_sub();
@@ -488,99 +845,120 @@ sub form_footer {
$introws = 2;
}
$rows = ($rows > $introws) ? $rows : $introws;
- $notes = qq||;
- $intnotes = qq||;
-
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
+ $notes =
+ qq||;
+ $intnotes =
+ qq||;
+
+ $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
$taxincluded = "";
if ($form->{taxaccounts}) {
$taxincluded = qq|
- {taxincluded}> |.$locale->text('Tax Included').qq|
|;
+ {taxincluded}> |
+ . $locale->text('Tax Included') . qq|
|;
}
if (!$form->{taxincluded}) {
foreach $item (split / /, $form->{taxaccounts}) {
if ($form->{"${item}_base"}) {
- $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
- $form->{invtotal} += $form->{"${item}_total"};
- $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
-
- $tax .= qq|
+ $form->{"${item}_total"} =
+ $form->round_amount(
+ $form->{"${item}_base"} * $form->{"${item}_rate"},
+ 2);
+ $form->{invtotal} += $form->{"${item}_total"};
+ $form->{"${item}_total"} =
+ $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
+
+ $tax .= qq|
- $form->{"${item}_description"} |
- $form->{"${item}_total"} |
+ $form->{"${item}_description"} |
+ . $form->{"${item}_rate"} * 100 .qq|% |
+ $form->{"${item}_total"} |
|;
}
}
- $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
+ $form->{invsubtotal} =
+ $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
$subtotal = qq|
- |.$locale->text('Subtotal').qq| |
- $form->{invsubtotal} |
+ | . $locale->text('Subtotal') . qq| |
+ $form->{invsubtotal} |
|;
}
-
- if ($form->{taxincluded}) {
- foreach $item (split / /, $form->{taxaccounts}) {
- if ($form->{"${item}_base"}) {
- $form->{"${item}_total"} = $form->round_amount(($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})) , 2);
- $form->{"${item}_netto"} = $form->round_amount(($form->{"${item}_base"}-$form->{"${item}_total"}), 2);
- $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
- $form->{"${item}_netto"} = $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
-
- $tax .= qq|
+ if ($form->{taxincluded}) {
+ foreach $item (split / /, $form->{taxaccounts}) {
+ if ($form->{"${item}_base"}) {
+ $form->{"${item}_total"} =
+ $form->round_amount(
+ ($form->{"${item}_base"} * $form->{"${item}_rate"} /
+ (1 + $form->{"${item}_rate"})
+ ),
+ 2);
+ $form->{"${item}_netto"} =
+ $form->round_amount(
+ ($form->{"${item}_base"} - $form->{"${item}_total"}),
+ 2);
+ $form->{"${item}_total"} =
+ $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
+ $form->{"${item}_netto"} =
+ $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
+
+ $tax .= qq|
- Enthaltene $form->{"${item}_description"} |
- $form->{"${item}_total"} |
+ Enthaltene $form->{"${item}_description"} |
+ . $form->{"${item}_rate"} * 100 .qq|% |
+ $form->{"${item}_total"} |
- Nettobetrag |
- $form->{"${item}_netto"} |
+ Nettobetrag |
+ $form->{"${item}_netto"} |
|;
}
}
-
-
+
}
-
$form->{oldinvtotal} = $form->{invtotal};
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
+ $form->{invtotal} =
+ $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
print qq|
-
-
+
+
- |.$locale->text('Notes').qq| |
- |.$locale->text('Internal Notes').qq| |
+ | . $locale->text('Notes') . qq| |
+ | . $locale->text('Internal Notes') . qq| |
+ | . $locale->text('Payment Terms') . qq| |
-
+
$notes |
$intnotes |
+ |
|
-
+ |
$taxincluded
-
+
$subtotal
$tax
- |.$locale->text('Total').qq| |
- $form->{invtotal} |
+ | . $locale->text('Total') . qq| |
+ $form->{invtotal} |
@@ -590,41 +968,53 @@ sub form_footer {
|;
if ($webdav) {
- $webdav_list = qq|
+ $webdav_list = qq|
-
|
+
|
-
- Dokumente im Webdav-Repository |
+
+ Dokumente im Webdav-Repository |
-
- Dateiname |
- Webdavlink |
+
+ Dateiname |
+ Webdavlink |
|;
- foreach $file (keys %{ $form->{WEBDAV}}) {
- $webdav_list .= qq|
-
- $file |
- $form->{WEBDAV}{$file} |
+ foreach $file (keys %{ $form->{WEBDAV} }) {
+ $webdav_list .= qq|
+
+ $file |
+ $form->{WEBDAV}{$file} |
|;
- }
- $webdav_list .= qq|
+ }
+ $webdav_list .= qq|
|;
-print $webdav_list;
-}
-print qq|
+ print $webdav_list;
+ }
+if ($form->{type} eq "credit_note") {
+ print qq|
+
+
+
+
+ |
+ . $locale->text('Payments') . qq| |
+
+|;
+} else {
+ print qq|
-
-
- |.$locale->text('Incoming Payments')
- .qq| |
+
+
+ |
+ . $locale->text('Incoming Payments') . qq| |
|;
+}
if ($form->{currency} eq $form->{defaultcurrency}) {
@column_index = qw(datepaid source memo paid AR_paid);
@@ -632,12 +1022,12 @@ print qq|
@column_index = qw(datepaid source memo paid exchangerate AR_paid);
}
- $column_data{datepaid} = "".$locale->text('Date')." | ";
- $column_data{paid} = "".$locale->text('Amount')." | ";
- $column_data{exchangerate} = "".$locale->text('Exch')." | ";
- $column_data{AR_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{AR_paid} = "" . $locale->text('Account') . " | ";
+ $column_data{source} = "" . $locale->text('Source') . " | ";
+ $column_data{memo} = "" . $locale->text('Memo') . " | ";
print "
@@ -647,6 +1037,8 @@ print qq|
";
+ my @triggers = ();
+
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
for $i (1 .. $form->{paidaccounts}) {
@@ -654,117 +1046,153 @@ print qq|
\n";
$form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
- $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
+ $form->{"selectAR_paid_$i"} =~
+ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
# format amounts
$totalpaid += $form->{"paid_$i"};
- $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
- $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ 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"}|;
+ $exchangerate = qq|$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{"AR_paid_$i"} = qq| | |;
- $column_data{"datepaid_$i"} = qq|{"datepaid_$i"}> | |;
- $column_data{"source_$i"} = qq| | |;
- $column_data{"memo_$i"} = qq| | |;
+ $exchangerate .= qq||;
+
+ $column_data{"paid_$i"} =
+ qq| | |;
+ $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
+ $column_data{"AR_paid_$i"} =
+ qq| | |;
+ $column_data{"datepaid_$i"} =
+ qq|
+ | |;
+ $column_data{"source_$i"} =
+ qq| | |;
+ $column_data{"memo_$i"} =
+ qq| | |;
map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
print "
\n";
+ push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
}
-
- print qq|
-{paidaccounts}>
-
-{oldinvtotal}>
-
-
+
+ map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
+ print qq|
+
|
-
|
+
|
|;
-
-
- &print_options;
+ print_options();
-
print qq|
|
|;
-
- $invdate = $form->datetonum($form->{invdate}, \%myconfig);
+ $invdate = $form->datetonum($form->{invdate}, \%myconfig);
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
if ($form->{id}) {
+ my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
+
print qq|
-
-
-
-
+
+
+
+ |;
+ print qq| | if ($show_storno);
+ print qq|
|;
-
- if (!$form->{revtrans}) {
- if (!$form->{locked}) {
- print qq|
-
-
+ print qq|
|;
- }
- }
+ if ($form->{id} && !($form->{type} eq "credit_note")) {
+ print qq|
+
+|;
+ }
+ if ($form->{radier}) {
+ print qq|
+
+|;
+ }
+
if ($invdate > $closedto) {
print qq|
-
-
+
|;
}
} else {
if ($invdate > $closedto) {
- print qq|
-
-
-
- |;
+ print qq|
+
+
+
+
+ | .
+ NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
+ '-class' => 'submit'));
}
}
- if ($form->{menubar}) {
- require "$form->{path}/menu.pl";
- &menubar;
+ # button for saving history
+ if($form->{id} ne "") {
+ print qq|
+ |;
}
-
- print qq|
-
-{rowcount}>
+ # /button for saving history
-
-{path}>
-{login}>
-{password}>
+ print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
+ qq|
+
+| .
+$cgi->hidden("-name" => "callback", "-value" => $form->{callback})
+. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
+. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
+map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(login password));
+print qq|
@@ -775,31 +1203,60 @@ 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);
+ if ($form->{second_run}) {
+ $form->{print_and_post} = 0;
+ }
+
+
+ if($form->{taxincluded}) {
+ $taxincluded = "checked";
+ }
+ $form->{update} = 1;
&check_name(customer);
- &check_project;
+ if(!$form->{taxincluded}) {
+ $form->{taxincluded} = $taxincluded;
+ }
+
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy')));
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
+ )));
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"}, 'buy')));
+ 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"}, 'buy'
+ )));
}
}
- $i = $form->{rowcount};
+ $i = $form->{rowcount};
$exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
# if last row empty, check the form otherwise retrieve new item
- if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
+ if ( ($form->{"partnumber_$i"} eq "")
+ && ($form->{"description_$i"} eq "")
+ && ($form->{"partsgroup_$i"} eq "")) {
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
&check_form;
@@ -810,81 +1267,108 @@ sub update {
$rows = scalar @{ $form->{item_list} };
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
+ $form->{"discount_$i"} =
+ $form->format_amount(\%myconfig, $form->{discount} * 100);
if ($rows) {
- $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
+ $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
if ($rows > 1) {
- &select_item;
- exit;
+ &select_item;
+ exit;
} else {
- $sellprice = $form->format_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] };
-
- $form->{"discount_$i"} = $form->{discount} * 100;
-
- $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"} *= (1 - $form->{tradediscount});
- $form->{"sellprice_$i"} /= $exchangerate;
- }
-
- $form->{"listprice_$i"} /= $exchangerate;
-
- $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
- map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
- map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
- map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
+ $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] };
+ if ($form->{"part_payment_id_$i"} ne "") {
+ $form->{payment_id} = $form->{"part_payment_id_$i"};
+ }
+
+ if ($form->{"not_discountable_$i"}) {
+ $form->{"discount_$i"} = 0;
+ }
+
+ $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"} *= (1 - $form->{tradediscount});
+ $form->{"sellprice_$i"} /= $exchangerate;
+ }
+
+ $form->{"listprice_$i"} /= $exchangerate;
+
+ $amount =
+ $form->{"sellprice_$i"} * $form->{"qty_$i"} *
+ (1 - $form->{"discount_$i"} / 100);
+ map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
+ map { $form->{"${_}_base"} += $amount }
+ (split / /, $form->{"taxaccounts_$i"});
+ map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
+ split / /, $form->{"taxaccounts_$i"}
+ if !$form->{taxincluded};
$form->{creditremaining} -= $amount;
+ map {
+ $form->{"${_}_$i"} =
+ $form->format_amount(\%myconfig, $form->{"${_}_$i"},
+ $decimalplaces)
+ } qw(sellprice listprice);
+
+ $form->{"qty_$i"} =
+ $form->format_amount(\%myconfig, $form->{"qty_$i"});
+
+ if ($lizenzen) {
+ if ($form->{"inventory_accno_$i"} ne "") {
+ $form->{"lizenzen_$i"} = qq||;
+ foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
+ $form->{"lizenzen_$i"} .=
+ qq||;
+ }
+ $form->{"lizenzen_$i"} .=
+ qq||;
+ }
+ }
- map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
-
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
-
- if ($lizenzen) {
- if ($form->{"inventory_accno_$i"} ne "") {
- $form->{"lizenzen_$i"} = qq||;
- foreach $item (@{ $form->{LIZENZEN}{$form->{"id_$i"}}}) {
- $form->{"lizenzen_$i"} .= qq||;
- }
- $form->{"lizenzen_$i"} .= qq||;
- }
- }
-
+ # get pricegroups for parts
+ IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+ # build up html code for prices_$i
+ &set_pricegroup($i);
}
&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 {
+ 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');
+ $form->{"id_$i"} = 0;
+ $form->{"unit_$i"} = $locale->text('ea');
- &new_item;
+ &new_item;
}
}
@@ -892,12 +1376,40 @@ sub update {
$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->{AR}) = split /--/, $form->{AR};
+ ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+ relink_accounts();
+ $form->redirect($locale->text(' Payment posted!'))
+ if (IS->post_payment(\%myconfig, \%$form));
+ $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("invdate", $locale->text('Invoice Date missing!'));
$form->isblank("customer", $locale->text('Customer missing!'));
# if oldcustomer ne customer redo form
@@ -905,59 +1417,152 @@ sub post {
&update;
exit;
}
-
+ if ($form->{second_run}) {
+ $form->{print_and_post} = 0;
+ }
+
&validate_items;
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
- $invdate = $form->datetonum($form->{invdate}, \%myconfig);
-
- $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto);
+ $invdate = $form->datetonum($form->{invdate}, \%myconfig);
+
+ $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->{AR}) = split /--/, $form->{AR};
+ ($form->{AR}) = split /--/, $form->{AR};
($form->{AR_paid}) = split /--/, $form->{AR_paid};
-
+
$form->{label} = $locale->text('Invoice');
$form->{id} = 0 if $form->{postasnew};
+
+ # get new invnumber in sequence if no invnumber is given or if posasnew was requested
+ if ($form->{postasnew}) {
+ if ($form->{type} eq "credit_note") {
+ undef($form->{cnnumber});
+ } else {
+ undef($form->{invnumber});
+ }
+ }
+
+ relink_accounts();
+ $form->error($locale->text('Cannot post invoice!'))
+ unless IS->post_invoice(\%myconfig, \%$form);
+ remove_draft() if $form->{remove_draft};
+
+ if(!exists $form->{addition}) {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = $print_post ? "PRINTED AND POSTED" :
+ $form->{storno} ? "STORNO" :
+ "POSTED";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
- $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") unless $form->{invnumber};
-
- $form->redirect($form->{label}." $form->{invnumber} ".$locale->text('posted!')) if (IS->post_invoice(\%myconfig, \%$form));
- $form->error($locale->text('Cannot post invoice!'));
-
+ $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
+ unless $print_post;
+
$lxdebug->leave_sub();
}
+sub print_and_post {
+ $lxdebug->enter_sub();
+ $old_form = new Form;
+ $print_post = 1;
+ $form->{print_and_post} = 1;
+ &post();
+ &edit();
+ $lxdebug->leave_sub();
-sub delete {
+}
+
+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 storno {
+ $lxdebug->enter_sub();
+
+ if ($form->{storno}) {
+ $form->error($locale->text('Cannot storno storno invoice!'));
+ }
+
+ if (IS->has_storno(\%myconfig, $form, "ar")) {
+ $form->error($locale->text("Invoice has already been storno'd!"));
+ }
+
+ map({ my $key = $_; delete($form->{$key})
+ unless (grep({ $key eq $_ } qw(login password id type))); }
+ keys(%{ $form }));
+
+ &invoice_links;
+ &prepare_invoice;
+ relink_accounts();
+
+ $form->{storno_id} = $form->{id};
+ $form->{storno} = 1;
+ $form->{id} = "";
+ $form->{invnumber} = "Storno zu " . $form->{invnumber};
+
+ &post();
+ $lxdebug->leave_sub();
+
+}
+
+sub preview {
+ $lxdebug->enter_sub();
+
+ $form->{preview} = 1;
+ $old_form = new Form;
+ for (keys %$form) { $old_form->{$_} = $form->{$_} }
+ $old_form->{rowcount}++;
+
+ &print_form($old_form);
+ $lxdebug->leave_sub();
+
+}
+
+sub delete {
+ $lxdebug->enter_sub();
+ if ($form->{second_run}) {
+ $form->{print_and_post} = 0;
+ }
$form->header;
print qq|
-
|;
-
$lxdebug->leave_sub();
}
+sub credit_note {
+ $lxdebug->enter_sub();
+
+ $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
+ $form->{duedate} =
+ $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+
+ $form->{id} = '';
+ $form->{rowcount}--;
+ $form->{shipto} = 1;
+
+
+ $form->{title} = $locale->text('Add Credit Note');
+ $form->{script} = 'is.pl';
+ $script = "is";
+ $buysell = 'buy';
+
+
+ # bo creates the id, reset it
+ map { delete $form->{$_} }
+ qw(id invnumber subject message cc bcc printed emailed queued);
+ $form->{ $form->{vc} } =~ s/--.*//g;
+ $form->{type} = "credit_note";
+
+
+ map { $form->{"select$_"} = "" } ($form->{vc}, currency);
+
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+ qw(creditlimit creditremaining);
+
+ $currency = $form->{currency};
+ &invoice_links;
+
+ $form->{currency} = $currency;
+ $form->{exchangerate} = "";
+ $form->{forex} = "";
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{invdate}, $buysell
+ )));
+ $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
+
+ &prepare_invoice;
+
+
+ &display_form;
+
+ $lxdebug->leave_sub();
+}
sub yes {
$lxdebug->enter_sub();
-
- $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form, $spool));
+ if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
+ # 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();
}
+sub e_mail {
+ $lxdebug->enter_sub();
+
+ if (!$form->{id}) {
+ $print_post = 1;
+
+ my $saved_form = save_form();
+
+ post();
+
+ my %saved_vars;
+ map({ $saved_vars{$_} = $form->{$_}; } qw(id invnumber));
+ restore_form($saved_form);
+ map({ $form->{$_} = $saved_vars{$_}; } qw(id invnumber));
+ }
+
+ edit_e_mail();
+
+ $lxdebug->leave_sub();
+}
| | | |