What is the solution to generate invoices every 2 weeks automatically? Cron Jobs?
I have multiple orders in the tbl_order table, I want to generate an invoices for every 2 weeks (for billing).
- tbl_order table
OrderID (PK)
ShopID (FK)
CustomerID (FK)
Status
Total
OrderDate
- invoice table
InvoiceID (PK)
InvoiceDate
InvoiceStatus
- invoice开发者_C百科order
invoiceorderID (PK)
InvoiceID (FK)
OrderID (FK)
The invoice date for Feb would be: 01 - 15 February, 16 - 28 February
and on March: 01 - 15 March, 16 - 31 March
So for example, generate invoice between 01 - 15 March on tbl_order.ShopID = 5
How can that be done if using Cron Jobs / PHP or alternative solution?
To assign cron task, use tutorial like this:
http://www.thefactory.ro/php-cron-tutorial
Next, in PHP handler query database for every order that was in that time range and create report based on your needs.
Assuming you are running on *nix, you should use cron - man crontab
.
If you wanted to run the job on say the 1st and 15th of every month @ midnight you would use:
0 0 1,15 * *
It goes without saying generally but I will say it anyway. Don't forget to save the invoice data in a separate table of your database for historical look up/tax purposes. This way you can store an invoice number and other variables such as paid and any discounts being applied.
精彩评论