From 464f44accd46ed0b2e1f7e2459f53337a6720a7f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 18 Jun 2015 13:50:27 +0200 Subject: [PATCH] =?utf8?q?Zahlungsbedingungen=20bei=20Lieferscheinen;=20ve?= =?utf8?q?raltete=20Spalte=20=C2=BBterms=C2=AB=20entfernt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AR.pm | 2 +- SL/DB/DeliveryOrder.pm | 6 ++--- SL/DB/Helper/FlattenToForm.pm | 2 +- SL/DB/Invoice.pm | 13 ++++------- SL/DB/MetaSetup/Customer.pm | 1 - SL/DB/MetaSetup/DeliveryOrder.pm | 7 +++++- SL/DB/MetaSetup/Invoice.pm | 1 - SL/DB/MetaSetup/Vendor.pm | 3 +-- SL/DO.pm | 6 ++--- SL/Form.pm | 1 - SL/IR.pm | 2 +- SL/IS.pm | 13 ++++------- bin/mozilla/do.pl | 9 -------- .../remove_terms_add_payment_id.sql | 23 +++++++++++++++++++ templates/webpages/do/form_header.html | 2 +- 15 files changed, 49 insertions(+), 42 deletions(-) create mode 100644 sql/Pg-upgrade2/remove_terms_add_payment_id.sql diff --git a/SL/AR.pm b/SL/AR.pm index 81be410e8..3ee8e0d92 100644 --- 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, | . diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index 436c9b1a5..3afd59162 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -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, ); diff --git a/SL/DB/Helper/FlattenToForm.pm b/SL/DB/Helper/FlattenToForm.pm index 9c34958c8..9cf2d119f 100644 --- a/SL/DB/Helper/FlattenToForm.pm +++ b/SL/DB/Helper/FlattenToForm.pm @@ -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 || '' : ''; diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 065d2b3cd..82cf66b5e 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -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, diff --git a/SL/DB/MetaSetup/Customer.pm b/SL/DB/MetaSetup/Customer.pm index deab35bfd..f88df8678 100644 --- a/SL/DB/MetaSetup/Customer.pm +++ b/SL/DB/MetaSetup/Customer.pm @@ -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' }, diff --git a/SL/DB/MetaSetup/DeliveryOrder.pm b/SL/DB/MetaSetup/DeliveryOrder.pm index c4ee93083..a3a218133 100644 --- a/SL/DB/MetaSetup/DeliveryOrder.pm +++ b/SL/DB/MetaSetup/DeliveryOrder.pm @@ -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' }, diff --git a/SL/DB/MetaSetup/Invoice.pm b/SL/DB/MetaSetup/Invoice.pm index ac7f6716f..15f9bc034 100644 --- a/SL/DB/MetaSetup/Invoice.pm +++ b/SL/DB/MetaSetup/Invoice.pm @@ -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' }, diff --git a/SL/DB/MetaSetup/Vendor.pm b/SL/DB/MetaSetup/Vendor.pm index 0b57e83f1..3a3c2a413 100644 --- a/SL/DB/MetaSetup/Vendor.pm +++ b/SL/DB/MetaSetup/Vendor.pm @@ -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' }, diff --git a/SL/DO.pm b/SL/DO.pm index 6c3991f00..236a173c2 100644 --- 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) diff --git a/SL/Form.pm b/SL/Form.pm index b0709dec4..9209f3a73 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -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/) { diff --git a/SL/IR.pm b/SL/IR.pm index 8bd2f5f53..a1cbb4d87 100644 --- 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, diff --git a/SL/IS.pm b/SL/IS.pm index a6445a31d..687c4379d 100644 --- 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, diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index 6b72eeeb0..1f9419b39 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -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 index 000000000..986f433ab --- /dev/null +++ b/sql/Pg-upgrade2/remove_terms_add_payment_id.sql @@ -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; diff --git a/templates/webpages/do/form_header.html b/templates/webpages/do/form_header.html index 2a28853d5..60059a2f9 100644 --- a/templates/webpages/do/form_header.html +++ b/templates/webpages/do/form_header.html @@ -84,6 +84,7 @@ + @@ -105,7 +106,6 @@ - -- 2.20.1