Beispiel #1
0
        private void btnFinalize_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmStockWithdrawal", "Finalize"))
                {
                    return;
                }

                string _SOId = "";

                foreach (DataRow _drStatus in loInventory.getInventoryStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    _SOId = _drStatus["SOId"].ToString();

                    if (_drStatus["Final"].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Stock Inventory is already FINALIZED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                }
                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue finalizing this Stock Inventory record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        if (loInventory.final(dgvList.CurrentRow.Cells[0].Value.ToString()))
                        {
                            //update SO Detail
                            foreach (DataRow _dr1 in loInventoryDetail.getInventoryDetails("", dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                            {
                                //update Qty
                                loSalesOrderDetail.updateQtyOutSalesOrderDetail(_dr1["SODetailId"].ToString(), decimal.Parse(_dr1["Qty Out"].ToString()), decimal.Parse(_dr1["Variance"].ToString()));
                                //updtae TotalPrice
                                decimal _totalPrice = 0;
                                foreach (DataRow _dr2 in loSalesOrderDetail.getSalesOrderDetail(_dr1["SODetailId"].ToString()).Rows)
                                {
                                    _totalPrice = decimal.Parse(_dr2["Qty Out"].ToString()) * decimal.Parse(_dr2["Unit Price"].ToString());
                                    loSalesOrderDetail.updateTotalPriceSalesOrderDetail(_dr1["SODetailId"].ToString(), _totalPrice);
                                }
                            }
                            //update PO Header Qty and Amount
                            decimal _totalQtyOut   = 0;
                            decimal _totalVariance = 0;
                            decimal _totalAmount   = 0;
                            foreach (DataRow _dr3 in loSalesOrderDetail.getSalesOrderDetails("", _SOId).Rows)
                            {
                                _totalQtyOut   += decimal.Parse(_dr3["Qty Out"].ToString());
                                _totalVariance += decimal.Parse(_dr3["Qty Variance"].ToString());
                                _totalAmount   += decimal.Parse(_dr3["Total Price"].ToString());
                            }

                            loSalesOrder.updateSOTotalAmount(_SOId, _totalQtyOut, _totalVariance, _totalAmount);

                            MessageBoxUI _mb1 = new MessageBoxUI("Stock Inventory record has been successfully finalized!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                            _mb1.ShowDialog();
                            previewInventoryDetail(dgvList.CurrentRow.Cells[0].Value.ToString());
                            //sendEmailToCreator();
                            refresh("Stock Withdrawal");
                        }
                        else
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnFinalize_Click");
                em.ShowDialog();
                return;
            }
        }