Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 70ae535d

Von Jan Büren vor mehr als 2 Jahren hinzugefügt

  • ID 70ae535d2d20cf6838cd95e892bb1f78081d5b01
  • Vorgänger 7a778ade
  • Nachfolger 74c871e5

Unterversionen für Angebote/Aufträge

Versionen werden finalisiert sobald sie per E-Mail rausgeschickt wurden
Danach ist die Bearbeitung gesperrt, aber es ist möglich eine neue
Unterversion des Belegs zu erstellen.
Unterversionen bekommen den Postfix -x, wobei x:= 2 .. n
Die Unterversion wird dann in die Belegnummer übernommen, es wird aber
kein neuer Beleg erstellt. Die alte Version ist über DMS/E-Mail-Journal
noch als PDF erkennbar.

Unterschiede anzeigen:

SL/Controller/Order.pm
47 47
use File::Spec;
48 48
use Cwd;
49 49
use Sort::Naturally;
50
use Try::Tiny;
50 51

  
51 52
use Rose::Object::MakeMethods::Generic
52 53
(
......
62 63
                        except => [ qw(edit show_customer_vendor_details_dialog price_popup load_second_rows) ]);
63 64

  
64 65
__PACKAGE__->run_before('recalc',
65
                        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
66
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment
67
                                     save_and_final_invoice save_and_ap_transaction add_subversion
66 68
                                     print send_email) ]);
67 69

  
68 70
__PACKAGE__->run_before('get_unalterable_data',
69
                        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
71
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment
72
                                     save_and_final_invoice save_and_ap_transaction add_subversion
70 73
                                     print send_email) ]);
71 74

  
72 75
#
......
216 219
  $self->redirect_to(@redirect_params);
217 220
}
218 221

  
219
# save the order as new document an open it for edit
222
# create new version and set version number
223
sub action_add_subversion {
224
  my ($self) = @_;
225

  
226
  try {
227
    my $new_version_number = $self->order->current_version_number + 1;
228

  
229
    if ($self->type eq sales_quotation_type() || $self->type eq request_quotation_type()) {
230
      $self->order->quonumber($self->order->quonumber . '-' . $new_version_number);
231
    } elsif ($self->type eq sales_order_type()|| $self->type eq purchase_order_type()) {
232
      $self->order->quonumber($self->order->quonumber . '-' . $new_version_number);
233
    } else { die "Invalid Call for Sub-Version. Need Order or Quotation."; }
234

  
235
    SL::DB::OrderVersion->new(oe_id   => $self->order->id,
236
                              version => $new_version_number,
237
                             )->save;
238

  
239
  } catch {  die "Could not create sub-version for record with id:" . $self->order->id . " Reason: $_" };
240

  
241
  # call the save action
242
  $self->action_save();
243

  
244
}
245

  
246
# save the order as new document and open it for edit
220 247
sub action_save_as_new {
221 248
  my ($self) = @_;
222 249

  
......
582 609

  
583 610
  $self->save_history('MAILED');
584 611

  
612
  # self is generated on the fly. form is a file from the dms
613
  # TODO: for the case Filesystem and Webdav we want the real file from the filesystem
614
  #       for the nyi case DMS/CMIS we need a gloid or whatever the system offers (elo_id for ELO)
615
  #       DMS kivi version should have a record_link to email_journal
616
  #       the record link has to refer to the correct version -> helper table file <-> file_version
617
  my $file_id = $self->{file_id} || $::form->{file_id};
618
  die "No file id" unless $file_id;
619

  
620
  # $main::lxdebug->message(0, "was wir hier haben" . $self->order->id . " " . $::form->{email_journal_id} . " file id noch frisch " . $self->{file_id});
621

  
622
  # email is sent -> set this version to final and link to journal and file
623
  my $current_version = SL::DB::Manager::OrderVersion->get_all(where => [oe_id => $self->order->id, final_version => 0]);
624
  die "Invalid version state" unless scalar @{ $current_version } == 1;
625
  $current_version->[0]->update_attributes(file_id          => $file_id,
626
                                           email_journal_id => $::form->{email_journal_id},
627
                                           final_version    => 1)->save;
628

  
585 629
  flash_later('info', t8('The email has been sent.'));
586 630

  
587 631
  my @redirect_params = (
......
1911 1955

  
1912 1956
    SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
1913 1957
    $self->order->save(cascade => 1);
1958
    # create first version if none exists
1959
    SL::DB::OrderVersion->new(oe_id => $self->order->id, version => 1)->save unless scalar @{ $self->order->order_version };
1914 1960

  
1915 1961
    # link records
1916 1962
    if ($::form->{converted_from_oe_id}) {
......
2159 2205
  my $right             = $right_for->{ $self->type };
2160 2206
  $right              ||= 'DOES_NOT_EXIST';
2161 2207
  my $may_edit_create   = $::auth->assert($right, 'may fail');
2208
  # VALID States for current Sales Version
2209
  # 1. save create version without email_id             -> open
2210
  # 2. send email set email_id for version 1            -> final
2211
  # 3. save and subversion new version without email_id -> open
2212
  # 4. send email set email_id for current subversion   -> final
2213
  # for all version > 1 set postfix -2 .. -n for recordnumber (don´t compute just use autoincrement db field)
2214
  my $final_sales_version = ($self->order->is_sales && $self->order->id) ? $self->order->is_final_version : undef;
2162 2215

  
2163 2216
  for my $bar ($::request->layout->get('actionbar')) {
2164 2217
    $bar->add(
......
2171 2224
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices', ['kivi.validate_form','#order_form'],
2172 2225
                         @req_trans_cost_art, @req_cusordnumber,
2173 2226
          ],
2174
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2227
          disabled => !$may_edit_create    ? t8('You do not have the permissions to access this function.')
2228
                    : $final_sales_version ? t8('This record is the final version. Please create a new subversion') : undef,
2175 2229
        ],
2176 2230
        action => [
2177 2231
          t8('Save and Close'),
......
2182 2236
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices', ['kivi.validate_form','#order_form'],
2183 2237
                         @req_trans_cost_art, @req_cusordnumber,
2184 2238
          ],
2185
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2239
          disabled => !$may_edit_create       ? t8('You do not have the permissions to access this function.')
2240
                    : $final_sales_version    ? t8('This record is the final version. Please create a new sub-version') : undef,
2241
        ],
2242
        action => [
2243
          t8('Create Sub-Version'),
2244
          call      => [ 'kivi.Order.save', 'add_subversion',
2245
          ],
2246
          disabled => !$may_edit_create     ? t8('You do not have the permissions to access this function.')
2247
                    : !$final_sales_version ? t8('This sub-version is not yet finalized') : undef,
2186 2248
        ],
2187 2249
        action => [
2188 2250
          t8('Save as new'),
......
2298 2360
                                                          $::instance_conf->get_order_warn_no_deliverydate,
2299 2361
                      ],
2300 2362
          checks   => [ @req_trans_cost_art, @req_cusordnumber ],
2301
          disabled => !$may_edit_create  ? t8('You do not have the permissions to access this function.') : undef,
2363
          disabled => !$may_edit_create    ? t8('You do not have the permissions to access this function.')
2364
                    : $final_sales_version ? t8('This record is a final version. Please create a new subversion') : undef,
2302 2365
        ],
2303 2366
        action => [
2304 2367
          t8('Save and print'),
......
2306 2369
                                                         $::instance_conf->get_order_warn_no_deliverydate,
2307 2370
                      ],
2308 2371
          checks   => [ @req_trans_cost_art, @req_cusordnumber ],
2309
          disabled => !$may_edit_create  ? t8('You do not have the permissions to access this function.') : undef,
2372
          disabled => !$may_edit_create    ? t8('You do not have the permissions to access this function.')
2373
                    : $final_sales_version ? t8('This record is a final version. Please create a new subversion') : undef,
2310 2374
        ],
