[patch]Modul payments deamona LMS - akt II :) poprawki :D
Zrobilem nowa wersje patcha do modulu payment daemona lms, bo stwierdzilem ze jak juz cos robic to porzadnie. No wiec poprawka ta wprowadza nowa opcje dla instancji modulu payments jaka jest once_per_day. Ustawienie tej wartosci na "yes" sprawi ze jesli payments bedzie odpalone kilka razy to za kazdym razem nie bedzie powtarzac naliczania wszystkich oplat, tylko sprawdzi czy byl juz dzis odpalony, i jesli tak to oleje ponowne naliczanie. Domysle przyjmowana jest wartosc "no", czyli modul chodzi tak jak chodzil zawsze. Dla mnie taka funkcjonalnosc jest przydatna, gdyz uzywajac funkcji "Przeladowanie" przeladowywalo mi rowniez payments, i naliczalo oplaty podwojnie/potrojnie/itd.
Mam nadzieje ze nie zasmiecam grupy niepotrzebnymi patchami :)
Pozdrawiam
Jerzy Kolosowski aka JPrezes
Index: daemon/modules/payments/payments.c =================================================================== RCS file: /home/cvsroot/lms/daemon/modules/payments/payments.c,v retrieving revision 1.50 diff -u -r1.50 payments.c --- daemon/modules/payments/payments.c 5 Oct 2005 14:56:29 -0000 1.50 +++ daemon/modules/payments/payments.c 6 Nov 2005 15:03:19 -0000 @@ -129,14 +129,15 @@ unsigned char *description, *invoiceid; int i, docid=0, last_customerid=0, number=0, exec=0, suspended=0, itemid=0;
- time_t t; - struct tm *tt; + time_t t, today; + struct tm *tt, *ttoday; unsigned char monthday[3], month[3], year[5], quarterday[3], weekday[2], yearday[4]; //odjac jeden? unsigned char start[12], end[12]; // get current date t = time(NULL); tt = localtime(&t); + ttoday = localtime(&t); strftime(monthday, sizeof(monthday), "%d", tt); strftime(weekday, sizeof(weekday), "%u", tt); strftime(yearday, sizeof(yearday), "%j", tt); @@ -175,6 +176,15 @@ tt->tm_mon = atoi(month)-1; tt->tm_year = atoi(year)-1900;
+ // poczatek dnia dzisiejszego + ttoday->tm_sec = 0; + ttoday->tm_min = 0; + ttoday->tm_hour = 0; + ttoday->tm_mday = atoi(monthday); + ttoday->tm_mon = atoi(month)-1; + ttoday->tm_year = atoi(year)-1900; + today = mktime(ttoday); + switch(p->num_period) { case DAILY: @@ -218,7 +228,9 @@ break; } strftime(end, sizeof(end), "%s", tt); - + if( p->once_per_day && (res = g->db_pquery(g->conn, "SELECT * FROM timestamps WHERE tablename LIKE '_payments'")) != NULL ) + if( atoi(g->db_get_data(res,0,"time")) > (int)today ) + return; /****** main payments *******/ if( (res = g->db_pquery(g->conn, "SELECT * FROM payments WHERE value <> 0 AND (period="_DAILY_" OR (period="_WEEKLY_" AND at=?) OR (period="_MONTHLY_" AND at=?) OR (period="_QUARTERLY_" AND at=?) OR (period="_YEARLY_" AND at=?))", weekday, monthday, quarterday, yearday))!= NULL ) { @@ -388,9 +400,10 @@ // set timestamps if(exec) { - g->db_exec(g->conn, "DELETE FROM timestamps WHERE tablename = 'cash' OR tablename = '_global'"); + g->db_exec(g->conn, "DELETE FROM timestamps WHERE tablename = 'cash' OR tablename = '_global' OR tablename = '_payments'"); g->db_exec(g->conn, "INSERT INTO timestamps (tablename, time) VALUES ('cash', %NOW%)"); g->db_exec(g->conn, "INSERT INTO timestamps (tablename, time) VALUES ('_global', %NOW%)"); + g->db_exec(g->conn, "INSERT INTO timestamps (tablename, time) VALUES ('_payments', %NOW%)"); } // remove old assignments if(p->expiry_days<0) p->expiry_days *= -1; // number of expiry days can't be negative @@ -420,6 +433,7 @@ p->comment = strdup(g->config_getstring(p->base.ini, p->base.instance, "comment", "Subscription: %tariff for period: %period")); p->deadline = strdup(g->config_getstring(p->base.ini, p->base.instance, "deadline", "14")); p->paytype = strdup(g->config_getstring(p->base.ini, p->base.instance, "paytype", "TRANSFER")); + p->once_per_day = g->config_getbool(p->base.ini, p->base.instance, "once_per_day", 0); p->up_payments = g->config_getbool(p->base.ini, p->base.instance, "up_payments", 1); p->expiry_days = g->config_getint(p->base.ini, p->base.instance, "expiry_days", 30); Index: daemon/modules/payments/payments.h =================================================================== RCS file: /home/cvsroot/lms/daemon/modules/payments/payments.h,v retrieving revision 1.9 diff -u -r1.9 payments.h --- daemon/modules/payments/payments.h 4 Aug 2005 17:00:51 -0000 1.9 +++ daemon/modules/payments/payments.h 6 Nov 2005 15:03:19 -0000 @@ -7,6 +7,7 @@ unsigned char *paytype; unsigned char *deadline; unsigned char *numberplanid; + int once_per_day; int up_payments; int expiry_days; int num_period;
uczestnicy (1)
-
Jerzy Kolosowski