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 6149973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:32:41+00:00 2026-05-23T19:32:41+00:00

My situation as follow: I’m building up an invoice system, I have almost everything

  • 0

My situation as follow:

I’m building up an invoice system, I have almost everything done, except the invoices recurrence. Here is what I’m trying to do without success.

The condition:

My condition to generate a new recurrence incoice is ->

  1. contract must be active.
  2. reference must be equal to PA.
  3. generate invoices only to contract that do not have invoices yet. (How can check it)

I will run the script with cron, and it will run everyday, then I’m going to generate invoices daily if the contract do not have one.
If contracts have invoice for this date then do nothing – exit.

Here I have a piece of code in SQL, that I’m retrieving everybody that has invoices to this date (NOW for month and year).

Some usefull information:

I have 324 active contracts with invoices already generated in the follow query.

SELECT contratos.id, contratos.idcliente, contratos.ativo, invoices.id as inv, invoices.due_date, invoices.contratoid 
FROM contratos 
LEFT JOIN invoices ON invoices.contratoid = contratos.id 
WHERE contratos.ativo = 1 
AND invoices.referencia = 'PA' 
AND YEAR(due_date) = YEAR(CURDATE()) 
AND MONTH(due_date) = MONTH(CURDATE()) 
GROUP BY invoices.id

I have 368 actives contracts in this other query.

SELECT * FROM contracts WHERE active=1

Then I know I have 44 contracts without invoices and I know I need to generate new invocies for the 44 contracts.

My question is how can I retrieve this 44 contracts and show it in my first query, It can be a null (no problem), the important to me id the Contract ID.

If I’m not clear enough please let me know.

Thanks Community.

[EDITED]
Summary

  • I run my first query and got results of 324 lines.
  • Then run the second query and compare the result of query1 and query2
  • the lines that does’nt match is the difference and I need to generate
    invoices to them.

I really would like to do this in my query (one query) and not in my code.

  • 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-23T19:32:42+00:00Added an answer on May 23, 2026 at 7:32 pm

    The LEFT JOIN is returning the invoices records being filled with all NULL values. When you are requiring invoices.referencia to = ‘PA’, that will eliminate all the records that are completely null (negating your outer join).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation, I have a string as follows 'a':1 'b':2 'c':3 I
I still have a question about Enumerations. Here's a quick sketch of the situation.
I have the follow problem. This is the situation i've got when user login
Here is my situation: I have created a QWebview, loaded a Youtube page, and
I am trying to follow the Aggregate design principle and have come up with
This is a problem that happens when you are in the follow situation: -Have
Here is the situation. I have a view controller titled MyViewController. Within this view
I have a situation I'm trying to cope with involving my company's SVN server.
I have a situation as follows <body> Test<br /> test<br /> test1<br /> </body>
Picture the following situation. I have an XML document as follows, <Form> <Control Type=Text

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.