Пример #1
0
int main() {
  Invoice invoiceOne;

  cout << invoiceOne.getNumber() << '-' << invoiceOne.getDescription() << '-'
       << invoiceOne.getQuantity() << '-' << invoiceOne.getPrice() << endl;

  invoiceOne.setNumber("Hello");
  invoiceOne.setDescription("World");
  invoiceOne.setQuantity(33);
  invoiceOne.setPrice(99);

  cout << invoiceOne.getNumber() << '-' << invoiceOne.getDescription() << '-'
       << invoiceOne.getQuantity() << '-' << invoiceOne.getPrice() << endl;

  Invoice invoiceTwo;

  cout << invoiceTwo.getNumber() << '-' << invoiceTwo.getDescription() << '-'
       << invoiceTwo.getQuantity() << '-' << invoiceTwo.getPrice() << endl;

  invoiceTwo.setQuantity(-55);
  invoiceTwo.setPrice(-99);

  cout << invoiceTwo.getNumber() << '-' << invoiceTwo.getDescription() << '-'
       << invoiceTwo.getQuantity() << '-' << invoiceTwo.getPrice() << endl;

  return 0;
}
Пример #2
0
bool
RecurringMaster::postOne(const Gltx& gltx, Id card_id)
{
    QDate nextDue = _curr.nextDue();
    Card card;
    _quasar->db()->lookup(card_id, card);

    General general;
    ItemAdjust adjustment;
    Invoice invoice;
    Receive receive;
    Cheque cheque;
    unsigned int i;

    switch (gltx.dataType()) {
    case DataObject::GENERAL:
	_quasar->db()->lookup(_curr.gltxId(), general);
	_quasar->db()->setActive(general, true);
	general.setNumber("#");
	general.setShiftId(INVALID_ID);
	general.setPostDate(nextDue);
	general.setPrinted(false);
	general.setPaid(false);
	general.payments().clear();

	if (!_quasar->db()->create(general)) {
	    QMessageBox::critical(this, tr("Error"), tr("Create failed"));
	    return false;
	}
	break;
    case DataObject::ITEM_ADJUST:
	_quasar->db()->lookup(_curr.gltxId(), adjustment);
	_quasar->db()->setActive(adjustment, true);
	adjustment.setNumber("#");
	adjustment.setShiftId(INVALID_ID);
	adjustment.setPostDate(nextDue);
	adjustment.setPrinted(false);
	adjustment.setPaid(false);
	adjustment.payments().clear();

	if (!_quasar->db()->create(adjustment)) {
	    QMessageBox::critical(this, tr("Error"), tr("Create failed"));
	    return false;
	}
	break;
    case DataObject::INVOICE:
	_quasar->db()->lookup(_curr.gltxId(), invoice);
	_quasar->db()->setActive(invoice, true);
	invoice.setNumber("#");
	invoice.setCustomerId(card_id);
	invoice.setCustomerAddress(card.address());
	invoice.setShiftId(INVALID_ID);
	invoice.setPostDate(nextDue);
	invoice.setPrinted(false);
	invoice.setPaid(false);
	invoice.payments().clear();

	// Recalculate item costs
	for (i = 0; i < invoice.items().size(); ++i) {
	    InvoiceItem& line = invoice.items()[i];
	    if (line.voided || line.item_id == INVALID_ID) continue;

	    Id store = invoice.storeId();
	    fixed qty = fabs(line.quantity);
	    fixed sign = line.quantity.sign();

	    Item item;
	    _quasar->db()->lookup(line.item_id, item);

	    fixed sell_cost;
	    _quasar->db()->itemSellingCost(item, line.size, store, qty,
					   line.ext_price, sell_cost);
	    line.inv_cost = sell_cost * sign;
	}

	// Fix gltx_card lines
	for (i = 0; i < invoice.cards().size(); ++i)
	    invoice.cards()[i].card_id = card_id;

	if (!_quasar->db()->create(invoice)) {
	    QMessageBox::critical(this, tr("Error"), tr("Create failed"));
	    return false;
	}
	break;
    case DataObject::RECEIVE:
	_quasar->db()->lookup(_curr.gltxId(), receive);
	_quasar->db()->setActive(receive, true);
	receive.setNumber("#");
	receive.setVendorId(card_id);
	receive.setVendorAddress(card.address());
	receive.setShiftId(INVALID_ID);
	receive.setPostDate(nextDue);
	receive.setInvoiceDate(nextDue);
	receive.setPrinted(false);
	receive.setPaid(false);
	receive.setClosed(false);
	receive.payments().clear();

	// Fix gltx_card lines
	for (i = 0; i < receive.cards().size(); ++i)
	    receive.cards()[i].card_id = card_id;

	if (!_quasar->db()->create(receive)) {
	    QMessageBox::critical(this, tr("Error"), tr("Create failed"));
	    return false;
	}
	break;
    case DataObject::CHEQUE:
	_quasar->db()->lookup(_curr.gltxId(), cheque);
	_quasar->db()->setActive(cheque, true);
	cheque.setNumber("#");
	cheque.setCardId(card_id);
	cheque.setAddress(card.address());
	cheque.setShiftId(INVALID_ID);
	cheque.setPostDate(nextDue);
	cheque.setPrinted(false);
	cheque.setPaid(false);
	cheque.payments().clear();

	if (!_quasar->db()->create(cheque)) {
	    QMessageBox::critical(this, tr("Error"), tr("Create failed"));
	    return false;
	}
	break;
    default:
	QString message = tr("Can't post %1 transactions yet")
	    .arg(gltx.dataTypeName());
	QMessageBox::critical(this, tr("Error"), message);
	return false;
    }

    return true;
}