Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 280261a5

Von Sven Schöling vor fast 10 Jahren hinzugefügt

  • ID 280261a5aeda0b21f1a0494151524d59cca8815e
  • Vorgänger e7c07dfd
  • Nachfolger f6ed86ef

Löschen von orderitems beim speichern von OE korrigiert.

Unterschiede anzeigen:

SL/OE.pm
387 387
                  AND (trans_id IN (SELECT id FROM orderitems WHERE trans_id = ?))|;
388 388
    do_query($form, $dbh, $query, $form->{id});
389 389

  
390
    $query = qq|DELETE FROM orderitems WHERE trans_id = ?|;
391
    do_query($form, $dbh, $query, $form->{id});
392

  
393 390
    $query = qq|DELETE FROM shipto | .
394 391
             qq|WHERE trans_id = ? AND module = 'OE'|;
395 392
    do_query($form, $dbh, $query, $form->{id});
......
417 414
  my @taxaccounts;
418 415
  my %taxaccounts;
419 416
  my $netamount = 0;
417
  my @processed_orderitems;
420 418

  
421 419
  $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
422 420
  my %price_factors = map { $_->{id} => $_->{factor} } @{ $form->{ALL_PRICE_FACTORS} };
......
518 516
      $pricegroup_id  = undef if !$pricegroup_id;
519 517

  
520 518
      # save detail record in orderitems table
519
      if (! $form->{"orderitems_id_$i"}) {
520
        $query = qq|SELECT nextval('orderitemsid')|;
521
        ($form->{"orderitems_id_$i"}) = selectrow_query($form, $dbh, $query);
522

  
523
        $query = qq|INSERT INTO orderitems (id) VALUES (?)|;
524
        do_query($form, $dbh, $query, $form->{"orderitems_id_$i"});
525
      }
521 526
      my $orderitems_id = $form->{"orderitems_id_$i"};
522
      ($orderitems_id)  = selectfirst_array_query($form, $dbh, qq|SELECT nextval('orderitemsid')|) if (!$orderitems_id);
523

  
524
      @values = ();
525
      $query = qq|INSERT INTO orderitems (
526
                    id, trans_id, parts_id, description, longdescription, qty, base_qty,
527
                    sellprice, discount, unit, reqdate, project_id, serialnumber, ship,
528
                    pricegroup_id, ordnumber, transdate, cusordnumber, subtotal,
529
                    marge_percent, marge_total, lastcost, price_factor_id, price_factor, marge_price_factor)
530
                  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
531
                          (SELECT factor FROM price_factors WHERE id = ?), ?)|;
532
      push(@values,
533
           conv_i($orderitems_id), conv_i($form->{id}), conv_i($form->{"id_$i"}),
527
      push @processed_orderitems, $orderitems_id;
528

  
529
       $query = <<SQL;
530
         UPDATE orderitems SET
531
          trans_id = ?, parts_id = ?, description = ?, longdescription = ?, qty = ?, base_qty = ?,
532
          sellprice = ?, discount = ?, unit = ?, reqdate = ?, project_id = ?, serialnumber = ?, ship = ?,
533
          pricegroup_id = ?, ordnumber = ?, transdate = ?, cusordnumber = ?, subtotal = ?,
534
          marge_percent = ?, marge_total = ?, lastcost = ?, price_factor_id = ?,
535
          price_factor = (SELECT factor FROM price_factors WHERE id = ?), marge_price_factor = ?
536
        WHERE id = ?
537
SQL
538
      @values = (
539
           conv_i($form->{id}), conv_i($form->{"id_$i"}),
534 540
           $form->{"description_$i"}, $restricter->process($form->{"longdescription_$i"}),
535 541
           $form->{"qty_$i"}, $baseqty,
536 542
           $fxsellprice, $form->{"discount_$i"},
......
541 547
           $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
542 548
           $form->{"lastcost_$i"},
543 549
           conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}),
544
           conv_i($form->{"marge_price_factor_$i"}));
550
           conv_i($form->{"marge_price_factor_$i"}),
551
           conv_i($orderitems_id),
552
      );
553

  
545 554
      do_query($form, $dbh, $query, @values);
546 555

  
547 556
      $form->{"sellprice_$i"} = $fxsellprice;
......
557 566
                                  dbh          => $dbh);
558 567
    }
559 568
  }
569
  # search for orphaned ids
570
  $query  = sprintf 'SELECT id FROM orderitems WHERE trans_id = ? AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_orderitems;
571
  @values = (conv_i($form->{id}), map { conv_i($_) } @processed_orderitems);
572
  my @orphaned_ids = map { $_->{id} } selectall_hashref_query($form, $dbh, $query, @values);
573

  
574
  if (scalar @orphaned_ids) {
575
    # clean up orderitems
576
    $query  = sprintf 'DELETE FROM orderitems WHERE id IN (%s)', join ', ', ("?") x scalar @orphaned_ids;
577
    do_query($form, $dbh, $query, @orphaned_ids);
578
  }
560 579

  
561 580
  $reqdate = ($form->{reqdate}) ? $form->{reqdate} : undef;
562 581

  
......
1001 1020
      }
1002 1021

  
1003 1022
      # delete orderitems_id in collective orders, so that they get cloned no matter what
1004
      delete $ref->{orderitems_id} if (@ids);
1023
      delete $ref->{orderitems_id} if $is_collective_order;
1005 1024

  
1006 1025
      # get tax rates and description
1007 1026
      my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};

Auch abrufbar als: Unified diff