$main::lxdebug->leave_sub();
}
-sub save_price_factor {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- SL::DB->client->with_transaction(sub {
- my $dbh = SL::DB->client->dbh;
-
- my $query;
- my @values = ($form->{description}, conv_i($form->{factor}));
-
- if ($form->{id}) {
- $query = qq|UPDATE price_factors SET description = ?, factor = ? WHERE id = ?|;
- push @values, conv_i($form->{id});
-
- } else {
- $query = qq|INSERT INTO price_factors (description, factor, sortkey) VALUES (?, ?, (SELECT COALESCE(MAX(sortkey), 0) + 1 FROM price_factors))|;
- }
-
- do_query($form, $dbh, $query, @values);
- 1;
- }) or do { die SL::DB->client->error };
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_all_price_factors {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = SL::DB->client->dbh;
-
- $form->{PRICE_FACTORS} = selectall_hashref_query($form, $dbh, qq|SELECT * FROM price_factors ORDER BY sortkey|);
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_price_factor {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = SL::DB->client->dbh;
-
- my $query = qq|SELECT description, factor,
- ((SELECT COUNT(*) FROM parts WHERE price_factor_id = ?) +
- (SELECT COUNT(*) FROM invoice WHERE price_factor_id = ?) +
- (SELECT COUNT(*) FROM orderitems WHERE price_factor_id = ?)) = 0 AS orphaned
- FROM price_factors WHERE id = ?|;
-
- ($form->{description}, $form->{factor}, $form->{orphaned}) = selectrow_query($form, $dbh, $query, (conv_i($form->{id})) x 4);
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_price_factor {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- SL::DB->client->with_transaction(sub {
- do_query($form, SL::DB->client->dbh, qq|DELETE FROM price_factors WHERE id = ?|, conv_i($form->{id}));
- 1;
- }) or do { die SL::DB->client->error };
-
- $main::lxdebug->leave_sub();
-}
-
sub save_warehouse {
$main::lxdebug->enter_sub();
],
},
+ price_factor => {
+ # Make locales.pl happy: $self->render("simple_system_setting/_price_factor_form")
+ class => 'PriceFactor',
+ titles => {
+ list => t8('Price Factors'),
+ add => t8('Add Price Factor'),
+ edit => t8('Edit Price Factor'),
+ },
+ list_attributes => [
+ { method => 'description', title => t8('Description') },
+ { method => 'factor_as_number', title => t8('Factor'), align => 'right' },
+ ],
+ },
+
pricegroup => {
# Make locales.pl happy: $self->render("simple_system_setting/_pricegroup_form")
class => 'Pricegroup',
__PACKAGE__->meta->initialize;
+sub orphaned {
+ my ($self) = @_;
+
+ die 'not an accessor' if @_ > 1;
+
+ require SL::DB::DeliveryOrderItem;
+ require SL::DB::InvoiceItem;
+ require SL::DB::OrderItem;
+ require SL::DB::Part;
+
+ return 1 if !$self->id;
+
+ return 0 if SL::DB::Manager::DeliveryOrderItem->get_first(query => [ price_factor_id => $self->id ]);
+ return 0 if SL::DB::Manager::InvoiceItem ->get_first(query => [ price_factor_id => $self->id ]);
+ return 0 if SL::DB::Manager::OrderItem ->get_first(query => [ price_factor_id => $self->id ]);
+ return 0 if SL::DB::Manager::Part ->get_first(query => [ price_factor_id => $self->id ]);
+
+ return 1;
+}
+
1;
__END__
$main::lxdebug->leave_sub();
}
-sub add_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- $form->{title} = $locale->text('Add Price Factor');
- $form->{callback} ||= build_std_url('action=add_price_factor');
-
- $form->header();
- print $form->parse_html_template('am/edit_price_factor');
-
- $main::lxdebug->leave_sub();
-}
-
-sub edit_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- $form->{title} = $locale->text('Edit Price Factor');
- $form->{callback} ||= build_std_url('action=add_price_factor');
-
- AM->get_price_factor(\%myconfig, $form);
-
- $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
-
- $form->header();
- print $form->parse_html_template('am/edit_price_factor');
-
- $main::lxdebug->leave_sub();
-}
-
-sub list_price_factors {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- AM->get_all_price_factors(\%myconfig, \%$form);
-
- foreach my $current (@{ $form->{PRICE_FACTORS} }) {
- $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
- }
-
- $form->{callback} = build_std_url('action=list_price_factors');
- $form->{title} = $locale->text('Price Factors');
- $form->{url_base} = build_std_url('callback');
-
- $form->header();
- print $form->parse_html_template('am/list_price_factors');
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- $form->isblank("description", $locale->text('Description missing!'));
- $form->isblank("factor", $locale->text('Factor missing!'));
-
- $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
-
- AM->save_price_factor(\%myconfig, $form);
-
- $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
-
- $form->redirect($locale->text('Price factor saved!'));
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- AM->delete_price_factor(\%myconfig, \%$form);
-
- $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
-
- $form->redirect($locale->text('Price factor deleted!'));
-
- $main::lxdebug->leave_sub();
-}
-
sub add_warehouse {
$main::lxdebug->enter_sub();
# run locales.pl from this directory to rebuild the translation files
$self->{texts} = {
- ' (in use so no change allowed)' => ' (Faktor wird verwendet, keine Änderung erlaubt)',
' Date missing!' => ' Datum fehlt!',
' bytes, max=' => ' Bytes, Maximum=',
' missing!' => ' fehlt!',
'Extended status' => 'Erweiterter Status',
'Extension Of Time' => 'Dauerfristverlängerung',
'Factor' => 'Faktor',
- 'Factor missing!' => 'Der Faktor fehlt.',
'Falsches Datumsformat!' => 'Falsches Datumsformat!',
'Fax' => 'Fax',
'Features' => 'Features',
'Not obsolete' => 'Gültig',
'Note' => 'Hinweis',
'Note: Taxkeys must have a "valid from" date, and will not behave correctly without.' => 'Hinweis: Steuerschlüssel sind fehlerhaft ohne "Gültig ab" Datum',
+ 'Note: the object is already in use. Therefore some values cannot be changed.' => 'Anmerkung: das Objekt ist bereits in Benutzung. Einige Werte können daher nicht geändert werden.',
'Notes' => 'Bemerkungen',
'Notes (translation for #1)' => 'Bemerkungen (Übersetzung für #1)',
'Notes (will appear on hard copy)' => 'Bemerkungen',
'Price Types' => 'Preistypen',
'Price factor (database ID)' => 'Preisfaktor (Datenbank-ID)',
'Price factor (name)' => 'Preisfaktor (Name)',
- 'Price factor deleted!' => 'Preisfaktor gelöscht.',
- 'Price factor saved!' => 'Preisfaktor gespeichert.',
'Price group' => 'Preisgruppe',
'Price group (database ID)' => 'Preisgruppe (Datenbank-ID)',
'Price group (name)' => 'Preisgruppe (Name) ',
id: system_price_factors
name: Price Factors
order: 1200
- module: am.pl
params:
- action: list_price_factors
+ action: SimpleSystemSetting/list
+ type: price_factor
- parent: system
id: system_departments
name: Departments
+++ /dev/null
-[%- USE T8 %]
-[%- USE HTML %]
-<h1>[% title %]</h1>
-
-
- [% IF MESSAGE %]<p>[% MESSAGE %]</p>[% END %]
-
- <form method="post" action="am.pl">
-
- <p>
- <table border="0">
- <tr>
- <td align="right">[% 'Description' | $T8 %]</td>
- <td><input id="description" name="description" value="[% HTML.escape(description) %]" class="initial_focus"></td>
- </tr>
-
- <tr>
- <td align="right">[% 'Factor' | $T8 %]</td>
-[% IF !id || orphaned %]
- <td><input name="factor" value="[% HTML.escape(factor) %]"></td>
-[% ELSE %]
- <td><input type="hidden" name="factor" value="[% HTML.escape(factor) %]">
- [% HTML.escape(factor) %] [% ' (in use so no change allowed)' | $T8 %]</td>
-[% END %]
- </tr>
- </table>
- </p>
-
- <p>
- <input type="hidden" name="callback" value="[% HTML.escape(callback) %]">
-
- <input type="hidden" name="type" value="price_factor">
-
- <input type="hidden" name="id" value="[% HTML.escape(id) %]">
- <input type="submit" name="action" value="[% 'Save' | $T8 %]">
- [% IF id %][% IF orphaned %]<input type="submit" name="action" value="[% 'Delete' | $T8 %]">[% END %][% END %]
- </p>
- </form>
+++ /dev/null
-[%- USE T8 %][% USE L %][% USE LxERP %]
-[% USE HTML %]
-<h1>[% title %]</h1>
-
- [% IF MESSAGE %]<p>[% MESSAGE %]</p>[% END %]
-
-
- <p>
- <table width="100%" id="price_factor_list">
- <thead>
- <tr class="listheading">
- <th align="center"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
- <th width="80%">[% 'Description' | $T8 %]</th>
- <th width="20%">[% 'Factor' | $T8 %]</th>
- </tr>
- </thead>
-
- <tbody>
- [% FOREACH factor = PRICE_FACTORS %]
- <tr class="listrow[% loop.count % 2 %]" id="price_factor_id_[% factor.id %]">
- <td align="center" class="dragdrop"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></td>
- <td><a href="[% url_base %]&action=edit_price_factor&id=[% HTML.url(factor.id) %]">[% HTML.escape(factor.description) %]</a></td>
- <td>[% HTML.escape(factor.factor) %]</td>
- </tr>
- [% END %]
- </tbody>
- </table>
- </p>
-
- <hr height="3">
-
- <p>
- <a href="am.pl?action=add&type=price_factor&callback=[% HTML.url(callback) %]">[%- 'Add' | $T8 %]</a>
- </p>
-
- [% L.sortable_element('#price_factor_list tbody', url => 'controller.pl?action=PriceFactor/reorder', with => 'price_factor_id') %]
--- /dev/null
+[%- USE LxERP -%][%- USE L -%][%- USE HTML -%]
+[%- SET orphaned = SELF.object.orphaned %]
+<table>
+ <tr>
+ <th align="right">[% LxERP.t8("Description") %]</th>
+ <td>[% L.input_tag("object.description", LxERP.t8(SELF.object.description), "data-validate"="required", "data-title"=LxERP.t8("Description")) %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% LxERP.t8("Factor") %]</th>
+ <td>
+ [% IF orphaned %]
+ [% L.input_tag("object.factor_as_number", LxERP.t8(SELF.object.factor_as_number), "data-validate"="required", "data-title"=LxERP.t8("Factor")) %]
+ [% ELSE %]
+ [% HTML.escape(SELF.object.factor_as_number) %]
+ [% END %]
+ </td>
+ </tr>
+</table>
+
+[% UNLESS orphaned %]
+ <p>
+ [% LxERP.t8("Note: the object is already in use. Therefore some values cannot be changed.") %]
+ </p>
+[% END %]