Exemplo n.º 1
0
        private void cbYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxControl1.SelectedItem.ToString().Equals("Issued Amount by Year"))
            {
                IssuedAmoutByYear issuedAmoutByYearReport = new IssuedAmoutByYear(CurrentContext.LoggedInUserName);

                issuedAmoutByYearReport.DataSource   = IssueDoc.IssuedAmoutByYear(Convert.ToInt32(cbYear.SelectedItem), Convert.ToInt32(lkAccount.EditValue), Convert.ToBoolean(checbySellingPrice.Checked));
                issuedAmoutByYearReport.xrMonth.Text = string.Format("{0}", cbYear.SelectedItem);
                printControl1.PrintingSystem         = issuedAmoutByYearReport.PrintingSystem;
                report = issuedAmoutByYearReport;
                issuedAmoutByYearReport.CreateDocument();
            }
            else if (listBoxControl1.SelectedItem.ToString().Equals("Received Amount by Year"))
            {
                ReceivedAmoutByYear receivedAmountReport = new ReceivedAmoutByYear(CurrentContext.LoggedInUserName);

                receivedAmountReport.DataSource   = ReceiveDoc.ReceivedAmoutByYear(Convert.ToInt32(cbYear.SelectedItem), Convert.ToInt32(lkAccount.EditValue));
                receivedAmountReport.xrMonth.Text = string.Format("{0}", cbYear.SelectedItem);
                printControl1.PrintingSystem      = receivedAmountReport.PrintingSystem;
                report = receivedAmountReport;
                receivedAmountReport.CreateDocument();
            }
            else if (lkMode.EditValue != null && lkCategories.EditValue != null && cbMonth.SelectedItem != null && cbYear.SelectedItem != null && cbToYear.SelectedItem != null && cbToMonth.SelectedItem != null && listBoxControl1.SelectedItem.ToString().Equals("Vital Report"))
            {
                LadVitalItemReport();
            }
            else
            {
                cbMonth_SelectedIndexChanged(null, null);
            }
        }
        /// <summary>
        /// This generates picklist for everything in the receivepallet entry.
        /// </summary>
        /// <param name="receiveDoc"></param>
        /// <param name="receivePallet"></param>
        /// <param name="order"></param>
        /// <param name="picklist"></param>
        /// <returns></returns>
        public PickListDetail CreatePicklistDetailWithOrder(ReceiveDoc receiveDoc, ReceivePallet receivePallet, Order order, PickList picklist)
        {
            double?      cost         = null;
            decimal      pack         = receivePallet.Balance / receiveDoc.QtyPerPack;
            OrderService orderService = new OrderService();

            orderService.CreateOrderDetail(receiveDoc, order, pack);
            if (!receiveDoc.IsColumnNull("Cost"))
            {
                cost = receiveDoc.Cost;
            }
            PickListDetail pickListDetail = PickListDetail.GeneratePickListDetail(pack, cost, receiveDoc.ID,
                                                                                  receiveDoc.ManufacturerId,
                                                                                  receivePallet.ID,
                                                                                  receiveDoc.QtyPerPack,
                                                                                  receiveDoc.StoreID, receiveDoc.UnitID,
                                                                                  receiveDoc.ItemID, picklist.ID,
                                                                                  receivePallet.PalletID,
                                                                                  receiveDoc.ExpDate.ToString(),
                                                                                  receiveDoc.BatchNo);

            ReceivePallet.ReserveQty(pack, receivePallet.ID);

            return(pickListDetail);
        }
Exemplo n.º 3
0
        private void BindConsolidation()
        {
            ReceiveDoc rd = new ReceiveDoc();

            rd.LoadUniqueReceivedItems();
            gridItems.DataSource = rd.DefaultView;
        }
        private void dtTo_ValueChanged(object sender, EventArgs e)
        {
            if (_isReady)
            {
                ReceiveDoc rec = new ReceiveDoc();
                dtFrom.CustomFormat = "MM/dd/yyyy";
                dtTo.CustomFormat   = "MM/dd/yyyy";
                DateTime dteFrom = new DateTime();
                DateTime dteTo   = new DateTime();

                dteFrom = ConvertDate.DateConverter(dtFrom.Text);
                dteTo   = ConvertDate.DateConverter(dtTo.Text);

                DataTable dtRec = new DataTable();
                if (dteFrom < dteTo)
                {
                    dtRec = rec.GetTransactionByDateRange(Convert.ToInt32(cboStores.EditValue), dteFrom, dteTo);
                }
                else
                {
                    dtRec = rec.GetAllTransaction(Convert.ToInt32(cboStores.EditValue));
                }
                PopulateTransactions(dtRec);
            }
        }
Exemplo n.º 5
0
        private void PopulateGrid()
        {
            if (IsReady)
            {
                if (cboStores.EditValue != null)
                {
                    int storeId = (cboStores.EditValue != null) ? Convert.ToInt32(cboStores.EditValue) : 1;

                    var recDoc = new ReceiveDoc();
                    var dtBal  = new DataTable();

                    switch (VisibilitySetting.HandleUnits)
                    {
                    case 1:
                        dtBal = (DataTable)recDoc.GetItemsWithPrice(storeId, Convert.ToInt32(lkCommodityTypes.EditValue));
                        break;

                    case 2:
                        dtBal = (DataTable)recDoc.GetItemsWithPrice(storeId, Convert.ToInt32(lkCommodityTypes.EditValue));
                        break;

                    default:
                        dtBal = (DataTable)recDoc.GetItemsWithPrice(storeId, Convert.ToInt32(lkCommodityTypes.EditValue));
                        break;
                    }

                    gridItemsChoice.DataSource = dtBal;
                }
            }
        }
        private void gridOrderListView_FocusedRowChanged(object sender,
                                                         DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            DataRow dr = gridOrderListView.GetFocusedDataRow();

            if (dr != null)
            {
                int        receiptID  = Convert.ToInt32(dr["ID"]);
                ReceiveDoc receiveDoc = new ReceiveDoc();
                receiveDoc.LoadAllByReceiptID(receiptID);
                DataTable         tbl = receiveDoc.DefaultView.ToTable();
                ReceiveDocDeleted receiveDocDeleted = new ReceiveDocDeleted();
                receiveDocDeleted.LoadAllByReceiptID(receiptID);

                LogReceiptStatus logReceiptStatus = new LogReceiptStatus();
                gridHistory.DataSource = logReceiptStatus.GetLogHistory(receiptID);

                if (receiveDocDeleted.RowCount > 0)
                {
                    tbl.Merge(receiveDocDeleted.DefaultView.ToTable());
                    BLL.User user = new User();
                    user.LoadByPrimaryKey(receiveDocDeleted.DeletedBy);
                    if (user.RowCount > 0)
                    {
                        lblDeletedBy.Text = string.Format("Deleted By {0}",
                                                          string.IsNullOrEmpty(user.FullName)
                                                              ? user.UserName
                                                              : user.FullName);
                    }
                }

                gridOrderDetail.DataSource = tbl;
            }
        }
