public decimal GetValue_ByCurrency(app_currency app_currency) { decimal Value = 0M; foreach (item_movement_value item_movement_valueLIST in item_movement_value) { if (item_movement_valueLIST.app_currencyfx.app_currency == app_currency) { Value = Value + item_movement_valueLIST.unit_value; } else { //Take value in that currency fx. do not convert into new fx rate. app_currencyfx app_currencyfx = item_movement_valueLIST.app_currencyfx; //convert into current currency. if (app_currency.app_currencyfx.Where(x => x.is_active).FirstOrDefault() != null) { Value = Value + Brillo.Currency.convert_Values(item_movement_valueLIST.unit_value, app_currency.app_currencyfx.Where(x => x.is_active).FirstOrDefault().id_currencyfx, app_currencyfx.id_currencyfx, App.Modules.Purchase); // Value = Value + Brillo.Currency.convert_Value(item_movement_valueLIST.unit_value, app_currencyfx.id_currencyfx, App.Modules.Purchase); } } } return(Value); }
public void Rearrange_Payment() { List <payment_schedual> payment_schedualList = base.payment_schedual.ToList(); foreach (payment_schedual parent in payment_schedualList) { foreach (payment_schedual child in parent.child) { if (child.payment_detail != null) { int id_currency = parent.app_currencyfx.id_currency; DateTime timestamp = child.payment_detail.trans_date; if (base.app_currencyfx.Where(x => x.type == entity.app_currencyfx.CurrencyFXTypes.Transaction && x.id_currency == id_currency && x.timestamp <= timestamp) .OrderByDescending(x => x.timestamp).FirstOrDefault() != null) { app_currencyfx app_currencyfx = base.app_currencyfx.Where(x => x.type == entity.app_currencyfx.CurrencyFXTypes.Transaction && x.id_currency == id_currency && x.timestamp <= timestamp) .OrderByDescending(x => x.timestamp).FirstOrDefault(); if (child.debit > 0) { child.debit = Currency.convert_Values(child.payment_detail.value, child.payment_detail.id_currencyfx, app_currencyfx.id_currencyfx, App.Modules.Purchase); } if (child.credit > 0) { child.credit = Currency.convert_Values(child.payment_detail.value, child.payment_detail.id_currencyfx, app_currencyfx.id_currencyfx, App.Modules.Sales); } } } } } base.SaveChanges(); }
public decimal get_SalesPrice(int id_item, contact Contact, int CurrencyFX_ID) { int PriceList_ID = 0; if (id_item > 0) { if (Contact != null) { if (Contact.id_price_list != null) { PriceList_ID = (int)Contact.id_price_list; } else { PriceList_ID = 0; } } //Step 1. If 'PriceList_ID' is 0, Get Default PriceList. if (PriceList_ID == 0 && PriceList_ID != null) { using (db db = new db()) { if (db.item_price_list.Where(x => x.is_active == true && x.id_company == Properties.Settings.Default.company_ID) != null) { PriceList_ID = db.item_price_list.Where(x => x.is_active == true && x.is_default == true && x.id_company == CurrentSession.Id_Company).FirstOrDefault().id_price_list; } } } //Step 1 1/2. Check if Quantity gets us a better Price List. //Step 2. Get Price in Currency. using (db db = new db()) { app_currencyfx app_currencyfx = null; if (db.app_currencyfx.Where(x => x.id_currencyfx == CurrencyFX_ID).FirstOrDefault() != null) { app_currencyfx = db.app_currencyfx.Where(x => x.id_currencyfx == CurrencyFX_ID).FirstOrDefault(); //Check if we have available Price for this Product, Currency, and List. item_price item_price = db.item_price.Where(x => x.id_item == id_item && x.id_currency == app_currencyfx.id_currency && x.id_price_list == PriceList_ID) .FirstOrDefault(); if (item_price != null) { //Return Perfect Value return(item_price.value); } else { //If Perfect Value not found, get one pased on Product and List. (Ignore Currency and Convert Later basd on Current Rate.) if (db.item_price.Where(x => x.id_item == id_item && x.id_price_list == PriceList_ID).FirstOrDefault() != null) { item_price = db.item_price.Where(x => x.id_item == id_item && x.id_price_list == PriceList_ID).FirstOrDefault(); app_currencyfx = db.app_currencyfx.Where(x => x.id_currency == item_price.id_currency && x.is_active == true).FirstOrDefault(); return(Currency.convert_BackValue(item_price.value, app_currencyfx.id_currencyfx, App.Modules.Sales)); } } } } } return(0); }
/// <summary> /// Executes code that will insert Invoiced Items into Movement. /// </summary> /// <param name="invoice"></param> public void Discount_Items_Origin(item_transfer_detail item_transfer_detail, int ID_BranchOrigin, int ID_BranchDestination, bool movebytruck) { entity.Brillo.Logic.Stock stock = new Brillo.Logic.Stock(); if (item_transfer_detail.item_product != null) { if (movebytruck) { app_currencyfx app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault(); app_location app_location = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault(); List <entity.Brillo.StockList> Items_InStockLIST; if (item_transfer_detail.movement_id != null) { entity.Brillo.Stock stockBrillo = new Brillo.Stock(); Items_InStockLIST = stockBrillo.ScalarMovement(base.item_movement.Where(x => x.id_movement == item_transfer_detail.movement_id).FirstOrDefault()); } else { entity.Brillo.Stock stockBrillo = new Brillo.Stock(); Items_InStockLIST = stockBrillo.List(app_location.app_branch, app_location, item_transfer_detail.item_product); } List <item_movement> item_movement_originList; item_movement_originList = stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location, item_transfer_detail.quantity_origin, item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", "")); base.item_movement.AddRange(item_movement_originList); item_movement item_movement_Dest; app_currencyfx app_currencyfxdest = base.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault(); app_location app_locationdest = base.app_location.Where(x => x.id_branch == ID_BranchDestination && x.is_default).FirstOrDefault(); item_movement_Dest = stock.CreditOnly_Movement( Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfxdest, item_transfer_detail.item_product, app_locationdest, item_transfer_detail.quantity_origin, item_transfer_detail.item_transfer.trans_date, 0, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""), null); base.item_movement.Add(item_movement_Dest); } else { app_currencyfx app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault(); app_location app_location = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault(); List <entity.Brillo.StockList> Items_InStockLIST; if (item_transfer_detail.movement_id != null) { entity.Brillo.Stock stockBrillo = new Brillo.Stock(); Items_InStockLIST = stockBrillo.ScalarMovement(base.item_movement.Where(x => x.id_movement == item_transfer_detail.movement_id).FirstOrDefault()); } else { entity.Brillo.Stock stockBrillo = new Brillo.Stock(); Items_InStockLIST = stockBrillo.List(app_location.app_branch, app_location, item_transfer_detail.item_product); } ///Debit Movement from Origin. List <item_movement> item_movement_originList; item_movement_originList = stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location, item_transfer_detail.quantity_origin, item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", "")); base.item_movement.AddRange(item_movement_originList); } } }
/// <summary> /// Executes code that will insert Invoiced Items into Movement. /// </summary> /// <param name="invoice"></param> public void Credit_Items_Destination(item_transfer_detail item_transfer_detail, int ID_BranchOrigin, int ID_BranchDestination, bool MoveByTruck) { entity.Brillo.Logic.Stock stock = new Brillo.Logic.Stock(); app_currencyfx app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_priority && x.is_active).FirstOrDefault(); app_location app_location_dest = base.app_location.Where(x => x.id_branch == ID_BranchDestination && x.is_default).FirstOrDefault(); if (MoveByTruck) { List <entity.Brillo.StockList> Items_InStockLIST; entity.Brillo.Stock stockBrillo = new Brillo.Stock(); Items_InStockLIST = stockBrillo.MovementForTransfer(item_transfer_detail.id_transfer_detail, item_transfer_detail.id_item_product); List <item_movement> item_movement_LIST = new List <entity.item_movement>(); ///Discount From Destination. Because merchendice is returned to Origin, so it must be discounted from Destintation. item_movement_LIST = stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location_dest, item_transfer_detail.quantity_destination, item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", "")); base.item_movement.AddRange(item_movement_LIST); app_location app_location_origin = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault(); //Credit in Origin only if it is MoveByTruck. item_movement item_movement_origin; item_movement_origin = stock.CreditOnly_Movement( Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location_origin, item_transfer_detail.quantity_destination, item_transfer_detail.item_transfer.trans_date, 0, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""), null ); base.item_movement.Add(item_movement_origin); } else { //Credit Destination. item_movement item_movement_dest; List <item_movement> Items_InStockLIST = base.item_movement.Where(x => x.id_transfer_detail == item_transfer_detail.id_transfer_detail && x.id_item_product == item_transfer_detail.id_item_product && x.debit > 0).ToList(); int count = 1; if (Items_InStockLIST.Count() > 0) { count = Items_InStockLIST.Count(); } item_movement parent_item_movement = Items_InStockLIST.FirstOrDefault(); item_movement_dest = stock.CreditOnly_Movement( Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location_dest, item_transfer_detail.quantity_destination, item_transfer_detail.item_transfer.trans_date, Items_InStockLIST.Sum(x => (x.item_movement_value.Sum(y => y.unit_value) / (x.item_movement_value.Count() != 0 ? x.item_movement_value.Count() : 1))) / count, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""), null ); item_movement_dest._parent = Items_InStockLIST.FirstOrDefault(); base.item_movement.Add(item_movement_dest); } }