add extension completion handling in InstitutionContract workflows and update repositories
This commit is contained in:
@@ -58,4 +58,5 @@ public interface IInstitutionContractRepository : IRepository<long, InstitutionC
|
||||
Task<InstitutionContractExtensionWorkshopsResponse> GetExtenstionWorkshops(InstitutionContractExtensionWorkshopsRequest request);
|
||||
Task<InstitutionContractExtensionPlanResponse> GetExtenstionInstitutionPlan(InstitutionContractExtensionPlanRequest request);
|
||||
Task<InstitutionContractExtensionPaymentResponse> GetExtenstionPaymentMethod(InstitutionContractExtensionPaymentRequest request);
|
||||
Task<OperationResult> ExtenstionComplete(InstitutionContractExtensionCompleteRequest request);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class InstitutionContractExtenstionTempWorkshop
|
||||
{
|
||||
public InstitutionContractExtenstionTempWorkshop(string workshopName, int countPerson, bool contractAndCheckout, bool contractAndCheckoutInPerson,
|
||||
bool insurance, bool insuranceInPerson,
|
||||
bool rollCall,bool rollCallInPerson, bool customizeCheckout)
|
||||
bool rollCall,bool rollCallInPerson, bool customizeCheckout,double price)
|
||||
{
|
||||
WorkshopName = workshopName;
|
||||
CountPerson = countPerson;
|
||||
@@ -109,6 +109,7 @@ public class InstitutionContractExtenstionTempWorkshop
|
||||
ContractAndCheckoutInPerson = contractAndCheckoutInPerson;
|
||||
InsuranceInPerson = insuranceInPerson;
|
||||
RollCallInPerson = rollCallInPerson;
|
||||
Price = price;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -156,6 +157,8 @@ public class InstitutionContractExtenstionTempWorkshop
|
||||
/// </summary>
|
||||
public bool InsuranceInPerson { get; private set; }
|
||||
|
||||
public double Price{ get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -227,6 +227,13 @@ public interface IInstitutionContractApplication
|
||||
//TODO:Complete Data.
|
||||
|
||||
|
||||
Task<OperationResult> ExtenstionComplete(InstitutionContractExtensionCompleteRequest request);
|
||||
}
|
||||
|
||||
public class InstitutionContractExtensionCompleteRequest
|
||||
{
|
||||
public Guid TemporaryId { get; set; }
|
||||
public bool IsInstallment { get; set; }
|
||||
}
|
||||
|
||||
public class InstitutionContractExtensionPaymentResponse
|
||||
|
||||
@@ -997,6 +997,11 @@ public class InstitutionContractApplication : IInstitutionContractApplication
|
||||
contractingParty = contractingPartyResult.Data;
|
||||
}
|
||||
|
||||
if (_institutionContractRepository.Exists(x =>
|
||||
x.ContractingPartyId == contractingParty.id && x.RepresentativeId == command.RepresentativeId &&
|
||||
x.TypeOfContract == "JobRelation"))
|
||||
return opration.Failed(
|
||||
"برای این معرف و طرف حساب قبلا قرارداد ایجاد شده است، شما میتوانید از تمدید استفاده کنید");
|
||||
|
||||
var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/0";
|
||||
|
||||
@@ -1292,6 +1297,11 @@ public class InstitutionContractApplication : IInstitutionContractApplication
|
||||
return await _institutionContractRepository.GetExtenstionPaymentMethod(request);
|
||||
}
|
||||
|
||||
public async Task<OperationResult> ExtenstionComplete(InstitutionContractExtensionCompleteRequest request)
|
||||
{
|
||||
return await _institutionContractRepository.ExtenstionComplete(request);
|
||||
}
|
||||
|
||||
private async Task<OperationResult<PersonalContractingParty>> CreateLegalContractingPartyEntity(
|
||||
CreateInstitutionContractLegalPartyRequest request, long representativeId, string address, string city,
|
||||
string state)
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.Enums;
|
||||
using _0_Framework.Application.Sms;
|
||||
using _0_Framework.Exceptions;
|
||||
using _0_Framework.InfraStructure;
|
||||
using Company.Domain.ContarctingPartyAgg;
|
||||
@@ -15,6 +16,7 @@ using Company.Domain.empolyerAgg;
|
||||
using Company.Domain.FinancialStatmentAgg;
|
||||
using Company.Domain.FinancialTransactionAgg;
|
||||
using Company.Domain.InstitutionContractAgg;
|
||||
using Company.Domain.InstitutionContractContactInfoAgg;
|
||||
using Company.Domain.InstitutionContractInsertTempAgg;
|
||||
using Company.Domain.InstitutionPlanAgg;
|
||||
using Company.Domain.WorkshopAgg;
|
||||
@@ -41,15 +43,17 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
private readonly IWorkshopRepository _workshopRepository;
|
||||
private readonly IMongoCollection<InstitutionContractExtenstionTemp> _institutionExtensionTemp;
|
||||
private readonly IPlanPercentageRepository _planPercentageRepository;
|
||||
private readonly ISmsService _smsService;
|
||||
|
||||
public InstitutionContractRepository(CompanyContext context, IEmployerRepository employerRepository,
|
||||
IWorkshopRepository workshopRepository, IMongoDatabase database,
|
||||
IPlanPercentageRepository planPercentageRepository) : base(context)
|
||||
IPlanPercentageRepository planPercentageRepository, ISmsService smsService) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
_employerRepository = employerRepository;
|
||||
_workshopRepository = workshopRepository;
|
||||
_planPercentageRepository = planPercentageRepository;
|
||||
_smsService = smsService;
|
||||
_institutionExtensionTemp =
|
||||
database.GetCollection<InstitutionContractExtenstionTemp>("InstitutionContractExtenstionTemp");
|
||||
}
|
||||
@@ -1993,7 +1997,17 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
var res = new InstitutionContractExtensionPlanResponse();
|
||||
|
||||
var newContractStart = previousInstitution.ContractEndGr;
|
||||
|
||||
DateTime newContractStart;
|
||||
if (previousInstitution.ContractEndGr <= DateTime.Now)
|
||||
{
|
||||
newContractStart = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
newContractStart = previousInstitution.ContractEndGr;
|
||||
}
|
||||
|
||||
if (hasInPerson)
|
||||
{
|
||||
res.OneMonth = null;
|
||||
@@ -2022,9 +2036,9 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
var workshops = request.WorkshopTemps
|
||||
.Select(x => new InstitutionContractExtenstionTempWorkshop(x.WorkshopName, x.CountPerson,
|
||||
x.ContractAndCheckout,
|
||||
x.ContractAndCheckoutInPerson, x.Insurance, x.InsuranceInPerson, x.RollCall, x.RollCall,
|
||||
x.RollCallInPerson)).ToList();
|
||||
x.ContractAndCheckout, x.ContractAndCheckoutInPerson,
|
||||
x.Insurance, x.InsuranceInPerson, x.RollCall, x.RollCall,
|
||||
x.RollCallInPerson, x.WorkshopServicesAmount)).ToList();
|
||||
|
||||
institutionTemp.SetWorkshopsAndPlanAmounts(workshops, res.OneMonth, res.ThreeMonths, res.SixMonths,
|
||||
res.TwelveMonths, hasInPerson);
|
||||
@@ -2038,12 +2052,12 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
InstitutionContractExtensionPaymentRequest request)
|
||||
{
|
||||
var institutionTemp = await _institutionExtensionTemp.Find(x => x.Id == request.TempId).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
if (institutionTemp == null)
|
||||
throw new BadRequestException("اطلاعات وارد شده نامعتبر است");
|
||||
|
||||
|
||||
var duration = request.Duration;
|
||||
|
||||
|
||||
|
||||
var selectedPlan = duration switch
|
||||
{
|
||||
@@ -2053,7 +2067,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
InstitutionContractDuration.TwelveMonths => institutionTemp.TwelveMonths,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
|
||||
var baseAmount = selectedPlan.TotalPayment.MoneyToDouble();
|
||||
var vatOrDiscount = baseAmount * 0.10;
|
||||
|
||||
@@ -2061,16 +2075,233 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
? CalculateInPersonPayment(selectedPlan, baseAmount, vatOrDiscount, request.Duration)
|
||||
: CalculateOnlinePayment(baseAmount, vatOrDiscount);
|
||||
|
||||
institutionTemp.SetAmountAndDuration(duration,res.Monthly,res.OneTime);
|
||||
|
||||
institutionTemp.SetAmountAndDuration(duration, res.Monthly, res.OneTime);
|
||||
|
||||
await _institutionExtensionTemp.ReplaceOneAsync(x => x.Id == institutionTemp.Id, institutionTemp);
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<OperationResult> ExtenstionComplete(InstitutionContractExtensionCompleteRequest request)
|
||||
{
|
||||
var institutionContractTemp = await _institutionExtensionTemp.Find(x => x.Id == request.TemporaryId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (institutionContractTemp == null)
|
||||
throw new BadRequestException("اطلاعات وارد شده نامعتبر است");
|
||||
var selectedDuration = institutionContractTemp.Duration switch
|
||||
{
|
||||
InstitutionContractDuration.OneMonth => institutionContractTemp.OneMonth,
|
||||
InstitutionContractDuration.ThreeMonths => institutionContractTemp.ThreeMonths,
|
||||
InstitutionContractDuration.SixMonths => institutionContractTemp.SixMonths,
|
||||
InstitutionContractDuration.TwelveMonths => institutionContractTemp.TwelveMonths,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
var previousInstitutionContract = await _context.InstitutionContractSet
|
||||
.FirstOrDefaultAsync(x => x.id == institutionContractTemp.PreviousId);
|
||||
|
||||
if (previousInstitutionContract == null)
|
||||
throw new NotFoundException("قرارداد مالی مورد نظر یافت نشد");
|
||||
|
||||
var contractingParty = await _context.PersonalContractingParties
|
||||
.FirstOrDefaultAsync(x => x.id == previousInstitutionContract.ContractingPartyId);
|
||||
|
||||
var payment = request.IsInstallment
|
||||
? institutionContractTemp.MonthlyPayment
|
||||
: institutionContractTemp.OneTimePayment;
|
||||
|
||||
bool dateMessages = false;
|
||||
string dateMaessageResult = String.Empty;
|
||||
var opration = new OperationResult();
|
||||
|
||||
var extensionNo = previousInstitutionContract.ExtensionNo + 1;
|
||||
|
||||
if (_context.InstitutionContractSet.Any(x =>
|
||||
x.ExtensionNo == extensionNo &&
|
||||
x.ContractingPartyId == previousInstitutionContract.ContractingPartyId &&
|
||||
x.TypeOfContract == previousInstitutionContract.TypeOfContract))
|
||||
return opration.Failed("برای این قرارداد قبلا تمدید ایجاد شده است");
|
||||
|
||||
|
||||
var contractStart = selectedDuration.ContractStart;
|
||||
if (string.IsNullOrWhiteSpace(contractStart))
|
||||
{
|
||||
dateMaessageResult = "تاریخ قراراداد اجباری است. ";
|
||||
dateMessages = true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contractStart))
|
||||
{
|
||||
dateMaessageResult += "تاریخ شروع قراراداد اجباری است. ";
|
||||
dateMessages = true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(selectedDuration.ContractEnd))
|
||||
{
|
||||
dateMaessageResult += "تاریخ پایان قراراداد اجباری است. ";
|
||||
dateMessages = true;
|
||||
}
|
||||
|
||||
if (dateMessages)
|
||||
return opration.Failed(dateMaessageResult);
|
||||
|
||||
var firstContract = GetFirstContract(previousInstitutionContract.ContractingPartyId,
|
||||
previousInstitutionContract.TypeOfContract);
|
||||
|
||||
var syear = firstContract.ContractStartFa.Substring(0, 4);
|
||||
var smonth = firstContract.ContractStartFa.Substring(5, 2);
|
||||
var sday = firstContract.ContractStartFa.Substring(8, 2);
|
||||
//شماره قرارداد
|
||||
var contractNo = $"{syear}{smonth}{sday}/{contractingParty.ArchiveCode}/{extensionNo}";
|
||||
|
||||
|
||||
var contractStartGr = contractStart.ToGeorgianDateTime();
|
||||
var contractEndGr = selectedDuration.ContractEnd.ToGeorgianDateTime();
|
||||
|
||||
var contractDateGr = contractStart.ToGeorgianDateTime();
|
||||
|
||||
if (Exists(x =>
|
||||
((contractStartGr >= x.ContractStartGr && contractStartGr <= x.ContractEndGr) ||
|
||||
(contractEndGr >= x.ContractStartGr && contractEndGr <= x.ContractEndGr)) &&
|
||||
x.TypeOfContract == previousInstitutionContract.TypeOfContract
|
||||
&& x.ContractingPartyId == previousInstitutionContract.ContractingPartyId))
|
||||
return opration.Failed("تاریخ شروع و پایان وارد شده با قرارداد دیگری تداخل دارد");
|
||||
|
||||
if (institutionContractTemp.Address != null && institutionContractTemp.Province == null)
|
||||
{
|
||||
return opration.Failed("لطفا استان و شهر را انتخاب کنید");
|
||||
}
|
||||
|
||||
if ((institutionContractTemp.Address != null && institutionContractTemp.Province != null) &&
|
||||
institutionContractTemp.City == "شهرستان")
|
||||
{
|
||||
return opration.Failed("لطفا شهر را انتخاب کنید");
|
||||
}
|
||||
|
||||
if (institutionContractTemp.Address == null && institutionContractTemp.Province != null)
|
||||
{
|
||||
return opration.Failed("لطفا آدرس را وارد کنید");
|
||||
}
|
||||
|
||||
var hasValueAddedTax = payment.Tax.MoneyToDouble() > 0 ? "true" : "false";
|
||||
|
||||
var workshopsCount = institutionContractTemp.Workshops.Count.ToString();
|
||||
|
||||
var workshopDetails = institutionContractTemp.Workshops.Select(x =>
|
||||
new InstitutionContractWorkshopInitial(x.WorkshopName, x.RollCall, x.RollCallInPerson, x.CustomizeCheckout,
|
||||
x.ContractAndCheckout,
|
||||
x.ContractAndCheckoutInPerson, x.Insurance, x.InsuranceInPerson, x.CountPerson, x.Price)).ToList();
|
||||
|
||||
var employeeCount = institutionContractTemp.Workshops.Sum(x => x.CountPerson).ToString();
|
||||
|
||||
var oneMonthPayment = selectedDuration.OneMonthPaymentDiscounted.MoneyToDouble();
|
||||
|
||||
|
||||
var contractingPartyFullName = previousInstitutionContract.ContractingPartyName;
|
||||
|
||||
var totalAmount = payment.PaymentAmount.MoneyToDouble();
|
||||
|
||||
var transaction = await _context.Database.BeginTransactionAsync();
|
||||
|
||||
var entity = new InstitutionContract(contractNo, previousInstitutionContract.RepresentativeId,
|
||||
previousInstitutionContract.RepresentativeName,
|
||||
previousInstitutionContract.ContractingPartyId,
|
||||
contractingPartyFullName, contractDateGr, contractStart,
|
||||
institutionContractTemp.Province, institutionContractTemp.City,
|
||||
institutionContractTemp.Address, contractStartGr,
|
||||
contractStart, contractEndGr, selectedDuration.ContractEnd,
|
||||
oneMonthPayment, selectedDuration.DailyCompenseation.MoneyToDouble(),
|
||||
selectedDuration.Obligation.MoneyToDouble(), totalAmount,
|
||||
extensionNo, workshopsCount, employeeCount,
|
||||
previousInstitutionContract.Description,
|
||||
"NotOfficial", "JobRelation", hasValueAddedTax,
|
||||
payment.Tax.MoneyToDouble(), workshopDetails);
|
||||
|
||||
await CreateAsync(entity);
|
||||
await SaveChangesAsync();
|
||||
|
||||
FinancialStatment financialStatement;
|
||||
if (_context.FinancialStatments.Any(x => x.ContractingPartyId == contractingParty.id))
|
||||
{
|
||||
financialStatement =
|
||||
await _context.FinancialStatments.FirstOrDefaultAsync(x => x.ContractingPartyId == contractingParty.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
financialStatement = new FinancialStatment(contractingParty.id, contractingPartyFullName);
|
||||
await _context.AddAsync(financialStatement);
|
||||
}
|
||||
|
||||
var today = DateTime.Today;
|
||||
if (request.IsInstallment && payment is InstitutionContractExtensionPaymentMonthly monthly)
|
||||
{
|
||||
|
||||
var installments = monthly.Installments.Select(x =>
|
||||
new InstitutionContractInstallment(x.InstalmentDate.ToGeorgianDateTime(),
|
||||
x.InstallmentAmountStr.MoneyToDouble(), "")).ToList();
|
||||
|
||||
// دریافت مبلغ اولین قسط
|
||||
//این کار برای این هست که اولین قسط باید با تاریخ امروز باشد و باید به وضعیت مالی بدهی ایجاد شود که یوزر اولین بدهی را وارد کند
|
||||
var firstInstallmentAmount = installments.First().Amount;
|
||||
|
||||
// حذف اولین قسط
|
||||
installments.RemoveAt(0);
|
||||
|
||||
// ایجاد قسط جدید با تاریخ امروز
|
||||
var todayInstallment = new InstitutionContractInstallment(DateTime.Today, firstInstallmentAmount, "");
|
||||
|
||||
var financialTransaction = new FinancialTransaction(0,today, today.ToFarsi(),
|
||||
"قسط اول سرویس", "debt", "بابت خدمات", firstInstallmentAmount, 0, 0);
|
||||
|
||||
financialStatement.AddFinancialTransaction(financialTransaction);
|
||||
|
||||
// اضافه کردن قسط جدید به ابتدای لیست
|
||||
installments.Insert(0, todayInstallment);
|
||||
|
||||
entity.SetInstallments(installments);
|
||||
}
|
||||
else
|
||||
{
|
||||
var financialTransaction = new FinancialTransaction(0, today, today.ToFarsi(),
|
||||
"پرداخت کل سرویس", "debt", "بابت خدمات",totalAmount , 0, 0);
|
||||
financialStatement.AddFinancialTransaction(financialTransaction);
|
||||
}
|
||||
|
||||
|
||||
await CreateAsync(entity);
|
||||
await SaveChangesAsync();
|
||||
|
||||
foreach (var contactInfo in institutionContractTemp.ContactInfos)
|
||||
{
|
||||
if (contactInfo.PhoneNumber != null)
|
||||
{
|
||||
var contactinfo = new InstitutionContractContactInfo(contactInfo.PhoneType,
|
||||
contactInfo.Position,contactInfo.PhoneNumber,contactInfo.FnameLname,entity.id,contactInfo.SendSmsString == "true");
|
||||
|
||||
_context.InstitutionContractContactInfos.Add(contactinfo);
|
||||
}
|
||||
}
|
||||
|
||||
var userPass = contractingParty.IsLegal == "حقیقی"
|
||||
? contractingParty.Nationalcode
|
||||
: contractingParty.NationalId;
|
||||
|
||||
|
||||
|
||||
await SaveChangesAsync();
|
||||
|
||||
await _smsService.SendInstitutionVerificationLink(contractingParty.Phone, contractingPartyFullName,
|
||||
entity.PublicId);
|
||||
|
||||
|
||||
await SaveChangesAsync();
|
||||
return opration.Succcedded();
|
||||
}
|
||||
|
||||
|
||||
private InstitutionContractExtensionPaymentResponse CalculateInPersonPayment(
|
||||
InstitutionContractExtensionPlanDetail selectedPlan, double baseAmount, double tenPercent, InstitutionContractDuration duration)
|
||||
InstitutionContractExtensionPlanDetail selectedPlan, double baseAmount, double tenPercent,
|
||||
InstitutionContractDuration duration)
|
||||
{
|
||||
// حالت پرداخت یکجا
|
||||
var oneTimeBase = baseAmount - tenPercent;
|
||||
@@ -2118,7 +2349,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private InstitutionContractExtensionPlanDetail CalculateInstitutionPlan(InstitutionContractDuration duration,
|
||||
double amount,
|
||||
@@ -2170,13 +2401,15 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
return result;
|
||||
}
|
||||
public static List<MonthlyInstallment> InstitutionMonthlyInstallmentCaculation(InstitutionContractDuration duration, double monthlyTotalPaymentDouble,
|
||||
|
||||
public static List<MonthlyInstallment> InstitutionMonthlyInstallmentCaculation(InstitutionContractDuration duration,
|
||||
double monthlyTotalPaymentDouble,
|
||||
string installmentstart)
|
||||
{
|
||||
var originalDay = int.Parse(installmentstart.Substring(8, 2));
|
||||
var installmentList = new List<MonthlyInstallment>();
|
||||
|
||||
|
||||
|
||||
int instalmentCount = (int)duration;
|
||||
var instalmentAmount = monthlyTotalPaymentDouble / instalmentCount;
|
||||
int currentInstallmentStartDay = int.Parse(installmentstart.Substring(8, 2));
|
||||
@@ -2196,15 +2429,15 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
var currentDay = int.Parse(installmentstart.Substring(8, 2));
|
||||
var currentMonth = int.Parse(installmentstart.Substring(5, 2));
|
||||
var currentYear = int.Parse(installmentstart.Substring(0, 4));
|
||||
|
||||
|
||||
// Get next month's date
|
||||
var nextMonthFa = installmentstart.ToGeorgianDateTime().AddMonthsFa(1, out var nextMonth);
|
||||
var maxDayInNextMonth = int.Parse(nextMonthFa.FindeEndOfMonth().Substring(8, 2));
|
||||
|
||||
|
||||
// Use original day if possible, otherwise use last day of month
|
||||
var dayToUse = Math.Min(originalDay, maxDayInNextMonth);
|
||||
installmentDate = nextMonthFa.Substring(0, 8) + dayToUse.ToString("D2");
|
||||
|
||||
|
||||
// Update installmentstart for next iteration
|
||||
installmentstart = installmentDate;
|
||||
}
|
||||
|
||||
@@ -319,267 +319,6 @@ public class institutionContractController : AdminBaseController
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("extension/{id}")]
|
||||
public ActionResult<EditInstitutionContract> OnGetExtension(long id)
|
||||
{
|
||||
var todayGr = DateTime.Now;
|
||||
var todayFa = todayGr.ToFarsi();
|
||||
var previusContract = _institutionContractApplication.GetDetails(id);
|
||||
var previusContractEnd = previusContract.ContractEndGr.AddDays(1);
|
||||
var startFa = previusContractEnd.ToFarsi();
|
||||
var endFa = startFa.FindeEndOfYear();
|
||||
|
||||
|
||||
var representativList = new List<RepresentativeViewModel>();
|
||||
var contractingPartyList = new List<PersonalContractingPartyViewModel>();
|
||||
var res = _institutionContractApplication.GetDetails(id);
|
||||
var representative = new RepresentativeViewModel
|
||||
{
|
||||
Id = res.RepresentativeId,
|
||||
FullName = res.RepresentativeName
|
||||
};
|
||||
representativList.Add(representative);
|
||||
var contractingParty = new PersonalContractingPartyViewModel
|
||||
{
|
||||
id = res.ContractingPartyId,
|
||||
FullName = _contractingPartyApplication.GetFullName(res.ContractingPartyId)
|
||||
};
|
||||
contractingPartyList.Add(contractingParty);
|
||||
res.RepresentativeSelectList =
|
||||
new SelectList(representativList, "Id", "FullName");
|
||||
res.ContractingPartiesSelectList =
|
||||
new SelectList(contractingPartyList, "id", "FullName");
|
||||
|
||||
var employer = _employerApplication.GetEmployerByContracrtingPartyID(res.ContractingPartyId);
|
||||
var emplId = employer.Select(x => x.Id).ToList();
|
||||
|
||||
var w = _workshopApplication.GetWorkshopsByEmployerId(emplId);
|
||||
var workshopIds = w.Select(x => x.Id).ToList();
|
||||
var workshopCount = Convert.ToString(w.Count);
|
||||
|
||||
var pCount = 0;
|
||||
if (workshopIds.Count > 0)
|
||||
{
|
||||
foreach (var workshopId in workshopIds)
|
||||
{
|
||||
var p = _workshopApplication.PersonnelCount(workshopId);
|
||||
pCount += p;
|
||||
}
|
||||
|
||||
res.EmployeeCount = Convert.ToString(pCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.EmployeeCount = "0";
|
||||
}
|
||||
|
||||
|
||||
//var left = _leftWorkApplication.GetLeftPersonelByWorkshopId(workshopIds);
|
||||
|
||||
res.WorkshopCount = workshopCount;
|
||||
|
||||
res.WorkshopManualCount = workshopCount;
|
||||
res.EmployeeManualCount = res.EmployeeCount;
|
||||
|
||||
res.ContractDateFa = todayFa;
|
||||
res.ContractStartFa = startFa;
|
||||
res.ContractEndFa = endFa;
|
||||
res.ContractAmountString = "0";
|
||||
res.DailyCompenseationString = "0";
|
||||
res.ObligationString = "0";
|
||||
res.TotalAmountString = "0";
|
||||
res.PrviousContractId = id;
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(res.EmployeeManualCount))
|
||||
{
|
||||
var countPerson = Convert.ToInt32(res.EmployeeCount);
|
||||
var finalAmount = _institutionContractApplication.GetcontractAmount(countPerson);
|
||||
|
||||
var syear = Convert.ToInt32(startFa.Substring(0, 4));
|
||||
var smonth = Convert.ToInt32(startFa.Substring(5, 2));
|
||||
var sday = Convert.ToInt32(startFa.Substring(8, 2));
|
||||
|
||||
|
||||
var eyear = Convert.ToInt32(endFa.Substring(0, 4));
|
||||
var emonth = Convert.ToInt32(endFa.Substring(5, 2));
|
||||
var eday = Convert.ToInt32(endFa.Substring(8, 2));
|
||||
emonth += 1;
|
||||
|
||||
var def = (eyear - syear) * 12 + emonth - smonth;
|
||||
|
||||
|
||||
//رند ماهیانه
|
||||
//int rightMDigits = (int)(finalAmount % 1000000);
|
||||
//if (rightMDigits < 500000)
|
||||
//{
|
||||
// finalAmount = (int)(finalAmount / 100000) * 100000;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// finalAmount = (int)(finalAmount / 100000 + 1) * 100000;
|
||||
//}
|
||||
finalAmount = (int)(finalAmount / 1000000) * 1000000;
|
||||
|
||||
double compute = 0;
|
||||
double tenPercent = 0;
|
||||
if (res.HasValueAddedTax == "true")
|
||||
{
|
||||
tenPercent = finalAmount * 10 / 100;
|
||||
res.ContractAmountOAlone = finalAmount.ToMoney();
|
||||
|
||||
//افزودن 10 درصد
|
||||
finalAmount += tenPercent;
|
||||
res.ContractAmountString = finalAmount.ToMoney();
|
||||
res.ValueAddedTaxStr = tenPercent.ToMoney();
|
||||
compute = finalAmount * def;
|
||||
res.ObligationString = compute.ToMoney();
|
||||
res.TotalAmountString = res.ObligationString;
|
||||
}
|
||||
else
|
||||
{
|
||||
res.ContractAmountOAlone = finalAmount.ToMoney();
|
||||
res.ContractAmountString = res.ContractAmountOAlone;
|
||||
res.ValueAddedTaxStr = "0";
|
||||
compute = finalAmount * def;
|
||||
res.ObligationString = compute.ToMoney();
|
||||
res.TotalAmountString = res.ObligationString;
|
||||
}
|
||||
|
||||
|
||||
//رند سالانه
|
||||
|
||||
//int rightYDigits = (int)(compute % 10000000);
|
||||
//if (rightYDigits < 5000000)
|
||||
|
||||
//compute = (int)(compute / 1000000) * 1000000;
|
||||
}
|
||||
|
||||
var contactInfo = _contactInfoApplication.GetContactInfolist(id);
|
||||
if (contactInfo.Count > 0)
|
||||
{
|
||||
res.ContactInfoCounter = contactInfo.Count;
|
||||
res.ContactInformationList = contactInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
res.ContactInfoCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("extension")]
|
||||
public async Task<ActionResult<OperationResult>> OnPostExtension(
|
||||
[FromBody] ExtenstionInstitutionContractRequest command)
|
||||
{
|
||||
var op = new OperationResult();
|
||||
|
||||
var phoneNumber = 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("شناسه ملی طرف حساب وجود ندارد"));
|
||||
if (phoneNumber == null)
|
||||
return new JsonResult(op.Failed("تعیین شماره همراه با سمت طرف قرارداد اجباریست"));
|
||||
|
||||
|
||||
var counter = command.ContactInfos.Count;
|
||||
|
||||
var result = await _institutionContractApplication.ExtensionAsync(command);
|
||||
|
||||
if (result.IsSuccedded && counter > 0)
|
||||
{
|
||||
for (var i = 0; i <= counter - 1; i++)
|
||||
{
|
||||
if (command.ContactInfos[i].PhoneNumber != null)
|
||||
{
|
||||
var contactinfo = new CreateContactInfo
|
||||
{
|
||||
InstitutionContractId = result.SendId,
|
||||
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);
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (result.IsSuccedded)
|
||||
{
|
||||
_institutionContractApplication.DeActive(command.PreviousContractId);
|
||||
_institutionContractApplication.ReActiveAllAfterCreateNew(command.ContractingPartyId);
|
||||
}
|
||||
|
||||
var contractingPartyId = _institutionContractApplication.GetDetails(result.SendId);
|
||||
|
||||
var getOldContarct = _institutionContractApplication.NewSearch(new InstitutionContractSearchModel()
|
||||
{ ContractingPartyId = contractingPartyId.ContractingPartyId, IsActiveString = "both" })
|
||||
.Where(x => x.IsActiveString == "false" || x.IsActiveString == "blue").ToList();
|
||||
if (result.IsSuccedded && counter > 0)
|
||||
{
|
||||
if (getOldContarct.Count > 0)
|
||||
{
|
||||
foreach (var item in getOldContarct)
|
||||
{
|
||||
_contactInfoApplication.RemoveContactInfo(item.Id);
|
||||
foreach (var phone in command.ContactInfos)
|
||||
{
|
||||
if (phone.PhoneNumber != null)
|
||||
{
|
||||
var contactinfo = new CreateContactInfo
|
||||
{
|
||||
InstitutionContractId = item.Id,
|
||||
PhoneType = phone.PhoneType,
|
||||
Position = phone.Position,
|
||||
PhoneNumber = phone.PhoneNumber,
|
||||
FnameLname = phone.FnameLname,
|
||||
SendSms = phone.SendSmsString == "true" ? true : false
|
||||
};
|
||||
_contactInfoApplication.Create(contactinfo);
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
//ساخت اکانت کلاینت
|
||||
var userPass = conractingParty.IsLegal == "حقیقی"
|
||||
? conractingParty.Nationalcode
|
||||
: conractingParty.NationalId;
|
||||
var checkExistAccount = _accountApplication.CheckExistClientAccount(userPass);
|
||||
if (!checkExistAccount)
|
||||
{
|
||||
var createAcc = new RegisterAccount
|
||||
{
|
||||
Fullname = conractingParty.LName,
|
||||
Username = userPass,
|
||||
Password = userPass,
|
||||
Mobile = phoneNumber.PhoneNumber,
|
||||
NationalCode = userPass
|
||||
};
|
||||
var res = _accountApplication.RegisterClient(createAcc);
|
||||
if (res.IsSuccedded)
|
||||
_institutionContractApplication.CreateContractingPartyAccount(command.ContractingPartyId,
|
||||
res.SendId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// دانلود اکسل
|
||||
/// </summary>
|
||||
@@ -740,26 +479,32 @@ public class institutionContractController : AdminBaseController
|
||||
|
||||
|
||||
[HttpGet("extenstion/inquiry/{previousContractId}")]
|
||||
public async Task<ActionResult<InstitutionContractExtensionInquiryResult>> GetExtenstionInquiry(long previousContractId)
|
||||
public async Task<ActionResult<InstitutionContractExtensionInquiryResult>> ExtenstionInquiry(long previousContractId)
|
||||
{
|
||||
var res= await _institutionContractApplication.GetExtenstionInquiry(previousContractId);
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("extenstion/workshops")]
|
||||
public async Task<ActionResult<InstitutionContractExtensionWorkshopsResponse>> GetExtenstionWorkshops([FromBody] InstitutionContractExtensionWorkshopsRequest request)
|
||||
public async Task<ActionResult<InstitutionContractExtensionWorkshopsResponse>> ExtenstionWorkshops([FromBody] InstitutionContractExtensionWorkshopsRequest request)
|
||||
{
|
||||
var res =await _institutionContractApplication.GetExtenstionWorkshops(request);
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("extenstion/institution-plan")]
|
||||
public async Task<ActionResult<InstitutionContractExtensionPlanResponse>> GetExtenstionInstitutionPlan([FromBody]InstitutionContractExtensionPlanRequest request)
|
||||
public async Task<ActionResult<InstitutionContractExtensionPlanResponse>> ExtenstionInstitutionPlan([FromBody]InstitutionContractExtensionPlanRequest request)
|
||||
{
|
||||
var res =await _institutionContractApplication.GetExtenstionInstitutionPlan(request);
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("extenstion/complete")]
|
||||
public async Task<ActionResult<OperationResult>> ExtenstionComplete(InstitutionContractExtensionCompleteRequest request)
|
||||
{
|
||||
var res =await _institutionContractApplication.ExtenstionComplete(request);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user