コード例 #1
0
        public static int GetRrfCategoryId(string programName)
        {
            var ginfo = new GeneralInfo();
               ginfo.LoadAll();
               var client1 = new ServiceRRFLookupClient();
               var periods = client1.GetCurrentReportingPeriod(ginfo.FacilityID, userName, password);
               var period = periods[0].Id;
               var forms = client1.GetForms(ginfo.FacilityID, userName, password);
               var formid = forms[0].Id;
               var formcategories = client1.GetFacilityRRForm(ginfo.FacilityID, formid, period, 1, userName, password).First().FormCategories.ToList();

               switch (programName)
               {
                   case "Malaria Prevention & Control":
                       return 14;
                   case "TB / Leprosy Prevention & Control":
                       return 13;
                   case "HIV/AIDS ans STIs and OIs":
                       return 15;
                   case "Curative care and emergency care":
                      return 15;
                   case "Family Planning":
                       return 13;
                   case "Disease Prevention and Control":
                       return 14;
                   case "Adolescent Reproductive Health":
                       return 13;
               }
               return 11;
        }
コード例 #2
0
        public static int GetBranchID()
        {
            var x = new BLL.GeneralInfo();

            x.LoadAll();
            return(x.FacilityID);
        }
コード例 #3
0
        /// <summary>
        /// Handles printing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();

            string header = info.HospitalName + " National Drug List";
            gridControl1.ShowPrintPreview();
        }
        public void PopulateItemList(DataTable dtItem)
        {
            progressBar1.Visible = true;
            progressBar1.Minimum = 1;
            progressBar1.Value = 1;
            progressBar1.Maximum = dtItem.Rows.Count;

            GeneralInfo pipline = new GeneralInfo();
            pipline.LoadAll();
            int min = pipline.Min;
            int max = pipline.Max;
            int storeId = (cboStores.SelectedValue != null)?Convert.ToInt32(cboStores.SelectedValue):1;
            lstItem.Items.Clear();
            int col = 0;
            int count = 1;
            Balance bal = new Balance();
            Items itmIssues = new Items();
            int year = Convert.ToInt32(cboYear.SelectedItem);
            foreach (DataRow dr in dtItem.Rows)
            {
                int itemId = Convert.ToInt32(dr["ID"]);
                string itemName = dr["ItemName"].ToString() + " - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString();
                int yer = (dtCurrent.Month < 11) ? year : year - 1;// (dtCurrent.Month < 11) ? Convert.ToInt32(cboYear.SelectedItem) : Convert.ToInt32(cboYear.SelectedItem) - 1;
                Int64 SOH = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, dtCurrent.Month, yer);

                int[] mon = {11,12,1,2,3,4,5,6,7,8,9,10};

                long[] cons = new long[12];
                for (int i = 0; i < mon.Length;i++ )
                {
                    int yr = (mon[i] < 11) ? year : year - 1;
                    cons[i] = itmIssues.GetQuantityIssuedByItemPerMonth(mon[i], itemId, storeId, yr);

                }
                string[] str = { count.ToString(), itemName, ((SOH != 0) ? SOH.ToString("#,###") : "0"), ((cons[0] != 0) ? cons[0].ToString("#,###") : "0"), ((cons[1] != 0) ? cons[1].ToString("#,###") : "0"), ((cons[2] != 0) ? cons[2].ToString("#,###") : "0"), ((cons[3] != 0) ? cons[3].ToString("#,###") : "0"), ((cons[4] != 0) ? cons[4].ToString("#,###") : "0"), ((cons[5] != 0) ? cons[5].ToString("#,###") : "0"), ((cons[6] != 0) ? cons[6].ToString("#,###") : "0"), ((cons[7] != 0) ? cons[7].ToString("#,###") : "0"), ((cons[8] != 0) ? cons[8].ToString("#,###") : "0"), ((cons[9] != 0) ? cons[9].ToString("#,###") : "0"), ((cons[10] != 0) ? cons[10].ToString("#,###") : "0"), ((cons[11] != 0) ? cons[11].ToString("#,###") : "0") };
                ListViewItem listItem = new ListViewItem(str);
                listItem.ToolTipText = itemName;
                listItem.Tag = dr["ID"];
                if (col != 0)
                {
                    listItem.BackColor = Color.FromArgb(233, 247, 248);
                    col = 0;
                }
                else
                {
                    col++;
                }
                lstItem.Items.Add(listItem);
                count++;
                progressBar1.PerformStep();
            }
            progressBar1.Visible = false;
        }
コード例 #5
0
 private static void PclCreateReportHeaderArea(object sender, DevExpress.XtraPrinting.CreateAreaEventArgs e)
 {
     var info = new GeneralInfo();
     info.LoadAll();
     var dtDate = new DateTimePickerEx
                                               {
                                                   Value = DateTime.Now,
                                                   CustomFormat = "MM/dd/yyyy"
                                               };
     DateTime dtCurrent = Convert.ToDateTime(dtDate.Text);
     //Old header
     string header = info.HospitalName + " Loss/Adjustment Activity Log " + dtCurrent.ToString("MM dd,yyyy");
     TextBrick brick = e.Graph.DrawString(header, Color.Navy, new RectangleF(0, 0, 500, 40),
                                          DevExpress.XtraPrinting.BorderSide.None);
     brick.Font = new Font("Arial", 16);
     brick.StringFormat = new DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center);
 }
コード例 #6
0
        public static bool AutoBackUp()
        {
            try
                {
                    GeneralInfo info = new GeneralInfo();
                    info.LoadAll();

                    string path = GetDBAutoBackupPath() + "\\" + info.HospitalName + "PharmaInventory" + DateTime.Now.ToString("MMMddyyyy") + ".bak";

                    string connectionString = "";

                    try
                    {
                        connectionString = Program.ConnStringManager.GetFromRegistry();
                    }
                    catch
                    {
                        connectionString = ConfigurationManager.AppSettings["dbConnection"].ToString();
                    }

                    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
                    System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand();

                    if (conn.State != ConnectionState.Open)
                        conn.Open();
                    string dbName = conn.Database;
                    com.CommandText = "BACKUP DATABASE [" + dbName + "] TO  DISK = N'" + path + "' WITH NOFORMAT, NOINIT,  NAME = N'PharmaInventory" + DateTime.Now.ToString("MMMddyyyy") + "-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10";
                    com.Connection = conn;
                    com.ExecuteNonQuery();
                    info.LoadAll();
                    info.LastBackUp = DateTime.Now;
                    info.Save();
                   // XtraMessageBox.Show("Backup completed to " + path + "!", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return true;
                }
                catch(Exception ex)
                {
                    //XtraMessageBox.Show("Auto Backup has failed! Backup the database manually.", "Backup the database manually", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return false;
        }
コード例 #7
0
        private void Link_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            // old header
            //string header = info.HospitalName + "Inventory Log of " + lblAdjDate.Text;

            //header with reference number  and date included
            CalendarLib.DateTimePickerEx dtDate = new CalendarLib.DateTimePickerEx
            {
                Value = DateTime.Now,
                CustomFormat = "MM/dd/yyyy"
            };
            DateTime dtCurrent = Convert.ToDateTime(dtDate.Text);
            string header = info.HospitalName + "Inventory Log of " + lblAdjDate.Text + "    " + dtCurrent.ToString("MM dd,yyyy");
            printableComponentLink1.PageHeaderFooter = header;

            TextBrick brick = e.Graph.DrawString("", Color.DarkBlue, new RectangleF(0, 0, 200, 100), BorderSide.None);
            TextBrick brick1 = e.Graph.DrawString(header, Color.DarkBlue, new RectangleF(0, 20, 200, 100), BorderSide.None);
            TextBrick brick2 = e.Graph.DrawString("", Color.DarkBlue, new RectangleF(0, 40, 200, 100), BorderSide.None);
        }
