Revision c307d4a1
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
22 | 22 |
use SL::DB::Part; |
23 | 23 |
use SL::DB::PartsGroup; |
24 | 24 |
use SL::DB::PriceRuleItem; |
25 |
use SL::DB::PurchaseBasketItem; |
|
25 | 26 |
use SL::DB::Shop; |
26 | 27 |
use SL::Helper::Flash; |
27 | 28 |
use SL::Helper::PrintOptions; |
... | ... | |
261 | 262 |
$self->render_form; |
262 | 263 |
} |
263 | 264 |
|
265 |
sub action_add_to_basket { |
|
266 |
my ( $self ) = @_; |
|
267 |
|
|
268 |
if ( !$self->_is_in_purchase_basket && scalar @{$self->part->makemodels}) { |
|
269 |
|
|
270 |
my $part = $self->part; |
|
271 |
|
|
272 |
my $needed_qty = $part->order_qty < ($part->rop - $part->onhandqty) ? |
|
273 |
$part->rop - $part->onhandqty |
|
274 |
: $part->order_qty; |
|
275 |
|
|
276 |
my $basket_part = SL::DB::PurchaseBasketItem->new( |
|
277 |
part_id => $part->id, |
|
278 |
qty => $needed_qty, |
|
279 |
orderer => SL::DB::Manager::Employee->current, |
|
280 |
)->save; |
|
281 |
|
|
282 |
$self->js->flash('info', t8('Part added to purchasebasket'))->render; |
|
283 |
} else { |
|
284 |
$self->js->flash('error', t8('Part already in purchasebasket or has no vendor'))->render; |
|
285 |
} |
|
286 |
return 1; |
|
287 |
} |
|
288 |
|
|
264 | 289 |
sub render_form { |
265 | 290 |
my ($self, %params) = @_; |
266 | 291 |
|
... | ... | |
1664 | 1689 |
return \@item_objects; |
1665 | 1690 |
} |
1666 | 1691 |
|
1692 |
sub _is_in_purchase_basket { |
|
1693 |
my ( $self ) = @_; |
|
1694 |
|
|
1695 |
return SL::DB::Manager::PurchaseBasketItem->get_all_count( query => [ part_id => $self->part->id ] ); |
|
1696 |
} |
|
1697 |
|
|
1698 |
sub _is_ordered { |
|
1699 |
my ( $self ) = @_; |
|
1700 |
|
|
1701 |
return $self->part->get_ordered_qty( $self->part->id ); |
|
1702 |
} |
|
1703 |
|
|
1667 | 1704 |
sub _setup_form_action_bar { |
1668 | 1705 |
my ($self) = @_; |
1669 | 1706 |
|
... | ... | |
1736 | 1773 |
: undef, |
1737 | 1774 |
], |
1738 | 1775 |
|
1776 |
action => [ |
|
1777 |
t8('Add to basket'), |
|
1778 |
call => [ 'kivi.Part.add_to_basket' ], |
|
1779 |
disabled => !$self->part->id ? t8('This object has not been saved yet.') |
|
1780 |
: $self->_is_in_purchase_basket ? t8('Part already in purchasebasket') |
|
1781 |
: $self->_is_ordered ? t8('Part already ordered') |
|
1782 |
: !scalar @{$self->part->makemodels} ? t8('No vendors to add to purchasebasket') |
|
1783 |
: undef, |
|
1784 |
], |
|
1785 |
|
|
1739 | 1786 |
'separator', |
1740 | 1787 |
|
1741 | 1788 |
action => [ |
js/kivi.Part.js | ||
---|---|---|
835 | 835 |
ns.reinit_widgets(); |
836 | 836 |
}; |
837 | 837 |
|
838 |
ns.add_to_basket = function() { |
|
839 |
var data = $('#ic').serializeArray(); |
|
840 |
data.push({ name: 'action', value: 'Part/add_to_basket' }); |
|
841 |
|
|
842 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
843 |
}; |
|
844 |
|
|
838 | 845 |
$(function(){ |
839 | 846 |
$('#ic').on('focusout', '.reformat_number', function(event) { |
840 | 847 |
ns.reformat_number(event); |
Auch abrufbar als: Unified diff
Part: Direkt aus der Artikelmaske zum Einkaufkorb hinzufügen