mirror of
https://github.com/itflow-org/itflow
synced 2026-03-27 07:45:37 +00:00
Recurring Payments - Added Auto Pay via cron, removed auto pay amount as it uses the recurring invoice amount, next up integrate with stripe
This commit is contained in:
31
cron.php
31
cron.php
@@ -516,7 +516,12 @@ if ($config_send_invoice_reminders == 1) {
|
|||||||
// Send Recurring Invoices that match todays date and are active
|
// Send Recurring Invoices that match todays date and are active
|
||||||
|
|
||||||
//Loop through all recurring that match today's date and is active
|
//Loop through all recurring that match today's date and is active
|
||||||
$sql_recurring = mysqli_query($mysqli, "SELECT * FROM recurring LEFT JOIN clients ON client_id = recurring_client_id WHERE recurring_next_date = CURDATE() AND recurring_status = 1");
|
$sql_recurring = mysqli_query($mysqli, "SELECT * FROM recurring
|
||||||
|
LEFT JOIN recurring_payments ON recurring_id = recurring_payment_recurring_invoice_id
|
||||||
|
LEFT JOIN clients ON client_id = recurring_client_id
|
||||||
|
WHERE recurring_next_date = CURDATE()
|
||||||
|
AND recurring_status = 1
|
||||||
|
");
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($sql_recurring)) {
|
while ($row = mysqli_fetch_array($sql_recurring)) {
|
||||||
$recurring_id = intval($row['recurring_id']);
|
$recurring_id = intval($row['recurring_id']);
|
||||||
@@ -534,7 +539,11 @@ while ($row = mysqli_fetch_array($sql_recurring)) {
|
|||||||
$client_id = intval($row['recurring_client_id']);
|
$client_id = intval($row['recurring_client_id']);
|
||||||
$client_name = sanitizeInput($row['client_name']);
|
$client_name = sanitizeInput($row['client_name']);
|
||||||
$client_net_terms = intval($row['client_net_terms']);
|
$client_net_terms = intval($row['client_net_terms']);
|
||||||
|
|
||||||
|
$recurring_payment_recurring_invoice_id = intval($row['recurring_payment_recurring_invoice_id']);
|
||||||
|
$recurring_payment_currency_code = sanitizeInput($row['recurring_payment_currency_code']);
|
||||||
|
$recurring_payment_method = sanitizeInput($row['recurring_payment_method']);
|
||||||
|
$recurring_payment_account_id = intval($row['recurring_payment_account_id']);
|
||||||
|
|
||||||
// Get the last Invoice Number and add 1 for the new invoice number
|
// Get the last Invoice Number and add 1 for the new invoice number
|
||||||
$sql_invoice_number = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1");
|
$sql_invoice_number = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1");
|
||||||
@@ -658,6 +667,24 @@ while ($row = mysqli_fetch_array($sql_recurring)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} //End if Autosend is on
|
} //End if Autosend is on
|
||||||
|
|
||||||
|
// Create Payment from Auto Payment
|
||||||
|
if ($recurring_payment_recurring_invoice_id) {
|
||||||
|
mysqli_query($mysqli,"INSERT INTO payments SET payment_date = CURDATE(), payment_amount = $recurring_amount, payment_currency_code = '$recurring_payment_currency_code', payment_account_id = $recurring_payment_account_id, payment_method = '$recurring_payment_method', payment_reference = 'Paid via AutoPay', payment_invoice_id = $new_invoice_id");
|
||||||
|
|
||||||
|
// Get Payment ID for reference
|
||||||
|
$payment_id = mysqli_insert_id($mysqli);
|
||||||
|
|
||||||
|
// Update Invoice Status
|
||||||
|
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $new_invoice_id");
|
||||||
|
|
||||||
|
//Add Payment to History
|
||||||
|
mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Paid', history_description = 'Payment added via Auto Pay', history_invoice_id = $new_invoice_id");
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
logAction("Invoice", "Payment", "Auto Payment amount of " . numfmt_format_currency($currency_format, $recurring_amount, $recurring_payment_currency_code) . " added to invoice $invoice_prefix$invoice_number", $client_id, $new_invoice_id);
|
||||||
|
} //End Auto Payment
|
||||||
|
|
||||||
} //End Recurring Invoices Loop
|
} //End Recurring Invoices Loop
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
|||||||
@@ -2396,10 +2396,18 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.4'");
|
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.4'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (CURRENT_DATABASE_VERSION == '1.7.4') {
|
if (CURRENT_DATABASE_VERSION == '1.7.4') {
|
||||||
// // Insert queries here required to update to DB version 1.7.5
|
|
||||||
|
// Remove Recurring Payment Amount as it will use the Recurring Invoice Amount and is unessessary
|
||||||
|
mysqli_query($mysqli, "ALTER TABLE `recurring_payments` DROP `recurring_payment_amount`");
|
||||||
|
|
||||||
|
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.5'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (CURRENT_DATABASE_VERSION == '1.7.5') {
|
||||||
|
// // Insert queries here required to update to DB version 1.7.6
|
||||||
// // Then, update the database to the next sequential version
|
// // Then, update the database to the next sequential version
|
||||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.5'");
|
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.6'");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,4 +5,4 @@
|
|||||||
* It is used in conjunction with database_updates.php
|
* It is used in conjunction with database_updates.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEFINE("LATEST_DATABASE_VERSION", "1.7.4");
|
DEFINE("LATEST_DATABASE_VERSION", "1.7.5");
|
||||||
|
|||||||
3
db.sql
3
db.sql
@@ -1392,7 +1392,6 @@ DROP TABLE IF EXISTS `recurring_payments`;
|
|||||||
/*!40101 SET character_set_client = utf8 */;
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
CREATE TABLE `recurring_payments` (
|
CREATE TABLE `recurring_payments` (
|
||||||
`recurring_payment_id` int(11) NOT NULL AUTO_INCREMENT,
|
`recurring_payment_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`recurring_payment_amount` decimal(15,2) NOT NULL,
|
|
||||||
`recurring_payment_currency_code` varchar(10) NOT NULL,
|
`recurring_payment_currency_code` varchar(10) NOT NULL,
|
||||||
`recurring_payment_method` varchar(200) NOT NULL,
|
`recurring_payment_method` varchar(200) NOT NULL,
|
||||||
`recurring_payment_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
`recurring_payment_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||||
@@ -2288,4 +2287,4 @@ CREATE TABLE `vendors` (
|
|||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2024-12-21 16:44:59
|
-- Dump completed on 2024-12-21 20:24:14
|
||||||
|
|||||||
@@ -1202,12 +1202,12 @@ if (isset($_POST['add_recurring_payment'])) {
|
|||||||
// Get Recurring Info for logging and alerting
|
// Get Recurring Info for logging and alerting
|
||||||
$sql = mysqli_query($mysqli, "SELECT * FROM recurring WHERE recurring_id = $recurring_id");
|
$sql = mysqli_query($mysqli, "SELECT * FROM recurring WHERE recurring_id = $recurring_id");
|
||||||
$row = mysqli_fetch_array($sql);
|
$row = mysqli_fetch_array($sql);
|
||||||
$recurring_prefix = nullable_htmlentities($row['recurring_prefix']);
|
$recurring_prefix = sanitizeInput($row['recurring_prefix']);
|
||||||
$recurring_number = intval($row['recurring_number']);
|
$recurring_number = intval($row['recurring_number']);
|
||||||
$recurring_amount = floatval($row['recurring_amount']);
|
$recurring_amount = floatval($row['recurring_amount']);
|
||||||
$client_id = intval($row['recurring_client_id']);
|
$client_id = intval($row['recurring_client_id']);
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO recurring_payments SET recurring_payment_amount = $recurring_amount, recurring_payment_currency_code = '$currency_code', recurring_payment_account_id = $account, recurring_payment_method = '$payment_method', recurring_payment_recurring_invoice_id = $recurring_id");
|
mysqli_query($mysqli,"INSERT INTO recurring_payments SET recurring_payment_currency_code = '$currency_code', recurring_payment_account_id = $account, recurring_payment_method = '$payment_method', recurring_payment_recurring_invoice_id = $recurring_id");
|
||||||
|
|
||||||
// Get Payment ID for reference
|
// Get Payment ID for reference
|
||||||
$recurring_payment_id = mysqli_insert_id($mysqli);
|
$recurring_payment_id = mysqli_insert_id($mysqli);
|
||||||
|
|||||||
Reference in New Issue
Block a user