示例#1
0
        private string ShowMileagePopup(string mode)
        {
            ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            DataRow[] drs = expDs.FnExpenseMileage.Select(string.Format(" ExpenseID = {0}", this.ExpDocumentID));
            ExpenseDataSet.FnExpenseDocumentRow row = expDs.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            string url = string.Empty;

            if ((expDs.FnExpenseMileage != null) && (expDs.FnExpenseMileage.Rows.Count > 0))
            {
                if (drs.Length > 0)
                {
                    url = String.Format(string.Concat(MileageURL, "&mileageId={3}&docId={4}&cp={5}"), this.TransactionId, this.ExpDocumentID, this.DocumentType, drs[0]["ExpenseMileageID"], row.DocumentID, Request.QueryString["cp"]);
                }
                else
                {
                    url = String.Format(string.Concat(MileageURL, "&docId={3}&cp={4}"), this.TransactionId, this.ExpDocumentID, this.DocumentType, row.DocumentID, Request.QueryString["cp"]).Replace("[mode]", FlagEnum.NewFlag);
                }
            }
            else
            {
                url = String.Format(string.Concat(MileageURL, "&docId={3}&cp={4}"), this.TransactionId, this.ExpDocumentID, this.DocumentType, row.DocumentID, Request.QueryString["cp"]).Replace("[mode]", FlagEnum.NewFlag);
            }

            return(url.Replace("[mode]", mode));
        }
        public long AddNewExpenseDocumentOnTransaction(FnExpenseDocument exp, Guid txId)
        {
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.DocumentRow docRow = ds.Document.NewDocumentRow();


            ExpenseDataSet.FnExpenseDocumentRow expRow = ds.FnExpenseDocument.NewFnExpenseDocumentRow();
            expRow.DocumentID = docRow.DocumentID;
            ds.FnExpenseDocument.AddFnExpenseDocumentRow(expRow);

            return(expRow.ExpenseID);
        }
示例#3
0
        public void Initialize(Guid txID, long documentID, string initFlag)
        {
            this.TransactionId = txID;
            this.ExpDocumentID = documentID;
            this.InitialFlag   = initFlag;

            ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow expenseDocumentRow = expDs.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            this.DocumentID = expenseDocumentRow.DocumentID;
            this.InitialControl();
            //this.BindControl();
        }
        protected void ctlRemittanceGridview_DataBound(object sender, EventArgs e)
        {
            ExpenseDataSet expenseDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow row = expenseDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            SS.Standard.WorkFlow.DTO.WorkFlow   wf  = null;
            int Ordinal = 0;

            if (Request["wfid"] != null)
            {
                WorkFlowID   = UIHelper.ParseLong(Request["wfid"].ToString());
                wf           = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(WorkFlowID);
                CurrentState = wf.CurrentState.Name;
                Ordinal      = wf.CurrentState.Ordinal;
            }
            DbCurrency mainCurrency = null;

            if (!row.IsMainCurrencyIDNull())
            {
                mainCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(row.MainCurrencyID);
            }
            if (mainCurrency != null)
            {
                ctlRemittanceGridview.Columns[7].HeaderText = string.Format(GetProgramMessage("ctlLblRemittanceMainAmount"), "(" + mainCurrency.Symbol + ")");
            }

            string expenseType = FnExpenseDocumentService.GetExpenseType(this.ExpDocumentID, this.TransactionId);
            bool   isRepOffice = row.IsIsRepOfficeNull() ? false : row.IsRepOffice;

            if (!expenseType.Equals(ZoneType.Domestic))
            {
                if (isRepOffice)
                {
                    if (CurrentState.Equals(WorkFlowStateFlag.WaitVerify) || Ordinal > 5)
                    {
                        ctlRemittanceGridview.Columns[7].Visible = true;
                        ctlRemittanceGridview.Columns[8].Visible = true;
                    }
                    else
                    {
                        ctlRemittanceGridview.Columns[7].Visible = true;
                        ctlRemittanceGridview.Columns[8].Visible = false;
                    }
                }
                else
                {
                    ctlRemittanceGridview.Columns[7].Visible = false;
                    ctlRemittanceGridview.Columns[8].Visible = true;
                }
            }
        }
        public void ShowPaymentInfo()
        {
            ExpenseDataSet expDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow expRow = expDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            long          tempDocumentID = expRow.DocumentID;
            int           status         = 2; // FnAutoPayment Success -> Status = 2
            FnAutoPayment payment        = ScgeAccountingQueryProvider.FnAutoPaymentQuery.GetFnAutoPaymentSuccessByDocumentID(tempDocumentID, status);
            StringBuilder paymentInfo    = new StringBuilder();

            if (payment != null)
            {
                if (ctlDdlPaymentType.SelectedValue.Equals(PaymentType.TR))
                {
                    if (payment.PaymentDate.HasValue)
                    {
                        ctlDateLabel.Visible = true;
                    }
                    ctlDate.Text = String.Format(" :{0} ,", UIHelper.BindDate(payment.PaymentDate));
                    if (!string.IsNullOrEmpty(payment.ChequeBankName))
                    {
                        ctlBankNameLabel.Visible = true;
                    }
                    ctlBankName.Text = String.Format(" :{0} ,", payment.ChequeBankName);
                    if (!string.IsNullOrEmpty(payment.PayeeBankAccountNumber))
                    {
                        ctlAccountBankNameLabel.Visible = true;
                    }
                    ctlAccountBankName.Text = String.Format(" :{0} ", payment.PayeeBankAccountNumber);
                }
                if (ctlDdlPaymentType.SelectedValue.Equals(PaymentType.CQ))
                {
                    if (payment.ChequeDate.HasValue)
                    {
                        ctlDateLabel.Visible = true;
                    }
                    ctlDate.Text = String.Format(" :{0} ,", UIHelper.BindDate(payment.ChequeDate));
                    if (!string.IsNullOrEmpty(payment.ChequeBankName))
                    {
                        ctlBankNameLabel.Visible = true;
                    }
                    ctlBankName.Text = String.Format(" :{0} ,", payment.ChequeBankName);
                    if (!string.IsNullOrEmpty(payment.ChequeNumber.Trim()))
                    {
                        ctlAccountBankNameLabel.Visible = true;
                    }
                    ctlAccountBankName.Text = String.Format(" :{0} ", payment.ChequeNumber);
                }
            }
        }
        public void ValdationMileageRateByDataset(Guid txId, long expDocumentID, bool isCopy)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseMileageRow  mileageRow = (ExpenseDataSet.FnExpenseMileageRow)ds.FnExpenseMileage.Select("ExpenseID = " + expDocumentID).FirstOrDefault();
            ExpenseDataSet.FnExpenseDocumentRow expRow     = ds.FnExpenseDocument.FindByExpenseID(expDocumentID);

            /*check owner employee*/

            if (mileageRow != null && mileageRow.Owner != "COM")
            {
                FnExpenseMileage mileage = new FnExpenseMileage();
                mileage.IsOverrideLevel = mileageRow.IsOverrideLevel;
                mileage.First100KmRate  = Convert.ToDouble(mileageRow.First100KmRate);
                mileage.Exceed100KmRate = Convert.ToDouble(mileageRow.Exceed100KmRate);
                mileage.TypeOfCar       = mileageRow.TypeOfCar;
                if (mileageRow.IsOverrideLevel == true)
                {
                    if (!mileageRow.IsOverrideCompanyIdNull())
                    {
                        mileage.OverrideCompanyId = mileageRow.OverrideCompanyId;
                    }
                    if (!String.IsNullOrEmpty(mileageRow.OverrideUserPersonalLevelCode))
                    {
                        mileage.OverrideUserPersonalLevelCode = mileageRow.OverrideUserPersonalLevelCode;
                    }
                }
                else
                {
                    if (!mileageRow.IsCurrentCompanyIdNull())
                    {
                        mileage.CurrentCompanyId = mileageRow.CurrentCompanyId;
                    }
                    if (!mileageRow.IsCurrentUserPersonalLevelCodeNull())
                    {
                        mileage.CurrentUserPersonalLevelCode = mileageRow.CurrentUserPersonalLevelCode;
                    }
                }

                DataRow[] row = ds.FnExpenseMileageItem.Select("ExpenseMileageID = " + mileageRow.ExpenseMileageID);

                foreach (DataRow result in row)
                {
                    ValidateMileageRateData(mileage, Convert.ToDateTime(result["TravelDate"]));
                }
            }
        }
        public void ClearAdvanceGridview()
        {
            ExpenseDataSet expenseDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow  expRow = expenseDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            ExpenseDataSet.FnExpenseAdvanceRow[] rows   = (ExpenseDataSet.FnExpenseAdvanceRow[])expenseDS.FnExpenseAdvance.Select();

            foreach (ExpenseDataSet.FnExpenseAdvanceRow row in rows)
            {
                double totalAmount = FnExpenseDocumentService.DeleteExpenseAdvanceFromTransaction(this.TransactionId, row.AdvanceID, (double)expRow.TotalAdvance);
                FnExpenseDocumentService.SetTotalAdvance(this.TransactionId, 0, totalAmount);
                FnExpenseDocumentService.RefreshRemittance(this.TransactionId, this.ExpDocumentID);
                row.Delete();
            }

            this.BindAdvanceGridView();
        }
示例#8
0
        private string ShowExpenseGeneral(long invoiceId)
        {
            string         url;
            ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow expenseDocumentRow = expDs.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            ExpenseDataSet.FnExpenseInvoiceRow  invoiceRows        = expDs.FnExpenseInvoice.FindByInvoiceID(invoiceId);
            if (invoiceRows != null)
            {
                url = String.Format(string.Concat(invoiceURL, "&invId={4}"), this.TransactionId, this.ExpDocumentID, this.DocumentType, expenseDocumentRow.DocumentID, invoiceId);
            }
            else
            {
                url = String.Format(invoiceURL, this.TransactionId, this.ExpDocumentID, this.DocumentType, expenseDocumentRow.DocumentID);
            }
            return(url);
        }
        protected void Advance_OnObjectLookUpCalling(object sender, ObjectLookUpCallingEventArgs e)
        {
            UserControls.LOV.AV.AdvanceLookup advanceLookUp = sender as UserControls.LOV.AV.AdvanceLookup;
            ExpenseDataSet expenseDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow row = expenseDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);

            if (!row.IsMainCurrencyIDNull())
            {
                this.MainCurrencyID = row.MainCurrencyID;
            }

            if (!row.IsPBIDNull())
            {
                this.PBID = row.PBID;
            }

            this.IsRepOffice = row.IsIsRepOfficeNull() ? false : row.IsRepOffice;

            advanceLookUp.CompanyID   = CompanyID;   // UIHelper.ParseLong(((LOV.SCG.DB.CompanyField)this.Parent.Parent.Parent.Parent.FindControl("ctlCompanyField")).CompanyID);
            advanceLookUp.RequesterID = RequesterID; // UIHelper.ParseLong(((ActorData)this.Parent.Parent.Parent.Parent.FindControl("ctlRequesterData")).UserID);
            advanceLookUp.AdvanceType = FnExpenseDocumentService.GetExpenseType(this.ExpDocumentID, this.TransactionId);
            advanceLookUp.IsRelateWithRemittanceButNotInExpense = true;
            advanceLookUp.PBID           = this.PBID;
            advanceLookUp.MainCurrencyID = this.MainCurrencyID;
            advanceLookUp.IsRepOffice    = this.IsRepOffice;
            if (!string.IsNullOrEmpty(Request.Params["wfid"]) && UIHelper.ParseInt(Request.Params["wfid"]) > 0)
            {
                long workFlowID = UIHelper.ParseLong(Request.Params["wfid"]);

                SS.Standard.WorkFlow.DTO.WorkFlow wf = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workFlowID);
                if (wf != null && wf.CurrentState != null && wf.CurrentState.Name != null && wf.CurrentState.Name.Equals(WorkFlowStateFlag.Draft))
                {
                    advanceLookUp.CurrentUserID = UserAccount.UserID;
                }
            }
            else
            {
                advanceLookUp.CurrentUserID = UserAccount.UserID;
            }
        }
示例#10
0
        public void BindSimpleExpense(string expenseType, long userId, bool refreshHeader)
        {
            this.refreshHeaderGrid = refreshHeader;
            ExpenseRecommend recommand = new ExpenseRecommend();

            recommand.UserID     = userId;
            recommand.LanguageID = UserAccount.CurrentLanguageID;

            SuUser requester = QueryProvider.SuUserQuery.FindByIdentity(userId);

            if (requester != null)
            {
                CompanyIDRequester = requester.Company.CompanyID;
            }

            this.DocumentType = expenseType;

            if (expenseType.Equals(ZoneType.Domestic))
            {
                recommand.IsDomesticRecommend = true;
            }
            else if (expenseType.Equals(ZoneType.Foreign))
            {
                recommand.IsForegnRecommend = true;
            }

            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow expRow = ds.FnExpenseDocument.FindByExpenseID(ExpDocumentID);

            if (!expRow.IsLocalCurrencyIDNull())
            {
                this.FinalCurrencyID = expRow.LocalCurrencyID;
            }

            ctlSimpleExpenseGridView.DataSource = ScgDbQueryProvider.DbAccountQuery.FindExpenseRecommendByExpenseGroup(recommand);
            ctlSimpleExpenseGridView.DataBind();
            SetCurrentSimpleExpense();
            ctlUpdateSimpleExpenseGridView.Update();
        }
        public void BindControl(bool refreshHeader)
        {
            this.refreshHeaderGrid = refreshHeader;
            if (InitialFlag.Equals(FlagEnum.ViewFlag))
            {
                ctlAddAdvance.Enabled = false;
                ctlTANoLookup.Visible = false;
                ctlDeleteTA.Visible   = false;
            }
            else
            {
                ctlAddAdvance.Enabled = true;
                ctlTANoLookup.Visible = true;
                ctlDeleteTA.Visible   = true;
            }

            if (this.DocumentType.Equals(ZoneType.Domestic))
            {
                this.IsDomestic = true;
                ctlRemittanceGridview.Visible = false;
                ctlTALookup.TravelBy          = TravellBy.Domestic;
                ctlControlPanel.Visible       = false;
            }
            else
            {
                this.IsDomestic = false;
                ctlRemittanceGridview.Visible = true;
                ctlTALookup.TravelBy          = TravellBy.Foreign;
                ctlControlPanel.Visible       = true;
            }

            ExpenseDataSet expenseDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow row = expenseDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            if (!row.IsTADocumentIDNull())
            {
                ctlTANoLookup.Enabled = false;
                TADocument ta = ScgeAccountingQueryProvider.TADocumentQuery.FindByIdentity(row.TADocumentID);
                SS.Standard.WorkFlow.DTO.WorkFlow wf = SS.Standard.WorkFlow.Query.WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(ta.DocumentID.DocumentID);
                ctlAddAdvance.Enabled         = false;
                ctlTANoLabel.Visible          = false;
                ctlTALinkButton.Text          = ta.DocumentID.DocumentNo;
                ctlTALinkButton.OnClientClick = "window.open('../Programs/DocumentView.aspx?wfid=" + wf.WorkFlowID.ToString() + "')";
                ctlBusinessChk.Checked        = !(row.IsIsBusinessPurposeNull() || row.IsBusinessPurpose == false);
                ctlTrainingChk.Checked        = !(row.IsIsTrainningPurposeNull() || row.IsTrainningPurpose == false);
                ctlOtherChk.Checked           = !(row.IsIsOtherPurposeNull() || row.IsOtherPurpose == false);
                ctlOther.Text   = row.IsOtherPurposeDescriptionNull() ? String.Empty : row.OtherPurposeDescription;
                ctlCountry.Text = row.IsCountryNull() ? String.Empty : row.Country;

                if (!row.IsFromDateNull())
                {
                    ctlFromDateCal.Value = row.FromDate;
                }
                if (!row.IsToDateNull())
                {
                    ctlToDateCal.Value = row.ToDate;
                }

                ctlPersonLevel.Text            = row.IsPersonalLevelNull() ? String.Empty : row.PersonalLevel;
                ctlExchangeRateForPerdiem.Text = row.IsExchangeRateForUSDAdvanceNull() ? String.Empty : row.ExchangeRateForUSDAdvance.ToString();
            }
            else
            {
                ResetTADataZone();
                if (expenseDS.FnExpenseAdvance.Rows.Count > 0)
                {
                    ctlTANoLookup.Enabled = false;
                    ctlDeleteTA.Enabled   = false;
                }
            }

            BindAdvanceGridView();
            BindRemittanceGridview();
            ctlUpdatePanelExpenseGeneral.Update();
        }
示例#12
0
        public void PrepareDataToDataset(ExpenseDataSet ds, long perdiemId)
        {
            ExpenseDataSet.FnExpensePerdiemRow  row    = ds.FnExpensePerdiem.FindByExpensePerdiemID(perdiemId);
            ExpenseDataSet.FnExpenseDocumentRow expRow = ds.FnExpenseDocument.FindByExpenseID(row.ExpenseID);
            string PerdiemType = expRow.ExpenseType;

            IList <FnExpensePerdiemItem> perdiemItemList = ScgeAccountingQueryProvider.FnExpensePerdiemItemQuery.GetPerdiemItemByPerdiemID(perdiemId);

            decimal totalNetDay = 0;

            foreach (FnExpensePerdiemItem item in perdiemItemList)
            {
                // Set data to perdiem item row in Dataset.
                ExpenseDataSet.FnExpensePerdiemItemRow itemRow = ds.FnExpensePerdiemItem.NewFnExpensePerdiemItemRow();
                itemRow.PerdiemItemID    = item.PerdiemItemID;
                itemRow.ExpensePerdiemID = item.ExpensePerdiem.ExpensePerdiemID;
                itemRow.FromDate         = item.FromDate.Value;
                itemRow.FromTime         = ConvertDateTime(item.FromDate.Value, item.FromTime.Value);
                itemRow.ToDate           = item.ToDate.Value;
                itemRow.ToTime           = ConvertDateTime(item.ToDate, item.ToTime);
                itemRow.AdjustedDay      = (decimal)item.AdjustedDay;
                itemRow.NetDay           = (decimal)item.NetDay;

                totalNetDay += itemRow.NetDay;

                if (PerdiemType == ZoneType.Foreign)
                {
                    itemRow.HalfDay = (decimal)item.HalfDay;
                    itemRow.FullDay = (decimal)item.FullDay;
                    itemRow.SetCountryIDNull();
                    if (item.CountryID != null)
                    {
                        itemRow.CountryID = item.CountryID.Value;
                    }
                    itemRow.SetCountryZoneIDNull();
                    if (item.CountryZoneID != null)
                    {
                        itemRow.CountryZoneID = item.CountryZoneID.Value;
                    }
                }

                itemRow.Remark = item.Remark;


                itemRow.Active  = item.Active;
                itemRow.CreBy   = item.CreBy;
                itemRow.CreDate = item.CreDate;
                itemRow.UpdBy   = item.UpdBy;
                itemRow.UpdDate = item.UpdDate;
                itemRow.UpdPgm  = item.UpdPgm;

                // Add perdiem item row to documentDataset.
                ds.FnExpensePerdiemItem.AddFnExpensePerdiemItemRow(itemRow);
            }

            if (PerdiemType == ZoneType.Domestic)
            {
                row.TotalFullDayPerdiem       = totalNetDay;
                row.TotalFullDayPerdiemAmount = totalNetDay * row.FullDayPerdiemRate;
            }
        }
示例#13
0
        protected void ctlRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            string url = string.Empty;

            if (e.Item.DataItem != null)
            {
                ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(TransactionId);
                ExpenseDataSet.FnExpenseInvoiceRow  invoice            = (ExpenseDataSet.FnExpenseInvoiceRow)e.Item.DataItem;
                ExpenseDataSet.FnExpenseDocumentRow expenseDocumentRow = expDs.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);

                PopupCaller popupEdit       = (PopupCaller)e.Item.FindControl("ctlEditPopupCaller");
                PopupCaller popupView       = (PopupCaller)e.Item.FindControl("ctlViewPopupCaller");
                LinkButton  edit            = (LinkButton)e.Item.FindControl("ctlEdit");
                LinkButton  delete          = (LinkButton)e.Item.FindControl("ctlDelete");
                LinkButton  view            = (LinkButton)e.Item.FindControl("ctlView");
                Literal     totalBaseAmount = (Literal)e.Item.FindControl("ctlTotalAmount");
                Literal     totalNetAmount  = (Literal)e.Item.FindControl("ctlNetAmount");

                if (IsRepOffice)
                {
                    totalBaseAmount.Text = UIHelper.BindDecimal(invoice.TotalBaseAmountLocalCurrency.ToString());
                    totalNetAmount.Text  = UIHelper.BindDecimal(invoice.NetAmountLocalCurrency.ToString());
                }
                else
                {
                    totalBaseAmount.Text = UIHelper.BindDecimal(invoice.TotalBaseAmount.ToString());
                    totalNetAmount.Text  = UIHelper.BindDecimal(invoice.NetAmount.ToString());
                }

                if (!invoice.IsInvoiceDocumentTypeNull() && invoice.InvoiceDocumentType.Equals(InvoiceType.Perdiem))
                {
                    popupEdit.URL = ShowPerdiemPopup(FlagEnum.EditFlag, invoice.InvoiceID);
                    popupView.URL = ShowPerdiemPopup(FlagEnum.ViewFlag, invoice.InvoiceID);
                }
                if (!invoice.IsInvoiceDocumentTypeNull() && invoice.InvoiceDocumentType.Equals(InvoiceType.General))
                {
                    url           = ShowExpenseGeneral(invoice.InvoiceID);
                    popupEdit.URL = url.Replace("[mode]", FlagEnum.EditFlag);
                    popupView.URL = url.Replace("[mode]", FlagEnum.ViewFlag);
                }

                // Show Mileage.
                if (!invoice.IsInvoiceDocumentTypeNull() && invoice.InvoiceDocumentType.Equals(InvoiceType.Mileage))
                {
                    popupEdit.URL = ShowMileagePopup(FlagEnum.EditFlag);
                    popupView.URL = ShowMileagePopup(FlagEnum.ViewFlag);
                }

                SS.Standard.WorkFlow.DTO.WorkFlow workflow = SS.Standard.WorkFlow.Query.WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(this.DocumentID);

                if (InitialFlag.Equals(FlagEnum.ViewFlag))
                {
                    edit.Visible   = false;
                    delete.Visible = false;
                    view.Visible   = true;
                }
                else
                {
                    edit.Visible = true;
                    view.Visible = false;

                    if (!invoice.IsInvoiceDocumentTypeNull() && invoice.InvoiceDocumentType.Equals(InvoiceType.Mileage))
                    {
                        delete.Visible = false;
                    }
                    else
                    if (workflow != null && workflow.CurrentState.Name.Equals(WorkFlowStateFlag.Hold))
                    {
                        delete.Visible = false;
                    }
                    else
                    {
                        delete.Visible = true;
                    }
                }

                Literal seq = (Literal)e.Item.FindControl("ctlSeq");

                seq.Text += e.Item.ItemIndex + 1;

                BaseGridView gridview = (BaseGridView)e.Item.FindControl("ctlInvoiceItem");

                string filter = String.Format("InvoiceID = {0}", invoice.InvoiceID);
                gridview.DataSource = expDs.FnExpenseInvoiceItem.Select(filter);
                gridview.DataBind();
            }
        }
        public void AddExpenseValidationMileageItemOnTransaction(FnExpenseMileageItem expenseMileageItem, Guid txId, long expDocumentID)
        {
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseMileageRow  mileageRow = (ExpenseDataSet.FnExpenseMileageRow)ds.FnExpenseMileage.Select("ExpenseID = " + expDocumentID).FirstOrDefault();//.FindByExpenseMileageID(expenseMileageID);
            ExpenseDataSet.FnExpenseDocumentRow expRow     = ds.FnExpenseDocument.FindByExpenseID(expDocumentID);
            Spring.Validation.ValidationErrors  errors     = new Spring.Validation.ValidationErrors();

            if (expRow.ExpenseType == ZoneType.Domestic)
            {
                DataRow[] row = ds.FnExpenseMileageItem.Select("ExpenseMileageID = " + mileageRow.ExpenseMileageID);
                foreach (DataRow dataRow in row)
                {
                    long     id            = Convert.ToInt64(dataRow["expenseMileageItemID"]);
                    Double   carMeterStart = Convert.ToDouble(dataRow["CarMeterStart"]);
                    Double   carMeterEnd   = Convert.ToDouble(dataRow["CarMeterEnd"]);
                    DateTime travelDate    = Convert.ToDateTime(dataRow["TravelDate"]);

                    if (expenseMileageItem.ExpenseMileageItemID != id)
                    {
                        if (expenseMileageItem.TravelDate > travelDate)
                        {
                            if (expenseMileageItem.CarMeterStart < carMeterEnd)
                            {
                                if (expenseMileageItem.CarMeterStart < carMeterStart)
                                {
                                    errors.AddError("MileageItem.Error", new Spring.Validation.ErrorMessage("TravelDateNotMatchMileageItem"));
                                }
                                else
                                {
                                    errors.AddError("MileageItem.Error", new Spring.Validation.ErrorMessage("CarmeterIsDuplicate"));
                                }
                            }
                        }
                        else if (expenseMileageItem.TravelDate < travelDate)
                        {
                            if (expenseMileageItem.CarMeterEnd > carMeterStart)
                            {
                                if (expenseMileageItem.CarMeterStart > carMeterStart)
                                {
                                    errors.AddError("MileageItem.Error", new Spring.Validation.ErrorMessage("TravelDateIsDuplicate"));
                                }
                                else
                                {
                                    errors.AddError("MileageItem.Error", new Spring.Validation.ErrorMessage("CarmeterIsDuplicate"));
                                }
                            }
                        }
                        else
                        {
                            if (expenseMileageItem.CarMeterStart >= carMeterStart && expenseMileageItem.CarMeterStart < carMeterEnd)
                            {
                                errors.AddError("MileageItem.Error", new Spring.Validation.ErrorMessage("CarmeterIsDuplicate"));
                            }
                            else if (expenseMileageItem.CarMeterEnd > carMeterStart && expenseMileageItem.CarMeterStart <= carMeterStart)
                            {
                                errors.AddError("MileageItem.Error", new Spring.Validation.ErrorMessage("CarmeterIsDuplicate"));
                            }
                        }
                    }
                    if (!errors.IsEmpty)
                    {
                        throw new ServiceValidationException(errors);
                    }
                }
            }
        }
示例#15
0
        public void BindControl()
        {
            SS.Standard.WorkFlow.DTO.WorkFlow workflow = null;
            long workFlowID = 0;

            if (!string.IsNullOrEmpty(Request.Params["wfid"]) && UIHelper.ParseInt(Request.Params["wfid"]) > 0)
            {
                workFlowID = UIHelper.ParseLong(Request.Params["wfid"]);
                workflow   = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workFlowID);
            }

            if (DocumentType.Equals(ZoneType.Foreign) || this.IsRepOffice)
            {
                ctlAddMilage.Style["display"] = "none";
            }
            else
            {
                ctlAddMilage.Style["display"] = string.Empty;
            }

            if (!InitialFlag.Equals(FlagEnum.ViewFlag) && (workflow == null || (workflow != null && !workflow.CurrentState.Name.Equals(WorkFlowStateFlag.Hold))))
            {
                ctlAddGeneralExpense.Enabled = true;
                ctlAddPerdiem.Enabled        = true;
                ctlAddMilage.Enabled         = true;
            }
            else
            {
                ctlAddGeneralExpense.Enabled = false;
                ctlAddPerdiem.Enabled        = false;
                ctlAddMilage.Enabled         = false;
            }
            ctlSimpleExpense.DocumentType = this.DocumentType;
            ctlPerdiemPopupCaller.URL     = ShowPerdiemPopup(InitialFlag, null);
            ctlInvoicePopupCaller.URL     = String.Format(invoiceURL.Replace("[mode]", FlagEnum.NewFlag), this.TransactionId, this.ExpDocumentID, this.DocumentType, this.DocumentID, string.Empty);
            ctlMileagePopupCaller.URL     = ShowMileagePopup(InitialFlag);

            ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            ExpenseDataSet.FnExpenseDocumentRow expenseDocumentRow = expDs.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
            this.DocumentID = expenseDocumentRow.DocumentID;

            ctlDivExchangeRateLocalInfo.Style["display"] = "none";
            ctlDivExchangeRateMainInfo.Style["display"]  = "none";

            if (!InitialFlag.Equals(FlagEnum.NewFlag) && IsRepOffice)
            {
                try
                {
                    if ((workflow != null && workflow.CurrentState.Ordinal >= 5) && (UserAccount.IsAccountant || UserAccount.IsPayment))
                    {
                        string mainCurrencySymbol  = string.Empty;
                        string localCurrencySymbol = string.Empty;
                        if (!expenseDocumentRow.IsLocalCurrencyIDNull())
                        {
                            DbCurrency localCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(expenseDocumentRow.LocalCurrencyID);
                            localCurrencySymbol = localCurrency.Symbol;
                        }

                        if (!expenseDocumentRow.IsMainCurrencyIDNull())
                        {
                            DbCurrency mainCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(expenseDocumentRow.MainCurrencyID);
                            mainCurrencySymbol = mainCurrency.Symbol;
                        }

                        ctlExRateMainCurrencyLabel.Text = GetProgramMessage("DisplayExchangeRateInfo");
                        ctlExchangeRateMain.Text        = UIHelper.BindExchangeRate(expenseDocumentRow.IsExchangeRateMainToTHBCurrencyNull() ? string.Empty : expenseDocumentRow.ExchangeRateMainToTHBCurrency.ToString());
                        ctlExchangeRateMainUnit.Text    = CurrencySymbol.THB + "/" + mainCurrencySymbol;

                        ctlExRateLocalCurrencyLabel.Text = GetProgramMessage("DisplayExchangeRateInfo");
                        ctlExchangeRateLocal.Text        = UIHelper.BindExchangeRate(expenseDocumentRow.IsExchangeRateForLocalCurrencyNull() ? string.Empty : expenseDocumentRow.ExchangeRateForLocalCurrency.ToString());
                        ctlExchangeRateLocalUnit.Text    = localCurrencySymbol + "/" + mainCurrencySymbol;

                        ctlDivExchangeRateMainInfo.Style["display"] = "block";
                        if (!expenseDocumentRow.IsMainCurrencyIDNull() && !expenseDocumentRow.IsLocalCurrencyIDNull() && (expenseDocumentRow.MainCurrencyID != expenseDocumentRow.LocalCurrencyID))
                        {
                            ctlDivExchangeRateLocalInfo.Style["display"] = "block";
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        public void SaveExpenseValidationMileageItemOnTransaction(Guid txId, long expDocumentID, string showError, bool isCopy)
        {
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseMileageRow  mileageRow = (ExpenseDataSet.FnExpenseMileageRow)ds.FnExpenseMileage.Select("ExpenseID = " + expDocumentID).FirstOrDefault();
            ExpenseDataSet.FnExpenseDocumentRow expRow     = ds.FnExpenseDocument.FindByExpenseID(expDocumentID);
            Spring.Validation.ValidationErrors  errors     = new Spring.Validation.ValidationErrors();
            if (isCopy)
            {
                expDocumentID = -1;
            }

            if (mileageRow == null)
            {
                return;
            }

            if (expRow.ExpenseType == ZoneType.Domestic)
            {
                DataRow[] row = ds.FnExpenseMileageItem.Select("ExpenseMileageID = " + mileageRow.ExpenseMileageID);
                foreach (DataRow dataRow in row)
                {
                    Double   carMeterStart = Convert.ToDouble(dataRow["CarMeterStart"]);
                    Double   carMeterEnd   = Convert.ToDouble(dataRow["CarMeterEnd"]);
                    DateTime travelDate    = Convert.ToDateTime(dataRow["TravelDate"]);

                    ValidateMilage mileageItemLeft  = FnExpenseMileageItemQuery.GetMileageItemForValidationLeft(expRow.DocumentRow.RequesterID, mileageRow.CarLicenseNo, travelDate, expDocumentID);
                    ValidateMilage mileageItemRight = FnExpenseMileageItemQuery.GetMileageItemForValidationRight(expRow.DocumentRow.RequesterID, mileageRow.CarLicenseNo, travelDate, expDocumentID);
                    ValidateMilage checklength      = FnExpenseMileageItemQuery.GetMileageItemForValidationCheckLength(expRow.DocumentRow.RequesterID, mileageRow.CarLicenseNo, travelDate, expDocumentID, carMeterStart);
                    if (mileageItemLeft != null)
                    {
                        if (string.IsNullOrEmpty(mileageItemLeft.DocumentNo))
                        {
                            mileageItemLeft.DocumentNo = "Draft";
                        }

                        if (mileageItemLeft.CarMeterEnd > carMeterStart)
                        {
                            if (mileageItemLeft.CarMeterStart > carMeterStart)
                            {
                                if (showError == "Mileage")
                                {
                                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentInvalidDateTimeline", new object[] { mileageItemLeft.DocumentNo }));
                                }
                                else
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentInvalidDateTimeline", new object[] { mileageItemLeft.DocumentNo }));
                                }
                            }
                            else
                            {
                                if (showError == "Mileage")
                                {
                                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { mileageItemLeft.DocumentNo }));
                                }
                                else
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { mileageItemLeft.DocumentNo }));
                                }
                            }
                        }
                    }
                    if (mileageItemRight != null)
                    {
                        if (string.IsNullOrEmpty(mileageItemRight.DocumentNo))
                        {
                            mileageItemRight.DocumentNo = "Draft";
                        }

                        if (mileageItemRight.CarMeterStart < carMeterEnd)
                        {
                            if (mileageItemRight.CarMeterStart < carMeterStart)
                            {
                                if (showError == "Mileage")
                                {
                                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("MileageNotMatchAntherDocument", new object[] { mileageItemRight.DocumentNo }));
                                }
                                else
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentInvalidDateTimeline", new object[] { mileageItemRight.DocumentNo }));
                                }
                            }
                            else
                            {
                                if (showError == "Mileage")
                                {
                                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("MileageNotMatchAntherDocument", new object[] { mileageItemRight.DocumentNo }));
                                }
                                else
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { mileageItemRight.DocumentNo }));
                                }
                            }
                        }
                    }
                    if (checklength != null)
                    {
                        if (string.IsNullOrEmpty(checklength.DocumentNo))
                        {
                            checklength.DocumentNo = "Draft";
                        }

                        if (showError == "Mileage")
                        {
                            errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { checklength.DocumentNo }));
                        }
                        else
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { checklength.DocumentNo }));
                        }
                    }
                    else
                    {
                        ValidateMilage mileageItemEquals = FnExpenseMileageItemQuery.GetMileageItemForValidationEquals(expRow.DocumentRow.RequesterID, mileageRow.CarLicenseNo, travelDate, expDocumentID, carMeterStart);
                        if (mileageItemEquals != null)
                        {
                            if (string.IsNullOrEmpty(mileageItemEquals.DocumentNo))
                            {
                                mileageItemEquals.DocumentNo = "Draft";
                            }

                            if (mileageItemEquals.CarMeterStart < carMeterEnd)
                            {
                                if (showError == "Mileage")
                                {
                                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { mileageItemEquals.DocumentNo }));
                                }
                                else
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MileageAnotherDocumentDuplicateDateTimeline", new object[] { mileageItemEquals.DocumentNo }));
                                }
                            }
                        }
                    }
                    if (!errors.IsEmpty)
                    {
                        throw new ServiceValidationException(errors);
                    }
                }
            }
        }
        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 void ValidateInvoiceItem(Guid txId, long expenseId)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseDocumentRow      expRow   = expDs.FnExpenseDocument.FindByExpenseID(expenseId);
            ExpenseDataSet.DocumentRow               docRow   = expDs.Document.FindByDocumentID(expRow.DocumentID);
            ExpenseDataSet.FnExpenseInvoiceItemRow[] itemRows = (ExpenseDataSet.FnExpenseInvoiceItemRow[])expDs.FnExpenseInvoiceItem.Select();

            foreach (ExpenseDataSet.FnExpenseInvoiceItemRow row in itemRows)
            {
                string accountCode = string.Empty;
                if (!row.IsIOIDNull())
                {
                    DbInternalOrder io = ScgDbQueryProvider.DbIOQuery.FindByIdentity(row.IOID);
                    if (io == null || !io.CompanyID.HasValue || io.CompanyID.Value != docRow.CompanyID)
                    {
                        if (io == null)
                        {
                            io = new DbInternalOrder()
                            {
                                IONumber = "Unknown"
                            };
                        }
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("InternalOrder_Is_Invalid", new object[] { io.IONumber }));
                    }
                }
                if (!row.IsAccountIDNull())
                {
                    DbAccount account = ScgDbQueryProvider.DbAccountQuery.FindByIdentity(row.AccountID);


                    IList <VOAccountCompany> accountList = ScgDbQueryProvider.DbAccountCompanyQuery.FindAccountCompany(docRow.CompanyID, row.AccountID);
                    if (account == null || accountList.Count == 0)
                    {
                        if (account == null)
                        {
                            account = new DbAccount()
                            {
                                AccountCode = "Unknown"
                            };
                        }
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExpenseCode_Is_Invalid", new object[] { account.AccountCode }));
                    }
                    accountCode = account.AccountCode;
                }
                if (!row.IsCostCenterIDNull())
                {
                    DbCostCenter cost = ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(row.CostCenterID);

                    if (cost == null || cost.CompanyID == null || cost.CompanyID.CompanyID != docRow.CompanyID)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CostCenter_Is_Invalid", new object[] { cost.CostCenterCode }));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(accountCode))
                        {
                            DbAccount ac = ScgDbQueryProvider.DbAccountQuery.FindAccountByAccountCodeExpenseGroup(accountCode, null);
                            if (ac == null)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExpenseCode_Is_Invalid_With_Costcenter", new object[] { accountCode, cost.CostCenterCode }));
                            }
                        }
                    }
                }
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
        }
        public void UpdateMessageSummary()
        {
            ExpenseDataSet expDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            if (expDS != null)
            {
                ExpenseDataSet.FnExpenseDocumentRow expRow = expDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);

                if (!IsRepOffice)
                {
                    if (expRow.DifferenceAmount > (decimal)0)
                    {
                        ctlMsgSummary.Text          = GetProgramMessage("$AdditionalPayFromCompany$");
                        ctlDifferenceAmount.Visible = true;
                    }
                    else if (expRow.DifferenceAmount < (decimal)0)
                    {
                        ctlMsgSummary.Text          = GetProgramMessage("$PayBackToCompany$");
                        ctlDifferenceAmount.Visible = true;
                    }
                    else if (expRow.TotalAdvance > 0 && expRow.DifferenceAmount == (decimal)0)
                    {
                        ctlMsgSummary.Text          = GetProgramMessage("$CompleteClearing$");
                        ctlDifferenceAmount.Visible = false;
                    }

                    if (expRow.TotalAdvance == (decimal)0)
                    {
                        ctlTotalAdvance.Visible    = false;
                        ctlLblTotalAdvance.Visible = false;
                    }
                    else
                    {
                        ctlTotalAdvance.Visible    = true;
                        ctlLblTotalAdvance.Visible = true;
                    }
                    if (expRow.TotalRemittance == (decimal)0)
                    {
                        ctlTotalRemitted.Visible = false;
                        ctlRemitted.Visible      = false;
                    }
                    else
                    {
                        ctlTotalRemitted.Visible = true;
                        ctlRemitted.Visible      = true;
                    }
                }
                else
                {
                    #region Local Currency Summary
                    if (expRow.DifferenceAmountLocalCurrency > (decimal)0)
                    {
                        ctlLblDifferenceAmtLocal.Text = GetProgramMessage("$AdditionalPayFromCompany$");
                        ctlDifferenceAmtLocal.Visible = true;
                    }
                    else if (expRow.DifferenceAmountLocalCurrency < (decimal)0)
                    {
                        ctlLblDifferenceAmtLocal.Text = GetProgramMessage("$PayBackToCompany$");
                        ctlDifferenceAmtLocal.Visible = true;
                    }
                    else if (expRow.TotalAdvanceLocalCurrency > 0 && expRow.DifferenceAmountLocalCurrency == (decimal)0)
                    {
                        ctlLblDifferenceAmtLocal.Text = GetProgramMessage("$CompleteClearing$");
                        ctlDifferenceAmtLocal.Visible = false;
                    }

                    if (expRow.TotalAdvanceLocalCurrency == (decimal)0)
                    {
                        ctlTotalAdvanceLocal.Visible    = false;
                        ctlLblTotalAdvanceLocal.Visible = false;
                    }
                    else
                    {
                        ctlTotalAdvanceLocal.Visible    = true;
                        ctlLblTotalAdvanceLocal.Visible = true;
                    }
                    if (expRow.TotalRemittanceLocalCurrency == (decimal)0)
                    {
                        ctlTotalRemittanceLocal.Visible    = false;
                        ctlLblTotalRemittanceLocal.Visible = false;
                    }
                    else
                    {
                        ctlTotalRemittanceLocal.Visible    = true;
                        ctlLblTotalRemittanceLocal.Visible = true;
                    }
                    #endregion

                    #region Main Currency Summary
                    if (expRow.DifferenceAmountMainCurrency > (decimal)0)
                    {
                        ctlLblDifferenceAmtMainCurrency.Text = GetProgramMessage("$AdditionalPayFromCompany$");
                        ctlDifferenceAmtMainCurrency.Visible = true;
                    }
                    else if (expRow.DifferenceAmountMainCurrency < (decimal)0)
                    {
                        ctlLblDifferenceAmtMainCurrency.Text = GetProgramMessage("$PayBackToCompany$");
                        ctlDifferenceAmtMainCurrency.Visible = true;
                    }
                    else if (expRow.TotalAdvanceMainCurrency > 0 && expRow.DifferenceAmountMainCurrency == (decimal)0)
                    {
                        ctlLblDifferenceAmtMainCurrency.Text = GetProgramMessage("$CompleteClearing$");
                        ctlDifferenceAmtMainCurrency.Visible = false;
                    }

                    if (expRow.TotalAdvanceMainCurrency == (decimal)0)
                    {
                        ctlTotalAdvanceMainCurrency.Visible    = false;
                        ctlLblTotalAdvanceMainCurrency.Visible = false;
                    }
                    else
                    {
                        ctlTotalAdvanceMainCurrency.Visible    = true;
                        ctlLblTotalAdvanceMainCurrency.Visible = true;
                    }
                    if (expRow.TotalRemittanceMainCurrency == (decimal)0)
                    {
                        ctlTotalRemittanceMainCurrency.Visible    = false;
                        ctlLblTotalRemittanceMainCurrency.Visible = false;
                    }
                    else
                    {
                        ctlTotalRemittanceMainCurrency.Visible    = true;
                        ctlLblTotalRemittanceMainCurrency.Visible = true;
                    }
                    #endregion

                    #region THB Currency Summary
                    if (expRow.DifferenceAmount > (decimal)0)
                    {
                        ctlLblDifferenceAmtTHB.Text = GetProgramMessage("$AdditionalPayFromCompany$");
                        ctlDifferenceAmtTHB.Visible = true;
                    }
                    else if (expRow.DifferenceAmount < (decimal)0)
                    {
                        ctlLblDifferenceAmtTHB.Text = GetProgramMessage("$PayBackToCompany$");
                        ctlDifferenceAmtTHB.Visible = true;
                    }
                    else if (expRow.TotalAdvance > 0 && expRow.DifferenceAmount == (decimal)0)
                    {
                        ctlLblDifferenceAmtTHB.Text = GetProgramMessage("$CompleteClearing$");
                        ctlDifferenceAmtTHB.Visible = false;
                    }

                    if (expRow.TotalAdvance == (decimal)0)
                    {
                        ctlTotalAdvanceTHB.Visible    = false;
                        ctlLblTotalAdvanceTHB.Visible = false;
                    }
                    else
                    {
                        ctlTotalAdvanceTHB.Visible    = true;
                        ctlLblTotalAdvanceTHB.Visible = true;
                    }
                    if (expRow.TotalRemittance == (decimal)0)
                    {
                        ctlTotalRemittanceTHB.Visible    = false;
                        ctlLblTotalRemittanceTHB.Visible = false;
                    }
                    else
                    {
                        ctlTotalRemittanceTHB.Visible    = true;
                        ctlLblTotalRemittanceTHB.Visible = true;
                    }
                    #endregion
                }
                ctlUpdatePanelPaymentDetail.Update();
            }
        }
        protected void ctlAdvanceGridview_DataBound(object sender, EventArgs e)
        {
            ExpenseDataSet expenseDS = (ExpenseDataSet)TransactionService.GetDS(this.TransactionId);

            if (expenseDS != null)
            {
                ExpenseDataSet.FnExpenseDocumentRow row = expenseDS.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
                SS.Standard.WorkFlow.DTO.WorkFlow   wf  = null;
                int Ordinal = 0;
                if (Request["wfid"] != null)
                {
                    WorkFlowID   = UIHelper.ParseLong(Request["wfid"].ToString());
                    wf           = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(WorkFlowID);
                    CurrentState = wf.CurrentState.Name;
                    Ordinal      = wf.CurrentState.Ordinal;
                }
                //DbCurrency localCurrency = null;
                DbCurrency mainCurrency = null;
                //if (!row.IsLocalCurrencyIDNull())
                //{
                //    localCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(row.LocalCurrencyID);
                //}
                if (!row.IsMainCurrencyIDNull())
                {
                    mainCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(row.MainCurrencyID);
                }
                //if (localCurrency != null)
                //{
                //    ctlAdvanceGridView.Columns[4].HeaderText = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "(" + localCurrency.Symbol + ")");
                //}
                //else
                //{
                ctlAdvanceGridView.Columns[4].HeaderText = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "");
                //}

                if (mainCurrency != null)
                {
                    ctlAdvanceGridView.Columns[5].HeaderText   = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "(" + mainCurrency.Symbol + ")");
                    ctlAdvanceGridView.HeaderRow.Cells[5].Text = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "(" + mainCurrency.Symbol + ")");
                }
                else
                {
                    ctlAdvanceGridView.Columns[5].HeaderText = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "");
                }

                string expenseType = FnExpenseDocumentService.GetExpenseType(this.ExpDocumentID, this.TransactionId);
                bool   isRepOffice = row.IsIsRepOfficeNull() ? false : row.IsRepOffice;

                if (expenseType.Equals(ZoneType.Domestic))
                {
                    if (isRepOffice)
                    {
                        if (CurrentState.Equals(WorkFlowStateFlag.WaitVerify) || Ordinal > 5)
                        {
                            ctlAdvanceGridView.Columns[4].Visible = false;
                            ctlAdvanceGridView.Columns[5].Visible = true;
                            ctlAdvanceGridView.Columns[6].Visible = true;
                        }
                        else
                        {
                            ctlAdvanceGridView.Columns[4].Visible = false;
                            ctlAdvanceGridView.Columns[5].Visible = true;
                            ctlAdvanceGridView.Columns[6].Visible = false;
                        }
                    }
                    else
                    {
                        ctlAdvanceGridView.Columns[4].Visible = false;
                        ctlAdvanceGridView.Columns[5].Visible = false;
                        ctlAdvanceGridView.Columns[6].Visible = true;
                    }
                }
                else
                {
                    if (isRepOffice)
                    {
                        if (CurrentState.Equals(WorkFlowStateFlag.WaitVerify) || Ordinal > 5)
                        {
                            ctlAdvanceGridView.Columns[4].Visible = false;
                            ctlAdvanceGridView.Columns[5].Visible = true;
                            ctlAdvanceGridView.Columns[6].Visible = true;
                        }
                        else
                        {
                            ctlAdvanceGridView.Columns[4].Visible = false;
                            ctlAdvanceGridView.Columns[5].Visible = true;
                            ctlAdvanceGridView.Columns[6].Visible = false;
                        }
                    }
                    else
                    {
                        ctlAdvanceGridView.Columns[4].Visible = false;
                        ctlAdvanceGridView.Columns[5].Visible = false;
                        ctlAdvanceGridView.Columns[6].Visible = true;
                    }
                }
            }

            if (ctlAdvanceGridView.Rows.Count == 0)
            {
                ctlTANoLookup.Enabled = true;
                ctlDeleteTA.Enabled   = true;
                //this.ClearRemittanceGridview();
            }
        }
