kivitendo Code angepasst.
}
if ($form->{no_assemblies}) {
- $filter .= qq| AND (NOT COALESCE(assembly, FALSE))|;
+ $filter .= qq| AND (NOT part_type = 'assembly')|;
}
if ($form->{assemblies}) {
- $filter .= qq| AND assembly=TRUE|;
+ $filter .= qq| AND part_type = 'assembly'|;
}
if ($form->{no_services}) {
- $filter .= qq| AND (inventory_accno_id is not NULL or assembly=TRUE)|;
+ $filter .= qq| AND NOT (part_type = 'service' OR part_type = 'assembly')|;
}
substr($filter, 1, 3) = "WHERE" if ($filter);
sub init_parts_by {
my ($self) = @_;
-# my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } },
+# my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->part_type = 'assembly' } @{ $self->existing_objects } },
# partnumber => { part => { },
# service => { } } };
#
# foreach my $part (@{ $self->existing_objects }) {
-# next if $part->assembly;
+# next if $part->part_type eq 'assembly';
# $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part;
# }
my ($self) = @_;
my $profile = $self->SUPER::init_profile;
- delete @{$profile}{qw(alternate assembly bom expense_accno_id income_accno_id inventory_accno_id makemodel priceupdate stockable type)};
+ delete @{$profile}{qw(bom expense_accno_id income_accno_id inventory_accno_id makemodel priceupdate stockable type)};
$profile->{"pricegroup_$_"} = '' for 1 .. scalar @{ $_[0]->all_pricegroups };
$form->{"partsgroup_${idx}"} = $item->part->partsgroup->partsgroup if _has($item->part, 'partsgroup_id');
_copy($item, $form, "${items_name}_", "_${idx}", 0, qw(id)) if $items_name;
- _copy($item->part, $form, '', "_${idx}", 0, qw(id partnumber weight assembly));
+ # TODO: is part_type correct here? Do we need to set part_type as default?
+ _copy($item->part, $form, '', "_${idx}", 0, qw(id partnumber weight part_type));
_copy($item->part, $form, '', "_${idx}", 0, qw(listprice));
_copy($item, $form, '', "_${idx}", 0, qw(description project_id ship serialnumber pricegroup_id ordnumber donumber cusordnumber unit
subtotal longdescription price_factor_id marge_price_factor approved_sellprice reqdate transdate
$prefix //= '';
- # this is to make selection like type => { part => 1, service => 1 } work
+ # this is to make selections like part_type => { part => 1, service => 1 } work
if ('HASH' eq ref $type) {
$type = [ grep { $type->{$_} } keys %$type ];
}
for my $type (@types) {
if ($type =~ m/^part/) {
- push @filter, (and => [ or => [ $prefix . assembly => 0, $prefix . assembly => undef ],
- "!${prefix}inventory_accno_id" => 0,
- "!${prefix}inventory_accno_id" => undef,
- ]);
+ push @filter, ($prefix . part_type => 'part');
} elsif ($type =~ m/^service/) {
- push @filter, (and => [ or => [ $prefix . assembly => 0, $prefix . assembly => undef ],
- or => [ $prefix . inventory_accno_id => 0, $prefix . inventory_accno_id => undef ],
- ]);
- } elsif ($type =~ m/^assembl/) {
- push @filter, ($prefix . assembly => 1);
+ push @filter, ($prefix . part_type => 'service');
+ } elsif ($type =~ m/^assembly/) {
+ push @filter, ($prefix . part_type => 'assembly');
}
}
return $self->type eq $type ? 1 : 0;
}
-sub is_part { $_[0]->is_type('part') }
-sub is_assembly { $_[0]->is_type('assembly') }
-sub is_service { $_[0]->is_type('service') }
+sub is_part { $_[0]->part_type eq 'part' }
+sub is_assembly { $_[0]->part_type eq 'assembly' }
+sub is_service { $_[0]->part_type eq 'service' }
sub type {
- my ($self, $type) = @_;
- if (@_ > 1) {
- die 'invalid type' unless $type =~ /^(?:part|service|assembly)$/;
- $self->assembly( $type eq 'assembly' ? 1 : 0);
- $self->inventory_accno_id($type eq 'part' ? 1 : undef);
- }
-
- return 'assembly' if $self->assembly;
- return 'part' if $self->inventory_accno_id;
- return 'service';
+ return $_[0]->part_type;
+ # my ($self, $type) = @_;
+ # if (@_ > 1) {
+ # die 'invalid type' unless $type =~ /^(?:part|service|assembly)$/;
+ # $self->assembly( $type eq 'assembly' ? 1 : 0);
+ # $self->inventory_accno_id($type ne 'service' ? 1 : undef);
+ # }
+
+ # return 'assembly' if $self->assembly;
+ # return 'part' if $self->inventory_accno_id;
+ # return 'service';
}
sub new_part {
my ($class, %params) = @_;
- $class->new(%params, type => 'part');
+ $class->new(%params, part_type => 'part');
}
sub new_assembly {
my ($class, %params) = @_;
- $class->new(%params, type => 'assembly');
+ $class->new(%params, part_type => 'assembly');
}
sub new_service {
my ($class, %params) = @_;
- $class->new(%params, type => 'service');
+ $class->new(%params, part_type => 'service');
}
sub orphaned {
# stuff different from the whole will not be overwritten, but saved with a suffix.
$query =
qq|SELECT doi.id AS delivery_order_items_id,
- p.partnumber, p.assembly, p.listprice, doi.description, doi.qty,
+ p.partnumber, p.part_type, p.listprice, doi.description, doi.qty,
doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.notes AS partnotes,
doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost,
doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription,
my @values;
if ($p->{searchitems} eq 'part') {
- $query .= qq|WHERE p.inventory_accno_id > 0|;
+ $query .= qq|WHERE p.part_type = 'part'|;
}
if ($p->{searchitems} eq 'service') {
- $query .= qq|WHERE p.inventory_accno_id IS NULL|;
+ $query .= qq|WHERE p.part_type = 'service'|;
}
if ($p->{searchitems} eq 'assembly') {
- $query .= qq|WHERE p.assembly = '1'|;
- }
- if ($p->{searchitems} eq 'labor') {
- $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
+ $query .= qq|WHERE p.part_type = 'assembly'|;
}
$query .= qq|ORDER BY partsgroup|;
$form->{lastmtime} = $form->{mtime};
$form->{onhand} *= 1;
+ die "part needs a part_type" unless $form->{part_type}; # TODO from part_type enum conversion
# part or service item
- $form->{item} = ($form->{inventory_accno}) ? 'part' : 'service';
- if ($form->{assembly}) {
- $form->{item} = 'assembly';
+ $form->{item} = $form->{part_type};
+ if ($form->{item} eq 'assembly') {
# retrieve assembly items
$query =
my $makemodel = ($form->{make_1} || $form->{model_1} || ($form->{makemodel_rows} > 1)) ? 1 : 0;
- $form->{assembly} = ($form->{item} eq 'assembly') ? 1 : 0;
my ($query, $sth);
$form->{partnumber} ||= $trans_number->create_unique;
($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|);
- do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber, unit) VALUES (?, ?, ?)|, $form->{id}, $form->{partnumber}, $form->{unit});
+ do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber, unit, part_type) VALUES (?, ?, ?, ?)|, $form->{id}, $form->{partnumber}, $form->{unit}, $form->{item});
$form->{orphaned} = 1;
}
partnumber = ?,
description = ?,
makemodel = ?,
- assembly = ?,
listprice = ?,
sellprice = ?,
lastcost = ?,
has_sernumber = ?,
not_discountable = ?,
microfiche = ?,
+ part_type = ?,
partsgroup_id = ?,
price_factor_id = ?
$priceupdate
@values = ($form->{partnumber},
$form->{description},
$makemodel ? 't' : 'f',
- $form->{assembly} ? 't' : 'f',
$form->{listprice},
$form->{sellprice},
$form->{lastcost},
$form->{has_sernumber} ? 't' : 'f',
$form->{not_discountable} ? 't' : 'f',
$form->{microfiche},
+ $form->{item},
conv_i($partsgroup_id),
conv_i($form->{price_factor_id}),
conv_i($form->{id})
FROM parts p2, assembly a
WHERE (p2.id = a.parts_id) AND (a.id = p.id)) AS inventory
FROM parts p
- WHERE NOT p.obsolete AND p.assembly $where|;
+ WHERE NOT p.obsolete AND p.part_type = 'assembly' $where|;
$form->{assembly_items} = selectall_hashref_query($form, $dbh, $query, @values);
}
for ($form->{searchitems}) {
- push @where_tokens, 'p.inventory_accno_id > 0' if /part/;
- push @where_tokens, 'p.inventory_accno_id IS NULL' if /service/;
- push @where_tokens, 'NOT p.assembly' if /service/;
- push @where_tokens, ' p.assembly' if /assembly/;
+ push @where_tokens, "p.part_type = 'part'" if /part/;
+ push @where_tokens, "p.part_type = 'service'" if /service/;
+ push @where_tokens, "p.part_type = 'assembly'" if /assembly/;
}
for ($form->{itemstatus}) {
my $i = $form->{rowcount};
# don't include assemblies or obsolete parts
- my $where = "NOT p.assembly = '1' AND NOT p.obsolete = '1'";
+ my $where = "NOT p.part_type = 'assembly' AND NOT p.obsolete = '1'";
my @values;
foreach my $table_column (qw(p.partnumber p.description pg.partsgroup)) {
my $query =
qq|SELECT
p.id, p.partnumber, p.description, p.lastcost AS sellprice, p.listprice,
- p.unit, p.assembly, p.onhand, p.formel,
+ p.unit, p.part_type, p.onhand, p.formel,
p.notes AS partnotes, p.notes AS longdescription, p.not_discountable,
p.inventory_accno_id, p.price_factor_id,
p.ean,
my ($dbh, $myconfig, $form, $position, $id, $totalqty) = @_;
my $query =
- qq|SELECT a.parts_id, a.qty, p.assembly, p.partnumber, p.description, p.unit,
+ qq|SELECT a.parts_id, a.qty, p.part_type, p.partnumber, p.description, p.unit,
p.inventory_accno_id, p.income_accno_id, p.expense_accno_id
FROM assembly a
JOIN parts p ON (a.parts_id = p.id)
# reverse inventory items
my $query =
- qq|SELECT i.id, i.parts_id, i.qty, i.assemblyitem, p.assembly, p.inventory_accno_id
+ qq|SELECT i.id, i.parts_id, i.qty, i.assemblyitem, p.part_type, p.inventory_accno_id
FROM invoice i
JOIN parts p ON (i.parts_id = p.id)
WHERE i.trans_id = ?|;
i.description, i.longdescription, i.qty, i.fxsellprice AS sellprice, i.discount, i.parts_id AS id, i.unit, i.deliverydate AS reqdate,
i.project_id, i.serialnumber, i.pricegroup_id, i.ordnumber, i.donumber, i.transdate, i.cusordnumber, i.subtotal, i.lastcost,
i.price_factor_id, i.price_factor, i.marge_price_factor, i.active_price_source, i.active_discount_source,
- p.partnumber, p.assembly, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, p.formel, p.listprice,
+ p.partnumber, p.part_type, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, p.formel, p.listprice,
pr.projectnumber, pg.partsgroup, prg.pricegroup
FROM invoice i
c3.new_chart_id AS expense_new_chart,
date($transdate) - c3.valid_from AS expense_valid,
- p.unit, p.assembly, p.onhand,
+ p.unit, p.part_type, p.onhand,
p.notes AS partnotes, p.notes AS longdescription,
p.not_discountable, p.formel, p.payment_id AS part_payment_id,
p.price_factor_id, p.weight,
c2.accno AS income_accno, c2.new_chart_id AS income_new_chart, date($transdate) - c2.valid_from as income_valid,
c3.accno AS expense_accno, c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from as expense_valid,
oe.ordnumber AS ordnumber_oe, oe.transdate AS transdate_oe, oe.cusordnumber AS cusordnumber_oe,
- p.partnumber, p.assembly, p.listprice, o.description, o.qty,
+ p.partnumber, p.part_type, p.listprice, o.description, o.qty,
o.sellprice, o.parts_id AS id, o.unit, o.discount, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id,
o.reqdate, o.project_id, o.serialnumber, o.ship, o.lastcost,
o.ordnumber, o.transdate, o.cusordnumber, o.subtotal, o.longdescription,
my $query = qq|SELECT assembly.parts_id, assembly.qty, parts.warehouse_id
FROM assembly INNER JOIN parts ON assembly.parts_id = parts.id
- WHERE assembly.id = ? AND (inventory_accno_id IS NOT NULL OR parts.assembly = TRUE)|;
+ WHERE assembly.id = ? AND parts.part_type != 'service'|;
my $sth_part_qty_assembly = prepare_execute_query($form, $dbh, $query, $params{assembly_id});
my @new_fields =
qw(id partnumber description sellprice listprice inventory_accno
- income_accno expense_accno bin unit weight assembly taxaccounts
+ income_accno expense_accno bin unit weight part_type taxaccounts
partsgroup formel longdescription not_discountable partnotes lastcost
price_factor_id price_factor);
}
if ($::form->{filter_type} eq 'assembly') {
- $where .= ' AND assembly';
+ $where .= " AND part_type = 'assembly'";
}
if ($::form->{filter_type} eq 'service') {
- $where .= ' AND inventory_accno_id IS NULL AND NOT assembly';
+ $where .= " AND part_type = 'service'";
}
if ($::form->{filter_type} eq 'part') {
- $where .= ' AND inventory_accno_id IS NOT NULL';
- $where .= ' AND NOT assembly';
+ $where .= " AND part_type = 'part'";
}
if ($::form->{filter_obsolete} eq 'obsolete') {
description => 'Fourty-two fifty-four',
lastcost => 222.22,
sellprice => 333.33,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part} }
description => 'Fourty-two fifty-four',
lastcost => 222.22,
sellprice => 333.33,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part} }
description => 'Fourty-two fifty-four',
lastcost => 222.22,
sellprice => 333.33,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part} }
}, 'object test simple', class => 'SL::DB::Manager::Part';
test {
- 'type' => 'assembly',
+ 'part_type' => 'assembly',
}, {
query => [
- 'assembly' => 1
- ],
+ 'part_type',
+ 'assembly'
+ ] ,
}, 'object test without prefix', class => 'SL::DB::Manager::Part';
test {
- 'part.type' => 'assembly',
+ 'part.part_type' => 'assembly',
}, {
query => [
- 'part.assembly' => 1
- ],
+ 'part.part_type',
+ 'assembly'
+ ]
}, 'object test with prefix', class => 'SL::DB::Manager::OrderItem';
test {
- 'type' => [ 'part', 'assembly' ],
+ 'part_type' => [ 'part', 'assembly' ],
}, {
query => [
- or => [
- and => [ or => [ assembly => 0, assembly => undef ],
- "!inventory_accno_id" => 0,
- "!inventory_accno_id" => undef,
- ],
- assembly => 1,
- ]
- ],
+ 'or',
+ [
+ 'part_type',
+ 'part',
+ 'part_type',
+ 'assembly'
+ ]
+ ]
}, 'object test without prefix but complex value', class => 'SL::DB::Manager::Part';
-
test {
- 'part.type' => [ 'part', 'assembly' ],
+ 'part.part_type' => [ 'part', 'assembly' ],
}, {
query => [
- or => [
- and => [ or => [ 'part.assembly' => 0, 'part.assembly' => undef ],
- "!part.inventory_accno_id" => 0,
- "!part.inventory_accno_id" => undef,
- ],
- 'part.assembly' => 1,
- ]
- ],
+ 'or',
+ [
+ 'part.part_type',
+ 'part',
+ 'part.part_type',
+ 'assembly'
+ ]
+ ]
}, 'object test with prefix but complex value', class => 'SL::DB::Manager::OrderItem';
test {
'listprice' => '0.00000',
'onhand' => '5.00000',
'partnumber' => 'v-519160549',
+ part_type => 'part',
#'partsgroup_id' => 111645,
'rop' => '0',
'sellprice' => '242.20000',
'id' => 25505,
'lastcost' => '153.00000',
'listprice' => '0.00000',
+ 'part_type' => 'part',
'onhand' => '9.00000',
'partnumber' => 'v-120160086',
# 'partsgroup_id' => 111639,
description => 'Fourty-two fifty-four',
lastcost => 1.93,
sellprice => 2.34,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part1} }
description => 'Zero EIGHT fifteeN @ 7%',
lastcost => 5.473,
sellprice => 9.714,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe7->id,
unit => $unit->name,
%{ $params{part2} }
description => 'Testware 19%',
lastcost => 0,
sellprice => 50,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part3} }
description => 'Testware 7%',
lastcost => 0,
sellprice => 50,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe7->id,
unit => $unit->name,
%{ $params{part4} }
description => 'Fourty-two fifty-four',
lastcost => 1.93,
sellprice => 2.34,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part1} }
description => 'Zero EIGHT fifteeN @ 7%',
lastcost => 5.473,
sellprice => 9.714,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe7->id,
unit => $unit->name,
%{ $params{part2} }
description => 'Triple 8',
lastcost => 0,
sellprice => 0.6,
+ part_type => 'part',
buchungsgruppen_id => $buchungsgruppe->id,
unit => $unit->name,
%{ $params{part3} }
is($assembly_part->inventory_accno_id, undef, "assembly doesn't have an inventory accno id");
-is($assembly_part->type, 'assembly', 'assembly has correct type');
+is($assembly_part->part_type, 'assembly', 'assembly has correct type');
is( scalar @{$assembly_part->assemblies}, 2, 'assembly consists of two parts' );
# fetch assembly item corresponding to partnumber 19000
$part1 = SL::DB::Part->new_part(partnumber => '19000',
unit => $unit->name,
+ part_type => 'part',
)->save;
$part2 = $part1->clone_and_reset($part1);
$part2->partnumber($part1->partnumber + 1);
SL::DB::Manager::Warehouse->delete_all(where => [ description => NAME() ]);
# Create test data
-$part = SL::DB::Part->new(unit => 'mg', description => NAME(), partnumber => NAME());
+$part = SL::DB::Part->new(unit => 'mg', description => NAME(), partnumber => NAME(), part_type => 'part');
$part->save();
is(ref($part), 'SL::DB::Part', 'loading a part to test with id ' . $part->id);