X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FIC.pm;h=961c639bf625798f9632c8bc47341200d18639a5;hb=a43c94fd42214048fc61bcd4404f2800e92c49de;hp=74e71cefd802c7e2f696244eabe61f3dbaf3be3b;hpb=23ae25e9dcd34ba16d930f723b66fddac10f52fb;p=kivitendo-erp.git diff --git a/SL/IC.pm b/SL/IC.pm index 74e71cefd..961c639bf 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -370,9 +370,7 @@ sub save { $form->{onhand} *= 1; $form->{ve} *= 1; $form->{ge} *= 1; - $form->{alu} *= 1; $form->{buchungsgruppen_id} *= 1; - $form->{adr_id} *= 1; $form->{not_discountable} *= 1; $form->{payment_id} *= 1; @@ -491,7 +489,6 @@ sub save { rop = $form->{rop}, bin = '$form->{bin}', buchungsgruppen_id = '$form->{buchungsgruppen_id}', - adr_id = '$form->{adr_id}', payment_id = '$form->{payment_id}', inventory_accno_id = (SELECT c.id FROM chart c WHERE c.accno = '$form->{inventory_accno}'), @@ -505,7 +502,6 @@ sub save { shop = '$form->{shop}', ve = '$form->{ve}', gv = '$form->{gv}', - alu = '$form->{alu}', not_discountable = '$form->{not_discountable}', microfiche = '$form->{microfiche}', partsgroup_id = $partsgroup_id @@ -797,6 +793,11 @@ sub delete { # connect to database, turn off AutoCommit my $dbh = $form->dbconnect_noauto($myconfig); + # first delete prices of pricegroup + my $query = qq|DELETE FROM prices + WHERE parts_id = $form->{id}|; + $dbh->do($query) || $form->dberror($query); + my $query = qq|DELETE FROM parts WHERE id = $form->{id}|; $dbh->do($query) || $form->dberror($query); @@ -1506,19 +1507,6 @@ sub create_links { } $sth->finish; - # get adr - $query = qq|SELECT id, adr_description, adr_code - FROM adr|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - - $form->{ADR} = []; - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $form->{ADR} }, $ref; - } - $sth->finish; - # get payment terms $query = qq|SELECT id, description FROM payment_terms @@ -1745,4 +1733,142 @@ sub retrieve_languages { } +sub follow_account_chain { + $main::lxdebug->enter_sub(); + + my ($self, $form, $dbh, $transdate, $accno_id, $accno) = @_; + + my @visited_accno_ids = ($accno_id); + + my ($query, $sth); + + $query = + "SELECT c.new_chart_id, date($transdate) >= c.valid_from AS is_valid, " . + " cnew.accno " . + "FROM chart c " . + "LEFT JOIN chart cnew ON c.new_chart_id = cnew.id " . + "WHERE (c.id = ?) AND NOT c.new_chart_id ISNULL AND (c.new_chart_id > 0)"; + $sth = $dbh->prepare($query); + + while (1) { + $sth->execute($accno_id) || $form->dberror($query . " ($accno_id)"); + $ref = $sth->fetchrow_hashref(); + last unless ($ref && $ref->{"is_valid"} && + !grep({ $_ == $ref->{"new_chart_id"} } @visited_accno_ids)); + $accno_id = $ref->{"new_chart_id"}; + $accno = $ref->{"accno"}; + push(@visited_accno_ids, $accno_id); + } + + $main::lxdebug->leave_sub(); + + return ($accno_id, $accno); +} + +sub retrieve_accounts { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form, $parts_id, $index, $copy_accnos) = @_; + + my ($query, $sth, $dbh); + + return $main::lxdebug->leave_sub() if (!defined($form->{"taxzone_id"})); + + $dbh = $form->dbconnect($myconfig); + + my $transdate = ""; + if ($form->{type} eq "invoice") { + if (($form->{vc} eq "vendor") || !$form->{deliverydate}) { + $transdate = $form->{invdate}; + } else { + $transdate = $form->{deliverydate}; + } + } else { + $transdate = $form->{transdate}; + } + + if ($transdate eq "") { + $transdate = "current_date"; + } else { + $transdate = $dbh->quote($transdate); + } + + $query = + "SELECT " . + " p.inventory_accno_id AS is_part, " . + " bg.inventory_accno_id, " . + " bg.income_accno_id_$form->{taxzone_id} AS income_accno_id, " . + " bg.expense_accno_id_$form->{taxzone_id} AS expense_accno_id, " . + " c1.accno AS inventory_accno, " . + " c2.accno AS income_accno, " . + " c3.accno AS expense_accno " . + "FROM parts p " . + "LEFT JOIN buchungsgruppen bg ON p.buchungsgruppen_id = bg.id " . + "LEFT JOIN chart c1 ON bg.inventory_accno_id = c1.id " . + "LEFT JOIN chart c2 ON bg.income_accno_id_$form->{taxzone_id} = c2.id " . + "LEFT JOIN chart c3 ON bg.expense_accno_id_$form->{taxzone_id} = c3.id " . + "WHERE p.id = ?"; + $sth = $dbh->prepare($query); + $sth->execute($parts_id) || $form->dberror($query . " ($parts_id)"); + my $ref = $sth->fetchrow_hashref(); + $sth->finish(); + +# $main::lxdebug->message(0, "q $query"); + + if (!$ref) { + $dbh->disconnect(); + return $lxdebug->leave_sub(); + } + + $ref->{"inventory_accno_id"} = undef unless ($ref->{"is_part"}); + + my %accounts; + foreach my $type (qw(inventory income expense)) { + next unless ($ref->{"${type}_accno_id"}); + ($accounts{"${type}_accno_id"}, $accounts{"${type}_accno"}) = + $self->follow_account_chain($form, $dbh, $transdate, + $ref->{"${type}_accno_id"}, + $ref->{"${type}_accno"}); + } + + map({ $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} } + qw(inventory income expense)); + + my $inc_exp = $form->{"vc"} eq "customer" ? "income" : "expense"; + my $accno_id = $accounts{"${inc_exp}_accno_id"}; + + $query = + "SELECT c.accno, t.taxdescription AS description, t.rate, t.taxnumber " . + "FROM tax t " . + "LEFT JOIN chart c ON c.id = t.chart_id " . + "WHERE t.id IN " . + " (SELECT tk.tax_id " . + " FROM taxkeys tk " . + " WHERE tk.chart_id = $accno_id AND startdate <= $transdate " . + " ORDER BY startdate DESC LIMIT 1) "; + $sth = $dbh->prepare($query); + $sth->execute() || $form->dberror($query); + $ref = $sth->fetchrow_hashref(); + $sth->finish(); + $dbh->disconnect(); + + return $lxdebug->leave_sub() unless ($ref); + + $form->{"taxaccounts_$index"} = $ref->{"accno"}; + if ($form->{"taxaccounts"} !~ /$ref->{accno}/) { + $form->{"taxaccounts"} .= "$ref->{accno} "; + } + map({ $form->{"$ref->{accno}_${_}"} = $ref->{$_}; } + qw(rate description taxnumber)); + +# $main::lxdebug->message(0, "formvars: rate " . $form->{"$ref->{accno}_rate"} . +# " description " . $form->{"$ref->{accno}_description"} . +# " taxnumber " . $form->{"$ref->{accno}_taxnumber"} . +# " || taxaccounts_$index " . $form->{"taxaccounts_$index"} . +# " || taxaccounts " . $form->{"taxaccounts"}); + + $sth->finish(); + + $main::lxdebug->leave_sub(); +} 1;