);
__PACKAGE__->meta->make_manager_class;
+__PACKAGE__->meta->add_relationship(
+ unit_obj => {
+ type => 'one to one',
+ class => 'SL::DB::Unit',
+ column_map => { unit => 'name' },
+ },
+);
__PACKAGE__->meta->initialize;
sub part {
# canonial alias for parts.
- return shift->parts;
+ goto &parts;
}
1;
);
__PACKAGE__->meta->add_relationship(
- part => {
- type => 'one to one',
- class => 'SL::DB::Part',
- column_map => { parts_id => 'id' },
- },
- price_factor_obj => {
- type => 'one to one',
- class => 'SL::DB::PriceFactor',
- column_map => { price_factor_id => 'id' },
- },
unit_obj => {
type => 'one to one',
class => 'SL::DB::Unit',
__PACKAGE__->meta->initialize;
+sub part {
+ # canonial alias for parts.
+ goto &parts;
+}
+
1;
key_columns => { price_factor_id => 'id' },
},
+ pricegroup => {
+ class => 'SL::DB::Pricegroup',
+ key_columns => { pricegroup_id => 'id' },
+ },
+
project => {
class => 'SL::DB::Project',
key_columns => { project_id => 'id' },
class => 'SL::DB::Part',
key_columns => { parts_id => 'id' },
},
+
+ price_factor_obj => {
+ class => 'SL::DB::PriceFactor',
+ key_columns => { price_factor_id => 'id' },
+ },
+
+ pricegroup => {
+ class => 'SL::DB::Pricegroup',
+ key_columns => { pricegroup_id => 'id' },
+ },
+
+ project => {
+ class => 'SL::DB::Project',
+ key_columns => { project_id => 'id' },
+ },
],
);
class => 'SL::DB::Part',
key_columns => { parts_id => 'id' },
},
+
+ price_factor_obj => {
+ class => 'SL::DB::PriceFactor',
+ key_columns => { price_factor_id => 'id' },
+ },
+
+ pricegroup => {
+ class => 'SL::DB::Pricegroup',
+ key_columns => { pricegroup_id => 'id' },
+ },
+
+ project => {
+ class => 'SL::DB::Project',
+ key_columns => { project_id => 'id' },
+ },
+
+ trans => {
+ class => 'SL::DB::Order',
+ key_columns => { trans_id => 'id' },
+ },
],
);
);
__PACKAGE__->meta->add_relationship(
- part => {
- type => 'one to one',
- class => 'SL::DB::Part',
- column_map => { parts_id => 'id' },
- },
- price_factor_obj => {
- type => 'one to one',
- class => 'SL::DB::PriceFactor',
- column_map => { price_factor_id => 'id' },
- },
unit_obj => {
type => 'one to one',
class => 'SL::DB::Unit',
column_map => { unit => 'name' },
},
- order => {
- type => 'one to one',
- class => 'SL::DB::Order',
- column_map => { trans_id => 'id' },
- },
);
__PACKAGE__->meta->initialize;
return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi);
}
+sub part {
+ # canonial alias for parts.
+ goto &parts;
+}
+
+sub order {
+ # canonial alias for trans.
+ goto &trans;
+}
+
1;
do_statement($form, $h_item_id, $q_item_id);
my ($item_id) = $h_item_id->fetchrow_array();
+ # Get pricegroup_id and save it. Unfortunately the interface
+ # also uses ID "0" for signalling that none is selected, but "0"
+ # must not be stored in the database. Therefore we cannot simply
+ # use conv_i().
+ my $pricegroup_id = $form->{"pricegroup_id_$i"} * 1;
+ $pricegroup_id = undef if !$pricegroup_id;
+
# save detail record in delivery_order_items table
@values = (conv_i($item_id), conv_i($form->{id}), conv_i($form->{"id_$i"}),
$form->{"description_$i"}, $form->{"longdescription_$i"},
$form->{"lastcost_$i"},
conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}),
conv_i($form->{"marge_price_factor_$i"}),
- conv_i($form->{"pricegroup_id_$i"}));
+ $pricegroup_id);
do_statement($form, $h_item, $q_item, @values);
my $stock_info = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_$i"});
}
}
- # get pricegroup_id and save it
+ # Get pricegroup_id and save it. Unfortunately the interface
+ # also uses ID "0" for signalling that none is selected, but "0"
+ # must not be stored in the database. Therefore we cannot simply
+ # use conv_i().
($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"});
$pricegroup_id *= 1;
+ $pricegroup_id = undef if !$pricegroup_id;
my ($invoice_id) = selectfirst_array_query($form, $dbh, qq|SELECT nextval('invoiceid')|);
$form->{"sellprice_$i"}, $fxsellprice,
$form->{"discount_$i"}, $allocated, 'f',
$form->{"unit_$i"}, conv_date($form->{"reqdate_$i"}), conv_i($form->{"project_id_$i"}),
- $form->{"serialnumber_$i"}, conv_i($pricegroup_id),
+ $form->{"serialnumber_$i"}, $pricegroup_id,
$form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
$form->{"cusordnumber_$i"}, $baseqty, $form->{"subtotal_$i"} ? 't' : 'f',
$form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
$reqdate = ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef;
- # get pricegroup_id and save ist
+ # Get pricegroup_id and save it. Unfortunately the interface
+ # also uses ID "0" for signalling that none is selected, but "0"
+ # must not be stored in the database. Therefore we cannot simply
+ # use conv_i().
($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"});
$pricegroup_id *= 1;
+ $pricegroup_id = undef if !$pricegroup_id;
# save detail record in orderitems table
my $orderitems_id = $form->{"orderitems_id_$i"};
$form->{"qty_$i"}, $baseqty,
$fxsellprice, $form->{"discount_$i"},
$form->{"unit_$i"}, conv_date($reqdate), conv_i($form->{"project_id_$i"}),
- $form->{"serialnumber_$i"}, $form->{"ship_$i"}, conv_i($pricegroup_id),
+ $form->{"serialnumber_$i"}, $form->{"ship_$i"}, $pricegroup_id,
$form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
$form->{"cusordnumber_$i"}, $form->{"subtotal_$i"} ? 't' : 'f',
$form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
--- /dev/null
+-- @tag: orderitems_delivery_order_items_invoice_foreign_keys
+-- @description: Fremdschlüssel für Tabellen oderitems, delivery_order_items, invoice
+-- @depends: release_3_0_0
+-- @charset: utf-8
+UPDATE orderitems SET pricegroup_id = NULL WHERE pricegroup_id = 0;
+UPDATE delivery_order_items SET pricegroup_id = NULL WHERE pricegroup_id = 0;
+UPDATE invoice SET pricegroup_id = NULL WHERE pricegroup_id = 0;
+
+UPDATE orderitems SET project_id = NULL WHERE project_id NOT IN (SELECT id FROM project);
+UPDATE delivery_order_items SET project_id = NULL WHERE project_id NOT IN (SELECT id FROM project);
+UPDATE invoice SET project_id = NULL WHERE project_id NOT IN (SELECT id FROM project);
+
+ALTER TABLE orderitems ADD FOREIGN KEY (trans_id) REFERENCES oe (id);
+ALTER TABLE orderitems ADD FOREIGN KEY (project_id) REFERENCES project (id);
+ALTER TABLE orderitems ADD FOREIGN KEY (pricegroup_id) REFERENCES pricegroup (id);
+ALTER TABLE orderitems ADD FOREIGN KEY (price_factor_id) REFERENCES price_factors (id);
+
+ALTER TABLE delivery_order_items ADD FOREIGN KEY (pricegroup_id) REFERENCES pricegroup (id);
+
+ALTER TABLE invoice ADD FOREIGN KEY (project_id) REFERENCES project (id);
+ALTER TABLE invoice ADD FOREIGN KEY (pricegroup_id) REFERENCES pricegroup (id);
+ALTER TABLE invoice ADD FOREIGN KEY (price_factor_id) REFERENCES price_factors (id);