Beispiel #1
0
// Set the data object from the widgets.
void
CardTransfer::widgetToData()
{
    _gltxFrame->getData(_curr);
    _curr.setMemo(_memo->text());
    _curr.setCardId(_from->getId());
    _quasar->db()->setActive(_curr, !_inactive->isChecked());

    _gltxFrame->getData(_link);
    _link.setNumber(_toNumber->text());
    _link.setShiftId(_toShift->getId());
    _link.setMemo(_memo->text());
    _link.setCardId(_to->getId());
    _quasar->db()->setActive(_link, !_inactive->isChecked());

    fixed amount = _amount->getFixed();
    Id transferAcct = _account->getId();
    Card card;

    Id fromAcct;
    _quasar->db()->lookup(_curr.cardId(), card);
    DataObject::DataType fromType = card.dataType();
    if (card.dataType() == DataObject::CUSTOMER) {
	Customer customer;
	_quasar->db()->lookup(card.id(), customer);
	fromAcct = customer.accountId();
    } else if (card.dataType() == DataObject::VENDOR) {
	Vendor vendor;
	_quasar->db()->lookup(card.id(), vendor);
	fromAcct = vendor.accountId();
    }

    Id toAcct;
    _quasar->db()->lookup(_link.cardId(), card);
    DataObject::DataType toType = card.dataType();
    if (card.dataType() == DataObject::CUSTOMER) {
	Customer customer;
	_quasar->db()->lookup(card.id(), customer);
	toAcct = customer.accountId();
    } else if (card.dataType() == DataObject::VENDOR) {
	Vendor vendor;
	_quasar->db()->lookup(card.id(), vendor);
	toAcct = vendor.accountId();
    }

    // Process fromAcct and transfer acct on first card
    _curr.cards().clear();
    _curr.cards().push_back(CardLine(_curr.cardId(), -amount));
    _curr.accounts().clear();
    if (fromType == DataObject::CUSTOMER) {
        _curr.accounts().push_back(AccountLine(fromAcct, -amount));
        _curr.accounts().push_back(AccountLine(transferAcct, amount));
    } else if (fromType == DataObject::VENDOR) {
        _curr.accounts().push_back(AccountLine(fromAcct, amount));
        _curr.accounts().push_back(AccountLine(transferAcct, -amount));
    }

    // Process toAcct and transfer acct on second card
    _link.cards().clear();
    if (fromType == toType) {
        _link.cards().push_back(CardLine(_link.cardId(), amount));
        _link.accounts().clear();
        if (toType == DataObject::CUSTOMER) {
            _link.accounts().push_back(AccountLine(toAcct, amount));
            _link.accounts().push_back(AccountLine(transferAcct, -amount));
        } else if (toType == DataObject::VENDOR) {
            _link.accounts().push_back(AccountLine(toAcct, -amount));
            _link.accounts().push_back(AccountLine(transferAcct, amount));
       }
    } else {
        _link.cards().push_back(CardLine(_link.cardId(), -amount));
        _link.accounts().clear();
        if (toType == DataObject::CUSTOMER) {
            _link.accounts().push_back(AccountLine(toAcct, -amount));
            _link.accounts().push_back(AccountLine(transferAcct, amount));
        } else if (toType == DataObject::VENDOR) {
            _link.accounts().push_back(AccountLine(toAcct, amount));
            _link.accounts().push_back(AccountLine(transferAcct, -amount));
	}
    }
}
Beispiel #2
0
void
ServiceCharges::slotPost()
{
    QDate end = _end->getDate();
    Id store_id = _store->getId();
    Id account_id = _account->getId();

    // Validate data
    if (store_id == INVALID_ID) {
	QString message = tr("A store must be entered");
	QMessageBox::critical(this, tr("Error"), message);
	_store->setFocus();
	return;
    }
    if (account_id == INVALID_ID) {
	QString message = tr("An account must be entered");
	QMessageBox::critical(this, tr("Error"), message);
	_account->setFocus();
	return;
    }

    QString message = tr("Are you sure you want to post the charges?");
    int ch = QMessageBox::warning(this, tr("Continue?"), message,
				  QMessageBox::No, QMessageBox::Yes);
    if (ch != QMessageBox::Yes) return;

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

    QListViewItemIterator it(_charges);
    for (; it.current(); ++it) {
	ListViewItem* item = (ListViewItem*)it.current();
	Id customer_id = item->id;
	fixed amount = item->value(1).toFixed();
	if (customer_id == INVALID_ID) continue;

	Customer customer;
	_quasar->db()->lookup(customer_id, customer);

	// Generate service charge transaction
	CardAdjust adjustment;
	adjustment.setPostDate(end);
	adjustment.setPostTime(QTime(0, 0, 0));
	adjustment.setMemo(tr("Service Charges"));
	adjustment.setCardId(customer_id);
	adjustment.setStoreId(store_id);

	CardLine cardLine(customer_id, amount);
	adjustment.cards().push_back(cardLine);

	// Add account lines
	Id receivables_id = customer.accountId();
	adjustment.accounts().push_back(AccountLine(receivables_id, amount));
	adjustment.accounts().push_back(AccountLine(account_id, -amount));

	// Post adjustment
	_quasar->db()->create(adjustment);
    }

    Company orig, company;
    _quasar->db()->lookup(orig);
    company = orig;

    company.setLastServiceCharge(end);
    company.setChargeAccount(account_id);
    _quasar->db()->update(orig, company);

    QApplication::restoreOverrideCursor();
    message = tr("The service charges have been posted");
    QMessageBox::information(this, tr("Posted"), message);

    close();
}
Beispiel #3
0
void
OpenBalances::slotPost()
{
    Id store_id = _store->getId();
    Id station_id = _station->getId();
    Id employee_id = _employee->getId();
    Id history_id = _account->getId();

    if (store_id == INVALID_ID) {
	QString message = tr("A store is required");
	QMessageBox::critical(this, tr("Error"), message);
	_store->setFocus();
	return;
    }

    if (history_id == INVALID_ID) {
	QString message = tr("An account is required");
	QMessageBox::critical(this, tr("Error"), message);
	_account->setFocus();
	return;
    }

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

    for (int row = 0; row < _customers->rows(); ++row) {
	Id customer_id = _customers->cellValue(row, 0).toId();
	QDate date = _customers->cellValue(row, 1).toDate();
	fixed amount = _customers->cellValue(row, 2).toFixed();
	if (customer_id == INVALID_ID || amount == 0.0) continue;

	Customer customer;
	_quasar->db()->lookup(customer_id, customer);
	Id customer_acct = customer.accountId();

	CardAdjust adjustment;
	adjustment.setPostDate(date);
	adjustment.setPostTime(QTime(0, 0, 0));
	adjustment.setMemo(tr("Open Balance"));
	adjustment.setStationId(station_id);
	adjustment.setEmployeeId(employee_id);
	adjustment.setCardId(customer_id);
	adjustment.setStoreId(store_id);

	adjustment.accounts().push_back(AccountLine(customer_acct, amount));
	adjustment.accounts().push_back(AccountLine(history_id, -amount));
	adjustment.cards().push_back(CardLine(customer_id, amount));

	if (!_quasar->db()->create(adjustment)) {
	    QString message = tr("Customer '%1' open balance failed")
		.arg(customer.name());
	    QMessageBox::critical(this, tr("Error"), message);
	}
    }

    for (int row = 0; row < _vendors->rows(); ++row) {
	Id vendor_id = _vendors->cellValue(row, 0).toId();
	QDate date = _vendors->cellValue(row, 1).toDate();
	fixed amount = _vendors->cellValue(row, 2).toFixed();
	if (vendor_id == INVALID_ID || amount == 0.0) continue;

	Vendor vendor;
	_quasar->db()->lookup(vendor_id, vendor);
	Id vendor_acct = vendor.accountId();

	CardAdjust adjustment;
	adjustment.setPostDate(date);
	adjustment.setPostTime(QTime(0, 0, 0));
	adjustment.setMemo(tr("Open Balance"));
	adjustment.setStationId(station_id);
	adjustment.setEmployeeId(employee_id);
	adjustment.setCardId(vendor_id);
	adjustment.setStoreId(store_id);

	adjustment.accounts().push_back(AccountLine(vendor_acct, -amount));
	adjustment.accounts().push_back(AccountLine(history_id, amount));
	adjustment.cards().push_back(CardLine(vendor_id, amount));

	if (!_quasar->db()->create(adjustment)) {
	    QString message = tr("Vendor '%1' open balance failed")
		.arg(vendor.name());
	    QMessageBox::critical(this, tr("Error"), message);
	}
    }

    for (int row = 0; row < _items->rows(); ++row) {
	Id item_id = _items->cellValue(row, 0).toId();
	QString number = _items->cellValue(row, 0).toPlu().number();
	QString size = _items->cellValue(row, 2).toString();
	fixed qty = _items->cellValue(row, 3).toFixed();
	fixed cost = _items->cellValue(row, 4).toFixed();
	if (item_id == INVALID_ID || (qty == 0.0 && cost == 0.0)) continue;

	Item item;
	_quasar->db()->lookup(item_id, item);
	Id item_acct = item.assetAccount();

	ItemAdjust adjustment;
	adjustment.setPostDate(QDate::currentDate());
	adjustment.setPostTime(QTime::currentTime());
	adjustment.setMemo(tr("Open Balance"));
	adjustment.setStationId(station_id);
	adjustment.setEmployeeId(employee_id);
	adjustment.setStoreId(store_id);
	adjustment.setAccountId(history_id);

	adjustment.accounts().push_back(AccountLine(item_acct, cost));
	adjustment.accounts().push_back(AccountLine(history_id, -cost));

	ItemLine line;
	line.item_id = item.id();
	line.number = number;
	line.size = size;
	line.size_qty = item.sizeQty(size);
	line.quantity = qty;
	line.inv_cost = cost;
	adjustment.items().push_back(line);

	if (!_quasar->db()->create(adjustment)) {
	    QString message = tr("Item '%1' open balance failed")
		.arg(item.number());
	    QMessageBox::critical(this, tr("Error"), message);
	}
    }

    for (int row = 0; row < _accounts->rows(); ++row) {
	Id account_id = _accounts->cellValue(row, 0).toId();
	fixed debit = _accounts->cellValue(row, 1).toFixed();
	fixed credit = _accounts->cellValue(row, 2).toFixed();
	if (account_id == INVALID_ID || (debit == 0.0 && credit == 0))
		continue;

	Account account;
	_quasar->db()->lookup(account_id, account);

	General general;
	general.setPostDate(QDate::currentDate());
	general.setPostTime(QTime::currentTime());
	general.setMemo(tr("Open Balance"));
	general.setStationId(station_id);
	general.setEmployeeId(employee_id);
	general.setStoreId(store_id);

	if (debit != 0.0) {
	    general.accounts().push_back(AccountLine(account_id, debit));
	    general.accounts().push_back(AccountLine(history_id, -debit));
	}
	if (credit != 0.0) {
	    general.accounts().push_back(AccountLine(account_id, -credit));
	    general.accounts().push_back(AccountLine(history_id, credit));
	}

	if (!_quasar->db()->create(general)) {
	    QString message = tr("Account '%1' open balance failed")
		.arg(account.name());
	    QMessageBox::critical(this, tr("Error"), message);
	}
    }

    QApplication::restoreOverrideCursor();

    close();
}