Пример #1
0
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();
}
Пример #2
0
void CustRegister::printRegister()
{
    QDate       theDate;
    QPrinter    prn;
    QPainter    p;
    QRect       rect;
    ADBTable    cust;
    ADBTable    cont;
    ADB         DB;
    QString     tmpSt;
    char        tStr[1024];
    int         yPos;
    int         pageNo = 1;
    float       Balance = 0.00;
    float       EndingBalance;
    CustomersDB CDB;
    AddressesDB addrDB;
    
    CDB.get(myCustID);
    addrDB.get(REF_CUSTOMER, myCustID, "Billing");
    
    theDate = QDate::currentDate();
    
    // prn.setPrintProgram("ghostview");
    prn.setPrinterName("PostScript");
    // prn.setOutputFileName("/home/marc/test.ps");
    // prn.setOutputToFile(TRUE);
    prn.setPageSize(QPrinter::Letter);
    
    prn.setDocName("Register Listing");
    prn.setCreator("Blarg! Online Services, Inc.");
    
    if (!prn.setup()) return;
    
    p.begin(&prn);
    
    EndingBalance = DB.sumFloat("select SUM(Amount) from AcctsRecv where CustomerID = %ld", myCustID);
    
    // 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", myCustID);
    
    yPos = 165;
    p.setFont(QFont("courier", 8, QFont::Normal));
    while (DB.getrow()) {
        int Lines = (int) (strlen(DB.curRow["Memo"]) / 52) + 1;
        int RowHeight = 15 * 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("courier", 8, QFont::Normal));
        } 
    
        // The transaction date.
        rect.setCoords(20, yPos, 79, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignVCenter|AlignHCenter, DB.curRow["TransDate"]);
        
        // The Due Date
        rect.setCoords(80, yPos, 139, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignVCenter|AlignHCenter, DB.curRow["DueDate"]);
        
        // The Login ID
        rect.setCoords(140, yPos, 199, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignVCenter|AlignHCenter, DB.curRow["LoginID"]);
        
        // The description...
        rect.setCoords(200, yPos, 419, yPos + RowHeight);
        p.drawRect(rect);
        rect.setCoords(203, yPos, 419, yPos + RowHeight);
        p.drawText(rect, WordBreak|AlignLeft|AlignVCenter, DB.curRow["Memo"]);
        
        // The amount.
        rect.setCoords(420, yPos, 479, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignRight|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(480, yPos, 539, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignRight|AlignVCenter, tStr);
        
        yPos += RowHeight;
    }

    // Put the footer on the page.
    printFooter(&p, pageNo);
    
    // prn.newPage();
    
    // p.drawText(300, 600, "Page 2");
    
    p.end();
}