You'll need to take the code from printpreivous and edit it a bit and
run it outside of citrusdb with the php command line program.  If use
use SELECT DISTINCT billing_details.invoice_number I don't think
you'll need to do that thing that removes duplicate results either.

Include the  functions at the top, Then In place of where you call the
printpreivousinvoice URL you can put the rest of the code from
printpreviousinvoice.

// holds the config vars for database connection
include('./include/config.inc.php');

// connects the database and gives you a $DB object that is required
for outputinvoice function
include('./include/database.inc.php');

// holds the outputinvoice printing function
include('./include/billing.inc.php');

$invoiceid = $dets[$m][1];
$lang = "./include/local/us-english.inc.php";
$path = 
"/home/user/invoices/".$sheetyear.$sheetmonth.$sheetday.$dets[$m][2].".pdf";

require('./include/fpdf.php');
$pdf = new FPDF();

// write the data from the specified invoice
$pdf = outputinvoice($DB, $invoiceid, $lang, "pdf", $pdf);

// save the invoice to a file, F signifies File in FPDF output function
$pdf->Output($path, "F");


I think something like this will work.

Also the billing_id is not actually necessary to print previous
invoices, it's just left over from some old link code.

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