samoht Posted September 8, 2009 Share Posted September 8, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/ Share on other sites More sharing options...
samoht Posted September 8, 2009 Author Share Posted September 8, 2009 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?? Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-914996 Share on other sites More sharing options...
mikesta707 Posted September 8, 2009 Share Posted September 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915001 Share on other sites More sharing options...
samoht Posted September 8, 2009 Author Share Posted September 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915011 Share on other sites More sharing options...
mikesta707 Posted September 8, 2009 Share Posted September 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915013 Share on other sites More sharing options...
samoht Posted September 8, 2009 Author Share Posted September 8, 2009 hmm, yes. what did you think about my idea in the second post? Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915022 Share on other sites More sharing options...
mikesta707 Posted September 8, 2009 Share Posted September 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915034 Share on other sites More sharing options...
samoht Posted September 8, 2009 Author Share Posted September 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915041 Share on other sites More sharing options...
mikesta707 Posted September 8, 2009 Share Posted September 8, 2009 ahhh I see, well then in that case, sure that would work. try that and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915045 Share on other sites More sharing options...
samoht Posted September 8, 2009 Author Share Posted September 8, 2009 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++; } ?? Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915059 Share on other sites More sharing options...
mikesta707 Posted September 8, 2009 Share Posted September 8, 2009 well in that script $bt never seems to be set. but beyond that it looks fine to me. make sure you set $bt to zero before the foreach, and test it. Quote Link to comment https://forums.phpfreaks.com/topic/173560-collect-files-within-a-range/#findComment-915064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.