# 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
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;
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) = @_;
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;
# 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 = ?)|;
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);
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)
);
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)) {
}
$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();
}
my $i = $form->{rowcount};
# don't include assemblies or obsolete parts
- my $where = "NOT p.assembly = '1' AND NOT p.obsolete = '1'";
+ my $where = "NOT p.part_type = 'assembly' AND NOT p.obsolete = '1'";
my @values;
foreach my $table_column (qw(p.partnumber p.description pg.partsgroup)) {
my $query =
qq|SELECT
p.id, p.partnumber, p.description, p.lastcost AS sellprice, p.listprice,
- p.unit, p.assembly, p.onhand, p.formel,
+ 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,
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
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);
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}}) {
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.
$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 };
}
'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);