Jump to content

Recommended Posts

Hello all,

 

I have this little billing and invoice application that I made a while back. It does a nice job of creating invoices and sending them out when I want them to go out. Now I am trying to add Billing Tickets to the functionality. A billing ticket would be created for each billable record within a billing period if the client requires a billing ticket as well as an invoice.

 

I have the code to create the billing tickets and when they are created they are given a filename with this syntax:

$filename = 'billing_tickets/'.$name.'-billing_ticket_'.date('m-d-Y_H-i-s').'.txt';

 

Now where I am having trouble is in gathering up all the billing tickets I need. Here is the code I started with:

//gather up the billing tickets and attach them to the email
$btdate = 'billing_tickets/*_'.date('m-d-Y_H-i-s').'.txt';
$btattachments = glob($btdate); 
foreach (glob("$btdate") as $filename){
echo '<input type="hidden" id="btatt'.$bt.'" name="btatt'.$bt.'" value="'.$filename.'"> '. "\n";
$bt++;
}

 

This will only grab a billing ticket if it was created in the same second that I requested it. How do I code $btdate to be a between a range of dates??

 

Thanks for any help or ideas,

 

Link to comment
https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/
Share on other sites

I had an idea,

 

what if I appended a letter to the end of the filename - and then when I called my function to collect all the billing tickets I would search for all the files with that letter appened - once I grabbed all those from the directory then I would rename the files and take away the letter so they would never be included in the search again. That way I'm not searching by a data range but gathering all the similar files?

 

the directory would look like this:

clientA-billing_ticket_8-23-2009_12-23-22.txt

clientB-billing_ticket_8-31-2009_10-03-12.txt

clientA-billing_ticket_9-7-2009_09-43-09-a.txt

clientB-billing_ticket_9-7-2009_14-33-16-a.txt

 

and the glob function like this:

//gather up the billing tickets and attach them to the email
$btdate = 'billing_tickets/*-a.txt';
$btattachments = glob($btdate); 
foreach (glob("$btdate") as $filename){
echo '<input type="hidden" id="btatt'.$bt.'" name="btatt'.$bt.'" value="'.$filename.'"> '. "\n";
$bt++;
}

 

but I am not sure how I would then rename the files and strip them of the "-a"

 

Any help??

this is just a wild stab but couldn't the following:

$btdate = 'billing_tickets/*_9-*-*-*-*-*.txt';

 

that could get all the files made in the month of september. Using this logic you could grab bills from a year, or a certain day, or even a certain hour. This is somewhat limited however in that you can't get a range between any two dates.

 

Just a stab in the dark, as I haven't used the glob function much

thanks mikesta707,

 

the problem is that within each month I will have to query my files 3 times. The first time is usually between the 1st and the 10th or 11th the second time is the next 14 days and the third time is the remainder of the month. So your method would not allow for these changes. But thanks for the suggestion. To bad my billing is not once a month  :)

Yeah I figured you had a situation like that. Perhaps you should think of a different naming scheme all together? I know that isn't the easiest way to solve the problem, but it may make adding different functionality in the future much easier also

that would work for a while, I suppose, but you will eventually run out of letters. Assuming every letter is for a certain range (IE may 1st through may 11th) you will eventually run out of letters to use.

 

I would suggest using the month, and whatever 3rd of the month it is. Forexample, if a bill falls under may 4th, then it would be in the first 3rd, so the end may look like

ClientA-May-1

 

something for may 15th may look like

ClientC-May-2

 

etc.

actually the appended letter is for a billing ticket not yet sent. Then when I send the billing ticket i would remove the letter so that I only need to use one letter.  Everything in my dir that has the letter needs to be billed - every file without the letter has already been billed.

 

Does that make sense?

Well, I'm note sure if I know how to accomplish what I want.

 

Will this work:

//gather up the billing tickets and attach them to the email
$btdate = 'billing_tickets/*-a.txt';
$btattachments = glob($btdate); 
foreach (glob("$btdate") as $filename){

echo '<input type="hidden" id="btatt'.$bt.'" name="btatt'.$bt.'" value="'.$filename.'"> '. "\n";
rename($filename,substr_replace($filename, " ",-6).".txt");
$bt++;
}

 

??

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.