Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: introduce new liabilities suspention methods #2474

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions bin/lms-maketcnew.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,14 @@ function ($value) {
JOIN assignments a ON (na.assignmentid = a.id)
" . ($ignore_assignment_suspensions
? ''
: "LEFT JOIN (
SELECT customerid, COUNT(id) AS allsuspended FROM assignments
WHERE tariffid IS NULL AND liabilityid IS NULL
AND datefrom <= ?NOW? AND (dateto = 0 OR dateto > ?NOW?)
GROUP BY customerid
) s ON s.customerid = a.customerid") . "
: "LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
AND vas.suspension_datefrom <= ?NOW?
AND (vas.suspension_dateto >= ?NOW? OR vas.suspension_dateto = 0)
AND a.datefrom <= ?NOW? AND (a.dateto >= ?NOW? OR a.dateto = 0)") . "
JOIN tariffs t ON (a.tariffid = t.id)
JOIN vnodes n ON (na.nodeid = n.id)
JOIN customers c ON (a.customerid = c.id)
WHERE " . ($ignore_assignment_suspensions ? '' : "s.allsuspended IS NULL AND a.suspended = 0 AND ") . "a.commited = 1
WHERE " . ($ignore_assignment_suspensions ? '' : "vas.suspended IS NOT NULL AND ") . "a.commited = 1
AND a.datefrom <= ?NOW? AND (a.dateto >= ?NOW? OR a.dateto = 0)
AND n.access = 1
AND (t.downrate > 0 OR t.downceil > 0 OR t.uprate > 0 OR t.upceil > 0)
Expand All @@ -292,12 +290,10 @@ function ($value) {
FROM assignments a
" . ($ignore_assignment_suspensions
? ''
: "LEFT JOIN (
SELECT customerid, COUNT(id) AS allsuspended FROM assignments
WHERE tariffid IS NULL AND liabilityid IS NULL
AND datefrom <= ?NOW? AND (dateto = 0 OR dateto > ?NOW?)
GROUP BY customerid
) s ON s.customerid = a.customerid") . "
: "LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = na.assignmentid
AND vas.suspension_datefrom <= ?NOW?
AND (vas.suspension_dateto >= ?NOW? OR vas.suspension_dateto = 0)
AND a.datefrom <= ?NOW? AND (a.dateto >= ?NOW? OR a.dateto = 0)") . "
JOIN tariffs t ON t.id = a.tariffid
JOIN customers c ON c.id = a.customerid
JOIN (
Expand All @@ -308,7 +304,7 @@ function ($value) {
WHERE (vn.ownerid > 0 AND nd.id IS NULL)
OR (vn.ownerid IS NULL AND nd.id IS NOT NULL)
) n ON n.ownerid = c.id
WHERE " . ($ignore_assignment_suspensions ? '' : "s.allsuspended IS NULL AND a.suspended = 0 AND ") . "a.commited = 1
WHERE " . ($ignore_assignment_suspensions ? '' : "vas.suspended IS NOT NULL AND ") . "a.commited = 1
AND n.id NOT IN (SELECT DISTINCT nodeid FROM nodeassignments)
AND a.id NOT IN (SELECT DISTINCT assignmentid FROM nodeassignments)
AND a.datefrom <= ?NOW?
Expand Down
71 changes: 46 additions & 25 deletions bin/lms-notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@
'ssl_allow_self_signed' => ConfigHelper::checkConfig($config_section . '.smtp_ssl_allow_self_signed'),
);