コード例 #8
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            int userID = Convert.ToInt32(e.Argument);
            BLL.User user = new User();
            user.LoadByPrimaryKey(userID);
            try
            {

                HelperClasses.DirectoryServices.RefreshFromDirectoryServices();
                BLL.GeneralInfo info = new GeneralInfo();
                info.LoadAll();
                info.LastSync = DateTime.Now;
                info.Save();
                e.Result = "Completed!";
            }
            catch (Exception ex)
            {
                if (user.UserType != UserType.Constants.SYSTEM_ADMIN)
                    e.Result =
                        "There has been a network error.  The database is not in sync with directory services.  Please connect to the Internet and try again.";
                else
                    e.Result = ex.Message;
            }
        }
        private void xpButton1_Click(object sender, EventArgs e)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";

            string header = info.HospitalName + " Consumption Trend " + cboStores.Text + " Date: " + dtDate.Text;
            lstItem.Title = header;
            lstItem.FitToPage = true;
            lstItem.Print();
        }
コード例 #10
0
        private void xpButton2_Click(object sender, EventArgs e)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";

            string[] header = { info.HospitalName, "Consumption Trend" , cboStores.Text , " Date: " + dtDate.Text };
            MainWindow.ExportToExcel(lstItem,header);
        }
コード例 #11
0
 public int CountVitalItemsStockOutForAllStore(int month, int year)
 {
     Items itm = new Items();
     DataTable dtItem = itm.GetVitalItems();
     GeneralInfo pipline = new GeneralInfo();
     pipline.LoadAll();
     int min = pipline.Min;
     int max = pipline.Max;
     double eop = pipline.EOP;
     int count = 0;
     Balance bal = new Balance();
     foreach (DataRow dr in dtItem.Rows)
     {
         Int64 AMC = bal.CalculateAMCAll(Convert.ToInt32(dr["ID"]), month, year);
         Int64 minCon = AMC * min;
         Int64 maxCon = AMC * max;
         double eopCon = AMC * (eop + 0.25);
         Int64 SOH = bal.GetSOHForAllStore(Convert.ToInt32(dr["ID"]), month, year);
         decimal MOS = (AMC != 0) ? (SOH / AMC) : 0;
         Int64 reorder = (maxCon > SOH) ? maxCon - SOH : 0;
         if (SOH == 0)
             count++;
         //string status = (SOH <= eopCon && SOH > 0) ? "Near EOP" : ((SOH > maxCon) ? "Excess Stock" : ((SOH <= 0) ? "Stock Out" : "Normal"));
     }
     return count;
 }
コード例 #12
0
        /// <summary>
        /// Gets Average Monthly consumption, without considering logical stores
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public Int64 CalculateAMCAll(int itemId, int month, int year)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            int range = info.AMCRange;
            Int64 cons = 0;
            IssueDoc iss = new IssueDoc();
            int yr = (month > 10) ? year - 1 : year;

            DateTime dt1 = new DateTime(yr, month, DateTime.DaysInMonth(yr, month));
            DateTime dt2 = dt1.AddMonths(-range);
            range = iss.GetAvailableNoOfMonthsAll(itemId, dt2, dt1);

            cons = iss.GetIssuedQuantityByDateRangeAll(itemId, dt2, dt1);

            Int64 AMC = cons / range;
            return AMC;
        }
