Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c9fdd205

Von Jan Büren vor fast 2 Jahren hinzugefügt

  • ID c9fdd2059d2ab6f7802ef76ad65b8eda4f8860db
  • Vorgänger 6919adb8
  • Nachfolger cf07eb6e

Wechselkurse für Belege oder Zahlungen für ar und ap holen und berechnen

Unterschiede anzeigen:

SL/Form.pm
2570 2570
    do_statement($self, $sth, $query, $self->{id});
2571 2571

  
2572 2572
    # get exchangerate for currency
2573
    $self->{exchangerate} =
2574
      $self->check_exchangerate($myconfig, $self->{currency}, $self->{transdate}, $fld);
2573
    ($self->{exchangerate}, $self->{record_forex}) = $self->check_exchangerate($myconfig, $self->{currency}, $self->{transdate}, $fld,
2574
                                                                               $self->{id}, $arap);
2575

  
2575 2576
    my $index = 0;
2576 2577

  
2577 2578
    # store amounts in {acc_trans}{$key} for multiple accounts
2578 2579
    while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
2580
      # credit and debit bookings calc fx rate for positions
2581
      # also used as exchangerate_$i for payments
2579 2582
      $ref->{exchangerate} =
2580 2583
        $self->check_exchangerate($myconfig, $self->{currency}, $ref->{transdate}, $fld);
2581 2584
      if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
bin/mozilla/ap.pl
396 396

  
397 397
  # currencies
398 398
  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
399
  if ($form->{currency} ne $form->{defaultcurrency}) {
400
    ($form->{exchangerate}, $form->{record_forex}) = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, "sell", $form->{id}, 'ap');
399
  if ($form->{currency} ne $form->{defaultcurrency} && !$form->{exchangerate}) {
400
    ($form->{exchangerate}, $form->{record_forex}) = $form->{id}
401
                                                  ?  $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, "sell", $form->{id}, 'ap')
402
                                                  :  $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, "sell");
401 403
  }
402 404

  
403 405
  # format amounts
......
533 535
  $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
534 536

  
535 537
  for my $i (1 .. $form->{paidaccounts}) {
538
    # hook for calc of of fx_paid and check if banktransaction has a record exchangerate
539
    if ($form->{"exchangerate_$i"}) {
540
      my $bt_acc_trans;
541
      my $bt_acc_trans = SL::DB::Manager::BankTransactionAccTrans->find_by(acc_trans_id => $form->{"acc_trans_id_$i"});
542
      if ($bt_acc_trans) {
543
        if ($bt_acc_trans->bank_transaction->exchangerate > 0) {
544
          $form->{"exchangerate_$i"} = $bt_acc_trans->bank_transaction->exchangerate;
545
          $form->{"forex_$i"}        = $form->{"exchangerate_$i"};
546
          $form->{"record_forex_$i"} = 1;
547
        }
548
      }
549
      $form->{"fx_paid_$i"} = $form->{"paid_$i"} / $form->{"exchangerate_$i"};
550
      $form->{"fx_totalpaid"} +=  $form->{"fx_paid_$i"};
551
    } # end hook fx_paid
536 552
    # format amounts
537 553
    if ($form->{"paid_$i"}) {
538 554
      $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
......
567 583
       $form->{'AP_paid_' . $i} . " " . SL::DB::Manager::Chart->find_by(accno => $form->{'AP_paid_' . $i})->description
568 584
     : '';
569 585
  }
570

  
571
  $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid};
586
  $form->{paid_missing} =  $::form->{is_linked_bank_transaction} && $form->{invoice_obj}->forex ?
587
                           $form->{invoice_obj}->open_amount
588
                        :  $form->{invtotal_unformatted} - $form->{totalpaid};
572 589

  
573 590
  $form->{payment_id} = $form->{invoice_obj}->{payment_id} // $form->{payment_id};
574 591
  print $form->parse_html_template('ap/form_header', {
......
1407 1424
                      : $is_linked_bank_transaction                 ? 1
1408 1425
                      : $has_sepa_exports                           ? 1
1409 1426
                      : 0;
1427
  # and is_linked_bank_transaction
1428
  $::form->{is_linked_bank_transaction} = $is_linked_bank_transaction;
1410 1429

  
1411 1430
  my $create_post_action = sub {
1412 1431
    # $_[0]: description
1413 1432
    # $_[1]: after_action
1414 1433
    action => [
1434

  
1415 1435
      $_[0],
1416 1436
      submit   => [ '#form', { action => "post", after_action => $_[1] } ],
1417 1437
      checks   => [ 'kivi.validate_form', 'kivi.AP.check_fields_before_posting', 'kivi.AP.check_duplicate_invnumber' ],
bin/mozilla/ar.pl
476 476

  
477 477
  my @payments;
478 478
  for my $i (1 .. $form->{paidaccounts}) {
479
    # hook for calc of of fx_paid and check if banktransaction has a record exchangerate
480
    if ($form->{"exchangerate_$i"}) {
481
      my $bt_acc_trans;
482
      my $bt_acc_trans = SL::DB::Manager::BankTransactionAccTrans->find_by(acc_trans_id => $form->{"acc_trans_id_$i"});
483
        if ($bt_acc_trans) {
484
          if ($bt_acc_trans->bank_transaction->exchangerate > 0) {
485
            $form->{"exchangerate_$i"} = $bt_acc_trans->bank_transaction->exchangerate;
486
            $form->{"forex_$i"}        = $form->{"exchangerate_$i"};
487
            $form->{"record_forex_$i"} = 1;
488
          }
489
        }
490
      $form->{"fx_paid_$i"} = $form->{"paid_$i"} / $form->{"exchangerate_$i"};
491
      $form->{"fx_totalpaid"} +=  $form->{"fx_paid_$i"};
492
    } # end hook fx_paid
479 493
    my $payment = {
480 494
      paid             => $form->{"paid_$i"},
481 495
      exchangerate     => $form->{"exchangerate_$i"} || '',
......
485 499
      memo             => $form->{"memo_$i"},
486 500
      AR_paid          => $form->{"AR_paid_$i"},
487 501
      forex            => $form->{"forex_$i"},
502
      record_forex     => $form->{"record_forex_$i"},
488 503
      datepaid         => $form->{"datepaid_$i"},
489 504
      paid_project_id  => $form->{"paid_project_id_$i"},
490 505
      gldate           => $form->{"gldate_$i"},
506
      fx_paid          => $form->{"fx_paid_$i"},
507
      fx_totalpaid     => $form->{"fx_totalpaid_$i"},
491 508
    };
492 509

  
493 510
    # default account for current assets (i.e. 1801 - SKR04) if no account is selected
......
534 551
  );
535 552

  
536 553
  setup_ar_form_header_action_bar();
554
  $::form->{paid_missing} =  $form->{is_linked_bank_transaction} && $form->{invoice_obj}->forex ?
555
                           $form->{invoice_obj}->open_amount
556
                        :  $::form->{invtotal} - $::form->{totalpaid};
537 557

  
538 558
  $form->header;
539 559
  print $::form->parse_html_template('ar/form_header', {
540
    paid_missing         => $::form->{invtotal} - $::form->{totalpaid},
560
    paid_missing         => $::form->{paidmissing},
541 561
    show_exch            => ($::form->{defaultcurrency} && ($::form->{currency} ne $::form->{defaultcurrency})),
542 562
    payments             => \@payments,
543 563
    transactions         => \@transactions,
......
1372 1392

  
1373 1393
  my $is_linked_bank_transaction;
1374 1394
  if ($::form->{id}
1375
      && SL::DB::Default->get->payments_changeable != 0
1376 1395
      && SL::DB::Manager::BankTransactionAccTrans->find_by(ar_id => $::form->{id})) {
1377 1396

  
1378 1397
    $is_linked_bank_transaction = 1;
......
1386 1405
                      : ($::form->{id} && $change_on_same_day_only) ? 1
1387 1406
                      : $is_linked_bank_transaction                 ? 1
1388 1407
                      : 0;
1408
  # and is_linked_bank_transaction
1409
  $::form->{is_linked_bank_transaction} = $is_linked_bank_transaction;
1389 1410
  for my $bar ($::request->layout->get('actionbar')) {
1390 1411
    $bar->add(
1391 1412
      action => [

Auch abrufbar als: Unified diff