2311 2375
        action => [
2312 2376
          t8('Save and E-mail'),
......
2314 2378
          call     => [ 'kivi.Order.save', 'save_and_show_email_dialog', $::instance_conf->get_order_warn_duplicate_parts,
2315 2379
                                                                         $::instance_conf->get_order_warn_no_deliverydate,
2316 2380
                      ],
2317
          disabled => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2318
                    : !$self->order->id  ? t8('This object has not been saved yet.')
2319
                    :                      undef,
2381
          disabled => !$may_edit_create    ? t8('You do not have the permissions to access this function.')
2382
                    : !$self->order->id    ? t8('This object has not been saved yet.')
2383
                    : $final_sales_version ? t8('This record is a final version. Please create a new subversion') : undef,
2320 2384
        ],
2321 2385
        action => [
2322 2386
          t8('Download attachments of all parts'),
......
2657 2721
      push @errors, t8('Storing the document to the WebDAV folder failed: #1', $@);
2658 2722
    };
2659 2723
  }
2724
  my $file_obj;
2660 2725
  if ($order->id && $::instance_conf->get_doc_storage) {
2661 2726
    eval {
2662
      SL::File->save(object_id     => $order->id,
2663
                     object_type   => $order->type,
2664
                     mime_type     => SL::MIME->mime_type_from_ext($filename),
2665
                     source        => 'created',
2666
                     file_type     => 'document',
2667
                     file_name     => $filename,
2668
                     file_contents => $content,
2669
                     print_variant => $variant);
2727
      $file_obj = SL::File->save(object_id     => $order->id,
2728
                                 object_type   => $order->type,
2729
                                 mime_type     => SL::MIME->mime_type_from_ext($filename),
2730
                                 source        => 'created',
2731
                                 file_type     => 'document',
2732
                                 file_name     => $filename,
2733
                                 file_contents => $content,
2734
                                 print_variant => $variant);
2735

  
2736
      $self->{file_id}  = $file_obj->id;
2670 2737
      1;
2671 2738
    } or do {
2672 2739
      push @errors, t8('Storing the document in the storage backend failed: #1', $@);
SL/DB/Order.pm
8 8
use List::Util qw(max);
9 9
use List::MoreUtils qw(any);
10 10

  
11
use SL::DBUtils ();
11 12
use SL::DB::MetaSetup::Order;
12 13
use SL::DB::Manager::Order;
13 14
use SL::DB::Helper::Attr;
......
57 58
      sort_by      => 'notes.itime',
58 59
    }
59 60
  },
61
  order_version => {
62
    type                   => 'one to many',
63
    class                  => 'SL::DB::OrderVersion',
64
    column_map             => { id => 'oe_id' },
65
  },
60 66
);
61 67

  
62 68
SL::DB::Helper::Attr::make(__PACKAGE__, daily_exchangerate => 'numeric');
......
547 553
    $self->date->to_kivitendo;
548 554
}
549 555

  
556
sub current_version_number {
557
  my ($self) = @_;
558

  
559
  my $query = <<EOSQL;
560
    SELECT max(version)
561
    FROM oe_version
562
    WHERE (oe_id = ?)
563
EOSQL
564

  
565
  my ($current_version_number) = SL::DBUtils::selectfirst_array_query($::form, $self->db->dbh, $query, ($self->id));
566
  die "Invalid State. No version linked" unless $current_version_number;
567

  
568
  return $current_version_number;
569
}
570

  
571
sub is_final_version {
572
  my ($self) = @_;
573

  
574
  my $order_versions = SL::DB::Manager::OrderVersion->get_all(where => [ oe_id => $self->id, final_version => 0 ]);
575
  die "Invalid version state" unless scalar @{ $order_versions } < 2;
576
  my $final_version = scalar @{ $order_versions } == 1 ? 0 : 1;
577

  
578
  return $final_version;
579
}
580

  
550 581
1;
551 582

  
552 583
__END__
SL/Form.pm
984 984
      if ($attfile) {
985 985
        $attfile->{override_file_name} = $attachment_name if $attachment_name;
986 986
        push @attfiles, $attfile;
987
        $self->{file_id} = $attfile->id;
987 988
      }
988 989

  
989 990
    } else {

Auch abrufbar als: Unified diff