Exemplo n.º 7
0
        private bool ValidatePickList()
        {
            foreach (DataRowView drv in _dvPickListMakeup)
            {
                int itemID         = Convert.ToInt32(drv["ItemID"]);
                int storeID        = Convert.ToInt32(drv["StoreID"]);
                int unitID         = Convert.ToInt32(drv["UnitID"]);
                int manufacturerID = Convert.ToInt32(drv["ManufacturerID"]);

                ReceiveDoc rd = new ReceiveDoc();

                if (BLL.Settings.BlockWhenExpectingPriceChange && BLL.ReceiveDoc.DoesPriceNeedToBeChanged(storeID, itemID, unitID, manufacturerID))
                {
                    OrderDetail odetail = new OrderDetail();
                    odetail.Where.ItemID.Value  = itemID;
                    odetail.Where.OrderID.Value = _orderID;
                    odetail.Query.Load();
                    if (odetail.RowCount > 0)
                    {
                        if (odetail.ApprovedQuantity == 0)
                        {
                            continue;
                        }
                    }

                    Item itm = new Item();
                    itm.LoadByPrimaryKey(itemID);
                    XtraMessageBox.Show(
                        string.Format("The item {0} cannot be issued because it is waiting for price change.", itm.FullItemName),
                        "Price Pending", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            //TODO: finish updating the changed locations
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            if (gridGRVs.DataSource == null)
            {
                return;
            }
            transaction.BeginTransaction();
            try
            {
                PalletLocation pl     = new PalletLocation();
                BLL.ReceiveDoc recDoc = new ReceiveDoc();
                recDoc.LoadByReceiptID(ReceiptID);
                recDoc.SetStatusAsReceived(null);
                BLL.Receipt receiptStatus = new BLL.Receipt();
                receiptStatus.LoadByPrimaryKey(ReceiptID);
                receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.RECEIVE_ENTERED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Return For Quantity Editing");

                transaction.CommitTransaction();
                this.LogActivity("Return-Receipt-To-Quantity-Confirmation", ReceiptID);
                XtraMessageBox.Show("Receipt Returned!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw exp;
            }
            PutAwayListsLoad(null, null);
        }
Exemplo n.º 9
0
        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();

            if (dr == null)
            {
                return;
            }

            int        tranId = Convert.ToInt32(dr["ID"]);
            ReceiveDoc rec    = new ReceiveDoc();

            rec.LoadByPrimaryKey(tranId);

            _dtDate.Value        = DateTime.Now;
            _dtDate.CustomFormat = "MM/dd/yyyy";
            IssueDoc iss = new IssueDoc();

            iss.GetIssueByBatchAndId(rec.ItemID, rec.BatchNo, rec.ID);
            DateTime dtCurrent = ConvertDate.DateConverter(_dtDate.Text);

            if ((rec.Date.Year != dtCurrent.Year && rec.Date.Month < 11) || (iss.RowCount != 0))
            {
                //XtraMessageBox.Show("Unable to edit, This Transaction has been processed. Try Loss and Adjustment.", "Unable to Edit", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                EditReceive edRec = new EditReceive(tranId, true);
                MainWindow.ShowForms(edRec);
            }
            else
            {
                EditReceive edRec = new EditReceive(tranId, false);
                MainWindow.ShowForms(edRec);
            }
        }
        public void CreateDetailTransactionsForErrorCorrection(Order order, BLL.PickList picklist,
                                        Issue stvLog, int receiptPalletId, int receiptID, User user, DateTime convertedEthDate
                                        , int newItemId, int newUnitId, int newManufacturerId, decimal pickedPack
                                        , decimal Convertedpack, int confirmationStatusId, bool changeExpiryDate
                                        , DateTime? ExpiryDate, bool changeBatchNo, string batchNo)
        {
            //Load the ReceivePallet First From that we Get the Information that We need
            ReceivePallet receivePalletOriginal = new ReceivePallet();
            receivePalletOriginal.LoadByPrimaryKey(receiptPalletId);

            ReceiveDoc receiveDocOriginal = new ReceiveDoc();
            receiveDocOriginal.LoadByPrimaryKey(receivePalletOriginal.ReceiveID);

            //Load ItemUnit Detail for For ItemUnit Change;
            ItemUnit newItemUnit = new ItemUnit();
            newItemUnit.LoadByPrimaryKey(newUnitId);

              // Generate PicklistDetail With OrderDetail information
            PickListService pickListService = new PickListService();
            PickListDetail pickListDetail = pickListService.CreatePicklistDetailWithOrder(receiveDocOriginal, receivePalletOriginal, order, picklist,
                                                          pickedPack);
            // Generate IssueDoc from picklistDetail and substract the quantity from receiveDoc
            IssueService issueService = new IssueService();
            issueService.CreateIssueFromPicklist(pickListDetail, order, convertedEthDate, stvLog, user);

            if (Convertedpack > 0)
            {
                //duplicate The ReceiveDoc and ReceiptPallet
                ReceiveService receiveService = new ReceiveService();
                receiveService.CloneReceiveForErrorCorrection(confirmationStatusId, receivePalletOriginal, receiveDocOriginal
                                                                , Convertedpack, user, newItemId
                                                                , receiveDocOriginal.StoreID, receiptID
                                                                , newManufacturerId, newItemUnit, convertedEthDate,changeExpiryDate,ExpiryDate,changeBatchNo,batchNo);
            }
        }
Exemplo n.º 11
0
        private void LkFromStoreEditValueChanged(object sender, EventArgs e)
        {
            var rDoc = new ReceiveDoc();

            if (lkFromStore.EditValue == null)
            {
                return;
            }

            string strStartDate;

            EthiopianDate.EthiopianDate startDate = EthiopianDate.EthiopianDate.Now;
            strStartDate = "11/1/" + (startDate.Year - 2).ToString();

            string strEndDate = EthiopianDate.EthiopianDate.Now.Month.ToString() + '/' + EthiopianDate.EthiopianDate.Now.Day.ToString() + '/' + EthiopianDate.EthiopianDate.Now.Year.ToString();

            var dtItem = rDoc.GetRecievedItemsWithBalanceForStore(Convert.ToInt32(lkFromStore.EditValue), (int)lkCategories.EditValue, strStartDate, strEndDate);

            PopulateItemList(dtItem);

            gridItemsView.ActiveFilterString = String.Format("[FullItemName] Like '{0}%' And [TypeID] = {1}", txtItemName.Text, (int)(lkCategories.EditValue ?? 0));

            //var inventory = new YearEnd();
            //if (inventory.IsInventoryCompleteToReceive(EthiopianDate.EthiopianDate.Now.Year-1, Convert.ToInt32(lkFromStore.EditValue)) != false) return;
            //XtraMessageBox.Show("Please First Finish All Inventory and come back!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //    btnSave.Enabled = false;
        }
Exemplo n.º 12
0
        private void cboStores_EditValueChanged(object sender, EventArgs e)
        {
            dtSelectedTable = null;
            string strStartDate;

            EthiopianDate.EthiopianDate startDate = EthiopianDate.EthiopianDate.Now;
            strStartDate = "11/1/" + (startDate.Year - 5).ToString();

            string strEndDate = EthiopianDate.EthiopianDate.Now.Month.ToString() + '/' + EthiopianDate.EthiopianDate.Now.Day.ToString() + '/' + EthiopianDate.EthiopianDate.Now.Year.ToString();

            var rDoc = new ReceiveDoc();

            if (ckExpired.Checked && cboStores.EditValue != null && lkCategories.EditValue != null)
            {
                var dtItem = rDoc.GetRecievedItemsWithBalanceForStore(Convert.ToInt32(cboStores.EditValue),
                                                                      (int)lkCategories.EditValue, strStartDate, strEndDate);
                PopulateItemList(dtItem);
                gridItemChoiceView.ActiveFilterString = String.Format("[ExpiryDate] < #{0}# and [TypeID]={1}",
                                                                      DateTime.Now, (int)lkCategories.EditValue);
            }
            if (!ckExpired.Checked && cboStores.EditValue != null && lkCategories.EditValue != null)
            {
                var dtItem = rDoc.GetRecievedItemsWithBalanceForStore(Convert.ToInt32(cboStores.EditValue),
                                                                      (int)lkCategories.EditValue, strStartDate, strEndDate);
                PopulateItemList(dtItem);
                gridItemChoiceView.ActiveFilterString = String.Format("[ExpiryDate] > #{0}# and [TypeID]={1}",
                                                                      DateTime.Now, (int)lkCategories.EditValue, strStartDate, strEndDate);
            }
        }
Exemplo n.º 13
0
        private void lstTree_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var dtDate = new CalendarLib.DateTimePickerEx
            {
                CustomFormat = "MM/dd/yyyy",
                Value        = DateTime.Now
            };
            DateTime dtCurrent = ConvertDate.DateConverter(dtDate.Text);
            var      dr        = (DataRowView)lstTree.GetDataRecordByNode(lstTree.FocusedNode);

            if (dr == null)
            {
                return;
            }

            var       rec = new ReceiveDoc();
            DataTable dtRec;

            if (dr["ParentID"] == DBNull.Value)
            {
                int      yr  = ((dtCurrent.Month > 10) ? dtCurrent.Year : dtCurrent.Year - 1);
                DateTime dt1 = new DateTime(Convert.ToInt32(dr["ID"]) - 1, 11, 1);
                DateTime dt2 = new DateTime(Convert.ToInt32(dr["ID"]), 11, 1);
                dtRec           = rec.GetTransactionByDateRange(Convert.ToInt32(cboStores.EditValue), dt1, dt2);
                lblRecDate.Text = dr["RefNo"].ToString();
            }
            else
            {
                dtRec           = rec.GetTransactionByRefNo(dr["RefNo"].ToString(), Convert.ToInt32(cboStores.EditValue), dr["Date"].ToString());
                lblRecDate.Text = Convert.ToDateTime(dr["Date"]).ToString("MM dd,yyyy");
            }

            gridReceives.DataSource = dtRec;
        }
Exemplo n.º 14
0
        private void PopulateListToGrid()
        {
            _dtRecGrid = new DataTable();
            var itm = new Items();
            var rec = new ReceiveDoc();

            _tabPage = 1;
            tabControl1.SelectedTabPageIndex = 1;
            if (_dtRecGrid.Columns.Count == 0)
            {
                string[] str = { "ID", "Stock Code", "Item Name", "Batch No", "Unit", "BU Qty", "Price", "Qty To Transfer", "RecID", "UnitID" };
                foreach (string col in str)
                {
                    _dtRecGrid.Columns.Add(col);
                }
            }
            int count = 1;

            foreach (DataRow dr in _dtSelectedTable.Rows)
            {
                rec.LoadByPrimaryKey(Convert.ToInt32(dr["ReceiveID"]));

                int    id    = Convert.ToInt32(dr["ItemID"]);
                double price = 0;
                if (!rec.IsColumnNull("Cost"))
                {
                    price = (rec.RowCount > 0) ? Convert.ToDouble(rec.Cost) * rec.QuantityLeft : 0;
                }
                DataTable dtItm    = itm.GetItemById(id);
                string    itemName = dtItm.Rows[0]["FullItemName"].ToString();
                object[]  obj;
                switch (VisibilitySetting.HandleUnits)
                {
                case 1:
                    obj = new object[]
                    {
                        id, dtItm.Rows[0]["StockCode"].ToString(), itemName, rec.BatchNo, dtItm.Rows[0]["Unit"].ToString(), rec.QuantityLeft, price, "", Convert.ToInt32(dr["ReceiveID"]), 0
                    };
                    break;

                case 2:
                    obj = new object[]
                    {
                        id, dtItm.Rows[0]["StockCode"].ToString(), itemName, rec.BatchNo, dtItm.Rows[0]["Unit"].ToString(), rec.QuantityLeft, price, "", Convert.ToInt32(dr["ReceiveID"]), rec.UnitID
                    };
                    break;

                default:
                    obj = new object[]
                    {
                        id, dtItm.Rows[0]["StockCode"].ToString(), itemName, rec.BatchNo, dtItm.Rows[0]["Unit"].ToString(), rec.QuantityLeft, price, "", Convert.ToInt32(dr["ReceiveID"]), rec.UnitID
                    };
                    break;
                }
                _dtRecGrid.Rows.Add(obj);
                count++;
            }
            receivingGrid.DataSource = _dtRecGrid;
            txtTranferFrom.Text      = lkFromStore.Text;
        }
Exemplo n.º 15
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     BLL.ReceiveDoc recDoc = new ReceiveDoc();
     recDoc.LoadByReceiptID(ReceiptID);
     if (PONumber.StartsWith("S2S-"))
     {
         if (SetFinalCost())
         {
             recDoc.ConfirmGRVPrinted(CurrentContext.UserId);
             BLL.Receipt receiptStatus = new BLL.Receipt();
             receiptStatus.LoadByPrimaryKey(ReceiptID);
             receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.GRV_PRINTED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Store To Store Confirmed");
         }
     }
     else
     {
         recDoc.ConfirmPrice(CurrentContext.UserId);
         BLL.Receipt receiptStatus = new BLL.Receipt();
         receiptStatus.LoadByPrimaryKey(ReceiptID);
         receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.PRICE_CONFIRMED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Price Confirmed");
     }
     this.LogActivity("Confirm-Price", ReceiptID);
     XtraMessageBox.Show("Received Cost and Margin Set successfully!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
     PutAwayListsLoad(null, null);
 }
Exemplo n.º 16
0
        private void ReturnToStoreForQuantityEdit()
        {
            //TODO: finish updating the changed locations
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            transaction.BeginTransaction();
            try
            {
                PalletLocation pl        = new PalletLocation();
                String         reference = gridReceiveView.GetFocusedDataRow()["RefNo"].ToString();

                int ReceiptID = Convert.ToInt32(gridReceiveView.GetFocusedDataRow()["ReceiptID"]);

                if (gridDetailView.DataSource == null)
                {
                    return;
                }

                BLL.ReceiveDoc recDoc = new ReceiveDoc();
                recDoc.LoadByReceiptID(ReceiptID);
                recDoc.SetStatusAsDraft(CurrentContext.UserId);

                BLL.Receipt receiptStatus = new BLL.Receipt();
                receiptStatus.LoadByPrimaryKey(ReceiptID);
                receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.DRAFT_RECEIPT, null, this.GetFormIdentifier(), CurrentContext.UserId, "Returned To Draft");

                transaction.CommitTransaction();
                XtraMessageBox.Show("Receipt Returned!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                BindFormContents();
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSetNewPrice_Click(object sender, EventArgs e)
        {
            bool       validated = false;
            ReceiveDoc rd        = new ReceiveDoc();

            validated = dxValidationProviderPrice.Validate();


            if (!validated)
            {
                XtraMessageBox.Show("Please fill in all required fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!isConfirmation)
            {
                if (XtraMessageBox.Show("Are u sure, you want to save the new price change?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    MyGeneration.dOOdads.TransactionMgr transactionMgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                    transactionMgr.BeginTransaction();
                    try
                    {
                        rs.NewUnitCost     = Convert.ToDouble(txtAverageCost.EditValue);
                        rs.Margin          = Convert.ToDouble(txtMargin.EditValue);
                        rs.NewSellingPrice = Convert.ToDouble(txtSellingPrice.EditValue);
                        rs.NewPrice        = rs.NewSellingPrice;
                        //rs.Remark = txtRemark.EditValue.ToString();
                        // set the item as  weighted average item
                        Item itm = new Item();
                        itm.LoadByPrimaryKey(rs.ItemID);
                        itm.IsFree = false;

                        itm.Save();

                        rd.SavePrice(rs, CurrentContext.UserId);

                        transactionMgr.CommitTransaction();
                        XtraMessageBox.Show("Price setting successful", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        transactionMgr.RollbackTransaction();
                        XtraMessageBox.Show("Price setting failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw ex;
                    }
                }
            }
            else
            {
                if (XtraMessageBox.Show("Are you sure you want to approve the new price change.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    rd.ConfirmMovingAverage(rs, CurrentContext.UserId);
                    XtraMessageBox.Show("Price setting successful", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            ResetForm();
        }
 private void btnConfirm_Click(object sender, EventArgs e)
 {
     foreach (DataRowView Cursor in ReceiveDocDetails.AsDataView())
     {
         int ID = Convert.ToInt32(Cursor["ID"]);
         ReceiveDoc.SetPricePerPackByReceiveDoc(ID, NewPricePerPack, CurrentContext.UserId);
     }
     this.Close();
 }
        private void BindDetails(DataRow dr)
        {
            // txtAdditionalCost.EditValue = 0;
            //txtMargin.EditValue = 100;
            try
            {
                Convert.ToInt16(dr["ItemID"]);
            }
            catch
            {
                ResetForm();
                return;
            }

            if (dr != null)
            {
                costElement = new CostElement(Convert.ToInt32(dr["ItemID"]), Convert.ToInt32(lkAccount.EditValue), Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["UnitID"]));

                //ToDo Remove ReceivedSummary ItemId and Stuff with CostElement
                rs = new ReceivedSummary();
                ReceiveDoc rd = new ReceiveDoc();
                rs.ItemID         = Convert.ToInt32(dr["ItemID"]);
                rs.SupplierID     = Convert.ToInt32(dr["SupplierID"]);
                rs.ManufacturerID = Convert.ToInt32(dr["ManufacturerID"]);
                rs.UnitID         = null;
                if (dr["UnitID"] != DBNull.Value)
                {
                    rs.UnitID = Convert.ToInt32(dr["UnitID"]);
                }
                rs.StoreID = Convert.ToInt32(lkAccount.EditValue);

                // TODO: fix this ( Remove ) try cache
                try
                {
                    txtUnit.Text = dr["Unit"].ToString();
                }
                catch
                {
                }

                txtItemName.Text     = dr["FullItemName"].ToString();
                txtManufacturer.Text = dr["Manufacturer"].ToString();

                rd.LoadForPricing(rs.ItemID, rs.SupplierID, rs.StoreID, rs.ManufacturerID, rs.UnitID);
                gridAllSimilarItems.DataSource = rd.DefaultView;



                LoadDecimalFormatings();

                rs.MovingAverageTable(rs.ItemID, rs.StoreID, rs.SupplierID, rs.ManufacturerID, rs.UnitID);
                txtAverageCost.EditValue  = rs.NewUnitCost;
                txtMargin.EditValue       = rs.Margin;
                txtSellingPrice.EditValue = rs.NewSellingPrice;
            }
        }
        private void btnReturn_Click(object sender, EventArgs e)
        {
            var recDoc = new ReceiveDoc();

            recDoc.LoadByReceiptID(receipt.ID);
            recDoc.ConfirmGRNFPrinted(CurrentContext.UserId);
            receipt.ChangeStatus(ReceiptConfirmationStatus.Constants.GRNF_PRINTED, null,
                                 this.GetFormIdentifier(), CurrentContext.UserId, "Price Set");
            MessageBox.Show("The Correction has been return to Pricing", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private HCMIS.Desktop.Reports.ReceiptConfirmationShortagePrintout PrintReceiptConfirmationForShortage(string reference, int printedID)
        {
            HCMIS.Desktop.Reports.ReceiptConfirmationShortagePrintout printout = new HCMIS.Desktop.Reports.ReceiptConfirmationShortagePrintout();
            ReceiptConfirmationPrintout rc = new ReceiptConfirmationPrintout();

            BLL.ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.LoadByReceiptID(ReceiptID);
            rc.PrepareDataForPrintout(ReceiptID, CurrentContext.UserId, true, 2, printedID, null, FiscalYear.Current);
            printout.DataSource = rc.DefaultView.ToTable();
            return(printout);
        }
Exemplo n.º 22
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string valid = ValidateFields();

            if (valid == "true")
            {
                if (XtraMessageBox.Show("Are You Sure, You want to save this Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    IssueDoc   iss = new IssueDoc();
                    ReceiveDoc rec = new ReceiveDoc();

                    iss.LoadByPrimaryKey(_tranId);

                    string batchNo = iss.BatchNo;
                    Int64  qty     = iss.Quantity;
                    rec.GetTransactionByBatch(iss.ItemID, iss.BatchNo, iss.StoreId);

                    iss.RefNo           = txtRefNo.Text;
                    iss.BatchNo         = txtBatchNo.Text;
                    iss.NoOfPack        = Convert.ToInt32(txtPack.Text);
                    iss.QtyPerPack      = Convert.ToInt32(txtQtyPack.Text);
                    iss.Quantity        = Convert.ToInt32(txtPack.Text) * Convert.ToInt32(txtQtyPack.Text);
                    iss.StoreId         = Convert.ToInt32(cboStores.SelectedValue);
                    iss.ReceivingUnitID = Convert.ToInt32(cboReceivingUnit.SelectedValue);
                    iss.Remark          = txtRemark.Text;
                    iss.IssuedBy        = txtReceivedBy.Text;
                    iss.Save();

                    Int64 newQty = 0;
                    if (qty > iss.Quantity)
                    {
                        newQty = rec.QuantityLeft + (qty - iss.Quantity);
                    }
                    else
                    {
                        newQty = rec.QuantityLeft - (iss.Quantity - qty);
                    }

                    rec.QuantityLeft = newQty;
                    if (rec.QuantityLeft > 0)
                    {
                        rec.Out = false;
                    }
                    rec.Save();

                    XtraMessageBox.Show("Transaction Succsfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
        private void ReturnToStoreForQuantityEdit()
        {
            //TODO: finish updating the changed locations
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            transaction.BeginTransaction();
            try
            {
                PalletLocation pl        = new PalletLocation();
                String         reference = gridReceiveView.GetFocusedDataRow()["RefNo"].ToString();
                //           pl.ConfirmAllReceived(reference);
                if (gridDetailView.DataSource == null)
                {
                    return;
                }

                foreach (DataRowView drv in gridDetailView.DataSource as DataView)
                {
                    int PalletLocationID         = Convert.ToInt32(drv["PalletLocationID"]);
                    int ProposedPalletLocationID = Convert.ToInt32(drv["ProposedPalletLocationID"]);
                    int PalletID  = Convert.ToInt32(drv["PalletID"]);
                    int receiveID = Convert.ToInt32(drv["ReceiveID"]);

                    if (PalletLocationID != ProposedPalletLocationID)
                    {
                        pl.LoadByPrimaryKey(PalletLocationID);
                        if (pl.IsColumnNull("PalletID"))
                        {
                            pl.Confirmed = false;
                            pl.Save();
                        }
                    }
                    else
                    {
                        pl.LoadByPrimaryKey(PalletLocationID);
                        pl.Confirmed = false;
                        pl.Save();
                    }
                }



                BLL.ReceiveDoc recDoc = new ReceiveDoc();
                recDoc.LoadByReferenceNo(reference);
                recDoc.SetStatusAsReceived(null);
                transaction.CommitTransaction();
                XtraMessageBox.Show("Receipt Returned!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                BindFormContents();
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 24
0
        private void GenerateStockStatusPieChart()
        {
            ReceiveDoc rec = new ReceiveDoc();

            progressBar1.Visible   = true;
            chartPie.UseWaitCursor = true;
            chartPie.Series.Clear();
            int storeId = (cboStores.SelectedValue != null) ? Convert.ToInt32(cboStores.SelectedValue) : 0;

            int neverRec = rec.CountNeverReceivedItems(storeId);

            curYear = Convert.ToInt32(cboYear.SelectedItem);
            curMont = (curYear == dtCurrent.Year) ? dtCurrent.Month : 12;
            progressBar1.PerformStep();



            DataTable dtList = new DataTable();

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

            //TODO: the pie has to display something doesn't it?

            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;

            progressBar1.PerformStep();

            ((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();


            lblHeader.Text         = GeneralInfo.Current.HospitalName + " Stock Status summary of year " + curYear + " of " + cboStores.Text;
            progressBar1.Visible   = false;
            chartPie.UseWaitCursor = false;
        }
 private void cboSuppliers_SelectedValueChanged(object sender, EventArgs e)
 {
     if (cboSuppliers.EditValue != null)
     {
         ReceiveDoc rec   = new ReceiveDoc();
         DataTable  dtRec = new DataTable();
         dtRec = rec.GetTransactionBySupplierId(Convert.ToInt32(cboStores.EditValue),
                                                Convert.ToInt32(cboSuppliers.EditValue));
         PopulateTransactions(dtRec);
     }
 }
Exemplo n.º 26
0
        private void ReturnFromGRVPrinting()
        {
            BLL.ReceiveDoc receiveDoc = new ReceiveDoc();
            int            ReceiptID  = Convert.ToInt32(gridReceiveView.GetFocusedDataRow()["ReceiptID"]);

            receiveDoc.LoadByReceiptID(ReceiptID);
            receiveDoc.ConfirmGRNFPrinted(null);
            BLL.Receipt receiptStatus = new BLL.Receipt();
            receiptStatus.LoadByPrimaryKey(ReceiptID);
            receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.PRICE_CALCULATED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Return For Price Change");
            BindFormContents();
        }
Exemplo n.º 27
0
        private void LkFromStoreEditValueChanged(object sender, EventArgs e)
        {
            var rDoc = new ReceiveDoc();

            if (lkFromStore.EditValue == null)
            {
                return;
            }
            var dtItem = rDoc.GetRecievedItemsWithBalanceForStore(Convert.ToInt32(lkFromStore.EditValue), (int)lkCategories.EditValue);

            PopulateItemList(dtItem);
        }
Exemplo n.º 28
0
        private void cboSupplier_EditValueChanged(object sender, EventArgs e)
        {
            if (cboSupplier.EditValue == null)
            {
                return;
            }
            var       rec   = new ReceiveDoc();
            DataTable dtRec = rec.GetTransactionBySupplierId(Convert.ToInt32(cboStores.EditValue),
                                                             Convert.ToInt32(cboSupplier.EditValue));

            gridReceives.DataSource = dtRec;
        }
Exemplo n.º 29
0
        private void BindLocationView()
        {
            ReceiveDoc rec  = new ReceiveDoc();
            DataTable  dtbl = rec.GetRecievedItemsWithBalance(_ItemID, _StoreID, _UnitID);

            dtbl.DefaultView.Sort = "ExpiryDate";

            PalletLocation.PopulatePalletLocationFor(dtbl);
            gridView1.ExpandAllGroups();
            gridLocations.DataSource  = dtbl.DefaultView;
            gridSOHSummary.DataSource = dtbl.DefaultView;
        }
        public PickListDetail CreatePicklistDetailWithOrder(ReceiveDoc receiveDoc, ReceivePallet receivePallet, Order order, PickList picklist, decimal pack)
        {
            double? cost = null;
            OrderService orderService = new OrderService();
            orderService.CreateOrderDetail(receiveDoc, order, pack);
            if (!receiveDoc.IsColumnNull("Cost"))
                cost = receiveDoc.Cost;
            PickListDetail pickListDetail = PickListDetail.GeneratePickListDetail(pack, cost, receiveDoc.ID, receiveDoc.ManufacturerId, receivePallet.ID,
                receiveDoc.QtyPerPack, receiveDoc.StoreID, receiveDoc.UnitID, receiveDoc.ItemID, picklist.ID, receivePallet.PalletID, receiveDoc.IsColumnNull("ExpDate")?"":receiveDoc.ExpDate.ToString(),  receiveDoc.IsColumnNull("BatchNo")?"":receiveDoc.BatchNo);
            ReceivePallet.ReserveQty(pack, receivePallet.ID);

            return pickListDetail;
        }
        private void PopulateItemDetails()
        {
            int  itemID = Convert.ToInt32(itemListView.GetFocusedDataRow()["ID"]);
            int  unitID = Convert.ToInt32(itemListView.GetFocusedDataRow()["UnitID"]);
            Item itm    = new Item();

            ReceiveDoc rec  = new ReceiveDoc();
            DataTable  dtbl = rec.GetRecievedItemsWithBalanceExcludeQuaranteen(itemID, unitID, chkShowAllFinished.Checked);

            dtbl.DefaultView.Sort = "ExpiryDate";
            PalletLocation.PopulatePalletLocationFor(dtbl);
            gridItemDetailList.DataSource = dtbl.DefaultView;
        }
Exemplo n.º 32
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            var us     = new User();
            var userID = MainWindow.LoggedinId;

            us.LoadByPrimaryKey(userID);

            var dr = grdLogReceive.GetFocusedDataRow();

            if (dr == null)
            {
                return;
            }

            int tranId = Convert.ToInt32(dr["ID"]);
            var rec    = new ReceiveDoc();

            rec.LoadByPrimaryKey(tranId);
            var iss = new IssueDoc();

            iss.GetIssueByBatchAndId(rec.ItemID, rec.BatchNo, rec.ID);
            _dtDate.CustomFormat = "MM/dd/yyyy";
            DateTime dtCurrent = ConvertDate.DateConverter(_dtDate.Text);

            if ((rec.Date.Year != dtCurrent.Year && rec.Date.Month < 11) || (iss.RowCount != 0))
            {
                XtraMessageBox.Show("Unable to Delete, This Transaction has been processed. Try Loss and Adjustment.",
                                    "Unable to Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            }
            else
            {
                if (
                    XtraMessageBox.Show(
                        "Are You Sure, You want to delete this Transaction? You will not be able to restore this data.",
                        "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    //AddDeletedRecieveDoc(rec);
                    rec.MarkAsDeleted();
                    rec.Save();

                    _dtDate.Value        = DateTime.Now;
                    _dtDate.CustomFormat = "MM/dd/yyyy";
                    dtCurrent            = ConvertDate.DateConverter(_dtDate.Text);
                    int       yr    = ((dtCurrent.Month > 10) ? dtCurrent.Year : dtCurrent.Year - 1);
                    DateTime  dt1   = new DateTime(yr, 11, 1);
                    DateTime  dt2   = new DateTime(dtCurrent.Year, dtCurrent.Month, dtCurrent.Day);
                    DataTable dtRec = rec.GetTransactionByDateRange(Convert.ToInt32(cboStores.EditValue), dt1, dt2);
                    gridReceives.DataSource = dtRec;
                }
            }
        }
        public int CreateTransactionForErrorCorrection(DataView dataView, int newItemId, int newUnitId, int newManufacturerId, decimal ConversionFactor, string Remark, DateTime convertedEthDate, int userId, bool changeExpiryDate = false, DateTime? ExpiryDate = null, bool changeBatchNo = false, string batchNo = null)
        {
            //Last Validation
            if (dataView.Count == 0)
            {
                throw new Exception("DataView is empty, the Error correction cannot be commited");
            }
            //User Information
            User user = new User();
            user.LoadByPrimaryKey(userId);

            var stvLog = new Issue();
            Order order;
            PickList picklist;

            //The First ReceiveDoc entry on the It Holds enough Informa
            var firstReceiveDoc = new ReceiveDoc();
            firstReceiveDoc.LoadByPrimaryKey(Convert.ToInt32(dataView[0]["ReceiveDocID"]));
            int activityId = firstReceiveDoc.StoreID;

            stvLog = HandleTransferBeforeReceipt(user,activityId, out order, out picklist);

            var listOfWarehouse = new List<int>();
            foreach (DataRow rw in dataView.Table.Rows)
            {
                if (!listOfWarehouse.Contains(Convert.ToInt32(rw["WearehouseID"])))
                {
                    listOfWarehouse.Add(Convert.ToInt32(rw["WearehouseID"]));
                }
            }

            foreach (var wearehouse in listOfWarehouse)
            {
                dataView.RowFilter = String.Format("WearehouseID = {0}", wearehouse);
                DataView singleWearehouseDataView = dataView;
                HandleTransferForSingleWearehouse(wearehouse,singleWearehouseDataView, newItemId, newUnitId, newManufacturerId, ConversionFactor, Remark, convertedEthDate, user, changeExpiryDate, ExpiryDate, changeBatchNo, batchNo,activityId,stvLog,order,picklist);
                dataView.RowFilter = string.Empty;
            }

            return stvLog.IDPrinted;
        }
        public void CloneReceiveForErrorCorrection(int confirmationStatusID, ReceivePallet receivePallet, ReceiveDoc receiveDoc, decimal pack, User user, int itemId, int storeId, int receiptId, int manufacturerId, ItemUnit itemUnit, DateTime convertedEthDate, bool changeExpiryDate = false, DateTime? ExpiryDate = null, bool changeBatchNo = false, string batchNo = null)
        {
            var newReceiveDoc = receiveDoc.Clone();

            newReceiveDoc.ItemID = itemId;

            if (changeBatchNo)
            {
                newReceiveDoc.BatchNo = batchNo;
            }

            if (changeExpiryDate)
            {
                if (ExpiryDate.HasValue)
                {
                    newReceiveDoc.ExpDate = ExpiryDate.Value;
                }
                else
                {
                    newReceiveDoc.SetColumnNull("ExpDate");
                }
            }

            newReceiveDoc.ManufacturerId = manufacturerId;
            newReceiveDoc.SetColumn("UnitID", itemUnit.ID);
            newReceiveDoc.Quantity = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.QuantityLeft = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.NoOfPack = pack;
            newReceiveDoc.InvoicedNoOfPack = pack;
            newReceiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            newReceiveDoc.Date = convertedEthDate;
            newReceiveDoc.ReceivedBy = user.UserName;
            newReceiveDoc.StoreID = storeId;
            newReceiveDoc.RefNo = receiptId.ToString();
            newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            newReceiveDoc.Confirmed = true;
            newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            newReceiveDoc.ReturnedStock = false;
            newReceiveDoc.ReceiptID = receiptId;

            newReceiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = newReceiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = confirmationStatusID;
            rdConf.Save();

            ReceivePallet newReceivePallet = new ReceivePallet();
            newReceivePallet.AddNew();
            newReceivePallet.ReceiveID = newReceiveDoc.ID;
            newReceivePallet.ReceivedQuantity = pack * itemUnit.QtyPerUnit;
            newReceivePallet.Balance = pack * itemUnit.QtyPerUnit;
            newReceivePallet.ReservedStock = 0;
            newReceivePallet.BoxSize = 0;
            newReceivePallet.PalletID = receivePallet.PalletID;
            newReceivePallet.IsOriginalReceive = true;
            if (!receivePallet.IsColumnNull("PalletLocationID"))
            {
                newReceivePallet.PalletLocationID = receivePallet.PalletLocationID;
            }
            newReceivePallet.Save();
        }
        public IssueDoc CreateIssueFromPicklist(PickListDetail picklistDetail,Order order,DateTime convertedEthDate,Issue stvLog,User user)
        {
            ReceivePallet receivePallet = new ReceivePallet();
            receivePallet.LoadByPrimaryKey(picklistDetail.ReceivePalletID);

            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.LoadByPrimaryKey(receivePallet.ReceiveID);

            IssueDoc issueDoc = new IssueDoc();
            issueDoc.AddNew();
            issueDoc.BatchNo = picklistDetail.BatchNumber;
            if(!picklistDetail.IsColumnNull("Cost"))
            issueDoc.Cost = picklistDetail.Cost;
            issueDoc.Date = convertedEthDate;
            issueDoc.EurDate = DateTimeHelper.ServerDateTime;
            issueDoc.StoreId = picklistDetail.StoreID;
            issueDoc.STVID = stvLog.ID;
            issueDoc.IsTransfer = true;
            issueDoc.IssuedBy = user.FullName;
            issueDoc.ItemID = picklistDetail.ItemID;
            issueDoc.NoOfPack = picklistDetail.Packs;
            issueDoc.QtyPerPack = picklistDetail.QtyPerPack;
            issueDoc.Quantity = picklistDetail.QuantityInBU;
            issueDoc.OrderID = order.ID;
            issueDoc.UnitID = receiveDoc.UnitID;
            issueDoc.ManufacturerID = receiveDoc.ManufacturerId;
            issueDoc.SetColumn("UnitCost" ,receiveDoc.GetColumn("Cost"));
            issueDoc.SetColumn("SellingPrice"  ,receiveDoc.GetColumn("SellingPrice"));
            issueDoc.SetColumn("Margin", receiveDoc.GetColumn("Margin"));
            issueDoc.SetColumn("PhysicalStoreID", receiveDoc.GetColumn("PhysicalStoreID"));
            issueDoc.PLDetailID = picklistDetail.ID;
            issueDoc.RecievDocID = picklistDetail.ReceiveDocID;
            issueDoc.SetColumn("InventoryPeriodID", receiveDoc.GetColumn("InventoryPeriodID"));
            // This is a deprecated field
            issueDoc.RecomendedQty = 0;// picklistDetail.Packs;
            issueDoc.RefNo = stvLog.IDPrinted.ToString();
            issueDoc.DispatchConfirmed = false;
            issueDoc.Save();

            //substract from QuantityLeft
            receiveDoc.QuantityLeft -= picklistDetail.QuantityInBU;
            if(receiveDoc.QuantityLeft < 0)
            {
                receiveDoc.QuantityLeft = 0;
            }
            receiveDoc.Save();

            receivePallet.Balance -= picklistDetail.QuantityInBU;
            if(receivePallet.Balance < 0)
            {
                receivePallet.Balance=0;
            }

            receivePallet.ReservedStock -= picklistDetail.Packs;
            if(receivePallet.ReservedStock < 0)
            {
                receivePallet.ReservedStock = 0;
            }
            receivePallet.Save();

            return issueDoc;
        }
        /// <summary>
        /// Saves the whole transaction for
        /// </summary>
        /// <param name="orderID">The order ID.</param>
        /// <param name="dvOutstandingPickList">The dv outstanding pick list.</param>
        /// <param name="remark">The remark.</param>
        /// <param name="issuedBy">The issued by.</param>
        /// <param name="etCurrentDate">The et current date.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public static Order SaveIssueTransaction(int orderID, ref DataView dvOutstandingPickList, string remark, string issuedBy, DateTime etCurrentDate)
        {
            // Add the IssueDocID field
            dvOutstandingPickList.Table.Columns.Add("IssueDocID");
            PickList plst = new PickList();
            IssueDoc issDoc = new IssueDoc();
            ReceiveDoc recDoc = new ReceiveDoc();
            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(orderID);
            plst.LoadByOrderID(ord.ID);

            foreach (DataRowView drv in dvOutstandingPickList)
            {
                // Pseudo:
                // for each row in the picklist
                // undate the issue document
                // subtract the issued quantity from the receive doc
                // subtract the issued quantity from recieve pallet
                // subtract the issued the reserved quantity irregardless of the quantity issued.

                //Saving the new Issue issue
                if (Convert.ToDecimal(drv["BUPICKED"]) == 0)
                {
                    continue;

                }

                if (Convert.ToDecimal(drv["SKUPicked"]) != Convert.ToDecimal(drv["SKUTOPICK"]))
                {
                    drv["Cost"] = Convert.ToDecimal(drv["SKUPicked"]) * Convert.ToDecimal(drv["UnitPrice"]);
                }

                // Select the receive doc that is associated with this issue.
                recDoc.LoadByPrimaryKey(Convert.ToInt32(drv["ReceiveDocID"]));

                issDoc.AddNew();
                issDoc.StoreId = Convert.ToInt32(drv["StoreID"]);
                issDoc.RefNo = ord.RefNo;
                if (!ord.IsColumnNull("RequestedBy"))
                    issDoc.ReceivingUnitID = ord.RequestedBy;
                // TOFIX:
                // TODO:
                // Lord have mercy kind of hack to avoid the feb date problem
                // this needs to be fixed for pagume also
                issDoc.Date = etCurrentDate;
                issDoc.EurDate = DateTimeHelper.ServerDateTime;
                issDoc.RecievDocID = Convert.ToInt32(drv["ReceiveDocID"]);
                issDoc.IsApproved = true;
                issDoc.IsTransfer = false;
                issDoc.Remark = remark;
                issDoc.ItemID = Convert.ToInt32(drv["ItemID"]);
                issDoc.Quantity = Convert.ToDecimal(drv["BUPICKED"]);
                issDoc.NoOfPack = Convert.ToDecimal(drv["SKUPICKED"]);
                issDoc.QtyPerPack = Convert.ToInt32(drv["SKUBU"]);
                issDoc.BatchNo = drv["BatchNumber"].ToString();
                issDoc.UnitID = recDoc.UnitID;
                issDoc.ManufacturerID = recDoc.ManufacturerId;
                if (drv["Cost"] != DBNull.Value)
                {
                    issDoc.Cost = Convert.ToDouble(drv["Cost"]);

                    issDoc.SellingPrice = Convert.ToDecimal(drv["UnitPrice"]);
                    if (!recDoc.IsColumnNull("Cost"))
                    {
                        issDoc.UnitCost = Convert.ToDecimal(recDoc.Cost);
                    }
                }
                issDoc.OrderID = orderID;
                issDoc.IssuedBy = issuedBy;
                // TODO: is this the right place where we need to pick the physical store ID from?
                // check it against the receipt pallet physical store.
                if (!recDoc.IsColumnNull("PhysicalStoreID"))
                {
                    issDoc.PhysicalStoreID = recDoc.PhysicalStoreID;
                }
                if (!recDoc.IsColumnNull("InventoryPeriodID"))
                {
                    //Todo: Remove for Inventory
                    issDoc.InventoryPeriodID = recDoc.InventoryPeriodID;
                }
                if (!recDoc.IsColumnNull("Margin"))
                {
                    issDoc.Margin = (decimal)recDoc.Margin;
                }
                //Replaced by
                issDoc.PLDetailID = Convert.ToInt32(drv["PLDetailID"]);
                BLL.Balance bal = new Balance();
                BLL.ReceiveDoc rd = new ReceiveDoc();
                rd.LoadByPrimaryKey(issDoc.RecievDocID);
                decimal currentBalance = bal.GetSoh(issDoc.ItemID, rd.UnitID, issDoc.StoreId, issDoc.Date.Month, issDoc.Date.Year);
                if (currentBalance < issDoc.NoOfPack)
                {
                    throw new Exception(string.Format("The item {0} is not available in {1} Qty.", drv["FullItemName"].ToString(), issDoc.NoOfPack));
                }

                // This is a field that is not applicable on the hub edition
                // It is about the dispensing unit quantity and there is no such thing as Dispensing unit
                // in the hub edition
                issDoc.DUSOH = 0;
                issDoc.RecomendedQty = 0;// ((recQty > 0) ? Convert.ToInt64(recQty) : 0);
                // End DU
                issDoc.DispatchConfirmed = false;
                issDoc.Save();
                drv["IssueDocID"] = issDoc.ID;
                // updating the receiving doc

                //long prevQuantityLeft = recDoc.QuantityLeft;

                recDoc.QuantityLeft = recDoc.QuantityLeft - issDoc.Quantity;

                if (recDoc.QuantityLeft < 0)
                {
                    //Possibly the wrong ReceiveDoc Entry chosen
                    BLL.Item itm = new Item();
                    itm.LoadByPrimaryKey(recDoc.ItemID);
                    throw new Exception(string.Format("Quantity problem detected for the item {0}", itm.FullItemName));
                }
                //long
                recDoc.Out = (recDoc.QuantityLeft == 0) ? true : false;
                recDoc.Save();

                ReceivePallet rp = new ReceivePallet();
                int id = Convert.ToInt32(drv["ReceivePalletID"]);
                rp.LoadByPrimaryKey(id);
                if (rp.IsColumnNull("Balance"))
                {
                    rp.Balance = rp.ReceivedQuantity;
                }
                rp.Balance -= issDoc.Quantity;

                if (rp.Balance < 0)
                {
                    BLL.Item itm = new Item();
                    itm.LoadByPrimaryKey(recDoc.ItemID);
                    throw new Exception(string.Format("Quantity problem detected for the item {0}", itm.FullItemName));
                }

                decimal totReservedQty = Convert.ToDecimal(drv["QuantityInBU"]);

                if (rp.IsColumnNull("ReservedStock"))
                    rp.ReservedStock = 0;

                rp.ReservedStock -= totReservedQty;
                if (rp.ReservedStock < 0) //If there has been a quantity problem somewhere
                    rp.ReservedStock = 0;
                rp.Save();
            }
            plst.IsConfirmed = true;
            ord.ChangeStatus(OrderStatus.Constant.ISSUED, CurrentContext.UserId);
            plst.Save();
            ord.Save();
            return ord;
        }
 public PickListDetail GeneratePickListDetail(ReceiveDoc rd, ReceivePallet rp, Order o, PickList pl)
 {
     PickListService pickListService = new PickListService ();
     return pickListService.CreatePicklistDetailWithOrder(rd, rp, o, pl);
 }
        public ReceiveDoc CreateInventoryReceive(Inventory inventory,int receiptID,Inventory.QuantityType quantityType,DateTime ethiopianDate,User user)
        {
            ItemUnit itemUnit = new ItemUnit();
            itemUnit.LoadByPrimaryKey(inventory.UnitID);

            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.AddNew();
            receiveDoc.ItemID = inventory.ItemID;
            receiveDoc.UnitID = inventory.UnitID;
            receiveDoc.ManufacturerId = inventory.ManufacturerID;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.Date = ethiopianDate;
            receiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            receiveDoc.PhysicalStoreID = inventory.PhysicalStoreID;
            receiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo"));
            decimal quantity = quantityType == Inventory.QuantityType.Sound
                                   ? inventory.InventorySoundQuantity
                                   : quantityType == Inventory.QuantityType.Damaged
                                    ? inventory.InventoryDamagedQuantity :inventory.InventoryExpiredQuantity;

            if(quantityType == Inventory.QuantityType.Damaged) receiveDoc.ShortageReasonID = ShortageReasons.Constants.DAMAGED;
            receiveDoc.Quantity = receiveDoc.QuantityLeft = quantity * itemUnit.QtyPerUnit;
            receiveDoc.NoOfPack = receiveDoc.InvoicedNoOfPack = quantity;
            receiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            receiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate"));

            receiveDoc.Out = false;

            receiveDoc.ReceivedBy = user.UserName;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.RefNo = "BeginningBalance";
            decimal cost = 0;
            decimal margin = 0;

            if (!inventory.IsColumnNull("Cost"))
            {
                cost = inventory.Cost;
            }

            if(!inventory.IsColumnNull("Margin"))
            {
                margin = inventory.Margin;
            }

            receiveDoc.Cost = Convert.ToDouble(cost);
            receiveDoc.PricePerPack = Convert.ToDouble(cost);
            receiveDoc.UnitCost = cost;
            receiveDoc.Margin = Convert.ToDouble(margin);
            receiveDoc.SellingPrice = Convert.ToDouble(BLL.Settings.IsCenter ? cost : cost * (1 + margin));
            receiveDoc.SupplierID = 2; //TODO: HARDCODE WARNING WARNING WARNING
            receiveDoc.DeliveryNote = false;
            receiveDoc.Confirmed = true;
            receiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            receiveDoc.ReturnedStock = false;
            receiveDoc.ReceiptID = receiptID;
            receiveDoc.RefNo = "BeginningBalance";
            receiveDoc.InventoryPeriodID = inventory.InventoryPeriodID;
            receiveDoc.IsDamaged = (quantityType == Inventory.QuantityType.Damaged ||
                                   quantityType == Inventory.QuantityType.Expired);
            receiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = receiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED;
            rdConf.Save();

            //TODO: Create Receive Pallet Here
            PalletLocation palletLocation = new PalletLocation();

            palletLocation.LoadByPrimaryKey(quantityType != Inventory.QuantityType.Damaged
                                                ? inventory.PalletLocationID
                                                : inventory.DamagedPalletLocationID);

            ReceivePallet receivePallet = new ReceivePallet();
            receivePallet.AddNew();
            receivePallet.Balance = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReceivedQuantity = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReservedStock = 0;
            receivePallet.ReceiveID = receiveDoc.ID;

            if(palletLocation.IsColumnNull("PalletID"))
            {
                Pallet pallet = new Pallet();
                pallet.AddNew();
                pallet.Save();
                palletLocation.PalletID = pallet.ID;
                palletLocation.Save();
            }

            receivePallet.PalletID = palletLocation.PalletID;
            receivePallet.PalletLocationID =palletLocation.ID;
            receivePallet.BoxSize = 0;
            receivePallet.IsOriginalReceive = true;
            receivePallet.Save();

            return receiveDoc;
        }
        private ReceiveDoc CreateReceiveDocForInventory(Inventory inventory, int confirmationStatusID, decimal foundQty, int receiptID, DateTime convertedEthDate, User user,string remark)
        {
            ReceiveDoc newReceiveDoc = new ReceiveDoc();
            newReceiveDoc.AddNew();

            newReceiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo"));
            newReceiveDoc.ItemID = inventory.ItemID;
            newReceiveDoc.ManufacturerId = inventory.ManufacturerID;
            newReceiveDoc.SetColumn("UnitID", inventory.UnitID);
            if (!inventory.IsColumnNull("SupplierID"))
                newReceiveDoc.SupplierID = inventory.SupplierID;
            BLL.ItemUnit iu = new ItemUnit();
            iu.LoadByPrimaryKey(inventory.UnitID);
            newReceiveDoc.Quantity = newReceiveDoc.QuantityLeft = foundQty*iu.QtyPerUnit;
            newReceiveDoc.NoOfPack = foundQty;
            newReceiveDoc.InvoicedNoOfPack = foundQty;
            newReceiveDoc.QtyPerPack = iu.QtyPerUnit;
            newReceiveDoc.Date = convertedEthDate;
            newReceiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate"));
            newReceiveDoc.Out = false;
            newReceiveDoc.ReceivedBy = user.UserName;
            newReceiveDoc.StoreID = inventory.ActivityID;
            newReceiveDoc.SetColumn("LocalBatchNo", inventory.GetColumn("BatchNo"));
            newReceiveDoc.RefNo = receiptID.ToString();
            newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("IsApproved", DBNull.Value);
            newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            newReceiveDoc.SetColumn("SellingPrice", inventory.GetColumn("SellingPrice"));
            newReceiveDoc.SetColumn("UnitCost", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("PricePerPack", inventory.GetColumn("Cost"));
            newReceiveDoc.SetColumn("DeliveryNote", DBNull.Value);
            newReceiveDoc.Confirmed = true;
            newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            newReceiveDoc.ReturnedStock = false;
            newReceiveDoc.ReceiptID = receiptID;
            newReceiveDoc.SetColumn("Margin", inventory.GetColumn("Margin"));
            newReceiveDoc.RefNo = "BeginningBalance";
            if(!string.IsNullOrEmpty(remark))
            newReceiveDoc.IsDamaged = false;
            if (!string.IsNullOrEmpty(remark))
            {
                newReceiveDoc.Remark = remark;
            }
            newReceiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = newReceiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = confirmationStatusID;
            rdConf.Save();

            return newReceiveDoc;
        }
 public void CreateOrderDetail(ReceiveDoc receiveDoc, Order order, decimal pack)
 {
     OrderDetail.GenerateOrderDetail(receiveDoc.UnitID, receiveDoc.StoreID, pack,order.ID, receiveDoc.QtyPerPack,
                                     receiveDoc.ItemID);
 }