SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating 1000 invoices on the fly

    Hi all,

    we're in the middle of creating an app for cardealers. They can enter their cars for a specific amount per week. At the end of the month, we would like the system to generate a detailed invoice for every car dealer. So, I would need an invoice per dealer, with every car on it, and its price.

    What would be the best way to develop sth like this? Would it be possible to let the system fetch the data from the db, create pdf's per dealer, and store them somewhere in a folder? That would be optimal.

    We will have about 1000 dealers every month, invoices can be more than 1 page.

    Any ideas or remarks?

    Many thanks,
    M

  2. #2
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have recently created something similar for my office. I work at a university and we generate funding announcements on a regular basis. My approach involved creating an "Announcement" class which included a function generateAnnouncement() that took the data from the database and ran it through a template.

    So my steps were as follows:
    1) Query the database for all new announcements
    2) For each new announcement, create an array of new Announcement objects to hold all its information.
    3) Send each object in the array through the template, and save the file (in my case, I did it as an html).

    I imagine you're quite capable of getting the data from the database, so here is the code I used for the templating:

    PHP Code:
    class Announcement {
        
    //DECLARE VARIABLES
        
    var $spnsr_id//sponsor ID
        
    var $spnsr_name//sponsor name
        
    var $pgm_id//program ID
        
    var $pgm_name//program name
        
    var $pgm_type;
        var 
    $pgm_description//program description
        
    var $pgm_contact//program contact
        
    var $cmp_id//competition ID
        
    var $cmp_guideline_url//competition URL
        
    var $cmp_name//competition name
        
    var $cmp_awrd_range//value of the award
        
    var $cmp_open_dt//is it an open-ended date?
        
    var $cmp_internal_dt//internal deadline
        
    var $cmp_dean_dt//dean's deadline
        
    var $cmp_agency_dt//agency deadline
        
    var $cmp_detail//compeition description
        
    var $cmp_admin_info//application details
        
    var $cmp_int_contact_nm//RDS contact person's name
        
    var $interest_descr = array(); //array of keywords
        
    var $address = array(array()); //2D array of addresses
        
    var $discipline = array(); //array of disciplines (based on sponsor)
        
    var $url//URL to link to back to PeopleSoft
        
        
        
        //CONSTRUCTOR
        
    function Announcement($spnsr_id$spnsr_name$pgm_id$pgm_name$pgm_type$pgm_description$pgm_contact$cmp_id$cmp_guideline_url$cmp_name$cmp_awrd_range$cmp_open_dt$cmp_internal_dt$cmp_dean_dt$cmp_agency_dt$cmp_detail$cmp_admin_info$cmp_int_contact_nm$interest_descr$address$discipline$url) {
            
    $this->spnsr_id $spnsr_id;
            
    $this->spnsr_name $spnsr_name;
            
    $this->pgm_id $pgm_id;
            
    $this->pgm_name $pgm_name;
            
    $this->pgm_type $pgm_type;
            
    $this->pgm_description $pgm_description;
            
    $this->pgm_contact $pgm_contact;
            
    $this->cmp_id $cmp_id;
            
    $this->cmp_guideline_url $cmp_guideline_url;
            
    $this->cmp_name $cmp_name;
            
    $this->cmp_awrd_range $cmp_awrd_range;
            
    $this->cmp_open_dt $cmp_open_dt
            
    $this->cmp_internal_dt $cmp_internal_dt
            
    $this->cmp_dean_dt $cmp_dean_dt
            
    $this->cmp_agency_dt $cmp_agency_dt
            
    $this->cmp_detail $cmp_detail
            
    $this->cmp_admin_info $cmp_admin_info
            
    $this->cmp_int_contact_nm $cmp_int_contact_nm
            
    $this->interest_descr $interest_descr
            
    $this->address $address;
            
    $this->discipline $discipline;
            
    $this->url $url;
        }
        
        
        
        
    //GENERATES THE ANNOUNCEMENT USING THE TEMPLATE
        
    function createAnnouncement($listingType) {
            
    ob_start(); //turn on output buffering
            
    require("templates/tmpAnnouncement.php"); //parse the file
            
    $output ob_get_contents(); //save its contents
            
    ob_end_clean(); //clear the buffer and turn off buffering
            
            //make the directory if its not available
            
    if (!is_dir("generatedAnnouncements")) {
                
    mkdir("generatedAnnouncements") or die("Cannot make directory");
            }
            if (!
    is_dir("generatedAnnouncements/".date("Y"))) {
                
    mkdir("generatedAnnouncements/".date("Y")) or die("Cannot make directory");
            }
            if (!
    is_dir("generatedAnnouncements/".date("Y")."/".date("M"))) {
                
    mkdir("generatedAnnouncements/".date("Y")."/".date("M")) or die("Cannot make directory"); 
            }
            if (!
    is_dir("generatedAnnouncements/".date("Y")."/".date("M")."/".$listingType)) {
                
    mkdir("generatedAnnouncements/".date("Y")."/".date("M")."/".$listingType) or die("Cannot make directory"); 
            }
            
            
    //put the file in the right spot
            
    $outputFile fopen("generatedAnnouncements/".date("Y")."/".date("M")."/".$listingType."/".$this->spnsr_id."-".$this->pgm_id."-".$this->cmp_id.".html""w"); //open the file
            
    fwrite($outputFile$output); //write the file
            
    fclose($outputFile); //close the file
                            
        

    and then my template this this calls looks like this:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>RDS Announcement</title>
    </head>
    <body>
    <center>
    <table width="650" border="2">
    <tr><td>
    <table width="650">
      <tr>
        <td width="160">
        <img src="../../../../images/logo.gif" alt="Research Western" />
        </td>
        <td align="left">
        <center><b>Funding Opportunites - Research</b><br />
        Further details regarding this announcement can be found at:<br />
        <a href="<?php echo (trim($this->cmp_guideline_url) != "" $this->cmp_guideline_url "N/A"); ?>" target="_blank"><?php echo (trim($this->cmp_guideline_url) != "" $this->cmp_guideline_url "N/A"); ?></a></center>
        </td>
      </tr>
      <tr>
        <td>
        <b>Agency/Award:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->spnsr_name) != "" $this->spnsr_name." - " "N/A"); ?> <?php echo (trim($this->pgm_name) != "" $this->pgm_name." - " "N/A"); ?> <?php echo (trim($this->cmp_name) != "" $this->cmp_name "N/A"); ?>    </td>
      </tr>
      <tr>
        <td>
        <b>Website: </b>
        </td>
        <td align="left">
        <a href="<?php echo (trim($this->cmp_guideline_url) != "" $this->cmp_guideline_url "N/A"); ?>" target="_blank"><?php echo $this->cmp_guideline_url?></a>    </td>
      </tr>
      <tr>
          <td colspan="2">
        <hr />
        </td>
      </tr>
      <tr>
        <td>
        <b>Grant Amount:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->cmp_award_range) != "" $this->cmp_award_range "N/A"); ?>    </td>
      </tr>
      <tr>
        <td>
        <b>Deadline:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->cmp_open_dt) == "Yes" "Deadline is Open<br />" ""); ?>
        <?php echo (trim($this->cmp_internal_dt) != "" "Internal: ".$this->cmp_internal_dt."<br />" ""); ?>
        <?php echo (trim($this->cmp_dean_dt) != "" "Dean's: ".$this->cmp_dean_dt."<br />" ""); ?>
        <?php echo (trim($this->cmp_agency_dt) != "" "Agency: ".$this->cmp_agency_dt."<br />" ""); ?>
        </td>
      </tr>
      <tr>
          <td colspan="2">
        <hr />
        </td>
      </tr>
      <tr>
        <td>
        <b>Subject Areas:</b>
        </td>
        <td align="left">
        <?php 
        
    for ($x 0$x count($this->interest_descr); $x++) {
            echo (
    trim($this->interest_descr[$x]) != "" $this->interest_descr[$x]." <br />" "");
        }
         
    ?>    </td>
      </tr>
      <tr>
        <td>
        <b>Description:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->pgm_description) != "" $this->pgm_description "N/A"); ?><br />
        <?php echo (trim($this->cmp_detail) != "" $this->cmp_detail "N/A"); ?>
        </td>
      </tr>
      <tr>
          <td colspan="2">
        <hr />
        </td>
      </tr>
      <tr>
        <td>
        <b>Application Details:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->cmp_admin_info) != "" $this->cmp_admin_info "N/A"); ?>    </td>
      </tr>
      <tr>
        <td colspan="2" align="left">
        <b>NOTE:</b> Letters of Intent and Full Applications are to be processed through Research Development Services for institutional signatures, and are to be accompanied by a completed RDAF form (bearing applicant, Chair and Dean signatures).  Requests for Institutional signatures should be received no less than 3 days prior to the posted Agency deadline.    </td>
      </tr>
      <tr>
        <td>
        <b>Western Contacts:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->cmp_int_contact_nm) != "" $this->cmp_int_contact_nm "N/A"); ?>    </td>
      </tr>
      <tr>
          <td colspan="2">
        <hr />
        </td>
      </tr>
      <tr>
        <td>
        <b>Agency Contacts:</b>
        </td>
        <td align="left">
        <?php echo (trim($this->pgm_contact) != "" $this->pgm_contact "N/A"); ?><br />
        <?php
            
    //the array of addresses
            
    for ($x 0$x count($this->address); $x++) {
                echo (
    trim($this->address[$this->numAddresses][spnsr_addr_descr]) != "" $this->address[$this->numAddresses][spnsr_addr_descr]." <br />" ""); 
                echo (
    trim($this->address[$this->numAddresses][spnsr_addr1]) != "" $this->address[$this->numAddresses][spnsr_addr1]." <br />" ""); 
                echo (
    trim($this->address[$this->numAddresses][spnsr_addr2]) != "" $this->address[$this->numAddresses][spnsr_addr2]." <br />" ""); 
                echo (
    trim($this->address[$this->numAddresses][spnsr_addr3]) != "" $this->address[$this->numAddresses][spnsr_addr3]." <br />" ""); 
                echo (
    trim($this->address[$this->numAddresses][spnsr_addr4]) != "" $this->address[$this->numAddresses][spnsr_addr4]." <br />" "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_city]) != "" $this->address[$this->numAddresses][spnsr_city].", " "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_state]) != "" $this->address[$this->numAddresses][spnsr_state].", " "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_country_descr]) != "" $this->address[$this->numAddresses][spnsr_country_descr]." <br />" ""); 
                echo (
    trim($this->address[$this->numAddresses][spnsr_postal_cd]) != "" $this->address[$this->numAddresses][spnsr_postal_cd]." <br />" "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_prefix]) != "" "Tel: ".$this->address[$this->numAddresses][spnsr_prefix]."-" "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_phone]) != "" $this->address[$this->numAddresses][spnsr_phone]." " "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_ext]) != "" "ext ".$this->address[$this->numAddresses][spnsr_ext]." <br />" "");
                echo (
    trim($this->address[$this->numAddresses][spnsr_fax]) != "" "Fax: ".$this->address[$this->numAddresses][spnsr_fax]." <br />" "");
            }
        
    ?>
        </td>
      </tr>
    </table>
    </td></tr>
    </table>
    </center>
    </body>
    </html>
    Hope this helps.
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeanco,

    that is similar indeed. Do you get any problems with the number of files? I guess we'll have about 1000 every time we run the extraction. We will remove them from the server and hold them locally.

    Thanks for the reply :-)

    M

  4. #4
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you get timout errors look at adjusting the max_execution_time in php.ini

    You can also do this using ini_set() http://ca.php.net/ini_set

    Take a look at the php.net site for a bit, they have some functions you can use to reset the timeout counter each time the function is called. This means that you'd be able to keep the timeout reasonable, but have it reset each time. See this link: http://ca.php.net/set_time_limit
    Ryan Price
    Subscribe to my blog for regular tips and tricks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •