X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIR.pm;h=f3f1fd0ca4ba5b065df0213bfa9e4dae4269d857;hb=c9b4e6bc629fb185b380cda69bca5d3460bc58e0;hp=a0bf6cdf6bdf51c19c3537d9c3b33f5a65d1e45a;hpb=723a11583380d2cef883c12f654d6a35bffee83b;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index a0bf6cdf6..f3f1fd0ca 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -25,7 +25,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Inventory received module @@ -40,6 +41,7 @@ use SL::Common; use SL::CVar; use SL::DATEV qw(:CONSTANTS); use SL::DBUtils; +use SL::DB::Draft; use SL::DO; use SL::GenericTranslations; use SL::HTML::Restrict; @@ -51,6 +53,9 @@ use SL::DB; use List::Util qw(min); use strict; +use constant PCLASS_OK => 0; +use constant PCLASS_NOTFORSALE => 1; +use constant PCLASS_NOTFORPURCHASE => 2; sub post_invoice { my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; @@ -806,21 +811,19 @@ SQL do_query($form, $dbh, $query, @orphaned_ids); } + if ($form->{draft_id}) { + SL::DB::Manager::Draft->delete_all(where => [ id => delete($form->{draft_id}) ]); + } + # safety check datev export if ($::instance_conf->get_datev_check_on_purchase_invoice) { - # if we need department for kostenstelle in DATEV check - $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id}; - my $transdate = $::form->{invdate} ? DateTime->from_lxoffice($::form->{invdate}) : undef; - $transdate ||= DateTime->today; my $datev = SL::DATEV->new( - exporttype => DATEV_ET_BUCHUNGEN, - format => DATEV_FORMAT_KNE, dbh => $dbh, trans_id => $form->{id}, ); - $datev->export; + $datev->generate_datev_data; if ($datev->errors) { die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors; @@ -1020,6 +1023,7 @@ sub retrieve_invoice { i.description, i.longdescription, i.qty, i.fxsellprice AS sellprice, i.parts_id AS id, i.unit, i.deliverydate, i.project_id, i.serialnumber, i.price_factor_id, i.price_factor, i.marge_price_factor, i.discount, i.active_price_source, i.active_discount_source, p.partnumber, p.part_type, pr.projectnumber, pg.partsgroup + ,p.classification_id FROM invoice i JOIN parts p ON (i.parts_id = p.id) @@ -1167,43 +1171,6 @@ sub get_vendor { } $sth->finish(); - if (!$params->{id} && $params->{type} !~ /_(order|quotation)/) { - # setup last accounts used - $query = - qq|SELECT c.id, c.accno, c.description, c.link, c.category - FROM chart c - JOIN acc_trans ac ON (ac.chart_id = c.id) - JOIN ap a ON (a.id = ac.trans_id) - WHERE (a.vendor_id = ?) - AND (NOT ((c.link LIKE '%_tax%') OR (c.link LIKE '%_paid%'))) - AND (a.id IN (SELECT max(a2.id) FROM ap a2 WHERE a2.vendor_id = ?))|; - my $refs = selectall_hashref_query($form, $dbh, $query, $vid, $vid); - - my $i = 0; - for $ref (@$refs) { - if ($ref->{category} eq 'E') { - $i++; - my ($tax_id, $rate); - if ($params->{initial_transdate}) { - my $tax_query = qq|SELECT tk.tax_id, t.rate FROM taxkeys tk - LEFT JOIN tax t ON (tk.tax_id = t.id) - WHERE (tk.chart_id = ?) AND (startdate <= ?) - ORDER BY tk.startdate DESC - LIMIT 1|; - ($tax_id, $rate) = selectrow_query($form, $dbh, $tax_query, $ref->{id}, $params->{initial_transdate}); - $params->{"taxchart_$i"} = "${tax_id}--${rate}"; - } - - $params->{"AP_amount_$i"} = "$ref->{accno}--$tax_id"; - } - - if ($ref->{category} eq 'L') { - $params->{APselected} = $params->{AP_1} = $ref->{accno}; - } - } - $params->{rowcount} = $i if ($i && !$params->{type}); - } - $main::lxdebug->leave_sub(); } @@ -1277,8 +1244,9 @@ sub retrieve_item { p.id, p.partnumber, p.description, p.lastcost AS sellprice, p.listprice, p.unit, p.part_type, p.onhand, p.formel, p.notes AS partnotes, p.notes AS longdescription, p.not_discountable, - p.inventory_accno_id, p.price_factor_id, + p.price_factor_id, p.ean, + p.classification_id, pfac.factor AS price_factor, @@ -1294,6 +1262,7 @@ sub retrieve_item { c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from AS expense_valid, + pt.used_for_purchase AS used_for_purchase, pg.partsgroup FROM parts p @@ -1310,6 +1279,7 @@ sub retrieve_item { FROM taxzone_charts tc WHERE tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c3.id) LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id) + LEFT JOIN part_classifications pt ON (pt.id = p.classification_id) LEFT JOIN price_factors pfac ON (pfac.id = p.price_factor_id) WHERE $where|; my $sth = prepare_execute_query($form, $dbh, $query, @values); @@ -1328,6 +1298,7 @@ sub retrieve_item { map { push @{ $_ }, prepare_query($form, $dbh, $_->[0]) } @translation_queries; $form->{item_list} = []; + my $has_wrong_pclass = PCLASS_OK; while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { if ($mm_by_id{$ref->{id}}) { @@ -1338,7 +1309,13 @@ sub retrieve_item { if (($::form->{"partnumber_$i"} ne '') && ($ref->{ean} eq $::form->{"partnumber_$i"})) { push @{ $ref->{matches} ||= [] }, $::locale->text('EAN') . ': ' . $ref->{ean}; } + $ref->{type_and_classific} = $::request->presenter->type_abbreviation($ref->{part_type}). + $::request->presenter->classification_abbreviation($ref->{classification_id}); + if (! $ref->{used_for_purchase} ) { + $has_wrong_pclass = PCLASS_NOTFORPURCHASE; + next; + } # In der Buchungsgruppe ist immer ein Bestandskonto verknuepft, auch wenn # es sich um eine Dienstleistung handelt. Bei Dienstleistungen muss das # Buchungskonto also aus dem Ergebnis rausgenommen werden. @@ -1408,12 +1385,15 @@ sub retrieve_item { $sth->finish(); $_->[1]->finish for @translation_queries; + $form->{is_wrong_pclass} = $has_wrong_pclass; + $form->{NOTFORSALE} = PCLASS_NOTFORSALE; + $form->{NOTFORPURCHASE} = PCLASS_NOTFORPURCHASE; foreach my $item (@{ $form->{item_list} }) { my $custom_variables = CVar->get_custom_variables(module => 'IC', trans_id => $item->{id}, dbh => $dbh, ); - + $form->{is_wrong_pclass} = PCLASS_OK; # one correct type map { $item->{"ic_cvar_" . $_->{name} } = $_->{value} } @{ $custom_variables }; }