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:

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