Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 72e545d6

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

  • ID 72e545d62bd1eb0d65e9afc0c05b97306864a15a
  • Vorgänger 07e01856
  • Nachfolger 515da96f

Anzahlungs-Rg.: Workflow vom Auftrag: alle Anzahlugns-Rg. und Schluss-Rg.

Wird der Workflow vom Auftrag aus begonnen, so werden alle Anzahlungs- und
die Schlussrechnung vom Auftrag aus gemacht.
Der Einstieg über eine Anzahlungs-Rg. und dann der Workflow
"weitere Anzahlungs-Rg." (...) und hieraus Schluss-Rg. bleibt bestehen.

Unterschiede anzeigen:

SL/Controller/Order.pm
57 57
__PACKAGE__->run_before('check_auth');
58 58

  
59 59
__PACKAGE__->run_before('recalc',
60
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_ap_transaction
60
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
61 61
                                     print send_email) ]);
62 62

  
63 63
__PACKAGE__->run_before('get_unalterable_data',
64
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_ap_transaction
64
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
65 65
                                     print send_email) ]);
66 66

  
67 67
#
......
698 698
  );
699 699
}
700 700

  
701
sub action_save_and_final_invoice {
702
  my ($self) = @_;
703

  
704
  $self->save_and_redirect_to(
705
    controller       => 'oe.pl',
706
    action           => 'oe_invoice_from_order',
707
    new_invoice_type => 'final_invoice',
708
  );
709
}
710

  
701 711
# workflow from sales order to sales quotation
702 712
sub action_sales_quotation {
703 713
  $_[0]->workflow_sales_or_request_for_quotation();
......
1990 2000
    $has_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr;
1991 2001
  }
1992 2002

  
2003
  my $has_final_invoice;
2004
  if ($self->order->id && $self->type eq sales_order_type()) {
2005
    my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']);
2006
    $has_final_invoice               = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr;
2007
  }
2008

  
1993 2009
  for my $bar ($::request->layout->get('actionbar')) {
1994 2010
    $bar->add(
1995 2011
      combobox => [
......
2057 2073
          ],
2058 2074
        ],
2059 2075
        action => [
2060
          t8('Save and Invoice for Advance Payment'),
2076
          ($has_invoice_for_advance_payment ? t8('Save and Further Invoice for Advance Payment') : t8('Save and Invoice for Advance Payment')),
2061 2077
          call      => [ 'kivi.Order.save', 'save_and_invoice_for_advance_payment', $::instance_conf->get_order_warn_duplicate_parts ],
2062 2078
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2063 2079
                         @req_trans_cost_art, @req_cusordnumber,
2064 2080
          ],
2065
          disabled  => $has_invoice_for_advance_payment ? t8('This order has already an invoice for advanced payment.')
2066
                                                        : undef,
2081
          disabled  => $has_final_invoice ? t8('This order has already a final invoice.')
2082
                                          : undef,
2067 2083
          only_if   => (any { $self->type eq $_ } (sales_order_type())),
2068 2084
        ],
2085
        action => [
2086
          t8('Save and Final Invoice'),
2087
          call      => [ 'kivi.Order.save', 'save_and_final_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
2088
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2089
                         @req_trans_cost_art, @req_cusordnumber,
2090
          ],
2091
          disabled  => $has_final_invoice ? t8('This order has already a final invoice.')
2092
                                          : undef,
2093
          only_if   => (any { $self->type eq $_ } (sales_order_type())) && $has_invoice_for_advance_payment,
2094
        ],
2069 2095
        action => [
2070 2096
          t8('Save and AP Transaction'),
2071 2097
          call      => [ 'kivi.Order.save', 'save_and_ap_transaction', $::instance_conf->get_order_warn_duplicate_parts ],
SL/IS.pm
578 578
  $form->{username} = $myconfig->{name};
579 579
  $form->{$_} = $form->format_amount($myconfig, $form->{$_}, 2) for @separate_totals;
580 580

  
581
  foreach my $invoice_for_advance_payment (@{$self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id})}) {
581
  my $id_for_iap = $form->{convert_from_oe_ids} || $form->{convert_from_ar_ids} || $form->{id};
582
  my $from_order = !!$form->{convert_from_oe_ids};
583
  foreach my $invoice_for_advance_payment (@{$self->_get_invoices_for_advance_payment($id_for_iap, $from_order)}) {
582 584
    # Collect VAT of invoices for advance payment.
583 585
    # Set sellprices to fxsellprices for items, because
584 586
    # the PriceTaxCalculator sets fxsellprice from sellprice before calculating.
......
1090 1092

  
1091 1093
  my $iap_amounts;
1092 1094
  if ($form->{type} eq 'final_invoice') {
1093
    my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id});
1095
    my $id_for_iap = $form->{convert_from_oe_ids} || $form->{convert_from_ar_ids} || $form->{id};
1096
    my $from_order = !!$form->{convert_from_oe_ids};
1097
    my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($id_for_iap, $from_order);
1094 1098
    if (scalar @$invoices_for_advance_payment > 0) {
1095 1099
      # reverse booking for invoices for advance payment
1096 1100
      foreach my $invoice_for_advance_payment (@$invoices_for_advance_payment) {
......
1587 1591
}
1588 1592

  
1589 1593
sub _get_invoices_for_advance_payment {
1590
  my ($self, $id) = @_;
1594
  my ($self, $id, $id_is_from_order) = @_;
1591 1595

  
1592 1596
  return [] if !$id;
1593 1597

  
1594
  my $invoice_obj      = SL::DB::Invoice->new(id => $id*1)->load;
1595
  my $links            = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1);
1598
  # Search all related invoices for advance payment.
1599
  # Case 1:
1600
  # (order) -> invoice for adv. payment 1 -> invoice for adv. payment 2 -> invoice for adv. payment 3 -> final invoice
1601
  #
1602
  # Case 2:
1603
  # order -> invoice for adv. payment 1
1604
  #   | |`-> invoice for adv. payment 2
1605
  #   | `--> invoice for adv. payment 3
1606
  #   `----> final invoice
1607
  #
1608
  # The id is currently that from the last invoice for adv. payment (3 in this example),
1609
  # that from the final invoice or that from the order.
1610

  
1611
  my $invoice_obj;
1612
  my $order_obj;
1613
  my $links;
1614

  
1615
  if (!$id_is_from_order) {
1616
    $invoice_obj = SL::DB::Invoice->load_cached($id*1);
1617
    $links       = $invoice_obj->linked_records(direction => 'from', from => ['Order']);
1618
    $order_obj   = $links->[0];
1619
  } else {
1620
    $order_obj   = SL::DB::Order->load_cached($id*1);
1621
  }
1622

  
1623
  if ($order_obj) {
1624
    $links        = $order_obj  ->linked_records(direction => 'to',   to => ['Invoice']);
1625
  } else {
1626
    $links        = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1);
1627
  }
1628

  
1596 1629
  my @related_invoices = grep {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$links;
1597 1630

  
1598
  push @related_invoices, $invoice_obj if "invoice_for_advance_payment" eq $invoice_obj->type;
1631
  push @related_invoices, $invoice_obj if !$order_obj && "invoice_for_advance_payment" eq $invoice_obj->type;
1599 1632

  
1600 1633
  return \@related_invoices;
1601 1634
}
......
2109 2142

  
2110 2143
  # if we delete a final invoice, the reverse bookings for the clearing account in the invoice for advance payment
2111 2144
  # must be deleted as well
2112
  my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id});
