Example #1
0
        public void SetPriceForReceiveDocs()
        {
            ReceiveDoc receiveDoc = new ReceiveDoc();

            receiveDoc.LoadbyItemUnitManufacturerMovingAverageID(ReceiptID.Value, ItemID, ItemUnitID, ManufacturerID, MovingAverageID);
            receiveDoc.Rewind();
            while (!receiveDoc.EOF)
            {
                if (receiveDoc.IsColumnNull("PricePerPack") || !(receiveDoc.PricePerPack > 0))
                {
                    receiveDoc.PricePerPack = AverageCost;
                }
                if (receiveDoc.IsColumnNull("UnitCost") || !(receiveDoc.PricePerPack > 0))
                {
                    receiveDoc.UnitCost = Convert.ToDecimal(AverageCost);
                }
                receiveDoc.Cost         = AverageCost;
                receiveDoc.Margin       = Margin;
                receiveDoc.SellingPrice = SellingPrice;
                receiveDoc.MoveNext();
            }
            receiveDoc.Save();
        }
Example #2
0
 private void btnCancelReceive_Click(object sender, EventArgs e)
 {
     if (XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, "Are you sure, you want to Cancel the Receipt Document?", "Are you sure:", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
     {
         try
         {
             int receiptID  = Convert.ToInt32(gridReceiveView.GetFocusedDataRow()["ReceiptID"].ToString());
             var receiveDoc = new ReceiveDoc();
             receiveDoc.LoadByReceiptID(receiptID);
             receiveDoc.Rewind();
             while (!receiveDoc.EOF)
             {
                 BLL.ReceiveDoc.DeleteAReceiveDocEntry(receiveDoc.ID, CurrentContext.UserId);
                 receiveDoc.MoveNext();
             }
             XtraMessageBox.Show("You have successfully canceled the draft receipt.", "Confirmation");
             BindFormContents();
         }
         catch (Exception exception)
         {
             XtraMessageBox.Show(exception.Message);
         }
     }
 }
        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;
        }
        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;
        }
        private void SaveReceive()
        {
            // Merge all Receives with Same Item information and Assigned to Same PhysicalStore as One Item , Quantity Sumed UP!
            MergeReceiveDocLines();

            BLL.ReceiveDoc rec = new ReceiveDoc();

            ////int receiptTypeID = srm
            ////    ? ReceiptType.CONSTANTS.STOCK_RETURN
            ////    : (deliveryNoteType != DeliveryNoteType.NotSet)
            ////        ? ReceiptType.CONSTANTS.DELIVERY_NOTE
            ////        : beginningBalance
            ////            ? ReceiptType.CONSTANTS.BEGINNING_BALANCE
            ////            : ReceiptType.CONSTANTS.STANDARD_RECEIPT;
            int receiptID;
            int warehouseID = Convert.ToInt32(lkWarehouse.EditValue);

            receiptID = SaveRelevantReceiptHeaders(_receiptTypeID, warehouseID);

            DataTable zeroQuantitiesDueToMultipleBatch = null;
            DataRow [] zeroQuantityRows =
                _dtRecGrid.Select(string.Format("[Pack Qty] = 0"),"[Ordering] ASC ");

            if (zeroQuantityRows.Any() && zeroQuantityRows.Any(r => r["ShortageReasonID"] == DBNull.Value))
            {
                zeroQuantityRows = CheckAndRemoveIfFullNotReceiveEntry(zeroQuantityRows);
                if (zeroQuantityRows.Any())
                    zeroQuantitiesDueToMultipleBatch =
                        zeroQuantityRows.Where(r => r["ShortageReasonID"] == DBNull.Value).CopyToDataTable();
            }

            var mergeableTables = _dtRecGrid.Select(string.Format("[Pack Qty] > 0 "), "[Ordering] ASC ");
            DataTable mergedDataTable = null;
            if (mergeableTables.Any())
            {
                mergedDataTable =
                    _dtRecGrid.Select(string.Format("[Pack Qty] > 0 "), "[Ordering] ASC ").CopyToDataTable();

                if (zeroQuantitiesDueToMultipleBatch != null)
                    mergedDataTable.Merge(zeroQuantitiesDueToMultipleBatch);

                if (grdShortageOrDamaged.DataSource != null)
                {
                    var shortageOrDamage = (DataTable) grdShortageOrDamaged.DataSource;
                    mergedDataTable.Merge(shortageOrDamage);
                }
            }
            else
            {
                if (grdShortageOrDamaged.DataSource != null)
                {
                    var shortageOrDamage = (DataTable)grdShortageOrDamaged.DataSource;
                    if (zeroQuantitiesDueToMultipleBatch != null)
                        shortageOrDamage.Merge(zeroQuantitiesDueToMultipleBatch);
                    //~ {"[ShortageReasonID] ASC} --> Just to give priority among shortages to Damaged reasons as we will create a receiveDoc entry for this ~//
                    mergedDataTable = mergedDataTable == null ? shortageOrDamage.Select(string.Format("[Pack Qty] >= 0 "), "[ShortageReasonID] ASC ").CopyToDataTable() : shortageOrDamage;

                }
            }

            foreach (DataRowView dr in mergedDataTable.DefaultView)
            {
                var shortageReasonID = dr["ShortageReasonID"];

                var onlyOneEntryFound = _dtRecGrid.Select(String.Format("GUID = '{0}'", dr["GUID"]));

                bool zeroQtyDueTomultipleBatchFound = (Convert.ToDecimal(dr["Pack Qty"]) == 0) && (shortageReasonID == DBNull.Value) && (onlyOneEntryFound.Count() == 1);
                bool fullNotReceivedEntry = (Convert.ToDecimal(dr["BU Qty"]) == 0) && (shortageReasonID != DBNull.Value) && (Convert.ToInt32(shortageReasonID) == ShortageReasons.Constants.NOT_RECEIVED) && (onlyOneEntryFound.Count() == 1);
                if (fullNotReceivedEntry)
                {
                    dr["Pack Qty"] = 0;
                }

                var item = new Item();
                item.LoadByPrimaryKey(Convert.ToInt32(dr["ID"]));

                if (item.NeedExpiryBatch || (shortageReasonID == DBNull.Value && ((dr["Expiry Date"] != DBNull.Value) && (Convert.ToDateTime(dr["Expiry Date"]) <= DateTimeHelper.ServerDateTime))))
                {

                    var expDate = Convert.ToDateTime(dr["Expiry Date"]);

                    if ((shortageReasonID == DBNull.Value && expDate > DateTimeHelper.ServerDateTime) || zeroQtyDueTomultipleBatchFound)
                    {
                        AddNewReceiveDoc(rec, receiptID, dr);
                    }
                    else
                    {
                        //for physically Damaged receives and expired receives
                        if ((shortageReasonID != DBNull.Value && Convert.ToInt32(shortageReasonID) == ShortageReasons.Constants.DAMAGED) || (shortageReasonID == DBNull.Value && expDate <= DateTimeHelper.ServerDateTime) || fullNotReceivedEntry)
                        {
                            AddNewReceiveDoc(rec, receiptID, dr, true);
                            if (shortageReasonID == DBNull.Value)
                            {
                                dr["ShortageReasonID"] = ShortageReasons.Constants.DAMAGED;
                            }
                        }
                        else
                        {

                            HandleReceiveDocShortage(dr, rec);
                        }
                    }
                }
                else
                {

                    if ((shortageReasonID == DBNull.Value) || zeroQtyDueTomultipleBatchFound)
                    {
                        AddNewReceiveDoc(rec, receiptID, dr);
                    }
                    else
                    {
                        //for physically Damaged receives
                        if (shortageReasonID != DBNull.Value && Convert.ToInt32(shortageReasonID) == ShortageReasons.Constants.DAMAGED || fullNotReceivedEntry)
                        {
                            AddNewReceiveDoc(rec, receiptID, dr, true);
                        }
                        else
                        {
                            HandleReceiveDocShortage(dr, rec);
                        }

                    }
                }

            }

            rec.SetStatusAsReceived(CurrentContext.UserId);

            BLL.Receipt receiptStatus = new BLL.Receipt();
            receiptStatus.LoadByPrimaryKey(receiptID);
            receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.RECEIVE_ENTERED, null,
                this.GetFormIdentifier(), CurrentContext.UserId, "Received");
            if (!BLL.Settings.HandleGRV) //If HandleGRV is true, the price isn't entered in the receive stage meaning
            {
                rec.Rewind();
                while (!rec.EOF)
                {
                    if (!ReceiveDoc.DoesPriceNeedToBeChanged(rec.StoreID, rec.ItemID, rec.UnitID, rec.ManufacturerId) &&
                        (deliveryNoteType == DeliveryNoteType.NotSet))
                    {
                        rec.SellingPrice = rec.Cost;
                        rec.UnitCost = Convert.ToDecimal(rec.Cost);
                        // Added by Heny In order to display Unit Cost on Vaccine
                        rec.Margin = 0;
                    }
                    rec.MoveNext();
                }
            }

            rec.Save(); //TODO: To be removed after the ShortageReasonID in receviedoc is discontinued.

            //SavePalletization(rdDamaged);
            _revDocRelatePalletGuid.Clear();
        }
 public void SetPriceForReceiveDocs()
 {
     ReceiveDoc receiveDoc = new ReceiveDoc();
     receiveDoc.LoadbyItemUnitManufacturerMovingAverageID(ReceiptID.Value,ItemID,ItemUnitID,ManufacturerID,MovingAverageID);
     receiveDoc.Rewind();
     while (!receiveDoc.EOF)
     {
         if(receiveDoc.IsColumnNull("PricePerPack") || !(receiveDoc.PricePerPack > 0))
             receiveDoc.PricePerPack = AverageCost;
         if(receiveDoc.IsColumnNull("UnitCost") || !(receiveDoc.PricePerPack > 0))
             receiveDoc.UnitCost = Convert.ToDecimal(AverageCost);
         receiveDoc.Cost = AverageCost;
         receiveDoc.Margin = Margin;
         receiveDoc.SellingPrice = SellingPrice;
         receiveDoc.MoveNext();
     }
     receiveDoc.Save();
 }
Example #7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int warehouseID = Convert.ToInt32(lkWarehouse.EditValue);

            receiveDoc.Rewind();
            var po             = new BLL.PO();
            var receiptInvoice = new BLL.ReceiptInvoice();

            while (!receiveDoc.EOF)
            {
                //Handle the PO.
                //int receiptID;
                if (po.RowCount == 0 || po.StoreID != receiveDoc.StoreID)
                {
                    Supplier supplier = new Supplier();
                    po = BLL.PO.CreatePOforStandard(OrderType.CONSTANTS.STANDARD_ORDER, receiveDoc.StoreID,
                                                    supplier.GetHubHomeOfficeSupplierID(), "", CurrentContext.LoggedInUser.ID);
                    //Should we receive it as hub to hub transfer? We're now using Standard order.
                    receipt = BLL.ReceiptInvoice.CreateAutomaticReceiptInvoiceForSTVTransfer(po.ID, warehouseID, STVNo,
                                                                                             CurrentContext.UserId);
                }

                receiveDoc.Quantity  = receiveDoc.QtyPerPack * receiveDoc.NoOfPack;
                receiveDoc.ReceiptID = receipt.ID;
                receiveDoc.MoveNext();
            }
            receiveDoc.Save();

            //Save the location
            receiveDoc.Rewind();

            BLL.ReceivePallet receivePallet = new ReceivePallet();
            while (!receiveDoc.EOF)
            {
                //Save Location Information
                BLL.PalletLocation palletLocation = new PalletLocation();

                receivePallet.AddNew();

                int palletLocationID = Convert.ToInt32(receiveDoc.GetColumn("PalletLocationID"));
                receivePallet.PalletLocationID = palletLocationID;

                palletLocation.LoadByPrimaryKey(palletLocationID);

                receivePallet.PalletID         = palletLocation.PalletID;
                receivePallet.ReceivedQuantity = receiveDoc.Quantity;
                receivePallet.Balance          = receiveDoc.Quantity;
                receivePallet.ReceiveID        = receiveDoc.ID;
                receivePallet.ReservedStock    = 0;


                //Save Discrepancy information if there is any
                receiveDocShortage.Rewind();
                while (receiveDocShortage.FindNextByGUID(receiveDoc.GetColumn("GUID").ToString()))
                {
                    receiveDocShortage.ReceiveDocID = receiveDoc.ID;

                    if (receiveDocShortage.ShortageReasonID == ShortageReasons.Constants.DAMAGED)
                    {
                        receiveDoc.NoOfPack += receiveDocShortage.NoOfPacks;
                        receiveDoc.Quantity += receiveDocShortage.NoOfPacks * receiveDoc.QtyPerPack;

                        palletLocationID = Convert.ToInt32(receiveDocShortage.GetColumn("PalletLocationID"));
                        receivePallet.AddNew();
                        receivePallet.PalletLocationID = palletLocationID;
                        palletLocation.LoadByPrimaryKey(palletLocationID);

                        receivePallet.PalletID         = palletLocation.PalletID;
                        receivePallet.ReceivedQuantity = receiveDocShortage.NoOfPacks * receiveDoc.QtyPerPack;
                        receivePallet.Balance          = receiveDocShortage.NoOfPacks * receiveDoc.QtyPerPack;
                        receivePallet.ReceiveID        = receiveDoc.ID;
                        receivePallet.ReservedStock    = 0;
                    }
                }

                receiveDoc.MoveNext();
            }
            receivePallet.IsOriginalReceive = true;
            receivePallet.Save();
        }
        /// <summary>
        /// Palletizes the transfer.
        /// </summary>
        /// <param name="rec">The rec.</param>
        public static void PalletizeTransfer(ReceiveDoc rec)
        {
            BLL.ReceivePallet rp = new ReceivePallet();
            Pallet pallet = new Pallet();
            PalletLocation pl = new PalletLocation();
            rec.Rewind();
            BLL.ItemManufacturer im = new BLL.ItemManufacturer();
            rp.AddNew();
            rp.ReceivedQuantity = rec.Quantity;
            rp.Balance = rec.Quantity;
            rp.ReservedStock = 0;
            rp.ReceiveID = rec.ID;
            //Just To Get the First Free pallet
            DataTable dtpl = PalletLocation.GetAllFreeForItem(rec.ItemID, StorageType.Free);
            DataRow drpl = dtpl.Rows[0];
            //After we assign the Location for it
            pl.LoadByPrimaryKey(Convert.ToInt32(drpl["ID"]));

            rp.PalletID = pl.PalletID;
            rp.PalletLocationID = pl.ID;
            rp.IsOriginalReceive = true;
            rp.Save();
        }
        private void btnCancelReceive_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, "Are you sure, you want to Cancel the Receipt Document?", "Are you sure:", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
            {

                try
                {
                    int receiptID = Convert.ToInt32(gridReceiveView.GetFocusedDataRow()["ReceiptID"].ToString());
                    var receiveDoc = new ReceiveDoc();
                    receiveDoc.LoadByReceiptID(receiptID);
                    receiveDoc.Rewind();
                    while (!receiveDoc.EOF)
                    {
                        BLL.ReceiveDoc.DeleteAReceiveDocEntry(receiveDoc.ID, CurrentContext.UserId);
                        receiveDoc.MoveNext();
                    }
                    XtraMessageBox.Show("You have successfully canceled the draft receipt.", "Confirmation");
                    BindFormContents();
                }
                catch (Exception exception)
                {
                    XtraMessageBox.Show(exception.Message);
                }

            }
        }