Skip to content

Commit

Permalink
POS: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerhahn authored and z4m1n0 committed Jan 4, 2025
1 parent 64a0ac1 commit 28999c3
Show file tree
Hide file tree
Showing 13 changed files with 1,725 additions and 19 deletions.
34 changes: 20 additions & 14 deletions SL/Controller/Order.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ sub action_update_item_input_row {
# add an item row for a new item entered in the input row
sub action_add_item {
my ($self) = @_;
my $template_name = $::form->{point_of_sale} ?
'pos/tabs/_row'
: 'order/tabs/_row';

delete $::form->{add_item}->{create_part_type};

Expand All @@ -1055,10 +1058,12 @@ sub action_add_item {
$self->get_item_cvpartnumber($item);

my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
my $row_as_html = $self->p->render('order/tabs/_row',
ITEM => $item,
ID => $item_id,
SELF => $self,

my $row_as_html = $self->p->render(
$template_name,
ITEM => $item,
ID => $item_id,
SELF => $self,
);

if ($::form->{insert_before_item_id}) {
Expand All @@ -1070,13 +1075,13 @@ sub action_add_item {
}

if ( $item->part->is_assortment ) {
$form_attr->{qty_as_number} = 1 unless $form_attr->{qty_as_number};
foreach my $assortment_item ( @{$item->part->assortment_items} ) {
my $attr = { parts_id => $assortment_item->parts_id,
qty => $assortment_item->qty * $::form->parse_amount(\%::myconfig, $form_attr->{qty_as_number}), # TODO $form_attr->{unit}
unit => $assortment_item->unit,
description => $assortment_item->part->description,
};
my $attr = {
parts_id => $assortment_item->parts_id,
qty => $assortment_item->qty * ($item->qty || 1), # TODO $item->unit
unit => $assortment_item->unit,
description => $assortment_item->part->description,
};
my $item = new_item($self->order, $attr);

# set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
Expand All @@ -1086,10 +1091,11 @@ sub action_add_item {
$self->recalc();
$self->get_item_cvpartnumber($item);
my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
my $row_as_html = $self->p->render('order/tabs/_row',
ITEM => $item,
ID => $item_id,
SELF => $self,
my $row_as_html = $self->p->render(
$template_name,
ITEM => $item,
ID => $item_id,
SELF => $self,
);
if ($::form->{insert_before_item_id}) {
$self->js
Expand Down
97 changes: 97 additions & 0 deletions SL/Controller/POS.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package SL::Controller::POS;

use strict;
use parent qw(SL::Controller::Base);

use SL::Controller::Order;

use SL::Model::Record;
use SL::DB::ValidityToken;
use SL::DB::Order::TypeData qw(:types);

use SL::Locale::String qw(t8);

use Rose::Object::MakeMethods::Generic
(
'scalar --get_set_init' => [ qw(
order_controller order
) ]
);

# add a new point of sales order
# it's a sales order with a diffrent form
sub action_add {
my ($self) = @_;
$::form->{type} = SALES_ORDER_TYPE();

$self->order(SL::Model::Record->update_after_new($self->order));

$self->order_controller->pre_render();
$self->pre_render();

if (!$::form->{form_validity_token}) {
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE())->token;
}

$self->render(
'pos/form',
title => t8('Point of Sales'),
%{$self->{template_args}}
);
}

sub action_edit_order_item_row_point_of_sales_dialog {
my ($self) = @_;

my $item;
my $temp_item_id = $::form->{item_id};
foreach my $idx (0 .. (scalar @{$::form->{orderitem_ids}} - 1)) {
if ($::form->{orderitem_ids}->[$idx] eq $temp_item_id) {
$item = $self->order->items->[$idx];
last;
}
}
die "cound not find item with item with id $temp_item_id" unless $item;

$self->render(
'pos/_edit_order_item_row_point_of_sales_dialog', { layout => 0 },
popup_dialog => 1,
popup_js_delete_row_function => "kivi.POS.delete_order_item_row_point_of_sales('$temp_item_id')",
popup_js_close_function => '$("#edit_order_item_row_point_of_sales_dialog").dialog("close")',
popup_js_assign_function => "kivi.POS.assign_edit_order_item_row_point_of_sales('$temp_item_id')",
ITEM => $item
);
}

#
# helpers
#

sub pre_render {
my ($self) = @_;

$::request->{layout}->use_javascript("${_}.js") for qw(
kivi.POS
);

# remove actionbar from order_controller
for my $bar ($::request->layout->get('actionbar')) {
$bar->actions([]);
}
}

sub order {
my $self = shift @_;
$self->order_controller->order(@_);
}

#
# intits
#

sub init_order_controller {
my ($self) = @_;
SL::Controller::Order->new();
}

1;
56 changes: 56 additions & 0 deletions css/design40/less/pos.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* ------------------------------------------------------------- */
/* POS (pos.less) */
/* ------------------------------------------------------------- */



// ------------------------------------------------------------
// General page layout
// ------------------------------------------------------------

.pos_wrapper{
border: solid blue;
position: relative;
height: 85vh;
}

// pos_content

.pos_content{
margin-right: 600px;
border: thin solid red;
}

// left_content

.left_input{
float:left;
padding-right: 3em;
}

// buttons

.buttons{
position: absolute;
right: 0px;
top: 0px;

width: 600px;
border: thin solid green;
}

.container_pos_left{
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 10px;
row-gap: 15px;
}

.pos_button{
height: 50px;
border: solid green !important;
text-align: center;
line-height: 50px;
padding: 0 !important;
display: inline-block;
}
1 change: 1 addition & 0 deletions css/design40/less/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
// -----------------------
@import 'requirement_spec.less'; //
@import 'specials.less';
@import 'pos.less';



Expand Down
8 changes: 4 additions & 4 deletions css/design40/manual/form-elements-special.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h2>ms2side (.ms2side / MultiSelect2Side)</h2>
<div class="ms2side__header">
Alle verfügbaren Elemente
</div>
<select title="Alle BenutzerInnen" name="group_usersms2side__sx" id="group_usersms2side__sx" size="undefined" multiple="multiple">
<select title="Alle BenutzerInnen" name="group_usersms2side__sx" id="group_clients" size="undefined" multiple="multiple">
<option value="2">Element 2</option>
<option value="1">Element 1</option>
</select>
Expand Down Expand Up @@ -201,10 +201,10 @@ <h4> Benutzerdefinierte Variablen </h4>

<div class="wrapper">
<div class="filter_toggle" style="display: block;">
<a href="#" onclick="javascript:$('.filter_toggle').toggle()" class="button toggle off neutral">Filter zeigen</a>
<a href="#" onclick="javascript:$('.filter-toggle-panel').toggle()" class="button toggle off neutral">Filter zeigen</a>
</div>
<div class="filter_toggle" style="display: none;">
<a href="#" onclick="javascript:$('.filter_toggle').toggle()" class="button toggle on neutral with-panel">Filter verbergen</a>
<a href="#" onclick="javascript:$('.filter-toggle-panel').toggle()" class="button toggle on neutral with-panel">Filter verbergen</a>
<!-- PENDENT: Panel einbauen -->
<div class="filter-toggle-panel">
<table id="filter_table" class="tbl-horizontal">
Expand Down Expand Up @@ -403,4 +403,4 @@ <h3 class="caption">Hat Regeltypen</h3>

</form>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion css/design40/style.css

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions js/kivi.POS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace('kivi.POS', function(ns) {
ns.delete_order_item_row_point_of_sales = function(item_id) {
var row = $('#item_' + item_id).parents("tbody").first();
$(row).remove();

$('#edit_order_item_row_point_of_sales_dialog').dialog('close');
kivi.Order.renumber_positions();
kivi.Order.recalc_amounts_and_taxes();
};


ns.edit_order_item_row_point_of_sales = function(item_id) {

var data = $('#order_form').serializeArray();
data.push({ name: 'item_id', value: item_id });

kivi.popup_dialog({
url: 'controller.pl?action=POS/edit_order_item_row_point_of_sales_dialog',
data: data,
id: 'edit_order_item_row_point_of_sales_dialog',
load: function() {kivi.reinit_widgets(); kivi.Order.init_row_handlers() },
dialog: {
title: kivi.t8('Edit row'),
width: 800,
height: 650
}
});
};

ns.assign_edit_order_item_row_point_of_sales = function(item_id) {
var row = $('#item_' + item_id).parents("tbody").first();

var discount = $('#item_discount_as_percent').val();
$(row).find('[name="discount_as_percent"]').html(discount);
$(row).find('[name="order.orderitems[].discount_as_percent"]').val(discount);

// TODO
// var salesman_id = 0;
// $(row).find('[name="order.orderitems[].salesman_id"]');


$('#edit_order_item_row_point_of_sales_dialog').dialog('close');
kivi.Order.recalc_amounts_and_taxes();
}

});
Loading

0 comments on commit 28999c3

Please sign in to comment.