コード例 #1
0
        public void ValidRemaining(Guid txID, long expDocumentId)
        {
            double         remaining = 0;
            ExpenseDataSet expDS     = (ExpenseDataSet)TransactionService.GetDS(txID);

            string filter = String.Format("ExpenseID = {0}", expDocumentId);

            DataRow[] rows = expDS.FnExpenseMileage.Select(filter);

            if (rows.Length > 0)
            {
                FnExpenseMileage mileage = new FnExpenseMileage();
                mileage.LoadFromDataRow(rows[0]);
                double totalInvoice = 0;

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

                foreach (DataRow row in invoiceRows)
                {
                    FnExpenseInvoice invoice = new FnExpenseInvoice();
                    invoice.LoadFromDataRow(row);

                    totalInvoice += ((double)Math.Round(Convert.ToDecimal(invoice.NetAmount), 2, MidpointRounding.AwayFromZero));
                }

                remaining = ((double)Math.Round(Convert.ToDecimal(mileage.HelpingAmount), 2, MidpointRounding.AwayFromZero)) - ((double)Math.Round(Convert.ToDecimal(totalInvoice), 2, MidpointRounding.AwayFromZero));

                Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
                if (rows[0].Field <string>("Owner").Equals(OwnerMileage.Company) && rows[0].Field <string>("TypeOfCar").Equals(TypeOfCar.Pickup))
                {
                    if (remaining != 0)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RemainingNotZero"));
                    }
                }
                if (!errors.IsEmpty)
                {
                    throw new ServiceValidationException(errors);
                }
            }
        }
コード例 #2
0
        public void SaveExpenseRecommend()
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            double totalAmount = 0.0;
            IList <FnExpenseInvoiceItem> RecommendList = new List <FnExpenseInvoiceItem>();
            FnExpenseInvoice             invoice       = new FnExpenseInvoice();

            invoice.Expense             = new FnExpenseDocument(this.ExpDocumentID);
            invoice.InvoiceDocumentType = InvoiceType.General;
            invoice.IsVAT = false;
            invoice.IsWHT = false;
            foreach (GridViewRow row in ctlSimpleExpenseGridView.Rows)
            {
                UserControls.LOV.SCG.DB.CostCenterField      cost    = row.FindControl("ctlCostCenterLabelLookup") as UserControls.LOV.SCG.DB.CostCenterField;
                UserControls.LOV.SCG.DB.AccountField         account = row.FindControl("ctlAccountLabelLookup") as UserControls.LOV.SCG.DB.AccountField;
                UserControls.LOV.SCG.DB.IOAutoCompleteLookup io      = row.FindControl("ctlIOLabelLookup") as UserControls.LOV.SCG.DB.IOAutoCompleteLookup;
                TextBox des          = row.FindControl("ctlTxtDescription") as TextBox;
                TextBox amount       = row.FindControl("ctlTxtAmountTHB") as TextBox;
                TextBox reference    = row.FindControl("ctlTxtRefNo") as TextBox;
                TextBox exchangeRate = row.FindControl("ctlTxtExchangeRate") as TextBox;

                if (!string.IsNullOrEmpty(amount.Text) && UIHelper.ParseDouble(amount.Text) > 0)
                {
                    FnExpenseInvoiceItem recommend = new FnExpenseInvoiceItem();
                    recommend.Invoice = invoice;

                    if (UIHelper.ParseLong(account.AccountID) > 0)
                    {
                        recommend.Account = new DbAccount(UIHelper.ParseLong(account.AccountID));
                    }

                    if (UIHelper.ParseLong(cost.CostCenterId) > 0)
                    {
                        recommend.CostCenter = new DbCostCenter(UIHelper.ParseLong(cost.CostCenterId));
                    }

                    if (UIHelper.ParseLong(io.IOID) > 0)
                    {
                        recommend.IO = new DbInternalOrder(UIHelper.ParseLong(io.IOID));
                    }

                    if (DocumentType.Equals(ZoneType.Foreign))
                    {
                        UserControls.Dropdownlist.SS.DB.CurrencyDropdown currencyDropdown = row.FindControl("ctlCurrencyDropdown") as UserControls.Dropdownlist.SS.DB.CurrencyDropdown;
                        if (currencyDropdown.SelectedValue == "")
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CurrencyIsRequired"));
                            throw new ServiceValidationException(errors);
                        }

                        TextBox currencyAmount = row.FindControl("ctlTxtCurrencyAmount") as TextBox;

                        recommend.CurrencyID     = UIHelper.ParseLong(currencyDropdown.SelectedValue);
                        recommend.CurrencyAmount = UIHelper.ParseDouble(currencyAmount.Text);

                        recommend.ExchangeRate = UIHelper.ParseDouble(exchangeRate.Text);
                        if (IsRepOffice)
                        {
                            recommend.LocalCurrencyAmount = recommend.ExchangeRate * (recommend.CurrencyAmount == (double?)0 ? 1 : recommend.CurrencyAmount);
                            totalAmount += recommend.LocalCurrencyAmount.Value;
                        }
                        else
                        {
                            recommend.Amount = recommend.ExchangeRate * (recommend.CurrencyAmount == (double?)0 ? 1 : recommend.CurrencyAmount);
                            totalAmount     += recommend.Amount.Value;
                        }
                    }
                    else
                    {
                        if (IsRepOffice)
                        {
                            recommend.LocalCurrencyAmount = UIHelper.ParseDouble(amount.Text);
                            totalAmount += recommend.LocalCurrencyAmount.Value;
                        }
                        else
                        {
                            recommend.Amount = UIHelper.ParseDouble(amount.Text);
                            totalAmount     += recommend.Amount.Value;
                        }
                    }

                    recommend.ReferenceNo = reference.Text;
                    recommend.Description = des.Text;

                    recommend.Description = des.Text;
                    recommend.ReferenceNo = reference.Text;
                    RecommendList.Add(recommend);
                }
            }
            try
            {
                if (RecommendList.Count > 0)
                {
                    if (IsRepOffice)
                    {
                        invoice.TotalBaseAmountLocalCurrency = invoice.NetAmountLocalCurrency = invoice.TotalAmountLocalCurrency = totalAmount;
                    }
                    else
                    {
                        invoice.TotalBaseAmount = invoice.NetAmount = invoice.TotalAmount = totalAmount;
                    }
                    long invoiceId = FnExpenseInvoiceService.AddInvoiceOnTransaction(invoice, this.TransactionId);
                    FnExpenseInvoiceItemService.AddRecommendInvoiceItemOnTransaction(invoiceId, DocumentType, RecommendList, this.TransactionId);
                    ctlSimpleExpenseGridView.DataSource = null;
                    ctlSimpleExpenseGridView.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
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);
            }
        }