X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIR.pm;h=a424ab99083b8a9334a193779adbace2050d2af1;hb=b391b42da949cd0c2a9c8c1860042e19eb0e62c2;hp=a0bf6cdf6bdf51c19c3537d9c3b33f5a65d1e45a;hpb=c364e43efab3ac6f0f0c20cd6f8f89a85ab45280;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index a0bf6cdf6..a424ab990 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,6 +811,10 @@ 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 @@ -1020,6 +1029,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 +1177,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 +1250,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 +1268,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 +1285,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 +1304,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 +1315,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 +1391,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 }; }