コード例 #13
0
        public Collection<Order> GetOrders()
        {
            var orders = new Collection<Order>();
            _tblRrf = (DataTable)gridItemsChoice.DataSource;
            tblRRF = (DataTable)gridItemsChoice.DataSource;

            var info = new GeneralInfo();
            info.LoadAll();

            var client1 = new ServiceRRFLookupClient();
            var req = new GetCurrentReportingPeriodRequest
            {
                Password = RRFServiceIntegration.PlitsPassword,
                UserName = RRFServiceIntegration.PlitsUserName,
                Supplychainunitid = RRFServiceIntegration.GetBranchID()
            };

            var branchReq = new GetBranchRRFormRequest
            {
                UserName = RRFServiceIntegration.PlitsUserName,
                Password = RRFServiceIntegration.PlitsPassword,
                Supplychainunitid = RRFServiceIntegration.GetBranchID()
            };

            var formReq = new GetFormsRequest
            {
                Password = RRFServiceIntegration.PlitsPassword,
                UserName = RRFServiceIntegration.PlitsUserName,
                Supplychainunitid = RRFServiceIntegration.GetBranchID()
            };

            var forms = client1.GetForms(formReq).GetFormsResult;
            var formid = forms[0].Id;

            var periods = client1.GetCurrentReportingPeriod(req).GetCurrentReportingPeriodResult;
            var period = periods[0].Id;

            branchReq.Formid = formid;
            branchReq.Reportingperiodid = period;

            var chosenCatId = 91;//RRFHelper.GetRrfCategoryId(cboStores.Text);
            var rrfs = client1.GetBranchRRForm(branchReq).GetBranchRRFormResult;
            var formCategories = rrfs.First().FormCategories;
            var chosenCategoryBody = formCategories.First(x => x.Id == chosenCatId); //Hard coding to be removed.
            var items = chosenCategoryBody.Pharmaceuticals; //Let's just store the items here (May not be required)

            var user = new User();
            user.LoadByPrimaryKey(CurrentContext.LoggedInUser.ID);
            var order = new HCMIS.Desktop.PLITSTransactionalService.Order
            {
                //Id = (int)rrf["Id"],
                RequestCompletedDate = BLL.DateTimeHelper.ServerDateTime,//Convert.ToDateTime(rrf["DateOfSubmissionEth"]),
                OrderCompletedBy = user.FullName,
                RequestVerifiedDate = BLL.DateTimeHelper.ServerDateTime,
                OrderTypeId = 1, //This needs to be changed to constant class or something. 1 - Regular, 2 - Emergency'
                SubmittedBy = user.FullName,
                SubmittedDate = BLL.DateTimeHelper.ServerDateTime,
                SupplyChainUnitId = Helpers.RRFServiceIntegration.GetBranchID(),
                OrderStatus = 1,//TODO: hardcoding
                FormId = formid,//TODO: hardcoding
                ReportingPeriodId = period  //TODO: hardcoding
            };

            // order.OrderTypeId = (int)tblrrf.Rows[i]["RRfTpyeId"];
            // Set order properties

            //order.FormId = rrfForm.Id; //Form.ID? or RRFForm.ID? - doesn't make sense
            //  order.ReportingPeriodId = periods[0].Id; //Asked again here?  Because RRFForm already contains this.

            var details = new Collection<OrderDetail>();
            int i = 0;
            var xx = tblRRF.Rows.Count;

            foreach (DataRow rrfLine in tblRRF.Rows)
            {
                var detail = new PLITSTransactionalService.OrderDetail();
                var hcmisItemID = Convert.ToInt32(rrfLine["ID"]);
                var rrFormPharmaceutical = items.FirstOrDefault(x => x.PharmaceuticalId == Convert.ToInt32(rrfLine["ID"]));
                if (rrfLine != null && rrFormPharmaceutical!=null)
                {

                    detail.BeginningBalance = Convert.ToInt32(rrfLine["BeginingBalance"]);
                    //DaysOutOfStock daysOfStockOut = new DaysOutOfStock() { NumberOfDaysOutOfStock = 1 };
                    //detail.DaysOutOfStocks.Add(daysOfStockOut);//Convert.ToInt32(rrfLine["DaysOutOfStock"]);
                    int eBalance = Convert.ToInt32(rrfLine["SOH"]);
                    detail.EndingBalance = eBalance == 0 ? 1 : eBalance;  //To make sure ending balance is not zero.
                    //detail.ItemId = Convert.ToInt32(rrfLine["ID"]); //Needs to come from the Code column of Items table.
                    detail.QuantityReceived = Convert.ToInt32(rrfLine["Received"]);
                    detail.QuantityOrdered = Convert.ToInt32(rrfLine["Quantity"]);
                    detail.LossAdjustment = Convert.ToInt32(rrfLine["LossAdj"]);

                    if (rrFormPharmaceutical != null)
                        detail.ItemId = rrFormPharmaceutical.ItemId;
                    else
                        throw new Exception("Item ID Mismatch");

                    var rdDoc = new ReceiveDoc();
                    var lossAndAdjustment = new LossAndAdjustment();
                    rdDoc.GetAllWithQuantityLeft(hcmisItemID, _storeID);
                    lossAndAdjustment.GetLossAdjustmentsForLastRRFPeriod(hcmisItemID, _storeID, periods[0].StartDate,
                                                                periods[0].EndDate);
                    int receiveDocEntries = rdDoc.RowCount;
                    int disposalEntries = lossAndAdjustment.RowCount;

                    rdDoc.Rewind();
                    for (var j = 0; j < receiveDocEntries; j++)
                    {
                        var exp = new Expiry
                                      {
                                          Amount = Convert.ToInt32(rdDoc.QuantityLeft),
                                          BatchNo = rdDoc.BatchNo,
                                          ExpiryDate = rdDoc.ExpDate
                                      };
                        detail.Expiries.Add(exp);
                        rdDoc.MoveNext();
                    }

                    lossAndAdjustment.Rewind();
                    for (var j = 0; j < disposalEntries; j++)
                    {
                        var adj = new Adjustment
                                      {Amount = Convert.ToInt32(lossAndAdjustment.Quantity), TypeId = 11, ReasonId = 39};

                        detail.Adjustments.Add(adj);
                        lossAndAdjustment.MoveNext();
                    }

                    var stockoutIndexedLists = StockoutIndexBuilder.Builder.GetStockOutHistory(hcmisItemID, _storeID);

                    for (int j = 0; j < stockoutIndexedLists.Count; j++)
                    {
                        var dos = new DaysOutOfStock
                                      {
                                          NumberOfDaysOutOfStock = stockoutIndexedLists[j].NumberOfDays,
                                          StockOutReasonId = 5
                                      };

                        detail.DaysOutOfStocks.Add(dos);
                    }

                    details.Add(detail);
                }

            }
            order.OrderDetails = details;
            orders.Add(order);

            // loop through each record and create order & order details objects
            return orders;

            //var user = new User();
            //user.LoadByPrimaryKey(NewMainWindow.LoggedInUser.ID);
            //foreach (DataRow rrf in tblRRF.Rows)
            //{
            //    var order = new HCMIS.Desktop.PLITSTransactionalService.Order
            //    {
            //        Id = (int)rrf["Id"],
            //        RequestCompletedDate = DateTime.Now,//Convert.ToDateTime(rrf["DateOfSubmissionEth"]),
            //        OrderCompletedBy = user.FullName,
            //        RequestVerifiedDate = DateTime.Now,
            //        OrderTypeId = 1, //This needs to be changed to constant class or something. 1 - Regular, 2 - Emergency'
            //        SubmittedBy = user.FullName,
            //        SubmittedDate = DateTime.Now,
            //        SupplyChainUnitId = RRFServiceIntegration.BranchID,
            //        OrderStatus = 1,
            //        FormId = formid
            //    };
            //    // order.OrderTypeId = (int)tblrrf.Rows[i]["RRfTpyeId"];
            //    // Set order properties

            //    //order.FormId = rrfForm.Id; //Form.ID? or RRFForm.ID? - doesn't make sense
            //    //  order.ReportingPeriodId = periods[0].Id; //Asked again here?  Because RRFForm already contains this.

            //    var details = new Collection<OrderDetail>();

            //    foreach (DataRow rrfLine in tblRRF.Rows)
            //    {
            //        var detail = new PLITSTransactionalService.OrderDetail();
            //        var rrFormPharmaceutical = items.FirstOrDefault(x => x.ItemId == Convert.ToInt32(rrfLine["ID"]));
            //        if (rrfLine != null && rrFormPharmaceutical != null)
            //        //detail.Adjustments[0].Amount =  (int)rrfLine["Adjustments"];
            //        {
            //            detail.BeginningBalance = Convert.ToInt32(rrfLine["BeginingBalance"]);
            //            //detail.DaysOutOfStocks = Convert.ToInt32(rrfLine["DaysOutOfStock"]);
            //            detail.EndingBalance = Convert.ToInt32(rrfLine["SOH"]);
            //            //detail.ItemId = Convert.ToInt32(rrfLine["ID"]); //Needs to come from the Code column of Items table.
            //            detail.QuantityReceived = Convert.ToInt32(rrfLine["Received"]);
            //            detail.QuantityOrdered = Convert.ToInt32(rrfLine["Quantity"]);
            //            detail.LossAdjustment = Convert.ToInt32(rrfLine["LossAdj"]);

            //            if (rrFormPharmaceutical != null)
            //                detail.PharmaceuticalId = rrFormPharmaceutical.PharmaceuticalId;
            //            //  detail.PharmaceuticalId = Convert.ToInt32(rrfLine["ItemID"]);
            //            // detail.PharmaceuticalId = pharId;

            //        }
            //        details.Add(detail);
            //    }
            //    order.OrderDetails = details;
            //    orders.Add(order);
            //}

            //// loop through each record and create order & order details objects
            //return orders;
        }
