CREATE TABLE IF NOT EXISTS `invoices`
(
id BIGINT (255) NOT NULL AUTO-INCREAMENT,
customer BIGINT (255),
invoiceno VARCHAR (255),
startdate DATE,
isPaidStatus ENUM ("YES,NO") DEFAULT 'NO',
payment_terms INT (5),
latefee INT (10),
subtotal DECIMAL ("6,2"),
vat DECIMAL ("6,2"),
total DECIMAL ("6,2"),
total_addtional DECIMAL ("6,2"),
PRIMARY KEY ( id)
) ENGINE = InnoDB ;
CREATE TABLE IF NOT EXISTS `latefees`
(
id BIGINT (255) NOT NULL AUTO-INCREAMENT,
type ENUM("%,Flat Fee") DEFAULT '%',
frequency INT (5),
amount DECIMAL ("6,2"),
PRIMARY KEY (`id`)
) ENGINE = InnoDB ;
respectively.
SELECT
`A`.customer,`A`.id,`A`.invoiceno,`A`.total,`A`._total,`A`.`latefee`,`A`.startdate,`A`.payment_terms,
`B`.name,`B`.type,`B`.frequency,`B`.amount,
((TO_DAYS(Current_Date()) - TO_DAYS(`A`.startdate)) - `A`.payment_terms) AS daysElasped,
MOD(((TO_DAYS(Current_Date()) - TO_DAYS(`A`.startdate)) - `A`.payment_terms), `B`.frequency) AS `isBillableDay`,
IF(`B`.type=1,(`A`.total + `A`.total_addtional)*(`B`.amount / 100),`B`.amount) AS `new_amount`
FROM
`invoices` AS `A`
LEFT JOIN
`latefees` AS `B` ON `B`.id=`A`.`latefee`
WHERE
`latefee` > 0 AND
`isPaidStatus` = 'NO' AND
((TO_DAYS(Current_Date()) - TO_DAYS(`A`.startdate)) > `A`.payment_terms) AND
(MOD(((TO_DAYS(Current_Date()) - TO_DAYS(`A`.startdate)) -`A`.payment_terms),`B`.frequency)=0)
This query basically does the following:
UPDATE `invoices` SET `status`='1',`total_addtional`=`total_addtional`+ {SQL-RESULTS}->FIELDS["new_amount"] WHERE id={SQL-RESULTS}->FIELDS["new_amount"]
3. After executing the above UPDATE query successfully then, notify the customer (i.e. {SQL-RESULTS}->FIELDS[]"cuHave a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Author
Commented:Is the 300 Words including the code snippets?
Author
Commented:I am a GENIUS but only on Coding and Software Development, i do lots of research and development stuff for Enterprises.
I also have my own business network portal where people can use ERP and CRM for free ( http://1stbn.co.za )
Two, i recently developed an Open Source server configuration utility tool "OVH Server Basement" (http://ovhserverbasement.co.za/) and whole lots of other genius commercial stuff.
The moral of the story is i have lots and lots of knowledge to share more especially on Programming and Development, i just do not have time to think of business models etc. Most of these articles are solutions i derived for problems that i experienced when i develop my own stuff or even clients stuff and i believe that there might be at-least one person out there who is still yet to go through what i went through and perhaps this article might just help them.
ALSO, i selected a tag called MySQL so automatically this article is targeted to someone who is already trying to write an SQL query for what ever reason that prompted them to do so.
Those are the people i was honestly having in mind when i was writing the article, people who already have a problem or business model and are just searching for solution
Author
Commented:https://www.experts-exchange.com/Networking/Linux_Networking/A_13635-How-to-setup-a-local-Area-Network-between-two-Ubuntu-servers.html
It was published but to me i do not think has a business model to it because i just went straight to the point