Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6755633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:25:35+00:00 2026-05-26T13:25:35+00:00

We have a script that generate invoice once a month (cron). But we would

  • 0

We have a script that generate invoice once a month (cron). But we would like to add feature, that we would be able to select date range “from – to” and then generate invoice only for the date selected.

I guess making input fields with calendar pop-up isn’t hard, but filtering with PHP is a bit bigger challenge, so if anyone want to take a look at my code and give me some tips, I would be grateful.

    function    genInvoice($clientID, $orderID=0, $paid=false)
{
    if($orderID == 0)
        $sql = "select tblorders.* from tblorders,tblusers where invoiceid=0 and tblorders.userid=tblusers.id " .
            "and status='closed' and tblusers.clientid=" . $clientID;
    else
        $sql = "select tblorders.* from tblorders,tblusers where invoiceid=0 and tblorders.userid=tblusers.id " .
            "and tblusers.clientid=" . $clientID . " and tblorders.id=" . $orderID;
    $res = full_query($sql) or die(mysql_error());
    // If no closed orders uninvoiced, just return
    if(!mysql_num_rows($res))
        return 0;

    $amount = 0;
    $orders = array();
    while($row = mysql_fetch_array($res, MYSQL_ASSOC))
    {
//      print_r($row);
//      print "<br><hr>";
        $amount += $row['amount'];
        $orders[] = $row['id'];
    }
    $date = date("Y-m-d");
    $status = $paid ?'Paid' : 'Unpaid';
    $sql = "insert into tblinvoices (clientid, date, duedate, subtotal, total, status) values (" . $clientID . ",'" . $date .
        "','" . $date . "'," . $amount  . "," . $amount . ",'" .  $status . "')";
    $res = full_query($sql) or die(mysql_error());
    $invoiceid = mysql_insert_id();
    $sql = "update tblorders set invoiceid=" . $invoiceid . " where id in (" . implode(",", $orders) . ")";
    $res = full_query($sql) or die(mysql_error());
    $sql = "select tblorders.id as ReportID, FirstName, LastName, SearchName, CountyID, StateID, bl_orderitems.userid, bl_orderitems.amount, " .
        "bl_orderitems.notes from tblorders, bl_orderitems left join bl_search on bl_search.id=packageid where tblorders.id in (" .
        implode(",", $orders) . ") and bl_orderitems.orderid=tblorders.id order by tblorders.id,bl_orderitems.id";
    $res = full_query($sql) or die(mysql_error());
    while($row = mysql_fetch_array($res, MYSQL_ASSOC))
    {
        if($row['CountyID'] != 0)
            $locale = getCounty($row['CountyID']);
        else if($row['StateID'] != 0)
            $locale = getState($row['StateID']);
        if($row['SearchName'] != "")
            $description = mysql_real_escape_string($row['FirstName'] . " " . $row['LastName'] . " " .
                $row['SearchName'] . " " . $locale . " (Order #" . $row['ReportID'] . ")");
        else
            $description = "Search Package: " . mysql_real_escape_string($row['notes'] . " (Order #" . $row['ReportID'] . ")");
        $sql = "insert into tblinvoiceitems (invoiceid, userid, type, description, amount, duedate) values " .
            "(" . $invoiceid . "," . $row['userid'] . ",'search','" . $description . "','" .
            $row['amount'] . "','" . $date . "')";
//       print $sql . "<br>";
        full_query($sql) or die(mysql_error());
    }
    sendmessage ('Invoice Created', $invoiceid);
    return $invoiceid;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:25:36+00:00Added an answer on May 26, 2026 at 1:25 pm

    not going to look through all that code, but filtering results by a date range is easy.

    SELECT id FROM some_table WHERE some_date_field BETWEEN $first_date AND $second_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to generate a dynamic image from a script, and then have
I would like to write a program or script that would generate .vcproj and
I have a Ruby script that defines a class. I would like the script
I have a datalist being generated with ASP, but unfortunately the jQuery script that
I have a PHP script that will generate a report using PHPExcel from data
I have a PHP script that will generate <input> s dynamically, so I was
I have a test script, that generate txt file with answers. And have 2
I have a php script that sends out emails with attachments once people have
I have a script in app/vendors/shells which is executed periodically via cron. In that
I have a script that generate me some command that I must execute... Example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.