Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ba0c9eb6

Von Werner Hahn vor mehr als 1 Jahr hinzugefügt

  • ID ba0c9eb643de69d6c2a9a0629c94db6270223a87
  • Vorgänger c7364fa8
  • Nachfolger 2fb77d82

DispositionsManager: Prototy mit Auftrag erstellen

Unterschiede anzeigen:

SL/Controller/DispositionsManager.pm
46 46
  $::request->{layout}->add_javascripts('kivi.DispositionsManager.js');
47 47
  my $basket = SL::DB::Manager::PurchaseBasket->get_all( query => [ cleared => 'F' ],  with_objects => [ 'parts', 'parts.makemodels' ]);
48 48
  $self->_setup_show_basket_action_bar;
49
  $self->render('dispositionsmanager/show_purchase_basket', PARTS => $basket );
49
  $self->render('dispositionsmanager/show_purchase_basket', PARTS => $basket, title => "Purchasebasket" );
50 50
}
51 51

  
52 52
sub action_transfer_to_purchase_order {
53 53
  my ( $self ) = @_;
54

  
54
  require SL::DB::Order;
55
  require SL::DB::OrderItem;
56
  require SL::DB::Part;
57
  require SL::DB::Vendor;
58
  my @error_report;
59

  
60
  my $v_id =  $::form->{vendor_id}->[0] ;
61
  my $vendor = SL::DB::Manager::Vendor->find_by(id => $v_id);
62
  die "Can't find vendor" unless $vendor;
63
  my $employee = SL::DB::Manager::Employee->current;
64
  die "Can't find employee" unless $employee;
65
  my $basket_items= SL::DB::Manager::PurchaseBasket->get_all( query => [ id => \@{ $::form->{id} } ] );
66

  
67
  my @items = map{
68
    my $part = SL::DB::Manager::Part->get_first( query => [ id => $_->parts_id,]);
69
    my $mm = SL::DB::Manager::MakeModel->get_first( query => [ make => $vendor->id, parts_id => $_->parts_id] );
70

  
71
    unless($part){
72
      push @error_report, t8('Part with id: #1 not found', $_->parts_id);
73
    }else{
74
      my $current_order_item = SL::DB::OrderItem->new(
75
        parts_id            => $_->parts_id,
76
        description         => $part->description,
77
        qty                 => $_->qty,
78
        sellprice           => $mm->lastcost,
79
        unit                => $part->unit,
80
        position            => $_->id,
81
        active_price_source => "makemodel/" . $mm->id,
82
      );
83
    }
84
  }@{$basket_items};
85

  
86
  my $order = SL::DB::Order->new(
87
    vendor_id               => $vendor->id,
88
    orderitems              => [ @items ],
89
    employee_id             => $employee->id,
90
    intnotes                => $vendor->notes,
91
    salesman_id             => $employee->id,
92
    payment_id              => $vendor->payment_id,
93
    taxzone_id              => $vendor->taxzone_id,
94
    currency_id             => $vendor->currency_id,
95
    transdate               => DateTime->today_local
96
  );
97

  
98
  $order->db->with_transaction( sub {
99
    $order->calculate_prices_and_taxes;
100
    $order->save;
101

  
102
    my $snumbers = "ordernumber_" . $order->ordnumber;
103
    SL::DB::History->new(
104
                      trans_id    => $order->id,
105
                      snumbers    => $snumbers,
106
                      employee_id => SL::DB::Manager::Employee->current->id,
107
                      addition    => 'SAVED',
108
                      what_done   => 'PurchaseBaket->Order',
109
                    )->save();
110
    foreach my $item(@{ $order->orderitems }){
111
      $item->parse_custom_variable_values->save;
112
      $item->{custom_variables} = \@{ $item->cvars_by_config };
113
      $item->save;
114
    }
115
    SL::DB::Manager::PurchaseBasket->delete_all( where => [ id => \@{ $::form->{id} }]);
116
  }) || die $order->db->error;
117
  $self->redirect_to(controller => "oe.pl", action => 'edit', type => 'purchase_order', vc => 'vendor', id => $order->id);
55 118

  
56 119
}
57 120

  
......
74 137
    $bar->add(
75 138
      action => [
76 139
        t8('Reload'),
77
        submit   => [ '#form', { action => "DispositionsManager/show_basket" } ],
140
        submit   => [ '#purchasebasket', { action => "DispositionsManager/show_basket" } ],
78 141
      ],
79 142
      action => [
80 143
        t8('Action'),
81
        submit   => [ '#form', { action => "DispositionsManager/transfer_to_purchase_order" } ],
144
        call   => [ 'kivi.DispositionsManager.create_order' ],
82 145
        tooltip  => t8('Create purchase order'),
83 146
      ],
84 147
    );
