->render($self);
}
-sub action_add_item_row {
+sub action_add_item {
my ($self) = @_;
- my $random_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
- my $row_as_html = $self->p->render('order/tabs/_row', ITEM => {id => $random_id});
+ my $form_attr = $::form->{add_item};
+ my $item = SL::DB::OrderItem->new;
+ $item->assign_attributes(%$form_attr);
+
+ my $part = SL::DB::Part->new(id => $form_attr->{parts_id})->load;
+ my $cv_class = "SL::DB::" . ucfirst($self->cv);
+ my $cv_discount = $::form->{$self->cv . '_id'}? $cv_class->new(id => $::form->{$self->cv . '_id'})->load->discount :0.0;
+
+ my %new_attr;
+ $new_attr{id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+ $new_attr{part} = $part;
+ $new_attr{qty} = 1.0 if ! $item->{qty};
+ $new_attr{unit} = $part->unit;
+ $new_attr{sellprice} = $part->sellprice if ! $item->{sellprice};
+ $new_attr{discount} = $cv_discount if ! $item->{discount};
+ $item->assign_attributes(%new_attr);
+
+ # add_items seems to fail if no items had been added before
+ if ($self->order->items) {
+ $self->order->add_items($item);
+ } else {
+ $self->order->items([$item]);
+ }
+
+ $self->_setup();
+
+ my $row_as_html = $self->p->render('order/tabs/_row', ITEM => $item);
$self->js
->append('#row_table_id tbody', $row_as_html)
->focus('#row_table_id tr:last [id$="parts_id_name"]')
->off('[id^="order_orderitems"][id$="parts_id"]', 'change', 'set_item_values')
->on('[id^="order_orderitems"][id$="parts_id"]', 'change', 'set_item_values')
+ ->html('#netamount_id', $::form->format_amount(\%::myconfig, $self->order->netamount, -2))
+ ->html('#amount_id', $::form->format_amount(\%::myconfig, $self->order->amount, -2))
+ ->remove('.tax_row')
+ ->insertBefore($self->build_tax_rows, '#amount_row_id')
->render($self);
}
</tr>
</table>
+ <div>
+ <table id="input_row_table_id">
+ <thead>
+ <tr class="listheading">
+ <th class="listheading" nowrap >[%- 'Part' | $T8 %] </th>
+ <th class="listheading" nowrap width="5" >[%- 'Qty' | $T8 %] </th>
+ <th class="listheading" nowrap width="15">[%- 'Price' | $T8 %] </th>
+ <th class="listheading" nowrap width="5" >[%- 'Discount' | $T8 %] </th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr valign="top" class="listrow">
+ <td>[% L.part_picker('add_item.parts_id', '', style='width: 300px') %]</td>
+ <td>[% L.input_tag('add_item.qty_as_number', '', size = 5, style='text-align:right') %]</td>
+ <td>[% L.input_tag('add_item.sellprice_as_number', '', size = 10, style='text-align:right') %]</td>
+ <td>[% L.input_tag('add_item.discount_as_percent', '', size = 5, style='text-align:right') %]</td>
+ <td>[% L.button_tag('add_item()', LxERP.t8('Add part')) %]</td>
+ </tr>
+ </tbody>
+ </table>
+
+ </div>
+
<table width="100%">
<tr>
<td>
[%- FOREACH item = SELF.order.items_sorted %]
[%- PROCESS order/tabs/_row.html ITEM=item %]
[%- END %]
- [%- IF !SELF.order.items.size %]
- [%- PROCESS order/tabs/_row.html ITEM='' %]
- [%- END %]
</tbody>
</table>
<tr>
</tr>
- <tr>
- <td>[%- L.button_tag('add_order_item_row()', LxERP.t8("Add Row")) -%]</td>
- </tr>
-
<tr>
<td align="right">
<table>
}, kivi.eval_json_result);
}
-function add_order_item_row() {
- $.post("controller.pl", { 'action': 'Order/add_item_row',
- 'type' : function(){ return $('#type').val() }
- }, kivi.eval_json_result);
+function add_item() {
+ var data = $('#order_form').serialize();
+ data += '&action=Order/add_item';
+ data += '&type=' + $('#type').val();
+
+ $.post("controller.pl", data, kivi.eval_json_result);
}
function delete_order_item_row(clicked) {