X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/9a076af6876160ab2a9d86692f64d61d5ee9003c..b35f15e8178c358ae79cfb5f1dfcc93e1c85776d:/SL/IR.pm diff --git a/SL/IR.pm b/SL/IR.pm index 8ce3d0428..dd042488b 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -106,6 +106,8 @@ sub post_invoice { for my $i (1 .. $form->{rowcount}) { next unless $form->{"id_$i"}; + my $position = $i; + $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"}); $form->{"qty_$i"} *= -1 if $form->{storno}; @@ -367,20 +369,37 @@ sub post_invoice { next if $payments_only; + my $cvars; if (!$form->{"invoice_id_$i"}) { # there is no persistent id, therefore create one with all necessary constraints my $q_invoice_id = qq|SELECT nextval('invoiceid')|; my $h_invoice_id = prepare_query($form, $dbh, $q_invoice_id); do_statement($form, $h_invoice_id, $q_invoice_id); $form->{"invoice_id_$i"} = $h_invoice_id->fetchrow_array(); - my $q_create_invoice_id = qq|INSERT INTO invoice (id, trans_id, parts_id) values (?, ?, ?)|; - do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}), conv_i($form->{id}), conv_i($form->{"id_$i"})); + my $q_create_invoice_id = qq|INSERT INTO invoice (id, trans_id, position, parts_id) values (?, ?, ?, ?)|; + do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}), + conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"})); $h_invoice_id->finish(); + + # get values for CVars from master data for new items + $cvars = CVar->get_custom_variables(dbh => $dbh, + module => 'IC', + trans_id => $form->{"id_$i"}, + ); + } else { + # get values for CVars from custom_variables for existing items + $cvars = CVar->get_custom_variables(dbh => $dbh, + module => 'IC', + sub_module => 'invoice', + trans_id => $form->{"invoice_id_$i"}, + ); } + # map only non-editable CVars to form (editable ones are already there) + map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; # save detail record in invoice table $query = <{id}), conv_i($form->{"id_$i"}), + @values = (conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"}), $form->{"description_$i"}, $restricter->process($form->{"longdescription_$i"}), $form->{"qty_$i"} * -1, $baseqty * -1, $form->{"sellprice_$i"}, $fxsellprice, $form->{"discount_$i"}, $allocated, $form->{"unit_$i"}, conv_date($form->{deliverydate}), @@ -407,6 +426,19 @@ SQL name_prefix => 'ic_', name_postfix => "_$i", dbh => $dbh); + # link previous items with invoice items See IS.pm (no credit note -> no invoice item) + foreach (qw(delivery_order_items orderitems)) { + if ($form->{"converted_from_${_}_id_$i"}) { + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => $_, + 'from_ids' => $form->{"converted_from_${_}_id_$i"}, + 'to_table' => 'invoice', + 'to_id' => $form->{"invoice_id_$i"}, + ); + delete $form->{"converted_from_${_}_id_$i"}; + } + } } $h_item_unit->finish(); @@ -683,13 +715,6 @@ SQL my $taxzone_id = $form->{taxzone_id} * 1; $taxzone_id = SL::DB::Manager::TaxZone->get_default->id unless SL::DB::Manager::TaxZone->find_by(id => $taxzone_id); - # Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr - # korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen - # Ich lass den Code von 2005 erstmal noch stehen ;-) jb 03-2011 - # copy & paste von IS.pm - if (!$form->{department_id}){ - $form->{department_id} = (split /--/, $form->{department})[1]; - } $form->{invnumber} = $form->{id} unless $form->{invnumber}; # save AP record @@ -742,14 +767,16 @@ SQL Common::webdav_folder($form); # Link this record to the records it was created from. - RecordLinks->create_links('dbh' => $dbh, - 'mode' => 'ids', - 'from_table' => 'oe', - 'from_ids' => $form->{convert_from_oe_ids}, - 'to_table' => 'ap', - 'to_id' => $form->{id}, - ); - delete $form->{convert_from_oe_ids}; + if ($form->{convert_from_oe_ids}) { + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => 'oe', + 'from_ids' => $form->{convert_from_oe_ids}, + 'to_table' => 'ap', + 'to_id' => $form->{id}, + ); + delete $form->{convert_from_oe_ids}; + } my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids}; if (scalar @convert_from_do_ids) { @@ -1010,7 +1037,7 @@ sub retrieve_invoice { WHERE i.trans_id = ? - ORDER BY i.id|; + ORDER BY i.position|; $sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {