void LogCall::setLoginID(const char * newLoginID) { QApplication::setOverrideCursor(waitCursor); if (strlen(newLoginID) < 32) { strcpy(myLoginID, newLoginID); loginID->setText(myLoginID); if (strlen(myLoginID)) { // Now, get the customer ID for this login ID char *query = new char[32768]; ADB DB; DB.query("select CustomerID from Logins where LoginID = '%s'", myLoginID); if (DB.rowCount == 1) { DB.getrow(); myCustID = atol(DB.curRow["CustomerID"]); // Load the customer's name so we can verify who we're talking // to. CustomersDB CDB; CDB.get(myCustID); strcpy(custName, (const char *) CDB.getStr("FullName")); sprintf(query, "Customer ID %ld selected (%s)", myCustID, custName); statusLabel->setText(query); } else { myCustID = 0; statusLabel->setText("No customer selected"); } } else { myCustID = 0; statusLabel->setText("No customer selected"); } } QApplication::restoreOverrideCursor(); }
void MakeDeposits::fillDepositList() { QApplication::setOverrideCursor(waitCursor); ADB DB; char tmpStr[1024]; float totalFunds = 0.00; strcpy(tmpStr, cfgVal("UndepositedFundsAccount")); emit(setStatus("Creating undeposited funds list...")); DB.query("select GL.InternalID, GL.TransDate, GL.Amount, AcctsRecv.RefNo, AcctsRecv.CustomerID, Customers.FullName from GL, AcctsRecv, Customers where GL.IntAccountNo = %d and GL.TransType = 2 and AcctsRecv.InternalID = GL.TransTypeLink and AcctsRecv.RefNo > 0 and Customers.CustomerID = AcctsRecv.CustomerID and GL.Cleared = 0", atoi(cfgVal("UndepositedFundsAcct"))); //DB.query("select * from GL where AccountNo = %d and LinkedTrans = 0", atoi(tmpStr)); if (DB.rowCount) while (DB.getrow()) { (void) new Q3ListViewItem(paymentList, DB.curRow["TransDate"], DB.curRow["CustomerID"], DB.curRow["FullName"], DB.curRow["RefNo"], DB.curRow["Amount"], DB.curRow["InternalID"] ); totalFunds += atof(DB.curRow["Amount"]); } sprintf(tmpStr, "$%.2f", totalFunds); undepositedAmount->setText(tmpStr); emit(setStatus("")); QApplication::restoreOverrideCursor(); }
void UnreleasedDomainsReport::refreshReport() { repBody->clear(); ADB DB; DB.query("select Domains.CustomerID, Domains.LoginID, DomainTypes.DomainType, Domains.DomainName from Domains, DomainTypes where Domains.Active <> 0 and Domains.Released = '' and DomainTypes.InternalID = Domains.DomainType"); if (DB.rowCount) while (DB.getrow()) { (void) new Q3ListViewItem(repBody, DB.curRow["CustomerID"], DB.curRow["LoginID"], DB.curRow["DomainType"], DB.curRow["DomainName"]); } }
void UserPrivs::refreshList() { ADB DB; char levelStr[1024]; AccessLevels level; Q3ListViewItem *curItem; bool foundSel = false; userList->clear(); DB.query("select * from Staff"); if (DB.rowCount) { while(DB.getrow()) { level = (AccessLevels) atoi(DB.curRow["AccessLevel"]); switch(level) { case Admin: strcpy(levelStr, "Administrator"); break; case Manager: strcpy(levelStr, "Manager"); break; case Staff: strcpy(levelStr, "Support Staff"); break; default: strcpy(levelStr, "Unknown"); break; } curItem = new Q3ListViewItem(userList, DB.curRow["LoginID"], levelStr, DB.curRow["InternalID"]); // Is this the user we previously had hilighted? If so, // hilight it now. if (myCurrentID == atol(DB.curRow["InternalID"])) { foundSel = true; userList->setCurrentItem(curItem); userList->setSelected(curItem, true); userList->ensureItemVisible(curItem); } } } // If we didn't find our previously hilighted entry, hilight the // first entry in the list. if (!foundSel) { // None selected, hilight the first one in the list. if (userList->firstChild()) { userList->setCurrentItem(userList->firstChild()); userList->setSelected(userList->firstChild(), true); userList->ensureItemVisible(userList->firstChild()); } } }
/** * setGLAccount() * * Overrides the GL Account that we post to - not the AcctsRecv side * but the billable side of the transaction. * * Returns 1 if successful, 0 if not. */ int AcctsRecv::setGLAccount(const char *acctNo) { int retVal = 0; ADB DB; DB.query("select IntAccountNo from Accounts where AccountNo = '%s'", acctNo); if (DB.rowCount) { DB.getrow(); myIntAcctNo = atoi(DB.curRow["IntAccountNo"]); retVal = 1; } return retVal; }
/** * CustomLoginFlagEditor::fillTable() * * Fills the table with the flags and values for the user. */ void CustomLoginFlagEditor::fillTable() { ADB db; long loginType; Q3Dict<QString> flagDict; // Get the login type. db.query("select LoginType from Logins where LoginID = '%s'", myLoginID); if (!db.rowCount) return; db.getrow(); loginType = atoi(db.curRow["LoginType"]); // Get the available login flags for this login type db.query("select Tag, Value from LoginTypeFlags where LoginTypeID = %ld", loginType); if (!db.rowCount) return; // Load the dictionary while(db.getrow()) { flagDict.insert(db.curRow["Tag"], new QString(db.curRow["Value"])); } // Get whatever data is in the LoginFlagValues that is custom for this user. db.query("select * from LoginFlagValues where LoginID = '%s'", myLoginID); if (db.rowCount) while (db.getrow()) { flagDict.replace(db.curRow["LoginFlag"], new QString(db.curRow["FlagValue"])); } // Now put the stuff from our flagDict into the grid Q3DictIterator<QString> it(flagDict); for( ; it.current(); ++it ) { flagTable->insertRows(flagTable->numRows(), 1); flagTable->setText(flagTable->numRows()-1, 0, it.currentKey()); flagTable->setText(flagTable->numRows()-1, 1, it.current()->ascii()); } // Set column 0(1) to be read only flagTable->setColumnReadOnly(0, true); flagTable->adjustColumn(1); }
void TE_Cities::loadCities() { QApplication::setOverrideCursor(Qt::waitCursor); ADB DB; DB.query("select distinct City, State from Addresses where RefFrom = %d", REF_CUSTOMER); if (DB.rowCount) while (DB.getrow()) { (void) new Q3ListViewItem(cityList, DB.curRow["City"], DB.curRow["State"]); } QApplication::restoreOverrideCursor(); }
void BillingCycles::refreshList(int) { ADB DB; Q3ListViewItem *curItem = NULL; // Save the state of the list. list->clear(); DB.query("select CycleID, CycleType, Description from BillingCycles order by CycleID"); if (DB.rowCount) while(DB.getrow()) { curItem = new Q3ListViewItem(list, DB.curRow["CycleID"], DB.curRow["CycleType"], DB.curRow["Description"]); } list->repaint(); }
void LoginTypeReport::refreshReport() { emit(setStatus("Generating report...")); QApplication::setOverrideCursor(waitCursor); ADB DB; char modDate[128]; char isActive[128]; char isPrimary[128]; QDateTime tmpQDT; bool showIt = false; repBody->clear(); DB.query("select Logins.LoginID, Customers.FullName, Logins.LastModified, Logins.Active, Logins.CustomerID, Customers.PrimaryLogin from Logins, Customers where Logins.LoginType = %d and Customers.CustomerID = Logins.CustomerID", loginType); if (DB.rowCount) while (DB.getrow()) { if (!strcmp(DB.curRow["LoginID"], DB.curRow["PrimaryLogin"])) strcpy(isPrimary, "Yes"); else strcpy(isPrimary, "No"); if (atoi(DB.curRow["Active"])) strcpy(isActive, "Yes"); else strcpy(isActive, "No"); tmpQDT = DB.curRow.col("LastModified")->toQDateTime(); sprintf(modDate, "%04d-%02d-%02d", tmpQDT.date().year(), tmpQDT.date().month(), tmpQDT.date().day()); showIt = false; if ((atoi(DB.curRow["Active"])) && showActive) showIt = true; if ((!atoi(DB.curRow["Active"])) && showInactive) showIt = true; if (showIt) { (void) new Q3ListViewItem(repBody, DB.curRow["LoginID"], DB.curRow["FullName"], modDate, isActive, isPrimary, DB.curRow["CustomerID"] ); }; } emit(setStatus("")); QApplication::restoreOverrideCursor(); }
void RatePlanReport::refreshReport() { QApplication::setOverrideCursor(waitCursor); repBody->clear(); char tmpActiveStr[1024]; char tmpInactiveStr[1024]; char *query = new char[65536]; ADB DB; ADB DB2; // Get a list of the rate plans. Then we'll count the customers that // are assigned that rate plan. DB.query("select InternalID, PlanTag, Description from RatePlans"); if (DB.rowCount) { while (DB.getrow()) { // Now, get the number of active customers associated with this // rate plan. DB2.query("select CustomerID from Customers where RatePlan = %s and Active <> 0", DB.curRow["InternalID"]); sprintf(tmpActiveStr, "%6ld", DB2.rowCount); // Now, get the number of INactive customers associated with this // rate plan. DB2.query("select CustomerID from Customers where RatePlan = %s and Active = 0", DB.curRow["InternalID"]); sprintf(tmpInactiveStr, "%6ld", DB2.rowCount); // Now, add the entry into the list, including the last column, // which is not shown, containing the internal ID so we can // zoom in on it. (void) new Q3ListViewItem(repBody, DB.curRow["PlanTag"], DB.curRow["Description"], tmpActiveStr, tmpInactiveStr, DB.curRow["InternalID"]); } } else { (void) new Q3ListViewItem(repBody, "No rate plans found!!!"); } delete query; QApplication::restoreOverrideCursor(); }
void ChangeBillingCycle::saveBillingCycleChange() { CustomersDB CDB; ADB DB; QApplication::setOverrideCursor(waitCursor); CDB.get(myCustID); DB.query("select InternalID from BillingCycles where CycleID = '%s'", (const char *) cycleList->text(cycleList->currentItem())); DB.getrow(); CDB.setValue("BillingCycleDate", effectiveDate->date().toString("yyyy-MM-dd").ascii()); CDB.setValue("BillingCycle", atol(DB.curRow["InternalID"])); CDB.upd(); QApplication::restoreOverrideCursor(); emit(customerUpdated(myCustID)); QMessageBox::information(this, "Rerate warning", "Note that billing cycle changes are not\nrerated automatically. You will need to\nmake any necessary adjustments to the\ncustomers register manually."); close(); }
void DNS_UnmanagedReport::refreshReport() { repBody->clear(); ADB DB; ADB DB2; ADB dnsDB(cfgVal("DNSSQLDB"), cfgVal("DNSSQLUser"), cfgVal("DNSSQLPass"), cfgVal("DNSSQLHost")); char domainName[1024]; char origin[1024]; char domainType[1024]; char isActive[1024]; long counter = 0; DB.query("select * from Domains where Active <> 0"); if (DB.rowCount) while (DB.getrow()) { emit(setProgress(++counter, DB.rowCount)); strcpy(domainType, "Unknown"); strcpy(isActive, ""); // Copy the domain name into a temp string and create the origin // for our remote query. strcpy(domainName, DB.curRow["DomainName"]); strcpy(origin, domainName); strcat(origin, "."); dnsDB.query("select soa.id, ZoneInfo.CustomerID from soa, ZoneInfo where soa.id = ZoneInfo.zoneid and soa.origin = '%s' and ZoneInfo.CustomerID = %ld", origin, atol(DB.curRow["CustomerID"])); if (!dnsDB.rowCount) { // Get the type of domain it is DB2.query("select DomainTypes.DomainType, Domains.InternalID from DomainTypes, Domains where Domains.DomainName = '%s' and DomainTypes.InternalID = Domains.DomainType", domainName); if (DB2.rowCount) { DB2.getrow(); strcpy(domainType, DB2.curRow["DomainType"]); } // Check to see if it is active if (atoi(DB.curRow["Active"])) strcpy(isActive, "Yes"); else strcpy(isActive, "No"); (void) new Q3ListViewItem(repBody, domainName, DB.curRow["LoginID"], domainType, DB.curRow["CustomerID"], isActive); } } }
ChangeBillingCycle::ChangeBillingCycle(QWidget* parent, const char* name, long CustID) : TAAWidget(parent) { setCaption( "Edit Customer Billing Cycle" ); if (!CustID) return; myCustID = CustID; // Create the widgets QLabel *customerLabel = new QLabel("Customer:", this, "customerLabel"); customerLabel->setAlignment(AlignRight|AlignVCenter); customer = new QLabel(this, "customer"); customer->setAlignment(AlignLeft|AlignVCenter); QLabel *cycleListLabel = new QLabel("New Billing Cycle:", this, "cycleListLabel"); cycleListLabel->setAlignment(AlignRight|AlignVCenter); cycleList = new QComboBox(false, this, "cycleList"); QLabel *effectiveDateLabel = new QLabel("Effective Date:", this, "effectiveDateLabel"); effectiveDateLabel->setAlignment(AlignRight|AlignVCenter); effectiveDate = new Q3DateEdit(QDate::currentDate(), this, "effectiveDate"); QPushButton *saveButton = new QPushButton("&Save", this, "saveButton"); connect(saveButton, SIGNAL(clicked()), this, SLOT(saveBillingCycleChange())); QPushButton *cancelButton = new QPushButton("&Save", this, "cancelButton"); connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelBillingCycleChange())); // Our layout. Q3BoxLayout *ml = new Q3BoxLayout(this, Q3BoxLayout::TopToBottom, 3); Q3GridLayout *gl = new Q3GridLayout(2, 3); int curRow = 0; gl->addWidget(customerLabel, curRow, 0); gl->addWidget(customer, curRow, 1); gl->setRowStretch(curRow, 0); curRow++; gl->addWidget(cycleListLabel, curRow, 0); gl->addWidget(cycleList, curRow, 1); gl->setRowStretch(curRow, 0); curRow++; gl->addWidget(effectiveDateLabel, curRow, 0); gl->addWidget(effectiveDate, curRow, 1); gl->setRowStretch(curRow, 0); gl->setColStretch(0, 0); gl->setColStretch(1, 1); ml->addLayout(gl, 0); ml->addStretch(1); Q3BoxLayout *bl = new Q3BoxLayout(Q3BoxLayout::LeftToRight, 3); bl->addStretch(1); bl->addWidget(saveButton, 0); bl->addWidget(cancelButton, 0); ml->addLayout(bl, 0); // Load the list of rate plans. ADB DB; CustomersDB CDB; char tmpStr[1024]; CDB.get(CustID); sprintf(tmpStr, "%s (%ld)", (const char *) CDB.getStr("FullName"), myCustID); customer->setText(tmpStr); DB.query("select CycleID,InternalID from BillingCycles order by CycleID"); while (DB.getrow()) { cycleList->insertItem(DB.curRow["CycleID"]); if (atol(DB.curRow["InternalID"]) == CDB.getLong("BillingCycle")) { cycleList->setCurrentItem(cycleList->count()-1); } } }
void parseFile(const char *SrcFile, const char *DstFile, long CustomerID, const char *LoginID, const char *DomainName) { FParser parser; FILE *dfp; char tmpstr[1024]; QString tmpDst; Q3StrList tmplist(TRUE); QString qst; QString tmpqstr2; char contactName[256]; char phoneNumber[32]; char theDate[64]; QDate theQDate; theQDate = QDate::currentDate(); strcpy(theDate, theQDate.toString()); ADB DB; CustomersDB CDB; LoginsDB LDB; AddressesDB addrDB; ADBTable LTDB; CDB.get(CustomerID); LDB.get(CustomerID, LoginID); LTDB.setTableName("LoginTypes"); LTDB.get(LDB.getLong("LoginType")); strcpy(tmpstr, CDB.getStr("BillingAddress")); addrDB.get(REF_CUSTOMER, CustomerID, tmpstr); // Since there is no default phone number, grab the first one from // the database. strcpy(phoneNumber, ""); DB.query("select PhoneNumber from CustomerContacts where Active <> 0 and CustomerID = %ld", CustomerID); if (DB.rowCount) { DB.getrow(); strcpy(phoneNumber, DB.curRow["PhoneNumber"]); } // fprintf(stderr, "parseFile: Reading File '%s'\n", SrcFile); // If strlen(DstFile) == 0, then generate a temp file name for it. if (!strlen(DstFile)) { tmpDst = makeTmpFileName("/tmp/parsefileXXXXXX"); } else { tmpDst = DstFile; } // Check to see if we have a contact name. if (strlen((const char *)CDB.getStr("ContactName"))) { strcpy(contactName, CDB.getStr("ContactName")); } else { strcpy(contactName, CDB.getStr("FullName")); } parser.set("DomainName", DomainName); parser.set("CompanyName", CDB.getStr("FullName")); parser.set("ContactName", contactName); parser.set("LoginID", LoginID); parser.set("NICName", contactName); parser.set("Addr1", addrDB.Address1); parser.set("Addr2", addrDB.Address2); parser.set("City", addrDB.City); parser.set("State", addrDB.State); parser.set("ZIP", addrDB.ZIP); parser.set("DayPhone", phoneNumber); parser.set("EvePhone", phoneNumber); parser.set("CurrentDate", theDate); parser.set("LoginType", LTDB.getStr("LoginType")); parser.set("LoginTypeD", LTDB.getStr("Description")); // Read in the entire source file. dfp = fopen(tmpDst.toAscii().constData(), "w"); parser.parseFile(SrcFile, dfp); fclose(dfp); }
void salesByServiceReport::refreshReport() { ADB DB; ADB DB2; QDate sDate = this->startDateCal->date(); QDate eDate = this->endDateCal->date(); char tmpStr[1024]; float grandTotal = 0.0; QApplication::setOverrideCursor(waitCursor); repBody->clear(); // Two queries, one for standalone billables, one for packages. DB.query("select AcctsRecv.ItemID, Billables.ItemID, sum(AcctsRecv.Amount) from AcctsRecv, Billables where Billables.ItemNumber = AcctsRecv.ItemID and AcctsRecv.TransType = 0 and AcctsRecv.ItemID > 0 and AcctsRecv.TransDate >= '%04d-%02d-%02d' and AcctsRecv.TransDate <= '%04d-%02d-%02d' group by AcctsRecv.ItemID order by Billables.ItemID", sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day()); if (DB.rowCount) while (DB.getrow()) { //DB2.query("select * from Domains where DomainType = %d and Active > 0", atol(DB.curRow["InternalID"])); //sprintf(tmpStr, "%5d", DB2.rowCount); if (atof(DB.curRow[2]) > 0.0) { new Q3ListViewItem(repBody, DB.curRow[1], DB.curRow[2], DB.curRow[0], // The Item ID "0" // isPackage ); grandTotal += atof(DB.curRow[2]); } } // The seocnd query for packages. DB.query("select AcctsRecv.PackageItem, Packages.PackageTag, sum(AcctsRecv.Amount) from AcctsRecv, Packages where Packages.InternalID = AcctsRecv.PackageItem and AcctsRecv.TransType = 0 and AcctsRecv.ItemID = 0 and AcctsRecv.TransDate >= '%04d-%02d-%02d' and AcctsRecv.TransDate <= '%04d-%02d-%02d' group by Packages.InternalID order by Packages.PackageTag", sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day()); if (DB.rowCount) while (DB.getrow()) { //DB2.query("select * from Domains where DomainType = %d and Active > 0", atol(DB.curRow["InternalID"])); //sprintf(tmpStr, "%5d", DB2.rowCount); sprintf(tmpStr, "%s - Package", DB.curRow[1]); if (atof(DB.curRow[2]) > 0.0) { new Q3ListViewItem(repBody, tmpStr, DB.curRow[2], DB.curRow["PackageItem"], // The Package ID "1" // isPackage ); grandTotal += atof(DB.curRow[2]); } } // One last query to get the stuff in the database prior to 5/1/06 DB.query("select sum(AcctsRecv.Amount) from AcctsRecv where AcctsRecv.TransType = 0 and AcctsRecv.ItemID = 0 and AcctsRecv.PackageItem = 0 and AcctsRecv.TransDate >= '%04d-%02d-%02d' and AcctsRecv.TransDate <= '%04d-%02d-%02d'", sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day()); if (DB.rowCount) while (DB.getrow()) { //DB2.query("select * from Domains where DomainType = %d and Active > 0", atol(DB.curRow["InternalID"])); //sprintf(tmpStr, "%5d", DB2.rowCount); //sprintf(tmpStr, "%s - Package", DB.curRow[1]); if (atof(DB.curRow[0]) > 0.0) { Q3ListViewItem *curItem = new Q3ListViewItem(repBody, "[Unknown Items]", DB.curRow[0] ); grandTotal += atof(DB.curRow[0]); } } sprintf(tmpStr, "%.2f", grandTotal); new Q3ListViewItem(repBody, "Total", tmpStr); sprintf(tmpStr, "Sales by Service\n%02d-%02d-%04d through %02d-%02d-%04d, $%.2f", sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day(), grandTotal); setTitle(tmpStr); QApplication::restoreOverrideCursor(); }
void DomainChecklist::refreshCheckList(void) { ADB DB; DomainsDB DDB; char tmpst[64]; DDB.get(myDomainID); myCustID = DDB.getLong("CustomerID"); customerID->setText(DDB.getStr("CustomerID")); loginID->setText(DDB.getStr("LoginID")); domainName->setText(DDB.getStr("DomainName")); if (strlen(DDB.getStr("LocalSubmit"))) { hostmasterSubmit->setChecked(TRUE); hostmasterSubmit->setEnabled(FALSE); hostmastDate->setText(DDB.getStr("LocalSubmit")); } else { hostmasterSubmit->setChecked(FALSE); hostmasterSubmit->setEnabled(TRUE); hostmastDate->setText(""); } if (strlen(DDB.getStr("NICSubmit"))) { internicSubmit->setChecked(TRUE); internicSubmit->setEnabled(FALSE); nicReqDate->setText(DDB.getStr("NICSubmit")); } else { internicSubmit->setChecked(FALSE); internicSubmit->setEnabled(TRUE); nicReqDate->setText(""); } if (strlen(DDB.getStr("DNSUpdated"))) { dnsDone->setChecked(TRUE); dnsDone->setEnabled(FALSE); dnsDate->setText(DDB.getStr("DNSUpdated")); } else { dnsDone->setChecked(FALSE); dnsDone->setEnabled(TRUE); dnsDate->setText(""); } if (strlen(DDB.getStr("MailSystemUpdated"))) { mailDone->setChecked(TRUE); mailDone->setEnabled(FALSE); mailDate->setText(DDB.getStr("MailSystemUpdated")); } else { mailDone->setChecked(FALSE); mailDone->setEnabled(TRUE); mailDate->setText(""); } if (strlen(DDB.getStr("VirtServerSetup"))) { vserverDone->setChecked(TRUE); vserverDone->setEnabled(FALSE); vserverDate->setText(DDB.getStr("VirtServerSetup")); } else { vserverDone->setChecked(FALSE); vserverDone->setEnabled(TRUE); vserverDate->setText(""); } if (strlen(DDB.getStr("NICCompleted"))) { internicDone->setChecked(TRUE); internicDone->setEnabled(FALSE); nicDoneDate->setText(DDB.getStr("NICCompleted")); } else { internicDone->setChecked(FALSE); internicDone->setEnabled(TRUE); nicDoneDate->setText(""); } if (strlen(DDB.getStr("Released"))) { domainDone->setChecked(TRUE); domainDone->setEnabled(FALSE); doneDate->setText(DDB.getStr("Released")); } else { domainDone->setChecked(FALSE); domainDone->setEnabled(TRUE); doneDate->setText(""); } ipAddress->setText(DDB.getStr("IPAddress")); nicAdminID->setText(DDB.getStr("NICAdminID")); nicBillID->setText(DDB.getStr("NICBillID")); strcpy(tmpst, DDB.getStr("Server")); serverList->clear(); DB.query("select distinct Server from Domains order by Server"); if (DB.rowCount) while (DB.getrow()) { serverList->insertItem(DB.curRow["Server"]); if (!strcmp(tmpst, DB.curRow["Server"])) { serverList->setCurrentItem(serverList->count() - 1); } } strcpy(tmpst, DDB.getStr("SubServer")); processList->clear(); DB.query("select distinct SubServer from Domains order by SubServer"); if (DB.rowCount) while (DB.getrow()) { processList->insertItem(DB.curRow["SubServer"]); // printf("tmpst = '%s', DB.curRow[0] = '%s'\n", tmpst, DB.curRow[0]); if (!strcmp(tmpst, DB.curRow["SubServer"])) { processList->setCurrentItem(processList->count() - 1); } } }
/** * refreshReport() * * Fills the report body with data. */ void salesByServiceDetailReport::refreshReport() { repBody->clear(); if (!myBillableID) return; ADB DB; QDate sDate = this->startDateCal->date(); QDate eDate = this->endDateCal->date(); QString companyName; QString customerName; QString tmpStr; double grandTotal = 0.00; QApplication::setOverrideCursor(waitCursor); if (myIsPackage) { PackagesDB PDB; PDB.get(myBillableID); tmpStr = tmpStr.sprintf("Sales Detail Report\n%s (Package)", PDB.getStr("Description")); setTitle(tmpStr); //debug(1,"select AcctsRecv.TransDate, AcctsRecv.PackageItem, Packages.InternalID, Packages.PackageTag, AcctsRecv.Amount, Customers.CustomerID, Customers.FullName, Customers.ContactName from AcctsRecv, Packages, Customers where Packages.InternalID = AcctsRecv.PackageItem and AcctsRecv.TransType = 0 and AcctsRecv.ItemID = %d and AcctsRecv.TransDate >= '%04d-%02d-%02d' and AcctsRecv.TransDate <= '%04d-%02d-%02d' and Customers.CustomerID = AcctsRecv.CustomerID order by Customers.CustomerID\n", myBillableID, sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day()); DB.query("select AcctsRecv.TransDate, AcctsRecv.PackageItem, Packages.InternalID, Packages.PackageTag, AcctsRecv.Amount, Customers.CustomerID, Customers.FullName, Customers.ContactName from AcctsRecv, Packages, Customers where Packages.InternalID = AcctsRecv.PackageItem and AcctsRecv.TransType = 0 and AcctsRecv.PackageItem = %d and AcctsRecv.TransDate >= '%04d-%02d-%02d' and AcctsRecv.TransDate <= '%04d-%02d-%02d' and Customers.CustomerID = AcctsRecv.CustomerID order by Customers.CustomerID", myBillableID, sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day()); } else { // Get the title. BillablesDB BDB; BDB.get(myBillableID); tmpStr = tmpStr.sprintf("Sales Detail Report\n%s", BDB.getStr("Description")); setTitle(tmpStr); // Two queries, one for standalone billables, one for packages. DB.query("select AcctsRecv.TransDate, AcctsRecv.ItemID, Billables.ItemID, AcctsRecv.Amount, AcctsRecv.StatementNo, Customers.CustomerID, Customers.FullName, Customers.ContactName from AcctsRecv, Billables, Customers where Billables.ItemNumber = AcctsRecv.ItemID and AcctsRecv.TransType = 0 and AcctsRecv.ItemID = %d and AcctsRecv.PackageItem = 0 and AcctsRecv.TransDate >= '%04d-%02d-%02d' and AcctsRecv.TransDate <= '%04d-%02d-%02d' and Customers.CustomerID = AcctsRecv.CustomerID order by Customers.CustomerID", myBillableID, sDate.year(), sDate.month(), sDate.day(), eDate.year(), eDate.month(), eDate.day()); } // Both queries return compatible result sets for a single pass // through the returned rows. if (DB.rowCount) while (DB.getrow()) { customerName = ""; companyName = ""; // Check for a company name. if (strlen(DB.curRow["ContactName"])) { customerName = DB.curRow["ContactName"]; companyName = DB.curRow["FullName"]; } else { customerName = DB.curRow["FullName"]; } new Q3ListViewItem(repBody, DB.curRow["TransDate"], DB.curRow["Amount"], DB.curRow["CustomerID"], customerName, companyName, DB.curRow["StatementNo"] ); grandTotal += atof(DB.curRow["Amount"]); } tmpStr = tmpStr.sprintf("%.2f", grandTotal); new Q3ListViewItem(repBody, "Total", tmpStr); QApplication::restoreOverrideCursor(); }
void TE_Main::sendMessage() { int doIt = 0; if (!tmessage->messageOk()) { QMessageBox::information(this, "Targeted Email", "The message is not complete.\nComplete the message before sending."); return; } // Find out if the user is really ready to do this... switch(QMessageBox::information(this, "Send Targeted Email", "Are you sure you wish to send this email?", "&Yes", "&No", "&Cancel", 0, // Enter == button 0, yes 2 // Escape == cancel, button 2 )) { case 0: // Yes, do it. doIt = 1; break; case 1: doIt = 0; break; default: // Cancel, close the window. close(); break; } if (doIt) { QApplication::setOverrideCursor(Qt::waitCursor); emit(setStatus("Sending targeted email...")); char srcfile[1024]; char dstfile[1024]; ADB DB; ADB DB2; CustomersDB CDB; int curStep = 0; int totSteps = 0; int hitCount = 0; int reqHits = 3; DB.query("select LoginID, LoginType, CustomerID, Active from Logins where Wiped < '1970-01-01'"); if (DB.rowCount) { strcpy(srcfile, tmessage->createMessage()); totSteps = DB.rowCount; while (DB.getrow()) { emit(setProgress(curStep++, totSteps)); hitCount = 0; hitCount += tlogins->isIncluded(atol(DB.curRow["LoginType"]), atoi(DB.curRow["Active"])); if (tcities->allCities()) hitCount++; else { // Load the City for the customer. DB2.query("select City from Addresses where RefFrom = %d and RefID = %ld", REF_CUSTOMER, atol(DB.curRow["CustomerID"])); if (DB2.rowCount) { DB2.getrow(); hitCount += tcities->isIncluded(DB2.curRow["LoginID"]); } } // Check for primary login only. if (tlogins->primaryOnly()) { CDB.get(atol(DB.curRow["CustomerID"])); if (!strcmp(CDB.getStr("PrimaryLogin"), DB.curRow["LoginID"])) hitCount++; } else { // All logins are being sent this email. hitCount++; } if (hitCount == reqHits) { // Send the message sprintf(dstfile, "/var/spool/taamail/TE-%s-%s-%s", DB.curRow["LoginID"], DB.curRow["LoginType"], DB.curRow["CustomerID"]); parseFile(srcfile, dstfile, atol(DB.curRow["CustomerID"]), DB.curRow["LoginID"], ""); } } // Remove the source file. unlink(srcfile); } emit(setStatus("")); QApplication::restoreOverrideCursor(); close(); } }
void CustomerSearch::startSearch() { ADB DB; ADB DB2; ADBTable custDB("Customers"); char tmpstr[4096]; int rowcnt = 0; int curRow = 0; long curCustID = 0; bool allLoaded = false; QString tmpsub; tmpsub = ""; char *isActive = new char[64]; // Change the cursor to an hourglass QApplication::setOverrideCursor(Qt::WaitCursor); emit(setStatus("Searching...")); // Save the state of the list. Q3ListViewItem *tmpCur; tmpCur = custList->currentItem(); emit(customerHighlighted(0)); custList->clear(); // Clear our map of loaded customers as well. loadedCusts.clear(); tmpsub = searchText->text(); QApplication::restoreOverrideCursor(); // If there is no query at all, simply return since the // list is now empty. if (!tmpsub.length()) return; QApplication::setOverrideCursor(Qt::WaitCursor); // First query. CustomerID if (tmpsub.toLong()) { // They specified a customer ID. Check for it DB.query("select CustomerID from Customers where CustomerID = %ld", tmpsub.toLong()); rowcnt = DB.rowCount; if (rowcnt) { while (DB.getrow()) { curCustID = atol(DB.curRow["CustomerID"]); // Load them into our loadedCusts map if (loadedCusts[curCustID] != curCustID) loadedCusts.insert(curCustID, curCustID); } } } // Check to see if the user specified a search string. // If they didn't, load the whole list. if (!rowcnt) { if (!strlen((const char *)tmpsub)) { DB.query("select CustomerID from Customers"); rowcnt = DB.rowCount; if (rowcnt) { while (DB.getrow()) { curCustID = atol(DB.curRow["CustomerID"]); // Load them into our loadedCusts map if (loadedCusts[curCustID] != curCustID) loadedCusts.insert(curCustID, curCustID); } } allLoaded = true; } } // Second query. LoginID if (!allLoaded) { DB.query("select CustomerID from Logins where LoginID = '%s'", (const char *) tmpsub); rowcnt = DB.rowCount; if (rowcnt) { while (DB.getrow()) { curCustID = atol(DB.curRow["CustomerID"]); // Load them into our loadedCusts map if (loadedCusts[curCustID] != curCustID) loadedCusts.insert(curCustID, curCustID); } } } // Third query. Customers.FullName or Customers.ContactName if (!allLoaded) { DB.query("select distinct CustomerID from Customers where FullName LIKE '%%%%%s%%%%' or ContactName LIKE '%%%%%s%%%%'", (const char *) tmpsub, (const char *) tmpsub); rowcnt = DB.rowCount; if (rowcnt) { while (DB.getrow()) { curCustID = atol(DB.curRow["CustomerID"]); // Load them into our loadedCusts map if (loadedCusts[curCustID] != curCustID) loadedCusts.insert(curCustID, curCustID); } } } // Fourth query. Logins.LoginID or Logins.ContactName if (!allLoaded) { DB.query("select distinct CustomerID from Logins where LoginID LIKE '%%%%%s%%%%' or ContactName LIKE '%%%%%s%%%%'", (const char *) tmpsub, (const char *) tmpsub); rowcnt = DB.rowCount; if (rowcnt) { while (DB.getrow()) { curCustID = atol(DB.curRow["CustomerID"]); // Load them into our loadedCusts map if (loadedCusts[curCustID] != curCustID) loadedCusts.insert(curCustID, curCustID); } } } if (loadedCusts.count()) { // One of our queries matched. DB will have a query full of // Customer IDs. We run several other queries on this one // to get the entire customer record for them. emit(setStatus("Loading matching customers...")); loadedCustMap::Iterator it; for (it = loadedCusts.begin(); it != loadedCusts.end(); ++it) { emit(setProgress(++curRow, rowcnt)); custDB.get(it.data()); sprintf(tmpstr, "%s", custDB.getStr("FullName")); if (strlen(custDB.getStr("ContactName"))) { strcat(tmpstr, "/"); strcat(tmpstr, custDB.getStr("ContactName")); } if (custDB.getInt("Active")) strcpy(isActive, "Yes"); else strcpy(isActive, "No"); // Create the parent record. tmpCur = new Q3ListViewItem(custList, tmpstr, // FullName/Contact Name custDB.getStr("PrimaryLogin"), custDB.getStr("CustomerID"), custDB.getStr("CurrentBalance"), isActive // Active ); // Get any child records. DB2.query("select ContactName, LoginID, Active from Logins where CustomerID = %ld", custDB.getLong("CustomerID")); if (DB2.rowCount) while (DB2.getrow()) { // Make sure that we're not re-loading the primary login if (strcmp(custDB.getStr("PrimaryLogin"), DB2.curRow["LoginID"])) { if (atoi(DB2.curRow["Active"])) strcpy(isActive, "Yes"); else strcpy(isActive, "No"); (void) new Q3ListViewItem(tmpCur, DB2.curRow["ContactName"], DB2.curRow["LoginID"], custDB.getStr("CustomerID"), "", isActive ); } } } emit(setStatus("")); } emit(setStatus("")); // Searching... // emit(refreshTabs(1)); QApplication::restoreOverrideCursor(); }
void DomainAliases::addAlias() { // First, make sure that there are no invalid characters in the // address. QRegExp rexp("[^a-z0-9_.-]", false); if (rexp.indexIn(address->text()) >= 0) { // Found a bad character. QMessageBox::warning(this, "Domain Alias", "Invalid character in address.\nOnly the characters a-z, A-Z, 0-9, '-', '_' and '.' are allowed."); return; } // The address must start with an alpha-numeric character rexp.setPattern("^[a-z0-9]+[^a-z0-9_.-]*"); if (address->text().length() && rexp.indexIn(address->text())) { // Found a bad character. QMessageBox::warning(this, "Domain Alias", "The first character of an\nalias must be alphanumeric."); return; } // Now, make sure the address isn't blank. if (address->text().length() == 0) { // The address is empty. Ask the user if they want to do an // all-mail/default setup. char tmpStr[1024]; sprintf(tmpStr, "An address was not specified.\n\nDid you want to set a default entry so any non-specific\nmatching address for %s\nwill be delivered to %s?", (const char *) domainList->currentText(), (const char *) loginList->currentText()); if (QMessageBox::warning(this, "Domain Alias", tmpStr, "&Yes", "&No", 0, 1)) return; // Make sure there is not already a default entry... } char fullAddr[1024]; char tmpAddr[1024]; if (address->text().length()) sprintf(fullAddr, "%s@%s", (const char *)address->text(), (const char *)domainList->currentText()); else sprintf(fullAddr, "@%s", (const char *)domainList->currentText()); // Make sure this alias doesn't already exist. QApplication::setOverrideCursor(Qt::waitCursor); ADBTable mailDB("Virtual", cfgVal("MailSQLDB"), cfgVal("MailSQLUser"), cfgVal("MailSQLPass"), cfgVal("MailSQLHost")); mailDB.query("select * from Virtual where Address = '%s'", fullAddr); QApplication::restoreOverrideCursor(); if (mailDB.rowCount) { // That alias already exists. QMessageBox::warning(this, "Domain Alias", "That address is already mapped."); return; } // If we made it here, we're good to go. char timedate[128]; long tmpCustID = myCustID; // Check to see if we need to lookup the customer ID. This will // be keyed on the login. if (!tmpCustID) { ADB tmpDB; tmpDB.query("select CustomerID from Logins where LoginID = '%s'", (const char *) loginList->currentText()); tmpDB.getrow(); tmpCustID = atol(tmpDB.curRow["CustomerID"]); } QDateTime cd = QDateTime::currentDateTime(); sprintf(timedate, "%04d-%02d-%02d %02d:%02d:%02d", cd.date().year(), cd.date().month(), cd.date().day(), cd.time().hour(), cd.time().minute(), cd.time().second() ); mailDB.clearData(); mailDB.setValue("CustomerID", tmpCustID); mailDB.setValue("AliasDate", timedate); mailDB.setValue("AddedBy", curUser().userName); mailDB.setValue("Address", fullAddr); mailDB.setValue("Mailbox", (const char *) loginList->currentText()); QApplication::setOverrideCursor(Qt::waitCursor); mailDB.ins(); if (address->text().length()) strcpy(tmpAddr, (const char *) address->text()); else strcpy(tmpAddr, "[Any Address]"); (void) new Q3ListViewItem(aliasList, tmpAddr, domainList->currentText(), loginList->currentText(), timedate, curUser().userName, mailDB.getStr("VirtualID") ); address->clear(); address->setFocus(); // We'll sneak this in here, too. We need to have an entry in there for // the domain by itself so that Postfix knows that the domain is okay to // accept email for. We need to get all of the domains that we take email // for and add them into the system. ADB DB; char addedBy[1024]; sprintf(addedBy, "%s (Auto)", curUser().userName); DB.query("select Domains.DomainName from Domains, DomainTypes where Domains.CustomerID = %ld and Domains.Active > 0 and Domains.DomainType = DomainTypes.InternalID and DomainTypes.AllowAliases > 0 order by DomainName", myCustID); if (DB.rowCount) while (DB.getrow()) { mailDB.query("select * from Virtual where Address = '%s' and Mailbox = '%s'", DB.curRow["DomainName"], DB.curRow["DomainName"]); if (!mailDB.rowCount) { // Wasn't found. Add it. mailDB.clearData(); mailDB.setValue("CustomerID", myCustID); mailDB.setValue("AliasDate", timedate); mailDB.setValue("AddedBy", addedBy); mailDB.setValue("Address", DB.curRow["DomainName"]); mailDB.setValue("Mailbox", DB.curRow["DomainName"]); mailDB.ins(); } } QApplication::restoreOverrideCursor(); }
void DomainAliases::setCustomerID(long custID) { QApplication::setOverrideCursor(Qt::waitCursor); myCustID = custID; char AddrPart[1024]; char DomainPart[1024]; __gnu_cxx::StrSplitMap parts; ADB domainDB; ADB mailDB(cfgVal("MailSQLDB"), cfgVal("MailSQLUser"), cfgVal("MailSQLPass"), cfgVal("MailSQLHost")); aliasList->clear(); if (mailDB.Connected()) { if (!myCustID) mailDB.query("select * from Virtual"); else { char sqlstr[65536]; sprintf(sqlstr, "select * from Virtual where CustomerID = %ld", myCustID); // Now, walk through the domains for this customer and get any // mailboxes from other customers that might be mapped. domainDB.query("select Domains.DomainName from Domains, DomainTypes where Domains.CustomerID = %ld and Domains.Active > 0 and Domains.DomainType = DomainTypes.InternalID and DomainTypes.AllowAliases > 0 order by DomainName", myCustID); if (domainDB.rowCount) while (domainDB.getrow()) { strcat(sqlstr, " or Address LIKE '%%@"); strcat(sqlstr, domainDB.curRow["DomainName"]); strcat(sqlstr, "'"); } mailDB.query(sqlstr); } if (mailDB.rowCount) while (mailDB.getrow()) { char mbstr[1024]; StrSplit(mailDB.curRow["Address"], "@", parts); strcpy(AddrPart, parts[0].c_str()); strcpy(DomainPart, parts[1].c_str()); if (!strlen(AddrPart)) strcpy(AddrPart, "[Any Address]"); // Check to see if the mailbox is a different customer, if so // note that in the list strcpy(mbstr, mailDB.curRow["Mailbox"]); if (atol(mailDB.curRow["CustomerID"]) != custID) { strcat(mbstr, " ("); strcat(mbstr, mailDB.curRow["CustomerID"]); strcat(mbstr, ")"); } // Add it to the list now. // Make sure it isn't the "special" mapped so Postfix knows // how to handle the domain and not give "mail loops back to // myself" errors. if (strcmp(mailDB.curRow["Mailbox"], mailDB.curRow["Address"])) { (void) new Q3ListViewItem(aliasList, AddrPart, DomainPart, mbstr, mailDB.curRow["AliasDate"], mailDB.curRow["AddedBy"], mailDB.curRow["VirtualID"] ); } } } // Now that the list is populated, populate the list of domains // for this customer. domainList->clear(); if (!myCustID) domainDB.query("select Domains.DomainName from Domains, DomainTypes where Domains.Active > 0 and Domains.DomainType = DomainTypes.InternalID and DomainTypes.AllowAliases > 0 order by DomainName"); else domainDB.query("select Domains.DomainName from Domains, DomainTypes where Domains.CustomerID = %ld and Domains.Active > 0 and Domains.DomainType = DomainTypes.InternalID and DomainTypes.AllowAliases > 0 order by DomainName", myCustID); if (domainDB.rowCount) while (domainDB.getrow()) { domainList->insertItem(domainDB.curRow["DomainName"]); } // Now populate the list of logins. loginList->clear(); if (!myCustID) domainDB.query("select * from Logins where Active > 0 order by LoginID"); else domainDB.query("select * from Logins where CustomerID = %ld and Active > 0 order by LoginID", myCustID); if (domainDB.rowCount) while (domainDB.getrow()) { loginList->insertItem(domainDB.curRow["LoginID"]); } // If we don't have a customer ID, disable the Auto button if (!myCustID) autoButton->setEnabled(false); else autoButton->setEnabled(true); QApplication::restoreOverrideCursor(); }
void Tab_Logins::unlockLogin(void) { char tmpstr[256]; char tmpLogin[256]; char subj[4096]; char body[4096]; Q3ListViewItem *curItem; curItem = list->currentItem(); if (curItem != NULL) { QApplication::setOverrideCursor(WaitCursor); ADB DB; BrassClient *BC; LoginsDB LDB; CustomersDB CDB; SubscriptionsDB SDB; LDB.get(myCustID, (const char *) curItem->text(0)); // First, check to see if this account has been wiped already. // If so, let the user know and exit. strcpy(tmpstr, LDB.getStr("Wiped")); if (strcmp(tmpstr, "0000-00-00")) { QApplication::restoreOverrideCursor(); QMessageBox::warning(this, "Unable to set flag.", "The selected login has been wiped, and no longer exists on the system."); return; } else { // Okay, we aren't wiped, so check to see if this account is // Active or not. If its active, lock it. If its inactive, // unlock it. // First, authenticate with the Brass server. BC = new BrassClient(); if (!BC->Connect()) { QApplication::restoreOverrideCursor(); QString tmpQES; tmpQES = "Error connecting to BRASS server "; tmpQES += cfgVal("BrassHost"); QMessageBox::critical(this, "BRASS Error", tmpQES); delete BC; return; } else { if (!BC->Authenticate()) { QApplication::restoreOverrideCursor(); QString tmpQES; tmpQES = "Error authenticating with BRASS server "; tmpQES += cfgVal("BrassHost"); QMessageBox::critical(this, "BRASS Error", tmpQES); delete BC; return; } } // If we've made it here, we're connected to the server. strcpy(tmpLogin, LDB.getStr("LoginID")); if (LDB.getInt("Active")) { // We are active, lock the account. sprintf(tmpstr, "Lock account '%s'\n\nAre you sure?", tmpLogin); QApplication::restoreOverrideCursor(); if (QMessageBox::warning(this, "Lock Account", tmpstr, "&Yes", "&No", 0, 1) == 0) { QApplication::setOverrideCursor(WaitCursor); if (!BC->LockUser(tmpLogin)) { QApplication::restoreOverrideCursor(); // We were unsuccessful. sprintf(tmpstr, "Unable to lock the account.\n\n%s", BC->ResponseStr(NULL)); QMessageBox::critical(this, "BRASS Error", tmpstr); } else { LDB.setValue("Active", (int) 0); LDB.upd(); // Now, update the subscriptions for this login ID. DB.query("select InternalID from Subscriptions where CustomerID = %ld and LoginID = '%s'", myCustID, tmpLogin); if (DB.rowCount) while (DB.getrow()) { SDB.get(atol(DB.curRow["InternalID"])); SDB.setValue("Active", (int) 0); SDB.upd(); } // And create a note for this transaction. NotesDB NDB; NDB.setValue("LoginID", tmpLogin); NDB.setValue("CustomerID", myCustID); NDB.setValue("AutoNote", 1); NDB.setValue("NoteType", "Operator"); NDB.setValue("Subject", "Login Locked"); NDB.setValue("NoteText", "Login Locked."); NDB.ins(); // Email the administrators with the change. sprintf(subj, "Login Locked %s", tmpLogin); sprintf(body, " Customer ID: %ld\n Login ID: %s\n\n Locked by: %s", myCustID, tmpLogin, curUser().userName); emailAdmins(subj, body); // Now, update the AR for the lock. if (isManager()) { QApplication::restoreOverrideCursor(); if (QMessageBox::warning(this, "Prorate Charges", "Do you wish to prorate the charges for this login?", "&Yes", "&No", 0, 1) == 0) { QApplication::setOverrideCursor(WaitCursor); updateARForLock(tmpLogin); } else { QApplication::setOverrideCursor(WaitCursor); } } emit(customerUpdated(myCustID)); refreshLoginList(myCustID); recountAllowedMailboxes(myCustID); QApplication::restoreOverrideCursor(); } } } else { if (!BC->UnLockUser(tmpLogin)) { // We were unsuccessful. QApplication::restoreOverrideCursor(); sprintf(tmpstr, "Unable to unlock the account.\n\n%s", BC->ResponseStr(NULL)); QMessageBox::critical(this, "BRASS Error", tmpstr); } else { LDB.setValue("Active", (int) 1); LDB.upd(); // Now, update the subscriptions for this login ID. DB.query("select InternalID from Subscriptions where CustomerID = %ld and LoginID = '%s'", myCustID, tmpLogin); if (DB.rowCount) while (DB.getrow()) { SDB.get(atol(DB.curRow["InternalID"])); SDB.setValue("Active", (int) 1); SDB.upd(); } // And create a note for this transaction. NotesDB NDB; NDB.setValue("LoginID", tmpLogin); NDB.setValue("CustomerID", myCustID); NDB.setValue("AutoNote", 1); NDB.setValue("NoteType", "Operator"); NDB.setValue("Subject", "Login Unlocked"); NDB.setValue("NoteText", "Login Unlocked."); NDB.ins(); // Email the administrators with the change. sprintf(subj, "Login Unlocked %s", tmpLogin); sprintf(body, " Customer ID: %ld\n Login ID: %s\n\n Unlocked by: %s", myCustID, tmpLogin, curUser().userName); emailAdmins(subj, body); // Now, update the AR for the lock. updateARForLock(tmpLogin); // And update their subscriptions. CDB.get(myCustID); CDB.doSubscriptions(); recountAllowedMailboxes(myCustID); emit(customerUpdated(myCustID)); refreshLoginList(myCustID); QApplication::restoreOverrideCursor(); } } delete BC; } } }
void BandwidthUsageReport::refreshReport() { if (!strlen(myLoginID)) return; QApplication::setOverrideCursor(waitCursor); repBody->clear(); char sDate[64]; char eDate[64]; char *query = new char[65536]; char tmpStr[2048]; char inStr[1024]; char outStr[1024]; char totStr[1024]; char dateStr[1024]; int totCons = 0; int curDay = 0; int daysInReport = 0; llong lastIn = (llong) 0; llong lastOut = (llong) 0; llong bytesIn = (llong) 0; llong currIn = (llong) 0; llong currOut = (llong) 0; llong bytesOut= (llong) 0; llong grandTotal = (llong) 0; QDate sampDate; ADB DB; if (inDays != NULL) { delete inDays; inDays = NULL; } if (outDays != NULL) { delete outDays; outDays = NULL; } if (totDays != NULL) { delete totDays; totDays = NULL; } sprintf(tmpStr, "Bandwidth Usage Report for '%s'", myLoginID); reportTitle->setText(tmpStr); // Get the starting and ending dates. sprintf(sDate, "%04d-%02d-%02d", startDate().year(), startDate().month(), startDate().day()); sprintf(eDate, "%04d-%02d-%02d", endDate().year(), endDate().month(), endDate().day()); DB.query("select SampleDate, SampleTime, OctetsIn, OctetsOut from TrafficUsage where LoginID = '%s' and SampleDate >= '%s' and SampleDate <= '%s' order by SampleDate, SampleTime", myLoginID, sDate, eDate ); if (DB.rowCount) { // Calculate the number of days in our report. daysInReport = startDate().daysTo(endDate()) + 1; inDays = new llong[daysInReport]; outDays = new llong[daysInReport]; totDays = new llong[daysInReport]; for (int i = 0; i < daysInReport; i++) { inDays[i] = (llong) 0; outDays[i] = (llong) 0; totDays[i] = (llong) 0; } totCons = DB.rowCount; while (DB.getrow()) { // We walk through the samples and add to to our totals, provided // that the last sample is less than the current sample. If the // last sample is less than the current sample, this indicates // that our router counter wrapped, or the router rebooted. // So, we give the customer some bandwidth for free... // Get the sample date. myDatetoQDate(DB.curRow["SampleDate"], &sampDate); curDay = startDate().daysTo(sampDate); currIn = atoll(DB.curRow["OctetsIn"]); currOut = atoll(DB.curRow["OctetsOut"]); if (currIn > lastIn && (lastIn)) { bytesIn = currIn - lastIn; } else { bytesIn = (llong) 0; } if (currOut > lastOut && (lastOut)) { bytesOut = currOut - lastOut; } else { bytesOut = (llong) 0; } inDays[curDay] += bytesIn; totDays[curDay] += bytesIn; outDays[curDay] += bytesOut; totDays[curDay] += bytesOut; lastIn = currIn; lastOut = currOut; } // Okay, now, go through each of the days in the month and insert // a report item for it, giving a grand total at the end. for (int i = 0; i < daysInReport; i++) { sampDate = startDate().addDays(i); sprintf(dateStr, "%04d-%02d-%02d", sampDate.year(), sampDate.month(), sampDate.day()); sprintf(inStr, "%.2f", inDays[i] / BW_MBYTE); sprintf(outStr, "%.2f", outDays[i] / BW_MBYTE); sprintf(totStr, "%.2f", totDays[i] / BW_MBYTE); grandTotal += totDays[i]; (void) new Q3ListViewItem(repBody, dateStr, inStr, outStr, totStr ); } // Now, put the grand totals in the display. sprintf(tmpStr, "Bandwidth Usage Report for '%s'\nTotal Transfer = %.2fMB (%.2fGB)", myLoginID, grandTotal / BW_MBYTE, grandTotal / (BW_MBYTE * 1024) ); reportTitle->setText(tmpStr); } else { (void) new Q3ListViewItem(repBody, "No data for specified period"); } delete query; QApplication::restoreOverrideCursor(); }
/** * getCustomerAgingData() * * Utility function that returns the AR Aging data * for the specified customer ID. * * currentBalance = The customer's current balance, including all charges and payments * totalOverdue = What portion of the currentBalance is overdue * currentDue = What portion of the currentBalance is not overdue * overdue = Amount overdue between 0 and 30 days * overdue30 = Amunt overdue between 31 and 60 days * overdue60 = Amount overdue between 61 and 90 days * overdue90 = Amount overdue 91 days or greater. */ const customerARAgingRecord getCustomerAgingData(long custID) { customerARAgingRecord retVal; ADB DB; // Set our return values retVal.customerID = 0; retVal.currentBalance = 0.00; retVal.totalOverdue = 0.00; retVal.currentDue = 0.00; retVal.overdue = 0.00; retVal.overdue30 = 0.00; retVal.overdue60 = 0.00; retVal.overdue90 = 0.00; DB.query("select CurrentBalance from Customers where CustomerID = %ld", custID); if (!DB.rowCount) return retVal; DB.getrow(); retVal.customerID = custID; retVal.currentBalance = atof(DB.curRow["CurrentBalance"]); if (retVal.currentBalance == 0.00) return retVal; // If we've made it here, we have a customer with a balance QDate today = QDate::currentDate(); QDate dueDate = QDate::currentDate(); QString dueDateSt; DB.query("select Amount, ClearedAmount, DueDate from AcctsRecv where CustomerID = %ld and DueDate <> '0000-00-00' and ClearedAmount <> Amount", custID); if (DB.rowCount) while (DB.getrow()) { double amount = 0.00; double cleared = 0.00; double diff = 0.00; int days = 0; dueDateSt = DB.curRow["DueDate"]; myDateToQDate(dueDateSt.ascii(), dueDate); amount = atof(DB.curRow["Amount"]); cleared = atof(DB.curRow["ClearedAmount"]); diff = amount - cleared; days = dueDate.daysTo(today); if (days > 90) { retVal.overdue90 += diff; retVal.totalOverdue += diff; } else if (days > 60) { retVal.overdue60 += diff; retVal.totalOverdue += diff; } else if (days > 30) { retVal.overdue30 += diff; retVal.totalOverdue += diff; } else if (days >= 1) { retVal.overdue += diff; retVal.totalOverdue += diff; } else { // else its not overdue yet, don't necessarily add them retVal.currentDue += diff; } } return retVal; }
void LoginCountReport::refreshReport() { ADB DB; ADB DB2; char tmpst1[1024]; char tmpst2[1024]; char tmpst3[1024]; char tmpst4[1024]; long activeCount = 0; long inactiveCount = 0; long curActiveCount = 0; long curInactiveCount = 0; long curSystemCount = 0; long systemCount = 0; int rowCount = 0; char rowCountSt[1024]; char todayStr[1024]; char typeStr[1024]; sprintf(todayStr, "As of %s", (const char *) QDateTime::currentDateTime().toString()); /* FParser parser; parser.set("Title", "Login Count Report"); parser.set("ReportDate", todayStr); */ QApplication::setOverrideCursor(waitCursor); // Set the sorting to a hidden column. repBody->setSorting(6); repBody->clear(); DB.query("select InternalID, LoginType, Description from LoginTypes order by LoginType"); if (DB.rowCount) while (DB.getrow()) { sprintf(rowCountSt, "%05d", rowCount++); sprintf(typeStr, DB.curRow["InternalID"]); DB2.query("select InternalID from Logins where LoginType = %d and Active <> 0 and Wiped = 0 and CustomerID >= 100", atoi(DB.curRow["InternalID"])); curActiveCount = DB2.rowCount; activeCount += curActiveCount; DB2.query("select InternalID from Logins where LoginType = %d and Active = 0 and Wiped = 0 and CustomerID >= 100", atoi(DB.curRow["InternalID"])); curInactiveCount = DB2.rowCount; inactiveCount += curInactiveCount; DB2.query("select InternalID from Logins where LoginType = %d and CustomerID < 100", atoi(DB.curRow["InternalID"])); curSystemCount = DB2.rowCount; systemCount += curSystemCount; // Add the columns. sprintf(tmpst1, "%ld", curActiveCount); sprintf(tmpst2, "%ld", curInactiveCount); sprintf(tmpst3, "%ld", curSystemCount); sprintf(tmpst4, "%ld", curActiveCount + curInactiveCount); /* parser.addRow("ReportData"); parser.addColumn("LoginType", DB.curRow["LoginType"]); parser.addColumn("Description", DB.curRow["Description"]); parser.addColumn("ActiveCount", tmpst1); parser.addColumn("InactiveCount", tmpst2); parser.addColumn("SystemCount", tmpst3); parser.addColumn("TotalCount", tmpst4); */ (void) new Q3ListViewItem(repBody, DB.curRow["LoginType"], DB.curRow["Description"], tmpst1, tmpst2, tmpst3, tmpst4, rowCountSt, DB.curRow["InternalID"]); } // Add the totals. sprintf(rowCountSt, "%05d", rowCount++); sprintf(tmpst1, "%ld", activeCount); sprintf(tmpst2, "%ld", inactiveCount); sprintf(tmpst3, "%ld", systemCount); sprintf(tmpst4, "%ld", activeCount + inactiveCount); /* parser.set("TotalActive", tmpst1); parser.set("TotalInactive", tmpst2); parser.set("TotalSystem", tmpst3); parser.set("GrandTotal", tmpst4); */ (void) new Q3ListViewItem(repBody, "TOTAL", "", tmpst1, tmpst2, tmpst3, tmpst4); /* char fName[4096]; strcpy(fName, cfgVal("ReportPath")); strcpy(fName, "/usr/local/lib/taa/reports/LoginCount.tmpl"); body->setText(parser.parseFileToMem(fName)); */ QApplication::restoreOverrideCursor(); }
void RateCenterManager::refreshRateCenters() { ADB myDB; ADB myDB2; ADB myDB3; ADB myDB4; char availStr[1024]; char activeStr[1024]; char totalStr[1024]; long avail; long active; long total; Q3ListViewItem *curItem; long curID = -1; // Get the ID of the currently hilighted item. Q3ListViewItem *tmpCur; tmpCur = rcList->currentItem(); if (tmpCur) { if (strlen(tmpCur->key(idColumn,0))) { curID = atol(tmpCur->key(idColumn,0)); } } QApplication::setOverrideCursor(Qt::waitCursor); rcList->clear(); // Get the list of countries myDB.query("select distinct(Country) from DID_Rate_Centers"); if (myDB.rowCount) { // Walk through the list of countries and get the states while(myDB.getrow()) { Q3ListViewItem *countryItem = new Q3ListViewItem(rcList, myDB.curRow["Country"], "", "", "", "0"); myDB2.query("select distinct(State) from DID_Rate_Centers where Country = '%s' order by State", myDB.curRow["Country"]); // No need to check if they exist since a state can't exist without a country. while (myDB2.getrow()) { Q3ListViewItem *stateItem = new Q3ListViewItem(countryItem, myDB2.curRow["State"], "", "", "", "0"); myDB3.query("select City, RateCenterID from DID_Rate_Centers where Country = '%s' and State = '%s' order by City", myDB.curRow["Country"], myDB2.curRow["State"]); while (myDB3.getrow()) { myDB4.query("select count(DID) from DID_Inventory where RateCenterID = %s", myDB3.curRow["RateCenterID"]); myDB4.getrow(); total = atol(myDB4.curRow[0]); myDB4.query("select count(DID) from DID_Inventory where RateCenterID = %s and CustomerID > 0", myDB3.curRow["RateCenterID"]); myDB4.getrow(); active = atol(myDB4.curRow[0]); myDB4.query("select count(DID) from DID_Inventory where RateCenterID = %s and CustomerID = 0 and Reserved = 0", myDB3.curRow["RateCenterID"]); myDB4.getrow(); avail = atol(myDB4.curRow[0]); sprintf(availStr, "%ld", avail); sprintf(activeStr, "%ld", active); sprintf(totalStr, "%ld", total); Q3ListViewItem *curItem = new Q3ListViewItem(stateItem, myDB3.curRow["City"], activeStr, availStr, totalStr, myDB3.curRow["RateCenterID"]); if (atol(myDB3.curRow["RateCenterID"]) == curID) { countryItem->setOpen(true); stateItem->setOpen(true); rcList->setCurrentItem(curItem); rcList->ensureItemVisible(curItem); } } // Count the children of this item and total up the DID counts curItem = stateItem->firstChild(); active = 0; avail = 0; total = 0; while (curItem) { active += atol(curItem->key(activeColumn, 0)); avail += atol(curItem->key(availColumn, 0)); total += atol(curItem->key(totalColumn, 0)); curItem = curItem->nextSibling(); } sprintf(availStr, "%ld", avail); sprintf(activeStr, "%ld", active); sprintf(totalStr, "%ld", total); stateItem->setText(activeColumn, activeStr); stateItem->setText(availColumn, availStr); stateItem->setText(totalColumn, totalStr); } // Count the children of this item and total up the DID counts curItem = countryItem->firstChild(); active = 0; avail = 0; total = 0; while (curItem) { active += atol(curItem->key(activeColumn, 0)); avail += atol(curItem->key(availColumn, 0)); total += atol(curItem->key(totalColumn, 0)); curItem = curItem->nextSibling(); } sprintf(availStr, "%ld", avail); sprintf(activeStr, "%ld", active); sprintf(totalStr, "%ld", total); countryItem->setText(activeColumn, activeStr); countryItem->setText(availColumn, availStr); countryItem->setText(totalColumn, totalStr); } } // Check to see if we had a hilighted item, if so, find it again. QApplication::restoreOverrideCursor(); }
void Tab_Logins::refreshLoginList(long) { ADB DB; QString tmpstr = ""; QString tmpQItemID = ""; QString tmpQActive = ""; QString qds; ADB DB2; bool showIt = true; char isActive[128]; char dateStamp[128]; QDate d; QTime t; list->clear(); DB.query("select Logins.LoginID, LoginTypes.LoginType, Logins.ContactName, Logins.LastModified, Logins.DiskSpace, Logins.DialupChannels, Logins.Active from Logins, LoginTypes where Logins.CustomerID = %ld and Logins.LoginType = LoginTypes.InternalID", myCustID); if (DB.rowCount) while (DB.getrow()) { strcpy(isActive, "No"); if (atoi(DB.curRow["Active"])) strcpy(isActive, "Yes"); // Get the date stamp. strcpy(dateStamp, "Unknown"); if (strncmp("0000", DB.curRow["LastModified"], 4)) { // There is a date in the LastModified field. d = DB.curRow.col("LastModified")->toQDateTime().date(); t = DB.curRow.col("LastModified")->toQDateTime().time(); sprintf(dateStamp, "%04d-%02d-%02d %2d:%02d", d.year(), d.month(), d.day(), t.hour(), t.minute()); } // Count how many custom flags there are. QString flagCount = "0"; DB2.query("select count(LoginFlag) from LoginFlagValues where LoginID = '%s'", DB.curRow["LoginID"]); if (DB2.rowCount) { DB2.getrow(); flagCount = DB2.curRow[0]; } showIt = true; if (hideWiped->isChecked() && !strncmp("W", DB.curRow["LoginID"], 1)) showIt = false; if (showIt) { (void) new Q3ListViewItem(list, DB.curRow["LoginID"], // Login ID DB.curRow["LoginType"], // Login Type DB.curRow["ContactName"], // Contact Name dateStamp, // Last Modified Date DB.curRow["DiskSpace"], // Disk Space flagCount, // Custom flags isActive // Active? ); } } /* // Fill in the subscriptions ListBox if (hideWiped->isChecked()) { sprintf(querystr, "select LoginID, LoginType, ContactName, LastModified, DiskSpace, DialupChannels, Active from Logins where CustomerID = %ld and Wiped < '1970-01-01' order by LoginID", myCustID); } else { sprintf(querystr, "select LoginID, LoginType, ContactName, LastModified, DiskSpace, DialupChannels, Active from Logins where CustomerID = %ld order by LoginID", myCustID); } DB.query("%s", querystr); // subscrIndex = new(int[DB.rowCount + 1]); int idxPtr = 0; while(DB.getrow()) { // subscrIndex[idxPtr] = atoi(DB.curRow[0]); idxPtr++; tmpQItemID = DB.curRow["ContactName"]; tmpQItemID.truncate(11); strcpy(tmpItemID, tmpQItemID); tmpQActive = "No"; if (atoi(DB.curRow["Active"])) { tmpQActive = "Yes"; } strcpy(tmpActive, tmpQActive); DB2.query("select LoginType from LoginTypes where InternalID = %d", atoi(DB.curRow["LoginType"])); if (DB2.getrow()) { strcpy(loginType, DB2.curRow["LoginID"]); } else { strcpy(loginType, "Unknown"); } // Parse out the time stamp. qds = DB.curRow["LastModified"]; sprintf(tmpDateStamp, "%4s-%2s-%2s %2s:%2s.%2s", (const char *) qds.mid(0,4), (const char *) qds.mid(4,2), (const char *) qds.mid(6,2), (const char *) qds.mid(8,2), (const char *) qds.mid(10,2), (const char *) qds.mid(12,2) ); (void) new QListViewItem(list, DB.curRow["LoginID"], // Login ID loginType, // Login Type DB.curRow["ContactName"], // Contact Name tmpDateStamp, // Last Modified Date DB.curRow["DiskSpace"], // Disk Space DB.curRow["DialupChannels"], // Dialup Channels tmpActive // Active? ); // list->insertItem(i); } */ }
void CollReport::printReport(long CustID) { QDate theDate; QPrinter prn(QPrinter::PrinterResolution); QPainter p; QRect rect; ADBTable cust; ADBTable cont; ADB DB; QString tmpSt; QDate tmpDate1; char tmpStr[1024]; char tStr[1024]; int yPos; int pageNo = 1; float Balance = 0.00; float EndingBalance; CustomersDB CDB; AddressesDB addrDB; char transFont[1024]; strcpy(transFont, "b&h lucida"); CDB.get(CustID); addrDB.get(REF_CUSTOMER, CustID, "Billing"); theDate = QDate::currentDate(); sprintf(tStr, "/tmp/collreport-%09ld.ps", CustID); // prn.setPrintProgram("ghostview"); //prn.setPrinterName("PostScript"); //prn.setOutputFileName(tStr); prn.setOutputToFile(false); prn.setPageSize(QPrinter::Letter); prn.setFullPage(true); prn.setDocName("Collections Report"); prn.setCreator("Total Accountability"); p.begin(&prn); EndingBalance = DB.sumFloat("select SUM(Amount) from AcctsRecv where CustomerID = %ld", CustID); // Put the Blarg header and contact information on the page. printHeader(&p, &CDB, &addrDB, EndingBalance); // Put the register header on the page. registerHeader(&p); // Now, get the register information from the database. DB.query("select TransDate, DueDate, LoginID, Memo, Amount from AcctsRecv where CustomerID = %ld order by TransDate, LoginID", CustID); yPos = 165; p.setFont(QFont(transFont, 8, QFont::Normal)); QFontMetrics fm(p.fontMetrics()); while (DB.getrow()) { //int Lines = (int) (strlen(DB.curRow["Memo"]) / 52) + 1; //int RowHeight = 15 * Lines; int Lines = (int) (fm.width(DB.curRow["Memo"]) / (descriptionX2 - descriptionX1 - 2)) + 1; int RowHeight = (fm.height()+2) * Lines; // Check to see if we have enough room on the page left for this // line. if (yPos+RowHeight >= 740) { printFooter(&p, pageNo++); prn.newPage(); printHeader(&p, &CDB, &addrDB, EndingBalance); registerHeader(&p); yPos = 165; p.setFont(QFont(transFont, 8, QFont::Normal)); } // The transaction date. myDatetoQDate(DB.curRow["TransDate"], &tmpDate1); sprintf(tmpStr, "%02d/%02d/%02d", tmpDate1.month(), tmpDate1.day(), tmpDate1.year()%100); rect.setCoords(transDateX1, yPos, transDateX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignVCenter|Qt::AlignHCenter, tmpStr); // The Due Date myDatetoQDate(DB.curRow["DueDate"], &tmpDate1); sprintf(tmpStr, "%02d/%02d/%02d", tmpDate1.month(), tmpDate1.day(), tmpDate1.year()%100); rect.setCoords(dueDateX1, yPos, dueDateX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignVCenter|Qt::AlignHCenter, tmpStr); // The Login ID /* rect.setCoords(140, yPos, 199, yPos + RowHeight); p.drawRect(rect); p.drawText(rect, Qt::AlignVCenter|Qt::AlignHCenter, DB.curRow["LoginID"]); */ // The description... //fprintf(stderr, "descriptionX1 = %d, descriptionX2 = %d\n", descriptionX1, descriptionX2); //fprintf(stderr, "description = '%s'\n", DB.curRow["Memo"]); rect.setCoords(descriptionX1, yPos, descriptionX2, yPos + RowHeight-1); p.drawRect(rect); rect.setCoords(descriptionX1+1, yPos, descriptionX2, yPos + RowHeight); p.drawText(rect, Qt::WordBreak|Qt::AlignLeft|Qt::AlignVCenter, DB.curRow["Memo"]); // The amount. rect.setCoords(amountX1, yPos, amountX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, DB.curRow["Amount"]); // The balance. Balance += atof(DB.curRow["Amount"]); sprintf(tStr, "%.2f", Balance); if (Balance == 0.0) strcpy(tStr, "0.00"); rect.setCoords(balanceX1, yPos, balanceX2, yPos + RowHeight-1); p.drawRect(rect); p.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, tStr); yPos += RowHeight; } // Put the footer on the page. printFooter(&p, pageNo); // prn.newPage(); // p.drawText(300, 600, "Page 2"); p.end(); }
void Tab_Logins::updateARForLock(const char * LoginID) { ADB DB; ADB DB2; CustomersDB CDB; LoginsDB LDB; SubscriptionsDB SDB; QDate tmpDate; QDate CycleStart; QDate CycleEnd; QDate yesterday; char sYesterday[64]; int cycleDays; int daysLeft; char today[64]; char sCycleEnd[64]; float Qty; int doEntry; BillingCyclesDB BCDB; tmpDate = QDate::currentDate(); sprintf(today, "%04d-%02d-%02d", tmpDate.year(), tmpDate.month(), tmpDate.day()); CDB.get(myCustID); LDB.get(myCustID, LoginID); BCDB.get(CDB.getInt("BillingCycle")); BCDB.getCycleDates(&CycleStart, &CycleEnd, &cycleDays, &daysLeft,NULL,myCustID); sprintf(sCycleEnd, "%04d-%02d-%02d", CycleEnd.year(), CycleEnd.month(), CycleEnd.day()); // Okay, the first thing we want/need to do is load up the entries // in the AcctsRecv table that have an EndDate > Today. DB.query("select ItemID, Price, Amount, Memo, InternalID from AcctsRecv where CustomerID = %ld and LoginID = '%s' and EndDate > '%s'", myCustID, LoginID, today ); if (DB.rowCount) { // If the customer is active, and we have more than one row, we don't // want to make any adjustments. If they are not active, we're here // to make adjusting entries. while (DB.getrow()) { doEntry = 1; // If they are active now, and our amount > 0, that means // that this is an account that was not previously prorated. // So we don't want to do the adjusting entry. if (LDB.getInt("Active") && (atof(DB.curRow["Amount"]) > 0.0)) doEntry = 0; // If they are not active now, and our amount < 0 that means // they have already been prorated, and we don't need to do // anything more with it. if (!LDB.getInt("Active") && (atof(DB.curRow["Amount"]) < 0.0)) doEntry = 0; if (doEntry) { // It looks as if we need to add to the balance of the user. AcctsRecv AR; AR.ARDB->setValue("CustomerID", myCustID); AR.ARDB->setValue("LoginID", LoginID); AR.ARDB->setValue("ItemID", atoi(DB.curRow["ItemID"])); AR.ARDB->setValue("TransDate", today); AR.ARDB->setValue("StartDate", today); AR.ARDB->setValue("EndDate", sCycleEnd); Qty = (float) daysLeft / cycleDays; if (atof(DB.curRow["Amount"]) > 0) { Qty = Qty * -1.0; } AR.ARDB->setValue("Quantity", Qty); AR.ARDB->setValue("Price", DB.curRow["Price"]); AR.ARDB->setValue("Amount", (float) (atof(DB.curRow["Price"]) * Qty)); AR.ARDB->setValue("Memo", DB.curRow["Memo"]); QString tmpQS; tmpQS = AR.ARDB->getStr("Memo"); if (tmpQS.find('(')) { tmpQS.truncate(tmpQS.find('(') -1); } if (Qty < 0.0) { tmpQS.append(" (Adjustment for account closure)"); } else { tmpQS.append(" (Adjustment for account reactiviation)"); } AR.ARDB->setValue("Memo", (const char *) tmpQS); AR.SaveTrans(); DB2.dbcmd("update AcctsRecv set EndDate = '%s' where InternalID = %ld", today, atol(DB.curRow["InternalID"])); } } } else { // There were no register entries. So make sure there are // Subscriptions for the user. If there aren't, add one. If there // are, update all of the subscriptions for this user so the ends on // date are yesterday, and then do a subscription run for the // customer. DB.query("select InternalID from Subscriptions where CustomerID = %ld and LoginID = '%s'", myCustID, LoginID); if (DB.rowCount) { QDate tmpEndsOn; tmpDate = QDate::currentDate(); yesterday = tmpDate.addDays(-1); sprintf(sYesterday, "%04d-%02d-%02d", yesterday.year(), yesterday.month(), yesterday.day()); while (DB.getrow()) { SDB.get(atol(DB.curRow["InternalID"])); myDatetoQDate((const char *) SDB.getStr("EndsOn"), &tmpEndsOn); // printf("sYesterday = %s, EndsOn = %s\n", sYesterday, (const char *) SDB.getStr("EndsOn")); if (tmpEndsOn < tmpDate) { SDB.setValue("EndsOn", sYesterday); SDB.upd(); } } } else { // No subscriptions. Add them. LDB.get(myCustID, LoginID); LDB.addSubscriptions(); } } }
void parseEmail(const char *tmplName, long CustomerID, const char *LoginID, const char *DomainName, int holdForSync, const char *emailFrom, const char *emailTo, const char *emailSubject, SElement *extraVars) { FParser parser; char tmpstr[1024]; char srcTextFile[1024]; FILE *srcTextFP; char srcHTMLFile[1024]; FILE *srcHTMLFP; int tmpFP; bool doHTML = false; Q3StrList tmplist(TRUE); QString qst; QString tmpqstr2; char contactName[256]; char phoneNumber[32]; // Default fields char msgFrom[1024]; char msgTo[1024]; char msgSubj[1024]; char theDate[64]; QDate theQDate; QTime theQTime = QTime::currentTime(); char curDateTime[1024]; theQDate = QDate::currentDate(); strcpy(theDate, theQDate.toString()); sprintf(curDateTime, "%04d%02d%02d%02d%02d%02d", theQDate.year(), theQDate.month(), theQDate.day(), theQTime.hour(), theQTime.minute(), theQTime.second()); ADB DB; CustomersDB CDB; LoginsDB LDB; AddressesDB addrDB; ADBTable LTDB; ADBTable emailDB("EmailQueue"); // Extract the template from the DB and store it in /tmp somewhere DB.query("select * from EmailTemplates where Name = '%s'", tmplName); if (!DB.rowCount) return; DB.getrow(); strcpy(srcTextFile, "/tmp/taatextXXXXXX"); strcpy(srcHTMLFile, "/tmp/taahtmlXXXXXX"); tmpFP = mkstemp(srcTextFile); close(tmpFP); srcTextFP = fopen(srcTextFile, "w"); fprintf(srcTextFP, "%s", DB.curRow["TextPart"]); fclose(srcTextFP); tmpFP = mkstemp(srcHTMLFile); close(tmpFP); srcHTMLFP = fopen(srcHTMLFile, "w"); fprintf(srcHTMLFP, "%s", DB.curRow["HTMLPart"]); fclose(srcHTMLFP); if (strlen(DB.curRow["HTMLPart"])) doHTML = true; // Get our defaults from the passed in options. strcpy(msgFrom, emailFrom); if (strlen(emailTo)) strcpy(msgTo, emailTo); else sprintf(msgTo, "%s@%s", LoginID, cfgVal("EmailDomain")); if (strlen(emailSubject)) strcpy(msgSubj, emailSubject); else strcpy(msgSubj, DB.curRow["DefaultSubject"]); CDB.get(CustomerID); LDB.get(CustomerID, LoginID); LTDB.setTableName("LoginTypes"); LTDB.get(LDB.getLong("LoginType")); strcpy(tmpstr, CDB.getStr("BillingAddress")); addrDB.get(REF_CUSTOMER, CustomerID, tmpstr); // Since there is no default phone number, grab the first one from // the database. strcpy(phoneNumber, ""); DB.query("select PhoneNumber from CustomerContacts where Active <> 0 and CustomerID = %ld", CustomerID); if (DB.rowCount) { DB.getrow(); strcpy(phoneNumber, DB.curRow["PhoneNumber"]); } // fprintf(stderr, "parseFile: Reading File '%s'\n", SrcFile); // Check to see if we have a contact name. if (strlen((const char *)CDB.getStr("ContactName"))) { strcpy(contactName, CDB.getStr("ContactName")); } else { strcpy(contactName, CDB.getStr("FullName")); } parser.set("DomainName", DomainName); parser.set("CompanyName", CDB.getStr("FullName")); parser.set("ContactName", contactName); parser.set("LoginID", LoginID); parser.set("NICName", contactName); parser.set("Addr1", addrDB.Address1); parser.set("Addr2", addrDB.Address2); parser.set("City", addrDB.City); parser.set("State", addrDB.State); parser.set("ZIP", addrDB.ZIP); parser.set("DayPhone", phoneNumber); parser.set("EvePhone", phoneNumber); parser.set("CurrentDate", theDate); parser.set("LoginType", LTDB.getStr("LoginType")); parser.set("LoginTypeD", LTDB.getStr("Description")); //fprintf(stderr, "Checking for extra variables to parse....\n"); if (extraVars != NULL) { int j = 0; while(strlen(extraVars[j].Name)) { //fprintf(stderr, "Adding '%s' as '%s'....\n", extraVars[j].Name, extraVars[j].Value); parser.set(extraVars[j].Name, extraVars[j].Value); j++; } } // Parse the files and put them into the database now. emailDB.setValue("ProcessID", tmplName); emailDB.setValue("EmailTime", curDateTime); emailDB.setValue("HoldForSync", holdForSync); emailDB.setValue("EmailFrom", msgFrom); emailDB.setValue("EmailTo", msgTo); emailDB.setValue("EmailSubject", msgSubj); emailDB.setValue("TextBody", parser.parseFileToMem(srcTextFile)); if (doHTML) { emailDB.setValue("HTMLBody", parser.parseFileToMem(srcHTMLFile)); } emailDB.ins(); // Remove our temp files unlink(srcTextFile); unlink(srcHTMLFile); }