When you said mailing them with a cron job, do you mean attaching them
to an email?  There is an e-invoice type for emailed invoices, however
it sends a text invoice right now.  At some point i'd like to add an
option that makes that attach pdf files to invoices too  that would
need to generate each pdf file and mime encode it and attach it to
each emailed e-invoice.  It may take longer for the server to
generate, and may make the invoice mail messages more susceptible to
spam blocking since PDF's are a common malware problem now.

Paul

2010/2/25 Ben Monypenny <benmonype...@googlemail.com>:
> Hi Paul,
>
> I have been working on a way to save the day's new invoices as PDF's to a
> path on the server for mailing with a cron job. My code is:
>
> <?php
>
> $host = 'localhost'; // MYSQL database host adress
> $db = 'dbname'; // MYSQL database name
> $user = 'dbuser'; // Mysql Datbase user
> $pass = $_REQUEST['password']; // Mysql Datbase password
> $rounddate = $_REQUEST['rounddate'];
>
> //parse round date
> $sheetyear = substr($rounddate,4,4);
> $sheetmonth = substr($rounddate,2,2);
> $sheetday = substr($rounddate,0,2);
> $date = $sheetyear."-".$sheetmonth."-".$sheetday;
>
> // Connect to the database
> $link = mysql_connect($host, $user, $pass);
> mysql_select_db($db);
>
> //Get data from citrus
> $query = "SELECT
> billing_details.billing_id,billing_details.invoice_number,customer.account_number
> FROM billing_details,customer WHERE
> billing_details.billing_id=customer.default_billing_id and
> billing_details.creation_date = '$date'";
> $result = mysql_query($query);
>
> //put data in array
> $i = "0";
> $details = array();
> while ($row = mysql_fetch_array($result)) {
> $details[$i][0]=$row[0];
> $details[$i][1]=$row[1];
> $details[$i][2]=$row[2];
> $i++;
> }
>
> //remove duplicates where there is more than one service per invoice
> $j = "0";
> $duplicates=array();
> $dets=$details;
> while ($j < $i+1) {
> if (in_array($details[$j][1],$duplicates)) {
> unset($dets[$j]);
> }
> array_push($duplicates,$details[$j][1]);
> //$details = array_values($details);
> $j++;
> }
>
> //save PDF invoices
> for ($m=0; $m<$i; $m++) {
> $url =
> "http://citrusurl/index.php?load=tools/printpreviousinvoice&billingid=".$dets[$m][0]."&invoiceid=".$dets[$m][1]."&details=on&type=dl&submit=on";;
> $path =
> "/home/user/invoices/".$sheetyear.$sheetmonth.$sheetday.$dets[$m][2].".pdf";
> $in = fopen($url,"rb");
> $out = fopen($path,"wb");
> while($chunk = fread($in,8192)){
> fwrite($out,$chunk,8192);
> }
> fclose($in);
> fclose($out);
>
> //print $dets[$m][0];
> //print $dets[$m][1];
> //print $dets[$m][2];
> }
>
> ?>
>
>
> When the script attempts to retrieve the PDF's it can't because it isn't
> logged into citrus. It is creating files with the citrus login page saved in
> them. Can you help with a workaround?
>
> Many thanks,
>
> Ben Monypenny
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Citrusdb-users mailing list
> Citrusdb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/citrusdb-users
>
>



-- 
The CitrusDB Project | http://www.citrusdb.org
Open Source Customer Care & Billing System

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Citrusdb-users mailing list
Citrusdb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/citrusdb-users

Reply via email to