示例#21
0
        protected void ctlInvoiceItem_DataBound(object sender, EventArgs e)
        {
            BaseGridView gridview = (BaseGridView)sender;

            if (DocumentType.Equals(ZoneType.Domestic))
            {
                gridview.Columns[5].Visible = false;
                gridview.Columns[4].Visible = false;
                gridview.Columns[6].Visible = false;
            }
            else
            {
                gridview.Columns[5].Visible = true;
                gridview.Columns[4].Visible = true;
                gridview.Columns[6].Visible = true;
            }

            if (IsRepOffice)
            {
                SS.Standard.WorkFlow.DTO.WorkFlow workflow = null;
                if (!string.IsNullOrEmpty(Request.Params["wfid"]) && UIHelper.ParseInt(Request.Params["wfid"]) > 0)
                {
                    long workFlowID = UIHelper.ParseLong(Request.Params["wfid"]);

                    try
                    {
                        workflow = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workFlowID);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                gridview.Columns[7].Visible    = true; //local currency
                gridview.Columns[7].HeaderText = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "(" + SelectedCurrency + ")");

                ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(TransactionId);

                ExpenseDataSet.FnExpenseDocumentRow expRow = expDs.FnExpenseDocument.FindByExpenseID(this.ExpDocumentID);
                if (!expRow.IsMainCurrencyIDNull())
                {
                    DbCurrency mainCurrency = SsDbQueryProvider.DbCurrencyQuery.FindByIdentity(expRow.MainCurrencyID);
                    if (mainCurrency != null)
                    {
                        gridview.Columns[8].HeaderText = string.Format(GetMessage("AmountCurrencyHeaderColumn"), "(" + mainCurrency.Symbol + ")");
                    }
                }

                if ((workflow != null && workflow.CurrentState.Ordinal >= 5) && (UserAccount.IsAccountant || UserAccount.IsPayment))
                {
                    if (!expRow.IsMainCurrencyIDNull() && !expRow.IsLocalCurrencyIDNull() && (expRow.MainCurrencyID == expRow.LocalCurrencyID))
                    {
                        gridview.Columns[8].Visible = false;  //hide main currency
                    }
                    else
                    {
                        gridview.Columns[8].Visible = true; //show main currency
                    }
                    gridview.Columns[9].Visible = true;     //THB
                }
                else
                {
                    gridview.Columns[8].Visible = false;
                    gridview.Columns[9].Visible = false;
                }
            }
            else
            {
                gridview.Columns[7].Visible = false;
                gridview.Columns[8].Visible = false;
                gridview.Columns[9].Visible = true;
            }
        }
示例#22
0
        public void UpdateExpenseMileageOnTransaction(FnExpenseMileage expenseMileage, Guid txId)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            ExpenseDataSet ds         = (ExpenseDataSet)TransactionService.GetDS(txId);
            long           documentId = 0;

            if (expenseMileage.Expense != null)
            {
                ExpenseDataSet.FnExpenseDocumentRow expRow = ds.FnExpenseDocument.FindByExpenseID(expenseMileage.Expense.ExpenseID);
                documentId = expRow == null ? 0 : expRow.DocumentID;
            }

            if (expenseMileage.CarLicenseNo.Length.Equals(0))
            {
                errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredCarLicenseNo"));
            }

            if (expenseMileage.Owner.Equals(OwnerMileage.Employee))
            {
                if (expenseMileage.First100KmRate.Equals((double)0))
                {
                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredFirst100KmOverZero"));
                }
                if (expenseMileage.Exceed100KmRate.Equals((double)0))
                {
                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredExceed100KmOverZero"));
                }
            }
            else
            {
                if (expenseMileage.TotalAmount.Equals((double)0))
                {
                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredTotalAmountOverZero"));
                }
            }

            if (!expenseMileage.Owner.Equals(OwnerMileage.Company) || !expenseMileage.TypeOfCar.Equals(TypeOfCar.Pickup))
            {
                // Validate CostCenter.
                if (expenseMileage.CostCenter == null)
                {
                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
                }
                else
                {
                    if (ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(expenseMileage.CostCenter.CostCenterID) == null)
                    {
                        errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
                    }
                }

                // Validate Account.
                if (expenseMileage.Account == null)
                {
                    errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
                }
                else
                {
                    if (ScgDbQueryProvider.DbAccountQuery.FindByIdentity(expenseMileage.Account.AccountID) == null)
                    {
                        errors.AddError("Mileage.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
                    }
                }
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            ExpenseDataSet.FnExpenseMileageRow row = ds.FnExpenseMileage.FindByExpenseMileageID(expenseMileage.ExpenseMileageID);

            row.BeginEdit();
            if (expenseMileage.Expense != null)
            {
                row.ExpenseID = expenseMileage.Expense.ExpenseID;
            }
            row.Owner                 = expenseMileage.Owner;
            row.CarLicenseNo          = expenseMileage.CarLicenseNo;
            row.TypeOfCar             = expenseMileage.TypeOfCar;
            row.PermissionNo          = expenseMileage.PermissionNo;
            row.HomeToOfficeRoundTrip = (decimal)expenseMileage.HomeToOfficeRoundTrip;
            row.PrivateUse            = (decimal)expenseMileage.PrivateUse;
            row.IsOverrideLevel       = expenseMileage.IsOverrideLevel;
            if (expenseMileage.OverrideCompanyId != null)
            {
                row.OverrideCompanyId = (long)expenseMileage.OverrideCompanyId;
            }
            if (expenseMileage.CurrentCompanyId != null)
            {
                row.CurrentCompanyId = (long)expenseMileage.CurrentCompanyId;
            }

            row.OverrideLevelRemark           = expenseMileage.OverrideLevelRemark;
            row.OverrideUserPersonalLevelCode = expenseMileage.OverrideUserPersonalLevelCode;
            row.CurrentUserPersonalLevelCode  = expenseMileage.CurrentUserPersonalLevelCode;

            row.First100KmRate    = (decimal)expenseMileage.First100KmRate;
            row.Exceed100KmRate   = (decimal)expenseMileage.Exceed100KmRate;
            row.HelpingAmount     = (decimal)expenseMileage.HelpingAmount;
            row.OverHelpingAmount = (decimal)expenseMileage.OverHelpingAmount;

            row.TotalAmount = (decimal)expenseMileage.TotalAmount;

            if (expenseMileage.CostCenter != null)
            {
                row.CostCenterID = expenseMileage.CostCenter.CostCenterID;
            }
            else
            {
                row.SetCostCenterIDNull();
            }

            if (expenseMileage.Account != null)
            {
                row.AccountID = expenseMileage.Account.AccountID;
            }
            else
            {
                row.SetAccountIDNull();
            }

            if (expenseMileage.IO != null)
            {
                row.IOID = expenseMileage.IO.IOID;
            }
            else
            {
                row.SetIOIDNull();
            }

            row.CreDate = DateTime.Now;
            row.CreBy   = UserAccount.UserID;
            row.UpdDate = DateTime.Now;
            row.UpdBy   = UserAccount.UserID;
            row.UpdPgm  = UserAccount.CurrentProgramCode;
            row.Active  = true;
            row.EndEdit();

            UpdateMileageSummary(txId, expenseMileage);

            ExpenseDataSet.FnExpenseMileageRow mileageRow = ds.FnExpenseMileage.FindByExpenseMileageID(expenseMileage.ExpenseMileageID);

            ExpenseDataSet.FnExpenseDocumentRow expenseRow = ds.FnExpenseDocument.FindByExpenseID(row.ExpenseID);
            long requesterId = 0;

            if (expenseRow != null)
            {
                ExpenseDataSet.DocumentRow docRow = ds.Document.FindByDocumentID(expenseRow.DocumentID);
                if (docRow != null)
                {
                    requesterId = docRow.RequesterID;
                }
            }
            long invoiceId = 0;

            DataRow[]        invoiceRows = ds.FnExpenseInvoice.Select(String.Format("InvoiceDocumentType = '{0}'", InvoiceType.Mileage));
            FnExpenseInvoice invoice     = new FnExpenseInvoice();

            string accountCode = string.Empty;
            SuUser requester   = SS.SU.Query.QueryProvider.SuUserQuery.FindByIdentity(requesterId);

            if (expenseMileage.Owner.Equals(OwnerMileage.Employee) || (expenseMileage.Owner.Equals(OwnerMileage.Company) && !expenseMileage.TypeOfCar.Equals(TypeOfCar.Pickup)))
            {
                if (invoiceRows.Length > 0)
                {
                    foreach (DataRow inv in invoiceRows)
                    {
                        invoiceId = inv.Field <long>("InvoiceID");
                        DataRow[] invoiceItemRows = ds.FnExpenseInvoiceItem.Select(String.Format("InvoiceID = {0} ", invoiceId));
                        foreach (DataRow item in invoiceRows)
                        {
                            item.Delete();
                        }
                        inv.Delete();
                    }
                }
            }

            //Add empty invoice
            invoice.InvoiceDocumentType = InvoiceType.Mileage;
            invoice.Expense             = expenseMileage.Expense;
            DbCostCenter cost         = null;
            string       expenseGroup = "0";

            if (!mileageRow.IsCostCenterIDNull())
            {
                cost         = ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(mileageRow.CostCenterID);
                expenseGroup = (cost == null ? string.Empty : cost.CostCenterCode.Substring(3, 1).Equals("0") ? "0" : "1");
            }

            DbInternalOrder io = null;

            if (expenseMileage.IO != null)
            {
                io = ScgDbQueryProvider.DbIOQuery.FindByIdentity(expenseMileage.IO.IOID);
            }

            if (expenseMileage.Owner.Equals(OwnerMileage.Employee))
            {
                double total = (double)mileageRow.TotalAmount;
                invoice.TotalAmount     = total;
                invoice.TotalBaseAmount = total;
                invoice.NetAmount       = total;
                invoiceId = FnExpenseInvoiceService.AddInvoiceOnTransaction(invoice, txId);

                invoice.InvoiceID = invoiceId;

                FnExpenseInvoiceItem invoiceItemGov   = new FnExpenseInvoiceItem();
                FnExpenseInvoiceItem invoiceItemExtra = new FnExpenseInvoiceItem();

                invoiceItemGov.Invoice   = invoice;
                invoiceItemExtra.Invoice = invoice;

                invoiceItemGov.CostCenter = expenseMileage.CostCenter;
                invoiceItemGov.Account    = expenseMileage.Account;
                invoiceItemGov.IO         = expenseMileage.IO;

                invoiceItemExtra.CostCenter = expenseMileage.CostCenter;
                if (io != null && !string.IsNullOrEmpty(io.IONumber))
                {
                    string ioType = io.IONumber.Substring(4, 2);
                    if (ioType.Contains("02") || ioType.Contains("03") || ioType.Contains("04") || ioType.Contains("09"))
                    {
                        invoiceItemExtra.IO = null;
                    }
                    else
                    {
                        invoiceItemExtra.IO = io;
                    }
                }

                invoiceItemExtra.Account = ScgDbQueryProvider.DbAccountQuery.FindAccountByAccountCodeExpenseGroup(ParameterServices.AccountMileageExtra, null);

                //switch (expenseGroup)
                //{
                //    case "0":
                //        invoiceItemExtra.Account = ScgDbQueryProvider.DbAccountQuery.FindAccountByAccountCodeExpenseGroup(ParameterServices.AccountMileageOfficeExtra, expenseGroup, null);
                //        break;
                //    case "1":
                //        invoiceItemExtra.Account = ScgDbQueryProvider.DbAccountQuery.FindAccountByAccountCodeExpenseGroup(ParameterServices.AccountMileageFactoryExtra, expenseGroup, null);
                //        break;

                //    default:
                //        break;
                //}
                if (mileageRow.HelpingAmount <= mileageRow.TotalAmount)
                {
                    invoiceItemGov.Amount = (double)mileageRow.HelpingAmount;
                }
                else if (mileageRow.HelpingAmount > mileageRow.TotalAmount)
                {
                    invoiceItemGov.Amount = (double)mileageRow.TotalAmount;
                }

                invoiceItemExtra.Amount = (double)mileageRow.OverHelpingAmount;
                if (invoiceItemGov.Amount > 0)
                {
                    FnExpenseInvoiceItemService.AddMileageInvoiceItem(invoiceItemGov, txId);
                }

                if (invoiceItemExtra.Amount > 0)
                {
                    FnExpenseInvoiceItemService.AddMileageInvoiceItem(invoiceItemExtra, txId);
                }
            }
            else if (expenseMileage.Owner.Equals(OwnerMileage.Company) && (!expenseMileage.TypeOfCar.Equals(TypeOfCar.Pickup)))
            {
                invoice.TotalAmount     = (double)mileageRow.HelpingAmount;
                invoice.TotalBaseAmount = (double)mileageRow.HelpingAmount;
                invoice.NetAmount       = (double)mileageRow.HelpingAmount;
                invoiceId = FnExpenseInvoiceService.AddInvoiceOnTransaction(invoice, txId);

                FnExpenseInvoiceItem invoiceItem = new FnExpenseInvoiceItem();

                invoice.InvoiceID      = invoiceId;
                invoiceItem.Invoice    = invoice;
                invoiceItem.CostCenter = expenseMileage.CostCenter;
                invoiceItem.Account    = expenseMileage.Account;
                invoiceItem.IO         = expenseMileage.IO;

                //switch (expenseGroup)
                //{
                //    case "0":
                //        accountCode = ParameterServices.AccountMileageOfficeCompany;
                //        break;
                //    case "1":

                //        accountCode = ParameterServices.AccountMileageFactoryCompany;
                //        break;

                //    default:
                //        break;
                //}

                //invoiceItem.Account = ScgDbQueryProvider.DbAccountQuery.FindAccountByAccountCodeExpenseGroup(accountCode, expenseGroup, null);
                invoiceItem.Amount = (double)mileageRow.HelpingAmount;
                FnExpenseInvoiceItemService.AddMileageInvoiceItem(invoiceItem, txId);
            }
        }
        public void UpdateExpenseDocumentOnTransaction(FnExpenseDocument exp, Guid txId)
        {
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            if (exp.Document != null)
            {
                ExpenseDataSet.DocumentRow docRow = ds.Document.FindByDocumentID(exp.Document.DocumentID);
                docRow.BeginEdit();
                docRow.DocumentNo = exp.Document.DocumentNo;
                //docRow.DocumentStatus = exp.Document.DocumentStatus;
                docRow.Subject = exp.Document.Subject;
                docRow.Memo    = exp.Document.Memo;
                if (exp.Document.DocumentType != null)
                {
                    docRow.DocumentTypeID = exp.Document.DocumentType.DocumentTypeID;
                }
                if (exp.Document.CompanyID != null)
                {
                    docRow.CompanyID = exp.Document.CompanyID.CompanyID;
                }
                if (exp.Document.CreatorID != null)
                {
                    docRow.CreatorID = exp.Document.CreatorID.Userid;
                }
                if (exp.Document.RequesterID != null)
                {
                    docRow.RequesterID = exp.Document.RequesterID.Userid;
                }
                if (exp.Document.ReceiverID != null)
                {
                    docRow.ReceiverID = exp.Document.ReceiverID.Userid;
                }
                if (exp.Document.ApproverID != null)
                {
                    docRow.ApproverID = exp.Document.ApproverID.Userid;
                }

                docRow.Active  = exp.Document.Active;
                docRow.CreDate = exp.CreDate;
                docRow.CreBy   = exp.CreBy;
                docRow.UpdDate = exp.UpdDate;
                docRow.UpdBy   = exp.UpdBy;
                docRow.UpdPgm  = exp.UpdPgm;

                docRow.EndEdit();
                docRow.AcceptChanges();
            }
            ExpenseDataSet.FnExpenseDocumentRow expRow = ds.FnExpenseDocument.FindByExpenseID(exp.ExpenseID);
            expRow.BeginEdit();

            if (exp.ServiceTeam != null)
            {
                expRow.ServiceTeamID = exp.ServiceTeam.ServiceTeamID;
            }
            if (exp.PB != null)
            {
                expRow.PBID = exp.PB.Pbid;
            }
            expRow.PaymentType  = exp.PaymentType;
            expRow.TotalAdvance = (decimal)exp.TotalAdvance;
            expRow.TotalExpense = (decimal)exp.TotalExpense;
            expRow.CreDate      = exp.CreDate;
            expRow.CreBy        = exp.CreBy;
            expRow.UpdDate      = exp.UpdDate;
            expRow.UpdBy        = exp.UpdBy;
            expRow.UpdPgm       = exp.UpdPgm;

            expRow.EndEdit();
            expRow.AcceptChanges();
        }
        public void AddInvoiceItemOnTransaction(FnExpenseInvoiceItem item, Guid txId, string expenseType)
        {
            bool isRepOffice = false;

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseDocumentRow expRow = null;
            long documentId = 0;

            if (item.Invoice != null && item.Invoice.Expense != null)
            {
                expRow     = ds.FnExpenseDocument.FindByExpenseID(item.Invoice.Expense.ExpenseID);
                documentId = expRow == null ? 0 : expRow.DocumentID;
                if (!expRow.IsIsRepOfficeNull())
                {
                    isRepOffice = expRow.IsRepOffice;
                }
            }

            // Validate CostCenter.
            if (item.CostCenter == null)
            {
                errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
            }
            else
            {
                if (ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(item.CostCenter.CostCenterID) == null)
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
                }
            }

            // Validate Account.
            if (item.Account == null)
            {
                errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
            }
            else
            {
                if (ScgDbQueryProvider.DbAccountQuery.FindByIdentity(item.Account.AccountID) == null)
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
                }
            }

            if (!string.IsNullOrEmpty(item.SaleOrder) && item.SaleOrder.Length < 10)
            {
                errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("SaleOrder_Has_10_Digit"));
            }

            if (expenseType.Equals(ZoneType.Domestic))
            {
                // Validate Amount.
                if (!isRepOffice)
                {
                    if (!item.Amount.HasValue || (item.Amount.HasValue && item.Amount.Value == 0))
                    {
                        errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAmount"));
                    }
                }
                else
                {
                    if (!item.LocalCurrencyAmount.HasValue || (item.LocalCurrencyAmount.HasValue && item.LocalCurrencyAmount.Value == 0))
                    {
                        errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAmount"));
                    }
                }
            }
            else if (expenseType.Equals(ZoneType.Foreign))
            {
                // Validate Currency.
                if (!item.CurrencyID.HasValue || (item.CurrencyID.HasValue && item.CurrencyID.Value == 0))
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredCurrency"));
                }
                // Validate Currency Amount.
                if (!item.CurrencyAmount.HasValue || (item.CurrencyAmount.HasValue && item.CurrencyAmount.Value == 0))
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAmount"));
                }

                // Validate ExchangeRate.
                if (!item.ExchangeRate.HasValue)
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredExchangeRate"));
                }
                else if ((item.ExchangeRate.HasValue) && (item.ExchangeRate.Value == 0))
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredExchangeRate"));
                }
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            ExpenseDataSet.FnExpenseInvoiceItemRow row = ds.FnExpenseInvoiceItem.NewFnExpenseInvoiceItemRow();

            if (item.Invoice != null)
            {
                row.InvoiceID = item.Invoice.InvoiceID;
            }

            if (item.CostCenter != null)
            {
                row.CostCenterID = item.CostCenter.CostCenterID;
            }
            else
            {
                row.SetCostCenterIDNull();
            }

            row.AccountID = item.Account.AccountID;

            if (item.IO != null)
            {
                row.IOID = item.IO.IOID;
            }

            if (item.CurrencyID.HasValue)
            {
                row.CurrencyID = item.CurrencyID.Value;
            }

            if (item.ExchangeRate.HasValue)
            {
                row.ExchangeRate = item.ExchangeRate.Value;
            }

            if (item.CurrencyAmount.HasValue)
            {
                row.CurrencyAmount = item.CurrencyAmount.Value;
            }

            if (item.LocalCurrencyAmount.HasValue)
            {
                row.LocalCurrencyAmount = (decimal)item.LocalCurrencyAmount.Value;
            }

            if (item.MainCurrencyAmount.HasValue)
            {
                row.MainCurrencyAmount = item.MainCurrencyAmount.Value;
            }

            if (expenseType.Equals(ZoneType.Foreign) && !isRepOffice)
            {
                row.Amount = (double)Math.Round((decimal)(item.CurrencyAmount.Value * item.ExchangeRate.Value), 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                if (item.Amount.HasValue)
                {
                    row.Amount = item.Amount.Value;
                }
            }

            row.SaleOrder   = item.SaleOrder;
            row.SaleItem    = item.SaleItem;
            row.Description = item.Description;
            row.ReferenceNo = item.ReferenceNo;

            row.Active  = true;
            row.CreBy   = UserAccount.UserID;
            row.CreDate = DateTime.Now;
            row.UpdBy   = UserAccount.UserID;
            row.UpdDate = DateTime.Now;
            row.UpdPgm  = UserAccount.CurrentProgramCode;

            ds.FnExpenseInvoiceItem.AddFnExpenseInvoiceItemRow(row);
        }