Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 30175d89

Von Philip Reetz vor fast 19 Jahren hinzugefügt

  • ID 30175d8928a88a8b7f224a4515e192e66fa37656
  • Vorgänger 9475cae8
  • Nachfolger 1c4fffbe

Splitbuchungen fuer Kreditoren ergaenzt

Unterschiede anzeigen:

SL/AP.pm
61 61
      : $form->parse_amount($myconfig, $form->{exchangerate});
62 62
  }
63 63

  
64
  for $i (1 .. $form->{rowcount}) {
65
    $form->{AP_amounts}{"amount_$i"} =
66
      (split(/--/, $form->{"AP_amount_$i"}))[0];
67
  }
68
  ($form->{AP_amounts}{payables}) = split(/--/, $form->{APselected});
69
  ($form->{AP}{payables})         = split(/--/, $form->{APselected});
70

  
64 71
  # reverse and parse amounts
65
  for my $i (1 .. 1) {
72
  for my $i (1 .. $form->{rowcount}) {
66 73
    $form->{"amount_$i"} =
67 74
      $form->round_amount(
68 75
                         $form->parse_amount($myconfig, $form->{"amount_$i"}) *
......
77 84
  # taxincluded doesn't make sense if there is no amount
78 85
  $form->{taxincluded} = 0 if ($form->{amount} == 0);
79 86

  
80
  $query =
81
    qq| SELECT c.accno, t.rate FROM chart c, tax t where c.id=t.chart_id AND t.taxkey=$form->{taxkey}|;
82
  $sth = $dbh->prepare($query);
83
  $sth->execute || $form->dberror($query);
84
  ($form->{AP}{"tax"}, $form->{taxrate}) = $sth->fetchrow_array;
85
  $sth->finish;
87
  for $i (1 .. $form->{rowcount}) {
88
    ($form->{"taxkey_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"};
86 89

  
87
  $formtax = $form->parse_amount($myconfig, $form->{"tax"});
88

  
89
  $form->{"tax"} = $form->{amount} * $form->{taxrate};
90
  $form->{"tax"} =
91
    $form->round_amount($form->{"tax"} * $form->{exchangerate}, 2) * -1;
90
    $query =
91
      qq| SELECT c.accno, t.rate FROM chart c, tax t where c.id=t.chart_id AND t.taxkey=$form->{"taxkey_$i"}|;
92
    $sth = $dbh->prepare($query);
93
    $sth->execute || $form->dberror($query);
94
    ($form->{AP_amounts}{"tax_$i"}, $form->{"taxrate_$i"}) =
95
      $sth->fetchrow_array;
96
    $form->{AP_amounts}{"tax_$i"}{taxkey}    = $form->{"taxkey_$i"};
97
    $form->{AP_amounts}{"amount_$i"}{taxkey} = $form->{"taxkey_$i"};
92 98

  
93
  if ($form->{taxcheck}) {
94
    $form->{"tax"} = $formtax * -1;
99
    $sth->finish;
100
    if (!$form->{"korrektur_$i"}) {
101
      if ($form->{taxincluded} *= 1) {
102
        $tax =
103
          $form->{"amount_$i"} -
104
          ($form->{"amount_$i"} / ($form->{"taxrate_$i"} + 1));
105
        $amount = $form->{"amount_$i"} - $tax;
106
        $form->{"amount_$i"} = $form->round_amount($amount, 2);
107
        $diff += $amount - $form->{"amount_$i"};
108
        $form->{"tax_$i"} = $form->round_amount($tax, 2);
109
        $form->{netamount} += $form->{"amount_$i"};
110
      } else {
111
        $form->{"tax_$i"} = $form->{"amount_$i"} * $form->{"taxrate_$i"};
112
        $form->{"tax_$i"} =
113
          $form->round_amount($form->{"tax_$i"} * $form->{exchangerate}, 2);
114
        $form->{netamount} += $form->{"amount_$i"};
115
      }
116
    }
117
    $form->{total_tax} += $form->{"tax_$i"} * -1;
95 118
  }
96 119

  
97
  $form->{total_tax} += ($form->{"tax"} * -1);
98

  
99 120
  # adjust paidaccounts if there is no date in the last row
100 121
  $form->{paidaccounts}-- unless ($form->{"datepaid_$form->{paidaccounts}"});
101 122

  
102 123
  $form->{invpaid} = 0;
124
  $form->{netamount} *= -1;
103 125

  
104 126
  # add payments
105 127
  for my $i (1 .. $form->{paidaccounts}) {
......
115 137
  $form->{invpaid} =
116 138
    $form->round_amount($form->{invpaid} * $form->{exchangerate}, 2);
117 139

  
118
  if ($form->{taxincluded} *= 1) {
119
    for $i (1 .. 1) {
120
      $tax =
121
        $form->{"amount_$i"} - ($form->{"amount_$i"} / ($form->{taxrate} + 1));
122
      if ($form->{taxcheck}) {
123
        $tax = $formtax * -1;
124
      }
125
      $amount = $form->{"amount_$i"} - $tax;
126
      $form->{"amount_$i"} = $form->round_amount($amount, 2);
127
      $diff += $amount - $form->{"amount_$i"};
128
      $form->{tax} = $form->round_amount($tax, 2);
129
      $form->{total_tax} = $form->{tax} * -1;
130
    }
131
    print(STDERR "Steuer $form->{tax}\n");
132
    print(STDERR "TotalSteuer $form->{total_tax}\n");
133

  
134
    # deduct taxes from amount
135
    # $form->{amount} -= $form->{total_tax};
136
    # deduct difference from amount_1
137
    # $form->{amount_1} += $form->round_amount($diff, 2);
138
    $form->{amount} = $form->{amount_1} * -1;
139
  }
140

  
141
  $form->{netamount} = $form->{amount};
142

  
143 140
  # store invoice total, this goes into ap table
144
  $form->{invtotal} = $form->{amount} + $form->{total_tax};
141
  $form->{invtotal} = $form->{netamount} + $form->{total_tax};
145 142

  
146 143
  # amount for total AP
147 144
  $form->{payables} = $form->{invtotal};
148

  
145
  print(STDERR $form->{payables},
146
        " Payables\n",
147
        $form->{invtotal},
148
        " Invtotal\n",
149
        $form->{netamount},
150
        " Netamount\n",
151
        $form->{total_tax},
152
        " Total_Tax\n\n");
149 153
  my ($query, $sth);
150 154

  
151 155
  # if we have an id delete old records
......
211 215
  }
212 216

  
213 217
  # add individual transactions
214
  foreach my $item (keys %{ $form->{AP} }) {
215
    if ($form->{$item} != 0) {
218
  for $i (1 .. $form->{rowcount}) {
219
    if ($form->{"amount_$i"} != 0) {
216 220
      $project_id = 'NULL';
217
      if ($item =~ /amount_/) {
218
        if ($form->{"project_id_$'"} && $form->{"projectnumber_$'"}) {
219
          $project_id = $form->{"project_id_$'"};
221
      if ("amount_$i" =~ /amount_/) {
222
        if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) {
223
          $project_id = $form->{"project_id_$i"};
220 224
        }
221 225
      }
226
      if ("amount_$i" =~ /amount/) {
227
        $taxkey = $form->{AP_amounts}{"amount_$i"}{taxkey};
228
      }
222 229

  
223 230
      # insert detail records in acc_trans
224 231
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
225 232
                                         project_id, taxkey)
226 233
                  VALUES ($form->{id}, (SELECT c.id FROM chart c
227
		                        WHERE c.accno = '$form->{AP}{$item}'),
228
		  $form->{$item}, '$form->{transdate}', $project_id, '$form->{taxkey}')|;
234
                                         WHERE c.accno = '$form->{AP_amounts}{"amount_$i"}'),
235
                    $form->{"amount_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
229 236
      $dbh->do($query) || $form->dberror($query);
230 237

  
238
      if ($form->{"tax_$i"} != 0) {
239

  
240
        # insert detail records in acc_trans
241
        $query =
242
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
243
                                          project_id, taxkey)
244
                    VALUES ($form->{id}, (SELECT c.id FROM chart c
245
                                          WHERE c.accno = '$form->{AP_amounts}{"tax_$i"}'),
246
                    $form->{"tax_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
247
        $dbh->do($query) || $form->dberror($query);
248
      }
249

  
231 250
    }
232 251
  }
233 252

  
253
  # add payables
254
  $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
255
                                      project_id)
256
              VALUES ($form->{id}, (SELECT c.id FROM chart c
257
                                    WHERE c.accno = '$form->{AP_amounts}{payables}'),
258
              $form->{payables}, '$form->{transdate}', $project_id)|;
259
  $dbh->do($query) || $form->dberror($query);
260

  
234 261
  # if there is no amount but a payment record a payable
235 262
  if ($form->{amount} == 0 && $form->{invtotal} == 0) {
236 263
    $form->{payables} = $form->{invpaid};
bin/mozilla/ap.pl
115 115

  
116 116
  $form->{duedate}   = $duedate if $duedate;
117 117
  $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
118
  $form->{rowcount}  = 1;
118 119

  
119 120
  # build the popup menus
120 121
  $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
......
172 173
    $form->{$key} = $form->{"select$key"};
173 174

  
174 175
    # if there is a value we have an old entry
175
    $j = 0;
176
    my $j = 0;
177
    my $k = 0;
178

  
176 179
    for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
177 180

  
178 181
      if ($key eq "AP_paid") {
......
194 197
        $akey = $key;
195 198
        $akey =~ s/AP_//;
196 199

  
197
        if ($key eq "AP_tax") {
200
        if (($key eq "AP_tax") || ($key eq "AR_tax")) {
198 201
          $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
199 202
            "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
200 203
          $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
201 204
            $form->round_amount(
202
             $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate * -1,
203
             2);
205
                  $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
206
                  2);
207

  
204 208
          if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
205 209
            $totaltax +=
206 210
              $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
......
212 216
            $withholdingrate +=
213 217
              $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
214 218
          }
215
          $formtax =
216
            $form->round_amount(
217
                  $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
218
                  2) * -1;
219
          $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
220
          $form->{"tax_$index"} =
221
            $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
222
          $totaltax += $form->{"tax_$index"};
223

  
219 224
        } else {
220
          $form->{"${akey}_$i"} =
225
          $k++;
226
          $form->{"${akey}_$k"} =
221 227
            $form->round_amount(
222 228
                  $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
223 229
                  2);
224 230
          if ($akey eq 'amount') {
231
            $form->{rowcount}++;
225 232
            $form->{"${akey}_$i"} *= -1;
226 233
            $totalamount += $form->{"${akey}_$i"};
227 234
            $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
228
            $form->{rowcount}++;
229
            $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} =
235
            $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
230 236
              "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
231
            $form->{"project_id_$i"} =
237
            $form->{"project_id_$k"} =
232 238
              "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
233 239
          }
234
          $form->{"${key}_$i"} =
240
          $form->{"${key}_$k"} =
235 241
            "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
236 242
          $form->{"select${key}"} =~
237
            /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*\">$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}<\/option>\n)/;
243
            /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}<\/option>\n/;
238 244
          $test = $1;
239
          $form->{"select${key}"} = $1;
245
          $form->{"${key}_$k"} = $1;
240 246
          if ($akey eq 'amount') {
241
            $form->{selecttaxchart} =~
242
              /(<option value=\"$form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^<]*)/;
243
            $form->{selecttaxchart} = $1;
247
            $form->{"taxchart_$k"} = $form->{taxchart};
248
            $form->{"taxchart_$k"} =~
249
              /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^\"]*)/;
250
            $form->{"taxchart_$k"} = $1;
244 251
          }
245 252
        }
246 253
      }
......
253 260
  if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
254 261

  
255 262
    # add tax to amounts and invtotal
256
    for $i (1 .. 1) {
263
    for $i (1 .. $form->{rowcount}) {
257 264
      $taxamount =
258 265
        ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
259 266
      $tax = $form->round_amount($taxamount, 2);
260 267
      $diff                += ($taxamount - $tax);
261
      $form->{"amount_$i"} += $tax;
268
      $form->{"amount_$i"} += $form->{"tax_$i"};
262 269
    }
263 270
    $form->{amount_1} += $form->round_amount($diff, 2);
264 271
  }
265 272

  
266
  # check if calculated is equal to stored
267
  if ($form->{taxincluded} && $form->{taxrate} && $witholdingrate) {
268
    if ($form->{"taxrate"} > 0) {
269
      $taxamount =
270
        $form->round_amount(
271
            ($form->{amount_1} - ($form->{amount_1} / ($form->{taxrate} + 1))),
272
            2);
273
    } else {
274
      $taxamount =
275
        $form->round_amount(
276
            ($totalamount + $totaltax + $totalwithholding) * $withholdingrate /
277
              (1 - $withholdingrate),
278
            2
279
        ) * $form->{"taxrate"} / $withholdingrate;
280
    }
281
  } else {
282
    $taxamount = $totalamount * $form->{"taxrate"};
283
  }
284 273
  $taxamount = $form->round_amount($taxamount, 2);
285
  $form->{tax} = $taxamount;
286 274

  
287
  $form->{tax} = $formtax;
288

  
289
  $form->{invtotal} = $totalamount + $totaltax + $totalwithholding;
290
  $form->{rowcount}++ if $form->{id};
275
  $form->{invtotal} = $totalamount + $totaltax;
291 276

  
292 277
  $form->{locked} =
293 278
    ($form->datetonum($form->{transdate}, \%myconfig) <=
......
307 292
  # type=submit $locale->text('Add Accounts Payables Transaction')
308 293
  # type=submit $locale->text('Edit Accounts Payables Transaction')
309 294

  
295
  $form->{javascript} = qq|<script type="text/javascript">
296
  <!--
297
  function setTaxkey(accno, row) {
298
    var taxkey = accno.options[accno.selectedIndex].value;
299
    var reg = /--([0-9])*/;
300
    var found = reg.exec(taxkey);
301
    var index = found[1];
302
    index = parseInt(index);
303
    var tax = 'taxchart_' + row;
304
    for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
305
      var reg2 = new RegExp("^"+ index, "");
306
      if (reg2.exec(document.getElementById(tax).options[i].value)) {
307
        document.getElementById(tax).options[i].selected = true;
308
        break;
309
      }
310
    }
311
  };
312
  //-->
313
  </script>|;
314

  
310 315
  # set option selected
311 316
  foreach $item (qw(vendor currency department)) {
312 317
    $form->{"select$item"} =~ s/ selected//;
......
317 322

  
318 323
  $form->{radier} =
319 324
    ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
320
  $readonly = ($form->{radier}) ? "" : $readonly;
321

  
322
  map { $form->{$_} =~ s/\"/&quot;/g } qw(AP_amount AP taxchart);
325
  $readonly                 = ($form->{radier}) ? "" : $readonly;
326
  $selectAP_amount_unquoted = $form->{selectAP_amount};
327
  $taxchart                 = $form->{taxchart};
328
  map { $form->{$_} =~ s/\"/&quot;/g }
329
    qw(AP_amount selectAP_amount AP taxchart);
323 330

  
324 331
  # format amounts
325 332
  $form->{exchangerate} =
......
355 362
            <tr>
356 363
              <td align=right><input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td>
357 364
              <th align=left nowrap>|
358
    . $locale->text('Tax Included')
359
    . qq|</th>
365
    . $locale->text('Tax Included') . qq|</th>
360 366
            </tr>
361 367
|;
362 368

  
......
391 397
    $button1 = qq|
392 398
       <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}> $readonly</td>
393 399
       <td><input type=button name=transdate id="trigger1" value=|
394
      . $locale->text('button')
395
      . qq|></td>
400
      . $locale->text('button') . qq|></td>
396 401
       |;
397 402
    $button2 = qq|
398 403
       <td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}> $readonly</td>
399 404
       <td><input type=button name=duedate id="trigger2" value=|
400
      . $locale->text('button')
401
      . qq|></td></td>
405
      . $locale->text('button') . qq|></td></td>
402 406
     |;
403 407

  
404 408
    #write Trigger
......
497 501
      </table>
498 502
    </td>
499 503
  </tr>
504

  
505

  
506

  
507
$jsscript
508
  <input type=hidden name=selectAP_amount value="$form->{selectAP_amount}">
500 509
  <input type=hidden name=AP_amount value="$form->{AP_amount}">
501 510
  <input type=hidden name=taxchart value="$form->{taxchart}">
502 511
  <input type=hidden name=rowcount value=$form->{rowcount}>
503 512
  <tr>
504
    <td>
505
      <table width=100%>
506

  
507
$jsscript
513
      <td>
514
          <table width=100%>
515
	   <tr class=listheading>
516
	  <th class=listheading style="width:15%">|
517
    . $locale->text('Account') . qq|</th>
518
	  <th class=listheading style="width:10%">|
519
    . $locale->text('Amount') . qq|</th>
520
          <th class=listheading style="width:10%">|
521
    . $locale->text('Tax') . qq|</th>
522
          <th class=listheading style="width:5%">|
523
    . $locale->text('Korrektur') . qq|</th>
524
          <th class=listheading style="width:10%">|
525
    . $locale->text('Taxkey') . qq|</th>
526
          <th class=listheading style="width:10%">|
527
    . $locale->text('Project') . qq|</th>
528
	</tr>
508 529
|;
509 530

  
510 531
  $amount  = $locale->text('Amount');
511 532
  $project = $locale->text('Project');
512 533

  
513
  for $i (1 .. 1) {
514

  
515
    #     $form->{"selectAP_amount"} =~ s/ selected//;
516
    #     $form->{"selectAP_amount"} =~ s/option>\Q$form->{"AP_amount_$i"}\E/option selected>$form->{"AP_amount_$i"}/;
534
  for $i (1 .. $form->{rowcount}) {
517 535

  
518 536
    # format amounts
519 537
    $form->{"amount_$i"} =
520 538
      $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
539
    $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
540
    $selectAP_amount = $selectAP_amount_unquoted;
541
    $selectAP_amount =~
542
      s/option value=\"$form->{"AP_amount_$i"}\"/option value=\"$form->{"AP_amount_$i"}\" selected/;
543
    $tax          = $taxchart;
544
    $tax_selected = $form->{"taxchart_$i"};
545
    $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
546
    $tax =
547
      qq|<td><select id="taxchart_$i" name="taxchart_$i">$tax</select></td>|;
521 548

  
522 549
    print qq|
523 550
	<tr>
524
	  <th align=right nowrap>$amount</th>
525
	  <td><input name="amount_$i" size=10 value=$form->{"amount_$i"} $readonly></td>
526
	  <th>$project</th>
551
          <td width=50%><select name="AP_amount_$i">$selectAP_amount</select></td>
552
          <td><input name="amount_$i" onChange="setTaxkey(this, $i)" size=10 value=$form->{"amount_$i"}></td>
553
          <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
554
          <td><input type="checkbox" name="korrektur_$i" value="1"></td>
555
          $tax
527 556
	  <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
528 557
	      <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
529 558
	      <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
530
	  <td width=50%><select  name="AP_amountselected">$form->{selectAP_amount}</select></td>
531 559
	</tr>
532 560
|;
533 561
    $amount  = "";
......
539 567
    ? $locale->text('Tax Included')
540 568
    : $locale->text('Tax');
541 569

  
542
  # format and reverse tax
543
  $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
570
  $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
544 571

  
545 572
  print qq|
546 573
        <tr>
547
	  <th align=right nowrap>${taxlabel}</th>
548
	  <td><input name="tax" size=10 value=$form->{"tax"} $readonly></td>
549
	  <td align=right><input name=taxcheck class=checkbox type=checkbox value=1></td>
550
          <td align=left nowrap>| . $locale->text('Correct Tax') . qq|</td>
551
	  <td><select name=taxchartselected>$form->{"selecttaxchart"}</select></td>
574
          <td colspan=6>
575
            <hr noshade>
576
          </td>
552 577
        </tr>
553
|;
554

  
555
  $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
556

  
557
  print qq|
558 578
        <tr>
559
	  <th align=right nowrap>| . $locale->text('Total') . qq|</th>
560
	  <td>$form->{invtotal}</td>
579
	  <td><select name=APselected>$form->{selectAP}</select></td>
580
          <input type=hidden name=AP value="$form->{AP}">
581
	  <th align=left>$form->{invtotal}</th>
561 582

  
562 583
	  <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
563 584
	  <input type=hidden name=oldtotalpaid value=$form->{oldtotalpaid}>
564 585

  
565 586
	  <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
566 587

  
567
	  <td colspan=2></td>
568
          <td><select name=APselected>$form->{selectAP}</select></td>
569
	  <input type=hidden name=AP value="$form->{AP}">
588
	  <td colspan=4></td>
570 589

  
571
	</tr>
572
	<tr>
573
	  <th align=right nowrap>| . $locale->text('Notes') . qq|</th>
574
	  <td colspan=5>$notes</td>
590

  
591
        </tr>
592
        </table>
593
        </td>
594
    </tr>
595
    <tr>
596
      <td>
597
        <table width=100%>
598
        <tr>
599
	  <th align=left width=1%>| . $locale->text('Notes') . qq|</th>
600
	  <td align=left>$notes</td>
575 601
	</tr>
576 602
      </table>
577 603
    </td>
......
746 772

  
747 773
  $form->{invtotal} = 0;
748 774

  
749
  $form->{selectAP_amount} = $form->{AP_amount};
750
  $form->{selectAP_amount} =~
751
    s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
775
  #   $form->{selectAP_amount} = $form->{AP_amount};
776
  #   $form->{selectAP_amount} =~
777
  #     s/value=\"$form->{AP_amountselected}\"/value=\"$form->{AP_amountselected}\" selected/;
752 778

  
753 779
  $form->{selectAP} = $form->{AP};
754 780
  $form->{selectAP} =~
......
767 793

  
768 794
  @flds  = qw(amount AP_amount projectnumber oldprojectnumber project_id);
769 795
  $count = 0;
770
  for $i (1 .. 1) {
796
  for $i (1 .. $form->{rowcount}) {
771 797
    $form->{"amount_$i"} =
772 798
      $form->parse_amount(\%myconfig, $form->{"amount_$i"});
799
    $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
773 800
    if ($form->{"amount_$i"}) {
774 801
      push @a, {};
775
      my $j = $#a;
802
      $j = $#a;
803
      if (!$form->{"korrektur_$i"}) {
804
        ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
805
        if ($taxkey > 1) {
806
          if ($form->{taxincluded}) {
807
            $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
808
          } else {
809
            $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
810
          }
811
        } else {
812
          $form->{"tax_$i"} = 0;
813
        }
814
      }
815
      $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
816

  
817
      $totaltax += $form->{"tax_$i"};
776 818
      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
777 819
      $count++;
778 820
    }
779 821
  }
780 822
  $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
781 823

  
782
  $form->{invtotal} += $form->{"amount_1"};
824
  map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
783 825

  
784 826
  $form->{exchangerate} = $exchangerate
785 827
    if (
......
795 837
  $form->{AP} = $save_AP;
796 838

  
797 839
  &check_project;
798

  
799
TAXCALC:
800

  
801
  # recalculate taxes
802

  
803
  @taxaccounts = split / /, $form->{taxaccounts};
804

  
805
  $form->{"tax"} = $form->parse_amount(\%myconfig, $form->{"tax"});
806

  
807
  if ($form->{taxincluded} && $form->{"rate"}) {
808
    $taxrate         = $form->{"rate"};
809
    $withholdingrate = 0;
810

  
811
    $amount =
812
      $form->round_amount(
813
                    ($form->{invtotal} - ($form->{invtotal} / ($taxrate + 1))),
814
                    2);
815
    $form->{"tax"} = $form->round_amount($amount, 2);
816
    $taxdiff += ($amount - $form->{"tax"});
817

  
818
    if (abs $taxdiff >= 0.005) {
819
      $form->{"tax"} += $form->round_amount($taxdiff, 2);
820
      $taxdiff = 0;
821
    }
822
    $totaltax += $form->{"tax"};
823

  
824
  } else {
825
    $form->{"tax"} =
826
      $form->round_amount($form->{invtotal} * $form->{"rate"}, 2);
827
    $totaltax += $form->{"tax"};
828

  
829
  }
840
  $form->{rowcount} = $count + 1;
830 841

  
831 842
  $form->{invtotal} =
832 843
    ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
......
1019 1030
    $button1 = qq|
1020 1031
       <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1021 1032
       <input type=button name=transdatefrom id="trigger1" value=|
1022
      . $locale->text('button')
1023
      . qq|></td>
1033
      . $locale->text('button') . qq|></td>
1024 1034
      |;
1025 1035
    $button2 = qq|
1026 1036
       <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1027 1037
       <input type=button name=transdateto name=transdateto id="trigger2" value=|
1028
      . $locale->text('button')
1029
      . qq|></td>
1038
      . $locale->text('button') . qq|></td>
1030 1039
     |;
1031 1040

  
1032 1041
    #write Trigger
......
1241 1250
    $option   .= $locale->text('Closed');
1242 1251
  }
1243 1252

  
1244
  @columns =
1245
    $form->sort_columns(
1253
  @columns = $form->sort_columns(
1246 1254
    qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee)
1247
    );
1255
  );
1248 1256

  
1249 1257
  foreach $item (@columns) {
1250 1258
    if ($form->{"l_$item"} eq "Y") {

Auch abrufbar als: Unified diff