Ejemplo n.º 1
0
 private void FillFromList()
 {
     InvtBatchADJ_HeaderEx.LoadCombo(ref cboFrom, "TxNumber", false);
 }
Ejemplo n.º 2
0
        private void FillToList()
        {
            InvtBatchADJ_HeaderEx.LoadCombo(ref cboTo, "TxNumber", false);

            cboTo.SelectedIndex = cboTo.Items.Count - 1;
        }
Ejemplo n.º 3
0
        private bool IsPostable(string headerId, ref DataTable errorTable)
        {
            bool isPostable = true;

            using (var ctx = new EF6.RT2020Entities())
            {
                Guid id = Guid.Empty;
                if (Guid.TryParse(headerId, out id))
                {
                    var oBatchHeader = InvtBatchADJ_HeaderEx.Get(id);
                    if (oBatchHeader != null)
                    {
                        if (!CheckTxDate(oBatchHeader.TxDate.Value))
                        {
                            #region 加一行
                            DataRow row = errorTable.NewRow();
                            row["HeaderId"]    = oBatchHeader.HeaderId.ToString();
                            row["TxNumber"]    = oBatchHeader.TxNumber;
                            row["STKCODE"]     = string.Empty;
                            row["APPENDIX1"]   = string.Empty;
                            row["APPENDIX2"]   = string.Empty;
                            row["APPENDIX3"]   = string.Empty;
                            row["ErrorReason"] = "Transaction date does not belong to current system month.";
                            row["PostDate"]    = DateTime.Now;

                            errorTable.Rows.Add(row);
                            #endregion
                            isPostable = isPostable & false;
                        }

                        if (oBatchHeader.Status == (int)EnumHelper.Status.Active && oBatchHeader.PostedBy != System.Guid.Empty)
                        {
                            #region 加一行
                            DataRow row = errorTable.NewRow();
                            row["HeaderId"]    = oBatchHeader.HeaderId.ToString();
                            row["TxNumber"]    = oBatchHeader.TxNumber;
                            row["STKCODE"]     = string.Empty;
                            row["APPENDIX1"]   = string.Empty;
                            row["APPENDIX2"]   = string.Empty;
                            row["APPENDIX3"]   = string.Empty;
                            row["ErrorReason"] = "Transaction already had been posted! Cannot post again!";
                            row["PostDate"]    = DateTime.Now;

                            errorTable.Rows.Add(row);
                            #endregion
                            isPostable = isPostable & false;
                        }

                        var detailList = ctx.InvtBatchADJ_Details.Where(x => x.HeaderId == oBatchHeader.HeaderId).AsNoTracking().ToList();
                        foreach (var detail in detailList)
                        {
                            bool   retired = false;
                            string stk = string.Empty, a1 = string.Empty, a2 = string.Empty, a3 = string.Empty;

                            var oProduct = ProductEx.Get(detail.ProductId);
                            if (oProduct != null)
                            {
                                stk     = oProduct.STKCODE;
                                a1      = oProduct.APPENDIX1;
                                a2      = oProduct.APPENDIX2;
                                a3      = oProduct.APPENDIX3;
                                retired = oProduct.Retired;
                            }

                            if (retired)
                            {
                                #region 加一行
                                DataRow row = errorTable.NewRow();
                                row["HeaderId"]    = oBatchHeader.HeaderId.ToString();
                                row["TxNumber"]    = oBatchHeader.TxNumber;
                                row["STKCODE"]     = stk;
                                row["APPENDIX1"]   = a1;
                                row["APPENDIX2"]   = a2;
                                row["APPENDIX3"]   = a3;
                                row["ErrorReason"] = "Product does not exist or has been removed!";
                                row["PostDate"]    = DateTime.Now;

                                errorTable.Rows.Add(row);
                                #endregion
                                isPostable = isPostable & false;
                            }

                            decimal qty = ProductHelper.GetOnHandQtyByWorkplaceId(detail.ProductId, oBatchHeader.WorkplaceId);
                            if ((qty + detail.Qty) < 0)
                            {
                                #region 加一行
                                DataRow row = errorTable.NewRow();
                                row["HeaderId"]    = oBatchHeader.HeaderId.ToString();
                                row["TxNumber"]    = oBatchHeader.TxNumber;
                                row["STKCODE"]     = stk;
                                row["APPENDIX1"]   = a1;
                                row["APPENDIX2"]   = a2;
                                row["APPENDIX3"]   = a3;
                                row["ErrorReason"] = "Product does not have enough on-hand qty!";
                                row["PostDate"]    = DateTime.Now;

                                errorTable.Rows.Add(row);
                                #endregion
                                isPostable = isPostable & false;
                            }
                        }

                        var oStaff = StaffEx.GetByStaffId(oBatchHeader.StaffId);
                        if (oStaff != null)
                        {
                            if (oStaff.Retired)
                            {
                                #region 加一行
                                DataRow row = errorTable.NewRow();
                                row["HeaderId"]    = oBatchHeader.HeaderId.ToString();
                                row["TxNumber"]    = oBatchHeader.TxNumber;
                                row["STKCODE"]     = string.Empty;
                                row["APPENDIX1"]   = string.Empty;
                                row["APPENDIX2"]   = string.Empty;
                                row["APPENDIX3"]   = string.Empty;
                                row["ErrorReason"] = "Staff does not exist or has been removed!";
                                row["PostDate"]    = DateTime.Now;

                                errorTable.Rows.Add(row);
                                #endregion
                                isPostable = isPostable & false;
                            }
                        }

                        var oInvtLedger = ctx.InvtLedgerHeader.Where(x => x.TxNumber == oBatchHeader.TxNumber && x.TxType == "ADJ").AsNoTracking().FirstOrDefault();
                        if (oInvtLedger != null)
                        {
                            #region 加一行
                            DataRow row = errorTable.NewRow();
                            row["HeaderId"]    = oBatchHeader.HeaderId.ToString();
                            row["TxNumber"]    = oBatchHeader.TxNumber;
                            row["STKCODE"]     = string.Empty;
                            row["APPENDIX1"]   = string.Empty;
                            row["APPENDIX2"]   = string.Empty;
                            row["APPENDIX3"]   = string.Empty;
                            row["ErrorReason"] = "Transaction existed in Inventory Ledger!";
                            row["PostDate"]    = DateTime.Now;

                            errorTable.Rows.Add(row);
                            #endregion
                            isPostable = isPostable & false;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(isPostable);
        }