public IStock BindCostFromLedger(IStock stock)
        {
            LedgerService ledgerService = new LedgerService(repository);
            Ledger        ledger        = ledgerService.GetLedger(stock.ItemId, stock.UnitId, stock.ManufacturerId,
                                                                  stock.MovingAverageId);

            stock.UnitCost     = ledger.UnitCost;
            stock.Margin       = ledger.Margin;
            stock.SellingPrice = ledger.SellingPrice;
            return(stock);
        }
 public static DataTable SetPrice(DataTable dataTable)
 {
     foreach (DataRow dataRow in dataTable.Rows)
     {
         var ledgerService = new LedgerService();
         var ledgerObject  = ledgerService.GetLedger(Convert.ToInt32(dataRow["ItemID"])
                                                     , Convert.ToInt32(dataRow["ItemUnitID"])
                                                     , Convert.ToInt32(dataRow["ManufacturerID"])
                                                     , Convert.ToInt32(dataRow["MovingAverageID"]));
         dataRow["UnitCost"] = Math.Round(ledgerObject.UnitCost, Settings.NoOfDigitsAfterTheDecimalPoint,
                                          MidpointRounding.AwayFromZero);
         dataRow["TotalCost"] = Math.Round(ledgerObject.UnitCost * Convert.ToDecimal(dataRow["PreviousQty"]),
                                           Settings.NoOfDigitsAfterTheDecimalPoint,
                                           MidpointRounding.AwayFromZero);
     }
     return(dataTable);
 }
Exemplo n.º 3
0
        public DataRow priceChangeReport(DataRow dr)
        {
            var costLedgerService = new LedgerService();
            var ledger            = costLedgerService.GetLedger(ItemID, ItemUnitID, ManufacturerID,
                                                                MovingAverageID);

            dr["FullItemName"]         = ItemName;
            dr["StockCode"]            = StockCode;
            dr["Manufacturer"]         = ManufacturerName;
            dr["Account"]              = AccountName;
            dr["Unit"]                 = ItemUnitName;
            dr["PreviousUnitCost"]     = ledger.UnitCost;
            dr["PreviousMargin"]       = ledger.Margin;
            dr["PreviousSellingPrice"] = ledger.SellingPrice;
            dr["NewUnitCost"]          = AverageCost;
            dr["NewMargin"]            = Margin;
            dr["NewSellingPrice"]      = SellingPrice;

            return(dr);
        }
        private void LoadAndCalculate()
        {
            var ledgerService = new LedgerService();
            var ledgerObject  = ledgerService.GetLedger(costElement.ItemID, costElement.ItemUnitID, costElement.ManufacturerID,
                                                        costElement.MovingAverageID);

            previousQty = ReceiveDoc.GetSoundStock(costElement);


            previousUnitCost = Math.Round(ledgerObject.UnitCost, BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                          MidpointRounding.AwayFromZero);


            AverageCostCalculator averageCostCalculator = new AverageCostCalculator(costElement);

            costElement.AverageCost = averageCostCalculator.CalculateMovingAverage(Convert.ToDouble(previousQty),
                                                                                   Convert.ToDouble(previousUnitCost),
                                                                                   costElement.Qty, costElement.UnitCost);
            costElement.SellingPrice = averageCostCalculator.GetSellingPrice(BLL.Settings.IsCenter?0:costElement.Margin);

            txtItemName.Text     = costElement.ItemName;
            txtManufacturer.Text = costElement.ManufacturerName;
            txtUnit.Text         = costElement.ItemUnitName;
        }
        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);
            }
        }