コード例 #14
0
        private void Send(FacilityOrderViewModel fOrder)
        {
            var client = new ServiceOrderClient();
            var ginfo = new GeneralInfo();
            ginfo.LoadAll();
            var result = client.SubmitFacilityOrders(ginfo.FacilityID, fOrder.Orders, ginfo.ScmsWSUserName, ginfo.ScmsWSPassword);
            var submitResult = result.FirstOrDefault();

            if (submitResult != null && submitResult.OrderIsValid)
            {
                XtraMessageBox.Show("RRF's Sent Successfully", "Confirmation");
            }
            else
            {
                if (submitResult != null && submitResult.OrderIsValid ==false)
                {
                    var summary = new RRF_Send_Result { gridControl1 = { DataSource = submitResult.ValidationMessages } };
                    summary.ShowDialog();
                }
            }
        }
コード例 #15
0
        private static string CheckRRFStatus(int rrfID)
        {
            GeneralInfo ginfo = new GeneralInfo();
            ginfo.LoadAll();

            if (ginfo.IsColumnNull("FacilityID"))
            {
                XtraMessageBox.Show("The Facility ID was not set, Please correct that and try again.");
                return "Unknown";
            }

            int facilityID = ginfo.FacilityID;
            RRF rrf = new RRF();
            rrf.LoadByPrimaryKey(rrfID);
            int startMonth = rrf.FromMonth; //Convert.ToInt32(cboFromMonth.EditValue);
            int endMonth = rrf.ToMonth; //Convert.ToInt32(cboToMonth.EditValue);
            //TODO: The Server side RRF reception will also have to handle the From/To Year values.
            int toYear = rrf.ToYear; //Convert.ToInt32(cboToYear.EditValue);
            int fromYear = rrf.FromYear; //Convert.ToInt32(cboFromYear.EditValue);

            RRFService.ServiceSoapClient sc = new RRFService.ServiceSoapClient();
            try
            {
                string rrfStatus = sc.GetRRFStatus(facilityID, toYear, startMonth, endMonth);
                    //TODO: The service as well needs to handle the From/To year value
                rrf.LastRRFStatus = rrfStatus;
                rrf.Save();
                return rrfStatus;
            }
            catch
            {
                XtraMessageBox.Show("There was a network Error, Please connect to the internet and try again.",
                                    "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return "Unknown";
            }
        }
コード例 #16
0
 /// Compiles a RRF Order that will be used by Send() method
 /// </summary>
 /// <returns>FacilityOrderViewModel</returns>
 private FacilityOrderViewModel CompileOrder(List<Order> orders)
 {
     var ginfo = new GeneralInfo();
     ginfo.LoadAll();
     var fOrder = new FacilityOrderViewModel
                      {
                          FacilityID = ginfo.FacilityID,
                          Username = ginfo.ScmsWSUserName,
                          Password = ginfo.ScmsWSPassword,
                          Orders = orders.ToArray()
                      };
     return fOrder;
 }
コード例 #17
0
 public static bool IsVaccine(GeneralInfo generalInfo)
 {
     return(generalInfo.InstitutionITypeID == Vaccine);
 }
 public static int GetBranchID()
 {
     var x = new BLL.GeneralInfo();
     x.LoadAll();
     return x.FacilityID;
 }
コード例 #19
0
 public static bool IsPfsa(GeneralInfo generalInfo)
 {
     return(generalInfo.InstitutionITypeID == PfsaHub);
 }
コード例 #20
0
 public int CountBelowMin(int storeId, int month, int year)
 {
     Items itm = new Items();
     DataTable dtItem = itm.GetAllItems(1);
     GeneralInfo pipline = new GeneralInfo();
     pipline.LoadAll();
     int min = pipline.Min;
     int max = pipline.Max;
     double eop = pipline.EOP;
     int count = 0;
     Balance bal = new Balance();
     if (storeId == 0)
     {
         count += (from DataRow dr in dtItem.Rows
                   let AMC = bal.CalculateAMCAll(Convert.ToInt32(dr["ID"]), month, year)
                   let MinCon = AMC * min
                   let maxCon = AMC * max
                   let eopCon = AMC * (eop + 0.25)
                   let SOH = bal.GetSOHAll(Convert.ToInt32(dr["ID"]), month, year)
                   let MOS = (AMC != 0) ? (SOH / AMC) : 0
                   let reorder = (maxCon > SOH) ? maxCon - SOH : 0
                   where SOH > eopCon && (SOH <= MinCon)
                   select MinCon).Count();
     }
     else
     {
         count += (from DataRow dr in dtItem.Rows
                   let AMC = bal.CalculateAMC(Convert.ToInt32(dr["ID"]), storeId, month, year)
                   let MinCon = AMC * min
                   let maxCon = AMC * max
                   let eopCon = AMC * (eop + 0.25)
                   let SOH = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, month, year)
                   let MOS = (AMC != 0) ? (SOH / AMC) : 0
                   let reorder = (maxCon > SOH) ? maxCon - SOH : 0
                   where SOH > eopCon && (SOH <= MinCon)
                   select MinCon).Count();
     }
     return count;
 }
コード例 #21
0
        private void GenerateStockStatusPieChart()
        {
            ReceiveDoc rec = new ReceiveDoc();

            chartPie.UseWaitCursor = true;
            chartPie.Series.Clear();
            int storeId = (cboStores.EditValue != null) ? Convert.ToInt32(cboStores.EditValue) : 0;
            curYear = Convert.ToInt32(cboYear.EditValue);

            var category = Convert.ToInt32(lkCategory.EditValue);
            curMont = (curYear == dtCurrent.Year) ? dtCurrent.Month : 12;
            //progressBar1.PerformStep();
            Balance bal = new Balance();
            Int64 stockin = bal.CountStockInByCategory(storeId, curMont, curYear ,category );
            // progressBar1.PerformStep();
            Int64 stockout = bal.CountStockOutByCategory(storeId, curMont, curYear, category);
            // progressBar1.PerformStep();
            Int64 overstock = bal.CountOverStockByCategory(storeId, curMont, curYear, category);
            // progressBar1.PerformStep();
            Int64 nearEOP = bal.CountNearEOPByCategory(storeId, curMont, curYear, category);
            // progressBar1.PerformStep();
            Int64 BelowEOP = bal.CountBelowEOPByCategory(storeId, curMont, curYear, category);

            object[] obj = {stockin, stockout, overstock, nearEOP, BelowEOP};

            DataTable dtList = new DataTable();
            dtList.Columns.Add("Type");
            dtList.Columns.Add("Value");
            dtList.Columns[1].DataType = typeof (Int64);

            object[] oo = {"In Stock", obj[0]};
            dtList.Rows.Add(oo);

            object[] oo2 = {"Stock Out", obj[1]};
            dtList.Rows.Add(oo2);

            object[] oo3 = {"Over Stock", obj[2]};
            dtList.Rows.Add(oo3);

            object[] oo4 = {"Near EOP", obj[3]};
            dtList.Rows.Add(oo4);

            object[] oo5 = {"Below EOP", obj[4]};
            dtList.Rows.Add(oo5);

            Series ser = new Series("pie", ViewType.Pie3D);
            ser.DataSource = dtList;

            ser.ArgumentScaleType = ScaleType.Qualitative;
            ser.ArgumentDataMember = "Type";
            ser.ValueScaleType = ScaleType.Numerical;
            ser.ValueDataMembers.AddRange(new string[] {"Value"});
            ser.PointOptions.PointView = PointView.ArgumentAndValues;
            ser.LegendText = "Key";
            ser.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
            ser.PointOptions.ValueNumericOptions.Precision = 0;

            ((PieSeriesLabel) ser.Label).Position = PieSeriesLabelPosition.TwoColumns;
            ((PiePointOptions) ser.PointOptions).PointView = PointView.ArgumentAndValues;

            chartPie.Series.Add(ser);
            chartPie.Size = new System.Drawing.Size(1000, 500);
            //progressBar1.PerformStep();
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();

            lblHeader.Text = info.HospitalName + " Stock Status summary of year " + curYear + " of " + cboStores.Text;
            // progressBar1.Visible = false;
            chartPie.UseWaitCursor = false;
        }
コード例 #22
0
        private void GetLastBackupAndSyncDates()
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            TimeSpan tt = new TimeSpan();

            if (!info.IsColumnNull("LastBackUp"))
            {
                string lastBackupDt = info.LastBackUp.ToString("MMM dd,yyyy") + " (" + DateTime.Now.Subtract(info.LastBackUp).Days + " days ago)"; ;
                lblLastBackupDate.Text = "Last Backup Date: " + lastBackupDt;
            }

            if (!info.IsColumnNull("LastSync"))
            {
                int days = DateTime.Now.Subtract(info.LastSync).Days;
                string lastSyncDt;
                if (days != 0)
                {
                    lastSyncDt = info.LastSync.ToString("MMM dd,yyyy") + " (" + days +
                                        " days ago)";
                }

                else
                    lastSyncDt = info.LastSync.ToString("MMM dd,yyyy") + " (Today)";

                lblLastSyncDate.Text = "Last Sync Date: " + lastSyncDt;
            }
        }
コード例 #23
0
        public DataTable CostBalanceByYear(int storeId, int year, int month, BackgroundWorker bw)
        {
            DataTable dtBal = new DataTable();
            GeneralInfo pipline = new GeneralInfo();

            // Dont Iterate
            DataTable dtbl = new DataTable();
            dtbl = GetSOH(storeId, month, year);
            return dtbl;
        }
コード例 #24
0
 private void btnAutoPushToPFSA_Click(object sender, EventArgs e)
 {
     if(!BLL.Settings.AllowOnlineOrders)
     {
         return;
     }
     var orders = GetOrders();
     var ginf = new GeneralInfo();
     ginf.LoadAll();
     var serviceModel = CompileOrder(ginf.FacilityID, orders);
     Send(serviceModel);
 }
コード例 #25
0
        //DU Info
        public Int64 CalculateDUAMC(int itemId, int receivingUnit, int month, int year, int LastSOH)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            int range = 3;
            try
            {
                range = info.DUAMCRange;
            }
            catch
            { }
            Int64 cons = 0;
            IssueDoc iss = new IssueDoc();

            int yr = (month > 10) ? year + 1 : year;

            DateTime dt1 = new DateTime(yr, month, DateTime.DaysInMonth(yr, month));
            DateTime dt2 = dt1.AddMonths(-range);
            int mon = dt2.Month;
            range = iss.GetAvailableNoOfMonthsDU(itemId, receivingUnit, dt2, dt1);
            yr = (mon > 10) ? year + 1 : year;
            cons = iss.GetDUConsumptionAfterMonth(itemId, receivingUnit, mon, yr);

            //for (int m = mon+1; m < month; m++ )
            //{
            //    yr = (m > 10) ? year - 1 : year;
            //    cons = cons + iss.GetDUConsumptionByMonth(itemId, receivingUnit, m, yr);
            //}
            yr = (month > 10) ? year + 1 : year;
            //yr = (month > 10) ? year : year  + 1 ;
            //Int64 lastIss = iss.GetDUIssueByMonth(itemId, receivingUnit, month, yr);
            Int64 lastIss = iss.GetDULastIssueQty(itemId, receivingUnit);
            // lastIss = ((lastIss > 0)? (lastIss - LastSOH) : lastIss );
            cons = cons + lastIss - LastSOH;
            //cons = cons - LastSOH;
            cons = ((cons > 0) ? cons : 0);
            Int64 AMC = cons / range;
            return AMC;
        }
コード例 #26
0
        public decimal GetMOS(int itemId, int storeId, DateTime dtCurrent)
        {
            GeneralInfo pipline = new GeneralInfo();
            pipline.LoadAll();
            int min = pipline.Min;
            int max = pipline.Max;
            double eop = pipline.EOP;
            Items itmB = new Items();
            Balance bal = new Balance();
               //Int64 AMC= bal.CalculateAMC(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
            double AMC = Builder.CalculateAverageConsumption(itemId,storeId,DateTime.Today.Subtract(TimeSpan.FromDays(180)), dtCurrent, CalculationOptions.Monthly);
                //bal.CalculateAMC(itemId, storeId, dtCurrent.Month, dtCurrent.Year);//dtBal.Rows.Count <= 0) ? 0 : ((dtBal.Rows[0]["AMC"].ToString() != "") ? Convert.ToInt64(dtBal.Rows[0]["AMC"]) : 0);
            double MinCon = AMC * min;
            double maxCon = AMC * max;
            double eopCon = AMC * (eop + 0.25);

            Int64 SOH = bal.GetSOH(itemId, storeId, dtCurrent.Month, dtCurrent.Year);

            decimal MOS = (AMC != 0) ? (SOH / Convert.ToDecimal(AMC)) : 0;
            MOS = Decimal.Round(MOS, 1);
            return MOS;
        }
コード例 #27
0
        private void printableComponentLink1_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
        {
            var info = new GeneralInfo();
            info.LoadAll();
            switch (filter)
            {
                case "Over Stocked":
                    {
                        string[] header =
                            {"Over Stocked Items Report",
                                info.HospitalName, "Date: " + dtDate.Text,
                                "Store: " + cboStores.Text
                            };
                        printableComponentLink1.Landscape = true;
                        printableComponentLink1.PageHeaderFooter = header;

                        TextBrick brick = e.Graph.DrawString(header[0], Color.DarkBlue, new RectangleF(0, 0, 200, 100),
                                                             BorderSide.None);
                        TextBrick brick1 = e.Graph.DrawString(header[1], Color.DarkBlue, new RectangleF(0, 20, 200, 100),
                                                              BorderSide.None);
                        TextBrick brick2 = e.Graph.DrawString(header[2], Color.DarkBlue, new RectangleF(0, 40, 200, 100),
                                                              BorderSide.None);
                        TextBrick brick3 = e.Graph.DrawString(header[3], Color.DarkBlue, new RectangleF(0, 60, 200, 100),
                                                              BorderSide.None);
                    }
                    break;
                case "Stock Out":
                    {
                        string[] header =
                            {
                                "Stocked Out Items Report",
                                info.HospitalName, "Date: " + dtDate.Text,
                                "Store: " + cboStores.Text
                            };
                        printableComponentLink1.Landscape = true;
                        printableComponentLink1.PageHeaderFooter = header;

                        TextBrick brick = e.Graph.DrawString(header[0], Color.DarkBlue, new RectangleF(0, 0, 200, 100),
                                                             BorderSide.None);
                        TextBrick brick1 = e.Graph.DrawString(header[1], Color.DarkBlue, new RectangleF(0, 20, 200, 100),
                                                              BorderSide.None);
                        TextBrick brick2 = e.Graph.DrawString(header[2], Color.DarkBlue, new RectangleF(0, 40, 200, 100),
                                                              BorderSide.None);
                        TextBrick brick3 = e.Graph.DrawString(header[3], Color.DarkBlue, new RectangleF(0, 60, 200, 100),
                                                              BorderSide.None);
                    }
                    break;
            }
        }
