Poprawilem modul daemona payments o to ze zapisuje w bazie (tabela timesamps) ze odpalil sie i jesli danego dnia odpalenie powtorzy sie to nie nalicza oplat, poprawka nie jest zbyt piekna ale pisalem na szybko :) Pozdrawiam Jerzy Kołosowski 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 5 Nov 2005 01:06:57 -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( (res = g->db_pquery(g->conn, "SELECT * FROM timestamps WHERE tablename LIKE '_payments'")) != NULL && db_nrows(res) > 0 ) + 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