public static MonthlyReport ToViewModel(this MicrosoftDynamicsCRMadoxioCannabismonthlyreport dynamicsMonthlyReport, IDynamicsClient dynamicsClient) { if (dynamicsMonthlyReport == null) { return(null); } MonthlyReport monthlyReportVM = new MonthlyReport() { licenseId = dynamicsMonthlyReport._adoxioLicenceidValue, licenseNumber = dynamicsMonthlyReport.AdoxioLicencenumber, reportingPeriodMonth = dynamicsMonthlyReport.AdoxioReportingperiodmonth, reportingPeriodYear = dynamicsMonthlyReport.AdoxioReportingperiodyear, statusCode = dynamicsMonthlyReport.Statuscode, employeesManagement = dynamicsMonthlyReport.AdoxioEmployeesmanagement, employeesAdministrative = dynamicsMonthlyReport.AdoxioEmployeesadministrative, employeesSales = dynamicsMonthlyReport.AdoxioEmployeessales, employeesProduction = dynamicsMonthlyReport.AdoxioEmployeesproduction, employeesOther = dynamicsMonthlyReport.AdoxioEmployeesother, inventorySalesReports = new List <InventorySalesReport>() }; monthlyReportVM.monthlyReportId = dynamicsMonthlyReport.AdoxioCannabismonthlyreportid; // fetch the establishment and get name and address Guid?adoxioEstablishmentId = null; if (!string.IsNullOrEmpty(dynamicsMonthlyReport._adoxioEstablishmentidValue)) { adoxioEstablishmentId = Guid.Parse(dynamicsMonthlyReport._adoxioEstablishmentidValue); } if (adoxioEstablishmentId != null) { var establishment = dynamicsClient.Establishments.GetByKey(adoxioEstablishmentId.ToString()); monthlyReportVM.establishmentName = establishment.AdoxioName; monthlyReportVM.establishmentAddressCity = establishment.AdoxioAddresscity; monthlyReportVM.establishmentAddressPostalCode = establishment.AdoxioAddresspostalcode; } IEnumerable <MicrosoftDynamicsCRMadoxioCannabisinventoryreport> inventoryReports = dynamicsClient.GetInventoryReportsForMonthlyReport(dynamicsMonthlyReport.AdoxioCannabismonthlyreportid); foreach (var inventoryReport in inventoryReports) { MicrosoftDynamicsCRMadoxioCannabisproductadmin product = dynamicsClient.Cannabisproductadmins.GetByKey(inventoryReport._adoxioProductidValue); InventorySalesReport inv = new InventorySalesReport() { product = product.AdoxioName, ProductDescription = product.AdoxioDescription, ProductDisplayOrder = product.AdoxioDisplayorder, inventoryReportId = inventoryReport.AdoxioCannabisinventoryreportid, openingInventory = inventoryReport.AdoxioOpeninginventory, domesticAdditions = inventoryReport.AdoxioQtyreceiveddomestic, returnsAdditions = inventoryReport.AdoxioQtyreceivedreturns, otherAdditions = inventoryReport.AdoxioQtyreceivedother, domesticReductions = inventoryReport.AdoxioQtyshippeddomestic, returnsReductions = inventoryReport.AdoxioQtyshippedreturned, destroyedReductions = inventoryReport.AdoxioQtydestroyed, lostReductions = inventoryReport.AdoxioQtyloststolen, otherReductions = inventoryReport.AdoxioOtherreductions, closingNumber = inventoryReport.AdoxioClosinginventory, closingValue = (inventoryReport.AdoxioValueofclosinginventory != null) ? inventoryReport.AdoxioValueofclosinginventory.Value : 0, totalSalesToConsumerQty = Convert.ToInt32(inventoryReport.AdoxioPackagedunitsnumber), totalSalesToConsumerValue = (inventoryReport.AdoxioTotalvalue != null) ? inventoryReport.AdoxioTotalvalue.Value : 0, totalSalesToRetailerQty = Convert.ToInt32(inventoryReport.AdoxioPackagedunitsnumberretailer), totalSalesToRetailerValue = (inventoryReport.AdoxioTotalvalueretailer != null) ? inventoryReport.AdoxioTotalvalueretailer.Value : 0 }; if (product.AdoxioName != "Seeds" && product.AdoxioName != "Vegetative Cannabis") { inv.closingWeight = (inventoryReport.AdoxioWeightofclosinginventory != null) ? inventoryReport.AdoxioWeightofclosinginventory.Value : 0; } if (product.AdoxioName == "Seeds") { inv.totalSeeds = inventoryReport.AdoxioTotalnumberseeds; } monthlyReportVM.inventorySalesReports.Add(inv); } return(monthlyReportVM); }
private DataTable GetInventroySalesReport(DataSet p_dsInventoryRecords) { string cat1ID = String.Empty; string cat2ID = String.Empty; string cat3ID = String.Empty; Hashtable htOrderedItems = new Hashtable(); SortedList slOrderedItems = null; DataTable dtInventorySalesReport = new DataTable(); dtInventorySalesReport.Columns.Add("ProductName", typeof(string)); dtInventorySalesReport.Columns.Add("FoodTypeName", typeof(string)); dtInventorySalesReport.Columns.Add("FoodBeverageTypeName", typeof(string)); dtInventorySalesReport.Columns.Add("Quantity", typeof(int)); dtInventorySalesReport.Columns.Add("Amount", typeof(double)); foreach (DataRow dtRow in p_dsInventoryRecords.Tables[0].Rows) { Int64 productID = Int64.Parse(dtRow["product_id"].ToString()); Int32 productLevel = Int32.Parse(dtRow["cat_level"].ToString()); string tempProductName = ""; if (productLevel == 3) { DataRow[] tempDataRowArr = Program.m_foodItemRecords.Select("cat3_id = " + productID); if (tempDataRowArr.Length > 0) //Added by Baruri .This was a bug previously when no row found. { tempProductName = tempDataRowArr[0]["cat3_name"].ToString(); cat2ID = tempDataRowArr[0]["cat2_id"].ToString(); } cat1ID = Program.m_categoryRecords.Select("cat2_id = " + cat2ID)[0]["cat1_id"].ToString(); cat1ID = Program.m_foodTypeRecords.Select("cat1_id = " + cat1ID)[0]["cat1_name"].ToString(); } else if (productLevel == 4) { DataRow[] tempDataRowArr = Program.m_selectionItemRecords.Select("cat4_id = " + productID); int tempCat3_id = 0; if (tempDataRowArr.Length > 0) { tempCat3_id = Convert.ToInt32("0" + tempDataRowArr[0]["cat3_id"]); } tempProductName = Program.m_selectionItemRecords.Select("cat4_id = " + productID)[0]["cat4_name"].ToString(); tempDataRowArr = Program.m_foodItemRecords.Select("cat3_id = " + tempCat3_id); if (tempDataRowArr.Length > 0)//If rows found { tempProductName += " " + tempDataRowArr[0]["cat3_name"].ToString(); cat2ID = tempDataRowArr[0]["cat2_id"].ToString(); } cat1ID = Program.m_categoryRecords.Select("cat2_id = " + cat2ID)[0]["cat1_id"].ToString(); cat1ID = Program.m_foodTypeRecords.Select("cat1_id = " + cat1ID)[0]["cat1_name"].ToString(); } InventorySalesReport objSalesReport = new InventorySalesReport(); objSalesReport.Quantity = Convert.ToInt32("0" + dtRow["quantity"].ToString()); objSalesReport.ProductName = tempProductName; objSalesReport.Amount = Convert.ToDouble("0" + dtRow["amount"].ToString()); objSalesReport.FoodBeverageTypeName = Convert.ToString(dtRow["food_type"]); objSalesReport.FoodTypeName = cat1ID; htOrderedItems.Add(cat1ID + "-" + objSalesReport.ProductName, objSalesReport);// Category 1 wise } NumericComparer ncomp = new NumericComparer(); slOrderedItems = new SortedList(htOrderedItems, ncomp); foreach (InventorySalesReport objSalesReport in slOrderedItems.Values) { dtInventorySalesReport.Rows.Add(new object[] { objSalesReport.ProductName, objSalesReport.FoodTypeName, objSalesReport.FoodBeverageTypeName, objSalesReport.Quantity, objSalesReport.Amount }); } return dtInventorySalesReport; }