public string DeleteAccountingObject(AccountingObjectEntity accountingObject)
        {
            const string sql = @"uspDelete_AccountingObject";

            object[] parms = { "@AccountingObjectID", accountingObject.AccountingObjectId };
            return(Db.Delete(sql, true, parms));
        }
        public AccountingObjectResponse InsertAccountObjectConvert(AccountingObjectEntity accountingObjectEntity)
        {
            var response = new AccountingObjectResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                var accoutingObjects = AccountingObjectDao.GetAccountingObjectByCode(accountingObjectEntity.AccountingObjectCode.Trim());
                var accoutingObject  = accoutingObjects.Where(x => x.IsEmployee = false).ToList();
                if (accoutingObject.Count > 0 && accountingObjectEntity.IsEmployee == false)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = @"Mã đối tượng " + accountingObjectEntity.AccountingObjectCode.Trim() + @" đã tồn tại!";
                    return(response);
                }
                var accoutingObjectEmployees = AccountingObjectDao.GetAccountingObjectByCode(accountingObjectEntity.AccountingObjectCode.Trim());
                var accoutingObjectEmployee  = accoutingObjectEmployees.Where(x => x.IsEmployee).ToList();
                if (accoutingObjectEmployee.Count > 0 && accountingObjectEntity.IsEmployee == true)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = @"Mã nhân viên " + accountingObjectEntity.AccountingObjectCode.Trim() + @" đã tồn tại!";
                    return(response);
                }
                if (!accountingObjectEntity.Validate())
                {
                    foreach (string error in accountingObjectEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                var accObject =
                    AccountingObjectCategoryDao.GetAccountingObjectCategory(accountingObjectEntity.AccountingObjectCategoryId);
                if (accObject != null)
                {
                    if (accObject.AccountingObjectCategoryCode == "NCC")
                    {
                        accountingObjectEntity.IsCustomerVendor = true;
                    }
                }
                //   var validAccountingObject = AccountingObjectDao.Get
                response.Message = AccountingObjectDao.InsertAccountingObject(accountingObjectEntity);

                if (!string.IsNullOrEmpty(response.Message))
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                response.AccountingObjectId = accountingObjectEntity.AccountingObjectId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
 /// <summary>
 /// Takes the specified budget source property.
 /// </summary>
 /// <param name="take">The take.</param>
 /// <returns></returns>
 private object[] Take(AccountingObjectEntity take)
 {
     return(new object[]
     {
         "@AccountingId", take.AccountingId,
         "@Code", take.Code,
         "@Type", take.Type,
         "@FullName", take.FullName,
         "@Address", take.Address,
         "@TaxCode", take.TaxCode,
         "@BankAcount", take.BankAcount,
         "@BankId", take.BankId,
         "@ContactName", take.ContactName,
         "@ContactAddress", take.ContactAddress,
         "@ContactIdNumber", take.ContactIdNumber,
         "@DateOfIssue", take.DateOfIssue,
         "@IssueAddress", take.IssueAddress
     });
 }
 private static object[] Take(AccountingObjectEntity accountingObjectEntity)
 {
     return(new object[]
     {
         "@AccountingObjectId", accountingObjectEntity.AccountingObjectId,
         "@AccountingObjectCode", accountingObjectEntity.AccountingObjectCode,
         "@Type", accountingObjectEntity.Type,
         "@FullName", accountingObjectEntity.FullName,
         "@Address", accountingObjectEntity.Address,
         "@TaxCode", accountingObjectEntity.TaxCode,
         "@BankAcount", accountingObjectEntity.BankAcount,
         "@BankId", accountingObjectEntity.BankId,
         "@BankName", accountingObjectEntity.BankName,
         "@ContactName", accountingObjectEntity.ContactName,
         "@ContactAddress", accountingObjectEntity.ContactAddress,
         "@ContactIdNumber", accountingObjectEntity.ContactIdNumber,
         "@IssueDate", accountingObjectEntity.IssueDate,
         "@IssueAddress", accountingObjectEntity.IssueAddress,
         "@IsActive", accountingObjectEntity.IsActive
     });
 }
Ejemplo n.º 5
0
 internal static AccountingObjectModel FromDataTransferObject(AccountingObjectEntity entity)
 {
     return(entity == null ? null : AutoMapper.Mapper.Map <AccountingObjectEntity, AccountingObjectModel>(entity));
 }
        public string UpdateAccountingObject(AccountingObjectEntity accountingObject)
        {
            const string sql = @"uspUpdate_AccountingObject";

            return(Db.Update(sql, true, Take(accountingObject)));
        }
        public int InsertAccountingObject(AccountingObjectEntity accountingObject)
        {
            const string sql = @"uspInsert_AccountingObject";

            return(Db.Insert(sql, true, Take(accountingObject)));
        }
 /// <summary>
 /// Takes the specified budget source property.
 /// </summary>
 /// <param name="accountingObjectEntity">The take.</param>
 /// <returns></returns>
 private static object[] Take(AccountingObjectEntity accountingObjectEntity)
 {
     return(new object[]
     {
         "@AccountingObjectID", accountingObjectEntity.AccountingObjectId,
         "@AccountingObjectCode", accountingObjectEntity.AccountingObjectCode,
         "@AccountingObjectCategoryID", accountingObjectEntity.AccountingObjectCategoryId,
         "@AccountingObjectName", accountingObjectEntity.AccountingObjectName,
         "@Address", accountingObjectEntity.Address,
         "@Tel", accountingObjectEntity.Tel,
         "@Fax", accountingObjectEntity.Fax,
         "@Website", accountingObjectEntity.Website,
         "@BankAccount", accountingObjectEntity.BankAccount,
         "@BankName", accountingObjectEntity.BankName,
         "@CompanyTaxCode", accountingObjectEntity.CompanyTaxCode,
         "@BudgetCode", accountingObjectEntity.BudgetCode,
         "@AreaCode", accountingObjectEntity.AreaCode,
         "@Description", accountingObjectEntity.Description,
         "@ContactName", accountingObjectEntity.ContactName,
         "@ContactTitle", accountingObjectEntity.ContactTitle,
         "@ContactSex", accountingObjectEntity.ContactSex,
         "@ContactMobile", accountingObjectEntity.ContactMobile,
         "@ContactEmail", accountingObjectEntity.ContactEmail,
         "@ContactOfficeTel", accountingObjectEntity.ContactOfficeTel,
         "@ContactHomeTel", accountingObjectEntity.ContactHomeTel,
         "@ContactAddress", accountingObjectEntity.ContactAddress,
         "@IsEmployee", accountingObjectEntity.IsEmployee,
         "@IsPersonal", accountingObjectEntity.IsPersonal,
         "@IdentificationNumber", accountingObjectEntity.IdentificationNumber,
         "@IssueDate", accountingObjectEntity.IssueDate,
         "@IssueBy", accountingObjectEntity.IssueBy,
         "@DepartmentID", accountingObjectEntity.DepartmentId,
         "@SalaryScaleID", accountingObjectEntity.SalaryScaleId,
         "@Insured", accountingObjectEntity.Insured,
         "@LabourUnionFee", accountingObjectEntity.LabourUnionFee,
         "@FamilyDeductionAmount", accountingObjectEntity.FamilyDeductionAmount,
         "@IsActive", accountingObjectEntity.IsActive,
         "@ProjectID", accountingObjectEntity.ProjectId,
         "@IsCustomerVendor", accountingObjectEntity.IsCustomerVendor,
         "@SalaryCoefficient", accountingObjectEntity.SalaryCoefficient,
         "@NumberFamilyDependent", accountingObjectEntity.NumberFamilyDependent,
         "@EmployeeTypeID", accountingObjectEntity.EmployeeTypeId,
         "@SalaryForm", accountingObjectEntity.SalaryForm,
         "@SalaryPercentRate", accountingObjectEntity.SalaryPercentRate,
         "@SalaryAmount", accountingObjectEntity.SalaryAmount,
         "@IsPayInsuranceOnSalary", accountingObjectEntity.IsPayInsuranceOnSalary,
         "@InsuranceAmount", accountingObjectEntity.InsuranceAmount,
         "@IsUnEmploymentInsurance", accountingObjectEntity.IsUnEmploymentInsurance,
         "@RefTypeAO", accountingObjectEntity.RefTypeAO,
         "@SalaryGrade", accountingObjectEntity.SalaryGrade,
         "@CustomField1", accountingObjectEntity.CustomField1,
         "@CustomField2", accountingObjectEntity.CustomField2,
         "@CustomField3", accountingObjectEntity.CustomField3,
         "@CustomField4", accountingObjectEntity.CustomField4,
         "@CustomField5", accountingObjectEntity.CustomField5,
         "@IsPaidInsuranceForPayrollItem", accountingObjectEntity.IsPaidInsuranceForPayrollItem,
         "@IsBornLeave", accountingObjectEntity.IsBornLeave,
         "@TaxDepartmentName", accountingObjectEntity.TaxDepartmentName,
         "@TreasuryName", accountingObjectEntity.TreasuryName,
         "@BudgetChapterID", accountingObjectEntity.BudgetChapterId,
         "@FundStructureID", accountingObjectEntity.BudgetItemId,
         "@OrganizationFeeCode", accountingObjectEntity.OrganizationFeeCode,
         "@OrganizationManageFee", accountingObjectEntity.OrganizationManageFee,
         "@TreasuryManageFee", accountingObjectEntity.TreasuryManageFee,
     });
 }
 public string Delete(AccountingObjectEntity obj)
 {
     throw new NotImplementedException();
 }
 public int Insert(AccountingObjectEntity obj)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Inserts the account object.
        /// </summary>
        /// <param name="accountingObjectEntity">The accounting object entity.</param>
        /// <returns></returns>
        public AccountingObjectResponse InsertAccountObject(AccountingObjectEntity accountingObjectEntity)
        {
            var response = new AccountingObjectResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                var accoutingObjects = AccountingObjectDao.GetAccountingObjectByCode(accountingObjectEntity.AccountingObjectCode.Trim());
                var accoutingObject  = accoutingObjects.Where(x => x.IsEmployee = false).ToList();
                if (accoutingObject.Count > 0 && accountingObjectEntity.IsEmployee == false)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = @"Mã đối tượng " + accountingObjectEntity.AccountingObjectCode.Trim() + @" đã tồn tại!";
                    return(response);
                }
                var accoutingObjectEmployees = AccountingObjectDao.GetAccountingObjectByCode(accountingObjectEntity.AccountingObjectCode.Trim());
                var accoutingObjectEmployee  = accoutingObjectEmployees.Where(x => x.IsEmployee).ToList();
                if (accoutingObjectEmployee.Count > 0 && accountingObjectEntity.IsEmployee == true)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = @"Mã nhân viên " + accountingObjectEntity.AccountingObjectCode.Trim() + @" đã tồn tại!";
                    return(response);
                }
                if (!accountingObjectEntity.Validate())
                {
                    foreach (string error in accountingObjectEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }

                accountingObjectEntity.AccountingObjectId = Guid.NewGuid().ToString();
                var accObject =
                    AccountingObjectCategoryDao.GetAccountingObjectCategory(accountingObjectEntity.AccountingObjectCategoryId);
                if (accObject != null)
                {
                    if (accObject.AccountingObjectCategoryCode == "NCC")
                    {
                        accountingObjectEntity.IsCustomerVendor = true;
                    }
                }
                //   var validAccountingObject = AccountingObjectDao.Get
                response.Message = AccountingObjectDao.InsertAccountingObject(accountingObjectEntity);
                if (accountingObjectEntity.AccountingObjectBanks.Count() > 0)
                {
                    accountingObjectEntity.AccountingObjectBanks.ForEach(item =>
                    {
                        var bank = new BankEntity()
                        {
                            BankId       = Guid.NewGuid().ToString(),
                            BankAccount  = item.BankAccount,
                            BankName     = item.BankName,
                            IsActive     = true,
                            ProjectId    = accountingObjectEntity.AccountingObjectId,
                            IsOpenInBank = true,
                            SortBank     = item.SortBank,
                        };
                        BankDAO.InsertBank(bank);
                    });
                }
                if (!string.IsNullOrEmpty(response.Message))
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                response.AccountingObjectId = accountingObjectEntity.AccountingObjectId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }
        /// <summary>
        /// Updates the accounting object.
        /// </summary>
        /// <param name="accountingObjectEntity">The accounting object entity.</param>
        /// <returns></returns>
        public AccountingObjectResponse UpdateAccountingObject(AccountingObjectEntity accountingObjectEntity)
        {
            var response = new AccountingObjectResponse {
                Acknowledge = AcknowledgeType.Success
            };

            try
            {
                var accoutingObjects = AccountingObjectDao.GetAccountingObjectByCode(accountingObjectEntity.AccountingObjectCode.Trim());
                var accoutingObject  = accoutingObjects.Where(x => x.IsEmployee == false && x.AccountingObjectId != accountingObjectEntity.AccountingObjectId).ToList();
                if (accoutingObject.Count > 0 && accountingObjectEntity.IsEmployee == false)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = @"Mã đối tượng " + accountingObjectEntity.AccountingObjectCode.Trim() + @" đã tồn tại!";
                    return(response);
                }
                var accoutingObjectEmployees = AccountingObjectDao.GetAccountingObjectByCode(accountingObjectEntity.AccountingObjectCode.Trim());
                var accoutingObjectEmployee  = accoutingObjectEmployees.Where(x => x.IsEmployee && x.AccountingObjectId != accountingObjectEntity.AccountingObjectId).ToList();
                if (accoutingObjectEmployee.Count > 0 && accountingObjectEntity.IsEmployee == true)
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    response.Message     = @"Mã nhân viên " + accountingObjectEntity.AccountingObjectCode.Trim() + @" đã tồn tại!";
                    return(response);
                }
                if (!accountingObjectEntity.Validate())
                {
                    foreach (string error in accountingObjectEntity.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                var accObject =
                    AccountingObjectCategoryDao.GetAccountingObjectCategory(accountingObjectEntity.AccountingObjectCategoryId);
                if (accObject != null)
                {
                    if (accObject.AccountingObjectCategoryCode == "NCC")
                    {
                        accountingObjectEntity.IsCustomerVendor = true;
                    }
                }

                response.Message = AccountingObjectDao.UpdateAccountingObject(accountingObjectEntity);
                // lay ra danh sach bank cu
                var oldBanks = BankDAO.GetProjectBank(accountingObjectEntity.AccountingObjectId);
                var newbanks = accountingObjectEntity.AccountingObjectBanks;
                oldBanks = oldBanks.Where(o => accountingObjectEntity.AccountingObjectBanks.Count() == 0 || !accountingObjectEntity.AccountingObjectBanks.Any(pb => o.BankId == pb.BankId)).ToList();
                if (oldBanks.Count() > 0 && newbanks.Count != 0)
                {
                    oldBanks.ForEach(bank =>
                    {
                        response.Message = BankDAO.DeleteBank(bank);
                        if (!string.IsNullOrEmpty(response.Message))
                        {
                            if (response.Message.Contains("FK"))
                            {
                                response.Message = @"Bạn không thể xóa tài khoản " + bank.BankAccount + " vì đã có phát sinh trong chứng từ hoặc danh mục liên quan!";
                            }
                            response.Acknowledge = AcknowledgeType.Failure;
                            throw new Exception(response.Message);
                        }
                    });
                }
                ;
                #region insert bank
                if (accountingObjectEntity.AccountingObjectBanks.Count() > 0)
                {
                    accountingObjectEntity.AccountingObjectBanks.ForEach(item =>
                    {
                        if (item.BankId == null || item.BankId == Guid.Empty.ToString())
                        {
                            var bank = new BankEntity()
                            {
                                BankId       = Guid.NewGuid().ToString(),
                                BankAccount  = item.BankAccount,
                                BankName     = item.BankName,
                                IsActive     = true,
                                ProjectId    = accountingObjectEntity.AccountingObjectId,
                                IsOpenInBank = true,
                                SortBank     = item.SortBank,
                            };
                            BankDAO.InsertBank(bank);
                        }
                        else
                        {
                            var bank = new BankEntity()
                            {
                                BankId       = item.BankId,
                                BankAccount  = item.BankAccount,
                                BankName     = item.BankName,
                                IsActive     = true,
                                ProjectId    = accountingObjectEntity.AccountingObjectId,
                                IsOpenInBank = true,
                                SortBank     = item.SortBank,
                            };
                            BankDAO.UpdateBank(bank);
                        }
                    });
                }
                #endregion
                if (!string.IsNullOrEmpty(response.Message))
                {
                    response.Acknowledge = AcknowledgeType.Failure;
                    return(response);
                }
                response.AccountingObjectId = accountingObjectEntity.AccountingObjectId;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(response);
            }
        }