]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/IC.pm
List::MoreUtils für kompakteren Code benutzen.
[kivitendo-erp.git] / SL / IC.pm
index a9360346f2e32481d598f2943b9b6ca1600b864f..5314d4b8e694ca4333e53a27c5b31e9f537745d0 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -35,6 +35,7 @@
 package IC;
 
 use Data::Dumper;
+use List::MoreUtils qw(all);
 use YAML;
 
 use SL::DBUtils;
@@ -308,6 +309,8 @@ sub save {
 
   my ($query, $sth);
 
+  my $priceupdate = ', priceupdate = current_date';
+
   if ($form->{id}) {
 
     # get old price
@@ -338,6 +341,11 @@ sub save {
     # delete translations
     do_query($form, $dbh, qq|DELETE FROM translation WHERE parts_id = ?|, conv_i($form->{id}));
 
+    # Check whether or not the prices have changed. If they haven't
+    # then 'priceupdate' should not be updated.
+    my $previous_values = selectfirst_hashref_query($form, $dbh, qq|SELECT * FROM parts WHERE id = ?|, conv_i($form->{id})) || {};
+    $priceupdate        = '' if (all { $previous_values->{$_} == $form->{$_} } qw(sellprice lastcost listprice));
+
   } else {
     my ($count) = selectrow_query($form, $dbh, qq|SELECT COUNT(*) FROM parts WHERE partnumber = ?|, $form->{partnumber});
     if ($count) {
@@ -393,7 +401,6 @@ sub save {
          sellprice = ?,
          lastcost = ?,
          weight = ?,
-         priceupdate = ?,
          unit = ?,
          notes = ?,
          formel = ?,
@@ -415,6 +422,7 @@ sub save {
          microfiche = ?,
          partsgroup_id = ?,
          price_factor_id = ?
+         $priceupdate
        WHERE id = ?|;
   @values = ($form->{partnumber},
              $form->{description},
@@ -424,7 +432,6 @@ sub save {
              $form->{sellprice},
              $form->{lastcost},
              $form->{weight},
-             conv_date($form->{priceupdate}),
              $form->{unit},
              $form->{notes},
              $form->{formel},