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, | .
sub items { goto &orderitems; }
sub add_items { goto &add_orderitems; }
+sub payment_terms { goto &payment; }
sub sales_order {
my $self = shift;
$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,
);
_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 || '' : '';
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';
$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,
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' },
notes => { type => 'text' },
ordnumber => { type => 'text' },
oreqnumber => { type => 'text' },
+ payment_id => { type => 'integer' },
reqdate => { type => 'date' },
salesman_id => { type => 'integer' },
shippingpoint => { type => 'text' },
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' },
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' },
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' },
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' },
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' },
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 = ?|;
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);
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)
"d.description" => "department",
"ct.name" => $table,
"cu.name" => "currency",
- "current_date + ct.terms" => "duedate",
);
if ($self->{type} =~ /delivery_order/) {
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,
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} = {};
$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)
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 = ?,
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',
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,
# 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,
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);
--- /dev/null
+-- @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;
<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) %]">