Skip to content

Commit

Permalink
S:C:Order: Standard Rabattartikel einfach hinzufügen
Browse files Browse the repository at this point in the history
  • Loading branch information
z4m1n0 committed Jan 18, 2025
1 parent 2d3180e commit f486410
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 6 deletions.
48 changes: 48 additions & 0 deletions SL/Controller/Order.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,54 @@ sub action_add_multi_items {
$self->js->render();
}

sub action_add_discount_item {
my ($self) = @_;
$self->recalc();

my $discount_part_id = $::instance_conf->get_discount_part_id
or die "no discount part set in client config";
my $discount_part = SL::DB::Part->load_cached($discount_part_id);

my $discount_type = $::form->{discount}->{type}
or die "discount.type needed";
my $discount_value_as_number = $::form->{discount}->{value};
my $discount_value = $::form->parse_amount(\%::myconfig, $discount_value_as_number);
$discount_value *= -1 if $discount_value > 0;

$::form->{add_item}->{parts_id} = $discount_part_id;
$::form->{add_item}->{qty_as_number} = 1;
$::form->{add_item}->{unit} = $discount_part->unit;
$::form->{add_item}->{discount_as_percent} = 0;

my $sellprice_as_number;
my $texts = get_part_texts($discount_part, $self->order->language_id);
my $description = $texts->{description};

if ($discount_type eq 'absolute') {
$sellprice_as_number = $::form->format_amount(\%::myconfig, $discount_value, 2, 0);
my $price_as_text = $::form->format_amount(\%::myconfig, -1 * $discount_value, 2, 0);

my $currency = $self->order->currency->name;
$description =~ s/<%discount_value%>/$price_as_text $currency/;
} elsif ($discount_type eq 'percent') {
$sellprice_as_number = $::form->format_amount(
\%::myconfig,
$self->order->amount * $::form->parse_amount(\%::myconfig, $discount_value) / 100,
2, 0
);
my $procent_as_text = $::form->format_amount(\%::myconfig, -1 * $discount_value);

$description =~ s/<%discount_value%>/$procent_as_text%/;
} else {
die "unknown discount.type $discount_type";
}

$::form->{add_item}->{sellprice_as_number} = $sellprice_as_number;
$::form->{add_item}->{description} = $description;

$self->action_add_item();
}

