LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need script to generate vouchers (https://www.linuxquestions.org/questions/programming-9/need-script-to-generate-vouchers-816199/)

suse_nerd 06-24-2010 04:09 PM

Need script to generate vouchers
 
I have a file, two columns, first column has a list of 15000 (yes 15k) unique codes, second column has the afilliate codes of 60 locations repeated to fill out the 15000 rows of unique codes.

I need to produce a nice neat paper voucher which will fit onto A6 (1/4 A4) and is ready to print. Each voucher has the unique code and corresponding location.

So far I am thinking PHP will do the job. This does it somewhat, but doesn't let be split the fields between the ",".


I did this so far in PHP
Code:

<?
$fp = fopen('filein.csv','r') or die("can't open file");
print "<table>\n";
while($csv_line = fgetcsv($fp,1024)) {
   
        print '<tr>';
    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
                print '<td>'.$csv_line[$i].'</td>';
    }
    print "</tr>\n";
}
print '</table>\n';
fclose($fp) or die("can't close file");
?>

How can I make sure my formatting fits to A5?

smoker 06-24-2010 10:43 PM

I would use imagemagick to create each file, so that you can specify the dimensions.

Alternatively, use htmldoc to create a pdf for each voucher, you can specify the page dimensions there too. You will have to experiment to get the correct alignment.

Both those tools can be scripted and sent commands from your script. I once used perl to create individual certificates in pdf format from database fields, running as a cgi script on a web server.

suse_nerd 06-25-2010 05:40 AM

I've now achieved what i want to do. Managed to get the list of afilliates re-organised thanks to some bash scripting. Took a while to get sed to play ball though. I don't think it likes variables that much!

Code:

for (( vet=1; vet<=60; vet++ )) ; do for (( repeat=1; repeat <=250; repeat++ )); do echo $vet; sed $vet'q;d' "populate.csv" >> newvetslist; done; done;
Code:

<?
$fp = fopen('filein.csv','r') or die("can't open file");

//print "<table border =1>\n";
while($csv_line = fgetcsv($fp,1024)) {
        //print '<tr>';
    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
     
                print '<center>Some html<BR></center>';
        print '<center>';
        if ($i=2)
                {print 'Voucher Code: '.$csv_line[0].'';};
                if ($i=1)
                {print ' Affiliate Code: '.$csv_line[1].'';};
                print '';
    }
                    print '</center>';
                        print '<HR>';

        //print "</tr>\n";
}
//print '</table>\n';
fclose($fp) or die("can't close file");
?>

finally did the job.
I hope its helpful to somebody.

suse_nerd 06-25-2010 10:13 AM

Finally got it working, complete with page break every 3 pages

Code:

<STYLE>
    DIV.pageBreak { page-break-before: always; }
</STYLE>

<?
//for (( vet=1; vet<=60; vet++ )) ; do for (( repeat=1; repeat <=250; repeat++ )); do echo $vet; sed $vet'q;d' "populate.csv" >> newvetslist; done; done;
$count = 0;
$fp = fopen('filein.csv','r') or die("can't open file");
while($csv_line = fgetcsv($fp,20)) {
    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
                        print '<BR><BR><HR>';

        print '<center><img src=""><BR><font color="blue" size="5">URL</font></center>';

            print '<center>Why not try  ? <BR></center>';
                print '<center>Text<BR></center>';
                print '<center>Some text<BR></center>';

                print '<center><b><font size="3" color="red">Some stuff</font></b><BR></center>';
                print '<BR>';

                print '<center>Just enter the following details at the checkout: <BR>';
                if ($i=2)
                {print 'Voucher Code <b> '.$csv_line[0].'</b>';};
                if ($i=1)
                {print ' Affiliate Code <b> '.$csv_line[1].'</b>';};
                print '';
                print '</center>';
                print '<BR><HR>';
$count++;                       

            if ($count==3) {print $count; print '<DIV CLASS="pageBreak"/>'; $count = 0; };

    }
                   
                       

//if j=60, then output <DIV CLASS="pageBreak"/>.

}
fclose($fp) or die("can't close file");
?>



All times are GMT -5. The time now is 03:51 PM.