/// <summary> /// Load Document Details /// </summary> /// <returns>error message or null</returns> public override String LoadDocumentDetails() { SetC_Currency_ID(Doc.NO_CURRENCY); MMatchInv matchInv = (MMatchInv)GetPO(); SetDateDoc(matchInv.GetDateTrx()); SetQty(matchInv.GetQty()); // Invoice Info int C_InvoiceLine_ID = matchInv.GetC_InvoiceLine_ID(); _invoiceLine = new MInvoiceLine(GetCtx(), C_InvoiceLine_ID, null); // BP for NotInvoicedReceipts int C_BPartner_ID = _invoiceLine.GetParent().GetC_BPartner_ID(); SetC_BPartner_ID(C_BPartner_ID); // int M_InOutLine_ID = matchInv.GetM_InOutLine_ID(); _receiptLine = new MInOutLine(GetCtx(), M_InOutLine_ID, null); // _pc = new ProductCost(GetCtx(), GetM_Product_ID(), matchInv.GetM_AttributeSetInstance_ID(), null); _pc.SetQty(GetQty()); return(null); }
/// <summary> /// Get Product Cost Info /// </summary> /// <returns>product cost</returns> public ProductCost GetProductCost() { if (_productCost == null) { _productCost = new ProductCost(_po.GetCtx(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), _po.Get_TrxName()); } return(_productCost); }
public Task <int> SaveProductCostAsync(ProductCost item) { if (item.ProductCostId != 0) { return(database.UpdateAsync(item)); } else { return(database.InsertAsync(item)); } }
/// <summary> /// Get Total Product Costs /// </summary> /// <param name="as1"></param> /// <param name="AD_Org_ID"></param> /// <param name="zeroCostsOK">zero/no costs are OK</param> /// <returns>costs</returns> public Decimal GetProductCosts(MAcctSchema as1, int AD_Org_ID, bool zeroCostsOK) { ProductCost pc = GetProductCost(); int C_OrderLine_ID = GetC_OrderLine_ID(); String costingMethod = null; Decimal? costs = pc.GetProductCosts(as1, AD_Org_ID, costingMethod, C_OrderLine_ID, zeroCostsOK); if (costs != null) { return(costs.Value); } return(Env.ZERO); }
public bool CreateProductCost(ProductCostCreate productCostCreate) { var entity = new ProductCost() { _product = product, Price = product.Price, }; using (var ctx = new ApplicationDbContext()) { ctx.ProductCosts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ProductsCRUDViewModel(ProductsAndCost productsAndCost) { IsEnabled = false; CurrentProduct = new Product(); CurrentProductCost = new ProductCost(); DeleteProductCommand = new Command(async() => await DeleteProduct()); UpdateProductCommand = new Command(async() => await UpdateProduct()); SaveTappedCommand = new Command(async() => await SaveProduct()); ClearTappedCommand = new Command(async() => await ClearEdits(productsAndCost)); GetProductCommand = new Command(async() => await GetProduct(productsAndCost.CurrentProduct.ProductId)); GetProductCommand.Execute(new Command(async() => await GetProduct(productsAndCost.CurrentProduct.ProductId))); GetProductCostCommand = new Command(async() => await GetProductCost(productsAndCost.CurrentProductCost.ProductId)); GetProductCostCommand.Execute(new Command(async() => await GetProductCost(productsAndCost.CurrentProductCost.ProductId))); }
private void btnClear_Click(object sender, EventArgs e) { id = 0; FName.Clear(); Surname.Clear(); Email.Clear(); City.Clear(); ProductCategory.Clear(); ProductCode.Clear(); ProductName.Clear(); ProductVolume.Clear(); ProductUnit.Clear(); comboBox1.Items.Clear(); ProductCost.Clear(); }
private async Task AddProduct() { CurrentProduct = new Product(); CurrentProductCost = new ProductCost(); CurrentProduct.Name = Name; CurrentProduct.Description = Description; CurrentProductCost.Cost = Cost; CurrentProductCost.EffectiveFrom = EffectiveFrom; await App.Database.SaveProductAsync(CurrentProduct); var recentProduct = new ObservableCollection <Product>(await App.Database.GetProductsAsync()).Last(); CurrentProductCost.ProductId = recentProduct.ProductId; await App.Database.SaveProductCostAsync(CurrentProductCost); MessagingCenter.Send <ProductsCRUDViewModel>(this, "Data Updated"); await App.Current.MainPage.Navigation.PopAsync(); }
/// <summary> /// Load Document Details /// </summary> /// <returns>error message or null</returns> public override String LoadDocumentDetails() { SetC_Currency_ID(Doc.NO_CURRENCY); MMatchPO matchPO = (MMatchPO)GetPO(); SetDateDoc(matchPO.GetDateTrx()); // _M_AttributeSetInstance_ID = matchPO.GetM_AttributeSetInstance_ID(); SetQty(matchPO.GetQty()); // _C_OrderLine_ID = matchPO.GetC_OrderLine_ID(); _oLine = new MOrderLine(GetCtx(), _C_OrderLine_ID, GetTrxName()); // _M_InOutLine_ID = matchPO.GetM_InOutLine_ID(); // m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID(); // _pc = new ProductCost(GetCtx(), GetM_Product_ID(), _M_AttributeSetInstance_ID, GetTrxName()); _pc.SetQty(GetQty()); return(null); }
public ProductCostViewModel(ProductCost cost, int?homeCountryID, int?sellingCountryID, int amount) { if (homeCountryID.HasValue) { HomeCountrySymbol = Persistent.Countries.GetCountryCurrency(homeCountryID.Value).Symbol; } if (sellingCountryID.HasValue) { IsForeignVat = true; SellingCountrySymbol = Persistent.Countries.GetCountryCurrency(sellingCountryID.Value).Symbol; } BasePrice = cost.BasePrice; Vat = cost.VatCost; ImportTax = cost.ImportTax; ExportTax = cost.ExportTax; HomeCost = cost.TotalHomeCost; ForeignCost = cost.TotalForeignCost; ClientCost = (BasePrice + (Vat ?? 0)) / amount; }
public void CompareProducts_should_sort_results_by_price() { // Arrange int consumption = _fixture.Create <int>(); var products = _fixture.CreateMany <Product>(2).ToList(); _repository.Setup(x => x.GetProducts()).Returns(products); var cost1 = new ProductCost(_fixture.Create <string>(), 500); var cost2 = new ProductCost(_fixture.Create <string>(), 200); _costCalculator.SetupSequence(x => x.CalculateYearlyCost(It.IsAny <Product>(), consumption)) .Returns(cost1) .Returns(cost2); // Act var result = _sut.CompareProducts(consumption).ToList(); // Assert result[0].Should().Be(cost2); result[1].Should().Be(cost1); }
public ProductCost CalculateProductCost(int amount, decimal nettoPrice, int?homeCountryID, int?sellingCountryID, ProductTypeEnum productType) { nettoPrice = Math.Round(nettoPrice, 2, MidpointRounding.AwayFromZero); ProductCost cost = new ProductCost() { BasePrice = amount * nettoPrice }; var productTaxes = productService.GetAllTaxesForProduct((int)productType, homeCountryID, sellingCountryID); if (homeCountryID != null || sellingCountryID != null) { cost.VatCost = Math.Round(cost.BasePrice * productTaxes.VAT, 2, MidpointRounding.AwayFromZero); } if (sellingCountryID != null && sellingCountryID != homeCountryID) { cost.ImportTax = Math.Round(cost.BasePrice * productTaxes.ImportTax, 2, MidpointRounding.AwayFromZero); if (homeCountryID != null) { cost.ExportTax = Math.Round(cost.BasePrice * productTaxes.ExportTax, 2, MidpointRounding.AwayFromZero); } } return(cost); }
public Task <int> DeleteProductCostAsync(ProductCost item) { return(database.DeleteAsync(item)); }
void AddCost(ProductCost cost) { product.ProductCost.Add(cost); OnPropertyChanged(nameof(Costs)); }
/// <summary> /// Create Landed Cost accounting & Cost lines /// </summary> /// <param name="as1">accounting schema</param> /// <param name="fact">fact</param> /// <param name="line">document line</param> /// <param name="dr">DR entry (normal api)</param> /// <returns>true if landed costs were created</returns> private bool LandedCost(MAcctSchema as1, Fact fact, DocLine line, bool dr) { int C_InvoiceLine_ID = line.Get_ID(); MLandedCostAllocation[] lcas = MLandedCostAllocation.GetOfInvoiceLine( GetCtx(), C_InvoiceLine_ID, GetTrx()); if (lcas.Length == 0) { return(false); } // Delete Old String sql = "DELETE FROM M_CostDetail WHERE C_InvoiceLine_ID=" + C_InvoiceLine_ID; int no = DataBase.DB.ExecuteQuery(sql, null, GetTrx()); if (no != 0) { log.Config("CostDetail Deleted #" + no); } // Calculate Total Base double totalBase = 0; for (int i = 0; i < lcas.Length; i++) { totalBase += Convert.ToDouble(lcas[i].GetBase());//.doubleValue(); } // Create New MInvoiceLine il = new MInvoiceLine(GetCtx(), C_InvoiceLine_ID, GetTrx()); for (int i = 0; i < lcas.Length; i++) { MLandedCostAllocation lca = lcas[i]; if (Env.Signum(lca.GetBase()) == 0) { continue; } double percent = totalBase / Convert.ToDouble(lca.GetBase()); String desc = il.GetDescription(); if (desc == null) { desc = percent + "%"; } else { desc += " - " + percent + "%"; } if (line.GetDescription() != null) { desc += " - " + line.GetDescription(); } // Accounting ProductCost pc = new ProductCost(GetCtx(), lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), GetTrx()); Decimal?drAmt = null; Decimal?crAmt = null; if (dr) { drAmt = lca.GetAmt(); } else { crAmt = lca.GetAmt(); } FactLine fl = fact.CreateLine(line, pc.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1), GetC_Currency_ID(), drAmt, crAmt); fl.SetDescription(desc); // Cost Detail - Convert to AcctCurrency Decimal allocationAmt = lca.GetAmt(); if (GetC_Currency_ID() != as1.GetC_Currency_ID()) { allocationAmt = MConversionRate.Convert(GetCtx(), allocationAmt, GetC_Currency_ID(), as1.GetC_Currency_ID(), GetDateAcct(), GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); } if (Env.Scale(allocationAmt) > as1.GetCostingPrecision()) { allocationAmt = Decimal.Round(allocationAmt, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero); } if (!dr) { allocationAmt = Decimal.Negate(allocationAmt); } if (!IsPosted()) { MCostDetail cd = new MCostDetail(as1, lca.GetAD_Org_ID(), lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), lca.GetM_CostElement_ID(), allocationAmt, lca.GetQty(), // Qty desc, GetTrx()); cd.SetC_InvoiceLine_ID(C_InvoiceLine_ID); bool ok = cd.Save(); if (ok && !cd.IsProcessed()) { MClient client = MClient.Get(as1.GetCtx(), as1.GetAD_Client_ID()); if (client.IsCostImmediate()) { cd.Process(); } } } } log.Config("Created #" + lcas.Length); return(true); }
public void MakeAddOfferTransactions(ProductCost cost, Company company, Country foreignCountry) { var companyEntity = company.Entity; var foreignEntity = foreignCountry?.Entity; var homeCountry = company.Region?.Country; var homeEntity = homeCountry?.Entity; Currency homeCurrency = null; Currency foreignCurrency = null; if (homeCountry != null) { homeCurrency = Persistent.Countries.GetCountryCurrency(homeCountry); } if (foreignCountry != null) { foreignCurrency = Persistent.Countries.GetCountryCurrency(foreignCountry); } if (homeCurrency != null && cost.ExportTax > 0 && homeCountry != null) { var money = new Money() { Amount = cost.ExportTax.Value, Currency = homeCurrency }; var transaction = new Transaction() { Arg1 = "Market offer creation - home cost", Arg2 = string.Format("{0}({1}) paid for creating market offer to {2}({3})", companyEntity.Name, companyEntity.EntityID, homeEntity?.Name, homeEntity?.EntityID), DestinationEntityID = homeCountry.ID, Money = money, SourceEntityID = company.ID, TransactionType = TransactionTypeEnum.MarketOfferImportCost }; companyFinanceSummaryService.AddFinances(company, new ExportTaxFinance(cost.ExportTax.Value, money.Currency.ID)); transactionService.MakeTransaction(transaction); } if (foreignCurrency != null && cost.TotalForeignCost > 0 && foreignEntity != null) { var money = new Money() { Amount = cost.TotalForeignCost, Currency = foreignCurrency }; var transaction = new Transaction() { Arg1 = "Market offer creation - foreign cost", Arg2 = string.Format("{0}({1}) paid for creating market offer to {2}({3})", companyEntity.Name, companyEntity.EntityID, foreignEntity.Name, foreignEntity.EntityID), DestinationEntityID = foreignCountry.ID, Money = money, SourceEntityID = company.ID, TransactionType = TransactionTypeEnum.MarketOfferCost }; companyFinanceSummaryService.AddFinances(company, new ImportTaxFinance(cost.TotalForeignCost, money.Currency.ID)); transactionService.MakeTransaction(transaction); } }