js/kivi.DispositionsManager.js
3 3
    $("table tr").each(function(index) {
4 4
      if ( index !== 0 ) {
5 5
        $row = $(this);
6
    //    alert( $row.find('#vendor_id').val() + '!=' + $('#cv_id').val());
7
        if( $row.find('#vendor_id').val() != $('#cv_id').val()) {
6
        //alert( $row.find("select[name='vendor_id[]']").val() + '!=' + $('#cv_id').val());
7
        if( $row.find("select[name='vendor_id[]']").val() != $('#cv_id').val()) {
8 8
          $row.remove();
9 9
        }
10 10
      }
11 11
    });
12 12
  }
13
  ns.create_order = function() {
14
    var data = $('#purchasebasket').serializeArray();
15
    data.push({ name: 'action', value: 'DispositionsManager/transfer_to_purchase_order' });
16

  
17
    $.post("controller.pl", data, kivi.eval_json_result);
18
  }
13 19
});
templates/webpages/dispositionsmanager/show_purchase_basket.html
2 2
[% USE Dumper %]
3 3
[%- INCLUDE 'common/flash.html' %]
4 4
<h1>[% title %]</h1>
5
<hr>
6 5
[% # Dumper.dump_html(PARTS) %]
7
<form id="form">
6
<form id="purchasebasket" style="margin:1em;">
8 7
[% P.customer_vendor.picker('vendor_id2', '', type='vendor', fat_set_item=1) %]<br>
9 8
<div>id  from change: <span id='change3'></span></div>
10 9
[% L.hidden_tag('cv_id', '') %]
11
  <table id="baskettable">
10
  <table id="baskettable" width="100%">
12 11
    <thead>
13 12
     <tr class="listheading">
14 13
       <th>[% L.checkbox_tag('check_all') %][% 'Purchasebasket' | $T8 %] </th>
......
28 27
        <td>[% L.checkbox_tag('id[]', checked = '1',  value=part.id) %]</td>
29 28
        <td>[% HTML.escape(part.parts.partnumber) %] </td>
30 29
        <td>[% HTML.escape(part.parts.description) %]</td>
31
        <td>[% part.parts.onhand_as_number %]        </td>
32
        <td>[% part.parts.rop_as_number %]           </td>
33
        <td>[% part.parts.min_order_qty %]           </td>
34
        <td>[% L.select_tag('vendor_id', part.parts.vendor_dropdown, value_key = 'value', title_key = 'title', default = part.parts.makemodels.item(0).make, size = select_size, style='width: 350px;' ) %]</td>
30
        <td class="numeric">[% part.parts.onhand_as_number %]        </td>
31
        <td class="numeric">[% part.parts.rop_as_number %]           </td>
32
        <td class="numeric">[% part.qty_as_number %] </td>
33
        <td>[% L.select_tag('vendor_id[]', part.parts.vendor_dropdown, value_key = 'value', title_key = 'title', default = part.parts.makemodels.item(0).make, size = select_size, style='width: 350px;' ) %]</td>
35 34
      </tr>
36 35
      [% END %]
37 36
    [% END %]
38 37
    </tbody>
39 38
  </table>
40 39
</form>
40
<hr>
41 41
<script type="text/javascript">
42 42
<!--
43 43

  

Auch abrufbar als: Unified diff