[lms-commits] CVS update of lms/daemon/modules/payments (payments.c)

LMS CVS cvs w lms.org.pl
Pon, 27 Wrz 2010, 15:16:48 CEST


Date: Monday, September 27, 2010 @ 15:16:48
Author: alec
Path: /cvsroot/lms/daemon/modules/payments

Modified: payments.c

- allow setting assignment period for disposable liabilities
- don't remove disposable liabilities immediately after accounting, use specified delay like with non-disposable liabilities


Diff URLs:
http://cvs.lms.org.pl/viewvc/Development/lms/daemon/modules/payments/payments.c.diff?&r1=1.90&r2=1.91


Index: lms/daemon/modules/payments/payments.c
diff -u lms/daemon/modules/payments/payments.c:1.90 lms/daemon/modules/payments/payments.c:1.91
--- lms/daemon/modules/payments/payments.c:1.90	Mon Jun 28 15:36:06 2010
+++ lms/daemon/modules/payments/payments.c	Mon Sep 27 15:16:48 2010
@@ -19,7 +19,7 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
  *
- *  $Id: payments.c,v 1.90 2010/06/28 13:36:06 alec Exp $
+ *  $Id: payments.c,v 1.91 2010/09/27 13:16:48 alec Exp $
  */
 #include <stdio.h>
 #include <stdlib.h>
@@ -481,7 +481,7 @@
 
 	/****** customer payments *******/
 	// let's create main query
-	char *query = strdup("SELECT a.tariffid, a.liabilityid, a.customerid, a.period, "
+	char *query = strdup("SELECT a.tariffid, a.customerid, a.period, "
 	    "a.at, a.suspended, a.invoice, a.id AS assignmentid, a.settlement, a.datefrom, a.discount, "
 		"c.paytype, a.paytype AS a_paytype, a.numberplanid, d.inv_paytype AS d_paytype, "
 		"UPPER(c.lastname) AS lastname, c.name AS custname, c.address, c.zip, c.city, c.ten, c.ssn, "
@@ -499,14 +499,15 @@
 		"LEFT JOIN liabilities li ON (a.liabilityid = li.id) "
 		"LEFT JOIN divisions d ON (d.id = c.divisionid) "
 		"WHERE c.status = 3 AND c.deleted = 0 "
-		    "AND (a.period="_DAILY_" "
-			    "OR (a.period="_WEEKLY_" AND at=?) "
-			    "OR (a.period="_MONTHLY_" AND at=?) "
-			    "OR (a.period="_QUARTERLY_" AND at=?) "
-			    "OR (a.period="_HALFYEARLY_" AND at=?) "
-			    "OR (a.period="_YEARLY_" AND at=?) "
-			    "OR (a.period="_DISPOSABLE_" AND at=?)) "
-		    "AND (a.datefrom <= ? OR a.datefrom = 0) AND (a.dateto >= ? OR a.dateto = 0) "
+		    "AND ((a.period="_DISPOSABLE_" AND at=?) "
+		        "OR ((a.period="_DAILY_" "
+			        "OR (a.period="_WEEKLY_" AND at=?) "
+			        "OR (a.period="_MONTHLY_" AND at=?) "
+			        "OR (a.period="_QUARTERLY_" AND at=?) "
+			        "OR (a.period="_HALFYEARLY_" AND at=?) "
+			        "OR (a.period="_YEARLY_" AND at=?)) "
+			        "AND (a.datefrom <= ? OR a.datefrom = 0) "
+			        "AND (a.dateto >= ? OR a.dateto = 0))) "
 		    "%nets"
 		    "%enets"
 		    "%groups"
@@ -519,7 +520,7 @@
 	g->str_replace(&query, "%egroups", strlen(egroupsql) ? egroups : "");
 
 	if( (res = g->db_pquery(g->conn, query,
-		weekday, monthday, quarterday, halfday, yearday, itoa(today), currtime, currtime)) != NULL)
+		itoa(today), weekday, monthday, quarterday, halfday, yearday,  currtime, currtime)) != NULL)
 	{
 		struct plan *plans = (struct plan *) malloc(sizeof(struct plan));
 		int invoice_number = 0;
@@ -556,7 +557,6 @@
 			int uid = atoi(g->db_get_data(res,i,"customerid"));
 			int s_state = atoi(g->db_get_data(res,i,"suspended"));
 			int period = atoi(g->db_get_data(res,i,"period"));
-			int liabilityid = atoi(g->db_get_data(res,i,"liabilityid"));
 			int settlement = atoi(g->db_get_data(res,i,"settlement"));
 			int datefrom = atoi(g->db_get_data(res,i,"datefrom"));
 			char *discount = g->db_get_data(res,i,"discount");
@@ -781,12 +781,6 @@
 			free(insert);
 			free(description);
 
-			// remove disposable liabilities
-			if( liabilityid && !period )
-			{
-				g->db_pexec(g->conn, "DELETE FROM liabilities WHERE id=?", itoa(liabilityid));
-			}
-
 			// settlements accounting has sense only for up payments
 			if( settlement && datefrom && p->up_payments)
 			{
@@ -936,15 +930,20 @@
 	// remove old assignments
 	if(p->expiry_days<0) p->expiry_days *= -1; // number of expiry days can't be negative
 
-	g->db_pexec(g->conn, "DELETE FROM liabilities WHERE id IN ("
-		"SELECT liabilityid FROM assignments "
-		"WHERE dateto < ? - 86400 * ? AND dateto != 0 AND liabilityid != 0)",
-		currtime, itoa(p->expiry_days));
-	g->db_pexec(g->conn, "DELETE FROM assignments WHERE dateto < ? - 86400 * ? AND dateto != 0 ",
-		currtime, itoa(p->expiry_days));
-	g->db_pexec(g->conn, "DELETE FROM assignments WHERE at = ?", itoa(today));
+    char *exp_days = strdup(itoa(p->expiry_days));
+
+	g->db_pexec(g->conn, "DELETE FROM liabilities "
+	    "WHERE id IN ("
+		    "SELECT liabilityid FROM assignments "
+	        "WHERE dateto < ? - 86400 * ? AND dateto != 0 AND at < ? - 86400 * ? "
+		        "AND liabilityid != 0)",
+	    currtime, exp_days, itoa(today), exp_days);
+	g->db_pexec(g->conn, "DELETE FROM assignments "
+	    "WHERE dateto < ? - 86400 * ? AND dateto != 0 AND at < ? - 86400 * ?",
+	    currtime, exp_days, itoa(today), exp_days);
 
 	// clean up
+	free(exp_days);
 	free(currtime);
 	free(nets); free(enets);
 	free(groups); free(egroups);


Więcej informacji o liście lms-commits