2145
  my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{id});
2113 2146

  
2114 2147
  # Todo: allow only if invoice for advance payment is not paid.
2115 2148
  # die if any { $_->paid } for @$invoices_for_advance_payment;
bin/mozilla/is.pl
336 336
    $has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->invoice_type} @$lr;
337 337
  }
338 338

  
339
  my $is_invoice_for_advance_payment_from_order;
340
  if ($form->{id} && $form->{type} eq "invoice_for_advance_payment") {
341
    my $invoice_obj = SL::DB::Invoice->load_cached($form->{id});
342
    my $lr          = $invoice_obj->linked_records(direction => 'from', from => ['Order']);
343
    $is_invoice_for_advance_payment_from_order = scalar @$lr >= 1;
344
  }
345

  
339 346
  for my $bar ($::request->layout->get('actionbar')) {
340 347
    $bar->add(
341 348
      action => [
......
428 435
                    : !$form->{id}      ? t8('This invoice has not been posted yet.')
429 436
                    : $has_further_invoice_for_advance_payment ? t8('This invoice has already a further invoice for advanced payment.')
430 437
                    : $has_final_invoice                       ? t8('This invoice has already a final invoice.')
438
                    : $is_invoice_for_advance_payment_from_order ? t8('This invoice was added from an order. See there.')
431 439
                    :                     undef,
432 440
          only_if  => $form->{type} eq "invoice_for_advance_payment",
433 441
        ],
......
439 447
                    : !$form->{id}      ? t8('This invoice has not been posted yet.')
440 448
                    : $has_further_invoice_for_advance_payment ? t8('This invoice has a further invoice for advanced payment.')
441 449
                    : $has_final_invoice                       ? t8('This invoice has already a final invoice.')
450
                    : $is_invoice_for_advance_payment_from_order ? t8('This invoice was added from an order. See there.')
442 451
                    :                     undef,
443 452
          only_if  => $form->{type} eq "invoice_for_advance_payment",
444 453
        ],
......
1213 1222

  
1214 1223
  $main::auth->assert('invoice_edit');
1215 1224

  
1216
  # search all related invoices for advance payment
1217
  #
1218
  # (order) -> invoice for adv. payment 1 -> invoice for adv. payment 2 -> invoice for adv. payment 3 -> final invoice
1219
  #
1220
  # we are currently in the last invoice for adv. payment (3 in this example)
1221 1225
  my $related_invoices = IS->_get_invoices_for_advance_payment($form->{id});
1222 1226

  
1223 1227
  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)};
bin/mozilla/oe.pl
1654 1654
    $::dispatcher->end_request;
1655 1655
  }
1656 1656

  
1657
  _oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'billed');
1657
  _oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'billed') if $form->{new_invoice_type} ne 'final_invoice';
1658 1658

  
1659 1659
  $form->{cp_id} *= 1;
1660 1660

  
......
1699 1699

  
1700 1700
  if (   $form->{type} eq 'sales_order'
1701 1701
      || $form->{type} eq 'sales_quotation') {
1702
    $form->{title}  = ($form->{new_invoice_type} eq 'invoice_for_advance_payment')
1703
                    ? $locale->text('Add Invoice for Advance Payment')
1702
    $form->{title}  = ($form->{new_invoice_type} eq 'invoice_for_advance_payment') ? $locale->text('Add Invoice for Advance Payment')
1703
                    : ($form->{new_invoice_type} eq 'final_invoice')               ? $locale->text('Add Final Invoice')
1704 1704
                    : $locale->text('Add Sales Invoice');
1705 1705
    $form->{script} = 'is.pl';
1706 1706
    $script         = "is";

Auch abrufbar als: Unified diff