예제 #1
0
 void EnergyCommodity::calculateSecondaryCostAmounts(
                                        const CommodityType& commodityType,
                                        Real totalQuantityValue,
                                        const Date& evaluationDate) const {
     secondaryCostAmounts_.empty();
     if (secondaryCosts_ != 0) {
         const Currency& baseCurrency =
             CommoditySettings::instance().currency();
         try {
             for (SecondaryCosts::const_iterator i = secondaryCosts_->begin();
                  i != secondaryCosts_->end(); i++) {
                 if (boost::any_cast<CommodityUnitCost>(&i->second)) {
                     Real value =
                         calculateUnitCost(
                             commodityType,
                             boost::any_cast<CommodityUnitCost>(i->second),
                             evaluationDate) * totalQuantityValue;
                     secondaryCostAmounts_[i->first] =
                         Money(baseCurrency, value);
                 } else if (boost::any_cast<Money>(&i->second)) {
                     const Money& amount = boost::any_cast<Money>(i->second);
                     Real fxConversionFactor =
                         calculateFxConversionFactor(amount.currency(),
                                                     baseCurrency,
                                                     evaluationDate);
                     secondaryCostAmounts_[i->first] =
                         Money(baseCurrency,
                               amount.value() * fxConversionFactor);
                 }
             }
         } catch (const std::exception& e) {
             QL_FAIL("error calculating secondary costs: " << e.what());
         }
     }
 }
예제 #2
0
void LaminatTask::clear()
{
    total = Money(0);
    ui->totalInput->setMoney(total);
    emit totalChanged();
    ui->price->setMoney(Money(0));
    ui->checkGroup->setChecked(false);
}
예제 #3
0
void PaymentView::cacheChanged()
{
    QModelIndex index = accountModel->index(Account::MAIN, 0);
    Account *main = (Account *) accountModel->data(index, PPLib::entityRole).toInt();
    ui->cache->setText(Money(main->fields["account_cache"]).toString());
    ui->nonCache->setText(Money(main->fields["account_noncache"]).toString());

    index = accountModel->index(Account::DEPOSIT, 0);
    Account *depo = (Account *) accountModel->data(index, PPLib::entityRole).toInt();
    ui->depoCache->setText(Money(depo->fields["account_cache"]).toString());
    ui->depoNonCache->setText(Money(depo->fields["account_noncache"]).toString());
}
예제 #4
0
MainWindow::MainWindow(QWidget* parent) :
    QMainWindow(parent),
    ui_(new Ui::MainWindow),
    data_file_name_(DATA_FILE_PATH),
    password_(QString()),
    money_(Money())
{
    ui_->setupUi(this);

    connect(ui_->ActionChangePass, SIGNAL(triggered()), this, SLOT(changePassword()));
    connect(ui_->ActionSave,       SIGNAL(triggered()), this, SLOT(saveData()));
    connect(ui_->ActionExit,       SIGNAL(triggered()), this, SLOT(requestExit()));
    connect(ui_->ActionUpdate,     SIGNAL(triggered()), this, SLOT(updateState()));
    connect(ui_->AddEventButton,   SIGNAL(clicked()),   this, SLOT(addEvent()));
    connect(ui_->AddFriendButton,  SIGNAL(clicked()),   this, SLOT(addFriend()));
    connect(ui_->DelEventsButton,  SIGNAL(clicked()),   this, SLOT(delEvents()));
    connect(ui_->DelFriendsButton, SIGNAL(clicked()),   this, SLOT(delFriends()));

    // financial events
    connect(ui_->CurRubNalEdit,    SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->CurEurNalEdit,    SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->CurUsdNalEdit,    SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->CurRubElecEdit,   SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->CurEurElecEdit,   SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->CurUsdElecEdit,   SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->OldRubNalEdit,    SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->OldEurNalEdit,    SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->OldUsdNalEdit,    SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->OldRubElecEdit,   SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->OldEurElecEdit,   SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));
    connect(ui_->OldUsdElecEdit,   SIGNAL(textChanged(QString)), this, SLOT(changeMoneyDiff()));

    loadData();
    updateState();
}
예제 #5
0
 const Money operator -(const Money &amount)
 {
   int final_dollars=-amount.dollars_;
   int final_cents=-amount.cents_;
   return Money(final_dollars,final_cents);
   //turns values negative. outputs them back
 }
예제 #6
0
파일: money.cpp 프로젝트: jingar/cplusplus
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());
}
예제 #7
0
Money Deposit::calcWithCap(double rates, m_long startsum,int day)
{
    m_long value=0;
    int day_to_ny=open_date.getDaysToNewYear();
    double D_i=0,persent_coef;
    while(day)
    {
        day_to_ny=open_date.getDaysToNewYear();
        if(day>=day_to_ny&&day!=0)
        {
            D_i=day_to_ny/30.;
            persent_coef=(1+rates*30./((open_date.isLeapYear()? 366. : 365.)*100.));
            value=(value+startsum)*pow(persent_coef,D_i)-startsum;
            open_date=open_date+day_to_ny;
            day=day-day_to_ny;
        }
        day_to_ny=open_date.getDaysToNewYear();
        if(day<day_to_ny&&day!=0)
        {
            D_i=day/30.;
            persent_coef=(1.+rates*30./((open_date.isLeapYear()?366.:365.)*100.));
            value=(value+startsum)*pow(persent_coef,D_i)-startsum;
            open_date=open_date+day;
            day=0;
        }

    }
    return Money(ABSTRACT, value);
}
예제 #8
0
파일: Money.cpp 프로젝트: milczarekIT/agila
Money Money::doubleWith2Decimal(double r)
{
    QString digit = QVariant(r).toString();
    if(digit.section(".",1,1).length()==1)
        digit.append('0');
        digit.replace('.',',');
    return Money(digit);
}
예제 #9
0
Money Money::READ(std::istream& lhs)
{
    int rub, kop;
    char c;
    lhs >> rub >> c;
    assert( c == ',' || c == '.' );
    lhs >> kop;
    return Money(rub, kop);
}
예제 #10
0
Money DebtReportM::getTotal()
{
    Money total;
    for (int i = 0; i < rowCount(); i++){
        int cents = abs(ReportModel::data(index(i, 2), Qt::DisplayRole).toInt());
        total = total + Money(cents);
    }
    return total;
}
예제 #11
0
파일: banktest.cpp 프로젝트: KDE/kdev-xtest
void BankTest::depositMoney()
{
    Bank b;
    int clientID = 10;
    Money m(5, "USD");

    b.deposit(clientID, m);
    QCOMPARE(Money(5, "USD"), b.accountBalance(clientID));
    QCOMPARE(1, b.numberOfClients());
}
예제 #12
0
TEST(MoneyTest, TempObject) {
    
    const Money& six_dol = Money(6,"USD");
    EXPECT_TRUE(six_dol == Money(6,"USD"));
    EXPECT_FALSE(six_dol == Money(5,"USD"));
    EXPECT_FALSE(six_dol == Money(6,"CHF"));
    
    const Money& six_fla = Money(6,"CHF");
    EXPECT_TRUE(six_fla == Money(6,"CHF"));
    EXPECT_FALSE(six_fla == Money(5,"CHF"));
    EXPECT_FALSE(six_fla == Money(6,"USD"));
    
}
예제 #13
0
파일: Money.cpp 프로젝트: milczarekIT/agila
Money Money::operator + (Money r)
{
    wasZeroFirst=false;
    wasBelowZero=false;
    long long int newtotal;
    newtotal= countPenny() + countPenny(r);
    QString total = QVariant(newtotal).toString();
    QString rest = total.right(2);
    if(rest.at(0)=='0')
        wasZeroFirst=true;
    return Money(newtotal / 100, newtotal % 100, wasZeroFirst);
}
예제 #14
0
파일: realEstate.c 프로젝트: ombt/ombt
Money
RealEstate::monthlyMortgagePayment() const
{
	Money lp = loanPrincipal;

	Number lly = loanLength;
	Number llm = loanLength*MonthsPerYear;

	Number liy = loanInterest/100.0;
	Number lim = liy/MonthsPerYear;

	return(Money(lp*lim/(1.0-pow((1.0+lim), -1.0*llm))));
}
예제 #15
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");
     }
 }
예제 #16
0
  /*
   * Overload of binary - operator. This is a friend function.
   * @param Money amount1 - The object to subtract from
   * @param Money amount2 - The object to be subtracted
   * @return Money - The result of the subtraction
   */
