Files
Backend-Api/Company.Domain/InstitutionContractAgg/InstitutionContract.cs

488 lines
17 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Security.Cryptography;
using _0_Framework.Application.Enums;
using _0_Framework.Domain;
using Company.Domain.InstitutionContractContactInfoAgg;
using CompanyManagment.App.Contracts.InstitutionContract;
namespace Company.Domain.InstitutionContractAgg;
public class InstitutionContract : EntityBase
{
public InstitutionContract(string contractNo, long representativeId, string representativeName,
long contractingPartyId,
string contractingPartyName, DateTime contractDateGr, string contractDateFa, string state, string city,
string address, DateTime contractStartGr, string contractStartFa, DateTime contractEndGr,
string contractEndFa, double contractAmount, double dailyCompenseation, double obligation,
double totalAmount, int extensionNo, string workshopManualCount, string employeeManualCount, string description,
string officialCompany, string typeOfcontract, string hasValueAddedTax, double valueAddedTax,
List<InstitutionContractWorkshopInitial> workshopDetails, long lawId,
int discountPercentage, double discountAmount)
{
ContractNo = contractNo;
RepresentativeId = representativeId;
RepresentativeName = representativeName;
ContractingPartyId = contractingPartyId;
ContractingPartyName = contractingPartyName;
ContractDateGr = contractDateGr;
ContractDateFa = contractDateFa;
State = state;
City = city;
Address = address;
//ContactInfoId = contactInfoId;
ContractStartGr = contractStartGr;
ContractStartFa = contractStartFa;
ContractEndGr = contractEndGr;
ContractEndFa = contractEndFa;
ContractAmount = contractAmount;
DailyCompenseation = dailyCompenseation;
Obligation = obligation;
TotalAmount = totalAmount;
ExtensionNo = extensionNo;
WorkshopManualCount = workshopManualCount;
EmployeeManualCount = employeeManualCount;
Description = description;
OfficialCompany = officialCompany;
IsActiveString = "true";
Signature = "0";
TypeOfContract = typeOfcontract;
HasValueAddedTax = hasValueAddedTax;
ValueAddedTax = valueAddedTax;
VerificationStatus = InstitutionContractVerificationStatus.PendingForVerify;
ContactInfoList = [];
Installments = [];
WorkshopGroup = new InstitutionContractWorkshopGroup(id, workshopDetails);
PublicId = Guid.NewGuid();
LawId = lawId;
DiscountPercentage = discountPercentage;
DiscountAmount = discountAmount;
}
public long LawId { get; private set; }
public string ContractNo { get; private set; }
public long RepresentativeId { get; private set; }
public string RepresentativeName { get; private set; }
public long ContractingPartyId { get; private set; }
public string ContractingPartyName { get; private set; }
public DateTime ContractDateGr { get; private set; }
public string ContractDateFa { get; private set; }
public string State { get; private set; }
public string City { get; private set; }
public string Address { get; private set; }
//public long ContactInfoId { get; private set; }
public DateTime ContractStartGr { get; private set; }
public string ContractStartFa { get; private set; }
public DateTime ContractEndGr { get; private set; }
public string ContractEndFa { get; private set; }
// مبلغ قرارداد
public double ContractAmount { get; private set; }
public double ContractAmountWithTax => !IsOldContract ? ContractAmount + ContractAmountTax
: ContractAmount;
public double ContractAmountTax => ContractAmount*0.10;
//خسارت روزانه
public double DailyCompenseation { get; private set; }
//وجه التزام
public double Obligation { get; private set; }
// مبلغ کل قرارداد
public double TotalAmount { get; private set; }
public string WorkshopManualCount { get; private set; }
public string EmployeeManualCount { get; private set; }
public string IsActiveString { get; private set; }
public int ExtensionNo { get; private set; }
public string Description { get; private set; }
public string Signature { get; private set; }
public string OfficialCompany { get; private set; }
public string TypeOfContract { get; private set; }
public string HasValueAddedTax { get; private set; }
public double ValueAddedTax { get; private set; }
public Guid PublicId { get; private set; }
public string VerifyCode { get; private set; }
public DateTime VerifyCodeCreation { get; private set; }
public string VerifierFullName { get; private set; }
public string VerifierPhoneNumber { get; private set; }
public double DiscountAmount { get; private set; }
public int DiscountPercentage { get; private set; }
[NotMapped] public bool VerifyCodeExpired => VerifyCodeCreation.Add(ExpireTime) <= DateTime.Now;
[NotMapped] public bool CanResendVerifyCode => VerifyCodeCreation.Add(ReSendTime) <= DateTime.Now;
[NotMapped] public TimeSpan ExpireTime => TimeSpan.FromMinutes(5);
[NotMapped] public TimeSpan ReSendTime => TimeSpan.FromMinutes(2);
public bool IsInstallment { get; set; }
public InstitutionContractVerificationStatus VerificationStatus { get; private set; }
public InstitutionContractWorkshopGroup WorkshopGroup { get; private set; }
public List<InstitutionContractContactInfo> ContactInfoList { get; set; }
public List<InstitutionContractInstallment> Installments { get; set; }
public List<InstitutionContractAmendment> Amendments { get; private set; }
public InstitutionContractSigningType? SigningType { get; private set; }
public bool IsOldContract => LawId== 0;
public InstitutionContract()
{
ContactInfoList = [];
Installments = [];
}
public void Edit(DateTime contractDateGr, string contractDateFa, string state, string city, string address,
DateTime contractStartGr, string contractStartFa, DateTime contractEndGr, string contractEndFa,
double contractAmount, double dailyCompenseation, double obligation, double totalAmount,
string workshopManualCount, string employeeManualCount, string description, string officialCompany,
string typeOfcontract, double valueAddedTax, string hasValueAddedTax)
{
ContractDateGr = contractDateGr;
ContractDateFa = contractDateFa;
State = state;
City = city;
Address = address;
ContractStartGr = contractStartGr;
ContractStartFa = contractStartFa;
ContractEndGr = contractEndGr;
ContractEndFa = contractEndFa;
ContractAmount = contractAmount;
DailyCompenseation = dailyCompenseation;
Obligation = obligation;
TotalAmount = totalAmount;
WorkshopManualCount = workshopManualCount;
EmployeeManualCount = employeeManualCount;
Description = description;
OfficialCompany = officialCompany;
TypeOfContract = typeOfcontract;
HasValueAddedTax = hasValueAddedTax;
ValueAddedTax = valueAddedTax;
}
public void Active()
{
this.IsActiveString = "true";
}
public void DeActive()
{
this.IsActiveString = "false";
}
public void DeActiveBlue()
{
this.IsActiveString = "blue";
}
public void Sign()
{
this.Signature = "1";
}
public void UnSign()
{
this.Signature = "0";
}
public void Verified()
{
VerificationStatus = InstitutionContractVerificationStatus.Verified;
}
public void SetPendingWorkflow()
{
VerificationStatus = InstitutionContractVerificationStatus.PendingWorkflow;
}
public void SetInstallments(List<InstitutionContractInstallment> installments)
{
Installments = installments;
IsInstallment = true;
}
public void SetVerifyCode(string code,string verifierFullName, string verifierPhoneNumber)
{
VerifyCode = code;
VerifyCodeCreation = DateTime.Now;
VerifierFullName = verifierFullName;
VerifierPhoneNumber = verifierPhoneNumber;
}
public void SetWorkshopGroup(InstitutionContractWorkshopGroup workshopGroup)
{
WorkshopGroup = workshopGroup;
}
public void SetAmount(double totalAmount, double tax, double oneMonthPayment)
{
ContractAmount = oneMonthPayment;
TotalAmount = totalAmount;
ValueAddedTax = tax;
HasValueAddedTax = tax > 0 ? "true" : "false";
}
public void ClearGroup()
{
WorkshopGroup = null;
}
public void SetSigningType(InstitutionContractSigningType signingType)
{
SigningType = signingType;
}
public void AddAmendment(InstitutionContractAmendment amendment)
{
Amendments.Add(amendment);
}
}
public class InstitutionContractAmendment : EntityBase
{
private InstitutionContractAmendment(){}
public InstitutionContractAmendment(long institutionContractId,
List<InstitutionContractInstallment> installments, double amount, bool hasInstallment,
List<InstitutionContractAmendmentChange> amendmentChanges, long lawId)
{
InstitutionContractId = institutionContractId;
Installments = installments is { Count: > 0} ? installments : [];
Amount = amount;
HasInstallment = hasInstallment;
AmendmentChanges = amendmentChanges;
LawId = lawId;
VerificationStatus = InstitutionContractVerificationStatus.PendingForVerify;
}
public long InstitutionContractId { get; set; }
public InstitutionContract InstitutionContract { get; set; }
public List<InstitutionContractInstallment> Installments { get; set; }
public double Amount { get; set; }
public bool HasInstallment { get; set; }
public string VerifyCode { get; set; }
public DateTime VerificationCreation { get; set; }
public List<InstitutionContractAmendmentChange> AmendmentChanges { get; set; }
public long LawId { get; set; }
public string VerifierPhoneNumber { get; private set; }
public string VerifierFullName { get; private set; }
public InstitutionContractVerificationStatus VerificationStatus { get; set; }
public DateTime VerifyCodeCreation { get; set; }
public void SetVerifyCode(string code,string verifierFullName, string verifierPhoneNumber)
{
VerifyCode = code;
VerifyCodeCreation = DateTime.Now;
VerifierFullName = verifierFullName;
VerifierPhoneNumber = verifierPhoneNumber;
}
public void Verified()
{
VerificationStatus = InstitutionContractVerificationStatus.Verified;
}
}
public class InstitutionContractAmendmentChange : EntityBase
{
private InstitutionContractAmendmentChange() { }
private InstitutionContractAmendmentChange(InstitutionContractAmendmentChangeType changeType,
DateTime changeDateGr, bool? hasCustomizeCheckoutPlan, bool? hasContractPlan,
bool? hasContractPlanInPerson, bool? hasInsurancePlan, bool? hasInsurancePlanInPerson, int? personnelCount,
bool? hasRollCallPlan, bool? hasRollCallInPerson,
long? currentWorkshopId, int personnelCountDifference)
{
ChangeType = changeType;
ChangeDateGr = changeDateGr;
HasRollCallPlan = hasRollCallPlan;
HasCustomizeCheckoutPlan = hasCustomizeCheckoutPlan;
HasContractPlan = hasContractPlan;
HasContractPlanInPerson = hasContractPlanInPerson;
HasInsurancePlan = hasInsurancePlan;
HasInsurancePlanInPerson = hasInsurancePlanInPerson;
PersonnelCount = personnelCount;
PersonnelCountDifference = personnelCountDifference;
CurrentWorkshopId = currentWorkshopId;
HasRollCallInPerson = hasRollCallInPerson;
}
/// <summary>
/// تغییر تعداد پرسنل
/// </summary>
public static InstitutionContractAmendmentChange CreatePersonCountChange(
DateTime changeDateGr, int personnelCount, int personnelCountDifference,
long currentWorkshopId)
{
return new InstitutionContractAmendmentChange(
changeType: InstitutionContractAmendmentChangeType.PersonCount,
changeDateGr: changeDateGr,
hasCustomizeCheckoutPlan: null,
hasContractPlan: null,
hasContractPlanInPerson: null,
hasInsurancePlan: null,
hasInsurancePlanInPerson: null,
personnelCount: personnelCount,
hasRollCallPlan: null,
hasRollCallInPerson: null,
currentWorkshopId: currentWorkshopId,
personnelCountDifference: personnelCountDifference);
}
/// <summary>
/// تغییر خدمات
/// </summary>
public static InstitutionContractAmendmentChange CreateServicesChange(
DateTime changeDateGr, long currentWorkshopId, bool hasRollCallPlan, bool hasRollCallInPerson,
bool hasCustomizeCheckoutPlan, bool hasContractPlan, bool hasContractPlanInPerson,
bool hasInsurancePlan, bool hasInsurancePlanInPerson)
{
return new InstitutionContractAmendmentChange(
changeType: InstitutionContractAmendmentChangeType.Services,
changeDateGr: changeDateGr,
hasCustomizeCheckoutPlan: hasCustomizeCheckoutPlan,
hasContractPlan: hasContractPlan,
hasContractPlanInPerson: hasContractPlanInPerson,
hasInsurancePlan: hasInsurancePlan,
hasInsurancePlanInPerson: hasInsurancePlanInPerson,
personnelCount: null,
hasRollCallPlan: hasRollCallPlan,
hasRollCallInPerson: hasRollCallInPerson,
currentWorkshopId: currentWorkshopId,
personnelCountDifference: 0);
}
/// <summary>
/// ایجاد کارگاه جدید
/// </summary>
public static InstitutionContractAmendmentChange CreateWorkshopCreatedChange(
DateTime changeDateGr, bool hasRollCallPlan, bool hasRollCallInPerson,
bool hasCustomizeCheckoutPlan, bool hasContractPlan, bool hasContractPlanInPerson,
bool hasInsurancePlan, bool hasInsurancePlanInPerson,int personnelCount)
{
return new InstitutionContractAmendmentChange(
changeType: InstitutionContractAmendmentChangeType.WorkshopCreated,
changeDateGr: changeDateGr,
hasCustomizeCheckoutPlan: hasCustomizeCheckoutPlan,
hasContractPlan: hasContractPlan,
hasContractPlanInPerson: hasContractPlanInPerson,
hasInsurancePlan: hasInsurancePlan,
hasInsurancePlanInPerson: hasInsurancePlanInPerson,
personnelCount: personnelCount,
hasRollCallPlan: hasRollCallPlan,
hasRollCallInPerson: hasRollCallInPerson,
currentWorkshopId: null,
personnelCountDifference: 0);
}
public long InstitutionContractAmendmentId { get; private set; }
public InstitutionContractAmendment InstitutionContractAmendment { get; private set; }
public InstitutionContractAmendmentChangeType ChangeType { get; private set; }
public DateTime ChangeDateGr { get; private set; }
/// <summary>
/// پلن حضور و غیاب
/// </summary>
public bool? HasRollCallPlan { get; private set; }
public bool? HasRollCallInPerson { get; set; }
/// <summary>
/// پلن فیش غیر رسمی
/// </summary>
public bool? HasCustomizeCheckoutPlan { get; private set; }
/// <summary>
/// پلن قرارداد و تصفیه
/// </summary>
public bool? HasContractPlan { get; private set; }
/// <summary>
/// پلن قرارداد و تصفیه حضوری
/// </summary>
public bool? HasContractPlanInPerson { get; private set; }
/// <summary>
/// پلن بیمه
/// </summary>
public bool? HasInsurancePlan { get; private set; }
/// <summary>
/// پلن بیمه حضوری
/// </summary>
public bool? HasInsurancePlanInPerson { get; private set; }
/// <summary>
/// تعداد پرسنل
/// </summary>
public int? PersonnelCount { get; private set; }
/// <summary>
/// مقدار تغییرات تعداد پرسنل
/// </summary>
public int PersonnelCountDifference { get; set; }
/// <summary>
/// تعداد کارگاه
/// </summary>
public long? CurrentWorkshopId { get; private set; }
}
public enum InstitutionContractAmendmentChangeType
{
PersonCount,
Services,
WorkshopCreated
}