Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ff10db79

Von Sven Schöling vor etwa 3 Jahren hinzugefügt

  • ID ff10db7973d975c7a7c6569b9e44ebf2d492ef02
  • Vorgänger 5eeb1d33
  • Nachfolger 3bf42ce3

DeliveryOrder: besseres update nach stock dialog

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
55 55

  
56 56
# safety
57 57
__PACKAGE__->run_before('check_auth',
58
                        except => [ qw(pack_stock_information) ]);
58
                        except => [ qw(update_stock_information) ]);
59 59

  
60 60
__PACKAGE__->run_before('get_unalterable_data',
61 61
                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction
......
920 920
  );
921 921
}
922 922

  
923
# we're using the old YAML based stock packing, but don't want to do this in
924
# the frontend so we're doing a tiny roundtrip to the backend, back the info in
925
# perl, serve it back to the frontend and store it in the DOM there
926
sub action_pack_stock_information {
923
sub action_update_stock_information {
927 924
  my ($self) = @_;
928 925

  
929 926
  my $stock_info = $::form->{stock_info};
927
  my $unit = $::form->{unit};
930 928
  my $yaml = SL::YAML::Dump($stock_info);
929
  my $stock_qty = $self->calculate_stock_in_out_from_stock_info($unit, $stock_info);
931 930

  
932
  $self->render(\$yaml, { layout => 0, process => 0 });
931
  my $response = {
932
    stock_info => $yaml,
933
    stock_qty => $stock_qty,
934
  };
935

  
936
  $self->render(\ SL::JSON::to_json($response), { layout => 0, type => 'json', process => 0 });
933 937
}
934 938

  
935 939
sub merge_stock_data {
......
2119 2123
  return @errors;
2120 2124
}
2121 2125

  
2126
sub calculate_stock_in_out_from_stock_info {
2127
  my ($self, $unit, $stock_info) = @_;
2128

  
2129
  return "" if !$unit;
2130

  
2131
  my %units_by_name = map { $_->name => $_ } @{ SL::DB::Manager::Unit->get_all };
2132

  
2133
  my $sum      = sum0 map {
2134
    $units_by_name{$_->{unit}}->convert_to($_->{qty}, $units_by_name{$unit})
2135
  } @$stock_info;
2136

  
2137
  my $content  = _format_number_units($sum, 2, $units_by_name{$unit}, $units_by_name{$unit});
2138

  
2139
  return $content;
2140
}
2141

  
2122 2142
sub calculate_stock_in_out {
2123
  my ($self, $item) = @_;
2143
  my ($self, $item, $stock_info) = @_;
2124 2144

  
2125 2145
  return "" if !$item->part || !$item->part->unit || !$item->unit;
2126 2146

  
2127
  my $in_out   = $self->type_data->transfer;
2128

  
2129
  my $do_qty   = $item->qty;
2130 2147
  my $sum      = sum0 map {
2131 2148
    $_->unit_obj->convert_to($_->qty, $item->unit_obj)
2132 2149
  } $item->delivery_order_stock_entries;
js/kivi.DeliveryOrder.js
121 121

  
122 122
    $.post("controller.pl",
123 123
      kivi.serialize({
124
        action:     "DeliveryOrder/pack_stock_information",
124
        action:     "DeliveryOrder/update_stock_information",
125
        unit:       $("#" + row).find("[name$=unit]").val(),
125 126
        stock_info: data,
126 127
        row:        row
127 128
      }),
128 129
      (data) => {
129
        $("#" + row + " .data-stock-info").val(data);
130
        $("#" + row + " .data-stock-info").val(data.stock_info);
131
        $("#" + row + " .data-stock-qty").text(data.stock_qty)
130 132
        $("#stock_in_out_dialog").dialog("close");
131 133
      }
132 134
    );
templates/webpages/delivery_order/tabs/_row.html
88 88
    </td>
89 89

  
90 90
    <td>
91
      <span id="stock_[% ID %]">[% SELF.calculate_stock_in_out(ITEM) %]</span>
91
      <span id="stock_[% ID %]" class="data-stock-qty">[% SELF.calculate_stock_in_out(ITEM) %]</span>
92 92
      [% P.button_tag("kivi.DeliveryOrder.open_stock_in_out_dialog(this, '" _ in_out _"')", "?") %]
93 93
    </td>
94 94
  </tr>

Auch abrufbar als: Unified diff