コード例 #28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rrfID"></param>
        private void SendRRF(int rrfID)
        {
            // Do the webservice magic here.
            GeneralInfo ginfo = new GeneralInfo();
            ginfo.LoadAll();

            chkCalculateInPacks.Checked = false;
            ChooseGridView();

            if (ginfo.IsColumnNull("FacilityID"))
            {
                XtraMessageBox.Show("The Facility ID Was not set, Please correct that and try again.");
                return;
            }

            int facilityID = ginfo.FacilityID;
            int startMonth = Convert.ToInt32(cboFromMonth.EditValue);
            int endMonth = Convert.ToInt32(cboToMonth.EditValue); //startMonth + 1;
            int fromYear = Convert.ToInt32(cboFromYear.EditValue);
            int toYear = Convert.ToInt32(cboToYear.EditValue);

            bool check;
            RRFService.ServiceSoapClient sc = new RRFService.ServiceSoapClient();
            try
            {
                check = sc.RRFExists(facilityID, toYear, startMonth, endMonth);
            }
            catch
            {
                XtraMessageBox.Show("There was a network Error, Please connect to the internet and try again.",
                                    "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (check)
            {
                check =
                    (XtraMessageBox.Show(
                        "Another Report has been submitted for the period you specified, Are you sure you would like to overwrite it?",
                        "Confirm Overwritting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
                     System.Windows.Forms.DialogResult.Yes);
            }

            if (!check)
            {
                RRFService.RrfSubmission rsubmission = new RrfSubmission
                                                           {
                                                               StartMonth = startMonth,
                                                               EndMonth = endMonth,
                                                               Year = toYear,
                                                               FacilityId = facilityID,
                                                               FacilityName = ginfo.HospitalName,
                                                               Items = new List<RRFItem>()
                                                           };

                DataTable dtbl = ((DataView) gridItemChoiceView.DataSource).Table;

                foreach (DataRow dr in dtbl.Rows)
                {
                    BLL.Items item = new Items();
                    item.LoadByPrimaryKey(Convert.ToInt32(dr["ID"]));

                    if (!item.MappingID.HasValue)
                    {
                        continue;
                    }

                    RRFService.RRFItem itm = new RRFService.RRFItem()
                                                 {
                                                     ItemID = item.MappingID.Value //  Convert.ToInt32(dr["ID"])
                                                     ,
                                                     BBalance = Convert.ToInt32(dr["BeginingBalance"])
                                                     ,
                                                     EBalance = Convert.ToInt32(dr["SOH"])
                                                     ,
                                                     Consumption = Convert.ToInt32(dr["Issued"])
                                                     ,
                                                     LossAdjustment = Convert.ToInt32(dr["LossAdj"])
                                                     ,
                                                     Max = Convert.ToInt32(dr["Max"])
                                                     ,
                                                     Received = Convert.ToInt32(dr["Received"])
                                                     ,
                                                     Requested = Convert.ToInt32(dr["Quantity"])
                                                 };

                    rsubmission.Items.Add(itm);
                }

                sc = new RRFService.ServiceSoapClient();
                try
                {
                    rsubmission.ReportedBy = "";
                    if (sc.SubmitRRF(rsubmission))
                    {
                        XtraMessageBox.Show("The Request has been submitted to PFSA.", "Confirmation",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        RRF rrf = new RRF();
                        rrf.LoadByPrimaryKey(rrfID);
                        rrf.DateOfSubmission = DateTime.Now;
                        rrf.LastRRFStatus = CheckRRFStatus(rrf.ID);
                        rrf.Save();
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
コード例 #29
0
        public DataTable GetECLSItemsStockOut(int storeId, int month, int year)
        {
            Items itm = new Items();
            Programs prog = new Programs();
            prog.GetProgramByName("Family Planning");
            DataTable dtItem = itm.GetItemsByProgram(prog.ID);
            GeneralInfo pipline = new GeneralInfo();
            pipline.LoadAll();
            int min = pipline.Min;
            int max = pipline.Max;
            double eop = pipline.EOP;

            DataTable dt = new DataTable();
            string[] cols = { "ID", "FullItemName", "DosageForm", "Strength", "Unit", "StockCode" };
            foreach (string st in cols)
            {
                dt.Columns.Add(st);
            }
            Balance bal = new Balance();
            foreach (DataRow dr in dtItem.Rows)
            {
                Int64 AMC = bal.CalculateAMC(Convert.ToInt32(dr["ID"]), storeId, month, year);
                Int64 MinCon = AMC * min;
                Int64 maxCon = AMC * max;
                double eopCon = AMC * (eop + 0.25);
                Int64 SOH = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, month, year);
                decimal MOS = (AMC != 0) ? (SOH / AMC) : 0;
                Int64 reorder = (maxCon > SOH) ? maxCon - SOH : 0;

                if (SOH == 0)
                {
                    object[] obb = { dr["ID"], dr["ItemName"], dr["DosageForm"], dr["Strength"], dr["Unit"], dr["StockCode"] };
                    dt.Rows.Add(obb);
                }
                //string status = (SOH <= eopCon && SOH > 0) ? "Near EOP" : ((SOH > maxCon) ? "Excess Stock" : ((SOH <= 0) ? "Stock Out" : "Normal"));
            }
            return dt;
        }
コード例 #30
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (VisibilitySetting.HandleUnits == 3) chkCalculateInPacks.Enabled = false;
            chkCalculateInPacks.Checked = false;
            if (
                XtraMessageBox.Show("Are you sure you want to save and print the RRF?", "Confirm",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                return;
            SaveRRF();
            var ginfo = new GeneralInfo();
            ginfo.LoadAll();
            var ethioDateFrom = new EthiopianDate.EthiopianDate(_fromYear, _fromMonth, 1);
            var ethioDateTo = new EthiopianDate.EthiopianDate(_toYear, _toMonth, 30);
            var rrfReport = new RRFReport
                                {
                                    FacilityName = {Text = ginfo.HospitalName},
                                    Period =
                                        {
                                            Text =
                                                string.Format("{0}, {1} - {2}, {3}", ethioDateFrom.GetMonthName(),
                                                              ethioDateFrom.Year, ethioDateTo.GetMonthName(),
                                                              ethioDateTo.Year)
                                        },
                                    ProgramName = {Text = cboProgram.Text},
                                    categoryName = {Text = lkCategory.Text}
                                };

            var tbl = ((DataView) gridItemChoiceView.DataSource).Table;
            tbl.TableName = "DataTable1";
            var dtset = new DataSet();
            dtset.Tables.Add(tbl.Copy());
            rrfReport.DataSource = dtset;
            if (Convert.ToInt32(cboProgram.EditValue) == 0 && Convert.ToInt32(lkCategory.EditValue) == 0)
            {
                rrfReport.ShowPreviewDialog();
            }
            else if(Convert.ToInt32(lkCategory.EditValue) != 0)
            {
                rrfReport.FilterString = String.Format("ProgramID={0} and TypeID ={1}", Convert.ToInt32(cboProgram.EditValue) ,Convert.ToInt32(lkCategory.EditValue));
                rrfReport.ShowPreviewDialog();
            }
            else
            {
                rrfReport.FilterString = String.Format("ProgramID={0}", Convert.ToInt32(cboProgram.EditValue));
                rrfReport.ShowPreviewDialog();
            }
        }
        /// <summary>
        /// Creates a marginal header area for the pcl object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Link_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
        {
            GeneralInfo info = new GeneralInfo();
            info.LoadAll();
            string[] header = { info.HospitalName , "Date:"  + dtDate.Text, "Store: " + cboStores.Text };
            pcl.Landscape = true;
            pcl.PageHeaderFooter = header;

            TextBrick brick = e.Graph.DrawString(header[0], Color.DarkBlue, new RectangleF(0, 0, 200, 100), BorderSide.None);
            TextBrick brick1 = e.Graph.DrawString(header[1], Color.DarkBlue, new RectangleF(0, 20, 200, 100), BorderSide.None);
            TextBrick brick2 = e.Graph.DrawString(header[2], Color.DarkBlue, new RectangleF(0, 40, 200, 100), BorderSide.None);
        }
コード例 #32
0
        public List<Order> GetStandardRRFOrders()
        {
            var client = new ServiceRRFLookupClient();
            var orders = new List<Order>();
            var ginfo = new GeneralInfo();
            ginfo.LoadAll();

            var dataView = gridItemChoiceView.DataSource as DataView;
            if (dataView != null)
            {
                dataView.RowFilter = gridItemChoiceView.ActiveFilterString;
                tblRRF = dataView.ToTable();
            }

            var periods = client.GetCurrentReportingPeriod(ginfo.FacilityID, ginfo.ScmsWSUserName, ginfo.ScmsWSPassword);
            var form = client.GetForms(ginfo.FacilityID, ginfo.ScmsWSUserName, ginfo.ScmsWSPassword);

            var rrfs = client.GetFacilityRRForm(ginfo.FacilityID, form[0].Id, periods[0].Id, 1, ginfo.ScmsWSUserName, ginfo.ScmsWSPassword);
            var formCategories = rrfs.First().FormCategories;
            var chosenCategoryBody = formCategories.First(x => x.Id == 1); //TODO:Hard coding to be removed.
            var items = chosenCategoryBody.Pharmaceuticals;

            var user = new User();
            user.LoadByPrimaryKey(MainWindow.LoggedinId);

            var order = new Order
                            {
                                RequestCompletedDate = DateTime.Now,
                                OrderCompletedBy = user.FullName,
                                RequestVerifiedDate = DateTime.Now,
                                OrderTypeId = STANDARD_ORDER,
                                SubmittedBy = user.FullName,
                                SubmittedDate = DateTime.Now,
                                SupplyChainUnitId = ginfo.FacilityID,
                                OrderStatus = 1, //TODO: hardcoding
                                FormId = form[0].Id, //TODO: hardcoding
                                ReportingPeriodId = periods[0].Id //TODO: hardcoding
                            };

            var details = new List<RRFTransactionService.OrderDetail>();

            foreach (DataRow rrfLine in tblRRF.Rows)
            {
                var detail = new RRFTransactionService.OrderDetail();
                var hcmisItemID = Convert.ToInt32(rrfLine["DSItemID"]);
                var rrFormPharmaceutical = items.SingleOrDefault(x => x.PharmaceuticalId == hcmisItemID);
                if (rrFormPharmaceutical != null && Convert.ToString(rrfLine["Status"]) != "Below EOP")
                {
                        detail.BeginningBalance = Convert.ToInt32(rrfLine["BeginingBalance"]);
                        detail.EndingBalance = Convert.ToInt32(rrfLine["SOH"]);
                        detail.QuantityReceived = Convert.ToInt32(rrfLine["Received"]);
                        detail.QuantityOrdered = Convert.ToInt32(rrfLine["Quantity"]);
                        detail.LossAdjustment = Convert.ToInt32(rrfLine["LossAdj"]);
                        detail.ItemId = rrFormPharmaceutical.ItemId;
                        var rdDoc = new ReceiveDoc();
                        var disposal = new Disposal();

                        rdDoc.GetAllWithQuantityLeft(hcmisItemID, _storeID);
                        disposal.GetLossAdjustmentsForLastRrfPeriod(hcmisItemID, _storeID, periods[0].StartDate,
                                                                    periods[0].EndDate);
                        int receiveDocEntries = rdDoc.RowCount;
                        int disposalEntries = disposal.RowCount;

                        if (rdDoc.RowCount == 0 && detail.EndingBalance == 0)
                            detail.Expiries = null;

                        detail.Expiries = new Expiry[receiveDocEntries];
                        detail.Adjustments = new Adjustment[disposalEntries];

                        rdDoc.Rewind();
                        int expiryAmountTotal = 0;

                        for (int j = 0; j < receiveDocEntries; j++)
                        {
                            var exp = new Expiry
                                          {
                                              Amount = Convert.ToInt32(rdDoc.QuantityLeft)
                                          };
                            expiryAmountTotal += exp.Amount;

                            exp.BatchNo = rdDoc.BatchNo;
                            exp.ExpiryDate = rdDoc.ExpDate;
                            if(exp.ExpiryDate > periods[0].EndDate.AddDays(ExpiryTreshHold))
                                exp.Amount = Convert.ToInt32(rdDoc.QuantityLeft);
                                exp.ExpiryDate = periods[0].EndDate;
                            detail.Expiries[j] = exp;
                            rdDoc.MoveNext();
                        }

                        disposal.Rewind();

                        int lossadjamt = 0;
                        for (int j = 0; j < disposalEntries; j++)
                        {
                            var adj = new Adjustment
                            {
                                Amount = Convert.ToInt32(disposal.Quantity),
                                TypeId = 1,
                                ReasonId = 1
                            };
                            lossadjamt += adj.Amount;

                            if (lossadjamt >= detail.LossAdjustment)
                                detail.LossAdjustment = lossadjamt;

                            detail.Adjustments[j] = adj;
                            disposal.MoveNext();
                        }

                        var stockoutIndexedLists = StockoutIndexBuilder.Builder.GetStockOutHistory(hcmisItemID, _storeID);
                        var DOSPerStockOut = stockoutIndexedLists.Count();
                        detail.DaysOutOfStocks = new DaysOutOfStock[stockoutIndexedLists.Count()];

                        for (int j = 0; j < stockoutIndexedLists.Count(); j++)
                        {
                            var dos = new DaysOutOfStock
                                          {
                                              NumberOfDaysOutOfStock = 5,
                                              StockOutReasonId = 5
                                          };
                            detail.DaysOutOfStocks[j] = dos;
                        }
                }
                else if(rrFormPharmaceutical != null && Convert.ToString(rrfLine["Status"]) == "Below EOP")
                {
                        detail.BeginningBalance = null;
                        detail.EndingBalance = null;
                        detail.QuantityReceived = null;
                        detail.QuantityOrdered = null;
                        detail.LossAdjustment = null;
                        detail.ItemId = rrFormPharmaceutical.ItemId;

                        var rdDoc = new ReceiveDoc();
                        var disposal = new Disposal();
                        rdDoc.GetAllWithQuantityLeft(hcmisItemID, _storeID);
                        disposal.GetLossAdjustmentsForLastRrfPeriod(hcmisItemID, _storeID, periods[0].StartDate,periods[0].EndDate);

                        int receiveDocEntries = rdDoc.RowCount;
                        int disposalEntries = disposal.RowCount;

                        if (rdDoc.RowCount == 0 && detail.EndingBalance == 0)
                            detail.Expiries = null;

                        detail.Expiries = new Expiry[receiveDocEntries];
                        detail.Adjustments = new Adjustment[disposalEntries];

                        rdDoc.Rewind();
                        int expiryAmountTotal = 0;
                        for (int j = 0; j < receiveDocEntries; j++)
                        {
                            var exp = new Expiry {Amount = Convert.ToInt32(rdDoc.QuantityLeft)};
                            expiryAmountTotal += exp.Amount;

                            exp.BatchNo = rdDoc.BatchNo;
                            exp.ExpiryDate = rdDoc.ExpDate;
                            if (expiryAmountTotal >= detail.EndingBalance)
                                if (detail.EndingBalance != null)
                                    exp.Amount = exp.Amount - (expiryAmountTotal - detail.EndingBalance.Value);
                            detail.Expiries[j] = null;
                            rdDoc.MoveNext();
                        }

                        disposal.Rewind();

                        int lossadjamt = 0;
                        for (int j = 0; j < disposalEntries; j++)
                        {
                            var adj = new Adjustment
                            {
                                Amount = Convert.ToInt32(disposal.Quantity),
                                TypeId = 11,
                                ReasonId = 39
                            };
                            lossadjamt += adj.Amount;

                            if (lossadjamt >= detail.LossAdjustment)
                                detail.LossAdjustment = lossadjamt;

                            detail.Adjustments[j] = null;
                            disposal.MoveNext();
                        }

                        var stockoutIndexedLists = StockoutIndexBuilder.Builder.GetStockOutHistory(hcmisItemID, _storeID);
                        var DOSPerStockOut = stockoutIndexedLists.Count();
                        detail.DaysOutOfStocks = new DaysOutOfStock[stockoutIndexedLists.Count()];

                        for (int j = 0; j < stockoutIndexedLists.Count(); j++)
                        {
                            var dos = new DaysOutOfStock();
                            dos.NumberOfDaysOutOfStock = 5;
                            dos.StockOutReasonId = 5;
                            detail.DaysOutOfStocks[j] = null;
                        }
                 }
                details.Add(detail);
            }
            order.OrderDetails = details.ToArray();
            orders.Add(order);
            // loop through each record and create order & order details objects
            return orders;
        }
        private void Link_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
        {
            var info = new GeneralInfo();
            info.LoadAll();

            int year = Convert.ToInt32(cboYear.EditValue);
            int month = 10;
            int day = 30;
            if (year == dtCurrent.Year)
            {
                month = dtCurrent.Month;
                day = dtCurrent.Day;
            }

            DateTime startDate = EthiopianDate.EthiopianDate.EthiopianToGregorian(String.Format("{0}/{1}/{2}", 1, 11, year - 1));
            DateTime endDate = EthiopianDate.EthiopianDate.EthiopianToGregorian(String.Format("{0}/{1}/{2}", day, month, year));
            DateTime currentDate = EthiopianDate.EthiopianDate.EthiopianToGregorian(String.Format("{0}/{1}/{2}", dtCurrent.Day, dtCurrent.Month, dtCurrent.Year));

            string strStartDate = EthiopianDate.EthiopianDate.GregorianToEthiopian(startDate);
            string strEndDate = EthiopianDate.EthiopianDate.GregorianToEthiopian(endDate);
            string strCurrentDate = EthiopianDate.EthiopianDate.GregorianToEthiopian(currentDate);

            string[] header = { info.HospitalName, "General Expiry For Current Year", "From Start Date: " + strStartDate, "To End Date: " + strEndDate, "Printed Date: " + strCurrentDate };
            printableComponentLink1.Landscape = true;
            printableComponentLink1.PageHeaderFooter = header;

            TextBrick brick = e.Graph.DrawString(header[0], Color.DarkBlue, new RectangleF(0, 0, 200, 100), BorderSide.None);
            TextBrick brick1 = e.Graph.DrawString(header[1], Color.DarkBlue, new RectangleF(0, 20, 200, 100), BorderSide.None);
            TextBrick brick2 = e.Graph.DrawString(header[2], Color.DarkBlue, new RectangleF(0, 40, 200, 100), BorderSide.None);
            TextBrick brick3 = e.Graph.DrawString(header[3], Color.DarkBlue, new RectangleF(160, 40, 200, 100), BorderSide.None);
            TextBrick brick4 = e.Graph.DrawString(header[4], Color.DarkBlue, new RectangleF(0, 60, 200, 100), BorderSide.None);
        }