void cashReceiptItem::sSave() { double epsilon = 0.005; QList<GuiErrorCheck> errors; errors<< GuiErrorCheck((_amountToApply->localValue() + _discountAmount->localValue()) - _openAmount->localValue() > epsilon, _amountToApply, tr("You may not apply more than the balance of this item.")) ; if (GuiErrorCheck::reportErrors(this, tr("Cannot Apply"), errors)) return; int sense = 1; if (_docType->text() == "C" || _docType->text() == "R") sense = -1; if (_mode == cNew) { XSqlQuery cashrcptitemid("SELECT NEXTVAL('cashrcptitem_cashrcptitem_id_seq') AS _cashrcptitem_id;"); if (cashrcptitemid.first()) _cashrcptitemid = cashrcptitemid.value("_cashrcptitem_id").toInt(); XSqlQuery newReceipt; newReceipt.prepare( "INSERT INTO cashrcptitem " "( cashrcptitem_id, cashrcptitem_cashrcpt_id," " cashrcptitem_aropen_id, cashrcptitem_amount, cashrcptitem_discount ) " "VALUES " "( :cashrcptitem_id, :cashrcptitem_cashrcpt_id," " :cashrcptitem_aropen_id, :cashrcptitem_amount, :cashrcptitem_discount );" ); newReceipt.bindValue(":cashrcptitem_id", _cashrcptitemid); newReceipt.bindValue(":cashrcptitem_cashrcpt_id", _cashrcptid); newReceipt.bindValue(":cashrcptitem_aropen_id", _aropenid); newReceipt.bindValue(":cashrcptitem_amount", _amountToApply->localValue() * sense); newReceipt.bindValue(":cashrcptitem_discount", _discountAmount->localValue() * sense); newReceipt.exec(); } else if (_mode == cEdit) { XSqlQuery updateReceipt; updateReceipt.prepare( "UPDATE cashrcptitem " "SET cashrcptitem_amount=:cashrcptitem_amount, " "cashrcptitem_discount=:cashrcptitem_discount " "WHERE (cashrcptitem_id=:cashrcptitem_id);" ); updateReceipt.bindValue(":cashrcptitem_id", _cashrcptitemid); updateReceipt.bindValue(":cashrcptitem_amount", _amountToApply->localValue() * sense); updateReceipt.bindValue(":cashrcptitem_discount", _discountAmount->localValue() * sense); updateReceipt.exec(); } done(_cashrcptitemid); }
void cashReceiptItem::sSave() { if (_amountToApply->localValue() > _openAmount->localValue()) { QMessageBox::warning( this, tr("Cannot Apply"), tr("You may not apply more than the balance of this item.") ); _amountToApply->setFocus(); return; } int sense = 1; if (_docType->text() == "C" || _docType->text() == "R") sense = -1; if (_mode == cNew) { XSqlQuery cashrcptitemid("SELECT NEXTVAL('cashrcptitem_cashrcptitem_id_seq') AS _cashrcptitem_id;"); if (cashrcptitemid.first()) _cashrcptitemid = cashrcptitemid.value("_cashrcptitem_id").toInt(); XSqlQuery newReceipt; newReceipt.prepare( "INSERT INTO cashrcptitem " "( cashrcptitem_id, cashrcptitem_cashrcpt_id," " cashrcptitem_aropen_id, cashrcptitem_amount, cashrcptitem_discount ) " "VALUES " "( :cashrcptitem_id, :cashrcptitem_cashrcpt_id," " :cashrcptitem_aropen_id, :cashrcptitem_amount, :cashrcptitem_discount );" ); newReceipt.bindValue(":cashrcptitem_id", _cashrcptitemid); newReceipt.bindValue(":cashrcptitem_cashrcpt_id", _cashrcptid); newReceipt.bindValue(":cashrcptitem_aropen_id", _aropenid); newReceipt.bindValue(":cashrcptitem_amount", _amountToApply->localValue() * sense); newReceipt.bindValue(":cashrcptitem_discount", _discountAmount->localValue() * sense); newReceipt.exec(); } else if (_mode == cEdit) { XSqlQuery updateReceipt; updateReceipt.prepare( "UPDATE cashrcptitem " "SET cashrcptitem_amount=:cashrcptitem_amount, " "cashrcptitem_discount=:cashrcptitem_discount " "WHERE (cashrcptitem_id=:cashrcptitem_id);" ); updateReceipt.bindValue(":cashrcptitem_id", _cashrcptitemid); updateReceipt.bindValue(":cashrcptitem_amount", _amountToApply->localValue() * sense); updateReceipt.bindValue(":cashrcptitem_discount", _discountAmount->localValue() * sense); updateReceipt.exec(); } done(_cashrcptitemid); }