151 lines
4.5 KiB
C#
151 lines
4.5 KiB
C#
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.FinancialStatment;
|
|
using CompanyManagment.App.Contracts.FinancilTransaction;
|
|
using CompanyManagment.App.Contracts.PersonalContractingParty;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace ServiceHost.Areas.Financial.Pages;
|
|
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly IPersonalContractingPartyApp _contractingPartyApp;
|
|
private readonly IFinancialStatmentApplication _financialStatmentApplication;
|
|
private readonly IFinancialTransactionApplication _financialTransactionApplication;
|
|
public long ContractingPartyId;
|
|
public string ContractingPartyName;
|
|
public FinancialDividViewModel DividedList;
|
|
|
|
public bool HasData;
|
|
public int I = 1;
|
|
public bool IsLegal;
|
|
public string ThisPageBalance;
|
|
public string ThisPageCredit;
|
|
public string ThisPageDebt;
|
|
public List<FinancialTransactionViewModel> TList;
|
|
public string Today;
|
|
public string TotalBalance;
|
|
public double TotalBalanceDouble;
|
|
public string TotalCredit;
|
|
public string TotalDebt;
|
|
|
|
public IndexModel(IFinancialStatmentApplication financialStatmentApplication,
|
|
IFinancialTransactionApplication financialTransactionApplication,
|
|
IPersonalContractingPartyApp contractingPartyApp)
|
|
{
|
|
_financialStatmentApplication = financialStatmentApplication;
|
|
_financialTransactionApplication = financialTransactionApplication;
|
|
_contractingPartyApp = contractingPartyApp;
|
|
}
|
|
|
|
public List<FinancialGroupViewModel> GroupeList { get; set; }
|
|
public string GoBack { get; set; }
|
|
public int pageCount { get; set; }
|
|
|
|
public void OnGet(long id, long approveId, string back)
|
|
{
|
|
var transactionCount = 0;
|
|
|
|
ContractingPartyId = id;
|
|
|
|
if (back == "true")
|
|
GoBack = "true";
|
|
|
|
var firstGetStatement = _financialStatmentApplication.GetDetailsByContractingPartyId(id);
|
|
var allTransactions = firstGetStatement.FinancialTransactionViewModels;
|
|
|
|
if (allTransactions != null && id > 0 && approveId == firstGetStatement.Id)
|
|
{
|
|
var todayGr = DateTime.Now;
|
|
Today = todayGr.ToFarsi();
|
|
var contractingParty = _contractingPartyApp.GetDetails(id);
|
|
HasData = true;
|
|
if (contractingParty.IsLegal == "حقوقی")
|
|
IsLegal = true;
|
|
ContractingPartyName = contractingParty.LName;
|
|
double firstBalance = 0;
|
|
double totalDebt = 0;
|
|
double totalCredit = 0;
|
|
double totalBalance = 0;
|
|
double thisPageDebt = 0;
|
|
double thisPageCredit = 0;
|
|
double thisPageBalance = 0;
|
|
var transActionsWithBalance = new List<FinancialTransactionViewModel>();
|
|
var tCounter = 1;
|
|
for (var i = 0; i < allTransactions.Count; i++)
|
|
{
|
|
if (allTransactions[i].TypeOfTransaction == "debt")
|
|
{
|
|
firstBalance += allTransactions[i].Deptor;
|
|
allTransactions[i].Balance = firstBalance;
|
|
allTransactions[i].BalanceString = firstBalance.ToMoney();
|
|
totalDebt += allTransactions[i].Deptor;
|
|
thisPageDebt += allTransactions[i].Deptor;
|
|
totalBalance = totalDebt - totalCredit;
|
|
}
|
|
else
|
|
{
|
|
firstBalance -= allTransactions[i].Creditor;
|
|
allTransactions[i].Balance = firstBalance;
|
|
allTransactions[i].BalanceString = firstBalance.ToMoney();
|
|
totalCredit += allTransactions[i].Creditor;
|
|
thisPageCredit += allTransactions[i].Creditor;
|
|
totalBalance = totalDebt - totalCredit;
|
|
}
|
|
|
|
allTransactions[i].Counter = tCounter;
|
|
tCounter++;
|
|
var tAction = allTransactions[i];
|
|
transActionsWithBalance.Add(tAction);
|
|
}
|
|
|
|
thisPageBalance = thisPageDebt - thisPageCredit;
|
|
ThisPageDebt = thisPageDebt.ToMoney();
|
|
ThisPageCredit = thisPageCredit.ToMoney();
|
|
ThisPageBalance = thisPageBalance.ToMoney();
|
|
TotalDebt = totalDebt.ToMoney();
|
|
TotalCredit = totalCredit.ToMoney();
|
|
TotalBalance = totalBalance.ToMoney();
|
|
TotalBalanceDouble = totalBalance;
|
|
TList = transActionsWithBalance.OrderBy(x => x.TdateGr).ToList();
|
|
|
|
transactionCount = TList.Count;
|
|
var finalGroup = new List<FinancialGroupViewModel>();
|
|
if (transactionCount <= 20)
|
|
{
|
|
var result = new FinancialGroupViewModel
|
|
{
|
|
TransactionList = TList
|
|
};
|
|
finalGroup.Add(result);
|
|
|
|
GroupeList = finalGroup;
|
|
}
|
|
else
|
|
{
|
|
var divide20 = transactionCount / 20;
|
|
var multiple = transactionCount - divide20 * 20;
|
|
|
|
for (var i = 1; i <= transactionCount; i += 20)
|
|
{
|
|
var start = i;
|
|
var end = i + 19;
|
|
|
|
var result = new FinancialGroupViewModel
|
|
{
|
|
TransactionList = TList.Where(x => x.Counter >= start && x.Counter <= end).ToList()
|
|
};
|
|
|
|
finalGroup.Add(result);
|
|
|
|
GroupeList = finalGroup;
|
|
}
|
|
}
|
|
|
|
pageCount = GroupeList.Count();
|
|
}
|
|
else
|
|
{
|
|
HasData = false;
|
|
}
|
|
}
|
|
} |