# 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.
#======================================================================
#
# Sales report
use List::Util qw(sum first);
use SL::AM;
+use SL::DB::Employee;
use SL::VK;
use SL::IS;
use SL::ReportGenerator;
use Data::Dumper;
-require "bin/mozilla/arap.pl";
require "bin/mozilla/common.pl";
-require "bin/mozilla/drafts.pl";
require "bin/mozilla/reportgenerator.pl";
use strict;
sub search_invoice {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger | invoice_edit');
+ $main::auth->assert('ar_transactions | ap_transactions | invoice_edit');
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- my ($customer, $department);
+ my ($customer);
- # setup customer selection
- $form->all_vc(\%myconfig, "customer", "AR");
+ $::request->layout->add_javascripts("autocomplete_project.js");
$form->{title} = $locale->text('Sales Report');
- $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
- "departments" => "ALL_DEPARTMENTS",
+ $form->get_lists("departments" => "ALL_DEPARTMENTS",
"business_types" => "ALL_BUSINESS_TYPES",
"salesmen" => "ALL_SALESMEN",
- 'employees' => 'ALL_EMPLOYEES',
- 'partsgroup' => 'ALL_PARTSGROUPS',
- "customers" => "ALL_VC");
+ 'partsgroup' => 'ALL_PARTSGROUPS');
+
+ $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted;
+
$form->{CUSTOM_VARIABLES_IC} = CVar->get_configs('module' => 'IC');
($form->{CUSTOM_VARIABLES_FILTER_CODE_IC},
$form->{CUSTOM_VARIABLES_INCLUSION_CODE_IC}) = CVar->render_search_options('variables' => $form->{CUSTOM_VARIABLES_IC},
$form->{CUSTOM_VARIABLES_INCLUSION_CODE_CT}) = CVar->render_search_options('variables' => $form->{CUSTOM_VARIABLES_CT},
'include_prefix' => 'l_',
'include_value' => 'Y');
- $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
- $form->{employee_labels} = sub { $_[0]->{"name"} || $_[0]->{"login"} };
- $form->{salesman_labels} = $form->{employee_labels};
-
$form->header;
print $form->parse_html_template('vk/search_invoice', { %myconfig });
sub invoice_transactions {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger | invoice_edit');
+ $main::auth->assert('ar_transactions | ap_transactions | invoice_edit');
my $form = $main::form;
my %myconfig = %main::myconfig;
};
if ( $form->{customer} =~ /--/ ) {
- # field data comes from dropdown box
- ($form->{customername}, $form->{customer_id}) = split(/--/, $form->{customer});
- } elsif ($form->{customer}) {
-
- # a value was added in the input box, we only want to filter for one
- # customer, so check that a unique customer can be found
-
- # check_name is executed with no_select => 1, if the result isn't unique
- # quit with an error message, the user has to enter a new name
-
- # Without no_select selecting a customer causes an update which doesn't
- # return anything, which is the reason for this workaround
-
- &check_name('customer', no_select => 1);
-
- # $form->{customer_id} was already set by check_name
- $form->{customername} = $form->{customer};
- };
+ # Felddaten kommen aus Dropdownbox
+ my $dummy;
+ ($dummy, $form->{customer_id}) = split(/--/, $form->{customer});
+ }
# if $form->{customer} is empty nothing further happens here
# test for decimalplaces or set to default of 2
$form->{title} = $locale->text('Sales Report');
@columns =
- qw(description invnumber transdate customernumber customername partnumber partsgroup country business transdate qty parts_unit weight sellprice sellprice_total discount lastcost lastcost_total marge_total marge_percent employee salesman);
+ qw(description invnumber transdate shipvia customernumber customername partnumber partsgroup country business transdate qty parts_unit weight sellprice sellprice_total discount lastcost lastcost_total marge_total marge_percent employee salesman);
my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs_ic }, @{ $cvar_configs_ct };
my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs_ic }, @{ $cvar_configs_ct };
# pass hidden variables for pdf/csv export
# first with l_ to determine which columns to show
# then with the options for headings (such as transdatefrom, partnumber, ...)
- my @hidden_variables = (qw(l_headers_mainsort l_headers_subsort l_subtotal_mainsort l_subtotal_subsort l_total l_parts l_customername l_customernumber transdatefrom transdateto decimalplaces customer customername customer_id department partnumber partsgroup country business description project_id customernumber salesman employee salesman_id employee_id business_id partsgroup_id mainsort subsort),
+ my @hidden_variables = (qw(l_headers_mainsort l_headers_subsort l_subtotal_mainsort l_subtotal_subsort l_total l_parts l_customername l_customernumber transdatefrom transdateto decimalplaces customer customer_id department_id partnumber partsgroup country business description project_id customernumber salesman employee salesman_id employee_id business_id partsgroup_id mainsort subsort),
"$form->{db}number",
map({ "cvar_$_->{name}" } @searchable_custom_variables),
map { "l_$_" } @columns
my %column_defs = (
'description' => { 'text' => $locale->text('Description'), },
'partnumber' => { 'text' => $locale->text('Part Number'), },
- 'partsgroup' => { 'text' => $locale->text('Group'), },
+ 'partsgroup' => { 'text' => $locale->text('Partsgroup'), },
'country' => { 'text' => $locale->text('Country'), },
'business' => { 'text' => $locale->text('Customer type'), },
'employee' => { 'text' => $locale->text('Employee'), },
'salesman' => { 'text' => $locale->text('Salesperson'), },
'invnumber' => { 'text' => $locale->text('Invoice Number'), },
'transdate' => { 'text' => $locale->text('Invoice Date'), },
+ 'shipvia' => { 'text' => $locale->text('Ship via'), },
'qty' => { 'text' => $locale->text('Quantity'), },
'parts_unit' => { 'text' => $locale->text('Base unit'), },
'weight' => { 'text' => $locale->text('Weight'), },
my @options;
push @options, $locale->text('Description') . " : $form->{description}" if $form->{description};
- push @options, $locale->text('Customer') . " : $form->{customername}" if $form->{customer};
+ push @options, $locale->text('Customer') . " : $form->{customer}" if $form->{customer};
push @options, $locale->text('Customer Number') . " : $form->{customernumber}" if $form->{customernumber};
# TODO: only customer id is passed
- push @options, $locale->text('Department') . " : " . (split /--/, $form->{department})[0] if $form->{department};
+ push @options, $locale->text('Department') . " : " . SL::DB::Department->new(id => $form->{department_id})->load->description if $form->{department_id};
push @options, $locale->text('Invoice Number') . " : $form->{invnumber}" if $form->{invnumber};
push @options, $locale->text('Invoice Date') . " : $form->{invdate}" if $form->{invdate};
+ push @options, $locale->text('Ship via') . " : $form->{shipvia}" if $form->{shipvia};
push @options, $locale->text('Part Number') . " : $form->{partnumber}" if $form->{partnumber};
- push @options, $locale->text('Group') . " : " . SL::DB::PartsGroup->new(id => $form->{partsgroup_id})->load->partsgroup if $form->{partsgroup_id};
+ push @options, $locale->text('Partsgroup') . " : " . SL::DB::PartsGroup->new(id => $form->{partsgroup_id})->load->partsgroup if $form->{partsgroup_id};
push @options, $locale->text('Country') . " : $form->{country}" if $form->{country};
push @options, $locale->text('Employee') . ' : ' . SL::DB::Employee->new(id => $form->{employee_id})->load->name if $form->{employee_id};
push @options, $locale->text('Salesman') . ' : ' . SL::DB::Employee->new(id => $form->{salesman_id})->load->name if $form->{salesman_id};
# The sellprice total can be calculated from sellprice or fxsellprice (the
# value that was actually entered in the sellprice field and is always
- # stored seperately). However, for fxsellprice this method only works when
+ # stored separately). However, for fxsellprice this method only works when
# the tax is not included, because otherwise fxsellprice includes the tax
# and there is no simple way to extract the tax rate of the article from
- # the big query.
+ # the big query.
#
# Using fxsellprice is potentially more accurate (certainly for tax
# included), because we can use the same method as is used while the
# sellprice_total_including_tax = qty * fxsellprice * (1-discount) / price_factor * exchangerate
# $ar->{sellprice_total_including_tax} = $form->round_amount( $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor}, $form->{"decimalplaces"});
- $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor;
- $ar->{sellprice_total} = $form->round_amount( $ar->{qty} * $ar->{sellprice} / $ar->{price_factor} , $form->{"decimalplaces"});
+ my $sellprice_orig = $ar->{sellprice};
+ my $qty_orig = $ar->{qty};
+ # adjust sellprice so it reflects the unit sellprice according to price_factor and basefactor
+ $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor;
+ # for sellprice_total use the original amounts
+ $ar->{sellprice_total} = $form->round_amount( $qty_orig * $sellprice_orig / $ar->{price_factor}, $form->{"decimalplaces"});
+ my $lastcost_orig = $ar->{lastcost};
$ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor} / $basefactor;
- $ar->{lastcost_total} = $form->round_amount( $ar->{qty} * $ar->{lastcost} / $ar->{price_factor}, $form->{"decimalplaces"});
+ $ar->{lastcost_total} = $form->round_amount( $qty_orig * $lastcost_orig / $ar->{price_factor}, $form->{"decimalplaces"});
# marge_percent is recalculated, because the value in invoice used to be empty
$ar->{marge_percent} = $ar->{sellprice_total} ? (($ar->{sellprice_total}-$ar->{lastcost_total}) / $ar->{sellprice_total} * 100) : 0;
$ar->{marge_total} = $ar->{sellprice_total} ? $ar->{sellprice_total}-$ar->{lastcost_total} : 0;
$ar->{discount} *= 100; # format discount value for output, 10% is stored as 0.1 in db
- # adapt qty to the chosen unit
+ # adjust qty to reflect the qty of the base unit
$ar->{qty} *= $basefactor;
+ # now $ar->{sellprice} * $ar->{qty} should be the same as $qty_orig * $ar->{qty}
+
# weight is the still the weight per part, but here we want the total weight
$ar->{weight} *= $ar->{qty};