示例#1
0
/**
 * Saves the selected pictures.
 * First pops up a dialog box asking for the target dir. Then pops up 
 * a progress dialog for feedback.
 */
void MainWindow::saveSelected() 
{
    /* Select target */
    selectWorkDir();

    /* Create a progress dialog */
    QProgressDialog* progress = new QProgressDialog(
        i18n("Downloading ..."), i18n("Cancel"), 100, this, "progress", TRUE);
    progress->setCaption("Download");
    connect(GPMessenger::instance(),SIGNAL(progressChanged(int)),
            progress,SLOT(setProgress(int)));
    progress->setAutoReset(false);
    progress->setAutoClose(false); 
    progress->setProgress(0);
    KApplication::kApplication()->processEvents();
     
    /* Download all pictures */
    for (QIconViewItem *i = iconView->firstItem(); 
                    i && !progress->wasCancelled(); i = i->nextItem() ) {
        if (i->isSelected()) {
            /* Update progress dialog */
            progress->setLabelText(i18n("Downloading ") + i->text() + "...");

            /* Download picture */
            GPInterface::downloadPicture(i->text(),"/");
        }
    } 

    progress->setProgress(100);
    delete progress;
}
示例#2
0
void
PromoBatchMaster::slotPrint()
{
    if (!saveItem(true)) return;
    dataToWidget();

    // Setup grid for printing
    Grid* grid = new Grid(6);
    Grid* header = new Grid(1, grid);
    TextFrame* text;
    text = new TextFrame(tr("Promotion Batch"), header);
    text->setJustify(ALIGN_CENTER);
    text->setFont(Font("Times", 24, 75));
    header->set(USE_NEXT, 0, text);
    if (_curr.executedOn().isNull()) {
        text = new TextFrame(tr("Preliminary"), header);
    } else {
        QString dateText = DateValcon().format(_curr.executedOn());
        text = new TextFrame(tr("Executed On: %1").arg(dateText), header);
    }
    text->setJustify(ALIGN_CENTER);
    text->setFont(Font("Times", 18));
    header->set(USE_NEXT, 0, text);
    header->setColumnWeight(0, 1);

    grid->set(0, 0, 1, grid->columns(), header, Grid::AllSides);
    grid->set(USE_NEXT, 0, "");
    for (int column = 0; column < 6; ++column) {
        grid->setColumnSticky(column, column < 3 ? Grid::Left : Grid::Right);
        grid->setColumnPad(column, 5);
    }
    grid->set(2, 0, tr("Item Number"));
    grid->set(3, 0, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 1, tr("Description"));
    grid->set(3, 1, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 2, tr("Size"));
    grid->set(3, 2, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 3, tr("Current Price"));
    grid->set(3, 3, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 4, tr("Promo Price"));
    grid->set(3, 4, new LineFrame(grid), Grid::LeftRight);
    grid->set(2, 5, tr("Ordered"));
    grid->set(3, 5, new LineFrame(grid), Grid::LeftRight);
    grid->setHeaderRows(grid->rows());

    // Setup progress dialog
    QProgressDialog* progress = new QProgressDialog(tr("Printing promos..."),
            tr("Cancel"),
            _curr.items().size(),
            this, "Progress", true);
    progress->setMinimumDuration(1000);
    progress->setCaption(tr("Progress"));

    // Print promos
    for (unsigned int i = 0; i < _curr.items().size(); ++i) {
        progress->setProgress(i);
        qApp->processEvents();
        if (progress->wasCancelled()) break;

        Id item_id = _curr.items()[i].item_id;
        if (item_id == INVALID_ID) continue;

        QString number = _curr.items()[i].number;
        QString size = _curr.items()[i].size;
        Price promoPrice = _curr.items()[i].price;
        fixed ordered = _curr.items()[i].ordered;

        Item item;
        findItem(item_id, item);

        Price currentPrice = item.price(_store->getId(), size);

        grid->set(USE_NEXT, 0, number);
        grid->set(USE_CURR, 1, item.description());
        grid->set(USE_CURR, 2, size);
        grid->set(USE_CURR, 3, currentPrice.toString());
        grid->set(USE_CURR, 4, promoPrice.toString());
        grid->set(USE_CURR, 5, ordered.toString());
    }
    bool cancelled = progress->wasCancelled();
    progress->setProgress(_curr.items().size());
    delete progress;

    if (!cancelled) grid->print(this);
    delete grid;
}
示例#3
0
void
ServiceCharges::slotCalculate()
{
    QDate start = _start->getDate();
    QDate end = _end->getDate();
    int days = end - start + 1;

    // Validate data
    if (start.isNull()) {
	QString message = tr("A start date must be entered");
	QMessageBox::critical(this, tr("Error"), message);
	_start->setFocus();
	return;
    }
    if (end.isNull()) {
	QString message = tr("An end date must be entered");
	QMessageBox::critical(this, tr("Error"), message);
	_end->setFocus();
	return;
    }
    if (start > end) {
	QString message = tr("Invalid date range");
	QMessageBox::critical(this, tr("Error"), message);
	_start->setFocus();
	return;
    }

    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    // Select all customers
    vector<Customer> customers;
    CustomerSelect conditions;
    conditions.activeOnly = true;
    _quasar->db()->select(customers, conditions);

    // Get invoice terms
    _quasar->db()->invoiceTerms(_invoice_ids, _invoice_term_ids);

    // Setup progress dialog
    unsigned int custs = customers.size();
    QString message = tr("Calculating service charges...");
    QProgressDialog* progress = new QProgressDialog(message, tr("Cancel"),
						    custs, this, "foo", true);
    progress->setMinimumDuration(0);
    progress->setCaption(tr("Progress"));

    // Process each customer
    fixed totalCharges;
    _charges->clear();
    for (unsigned int i = 0; i < custs; ++i) {
	progress->setProgress(i);
	qApp->processEvents();
	if (progress->wasCancelled()) {
	    _charges->clear();
	    QApplication::restoreOverrideCursor();
	    QString message = tr("Service charge calculation cancelled");
	    QMessageBox::information(this, tr("Cancelled"), message);
	    return;
	}

	const Customer& customer = customers[i];
	if (customer.serviceCharge() == 0.0) continue;
	double dailyRate = customer.serviceCharge().toDouble() * 1000.0/365.0;

	// Get all transactions for customer
	GltxSelect conditions;
	conditions.activeOnly = true;
	conditions.card_id = customer.id();
	_quasar->db()->select(_gltxs, conditions);
	if (_gltxs.size() == 0) continue;

	// Remove all that don't effect card balance
	for (int k = _gltxs.size() - 1; k >= 0; --k) {
	    const Gltx& gltx = _gltxs[k];
	    if (gltx.cardTotal() != 0.0) continue;
	    _gltxs.erase(_gltxs.begin() + k);
	}

	// Sort by date
	std::sort(_gltxs.begin(), _gltxs.end());

	// Allocate unallocated payments
	for (unsigned int j = 0; j < _gltxs.size(); ++j) {
	    const Gltx& payment = _gltxs[j];
	    if (payment.cardTotal() >= 0.0) continue;
	    if (payment.cardTotal() == payment.paymentTotal()) continue;

	    fixed alloc = -(payment.cardTotal() - payment.paymentTotal());
	    for (unsigned int k = 0; k < _gltxs.size(); ++k) {
		Gltx& gltx = _gltxs[k];
		if (gltx.cardTotal() <= 0.0) continue;
		if (gltx.cardTotal() == gltx.paymentTotal()) continue;

		fixed pay = gltx.cardTotal() - gltx.paymentTotal();
		if (pay > alloc) pay = alloc;

		gltx.payments().push_back(PaymentLine(payment.id(), pay, 0.0));
		alloc -= pay;
		if (alloc == 0.0) break;
	    }

	    // If not all allocated then nothing left to allocate against
	    if (alloc != 0.0) break;
	}

	// Calculate service charge total
	double totalCharge = 0.0;
	for (unsigned int j = 0; j < _gltxs.size(); ++j) {
	    const Gltx& gltx = _gltxs[j];
	    if (gltx.cardTotal() < 0.0) continue;

	    for (int day = 0; day < days; ++day) {
	        fixed balance = balanceOn(gltx, start + day);
		double charge = balance.toDouble() * dailyRate;
		totalCharge += charge;
	    }
	}

	// Adjust and round
	fixed serviceCharge = totalCharge / 100000.0;
	serviceCharge.moneyRound();
	if (serviceCharge <= 0.0) continue;

	ListViewItem* item = new ListViewItem(_charges, customer.id());
	item->setValue(0, customer.name());
	item->setValue(1, serviceCharge);
	totalCharges += serviceCharge;
    }

    ListViewItem* item = new ListViewItem(_charges);
    item->isLast = true;
    item->setValue(0, "Total");
    item->setValue(1, totalCharges);

    progress->setProgress(custs);
    delete progress;

    QApplication::restoreOverrideCursor();
    message = tr("Service charge calculation is complete");
    QMessageBox::information(this, tr("Complete"), message);
}
示例#4
0
void
Journal::slotRealRefresh()
{
    if (_loading) return;
    _loading = true;
    setEnabled(false);
    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    // Disabled updates so that progress bar updating doesn't also do lists
    _general->setUpdatesEnabled(false);
    _disbursements->setUpdatesEnabled(false);
    _receipts->setUpdatesEnabled(false);
    _sales->setUpdatesEnabled(false);
    _purchases->setUpdatesEnabled(false);
    _inventory->setUpdatesEnabled(false);
    _all->setUpdatesEnabled(false);

    // Load accounts if needed
    if (_accounts.size() == 0) {
	_quasar->db()->select(_accounts, AccountSelect());
    }

    // Clear out old values
    _general->clearList();
    _disbursements->clearList();
    _receipts->clearList();
    _sales->clearList();
    _purchases->clearList();
    _inventory->clearList();
    _all->clearList();

    _lastStart = _from->getDate();
    _lastEnd = _to->getDate();
    int days = _lastEnd - _lastStart + 1;

    // Setup progress dialog
    QProgressDialog* progress = new QProgressDialog(tr("Loading transactions..."),
						    tr("Cancel"), days, this,
						    "Progress", true);
    progress->setMinimumDuration(0);
    progress->setCaption(tr("Progress"));

    for (int day = 0; day < days; ++day) {
	loadDate(_lastStart + day);

	progress->setProgress(day);
	qApp->processEvents();
	if (progress->wasCancelled()) {
	    // TODO: add cancelled line
	    break;
	}
    }

    progress->setProgress(days);
    delete progress;

    // Enable updates on lists
    _general->setUpdatesEnabled(true);
    _disbursements->setUpdatesEnabled(true);
    _receipts->setUpdatesEnabled(true);
    _sales->setUpdatesEnabled(true);
    _purchases->setUpdatesEnabled(true);
    _inventory->setUpdatesEnabled(true);
    _all->setUpdatesEnabled(true);

    QApplication::restoreOverrideCursor();
    setEnabled(true);
    _loading = false;
    _refreshPending = false;
}
示例#5
0
bool BpDocument::composeGraphs( bool lineGraphs, bool showDialogs )
{

    // Bar graph settings
    int    tics = 2;
    double max  = 100.;
    double min  = 0.;
    // Line graph settings
    if ( lineGraphs )
    {
        tics = 11;
        max = tableRow( tableRows()-1 );
        min = tableRow(0);
    }
    GraphAxleParms *xParms = new GraphAxleParms( min, max, tics );
    checkmem( __FILE__, __LINE__, xParms, "GraphAxleParms xParms", 1 );
    if ( lineGraphs && min > 0.
      && property()->boolean( "graphXOriginAtZero" ) )
    {
        xParms->useOrigin();
    }

    // Determine the x-, y-, and z-variables.
    EqVar *xVar = m_eqTree->m_rangeVar[0];
    EqVar *zVar = m_eqTree->m_rangeVar[1];
    EqVar *yVar = 0;

    //--------------------------------------------------------------------------
    // 2: Determine nice axis parameters for the x- and all the y-variables.
    //--------------------------------------------------------------------------

    // Initialize the Y axle for each graph to a nice range
    QPtrList<GraphAxleParms> *yParmsList = new QPtrList<GraphAxleParms>();
    yParmsList->setAutoDelete( true );
    GraphAxleParms *yParms = 0;
    int yid;
    for ( yid = 0;
          yid < tableVars();
          yid++ )
    {
        yVar = tableVar( yid );
        yParms = 0;
        // The yVar must be continuous.
        if ( yVar->isContinuous() )
        {
            // Get Y range
            if ( lineGraphs )
            {
                graphYMinMax( yid, min, max );
            }
            else
            {
                barYMinMax( yid, min, max );
            }
            // Determine and store nice axis parameters
            tics = 11;
            yParms = new GraphAxleParms( min, max, tics );
            checkmem( __FILE__, __LINE__, yParms, "GraphAxleParms yParms", 1 );
            yParmsList->append( yParms );
            // If bar graph, or line graphs must start at origin
            if ( min > 0. )
            {
                if ( ! lineGraphs
                    || property()->boolean( "graphYOriginAtZero" ) )
                {
                    yParms->useOrigin();
                }
            }
            // If min and max are the same, make them different
            if ( min == max )
            {
                yParms->setAxle( min-1., max+1., 3 );
            }
        }
    }

    //--------------------------------------------------------------------------
    // 1: Allow the user to change the axle parameters.
    //--------------------------------------------------------------------------

    if ( showDialogs
      && property()->boolean( "graphYUserRange" ) )
    {
        GraphLimitsDialog *dialog =
            new GraphLimitsDialog( this, yParmsList, "graphLimitsDialog" );
        checkmem( __FILE__, __LINE__, dialog, "GraphLimitsDialog dialog", 1 );
        if ( dialog->exec() == QDialog::Accepted )
        {
            dialog->store();
        }
        delete dialog;  dialog = 0;
    }

    //--------------------------------------------------------------------------
    // 3: Draw each graph.
    //--------------------------------------------------------------------------

    // Set up the progress dialog.
    int step = 0;
    int steps = tableVars();
    QString text(""), button("");
    if ( lineGraphs )
    {
        translate( text, "BpDocument:Graphs:DrawingLineGraphs" );
    }
    else
    {
        translate( text, "BpDocument:Graphs:DrawingBarGraphs" );
    }
    translate( button, "BpDocument:Graphs:Abort" );
    QProgressDialog *progress = new QProgressDialog(
        QString( text ).arg( steps ), button, steps );
    Q_CHECK_PTR( progress );
    progress->setMinimumDuration( 0 );
    progress->setProgress( 0 );

    // Loop for each output variable: one graph is composed per output variable.
    bool result = true;
    for ( yid = 0, yParms = yParmsList->first();
          yid < tableVars();
          yid++ )
    {
        yVar = tableVar( yid );
        // The yVar must be continuous.
        if ( yVar->isContinuous() )
        {
            // Recompute nice Y axis
            //min = ( yParms->m_axleMin < yParms->m_dataMin )
            //    ? yParms->m_axleMin
            //    : yParms->m_dataMin;
            min = yParms->m_axleMin;
            //max = ( yParms->m_axleMax > yParms->m_dataMax )
            //    ? yParms->m_axleMax
            //    : yParms->m_dataMax;
            max = yParms->m_axleMax;
            // If min and max are the same, make them different
            tics = 11;
            if ( min == max )
            {
                yParms->setAxle( min-1., max+1., 3 );
            }
            // Compose this graph.
            if ( lineGraphs )
            {
                composeLineGraph( yid, xVar, yVar, zVar, xParms, yParms );
            }
            else
            {
                composeBarGraph( yid, xVar, yVar, xParms, yParms );
            }
            // Update progress dialog.
            progress->setProgress( ++step );
            qApp->processEvents();
            if ( progress->wasCancelled() )
            {
                result = false;
                break;
            }
            yParms = yParmsList->next();
        }
    }
    // Cleanup and return.
    delete progress;    progress = 0;
    delete xParms;      xParms = 0;
    delete yParmsList;  yParmsList = 0;
    return( result );
}
示例#6
0
void
ItemInquiry::slotRefresh(QDate from, QDate to, Id store_id)
{
    if (loading) return;
    loading = true;
    needsRefresh = false;
    delete _grid;
    _grid = NULL;

    // Clear data
    list->clear();
    for (int label = 0; label < 10; ++label)
        labels[label]->setText(" ");

    // Get item to show and return if none
    Id item_id = search->getId();
    if (item_id == INVALID_ID) {
        loading = false;
        return;
    }

    setEnabled(false);
    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    // Get item information
    Item item;
    quasar->db()->lookup(item_id, item);

    fixed beginOnHand = 0.0;
    fixed beginCost = 0.0;
    fixed beginOnOrder = 0.0;
    fixed totalDebits = 0.0;
    fixed totalCredits = 0.0;

    labels[0]->setText(tr("Beginning Balance"));
    labels[1]->setText(tr("Total Increase"));
    labels[2]->setText(tr("Total Decrease"));
    labels[3]->setText(tr("Net Change"));
    labels[4]->setText(tr("Ending Balance"));

    // Get beginning balance
    if (!from.isNull())
        quasar->db()->itemGeneral(item.id(), "", store_id, from - 1,
                                  beginOnHand, beginCost, beginOnOrder);

    // Select transactions
    vector<Gltx> gltxs;
    vector<fixed> quantities;
    vector<fixed> ext_costs;
    vector<fixed> ext_prices;
    vector<bool> void_flags;
    quasar->db()->selectItem(item.id(), store_id, from, to, gltxs,
                             quantities, ext_costs, ext_prices, void_flags);

    // Setup grid
    _grid = new Grid(8);
    Grid* header = new Grid(1, _grid);
    TextFrame* text;
    text = new TextFrame(tr("Item Inquiry"), header);
    text->setFont(Font("Times", 24));
    header->set(USE_NEXT, 0, text);
    text = new TextFrame(item.number() + " " + item.description(), header);
    text->setFont(Font("Times", 18));
    header->set(USE_NEXT, 0, text);
    text = new TextFrame(DateValcon().format(from) + tr(" to ") +
                         DateValcon().format(to), header);
    text->setFont(Font("Times", 18));
    header->set(USE_NEXT, 0, text);
    header->setColumnWeight(0, 1);

    _grid->set(0, 0, 1, _grid->columns(), header, Grid::AllSides);
    _grid->set(USE_NEXT, 0, "");
    for (int column = 0; column < 8; ++column) {
        _grid->setColumnSticky(column, column < 4 ? Grid::Left : Grid::Right);
        _grid->setColumnPad(column, 5);
    }
    _grid->set(2, 0, tr("Type"));
    _grid->set(3, 0, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 1, tr("Id #"));
    _grid->set(3, 1, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 2, tr("Store"));
    _grid->set(3, 2, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 3, tr("Date"));
    _grid->set(3, 3, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 4, tr("Memo"));
    _grid->set(3, 4, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 5, tr("Debit"));
    _grid->set(3, 5, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 6, tr("Credit"));
    _grid->set(3, 6, new LineFrame(_grid), Grid::LeftRight);
    _grid->set(2, 7, tr("Voided?"));
    _grid->set(3, 7, new LineFrame(_grid), Grid::LeftRight);
    _grid->setHeaderRows(_grid->rows());

    // Setup progress dialog
    QProgressDialog* progress = new QProgressDialog(tr("Loading data..."),
            tr("Cancel"), gltxs.size(),
            this, "Progress", true);
    progress->setMinimumDuration(1000);
    progress->setCaption(tr("Progress"));

    // Process each transaction
    for (unsigned int i = 0; i < gltxs.size(); ++i) {
        const Gltx& gltx = gltxs[i];
        fixed ext_cost = ext_costs[i];
        // TODO: pick to show cost, qty, or price

        if (i % 50 == 0) {
            progress->setProgress(i);
            qApp->processEvents();
            if (progress->wasCancelled()) {
                break;
            }
        }

        // Don't show voided lines or quotes
        if (void_flags[i] || gltx.dataType() == DataObject::QUOTE)
            continue;

        Store store;
        quasar->db()->lookup(gltx.storeId(), store);

        ListViewItem* item = new ListViewItem(list, gltx.id());
        item->setValue(0, gltx.dataTypeName());
        item->setValue(1, gltx.number());
        item->setValue(2, store.number());
        item->setValue(3, gltx.postDate());
        item->setValue(4, gltx.memo());
        item->setValue(7, !gltx.isActive());

        _grid->set(USE_NEXT, 0, gltx.dataTypeName());
        _grid->set(USE_CURR, 1, gltx.number());
        _grid->set(USE_CURR, 2, store.number());
        _grid->set(USE_CURR, 3, DateValcon().format(gltx.postDate()));
        _grid->set(USE_CURR, 4, gltx.memo());
        _grid->set(USE_CURR, 7, gltx.isActive() ? " " : "x");

        // Correct sign based on type
        switch (gltx.dataType()) {
        case DataObject::INVOICE:
        case DataObject::RETURN:
            ext_cost = -ext_cost;
            break;
        default:
            break;
        }

        if (ext_cost >= 0.0) {
            item->setValue(5, ext_cost);
            _grid->set(USE_CURR, 5, MoneyValcon().format(ext_cost));
            if (gltx.isActive()) totalDebits += ext_cost;
        } else {
            item->setValue(6, -ext_cost);
            _grid->set(USE_CURR, 6, MoneyValcon().format(-ext_cost));
            if (gltx.isActive()) totalCredits += -ext_cost;
        }
    }
    progress->setProgress(gltxs.size());
    delete progress;

    // Set bottom totals
    fixed netChange = totalDebits - totalCredits;
    fixed endBalance = beginCost + netChange;

    MoneyValcon moneyValcon;
    labels[5]->setText(moneyValcon.format(beginCost));
    labels[6]->setText(moneyValcon.format(totalDebits));
    labels[7]->setText(moneyValcon.format(totalCredits));
    labels[8]->setText(moneyValcon.format(netChange));
    labels[9]->setText(moneyValcon.format(endBalance));

    _grid->set(USE_NEXT, 0, "");
    _grid->set(USE_NEXT, 0, 1, 5, tr("Beginning Balance"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(beginCost));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Total Debits"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(totalDebits));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Total Credits"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(totalCredits));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Net Change"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(netChange));
    _grid->set(USE_NEXT, 0, 1, 5, tr("Ending Balance"), Grid::Right);
    _grid->set(USE_CURR, 5, 1, 2, MoneyValcon().format(endBalance));

    QApplication::restoreOverrideCursor();
    setEnabled(true);
    loading = false;
}