X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/bb7e2e85d50544c6b72eb40d57f513eeacf578d5..be418943f8d231dab72bdb1849cc7d0dfdc5ae06:/SL/IS.pm diff --git a/SL/IS.pm b/SL/IS.pm index c5fd8821f..f429034e8 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -44,12 +44,14 @@ use SL::DATEV qw(:CONSTANTS); use SL::DBUtils; use SL::DO; use SL::GenericTranslations; +use SL::HTML::Restrict; use SL::MoreCommon; use SL::IC; use SL::IO; use SL::TransNumber; use SL::DB::Default; use SL::DB::Tax; +use SL::DB::TaxZone; use SL::TransNumber; use Data::Dumper; @@ -396,7 +398,7 @@ sub invoice_details { push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} }, $form->{"${item}_taxnumber"}); my $tax_obj = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"}); - my $description = $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) if $tax_obj; + my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) : ''; push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%}); } @@ -546,6 +548,7 @@ sub post_invoice { # connect to database, turn off autocommit my $dbh = $provided_dbh ? $provided_dbh : $form->get_standard_dbh; + my $restricter = SL::HTML::Restrict->create; my ($query, $sth, $null, $project_id, @values); my $exchangerate = 0; @@ -580,8 +583,8 @@ sub post_invoice { $query = qq|SELECT nextval('glid')|; ($form->{"id"}) = selectrow_query($form, $dbh, $query); - $query = qq|INSERT INTO ar (id, invnumber, currency_id) VALUES (?, ?, (SELECT id FROM currencies WHERE name=?))|; - do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"}, $form->{currency}); + $query = qq|INSERT INTO ar (id, invnumber, currency_id, taxzone_id) VALUES (?, ?, (SELECT id FROM currencies WHERE name=?), ?)|; + do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"}, $form->{currency}, $form->{taxzone_id}); if (!$form->{invnumber}) { my $trans_number = SL::TransNumber->new(type => $form->{type}, dbh => $dbh, number => $form->{invnumber}, id => $form->{id}); @@ -749,7 +752,7 @@ sub post_invoice { (SELECT factor FROM price_factors WHERE id = ?), ?)|; @values = ($invoice_id, conv_i($form->{id}), conv_i($form->{"id_$i"}), - $form->{"description_$i"}, $form->{"longdescription_$i"}, $form->{"qty_$i"}, + $form->{"description_$i"}, $restricter->process($form->{"longdescription_$i"}), $form->{"qty_$i"}, $form->{"sellprice_$i"}, $fxsellprice, $form->{"discount_$i"}, $allocated, 'f', $form->{"unit_$i"}, conv_date($form->{"reqdate_$i"}), conv_i($form->{"project_id_$i"}), @@ -1143,10 +1146,10 @@ sub post_invoice { do_query($form, $dbh, qq|UPDATE ar SET paid = amount WHERE id = ?|, conv_i($form->{"id"})); } - # add shipto $form->{name} = $form->{customer}; $form->{name} =~ s/--\Q$form->{customer_id}\E//; + # add shipto if (!$form->{shipto_id}) { $form->add_shipto($dbh, $form->{id}, "AR"); } @@ -1390,8 +1393,8 @@ sub cogs { c3.accno AS expense_accno, c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from AS expense_valid FROM invoice i, parts p LEFT JOIN chart c1 ON ((SELECT inventory_accno_id FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id) - LEFT JOIN chart c2 ON ((SELECT income_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c2.id) - LEFT JOIN chart c3 ON ((select expense_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c3.id) + 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.parts_id = p.id) AND (i.parts_id = ?) AND ((i.base_qty + i.allocated) < 0) @@ -1613,12 +1616,6 @@ sub retrieve_invoice { $form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "buy"); - # get shipto - $query = qq|SELECT * FROM shipto WHERE (trans_id = ?) AND (module = 'AR')|; - $ref = selectfirst_hashref_query($form, $dbh, $query, $id); - delete $ref->{id}; - map { $form->{$_} = $ref->{$_} } keys %{ $ref }; - foreach my $vc (qw(customer vendor)) { next if !$form->{"delivery_${vc}_id"}; ($form->{"delivery_${vc}_string"}) = selectrow_query($form, $dbh, qq|SELECT name FROM customer WHERE id = ?|, $id); @@ -1642,7 +1639,7 @@ sub retrieve_invoice { my $taxzone_id = $form->{taxzone_id} *= 1; - $taxzone_id = 0 if (0 > $taxzone_id) || (3 < $taxzone_id); + $taxzone_id = SL::DB::Manager::TaxZone->get_default->id unless SL::DB::Manager::TaxZone->find_by(id => $taxzone_id); # retrieve individual items $query = @@ -1665,8 +1662,8 @@ sub retrieve_invoice { LEFT JOIN pricegroup prg ON (i.pricegroup_id = prg.id) LEFT JOIN chart c1 ON ((SELECT inventory_accno_id FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id) - LEFT JOIN chart c2 ON ((SELECT income_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c2.id) - LEFT JOIN chart c3 ON ((SELECT expense_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c3.id) + 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|; @@ -1835,19 +1832,6 @@ sub get_customer { } $sth->finish; - # get shipto if we did not converted an order or invoice - if (!$form->{shipto}) { - map { delete $form->{$_} } - qw(shiptoname shiptodepartment_1 shiptodepartment_2 - shiptostreet shiptozipcode shiptocity shiptocountry - shiptocontact shiptophone shiptofax shiptoemail); - - $query = qq|SELECT * FROM shipto WHERE trans_id = ? AND module = 'CT'|; - $ref = selectfirst_hashref_query($form, $dbh, $query, $cid); - delete $ref->{id}; - map { $form->{$_} = $ref->{$_} } keys %$ref; - } - # setup last accounts used for this customer if (!$form->{id} && $form->{type} !~ /_(order|quotation)/) { $query = @@ -1976,13 +1960,13 @@ sub retrieve_item { FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id) LEFT JOIN chart c2 ON - ((SELECT income_accno_id_${taxzone_id} - FROM buchungsgruppen - WHERE id = p.buchungsgruppen_id) = c2.id) + ((SELECT tc.income_accno_id + FROM taxzone_charts tc + WHERE tc.buchungsgruppen_id = p.buchungsgruppen_id and tc.taxzone_id = ${taxzone_id}) = c2.id) LEFT JOIN chart c3 ON - ((SELECT expense_accno_id_${taxzone_id} - FROM buchungsgruppen - WHERE id = p.buchungsgruppen_id) = c3.id) + ((SELECT tc.expense_accno_id + FROM taxzone_charts tc + WHERE tc.buchungsgruppen_id = p.buchungsgruppen_id and tc.taxzone_id = ${taxzone_id}) = c3.id) LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id) LEFT JOIN price_factors pfac ON (pfac.id = p.price_factor_id) WHERE $where|;