$suspension_percentage = floatval(ConfigHelper::getConfig('payments.suspension_percentage', ConfigHelper::getConfig('finances.suspension_percentage', 0)));
$debug_email = ConfigHelper::getConfig($config_section . '.debug_email', '', true);
$mail_from = ConfigHelper::getConfig($config_section . '.sender_email', ConfigHelper::getConfig($config_section . '.mailfrom', '', true));
$mail_fname = ConfigHelper::getConfig($config_section . '.sender_name', ConfigHelper::getConfig($config_section . '.mailfname', '', true));
Expand Down Expand Up @@ -720,30 +719,29 @@ function parse_customer_data($data, $format, $row)
);
if (preg_match("/\%abonament/", $data)) {
$assignments = $DB->GetAll(
'SELECT SUM(ROUND(((((100 - a.pdiscount) * (CASE WHEN a.liabilityid IS NULL THEN t.value ELSE l.value END)) / 100) - a.vdiscount) *
(CASE a.suspended WHEN 0
THEN 1.0
ELSE ?
END), 2)) AS value,
'SELECT SUM(
(CASE WHEN vas.suspended IS NULL
THEN ROUND(((((100 - a.pdiscount) * (CASE WHEN a.liabilityid IS NULL THEN t.value ELSE l.value END)) / 100) - a.vdiscount), 2)
ELSE vas.suspension_price
END)
) AS value,
(CASE WHEN a.liabilityid IS NULL THEN t.currency ELSE l.currency END) AS acurrency
FROM assignments a
LEFT JOIN tariffs t ON t.id = a.tariffid
LEFT JOIN liabilities l ON l.id = a.liabilityid
WHERE a.customerid = ? AND (t.id IS NOT NULL OR l.id IS NOT NULL)
AND a.datefrom <= ? AND (a.dateto > ? OR a.dateto = 0)
AND NOT EXISTS (
SELECT 1 FROM assignments
WHERE customerid = a.customerid AND tariffid IS NULL AND liabilityid IS NULL
AND datefrom <= ? AND (dateto > ? OR dateto = 0)
)
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
AND vas.suspension_datefrom <= ?
AND (vas.suspension_dateto >= ? OR vas.suspension_dateto = 0)
AND datefrom <= ? AND (dateto > ? OR dateto = 0)
WHERE a.customerid = ?
AND vas.suspended IS NULL
GROUP BY acurrency',
array(
round($GLOBALS['suspension_percentage'] / 100, 2),
$row['id'],
$GLOBALS['currtime'],
$GLOBALS['currtime'],
$GLOBALS['currtime'],
$GLOBALS['currtime'],
$row['id'],
)
);
$saldo = array();
Expand Down Expand Up @@ -3536,8 +3534,13 @@ function send_sms_to_user($phone, $data)
WHERE status <> ' . $target_cstatus . ' AND customers.id = c.id)';
break;
case 'all-assignment-suspension':
$where_customers[] = 'NOT EXISTS (SELECT id FROM assignments
WHERE customerid = c.id AND tariffid IS NULL AND liabilityid IS NULL)';
$where_customers[] = 'NOT EXISTS (SELECT id
FROM assignments
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
AND vas.suspension_datefrom <= ?NOW?
AND (vas.suspension_dateto >= ?NOW? OR vas.suspension_dateto = 0)
AND a.datefrom <= ?NOW? AND (a.dateto >= ?NOW? OR a.dateto = 0)
WHERE customerid = c.id AND vas.suspension_suspend_all = 1)';
break;
case 'customer-group':
$where_customers[] = 'NOT EXISTS (
Expand Down Expand Up @@ -3745,7 +3748,10 @@ function send_sms_to_user($phone, $data)
);
foreach ($customers as $cid) {
if (!$DB->GetOne(
"SELECT id FROM assignments WHERE customerid = ? AND tariffid IS NULL AND liabilityid IS NULL",
"SELECT id
FROM assignments
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
WHERE customerid = ? AND vas.suspension_suspend_all = 1",
array($cid)
)) {
if (!$quiet) {
Expand Down Expand Up @@ -3875,8 +3881,10 @@ function send_sms_to_user($phone, $data)
WHERE status <> ' . $target_cstatus . ' AND customers.id = c.id)';
break;
case 'all-assignment-suspension':
$where_customers[] = 'EXISTS (SELECT id FROM assignments
WHERE customerid = c.id AND tariffid IS NULL AND liabilityid IS NULL)';
$where_customers[] = 'EXISTS (SELECT id
FROM assignments
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
WHERE customerid = c.id AND vas.suspension_suspend_all = 1)';
break;
case 'customer-group':
$where_customers[] = 'EXISTS (
Expand Down Expand Up @@ -4073,15 +4081,23 @@ function send_sms_to_user($phone, $data)
$SYSLOG->NewTransaction('lms-notify.php');
}
if ($datefrom = $DB->GetOne(
"SELECT datefrom FROM assignments WHERE customerid = ? AND tariffid IS NULL AND liabilityid IS NULL",
"SELECT datefrom
FROM assignments
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
WHERE customerid = ? AND vas.suspension_suspend_all = 1",
array($cid)
)) {
$year = intval(date('Y', $datefrom));
$month = intval(date('m', $datefrom));
if ($year < $current_year || ($year == $current_year && $month < $current_month)) {
$aids = $DB->GetCol(
"SELECT id FROM assignments
WHERE customerid = ? AND (tariffid IS NOT NULL OR liabilityid IS NOT NULL)
"SELECT id
FROM assignments
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
AND vas.suspension_datefrom <= ?NOW?
AND (vas.suspension_dateto >= ?NOW? OR vas.suspension_dateto = 0)
AND a.datefrom <= ?NOW? AND (a.dateto >= ?NOW? OR a.dateto = 0)
WHERE customerid = ? AND vas.suspension_suspend_all = 1
AND datefrom < ?NOW? AND (dateto = 0 OR dateto > ?NOW?)",
array($cid)
);
Expand All @@ -4104,8 +4120,13 @@ function send_sms_to_user($phone, $data)
}
}
}
$aids = $DB->GetCol("SELECT id FROM assignments
WHERE customerid = ? AND tariffid IS NULL AND liabilityid IS NULL", array($cid));
$aids = $DB->GetCol(
"SELECT id
FROM assignments
LEFT JOIN vassignmentsuspensions vas ON vas.suspension_assignment_id = a.id
WHERE customerid = ? AND vas.suspension_suspend_all = 1",
array($cid)
);
if (!empty($aids)) {
foreach ($aids as $aid) {
if (!$quiet) {
Expand Down
Loading