protected void ctlMaintain_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex; if (e.CommandName.Equals("MaintainRate")) { ctlDatePicker.Value = DateTime.Now; rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; ctlMaintain.SelectedIndex = rowIndex; PBID = UIHelper.ParseShort(ctlMaintain.DataKeys[rowIndex].Values["Pbid"].ToString()); DbPb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(PBID); if (DbPb != null && DbPb.MainCurrencyID != null) { CurrencyDropdown1.BindCurrency(DbPb.MainCurrencyID.Value); CurrencyDropdown1.Enable = false; } else { CurrencyDropdown1.ResetControl(); CurrencyDropdown1.Enable = true; } ctlDivMaintainInfo.Style["display"] = "block"; ctlMaintainInfo.DataCountAndBind(); } ctlUpdatePanelMaintainRateGrid.Update(); }
protected void ctlReport_DataBound(object sender, EventArgs e) { Dbpb dbPb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(Convert.ToInt64(ctlPbDropdownList.SelectedValue)); DbCurrency dbCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(Convert.ToInt16(dbPb.MainCurrencyID)); ctlReport.Columns[6].HeaderText = string.Format(GetProgramMessage("ctlMainCurrency"), "(" + dbCurrency.Symbol + ")"); }
protected void ctlPB_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex; if (e.CommandName.Equals("PBEdit")) { rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; PBID = UIHelper.ParseShort(ctlPBGrid.DataKeys[rowIndex].Values["Pbid"].ToString()); PBEditor.Initialize(FlagEnum.EditFlag, PBID); PBEditor.ShowPopUp(); } if (e.CommandName.Equals("PBDelete")) { try { rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; PBID = UIHelper.ParseShort(ctlPBGrid.DataKeys[rowIndex].Value.ToString()); Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(PBID); DbPBService.DeletePB(pb); } catch (Exception ex) { if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertInUseData", "alert('This data is now in use.');", true); ctlPBGrid.DataCountAndBind(); } } ctlPBGrid.DataCountAndBind(); ctlPBUpdatePanel.Update(); } }
public void Initialize(string mode, long id) { Mode = mode.ToString(); PbDataSet = new DBPbDataSet(); ctlMainCurrencyDropdown.DataSource = SsDbQueryProvider.DbCurrencyQuery.FindAll(); //GetCurrencyLangByCurrencyID();//currencyId, UserAccount.CurrentLanguageID); ctlMainCurrencyDropdown.DataTextField = "Symbol"; ctlMainCurrencyDropdown.DataValueField = "CurrencyID"; ctlMainCurrencyDropdown.DataBind(); ctlMainCurrencyDropdown.Items.Insert(0, new ListItem("Please Select", string.Empty)); PBID = id; if (mode.Equals(FlagEnum.EditFlag)) { Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(PBID); ctlPBCode.Text = pb.PBCode; ctlPettyCashLimit.Text = UIHelper.BindDecimal(pb.PettyCashLimit.ToString()); ctlSupplementary.Text = pb.Supplementary; ctlActive.Checked = pb.Active; DbCompany company = ScgDbQueryProvider.DbCompanyQuery.getDbCompanyByCompanyCode(pb.CompanyCode); if (company != null) { ctlCompanyField.SetValue(company.CompanyID); } ctlPBEditorGrid.DataCountAndBind(); IList <DbPBCurrency> list = ScgDbQueryProvider.DbPBCurrencyQuery.FindPBCurrencyByPBID(PBID); ctlRepOffice.Checked = pb.RepOffice; if (pb.MainCurrencyID.HasValue && pb.MainCurrencyID.Value != 0) { ctlMainCurrencyDropdown.SelectedValue = pb.MainCurrencyID.ToString(); } //loop add to dataset foreach (DbPBCurrency pbCurrency in list) { DBPbDataSet.DbPBCurrencyRow row = PbDataSet.DbPBCurrency.NewDbPBCurrencyRow(); row.ID = pbCurrency.ID; row.PBID = pbCurrency.PBID; row.CurrencyID = pbCurrency.CurrencyID; row.CreBy = pbCurrency.CreBy; row.CreDate = pbCurrency.CreDate; row.UpdBy = pbCurrency.UpdBy; row.UpdDate = pbCurrency.UpdDate; row.UpdPgm = pbCurrency.UpdPgm; PbDataSet.DbPBCurrency.AddDbPBCurrencyRow(row); } PbDataSet.AcceptChanges(); BindLocalCurrency(); ctlPBUpdatePanel.Update(); } else if (mode.ToString() == FlagEnum.NewFlag) { ResetValue(); ctlCompanyField.ResetValue(); } if (ctlRepOffice.Checked) { ctlMainCurrencyLabel.Visible = true; ctlMainCurrencyDropdown.Visible = true; ctlLocalCurrencyLabel.Visible = true; ctlLocalCurrencyDropdown.Visible = true; ctlAddLocalCurrencyButton.Visible = true; ctlPBLocalCurrencyGridview.Visible = true; } else { ctlMainCurrencyLabel.Visible = false; ctlMainCurrencyDropdown.Visible = false; ctlLocalCurrencyLabel.Visible = false; ctlLocalCurrencyDropdown.Visible = false; ctlAddLocalCurrencyButton.Visible = false; ctlPBLocalCurrencyGridview.Visible = false; } }
protected void ctlAdd_Click(object sender, ImageClickEventArgs e) { Dbpb pb = new Dbpb(); if (Mode.Equals(FlagEnum.EditFlag)) { pb.Pbid = PBID; } pb.PBCode = ctlPBCode.Text; pb.Supplementary = ctlSupplementary.Text; pb.Active = ctlActive.Checked; pb.UpdBy = UserAccount.UserID; pb.UpdDate = DateTime.Now; pb.UpdPgm = UserAccount.CurrentLanguageCode; pb.CreDate = DateTime.Now; pb.CreBy = UserAccount.UserID; pb.CurrencyID = UIHelper.ParseLong(ctlMainCurrencyDropdown.SelectedValue); pb.RepOffice = ctlRepOffice.Checked; if (!string.IsNullOrEmpty(ctlMainCurrencyDropdown.SelectedValue)) { pb.MainCurrencyID = UIHelper.ParseShort(ctlMainCurrencyDropdown.SelectedValue); } try { pb.PettyCashLimit = UIHelper.ParseDouble(ctlPettyCashLimit.Text); DbCompany com = ScgDbQueryProvider.DbCompanyQuery.FindByIdentity(UIHelper.ParseLong(ctlCompanyField.CompanyID)); pb.CompanyCode = com.CompanyCode; pb.CompanyID = com; } catch (Exception) { Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); errors.AddError("PB.Error", new ErrorMessage("Check For Petty Cash Limit or Company Code.")); ValidationErrors.MergeErrors(errors); return; } try { // save or update PB if (Mode.Equals(FlagEnum.EditFlag)) { DbPBService.UpdatePB(pb, PbDataSet); } else { long PBId = DbPBService.AddPB(pb, PbDataSet); pb.Pbid = PBId; } // save or update PBlang IList <DbpbLang> list = new List <DbpbLang>(); foreach (GridViewRow row in ctlPBEditorGrid.Rows) { short languageId = UIHelper.ParseShort(ctlPBEditorGrid.DataKeys[row.RowIndex]["LanguageID"].ToString()); TextBox Description = row.FindControl("ctrDescription") as TextBox; TextBox Comment = (TextBox)row.FindControl("ctrComment") as TextBox; CheckBox Active = (CheckBox)row.FindControl("ctlActive") as CheckBox; //comment by oum 02/06/2009 //ไม่ต้อง check description is null or empty เพราะว่าไม่ใช่ require field //if ((!string.IsNullOrEmpty(Description.Text))) //{ DbpbLang pbLang = new DbpbLang(); pbLang.Active = Active.Checked; pbLang.CreBy = UserAccount.UserID; pbLang.CreDate = DateTime.Now; pbLang.Description = Description.Text; pbLang.Comment = Comment.Text; pbLang.LanguageID = new DbLanguage(languageId); pbLang.PBID = pb; pbLang.UpdBy = UserAccount.UserID; pbLang.UpdDate = DateTime.Now; pbLang.UpdPgm = UserAccount.CurrentLanguageCode; list.Add(pbLang); //} } if (Mode.Equals(FlagEnum.EditFlag)) { DbPBLangService.UpdatePBLang(list); } if (Mode.Equals(FlagEnum.NewFlag)) { DbPBLangService.AddPBLang(list); } Notify_Ok(sender, e); } catch (ServiceValidationException ex) { this.ValidationErrors.MergeErrors(ex.ValidationErrors); } //} }
public void BindDifferenceAmountSummary() { FnExpenseDocumentService.CalculateTotalExpense(this.TransactionId, this.ExpDocumentID, IsRepOffice); FnExpenseDocumentService.CalculateDifferenceAmount(this.TransactionId, this.ExpDocumentID, IsRepOffice); ExpenseDataSet expDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId); if (expDS != null) { ExpenseDataSet.FnExpenseDocumentRow expRow = expDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID); if (expRow != null) { if (!IsRepOffice) { DivTotalSummaryForThailand.Style["display"] = "block"; DivTotalSummaryForRepOffice.Style["display"] = "none"; ctlTotalExpense.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalExpense.ToString()); ctlTotalExpense.ForeColor = expRow.TotalExpense < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlTotalAdvance.Text = UIHelper.BindDecimalNumberAccountFormat((-1 * expRow.TotalAdvance).ToString()); ctlTotalAdvance.ForeColor = (-1 * expRow.TotalAdvance) < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlTotalRemitted.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalRemittance.ToString()); ctlTotalRemitted.ForeColor = expRow.TotalRemittance < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlDifferenceAmount.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.DifferenceAmount.ToString()); ctlDifferenceAmount.ForeColor = expRow.DifferenceAmount < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; } else { DivTotalSummaryForThailand.Style["display"] = "none"; DivTotalSummaryForRepOffice.Style["display"] = "block"; ctlTHBCurrencyTab.Visible = false; ctlMainCurrencyTab.Visible = false; if (CounterCashierID.HasValue) { Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(CounterCashierID.Value); DbCurrency localCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(LocalCurrencyID.HasValue ? LocalCurrencyID.Value : (short)0); DbCurrency mainCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(pb.MainCurrencyID.HasValue ? pb.MainCurrencyID.Value : (short)0); if (localCurrency != null) { ctlLocalCurrencyTab.HeaderText = localCurrency.Symbol; } if (mainCurrency != null) { ctlMainCurrencyTab.HeaderText = mainCurrency.Symbol; } } #region Amount LocalCurrency Tab ctlLocalCurrencyTab.Visible = true; ctlTotalExpenseLocal.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalExpenseLocalCurrency.ToString()); ctlTotalExpenseLocal.ForeColor = expRow.TotalExpenseLocalCurrency < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; if (!expRow.IsTotalAdvanceLocalCurrencyNull()) { ctlTotalAdvanceLocal.Text = UIHelper.BindDecimalNumberAccountFormat((-1 * expRow.TotalAdvanceLocalCurrency).ToString()); ctlTotalAdvanceLocal.ForeColor = (-1 * expRow.TotalAdvanceLocalCurrency) < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; } if (!expRow.IsTotalRemittanceLocalCurrencyNull()) { ctlTotalRemittanceLocal.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalRemittanceLocalCurrency.ToString()); ctlTotalRemittanceLocal.ForeColor = expRow.TotalRemittanceLocalCurrency < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; } if (!expRow.IsDifferenceAmountLocalCurrencyNull()) { ctlDifferenceAmtLocal.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.DifferenceAmountLocalCurrency.ToString()); ctlDifferenceAmtLocal.ForeColor = expRow.DifferenceAmountLocalCurrency < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; } #endregion SS.Standard.WorkFlow.DTO.WorkFlow workflow = SS.Standard.WorkFlow.Query.WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(expRow.DocumentID); if (workflow != null && workflow.CurrentState.Ordinal >= 5) { if (UserAccount.IsAccountant || UserAccount.IsPayment) { #region Amount MainCurrency Tab if (expRow.LocalCurrencyID != expRow.MainCurrencyID) { ctlMainCurrencyTab.Visible = true; } ctlTotalExpenseMainCurrency.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalExpenseMainCurrency.ToString()); ctlTotalExpenseMainCurrency.ForeColor = expRow.TotalExpenseMainCurrency < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlTotalAdvanceMainCurrency.Text = UIHelper.BindDecimalNumberAccountFormat((-1 * expRow.TotalAdvanceMainCurrency).ToString()); ctlTotalAdvanceMainCurrency.ForeColor = (-1 * expRow.TotalAdvanceMainCurrency) < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlTotalRemittanceMainCurrency.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalRemittanceMainCurrency.ToString()); ctlTotalRemittanceMainCurrency.ForeColor = expRow.TotalRemittanceMainCurrency < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlDifferenceAmtMainCurrency.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.DifferenceAmountMainCurrency.ToString()); ctlDifferenceAmtMainCurrency.ForeColor = expRow.DifferenceAmountMainCurrency < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; #endregion #region Amount THB Currency Tab ctlTHBCurrencyTab.Visible = true; ctlTotalExpenseTHB.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalExpense.ToString()); ctlTotalExpenseTHB.ForeColor = expRow.TotalExpense < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlTotalAdvanceTHB.Text = UIHelper.BindDecimalNumberAccountFormat((-1 * expRow.TotalAdvance).ToString()); ctlTotalAdvanceTHB.ForeColor = (-1 * expRow.TotalAdvance) < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlTotalRemittanceTHB.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.TotalRemittance.ToString()); ctlTotalRemittanceTHB.ForeColor = expRow.TotalRemittance < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; ctlDifferenceAmtTHB.Text = UIHelper.BindDecimalNumberAccountFormat(expRow.DifferenceAmount.ToString()); ctlDifferenceAmtTHB.ForeColor = expRow.DifferenceAmount < 0 ? System.Drawing.Color.Red : System.Drawing.Color.Black; #endregion } } } } } }
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); } }
public void UpdateInvoiceItemByInvoiceID(Guid txID, long invoiceId, FnExpenseDocument expenseDocument) { ExpenseDataSet expDS = (ExpenseDataSet)TransactionService.GetDS(txID); ExpenseDataSet.FnExpenseInvoiceRow invoiceRow = expDS.FnExpenseInvoice.FindByInvoiceID(invoiceId); ExpenseDataSet.FnExpenseInvoiceItemRow[] itemRows = (ExpenseDataSet.FnExpenseInvoiceItemRow[])expDS.FnExpenseInvoiceItem.Select(); DbAccount account = new DbAccount(); foreach (ExpenseDataSet.FnExpenseInvoiceItemRow row in itemRows) { account = ScgDbQueryProvider.DbAccountQuery.FindByIdentity(row.AccountID); } string filter = String.Format("InvoiceID = {0}", invoiceId); DataRow[] rows = expDS.FnExpenseInvoiceItem.Select(filter); Dbpb pb = null; double totalLocalCurrencyAmount = 0; double totalMainCurrencyAmount = 0; double totalAmountTHB = 0; bool isRepOffice = expenseDocument.IsRepOffice.HasValue ? expenseDocument.IsRepOffice.Value : false; if (expenseDocument.PB != null) { pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(expenseDocument.PB.Pbid); } foreach (DataRow row in rows) { FnExpenseInvoiceItem item = new FnExpenseInvoiceItem(); item.LoadFromDataRow(row); item.Invoice.Expense = expenseDocument; if (account.SaveAsVendor) { if (invoiceRow.isVAT) { if (!invoiceRow.IsVendorIDNull()) { item.VendorCodeAP = invoiceRow.VendorCode; } } } if (isRepOffice) { if (expenseDocument.MainCurrencyID.HasValue) { item.MainCurrencyID = expenseDocument.MainCurrencyID.Value; } if (expenseDocument.ExchangeRateForLocalCurrency.HasValue && expenseDocument.ExchangeRateForLocalCurrency.Value != 0) { if (item.LocalCurrencyAmount.HasValue) { if (expenseDocument.MainCurrencyID == expenseDocument.LocalCurrencyID) { item.MainCurrencyAmount = item.LocalCurrencyAmount; } else { item.MainCurrencyAmount = (double)Math.Round((decimal)(item.LocalCurrencyAmount.Value / expenseDocument.ExchangeRateForLocalCurrency.Value), 2, MidpointRounding.AwayFromZero); } totalMainCurrencyAmount += item.MainCurrencyAmount.Value; totalLocalCurrencyAmount += item.LocalCurrencyAmount.Value; } } if (expenseDocument.ExchangeRateMainToTHBCurrency.HasValue) { if (item.MainCurrencyAmount.HasValue) { item.Amount = (double)Math.Round((decimal)(item.MainCurrencyAmount * expenseDocument.ExchangeRateMainToTHBCurrency), 2, MidpointRounding.AwayFromZero); totalAmountTHB += item.Amount.Value; } } } else { if (expenseDocument.ExpenseType == ZoneType.Foreign) { //item.ExchangeRate = (double)Math.Round(Convert.ToDecimal(expenseDocument.ExchangeRateForUSDAdvance), 4, MidpointRounding.AwayFromZero); item.Amount = (double)Math.Round(Convert.ToDecimal(item.CurrencyAmount * item.ExchangeRate), 2, MidpointRounding.AwayFromZero); } totalAmountTHB += item.Amount.Value; } UpdateInvoiceItemOnTransaction(item, txID, expenseDocument.ExpenseType); } invoiceRow.BeginEdit(); if (isRepOffice) { invoiceRow.TotalAmountLocalCurrency = invoiceRow.TotalBaseAmountLocalCurrency = invoiceRow.NetAmountLocalCurrency = (decimal)totalLocalCurrencyAmount; } invoiceRow.TotalAmount = (decimal)totalAmountTHB; invoiceRow.EndEdit(); }
public void UpdateAvDocumentTransaction(AvAdvanceDocument avAdvanceDoc, Guid txid) { bool isRepOffice = false; IList <object> advanceEditableField = new List <object>(); string mode = string.Empty; if (UserAccount.CurrentProgramCode == "AdvanceForeignForm") { mode = "FR"; } else if (UserAccount.CurrentProgramCode == "AdvanceDomesticForm") { mode = "DM"; } if (avAdvanceDoc.DocumentID != null) { advanceEditableField = GetEditableFields(avAdvanceDoc.DocumentID.DocumentID, null); } Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); AdvanceDataSet ds = (AdvanceDataSet)TransactionService.GetDS(txid); AdvanceDataSet.AvAdvanceDocumentRow rowAdvance = (AdvanceDataSet.AvAdvanceDocumentRow)ds.AvAdvanceDocument.FindByAdvanceID(avAdvanceDoc.AdvanceID); SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(avAdvanceDoc.DocumentID.DocumentID); AdvanceDataSet.DocumentRow rowDocument = (AdvanceDataSet.DocumentRow)ds.Document.FindByDocumentID(rowAdvance.DocumentID); if (!rowAdvance.IsIsRepOfficeNull()) { isRepOffice = rowAdvance.IsRepOffice; } //IList<AvAdvanceItem> advanceItem = ScgeAccountingQueryProvider.AvAdvanceItemQuery.FindByAvAdvanceItemAdvanceID(rowAdvance.AdvanceID); //ds.AvAdvanceItem.FindByAdvanceID(rowAdvance.AdvanceID); DataRow[] drItem = ds.AvAdvanceItem.Select(string.Format("AdvanceID={0}", rowAdvance.AdvanceID)); rowAdvance.BeginEdit(); // Validate Amount. if (avAdvanceDoc.AdvanceType == ZoneType.Domestic) { Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(avAdvanceDoc.PBID == null ? 0 : avAdvanceDoc.PBID.Pbid); if (!isRepOffice) { if (avAdvanceDoc.Amount == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountDomesticIsRequired")); } //เกินวงเงินของ counter cashier if (avAdvanceDoc.PaymentType == PaymentType.CA) { if (pb != null && avAdvanceDoc.Amount > pb.PettyCashLimit && pb.PettyCashLimit != 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountDomesticIsOverPettyCashLimit")); } } } else { if (avAdvanceDoc.LocalCurrencyAmount == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountIsRequired")); } if (avAdvanceDoc.PaymentType == PaymentType.CA) { if (avAdvanceDoc.MainCurrencyAmount > pb.PettyCashLimit && pb.PettyCashLimit != 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountDomesticIsOverPettyCashLimit")); } } } //ถ้าเป็นไม่เป้นเงินโอน ต้องใส่ค่า dbpb if (drItem.Length > 0) { if (!drItem[0]["PaymentType"].ToString().Equals(PaymentType.TR)) { if (avAdvanceDoc.PBID == null || avAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CounterCashierIsRequired")); } } } // Validate Service Team if (avAdvanceDoc.ServiceTeamID.ServiceTeamID == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ServiceTeamIsRequired")); } } else { if (avAdvanceDoc.ArrivalDate == null) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ArrivalDateIsRequired")); } if (avAdvanceDoc.ArrivalDate.Equals(DateTime.MinValue)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ArrivalDateIsMoreThanRequestDateofAdvance")); } // Validate Counter Cashier if (avAdvanceDoc.PBID == null || avAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CounterCashierFNIsRequired")); } if ((workFlow != null && workFlow.CurrentState.Name == WorkFlowStateFlag.WaitVerify) && advanceEditableField.Contains(AdvanceFieldGroup.ExchangeRateForPerDiemCalculation) && avAdvanceDoc.PerDiemExRateUSD < 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExchangeRateforPerDiemCalculationIsRequired")); } } // Validate Request date of advance if (avAdvanceDoc.RequestDateOfAdvance.Equals(DateTime.MinValue)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofAdvanceIsRequired")); } else if ((workFlow != null && workFlow.CurrentState.Name == WorkFlowStateFlag.WaitVerify) && (!string.IsNullOrEmpty(rowAdvance["RequestDateOfAdvanceApproved"].ToString()) && avAdvanceDoc.RequestDateOfAdvance < rowAdvance.RequestDateOfAdvanceApproved)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofAdvanceMustMoreOrEqualThanApproved")); } else if (!avAdvanceDoc.RequestDateOfAdvance.Equals(DateTime.MinValue) && !avAdvanceDoc.RequestDateOfAdvance.Equals(DateTime.MaxValue)) { if (DbHolidayProfileService.CheckDay(avAdvanceDoc.RequestDateOfAdvance, mode)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("SystemNotAllowRequestDateOfAdvanceOnHoliday")); } } // Validate Request date of advance if (avAdvanceDoc.DocumentID.DocumentID == -1 || workFlow.CurrentState.Name.Equals(WorkFlowStateFlag.Draft)) { if (avAdvanceDoc.RequestDateOfAdvance.Date.CompareTo(DateTime.Today) < 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofAdvanceMustBeLaterThanToday")); } } // Validate Request date of Remittance if (avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MinValue)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofRemittanceIsRequired")); } // Validate Reason if (avAdvanceDoc.RequestDateOfRemittance.CompareTo(avAdvanceDoc.DueDateOfRemittance) > 0) { if (string.IsNullOrEmpty(avAdvanceDoc.Reason)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReasonIsRequired")); } } // Validate request date of remittance ; check request date between advance date and advance date + x Day // use maxValue ในการ check ถ้าส่งมาเป้น max value แปลว่า วันที่เลือกมาอยู่นอกช่วงที่กำหนด if (avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MaxValue)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofRemittanceIsNotIntime")); } else if (!avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MaxValue) && !avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MinValue)) { if (DbHolidayProfileService.CheckDay(avAdvanceDoc.RequestDateOfRemittance, mode)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("SystemNotAllowRequestDateOfRemittanceOnHoliday")); } } if (!errors.IsEmpty) { throw new ServiceValidationException(errors); } rowAdvance.DocumentID = avAdvanceDoc.DocumentID.DocumentID; if (avAdvanceDoc.TADocumentID.HasValue) { rowAdvance.TADocumentID = avAdvanceDoc.TADocumentID.Value; } else { rowAdvance.SetTADocumentIDNull(); } if (avAdvanceDoc.PBID != null) { rowAdvance.PBID = avAdvanceDoc.PBID.Pbid; } else { rowAdvance.SetPBIDNull(); } rowAdvance.AdvanceType = avAdvanceDoc.AdvanceType; if (avAdvanceDoc.ServiceTeamID != null) { rowAdvance.ServiceTeamID = avAdvanceDoc.ServiceTeamID.ServiceTeamID; } else { rowAdvance.SetServiceTeamIDNull(); } rowAdvance.RequestDateOfAdvance = avAdvanceDoc.RequestDateOfAdvance; rowAdvance.DueDateOfRemittance = avAdvanceDoc.DueDateOfRemittance; rowAdvance.RequestDateOfRemittance = avAdvanceDoc.RequestDateOfRemittance; if (avAdvanceDoc.ArrivalDate != null) { rowAdvance.ArrivalDate = avAdvanceDoc.ArrivalDate.Value; } else { rowAdvance.ArrivalDate = DateTime.MinValue; } rowAdvance.Reason = avAdvanceDoc.Reason; if (workFlow == null || workFlow.CurrentState.Name == WorkFlowStateFlag.Draft) { rowAdvance.PerDiemExRateUSD = 0; } else { rowAdvance.PerDiemExRateUSD = Math.Round((decimal)avAdvanceDoc.PerDiemExRateUSD, 5, MidpointRounding.AwayFromZero); } rowAdvance.Amount = Math.Round((decimal)avAdvanceDoc.Amount, 2, MidpointRounding.AwayFromZero); rowAdvance.RemittanceAmount = Math.Round((decimal)avAdvanceDoc.RemittanceAmount, 2, MidpointRounding.AwayFromZero); rowAdvance.ExpenseAmount = Math.Round((decimal)avAdvanceDoc.ExpenseAmount, 2, MidpointRounding.AwayFromZero); rowAdvance.Active = avAdvanceDoc.Active; rowAdvance.CreBy = UserAccount.UserID; rowAdvance.CreDate = DateTime.Now; rowAdvance.UpdBy = UserAccount.UserID; rowAdvance.UpdDate = DateTime.Now; rowAdvance.UpdPgm = UserAccount.CurrentProgramCode; if (avAdvanceDoc.IsRepOffice.HasValue) { rowAdvance.IsRepOffice = avAdvanceDoc.IsRepOffice.Value; } if (avAdvanceDoc.MainCurrencyID.HasValue && avAdvanceDoc.MainCurrencyID.Value > 0) { rowAdvance.MainCurrencyID = avAdvanceDoc.MainCurrencyID.Value; } else { rowAdvance.SetMainCurrencyIDNull(); } if (avAdvanceDoc.MainCurrencyAmount.HasValue) { rowAdvance.MainCurrencyAmount = (decimal)avAdvanceDoc.MainCurrencyAmount.Value; } else { rowAdvance.SetMainCurrencyAmountNull(); } if (avAdvanceDoc.ExchangeRateForLocalCurrency.HasValue) { rowAdvance.ExchangeRateForLocalCurrency = (decimal)avAdvanceDoc.ExchangeRateForLocalCurrency.Value; } else { rowAdvance.SetExchangeRateForLocalCurrencyNull(); } if (avAdvanceDoc.ExchangeRateMainToTHBCurrency.HasValue) { rowAdvance.ExchangeRateMainToTHBCurrency = (decimal)avAdvanceDoc.ExchangeRateMainToTHBCurrency.Value; } else { rowAdvance.SetExchangeRateMainToTHBCurrencyNull(); } if (avAdvanceDoc.LocalCurrencyAmount.HasValue) { rowAdvance.LocalCurrencyAmount = (decimal)avAdvanceDoc.LocalCurrencyAmount.Value; } else { rowAdvance.SetLocalCurrencyAmountNull(); } rowAdvance.EndEdit(); }
public void UpdateFixedDocumentTransaction(FixedAdvanceDocument fixedAvAdvanceDoc, Guid txid) { DateTime dateAndTime = DateTime.Now; DateTime CurDate = dateAndTime.Date; IList <object> fixedadvanceEditableField = new List <object>(); string mode = string.Empty; mode = "DM"; if (fixedAvAdvanceDoc.DocumentID != null) { fixedadvanceEditableField = GetEditableFields(fixedAvAdvanceDoc.DocumentID.DocumentID); } Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); FixedAdvanceDataSet ds = (FixedAdvanceDataSet)TransactionService.GetDS(txid); FixedAdvanceDataSet.FixedAdvanceDocumentRow rowFixedAdvance = (FixedAdvanceDataSet.FixedAdvanceDocumentRow)ds.FixedAdvanceDocument.FindByFixedAdvanceID(fixedAvAdvanceDoc.FixedAdvanceID); SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(fixedAvAdvanceDoc.DocumentID.DocumentID); FixedAdvanceDataSet.DocumentRow rowDocument = (FixedAdvanceDataSet.DocumentRow)ds.Document.FindByDocumentID(rowFixedAdvance.DocumentID); rowFixedAdvance.BeginEdit(); // Validate Amount. Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(fixedAvAdvanceDoc.PBID == null ? 0 : fixedAvAdvanceDoc.PBID.Pbid); #region Validate value if (workFlow == null) { if (fixedAvAdvanceDoc.NetAmount > 0) { if (fixedAvAdvanceDoc.PaymentType == "CA") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Can't receiv payment type cash.")); } } else { if (fixedAvAdvanceDoc.PaymentType == "CQ") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return payment can't receiv payment type cheque.")); } } if (String.IsNullOrEmpty(fixedAvAdvanceDoc.PaymentType)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } if (fixedAvAdvanceDoc.Amount == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("PleaseFillAmount")); } if (String.IsNullOrEmpty(fixedAvAdvanceDoc.Objective)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ObjectiveIsRequired")); } if (fixedAvAdvanceDoc.EffectiveFromDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromdateOverEffectiveTodate")); } if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired")); } else { if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom")); } if (fixedAvAdvanceDoc.RequestDate < CurDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); } if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } if (fixedAvAdvanceDoc.PaymentType == "CQ" && (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } if (fixedAvAdvanceDoc.PaymentType == "CA" && (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } if (fixedAvAdvanceDoc.FixedAdvanceType == 1) { if (fixedAvAdvanceDoc.EffectiveFromDate < CurDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromIsLessThanToday")); } } else { if (fixedAvAdvanceDoc.RefFixedAdvanceID == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RefFixedAdvanceIsRequired")); } } } else { if (workFlow.CurrentState.Name == "Outstanding") { if (fixedAvAdvanceDoc.ReturnRequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReturnDateIsRequired")); } else { if (fixedAvAdvanceDoc.ReturnRequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOverRequestDate")); } if (fixedAvAdvanceDoc.ReturnRequestDate < CurDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); } if (fixedAvAdvanceDoc.ReturnRequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } if (String.IsNullOrEmpty(fixedAvAdvanceDoc.ReturnPaymentType)) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else { if (fixedAvAdvanceDoc.ReturnPBID == null || fixedAvAdvanceDoc.ReturnPBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return Counter Cashier is Required.")); } } if (fixedAvAdvanceDoc.ReturnPaymentType == "CQ") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return payment can't receiv payment type cheque.")); } } else if (workFlow.CurrentState.Name == "WaitReturnComplete") { /*N-Addnew*/ if (fixedAvAdvanceDoc.ReturnPaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return Payment Type is Required.")); } else { if (fixedAvAdvanceDoc.ReturnPBID == null || fixedAvAdvanceDoc.ReturnPBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return Counter Cashier is Required.")); } } } else if (workFlow.CurrentState.Name == "WaitReturn") { /*N-Addnew*/ if (fixedAvAdvanceDoc.FixedAdvanceType == 1) { /*New*/ if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else if (fixedAvAdvanceDoc.PaymentType == "CQ") { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } /*check change Requestdate*/ if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired")); } else { if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom")); } if (fixedAvAdvanceDoc.RequestDate < CurDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); } if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } } else { /*Adjust*/ if (fixedAvAdvanceDoc.NetAmount < 0) { /*PaybackCompany*/ if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } } else { if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else if (fixedAvAdvanceDoc.PaymentType == "CQ") { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } } } /*check change Requestdate*/ if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired")); } else { if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom")); } if (fixedAvAdvanceDoc.RequestDate < CurDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); } if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } } else if (workFlow.CurrentState.Name == "WaitVerify") { /*N-Addnew*/ //check verifyer edit valueCounter Cashier is Required. if (fixedAvAdvanceDoc.FixedAdvanceType == 1) { /*New*/ if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else if (fixedAvAdvanceDoc.PaymentType == "CQ") { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } /*check change Requestdate*/ if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired")); } else { if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom")); } //if (fixedAvAdvanceDoc.RequestDate < CurDate) //{ // errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); //} if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } } else { /*Adjust*/ if (fixedAvAdvanceDoc.NetAmount < 0) { /*PaybackCompany*/ if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } } else { if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else if (fixedAvAdvanceDoc.PaymentType == "CQ") { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } } if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired")); } else { if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom")); } //if (fixedAvAdvanceDoc.RequestDate < CurDate) //{ // errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); //} if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } } } else { if (fixedAvAdvanceDoc.EffectiveFromDate < CurDate && fixedAvAdvanceDoc.FixedAdvanceType == 1) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromIsLessThanToday")); } if (fixedAvAdvanceDoc.EffectiveFromDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromdateOverEffectiveTodate")); } /*check change Requestdate*/ if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired")); } else { if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom")); } if (fixedAvAdvanceDoc.RequestDate < CurDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday")); } if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate")); } } if (fixedAvAdvanceDoc.RefFixedAdvanceID == 0 && fixedAvAdvanceDoc.FixedAdvanceType == 2) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RefFixedAdvanceIsRequired")); } if (fixedAvAdvanceDoc.NetAmount < 0) { /*PaybackCompany*/ if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } } else { if (fixedAvAdvanceDoc.PaymentType == "") { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required.")); } else if (fixedAvAdvanceDoc.PaymentType == "CQ") { if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required.")); } } } } } var result = fixedAvAdvanceDoc.EffectiveToDate - fixedAvAdvanceDoc.EffectiveFromDate; //var a = Convert.ToString(result.Days); //DateTime datenow = DateTime.Now; //DateTime setyearnow = new DateTime(datenow.Year, 1, 1); /*N-edited*/ DateTime setyearnow = DateTime.Now; DateTime setaddmonth = setyearnow.AddMonths(int.Parse(ParameterServices.FixedAdvanceConfigEffectiveDate)); var result2 = setaddmonth - setyearnow; int paramdate = result2.Days; if (Convert.ToInt32(result.Days) > paramdate) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveDateToIsOverMaximumRange")); } if (!errors.IsEmpty) { throw new ServiceValidationException(errors); } #endregion rowFixedAdvance.DocumentID = fixedAvAdvanceDoc.DocumentID.DocumentID; if (fixedAvAdvanceDoc.PBID != null) { rowFixedAdvance.PBID = fixedAvAdvanceDoc.PBID.Pbid; } else { rowFixedAdvance.SetPBIDNull(); } if (fixedAvAdvanceDoc.ReturnPBID != null) { rowFixedAdvance.ReturnPBID = fixedAvAdvanceDoc.ReturnPBID.Pbid; } else { rowFixedAdvance.SetReturnPBIDNull(); } if (fixedAvAdvanceDoc.ServiceTeamID != null) { rowFixedAdvance.ServiceTeamID = fixedAvAdvanceDoc.ServiceTeamID.ServiceTeamID; } else { rowFixedAdvance.SetServiceTeamIDNull(); } if (fixedAvAdvanceDoc.ReturnServiceTeamID != null) { rowFixedAdvance.ReturnServiceTeamID = fixedAvAdvanceDoc.ReturnServiceTeamID.ServiceTeamID; } else { rowFixedAdvance.SetReturnServiceTeamIDNull(); } if (fixedAvAdvanceDoc.RefFixedAdvanceID != null) { rowFixedAdvance.RefFixedAdvanceID = (long)fixedAvAdvanceDoc.RefFixedAdvanceID; } else { rowFixedAdvance.SetRefFixedAdvanceIDNull(); } rowFixedAdvance.FixedAdvanceType = fixedAvAdvanceDoc.FixedAdvanceType; rowFixedAdvance.PaymentType = fixedAvAdvanceDoc.PaymentType; rowFixedAdvance.ReturnPaymentType = fixedAvAdvanceDoc.ReturnPaymentType; rowFixedAdvance.FixedAdvanceBankAccount = fixedAvAdvanceDoc.FixedAdvanceBankAccount; rowFixedAdvance.RequestDate = fixedAvAdvanceDoc.RequestDate; if (fixedAvAdvanceDoc.ReturnRequestDate != null) { rowFixedAdvance.ReturnRequestDate = (DateTime)fixedAvAdvanceDoc.ReturnRequestDate; } else { rowFixedAdvance.SetReturnRequestDateNull(); } if (fixedAvAdvanceDoc.BaseLineDateReturn != null) { rowFixedAdvance.BaseLineDateReturn = (DateTime)fixedAvAdvanceDoc.BaseLineDateReturn; } else { rowFixedAdvance.SetBaseLineDateReturnNull(); } if (fixedAvAdvanceDoc.PaymentMethodIDReturn != null) { rowFixedAdvance.PaymentMethodIDReturn = (long)fixedAvAdvanceDoc.PaymentMethodIDReturn; } else { rowFixedAdvance.SetPaymentMethodIDReturnNull(); } if (fixedAvAdvanceDoc.PostingDateReturn != null) { rowFixedAdvance.PostingDateReturn = (DateTime)fixedAvAdvanceDoc.PostingDateReturn; } rowFixedAdvance.BranchCodeReturn = fixedAvAdvanceDoc.BranchCodeReturn; rowFixedAdvance.EffectiveFromDate = fixedAvAdvanceDoc.EffectiveFromDate; rowFixedAdvance.EffectiveToDate = fixedAvAdvanceDoc.EffectiveToDate; rowFixedAdvance.Objective = fixedAvAdvanceDoc.Objective; rowFixedAdvance.Amount = Math.Round((decimal)fixedAvAdvanceDoc.Amount, 2, MidpointRounding.AwayFromZero); rowFixedAdvance.NetAmount = Math.Round((decimal)fixedAvAdvanceDoc.NetAmount, 2, MidpointRounding.AwayFromZero); rowFixedAdvance.Active = fixedAvAdvanceDoc.Active; rowFixedAdvance.CreBy = UserAccount.UserID; rowFixedAdvance.CreDate = DateTime.Now; rowFixedAdvance.UpdBy = UserAccount.UserID; rowFixedAdvance.UpdDate = DateTime.Now; rowFixedAdvance.UpdPgm = UserAccount.CurrentProgramCode; rowFixedAdvance.EndEdit(); }