webERP Forum

Full Version: Automated Printing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this working. Smile


/public_html/webERP/includes/tcpdf/tcpdf.php has a function Output()

public function Output($name='doc.pdf', $dest='I') {




There was already in place a case statement:

case 'F': {
// Save PDF to a local file
if ($this->diskcache) {
copy($this->buffer, $name);
} else {
$f = fopen($name, 'wb');
if (!$f) {
$this->Error('Unable to create output file: '.$name);
}
fwrite($f, $this->getBuffer(), $this->bufferlen);
fclose($f);
}
break;
}




/public_html/webERP/includes/class.pdf.php has two functions:

function OutputI($DocumentFilename = 'Document.pdf') {
function OutputD($DocumentFilename = 'Document.pdf') {

I added a third:

function OutputF($DocumentFilename = 'Document.pdf') {
if (($DocumentFilename == null) or ($DocumentFilename == '')) {
$DocumentFilename = _('Document'.date(DATE_ATOM).'pdf');
}
$this->Output($DocumentFilename,'F');
}
(I should later change the date(DATE_ATOM).
The ":"'s in the filename caused me much lost sleep last night
from using it in the higher level function call.
But that one line of code will only run if you forget to pass a parameter.)




I duplicated /public_html/webERP/PrintCustOrder_generic.php and created
PrintCustOrder_generic_tofile.php
I added my new scripts to the "scripts" table and set the security setting the same.




In PrintCustOrder_generic_tofile.php

I replaced:
$pdf->OutputD($_SESSION['DatabaseName'] . '_PackingSlip_' . date('Y-m-d') . '.pdf');

with

$tempname = date(DATE_ATOM);
$tempname = str_replace(":", "_", $tempname);
$pdf->OutputF('pdf/' . $_SESSION['DatabaseName'] . '_PackingSlip_'. $_GET['TransNo'] . $tempname . '.pdf');
There should also be a check here to see if the file already exists
and to generate a new DATE_ATOM name but for my purposes a
duplicate filename would be extremely unlikely.


In /public_html/webERP/DeliveryDetails.php I added an additional choice:

echo '<tr>
<td><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td>
<td>' . ' ' . '<a target="_blank" href="' . $rootpath . '/PrintCustOrder_generic_tofile.php?identifier='.$identifier . '&TransNo=' . $OrderNo . '">'. _('Print packing slip To Temporary Folder') . ' (' . _('Laser') . ')' .'</a></td>
</tr>';




So a "pdf" folder under the webERP folder collects these created PDF files.


I am using WatchFTP
http://www.watchftp.com/index.html
to download these files to a personal computer running Windows
and deleting them from the server once downloaded.


I am using WatchDirectory
http://www.watchdirectory.net/index.html
to print any files that have not yet been printed,
which have been downloaded to a specific folder


The Vendor of these products,
which are very reasonable in cost,
tells me that I can have WatchFTP run a batch command
to have FoxIt print each file
and he has sent me an example batch file which I will try soon.



So a call to $pdf->OutputF from other scripts in the code base
should allow
accumulating all print jobs in a folder or an assortment of folders.
Naming conventions can be changed depending on if it is a Sales Order or Packing Slip or Invoice or Workorder etc

The flexibility with a third party FTP and naming conventions and printing mechanism
can let you direct certain print job types to a variety of printers at the users locations.

My only problem right now is that my call to PrintCustOrder_generic_tofile.php
leaves a blank window open and I have to close it manually
then I return to DeliveryDetails.php. I expect that this is an easy fix,
but I don't know what command to use and where to put it yet.
Just need to lose the

target="_blank"

out of the link to suppress the new blank page.

I am not sure how we could make this generic as it depends on:

a) 2 lots of external software
b) The same machine always doing the invoice printing

But ... nice one - it works for you.
(08-17-2012, 07:27 AM)phil Wrote: [ -> ]Just need to lose the

target="_blank"

out of the link to suppress the new blank page.

I am not sure how we could make this generic as it depends on:

a) 2 lots of external software
b) The same machine always doing the invoice printing

But ... nice one - it works for you.

I have been thinking that if there were a configuration parameter "Store Generic Picking Tickets For Batch Printing" and "Store Pre Printed Picking Tickets For Batch Printing" and similar prompts for other desired documents then those prompts could appear on the printing screens. Then client side solution providers could do whatever they want to do the automated printing. I expect that Unix guys could do a FTP script to grab a file, print the file, then erase the file. The WatchFTP product, for me, is low cost, and has extra features already built in.
I have now my PDF file being created in my temporary folder at the server, but I have a blank screen then I have to hit a BACK button and the browser complains and tells me to Try Again to refresh the page.

So there must be some way to return to Delivery Details in my '/PrintCustOrder_generic_tofile.php" script after the file is created. I'll start hunting and guessing.

echo '<tr>
<td><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td>

<td>' . ' ' . '<a href="' . $rootpath . '/PrintCustOrder_generic_tofile.php?identifier='.$identifier . '&TransNo=' . $OrderNo . '">'. _('Print packing slip To Temporary Folder') . ' (' . _('Laser') . ')' .'</a>
</td>
</tr>';

Here is the end of PrintCustOrder_generic_tofile.php , what do I need here to return and repaint the Delivery Details script?

$tempname = date(DATE_ATOM);
$tempname = str_replace(":", "_", $tempname);
$pdf->OutputF('pdf/' . $_SESSION['DatabaseName'] . '_PackingSlip_'. $_GET['TransNo'] . $tempname . '.pdf');

$pdf->__destruct();
$sql = "UPDATE salesorders SET printedpackingslip=1,
datepackingslipprinted='" . Date('Y-m-d') . "'
WHERE salesorders.orderno='" . $_GET['TransNo'] . "'";

$result = DB_query($sql,$db);
}
?>
Well there are some parameters to send to create the pdf as a file using OutputD send directly to file...
then you will want to meta refresh to some other page once complete - or you could probably use Location header to redirect to another page.
I just put the target="_blank" back in there. Just tell them to click the X to close the blank window until I have time to learn about Location header and meta refresh.