public IEnumerable<ProductTax> ReadTaxes() { var productTaxes = new List<ProductTax>(); var con = new SQLiteConnection(ConnectionString); con.Open(); using (con) { var sqlCommandString = @"SELECT Id, ProductName, Tax FROM ProductTaxes"; var sqlCommand = new SQLiteCommand(sqlCommandString, con); using (var reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { int id = (int)reader["Id"]; string name = (string)reader["ProductName"]; double tax = (double)reader["Tax"]; var taxItem = new ProductTax(id, name, tax); productTaxes.Add(taxItem); } } } return productTaxes; }
public void Create(ProductTax tax) { IcmsAliquot = tax.IcmsAliquot; IpiAliquot = tax.IpiAliquot; Id = tax.Id; IcmsValue = tax.IcmsValue; IpiValue = tax.IpiValue; }
public void CreateProduct(Product productToAdd, Tax taxToAdd) { var hasProductName = _dbCashierRegisterContext.Products.Any(product => string.Equals(product.Name, productToAdd.Name, StringComparison.CurrentCultureIgnoreCase)); if (hasProductName) { throw new Exception($"Product with name: {productToAdd.Name} already exists"); } var newProduct = new Product { Id = new Guid(), Name = productToAdd.Name, Price = productToAdd.Price, CountInStorage = productToAdd.CountInStorage }; _dbCashierRegisterContext.Products.Add(newProduct); var taxOrDefault = _dbCashierRegisterContext.Taxes.SingleOrDefault(tax => tax.Name == taxToAdd.Name); if (taxOrDefault == null) { taxOrDefault = new Tax { Name = taxToAdd.Name, Percentage = taxToAdd.Percentage, TaxType = TaxType.Excise }; _dbCashierRegisterContext.Taxes.Add(taxOrDefault); } var taxesOnProduct = new ProductTax { Product = newProduct, ProductId = newProduct.Id, Tax = taxOrDefault, TaxId = taxOrDefault.Id }; _dbCashierRegisterContext.ProductTaxes.Add(taxesOnProduct); var directTax = _dbCashierRegisterContext.Taxes.First(tax => tax.TaxType == TaxType.Direct); var directTaxOnProduct = new ProductTax { Product = newProduct, ProductId = newProduct.Id, Tax = directTax, TaxId = directTax.Id }; _dbCashierRegisterContext.ProductTaxes.Add(directTaxOnProduct); _dbCashierRegisterContext.SaveChanges(); }
public void ProductTax_Domain_CalculateIcms_Sucessfully() { //Arrange _taxProduct = ObjectMother.ValidProductTax(); double amount = 50; //ação _taxProduct.CalculateIcms(amount); //verificação _taxProduct.IcmsValue.Should().Be(2); }
private void BtnAddProductTax_Click(object sender, EventArgs e) { var productType = new ProductTax { ID = Guid.NewGuid(), ProductID = _product.ID, TaxId = (Guid)((ComboboxItem)comboTax.SelectedItem).Value, EntryDate = DateTime.Now, Status = "Active" }; productTaxController.Add(productType); MessageBox.Show("Product Tax Added Sucessfully"); this.Close(); _productComponent.PopulateProduct(_product.ID); }
public ProductAllTaxes GetAllTaxesForProduct(int productID, int?countryID, int?foreignCountryID) { ProductTax vatTax = null; if (countryID.HasValue) { vatTax = GetVatTax(productID, countryID); } ProductTax importTax = null, exportTax = null; if (foreignCountryID.HasValue && foreignCountryID != countryID) { importTax = productTaxRepository.FirstOrDefault(t => t.ProductID == productID && t.CountryID == foreignCountryID && t.ForeignCountryID == countryID && t.ProductTaxTypeID == (int)ProductTaxTypeEnum.Import); exportTax = productTaxRepository.FirstOrDefault(t => t.ProductID == productID && t.CountryID == countryID && t.ForeignCountryID == foreignCountryID && t.ProductTaxTypeID == (int)ProductTaxTypeEnum.Export); } List <ProductTax> taxes = new List <ProductTax>() { vatTax, importTax, exportTax }; var ret = new ProductAllTaxes(taxes); if (countryID.HasValue == false) { ret.VAT = 0; } if (foreignCountryID.HasValue == false) { ret.ImportTax = 0; ret.ExportTax = 0; } return(ret); }
public bool EditProduct(Product productEdited, Tax taxEdited) { var productInQuestion = ReadProduct(productEdited.Id); productInQuestion.Name = productEdited.Name; productInQuestion.Price = productEdited.Price; productInQuestion.CountInStorage = productEdited.CountInStorage; var productExciseTaxOrDefault = _dbCashierRegisterContext.Taxes.FirstOrDefault(tax => tax.Name == taxEdited.Name); if (productExciseTaxOrDefault != null) { productExciseTaxOrDefault.Percentage = taxEdited.Percentage; } else { productExciseTaxOrDefault = new Tax { Name = taxEdited.Name, Percentage = taxEdited.Percentage, TaxType = TaxType.Excise }; _dbCashierRegisterContext.Taxes.Add(productExciseTaxOrDefault); var productTax = new ProductTax { Product = productInQuestion, ProductId = productInQuestion.Id, Tax = productExciseTaxOrDefault, TaxId = productExciseTaxOrDefault.Id }; _dbCashierRegisterContext.ProductTaxes.Add(productTax); } _dbCashierRegisterContext.SaveChanges(); return(true); }
// override method ToString(): public override string ToString() { // String format from this documentation: (the link provide on the assignment was broken) // https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=netcore-3.1 // .ToString("C") adds th currency // string asteriskLine = new string('*', 40); string strFormated = String.Format( "* Name: {0,-30} *\n" + "* Price per unit: {1,-20:F2} *\n" + "* Quantity: {2, -26} *\n" + "* Total before tax: {3,-18:F2} *\n" + "* Tax: {4,-31:F2} *\n" + "* Total after tax: {5,-19:F2} *" , ProductName , PricePerUnit.ToString("C") , Quantity , ProductTotalBeforeTax.ToString("C") , ProductTax.ToString("C") , ProductTotalAfterTax.ToString("C")); return(strFormated); }
private void addForeignTax(CongressVoting voting, ProductTypeEnum productType, double rate, int foreignCountryID) { var tax = productTaxRepository.FirstOrDefault(t => t.ProductID == (int)productType && t.CountryID == voting.CountryID); if (tax == null) { tax = new ProductTax() { CountryID = voting.CountryID, ProductID = (int)productType, ProductTaxTypeID = (int)getProductTaxType((VotingTypeEnum)voting.VotingTypeID), TaxRate = (decimal)(rate / 100.0), ForeignCountryID = foreignCountryID }; productTaxRepository.Add(tax); } else { tax.TaxRate = (decimal)rate; } }
private KeyValuePair <ProductTaxTypeEnum, decimal> createDicTax(ProductTax tax) { return(new KeyValuePair <ProductTaxTypeEnum, decimal>((ProductTaxTypeEnum)tax.ProductTaxTypeID, tax.TaxRate)); }
public void Remove(ProductTax productTax) { this.productTaxesRepository.Delete(productTax); }
public void AddProductTax(ProductTax productTax) { this.productTaxesRepository.AddProductTax(productTax); }
public void Delete(ProductTax entry) { this.context.ProductsTaxes.Remove(entry); }
public void AddProductTax(ProductTax entry) { this.context.ProductsTaxes.Add(entry); }
public void FinishVoting(CongressVoting voting) { voting.VotingStatusID = (int)VotingStatusEnum.Accepted; switch ((VotingTypeEnum)voting.VotingTypeID) { case VotingTypeEnum.ChangeCongressVotingLength: { voting.Country.CountryPolicy.CongressVotingLength = int.Parse(voting.Argument1); break; } case VotingTypeEnum.ChangePartyPresidentCadenceLength: { voting.Country.CountryPolicy.PartyPresidentCadenceLength = int.Parse(voting.Argument1); break; } case VotingTypeEnum.ChangeCongressCadenceLength: { voting.Country.CountryPolicy.CongressCadenceLength = int.Parse(voting.Argument1); break; } case VotingTypeEnum.ChangeNormalJobMarketFee: { voting.Country.CountryPolicy.NormalJobMarketFee = (decimal)(double.Parse(voting.Argument1)); break; } case VotingTypeEnum.ChangeContractJobMarketFee: { voting.Country.CountryPolicy.ContractJobMarketFee = (decimal)(double.Parse(voting.Argument1)); break; } case VotingTypeEnum.ChangeProductVAT: { ProductTypeEnum productType = ((ProductTypeEnum)int.Parse(voting.Argument1)); var rate = double.Parse(voting.Argument2); var tax = productTaxRepository.FirstOrDefault(t => t.ProductID == (int)productType && t.CountryID == voting.CountryID); if (tax == null) { tax = new ProductTax() { CountryID = voting.CountryID, ProductID = (int)productType, ProductTaxTypeID = (int)ProductTaxTypeEnum.VAT, TaxRate = (decimal)(rate / 100.0), ForeignCountryID = voting.CountryID }; productTaxRepository.Add(tax); } else { tax.TaxRate = (decimal)rate; } productTaxRepository.SaveChanges(); break; } case VotingTypeEnum.ChangeProductExportTax: case VotingTypeEnum.ChangeProductImportTax: { ProductTypeEnum productType = ((ProductTypeEnum)int.Parse(voting.Argument1)); var rate = double.Parse(voting.Argument2); int countryID = voting.CountryID; int foreignCountryID = int.Parse(voting.Argument3); if (foreignCountryID != -1) { addForeignTax(voting, productType, rate, foreignCountryID); } else { foreach (var country in Persistent.Countries.GetAll()) { if (country.ID == countryID) { continue; } addForeignTax(voting, productType, rate, country.ID); } } productTaxRepository.SaveChanges(); break; } case VotingTypeEnum.ChangeArticleTax: { var taxRate = double.Parse(voting.Argument1); voting.Country.CountryPolicy.ArticleTax = (decimal)(taxRate / 100.0); break; } case VotingTypeEnum.ChangeNewspaperCreateCost: { var cost = double.Parse(voting.Argument1); voting.Country.CountryPolicy.NewspaperCreateCost = (decimal)cost; break; } case VotingTypeEnum.ChangeMarketOfferCost: { var cost = double.Parse(voting.Argument1); voting.Country.CountryPolicy.MarketOfferCost = (decimal)cost; break; } case VotingTypeEnum.ChangeOrganisationCreateCost: { var cost = double.Parse(voting.Argument1); voting.Country.CountryPolicy.OrganisationCreateCost = (decimal)cost; break; } case VotingTypeEnum.ChangePresidentCadenceLength: { var length = int.Parse(voting.Argument1); voting.Country.CountryPolicy.PresidentCadenceLength = length; break; } case VotingTypeEnum.ChangePartyCreateFee: { var cost = double.Parse(voting.Argument1); voting.Country.CountryPolicy.PartyFoundingFee = (decimal)cost; break; } case VotingTypeEnum.ChangeNormalCongressVotingWinPercentage: { var winPercentage = double.Parse(voting.Argument1); voting.Country.CountryPolicy.NormalCongressVotingWinPercentage = (decimal)(winPercentage / 100.0); break; } case VotingTypeEnum.ChangeCitizenCompanyCost: case VotingTypeEnum.ChangeOrganisationCompanyCost: { var cost = double.Parse(voting.Argument1); if ((VotingTypeEnum)voting.VotingTypeID == VotingTypeEnum.ChangeCitizenCompanyCost) { voting.Country.CountryPolicy.CitizenCompanyCost = (decimal)cost; } else { voting.Country.CountryPolicy.OrganisationCompanyCost = (decimal)cost; } break; } case VotingTypeEnum.ChangeMonetaryTaxRate: { var rate = double.Parse(voting.Argument1); voting.Country.CountryPolicy.MonetaryTaxRate = (decimal)rate / 100; break; } case VotingTypeEnum.ChangeMinimumMonetaryTaxValue: { var value = double.Parse(voting.Argument1); voting.Country.CountryPolicy.MinimumMonetaryTax = (decimal)value; break; } case VotingTypeEnum.ChangeTreasureLawHolder: { var value = int.Parse(voting.Argument1); voting.Country.CountryPolicy.TreasuryVisibilityLawAllowHolderID = value; break; } case VotingTypeEnum.ChangeCompanyCreationLawHolder: { var value = int.Parse(voting.Argument1); voting.Country.CountryPolicy.CountryCompanyBuildLawAllowHolder = value; break; } case VotingTypeEnum.CreateNationalCompany: { var country = voting.Country; var regionID = Convert.ToInt32(voting.Argument2); var region = regionRepository.GetById(regionID); if (region.CountryID != voting.CountryID) { RejectVoting(voting, CongressVotingRejectionReasonEnum.RegionIsNotYoursConstructCompany); break; } var companyName = voting.Argument1; ProductTypeEnum productType = (ProductTypeEnum)Convert.ToInt32(voting.Argument3); if (productType == ProductTypeEnum.MedicalSupplies) { companyName = hospitalService.GenerateNameForHospital(region); } reservedEntityNameRepository.Remove(companyName); var company = companyService.CreateCompanyForCountry(companyName, productType, regionID, country, payForCreation: false); if (productType == ProductTypeEnum.MedicalSupplies) { region.Hospital = company.Hospital; } RemoveFromGameMoneyInVoting(voting); break; } case VotingTypeEnum.RemoveNationalCompany: { int companyID = int.Parse(voting.Argument1); var company = companyRepository.GetById(companyID); if (company.Region.CountryID != voting.CountryID) { RejectVoting(voting, CongressVotingRejectionReasonEnum.CompanyIsNotYoursRemoveCompany); break; } removalService.RemoveCompany(company); break; } case VotingTypeEnum.AssignManagerToCompany: { var companyID = int.Parse(voting.Argument1); var citizenID = int.Parse(voting.Argument2); var company = companyRepository.GetById(companyID); var citizen = citizenRepository.GetById(citizenID); if (company.CompanyManagers.Any(manager => manager.EntityID == citizenID)) { RejectVoting(voting, CongressVotingRejectionReasonEnum.AlreadyManagerAssignManager); } companyService.AddManager(company, citizen, new CompanyRights(true, 100)); break; } case VotingTypeEnum.TransferCashToCompany: { decimal amount = decimal.Parse(voting.Argument1); int companyID = int.Parse(voting.Argument2); int currencyID = int.Parse(voting.Argument3); var company = companyRepository.GetById(companyID); var money = new Money(currencyID, amount); var country = voting.Country; var possibleReason = GetRejectionReasonForTransferCashToCompany(money, company, country); if (possibleReason.HasValue) { RejectVoting(voting, possibleReason.Value); break; } transactionsService.TransferMoneyFromCountryToCompany(money, company, country); RemoveFromGameMoneyInVoting(voting); break; } case VotingTypeEnum.ChangeGreetingMessage: { int greetingID = int.Parse(voting.Argument1); var message = votingGreetingMessageRepository.GetById(greetingID).Message; voting.Country.GreetingMessage = message; break; } case VotingTypeEnum.ChangeCitizenStartingMoney: { decimal amount = decimal.Parse(voting.Argument1); var policy = voting.Country.CountryPolicy; policy.CitizenFee = amount; break; } case VotingTypeEnum.ChangeMinimumContractLength: { int length = int.Parse(voting.Argument1); var policy = voting.Country.CountryPolicy; policy.MinimumContractLength = length; break; } case VotingTypeEnum.ChangeMaximumContractLength: { int length = int.Parse(voting.Argument1); var policy = voting.Country.CountryPolicy; policy.MaximumContractLength = length; break; } case VotingTypeEnum.PrintMoney: { int moneyAmount = int.Parse(voting.Argument1); var money = new Money() { Currency = Persistent.Countries.GetCountryCurrency(voting.CountryID), Amount = moneyAmount }; transactionsService.PrintMoney(voting.Country, money); RemoveFromGameMoneyInVoting(voting); break; } case VotingTypeEnum.ChangeMinimalWage: { var minimalWage = decimal.Parse(voting.Argument1); voting.Country.CountryPolicy.MinimalWage = minimalWage; companyService.RemoveJobOffersThatDoesNotMeetMinimalWage(minimalWage, voting.CountryID); break; } case VotingTypeEnum.BuildDefenseSystem: { var quality = int.Parse(voting.Argument3); var regionID = int.Parse(voting.Argument1); var region = regionRepository.GetById(regionID); defenseSystemService.BuildDefenseSystem(region, voting.Country, quality, constructionService); break; } case VotingTypeEnum.ChangeHotelTax: { var tax = decimal.Parse(voting.Argument1); voting.Country.CountryPolicy.HotelTax = tax / 100m; break; } case VotingTypeEnum.ChangeHouseTax: { var tax = decimal.Parse(voting.Argument1); voting.Country.CountryPolicy.HouseTax = tax / 100m; break; } default: { throw new NotImplementedException(); } } countryEventService.AddVotingEvent(voting, VotingStatusEnum.Accepted); ConditionalSaveChanges(congressVotingRepository); }
public void Initialize() { _taxProduct = new ProductTax(); }