X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIR.pm;h=891f24a6f507a42bd04b5b206e8b5d96a3faab38;hb=826d79929635c726f7459296fafa7e630c00e72d;hp=25820bd12f7dc4d2c1f3933d99cbe490caf7f815;hpb=98b64fe1e380c232428d63cea0eb5f44b1d1a2c3;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index 25820bd12..891f24a6f 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; @@ -837,7 +840,7 @@ sub reverse_invoice { # reverse inventory items my $query = - qq|SELECT i.parts_id, p.inventory_accno_id, p.expense_accno_id, i.qty, i.allocated, i.sellprice + qq|SELECT i.parts_id, p.part_type, i.qty, i.allocated, i.sellprice FROM invoice i, parts p WHERE (i.parts_id = p.id) AND (i.trans_id = ?)|; @@ -848,7 +851,7 @@ sub reverse_invoice { while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { $netamount += $form->round_amount($ref->{sellprice} * $ref->{qty} * -1, 2); - next unless $ref->{inventory_accno_id}; + next unless $ref->{part_type} eq 'part'; # if $ref->{allocated} > 0 than we sold that many items next if ($ref->{allocated} <= 0); @@ -1019,7 +1022,8 @@ sub retrieve_invoice { i.id AS invoice_id, 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.inventory_accno_id AS part_inventory_accno_id, pr.projectnumber, pg.partsgroup + p.partnumber, p.part_type, pr.projectnumber, pg.partsgroup + ,p.classification_id FROM invoice i JOIN parts p ON (i.parts_id = p.id) @@ -1043,8 +1047,7 @@ sub retrieve_invoice { ); map { $ref->{"ic_cvar_$_->{name}"} = $_->{value} } @{ $cvars }; - map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid)) if !$ref->{"part_inventory_accno_id"}; - delete($ref->{"part_inventory_accno_id"}); + map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid)) if !$ref->{"part_type"} eq 'part'; foreach my $type (qw(inventory income expense)) { while ($ref->{"${type}_new_chart"} && ($ref->{"${type}_valid"} >=0)) { @@ -1168,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(); } @@ -1278,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, @@ -1295,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 @@ -1311,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); @@ -1329,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}}) { @@ -1339,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. @@ -1409,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 }; } @@ -1468,6 +1447,13 @@ sub vendor_details { 'trans_id' => $form->{vendor_id}); map { $form->{"vc_cvar_$_->{name}"} = $_->{value} } @{ $custom_variables }; + if ($form->{cp_id}) { + $custom_variables = CVar->get_custom_variables(dbh => $dbh, + module => 'Contacts', + trans_id => $form->{cp_id}); + $form->{"cp_cvar_$_->{name}"} = $_->{value} for @{ $custom_variables }; + } + $form->{cp_greeting} = GenericTranslations->get('dbh' => $dbh, 'translation_type' => 'greetings::' . ($form->{cp_gender} eq 'f' ? 'female' : 'male'), 'allow_fallback' => 1);