X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/9a076af6876160ab2a9d86692f64d61d5ee9003c..d557935a1484e5ebbb15f0eabe107d74e192ff0b:/SL/IS.pm diff --git a/SL/IS.pm b/SL/IS.pm index e09c08c31..a64765388 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -373,6 +373,24 @@ sub invoice_details { $sth->finish; } + my $cvars; + if (! $form->{"invoice_id_$i"}) { + # 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 }; + push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_) for @{ $ic_cvar_configs }; @@ -578,13 +596,6 @@ sub post_invoice { $form->{defaultcurrency} = $form->get_default_currency($myconfig); my $defaultcurrency = $form->{defaultcurrency}; - # 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 - if (!$form->{department_id}){ - ($null, $form->{department_id}) = split(/--/, $form->{department}); - } - my $all_units = AM->retrieve_units($myconfig, $form); if (!$payments_only) { @@ -655,6 +666,7 @@ sub post_invoice { if ($form->{"id_$i"}) { my $item_unit; + my $position = $i; if (defined($baseunits{$form->{"id_$i"}})) { $item_unit = $baseunits{$form->{"id_$i"}}; @@ -740,7 +752,7 @@ sub post_invoice { if ($form->{"assembly_$i"}) { # record assembly item as allocated - &process_assembly($dbh, $myconfig, $form, $form->{"id_$i"}, $baseqty); + &process_assembly($dbh, $myconfig, $form, $position, $form->{"id_$i"}, $baseqty); } else { $allocated = &cogs($dbh, $myconfig, $form, $form->{"id_$i"}, $baseqty, $basefactor, $i); @@ -755,20 +767,37 @@ sub post_invoice { $pricegroup_id *= 1; $pricegroup_id = undef if !$pricegroup_id; + 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"}, $form->{"sellprice_$i"}, $fxsellprice, $form->{"discount_$i"}, $allocated, 'f', @@ -803,6 +832,19 @@ SQL name_postfix => "_$i", dbh => $dbh); } + # link previous items with invoice items + foreach (qw(delivery_order_items orderitems invoice)) { + 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"}; + } + } } # total payments, don't move we need it here @@ -1200,14 +1242,16 @@ SQL } # 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' => 'ar', - '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' => 'ar', + '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}; @@ -1380,7 +1424,7 @@ sub post_payment { sub process_assembly { $main::lxdebug->enter_sub(); - my ($dbh, $myconfig, $form, $id, $totalqty) = @_; + my ($dbh, $myconfig, $form, $position, $id, $totalqty) = @_; my $query = qq|SELECT a.parts_id, a.qty, p.assembly, p.partnumber, p.description, p.unit, @@ -1401,7 +1445,7 @@ sub process_assembly { $ref->{qty} *= $totalqty; if ($ref->{assembly}) { - &process_assembly($dbh, $myconfig, $form, $ref->{parts_id}, $ref->{qty}); + &process_assembly($dbh, $myconfig, $form, $position, $ref->{parts_id}, $ref->{qty}); next; } else { if ($ref->{inventory_accno_id}) { @@ -1411,9 +1455,10 @@ sub process_assembly { # save detail record for individual assembly item in invoice table $query = - qq|INSERT INTO invoice (trans_id, description, parts_id, qty, sellprice, fxsellprice, allocated, assemblyitem, unit) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)|; - my @values = (conv_i($form->{id}), $ref->{description}, conv_i($ref->{parts_id}), $ref->{qty}, 0, 0, $allocated, 't', $ref->{unit}); + qq|INSERT INTO invoice (trans_id, position, description, parts_id, qty, sellprice, fxsellprice, allocated, assemblyitem, unit) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; + my @values = (conv_i($form->{id}), conv_i($position), $ref->{description}, + conv_i($ref->{parts_id}), $ref->{qty}, 0, 0, $allocated, 't', $ref->{unit}); do_query($form, $dbh, $query, @values); } @@ -1715,7 +1760,7 @@ sub retrieve_invoice { LEFT JOIN chart c2 ON ((SELECT tc.income_accno_id FROM taxzone_charts tc WHERE tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c2.id) LEFT JOIN chart c3 ON ((SELECT tc.expense_accno_id FROM taxzone_charts tc WHERE tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c3.id) - WHERE (i.trans_id = ?) AND NOT (i.assemblyitem = '1') ORDER BY i.id|; + WHERE (i.trans_id = ?) AND NOT (i.assemblyitem = '1') ORDER BY i.position|; $sth = prepare_execute_query($form, $dbh, $query, $id);