mirror of https://github.com/itflow-org/itflow
Added support for multi-company to cron.php added enable_cron variable and some other tiny things
This commit is contained in:
parent
5ca8d201b0
commit
e114e61261
377
cron.php
377
cron.php
|
|
@ -12,201 +12,224 @@ use PHPMailer\PHPMailer\Exception;
|
|||
|
||||
<?php
|
||||
|
||||
//GET ALERTS
|
||||
$sql_companies = mysqli_query($mysqli,"SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id");
|
||||
|
||||
//DOMAINS EXPIRING
|
||||
while($row = mysqli_fetch_array($sql_companies)){
|
||||
$company_id = $row['company_id'];
|
||||
$company_name = $row['company_name'];
|
||||
$config_enable_cron = $row['config_enable_cron'];
|
||||
$config_invoice_overdue_reminders = $row['config_invoice_overdue_reminders'];
|
||||
$config_invoice_prefix = $row['config_invoice_prefix'];
|
||||
$config_invoice_next_number = $row['config_invoice_next_number'];
|
||||
$config_recurring_email_auto_send = $row['config_recurring_email_auto_send'];
|
||||
$config_smtp_host = $row['config_smtp_host'];
|
||||
$config_smtp_username = $row['config_smtp_username'];
|
||||
$config_smtp_password = $row['config_smtp_password'];
|
||||
$config_smtp_port = $row['config_smtp_port'];
|
||||
$config_mail_from_email = $row['config_mail_from_email'];
|
||||
$config_mail_from_name = $row['config_mail_from_name'];
|
||||
|
||||
$domainAlertArray = [1, 14, 30, 90];
|
||||
if($config_enable_cron == 1){
|
||||
|
||||
foreach ($domainAlertArray as $day) {
|
||||
//GET ALERTS
|
||||
|
||||
//Get Domains Expiring
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM domains, clients
|
||||
WHERE domains.client_id = clients.client_id
|
||||
AND domain_expire = CURDATE() + INTERVAL $day DAY
|
||||
ORDER BY domain_id DESC"
|
||||
);
|
||||
//DOMAINS EXPIRING
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$domain_id = $row['domain_id'];
|
||||
$domain_name = $row['domain_name'];
|
||||
$domain_expire = $row['domain_expire'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$domainAlertArray = [1, 14, 30, 90];
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $domain_name will expire in $day Days on $domain_expire', alert_date = NOW()");
|
||||
foreach($domainAlertArray as $day){
|
||||
|
||||
}
|
||||
//Get Domains Expiring
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM domains, clients
|
||||
WHERE domains.client_id = clients.client_id
|
||||
AND domain_expire = CURDATE() + INTERVAL $day DAY
|
||||
AND domains.company_id = $company_id
|
||||
ORDER BY domain_id DESC"
|
||||
);
|
||||
|
||||
}
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$domain_id = $row['domain_id'];
|
||||
$domain_name = $row['domain_name'];
|
||||
$domain_expire = $row['domain_expire'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
//PAST DUE INVOICES
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $domain_name will expire in $day Days on $domain_expire', alert_date = NOW(), company_id = $company_id");
|
||||
|
||||
$invoiceAlertArray = [$config_invoice_overdue_reminders];
|
||||
}
|
||||
|
||||
foreach ($invoiceAlertArray as $day) {
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
AND invoices.invoice_status NOT LIKE 'Draft'
|
||||
AND invoices.invoice_status NOT LIKE 'Paid'
|
||||
AND invoices.invoice_status NOT LIKE 'Cancelled'
|
||||
AND DATE_ADD(invoices.invoice_due, INTERVAL $day DAY) = CURDATE()
|
||||
ORDER BY invoices.invoice_number DESC"
|
||||
);
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$invoice_number = $row['invoice_number'];
|
||||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Invoice', alert_message = 'Invoice INV-$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days', alert_date = NOW()");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//LOW BALANCE ALERTS
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM accounts ORDER BY account_id DESC");
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$account_id = $row['account_id'];
|
||||
$account_name = $row['account_name'];
|
||||
$opening_balance = $row['opening_balance'];
|
||||
|
||||
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_payments);
|
||||
$total_payments = $row['total_payments'];
|
||||
|
||||
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_expenses);
|
||||
$total_expenses = $row['total_expenses'];
|
||||
|
||||
$balance = $opening_balance + $total_payments - $total_expenses;
|
||||
|
||||
if($balance < $config_account_balance_threshold){
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Account Low Balance', alert_message = 'Threshold of $config_account_balance_threshold triggered low balance of $balance on account $account_name', alert_date = NOW()");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Send Recurring Invoices that match todays date and are active
|
||||
|
||||
$sql_recurring = mysqli_query($mysqli,"SELECT * FROM recurring, clients WHERE clients.client_id = recurring.client_id AND recurring.recurring_next_date = CURDATE() AND recurring.recurring_status = 1");
|
||||
|
||||
while($row = mysqli_fetch_array($sql_recurring)){
|
||||
$recurring_id = $row['recurring_id'];
|
||||
$recurring_frequency = $row['recurring_frequency'];
|
||||
$recurring_status = $row['recurring_status'];
|
||||
$recurring_last_sent = $row['recurring_last_sent'];
|
||||
$recurring_next_date = $row['recurring_next_date'];
|
||||
$recurring_amount = $row['recurring_amount'];
|
||||
$recurring_note = $row['recurring_note'];
|
||||
$category_id = $row['category_id'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_net_terms = $row['client_net_terms'];
|
||||
|
||||
//Get the last Invoice Number and add 1 for the new invoice number
|
||||
$new_invoice_number = "$config_invoice_prefix$config_invoice_next_number";
|
||||
$new_config_invoice_next_number = $config_invoice_next_number + 1;
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_invoice_next_number = $new_config_invoice_next_number WHERE company_id = 1");
|
||||
|
||||
//Generate a unique URL key for clients to access
|
||||
$url_key = keygen();
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = '$new_invoice_number', invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), invoice_amount = '$recurring_amount', invoice_note = '$recurring_note', category_id = $category_id, invoice_status = 'Sent', invoice_url_key = '$url_key', invoice_created_at = NOW(), client_id = $client_id");
|
||||
|
||||
$new_invoice_id = mysqli_insert_id($mysqli);
|
||||
|
||||
//Copy Items from original invoice to new invoice
|
||||
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring_id = $recurring_id ORDER BY item_id ASC");
|
||||
|
||||
while($row = mysqli_fetch_array($sql_invoice_items)){
|
||||
$item_id = $row['item_id'];
|
||||
$item_name = $row['item_name'];
|
||||
$item_description = $row['item_description'];
|
||||
$item_quantity = $row['item_quantity'];
|
||||
$item_price = $row['item_price'];
|
||||
$item_subtotal = $row['item_price'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = '$item_price', item_subtotal = '$item_subtotal', item_tax = '$item_tax', item_total = '$item_total', item_created_at = NOW(), invoice_id = $new_invoice_id");
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_created_at = NOW(), invoice_id = $new_invoice_id");
|
||||
|
||||
//update the recurring invoice with the new dates
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency), recurring_updated_at = NOW() WHERE recurring_id = $recurring_id");
|
||||
|
||||
if($config_recurring_email_auto_send == 1){
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
AND invoices.invoice_id = $new_invoice_id"
|
||||
);
|
||||
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_number = $row['invoice_number'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_url_key = $row['invoice_url_key'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_address = $row['client_address'];
|
||||
$client_city = $row['client_city'];
|
||||
$client_state = $row['client_state'];
|
||||
$client_zip = $row['client_zip'];
|
||||
$client_email = $row['client_email'];
|
||||
$client_phone = $row['client_phone'];
|
||||
if(strlen($client_phone)>2){
|
||||
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
|
||||
}
|
||||
$base_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
//PAST DUE INVOICES
|
||||
|
||||
try{
|
||||
$invoiceAlertArray = [$config_invoice_overdue_reminders];
|
||||
|
||||
//Mail Server Settings
|
||||
foreach($invoiceAlertArray as $day){
|
||||
|
||||
//$mail->SMTPDebug = 2; // Enable verbose debug output
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = $config_smtp_host; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = $config_smtp_username; // SMTP username
|
||||
$mail->Password = $config_smtp_password; // SMTP password
|
||||
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = $config_smtp_port; // TCP port to connect to
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
AND invoices.invoice_status NOT LIKE 'Draft'
|
||||
AND invoices.invoice_status NOT LIKE 'Paid'
|
||||
AND invoices.invoice_status NOT LIKE 'Cancelled'
|
||||
AND DATE_ADD(invoices.invoice_due, INTERVAL $day DAY) = CURDATE()
|
||||
AND invoices.company_id = $company_id
|
||||
ORDER BY invoices.invoice_number DESC"
|
||||
);
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$invoice_id = $row['invoice_id'];
|
||||
$invoice_number = $row['invoice_number'];
|
||||
$invoice_status = $row['invoice_status'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom($config_mail_from_email, $config_mail_from_name);
|
||||
$mail->addAddress("$client_email", "$client_name"); // Add a recipient
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Invoice', alert_message = 'Invoice INV-$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days', alert_date = NOW(), company_id = $company_id");
|
||||
}
|
||||
|
||||
// Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
|
||||
$mail->Subject = "Invoice $invoice_number";
|
||||
$mail->Body = "Hello $client_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_number<br>Issue Date: $invoice_date<br>Total: $$invoice_amount<br>Due Date: $invoice_due<br><br><br>To view your invoice online click <a href='https://$config_base_url/guest_view_invoice.php?invoice_id=$new_invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$config_company_name<br>$config_company_phone";
|
||||
|
||||
$mail->send();
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Auto Emailed Invoice!', history_created_at = NOW(), invoice_id = $new_invoice_id");
|
||||
|
||||
//Update Invoice Status to Sent
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), client_id = $client_id WHERE invoice_id = $new_invoice_id");
|
||||
|
||||
}catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'Failed to send Invoice!', history_created_at = NOW(), invoice_id = $new_invoice_id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//LOW BALANCE ALERTS
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM accounts WHERE company_id = $company_id ORDER BY account_id DESC");
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$account_id = $row['account_id'];
|
||||
$account_name = $row['account_name'];
|
||||
$opening_balance = $row['opening_balance'];
|
||||
|
||||
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_payments);
|
||||
$total_payments = $row['total_payments'];
|
||||
|
||||
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_expenses);
|
||||
$total_expenses = $row['total_expenses'];
|
||||
|
||||
$balance = $opening_balance + $total_payments - $total_expenses;
|
||||
|
||||
if($balance < $config_account_balance_threshold){
|
||||
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Account Low Balance', alert_message = 'Threshold of $config_account_balance_threshold triggered low balance of $balance on account $account_name', alert_date = NOW(), company_id = $company_id");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Send Recurring Invoices that match todays date and are active
|
||||
|
||||
$sql_recurring = mysqli_query($mysqli,"SELECT * FROM recurring, clients WHERE clients.client_id = recurring.client_id AND recurring.recurring_next_date = CURDATE() AND recurring.recurring_status = 1 AND recurring.company_id = $company_id");
|
||||
|
||||
while($row = mysqli_fetch_array($sql_recurring)){
|
||||
$recurring_id = $row['recurring_id'];
|
||||
$recurring_frequency = $row['recurring_frequency'];
|
||||
$recurring_status = $row['recurring_status'];
|
||||
$recurring_last_sent = $row['recurring_last_sent'];
|
||||
$recurring_next_date = $row['recurring_next_date'];
|
||||
$recurring_amount = $row['recurring_amount'];
|
||||
$recurring_note = $row['recurring_note'];
|
||||
$category_id = $row['category_id'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_net_terms = $row['client_net_terms'];
|
||||
|
||||
//Get the last Invoice Number and add 1 for the new invoice number
|
||||
$new_invoice_number = "$config_invoice_prefix$config_invoice_next_number";
|
||||
$new_config_invoice_next_number = $config_invoice_next_number + 1;
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_invoice_next_number = $new_config_invoice_next_number WHERE company_id = $company_id");
|
||||
|
||||
//Generate a unique URL key for clients to access
|
||||
$url_key = keygen();
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = '$new_invoice_number', invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), invoice_amount = '$recurring_amount', invoice_note = '$recurring_note', category_id = $category_id, invoice_status = 'Sent', invoice_url_key = '$url_key', invoice_created_at = NOW(), client_id = $client_id, company_id = $company_id");
|
||||
|
||||
$new_invoice_id = mysqli_insert_id($mysqli);
|
||||
|
||||
//Copy Items from original invoice to new invoice
|
||||
$sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE recurring_id = $recurring_id ORDER BY item_id ASC");
|
||||
|
||||
while($row = mysqli_fetch_array($sql_invoice_items)){
|
||||
$item_id = $row['item_id'];
|
||||
$item_name = $row['item_name'];
|
||||
$item_description = $row['item_description'];
|
||||
$item_quantity = $row['item_quantity'];
|
||||
$item_price = $row['item_price'];
|
||||
$item_subtotal = $row['item_price'];
|
||||
$item_tax = $row['item_tax'];
|
||||
$item_total = $row['item_total'];
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = '$item_price', item_subtotal = '$item_subtotal', item_tax = '$item_tax', item_total = '$item_total', item_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
||||
|
||||
//update the recurring invoice with the new dates
|
||||
mysqli_query($mysqli,"UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency), recurring_updated_at = NOW() WHERE recurring_id = $recurring_id");
|
||||
|
||||
if($config_recurring_email_auto_send == 1){
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
|
||||
WHERE invoices.client_id = clients.client_id
|
||||
AND invoices.invoice_id = $new_invoice_id
|
||||
AND invoices.company_id = $company_id"
|
||||
);
|
||||
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$invoice_number = $row['invoice_number'];
|
||||
$invoice_date = $row['invoice_date'];
|
||||
$invoice_due = $row['invoice_due'];
|
||||
$invoice_amount = $row['invoice_amount'];
|
||||
$invoice_url_key = $row['invoice_url_key'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
$client_address = $row['client_address'];
|
||||
$client_city = $row['client_city'];
|
||||
$client_state = $row['client_state'];
|
||||
$client_zip = $row['client_zip'];
|
||||
$client_email = $row['client_email'];
|
||||
$client_phone = $row['client_phone'];
|
||||
if(strlen($client_phone)>2){
|
||||
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
|
||||
}
|
||||
$base_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try{
|
||||
|
||||
//Mail Server Settings
|
||||
|
||||
//$mail->SMTPDebug = 2; // Enable verbose debug output
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = $config_smtp_host; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = $config_smtp_username; // SMTP username
|
||||
$mail->Password = $config_smtp_password; // SMTP password
|
||||
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = $config_smtp_port; // TCP port to connect to
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom($config_mail_from_email, $config_mail_from_name);
|
||||
$mail->addAddress("$client_email", "$client_name"); // Add a recipient
|
||||
|
||||
// Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
|
||||
$mail->Subject = "Invoice $invoice_number";
|
||||
$mail->Body = "Hello $client_name,<br><br>Please view the details of the invoice below.<br><br>Invoice: $invoice_number<br>Issue Date: $invoice_date<br>Total: $$invoice_amount<br>Due Date: $invoice_due<br><br><br>To view your invoice online click <a href='https://$config_base_url/guest_view_invoice.php?invoice_id=$new_invoice_id&url_key=$invoice_url_key'>here</a><br><br><br>~<br>$company_name<br>$config_company_phone";
|
||||
|
||||
$mail->send();
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Auto Emailed Invoice!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
||||
|
||||
//Update Invoice Status to Sent
|
||||
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), client_id = $client_id WHERE invoice_id = $new_invoice_id");
|
||||
|
||||
}catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'Failed to send Invoice!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id");
|
||||
} //End Mail Try
|
||||
} //End if Autosend is on
|
||||
} //End Recurring Invoices Loop
|
||||
} //End Cron Check
|
||||
} //End Company Loop through
|
||||
|
||||
?>
|
||||
|
|
@ -52,6 +52,7 @@ $config_default_expense_payment_method = $row['config_default_expense_payment_me
|
|||
$config_recurring_email_auto_send = $row['config_recurring_email_auto_send'];
|
||||
|
||||
$config_api_key = $row['config_api_key'];
|
||||
$config_enable_cron = $row['config_enable_cron'];
|
||||
|
||||
$config_base_url = $row['config_base_url'];
|
||||
|
||||
|
|
|
|||
9
post.php
9
post.php
|
|
@ -35,6 +35,13 @@ if(isset($_POST['edit_general_settings'])){
|
|||
$config_start_page = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_start_page']));
|
||||
$config_account_balance_threshold = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_account_balance_threshold']));
|
||||
$config_api_key = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_api_key']));
|
||||
$config_enable_cron = intval($_POST['config_enable_cron']);
|
||||
|
||||
if($config_enable_cron == 1){
|
||||
$config_enable_cron = 1;
|
||||
}else{
|
||||
$config_enable_cron = 0;
|
||||
}
|
||||
|
||||
$path = "$config_invoice_logo";
|
||||
|
||||
|
|
@ -48,7 +55,7 @@ if(isset($_POST['edit_general_settings'])){
|
|||
move_uploaded_file($_FILES['file']['tmp_name'], $path);
|
||||
}
|
||||
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_start_page = '$config_start_page', config_account_balance_threshold = '$config_account_balance_threshold', config_invoice_logo = '$path', config_api_key = '$config_api_key' WHERE company_id = $session_company_id");
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_start_page = '$config_start_page', config_account_balance_threshold = '$config_account_balance_threshold', config_invoice_logo = '$path', config_api_key = '$config_api_key', config_enable_cron = $config_enable_cron WHERE company_id = $session_company_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Settings updated";
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="custom-control custom-switch mb-2">
|
||||
<input type="checkbox" class="custom-control-input" name="config_enable_cron" <?php if($config_enable_cron == 1){ echo "checked"; } ?> value="1" id="customSwitch1">
|
||||
<label class="custom-control-label" for="customSwitch1">Enable Cron <small>(cron.php must also be added to cron and run nightly at 12:00AM for auto jobs to work)</small></label>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label>Logo</label>
|
||||
<input type="file" class="form-control-file" name="file">
|
||||
|
|
|
|||
|
|
@ -24,14 +24,6 @@
|
|||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php if(basename($_SERVER["REQUEST_URI"]) == "settings-carddav.php") { echo "active"; } ?>"
|
||||
href="settings-carddav.php">
|
||||
<i class="fa fa-fw fa-2x fa-address-book"></i><br>
|
||||
CardDAV
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php if(basename($_SERVER["REQUEST_URI"]) == "settings-defaults.php") { echo "active"; } ?>"
|
||||
href="settings-defaults.php">
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ if(isset($_POST['add_company_settings'])){
|
|||
|
||||
mysqli_query($mysqli,"INSERT INTO user_companies SET user_id = $user_id, company_id = $company_id");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO settings SET company_id = $company_id, config_company_name = '$config_company_name', config_company_address = '$config_company_address', config_company_city = '$config_company_city', config_company_state = '$config_company_state', config_company_zip = '$config_company_zip', config_company_phone = $config_company_phone, config_company_site = '$config_company_site', config_start_page = 'dashboard.php', config_invoice_prefix = 'INV-', config_invoice_next_number = 1, config_invoice_overdue_reminders = '1,3,7', config_quote_prefix = 'QUO-', config_quote_next_number = 1, config_api_key = '$config_api_key', config_recurring_auto_send_invoice = 1, config_default_net_terms = 7, config_send_invoice_reminders = 0");
|
||||
mysqli_query($mysqli,"INSERT INTO settings SET company_id = $company_id, config_company_name = '$config_company_name', config_company_address = '$config_company_address', config_company_city = '$config_company_city', config_company_state = '$config_company_state', config_company_zip = '$config_company_zip', config_company_phone = $config_company_phone, config_company_site = '$config_company_site', config_start_page = 'dashboard.php', config_invoice_prefix = 'INV-', config_invoice_next_number = 1, config_invoice_overdue_reminders = '1,3,7', config_quote_prefix = 'QUO-', config_quote_next_number = 1, config_api_key = '$config_api_key', config_recurring_auto_send_invoice = 1, config_default_net_terms = 7, config_send_invoice_reminders = 0, config_enable_cron = 0");
|
||||
|
||||
//Create Some Data
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue