X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/d735aab3fc2987d555c63ce0dc8e24626ca30654..refs/heads/order_controller:/SL/Form.pm diff --git a/SL/Form.pm b/SL/Form.pm index 81b5370b7..eee73db63 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -66,6 +66,7 @@ use SL::IC; use SL::IS; use SL::Layout::Dispatcher; use SL::Locale; +use SL::Locale::String; use SL::Mailer; use SL::Menu; use SL::MoreCommon qw(uri_encode uri_decode); @@ -468,7 +469,7 @@ sub header { # standard css for all # this should gradually move to the layouts that need it $layout->use_stylesheet("$_.css") for qw( - main menu common list_accounts jquery.autocomplete + common main menu list_accounts jquery.autocomplete jquery.multiselect2side ui-lightness/jquery-ui jquery-ui.custom @@ -821,6 +822,7 @@ sub format_amount { my $force_places = defined $places && $places >= 0; $amount = $self->round_amount($amount, abs $places) if $force_places; + $neg = 0 if $amount == 0; # don't show negative zero $amount = sprintf "%.*f", ($force_places ? $places : 10), abs $amount; # 6 is default for %fa # before the sprintf amount was a number, afterwards it's a string. because of the dynamic nature of perl @@ -837,7 +839,7 @@ sub format_amount { if ($places || $p[1]) { $amount .= $d[0] . ( $p[1] || '' ) - . (0 x (abs($places || 0) - length ($p[1]||''))); # pad the fraction + . (0 x max(abs($places || 0) - length ($p[1]||''), 0)); # pad the fraction } $amount = do { @@ -980,7 +982,9 @@ sub round_amount { # part. If an overflow occurs then apply that overflow to the part # before the decimal sign as well using integer arithmetic again. - my $amount_str = sprintf '%.*f', $places + 10, abs($amount); + my $int_amount = int(abs $amount); + my $str_places = max(min(10, 16 - length("$int_amount") - $places), $places); + my $amount_str = sprintf '%.*f', $places + $str_places, abs($amount); return $amount unless $amount_str =~ m{^(\d+)\.(\d+)$}; @@ -2604,19 +2608,20 @@ sub all_vc { } sub mtime_ischanged { - my ($self, $relation,$option) = @_; - #$main::lxdebug->message(LXDebug->DEBUG2(),"mtime_ischanged from rel=".$relation." id=".$id); - if ( ! $self->{id} ) { return ; } - - my $query = "SELECT mtime, itime FROM ".$relation." WHERE id = ?"; - my $ref = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id}); - $ref->{mtime} = $ref->{itime} if !$ref->{mtime}; - #$main::lxdebug->message(LXDebug->DEBUG2(),"my mtime=".$self->{lastmtime}." new mtime=".$ref->{mtime}); + my ($self, $table, $option) = @_; + + return unless $self->{id}; + croak ("wrong call, no valid table defined") unless $table =~ /^(oe|ar|ap|delivery_orders|parts)$/; + + my $query = "SELECT mtime, itime FROM " . $table . " WHERE id = ?"; + my $ref = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id}); + $ref->{mtime} ||= $ref->{itime}; + if ($self->{lastmtime} && $self->{lastmtime} ne $ref->{mtime} ) { - my $etxt = $main::locale->text("The document has been changed from other user. Please reopen it in another window and copy the changes to the new window"); - $etxt = $main::locale->text("The document has been changed from other user. No mail was sent. Please reopen it in another window and copy the changes to the new window") - if defined $option && $option eq 'mail'; - $self->error($main::locale->text($etxt)); + $self->error(($option eq 'mail') ? + t8("The document has been changed by another user. No mail was sent. Please reopen it in another window and copy the changes to the new window") : + t8("The document has been changed by another user. Please reopen it in another window and copy the changes to the new window") + ); ::end_of_request(); } } @@ -2772,7 +2777,7 @@ sub create_links { qq|SELECT a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid, a.duedate, a.ordnumber, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.notes, - a.mtime,a.itime, + a.mtime, a.itime, a.intnotes, a.department_id, a.amount AS oldinvtotal, a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type, a.globalproject_id, ${extra_columns} @@ -2789,7 +2794,7 @@ sub create_links { foreach my $key (keys %$ref) { $self->{$key} = $ref->{$key}; } - $self->{mtime} = $self->{itime} if ! $self->{mtime}; + $self->{mtime} ||= $self->{itime}; $self->{lastmtime} = $self->{mtime}; my $transdate = "current_date"; if ($self->{transdate}) { @@ -3756,6 +3761,17 @@ Used to override the default favicon. A html page title will be generated from this +=item mtime_ischanged + +Tries to avoid concurrent write operations to records by checking the database mtime with a fetched one. + +Can be used / called with any table, that has itime and mtime attributes. +Valid C names are: oe, ar, ap, delivery_orders, parts. +Can be called wit C