void Journal::addToList(JournalWindow* window, const Gltx& gltx) { if (window == NULL) return; ListViewItem* item = new ListViewItem(window->list, window->last, gltx.id()); window->last = item; Store store; findStore(gltx.storeId(), store); 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()); for (unsigned int i = 0; i < gltx.accounts().size(); ++i) { const AccountLine& line = gltx.accounts()[i]; Account account; for (unsigned int a = 0; a < _accounts.size(); ++a) { if (_accounts[a].id() == line.account_id) { account = _accounts[a]; break; } } ListViewItem* item = new ListViewItem(window->list, window->last, gltx.id()); window->last = item; item->setValue(4, account.name()); if (line.amount >= 0.0) item->setValue(5, line.amount); else item->setValue(6, -line.amount); } }
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; }