# recalculate all linetotals, amounts and taxes and redisplay them
sub action_recalc_amounts_and_taxes {
my ($self) = @_;
Expand Down
6 changes: 6 additions & 0 deletions SL/DB/MetaSetup/Default.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ __PACKAGE__->meta->columns(
delivery_date_interval => { type => 'integer', default => '0' },
deliverydate_on => { type => 'boolean', default => 'true' },
disabled_price_sources => { type => 'array' },
discount_part_id => { type => 'integer' },
doc_delete_printfiles => { type => 'boolean', default => 'false' },
doc_files => { type => 'boolean', default => 'false' },
doc_files_rootpath => { type => 'text', default => './documents' },
Expand Down Expand Up @@ -284,6 +285,11 @@ __PACKAGE__->meta->foreign_keys(
key_columns => { currency_id => 'id' },
},

discount_part => {
class => 'SL::DB::Part',
key_columns => { discount_part_id => 'id' },
},

loss_carried_forward_chart => {
class => 'SL::DB::Chart',
key_columns => { loss_carried_forward_chart_id => 'id' },
Expand Down
11 changes: 11 additions & 0 deletions js/kivi.Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ namespace('kivi.Order', function(ns) {
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.add_discount_item = function() {
if (!ns.check_cv()) return;

$('#row_table_id thead a img').remove();

var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/add_discount_item' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.delete_order_item_row = function(clicked) {
var row = $(clicked).parents("tbody").first();
$(row).remove();
Expand Down
6 changes: 6 additions & 0 deletions locale/de/all
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ $self->{texts} = {
'Abbreviation Legend' => 'Beschreibung der Typ-Abkürzungen (1 Zeichen Typ, 1-2 Zeichen Klassifizierung)',
'Abort' => 'Abbrechen',
'Abrechnungsnummer' => 'Abrechnungsnummer',
'Absolute' => 'Absolute',
'Absolute BB Balance' => 'Gesamtsaldo laut Bankbuchungen',
'Absolute BT Balance' => 'Gesamtsaldo laut Kontoauszug',
'Acc Transaction' => 'Hauptbuch',
Expand Down Expand Up @@ -247,6 +248,7 @@ $self->{texts} = {
'Add custom report query' => 'Benutzerdefinierte Berichts-Abfrage erfassen',
'Add custom variable' => 'Benutzerdefinierte Variable erfassen',
'Add department' => 'Abteilung hinzufügen',
'Add discount' => 'Rabatt hinzufügen',
'Add document for' => 'Dokument hinzügen für ',
'Add document for AP transactions' => 'Dokumente für Kreditorenbuchung hinzufügen (benötigt DMS)',
'Add document for AR transactions' => 'Dokumente für Debitorenbuchung hinzufügen (benötigt DMS)',
Expand Down Expand Up @@ -1156,6 +1158,7 @@ $self->{texts} = {
'Default client' => 'Standardmandant',
'Default currency' => 'Standardwährung',
'Default currency missing!' => 'Standardwährung fehlt!',
'Default discount part' => 'Standard-Rabattartikel',
'Default hourly rate for new customers' => 'Standard-Stundensatz für neue Kunden',
'Default means "if no language selected then..."' => 'Standard bedeutet "wenn keine Sprache ausgewählt, dann..."',
'Default output medium' => 'Standardausgabekanal',
Expand Down Expand Up @@ -1268,6 +1271,7 @@ $self->{texts} = {
'Discard entries with duplicates in database or CSV file' => 'Einträge aus CSV-Datei verwerfen, die es bereits in der Datenbank oder der CSV-Datei gibt',
'Discount' => 'Rabatt',
'Discount #1%' => 'Rabatt #1%',
'Discount part' => 'Rabattartikel',
'Discounts' => 'Rabatte',
'Display' => 'Anzeigen',
'Display file' => 'Datei anzeigen',
Expand Down Expand Up @@ -1965,6 +1969,7 @@ $ ./scripts/installation_check.pl',
'III' => 'III',
'IMPORT' => 'Importiert',
'IV' => 'IV',
'If a part is set, a quick entry for this article is displayed in quotations, order intakes and order confirmations. An absolute amount or a percentage amount of the current items can be selected and this item will be added to the record. The amount or percentage can be included in the item description using the <%discount_value%> placeholder. It is recommended that the discount is added at the end as the percentage is calculated at the point of addition.' => 'Wenn ein Artikel ausgewählt ist, wird eine Schnelleingabe für diesen Artikel in Angeboten, Auftragseingängen und Auftragsbestätigungen angezeigt. Es kann ein absoluter Betrag oder ein Prozentsatz der aktuellen Positionen gewählt werden und dieser Artikel wird dem Beleg hinzugefügt. Der entsprechende Betrag oder Prozentsatz kann mit dem Platzhalter <%discount_value%> in die Artikelbeschreibung übernommen werden. Es wird empfohlen, dies am Ende zu tun, da der Prozentsatz zum Zeitpunkt des Hinzufügens berechnet wird.',
'If all of the following match' => 'Wenn alle der folgenden Bedingungen zutreffen',
'If amounts differ more than "Maximal amount difference" (see settings), this item is marked as invalid.' => 'Weichen die Beträge mehr als die "maximale Betragsabweichung" (siehe Einstellungen) ab, so wird diese Position als ungültig markiert.',
'If checked the taxkey will not be exported in the DATEV Export, but only IF chart taxkeys differ from general ledger taxkeys' => 'Falls angehakt wird der DATEV-Steuerschlüssel bei Buchungen auf dieses Konto nicht beim DATEV-Export mitexportiert, allerdings nur wenn zusätzlich der Konto-Steuerschlüssel vom Buchungs (Hauptbuch) Steuerschlüssel abweicht',
Expand Down Expand Up @@ -2871,6 +2876,7 @@ $ ./scripts/installation_check.pl',
'Payments' => 'Zahlungsausgänge',
'Payments Changeable' => 'Änderbarkeit von Zahlungen',
'Per. Inv.' => 'Wied. Rech.',
'Percent' => 'Prozent',
'Perform check when a gl transaction is posted?' => 'Prüfung durchführen, wenn eine Dialogbuchung gebucht wird?',
'Perform check when a purchase invoice or a payment for a purchase invoice is posted?' => 'Prüfung durchführen, wenn eine Einkaufsrechnung oder ein Zahlungsausgang hierfür gebucht wird?',
'Perform check when a sales invoice or a payment for a sales invoice is posted?' => 'Prüfung durchführen, wenn eine Verkaufsrechnung oder ein Zahlungseingang hierfür gebucht wird?',
Expand Down
6 changes: 6 additions & 0 deletions locale/en/all
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ $self->{texts} = {
'Abbreviation Legend' => '',
'Abort' => '',
'Abrechnungsnummer' => '',
'Absolute' => '',
'Absolute BB Balance' => '',
'Absolute BT Balance' => '',
'Acc Transaction' => '',
Expand Down Expand Up @@ -247,6 +248,7 @@ $self->{texts} = {
'Add custom report query' => '',
'Add custom variable' => '',
'Add department' => '',
'Add discount' => '',
'Add document for' => '',
'Add document for AP transactions' => '',
'Add document for AR transactions' => '',
Expand Down Expand Up @@ -1156,6 +1158,7 @@ $self->{texts} = {
'Default client' => '',
'Default currency' => '',
'Default currency missing!' => '',
'Default discount part' => '',
'Default hourly rate for new customers' => '',
'Default means "if no language selected then..."' => '',
'Default output medium' => '',
Expand Down Expand Up @@ -1268,6 +1271,7 @@ $self->{texts} = {
'Discard entries with duplicates in database or CSV file' => '',
'Discount' => '',
'Discount #1%' => '',
'Discount part' => '',
'Discounts' => '',
'Display' => '',
'Display file' => '',
Expand Down Expand Up @@ -1964,6 +1968,7 @@ $self->{texts} = {
'III' => '',
'IMPORT' => '',
'IV' => '',
'If a part is set, a quick entry for this article is displayed in quotations, order intakes and order confirmations. An absolute amount or a percentage amount of the current items can be selected and this item will be added to the record. The amount or percentage can be included in the item description using the <%discount_value%> placeholder. It is recommended that the discount is added at the end as the percentage is calculated at the point of addition.' => '',
'If all of the following match' => '',
'If amounts differ more than "Maximal amount difference" (see settings), this item is marked as invalid.' => '',
'If checked the taxkey will not be exported in the DATEV Export, but only IF chart taxkeys differ from general ledger taxkeys' => '',
Expand Down Expand Up @@ -2870,6 +2875,7 @@ $self->{texts} = {
'Payments' => '',
'Payments Changeable' => '',
'Per. Inv.' => '',
'Percent' => '',
'Perform check when a gl transaction is posted?' => '',
'Perform check when a purchase invoice or a payment for a purchase invoice is posted?' => '',
'Perform check when a sales invoice or a payment for a sales invoice is posted?' => '',
Expand Down
5 changes: 5 additions & 0 deletions sql/Pg-upgrade2/defaults_add_discount_part.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- @tag: defaults_add_discount_part
-- @description: Mandantenkonfiguration für Rabattartikel
-- @depends: release_3_9_0

ALTER TABLE defaults ADD COLUMN discount_part_id INTEGER references parts(id);
18 changes: 13 additions & 5 deletions templates/design40_webpages/client_config/_features.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@
<tr>
<th class="caption" colspan="3"> [% 'E-mail' | $T8 %] </th>
</tr>
<tr>
<th>[% LxERP.t8('Invoice email settings') %]</th>
<td>
[% L.select_tag('defaults.invoice_mail_settings', [ [ 'cp', LxERP.t8('Contact Person') ],[ 'invoice_mail', LxERP.t8('Invoice email') ],[ 'invoice_mail_cc_cp', LxERP.t8('Invoice email and Contact Person') ] ], default=SELF.defaults.invoice_mail_settings) %]
</td>
<td class="long-desc">[% 'The invoice recipient can either be a selected contact person (default) or the email adress set in the master data of the customer. Additionally a contact persons mail and the company\'s invoicing mail can be combined.' | $T8 %]</td>
</tr>
<tr>
<th>[% LxERP.t8('Global Record BCC') %]</th>
<td colspan="2"> [% L.input_tag('defaults.global_bcc', SELF.defaults.global_bcc, class='wi-wide') %] <div class="description">[% 'Manually sent E-Mails will have their BCC field appended with this address. Will not trigger for employees without the right to send bcc, and will not apply to mails sent by automated jobs.' | $T8 %]</div></td>
Expand Down Expand Up @@ -481,11 +488,12 @@
<td class="long-desc">[% LxERP.t8('Before saving a sales order, this article will be checked and a warning is generated.') %]</td>
</tr>
<tr>
<th>[% LxERP.t8('Invoice email settings') %]</th>
<td>
[% L.select_tag('defaults.invoice_mail_settings', [ [ 'cp', LxERP.t8('Contact Person') ],[ 'invoice_mail', LxERP.t8('Invoice email') ],[ 'invoice_mail_cc_cp', LxERP.t8('Invoice email and Contact Person') ] ], default=SELF.defaults.invoice_mail_settings) %]
</td>
<td class="long-desc">[% 'The invoice recipient can either be a selected contact person (default) or the email adress set in the master data of the customer. Additionally a contact persons mail and the company\'s invoicing mail can be combined.' | $T8 %]</td>
<th class="caption" colspan="3">[% LxERP.t8('Discount part') %]</th>
</tr>
<tr>
<th>[% LxERP.t8('Default discount part') %]</th>
<td>[% P.part.picker('defaults.discount_part_id', SELF.defaults.discount_part_id, class='wi-mediumsmall') %]</td>
<td class="long-desc">[% LxERP.t8('If a part is set, a quick entry for this article is displayed in quotations, order intakes and order confirmations. An absolute amount or a percentage amount of the current items can be selected and this item will be added to the record. The amount or percentage can be included in the item description using the <%discount_value%> placeholder. It is recommended that the discount is added at the end as the percentage is calculated at the point of addition.') %]</td>
</tr>
<tr>
<th class="caption" colspan="3">[% LxERP.t8("Requirement Specs") %]</th>
Expand Down
20 changes: 19 additions & 1 deletion templates/design40_webpages/order/tabs/_item_input.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,23 @@
</tr>
</tbody>
</table>
</div><!-- /.entry-panel -->
</div><!-- new part -->

[%- IF INSTANCE_CONF.get_discount_part_id %]
<div class="input-panel control-panel short">
<table id="input_row_table_id" class="tbl-plain condensed">
<caption>[% 'Add discount' | $T8 %]!</caption>
<tbody>
<tr>
<td class="tooltipster-html" title="[%- 'Add discount' | $T8 -%]">
<span class="label above">[% 'Discount' | $T8 %] </span>
[% L.input_tag('discount.value', 0, class='reformat_number numeric wi-small') %]
[% L.select_tag('discount.type', [['percent', LxERP.t8('Percent')], ['absolute', LxERP.t8('Absolute')]]) %]
[% L.button_tag('kivi.Order.add_discount_item()', LxERP.t8('+')) %]
</tr>
</tbody>
</table>
</div><!-- discount part -->
[%- END %]

</div><!-- /.wrapper -->

0 comments on commit f486410

Please sign in to comment.