Zahlungsbedingungen bei Lieferscheinen; veraltete Spalte »terms« entfernt
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 18 Jun 2015 11:50:27 +0000 (13:50 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 18 Jun 2015 11:51:37 +0000 (13:51 +0200)
15 files changed:
SL/AR.pm
SL/DB/DeliveryOrder.pm
SL/DB/Helper/FlattenToForm.pm
SL/DB/Invoice.pm
SL/DB/MetaSetup/Customer.pm
SL/DB/MetaSetup/DeliveryOrder.pm
SL/DB/MetaSetup/Invoice.pm
SL/DB/MetaSetup/Vendor.pm
SL/DO.pm
SL/Form.pm
SL/IR.pm
SL/IS.pm
bin/mozilla/do.pl
sql/Pg-upgrade2/remove_terms_add_payment_id.sql [new file with mode: 0644]
templates/webpages/do/form_header.html

index 81be410..3ee8e0d 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -458,7 +458,7 @@ sub ar_transactions {
   my $query =
     qq|SELECT DISTINCT a.id, a.invnumber, a.ordnumber, a.cusordnumber, a.transdate, | .
     qq|  a.duedate, a.netamount, a.amount, a.paid, | .
-    qq|  a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, | .
+    qq|  a.invoice, a.datepaid, a.notes, a.shipvia, | .
     qq|  a.shippingpoint, a.storno, a.storno_id, a.globalproject_id, | .
     qq|  a.marge_total, a.marge_percent, | .
     qq|  a.transaction_description, | .
index 436c9b1..3afd591 100644 (file)
@@ -50,6 +50,7 @@ sub _before_save_set_donumber {
 
 sub items { goto &orderitems; }
 sub add_items { goto &add_orderitems; }
+sub payment_terms { goto &payment; }
 
 sub sales_order {
   my $self   = shift;
@@ -104,15 +105,12 @@ sub new_from {
     $item_parent_column    = 'order';
   }
 
-  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0;
-
   my %args = ( map({ ( $_ => $source->$_ ) } qw(cp_id currency_id customer_id cusordnumber department_id employee_id globalproject_id intnotes language_id notes
-                                                ordnumber reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id
+                                                ordnumber payment_id reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id
                                              )),
                closed    => 0,
                is_sales  => !!$source->customer_id,
                delivered => 0,
-               terms     => $terms,
                transdate => DateTime->today_local,
             );
 
index 9c34958..9cf2d11 100644 (file)
@@ -16,7 +16,7 @@ sub flatten_to_form {
 
   _copy($self, $form, '', '', 0, qw(id type taxzone_id ordnumber quonumber invnumber donumber cusordnumber taxincluded shippingpoint shipvia notes intnotes cp_id
                                     employee_id salesman_id closed department_id language_id payment_id delivery_customer_id delivery_vendor_id shipto_id proforma
-                                    globalproject_id delivered transaction_description container_type accepted_by_customer invoice terms storno storno_id dunning_config_id
+                                    globalproject_id delivered transaction_description container_type accepted_by_customer invoice storno storno_id dunning_config_id
                                     orddate quodate reqdate gldate duedate deliverydate datepaid transdate delivery_term_id));
   $form->{currency} = $form->{curr} = $self->currency_id ? $self->currency->name || '' : '';
 
index 065d2b3..82cf66b 100644 (file)
@@ -138,14 +138,10 @@ sub new_from {
 
   require SL::DB::Employee;
 
-  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms
-            : $source->customer_id                              ? $source ->customer->payment_terms
-            :                                                     undef;
-
   my (@columns, @item_columns, $item_parent_id_column, $item_parent_column);
 
   if (ref($source) eq 'SL::DB::Order') {
-    @columns      = qw(quonumber payment_id delivery_customer_id delivery_vendor_id);
+    @columns      = qw(quonumber delivery_customer_id delivery_vendor_id);
     @item_columns = qw(subtotal);
 
     $item_parent_id_column = 'trans_id';
@@ -158,12 +154,13 @@ sub new_from {
     $item_parent_column    = 'delivery_order';
   }
 
+  my $terms = $source->can('payment_id') ? $source->payment_terms : undef;
+
   my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes salesman_id cusordnumber ordnumber department_id
-                                                cp_id language_id taxzone_id shipto_id globalproject_id transaction_description currency_id delivery_term_id), @columns),
+                                                cp_id language_id taxzone_id shipto_id globalproject_id transaction_description currency_id delivery_term_id payment_id), @columns),
                transdate   => DateTime->today_local,
                gldate      => DateTime->today_local,
-               duedate     => DateTime->today_local->add(days => ($terms ? $terms->terms_netto * 1 : 1)),
-               payment_id  => $terms ? $terms->id : undef,
+               duedate     => $terms ? $terms->calc_date(reference_date => DateTime->today_local) : DateTime->today_local,
                invoice     => 1,
                type        => 'invoice',
                storno      => 0,
index deab35b..f88df86 100644 (file)
@@ -54,7 +54,6 @@ __PACKAGE__->meta->columns(
   taxincluded_checked       => { type => 'boolean' },
   taxnumber                 => { type => 'text' },
   taxzone_id                => { type => 'integer', not_null => 1 },
-  terms                     => { type => 'integer', default => '0' },
   user_password             => { type => 'text' },
   username                  => { type => 'text' },
   ustid                     => { type => 'text' },
index c4ee930..a3a2181 100644 (file)
@@ -29,6 +29,7 @@ __PACKAGE__->meta->columns(
   notes                   => { type => 'text' },
   ordnumber               => { type => 'text' },
   oreqnumber              => { type => 'text' },
+  payment_id              => { type => 'integer' },
   reqdate                 => { type => 'date' },
   salesman_id             => { type => 'integer' },
   shippingpoint           => { type => 'text' },
@@ -36,7 +37,6 @@ __PACKAGE__->meta->columns(
   shipvia                 => { type => 'text' },
   taxincluded             => { type => 'boolean' },
   taxzone_id              => { type => 'integer', not_null => 1 },
-  terms                   => { type => 'integer' },
   transaction_description => { type => 'text' },
   transdate               => { type => 'date', default => 'now()' },
   vendor_id               => { type => 'integer' },
@@ -87,6 +87,11 @@ __PACKAGE__->meta->foreign_keys(
     key_columns => { language_id => 'id' },
   },
 
+  payment => {
+    class       => 'SL::DB::PaymentTerm',
+    key_columns => { payment_id => 'id' },
+  },
+
   salesman => {
     class       => 'SL::DB::Employee',
     key_columns => { salesman_id => 'id' },
index ac7f671..15f9bc0 100644 (file)
@@ -53,7 +53,6 @@ __PACKAGE__->meta->columns(
   storno_id                 => { type => 'integer' },
   taxincluded               => { type => 'boolean' },
   taxzone_id                => { type => 'integer', not_null => 1 },
-  terms                     => { type => 'integer', default => '0' },
   transaction_description   => { type => 'text' },
   transdate                 => { type => 'date', default => 'now' },
   type                      => { type => 'text' },
index 0b57e83..3a3c2a4 100644 (file)
@@ -26,7 +26,7 @@ __PACKAGE__->meta->columns(
   department_2     => { type => 'text' },
   depositor        => { type => 'text' },
   direct_debit     => { type => 'boolean', default => 'false' },
-  discount         => { type => 'float', scale => 4 },
+  discount         => { type => 'float', precision => 4, scale => 4 },
   email            => { type => 'text' },
   fax              => { type => 'text' },
   greeting         => { type => 'text' },
@@ -47,7 +47,6 @@ __PACKAGE__->meta->columns(
   taxincluded      => { type => 'boolean' },
   taxnumber        => { type => 'text' },
   taxzone_id       => { type => 'integer', not_null => 1 },
-  terms            => { type => 'integer', default => '0' },
   user_password    => { type => 'text' },
   username         => { type => 'text' },
   ustid            => { type => 'text' },
index 6c3991f..236a173 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -460,7 +460,7 @@ SQL
          shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, closed = ?,
          delivered = ?, department_id = ?, language_id = ?, shipto_id = ?,
          globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?,
-         is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, currency_id = (SELECT id FROM currencies WHERE name = ?),
+         is_sales = ?, taxzone_id = ?, taxincluded = ?, payment_id = ?, currency_id = (SELECT id FROM currencies WHERE name = ?),
          delivery_term_id = ?
        WHERE id = ?|;
 
@@ -475,7 +475,7 @@ SQL
              conv_i($form->{salesman_id}), conv_i($form->{cp_id}),
              $form->{transaction_description},
              $form->{type} =~ /^sales/ ? 't' : 'f',
-             conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{terms}), $form->{currency},
+             conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{payment_id}), $form->{currency},
              conv_i($form->{delivery_term_id}),
              conv_i($form->{id}));
   do_query($form, $dbh, $query, @values);
@@ -689,7 +689,7 @@ sub retrieve {
          d.description AS department, dord.language_id,
          dord.shipto_id,
          dord.globalproject_id, dord.delivered, dord.transaction_description,
-         dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.name FROM currencies cu WHERE cu.id=dord.currency_id) AS currency,
+         dord.taxzone_id, dord.taxincluded, dord.payment_id, (SELECT cu.name FROM currencies cu WHERE cu.id=dord.currency_id) AS currency,
          dord.delivery_term_id, dord.itime::DATE AS insertdate
        FROM delivery_orders dord
        JOIN ${vc} cv ON (dord.${vc}_id = cv.id)
index b0709de..9209f3a 100644 (file)
@@ -2919,7 +2919,6 @@ sub lastname_used {
                     "d.description"           => "department",
                     "ct.name"                 => $table,
                     "cu.name"                 => "currency",
-                    "current_date + ct.terms" => "duedate",
     );
 
   if ($self->{type} =~ /delivery_order/) {
index 8bd2f5f..a1cbb4d 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -1129,7 +1129,7 @@ sub get_vendor {
   my $query =
     qq|SELECT
          v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount,
-         v.creditlimit, v.terms, v.notes AS intnotes,
+         v.creditlimit, v.notes AS intnotes,
          v.email, v.cc, v.bcc, v.language_id, v.payment_id, v.delivery_term_id,
          v.street, v.zipcode, v.city, v.country, v.taxzone_id, cu.name AS curr, v.direct_debit,
          $duedate + COALESCE(pt.terms_netto, 0) AS duedate,
index a6445a3..687c437 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -68,9 +68,6 @@ sub invoice_details {
   my $dbh = $form->get_standard_dbh;
   my $sth;
 
-  my $query = qq|SELECT date | . conv_dateq($form->{duedate}) . qq| - date | . conv_dateq($form->{invdate}) . qq| AS terms|;
-  ($form->{terms}) = selectrow_query($form, $dbh, $query);
-
   my (@project_ids);
   $form->{TEMPLATE_ARRAYS} = {};
 
@@ -354,7 +351,7 @@ sub invoice_details {
           $sortorder = qq|ORDER BY a.oid|;
         }
 
-        $query =
+        my $query =
           qq|SELECT p.partnumber, p.description, p.unit, a.qty, pg.partsgroup
              FROM assembly a
              JOIN parts p ON (a.parts_id = p.id)
@@ -1170,7 +1167,7 @@ SQL
                 transdate   = ?, orddate       = ?, quodate       = ?, customer_id   = ?,
                 amount      = ?, netamount     = ?, paid          = ?,
                 duedate     = ?, deliverydate  = ?, invoice       = ?, shippingpoint = ?,
-                shipvia     = ?, terms         = ?, notes         = ?, intnotes      = ?,
+                shipvia     = ?,                    notes         = ?, intnotes      = ?,
                 currency_id = (SELECT id FROM currencies WHERE name = ?),
                 department_id = ?, payment_id    = ?, taxincluded   = ?,
                 type        = ?, language_id   = ?, taxzone_id    = ?, shipto_id     = ?,
@@ -1185,7 +1182,7 @@ SQL
              conv_date($form->{"invdate"}),  conv_date($form->{"orddate"}),    conv_date($form->{"quodate"}),    conv_i($form->{"customer_id"}),
                        $amount,                        $netamount,                       $form->{"paid"},
              conv_date($form->{"duedate"}),  conv_date($form->{"deliverydate"}),    '1',                                $form->{"shippingpoint"},
-                       $form->{"shipvia"},      conv_i($form->{"terms"}), $restricter->process($form->{"notes"}),       $form->{"intnotes"},
+                       $form->{"shipvia"},                                $restricter->process($form->{"notes"}),       $form->{"intnotes"},
                        $form->{"currency"},     conv_i($form->{"department_id"}), conv_i($form->{"payment_id"}),        $form->{"taxincluded"} ? 't' : 'f',
                        $form->{"type"},         conv_i($form->{"language_id"}),   conv_i($form->{"taxzone_id"}), conv_i($form->{"shipto_id"}),
                 conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}),   conv_i($form->{storno_id}),           $form->{"storno"} ? 't' : 'f',
@@ -1816,7 +1813,7 @@ sub retrieve_invoice {
            a.invnumber, a.ordnumber, a.quonumber, a.cusordnumber,
            a.orddate, a.quodate, a.globalproject_id,
            a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
-           a.shippingpoint, a.shipvia, a.terms, a.notes, a.intnotes, a.taxzone_id,
+           a.shippingpoint, a.shipvia, a.notes, a.intnotes, a.taxzone_id,
            a.duedate, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.shipto_id, a.cp_id,
            a.employee_id, a.salesman_id, a.payment_id,
            a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type,
@@ -1983,7 +1980,7 @@ sub get_customer {
   # get customer
   $query =
     qq|SELECT
-         c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, c.terms,
+         c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit,
          c.email, c.cc, c.bcc, c.language_id, c.payment_id, c.delivery_term_id,
          c.street, c.zipcode, c.city, c.country,
          c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, cu.name AS curr,
index 6b72eee..1f9419b 100644 (file)
@@ -836,15 +836,6 @@ sub invoice {
   my $currency = $form->{currency};
   invoice_links();
 
-  if ($form->{ordnumber}) {
-    require SL::DB::Order;
-    if (my $order = SL::DB::Manager::Order->find_by(ordnumber => $form->{ordnumber})) {
-      $order->load;
-      $form->{orddate} = $order->transdate_as_date;
-      $form->{$_}      = $order->$_ for qw(payment_id salesman_id taxzone_id quonumber);
-    }
-  }
-
   $form->{currency}     = $currency;
   $form->{exchangerate} = "";
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell);
diff --git a/sql/Pg-upgrade2/remove_terms_add_payment_id.sql b/sql/Pg-upgrade2/remove_terms_add_payment_id.sql
new file mode 100644 (file)
index 0000000..986f433
--- /dev/null
@@ -0,0 +1,23 @@
+-- @tag: remove_terms_add_payment_id
+-- @description: In betroffenen Tabellen die veraltete Spalte »terms« löschen und dort, wo sie fehlt, payment_id ergänzen
+-- @depends: release_3_2_0
+
+ALTER TABLE delivery_orders ADD COLUMN payment_id INTEGER;
+ALTER TABLE delivery_orders ADD FOREIGN KEY (payment_id) REFERENCES payment_terms (id);
+
+UPDATE delivery_orders
+SET payment_id = (
+  SELECT oe.payment_id
+  FROM record_links rl
+  LEFT JOIN oe ON rl.from_id = oe.id
+  WHERE (rl.from_table = 'oe')
+    AND (rl.to_table   = 'delivery_orders')
+    AND (rl.to_id      = delivery_orders.id)
+  ORDER BY rl.itime DESC
+  LIMIT 1
+);
+
+ALTER TABLE ar              DROP COLUMN terms;
+ALTER TABLE customer        DROP COLUMN terms;
+ALTER TABLE delivery_orders DROP COLUMN terms;
+ALTER TABLE vendor          DROP COLUMN terms;
index 2a28853..60059a2 100644 (file)
@@ -84,6 +84,7 @@
   <input type="hidden" name="max_dunning_level" value="[% HTML.escape(max_dunning_level) %]">
   <input type="hidden" name="media" value="[% HTML.escape(media) %]">
   <input type="hidden" name="message" value="[% HTML.escape(message) %]">
+  <input type="hidden" name="payment_id" value="[% HTML.escape(payment_id) %]">
   <input type="hidden" name="printed" value="[% HTML.escape(printed) %]">
   <input type="hidden" name="proforma" value="[% HTML.escape(proforma) %]">
   <input type="hidden" name="queued" value="[% HTML.escape(queued) %]">
   <input type="hidden" name="subject" value="[% HTML.escape(subject) %]">
   <input type="hidden" name="taxincluded" value="[% HTML.escape(taxincluded) %]">
   <input type="hidden" name="taxzone_id" value="[% HTML.escape(taxzone_id) %]">
-  <input type="hidden" name="terms" value="[% HTML.escape(terms) %]">
   <input type="hidden" name="title" value="[% HTML.escape(title) %]">
   <input type="hidden" name="type" value="[% HTML.escape(type) %]">
   <input type="hidden" name="vc" value="[% HTML.escape(vc) %]">