#===================================================================== # LedgerSMB Small Medium Business Accounting # http://www.ledgersmb.org/ # # Copyright (C) 2006 # This work contains copyrighted information from a number of sources all used # with permission. # # This file contains source code included with or based on SQL-Ledger which # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed # under the GNU General Public License version 2 or, at your option, any later # version. For a full list including contact information of contributors, # maintainers, and copyright holders, see the CONTRIBUTORS file. # # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork): # Copyright (c) 2001 # # Author: DWS Systems Inc. # Web: http://www.sql-ledger.org # # Contributors: Reed White # # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 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. #====================================================================== # # customer/vendor module # #====================================================================== use LedgerSMB::CT; use LedgerSMB::Template; 1; # end of main sub add { $form->{title} = "Add"; # $locale->text('Add Customer') # $locale->text('Add Vendor') $form->{callback} = "$form->{script}?action=add&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; CT->create_links( \%myconfig, \%$form ); &form_header; &form_footer; } sub history { # $locale->text('Customer History') # $locale->text('Vendor History') my %hiddens; my @buttons; $history = 1; $label = ucfirst $form->{db}; $label .= " History"; if ( $form->{db} eq 'customer' ) { $form->{invlabel} = $locale->text('Sales Invoices'); $form->{ordlabel} = $locale->text('Sales Orders'); $form->{quolabel} = $locale->text('Quotations'); } else { $form->{invlabel} = $locale->text('Vendor Invoices'); $form->{ordlabel} = $locale->text('Purchase Orders'); $form->{quolabel} = $locale->text('Request for Quotations'); } $form->{title} = $locale->text($label); $form->{nextsub} = "list_history"; &search_name(\%hiddens, \@buttons); ##SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'ct-search', ); $template->render({ form => $form, user => \%myconfig, hiddens => \%hiddens, buttons => \@buttons, }); } sub transactions { if ( $form->{db} eq 'customer' ) { $form->{translabel} = $locale->text('AR Transactions'); $form->{invlabel} = $locale->text('Sales Invoices'); $form->{ordlabel} = $locale->text('Sales Orders'); $form->{quolabel} = $locale->text('Quotations'); } else { $form->{translabel} = $locale->text('AP Transactions'); $form->{invlabel} = $locale->text('Vendor Invoices'); $form->{ordlabel} = $locale->text('Purchase Orders'); $form->{quolabel} = $locale->text('Request for Quotations'); } } sub include_in_report { $label = ucfirst $form->{db}; my @fields = (); push @fields, { name => 'l_ndx', label => $locale->text('No.'), }; push @fields, { name => 'l_id', label => $locale->text('ID'), }; push @fields, { name => "l_$form->{db}number", label => $locale->text($label . ' Number'), }; push @fields, { name => 'l_name', label => $locale->text('Company Name'), $form->{l_name} => $form->{l_name}, }; push @fields, { name => 'l_contact', label => $locale->text('Contact'), $form->{l_contact} => $form->{l_contact}, }; push @fields, { name => 'l_email', label => $locale->text('E-mail'), $form->{l_email} => $form->{l_email}, }; push @fields, { name => 'l_address', label => $locale->text('Address'), }; push @fields, { name => 'l_city', label => $locale->text('City'), }; push @fields, { name => 'l_state', label => $locale->text('State/Province'), }; push @fields, { name => 'l_zipcode', label => $locale->text('Zip/Postal Code'), }; push @fields, { name => 'l_country', label => $locale->text('Country'), }; push @fields, { name => 'l_phone', label => $locale->text('Phone'), $form->{l_phone} => $form->{l_phone}, }; push @fields, { name => 'l_fax', label => $locale->text('Fax'), }; push @fields, { name => 'l_cc', label => $locale->text('Cc'), }; if ( $myconfig{role} =~ /(admin|manager)/ ) { push @fields, { name => 'l_bcc', label => $locale->text('Bcc'), }; } push @fields, { name => 'l_notes', label => $locale->text('Notes'), }; push @fields, { name => 'l_discount', label => $locale->text('Discount'), }; push @fields, { name => 'l_taxaccount', label => $locale->text('Tax Account'), }; push @fields, { name => 'l_taxnumber', label => $locale->text('Tax Number'), }; if ( $form->{db} eq 'customer' ) { push @fields, { name => 'l_employee', label => $locale->text('Salesperson'), }; push @fields, { name => 'l_manager', label => $locale->text('Manager'), }; push @fields, { name => 'l_pricegroup', label => $locale->text('Pricegroup'), }; } else { push @fields, { name => 'l_employee', label => $locale->text('Employee'), }; push @fields, { name => 'l_manager', label => $locale->text('Manager'), }; push @fields, { name => 'l_gifi_accno', label => $locale->text('GIFI'), }; } push @fields, { name => 'l_sic_code', label => $locale->text('SIC'), }; push @fields, { name => 'l_iban', label => $locale->text('IBAN'), }; push @fields, { name => 'l_bic', label => $locale->text('BIC'), }; push @fields, { name => 'l_business', label => $locale->text('Type of Business'), }; push @fields, { name => 'l_terms', label => $locale->text('Terms'), }; push @fields, { name => 'l_langauge', label => $locale->text('Language'), }; push @fields, { name => 'l_startdate', label => $locale->text('Startdate'), }; push @fields, { name => 'l_enddate', label => $locale->text('Enddate'), }; $form->{includes} = []; my $i = 0; while (@fields) { push @{$form->{includes}}, []; for ( 1 .. 5 ) { push @{$form->{includes}[$i]}, shift(@fields); if ($form->{includes}[$i][$_ - 1]) { $form->{includes}[$i][$_ - 1]{type} = 'checkbox'; $form->{includes}[$i][$_ - 1]{value} = 'Y'; } } $i++; } } sub search { # $locale->text('Customers') # $locale->text('Vendors') my %hiddens; my @buttons; $form->{title} = $locale->text('Search') unless $form->{title}; for (qw(name contact phone email)) { $form->{"l_$_"} = 'checked' } $form->{nextsub} = "list_names"; &transactions; &include_in_report; &search_name(\%hiddens, \@buttons); ##SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'ct-search', ); $template->render({ form => $form, user => \%myconfig, hiddens => \%hiddens, buttons => \@buttons, }); } sub search_name { my $hiddens = shift; my $buttons = shift; my $label = ucfirst $form->{db}; $form->{label} = $label; $hiddens->{$_} = $form->{$_} foreach qw(db nextsub path login sessionid); push @{$buttons}, { name => 'action', value => 'continue', text => $locale->text('Continue'), }; } sub list_names { my %hiddens; my @buttons; my @options; CT->search( \%myconfig, \%$form ); my $href = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}"; $form->sort_order(); my $callback = "$form->{script}?action=list_names&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&l_subtotal=$form->{l_subtotal}"; my @columns = $form->sort_columns( id, name, "$form->{db}number", address, city, state, zipcode, country, contact, phone, fax, email, cc, bcc, employee, manager, notes, discount, terms, taxaccount, taxnumber, gifi_accno, sic_code, business, pricegroup, language, iban, bic, startdate, enddate, invnumber, invamount, invtax, invtotal, ordnumber, ordamount, ordtax, ordtotal, quonumber, quoamount, quotax, quototal ); unshift @columns, "ndx"; $form->{l_invnumber} = "Y" if $form->{l_transnumber}; foreach my $item (qw(inv ord quo)) { if ( $form->{"l_${item}number"} ) { for (qw(amount tax total)) { $form->{"l_$item$_"} = $form->{"l_$_"}; } $removeemployee = 1; $openclosed = 1; } } $form->{open} = $form->{closed} = "" if !$openclosed; my @column_index; foreach my $item (@columns) { if ( $form->{"l_$item"} eq "Y" ) { push @column_index, $item; # add column to href and callback $callback .= "&l_$item=Y"; $href .= "&l_$item=Y"; } } foreach my $item (qw(amount tax total transnumber)) { if ( $form->{"l_$item"} eq "Y" ) { $callback .= "&l_$item=Y"; $href .= "&l_$item=Y"; } } if ( $form->{status} eq 'all' ) { push @options, $locale->text('All'); } elsif ( $form->{status} eq 'orphaned' ) { push @options, $locale->text('Orphaned'); } elsif ( $form->{status} eq 'active' ) { push @options, $locale->text('Active'); } elsif ( $form->{status} eq 'inactive' ) { push @options, $locale->text('Inactive'); } if ( $form->{name} ) { $callback .= "&name=" . $form->escape( $form->{name}, 1 ); $href .= "&name=" . $form->escape( $form->{name} ); push @options, $locale->text('Name: [_1]', $form->{name}); } if ( $form->{address} ) { $callback .= "&address=" . $form->escape( $form->{address}, 1 ); $href .= "&address=" . $form->escape( $form->{address} ); push @options, $locale->text('Address: [_1]', $form->{address}); } if ( $form->{city} ) { $callback .= "&city=" . $form->escape( $form->{city}, 1 ); $href .= "&city=" . $form->escape( $form->{city} ); push @options, $locale->text('City: [_1]', $form->{city}); } if ( $form->{state} ) { $callback .= "&state=" . $form->escape( $form->{state}, 1 ); $href .= "&state=" . $form->escape( $form->{state} ); push @options, $locale->text('State: [_1]', $form->{state}); } if ( $form->{zipcode} ) { $callback .= "&zipcode=" . $form->escape( $form->{zipcode}, 1 ); $href .= "&zipcode=" . $form->escape( $form->{zipcode} ); push @options, $locale->text('Zip/Postal Code: [_1]', $form->{zipcode}); } if ( $form->{country} ) { $callback .= "&country=" . $form->escape( $form->{country}, 1 ); $href .= "&country=" . $form->escape( $form->{country} ); push @options, $locale->text('Country: [_1]', $form->{country}); } if ( $form->{contact} ) { $callback .= "&contact=" . $form->escape( $form->{contact}, 1 ); $href .= "&contact=" . $form->escape( $form->{contact} ); push @options, $locale->text('Contact: [_1]', $form->{contact}); } if ( $form->{employee} ) { $callback .= "&employee=" . $form->escape( $form->{employee}, 1 ); $href .= "&employee=" . $form->escape( $form->{employee} ); if ( $form->{db} eq 'customer' ) { push @options, $locale->text('Salesperson: [_1]', $form->{employee}); } elsif ( $form->{db} eq 'vendor' ) { push @options, $locale->text('Employee: [_1]', $form->{employee}); } } my $fromdate = ""; my $todate = ""; if ( $form->{startdatefrom} ) { $callback .= "&startdatefrom=$form->{startdatefrom}"; $href .= "&startdatefrom=$form->{startdatefrom}"; $fromdate = $locale->date( \%myconfig, $form->{startdatefrom}, 1 ); } if ( $form->{startdateto} ) { $callback .= "&startdateto=$form->{startdateto}"; $href .= "&startdateto=$form->{startdateto}"; $todate = $locale->date( \%myconfig, $form->{startdateto}, 1 ); } if ( $fromdate || $todate ) { push @options, $locale->text('Startdate [_1] - [_2]', $fromdate, $todate); } if ( $form->{notes} ) { $callback .= "¬es=" . $form->escape( $form->{notes}, 1 ); $href .= "¬es=" . $form->escape( $form->{notes} ); push @options, $locale->text('Notes: [_1]', $form->{notes}); } if ( $form->{"$form->{db}number"} ) { $callback .= qq|&$form->{db}number=| . $form->escape( $form->{"$form->{db}number"}, 1 ); $href .= "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} ); push @options, $locale->text('Number: [_1]', $form->{"$form->{db}number"}); } if ( $form->{phone} ) { $callback .= "&phone=" . $form->escape( $form->{phone}, 1 ); $href .= "&phone=" . $form->escape( $form->{phone} ); push @options, $locale->text('Phone: [_1]', $form->{phone}); } if ( $form->{email} ) { $callback .= "&email=" . $form->escape( $form->{email}, 1 ); $href .= "&email=" . $form->escape( $form->{email} ); push @options, $locale->text('E-mail: [_1]', $form->{email}); } if ( $form->{transdatefrom} ) { $callback .= "&transdatefrom=$form->{transdatefrom}"; $href .= "&transdatefrom=$form->{transdatefrom}"; push @options, $locale->text('From [_1]', $locale->date( \%myconfig, $form->{transdatefrom}, 1 )); } if ( $form->{transdateto} ) { $callback .= "&transdateto=$form->{transdateto}"; $href .= "&transdateto=$form->{transdateto}"; if ( $form->{transdatefrom} ) { pop @options; push @options, $locale->text('From [_1] To [_2]', $locale->date( \%myconfig, $form->{transdatefrom}, 1 ), $locale->date( \%myconfig, $form->{transdateto}, 1 )); } else { push @options, $locale->text('To [_1]', $locale->date( \%myconfig, $form->{transdateto}, 1 )); } } if ( $form->{open} ) { $callback .= "&open=$form->{open}"; $href .= "&open=$form->{open}"; push @options, $locale->text('Open'); } if ( $form->{closed} ) { $callback .= "&closed=$form->{closed}"; $href .= "&closed=$form->{closed}"; push @options, $locale->text('Closed'); } $form->{callback} = "$callback&sort=$form->{sort}"; $callback = $form->escape( $form->{callback} ); my %column_header; $column_header{ndx} = ' '; $column_header{id} = $locale->text('ID'); $column_header{"$form->{db}number"} = { href => "$href&sort=$form->{db}number", text => $locale->text('Number') }; $column_header{name} = { href => "$href&sort=name", text => $locale->text('Name') }; $column_header{address} = $locale->text('Address'); $column_header{city} = { href => "$href&sort=city", text => $locale->text('City') }; $column_header{state} = { href => "$href&sort=state", text => $locale->text('State/Province') }; $column_header{zipcode} = { href => "$href&sort=zipcode", text => $locale->text('Zip/Postal Code') }; $column_header{country} = { href => "$href&sort=country", text => $locale->text('Country') }; $column_header{contact} = { href => "$href&sort=contact", text => $locale->text('Contact'), }; $column_header{phone} = { href => "$href&sort=phone", text => $locale->text('Phone') }; $column_header{fax} = { href => "$href&sort=fax", text => $locale->text('Fax') }; $column_header{email} = { href => "$href&sort=email", text => $locale->text('E-mail') }; $column_header{cc} = { href => "$href&sort=cc", text => $locale->text('Cc') }; $column_header{bcc} = { href => "$href&sort=cc", text => $locale->text('Bcc') }; $column_header{notes} = { href => "$href&sort=notes", text => $locale->text('Notes') }; $column_header{discount} = '%'; $column_header{terms} = $locale->text('Terms'); $column_header{taxnumber} = { href => "$href&sort=taxnumber", text => $locale->text('Tax Number') }; $column_header{taxaccount} = $locale->text('Tax Account'); $column_header{gifi_accno} = { href => "$href&sort=gifi_accno", text => $locale->text('GIFI') }; $column_header{sic_code} = { href => "$href&sort=sic_code", text => $locale->text('SIC') }; $column_header{business} = { href => "$href&sort=business", text => $locale->text('Type of Business') }; $column_header{iban} = $locale->text('IBAN'); $column_header{bic} = $locale->text('BIC'); $column_header{startdate} = { href => "$href&sort=startdate", text => $locale->text('Startdate') }; $column_header{enddate} = { href => "$href&sort=enddate", text => $locale->text('Enddate') }; $column_header{invnumber} = { href => "$href&sort=invnumber", text => $locale->text('Invoice') }; $column_header{ordnumber} = { href => "$href&sort=ordnumber", text => $locale->text('Order') }; $column_header{quonumber} = { href => "$href&sort=quonumber", text => $locale->text('Quotation') }; if ( $form->{db} eq 'customer' ) { $column_header{employee} = { href => "$href&sort=employee", text => $locale->text('Salesperson') }; } else { $column_header{employee} = { href => "$href&sort=employee", text => $locale->text('Employee') }; } $column_header{manager} = { href => "$href&sort=manager", text => $locale->text('Manager') }; $column_header{pricegroup} = { href => "$href&sort=pricegroup", text => $locale->text('Pricegroup') }; $column_header{language} = { href => "$href&sort=language", text => $locale->text('Language') }; $amount = $locale->text('Amount'); $tax = $locale->text('Tax'); $total = $locale->text('Total'); $column_header{invamount} = $amount; $column_header{ordamount} = $amount; $column_header{quoamount} = $amount; $column_header{invtax} = $tax; $column_header{ordtax} = $tax; $column_header{quotax} = $tax; $column_header{invtotal} = $total; $column_header{ordtotal} = $total; $column_header{quototal} = $total; if ( $form->{status} ) { $label = ucfirst $form->{db} . "s"; $form->{title} = $locale->text($label); } else { $label = ucfirst $form->{db}; $form->{title} = $locale->text( $label . " Transactions" ); } my $ordertype = ( $form->{db} eq 'customer' ) ? 'sales_order' : 'purchase_order'; my $quotationtype = ( $form->{db} eq 'customer' ) ? 'sales_quotation' : 'request_quotation'; $subtotal = 0; my $i = 0; my @rows; foreach my $ref ( @{ $form->{CT} } ) { if ( $ref->{ $form->{sort} } ne $sameitem && $form->{l_subtotal} ) { # append subtotal if ($subtotal) { push @rows, &list_subtotal; } } my %column_data; if ( $ref->{id} eq $sameid ) { for (@column_index) { $column_data{$_} = ' ' } } else { $i++; $ref->{notes} =~ s/\r?\n/
/g; for (@column_index) { $column_data{$_} = $ref->{$_}; } $column_data{ndx} = $i; if ( $ref->{ $form->{sort} } eq $sameitem ) { $column_data{ $form->{sort} } = ' '; } $column_data{address} = "$ref->{address1} $ref->{address2}"; $column_data{name} = { text => $ref->{name}, href => "$form->{script}?action=edit&id=$ref->{id}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}&callback=$callback", }; $email = ""; if ( $form->{sort} =~ /(email|cc)/ ) { if ( $ref->{ $form->{sort} } ne $sameitem ) { $email = 1; } } else { $email = 1; } if ($email) { foreach $item (qw(email cc bcc)) { if ( $ref->{$item} ) { $email = $ref->{$item}; $column_data{$item} = { href => "mailto:$ref->{$item}", text => $email, }; } } } } if ( $ref->{formtype} eq 'invoice' ) { $column_data{invnumber} = { href => "$ref->{module}.pl?action=edit&id=$ref->{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback", text => $ref->{invnumber}, }; $column_data{invamount} = $form->format_amount( \%myconfig, $ref->{netamount}, 2, ' ' ); $column_data{invtax} = $form->format_amount( \%myconfig, $ref->{amount} - $ref->{netamount}, 2, ' ' ); $column_data{invtotal} = $form->format_amount( \%myconfig, $ref->{amount}, 2, ' ' ); $invamountsubtotal += $ref->{netamount}; $invtaxsubtotal += ( $ref->{amount} - $ref->{netamount} ); $invtotalsubtotal += $ref->{amount}; $subtotal = 1; } elsif ( $ref->{formtype} eq 'order' ) { $column_data{ordnumber} = { href => "$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback", text => $ref->{ordnumber}, }; $column_data{ordamount} = $form->format_amount( \%myconfig, $ref->{netamount}, 2, ' ' ); $column_data{ordtax} = $form->format_amount( \%myconfig, $ref->{amount} - $ref->{netamount}, 2, ' ' ); $column_data{ordtotal} = $form->format_amount( \%myconfig, $ref->{amount}, 2, ' ' ); $ordamountsubtotal += $ref->{netamount}; $ordtaxsubtotal += ( $ref->{amount} - $ref->{netamount} ); $ordtotalsubtotal += $ref->{amount}; $subtotal = 1; } elsif ( $ref->{formtype} eq 'quotation' ) { $column_data{quonumber} = { href => "$ref->{module}.pl?action=edit&id=$ref->{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback", text => $ref->{quonumber}, }; $column_data{quoamount} = $form->format_amount( \%myconfig, $ref->{netamount}, 2, ' ' ); $column_data{quotax} = $form->format_amount( \%myconfig, $ref->{amount} - $ref->{netamount}, 2, ' ' ); $column_data{quototal} = $form->format_amount( \%myconfig, $ref->{amount}, 2, ' ' ); $quoamountsubtotal += $ref->{netamount}; $quotaxsubtotal += ( $ref->{amount} - $ref->{netamount} ); $quototalsubtotal += $ref->{amount}; $subtotal = 1; } if ( $sameid ne "$ref->{id}" ) { if ( $form->{l_discount} ) { $column_data{discount} = $form->format_amount( \%myconfig, $ref->{discount} * 100, "", ' ' ); } if ( $form->{l_terms} ) { $column_data{terms} = $form->format_amount( \%myconfig, $ref->{terms}, "", ' ' ); } } $j++; $j %= 2; $column_data{i} = $j; $sameitem = $ref->{$form->{sort}}; $sameid = $ref->{id}; push @rows, \%column_data; } if ( $form->{l_subtotal} && $subtotal ) { push @rows, &list_subtotal; } $i = 1; if ( $myconfig{acs} !~ /AR--AR/ ) { if ( $form->{db} eq 'customer' ) { $button{'AR--Customers--Add Customer'}{code} = { name => 'action', value => 'add_customer', text => $locale->text('Add Customer'), }; $button{'AR--Customers--Add Customer'}{order} = $i++; } } if ( $myconfig{acs} !~ /AP--AP/ ) { if ( $form->{db} eq 'vendor' ) { $button{'AP--Vendors--Add Vendor'}{code} = { name => 'action', value => 'add_vendor', text => $locale->text('Add Vendor'), }; $button{'AP--Vendors--Add Vendor'}{order} = $i++; } } foreach $item ( split /;/, $myconfig{acs} ) { delete $button{$item}; } $hiddens{$_} = $form->{$_} foreach qw(callback db path login sessionid); if ( $form->{status} ) { foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) { push @buttons, $item->{code}; } } ##SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'form-dynatable', ); $template->render({ form => $form, user => \%myconfig, hiddens => \%hiddens, buttons => \@buttons, options => \@options, rows => \@rows, columns => \@column_index, heading => \%column_header, }); } sub list_subtotal { my %column_data; $column_data{invamount} = $form->format_amount( \%myconfig, $invamountsubtotal, 2, ' ' ); $column_data{invtax} = $form->format_amount( \%myconfig, $invtaxsubtotal, 2, ' ' ); $column_data{invtotal} = $form->format_amount( \%myconfig, $invtotalsubtotal, 2, ' ' ); $invamountsubtotal = 0; $invtaxsubtotal = 0; $invtotalsubtotal = 0; $column_data{ordamount} = $form->format_amount( \%myconfig, $ordamountsubtotal, 2, ' ' ); $column_data{ordtax} = $form->format_amount( \%myconfig, $ordtaxsubtotal, 2, ' ' ); $column_data{ordtotal} = $form->format_amount( \%myconfig, $ordtotalsubtotal, 2, ' ' ); $ordamountsubtotal = 0; $ordtaxsubtotal = 0; $ordtotalsubtotal = 0; $column_data{quoamount} = $form->format_amount( \%myconfig, $quoamountsubtotal, 2, ' ' ); $column_data{quotax} = $form->format_amount( \%myconfig, $quotaxsubtotal, 2, ' ' ); $column_data{quototal} = $form->format_amount( \%myconfig, $quototalsubtotal, 2, ' ' ); $quoamountsubtotal = 0; $quotaxsubtotal = 0; $quototalsubtotal = 0; $column_data{class} = 'subtotal'; \%column_data; } sub list_history { CT->get_history( \%myconfig, \%$form ); $href = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}"; $form->sort_order(); $callback = "$form->{script}?action=list_history&direction=$form->{direction}&oldsort=$form->{oldsort}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$form->{type}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&history=$form->{history}"; $form->{l_fxsellprice} = $form->{l_curr}; @columns = $form->sort_columns( partnumber, description, qty, unit, sellprice, fxsellprice, curr, discount, deliverydate, projectnumber, serialnumber ); if ( $form->{history} eq 'summary' ) { @columns = $form->sort_columns( partnumber, description, qty, unit, sellprice, curr ); } foreach $item (@columns) { if ( $form->{"l_$item"} eq "Y" ) { push @column_index, $item; # add column to href and callback $callback .= "&l_$item=Y"; $href .= "&l_$item=Y"; } } if ( $form->{history} eq 'detail' ) { $option = $locale->text('Detail'); } if ( $form->{history} eq 'summary' ) { $option .= $locale->text('Summary'); } if ( $form->{name} ) { $callback .= "&name=" . $form->escape( $form->{name}, 1 ); $href .= "&name=" . $form->escape( $form->{name} ); $option .= "\n
" . $locale->text('Name') . " : $form->{name}"; } if ( $form->{contact} ) { $callback .= "&contact=" . $form->escape( $form->{contact}, 1 ); $href .= "&contact=" . $form->escape( $form->{contact} ); $option .= "\n
" . $locale->text('Contact') . " : $form->{contact}"; } if ( $form->{"$form->{db}number"} ) { $callback .= qq|&$form->{db}number=| . $form->escape( $form->{"$form->{db}number"}, 1 ); $href .= "&$form->{db}number=" . $form->escape( $form->{"$form->{db}number"} ); $option .= "\n
" . $locale->text('Number') . qq| : $form->{"$form->{db}number"}|; } if ( $form->{email} ) { $callback .= "&email=" . $form->escape( $form->{email}, 1 ); $href .= "&email=" . $form->escape( $form->{email} ); $option .= "\n
" . $locale->text('E-mail') . " : $form->{email}"; } if ( $form->{transdatefrom} ) { $callback .= "&transdatefrom=$form->{transdatefrom}"; $href .= "&transdatefrom=$form->{transdatefrom}"; $option .= "\n
" if ($option); $option .= $locale->text('From') . " " . $locale->date( \%myconfig, $form->{transdatefrom}, 1 ); } if ( $form->{transdateto} ) { $callback .= "&transdateto=$form->{transdateto}"; $href .= "&transdateto=$form->{transdateto}"; if ( $form->{transdatefrom} ) { $option .= " "; } else { $option .= "\n
" if ($option); } $option .= $locale->text('To') . " " . $locale->date( \%myconfig, $form->{transdateto}, 1 ); } if ( $form->{open} ) { $callback .= "&open=$form->{open}"; $href .= "&open=$form->{open}"; $option .= "\n
" if ($option); $option .= $locale->text('Open'); } if ( $form->{closed} ) { $callback .= "&closed=$form->{closed}"; $href .= "&closed=$form->{closed}"; $option .= "\n
" if ($option); $option .= $locale->text('Closed'); } $form->{callback} = "$callback&sort=$form->{sort}"; $callback = $form->escape( $form->{callback} ); $column_header{partnumber} = qq|| . $locale->text('Part Number') . qq||; $column_header{description} = qq|| . $locale->text('Description') . qq||; if ( $form->{history} eq 'summary' ) { $column_header{sellprice} = qq|| . $locale->text('Total') . qq||; } else { $column_header{sellprice} = qq|| . $locale->text('Sell Price') . qq||; } $column_header{fxsellprice} = qq| |; $column_header{curr} = qq|| . $locale->text('Curr') . qq||; $column_header{discount} = qq|| . $locale->text('Discount') . qq||; $column_header{qty} = qq|| . $locale->text('Qty') . qq||; $column_header{unit} = qq|| . $locale->text('Unit') . qq||; $column_header{deliverydate} = qq|| . $locale->text('Delivery Date') . qq||; $column_header{projectnumber} = qq|| . $locale->text('Project Number') . qq||; $column_header{serialnumber} = qq|| . $locale->text('Serial Number') . qq||; # $locale->text('Customer History') # $locale->text('Vendor History') $label = ucfirst $form->{db}; $form->{title} = $locale->text( $label . " History" ); $colspan = $#column_index + 1; $form->header; print qq|
$form->{title}
$option
|; for (@column_index) { print "$column_header{$_}\n" } print qq| |; $module = 'oe'; if ( $form->{db} eq 'customer' ) { $invlabel = $locale->text('Sales Invoice'); $ordlabel = $locale->text('Sales Order'); $quolabel = $locale->text('Quotation'); $ordertype = 'sales_order'; $quotationtype = 'sales_quotation'; if ( $form->{type} eq 'invoice' ) { $module = 'is'; } } else { $invlabel = $locale->text('Vendor Invoice'); $ordlabel = $locale->text('Purchase Order'); $quolabel = $locale->text('RFQ'); $ordertype = 'purchase_order'; $quotationtype = 'request_quotation'; if ( $form->{type} eq 'invoice' ) { $module = 'ir'; } } $ml = ( $form->{db} eq 'vendor' ) ? -1 : 1; foreach $ref ( @{ $form->{CT} } ) { if ( $ref->{id} ne $sameid ) { # print the header print qq| |; } if ( $form->{type} ne 'invoice' ) { $ref->{fxsellprice} = $ref->{sellprice}; $ref->{sellprice} *= $ref->{exchangerate}; } if ( $form->{history} eq 'detail' and $ref->{invid} ne $sameinvid ) { # print inv, ord, quo number $i++; $i %= 2; print qq| |; if ( $form->{type} eq 'invoice' ) { print qq||; } if ( $form->{type} eq 'order' ) { print qq||; } if ( $form->{type} eq 'quotation' ) { print qq||; } print qq| |; } for (@column_index) { $column_data{$_} = "" } if ( $form->{l_curr} ) { $column_data{fxsellprice} = qq|"; } $column_data{sellprice} = qq|"; $column_data{qty} = qq|"; $column_data{discount} = qq|"; $column_data{partnumber} = qq||; $i++; $i %= 2; print qq| |; for (@column_index) { print "$column_data{$_}\n" } print qq| |; $sameid = $ref->{id}; $sameinvid = $ref->{invid}; } print qq|
{script}?action=edit&id=$ref->{ctid}&db=$form->{db}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{name} $ref->{address}
{invid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$invlabel $ref->{invnumber} / $ref->{employee}{invid}&type=$ordertype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ordlabel $ref->{ordnumber} / $ref->{employee}{invid}&type=$quotationtype&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$quolabel $ref->{quonumber} / $ref->{employee}
$ref->{$_} | . $form->format_amount( \%myconfig, $ref->{fxsellprice}, 2 ) . "| . $form->format_amount( \%myconfig, $ref->{sellprice}, 2 ) . "| . $form->format_amount( \%myconfig, $ref->{qty} * $ml ) . "| . $form->format_amount( \%myconfig, $ref->{discount} * 100, "", " " ) . "{pid}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}

|; if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print qq| |; } sub edit { # $locale->text('Edit Customer') # $locale->text('Edit Vendor') CT->create_links( \%myconfig, \%$form ); for ( keys %$form ) { $form->{$_} = $form->quote( $form->{$_} ) } $form->{title} = "Edit"; # format discount $form->{discount} *= 100; &form_header; &form_footer; } sub form_header { $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : ""; $form->{creditlimit} = $form->format_amount( \%myconfig, $form->{creditlimit}, 0 ); $form->{discount} = $form->format_amount( \%myconfig, $form->{discount}, "" ); $form->{terms} = $form->format_amount( \%myconfig, $form->{terms}, "" ); if ( $form->{currencies} ) { # currencies $form->{selectcurrency} = { name => 'curr', options => [], default_values => $form->{curr}, }; push @{$form->{selectcurrency}{options}}, { text => $_, value => $_, } foreach split /:/, $form->{currencies}; } $form->{taxable} = []; foreach my $item ( split / /, $form->{taxaccounts} ) { my $temp_tax = { name => "tax_$item", value => 1, type => 'checkbox', label => $form->{tax}{$item}{description} }; $temp_tax->{checked} = 'checked' if $form->{tax}{$item}{taxable}; push @{$form->{taxable}}, $temp_tax; } if (ref $form->{all_business} eq 'ARRAY') { $form->{selectbusiness} = { name => 'business', options => [{text => '', value => ''}], }; push @{$form->{selectbusiness}{options}}, { text => $_->{description}, value => "$_->{description}--$_->{id}", } foreach @{$form->{all_business}}; $form->{selectbusiness}{default_values} = "$form->{business}--$form->{business_id}"; } if (ref $form->{all_pricegroup} eq 'ARRAY' && $form->{db} eq 'customer') { $form->{selectpricegroup} = { name => 'pricegroup', options => [{text => '', value => ''}], }; push @{$form->{selectpricegroup}{options}}, { name => $_->{pricegroup}, value => "$_->{pricegroup}--$_->{id}", } foreach @{$form->{all_pricegroup}}; $form->{selectpricegroup}{default_values} = "$form->{pricegroup}--$form->{pricegroup_id}"; } if ( @{ $form->{all_language} } ) { $form->{selectlanguage} = { name => 'language', options => [{text => '', value => ''}], }; push @{$form->{selectlanguage}{options}}, { text => $_->{description}, value => "$_->{description}--$_->{code}", } foreach @{$form->{all_language}}; $form->{selectlangauge}{default_values} = "$form->{language}--$form->{language_code}"; } $form->{selectemployee} = { name => 'employee', options => [{text => '', value => ''}], default_values => "$form->{employee}--$form->{employee_id}", }; push @{$form->{selectemployee}{options}}, { text => $_->{name}, value => "$_->{name}--$_->{id}", } foreach @{$form->{all_employee}}; if (ref $form->{all_employee} eq 'ARRAY') { if ( $myconfig{role} eq 'user' && $form->{id} ) { $hiddens{employee} = "$form->{employee}--$form->{employee_id}"; } } # $locale->text('Customer Number') # $locale->text('Vendor Number') $label = ucfirst $form->{db}; $form->{label} = $label; $form->{title} = $locale->text("$form->{title} $label"); } sub form_footer { # type=submit $locale->text('Save') # type=submit $locale->text('Save as new') # type=submit $locale->text('AR Transaction') # type=submit $locale->text('Sales Invoice') # type=submit $locale->text('Sales Order') # type=submit $locale->text('Quotation') # type=submit $locale->text('AP Transaction') # type=submit $locale->text('Vendor Invoice') # type=submit $locale->text('Purchase Order') # type=submit $locale->text('RFQ') # type=submit $locale->text('Pricelist') # type=submit $locale->text('Delete') # type=submit $locale->text('POS') my %hiddens; my @buttons; %button = ( 'save' => { ndx => 1, key => 'S', value => $locale->text('Save') }, 'save_as_new' => { ndx => 2, key => 'N', value => $locale->text('Save as new') }, 'ar_transaction' => { ndx => 7, key => 'A', value => $locale->text('AR Transaction') }, 'ap_transaction' => { ndx => 8, key => 'A', value => $locale->text('AP Transaction') }, 'sales_invoice' => { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') }, 'pos' => { ndx => 10, key => 'C', value => $locale->text('POS') }, 'sales_order' => { ndx => 11, key => 'O', value => $locale->text('Sales Order') }, 'quotation' => { ndx => 12, key => 'Q', value => $locale->text('Quotation') }, 'vendor_invoice' => { ndx => 13, key => 'I', value => $locale->text('Vendor Invoice') }, 'purchase_order' => { ndx => 14, key => 'O', value => $locale->text('Purchase Order') }, 'rfq' => { ndx => 15, key => 'Q', value => $locale->text('RFQ') }, 'pricelist' => { ndx => 16, key => 'P', value => $locale->text('Pricelist') }, 'delete' => { ndx => 17, key => 'D', value => $locale->text('Delete') }, ); my %blist = (); if ( $form->{db} eq 'customer' ) { if ( $myconfig{acs} !~ /AR--Customers--Add Customer/ ) { $blist{'save'} = 1; if ( $form->{id} ) { $blist{'save_as_new'} = 1; if ( $form->{status} eq 'orphaned' ) { $blist{'delete'} = 1; } } } if ( $myconfig{acs} !~ /AR--AR/ ) { if ( $myconfig{acs} !~ /AR--Add Transaction/ ) { $blist{'ar_transaction'} = 1; } if ( $myconfig{acs} !~ /AR--Sales Invoice/ ) { $blist{'sales_invoice'} = 1; } } if ( $myconfig{acs} !~ /POS--POS/ ) { if ( $myconfig{acs} !~ /POS--Sale/ ) { $blist{'pos'} = 1; } } if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) { if ( $myconfig{acs} !~ /Order Entry--Sales Order/ ) { $blist{'sales_order'} = 1; } } if ( $myconfig{acs} !~ /Quotations--Quotations/ ) { if ( $myconfig{acs} !~ /Quotations--Quotation/ ) { $blist{'quotation'} = 1; } } } if ( $form->{db} eq 'vendor' ) { if ( $myconfig{acs} !~ /AP--Vendors--Add Vendor/ ) { $blist{'save'} = 1; if ( $form->{id} ) { $blist{'save_as_new'} = 1; if ( $form->{status} eq 'orphaned' ) { $blist{'delete'} = 1; } } } if ( $myconfig{acs} !~ /AP--AP/ ) { if ( $myconfig{acs} !~ /AP--Add Transaction/ ) { $blist{'ap_transaction'} = 1; } if ( $myconfig{acs} !~ /AP--Vendor Invoice/ ) { $blist{'vendor_invoice'} = 1; } } if ( $myconfig{acs} !~ /Order Entry--Order Entry/ ) { if ( $myconfig{acs} !~ /Order Entry--Purchase Order/ ) { $blist{'purchase_order'} = 1; } } if ( $myconfig{acs} !~ /Quotations--Quotations/ ) { if ( $myconfig{acs} !~ /Quotations--RFQ/ ) { $blist{'rfq'} = 1; } } } if ( $myconfig{acs} !~ /Goods & Services--Goods & Services/ ) { $myconfig{acs} =~ s/(Goods & Services--)Add (Service|Assembly).*;/$1--Add Part/g; if ( $myconfig{acs} !~ /Goods & Services--Add Part/ ) { $blist{'pricelist'} = 1; } } $hiddens{$_} = $form->{$_} foreach qw(id taxaccounts path login sessionid callback db); for ( keys %button ) { delete $button{$_} if !$blist{$_} } for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { push @buttons, { name => 'action', value => $_, accesskey => $button{$_}{key}, title => "$button{$name}{value} [Alt-$button{$_}{key}]", text => $button{$_}{value}, }; } ##SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } $form->{dbnumber} = "$form->{db}number"; my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'ct-form', ); $template->render({ form => $form, user => \%myconfig, hiddens => \%hiddens, buttons => \@buttons, options => \@options, }); } sub pricelist { $form->isblank( "name", $locale->text('Name missing!') ); $form->{display_form} ||= "display_pricelist"; CT->pricelist( \%myconfig, \%$form ); foreach $ref ( @{ $form->{"all_partspricelist"} } ) { $i++; for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} } } $form->{rowcount} = $i; # currencies @curr = split /:/, $form->{currencies}; for (@curr) { $form->{selectcurrency} .= "