Preisgruppenerweiterung auf Basis von Andres Patch - Thanks
authorStephan Köhler <s.koehler@linet-services.de>
Mon, 31 Oct 2005 19:49:54 +0000 (19:49 +0000)
committerStephan Köhler <s.koehler@linet-services.de>
Mon, 31 Oct 2005 19:49:54 +0000 (19:49 +0000)
-Preisgruppenverwaltung
-Preiseingabe der Preisgruppen in Masken Waren,etc.
-Auswahl der Preisgruppen in den Verkaufsmasken
-...

Erweiterung Datenbankschema

16 files changed:
SL/CT.pm
SL/Form.pm
SL/IC.pm
SL/IS.pm
SL/OE.pm
SL/PE.pm
bin/mozilla/ct.pl
bin/mozilla/ic.pl
bin/mozilla/io.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl
bin/mozilla/pe.pl
menu.ini
sql/Pg-upgrade-2.1.1-2.1.2.sql
sql/lx-office.sql

index c6f55da..1db023b 100644 (file)
--- a/SL/CT.pm
+++ b/SL/CT.pm
@@ -221,16 +221,21 @@ sub save_customer {
 
   my ($self, $myconfig, $form) = @_;
 
+  # set pricegroup to default
+  if ($form->{klass}) { }
+  else { $form->{klass} = 0; }
+
   # connect to database
   my $dbh = $form->dbconnect($myconfig);
 ##LINET
-  map({ $form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
-          if ($form->{"selected_cp_${_}"});
+  map({
+      $form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
+        if ($form->{"selected_cp_${_}"});
   } qw(title greeting));
-
+#
   # escape '
   map { $form->{$_} =~ s/\'/\'\'/g }
-    qw(customernumber name street zipcode city country homepage contact notes cp_title cp_greeting language);
+    qw(customernumber name street zipcode city country homepage contact notes cp_title cp_greeting language pricegroup);
 ##/LINET
   # assign value discount, terms, creditlimit
   $form->{discount} = $form->parse_amount($myconfig, $form->{discount});
@@ -314,7 +319,8 @@ sub save_customer {
               username = '$form->{username}',
               salesman_id = '$form->{salesman_id}',
               user_password = '$form->{user_password}',
-              c_vendor_id = '$form->{c_vendor_id}'
+              c_vendor_id = '$form->{c_vendor_id}',
+              klass = '$form->{klass}'
              WHERE id = $form->{id}|;
   $dbh->do($query) || $form->dberror($query);
 
@@ -362,8 +368,9 @@ sub save_vendor {
   # connect to database
   my $dbh = $form->dbconnect($myconfig);
 ##LINET
-  map({ $form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
-          if ($form->{"selected_cp_${_}"});
+  map({
+      $form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
+        if ($form->{"selected_cp_${_}"});
   } qw(title greeting));
 
   # escape '
index d6cbc0b..2150838 100644 (file)
@@ -382,8 +382,8 @@ function fokus(){document.$self->{fokus}.focus();}
       $jsscript = qq|
         <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
         <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
-        <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
-        <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
+        <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
+        <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
         $self->{javascript}
        |;
     }
@@ -450,25 +450,25 @@ sub write_trigger {
 
   $trigger_1 = qq|
        Calendar.setup(
-       {
-         inputField  : "$inputField_1",
-         ifFormat    :"$ifFormat",
-         align    : "$align_1",     
-         button      : "$button_1"
-       }
-       );
+      {
+      inputField : "$inputField_1",
+      ifFormat :"$ifFormat",
+      align : "$align_1", 
+      button : "$button_1"
+      }
+      );
        |;
 
   if ($qty == 2) {
     $trigger_2 = qq|
        Calendar.setup(
        {
-         inputField  : "$inputField_2",
-         ifFormat    :"$ifFormat",
-         align    : "$align_2",     
-         button      : "$button_2"
-       }
-       );
+      inputField : "$inputField_2",
+      ifFormat :"$ifFormat",
+      align : "$align_2", 
+      button : "$button_2"
+      }
+      );
         |;
   }
   $jsscript = qq|
@@ -2120,6 +2120,38 @@ sub get_partsgroup {
 }
 
 
+sub get_pricegroup {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $p) = @_;
+
+  my $dbh = $self->dbconnect($myconfig);
+
+  my $query = qq|SELECT p.id, p.pricegroup
+                 FROM pricegroup p|;
+
+  $query .= qq|
+                ORDER BY pricegroup|;
+
+  if ($p->{all}) {
+    $query = qq|SELECT id, pricegroup FROM pricegroup
+                ORDER BY pricegroup|;
+  }
+
+  my $sth = $dbh->prepare($query);
+  $sth->execute || $self->dberror($query);
+
+  $self->{all_pricegroup} = ();
+  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+    push @{ $self->{all_pricegroup} }, $ref;
+  }
+  $sth->finish;
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+
+
 sub audittrail {
   my ($self, $dbh, $myconfig, $audittrail) = @_;
   
index 48c7996..2db7546 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -33,7 +33,7 @@
 #======================================================================
 
 package IC;
-
+use Data::Dumper;
 sub get_part {
   $main::lxdebug->enter_sub();
 
@@ -101,6 +101,76 @@ sub get_part {
   $form->{amount}{IC_expense} = $form->{expense_accno};
   $form->{amount}{IC_cogs}    = $form->{expense_accno};
 
+  # get prices
+  $query =
+    qq|SELECT p.parts_id, p.pricegroup_id, p.price, (SELECT pg.pricegroup FROM pricegroup pg WHERE pg.id=p.pricegroup_id) AS pricegroup FROM prices p
+              WHERE parts_id = $form->{id}
+              ORDER by pricegroup|;
+
+  $sth = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  @pricegroups          = ();
+  @pricegroups_not_used = ();
+
+  #for pricegroups
+  my $i = 1;
+  while (
+         ($form->{"klass_$i"}, $form->{"pricegroup_id_$i"},
+          $form->{"price_$i"}, $form->{"pricegroup_$i"})
+         = $sth->fetchrow_array
+    ) {
+    $form->{"price_$i"} = $form->round_amount($form->{"price_$i"}, 5);
+    $form->{"price_$i"} =
+      $form->format_amount($myconfig, $form->{"price_$i"}, 5);
+    push @pricegroups, $form->{"pricegroup_id_$i"};
+    $i++;
+  }
+
+  $sth->finish;
+
+  # get pricegroups
+  $query = qq|SELECT p.id, p.pricegroup FROM pricegroup p|;
+
+  $pkq = $dbh->prepare($query);
+  $pkq->execute || $form->dberror($query);
+  while ($pkr = $pkq->fetchrow_hashref(NAME_lc)) {
+    push @{ $form->{PRICEGROUPS} }, $pkr;
+  }
+  $pkq->finish;
+
+  #find not used pricegroups
+  while ($tmp = pop @{ $form->{PRICEGROUPS} }) {
+    my $insert = 0;
+    foreach $item (@pricegroups) {
+      if ($item eq $tmp->{id}) {
+
+        #drop
+        $insert = 1;
+      }
+    }
+    if ($insert == 0) {
+      push @pricegroups_not_used, $tmp;
+    }
+  }
+
+  # if not used pricegroups are avaible
+  if (@pricegroups_not_used) {
+
+    foreach $name (@pricegroups_not_used) {
+      $form->{"klass_$i"} = "$name->{id}";
+      $form->{"price_$i"} = $form->round_amount($form->{sellprice}, 5);
+      $form->{"price_$i"} =
+        $form->format_amount($myconfig, $form->{"price_$i"}, 5);
+      $form->{"pricegroup_id_$i"} = "$name->{id}";
+      $form->{"pricegroup_$i"}    = "$name->{pricegroup}\n";
+      $i++;
+    }
+  }
+
+  #correct rows
+  $form->{price_rows} = $i - 1;
+
   unless ($form->{item} eq 'service') {
 
     # get makes
@@ -332,6 +402,26 @@ sub save {
              WHERE id = $form->{id}|;
   $dbh->do($query) || $form->dberror($query);
 
+  # delete price records
+  $query = qq|DELETE FROM prices
+              WHERE parts_id = $form->{id}|;
+  $dbh->do($query) || $form->dberror($query);
+
+  # insert price records only if different to sellprice
+  for my $i (1 .. $form->{price_rows}) {
+    if ((   $form->{"price_$i"} 
+        || $form->{"klass_$i"}
+        || $form->{"pricegroup_id_$i"}) and $form->{"price_$i"} != $form->{sellprice}) {
+      $klass = $form->parse_amount($myconfig, $form->{"klass_$i"});
+      $price = $form->parse_amount($myconfig, $form->{"price_$i"});
+      $pricegroup_id =
+        $form->parse_amount($myconfig, $form->{"pricegroup_id_$i"});
+      $query = qq|INSERT INTO prices (parts_id, pricegroup_id, price)
+                  VALUES($form->{id},$pricegroup_id,$price)|;
+      $dbh->do($query) || $form->dberror($query);
+    }
+  }
+
   # insert makemodel records
   unless ($form->{item} eq 'service') {
     for my $i (1 .. $form->{makemodel_rows}) {
index eac4440..a547fa9 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -34,6 +34,8 @@
 
 package IS;
 
+use Data::Dumper;
+
 sub invoice_details {
   $main::lxdebug->enter_sub();
 
@@ -365,7 +367,7 @@ sub customer_details {
 
 sub post_invoice {
   $main::lxdebug->enter_sub();
-
+print STDERR "IS.pm-post_invoice\n";
   my ($self, $myconfig, $form) = @_;
 
   # connect to database, turn off autocommit
@@ -549,16 +551,21 @@ sub post_invoice {
         ? qq|'$form->{"deliverydate_$i"}'|
         : "NULL";
 
+
+      # get pricegroup_id and save ist
+      ($null, my $pricegroup_id) = split /--/, $form->{"sellprice_drag_$i"};
+
       # save detail record in invoice table
       $query = qq|INSERT INTO invoice (trans_id, parts_id, description, qty,
                   sellprice, fxsellprice, discount, allocated, assemblyitem,
-                 unit, deliverydate, project_id, serialnumber)
+                 unit, deliverydate, project_id, serialnumber, pricegroup_id)
                  VALUES ($form->{id}, $form->{"id_$i"},
                  '$form->{"description_$i"}', $form->{"qty_$i"},
                  $form->{"sellprice_$i"}, $fxsellprice,
                  $form->{"discount_$i"}, $allocated, 'f',
                  '$form->{"unit_$i"}', $deliverydate, (SELECT id from project where projectnumber = '$project_id'),
-                 '$form->{"serialnumber_$i"}')|;
+                 '$form->{"serialnumber_$i"}',
+      '$pricegroup_id')|;
       $dbh->do($query) || $form->dberror($query);
 
       if ($form->{lizenzen}) {
@@ -1105,7 +1112,7 @@ sub delete_invoice {
 
 sub retrieve_invoice {
   $main::lxdebug->enter_sub();
-
+print STDERR "IS.pm-retrieve_invoice\n";
   my ($self, $myconfig, $form) = @_;
 
   # connect to database
@@ -1211,7 +1218,7 @@ sub retrieve_invoice {
                i.discount, i.parts_id AS id, i.unit, i.deliverydate,
                i.project_id, pr.projectnumber, i.serialnumber,
                p.partnumber, p.assembly, p.bin, p.notes AS partnotes, i.id AS invoice_pos,
-               pg.partsgroup
+               pg.partsgroup, i.pricegroup_id, (SELECT pricegroup FROM pricegroup WHERE id=i.pricegroup_id) as pricegroup
                FROM invoice i
                JOIN parts p ON (i.parts_id = p.id)
                LEFT JOIN project pr ON (i.project_id = pr.id)
@@ -1306,7 +1313,7 @@ sub get_customer {
                  c.email, c.cc, c.bcc, c.language,
                 c.street, c.zipcode, c.city, c.country,
                 $duedate + c.terms AS duedate, c.notes AS intnotes,
-                b.discount AS tradediscount, b.description AS business
+                b.discount AS tradediscount, b.description AS business, c.klass as customer_klass
                  FROM customer c
                 LEFT JOIN business b ON (b.id = c.business_id)
                 WHERE c.id = $form->{customer_id}|;
@@ -1513,7 +1520,6 @@ sub retrieve_item {
         $stw->finish;
       }
     }
-
   }
   $sth->finish;
   $dbh->disconnect;
@@ -1521,6 +1527,154 @@ sub retrieve_item {
   $main::lxdebug->leave_sub();
 }
 
+##########################
+# get pricegroups from database
+# build up selected pricegroup
+# if an exchange rate - change price 
+# for each part
+#
+sub get_pricegroups_for_parts {
+print STDERR "IS.pm - get_pricegroups_for_parts\n";
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $i  = 1;
+  my $id = 0;
+
+  while (($form->{"id_$i"}) or ($form->{"new_id_$i"})) {
+
+    $id = $form->{"id_$i"};
+
+    if (!($form->{"id_$i"}) and $form->{"new_id_$i"}) {
+
+      $id = $form->{"new_id_$i"};
+    }
+
+    ($price, $selectedpricegroup_id) = split /--/, $form->{"sellprice_drag_$i"};
+#  print (STDERR "sellprice_drag_$i", Dumper($form->{"sellprice_drag_$i"}));
+
+    $pricegroup_old = $form->{"pricegroup_old_$i"};
+#  print (STDERR "pricegroup_old_i-$i", Dumper($pricegroup_old));
+
+    $price_new = $form->{"price_new_$i"};
+
+    $price_old = $form->{"price_old_$i"};
+
+    $query = qq|SELECT pricegroup_id, (SELECT p.sellprice from parts p where p.id = $id) as default_sellprice,(SELECT pg.pricegroup FROM pricegroup pg WHERE id=pricegroup_id) AS pricegroup, price, '' AS selected FROM prices WHERE parts_id = $id UNION SELECT 0 as pricegroup_id,(SELECT sellprice FROM parts WHERE id=$id) as default_sellprice,'' as pricegroup, (SELECT DISTINCT sellprice from parts where id=$id) as price, 'selected' AS selected from prices ORDER BY pricegroup|;
+
+    $pkq = $dbh->prepare($query);
+    $pkq->execute || $form->dberror($query);
+    while ($pkr = $pkq->fetchrow_hashref(NAME_lc)) {
+#       push @{ $form->{PRICES}{$id} }, $pkr;
+        push @{ $form->{PRICES}{$i} }, $pkr;
+        $pkr->{id} = $id;
+        $pkr->{selected}  = '';
+
+    # if there is an exchange rate change price
+      if (($form->{exchangerate} * 1) != 0) {
+# print STDERR "WECHSELKURS?-$form->{exchangerate}\n";
+        $pkr->{price} /= $form->{exchangerate};
+      }
+      $pkr->{price} = $form->format_amount($myconfig,$pkr->{price},5);
+
+
+      if ($selectedpricegroup_id eq undef) {
+        if ($pkr->{pricegroup_id} eq $form->{customer_klass}) {
+print STDERR "   INIT ROW \n";
+#print (STDERR "   PREIS", Dumper($pkr->{price}));
+          $pkr->{selected}  = ' selected';
+          $last->{selected} = '';
+# print (STDERR "   SELLPRICE", Dumper($form->{"sellprice_$i"}));
+
+        # no customer pricesgroup set 
+          if ($pkr->{price} == $pkr->{default_sellprice}) {
+print (STDERR "   PREIS IST DEFAULT-SELLPRICE", Dumper($form->{"sellprice_$i"}));
+           $pkr->{price} = $form->{"sellprice_$i"};
+
+#  if ($form->{tradediscount}){
+#  print (STDERR "TRADE--", Dumper($pkr->{price}));
+#               $pkr->{price} =$pkr->{price} * (1 - $form->{tradediscount});
+#               $pkr->{price} = $form->format_amount($myconfig,$pkr->{price},5);
+#  print (STDERR "TRADE--", Dumper($pkr->{price}));
+#  }
+
+          } else {
+print STDERR "   PREIS IST NICHT NULL\n";
+             $form->{"sellprice_$i"} = $pkr->{price};
+          }
+# print (STDERR "           PRICE", Dumper($pkr->{price}));
+
+        } else {
+print STDERR "   INIT ROW but what\n";
+print (STDERR "   PREIS -", Dumper($pkr->{price}), "Default", Dumper($pkr->{default_sellprice}));
+          if ($pkr->{price} == $pkr->{default_sellprice}) {
+print (STDERR "   PREIS IST DEFAULT-", Dumper($form->{"sellprice_$i"}));
+            $pkr->{price} = $form->{"sellprice_$i"};
+            $pkr->{selected}                    = ' selected';
+          }
+        }
+      }
+      if ($selectedpricegroup_id or $selectedpricegroup_id == 0){
+        if ($selectedpricegroup_id ne $pricegroup_old) {
+          if ($pkr->{pricegroup_id} eq $selectedpricegroup_id) {
+            if ($price_new != $form->{"sellprice_$i"}) {
+print STDERR "   MANUELLEN PREIS WÄHLEN\n";
+            } else {
+print STDERR "   UPDATE CHANGE PRICEGROUP\n";
+              $pkr->{selected}                    = ' selected';
+              $last->{selected}                   = '';
+#$form->{"pricegroup_old_$i"} = $pkr->{$pricegroup_id};
+            }
+          }
+        } else { 
+          if (($price_new != $form->{"sellprice_$i"}) and ($price_new ne 0)) {
+            if ($pkr->{pricegroup_id} == 0) {
+print STDERR "   UPDATE CHANGE PRICEGROUP with price manuelly\n";
+print (STDERR "  SELLPRICE??? ---", Dumper($form->{"sellprice_$i"}));
+print (STDERR "  NEWPRICE??? ---", Dumper($price_new));
+              $pkr->{price} = $form->{"sellprice_$i"};
+              $pkr->{selected}                    = ' selected';
+              $last->{selected}                   = '';
+       #$form->{"sellprice_$i"} = $form->format_amount($myconfig, $price_new, 2);
+# print (STDERR "----5555---", Dumper($pkr));
+            }
+          } else {
+            if ($pkr->{pricegroup_id} eq $selectedpricegroup_id) {
+print STDERR "   UPDATE NO CHANGE\n";
+              $pkr->{selected}                    = ' selected';
+              $last->{selected}                   = '';
+print STDERR "  DEFAULTPRICE??? ---$pkr->{default_sellprice}\n";
+print (STDERR "  SELLPRICE??? ---", Dumper($form->{"sellprice_$i"}));
+# print (STDERR "  HIER DER SELLPRICE DEFAULT??? ---", Dumper($form));
+print STDERR "  NEWPRICE??? ---$price_new_\n";
+              if (($pkr->{pricegroup_id} == 0) and ($pkr->{price} == $form->{"sellprice_$i"})) {
+print (STDERR "  UPDATE NO CHANGE BUT PRICE MANUELLY SET", Dumper($pkr->{price}));
+                # $pkr->{price}                         = $form->{"sellprice_$i"};
+              } else {
+                $pkr->{price} = $form->{"sellprice_$i"};
+              }
+#print (STDERR "   FEHLER", Dumper($form->{"sellprice_$i"}));
+            }
+          }
+        }
+      }
+    }
+    $i++;
+
+    $pkq->finish;
+  }
+
+  $dbh->disconnect;
+
+#        print (STDERR "TEST", Dumper($form->{PRICES}));
+# print (STDERR "TEST id_$i", Dumper($form->{"id_$i"}));
+  $main::lxdebug->leave_sub();
+}
+
 sub webdav_folder {
   $main::lxdebug->enter_sub();
 
index b39c8e9..334355d 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -311,11 +311,14 @@ sub save {
       $reqdate =
         ($form->{"reqdate_$i"}) ? qq|'$form->{"reqdate_$i"}'| : "NULL";
 
+      # get pricegroup_id and save ist
+      ($null, my $pricegroup_id) = split /--/, $form->{"sellprice_drag_$i"};
+
       # save detail record in orderitems table
       $query = qq|INSERT INTO orderitems (|;
       $query .= "id, " if $form->{"orderitems_id_$i"};
       $query .= qq|trans_id, parts_id, description, qty, sellprice, discount,
-                  unit, reqdate, project_id, serialnumber, ship)
+                  unit, reqdate, project_id, serialnumber, ship, pricegroup_id)
                    VALUES (|;
       $query .= qq|$form->{"orderitems_id_$i"},|
         if $form->{"orderitems_id_$i"};
@@ -323,7 +326,8 @@ sub save {
                   '$form->{"description_$i"}', $form->{"qty_$i"},
                   $fxsellprice, $form->{"discount_$i"},
                   '$form->{"unit_$i"}', $reqdate, (SELECT id from project where projectnumber = '$project_id'),
-                  '$form->{"serialnumber_$i"}', $form->{"ship_$i"})|;
+                  '$form->{"serialnumber_$i"}', $form->{"ship_$i"},
+       '$pricegroup_id')|;
       $dbh->do($query) || $form->dberror($query);
 
       $form->{"sellprice_$i"} = $fxsellprice;
@@ -631,7 +635,7 @@ sub retrieve {
                o.sellprice, o.parts_id AS id, o.unit, o.discount, p.bin, p.notes AS partnotes,
                 o.reqdate, o.project_id, o.serialnumber, o.ship,
                pr.projectnumber,
-               pg.partsgroup
+               pg.partsgroup, o.pricegroup_id, (SELECT pricegroup FROM pricegroup WHERE id=o.pricegroup_id) as pricegroup
                FROM orderitems o
                JOIN parts p ON (o.parts_id = p.id)
                LEFT JOIN chart c1 ON (p.inventory_accno_id = c1.id)
index 9c17b52..1532e79 100644 (file)
--- a/SL/PE.pm
+++ b/SL/PE.pm
@@ -35,6 +35,8 @@
 
 package PE;
 
+use Data::Dumper;
+
 sub projects {
   $main::lxdebug->enter_sub();
 
@@ -290,5 +292,133 @@ sub delete_tuple {
   $main::lxdebug->leave_sub();
 }
 
+##########################
+# get pricegroups from database
+#
+sub pricegroups {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  my $var;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $sortorder = ($form->{sort}) ? $form->{sort} : "pricegroup";
+
+  my $query = qq|SELECT g.id, g.pricegroup
+                 FROM pricegroup g|;
+
+  my $where = "1 = 1";
+
+  if ($form->{pricegroup}) {
+    $var = $form->like(lc $form->{pricegroup});
+    $where .= " AND lower(g.pricegroup) LIKE '$var'";
+  }
+  $query .= qq|
+               WHERE $where
+              ORDER BY $sortorder|;
+
+  if ($form->{status} eq 'orphaned') {
+    $query = qq|SELECT pg.*
+                FROM pricegroup pg
+                LEFT JOIN prices p ON (p.pricegroup_id = pg.id)
+               WHERE $where
+                EXCEPT
+                SELECT pg.*
+               FROM pricegroup pg
+               JOIN prices p ON (p.pricegroup_id = pg.id)
+               WHERE $where
+               ORDER BY $sortorder|;
+  }
+print STDERR "asdfasdf-$query\n";
+
+  $sth = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  my $i = 0;
+  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+    push @{ $form->{item_list} }, $ref;
+    $i++;
+  }
+
+  $sth->finish;
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+
+  return $i;
+}
+########################
+# save pricegruop to database
+#
+sub save_pricegroup {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  map { $form->{$_} =~ s/\'/\'\'/g } (pricegroup);
+
+  $form->{discount} /= 100;
+
+  if ($form->{id}) {
+    $query = qq|UPDATE pricegroup SET
+                pricegroup = '$form->{pricegroup}'
+               WHERE id = $form->{id}|;
+  } else {
+    $query = qq|INSERT INTO pricegroup
+                (pricegroup)
+                VALUES ('$form->{pricegroup}')|;
+  }
+  $dbh->do($query) || $form->dberror($query);
+
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+############################
+# get one pricegroup from database
+#
+sub get_pricegroup {
+  $main::lxdebug->enter_sub();
+print STDERR "PE.pm-get_pricegroup\n";
+  my ($self, $myconfig, $form) = @_;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $query = qq|SELECT p.id, p.pricegroup
+                 FROM pricegroup p
+                WHERE p.id = $form->{id}|;
+  my $sth = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+  map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+  $sth->finish;
+
+  # check if it is orphaned
+  $query = qq|SELECT count(*)
+              FROM prices p
+             WHERE p.pricegroup_id = $form->{id}|;
+  $sth = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  ($form->{orphaned}) = $sth->fetchrow_array;
+  $form->{orphaned} = !$form->{orphaned};
+
+  $sth->finish;
+
+  $dbh->disconnect;
+#print (STDERR "   ", Dumper($form));
+  $main::lxdebug->leave_sub();
+}
+
 1;
 
index 18171b5..c1bd16e 100644 (file)
@@ -69,8 +69,7 @@ sub search {
   if ($form->{db} eq 'vendor') {
     $gifi = qq|
                <td><input name="l_gifi_accno" type=checkbox class=checkbox value=Y> |
-      . $locale->text('GIFI')
-      . qq|</td>
+      . $locale->text('GIFI') . qq|</td>
 |;
   }
 
@@ -112,8 +111,7 @@ sub search {
          <td><input name=status class=radio type=radio value=all checked>&nbsp;|
     . $locale->text('All') . qq|
          <input name=status class=radio type=radio value=orphaned>&nbsp;|
-    . $locale->text('Orphaned')
-    . qq|</td>
+    . $locale->text('Orphaned') . qq|</td>
        </tr>
        <tr>
          <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
@@ -121,54 +119,40 @@ sub search {
            <table>
              <tr>
                <td><input name="l_id" type=checkbox class=checkbox value=Y> |
-    . $locale->text('ID')
-    . qq|</td>
+    . $locale->text('ID') . qq|</td>
                <td><input name="l_$form->{db}number" type=checkbox class=checkbox value=Y> |
-    . $locale->text($label . ' Number')
-    . qq|</td>
+    . $locale->text($label . ' Number') . qq|</td>
                <td><input name="l_name" type=checkbox class=checkbox value=Y checked> |
-    . $locale->text('Company Name')
-    . qq|</td>
+    . $locale->text('Company Name') . qq|</td>
                <td><input name="l_address" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Address')
-    . qq|</td>
+    . $locale->text('Address') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_contact" type=checkbox class=checkbox value=Y checked> |
-    . $locale->text('Contact')
-    . qq|</td>
+    . $locale->text('Contact') . qq|</td>
                <td><input name="l_phone" type=checkbox class=checkbox value=Y checked> |
-    . $locale->text('Phone')
-    . qq|</td>
+    . $locale->text('Phone') . qq|</td>
                <td><input name="l_fax" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Fax')
-    . qq|</td>
+    . $locale->text('Fax') . qq|</td>
                <td><input name="l_email" type=checkbox class=checkbox value=Y checked> |
-    . $locale->text('E-mail')
-    . qq|</td>
+    . $locale->text('E-mail') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_taxnumber" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Tax Number')
-    . qq|</td>
+    . $locale->text('Tax Number') . qq|</td>
                $gifi
                <td><input name="l_sic_code" type=checkbox class=checkbox value=Y> |
-    . $locale->text('SIC')
-    . qq|</td>
+    . $locale->text('SIC') . qq|</td>
                <td><input name="l_business" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Type of Business')
-    . qq|</td>
+    . $locale->text('Type of Business') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_invnumber" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Invoices')
-    . qq|</td>
+    . $locale->text('Invoices') . qq|</td>
                <td><input name="l_ordnumber" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Orders')
-    . qq|</td>
+    . $locale->text('Orders') . qq|</td>
                <td><input name="l_quonumber" type=checkbox class=checkbox value=Y> |
-    . $locale->text('Quotations')
-    . qq|</td>
+    . $locale->text('Quotations') . qq|</td>
              </tr>
            </table>
          </td>
@@ -363,7 +347,6 @@ sub list_names {
 
     if ($ref->{id} eq $sameid) {
       map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
-      map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } (invnumber, ordnumber, quonumber);
     } else {
       map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
 
@@ -529,10 +512,10 @@ sub form_header {
   </tr>
 |;
   }
-
   $form->{selectbusiness} = qq|<option>\n|;
   map {
-    $form->{selectbusiness} .= qq|<option value=$_->{id}>$_->{description}\n|
+    $form->{selectbusiness} .=
+      qq|<option value=$_->{id}>$_->{description}\n|
   } @{ $form->{all_business} };
   if ($form->{business_save}) {
     $form->{selectbusiness} = $form->{business_save};
@@ -596,10 +579,42 @@ sub form_header {
 
   $select_greeting =
     qq|&nbsp;<select name=selected_cp_greeting><option></option>|;
-  map({ $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
+  map(
+     { $select_greeting .= qq|<option>$_</option>|; } @{ $form->{GREETINGS} });
   $select_greeting .= qq|</select>|;
 ## /LINET
 
+  if ($form->{db} eq 'customer') {
+  #get pricegroup and form it
+  $form->get_pricegroup(\%myconfig, { all => 1 });
+
+  $form->{pricegroup}    = "$form->{klass}";
+  $form->{pricegroup_id} = "$form->{klass}";
+
+  if (@{ $form->{all_pricegroup} }) {
+
+    $form->{selectpricegroup} = qq|<option>\n|;
+    map {
+      $form->{selectpricegroup} .=
+        qq|<option value="$_->{id}">$_->{pricegroup}\n|
+    } @{ $form->{all_pricegroup} };
+  }
+
+  if ($form->{selectpricegroup}) {
+    $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
+
+    $pricegroup =
+      qq|<input type=hidden name=selectpricegroup value="|
+      . $form->escape($form->{selectpricegroup}, 1) . qq|">|;
+
+    $form->{selectpricegroup} =~
+      s/(<option value="\Q$form->{klass}\E")/$1 selected/;
+
+    $pricegroup .= qq|<select name=klass>$form->{selectpricegroup}</select>|;
+
+    $group = $locale->text('Hola');
+  }
+ }
   # $locale->text('Customer Number')
   # $locale->text('Vendor Number')
   $form->{fokus} = "ct.name";
@@ -618,11 +633,9 @@ sub form_header {
       <table width=100%>
        <tr class=listheading>
          <th class=listheading colspan=2 width=50%>|
-    . $locale->text('Billing Address')
-    . qq|</th>
+    . $locale->text('Billing Address') . qq|</th>
          <th class=listheading width=50%>|
-    . $locale->text('Shipping Address')
-    . qq|</th>
+    . $locale->text('Shipping Address') . qq|</th>
        </tr>
        <tr height="5"></tr>
         $business_salesman
@@ -649,9 +662,7 @@ sub form_header {
        </tr>
        <tr>
          <th align=right nowrap>|
-    . $locale->text('Zipcode') . "/"
-    . $locale->text('City')
-    . qq|</th>
+    . $locale->text('Zipcode') . "/" . $locale->text('City') . qq|</th>
          <td><input name=zipcode size=5 tabindex=5 maxlength=10 value="$form->{zipcode}">
           <input name=city size=30 tabindex=6 maxlength=75 value="$form->{city}"></td>
          <td><input name=shiptozipcode size=5 maxlength=10 value="$form->{shiptozipcode}">
@@ -695,8 +706,7 @@ sub form_header {
                 <table>
                 <tr>
                  <th align=right nowrap>|
-    . $locale->text('Contact Person')
-    . qq|</th>
+    . $locale->text('Contact Person') . qq|</th>
                 </tr>
                 <tr>
                   <th></th>
@@ -710,8 +720,7 @@ sub form_header {
                 <tr>
                   <th></th>
                   <th align=left nowrap>|
-    . $locale->text('Given Name')
-    . qq|</th>
+    . $locale->text('Given Name') . qq|</th>
                   <td><input name=cp_givenname size=30 maxlength=40 value="$form->{cp_givenname}"></td>
                  <th align=left nowrap>| . $locale->text('Name') . qq|</th>
                   <td><input name=cp_name size=30 maxlength=40 value="$form->{cp_name}"></td>
@@ -747,8 +756,7 @@ sub form_header {
          <td><input name=creditlimit tabindex=13 size=9 value="$form->{creditlimit}"></td>
          <th align=right>| . $locale->text('Terms: Net') . qq|</th>
          <td><input name=terms tabindex=14 size=2 value="$form->{terms}">|
-    . $locale->text('days')
-    . qq|</td>
+    . $locale->text('days') . qq|</td>
          <th align=right>| . $locale->text('Discount') . qq|</th>
          <td><input name=discount tabindex=15 size=4 value="$form->{discount}">
          %</td>
@@ -773,7 +781,12 @@ sub form_header {
          <th align=right>| . $locale->text('Language') . qq|</th>
          <td><select name=language tabindex=23>$lang
                           </select></td>|;
+if ($form->{db} eq 'customer'){
 
+print qq|
+          <th align=right>| . $locale->text('Preisklasse') . qq|</th>
+          <td>$pricegroup</td>|;
+}
   print qq|        </tr>
         <tr>
           <td align=right>| . $locale->text('Obsolete') . qq|</td>
@@ -835,6 +848,8 @@ sub form_footer {
 <input type=hidden name=callback value="$form->{callback}">
 <input type=hidden name=db value=$form->{db}>
 
+
+
 <br>
 $update_button
 <input class=submit type=submit name=action accesskey="s" value="|
index 6d49eab..6d1f611 100644 (file)
@@ -32,6 +32,7 @@
 #======================================================================
 
 use SL::IC;
+#use SL::PE;
 
 require "$form->{path}/io.pl";
 
@@ -84,14 +85,12 @@ sub search {
     $button1 = qq|
        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>
        <td><input type=button name=transdatefrom id="trigger1" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
       |;
     $button2 = qq|
        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>
        <td><input type=button name=transdateto name=transdateto id="trigger2" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
      |;
 
     #write Trigger
@@ -132,8 +131,7 @@ sub search {
 
     $l_serialnumber = qq|
         <td><input name=l_serialnumber class=checkbox type=checkbox value=Y>&nbsp;|
-      . $locale->text('Serial Number')
-      . qq|</td>
+      . $locale->text('Serial Number') . qq|</td>
 |;
 
   }
@@ -272,8 +270,7 @@ sub search {
         </tr>
         <tr>
           <th align=right nowrap>|
-    . $locale->text('Part Description')
-    . qq|</th>
+    . $locale->text('Part Description') . qq|</th>
           <td colspan=3><input name=description size=40></td>
         </tr>
        <tr>
@@ -310,71 +307,53 @@ sub search {
        </tr>
        <tr>
           <th align=right nowrap>|
-    . $locale->text('Include in Report')
-    . qq|</th>
+    . $locale->text('Include in Report') . qq|</th>
           <td colspan=3>
             <table>
               <tr>
                 <td><input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|
-    . $locale->text('Part Number')
-    . qq|</td>
+    . $locale->text('Part Number') . qq|</td>
                <td><input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|
-    . $locale->text('Part Description')
-    . qq|</td>
+    . $locale->text('Part Description') . qq|</td>
                $l_serialnumber
                <td><input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|
-    . $locale->text('Unit of measure')
-    . qq|</td>
+    . $locale->text('Unit of measure') . qq|</td>
              </tr>
              <tr>
                 <td><input name=l_listprice class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('List Price')
-    . qq|</td>
+    . $locale->text('List Price') . qq|</td>
                <td><input name=l_sellprice class=checkbox type=checkbox value=Y checked>&nbsp;|
-    . $locale->text('Sell Price')
-    . qq|</td>
+    . $locale->text('Sell Price') . qq|</td>
                <td><input name=l_lastcost class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Last Cost')
-    . qq|</td>
+    . $locale->text('Last Cost') . qq|</td>
                <td><input name=l_linetotal class=checkbox type=checkbox value=Y checked>&nbsp;|
-    . $locale->text('Line Total')
-    . qq|</td>
+    . $locale->text('Line Total') . qq|</td>
              </tr>
              <tr>
                 <td><input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Updated')
-    . qq|</td>
+    . $locale->text('Updated') . qq|</td>
                <td><input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Bin')
-    . qq|</td>
+    . $locale->text('Bin') . qq|</td>
                <td><input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('ROP')
-    . qq|</td>
+    . $locale->text('ROP') . qq|</td>
                <td><input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Weight')
-    . qq|</td>
+    . $locale->text('Weight') . qq|</td>
               </tr>
              <tr>
                 <td><input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Image')
-    . qq|</td>
+    . $locale->text('Image') . qq|</td>
                <td><input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Drawing')
-    . qq|</td>
+    . $locale->text('Drawing') . qq|</td>
                <td><input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Microfiche')
-    . qq|</td>
+    . $locale->text('Microfiche') . qq|</td>
                <td><input name=l_partsgroup class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Group')
-    . qq|</td>
+    . $locale->text('Group') . qq|</td>
               </tr>
              <tr>
                 <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('Subtotal')
-    . qq|</td>
+    . $locale->text('Subtotal') . qq|</td>
                <td><input name=l_soldtotal class=checkbox type=checkbox value=Y>&nbsp;|
-    . $locale->text('soldtotal')
-    . qq|</td>
+    . $locale->text('soldtotal') . qq|</td>
              </tr>
             </table>
           </td>
@@ -433,11 +412,9 @@ sub choice {
       <table>
        <tr class=listheading>
          <th class=listheading nowrap>|
-    . $locale->text('Part Number')
-    . qq|</th>
+    . $locale->text('Part Number') . qq|</th>
          <th class=listheading nowrap>|
-    . $locale->text('Part Description')
-    . qq|</th>
+    . $locale->text('Part Description') . qq|</th>
         </tr>
         <tr valign=top>
          <td><input type=text name=partnumber size=20 value=></td>
@@ -858,10 +835,9 @@ sub addtop100 {
     $option   .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
   }
 
-  @columns =
-    $form->sort_columns(
+  @columns = $form->sort_columns(
     qw(number partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal)
-    );
+  );
 
   if ($form->{l_linetotal}) {
     $form->{l_onhand} = "Y";
@@ -1441,10 +1417,9 @@ sub generate_report {
     $option   .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
   }
 
-  @columns =
-    $form->sort_columns(
+  @columns = $form->sort_columns(
     qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal)
-    );
+  );
 
   if ($form->{l_linetotal}) {
     $form->{l_onhand} = "Y";
@@ -1921,7 +1896,9 @@ sub link_part {
   delete $form->{amount};
 
   $form->get_partsgroup(\%myconfig, { all => 1 });
+
   $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
+
   if (@{ $form->{all_partsgroup} }) {
     $form->{selectpartsgroup} = qq|<option>\n|;
     map {
@@ -2018,6 +1995,7 @@ sub form_header {
       }
     }
   }
+
   if ($form->{selectpartsgroup}) {
     $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
     $partsgroup =
@@ -2044,8 +2022,7 @@ sub form_header {
   $lastcost = qq|
              <tr>
                 <th align="right" nowrap="true">|
-    . $locale->text('Last Cost')
-    . qq|</th>
+    . $locale->text('Last Cost') . qq|</th>
                 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
               </tr>
 |;
@@ -2153,8 +2130,7 @@ sub form_header {
              <tr>
                <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
                <th align=left nowrap class="plus$n">&nbsp;|
-      . $form->format_amount(\%myconfig, $form->{onhand})
-      . qq|</th>
+      . $form->format_amount(\%myconfig, $form->{onhand}) . qq|</th>
              </tr>
 |;
 
@@ -2183,14 +2159,12 @@ sub form_header {
     $vegv = qq|
              <tr>
                <th align="right" nowrap="true">|
-      . $locale->text('Verrechnungseinheit')
-      . qq|</th>
+      . $locale->text('Verrechnungseinheit') . qq|</th>
                <td><input name=ve size=10 value=$form->{ve}></td>
              </tr>
               <tr>
                <th align="right" nowrap="true">|
-      . $locale->text('Geschäftsvolumen')
-      . qq|</th>
+      . $locale->text('Geschäftsvolumen') . qq|</th>
                <td><input name=gv size=10 value=$form->{gv}></td>
              </tr>
 |;
@@ -2227,8 +2201,7 @@ sub form_header {
   $obsolete .= qq|
               <tr>
                 <th align=right nowrap>|
-    . $locale->text('Shopartikel')
-    . qq|</th>
+    . $locale->text('Shopartikel') . qq|</th>
                 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
              </tr>
 |;
@@ -2249,8 +2222,7 @@ sub form_header {
     $button1 = qq|
        <td width="13"><input name=priceupdate id=priceupdate size=11  title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
        <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
       |;
 
     #write Trigger
@@ -2314,8 +2286,7 @@ sub form_header {
             <table width="100%" height="100%">
               <tr class="listheading">
                 <th class="listheading" align="center" colspan=2>|
-    . $locale->text('Link Accounts')
-    . qq|</th>
+    . $locale->text('Link Accounts') . qq|</th>
               </tr>
               $linkaccounts
               <tr>
@@ -2332,8 +2303,7 @@ sub form_header {
            <table width="100%">
              <tr>
                 <th align="right" nowrap="true">|
-    . $locale->text('Updated')
-    . qq|</th>
+    . $locale->text('Updated') . qq|</th>
                 $button1
               </tr>
              <tr>
@@ -2378,11 +2348,9 @@ sub form_footer {
             <table width="100%">
               <tr>
                 <th colspan=2 align=right>|
-      . $locale->text('Total')
-      . qq|&nbsp;</th>
+      . $locale->text('Total') . qq|&nbsp;</th>
                 <th align=right>|
-      . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2)
-      . qq|</th>
+      . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
               </tr>
             </table>
           </td>
@@ -2415,6 +2383,9 @@ sub form_footer {
     |;
   }
 
+  print qq|
+     <input type=hidden name=price_rows value=$form->{price_rows}>|;
+
   print qq|
       <input class=submit type=submit name=action value="|
     . $locale->text('Save') . qq|">|;
@@ -2718,7 +2689,6 @@ sub update {
   if ($form->{item} eq 'service') {
     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
       qw(sellprice listprice);
-
     &form_header;
     &form_footer;
   }
@@ -2898,15 +2868,13 @@ sub stock_assembly {
       <table>
         <tr>
           <th align="right" nowrap="true">|
-    . $locale->text('Part Number')
-    . qq|</th>
+    . $locale->text('Part Number') . qq|</th>
           <td><input name=partnumber size=20></td>
           <td>&nbsp;</td>
         </tr>
         <tr>
           <th align="right" nowrap="true">|
-    . $locale->text('Part Description')
-    . qq|</th>
+    . $locale->text('Part Description') . qq|</th>
           <td><input name=description size=40></td>
         </tr>
       </table>
@@ -3053,4 +3021,37 @@ sub restock_assemblies {
   $lxdebug->leave_sub();
 }
 
+sub price_row {
+  $lxdebug->enter_sub();
+
+  my ($numrows) = @_;
+
+  print qq|
+  <tr>
+    <td>
+      <table width=100%>
+        <tr>
+          <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
+          <th class="listheading">| . $locale->text('Preis') . qq|</th>
+        </tr>
+|;
+  for $i (1 .. $numrows) {
+    print qq|
+        <tr>
+          <td width=50%><input name="pricegroup_$i" size=30  value=$form->{"pricegroup_$i"} readonly></td>
+          <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
+          <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
+        </tr>
+|;
+  }
+
+  print qq|
+      </table>
+    </td>
+  </tr>
+|;
+
+  $lxdebug->leave_sub();
+}
+
 sub continue { &{ $form->{nextsub} } }
index 2a47a62..9ae9739 100644 (file)
@@ -72,6 +72,8 @@ if (-f "$form->{path}/$form->{login}_io.pl") {
 # $locale->text('Oct')
 # $locale->text('Nov')
 # $locale->text('Dec')
+use SL::IS;
+use SL::PE;
 use Data::Dumper;
 ########################################
 # Eintrag fuer Version 2.2.0 geaendert #
@@ -80,7 +82,7 @@ use Data::Dumper;
 sub display_row {
   $lxdebug->enter_sub();
   my $numrows = shift;
-
+print STDERR "io.pl-display_row\n";
   if ($lizenzen && $form->{vc} eq "customer") {
     if ($form->{type} =~ /sales_order/) {
       @column_index = (runningnumber, partnumber, description, ship, qty);
@@ -99,7 +101,14 @@ sub display_row {
   }
 ############## ENDE Neueintrag ##################
 
-  push @column_index, qw(unit sellprice);
+  push @column_index, qw(unit);
+
+  #for pricegroups column
+  if ($form->{type} =~ (/sales_quotation/) or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/)) or (($form->{level} eq undef) and ($form->{type} =~ /invoice/)) or ($form->{type} =~ /sales_order/)) {
+    push @column_index, qw(sellprice_drag);
+  }
+
+  push @column_index, qw(sellprice);
 
   if ($form->{vc} eq 'customer') {
     push @column_index, qw(discount);
@@ -153,9 +162,13 @@ sub display_row {
     . $locale->text('Project')
     . qq|</th>|;
   $column_data{sellprice} =
-      qq|<th align=left nowrap width=10 class=listheading>|
+      qq|<th align=left nowrap width=15 class=listheading>|
     . $locale->text('Price')
     . qq|</th>|;
+  $column_data{sellprice_drag} =
+      qq|<th align=left nowrap width=15 class=listheading>|
+    . $locale->text('Pricegroup')
+    . qq|</th>|;
   $column_data{discount} =
       qq|<th align=left class=listheading>|
     . $locale->text('Discount')
@@ -201,7 +214,7 @@ sub display_row {
     map {
       $form->{"${_}_$i"} =
         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
-    } qw(qty ship discount sellprice);
+    } qw(qty ship discount sellprice price_new price_old);
 
     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
     $dec           = length $dec;
@@ -211,6 +224,7 @@ sub display_row {
       $form->round_amount(
                         $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100,
                         $decimalplaces);
+
     $linetotal =
       $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
     $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
@@ -239,20 +253,57 @@ sub display_row {
     }
 
     $column_data{qty} =
-        qq|<td align=right><input name="qty_$i" size=5 value=|
-      . $form->format_amount(\%myconfig, $form->{"qty_$i"})
-      . qq|></td>|;
+        qq|<td align=right><input name="qty_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"},0).qq|></td>|;
     $column_data{ship} =
         qq|<td align=right><input name="ship_$i" size=5 value=|
       . $form->format_amount(\%myconfig, $form->{"ship_$i"})
       . qq|></td>|;
     $column_data{unit} =
       qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
-    $column_data{sellprice} =
-      qq|<td align=right><input name="sellprice_$i" size=9 value=|
-      . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
-                             $decimalplaces)
-      . qq|></td>|;
+
+
+
+ #print (STDERR "io.pl---111-i-$i", Dumper($form->{PRICES}));
+    # build in dragdrop for pricesgroups
+    if ($form->{"prices_$i"}) {
+ print STDERR " YES  prices\n";
+      $price_tmp = $form->format_amount(\%myconfig, $form->{"price_new_$i"}, 2);
+
+      $column_data{sellprice_drag} =
+        qq|<td align=right><select name="sellprice_drag_$i">$form->{"prices_$i"}</select></td>|;
+      $column_data{sellprice} =
+        qq|<td><input name="sellprice_$i" size=5 value=$price_tmp></td>|;
+    } else {
+      print STDERR " NO prices\n";
+      # for last row and report
+      # set pricegroup dragdrop from report menu
+      if ($form->{"sellprice_$i"} != 0) {
+print STDERR "   HIER NOCH FÜR RECHNUNGSAUFRUFE\n";
+print (STDERR "sellprice_$i   ", Dumper($form->{"sellprice_$i"}), " pricegroup_id_$i ", Dumper($form->{"pricegroup_id_$i"}));
+        $prices =
+             qq|<option value="$form->{"sellprice_$i"}--$form->{"pricegroup_id_$i"}" selected>$form->{"pricegroup_$i"}</option>\n|;
+
+        $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
+
+        $column_data{sellprice_drag} =
+          qq|<td align=right><select name="sellprice_drag_$i">$prices</select></td>|;
+
+        }else {
+          # for last row
+          $column_data{sellprice_drag} =
+            qq|<td align=right><input name="sellprice_$i" size=9 value=|
+              . $form->format_amount(\%myconfig, $form->{"prices_$i"},
+                               $decimalplaces)
+            . qq|></td>|;
+          }
+
+      $column_data{sellprice} =
+        qq|<td><input name="sellprice_$i" size=5 value=|
+        . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
+                               $decimalplaces)
+        . qq|></td>|;
+    }
+#print (STDERR "io.pl---555-i-$i", Dumper($form->{"price_old_$i"}));
     $column_data{discount} =
         qq|<td align=right><input name="discount_$i" size=3 value=|
       . $form->format_amount(\%myconfig, $form->{"discount_$i"})
@@ -289,6 +340,10 @@ sub display_row {
 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
 <input type=hidden name="bo_$i" value=$form->{"bo_$i"}>
 
+<input type=hidden name="pricegroup_old_$i" value=$form->{"pricegroup_old_$i"}>
+<input type=hidden name="price_old_$i" value=$form->{"price_old_$i"}>
+<input type=hidden name="price_new_$i" value=|.$form->format_amount(\%myconfig,$form->{"price_new_$i"}).qq|>
+
 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
 <input type=hidden name="inventory_accno_$i" value=$form->{"inventory_accno_$i"}>
 <input type=hidden name="bin_$i" value="$form->{"bin_$i"}">
@@ -357,9 +412,53 @@ sub display_row {
   $lxdebug->leave_sub();
 }
 
-sub select_item {
+##################################################
+# build html-code for pricegroups in variable $form->{prices_$j}
+
+sub set_pricegroup {
   $lxdebug->enter_sub();
+print STDERR "io.pl-set_pricegroup-i-$i\n";
+  for $j (1 .. $i) {
+
+    my $pricegroup_old = $form->{"pricegroup_old_$i"};
+    if ($form->{PRICES}{ $j }) {
+      $len    = 0;
+      $prices = '';
+      $price = 0;
+      foreach $item (@{ $form->{PRICES}{ $j } }) {
+print STDERR "TEST--i--$i--jjj-$j\n";
+# print STDERR "-VOR   PREIS--$item->{price}--PREISGRUOP-$item->{pricegroup_id}\n";
+        $price         = $form->round_amount($myconfig, $item->{price},5);
+        $price         = $form->format_amount($myconfig, $item->{price},2);
+        $price         = $item->{price};
+# print STDERR "-NACH PREIS--$price--PREISGRUOP-$item->{pricegroup_id}\n";
+        $pricegroup_id = $item->{pricegroup_id};
+        $pricegroup    = $item->{pricegroup};
+        # build dragdrop for pricegroups
+        $prices .=
+             qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
+
+        $len += 1;
+# print STDERR "prices---$prices\n";
+        # set new selectedpricegroup_id and prices for "Preis"
+        if ($item->{selected}) {
+          $form->{"pricegroup_old_$j"} = $pricegroup_id;
+          $form->{"price_new_$j"} = $price;
+           $form->{"sellprice_$j"} = $price;
+        }
+        if ($len >= 1) {
+          $form->{"prices_$j"} = $prices;
+        }
+      }
+    }
+  }
+  print (STDERR "", Dumper($form->{PRICES}));
+  $lxdebug->leave_sub();
+}
 
+sub select_item {
+  $lxdebug->enter_sub();
+print STDERR "io.pl-select_item\n";
   @column_index = qw(ndx partnumber description onhand sellprice);
 
   $column_data{ndx}        = qq|<th>&nbsp;</th>|;
@@ -411,10 +510,11 @@ sub select_item {
     }
 
     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description unit);
-
+#sk tradediscount
+print STDERR "TRADEDISCOUNT $ref->{sellprice}\n";
     $ref->{sellprice} =
       $form->round_amount($ref->{sellprice} * (1 - $form->{tradediscount}), 2);
-
+print STDERR "TRADEDISCOUNT $ref->{sellprice}\n";
     $column_data{ndx} =
       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
     $column_data{partnumber} =
@@ -496,7 +596,7 @@ sub select_item {
 
 sub item_selected {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-item_selected\n";
   # replace the last row with the checked row
   $i = $form->{rowcount};
   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
@@ -504,6 +604,10 @@ sub item_selected {
   # index for new item
   $j = $form->{ndx};
 
+  #sk
+  #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
+  #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
+
   # if there was a price entered, override it
   $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
@@ -563,6 +667,12 @@ sub item_selected {
       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
   } qw(sellprice listprice) if $form->{item} ne 'assembly';
 
+  # get pricegroups for parts
+  IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+
+  # build up html code for prices_$i
+  set_pricegroup();
+
   &display_form;
 
   $lxdebug->leave_sub();
@@ -638,10 +748,11 @@ sub new_item {
 
 sub display_form {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-display_form\n";
   # if we have a display_form
   if ($form->{display_form}) {
     &{"$form->{display_form}"};
+print STDERR "        --------------------- exit\n";
     exit;
   }
   if (   $form->{print_and_post}
@@ -676,10 +787,23 @@ sub display_form {
   $subroutine = "display_row";
 
   if ($form->{item} eq 'part') {
+print STDERR "  part\n";
+    #set preisgruppenanzahl
+    $numrows    = $form->{price_rows};
+    $subroutine = "price_row";
+
+    &{$subroutine}($numrows);
+
     $numrows    = ++$form->{makemodel_rows};
     $subroutine = "makemodel_row";
   }
   if ($form->{item} eq 'assembly') {
+print STDERR "  assembly\n";
+    $numrows    = ++$form->{price_rows};
+    $subroutine = "price_row";
+
+    &{$subroutine}($numrows);
+
     $numrows    = ++$form->{makemodel_rows};
     $subroutine = "makemodel_row";
 
@@ -690,6 +814,12 @@ sub display_form {
     $subroutine = "assembly_row";
   }
   if ($form->{item} eq 'service') {
+print STDERR "  service\n";
+    $numrows    = ++$form->{price_rows};
+    $subroutine = "price_row";
+
+    &{$subroutine}($numrows);
+
     $numrows = 0;
   }
 
@@ -707,7 +837,7 @@ sub display_form {
 
 sub check_form {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-check_form\n";
   my @a     = ();
   my $count = 0;
   my @flds  = (
@@ -752,6 +882,8 @@ sub check_form {
 
         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
 
+        #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
+
         $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"});
         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"});
         $count++;
@@ -808,6 +940,20 @@ sub check_form {
 
     }
   }
+  
+  #sk 
+print STDERR "LEVEL--$form->{level}\n";
+print STDERR "Type--$form->{type}\n";
+  # if pricegroups
+  if ($form->{type} =~ (/sales_quotation/) or (($form->{level} =~ /Sales/) and ($form->{type} =~ /invoice/)) or (($form->{level} eq undef) and ($form->{type} =~ /invoice/)) or ($form->{type} =~ /sales_order/)) {
+  
+  # get pricegroups for parts
+  IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+
+  # build up html code for prices_$i
+  set_pricegroup();
+  }
 
   &display_form;
 
@@ -829,6 +975,8 @@ sub invoicetotal {
     $discount  = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
     $qty       = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
+    #($form->{"sellprice_$i"}, $form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
+
     $amount = $sellprice * (1 - $discount / 100) * $qty;
     map { $form->{"${_}_base"} += $amount }
       (split / /, $form->{"taxaccounts_$i"});
@@ -852,7 +1000,7 @@ sub invoicetotal {
 
 sub validate_items {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-validate_items\n";
   # check if items are valid
   if ($form->{rowcount} == 1) {
     &update;
@@ -1086,7 +1234,7 @@ sub send_email {
 
 sub print_options {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-print_options\n";
   $form->{sendmode} = "attachment";
   $form->{copies}   = 3 unless $form->{copies};
 
@@ -1243,7 +1391,7 @@ sub print_options {
 
 sub print {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-print\n";
   # if this goes to the printer pass through
   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
     $form->error($locale->text('Select postscript or PDF!'))
@@ -1261,10 +1409,10 @@ sub print {
 sub print_form {
   $lxdebug->enter_sub();
   my ($old_form) = @_;
-
+print STDERR "io.pl-print_form\n";
   $inv = "inv";
   $due = "due";
-
+#print (STDERR "", Dumper($form));
   $numberfld = "invnumber";
 
   $display_form =
@@ -1356,7 +1504,16 @@ sub print_form {
   if (!$form->{"${inv}number"} && !$form->{preview}) {
     $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
     if ($form->{media} ne 'email') {
+        $i = $form->{rowcount};
+        # get pricegroups for parts
+        IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+
+        # build up html code for prices_$i
+        set_pricegroup();
+
       $form->{rowcount}--;
+
       &{"$display_form"};
       exit;
     }
@@ -1552,7 +1709,7 @@ sub print_form {
 
 sub customer_details {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-customer_details\n";
   IS->customer_details(\%myconfig, \%$form);
   $lxdebug->leave_sub();
 }
@@ -1578,23 +1735,29 @@ sub post_as_new {
 
 sub ship_to {
   $lxdebug->enter_sub();
-
+print STDERR "io.pl-ship_to\n";
   $title = $form->{title};
   $form->{title} = $locale->text('Ship to');
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(exchangerate creditlimit creditremaining);
-  $form_id = $form->{id};
+
 
   # get details for name
   &{"$form->{vc}_details"};
-  $form->{id} = $form_id;
 
   $number =
     ($form->{vc} eq 'customer')
     ? $locale->text('Customer Number')
     : $locale->text('Vendor Number');
 
+  $i = $form->{rowcount};
+  # get pricegroups for parts
+  IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+
+  # build up html code for prices_$i
+  set_pricegroup();
+
   $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
 
   $form->{rowcount}--;
index a684593..caa8a0e 100644 (file)
@@ -43,7 +43,7 @@ require "$form->{path}/arap.pl";
 
 sub add {
   $lxdebug->enter_sub();
-
+print STDERR "ir.pl-add\n";
   $form->{title} = $locale->text('Add Vendor Invoice');
 
   &invoice_links;
@@ -67,7 +67,7 @@ sub edit {
 
 sub invoice_links {
   $lxdebug->enter_sub();
-
+print STDERR "ir.pl-invoice_links\n";
   # create links
   $form->{webdav} = $webdav;
 
@@ -160,7 +160,7 @@ sub invoice_links {
 
 sub prepare_invoice {
   $lxdebug->enter_sub();
-
+print STDERR "ir.pl-prepare_invoice\n";
   if ($form->{id}) {
 
     map { $form->{$_} =~ s/\"/&quot;/g } qw(invnumber ordnumber quonumber);
@@ -188,7 +188,7 @@ sub prepare_invoice {
 
 sub form_header {
   $lxdebug->enter_sub();
-
+print STDERR "ir.pl-form_header\n";
   # set option selected
   foreach $item (qw(AP vendor currency department contact)) {
     $form->{"select$item"} =~ s/ selected//;
@@ -304,6 +304,7 @@ sub form_header {
 <input type=hidden name=title value="$form->{title}">
 <input type=hidden name=vc value="vendor">
 <input type=hidden name=type value=$form->{type}>
+<input type=hidden name=level value=$form->{level}>
 
 <input type=hidden name=creditlimit value=$form->{creditlimit}>
 <input type=hidden name=creditremaining value=$form->{creditremaining}>
@@ -416,7 +417,7 @@ $jsscript
 
 sub form_footer {
   $lxdebug->enter_sub();
-
+print STDERR "ir.pl-form_footer\n";
   $form->{invtotal} = $form->{invsubtotal};
 
   if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
index 4e6a066..31d017e 100644 (file)
@@ -33,6 +33,7 @@
 
 use SL::IS;
 use SL::PE;
+use Data::Dumper;
 
 require "$form->{path}/io.pl";
 require "$form->{path}/arap.pl";
@@ -66,7 +67,7 @@ sub add {
 
 sub edit {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-edit\n";
   $form->{title} = $locale->text('Edit Sales Invoice');
 
   if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
@@ -83,7 +84,7 @@ sub edit {
 
 sub invoice_links {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-invoice_links\n";
   $form->{vc} = 'customer';
 
   # create links
@@ -183,7 +184,7 @@ sub invoice_links {
 
 sub prepare_invoice {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-prepare_invoice\n";
   $form->{type}     = "invoice";
   $form->{formname} = "invoice";
   $form->{format}   = "html";
@@ -194,12 +195,14 @@ sub prepare_invoice {
     map { $form->{$_} =~ s/\"/&quot;/g }
       qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
 
+#     # get pricegroups for parts
+#     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+
     foreach $ref (@{ $form->{invoice_details} }) {
       $i++;
       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
       $form->{"discount_$i"} =
         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-
       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
       $dec           = length $dec;
       $decimalplaces = ($dec > 2) ? $dec : 2;
@@ -212,6 +215,10 @@ sub prepare_invoice {
       map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
         qw(partnumber description unit partnotes);
       $form->{rowcount} = $i;
+
+#      # build up html code for prices_$i
+# print STDERR "set_pricegroup aus is.pl-prepare_invoice\n";
+#      set_pricegroup();
     }
   }
   $lxdebug->leave_sub();
@@ -219,7 +226,7 @@ sub prepare_invoice {
 
 sub form_header {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-form_header\n";
   # set option selected
   foreach $item (qw(AR customer currency department employee contact)) {
     $form->{"select$item"} =~ s/ selected//;
@@ -389,6 +396,7 @@ sub form_header {
              <tr>
                <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
                <td colspan=3>$customer</td>
+    <input type=hidden name=customer_klass value=$form->{customer_klass}>
                <input type=hidden name=customer_id value=$form->{customer_id}>
                <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
                 <th align=richt nowrap>|
@@ -514,7 +522,7 @@ $jsscript
 
 sub form_footer {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-form_footer\n";
   $form->{invtotal} = $form->{invsubtotal};
 
   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
@@ -852,7 +860,7 @@ sub form_footer {
 
 sub update {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-update\n";
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(exchangerate creditlimit creditremaining);
 
@@ -916,7 +924,7 @@ sub update {
       } else {
 
         $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
-
+#print STDERR " SELLPRICE-111- $sellprice\n";
         map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
           qw(partnumber description unit);
         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
@@ -973,6 +981,11 @@ sub update {
           }
         }
 
+        # get pricegroups for parts
+        IS->get_pricegroups_for_parts(\%myconfig, \%$form, "new");
+
+        # build up html code for prices_$i
+        set_pricegroup();
       }
 
       &display_form;
@@ -1003,7 +1016,7 @@ sub update {
 
 sub post {
   $lxdebug->enter_sub();
-
+print STDERR "is.pl-post\n";
   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
   $form->isblank("customer", $locale->text('Customer missing!'));
 
index 44bfbd4..482b4c7 100644 (file)
@@ -241,14 +241,12 @@ sub form_header {
     $button1 = qq|
        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
        <td><input type=button name=transdate id="trigger1" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
       |;
     $button2 = qq|
        <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
        <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
      |;
 
     #write Trigger
@@ -272,11 +270,9 @@ sub form_header {
          <table>
            <tr>
              <th nowrap><input name=closed type=radio class=radio value=0 $checkedopen> |
-      . $locale->text('Open')
-      . qq|</th>
+      . $locale->text('Open') . qq|</th>
              <th nowrap><input name=closed type=radio class=radio value=1 $checkedclosed> |
-      . $locale->text('Closed')
-      . qq|</th>
+      . $locale->text('Closed') . qq|</th>
            </tr>
          </table>
        </td>
@@ -345,8 +341,7 @@ sub form_header {
                     <tr>
                      <th align=right nowrap>| . $locale->text('Terms: Net') . qq|</th>
                      <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |
-    . $locale->text('days')
-    . qq|</td>
+    . $locale->text('days') . qq|</td>
                     </tr>
 |;
 
@@ -371,14 +366,12 @@ sub form_header {
              </tr>
              <tr>
                <th width=70% align=right nowrap>|
-      . $locale->text('Quotation Number')
-      . qq|</th>
+      . $locale->text('Quotation Number') . qq|</th>
                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
              </tr>
               <tr>
                <th width=70% align=right nowrap>|
-      . $locale->text('Customer Order Number')
-      . qq|</th>
+      . $locale->text('Customer Order Number') . qq|</th>
                 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
              </tr>
              <tr>
@@ -419,8 +412,7 @@ sub form_header {
       $ordnumber = qq|
              <tr>
                <th width=70% align=right nowrap>|
-        . $locale->text('Quotation Number')
-        . qq|</th>
+        . $locale->text('Quotation Number') . qq|</th>
                <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
                <input type=hidden name=ordnumber value="$form->{ordnumber}">
              </tr>
@@ -471,6 +463,7 @@ sub form_header {
   if ($form->{type} eq 'sales_order') {
     if ($form->{selectemployee}) {
       $employee = qq|
+    <input type=hidden name=customer_klass value=$form->{customer_klass}>
              <tr>
                <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
                <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
@@ -481,6 +474,7 @@ sub form_header {
     }
   } else {
     $employee = qq|
+    <input type=hidden name=customer_klass value=$form->{customer_klass}>
              <tr>
                <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
                <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
@@ -537,8 +531,7 @@ sub form_header {
                <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
                <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
                 <th align=richt nowrap>|
-    . $locale->text('Contact Person')
-    . qq|</th>
+    . $locale->text('Contact Person') . qq|</th>
                 <td colspan=3>$contact</td>
              </tr>
              $creditremaining
@@ -633,8 +626,7 @@ sub form_footer {
   if ($form->{taxaccounts}) {
     $taxincluded = qq|
              <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
-      . $locale->text('Tax Included')
-      . qq|</b><br><br>
+      . $locale->text('Tax Included') . qq|</b><br><br>
 |;
   }
 
@@ -888,7 +880,9 @@ sub update {
                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
                     )));
 
-  my $i = $form->{rowcount};
+  # for pricegroups
+  $i = $form->{rowcount};
+
   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
   if (   ($form->{"partnumber_$i"} eq "")
@@ -940,6 +934,7 @@ sub update {
           $form->{"sellprice_$i"} = $sellprice;
         } else {
 
+          $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
           # if there is an exchange rate adjust sellprice
           $form->{"sellprice_$i"} /= $exchangerate;
         }
@@ -961,6 +956,12 @@ sub update {
                                $decimalplaces);
         $form->{"qty_$i"} =
           $form->format_amount(\%myconfig, $form->{"qty_$i"});
+
+        # get pricegroups for parts
+        IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+
+        # build up html code for prices_$i
+        set_pricegroup();
       }
 
       &display_form;
@@ -1046,7 +1047,8 @@ sub search {
       $form->{warehouse}       = qq|$form->{warehouse}--$form->{warehouse_id}|;
 
       map {
-        $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n"
+        $form->{selectwarehouse} .=
+          "<option>$_->{description}--$_->{id}\n"
       } (@{ $form->{all_warehouses} });
 
       $warehouse = qq|
@@ -1099,11 +1101,9 @@ sub search {
     $openclosed = qq|
              <tr>
                <td><input name="open" class=checkbox type=checkbox value=1 checked> |
-      . $locale->text('Open')
-      . qq|</td>
+      . $locale->text('Open') . qq|</td>
                <td><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |
-      . $locale->text('Closed')
-      . qq|</td>
+      . $locale->text('Closed') . qq|</td>
              </tr>
 |;
   } else {
@@ -1122,14 +1122,12 @@ sub search {
     $button1 = qq|
        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
        <input type=button name=transdatefrom id="trigger3" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
       |;
     $button2 = qq|
        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
        <input type=button name=transdateto name=transdateto id="trigger4" value=|
-      . $locale->text('button')
-      . qq|></td>
+      . $locale->text('button') . qq|></td>
      |;
 
     #write Trigger
@@ -1187,34 +1185,27 @@ sub search {
                | . $locale->text('ID') . qq|</td>
                <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
                <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
-    . $locale->text('Date')
-    . qq|</td>
+    . $locale->text('Date') . qq|</td>
                <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
-    . $locale->text('Required by')
-    . qq|</td>
+    . $locale->text('Required by') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
                <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
                <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
-    . $locale->text('Ship via')
-    . qq|</td>
+    . $locale->text('Ship via') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
-    . $locale->text('Amount')
-    . qq|</td>
+    . $locale->text('Amount') . qq|</td>
                <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
-    . $locale->text('Tax')
-    . qq|</td>
+    . $locale->text('Tax') . qq|</td>
                <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
-    . $locale->text('Total')
-    . qq|</td>
+    . $locale->text('Total') . qq|</td>
              </tr>
              <tr>
                <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
-    . $locale->text('Subtotal')
-    . qq|</td>
+    . $locale->text('Subtotal') . qq|</td>
              </tr>
            </table>
           </td>
@@ -2119,7 +2110,8 @@ sub ship_receive {
 
     # undo formatting from prepare_order
     map {
-      $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
+      $form->{"${_}_$i"} =
+        $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
     } qw(qty ship);
     $n = ($form->{"qty_$i"} -= $form->{"ship_$i"});
     if (abs($n) > 0
index 201e96b..8d2c07d 100644 (file)
@@ -65,7 +65,9 @@ sub edit {
   if ($form->{type} eq 'partsgroup') {
     PE->get_partsgroup(\%myconfig, \%$form);
   }
-
+  if ($form->{type} eq 'pricegroup') {
+    PE->get_pricegroup(\%myconfig, \%$form);
+  }
   &{"form_$form->{type}_header"};
   &{"form_$form->{type}_footer"};
 
@@ -106,6 +108,21 @@ sub search {
 
   }
 
+  # for pricesgroups
+  if ($form->{type} eq 'pricegroup') {
+    $report        = "pricegroup_report";
+    $sort          = 'pricegroup';
+    $form->{title} = $locale->text('Pricegroup');
+
+    $number = qq|
+       <tr>
+         <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
+         <td><input name=pricegroup size=20></td>
+       </tr>
+|;
+
+  }
+
   $form->header;
 
   print qq|
@@ -130,8 +147,7 @@ sub search {
          <td><input name=status class=radio type=radio value=all checked>&nbsp;|
     . $locale->text('All') . qq|
          <input name=status class=radio type=radio value=orphaned>&nbsp;|
-    . $locale->text('Orphaned')
-    . qq|</td>
+    . $locale->text('Orphaned') . qq|</td>
        </tr>
       </table>
     </td>
@@ -397,6 +413,13 @@ sub save {
     $form->redirect($locale->text('Group saved!'));
   }
 
+  # choice pricegroup and save
+  if ($form->{type} eq 'pricegroup') {
+    $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
+    PE->save_pricegroup(\%myconfig, \%$form);
+    $form->redirect($locale->text('Pricegroup saved!'));
+  }
+
   $lxdebug->leave_sub();
 }
 
@@ -411,6 +434,9 @@ sub delete {
   if ($form->{type} eq 'partsgroup') {
     $form->redirect($locale->text('Group deleted!'));
   }
+  if ($form->{type} eq 'pricegroup') {
+    $form->redirect($locale->text('Pricegroup deleted!'));
+  }
 
   $lxdebug->leave_sub();
 }
@@ -534,7 +560,7 @@ sub partsgroup_report {
 sub form_partsgroup_header {
   $lxdebug->enter_sub();
 
-  $form->{title} = $locale->text("$form->{title} Group");
+  $form->{title} = $locale->text("$form->{title} Pricegroup");
 
   # $locale->text('Add Group')
   # $locale->text('Edit Group')
@@ -560,7 +586,7 @@ sub form_partsgroup_header {
     <td>
       <table width=100%>
        <tr>
-         <th align=right>| . $locale->text('Group') . qq|</th>
+         <th align=right>| . $locale->text('Pricegroup') . qq|</th>
 
           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
        </tr>
@@ -611,3 +637,205 @@ sub form_partsgroup_footer {
 
   $lxdebug->leave_sub();
 }
+
+#################################
+# get pricesgroups and build up html-code
+#
+sub pricegroup_report {
+  $lxdebug->enter_sub();
+
+  map { $form->{$_} = $form->unescape($form->{$_}) } (pricegroup);
+  PE->pricegroups(\%myconfig, \%$form);
+
+  $callback =
+    "$form->{script}?action=pricegroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
+
+  if ($form->{status} eq 'all') {
+    $option = $locale->text('All');
+  }
+  if ($form->{status} eq 'orphaned') {
+    $option .= $locale->text('Orphaned');
+  }
+  if ($form->{pricegroup}) {
+    $callback .= "&pricegroup=$form->{pricegroup}";
+    $option   .=
+      "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
+  }
+
+  @column_index = $form->sort_columns(qw(pricegroup));
+
+  $column_header{pricegroup} =
+      qq|<th class=listheading width=90%>|
+    . $locale->text('Pricegroup')
+    . qq|</th>|;
+
+  $form->{title} = $locale->text('Pricegroup');
+
+  $form->header;
+
+  print qq|
+<body>
+
+<table width=100%>
+  <tr>
+    <th class=listtop>$form->{title}</th>
+  </tr>
+  <tr height="5"></tr>
+  <tr>
+    <td>$option</td>
+  </tr>
+  <tr>
+    <td>
+      <table width=100%>
+       <tr class=listheading>
+|;
+
+  map { print "$column_header{$_}\n" } @column_index;
+
+  print qq|
+        </tr>
+|;
+
+  # escape callback
+  $form->{callback} = $callback;
+
+  # escape callback for href
+  $callback = $form->escape($callback);
+
+  foreach $ref (@{ $form->{item_list} }) {
+
+    $i++;
+    $i %= 2;
+
+    print qq|
+        <tr valign=top class=listrow$i>
+|;
+    $column_data{pricegroup} =
+      qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{pricegroup}</td>|;
+
+    map { print "$column_data{$_}\n" } @column_index;
+
+    print "
+        </tr>
+";
+  }
+
+  print qq|
+      </table>
+    </td>
+  </tr>
+  <tr>
+    <td><hr size=3 noshade></td>
+  </tr>
+</table>
+
+<br>
+<form method=post action=$form->{script}>
+
+<input name=callback type=hidden value="$form->{callback}">
+
+<input type=hidden name=type value=$form->{type}>
+
+<input type=hidden name=path value=$form->{path}>
+<input type=hidden name=login value=$form->{login}>
+<input type=hidden name=password value=$form->{password}>
+
+<input class=submit type=submit name=action value="|
+    . $locale->text('Add') . qq|">|;
+
+  if ($form->{menubar}) {
+    require "$form->{path}/menu.pl";
+    &menubar;
+  }
+
+  print qq|
+  </form>
+
+</body>
+</html>
+|;
+
+  $lxdebug->leave_sub();
+}
+
+#######################
+#build up pricegroup_header
+#
+sub form_pricegroup_header {
+  $lxdebug->enter_sub();
+
+  $form->{title} = $locale->text("$form->{title} Group");
+
+  $form->{pricegroup} =~ s/\"/&quot;/g;
+
+  $form->header;
+
+  print qq|
+<body>
+
+<form method=post action=$form->{script}>
+
+<input type=hidden name=id value=$form->{id}>
+<input type=hidden name=type value=$form->{type}>
+
+<table width=100%>
+  <tr>
+    <th class=listtop>$form->{title}</th>
+  </tr>
+  <tr height="5"></tr>
+  <tr>
+    <td>
+      <table width=100%>
+       <tr>
+         <th align=right>| . $locale->text('Preisgruppe') . qq|</th>
+          <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
+       </tr>
+      </table>
+    </td>
+  </tr>
+  <tr>
+    <td colspan=2><hr size=3 noshade></td>
+  </tr>
+</table>
+|;
+
+  $lxdebug->leave_sub();
+}
+######################
+#build up pricegroup_footer
+#
+sub form_pricegroup_footer {
+  $lxdebug->enter_sub();
+
+  print qq|
+
+<input name=callback type=hidden value="$form->{callback}">
+
+<input type=hidden name=path value=$form->{path}>
+<input type=hidden name=login value=$form->{login}>
+<input type=hidden name=password value=$form->{password}>
+
+<br><input type=submit class=submit name=action value="|
+    . $locale->text('Save') . qq|">
+|;
+
+  if ($form->{id} && $form->{orphaned}) {
+    print qq|
+<input type=submit class=submit name=action value="|
+      . $locale->text('Delete') . qq|">|;
+  }
+
+  if ($form->{menubar}) {
+    require "$form->{path}/menu.pl";
+    &menubar;
+  }
+
+  print qq|
+</form>
+
+</body>
+</html>
+|;
+
+  $lxdebug->leave_sub();
+}
index 18401fc..ddeda11 100644 (file)
--- a/menu.ini
+++ b/menu.ini
@@ -35,6 +35,12 @@ module=pe.pl
 action=add
 type=project
 
+#sk
+[Master Data--Add Pricegroup]
+module=pe.pl
+action=add
+type=pricegroup
+
 [Master Data--Add License]
 module=licenses.pl
 action=add
@@ -76,7 +82,6 @@ module=pe.pl
 action=search
 type=partsgroup
 
-
 [Master Data--Reports--Projects]
 module=pe.pl
 action=search
@@ -91,6 +96,12 @@ report=projects
 module=licenses.pl
 action=search
 
+#sk
+[Master Data--Reports--Pricegroups]
+module=pe.pl
+action=search
+type=pricegroup
+
 
 [AR]
 
index 8973fd0..6cfb12b 100644 (file)
@@ -197,6 +197,27 @@ CREATE TABLE audittrail (
   employee_id int
 );
 
+-- pricegroups
+
+CREATE TABLE "pricegroup" (
+  "id" integer DEFAULT nextval('id'::text),
+  "pricegroup" text not null,
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE "prices" (
+  "parts_id" integer REFERENCES parts(id),
+  "pricegroup_id" integer REFERENCES pricegroup(id),
+  "price" numeric(15,5)
+);
+
+ALTER TABLE customer ADD column klass integer;
+ALTER TABLE customer ALTER column klass set default 0;
+
+-- 
+ALTER TABLE invoice ADD column pricegroup_id integer;
+ALTER TABLE orderitems ADD column pricegroup_id integer;
+
 update defaults set version = '2.1.2', audittrail = 't';
 --
 
index 6ccc099..4b1606c 100644 (file)
@@ -160,7 +160,8 @@ CREATE TABLE "invoice" (
        "deliverydate" date,
        "serialnumber" text,
         "itime" timestamp DEFAULT now(),
-        "mtime" timestamp
+        "mtime" timestamp,
+        "pricegroup_id" integer
 );
 
 CREATE TABLE "vendor" (
@@ -241,7 +242,8 @@ CREATE TABLE "customer" (
         "username" varchar(50),
         "user_password" varchar(12),
         "salesman_id" integer,
-        "c_vendor_id" text
+        "c_vendor_id" text,
+        "klass" integer DEFAULT 0
         
 );
 
@@ -394,7 +396,8 @@ CREATE TABLE "orderitems" (
        "serialnumber" text,
        "id" integer DEFAULT nextval('orderitemsid'::text) PRIMARY KEY,
         "itime" timestamp DEFAULT now(),
-        "mtime" timestamp
+        "mtime" timestamp,
+        "pricegroup_id" integer
 );
 
 CREATE TABLE "exchangerate" (
@@ -551,6 +554,22 @@ CREATE TABLE "licenseinvoice" (
   license_id integer
 );
 
+-- Preisgruppenverwaltung
+CREATE TABLE "pricegroup" (
+  "id" integer DEFAULT nextval('id'::text),
+  "pricegroup" text not null,
+  PRIMARY KEY (id)
+);
+--Preisverwaltung der Preisgruppen
+CREATE TABLE "prices" (
+  "parts_id" integer REFERENCES parts(id),
+  "pricegroup_id" integer REFERENCES pricegroup(id),
+  "price" numeric(15,5)
+);
+
+
+
+
 -- Table of tax authoritys
 -- for module ustva
 -- Lx office