use SL::DN;
use Data::Dumper;
+require "bin/mozilla/common.pl";
require "bin/mozilla/io.pl";
require "bin/mozilla/arap.pl";
sub edit_config {
$lxdebug->enter_sub();
- # edit all dunning config data
-
- $form->header;
DN->get_config(\%myconfig, \%$form);
- $form->{title} = $locale->text('Edit Dunning Process Config');
-
- $form->{callback} =
- "$form->{script}?action=edit_config&login=$form->{login}&password=$form->{password}"
- unless $form->{callback};
- @column_index = qw(dunning_level dunning_description active auto email payment_terms terms fee interest_rate template);
+ $form->{title} = $locale->text('Edit Dunning Process Config');
+ $form->{callback} ||= build_std_url("action=edit_config");
+ $form->{rowcount} = 1 + scalar @{ $form->{DUNNING} };
+ $form->{rowcount_odd} = $form->{rowcount} % 2;
- $column_header{dunning_level} =
- qq|<th class=listheading>|
- . $locale->text('Dunning Level')
- . qq|</th>|;
- $column_header{dunning_description} =
- qq|<th class=listheading>|
- . $locale->text('Dunning Description')
- . qq|</th>|;
- $column_header{active} =
- qq|<th class=listheading>|
- . $locale->text('Active?')
- . qq|</th>|;
- $column_header{auto} =
- qq|<th class=listheading>|
- . $locale->text('Auto Send?')
- . qq|</th>|;
- $column_header{email} =
- qq|<th class=listheading>|
- . $locale->text('eMail Send?')
- . qq|</th>|;
- $column_header{payment_terms} =
- qq|<th class=listheading>|
- . $locale->text('Fristsetzung')
- . qq|</th>|;
- $column_header{terms} =
- qq|<th class=listheading>|
- . $locale->text('Duedate +Days')
- . qq|</th>|;
- $column_header{fee} =
- qq|<th class=listheading>|
- . $locale->text('Fee')
- . qq|</th>|;
- $column_header{interest_rate} =
- qq|<th class=listheading>|
- . $locale->text('Interest Rate')
- . qq|</th>|;
- $column_header{template} =
- qq|<th class=listheading>|
- . $locale->text('Template')
- . qq|</th>|;
- print qq|
-<body>
-<script type="text/javascript" src="js/common.js"></script>
-<script type="text/javascript" src="js/dunning.js"></script>
-<form method=post action=$form->{script}>
-
-
-<table width=100%>
- <tr>
- <th class=listtop colspan=10>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>|;
- map { print "$column_header{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
- my $i = 0;
- foreach $ref (@{ $form->{DUNNING} }) {
-
- $i++;
- my $j = $i % 2;
-
- print qq|
- <tr valign=top class=listrow$j>
-|;
-
-
- $column_data{dunning_level} =
- qq|<td><input type=hidden name=dunning_level_$i size=2 value="$i"><input type=hidden name=id_$i value="$ref->{id}">$i</td>|;
- $column_data{dunning_description} = qq|<td><input name=dunning_description_$i value="$ref->{dunning_description}"></td>|;
- my $active = ($ref->{active}) ? "checked" : "";
- $column_data{active} =
- qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
- my $email = ($ref->{email}) ? "checked" : "";
- $column_data{email} =
- qq|<td><input type=checkbox name=email_$i value=1 $email><button type="button" onclick="set_email_window('email_subject_$i', 'email_body_$i', 'email_attachment_$i')">| . $locale->text('L') . qq|</button><input type=hidden name=email_body_$i value="$ref->{email_body}"><input type=hidden name=email_subject_$i value="$ref->{email_subject}"><input type=hidden name=email_attachment_$i value="$ref->{email_attachment}"></td>|;
-
- my $auto = ($ref->{auto}) ? "checked" : "";
- $column_data{auto} =
- qq|<td><input type=checkbox name=auto_$i value=1 $auto></td>|;
- $column_data{payment_terms} = qq|<td><input name=payment_terms_$i size=3 value="$ref->{payment_terms}"></td>|;
- $column_data{terms} = qq|<td><input name=terms_$i size=3 value="$ref->{terms}"></td>|;
- $column_data{fee} = qq|<td><input name=fee_$i size=5 value="$ref->{fee}"></td>|;
- $column_data{interest_rate} = qq|<td><input name=interest_rate_$i size=4 value="$ref->{interest}">%</td>|;
- $column_data{template} = qq|<td><input name=template_$i value="$ref->{template}"></td>|;
-
-
-
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
- }
- $i++;
- my $j = $i % 2;
-
- print qq|
- <tr valign=top class=listrow$j>
-|;
-
-
- $column_data{dunning_level} =
- qq|<td><input type=hidden size=2 name=dunning_level_$i value=$i>$i</td>|;
- $column_data{dunning_description} = qq|<td><input name=dunning_description_$i ></td>|;
- $column_data{active} =
- qq|<td><input type=checkbox name=active_$i value=1></td>|;
- my $email = "";
- $column_data{email} =
- qq|<td><input type=checkbox name=email_$i value=1 $email><button type="button" onclick="set_email_window('email_subject_$i', 'email_body_$i', 'email_attachment_$i')">| . $locale->text('L') . qq|</button><input type=hidden name=email_body_$i><input type=hidden name=email_subject_$i><input type=hidden name=email_attachment_$i></td>|;
- my $auto = "";
- $column_data{auto} =
- qq|<td><input type=checkbox name=auto_$i value=1 $auto></td>|;
- $column_data{payment_terms} = qq|<td><input size=3 name=payment_terms_$i></td>|;
- $column_data{terms} = qq|<td><input size=3 name=terms_$i></td>|;
- $column_data{fee} = qq|<td><input size=5 name=fee_$i></td>|;
- $column_data{interest_rate} = qq|<td><input size=4 name=interest_rate_$i>%</td>|;
- $column_data{template} = qq|<td><input name=template_$i></td>|;
-
-
- $form->{rowcount} = $i;
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
-
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<br>
-<form method=post action=$form->{script}>
-
-<input name=callback type=hidden value="$form->{callback}">
-<input name=rowcount type=hidden value="$form->{rowcount}">
-
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
-<input class=submit type=submit name=action value="|
- . $locale->text('Save') . qq|">
-
- </form>
-
- </body>
- </html>
-|;
+ $form->header();
+ print $form->parse_html_template("dunning/edit_config");
$lxdebug->leave_sub();
}
sub add {
$lxdebug->enter_sub();
+
# setup customer selection
$form->all_vc(\%myconfig, "customer", "AR");
DN->get_config(\%myconfig, \%$form);
- if (@{ $form->{all_customer} }) {
- map { $customer .= "<option>$_->{name}--$_->{id}\n" }
- @{ $form->{all_customer} };
- $customer = qq|<select name=customer><option>\n$customer</select>|;
- } else {
- $customer = qq|<input name=customer size=35>|;
- }
-
- # dunning levels
- if (@{ $form->{DUNNING} }) {
- $form->{selectdunning_level} = "<option></option\n";
- map {
- $form->{selectdunning_level} .=
- "<option value=$_->{id}>$_->{dunning_description}</option>\n"
- } (@{ $form->{DUNNING} });
- }
- $dunning_level = qq|
- <tr>
- <th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
- <td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
- </tr>
- | if $form->{selectdunning_level};
-
- # departments
- if (@{ $form->{all_departments} }) {
- $form->{selectdepartment} = "<option>\n";
- map {
- $form->{selectdepartment} .=
- "<option>$_->{description}--$_->{id}\n"
- } (@{ $form->{all_departments} });
- }
- $department = qq|
- <tr>
- <th align=right nowrap>| . $locale->text('Department') . qq|</th>
- <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
- </tr>
- | if $form->{selectdepartment};
-
- $form->{title} = $locale->text('Start Dunning Process');
- $form->{nextsub} = "show_invoices";
+ $form->{SHOW_CUSTOMER_SELECTION} = $form->{all_customer} && scalar @{ $form->{all_customer} };
+ $form->{SHOW_DUNNING_LEVEL_SELECTION} = $form->{DUNNING} && scalar @{ $form->{DUNNING} };
+ $form->{SHOW_DEPARTMENT_SELECTION} = $form->{all_departments} && scalar @{ $form->{all_departments} };
- $form->{jsscript} = 1;
- $form->{fokus} = "search.customer";
- $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
+ $form->{title} = $locale->text('Start Dunning Process');
+ $form->{jsscript} = 1;
+ $form->{fokus} = "search.customer";
$form->header();
- $onload = qq|focus()|;
- $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
- $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
-
- print qq|
-<body onLoad="$onload">
-
-<form method=post name="search" action=$form->{script}>
-
-<table width=100%>
- <tr><th class=listtop>$form->{title}</th></tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right>| . $locale->text('Customer') . qq|</th>
- <td colspan=3>$customer</td>
- </tr>
- $dunning_level
- $department
- <tr>
- <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
- <td colspan=3><input name=invnumber size=20></td>
- </tr>
- <tr>
- <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
- <td colspan=3><input name=ordnumber size=20></td>
- </tr>
- <tr>
- <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
- <td colspan=3><input name=notes size=40></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right nowrap>| . $locale->text('Minimum Amount') . qq|</th>
- <td><input name=minamount size=6></td>
- </tr>
- <tr>
- <th align=right nowrap>| . $locale->text('Group Invoices') . qq|</th>
- <td><input type=checkbox value=1 name=groupinvoices checked></td>
- </tr>
- </table>
- </td>
- </tr>
-</table>
-
-<input type=hidden name=nextsub value=$form->{nextsub}>
-
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
-<br>
-<input class=submit type=submit name=action value="|
- . $locale->text('Continue') . qq|">
-
-</form>
-
-</body>
-
-$jsscript
-
-</html>
-|;
+ print $form->parse_html_template("dunning/add");
$lxdebug->leave_sub();
-
}
sub show_invoices {
DN->get_invoices(\%myconfig, \%$form);
$form->{title} = $locale->text('Start Dunning Process');
- if (@{ $form->{DUNNING_CONFIG} }) {
- foreach $item (@{ $form->{DUNNING_CONFIG} }) {
- $form->{selectdunning} .=
- "<option value=$item->{id}>$item->{dunning_description}</option>";
- }
- }
-
-
- $form->{nextsub} = "save_dunning";
-
- $form->{jsscript} = 1;
- $form->{javascript} .= qq|<script type="text/javascript" src="js/checkbox_utils.js"></script>|;
-
- $form->{callback} =
- "$form->{script}?action=show_invoices&login=$form->{login}&password=$form->{password}&customer=$form->{customer}&invnumber=$form->{invnumber}&ordnumber=$form->{ordnumber}&paymentuntil=$form->{paymentuntil}&groupinvoices=$form->{groupinvoices}&minamount=$form->{minamount}&dunning_level=$form->{dunning_level}¬es=$form->{notes}"
- unless $form->{callback};
-
- @column_index = qw(dunning_description dunning_description_next active email customername invnumber invdate inv_duedate amount next_duedate fee interest );
+ foreach my $row (@{ $form->{DUNNINGS} }) {
+ $row->{DUNNING_CONFIG} = [ map +{ %{ $_ } }, @{ $form->{DUNNING_CONFIG} } ];
- $column_header{dunning_description} =
- qq|<th class="listheading" colspan="2">|
- . $locale->text('Current / Next Level')
- . qq|</th>|;
- $column_header{active} =
- qq|<th class=listheading>|
- . NTI($cgi->checkbox('-name' => 'selectall_active',
- '-label' => $locale->text('Active?'),
- '-checked' => 0,
- '-onclick' => "checkbox_check_all('selectall_active', 'active_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
- . qq|</th>|;
- $column_header{email} =
- qq|<th class=listheading>|
- . NTI($cgi->checkbox('-name' => 'selectall_email',
- '-label' => $locale->text('eMail?'),
- '-checked' => 0,
- '-onclick' => "checkbox_check_all('selectall_email', 'email_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
- . qq|</th>|;
- $column_header{customername} =
- qq|<th class=listheading>|
- . $locale->text('Customername')
- . qq|</th>|;
- $column_header{invnumber} =
- qq|<th class=listheading>|
- . $locale->text('Invno.')
- . qq|</th>|;
- $column_header{inv_duedate} =
- qq|<th class=listheading>|
- . $locale->text('Inv. Duedate')
- . qq|</th>|;
- $column_header{next_duedate} =
- qq|<th class=listheading>|
- . $locale->text('Dunning Duedate')
- . qq|</th>|;
- $column_header{invdate} =
- qq|<th class=listheading>|
- . $locale->text('Invdate')
- . qq|</th>|;
- $column_header{amount} =
- qq|<th class=listheading>|
- . $locale->text('Amount')
- . qq|</th>|;
- $column_header{fee} =
- qq|<th class=listheading>|
- . $locale->text('Total Fees')
- . qq|</th>|;
- $column_header{interest} =
- qq|<th class=listheading>|
- . $locale->text('Interest')
- . qq|</th>|;
-
- $form->header;
-
-
- print qq|
-<body>
-<script type="text/javascript" src="js/common.js"></script>
-<script type="text/javascript" src="js/dunning.js"></script>
-<form name=Form method=post action=$form->{script}>
-
-
-<table width=100%>
- <tr>
- <th class=listtop colspan=12>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>|;
- map { print "$column_header{$_}\n" if $column_header{$_}; } @column_index;
-
- print qq|
- </tr>
-|;
- my $i = 0;
- foreach $ref (@{ $form->{DUNNINGS} }) {
-
- $i++;
- my $j = $i % 2;
-
- print qq|
- <tr valign=top class=listrow$j>
-|;
-
- $form->{selectdunning} =~ s/ selected//g;
- if ($ref->{next_dunning_config_id} ne "") {
- $form->{selectdunning} =~ s/value=$ref->{next_dunning_config_id}/value=$ref->{next_dunning_config_id} selected/;
+ if ($row->{next_dunning_config_id}) {
+ map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } };
}
-
- $column_data{dunning_description} =
- qq|<td>|
- . qq|<input type=hidden name=inv_id_$i size=2 value="$ref->{id}">|
- . qq|<input type=hidden name=customer_id_$i size=2 value="$ref->{customer_id}">|
- . ($ref->{dunning_level} ? $ref->{dunning_level} : " ")
- . qq|</td>|;
- $column_data{dunning_description_next} =
- qq|<td>|
- . qq|<select name=next_dunning_config_id_$i>$form->{selectdunning}</select>|
- . qq|</td>|;
- my $active = ($ref->{active}) ? "checked" : "";
- $column_data{active} =
- qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
- my $email = ($ref->{email}) ? "checked" : "";
- $column_data{email} =
- qq|<td><input type=checkbox name=email_$i value=1 $email></td>|;
- $column_data{next_duedate} = qq|<td>$ref->{next_duedate}</td>|;
-
- $column_data{inv_duedate} = qq|<td><input type=hidden name=inv_duedate_$i size=6 value="$ref->{duedate}">$ref->{duedate}</td>|;
- $column_data{invdate} = qq|<td><input type=hidden name=invdate_$i size=6 value="$ref->{transdate}">$ref->{transdate}</td>|;
- $column_data{invnumber} = qq|<td><input type=hidden name=invnumber_$i size=6 value="$ref->{invnumber}">$ref->{invnumber}</td>|;
- $column_data{customername} = qq|<td><input type=hidden name=customername_$i size=6 value="$ref->{customername}">$ref->{customername}</td>|;
-
- map { $column_data{$_} =
- qq|<td align="right">|
- . H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2))
- . qq|</td>|
- } qw(amount fee interest);
-
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
+ map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount fee interest);
}
- $form->{rowcount} = $i;
-
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>|;
- print_options();
- print qq|
-<br>
-<form method=post action=$form->{script}>
-
-<input name=callback type=hidden value="$form->{callback}">
-<input name=rowcount type=hidden value="$form->{rowcount}">
-<input name=nextsub type=hidden value="$form->{nextsub}">
-<input name=groupinvoices type=hidden value="$form->{groupinvoices}">
-
+ $form->{rowcount} = scalar @{ $form->{DUNNINGS} };
+ $form->{jsscript} = 1;
+ $form->{callback} ||= build_std_url("action=show_invoices", qw(login password customer invnumber ordnumber groupinvoices minamount dunning_level notes));
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-<input type="hidden" name="action">
-<input type="submit" name="dummy" value="|
- . $locale->text('Continue') . qq|" onclick="this.disabled=true; this.value='| . $locale->text("The dunning process started") . qq|'; document.Form.action.value='| . $locale->text('Continue') . qq|'; document.Form.submit()">
-
- </form>
-
- </body>
- </html>
-|;
+ $form->{PRINT_OPTIONS} = print_options(1);
+ $form->header();
+ print $form->parse_html_template("dunning/show_invoices");
$lxdebug->leave_sub();
-
}
sub save {