summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-17 22:40:56 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-17 22:40:56 +0000
commitc26026c25ae610cf5332ed3c65eede1675225e73 (patch)
tree98446bb723f780e91b7ecdb570e163d3c4da8397 /scripts
parentaa669cac70369aa86ac87165b455b7afdb618a39 (diff)
Commiting David Mora's payment code
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1871 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'scripts')
-rw-r--r--scripts/payment.pl249
1 files changed, 226 insertions, 23 deletions
diff --git a/scripts/payment.pl b/scripts/payment.pl
index f36b0b91..ae476a9b 100644
--- a/scripts/payment.pl
+++ b/scripts/payment.pl
@@ -1,4 +1,3 @@
-
=pod
=head1 NAME
@@ -66,14 +65,13 @@ TT2 system. (hopefully it will... )
sub payment {
my ($request) = @_;
my $locale = $request->{_locale};
- my $templateData;
my $dbPayment = LedgerSMB::DBObject::Payment->new({'base' => $request});
# Lets get the project data...
my @projectOptions;
my @arrayOptions = $dbPayment->list_open_projects();
push @projectOptions, {}; #A blank field on the select box
for my $ref (0 .. $#arrayOptions) {
- push @projectOptions, { value => $arrayOptions[$ref]->{id},
+ push @projectOptions, { value => $arrayOptions[$ref]->{id}."--".$arrayOptions[$ref]->{projectnumber}."--".$arrayOptions[$ref]->{description},
text => $arrayOptions[$ref]->{projectnumber}."--".$arrayOptions[$ref]->{description}};
}
# Lets get the departments data...
@@ -82,30 +80,32 @@ sub payment {
@arrayOptions = $dbPayment->list_departments($role);
push @departmentOptions, {}; # A blank field on the select box
for my $ref (0 .. $#arrayOptions) {
- push @departmentOptions, { value => $arrayOptions[$ref]->{id},
+ push @departmentOptions, { value => $arrayOptions[$ref]->{id}."--".$arrayOptions[$ref]->{description},
text => $arrayOptions[$ref]->{description}};
}
# Lets get the customer or vendor :)
my @vcOptions;
- $dbPayment->{account_class} = $request->{type} eq 'receipt' ? 2 : 1;
@arrayOptions = $dbPayment->get_open_accounts();
for my $ref (0 .. $#arrayOptions) {
- push @vcOptions, { value => $arrayOptions[$ref]->{id},
- text => $arrayOptions[$ref]->{description}};
+ push @vcOptions, { value => $arrayOptions[$ref]->{id}.'--'.$arrayOptions[$ref]->{name},
+ text => $arrayOptions[$ref]->{name}};
}
# Lets get the open currencies (this uses the $dbPayment->{account_class} property)
my @currOptions;
@arrayOptions = $dbPayment->get_open_currencies();
for my $ref (0 .. $#arrayOptions) {
- push @arrayOptions, { value => $arrayOptions[$ref]->{id},
- text => $arrayOptions[$ref]->{description}};
+ push @currOptions, { value => $arrayOptions[$ref]->{payments_get_open_currencies},
+ text => $arrayOptions[$ref]->{payments_get_open_currencies} };
}
# Lets build filter by period
my $date = LedgerSMB::DBObject::Date->new({base => $request});
$date->build_filter_by_period($locale);
+
# Lets set the data in a hash for the template system. :)
my $select = {
stylesheet => $request->{_user}->{stylesheet},
+ login => { name => 'login',
+ value => $request->{_user}->{login} },
projects => {
name => 'projects',
options => \@projectOptions
@@ -114,8 +114,8 @@ my $select = {
name => 'department',
options => \@departmentOptions
},
- customer => {
- name => 'customer',
+ vendor_customer => {
+ name => 'vendor-customer',
options => \@vcOptions
},
curr => {
@@ -132,27 +132,24 @@ my $select = {
},
interval_radios => $date->{radioOptions},
amountfrom => {
- type => 'text',
name => 'amountfrom',
- size => '10',
- maxlength => '10'
- },
+ },
amountto => {
- type => 'text',
name => 'amountto',
- size => '10',
- maxlength => '10'
},
- sort => {
- type => 'hidden',
- value => 'sort_value'
+ accountclass => {
+ name => 'account_class',
+ value => $dbPayment->{account_class}
+ },
+ type => {
+ name => 'type',
+ value => $request->{type}
},
action => {
name => 'action',
- value => 'continue',
+ value => 'payment2',
text => $locale->text("Continue"),
},
-
};
# Lets call upon the template system
my $template;
@@ -166,4 +163,210 @@ my $template;
$template->render($select);# And finally, Lets print the screen :)
}
+=pod
+
+=item payment2
+
+This method is used for the payment module, it is a consecuence of the payment sub,
+and its used for all the mechanics of an invoices payment module.
+
+=back
+
+=cut
+
+sub payment2 {
+my ($request) = @_;
+my $locale = $request->{_locale};
+my $dbPayment = LedgerSMB::DBObject::Payment->new({'base' => $request});
+
+my @array_options;
+# LETS GET THE CUSTOMER/VENDOR INFORMATION
+ ($dbPayment->{entity_id}, my $vendor_customer_name) = split /--/ , $request->{'vendor-customer'};
+
+my @array_options;
+my $exchangerate;
+
+# LETS BUILD THE PROJECTS INFO
+# I DONT KNOW IF I NEED ALL THIS, BUT AS IT IS AVAILABLE I'LL STORE IT FOR LATER USAGE.
+my ($project_id, $project_number, $project_name) = split /--/ , $request->{projects} ;
+my @project = { name => 'project', text => $project_number.' '.$project_name, value => $project_id };
+# LETS GET THE DEPARTMENT INFO
+my ($department_id, $department_name) = split /--/, $request->{department};
+my @department = { name => 'department', text => $department_name, value => $department_id };
+# LETS GET ALL THE ACCOUNTS
+my @account_options;
+@array_options = $dbPayment->list_accounting();
+for my $ref (0 .. $#array_options) {
+ push @account_options, { value => $array_options[$ref]->{id},
+ text => $array_options[$ref]->{description}};
+}
+# LETS GET THE POSSIBLE SOURCES
+my @sources_options;
+@array_options = $dbPayment->get_sources(\%$locale);
+for my $ref (0 .. $#array_options) {
+ push @sources_options, { value => $array_options[$ref],
+ text => $array_options[$ref]};
+}
+# WE MUST PREPARE THE ENTITY INFORMATION
+ @array_options = $dbPayment->get_vc_info();
+# LETS BUILD THE CURRENCIES INFORMATION
+# FIRST, WE NEED TO KNOW THE DEFAULT CURRENCY
+my $default_currency = $dbPayment->get_default_currency();
+my @currency_options;
+# LETS BUILD THE COLUMN HEADERS WE ALWAYS NEED
+# THE OTHER HEADERS WILL BE BUILT IF THE RIGHT CONDITIONS ARE MET.
+# -----------------------------------------------
+# SOME USERS WONT USE MULTIPLE CURRENCIES, AND WONT LIKE THE FACT CURRENCY BEING
+# ON THE SCREEN ALL THE TIME, SO IF THEY ARE USING THE DEFAULT CURRENCY WE WONT PRINT IT
+my $currency_text = $request->{curr} eq $default_currency ? '' : '('.$request->{curr}.')';
+my $default_currency_text = $currency_text ? '('.$default_currency.')' : '';
+
+my @columnAS = ({text => $locale->text('Invoice')},
+ {text => $locale->text('Date')},
+ {text => $locale->text('Total').$default_currency_text},
+ {text => $locale->text('Paid').$default_currency_text},
+ {text => $locale->text('Amount Due').$default_currency_text},
+ {text => $locale->text('To pay').$default_currency_text}
+ );
+
+my @column_headers = ({text => $locale->text('Invoice')},
+ {text => $locale->text('Date')},
+ {text => $locale->text('Total').$default_currency_text},
+ {text => $locale->text('Paid').$default_currency_text},
+ {text => $locale->text('Amount Due').$default_currency_text},
+ {text => $locale->text('To pay').$default_currency_text}
+ );
+ # WE NEED TO KNOW IF WE ARE USING A CURRENCY THAT NEEDS AN EXCHANGERATE
+ if ($default_currency ne $request->{curr} ) {
+ # FIRST WE PUSH THE OTHER COLUMN HEADERS WE NEED
+ push @column_headers, {text => $locale->text('Exchange Rate')},
+ {text => $locale->text('Amount Due').$currency_text},
+ {text => $locale->text('To pay').$currency_text};
+ # WE SET THEM IN THE RIGHT ORDER FOR THE TABLE INSIDE THE UI
+ @column_headers[5,6,7] = @column_headers[6,7,5];
+ # DOES THE CURRENCY IN USE HAS AN EXCHANGE RATE?, IF SO
+ # WE MUST SET THE VALUE, OTHERWISE THE UI WILL HANDLE IT
+ $exchangerate = $dbPayment->get_exchange_rate($request->{curr}, $dbPayment->{current_date});
+ if ($exchangerate) {
+ @currency_options = {
+ name => 'date_curr',
+ value => "$exchangerate", #THERE IS A STRANGE BEHAVIOUR WITH THIS,
+ text => "$exchangerate" #IF I DONT USE THE DOUBLE QUOTES, IT WILL PRINT THE ADDRESS
+ #THERE MUST BE A REASON FOR THIS, I MUST RETURN TO IT LATER
+ };
+ } else {
+ @currency_options = {
+ name => 'date_curr'};
+ }
+
+ } else {
+ # WE MUST SET EXCHANGERATE TO 1 FOR THE MATHS SINCE WE
+ # ARE USING THE DEFAULT CURRENCY
+ $exchangerate = 1;
+ }
+# WE NEED TO QUERY THE DATABASE TO CHECK FOR OPEN INVOICES
+# IF WE DONT HAVE ANY INVOICES MATCHING THE FILTER PARAMETERS, WE WILL WARN THE USER AND STOP
+# THE PROCCESS.
+my @invoice_data;
+@array_options = $dbPayment->get_open_invoices();
+if (!$array_options[0]->{invoice_id}) {
+ $request->error($locale->text("Nothing to do"));
+}
+for my $ref (0 .. $#array_options) {
+ push @invoice_data, { invoice => { number => $array_options[$ref]->{invnumber},
+ href => 'ar.pl?id='."$array_options[$ref]->{invoice_id}"
+ },
+ invoice_date => "$array_options[$ref]->{invoice_date}",
+ amount => "$array_options[$ref]->{amount}",
+ due => "$array_options[$ref]->{due}",
+ paid => "$array_options[$ref]->{amount}" - "$array_options[$ref]->{due}",
+ exchange_rate => "$exchangerate",
+ due_fx => "$exchangerate"? "$array_options[$ref]->{due}"/"$exchangerate" : 'N/A',
+ topay => "$array_options[$ref]->{due}",
+ topay_fx => { name => "topay_fx_$ref",
+ value => "$exchangerate" ? "$array_options[$ref]->{due}"/"$exchangerate" : 'N/A'
+ }
+
+ };
+}
+# LETS BUILD THE SELECTION FOR THE UI
+my $select = {
+ stylesheet => $request->{_user}->{stylesheet},
+ header => { text => $request->{type} eq 'receipt' ? $locale->text('Receipt') : $locale->text('Payment') },
+ project => @project,
+ department => @department,
+ account => {
+ name => 'account',
+ options => \@account_options},
+ datepaid => {
+ name => 'datepaid',
+ value => $dbPayment->{current_date}
+ },
+ source => {
+ name => 'source',
+ options => \@sources_options
+ },
+ source_text => {
+
+ name => 'source_text',
+ },
+
+ defaultcurrency => {
+ text => $default_currency
+ },
+ curr => {
+ text => $request->{curr}
+ },
+ column_headers => \@column_headers,
+ rows => \@invoice_data,
+
+ vc => { name => $vendor_customer_name,
+ address => [ {text => 'Crra 83 #32 -1'},
+ {text => '442 6464'},
+ {text => 'Medellín'},
+ {text => 'Colombia'}]},
+
+ post => {
+ accesskey => 'O',
+ title => 'POST ALT+O',
+ name => 'action',
+ value => 'post',
+ text => "POST"
+ },
+ post_and_print => {
+ accesskey => 'R',
+ title => 'POST AND PRINT ALT+R',
+ name => 'action',
+ value => 'post_and_print',
+ text => "POST AND PRINT"
+ },
+ format => {
+ name => 'FORMAT',
+ options => [
+ {value => 1, text => "HTML" },
+ {value => 2, text => "PDF" },
+ {value => 3, text => "POSTSCRIPT" }
+ ],
+ },
+ media => {
+ name => 'MEDIA',
+ options => [
+ {value => 1, text => "Screen" },
+ {value => 2, text => "PRINTER" },
+ {value => 3, text => "EMAIL" }
+ ],
+ },
+ date_curr => @currency_options # I HAVE TO PUT THIS LAST, BECAUSE IT CAN BE NULL
+ # THIS IS AN UGLY HACK THAT MUST BE FIXED.
+};
+my $template = LedgerSMB::Template->new(
+ user => $request->{_user},
+ locale => $request->{_locale},
+ path => 'UI',
+ template => 'payment2',
+ format => 'HTML' );
+eval {$template->render($select) };
+if ($@) { $request->error("$@"); }
+}
+
1;