Ejemplo n.º 1
0
        public DataTable DeleteRemittanceItemFromTransaction(Guid txID, long fnremittrnceItemID, bool isFromAdvanceGrid)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            long remittanceId = 0;
            FnRemittanceDataset remittanceDS = (FnRemittanceDataset)TransactionService.GetDS(txID);

            FnRemittanceDataset.FnRemittanceItemRow remittanceItemRow = remittanceDS.FnRemittanceItem.FindByRemittanceItemID(fnremittrnceItemID);
            if (remittanceItemRow != null && !remittanceItemRow.IsNull("RemittanceID"))
            {
                remittanceId = remittanceItemRow.RemittanceID;
            }

            if (!isFromAdvanceGrid)
            {
                if (remittanceItemRow.IsImportFromAdvance)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CanNotDeleteItemInsertFromAdvance"));
                }

                if (!errors.IsEmpty)
                {
                    throw new ServiceValidationException(errors);
                }
            }
            remittanceItemRow.Delete();

            FnRemittanceService.UpdateTotalRemittanceAmount(txID, remittanceId);

            return(remittanceDS.FnRemittanceItem);
        }
Ejemplo n.º 2
0
        public void UpdateRemittanceItemList(Guid txID, long remittanceId, List <FnRemittanceItem> remittanceItemList, bool isFullClearing)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            double totalDivAmount = 0;

            foreach (FnRemittanceItem item in remittanceItemList)
            {
                if (item.ForeignCurrencyAdvanced >= item.ForeignCurrencyRemitted)
                {
                    totalDivAmount += item.ForeignCurrencyAdvanced - item.ForeignCurrencyRemitted;
                }
                else
                {
                    totalDivAmount += item.ForeignCurrencyRemitted - item.ForeignCurrencyAdvanced;
                }
            }
            logger.Info("totalDivAmount" + totalDivAmount);
            foreach (FnRemittanceItem item in remittanceItemList)
            {
                if (totalDivAmount == 0 || isFullClearing)
                {
                    item.AmountTHB = item.ForeignAmountTHBAdvanced;
                }
                UpdateRemittanceItemTransaction(txID, item, !item.IsImportFromAdvance);
            }

            double sumRemittanceItemAmount = remittanceItemList.Sum(x => (double)Math.Round((decimal)x.AmountTHB, 2, MidpointRounding.AwayFromZero));
            double sumAdvanceAmount        = remittanceItemList.Sum(x => (double)Math.Round((decimal)x.ForeignAmountTHBAdvanced, 2, MidpointRounding.AwayFromZero));

            logger.Info("TotalRemittance" + sumRemittanceItemAmount);
            logger.Info("TotalAdvance" + sumAdvanceAmount);
            if ((!isFullClearing && sumRemittanceItemAmount > sumAdvanceAmount) && totalDivAmount != 0)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TotalRemittanceItemNotMoreThanTotalAdvance"));
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            FnRemittanceService.UpdateTotalRemittanceAmount(txID, remittanceId);
        }
        public void ValidateSCGDocument(SCGDocument document, bool haveReceiver, bool haveApprover)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            // DocumentSubTypeID = ใบของบประมาณระหว่างงวด. Not use in eAccounting.
            // Must specific Approver.
            if (document.CompanyID == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CompanyIsRequired"));
            }
            else
            {
                DbCompany company = ScgDbQueryProvider.DbCompanyQuery.FindByIdentity(document.CompanyID.CompanyID);
                if (company == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CompanyIsRequired"));
                }
            }
            if (document.PaymentMethodID == 39)
            {
                if (document.RequesterID.Userid != document.ReceiverID.Userid)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReceiverCannotBeDifferentRequester"));
                }
            }

            if (string.IsNullOrEmpty(document.Subject))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("SubjectIsRequired"));
            }

            if (haveReceiver)
            {
                if (document.ReceiverID == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReceiverIsRequired"));
                }
                else
                {
                    SuUser receiver = QueryProvider.SuUserQuery.FindByIdentity(document.ReceiverID.Userid);

                    if (document.ReceiverID == null)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReceiverIsRequired"));
                    }
                }
            }

            if (haveApprover)
            {
                if (document.ApproverID == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ApproverIsRequired"));
                }
                else
                {
                    SuUser approver = QueryProvider.SuUserQuery.FindByIdentity(document.ApproverID.Userid);

                    if (approver == null)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ApproverIsRequired"));
                    }
                }
            }

            if (document.RequesterID == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequesterIsRequired"));
            }
            else
            {
                SuUser requester = QueryProvider.SuUserQuery.FindByIdentity(document.RequesterID.Userid);

                if (requester == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequesterIsRequired"));
                }
            }
            //add new field
            //IList<object> advanceEditableField = AvAdvanceDocumentService.GetEditableFields(document.DocumentID, null);
            IList <object> expenseEditableField    = FnExpenseDocumentService.GetEditableFields(document.DocumentID);
            IList <object> remittanceEditableField = FnRemittanceService.GetEditableFields(document.DocumentID);

            if (/*advanceEditableField.Contains(AdvanceFieldGroup.VerifyDetail) ||*/ expenseEditableField.Contains(ExpenseFieldGroup.VerifyDetail) || remittanceEditableField.Contains(RemittanceFieldGroup.VerifyDetail))
            {
                if (string.IsNullOrEmpty(document.BranchCode))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("BranchCodeIsRequired"));
                }
                //if (!document.PaymentMethodID.HasValue)
                //{
                //    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("PaymentMethodID_IsRequired"));
                //}
                if (!document.PostingDate.HasValue)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("PostingDateIsRequired"));
                }
                if (!document.BaseLineDate.HasValue)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("BaseLineDateIsRequired"));
                }
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
        }
        public void UpdateTransactionDocument(Guid TxID, SCGDocument document, bool haveReceiver, bool haveApprover)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            try
            {
                this.ValidateSCGDocument(document, haveReceiver, haveApprover);
            }
            catch (ServiceValidationException ex)
            {
                errors.MergeErrors(ex.ValidationErrors);
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            DataSet   ds            = TransactionService.GetDS(TxID);
            DataTable documentTable = ds.Tables["Document"];

            if (documentTable.Rows.Count > 0)
            {
                DataRow documentRow = documentTable.Rows[0];
                documentRow.BeginEdit();

                if (document.CompanyID != null)
                {
                    documentRow["CompanyID"] = document.CompanyID.CompanyID;
                }
                if (document.CreatorID != null)
                {
                    documentRow["CreatorID"] = document.CreatorID.Userid;
                }
                if (document.RequesterID != null)
                {
                    documentRow["RequesterID"] = document.RequesterID.Userid;
                }
                if (document.ApproverID != null)
                {
                    documentRow["ApproverID"] = document.ApproverID.Userid;
                }
                if (document.ReceiverID != null)
                {
                    documentRow["ReceiverID"] = document.ReceiverID.Userid;
                }
                //documentRow["DocumentNo"] = document.DocumentNo;
                if (document.DocumentType != null)
                {
                    documentRow["DocumentTypeID"] = document.DocumentType.DocumentTypeID;
                }
                IList <object> advanceEditableField      = AvAdvanceDocumentService.GetEditableFields(document.DocumentID, null);
                IList <object> expenseEditableField      = FnExpenseDocumentService.GetEditableFields(document.DocumentID);
                IList <object> remittanceEditableField   = FnRemittanceService.GetEditableFields(document.DocumentID);
                IList <object> fixedAdvanceEditableField = FixedAdvanceDocumentService.GetEditableFields(document.DocumentID);
                if (advanceEditableField.Contains(AdvanceFieldGroup.VerifyDetail) || expenseEditableField.Contains(ExpenseFieldGroup.VerifyDetail) || remittanceEditableField.Contains(RemittanceFieldGroup.VerifyDetail) || fixedAdvanceEditableField.Contains(FixedAdvanceFieldGroup.VerifyDetail))
                {
                    //add new field
                    if (!string.IsNullOrEmpty(document.BranchCode))
                    {
                        documentRow["BranchCode"] = document.BranchCode;
                    }
                    if (!string.IsNullOrEmpty(document.BusinessArea))
                    {
                        documentRow["BusinessArea"] = document.BusinessArea;
                    }
                    else
                    {
                        documentRow["BusinessArea"] = string.Empty;
                    }

                    if (!string.IsNullOrEmpty(document.Supplementary))
                    {
                        documentRow["Supplementary"] = document.Supplementary;
                    }
                    else
                    {
                        documentRow["Supplementary"] = string.Empty;
                    }

                    if (document.PaymentMethodID.HasValue && document.PaymentMethodID > 0)
                    {
                        documentRow["PaymentMethodID"] = document.PaymentMethodID.Value;
                    }
                    if (document.PostingDate.HasValue && document.PostingDate.Value != DateTime.MinValue)
                    {
                        documentRow["PostingDate"] = document.PostingDate;
                    }
                    if (document.BaseLineDate.HasValue && document.BaseLineDate.Value != DateTime.MinValue)
                    {
                        documentRow["BaseLineDate"] = document.BaseLineDate;
                    }
                    if (!string.IsNullOrEmpty(document.BankAccount))
                    {
                        documentRow["BankAccount"] = document.BankAccount;
                    }
                }
                if (!string.IsNullOrEmpty(document.ReferenceNo))
                {
                    documentRow["ReferenceNo"] = document.ReferenceNo;
                }
                else
                {
                    if (!documentRow["DocumentNo"].ToString().StartsWith("EHR"))
                    {
                        documentRow["ReferenceNo"] = document.ReferenceNo;
                    }
                }

                documentRow["IsVerifyImage"] = document.IsVerifyImage;
                documentRow["Subject"]       = document.Subject;
                documentRow["Memo"]          = document.Memo;
                documentRow["Active"]        = document.Active;
                documentRow["CreBy"]         = UserAccount.UserID;
                documentRow["CreDate"]       = DateTime.Now;
                documentRow["UpdBy"]         = UserAccount.UserID;
                documentRow["UpdDate"]       = DateTime.Now;
                documentRow["UpdPgm"]        = UserAccount.CurrentProgramCode;

                documentRow.EndEdit();
            }
        }
