private void btnMovingAverage_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            var dialogResult =
                XtraMessageBox.Show(
                    String.Format("Are you Sure you want to Set the  Price for {0}", txtItemName.Text),
                    "Are you sure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    transaction.BeginTransaction();
                    // This is where we set the Price
                    JournalService journalService = new JournalService();
                    journalService.StartRecordingSession();
                    costElement.SavePrice(CurrentContext.UserId, "", journalService, ChangeMode.BeginningBalance);
                    journalService.CommitRecordingSession();
                    journalService.StartRecordingSession();
                    costElement.ConfirmPrice(CurrentContext.UserId, "", journalService, ChangeMode.BeginningBalance);
                    journalService.CommitRecordingSession();
                    ReceiveDoc receiveDoc = new ReceiveDoc();
                    receiveDoc.SavePrice(costElement, CurrentContext.UserId);

                    ReceiveDocConfirmation receiveDocConfirmation = new ReceiveDocConfirmation();
                    receiveDocConfirmation.ChangeStatusByAccountReceiveDocs(receiveDocs, ReceiptConfirmationStatus.Constants.GRV_PRINTED, ReceiptConfirmationStatus.Constants.PRICE_CALCULATED);
                    transaction.CommitTransaction();
                    this.Close();
                }
                catch (Exception exception)
                {
                    transaction.RollbackTransaction();
                    XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    throw exception;
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            var dt = grdDetailView.DataSource as DataView;

            if ((dt) != null)
            {
                // This is where we set the Price

                foreach (DataRow dr in dt.Table.Rows)
                {
                    var costElement = new CostElement();
                    costElement.LoadFromDataRow(dr, receipt.ID);
                    costElement.AverageCost = Math.Round(Convert.ToDouble(dr["AverageCost"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint, MidpointRounding.AwayFromZero);
                    costElement.Margin      = Convert.ToDouble(dr["Margin"]);

                    costElement.SellingPrice = Math.Round(Convert.ToDouble(dr["SellingPrice"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint, MidpointRounding.AwayFromZero);
                    try
                    {
                        transaction.BeginTransaction();
                        var journalService = new JournalService();
                        journalService.StartRecordingSession();
                        costElement.SetPriceForReceiveDocs();
                        costElement.SavePrice(CurrentContext.UserId, costElement.ReceiptID.ToString(), journalService,
                                              ChangeMode.ErrorCorrection);
                        journalService.CommitRecordingSession();
                        transaction.CommitTransaction();
                    }
                    catch (Exception exception)
                    {
                        transaction.RollbackTransaction();
                        XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        throw exception;
                    }
                    var report = new PriceOverridePrintout
                    {
                        xrCostedBy = { Text = CurrentContext.LoggedInUserName },
                        lblDate    = { Text = DateTimeHelper.ServerDateTime.ToString() },
                        DataSource = getPriceChangeReport(costElement)
                    };
                    report.ShowPreviewDialog();
                }
                var recDoc = new ReceiveDoc();
                recDoc.LoadByReceiptID(receipt.ID);
                recDoc.SetPrice(CurrentContext.UserId);
                receipt.ChangeStatus(ReceiptConfirmationStatus.Constants.PRICE_CALCULATED, null,
                                     this.GetFormIdentifier(), CurrentContext.UserId, "Price Set");
            }
        }
        public static void ConfirmPriceChange(IEnumerable <CostElement> costElements, int userId, ChangeType changeType, string identifier = "")
        {
            var journalService = new JournalService();

            journalService.StartRecordingSession();

            foreach (var costElement in costElements)
            {
                journalService.Confirm(identifier, costElement.ItemID, costElement.ItemUnitID,
                                       costElement.ManufacturerID, costElement.MovingAverageID,
                                       Convert.ToDecimal(costElement.AverageCost),
                                       Convert.ToDecimal(costElement.Margin),
                                       Convert.ToDecimal(costElement.SellingPrice), userId, changeType);
            }

            journalService.CommitRecordingSession();
        }
Пример #4
0
        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.Text;
                        costElement.AverageCost  = rs.NewUnitCost;
                        costElement.Margin       = rs.Margin;
                        costElement.SellingPrice = rs.NewSellingPrice;
                        Item itm = new Item();
                        itm.LoadByPrimaryKey(rs.ItemID);
                        itm.IsFree = false;

                        itm.Save();

                        rd.SavePrice(rs, CurrentContext.UserId);
                        try
                        {
                            IJournalService journal = new JournalService();
                            journal.StartRecordingSession();
                            costElement.SavePrice(CurrentContext.UserId, "", journal, ChangeMode.PriceOverride);
                            journal.CommitRecordingSession();
                            journal.StartRecordingSession();
                            costElement.ConfirmPrice(CurrentContext.UserId, "", journal, ChangeMode.PriceOverride);
                            journal.CommitRecordingSession();
                        }
                        catch (Exception exception)
                        {
                            // since Cost tier is not Full Started
                        }
                        transactionMgr.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        transactionMgr.RollbackTransaction();
                        XtraMessageBox.Show("Price setting failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw ex;
                    }
                    XtraMessageBox.Show("Price setting successful", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            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 btnApprove_Click(object sender, EventArgs e)
        {
            //dxCostingValidation.RemoveControlError(lkPeriod);
            if (!dxCostingValidation.Validate())
            {
                return;
            }
            if (lkWarehouse.EditValue != null && lkAccount.EditValue != null && XtraMessageBox.Show(String.Format("Are you sure you want to Approve All Items, Once Approved the item will be available for release"), "Are you sure...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    ReceiveDocConfirmation receiveDocConfirmation = new ReceiveDocConfirmation();
                    string   receiveDocs       = "";
                    string   rdPendingAverages = "";
                    var      ledgerService     = new LedgerService();
                    DataView dataView          = (gridMain.DataSource as DataView);
                    dataView.RowFilter = "PricePerPack <>0 and isConfirmed = 1";
                    foreach (DataRowView drv in dataView)
                    {
                        var costElement = new CostElement
                        {
                            ItemID          = Convert.ToInt32(drv["ItemID"]),
                            ItemUnitID      = Convert.ToInt32(drv["UnitID"]),
                            ManufacturerID  = Convert.ToInt32(drv["ManufacturerID"]),
                            MovingAverageID = Convert.ToInt32(drv["MovingAverageID"])
                        };

                        var ledgerObject = ledgerService.GetLedger(costElement.ItemID, costElement.ItemUnitID,
                                                                   costElement.ManufacturerID, costElement.MovingAverageID);

                        costElement.UnitCost = Math.Round(Convert.ToDouble(ledgerObject.UnitCost),
                                                          BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                          MidpointRounding.AwayFromZero);
                        costElement.AverageCost = Math.Round(Convert.ToDouble(drv["PricePerPack"]),
                                                             BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                             MidpointRounding.AwayFromZero);
                        costElement.Margin       = Convert.ToDouble(drv["Margin"]) / 100;
                        costElement.SellingPrice = costElement.AverageCost * (1 + costElement.Margin);
                        var isSound = drv["Remark"].Equals("Sound");
                        if ((Math.Abs(costElement.UnitCost - costElement.AverageCost) == 0) || !isSound)
                        {
                            receiveDocs = receiveDocs != ""
                                       ? receiveDocs + ',' + drv["ReceiveDocIDs"].ToString()
                                       : receiveDocs + drv["ReceiveDocIDs"].ToString();
                        }
                        else if (ReceiveDoc.GetSoundStock(costElement) > 0)
                        {
                            rdPendingAverages = rdPendingAverages != ""
                                             ? rdPendingAverages + ',' + drv["ReceiveDocIDs"].ToString()
                                             : rdPendingAverages + drv["ReceiveDocIDs"].ToString();
                        }
                        else
                        {
                            IJournalService journal = new JournalService();
                            journal.StartRecordingSession();
                            costElement.SavePrice(CurrentContext.UserId, "", journal, ChangeMode.BeginningBalance);
                            journal.CommitRecordingSession();

                            journal.StartRecordingSession();
                            costElement.ConfirmPrice(CurrentContext.UserId, "", journal, ChangeMode.BeginningBalance);
                            journal.CommitRecordingSession();

                            receiveDocs = receiveDocs != ""
                                       ? receiveDocs + ',' + drv["ReceiveDocIDs"].ToString()
                                       : receiveDocs + drv["ReceiveDocIDs"].ToString();
                        }
                    }

                    receiveDocConfirmation.ChangeStatusByAccountReceiveDocs(receiveDocs,
                                                                            ReceiptConfirmationStatus.Constants.GRV_PRINTED,
                                                                            ReceiptConfirmationStatus.Constants.GRNF_PRINTED);
                    receiveDocConfirmation.ChangeStatusByAccountReceiveDocs(rdPendingAverages,
                                                                            ReceiptConfirmationStatus.Constants.
                                                                            PRICE_CALCULATED,
                                                                            ReceiptConfirmationStatus.Constants.GRNF_PRINTED);
                    XtraMessageBox.Show("Price has been successfully confirmed", "Success...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    XtraMessageBox.Show(exception.Message, "Success...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    throw;
                }
                lkWarehouse_EditValueChanged(null, null);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();


            if (gridPriceList.DataSource != null && (gridPriceList.DataSource as DataTable).GetChanges() != null)
            {
                DataTable dtChangedPricelist = (gridPriceList.DataSource as DataTable).GetChanges();
                if (dtChangedPricelist != null)
                {
                    foreach (DataRowView drw in dtChangedPricelist.DefaultView)
                    {
                        var dialogResult =
                            XtraMessageBox.Show(
                                String.Format("Are you Sure you want to Change Price for {0}", drw["ItemName"]),
                                "Are you sure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        if (dialogResult == DialogResult.Cancel)
                        {
                            return;
                        }

                        if (dialogResult == DialogResult.Yes)
                        {
                            try
                            {
                                transaction.BeginTransaction();
                                // This is where we set the Price
                                JournalService journalService = new JournalService();
                                journalService.StartRecordingSession();
                                CostElement costElement = new CostElement(Convert.ToInt32(drw["ItemID"])
                                                                          , Convert.ToInt32(drw["MovingAverageGroupID"])
                                                                          , Convert.ToInt32(drw["ManufacturerID"])
                                                                          , Convert.ToInt32(drw["UnitID"]));

                                costElement.AverageCost = Math.Round(Convert.ToDouble(drw["UnitCost"]),
                                                                     BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                                     MidpointRounding.AwayFromZero);
                                costElement.Margin = Math.Round(Convert.ToDouble(drw["Margin"]),
                                                                BLL.Settings.NoOfDigitsAfterTheDecimalPoint + 2,
                                                                MidpointRounding.AwayFromZero);
                                if (BLL.Settings.IsCenter)
                                {
                                    costElement.SellingPrice = costElement.AverageCost;
                                }
                                else
                                {
                                    costElement.SellingPrice = Math.Round(Convert.ToDouble(drw["SellingPrice"]),
                                                                          BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                                          MidpointRounding.AwayFromZero);
                                }


                                costElement.SavePrice(CurrentContext.UserId, "", journalService, ChangeMode.PriceOverride);

                                PriceOverridePrintout report = new PriceOverridePrintout();
                                report.xrCostedBy.Text = CurrentContext.LoggedInUserName;
                                report.lblDate.Text    = DateTimeHelper.ServerDateTime.ToString();
                                report.DataSource      = getPriceChangeReport(costElement);

                                journalService.CommitRecordingSession();
                                transaction.CommitTransaction();

                                report.ShowPreviewDialog();
                            }
                            catch (Exception exception)
                            {
                                transaction.RollbackTransaction();
                                XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error);
                                throw exception;
                            }
                        }
                    }
                    BindDataSet();
                    XtraMessageBox.Show("Change was Successfull", "Success...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    return;
                }
            }

            XtraMessageBox.Show("No Changes have been made", "No Changes...", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            DataView dtChangedPricelist = gridViewPriceList.DataSource as DataView;

            if (dtChangedPricelist != null)
            {
                dtChangedPricelist.RowFilter = "IsConfirmed = 1";

                foreach (DataRowView drw in dtChangedPricelist)
                {
                    var dialogResult =
                        XtraMessageBox.Show(
                            String.Format("Are you Sure you want to Change Price for {0}", drw["ItemName"]),
                            "Are you sure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (dialogResult == DialogResult.Yes)
                    {
                        try
                        {
                            transaction.BeginTransaction();
                            // This is where we set the Price
                            JournalService journalService = new JournalService();
                            journalService.StartRecordingSession();
                            CostElement costElement = new CostElement(Convert.ToInt32(drw["ItemID"])
                                                                      , Convert.ToInt32(drw["MovingAverageGroupID"])
                                                                      , Convert.ToInt32(drw["ManufacturerID"])
                                                                      , Convert.ToInt32(drw["UnitID"]));

                            costElement.AverageCost = Math.Round(Convert.ToDouble(drw["UnitCost"]),
                                                                 BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                                 MidpointRounding.AwayFromZero);
                            costElement.Margin = Math.Round(Convert.ToDouble(drw["Margin"]),
                                                            BLL.Settings.NoOfDigitsAfterTheDecimalPoint + 2,
                                                            MidpointRounding.AwayFromZero);
                            costElement.SellingPrice = Math.Round(Convert.ToDouble(drw["SellingPrice"]),
                                                                  BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                                  MidpointRounding.AwayFromZero);


                            costElement.ConfirmPrice(CurrentContext.UserId, "", journalService, ChangeMode.PriceOverride);
                            ReceiveDoc receiveDoc = new ReceiveDoc();
                            receiveDoc.SavePrice(costElement, CurrentContext.UserId);
                            journalService.CommitRecordingSession();
                            transaction.CommitTransaction();
                        }
                        catch (Exception exception)
                        {
                            transaction.RollbackTransaction();
                            XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            throw exception;
                        }
                    }
                }
                BindDataSet();
                XtraMessageBox.Show("Change was Successfull", "Success...", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                return;
            }

            XtraMessageBox.Show("No Changes have been made", "No Changes...", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }