my $query =
qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, a.curr | .
- qq|FROM $arap a | .
+ qq|FROM $arap a | .
qq|WHERE (a.${vc}_id = ?) AND (a.curr = ? $curr_null) AND NOT (a.amount = paid)| .
- qq|ORDER BY a.id|;
+ qq|ORDER BY a.id|;
my $sth = prepare_execute_query($form, $dbh, $query,
conv_i($form->{"${vc}_id"}),
$form->{currency});
qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, | .
qq| cleared, fx_transaction) | .
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
- @values = (conv_i($form->{"id_$i"}), $paymentaccno,
+ @values = (conv_i($form->{"id_$i"}), $paymentaccno,
conv_date($form->{datepaid}), ($amount * $ml * -1), '0',
'1');
do_query($form, $dbh, $query, @values);
# update AR/AP transaction
$query = qq|UPDATE $arap SET $paid, datepaid = ? WHERE id = ?|;
- @values = (conv_date($form->{datepaid}), conv_i($form->{"id_$i"}));
+ @values = (conv_date($form->{datepaid}), conv_i($form->{"id_$i"}));
do_query($form, $dbh, $query, @values);
# saving the history
$form->{id} = $form->{"id_$i"};
}
}
- # record a AR/AP with a payment
- if ($form->round_amount($paymentamount, 2) > 0) {
- $form->{invnumber} = "";
- OP::overpayment("", $myconfig, $form, $dbh, $paymentamount, $ml, 1);
- }
-
my $rc;
if ($form->round_amount($paymentamount, 2) < 0) {
- $dbh->rollback;
+ # Hier werden negativen Zahlungseingänge abgefangen
+ # Besser: in Oberfläche schon prüfen
+ # Zahlungsein- und ausgänge sind immer positiv
+ $dbh->rollback;
$rc = 0;
}
if ($form->round_amount($paymentamount, 2) == 0) {
if (($form->{"make_$i"}) || ($form->{"model_$i"})) {
$query = qq|INSERT INTO makemodel (parts_id, make, model) | .
- qq|VALUES (?, ?, ?)|;
- @values = (conv_i($form->{id}), conv_i($form->{"make_$i"}), $form->{"model_$i"});
+ qq|VALUES (?, ?, ?)|;
+ @values = (conv_i($form->{id}), conv_i($form->{"make_$i"}), $form->{"model_$i"});
do_query($form, $dbh, $query, @values);
}
$query =
qq|INSERT INTO partstax (parts_id, chart_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?))|;
- @values = (conv_i($form->{id}), $item);
+ @values = (conv_i($form->{id}), $item);
do_query($form, $dbh, $query, @values);
}
}
if ($form->{"qty_$i"} != 0) {
$form->{"bom_$i"} *= 1;
$query = qq|INSERT INTO assembly (id, parts_id, qty, bom) | .
- qq|VALUES (?, ?, ?, ?)|;
- @values = (conv_i($form->{id}), conv_i($form->{"id_$i"}), conv_i($form->{"qty_$i"}), $form->{"bom_$i"} ? 't' : 'f');
+ qq|VALUES (?, ?, ?, ?)|;
+ @values = (conv_i($form->{id}), conv_i($form->{"id_$i"}), conv_i($form->{"qty_$i"}), $form->{"bom_$i"} ? 't' : 'f');
do_query($form, $dbh, $query, @values);
}
}
#my $order_clause = " ORDER BY $form->{sort} $sort_order";
- my $limit_clause = " LIMIT 100" if $form->{top100};
+ my $limit_clause;
+ $limit_clause = " LIMIT 100" if $form->{top100};
+ $limit_clause = " LIMIT " . $form->{limit} * 1 if $form->{limit} * 1;
#=== joins and complicated filters ========#
}
$main::lxdebug->leave_sub();
+
+ return wantarray ? @{ $form->{parts} } : $form->{parts};
}
sub _create_filter_for_priceupdate {
qq| cnew.accno | .
qq|FROM chart c | .
qq|LEFT JOIN chart cnew ON c.new_chart_id = cnew.id | .
- qq|WHERE (c.id = ?) AND NOT c.new_chart_id ISNULL AND (c.new_chart_id > 0)|;
+ qq|WHERE (c.id = ?) AND NOT c.new_chart_id IS NULL AND (c.new_chart_id > 0)|;
$sth = prepare_query($form, $dbh, $query);
while (1) {
use strict;
- =head1 NAME
-
- OE.pm - Order entry module
-
- =head1 DESCRIPTION
-
- OE.pm is part of the OE module. OE is responsible for sales and purchase orders, as well as sales quotations and purchase requests. This file abstracts the database tables C<oe> and C<orderitems>.
-
- =head1 FUNCTIONS
-
- =over 4
-
- =cut
-
sub transactions {
$main::lxdebug->enter_sub();
return $rc;
}
- =item retrieve_simple PARAMS
-
- simple OE retrieval by id. does not look up customer, vendor, units or any other stuff. only oe and orderitems.
-
- my $order = retrieve_simple(id => 2);
-
- $order => {
- %_OE_CONTENT,
- orderitems => [
- %_ORDERITEM_ROW_1,
- %_ORDERITEM_ROW_2,
- ...
- ]
- }
-
- =cut
sub retrieve_simple {
$main::lxdebug->enter_sub();
}
$query = qq|SELECT p.partnumber, p.description, p.unit, a.qty, | .
- qq|pg.partsgroup | .
- qq|FROM assembly a | .
- qq| JOIN parts p ON (a.parts_id = p.id) | .
- qq| LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) | .
- qq| WHERE a.bom = '1' | .
- qq| AND a.id = ? | . $sortorder;
- @values = ($form->{"id_$i"});
+ qq|pg.partsgroup | .
+ qq|FROM assembly a | .
+ qq| JOIN parts p ON (a.parts_id = p.id) | .
+ qq| LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) | .
+ qq| WHERE a.bom = '1' | .
+ qq| AND a.id = ? | . $sortorder;
+ @values = ($form->{"id_$i"});
$sth = $dbh->prepare($query);
$sth->execute(@values) || $form->dberror($query);
return $value;
}
+##########################
+# Get data for the submitted order id
+# from database
+#
+sub get_order_data_by_ordnumber {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ Common::check_params(\%params, qw(ordnumber));
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $dbh = $form->get_standard_dbh();
+
+ my @values = ($params{ordnumber});
+
+ # We query the database for the fields we need using the submitted "ordnumber"
+ my $query = <<SQL;
+ SELECT o.payment_id, o.salesman_id, o.transdate AS orddate, o.taxzone_id, o.quonumber
+ FROM oe o
+ WHERE o.ordnumber = ?;
+SQL
+
+ # Do the actual query and return the results for later processing by our "frontend"
+ my $result = selectfirst_hashref_query($form, $dbh, $query, @values);
+
+ $main::lxdebug->leave_sub();
+
+ return $result;
+}
+
1;
+
+ __END__
+
+ =head1 NAME
+
+ OE.pm - Order entry module
+
+ =head1 DESCRIPTION
+
+ OE.pm is part of the OE module. OE is responsible for sales and purchase orders, as well as sales quotations and purchase requests. This file abstracts the database tables C<oe> and C<orderitems>.
+
+ =head1 FUNCTIONS
+
+ =over 4
+
+ =item retrieve_simple PARAMS
+
+ simple OE retrieval by id. does not look up customer, vendor, units or any other stuff. only oe and orderitems.
+
+ my $order = retrieve_simple(id => 2);
+
+ $order => {
+ %_OE_CONTENT,
+ orderitems => [
+ %_ORDERITEM_ROW_1,
+ %_ORDERITEM_ROW_2,
+ ...
+ ]
+ }
+
+ =back
+
+ =cut
#======================================================================
use SL::CP;
-use SL::OP;
use SL::IS;
use SL::IR;
$form->format_amount(\%myconfig, $form->{exchangerate});
if ($form->{forex}) {
$exchangerate = qq|
- <tr>
- <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
- <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
- </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
+ <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
+ </tr>
|;
} else {
$exchangerate = qq|
- <tr>
- <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
- <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
- </tr>
+ <tr>
+ <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
+ <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
+ </tr>
|;
}
}
<tr>
<td>
<table width=100%>
- <tr>
- <th class=listheading colspan=$colspan>$invoice</th>
- </tr>
+ <tr>
+ <th class=listheading colspan=$colspan>$invoice</th>
+ </tr>
|;
$column_data{invnumber} =
$j++;
$j %= 2;
print qq|
- <tr class=listrow$j>
+ <tr class=listrow$j>
|;
map { print "$column_data{$_}\n" } @column_index;
print qq|
$format .= qq|
<option value=postscript $form->{DF}{postscript}>|
. $locale->text('Postscript') . qq|
- <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
+ <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
}
print qq|
use SL::FU;
use SL::IS;
use SL::PE;
+use SL::OE;
use Data::Dumper;
use List::Util qw(max sum);
$ref->{name} = $form->quote($ref->{name});
}
+ # Load data for a specific order and update form fields
+ my $order_data = OE->get_order_data_by_ordnumber(%$form) if $form->{ordnumber};
+
+ # Copy the fields we need to %form
+ for my $key (qw(payment_id salesman_id orddate taxzone_id quonumber)) {
+ $form->{$key} = $order_data->{$key};
+ }
+
$form->restore_vars(qw(id));
IS->retrieve_invoice(\%myconfig, \%$form);
$form->restore_vars(qw(taxincluded)) if $form->{id};
$form->restore_vars(qw(salesman_id)) if $main::editing;
+
# build vendor/customer drop down comatibility... don't ask
if (@{ $form->{"all_customer"} }) {
$form->{"selectcustomer"} = 1;
$form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
my $set_duedate_url = "$form->{script}?action=set_duedate";
"taxzones" => "ALL_TAXZONES",
"currencies" => "ALL_CURRENCIES",
"customers" => "ALL_CUSTOMERS",
+ "departments" => "all_departments",
"price_factors" => "ALL_PRICE_FACTORS");
$TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
# saving the history
- if(!exists $form->{addition}) {
+ if(!exists $form->{addition}) {
$form->{snumbers} = qq|invnumber_| . $form->{invnumber};
- $form->{addition} = "DELETED";
- $form->save_history($form->dbconnect(\%myconfig));
+ $form->{addition} = "DELETED";
+ $form->save_history($form->dbconnect(\%myconfig));
}
# /saving the history
$form->redirect($locale->text('Invoice deleted!'));