/** * @brief StatUtil::_inspectExtraException * 重新计算指定科目的余额,并检测其余额是否异常 * 异常的余额:正向记账科目,余额方向为贷,反向记账科目,余额方向为借 * @param fsub * @param ssub * @param mt */ void StatUtil::_inspectExtraException(BusiAction* ba) { FirstSubject* fsub = ba->getFirstSubject(); SecondSubject* ssub = ba->getSecondSubject(); Money* mt = ba->getMt(); int key_f = fsub->getId() * 10 + mt->code(); int key_s = ssub->getId() * 10 + mt->code(); bool r = false; if(fsub->getJdDir()){ //正向记账科目 //余额方向必须在借方,且余额必须大于0 if((endFDir.value(key_f) == MDIR_D && endFExa.value(key_f) > 0.0) || (endFDir.value(key_f) == MDIR_J && endFExa.value(key_f) < 0.0)) r = true; if((endSDir.value(key_s) == MDIR_D && endSExa.value(key_s) > 0.0) || (endSDir.value(key_s) == MDIR_J && endSExa.value(key_s) < 0.0)) r = true; } else{ //余额必须在贷方,且余额值必须大于0 if((endFDir.value(key_f) == MDIR_J && endFExa.value(key_f) > 0.0) || (endFDir.value(key_f) == MDIR_D && endFExa.value(key_f) < 0.0)) r = true; if((endSDir.value(key_s) == MDIR_J && endSExa.value(key_s) > 0.0) || (endSDir.value(key_s) == MDIR_D && endSExa.value(key_s) < 0.0)) r = true; } if(r) emit extraException(ba,endFExa.value(key_f), endFDir.value(key_f),endSExa.value(key_s),endSDir.value(key_s)); }
void Money::operator =(Money Cash) { this->wasBelowZero=Cash.getWasBelowZero(); this->wasZeroFirst=Cash.getWasZero(); this->gold=Cash.gold; this->penny=Cash.penny; }
//------------------------------------------------------------------------------ void ConditionValueDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { switch (field(index)) { case AssignmentRule::Date: { QDateEdit* dateEditor = static_cast<QDateEdit*>(editor); QDate date = dateEditor->date(); model->setData(index, date.toString(Qt::ISODate), Qt::EditRole); } break; case AssignmentRule::Amount: { MoneyEdit* moneyEditor = static_cast<MoneyEdit*>(editor); Money amount = moneyEditor->value(); QString newVal = QString("%1,%2") .arg(amount.amount()).arg(amount.currency().code()); model->setData(index, newVal, Qt::EditRole); } break; default: { LineEdit* stringEditor = static_cast<LineEdit*>(editor); model->setData(index, stringEditor->text(), Qt::EditRole); } } }
// // ------ (/) operator --- // Money Money::operator/(double value) const { Money temp; if (value != 0) temp.amount(amount() / value); return temp; }
Money operator+(const Money& l,const Money& r) { // std::cout << "left cents: " << l.get_cents() << '\n'; // std::cout << "right cents: " << r.get_cents() << '\n'; // std::cout << "left + right: " << l.get_cents() + r.get_cents() << '\n'; return Money(l.get_money_in_cents() + r.get_money_in_cents()); }
void CollisionMoneyIndie(iCollidable& _money, iCollidable& _indie) { Money* money = dynamic_cast<Money*>(&_money); Indie* indie = dynamic_cast<Indie*>(&_indie); money->markMeForDeletion(); Vector2 formerSize = indie->GetSize(); //indie->SetSize(formerSize.X * 2, formerSize.Y * 2); }
TEST(ExpressionTest, PlusReturnSum) { Money* five = Money::dollar(5); Expression* result = five->plus(five); Sum* sum = dynamic_cast<Sum*>(result); EXPECT_EQ(*five,*(sum->augend)); EXPECT_EQ(*five,*(sum->addend)); delete five; delete result; }
// // ------ Main (Driver) ------ int main(void) { Money Giveme(10,120); Money IWant(11.20); Money GotNone; cout << " I gave you " ; Giveme.show(); cout << endl; cout << " You Wanted " ; IWant.show(); cout << endl; cout << " you got nothing " ; GotNone.show() ; cout << endl; return 0; }
// // ------ Main (Driver) ------ int main(void) { Money Giveme(10,12); Money IWant(11.20); Money GotNone; cout << " I gave you " << Giveme.amount() << endl; cout << " You Wanted " << IWant.amount() << endl; cout << " you got nothing " << GotNone.amount() << endl; cout << " Giving you more from " << Giveme.amount(20.35); cout << " To " << Giveme.amount() << endl; Money MaxMoney = Giveme.max(IWant), MinMoney = IWant.min(Giveme); cout << " The Max Money is " << MaxMoney.amount() << endl; cout << " The Min Money is " << MinMoney.amount() << endl; Giveme.add(IWant); cout << " The Add Money is " ; Giveme.show(); cout << endl; IWant.sub(Giveme); cout << " The Sub Money is " ; IWant.show() ; cout << endl; IWant.use_parens(); cout << " The account style Money is " ; IWant.show() ; cout << endl; Giveme.mul(2.0); cout << " The Mul Money is " ; Giveme.show(); cout << endl; IWant.div(-1.0); cout << " The div Money is " ; IWant.show() ; cout << endl; return 0; }
void CompanyWidget::updateInfo() { int index = ui->company->currentIndex(); if (index < 0) { return; } Company *company = (Company *) ui->company->itemData(index, PPLib::entityRole).toInt(); Money credit = company->fields["company_credit"]; ui->creditCustomer->setText(credit.toString()); Money debt = company->fields["company_debt"]; ui->debtCustomer->setText(debt.toString()); }
Money Money::Sub(Money b) { Money a; RtoK(); b.RtoK(); a = *this; a.rub = a.rub.Sub(b.rub); KtoR(); b.KtoR(); return a; }
TEST(MoneyTest, SimpleAddition) { Money* five = Money::dollar(5); Money* ten = Money::dollar(10); Expression* sum = five->plus(five); Bank* bank = new Bank(); Money* reduced = bank->reduce(sum,"USD"); EXPECT_EQ(*ten,*reduced); delete five; delete ten; delete sum; delete reduced; }
bool Wager::MethodPress(Money &cMoney, const Table &cTable, std::list<Bet> &lBets, const int nTimes) { BetModificationSetup(cTable, lBets); if (m_bWon) ++m_nBetModCounter; // If a bet won and counter is less than or equal to nTimes, Press the bet. // 1) Loop through bets, find those that are modifiable and have won. // 2) Double their wager // 3) Set their state to Unresolved int nNewWager = 0; if (m_bWon) { if (m_nBetModCounter <= nTimes) { for (std::list<Bet>::iterator it = lBets.begin(); it != lBets.end(); ++it) { if (it->Modifiable() && it->Won()) { nNewWager = it->Wager() * 2; cMoney.Decrement(nNewWager); it->SetWager(nNewWager); it->SetUnresolved(); } } } else { m_nBetModCounter = 0; } } return (false); }
Money Money::operator*(double r) { wasBelowZero=false; wasZeroFirst=false; long long int newtotal; Money cash = doubleWith2Decimal(r); newtotal= countPenny() * cash.countPenny(); QString total = QVariant(newtotal).toString(); QString rest = total.right(4); if(rest.at(0)=='0') wasZeroFirst=true; return Money(newtotal / 10000, roundPennys(newtotal % 10000), wasZeroFirst); }
/*Money*/void Money::Div(Money b) { //Money a; RtoK(); b.RtoK(); //a = *this; //a.rub = a.rub.Div(b.rub); rub.Div(b.rub); KtoR(); b.KtoR(); //return a; }
Decimal operator/(const Money& m1, const Money& m2) { if (m1.currency() == m2.currency()) { return m1.value()/m2.value(); } else if (Money::conversionType == Money::BaseCurrencyConversion) { Money tmp1 = m1; convertToBase(tmp1); Money tmp2 = m2; convertToBase(tmp2); return tmp1/tmp2; } else if (Money::conversionType == Money::AutomatedConversion) { Money tmp = m2; convertTo(tmp, m1.currency()); return m1/tmp; } else { QL_FAIL("currency mismatch and no conversion specified"); } }
bool close_enough(const Money& m1, const Money& m2, Size n) { if (m1.currency() == m2.currency()) { return close_enough(m1.value(),m2.value(),n); } else if (Money::conversionType == Money::BaseCurrencyConversion) { Money tmp1 = m1; convertToBase(tmp1); Money tmp2 = m2; convertToBase(tmp2); return close_enough(tmp1,tmp2,n); } else if (Money::conversionType == Money::AutomatedConversion) { Money tmp = m2; convertTo(tmp, m1.currency()); return close_enough(m1,tmp,n); } else { QL_FAIL("currency mismatch and no conversion specified"); } }
// "const" can protect the sum Money object from the unwanted change const Money operator +(const Money& amount1, const Money& amount2){ int allCents1 = amount1.getCents() + amount1.getDollars() * 100; int allCents2 = amount2.getCents() + amount2.getDollars() * 100; int summAllCents = allCents1 + allCents2; int absAllCents = abs(summAllCents); // Money can be negative int finalDollars = absAllCents / 100; int finalCents = absAllCents % 100; if (sumAllCents < 0){ finalDollars = -finalDollars; finalCents = -finalCents; } // constructor is not a "void" function // A constructor can return an object // Called an "anonymous object" return Money(finalDollars, finalCents); }
TEST(DollarTest, MultiPlication) { Money* five = Money::dollar(5); Expression* ten = five->times(2); Expression* fifteen = five->times(3); Money* cmp_ten = Money::dollar(10); Money* cmp_fifteen = Money::dollar(15); EXPECT_EQ(*cmp_ten,*ten); EXPECT_EQ(*cmp_fifteen,*fifteen); delete cmp_ten; delete cmp_fifteen; delete ten; delete fifteen; delete five; }
void CompanyWidget::on_company_currentIndexChanged(int index) { if (index < 0) { return; } Company *company = (Company *) ui->company->itemData(index, PPLib::entityRole).toInt(); if (!ui->contactFrame->isHidden()) { contactF->setMatchValue(company->getId()); } if (!ui->finFrame->isHidden()){ Money credit = company->fields["company_credit"]; ui->creditCustomer->setText(credit.toString()); Money debt = company->fields["company_debt"]; ui->debtCustomer->setText(debt.toString()); } emit companyChanged(company); }
bool Wager::MethodTakeDownAfterHits(Money &cMoney, const Table &cTable, std::list<Bet> &lBets, const int nTimes) { BetModificationSetup(cTable, lBets); if (m_bWon) ++m_nBetModCounter; // If a bet won and counter is less than or equal to nTimes, Press the bet. // 1) Loop through bets, find those that are modifiable and have won. // 2) Make a new bet at the same wager. // 3) Set their state to Unresolved if (m_bWon) { if (m_nBetModCounter <= nTimes) { for (std::list<Bet>::iterator it = lBets.begin(); it != lBets.end(); ++it) { if (it->Modifiable() && it->Won()) { cMoney.Decrement(it->Wager()); it->SetUnresolved(); } } } // Else remove all modifiable unresolved bets and reset thge counter else { for (std::list<Bet>::iterator it = lBets.begin(); it != lBets.end(); ++it) { if (it->Modifiable() && !it->Resolved()) { cMoney.Increment(it->Wager()); it->SetReturned(); } } m_nBetModCounter = 0; } } return (false); }
// // ------ Main (Driver) ------ int main(void) { Money Giveme(10,12); Money IWant; Money GotNone; cout << " Enter what you want " ; cin >> IWant; cout << " I gave you " << Giveme.amount() << endl; cout << " You Wanted " << IWant.amount() << endl; cout << " you got nothing " << GotNone.amount() << endl; cout << " Giving you more from " << Giveme.amount(20.35); cout << " To " << Giveme.amount() << endl; Money MaxMoney = Giveme.max(IWant), MinMoney = IWant.min(Giveme); cout << " The Max Money is " << MaxMoney.amount() << endl; cout << " The Min Money is " << MinMoney.amount() << endl; Money AddMoney = Giveme + IWant; cout << " The Add Money is " << AddMoney << endl; Money SubMoney = IWant - Giveme; cout << " The account style Money is " << SubMoney << endl; SubMoney.use_parens(); cout << " The account style Money is " << SubMoney << endl; Money MulMoney2 = Giveme * 2.0; cout << " The Mul Money * 2 is " << MulMoney2 << endl; Money MulMoney4 = 4.0 * Giveme; cout << " The 4 * Mul Money is " << MulMoney4 << endl; Money DivMoney = IWant / (2.0); cout << " The div Money is " << DivMoney << endl; return 0; }
bool Money::operator < (Money b) { RtoK(); b.RtoK(); if (rub < b.rub) { KtoR(); return true; } else { KtoR(); return false; } }
int main() { Money A; A.setC(45); A.setD(40); cout<<"cent="<<A.getC()<<endl; cout<<"dollar="<<A.getD()<<endl; cout<<"money="<<A.getMoney()<<endl; cin.get(); return 0; }
Money ExchangeRate::exchange(const Money& amount) const { switch (type_) { case Direct: if (amount.currency() == source_) return Money(amount.value()*rate_, target_); else if (amount.currency() == target_) return Money(amount.value()/rate_, source_); else QL_FAIL("exchange rate not applicable"); case Derived: if (amount.currency() == rateChain_.first->source() || amount.currency() == rateChain_.first->target()) return rateChain_.second->exchange( rateChain_.first->exchange(amount)); else if (amount.currency() == rateChain_.second->source() || amount.currency() == rateChain_.second->target()) return rateChain_.first->exchange( rateChain_.second->exchange(amount)); else QL_FAIL("exchange rate not applicable"); default: QL_FAIL("unknown exchange-rate type"); } }
//---------------------------------------------------------------------- // remove effect from target //---------------------------------------------------------------------- void EffectDecayItem::unaffect (Zone* pZone , ZoneCoord_t x , ZoneCoord_t y , Object* pTarget) throw(Error) { __BEGIN_TRY // 올바른 좌표이어야 한다. Assert(isValidZoneCoord(pZone, x, y)); // TempItem 변수를 잡는다. Item* pTempItem = NULL; // 여기서는 지정 아이템이 없을 수 있으며, 또 다른 아이템이 놓여 있을 수도 있다. // 이 경우는 오리지널 아이템과 지금 현재 바닥에 있는 아이템을 비교하여 삭제해야 한다. // 없을 경우는 무시하면 된다. Tile & tile = pZone->getTile(x, y); if (tile.hasItem()) { pTempItem = tile.getItem(); if (pTempItem != NULL) { // ObjectID가 같다는 말은 같은 아이템이란 말이다. //if (pTempItem->getObjectID() == m_ObjectID) { if (pTempItem->getObjectID() == m_ObjectID) { pZone->deleteItem(pTempItem , x, y); // 아이템이 사라졌다는 패킷을 날린다. GCDeleteObject gcDeleteObject; gcDeleteObject.setObjectID(m_ObjectID); pZone->broadcastPacket(x, y , &gcDeleteObject); if (m_bDeleteFromDB) { //ItemInfo* pItemInfo = g_pItemInfoManager->getItemInfo(pTempItem->getItemClass(), pTempItem->getItemType()); //Assert(pItemInfo!=NULL); // 유니크 아이템인 경우 개수를 줄인다. if (pTempItem->isUnique()) { // create한 아이템이 아닌 경우만 지워준다. if (pTempItem->getCreateType()!=Item::CREATE_TYPE_CREATE) UniqueItemManager::deleteItem(pTempItem->getItemClass(), pTempItem->getItemType()); filelog("uniqueItem.txt", "[EffectDecayItem] %s", pTempItem->toString().c_str()); } // ItemTraceLog 를 남긴다 /* * 존에 떨어진 아이템중 expire time인것들 모두 로그를 빼버린다. if (pTempItem != NULL && pTempItem->isTraceItem() ) { char zoneName[15]; sprintf(zoneName, "%4d%3d%3d", pZone->getZoneID(), x, y); remainTraceLog(pTempItem, zoneName, "GOD", ITEM_LOG_DELETE, DETAIL_TIMEOUT); } */ // 돈 로그 남기자 if (pTempItem->getItemClass() == Item::ITEM_CLASS_MONEY ) { Money* pMoney = dynamic_cast<Money*>(pTempItem); if (pMoney->getAmount() >= g_pVariableManager->getMoneyTraceLogLimit() ) { char zoneName[15]; sprintf(zoneName, "%4d%3d%3d", pZone->getZoneID(), x, y); remainMoneyTraceLog(zoneName, "GOD", ITEM_LOG_DELETE, DETAIL_TIMEOUT, pMoney->getAmount()); } } pTempItem->destroy(); } SAFE_DELETE(pTempItem); } } } pTarget = NULL; __END_CATCH }
Money operator*(const Money &m, double factor) { return Money(m.amount() * factor); }
Money Money::operator-(const Money & m) const { return Money(amount() - m.amount()); }
Money Money::operator+(const Money & m) const { return Money(m.amount() + amount()); }
// For testing (DO NOT ALTER) void UnitTest() { cout << string(40, '-') << endl; cout << "UNIT TEST:\n" << string(40, '-') << endl; if (num_of_tests != 0) cout << "Total Number of Tests: " << num_of_tests << endl; string yours = "", actual = ""; // Tests Money amount1(123, 45), amount2(10, 9); Money sum = amount1 + amount2; Money diff1 = amount1 - amount2; Money diff2 = amount2 - amount1; Test(sum.dollars() == 133 && sum.cents() == 54, __LINE__, "$123.45 + $10.09"); Test(diff1.dollars() == 113 && diff1.cents() == 36, __LINE__, "$123.45 - $10.09"); Test(diff2.dollars() == -113 && diff2.cents() == -36, __LINE__, "$10.09 - $123.45"); amount1 = -amount1; Test(amount1.dollars() == -123 && amount1.cents() == -45, __LINE__, "-$123.45"); Test((diff2 == diff1) == false, __LINE__, "$113.36 == $-113.36"); amount1.set_dollars(-8); amount1.set_cents(-75); amount2.set_dollars(0); amount2.set_cents(50); sum = amount1 + amount2; diff1 = amount1 - amount2; diff2 = amount2 - amount1; Test(sum.dollars() == -8 && sum.cents() == -25, __LINE__, "$-8.75 + $0.50"); Test(diff1.dollars() == -9 && diff1.cents() == -25, __LINE__, "$-8.75 - $0.50"); Test(diff2.dollars() == 9 && diff2.cents() == 25, __LINE__, "$0.50 - $8.75"); diff1 = -diff1; Test(diff1.dollars() == 9 && diff1.cents() == 25, __LINE__, "-$-9.25"); Test((diff2 == diff1) == true, __LINE__, "$9.25 == $9.25"); Money one(0, 10), two(0, -10), three(100, 2), four(-100, -2); std::streambuf* old_cout = cout.rdbuf(); std::ostringstream capture_cout; cout.rdbuf(capture_cout.rdbuf()); cout << Money(0, 10); cout.rdbuf(old_cout); yours = capture_cout.str(); actual = "$0.10"; Test(yours == actual, __LINE__, "<< Money(0, 10)", yours, actual); capture_cout.str(""); cout.rdbuf(capture_cout.rdbuf()); cout << Money(0, -10); cout.rdbuf(old_cout); yours = capture_cout.str(); actual = "$-0.10"; Test(yours == actual, __LINE__, "<< Money(0, -10)", yours, actual); capture_cout.str(""); cout.rdbuf(capture_cout.rdbuf()); cout << Money(100, 2); cout.rdbuf(old_cout); yours = capture_cout.str(); actual = "$100.02"; Test(yours == actual, __LINE__, "<< Money(100, 2)", yours, actual); capture_cout.str(""); cout.rdbuf(capture_cout.rdbuf()); cout << Money(-100, -2); cout.rdbuf(old_cout); yours = capture_cout.str(); actual = "$-100.02"; Test(yours == actual, __LINE__, "<< Money(-100, -2)", yours, actual); cout << string(40, '-') << endl; cout << "Passed: " << ut_passed << " / " << ut_total << endl; OutputFailedTests(); cout << string(40, '-') << endl; cout << "END OF UNIT TEST!\n"; cout << string(40, '-') << endl; cout << "Be sure to run 'make style' to check for any style errors.\n" << "Please note that 'make style' does NOT check variable names or" << " indentation" << endl << endl; }