}//GetTakenBy //----------------------------------------------------------------------------------------------// private void AddItem(Models.Product product, WorkSpace ws) { stockRecord = (StockRecord)ws.CreateObject("StockRecord"); //Create a stockRecord with lvi.Text and look for it in database. SDOHelper.Write(stockRecord, "STOCK_CODE", product.Code); if (stockRecord.Find(false)) { //Add item to the order. sopItem = SDOHelper.Add(sopPost.Items); //Put product details and prices into sopItem SDOHelper.Write(sopItem, "STOCK_CODE", SDOHelper.Read(stockRecord, "STOCK_CODE")); SDOHelper.Write(sopItem, "DESCRIPTION", SDOHelper.Read(stockRecord, "DESCRIPTION")); double qty = product.Qty; double salePrc = product.SalePrice; double netAmt = salePrc * qty * (1 - cusDiscountRate / 100); double taxAmt = netAmt * defTaxRate / 100; SDOHelper.Write(sopItem, "QTY_ORDER", qty); SDOHelper.Write(sopItem, "UNIT_PRICE", salePrc); SDOHelper.Write(sopItem, "NET_AMOUNT", netAmt); SDOHelper.Write(sopItem, "TAX_AMOUNT", taxAmt); SDOHelper.Write(sopItem, "TAX_RATE", defTaxRate); SDOHelper.Write(sopItem, "NOMINAL_CODE", ((int)setUsr.stockNomCode).ToString()); SDOHelper.Write(sopItem, "TAX_CODE", (short)taxCode); } else { throw new MyException("Stock: " + product.Code + " does not seem to exist."); } //Else } //AddItem
}//ctor //-------------------------------------------------------------------------------------------------------// public double GetCostPrice(string prodCode) { //Create product with prodCode stockRecord = (StockRecord)ws.CreateObject("StockRecord"); SDOHelper.Write(stockRecord, "STOCK_CODE", prodCode); var result = stockRecord.Find(false); return((double)SDOHelper.Read(stockRecord, "LAST_PURCHASE_PRICE")); }//GetCostPrice
}//CTOR //-------------------------------------------------------------------------------------------------------// /// <summary> /// Reads all invoices and stores it's values in a List. /// </summary> /// <param name="customersFileName"></param> public MyDictionary<MyDictionary<double>> ReadPriceListData() { //PriceListActivity set to new() so null is not returned. MyDictionary<MyDictionary<double>> PriceListActivity = new MyDictionary<MyDictionary<double>>(); try { sdo = new SDOEngine(); //Try a connection, will throw an exception if it fails ws = (WorkSpace)sdo.Workspaces.Add("App Server Update"); ws.Connect(sageUserSet.sageDBDir, sageUserSet.sageUsername, sageUserSet.sagePassword, "UniqueUpdater"); //Dictionary of PriceList Name vs PriceList Data. MyDictionary<MyDictionary<double>> miniPLActivity = new MyDictionary<MyDictionary<double>>(); //Dictionary of PriceList Name vs PriceListUserList. MyDictionary<List<string>> plUsers = new MyDictionary<List<string>>(); //Create instances of the objects priceRecord = (PriceRecord)ws.CreateObject("PriceRecord"); salesRecord = (SalesRecord)ws.CreateObject("SalesRecord"); stockRecord = (StockRecord)ws.CreateObject("StockRecord"); //Create a dictionary of PL's that are acually being referenced v's Empty ProductActivities. //Single Price Lists can be used for multiple Customers salesRecord.MoveFirst(); do { string cusCode; string cusPriceListRef = ((String)SDOHelper.Read(salesRecord, "PRICE_LIST_REF")).Trim(); //If pLists already contains PL then add customer to it's entry. Else make new entry if not empty string. if (plUsers.ContainsKey(cusPriceListRef)) { cusCode = (String)SDOHelper.Read(salesRecord, "ACCOUNT_REF"); plUsers[cusPriceListRef].Add(cusCode); } else if (!cusPriceListRef.Equals(String.Empty)) { plUsers[cusPriceListRef] = new List<string>(); cusCode = (String)SDOHelper.Read(salesRecord, "ACCOUNT_REF"); plUsers[cusPriceListRef].Add(cusCode); //Add new entry for each priceList. miniPLActivity[cusPriceListRef] = new MyDictionary<double>(); }//Else } while (salesRecord.MoveNext()); Dictionary<string, double> productActivity = null; string plName = String.Empty; string plNamePrev = String.Empty; double calcValue; int calcMeth; double xRate = 1; double costPrice; double salePrice; double listPrice; string stockCode; //Start at first pricerecord priceRecord.MoveFirst(); do { //Get first stock code in Price List. stockCode = (String)SDOHelper.Read(priceRecord, "STOCK_CODE"); //Create SDO stockRecord with this stockCode to use for searching later. SDOHelper.Write(stockRecord, "STOCK_CODE", stockCode); plName = ((string)SDOHelper.Read(priceRecord, "EXT_REF")).Trim(); calcValue = (double)SDOHelper.Read(priceRecord, "VALUE"); calcMeth = (sbyte)SDOHelper.Read(priceRecord, "DISCOUNT_TYPE"); salePrice = (double)SDOHelper.Read(stockRecord, "SALES_PRICE"); costPrice = CheckProduct(stockCode).CostPrice; if (plName.Equals(plNamePrev)) { //Old plName: Check stock, if found get it's list price & add to productActivity from PLACtivity. if (stockRecord.Find(false)) { listPrice = CalculateListPrice(calcValue, calcMeth, costPrice, salePrice, xRate); productActivity[stockCode] = listPrice; }//If } else if (miniPLActivity.ContainsKey(plName)) { //New name: Check stock, if found get it's list price & add to productActivity from PLACtivity. //Change plNamePrev //Get new currency, keep till next Price List. if (stockRecord.Find(false)) { xRate = GetCurrency(priceRecord); listPrice = CalculateListPrice(calcValue, calcMeth, costPrice, salePrice, xRate); productActivity = miniPLActivity[plName]; productActivity[stockCode] = listPrice; plNamePrev = plName; }//If }//Else } while (priceRecord.MoveNext()); //Give each customer their own PriceList. foreach (string key in plUsers.Keys) { foreach (string cusCode in plUsers[key]) { PriceListActivity[cusCode] = miniPLActivity[key]; }//ForEach }//ForEach } finally { DestroyAllObjects(); }//Finally return PriceListActivity; }//ReadPriceListData