Beispiel #1
0
void
AddressBook::addToPopup(QPopupMenu* menu)
{
    ActiveList::addToPopup(menu);
    menu->insertItem(tr("Send Email"), this, SLOT(slotEmail()));

    Card card;
    if (!_quasar->db()->lookup(currentId(), card)) return;
    if (card.dataType() == DataObject::PERSONAL) return;
    if (card.dataType() == DataObject::EMPLOYEE) return;

    menu->insertItem(tr("Inquiry"), this, SLOT(slotInquiry()));
    menu->insertItem(tr("Find Tx"), this, SLOT(slotFindTx()));
    if (card.dataType() == DataObject::CUSTOMER) {
	menu->insertItem(tr("Aged List"), this, SLOT(slotAgedAR()));
	menu->insertItem(tr("Sales"), this, SLOT(slotSales()));
	menu->insertItem(tr("Payment"), this, SLOT(slotReceipt()));
	menu->insertItem(tr("Withdraw"), this, SLOT(slotWithdraw()));
	menu->insertItem(tr("Write Cheque"), this, SLOT(slotCheque()));
	menu->insertItem(tr("Allocate"), this, SLOT(slotAllocate()));
    }
    if (card.dataType() == DataObject::VENDOR) {
	menu->insertItem(tr("Aged List"), this, SLOT(slotAgedAP()));
	menu->insertItem(tr("Purchases"), this, SLOT(slotPurchases()));
	menu->insertItem(tr("Payment"), this, SLOT(slotPayment()));
	menu->insertItem(tr("Allocate"), this, SLOT(slotAllocate()));
    }
}
Beispiel #2
0
bool
QuasarDB::validate(const Receipt& receipt)
{
    Card card;
    if (!lookup(receipt.cardId(), card))
	return error("Customer doesn't exist");
    if (card.dataType() != DataObject::CUSTOMER)
	return error("Card isn't a customer");

    fixed totalPaid = 0.0;
    for (unsigned int i = 0; i < receipt.payments().size(); ++i) {
	const PaymentLine& line = receipt.payments()[i];

	Gltx gltx;
	if (!lookup(line.gltx_id, gltx))
	    return error("Transaction doesn't exist");

	totalPaid += line.amount + line.discount;
    }

    if (-totalPaid > -receipt.cardTotal() && receipt.accounts().size() > 0) {
	return error("Payment allocations larger than amount");
    }

    if (receipt.accounts().size() > 0 && receipt.isActive())
	if (receipt.tenderTotal() != receipt.total())
	    return error("Incomplete tendering");

    return validate((Gltx&)receipt);
}
Beispiel #3
0
void
AddressBook::performEdit()
{
    Id card_id = currentId();
    Card card;
    if (!_quasar->db()->lookup(card_id, card))
	return;

    QWidget* window = NULL;
    switch (card.dataType()) {
    case DataObject::CUSTOMER:
	window = new CustomerMaster(_main, card_id);
	break;
    case DataObject::EMPLOYEE:
	window = new EmployeeMaster(_main, card_id);
	break;
    case DataObject::PERSONAL:
	window = new PersonalMaster(_main, card_id);
	break;
    case DataObject::VENDOR:
	window = new VendorMaster(_main, card_id);
	break;
    default:
	assert(false);
    }
    window->show();
}
Beispiel #4
0
bool
QuasarDB::validate(const Cheque& cheque)
{
    Card card;
    lookup(cheque.cardId(), card);

    switch (cheque.type()) {
    case Cheque::ACCOUNT:
	// Note: any card type is allowed
	break;
    case Cheque::VENDOR:
	if (card.id() == INVALID_ID)
	    return error("Vendor is required");
	if (card.dataType() != DataObject::VENDOR)
	    return error("Card isn't a vendor");
	break;
    case Cheque::CUSTOMER:
	if (card.id() == INVALID_ID)
	    return error("Customer is reuqired");
	if (card.dataType() != DataObject::CUSTOMER)
	    return error("Card isn't a customer");
	break;
    }

    if (cheque.total() == 0.0)
	return error("Cannot create a zero value cheque");

    fixed totalPaid = 0.0;
    for (unsigned int i = 0; i < cheque.payments().size(); ++i) {
	const PaymentLine& line = cheque.payments()[i];

	Gltx gltx;
	if (!lookup(line.gltx_id, gltx))
	    return error("Transaction doesn't exist");

	totalPaid += line.amount;
    }

    if (totalPaid.abs() > cheque.cardTotal().abs()) {
	return error("Payment allocations larger than amount");
    }

    return validate((Gltx&)cheque);
}
Beispiel #5
0
bool
QuasarDB::validate(const Slip& slip)
{
    if (!validate((DataObject&)slip)) return false;

    if (slip.number().stripWhiteSpace().isEmpty())
	return error("Blank slip number");

    Card card;
    if (!lookup(slip.vendorId(), card))
	return error("Vendor doesn't exist");
    if (card.dataType() != DataObject::VENDOR)
	return error("Card is not a vendor");

    if (slip.shipDate().isNull())
	return error("Blank ship date");

    if (slip.items().size() < 1)
	return error("Slip must have at least one line");

    unsigned int i;
    for (i = 0; i < slip.items().size(); ++i) {
	const SlipItem& line = slip.items()[i];

	Item item;
	if (!lookup(line.item_id, item))
	    return error("Item doesn't exist");
	if (!item.isPurchased())
	    return error("Item isn't purchased");

	if (line.number.isEmpty())
	    return error("Blank item number");

	if (line.quantity < 0.0)
	    return error("Negative quantity");
	if (line.ext_cost < 0.0)
	    return error("Negative extended cost");
    }

    return true;
}
Beispiel #6
0
bool
QuasarDB::validate(const Gltx& gltx)
{
    if (!validate((DataObject&)gltx)) return false;

    if (gltx.postDate().isNull())
	return error("Invalid posting date");

    Store store;
    if (gltx.storeId() == INVALID_ID)
	return error("Store is required");
    if (!lookup(gltx.storeId(), store))
	return error("Invalid store");

    Station station;
    if (gltx.stationId() != INVALID_ID) {
	if (!lookup(gltx.stationId(), station))
	    return error("Station doesn't exist");
    }

    if (gltx.employeeId() != INVALID_ID) {
	Card card;
	if (!lookup(gltx.employeeId(), card))
	    return error("Employee card doesn't exist");
	if (card.dataType() != DataObject::EMPLOYEE)
	    return error("Invalid employee card");
    }
    if (gltx.cardId() != INVALID_ID) {
	Card card;
	if (!lookup(gltx.cardId(), card))
	    return error("Card doesn't exist");
	// TODO: verify right type of card by tx type
    }

    if (gltx.dataType() == DataObject::GENERAL) {
	if (gltx.memo().stripWhiteSpace().isEmpty())
	    return error("Blank memo");
	if (gltx.accounts().size() < 2 && gltx.isActive())
	    return error("GL transactions need 2 or more lines");
    }

    fixed total = 0.0;
    for (unsigned int i = 0; i < gltx.accounts().size(); ++i) {
	const AccountLine& line = gltx.accounts()[i];
	Account account;
	if (!lookup(line.account_id, account))
	    return error("Unknown account in lines");
	if (account.isHeader())
	    return error("Header account in lines");

	fixed rounded = line.amount;
	rounded.moneyRound();
	if (rounded != line.amount) {
	    return error("Extra decimal places: " + account.name() +
			 "," + line.amount.toString());
	}

	//qDebug("%s: %f", account.name().latin1(), line.amount.toDouble());
	total += line.amount;
    }
    if (total != 0.0)
	return error("Transaction doesn't balance to zero: " +
		     MoneyValcon().format(total));

    return true;
}
Beispiel #7
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 #8
0
void
AddressBook::setActive(Id card_id, bool active)
{
    if (card_id == INVALID_ID) return;

    if (!active) {
	fixed balance = _quasar->db()->cardBalance(card_id);
	if (balance != 0.0) {
	    QString message = tr("This card still has a balance.  It must "
				 "have\na zero balance before it can be "
				 "made inactive.");
	    QMessageBox::warning(this, tr("Error"), message, QMessageBox::Ok,
				 0);
	    return;
	}
    }

    Card card;
    _quasar->db()->lookup(card_id, card);

    switch (card.dataType()) {
    case DataObject::CUSTOMER:
    {
	Customer customer;
	_quasar->db()->lookup(card_id, customer);
	Customer orig = customer;
	_quasar->db()->setActive(customer, active);
	_quasar->db()->update(orig, customer);
	break;
    }
    case DataObject::EMPLOYEE:
    {
	Employee employee;
	_quasar->db()->lookup(card_id, employee);
	Employee orig = employee;
	_quasar->db()->setActive(employee, active);
	_quasar->db()->update(orig, employee);
	break;
    }
    case DataObject::PERSONAL:
    {
	Personal personal;
	_quasar->db()->lookup(card_id, personal);
	Personal orig = personal;
	_quasar->db()->setActive(personal, active);
	_quasar->db()->update(orig, personal);
	break;
    }
    case DataObject::VENDOR:
    {
	Vendor vendor;
	_quasar->db()->lookup(card_id, vendor);
	Vendor orig = vendor;
	_quasar->db()->setActive(vendor, active);
	_quasar->db()->update(orig, vendor);
	break;
    }
    default:
	assert(0);
    }
}