Ejemplo n.º 5
0
        public long AddFnRemittanceItemTransaction(Guid txID, FnRemittanceItem fnRemittanceItem, bool isFromAddvance, double totalAdvance)
        {
            Spring.Validation.ValidationErrors errors  = new Spring.Validation.ValidationErrors();
            FnRemittanceDataset fnRemittanceDocumentDS = (FnRemittanceDataset)TransactionService.GetDS(txID);

            DataRow[] dr;
            //FnRemittanceDataset.FnRemittanceRow remittanceRow = fnRemittanceDocumentDS.FnRemittance.FindByRemittanceID(fnRemittanceItem.Remittance.RemittanceID);
            if (fnRemittanceItem.Remittance.PB.Pbid != 0)
            {
                Dbpb dbPb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(Convert.ToInt64(fnRemittanceItem.Remittance.PB.Pbid));
                IsRepOffice = dbPb.RepOffice;
            }
            if (isFromAddvance)
            {
                string strSQL = " PaymentType = '{0}' AND CurrencyID = {1} ";
                dr = fnRemittanceDocumentDS.FnRemittanceItem.Select(string.Format(strSQL, fnRemittanceItem.PaymentType, fnRemittanceItem.Currency.CurrencyID));
            }
            else
            {
                if (fnRemittanceItem.Currency == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CurrencyIsRequire"));
                }
                if (fnRemittanceItem.ExchangeRate == 0 || fnRemittanceItem.ForeignCurrencyRemitted == 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExchangerateAndForeignCurrencyRemittedMustMoreThanZero"));
                }
                double totalRemittanceItemAmount = 0;
                foreach (FnRemittanceDataset.FnRemittanceItemRow remittanceItemRow in fnRemittanceDocumentDS.FnRemittanceItem.Select())
                {
                    if (!IsRepOffice)
                    {
                        totalRemittanceItemAmount += (double)Math.Round((decimal)remittanceItemRow.AmountTHB, 2, MidpointRounding.AwayFromZero);
                    }
                    else
                    {
                        totalRemittanceItemAmount += (double)Math.Round((decimal)remittanceItemRow.MainCurrencyAmount, 2, MidpointRounding.AwayFromZero);
                    }
                }
                if (!IsRepOffice)
                {
                    if (totalRemittanceItemAmount + fnRemittanceItem.AmountTHB > totalAdvance)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TotalRemittanceItemNotMoreThanTotalAdvance"));
                    }
                }
                else
                {
                    if (totalRemittanceItemAmount + fnRemittanceItem.MainCurrencyAmount > totalAdvance)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TotalRemittanceItemNotMoreThanTotalAdvance"));
                    }
                }
                if (!errors.IsEmpty)
                {
                    throw new ServiceValidationException(errors);
                }
                dr = fnRemittanceDocumentDS.FnRemittanceItem.Select(string.Format("CurrencyID = {0}", fnRemittanceItem.Currency.CurrencyID.ToString()));
            }
            if (dr.Length > 0)
            {
                if (isFromAddvance)
                {
                    dr[0]["ForeignAmountTHBAdvanced"] = Convert.ToDouble(dr[0]["ForeignAmountTHBAdvanced"]) + fnRemittanceItem.ForeignAmountTHBAdvanced;
                    dr[0]["ForeignCurrencyAdvanced"]  = Convert.ToDouble(dr[0]["ForeignCurrencyAdvanced"]) + fnRemittanceItem.ForeignCurrencyAdvanced;

                    if (Convert.ToDouble(dr[0]["ExchangeRate"]).Equals(0))
                    {
                        dr[0]["ExchangeRate"] = fnRemittanceItem.ExchangeRate;
                    }
                    else
                    {
                        dr[0]["ExchangeRate"] = (Convert.ToDouble(dr[0]["ExchangeRate"]) + fnRemittanceItem.ExchangeRate) / 2;
                    }
                }
                else
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("DuplicateCurrency"));
                }
                if (!errors.IsEmpty)
                {
                    throw new ServiceValidationException(errors);
                }
                return(Convert.ToInt64(dr[0]["RemittanceItemID"]));
            }
            else
            {
                FnRemittanceDataset.FnRemittanceItemRow fnRemittanceItemRow = fnRemittanceDocumentDS.FnRemittanceItem.NewFnRemittanceItemRow();

                if (fnRemittanceItem.Remittance != null)
                {
                    fnRemittanceItemRow.RemittanceID = fnRemittanceItem.Remittance.RemittanceID;
                }
                fnRemittanceItemRow.PaymentType                       = fnRemittanceItem.PaymentType;
                fnRemittanceItemRow.CurrencyID                        = fnRemittanceItem.Currency.CurrencyID;
                fnRemittanceItemRow.ForeignCurrencyAdvanced           = (double)Math.Round((decimal)fnRemittanceItem.ForeignCurrencyAdvanced, 2, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ExchangeRate                      = (double)Math.Round((decimal)fnRemittanceItem.ExchangeRate, 5, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ForeignCurrencyRemitted           = (double)Math.Round((decimal)fnRemittanceItem.ForeignCurrencyRemitted, 2, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ForeignAmountTHBAdvanced          = (double)Math.Round((decimal)fnRemittanceItem.ForeignAmountTHBAdvanced, 2, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ExchangeRateTHB                   = (double)Math.Round((decimal)fnRemittanceItem.ExchangeRateTHB, 5, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ForeignAmountMainCurrencyAdvanced = (double)Math.Round((decimal)fnRemittanceItem.ForeignAmountMainCurrencyAdvanced, 2, MidpointRounding.AwayFromZero);

                if (isFromAddvance)
                {
                    fnRemittanceItemRow.AmountTHB          = 0.00;
                    fnRemittanceItemRow.MainCurrencyAmount = 0.00;
                }
                else
                {
                    fnRemittanceItemRow.AmountTHB          = (double)Math.Round((decimal)fnRemittanceItem.AmountTHB, 2, MidpointRounding.AwayFromZero);
                    fnRemittanceItemRow.MainCurrencyAmount = (double)Math.Round((decimal)fnRemittanceItem.MainCurrencyAmount, 2, MidpointRounding.AwayFromZero);
                }
                fnRemittanceItemRow.IsImportFromAdvance = isFromAddvance;
                fnRemittanceItemRow.Active  = fnRemittanceItem.Active;
                fnRemittanceItemRow.CreBy   = UserAccount.UserID;
                fnRemittanceItemRow.CreDate = DateTime.Now;
                fnRemittanceItemRow.UpdBy   = UserAccount.UserID;
                fnRemittanceItemRow.UpdDate = DateTime.Now;
                fnRemittanceItemRow.UpdPgm  = UserAccount.CurrentProgramCode;
                fnRemittanceDocumentDS.FnRemittanceItem.AddFnRemittanceItemRow(fnRemittanceItemRow);

                FnRemittanceService.UpdateTotalRemittanceAmount(txID, fnRemittanceItemRow.RemittanceID);

                return(fnRemittanceItemRow.RemittanceItemID);
            }
        }