Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d94f14be

Von Bernd Bleßmann vor fast 3 Jahren hinzugefügt

  • ID d94f14be752b6293190a97fdfd33c12e9b3e57b8
  • Vorgänger 19132371
  • Nachfolger 58186225

Anzahlungs-Rg.: Workflow Anzahlungs-Rg. -> Schluss-Rg.

Unterschiede anzeigen:

bin/mozilla/is.pl
36 36
use SL::IS;
37 37
use SL::OE;
38 38
use SL::MoreCommon qw(restore_form save_form);
39
use SL::RecordLinks;
40

  
39 41
use Data::Dumper;
40 42
use DateTime;
41 43
use List::MoreUtils qw(any uniq);
......
317 319
    $has_further_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr;
318 320
  }
319 321

  
322
  my $has_final_invoice;
323
  if ($form->{id} && $form->{type} eq "invoice_for_advance_payment") {
324
    my $invoice_obj = SL::DB::Invoice->load_cached($form->{id});
325
    my $lr          = $invoice_obj->linked_records(direction => 'to', to => ['Invoice']);
326
    $has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "invoice" eq $_->invoice_type} @$lr;
327
  }
328

  
320 329
  for my $bar ($::request->layout->get('actionbar')) {
321 330
    $bar->add(
322 331
      action => [
......
408 417
          disabled => !$may_edit_create ? t8('You must not change this invoice.')
409 418
                    : !$form->{id}      ? t8('This invoice has not been posted yet.')
410 419
                    : $has_further_invoice_for_advance_payment ? t8('This invoice has already a further invoice for advanced payment.')
420
                    : $has_final_invoice                       ? t8('This invoice has already a final invoice.')
421
                    :                     undef,
422
          only_if  => $form->{type} eq "invoice_for_advance_payment",
423
        ],
424
        action => [
425
          t8('Final Invoice'),
426
          submit   => [ '#form', { action => "final_invoice" } ],
427
          checks   => [ 'kivi.validate_form' ],
428
          disabled => !$may_edit_create ? t8('You must not change this invoice.')
429
                    : !$form->{id}      ? t8('This invoice has not been posted yet.')
430
                    : $has_further_invoice_for_advance_payment ? t8('This invoice has a further invoice for advanced payment.')
431
                    : $has_final_invoice                       ? t8('This invoice has already a final invoice.')
411 432
                    :                     undef,
412 433
          only_if  => $form->{type} eq "invoice_for_advance_payment",
413 434
        ],
......
1170 1191
  &display_form;
1171 1192
}
1172 1193

  
1194
sub final_invoice {
1195
  my $form     = $main::form;
1196
  my %myconfig = %main::myconfig;
1197

  
1198
  $main::auth->assert('invoice_edit');
1199

  
1200
  # search all related invoices for advance payment
1201
  #
1202
  # (order) -> invoice for adv. payment 1 -> invoice for adv. payment 2 -> invoice for adv. payment 3 -> final invoice
1203
  #
1204
  # we are currently in the last invoice for adv. payment (3 in this example)
1205
  my $invoice_obj      = SL::DB::Invoice->load_cached($form->{id});
1206
  my $links            = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1);
1207
  my @related_invoices = grep {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$links;
1208

  
1209
  push @related_invoices, $invoice_obj;
1210

  
1211
  delete @{ $form }{qw(printed emailed queued invnumber invdate exchangerate forex deliverydate datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno locked)};
1212

  
1213
  $form->{convert_from_ar_ids} = $form->{id};
1214
  $form->{id}                  = '';
1215
  $form->{type}                = 'invoice';
1216
  $form->{title}               = t8('Edit Final Invoice');
1217
  $form->{paidaccounts}        = 1;
1218
  $form->{invdate}             = $form->current_date(\%myconfig);
1219
  my $terms                    = get_payment_terms_for_invoice();
1220
  $form->{duedate}             = $terms ? $terms->calc_date(reference_date => $form->{invdate})->to_kivitendo : $form->{invdate};
1221
  $form->{employee_id}         = SL::DB::Manager::Employee->current->id;
1222
  $form->{forex}               = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
1223
  $form->{exchangerate}        = $form->{forex} if $form->{forex};
1224

  
1225
  foreach my $i (1 .. $form->{"rowcount"}) {
1226
    delete $form->{"id_$i"};
1227
    delete $form->{"invoice_id_$i"};
1228
    delete $form->{"parts_id_$i"};
1229
    delete $form->{"partnumber_$i"};
1230
    delete $form->{"description_$i"};
1231
  }
1232

  
1233
  remove_emptied_rows(1);
1234

  
1235
  my $i = 0;
1236
  foreach my $ri (@related_invoices) {
1237
    foreach my $item (@{$ri->items_sorted}) {
1238
      $i++;
1239
      $form->{"id_$i"}         = $item->parts_id;
1240
      $form->{"partnumber_$i"} = $item->part->partnumber;
1241
      $form->{"discount_$i"}   = $item->discount*100.0;
1242
      $form->{"sellprice_$i"}  = $item->fxsellprice;
1243
      $form->{$_ . "_" . $i}   = $item->$_       for qw(description longdescription qty price_factor_id unit sellprice active_price_source active_discount_source);
1244

  
1245
      $form->{$_ . "_" . $i}   = $form->format_amount(\%myconfig, $form->{$_ . "_" . $i}) for qw(qty sellprice discount);
1246
    }
1247
  }
1248
  $form->{rowcount} = $i;
1249

  
1250
  update();
1251
  $::dispatcher->end_request;
1252
}
1253

  
1173 1254
sub storno {
1174 1255
  $main::lxdebug->enter_sub();
1175 1256

  

Auch abrufbar als: Unified diff