const Money operator -(const Money& amount1, const Money& amount2) {
  int all_cents1 = amount1.cents_ + amount1.dollars_ * 100;
  int all_cents2 = amount2.cents_ + amount2.dollars_ * 100;
  // subtract all the cents together
  int difference_all_cents = all_cents1 - all_cents2;
  // Handle the fact that money can be negative
  int abs_all_cents = abs(difference_all_cents);
  int final_dollars = abs_all_cents / 100;
  int final_cents = abs_all_cents % 100;
  // If the result of the operation was negative, negate final dollars and cents
  if (difference_all_cents < 0) {
    final_dollars = -final_dollars;
    final_cents = -final_cents;
  }
  return Money(final_dollars, final_cents);
  }
예제 #17
0
파일: Money.cpp 프로젝트: milczarekIT/agila
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);
}
예제 #18
0
const Money operator -(const Money& amount1, const Money& amount2)
{
  int all_cents1=amount1.cents_ + amount1.dollars_*100;
  int all_cents2=amount2.cents_ + amount2.dollars_*100;
  int subtraction=all_cents1-all_cents2;
  //take first value minus second
  int abs_all_cents=abs(subtraction);
  int final_dollars= abs_all_cents/100;
  int final_cents= abs_all_cents%100;
  if(subtraction<0)
  //negates if necessary
  {
    final_dollars=-final_dollars;
    final_cents=-final_cents;
  }
  return Money(final_dollars,final_cents);
}
예제 #19
0
// This function definition provided as an example and is FULLY COMPLETE
const Money operator +(const Money& amount1, const Money& amount2) {
  // Get all the cents of object 1
  int all_cents1 = amount1.cents_ + amount1.dollars_ * 100;
  // Get all the cents of object 2
  int all_cents2 = amount2.cents_ + amount2.dollars_ * 100;
  // Add all the cents together
  int sum_all_cents = all_cents1 + all_cents2;
  // Handle the fact that money can be negative
  int abs_all_cents = abs(sum_all_cents);
  int final_dollars = abs_all_cents / 100;
  int final_cents = abs_all_cents % 100;
  // If the result of the operation was negative, negate final dollars and cents
  if (sum_all_cents < 0) {
    final_dollars = -final_dollars;
    final_cents = -final_cents;
  }
  return Money(final_dollars, final_cents);
}
예제 #20
0
파일: Money.cpp 프로젝트: milczarekIT/agila
Money Money::operator - (Money r)
{
    wasZeroFirst=false;
    wasBelowZero=false;
    long long int newtotal ;

    if(countPenny()-countPenny(r)>0 && countPenny()-countPenny(r) <10 )
        wasZeroFirst=true;
    else if (countPenny()-countPenny(r)>-10 && countPenny()-countPenny(r) <-0)
      {
       wasZeroFirst=true;
       wasBelowZero=true;
      }
   else if (countPenny()-countPenny(r)<0)
       wasBelowZero=true;

    newtotal= abs(countPenny() - countPenny(r));
    return Money(newtotal / 100, newtotal % 100,wasZeroFirst,wasBelowZero);

}
예제 #21
0
void LaminatTask::entity2Form(Entity *task)
{
    ui->product->blockSignals(true);

    Stock *stock = ui->product->getParam();
    if (stock == NULL) {
        ui->product->setRole(ProductModel::processRole, processId);
    }

    total = Money(task->fields["task_total"]);
    total.isCustom = true;

    ui->equip->setEquip(task->fields["equipment_id"].toInt());

    int productId = task->fields["product_id"].toInt();
    int stockId = task->fields["stock_id"].toInt();
    ui->product->setParam(productId, stockId);

    ui->checkGroup->setChecked(true);
}
예제 #22
0
int main (void)
{
	struct nodo * list = NULL; 	/* list will be a pointer to the first
					node of the linked list */
	int	choice;
	do
	{
		clrscr();
		textcolor (4);
		cputs ("\nDouble Linked Lists - Nicolas Raitman");
		textcolor (7);
		puts("\n\n0 - Exit");
		puts("1 - New Item");
		puts("2 - See All Items in the Linked List");
		puts("3 - Show Items One by One");
		puts("4 - Search Item");
		puts("5 - Delete Item");
		puts("6 - Delete Entire List");
		puts("7 - Money");
		puts("8 - Flush Linked List to File");
		puts("9 - Read File and Create Linked List");
		CHOICE (choice);
		switch (choice)
		{
			case 0:	Exit(&list); break;
			case 1: AddClient(&list); break;
			case 2: SeeAll(&list); break;
			case 3: OneByOne(&list); break;
			case 4: Search(&list); break;
			case 5: Delete(&list); break;
			case 6: FreeAll(&list); break;
			case 7: Money (&list); break;
			case 8: Flush2File(&list); break;
			case 9: ReadFile(&list); break;
			default: break;
		}
	} while (choice != 0);
	return EXIT_OK;
}
//------------------------------------------------------------------------------
void ConditionValueDelegate::setEditorData(QWidget* editor,
	const QModelIndex& index) const
{
	QString value = index.model()->data(index, Qt::EditRole).toString();

	switch (field(index))
	{
	case AssignmentRule::Date:
	{
		QDateEdit* dateEditor = static_cast<QDateEdit*>(editor);
		QDate date = QVariant(value).toDate();
		if (date.isValid())
			dateEditor->setDate(date);
		else
			dateEditor->setDate(QDate::currentDate());
	}
		break;

	case AssignmentRule::Amount:
	{
		MoneyEdit* moneyEditor = static_cast<MoneyEdit*>(editor);
		if ( ! value.contains(","))
			return;
		QStringList amtParts = value.split(",");
		if (amtParts.size() != 2)
			return;
		Money amount = Money(QVariant(amtParts[0]).toDouble(), amtParts[1]);
		moneyEditor->setValue(amount);
	}
		break;

	default:
	{
		LineEdit* stringEditor = static_cast<LineEdit*>(editor);
		stringEditor->setText(value);
	}
		break;
	}
}
예제 #24
0
//------------------------------------------------------------------------------
Budget::Budget()
	: budgetName(tr("New Budget")), period(new BudgetingPeriod),
	  initial(Balance::create())
{
	rootEstimate = Estimate::createRoot();
	Estimate* root = rootEstimate.data();
	Estimate* expenses = Estimate::create(root, 1001,
		"Expenses", "", Estimate::Expense, Money(12.0), -1, false);
	Estimate* incomes = Estimate::create(root, 1002,
		"Incomes", "", Estimate::Income, Money(32.0), -1, true);
	Estimate* salary = Estimate::create(incomes, 2001,
		"Salary", "", Estimate::Income, Money(100.0), -1, false);
	Estimate* utilities = Estimate::create(expenses, 3001,
		"Utilities", "", Estimate::Expense, Money(50.0), -1, true);
	Estimate* rent = Estimate::create(utilities, 4001,
		"Rent", "Apt.", Estimate::Expense, Money(500.0), 27, false);
	Estimate* water = Estimate::create(utilities, 4002,
		"Water", "", Estimate::Expense, Money(25.34), 10, true);
	Estimate* food = Estimate::create(expenses, 3002,
		"Food", "", Estimate::Expense, Money(120.0), -1, false);
	Estimate* loan = Estimate::create(root, 1003,
		"Loan Payment", "", Estimate::Transfer, Money(50.0), 20, false);

	assignmentRules = AssignmentRules::create();
	QList<AssignmentRule::Condition> conditions;
	conditions << AssignmentRule::Condition(AssignmentRule::Payee, AssignmentRule::StringEquals, false, "Vendor");

	assignmentRules->createRule(20010, 2001, conditions);
	assignmentRules->createRule(40010, 4001, conditions);
	conditions << AssignmentRule::Condition(AssignmentRule::DepositAccount, AssignmentRule::EndsWith, true, "Acct");
	assignmentRules->createRule(30020, 3002, conditions);
	conditions.removeAt(0);
	assignmentRules->createRule(10030, 1003, conditions);

	uiPrefs = UIPrefs::create();
}
예제 #25
0
파일: realEstate.c 프로젝트: ombt/ombt
Money
RealEstate::interestPaid(const Number &year) const
{
	Money lp = loanPrincipal;

	Number lly = loanLength;
	Number llm = loanLength*MonthsPerYear;

	Number liy = loanInterest/100.0;
	Number lim = liy/MonthsPerYear;

	Money pm = lp*lim/(1.0-pow((1.0+lim), -1.0*llm));

	Number s = (year - 1.0)*MonthsPerYear;
	Number e = year*MonthsPerYear;
	if (s < 0.0)
		s = 0.0;

	Money sp = lp*pow((1.0+lim), s) - pm*(-1.0+pow((1.0+lim), s))/lim;
	Money ep = lp*pow((1.0+lim), e) - pm*(-1.0+pow((1.0+lim), e))/lim;

	return(Money(MonthsPerYear*pm - (sp - ep)));
}
예제 #26
0
Money Deposit::simpleCalc(double rates, m_long  startsum, int day)
{
    m_long value=0;
    int day_to_ny=open_date.getDaysToNewYear();
    while(day)
    {
        day_to_ny=open_date.getDaysToNewYear();
        if(day>=day_to_ny&&day!=0)
        {
            value=value+startsum*rates*day_to_ny/((open_date.isLeapYear()?366.:365.)*100.);
            open_date=open_date+day_to_ny;
            day=day-day_to_ny;
        }
        day_to_ny=open_date.getDaysToNewYear();
        if(day<day_to_ny&&day!=0)
        {
            value=value+startsum*rates*day/((open_date.isLeapYear()?366.:365.)*100.);
            open_date=open_date+day;
            day=0;
        }

    }
    return Money(ABSTRACT, value);
}
예제 #27
0
void PaymentDialog::setModel(QAbstractItemModel *model, int mode, Entity *view)
{
    paymentModel = (PaymentModel *) model;
    this->mode = mode;
    this->view = view;
    payment = new Payment();
    int id;

    if (mode == OTHER) {
        payModelF->setFilterRole(PayModel::otherRole);
        payModelF->setMatchValue(true);

        ui->table->hide();
        adjustSize();
        return;

    } else if (mode == ORDER) {
        id = view->fields["ordr_id"].toInt();

        payModelF->setFilterRole(PayModel::orderRole);
        payModelF->setMatchValue(true);

        QString info = QString::fromUtf8("Заказ №%1  ").arg(id);
        setupInfo(info);
        ui->total->setMoney(Money(view->fields["ordr_debt"]));
        setupTable(id, Pay::ORDER);

    } else if (mode == MATERIAL) {
        id = view->fields["material_id"].toInt();
        Material *material = (Material *) view;

        payModelF->setFilterRole(PayModel::materialRole);
        payModelF->setMatchValue(true);

        QString info = QString::fromUtf8("%1 %2 %3")
                        .arg(material->getProductName())
                        .arg(material->getStockName())
                        .arg(material->getParametr());

        setupInfo(info);
        ui->total->setMoney(Money(view->fields["material_debt"]));

        QString invoice = view->fields["material_invoice"].toString();
        ui->invoice->setInvoice(invoice);
        setupTable(id, Pay::MATERIAL);

    }  else if (mode == DEPOSIT) {
        id = view->fields["payment_field_id"].toInt();
        Payment *depositPayment = (Payment *) view;
        int type = depositPayment->getPayType();
        int paymentId = view->fields["payment_id"].toInt();

        if (type == Pay::ORDER ) {
            payModelF->setFilterRole(PayModel::debtOrderRole);
            setupTable(paymentId, Pay::ORDER);

        } else if (type == Pay::MATERIAL ) {
            payModelF->setFilterRole(PayModel::debtMaterialRole);
            setupTable(paymentId, Pay::MATERIAL);

        } else if (type == Pay::OTHER ) {
            payModelF->setFilterRole(PayModel::debtOtherRole);
            setupTable(paymentId, Pay::OTHER);
        }

        payModelF->setMatchValue(true);

        QString info = QString::fromUtf8("Относится к платежу %1.")
                .arg(paymentId);

        setupInfo(info);
        int cents = abs(view->fields["payment_debt"].toInt());
        ui->total->setMoney(Money(cents));

        QString invoice = view->fields["payment_invoice"].toString();
        ui->invoice->setInvoice(invoice);
    }

     payment->fields["payment_field_id"] = id;

}
예제 #28
0
Money operator*(const Money &m, double factor)
{
	return Money(m.amount() * factor);	 
}
예제 #29
0
Money Money::operator-(const Money & m) const
{
	 return Money(amount() - m.amount());
}
예제 #30
0
Money Money::operator+(const Money & m) const
{
	return Money(m.amount() + amount());	 
}