@@ -711,7 +934,7 @@ sub e_mail {
- |.$locale->text('To').qq|
+ |.$locale->text('E-mail').qq|
|.$locale->text('Cc').qq|
@@ -740,15 +963,15 @@ sub e_mail {
|;
+ $form->{oldmedia} = $form->{media};
+ $form->{media} = "email";
+ $form->{format} = "pdf";
+
&print_options;
- map { delete $form->{$_} } qw(action email cc bcc subject message type sendmode format);
+ map { delete $form->{$_} } qw(action email cc bcc subject message formname sendmode format header);
- # save all other variables
- foreach $key (keys %$form) {
- $form->{$key} =~ s/"/"/g;
- print qq| \n|;
- }
+ $form->hide_form();
print qq|
@@ -774,8 +997,10 @@ sub e_mail {
sub send_email {
$old_form = new Form;
+
map { $old_form->{$_} = $form->{$_} } keys %$form;
- $old_form->{media} = $form->{oldmedia};
+ $old_form->{media} = $old_form->{oldmedia};
+
&print_form($old_form);
}
@@ -785,232 +1010,482 @@ sub send_email {
sub print_options {
$form->{sendmode} = "attachment";
- $form->{copies} = 3 unless $form->{copies};
+ $form->{copies} = 1 unless $form->{copies};
- $form->{PD}{$form->{type}} = "checked";
- $form->{DF}{$form->{format}} = "checked";
- $form->{OP}{$form->{media}} = "checked";
- $form->{SM}{$form->{sendmode}} = "checked";
+ $form->{PD}{$form->{formname}} = "selected";
+ $form->{DF}{$form->{format}} = "selected";
+ $form->{SM}{$form->{sendmode}} = "selected";
- if ($form->{type} =~ /_order/) {
- $order = qq|
- {PD}{"$`_order"}>|.$locale->text('Order').qq|
-|;
- } else {
- $invoice = qq|
- {PD}{invoice}>|.$locale->text('Invoice').qq|
- {PD}{packing_list}>|.$locale->text('Packing List').qq|
-|;
+ if ($form->{selectlanguage}) {
+ $form->{"selectlanguage"} = $form->unescape($form->{"selectlanguage"});
+ $form->{"selectlanguage"} =~ s/ selected//;
+ $form->{"selectlanguage"} =~ s/($form->{selectlanguage}
+ {oldlanguage_code}>
+ |;
}
-
+
+ if ($form->{type} eq 'purchase_order') {
+ $type = qq|
+ {PD}{purchase_order}>|.$locale->text('Purchase Order').qq|
+ {PD}{bin_list}>|.$locale->text('Bin List').qq| |;
+ }
+
+ if ($form->{type} eq 'sales_order') {
+ $type = qq|
+ {PD}{sales_order}>|.$locale->text('Sales Order').qq|
+ {PD}{work_order}>|.$locale->text('Work Order').qq|
+ {PD}{pick_list}>|.$locale->text('Pick List').qq|
+ {PD}{packing_list}>|.$locale->text('Packing List').qq| |;
+ }
+
+ if ($form->{type} =~ /_quotation$/) {
+ $type = qq|
+ {PD}{"$`_quotation"}>|.$locale->text('Quotation').qq| |;
+ }
+
+ if ($form->{type} eq 'invoice') {
+ $type = qq|
+ {PD}{invoice}>|.$locale->text('Invoice').qq|
+ {PD}{pick_list}>|.$locale->text('Pick List').qq|
+ {PD}{packing_list}>|.$locale->text('Packing List').qq| |;
+ }
+
+ if ($form->{type} eq 'ship_order') {
+ $type = qq|
+ {PD}{pick_list}>|.$locale->text('Pick List').qq|
+ {PD}{packing_list}>|.$locale->text('Packing List').qq| |;
+ }
+
+ if ($form->{type} eq 'receive_order') {
+ $type = qq|
+ {PD}{bin_list}>|.$locale->text('Bin List').qq| |;
+ }
+
if ($form->{media} eq 'email') {
- $email = qq|
- {SM}{attachment}> |.$locale->text('Attachment')
- .qq| {SM}{inline}> |.$locale->text('In-line').qq|
-|;
+ $media = qq|
+ {SM}{attachment}>|.$locale->text('Attachment').qq|
+ {SM}{inline}>|.$locale->text('In-line').qq| |;
} else {
- $screen = qq|
- {OP}{screen}>
- |.$locale->text('Screen').qq|
-|;
+ $media = qq|
+ |.$locale->text('Screen');
+ if (%printer && $latex) {
+ map { $media .= qq|
+ $_| } sort keys %printer;
+ }
+ if ($latex) {
+ $media .= qq|
+ |.$locale->text('Queue');
+ }
+ $media .= qq| |;
+
+ # set option selected
+ $media =~ s/(
-
- $invoice
- $order
- {DF}{html}>
- html
-|;
+ $format = qq|
+ {DF}{html}>html|;
+
+# {DF}{txt}>txt|;
if ($latex) {
- print qq|
- {DF}{postscript}>
- |.$locale->text('Postscript').qq|
- {DF}{pdf}>
- |.$locale->text('PDF').qq|
-|;
+ $format .= qq|
+ {DF}{postscript}>|.$locale->text('Postscript').qq|
+ {DF}{pdf}>|.$locale->text('PDF');
}
+ $format .= qq| |;
print qq|
- $screen
+
|;
+
}
+
sub print {
-
+
# if this goes to the printer pass through
- if ($form->{media} eq 'printer') {
- $form->error($locale->text('Select postscript or PDF!')) if ($form->{format} !~ /(postscript|pdf)/);
+ if ($form->{media} !~ /(screen|email)/) {
+ $form->error($locale->text('Select txt, postscript or PDF!')) if ($form->{format} !~ /(txt|postscript|pdf)/);
$old_form = new Form;
map { $old_form->{$_} = $form->{$_} } keys %$form;
+
}
-
+
&print_form($old_form);
}
sub print_form {
- my $old_form = shift;
-
+ my ($old_form) = @_;
+
$inv = "inv";
$due = "due";
- if ($form->{type} eq "invoice") {
+ $numberfld = "sinumber";
+
+ $display_form = ($form->{display_form}) ? $form->{display_form} : "display_form";
+
+ if ($form->{formname} eq "invoice") {
$form->{label} = $locale->text('Invoice');
}
- if ($form->{type} eq "packing_list") {
- $form->{label} = $locale->text('Packing List');
- }
- if ($form->{type} eq 'sales_order') {
+ if ($form->{formname} eq 'sales_order') {
$inv = "ord";
$due = "req";
$form->{label} = $locale->text('Sales Order');
+ $numberfld = "sonumber";
+ $order = 1;
}
- if ($form->{type} eq 'purchase_order') {
+ if ($form->{formname} eq 'work_order') {
+ $inv = "ord";
+ $due = "req";
+ $form->{label} = $locale->text('Work Order');
+ $numberfld = "sonumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'packing_list') {
+ # we use the same packing list as from an invoice
+ $form->{label} = $locale->text('Packing List');
+
+ if ($form->{type} ne 'invoice') {
+ $inv = "ord";
+ $due = "req";
+ $numberfld = "sonumber";
+ $order = 1;
+ }
+ }
+ if ($form->{formname} eq 'pick_list') {
+ $form->{label} = $locale->text('Pick List');
+ if ($form->{type} ne 'invoice') {
+ $inv = "ord";
+ $due = "req";
+ $order = 1;
+ $numberfld = "sonumber";
+ }
+ }
+ if ($form->{formname} eq 'purchase_order') {
$inv = "ord";
$due = "req";
$form->{label} = $locale->text('Purchase Order');
+ $numberfld = "ponumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'bin_list') {
+ $inv = "ord";
+ $due = "req";
+ $form->{label} = $locale->text('Bin List');
+ $numberfld = "ponumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'sales_quotation') {
+ $inv = "quo";
+ $due = "req";
+ $form->{label} = $locale->text('Quotation');
+ $numberfld = "sqnumber";
+ $order = 1;
+ }
+ if ($form->{formname} eq 'request_quotation') {
+ $inv = "quo";
+ $due = "req";
+ $form->{label} = $locale->text('Quotation');
+ $numberfld = "rfqnumber";
+ $order = 1;
}
+
+ $form->{"${inv}date"} = $form->{transdate};
$form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email');
- $form->isblank("${inv}number", $locale->text($form->{label} .' Number missing!'));
$form->isblank("${inv}date", $locale->text($form->{label} .' Date missing!'));
+ # get next number
+ if (! $form->{"${inv}number"}) {
+ $form->{"${inv}number"} = $form->update_defaults(\%myconfig, $numberfld);
+ if ($form->{media} eq 'screen') {
+ &update;
+ exit;
+ }
+ }
+
+
# $locale->text('Invoice Number missing!')
# $locale->text('Invoice Date missing!')
# $locale->text('Packing List Number missing!')
# $locale->text('Packing List Date missing!')
# $locale->text('Order Number missing!')
# $locale->text('Order Date missing!')
+# $locale->text('Quotation Number missing!')
+# $locale->text('Quotation Date missing!')
&validate_items;
&{ "$form->{vc}_details" };
@a = ();
- map { push @a, ("partnumber_$_", "description_$_") } (1 .. $form->{rowcount});
+ foreach $i (1 .. $form->{rowcount}) {
+ push @a, ("partnumber_$i", "description_$i", "projectnumber_$i", "partsgroup_$i", "serialnumber_$i", "bin_$i", "unit_$i");
+ }
map { push @a, "${_}_description" } split / /, $form->{taxaccounts};
- $form->format_string(@a);
+ $ARAP = ($form->{vc} eq 'customer') ? "AR" : "AP";
+ push @a, $ARAP;
+
# format payment dates
- map { $form->{"datepaid_$_"} = $locale->date(\%myconfig, $form->{"datepaid_$_"}) } (1 .. $form->{paidaccounts});
+ for $i (1 .. $form->{paidaccounts} - 1) {
+ if (exists $form->{longformat}) {
+ $form->{"datepaid_$i"} = $locale->date(\%myconfig, $form->{"datepaid_$i"}, $form->{longformat});
+ }
+
+ push @a, "${ARAP}_paid_$i", "source_$i", "memo_$i";
+ }
+
+ $form->format_string(@a);
- # create the form variables for the invoice, packing list or order
- if ($form->{type} =~ /order$/) {
+ ($form->{employee}) = split /--/, $form->{employee};
+ ($form->{warehouse}, $form->{warehouse_id}) = split /--/, $form->{warehouse};
+
+ # this is a label for the subtotals
+ $form->{groupsubtotaldescription} = $locale->text('Subtotal') if not exists $form->{groupsubtotaldescription};
+ delete $form->{groupsubtotaldescription} if $form->{deletegroupsubtotal};
+
+ # create the form variables
+ if ($order) {
OE->order_details(\%myconfig, \%$form);
} else {
IS->invoice_details(\%myconfig, \%$form);
}
- $form->{"${inv}date"} = $locale->date(\%myconfig, $form->{"${inv}date"}, 1);
- $form->{"${due}date"} = $locale->date(\%myconfig, $form->{"${due}date"}, 1);
-
+ if (exists $form->{longformat}) {
+ map { $form->{$_} = $locale->date(\%myconfig, $form->{$_}, $form->{longformat}) } ("${inv}date", "${due}date", "shippingdate", "transdate");
+ }
- @a = qw(name addr1 addr2 addr3 addr4);
+ @a = qw(name address1 address2 city state zipcode country);
- $fillshipto = 1;
+ $shipto = 1;
# if there is no shipto fill it in from billto
foreach $item (@a) {
if ($form->{"shipto$item"}) {
- $fillshipto = 0;
+ $shipto = 0;
last;
}
}
- if ($fillshipto) {
- if ($form->{type} eq 'purchase_order') {
+ if ($shipto) {
+ if ($form->{formname} eq 'purchase_order' || $form->{formname} eq 'request_quotation') {
$form->{shiptoname} = $myconfig{company};
- $form->{shiptoaddr1} = $myconfig{address};
+ $form->{shiptoaddress1} = $myconfig{address};
} else {
- map { $form->{"shipto$_"} = $form->{$_} } @a;
+ if ($form->{formname} !~ /bin_list/) {
+ map { $form->{"shipto$_"} = $form->{$_} } @a;
+ }
}
}
$form->{notes} =~ s/^\s+//g;
# some of the stuff could have umlauts so we translate them
- push @a, qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shippingpoint company address signature notes);
+ push @a, qw(contact shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptoemail shippingpoint shipvia notes employee warehouse);
- push @a, ("${inv}date", "${due}date");
+ push @a, ("${inv}number", "${inv}date", "${due}date", "email", "cc", "bcc");
+ map { $form->{$_} = $myconfig{$_} } (qw(company address tel fax signature businessnumber));
+ map { $form->{"user$_"} = $myconfig{$_} } qw(name email);
+ push @a, qw(company address tel fax signature businessnumber username useremail);
+
$form->format_string(@a);
$form->{templates} = "$myconfig{templates}";
- $form->{IN} = "$form->{type}.html";
+ $form->{IN} = "$form->{formname}.$form->{format}";
- if ($form->{format} eq 'postscript') {
- $form->{postscript} = 1;
- $form->{IN} =~ s/html$/tex/;
- }
- if ($form->{format} eq 'pdf') {
- $form->{pdf} = 1;
- $form->{IN} =~ s/html$/tex/;
+ if ($form->{format} =~ /(postscript|pdf)/) {
+ $form->{IN} =~ s/$&$/tex/;
}
- $form->format_string(email, shiptoemail, cc, bcc) if $form->{format} =~ /(pdf|postscript)/;
-
- if ($form->{media} eq 'printer') {
- $form->{OUT} = "| $myconfig{printer}";
+ $form->{pre} = "\n" if $form->{format} eq 'txt';
+
+ if ($form->{media} !~ /(screen|queue|email)/) {
+ $form->{OUT} = "| $printer{$form->{media}}";
+
+ if ($form->{printed} !~ /$form->{formname}/) {
+
+ $form->{printed} .= " $form->{formname}";
+ $form->{printed} =~ s/^ //;
+
+ $form->update_status(\%myconfig);
+ }
+
+ $old_form->{printed} = $form->{printed};
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'printed',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+
}
+
if ($form->{media} eq 'email') {
$form->{subject} = qq|$form->{label} $form->{"${inv}number"}| unless $form->{subject};
-
+
+ $form->{plainpaper} = 1;
$form->{OUT} = "$sendmail";
+
+ if ($form->{emailed} !~ /$form->{formname}/) {
+ $form->{emailed} .= " $form->{formname}";
+ $form->{emailed} =~ s/^ //;
+
+ # save status
+ $form->update_status(\%myconfig);
+ }
+
+ $now = scalar localtime;
+ $cc = $locale->text('Cc').qq|: $form->{cc}\n| if $form->{cc};
+ $bcc = $locale->text('Bcc').qq|: $form->{bcc}\n| if $form->{bcc};
+
+ $old_form->{intnotes} = qq|$old_form->{intnotes}\n\n| if $old_form->{intnotes};
+ $old_form->{intnotes} .= qq|[email]
+|.$locale->text('Date').qq|: $now
+|.$locale->text('To').qq|: $form->{email}
+$cc${bcc}|.$locale->text('Subject').qq|: $form->{subject}\n|;
+
+ $old_form->{intnotes} .= qq|\n|.$locale->text('Message').qq|: |;
+ $old_form->{intnotes} .= ($form->{message}) ? $form->{message} : $locale->text('sent');
+
+ $old_form->{message} = $form->{message};
+ $old_form->{emailed} = $form->{emailed};
+
+ $old_form->{format} = "postscript" if $myconfig{printer};
+ $old_form->{media} = $myconfig{printer};
+
+ $old_form->save_intnotes(\%myconfig, ($order) ? 'oe' : lc $ARAP);
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'emailed',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+ }
+
+
+ if ($form->{media} eq 'queue') {
+ %queued = split / /, $form->{queued};
+
+ if ($filename = $queued{$form->{formname}}) {
+ $form->{queued} =~ s/$form->{formname} $filename//;
+ unlink "$spool/$filename";
+ $filename =~ s/\..*$//g;
+ } else {
+ $filename = time;
+ $filename .= $$;
+ }
+
+ $filename .= ($form->{format} eq 'postscript') ? '.ps' : '.pdf';
+ $form->{OUT} = ">$spool/$filename";
+
+ $form->{queued} .= " $form->{formname} $filename";
+ $form->{queued} =~ s/^ //;
+
+ # save status
+ $form->update_status(\%myconfig);
+
+ $old_form->{queued} = $form->{queued};
+
+ %audittrail = ( tablename => ($order) ? 'oe' : lc $ARAP,
+ reference => $form->{"${inv}number"},
+ formname => $form->{formname},
+ action => 'queued',
+ id => $form->{id} );
+
+ $old_form->{audittrail} .= $form->audittrail("", \%myconfig, \%audittrail);
+
}
-
- $form->parse_template(\%myconfig, $userspath);
- $form->{callback} = "";
+ $form->{fileid} = $form->{"${inv}number"};
+ $form->{fileid} =~ s/(\s|\W)+//g;
+ $form->parse_template(\%myconfig, $userspath);
+
# if we got back here restore the previous form
- if ($form->{media} =~ /(printer|email)/) {
- if ($old_form) {
- # restore and display form
- map { $form->{$_} = $old_form->{$_} } keys %$old_form;
- $form->{rowcount}--;
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
-
- for $i (1 .. $form->{paidaccounts}) {
- map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
- }
-
- &display_form;
- exit;
+ if ($old_form) {
+
+ $old_form->{"${inv}number"} = $form->{"${inv}number"};
+
+ # restore and display form
+ map { $form->{$_} = $old_form->{$_} } keys %$old_form;
+ delete $form->{pre};
+
+ $form->{rowcount}--;
+
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
+
+ for $i (1 .. $form->{paidaccounts}) {
+ map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
}
- $msg = ($form->{media} eq 'printer') ? $locale->text('sent to printer') : $locale->text('emailed to')." $form->{email}";
- $form->redirect(qq|$form->{label} $form->{"${inv}number"} $msg|);
+ &{ "$display_form" };
+
}
}
@@ -1033,6 +1508,8 @@ sub vendor_details {
sub post_as_new {
$form->{postasnew} = 1;
+ map { delete $form->{$_} } qw(printed emailed queued);
+
&post;
}
@@ -1042,14 +1519,18 @@ sub ship_to {
$title = $form->{title};
$form->{title} = $locale->text('Ship to');
-
- $form->{rowcount}--;
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
# get details for name
&{ "$form->{vc}_details" };
+ $number = ($form->{vc} eq 'customer') ? $locale->text('Customer Number') : $locale->text('Vendor Number');
+
+ $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
+
+ $form->{rowcount}--;
+
$form->header;
print qq|
@@ -1062,53 +1543,63 @@ sub ship_to {
+
+
|;
# delete shipto
- map { delete $form->{$_} } qw(shiptoname shiptoaddr1 shiptoaddr2 shiptoaddr3 shiptoaddr4 shiptocontact shiptophone shiptofax shiptoemail);
+ map { delete $form->{$_} } qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail header);
$form->{title} = $title;
- foreach $key (keys %$form) {
- $form->{$key} =~ s/"/"/g;
- print qq| \n|;
- }
+ $form->hide_form();
print qq|
-
-