update institutionContractController and application to improve validation and switch to async operations for contract creation

This commit is contained in:
MahanCh
2025-08-03 10:53:08 +03:30
parent 7a33b7da46
commit 1f3bf123c4
3 changed files with 280 additions and 91 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks;
using _0_Framework.Application;
using CompanyManagment.App.Contracts.Checkout;
using CompanyManagment.App.Contracts.InstitutionContractContactinfo;
using CompanyManagment.App.Contracts.Workshop;
using Microsoft.AspNetCore.Mvc;
@@ -55,8 +56,32 @@ public interface IInstitutionContractApplication
(InstitutionContractListSearchModel searchModel);
#endregion
}
Task<OperationResult> CreateAsync(CreateInstitutionContractRequest command);
}
public class CreateInstitutionContractRequest
{
public List<CreateContactInfo> ContactInfos { get; set; }
public long ContractingPartyId { get; set; }
public long RepresentativeId { get; set; }
public string TypeOfContract { get; set; }
public string ContractDateFa { get; set; }
public string ContractStartFa { get; set; }
public string ContractEndFa { get; set; }
public string Address { get; set; }
public string State { get; set; }
public string City { get; set; }
public string OfficialCompany { get; set; }
public string HasValueAddedTax { get; set; }
public string ContractAmountString { get; set; }
public string DailyCompenseationString { get; set; }
public string ObligationString { get; set; }
public string TotalAmountString { get; set; }
public string ValueAddedTaxStr { get; set; }
public string WorkshopManualCount { get; set; }
public string EmployeeManualCount { get; set; }
public string Description { get; set; }
}
public class InstitutionContractListSearchModel
{
/// <summary>

View File

@@ -30,9 +30,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
private readonly IWorkshopRepository _workshopRepository;
private readonly ILeftWorkRepository _leftWorkRepository;
private readonly IWorkshopApplication _workshopApplication;
public InstitutionContractApplication(IInstitutionContractRepository institutionContractRepository, IPersonalContractingPartyRepository contractingPartyRepository, IRepresentativeRepository representativeRepository, IEmployerRepository employerRepository, IWorkshopRepository workshopRepository, ILeftWorkRepository leftWorkRepository, IFinancialStatmentApplication financialStatmentApplication, IWorkshopApplication workshopApplication)
public InstitutionContractApplication(IInstitutionContractRepository institutionContractRepository,
IPersonalContractingPartyRepository contractingPartyRepository,
IRepresentativeRepository representativeRepository, IEmployerRepository employerRepository,
IWorkshopRepository workshopRepository, ILeftWorkRepository leftWorkRepository,
IFinancialStatmentApplication financialStatmentApplication, IWorkshopApplication workshopApplication)
{
_institutionContractRepository = institutionContractRepository;
_contractingPartyRepository = contractingPartyRepository;
@@ -46,25 +50,28 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public OperationResult Create(CreateInstitutionContract command)
{
string contractingPartyName = String.Empty;
bool dateMessages = false;
string dateMaessageResult = String.Empty;
var opration = new OperationResult();
if (_institutionContractRepository.Exists(x =>
x.ContractingPartyId == command.ContractingPartyId && x.RepresentativeId == command.RepresentativeId && x.TypeOfContract == command.TypeOfContract))
return opration.Failed("برای این معرف و طرف حساب قبلا قرارداد ایجاد شده است، شما میتوانید از تمدید استفاده کنید");
x.ContractingPartyId == command.ContractingPartyId && x.RepresentativeId == command.RepresentativeId &&
x.TypeOfContract == command.TypeOfContract))
return opration.Failed(
"برای این معرف و طرف حساب قبلا قرارداد ایجاد شده است، شما میتوانید از تمدید استفاده کنید");
if (string.IsNullOrWhiteSpace(command.ContractDateFa))
{
dateMaessageResult = "تاریخ قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractStartFa))
{
dateMaessageResult += "تاریخ شروع قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractEndFa))
{
dateMaessageResult += "تاریخ پایان قراراداد اجباری است. ";
@@ -81,7 +88,6 @@ public class InstitutionContractApplication : IInstitutionContractApplication
else if (command.ContractingPartyId < 1 && command.RepresentativeId > 1)
{
return opration.Failed("طرف حساب را انتخاب کنید");
}
else if (command.ContractingPartyId < 1 && command.RepresentativeId < 1)
{
@@ -94,15 +100,17 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var contractingParty = _contractingPartyRepository.GetDetails(command.ContractingPartyId);
//شماره قرارداد
var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/0";
///////////////////////
if (command.ContactInformationList.Count == 0)
return opration.Failed("ورود شماره تماس برای ارسال پیامک الزامیست");
var accountContact = command.ContactInformationList.Where(x =>
x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه" && !string.IsNullOrWhiteSpace(x.PhoneNumber)).ToList();
if(accountContact.Count == 0)
x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه" &&
!string.IsNullOrWhiteSpace(x.PhoneNumber)).ToList();
if (accountContact.Count == 0)
return opration.Failed("ورود شماره همراه با سمت طرف قرارداد برای ساخت حساب کاربری الزامیست");
var accountContactCount = command.ContactInformationList.Where(x => x.PhoneType == "شماره همراه" && x.Position == "طرف قرارداد").ToList();
var accountContactCount = command.ContactInformationList
.Where(x => x.PhoneType == "شماره همراه" && x.Position == "طرف قرارداد").ToList();
if (accountContactCount.Count > 1)
return opration.Failed("فقط یکی از شماره تلفن ها میتواند سمت طرف قرارداد داشته باشد");
@@ -117,25 +125,22 @@ public class InstitutionContractApplication : IInstitutionContractApplication
if (command.Address != null && command.State == null)
{
return opration.Failed("لطفا استان و شهر را انتخاب کنید");
}
if ((command.Address != null && command.State != null) && command.City == "شهرستان")
{
return opration.Failed("لطفا شهر را انتخاب کنید");
}
if (command.Address == null && command.State != null)
{
return opration.Failed("لطفا آدرس را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.OfficialCompany))
return opration.Failed("رسمی یا غیر رسمی بودن پرداخت را مشخص کنید");
if(command.OfficialCompany == "Official" && string.IsNullOrWhiteSpace(command.HasValueAddedTax))
if (command.OfficialCompany == "Official" && string.IsNullOrWhiteSpace(command.HasValueAddedTax))
return opration.Failed("وضعیت ارزش افزوده را مشخص کنید");
if (string.IsNullOrWhiteSpace(command.TypeOfContract))
return opration.Failed("عنوان قرارداد را انتخاب کنید");
@@ -148,7 +153,9 @@ public class InstitutionContractApplication : IInstitutionContractApplication
command.ObligationString = "0";
if (string.IsNullOrWhiteSpace(command.TotalAmountString))
command.TotalAmountString = "0";
command.ValueAddedTax = string.IsNullOrWhiteSpace(command.ValueAddedTaxStr) ? 0 : command.ValueAddedTaxStr.MoneyToDouble();
command.ValueAddedTax = string.IsNullOrWhiteSpace(command.ValueAddedTaxStr)
? 0
: command.ValueAddedTaxStr.MoneyToDouble();
var contractAmount = command.ContractAmountString.ToDoubleMoney();
command.ContractAmount = Convert.ToDouble(contractAmount);
var DailyCompenseation = command.DailyCompenseationString.ToDoubleMoney();
@@ -165,14 +172,15 @@ public class InstitutionContractApplication : IInstitutionContractApplication
// valueAddedTax = command.ContractAmount * 0.1;
// command.ContractAmount += valueAddedTax;
//}
var createContract = new InstitutionContract(contractNo, command.RepresentativeId, representative,
command.ContractingPartyId,
contractingPartyName, contractDateGr, command.ContractDateFa, command.State, command.City,
command.Address, contractStartGr,
command.ContractStartFa, contractEndGr, command.ContractEndFa, command.ContractAmount,
command.DailyCompenseation, command.Obligation,
command.TotalAmount, 0,command.WorkshopManualCount,command.EmployeeManualCount,command.Description, command.OfficialCompany, command.TypeOfContract,command.HasValueAddedTax,command.ValueAddedTax);
command.TotalAmount, 0, command.WorkshopManualCount, command.EmployeeManualCount, command.Description,
command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax, command.ValueAddedTax);
_institutionContractRepository.Create(createContract);
_institutionContractRepository.SaveChanges();
@@ -181,27 +189,29 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public OperationResult Extension(CreateInstitutionContract command)
{
bool dateMessages = false;
string dateMaessageResult = String.Empty;
var opration = new OperationResult();
command.ExtensionNo += 1;
if (_institutionContractRepository.Exists(x =>
x.ExtensionNo == command.ExtensionNo && x.ContractingPartyId == command.ContractingPartyId && x.TypeOfContract == command.TypeOfContract))
x.ExtensionNo == command.ExtensionNo && x.ContractingPartyId == command.ContractingPartyId &&
x.TypeOfContract == command.TypeOfContract))
return opration.Failed("برای این قرارداد قبلا تمدید ایجاد شده است");
if (string.IsNullOrWhiteSpace(command.ContractDateFa))
{
dateMaessageResult = "تاریخ قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractStartFa))
{
dateMaessageResult += "تاریخ شروع قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractEndFa))
{
dateMaessageResult += "تاریخ پایان قراراداد اجباری است. ";
@@ -211,7 +221,8 @@ public class InstitutionContractApplication : IInstitutionContractApplication
if (dateMessages)
return opration.Failed(dateMaessageResult);
var firstContract = _institutionContractRepository.GetFirstContract(command.ContractingPartyId, command.TypeOfContract);
var firstContract =
_institutionContractRepository.GetFirstContract(command.ContractingPartyId, command.TypeOfContract);
var syear = firstContract.ContractStartFa.Substring(0, 4);
var smonth = firstContract.ContractStartFa.Substring(5, 2);
@@ -219,32 +230,32 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var contractingParty = _contractingPartyRepository.GetDetails(command.ContractingPartyId);
//شماره قرارداد
var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/{command.ExtensionNo}";
var contractStartGr = command.ContractStartFa.ToGeorgianDateTime();
var contractEndGr = command.ContractEndFa.ToGeorgianDateTime();
var contractDateGr = command.ContractDateFa.ToGeorgianDateTime();
if (_institutionContractRepository.Exists(x =>
((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr)||(contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) && x.TypeOfContract == command.TypeOfContract && x.ContractingPartyId == command.ContractingPartyId))
((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr) ||
(contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) &&
x.TypeOfContract == command.TypeOfContract && x.ContractingPartyId == command.ContractingPartyId))
return opration.Failed("تاریخ شروع و پایان وارد شده با قرارداد دیگری تداخل دارد");
if (command.Address != null && command.State == null)
{
return opration.Failed("لطفا استان و شهر را انتخاب کنید");
}
if ((command.Address != null && command.State != null) && command.City == "شهرستان")
{
return opration.Failed("لطفا شهر را انتخاب کنید");
}
if (command.Address == null && command.State != null)
{
return opration.Failed("لطفا آدرس را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.OfficialCompany))
return opration.Failed("رسمی یا غیر رسمی بودن پرداخت را مشخص کنید");
if (command.OfficialCompany == "Official" && string.IsNullOrWhiteSpace(command.HasValueAddedTax))
@@ -259,7 +270,9 @@ public class InstitutionContractApplication : IInstitutionContractApplication
command.ObligationString = "0";
if (string.IsNullOrWhiteSpace(command.TotalAmountString))
command.TotalAmountString = "0";
command.ValueAddedTax = string.IsNullOrWhiteSpace(command.ValueAddedTaxStr) ? 0 : command.ValueAddedTaxStr.MoneyToDouble();
command.ValueAddedTax = string.IsNullOrWhiteSpace(command.ValueAddedTaxStr)
? 0
: command.ValueAddedTaxStr.MoneyToDouble();
var contractAmount = command.ContractAmountString.ToDoubleMoney();
command.ContractAmount = Convert.ToDouble(contractAmount);
var DailyCompenseation = command.DailyCompenseationString.ToDoubleMoney();
@@ -274,11 +287,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
command.Address, contractStartGr,
command.ContractStartFa, contractEndGr, command.ContractEndFa, command.ContractAmount,
command.DailyCompenseation, command.Obligation,
command.TotalAmount, command.ExtensionNo, command.WorkshopManualCount, command.EmployeeManualCount, command.Description,command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax, command.ValueAddedTax);
command.TotalAmount, command.ExtensionNo, command.WorkshopManualCount, command.EmployeeManualCount,
command.Description, command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax,
command.ValueAddedTax);
_institutionContractRepository.Create(createContract);
_institutionContractRepository.SaveChanges();
return opration.Succcedded(createContract.id);
}
@@ -291,14 +306,17 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var ContractEdit = _institutionContractRepository.Get(command.Id);
if (ContractEdit == null)
opration.Failed("رکورد مورد نظر وجود ندارد");
var contractStartGr = command.ContractStartFa.ToGeorgianDateTime();
var contractEndGr = command.ContractEndFa.ToGeorgianDateTime();
var contractDateGr = command.ContractDateFa.ToGeorgianDateTime();
if (_institutionContractRepository.Exists(x =>
x.ContractingPartyId == ContractEdit.ContractingPartyId && ((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr) || (contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) && x.id != command.Id && x.TypeOfContract == command.TypeOfContract))
x.ContractingPartyId == ContractEdit.ContractingPartyId &&
((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr) ||
(contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) && x.id != command.Id &&
x.TypeOfContract == command.TypeOfContract))
return opration.Failed("در بازه تاریخ وارد شده قرارداد دیگری وجود دارد");
//if (_institutionContractRepository.Exists(x =>
// x.ContractingPartyId == ContractEdit.ContractingPartyId && (x.ContractStartGr <= contractDateGr || x.ContractDateGr <= contractDateGr) && x.id != command.Id))
@@ -308,11 +326,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
dateMaessageResult = "تاریخ قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractStartFa))
{
dateMaessageResult += "تاریخ شروع قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractEndFa))
{
dateMaessageResult += "تاریخ پایان قراراداد اجباری است. ";
@@ -323,19 +343,16 @@ public class InstitutionContractApplication : IInstitutionContractApplication
return opration.Failed(dateMaessageResult);
if (command.Address != null && command.State == null)
{
return opration.Failed("لطفا استان و شهر را انتخاب کنید");
}
if ((command.Address != null && command.State != null) && command.City == "شهرستان")
{
return opration.Failed("لطفا شهر را انتخاب کنید");
}
if (command.Address == null && command.State != null)
{
return opration.Failed("لطفا آدرس را وارد کنید");
}
@@ -354,7 +371,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
command.ObligationString = "0";
if (string.IsNullOrWhiteSpace(command.TotalAmountString))
command.TotalAmountString = "0";
command.ValueAddedTax = command.ValueAddedTaxStr.MoneyToDouble();
var contractAmount = command.ContractAmountString.ToDoubleMoney();
command.ContractAmount = Convert.ToDouble(contractAmount);
@@ -365,12 +382,15 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var TotalAmount = command.TotalAmountString.ToDoubleMoney();
command.TotalAmount = Convert.ToDouble(TotalAmount);
ContractEdit.Edit(contractDateGr, command.ContractDateFa,command.State,command.City,command.Address,contractStartGr,
command.ContractStartFa,contractEndGr,command.ContractEndFa,command.ContractAmount,command.DailyCompenseation,
command.Obligation,command.TotalAmount,command.WorkshopManualCount, command.EmployeeManualCount,command.Description,command.OfficialCompany, command.TypeOfContract, command.ValueAddedTax, command.HasValueAddedTax);
ContractEdit.Edit(contractDateGr, command.ContractDateFa, command.State, command.City, command.Address,
contractStartGr,
command.ContractStartFa, contractEndGr, command.ContractEndFa, command.ContractAmount,
command.DailyCompenseation,
command.Obligation, command.TotalAmount, command.WorkshopManualCount, command.EmployeeManualCount,
command.Description, command.OfficialCompany, command.TypeOfContract, command.ValueAddedTax,
command.HasValueAddedTax);
_institutionContractRepository.SaveChanges();
return opration.Succcedded(command.Id);
}
public EditInstitutionContract GetDetails(long id)
@@ -380,18 +400,17 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public List<InstitutionContractViewModel> Search(InstitutionContractSearchModel searchModel)
{
var query = _institutionContractRepository.Search(searchModel);
var join = new List<InstitutionContractViewModel>();
var now = DateTime.Now;
var nowFa = now.ToFarsi();
var endFa = nowFa.FindeEndOfMonth();
var endThisMontGr = endFa.ToGeorgianDateTime();
//var watch = System.Diagnostics.Stopwatch.StartNew();
var newResult = query.Select(x => new InstitutionContractViewModel
{
Id = x.Id,
@@ -407,8 +426,10 @@ public class InstitutionContractApplication : IInstitutionContractApplication
//BlockTimes = _contractingPartyRepository.GetDetails(x.ContractingPartyId).BlockTimes,
ContractingPartyId = x.ContractingPartyId,
EmployerViewModels = _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId),
EmployerNo = _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId).FirstOrDefault(xn => xn.ContractingPartyID == x.ContractingPartyId)?.EmployerNo,
EmployerName = _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId).FirstOrDefault(xn => xn.ContractingPartyID == x.ContractingPartyId)?.FullName,
EmployerNo = _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId)
.FirstOrDefault(xn => xn.ContractingPartyID == x.ContractingPartyId)?.EmployerNo,
EmployerName = _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId)
.FirstOrDefault(xn => xn.ContractingPartyID == x.ContractingPartyId)?.FullName,
//EmployerId = _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId).FirstOrDefault(xn => xn.ContractingPartyID == x.ContractingPartyId)?.Id == null ? 0 :
// _employerRepository.GetEmployerByContracrtingPartyID(x.ContractingPartyId).FirstOrDefault(xn => xn.ContractingPartyID == x.ContractingPartyId)!.Id,
ContractAmount = x.ContractAmount,
@@ -425,7 +446,6 @@ public class InstitutionContractApplication : IInstitutionContractApplication
//EmployeeCount = WorkShopDetailsAndEmployeeCount(x.ContractingPartyId).EmployeeCount,
//ArchiveCode = WorkShopDetailsAndEmployeeCount(x.ContractingPartyId).ArchiveCode,
TypeOfContract = x.TypeOfContract
}).ToList();
//Console.WriteLine("efTime : " + watch.Elapsed);
@@ -451,7 +471,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
item.IsContractingPartyBlock = contractingParty.IsBlock;
item.BlockTimes = contractingParty.BlockTimes;
}
var employer = _employerRepository.GetEmployerByContracrtingPartyID(item.ContractingPartyId);
item.EmployerViewModels = employer;
@@ -473,14 +493,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
//var reslt = _workshopApplication.GetConnectedPersonnels(workshopId);
//var noBlock = reslt.Where(x => x.Black == false).ToList();
//joinPersonelList.AddRange(noBlock);
var p = _workshopApplication.PersonnelCount(workshopId);
pCount += p;
var p = _workshopApplication.PersonnelCount(workshopId);
pCount += p;
}
//var joinlistWithoutDuplicat = joinPersonelList.GroupBy(x => x.PersonName).Select(x => x.First()).ToList();
//left = joinlistWithoutDuplicat.Count();
// var left= _leftWorkRepository.GetLeftPersonelByWorkshopId(workshopIds).Count();
item.EmployeeCount = Convert.ToString(pCount);
//if (item.ContractEndGr < now)
// item.ExpireColor = "black";
@@ -496,8 +515,8 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var arc = workshop.Select(x => new ArchiveCodConvertoint
{
ArchiveCodeInt = x.ArchiveCode.Substring(0, 1) == "b" ? 10000000 : x.ArchiveCode.ConvertToInt(),
}).OrderBy(x=>x.ArchiveCodeInt).ToList();
var minArchiveCode = arc.Min(x=>x.ArchiveCodeInt);
}).OrderBy(x => x.ArchiveCodeInt).ToList();
var minArchiveCode = arc.Min(x => x.ArchiveCodeInt);
archiveCode = minArchiveCode == 10000000 ? 0 : minArchiveCode;
}
@@ -537,11 +556,10 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var findeByFilter = new List<InstitutionContractViewModel>();
if (searchModel.WorkshopId != 0)
{
foreach (var item in join)
{
var check = item.WorkshopViewModels.Where(x => x.Id == searchModel.WorkshopId).ToList();
if(check.Count >0)
if (check.Count > 0)
findeByFilter.Add(item);
}
@@ -551,32 +569,29 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var findeByFilter2 = new List<InstitutionContractViewModel>();
if (searchModel.EmployerId != 0)
{
foreach (var item in join)
{
var check = item.EmployerViewModels.Where(x => x.Id == searchModel.EmployerId).ToList();
if (check.Count > 0)
findeByFilter2.Add(item);
}
join = findeByFilter2;
}
join = join.OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
.ThenBy(x => x.WorkshopCount == "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
.ThenBy(x=>x.ExpireColor=="red")
.ThenBy(x => x.ExpireColor == "red")
.ThenBy(x => x.ExpireColor == "purple")
.ThenBy(x=>x.ExpireColor=="black").ToList();
.ThenBy(x => x.ExpireColor == "black").ToList();
return join;
}
public List<InstitutionContractViewModel> NewSearch(InstitutionContractSearchModel searchModel)
{
return _institutionContractRepository.NewSearch(searchModel);
return _institutionContractRepository.NewSearch(searchModel);
}
@@ -584,10 +599,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
{
var result = _institutionContractRepository.NewSearch(new InstitutionContractSearchModel());
return result.Where(x => x.IsActiveString == "true" && x.IsContractingPartyBlock !="true" && x.WorkshopCount != "0" && x.ContractStartGr <= DateTime.Now && x.ContractEndGr >= DateTime.Now).ToList();
return result.Where(x =>
x.IsActiveString == "true" && x.IsContractingPartyBlock != "true" && x.WorkshopCount != "0" &&
x.ContractStartGr <= DateTime.Now && x.ContractEndGr >= DateTime.Now).ToList();
}
public string ExpCheckColor(DateTime now, DateTime ContractEndGr, DateTime endThisMontGr, string ContractAmount, string isActiveString)
public string ExpCheckColor(DateTime now, DateTime ContractEndGr, DateTime endThisMontGr, string ContractAmount,
string isActiveString)
{
string result = "";
@@ -605,7 +623,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public TotalbalancViewModel TotalBalance(long contractingPartyId)
{
var result = new TotalbalancViewModel();
var firstGetStatement = _financialStatmentApplication.GetDetailsByContractingPartyId(contractingPartyId);
var allTransactions = firstGetStatement.FinancialTransactionViewModels;
if (allTransactions != null)
@@ -616,6 +634,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
result.TotalBalanceDbl = debt - credit;
result.TotalBalanceStr = result.TotalBalanceDbl.ToMoney();
}
return result;
}
@@ -623,11 +642,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
{
var result = new WorkshopsAndEmployeeViewModel();
var emplId = _employerRepository.GetEmployerByContracrtingPartyID(contractingPartyId).Select(x => x.Id).ToList(); ;
var emplId = _employerRepository.GetEmployerByContracrtingPartyID(contractingPartyId).Select(x => x.Id)
.ToList();
;
result.WorkshopViewModels = _workshopRepository.GetWorkshopsByEmployerId(emplId);
var workshopIds = result.WorkshopViewModels.Select(x => x.Id).ToList();
var left = 0;
result.WorkshopCount= Convert.ToString(workshopIds.Count);
result.WorkshopCount = Convert.ToString(workshopIds.Count);
var joinPersonelList = new List<ConnectedPersonnelViewModel>();
foreach (var workshopId in workshopIds)
{
@@ -636,7 +657,6 @@ public class InstitutionContractApplication : IInstitutionContractApplication
//joinPersonelList.AddRange(noBlock);
var pCount = _workshopApplication.PersonnelCount(workshopId);
result.EmployeeCount = Convert.ToString(pCount);
}
//var joinlistWithoutDuplicat = joinPersonelList.GroupBy(x => x.PersonName).Select(x => x.First()).ToList();
//left = joinlistWithoutDuplicat.Count();
@@ -655,7 +675,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var minArchiveCode = arc.Min(x => x.ArchiveCodeInt);
result.ArchiveCode = minArchiveCode == 10000000 ? 0 : minArchiveCode;
}
return result;
}
@@ -675,13 +695,13 @@ public class InstitutionContractApplication : IInstitutionContractApplication
{
Id = get.Id,
ContractNo = get.ContractNo,
ContractStartFa = get.ContractStartFa,
ContractEndFa = get.ContractEndFa,
ContractingPartyName = get.ContractingPartyName,
ContractingPartyId = get.ContractingPartyId,
ContractDateFa = get.ContractDateFa,
State = get.State,
@@ -695,7 +715,6 @@ public class InstitutionContractApplication : IInstitutionContractApplication
Obligation = get.ObligationString,
TotalAmount = get.TotalAmountString,
WorkshopViewModels = workshops
};
return res;
}
@@ -703,7 +722,6 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public OperationResult Active(long id)
{
var opration = new OperationResult();
var contract = _institutionContractRepository.Get(id);
if (contract == null)
@@ -768,6 +786,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var res = _employerRepository.DeActiveAll(employer.Id);
}
}
return opration.Succcedded();
}
@@ -797,6 +816,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
var res = _employerRepository.ActiveAll(employer.Id);
}
}
return opration.Succcedded();
}
@@ -810,10 +830,10 @@ public class InstitutionContractApplication : IInstitutionContractApplication
contractingParty.Active();
_contractingPartyRepository.SaveChanges();
}
var employers =
_employerRepository.GetEmployerByContracrtingPartyID(contractingPartyId);
foreach (var employer in employers)
{
var res = _employerRepository.ActiveAll(employer.Id);
@@ -825,7 +845,6 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public void RemoveContract(long id)
{
_institutionContractRepository.RemoveContract(id);
}
@@ -861,7 +880,7 @@ public class InstitutionContractApplication : IInstitutionContractApplication
public void CreateContractingPartyAccount(long contractingPartyid, long accountId)
{
_institutionContractRepository.CreateContractingPartyAccount(contractingPartyid,accountId);
_institutionContractRepository.CreateContractingPartyAccount(contractingPartyid, accountId);
}
public double GetcontractAmount(int countPerson)
@@ -873,8 +892,147 @@ public class InstitutionContractApplication : IInstitutionContractApplication
{
return await _institutionContractRepository.GetList(searchModel);
}
}
public async Task<OperationResult> CreateAsync(CreateInstitutionContractRequest command)
{
string contractingPartyName = String.Empty;
bool dateMessages = false;
string dateMaessageResult = String.Empty;
var opration = new OperationResult();
if (_institutionContractRepository.Exists(x =>
x.ContractingPartyId == command.ContractingPartyId && x.RepresentativeId == command.RepresentativeId &&
x.TypeOfContract == command.TypeOfContract))
return opration.Failed(
"برای این معرف و طرف حساب قبلا قرارداد ایجاد شده است، شما میتوانید از تمدید استفاده کنید");
if (string.IsNullOrWhiteSpace(command.ContractDateFa))
{
dateMaessageResult = "تاریخ قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractStartFa))
{
dateMaessageResult += "تاریخ شروع قراراداد اجباری است. ";
dateMessages = true;
}
if (string.IsNullOrWhiteSpace(command.ContractEndFa))
{
dateMaessageResult += "تاریخ پایان قراراداد اجباری است. ";
dateMessages = true;
}
if (dateMessages)
return opration.Failed(dateMaessageResult);
if (command.RepresentativeId < 1 && command.ContractingPartyId > 1)
{
return opration.Failed("معرف را انتخاب کنید");
}
else if (command.ContractingPartyId < 1 && command.RepresentativeId > 1)
{
return opration.Failed("طرف حساب را انتخاب کنید");
}
else if (command.ContractingPartyId < 1 && command.RepresentativeId < 1)
{
return opration.Failed("معرف و طرف حساب را انتخاب کنید");
}
var syear = command.ContractStartFa.Substring(0, 4);
var smonth = command.ContractStartFa.Substring(5, 2);
var sday = command.ContractStartFa.Substring(8, 2);
var contractingParty = _contractingPartyRepository.GetDetails(command.ContractingPartyId);
//شماره قرارداد
var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/0";
///////////////////////
if (command.ContactInfos.Count == 0)
return opration.Failed("ورود شماره تماس برای ارسال پیامک الزامیست");
var accountContact = command.ContactInfos.Where(x =>
x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه" &&
!string.IsNullOrWhiteSpace(x.PhoneNumber)).ToList();
if (accountContact.Count == 0)
return opration.Failed("ورود شماره همراه با سمت طرف قرارداد برای ساخت حساب کاربری الزامیست");
var accountContactCount = command.ContactInfos
.Where(x => x.PhoneType == "شماره همراه" && x.Position == "طرف قرارداد").ToList();
if (accountContactCount.Count > 1)
return opration.Failed("فقط یکی از شماره تلفن ها میتواند سمت طرف قرارداد داشته باشد");
contractingPartyName = contractingParty.LName;
//نام معرف
var representative = _representativeRepository.GetDetails(command.RepresentativeId).FullName;
var contractStartGr = command.ContractStartFa.ToGeorgianDateTime();
var contractEndGr = command.ContractEndFa.ToGeorgianDateTime();
var contractDateGr = command.ContractDateFa.ToGeorgianDateTime();
if (command.Address != null && command.State == null)
{
return opration.Failed("لطفا استان و شهر را انتخاب کنید");
}
if ((command.Address != null && command.State != null) && command.City == "شهرستان")
{
return opration.Failed("لطفا شهر را انتخاب کنید");
}
if (command.Address == null && command.State != null)
{
return opration.Failed("لطفا آدرس را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.OfficialCompany))
return opration.Failed("رسمی یا غیر رسمی بودن پرداخت را مشخص کنید");
if (command.OfficialCompany == "Official" && string.IsNullOrWhiteSpace(command.HasValueAddedTax))
return opration.Failed("وضعیت ارزش افزوده را مشخص کنید");
if (string.IsNullOrWhiteSpace(command.TypeOfContract))
return opration.Failed("عنوان قرارداد را انتخاب کنید");
if (string.IsNullOrWhiteSpace(command.ContractAmountString))
command.ContractAmountString = "0";
if (string.IsNullOrWhiteSpace(command.DailyCompenseationString))
command.DailyCompenseationString = "0";
if (string.IsNullOrWhiteSpace(command.ObligationString))
command.ObligationString = "0";
if (string.IsNullOrWhiteSpace(command.TotalAmountString))
command.TotalAmountString = "0";
var valueAddedTax = string.IsNullOrWhiteSpace(command.ValueAddedTaxStr)
? 0
: command.ValueAddedTaxStr.MoneyToDouble();
var contractAmountStr = command.ContractAmountString.ToDoubleMoney();
var contractAmount = Convert.ToDouble(contractAmountStr);
var DailyCompenseationStr = command.DailyCompenseationString.ToDoubleMoney();
var dailyCompenseation = Convert.ToDouble(DailyCompenseationStr);
var ObligationStr = command.ObligationString.ToDoubleMoney();
var obligation = Convert.ToDouble(ObligationStr);
var TotalAmountStr = command.TotalAmountString.ToDoubleMoney();
var totalAmount = Convert.ToDouble(TotalAmountStr);
//var hasValueAddedTax = "false";
//double valueAddedTax = 0;
//if (command.HasValueAddedTax == "true")
//{
// hasValueAddedTax = "true";
// valueAddedTax = command.ContractAmount * 0.1;
// command.ContractAmount += valueAddedTax;
//}
var createContract = new InstitutionContract(contractNo, command.RepresentativeId, representative,
command.ContractingPartyId,
contractingPartyName, contractDateGr, command.ContractDateFa, command.State, command.City,
command.Address, contractStartGr,
command.ContractStartFa, contractEndGr, command.ContractEndFa, contractAmount,
dailyCompenseation, obligation,
totalAmount, 0, command.WorkshopManualCount, command.EmployeeManualCount, command.Description,
command.OfficialCompany, command.TypeOfContract, command.HasValueAddedTax, valueAddedTax);
_institutionContractRepository.Create(createContract);
_institutionContractRepository.SaveChanges();
return opration.Succcedded(createContract.id);
}
}
#region CustomViewModels
@@ -888,7 +1046,7 @@ public class WorkshopsAndEmployeeViewModel
{
public List<WorkshopViewModel> WorkshopViewModels { get; set; }
public string WorkshopCount { get; set; }
public string EmployeeCount { get; set;}
public string EmployeeCount { get; set; }
public int ArchiveCode { get; set; }
}

View File

@@ -8,6 +8,7 @@ using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Admin.Controllers;
/// <summary>
/// کنترلر قرارداد های مالی موسسه
/// </summary>
@@ -37,36 +38,41 @@ public class institutionContractController : AdminBaseController
return await _institutionContractApplication.GetList(searchModel);
}
/// <summary>
/// ایجاد
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
[HttpPost]
public async Task<ActionResult<OperationResult>>Create([FromBody]CreateInstitutionContract command)
public async Task<ActionResult<OperationResult>>Create([FromBody]CreateInstitutionContractRequest command)
{
var op = new OperationResult();
var counter = command.ContactInformationList.Count;
var counter = command.ContactInfos.Count;
//if (string.IsNullOrWhiteSpace(command.HasValueAddedTax))
// command.HasValueAddedTax = "false";
var phone = command.ContactInformationList.FirstOrDefault(x =>
var phone = command.ContactInfos.FirstOrDefault(x =>
x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه");
var conractingParty = _contractingPartyApplication.GetDetails(command.ContractingPartyId);
if (conractingParty.IsLegal == "حقیقی" && string.IsNullOrWhiteSpace(conractingParty.Nationalcode))
return new JsonResult(op.Failed("کد ملی طرف حساب وجود ندارد"));
if (conractingParty.IsLegal == "حقوقی" && string.IsNullOrWhiteSpace(conractingParty.NationalId))
return new JsonResult(op.Failed("شناسه ملی طرف حساب وجود ندارد"));
var result = _institutionContractApplication.Create(command);
var result =await _institutionContractApplication.CreateAsync(command);
if (result.IsSuccedded && counter > 0)
{
for (var i = 0; i <= counter - 1; i++)
{
if (command.ContactInformationList[i].PhoneNumber != null)
if (command.ContactInfos[i].PhoneNumber != null)
{
var contactinfo = new CreateContactInfo
{
InstitutionContractId = result.SendId,
PhoneType = command.ContactInformationList[i].PhoneType,
Position = command.ContactInformationList[i].Position,
PhoneNumber = command.ContactInformationList[i].PhoneNumber,
FnameLname = command.ContactInformationList[i].FnameLname,
SendSms = command.ContactInformationList[i].SendSmsString == "true" ? true : false
PhoneType = command.ContactInfos[i].PhoneType,
Position = command.ContactInfos[i].Position,
PhoneNumber = command.ContactInfos[i].PhoneNumber,
FnameLname = command.ContactInfos[i].FnameLname,
SendSms = command.ContactInfos[i].SendSmsString == "true" ? true : false
};
_contactInfoApplication.Create(contactinfo);
}