private async Task <Document> createDocument(TransferMoney transferMoney, string from, string to, int organId) { DocumentRule documentRule = new DocumentRule(); FinanYearRule finanYearRule = new FinanYearRule(); var finanYears = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanYears.Where(x => x.Closed == false && x.OrganId == organId).SingleOrDefault(); Document document = new Document(); document.Credit = transferMoney.Amount; document.DateTime = DateTime.Now; document.Debit = transferMoney.Amount; document.Description = " انتقال وجه از " + from + " به " + to; document.DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now); document.IsManual = false; document.Number = await documentRule.createNumberDocumentAsync(organId); document.Number2 = await documentRule.createNumberDocumentAsync(organId); document.Status = ZhivarEnums.DocumentStatus.TaeedShode; document.StatusString = "تایید شده"; document.OrganId = organId; document.FinanYear = finanYear; document.FinanYearId = finanYear.ID; document.Type = ZhivarEnums.NoeDoc.Transfer; List <Transaction> transactions = new List <Transaction>(); transactions = await RegisterTransaction(document, transferMoney, organId); document.Transactions = transactions; return(document); }
private static void AddBatterySheet(IReadOnlyDbContext db, ExcelPackage pkg, Dictionary <string, string> centerNames) { var sheet = pkg.Workbook.Worksheets.Add("Batteries"); var data = db.Find <RectifierAndBattery>(rb => rb.Deleted != true) .Project(rb => new { rb.Center, rb.Batteries }).ToList(); sheet.SetValue(1, 1, "مرکز"); for (int i = 0; i < data.Max(d => d.Batteries.Count); i++) { sheet.SetValue(1, i * 6 + 2, (i + 1) + ". مدل"); sheet.SetValue(1, i * 6 + 3, (i + 1) + ". ظرفیت"); sheet.SetValue(1, i * 6 + 4, (i + 1) + ". نوع"); sheet.SetValue(1, i * 6 + 5, (i + 1) + ". تعداد سلول ها"); sheet.SetValue(1, i * 6 + 6, (i + 1) + ". تاریخ تولید"); sheet.SetValue(1, i * 6 + 7, (i + 1) + ". تاریخ نصب"); } for (int row = 0; row < data.Count; row++) { if (centerNames.ContainsKey(data[row].Center)) { sheet.SetValue(row + 2, 1, centerNames[data[row].Center]); } for (int i = 0; i < data[row].Batteries.Count; i++) { sheet.SetValue(row + 2, i * 6 + 2, data[row].Batteries[i].Model); sheet.SetValue(row + 2, i * 6 + 3, data[row].Batteries[i].Capacity); sheet.SetValue(row + 2, i * 6 + 4, data[row].Batteries[i].Type); sheet.SetValue(row + 2, i * 6 + 5, (int)data[row].Batteries[i].CellsCount); sheet.SetValue(row + 2, i * 6 + 6, PersianDateUtils.GetPersianDateString(data[row].Batteries[i].ProductionDate)); sheet.SetValue(row + 2, i * 6 + 7, PersianDateUtils.GetPersianDateString(data[row].Batteries[i].InstallationDate)); } } }
private async Task <Document> createDocument(PayRecevie payRecevie, int organId, int numberDocument) { FinanYearRule finanYearRule = new FinanYearRule(); var finanYears = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanYears.Where(x => x.Closed == false).SingleOrDefault(); Document document = new Document(); document.Credit = payRecevie.Amount; document.DateTime = PersianDateUtils.ToDateTime(payRecevie.DisplayDate); document.Debit = payRecevie.Amount; document.Description = payRecevie.Description; document.DisplayDate = payRecevie.DisplayDate; document.IsManual = false; document.Status = ZhivarEnums.DocumentStatus.TaeedShode; document.ObjectState = OMF.Common.Enums.ObjectState.Added; if (numberDocument != 0) { document.Number = numberDocument; document.Number2 = numberDocument; } else { DocumentRule documentRule = new DocumentRule(); document.Number = await documentRule.createNumberDocumentAsync(organId); document.Number2 = await documentRule.createNumberDocumentAsync(organId); } document.Status = ZhivarEnums.DocumentStatus.TaeedShode; document.StatusString = "تایید شده"; document.OrganId = organId; document.FinanYear = finanYear; document.FinanYearId = finanYear.ID; List <Transaction> transactions = new List <Transaction>(); if (payRecevie.IsReceive) { document.Type = ZhivarEnums.NoeDoc.Recive; transactions = await RegisterTransactionRecevie(document, payRecevie, organId); } else { document.Type = ZhivarEnums.NoeDoc.Pay; transactions = await RegisterTransactionPay(document, payRecevie, organId); } document.Transactions = transactions; return(document); }
public async Task <HttpResponseMessage> GetPersonelById([FromBody] int id) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var personel = await Rule.FindAsync(id); UserInfo user = new UserInfo(); UserRole userRole = new UserRole(); if (personel != null) { user = await this.Rule.UnitOfWork.RepositoryAsync <UserInfo>().Queryable().Where(x => x.ID == personel.UserID).FirstOrDefaultAsync(); userRole = await this.Rule.UnitOfWork.RepositoryAsync <UserRole>().Queryable().Where(x => x.UserId == personel.UserID).FirstOrDefaultAsync(); } PersonelVM personelVM = new PersonelVM() { AzTarikh = personel.AzTarikh, DarHalKhedmat = personel.DarHalKhedmat, Darsd = personel.Darsd, DisplayAzTarikh = PersianDateUtils.ToPersianDateTime(personel.AzTarikh), Email = user.Email, OrganizationId = organId, UserID = user.ID, FirstName = user.FirstName, LastName = user.LastName, MobileNo = user.MobileNo, NationalCode = user.NationalCode, NoeMozd = personel.NoeMozd, Password = user.Password, RoleID = userRole.RoleId, Salary = personel.Salary, TaTarikh = personel.TaTarikh, Tel = user.Tel, UserName = user.UserName, PlainPassword = user.PlainPassword, Gender = user.Gender, ID = personel.ID, }; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = personelVM })); }
private ConnectionViewModel ConnectionToViewModel(Connection c, bool addMoreDetails = false) { var vm = Mapper.Map <ConnectionViewModel>(c); if (c.CustomerId != null) { vm.Customer = db.FindById <Customer>(c.CustomerId); vm.CustomerIcon = c.CustomerIcon; } foreach (var e in db.Find <EndPoint>(e => e.Connection == c.Id).SortBy(e => e.Index).ToEnumerable()) { var evm = Mapper.Map <EndPointViewModel>(e); if (addMoreDetails) { var device = db.FindById <Device>(evm.Device); evm.Center = device.GetCenterId(db); } vm.EndPoints.Add(evm); } var endPointsIds = vm.EndPoints.Select(e => e.Id).ToList(); var createActivity = db.FindFirst <UserActivity>(a => endPointsIds.Contains(a.ObjId) && a.ActivityType == ActivityType.Insert); var lastEditActivity = db.Find <UserActivity>(a => endPointsIds.Contains(a.ObjId) && a.ActivityType == ActivityType.Update) .Project(a => new { a.Time, a.Username }) .SortByDescending(a => a.Time).FirstOrDefault(); if (createActivity != null) { vm.CreateDate = PersianDateUtils.GetPersianDateString(createActivity.Time); var user = db.FindFirst <AuthUserX>(u => u.Username == createActivity.Username); if (user != null) { vm.CreatedUser = user.DisplayName; } } if (lastEditActivity != null) { vm.LastEditDate = PersianDateUtils.GetPersianDateString(lastEditActivity.Time); var user = db.FindFirst <AuthUserX>(u => u.Username == lastEditActivity.Username); if (user != null) { vm.EditedUser = user.DisplayName; } } return(vm); }
public async Task <ActionResult <List <EquipmentsPmListItemVM> > > List(PmSearchVM search) { stringNormalizer.Preprocess(search); var query = GetPmList(search); if (query == null) { return(new List <EquipmentsPmListItemVM>()); } if (search.Limit > 0) { query = query.Limit(search.Limit); } else { query = query.Limit(1000); } var pmList = await query.ToListAsync(); var centers = pmList.GroupBy(pm => pm.CenterId) .Select(g => db.FindById <CommCenterX>(g.Key)).Where(c => c != null).ToDictionary(c => c.Id); var cities = centers.Values.GroupBy(c => c.City).Select(c => db.FindById <City>(c.Key)).Where(c => c != null).ToDictionary(c => c.Id); var users = pmList.GroupBy(pm => pm.ReportingUser) .Select(g => db.FindById <AuthUserX>(g.Key)).ToDictionary(u => u.Id); return(pmList.Select(pm => new EquipmentsPmListItemVM { Id = pm.Id, Center = centers.ContainsKey(pm.CenterId) ? centers[pm.CenterId].Name : "(مرکز حذف شده)", City = centers.ContainsKey(pm.CenterId) && cities.ContainsKey(centers[pm.CenterId].City) ? cities[centers[pm.CenterId].City].Name : "", EditDate = PersianDateUtils.GetPersianDateString(pm.EditDate), SubmitDate = PersianDateUtils.GetPersianDateString(pm.SubmitDate), PmDate = PersianDateUtils.GetPersianDateString(pm.PmDate), ReportingUser = users[pm.ReportingUser]?.DisplayName ?? "(کاربر حذف شده)", TotalRate = pm.TotalRate }) .ToList()); }
public async Task <Document> RegisterDocument(CostVM cost, int personId) { var documentNumber = await createNumberDocument(personId); Document document = new Document(); document.Credit = cost.Sum; document.Debit = cost.Sum; document.IsManual = false; document.Number = documentNumber; document.Number2 = documentNumber; document.Status = ZhivarEnums.DocumentStatus.TaeedShode; document.StatusString = "تایید شده"; document.DisplayDate = cost.DisplayDate; document.DateTime = PersianDateUtils.ToDateTime(cost.DisplayDate); document.Type = ZhivarEnums.NoeDoc.Cost; List <Transaction> transactions = new List <Transaction>(); document.Description = cost.Explain; transactions = await RegisterTransaction(document, cost, personId); document.Transactions = transactions; if (document.Transactions != null && document.Transactions.Any()) { var credit = document.Transactions.Sum(x => x.Credit); var debit = document.Transactions.Sum(x => x.Debit); document.Credit = credit; document.Debit = debit; } return(document); }
public async Task <HttpResponseMessage> SaveReceiveAndPay([FromBody] PayRecevie payRecevie) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); FinanYearRule finanYearRule = new FinanYearRule(); var finanYerar = await finanYearRule.GetCurrentFinanYear(organId); var documentNumber = 0; int payRecevieNumber = 0; if (payRecevie.ID > 0) { PayRecevie temp = new PayRecevie(); temp = payRecevie; PayRecevieRule payRecevieRule = new PayRecevieRule(); payRecevieRule.Delete(payRecevie.ID); documentNumber = payRecevie.Document.Number; payRecevieNumber = payRecevie.Number; await payRecevieRule.SaveChangesAsync(); } payRecevie.ID = -1; if (payRecevie.Contact != null) { payRecevie.ContactId = payRecevie.Contact.ID; payRecevie.Contact.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; } if (payRecevie.Invoice != null) { payRecevie.InvoiceId = payRecevie.Invoice.ID; payRecevie.Invoice.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; } if (payRecevie.Cost != null) { payRecevie.CostId = payRecevie.Cost.ID; payRecevie.Cost.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; } payRecevie.OrganId = organId; payRecevie.Type = payRecevie.Type; payRecevie.Date = PersianDateUtils.ToDateTime(payRecevie.DisplayDate); payRecevie.DisplayDate = payRecevie.DisplayDate; // payRecevie.Date = DateTime.Now; //payRecevie.DisplayDate = Utilities.PersianDateUtils.ToPersianDate(DateTime.Now); decimal amount = 0; foreach (var item in payRecevie.Items) { amount += item.Amount; if (item.Cash != null) { item.CashId = item.Cash.ID; } else if (item.Bank != null) { item.BankId = item.Bank.ID; } else if (item.Cheque != null && item.Type == ZhivarEnums.DetailPayReceiveType.Cheque) { Cheque cheque = new Cheque() { Amount = item.Amount, BankBranch = item.Cheque.BankBranch, BankName = item.Cheque.BankName, ChequeNumber = item.Cheque.ChequeNumber, Contact = payRecevie.Contact, ContactId = payRecevie.Contact.ID, Date = PersianDateUtils.ToDateTime(item.Cheque.DisplayDate), OrganId = organId, Status = ZhivarEnums.ChequeStatus.Normal, DisplayDate = item.Cheque.DisplayDate, }; if (payRecevie.IsReceive) { cheque.Type = ZhivarEnums.ChequeType.Dareaftani; } else { cheque.Type = ZhivarEnums.ChequeType.Pardakhtani; } if (item.Cheque.ReceiptDate != null) { cheque.ReceiptDate = item.Cheque.ReceiptDate; } item.Cheque = cheque; item.ChequeId = item.Cheque.ID; item.Cheque.ObjectState = OMF.Common.Enums.ObjectState.Added; if (!payRecevie.IsReceive) { var temp = item.ChequeBank.ID; item.ChequeBank = new ChequeBank() { BankId = temp, ChequeId = item.Cheque.ID, OrganId = organId }; item.ChequeBank.ObjectState = OMF.Common.Enums.ObjectState.Added; item.ChequeBankId = item.ChequeBank.ID; } item.ObjectState = OMF.Common.Enums.ObjectState.Added; } if (item.Type == ZhivarEnums.DetailPayReceiveType.KharjCheque) { ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(item.Cheque.ID); cheque.Status = ZhivarEnums.ChequeStatus.Sold; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); item.Cheque.ContactId = item.Cheque.Contact.ID; } item.ObjectState = OMF.Common.Enums.ObjectState.Added; } payRecevie.Amount = amount; if (payRecevie.Invoice != null) { //if (payRecevie.Invoice.Contact != null) payRecevie.Invoice.ContactId = payRecevie.Invoice.ContactId; //payRecevie.Invoice.FinanYear = finanYerar; //payRecevie.Invoice.FinanYearId = finanYerar.ID; var invoice = payRecevie.Invoice; invoice.Rest -= amount; invoice.Paid += amount; if (invoice.Rest <= 0) { invoice.Status = ZhivarEnums.NoeInsertFactor.Received; } this.BusinessRule.UnitOfWork.RepositoryAsync <Invoice>().Update(invoice); } if (payRecevie.Cost != null) { //if (payRecevie.Cost.Contact != null) payRecevie.Cost.ContactId = payRecevie.Cost.ContactId; var cost = payRecevie.Cost; cost.Rest -= amount; cost.Paid += amount; if (cost.Rest <= 0) { cost.Status = ZhivarEnums.CostStatus.Paid; } this.BusinessRule.UnitOfWork.RepositoryAsync <Cost>().Update(cost); } payRecevie.Document = await createDocument(payRecevie, organId, documentNumber); if (payRecevieNumber > 0) { payRecevie.Number = payRecevieNumber; } else { var payRecevies = await Rule.GetAllByOrganIdAsync(organId); var lastPayRecevies = payRecevies.OrderByDescending(x => x.ID).FirstOrDefault(); if (lastPayRecevies != null) { payRecevie.Number = lastPayRecevies.Number + 1; } else { payRecevie.Number = 1; } } foreach (var transaction in payRecevie.Document.Transactions) { transaction.ObjectState = OMF.Common.Enums.ObjectState.Added; //if (transaction.AccDocument != null) // transaction.AccDocument.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; if (transaction.Account != null) { transaction.Account.ObjectState = OMF.Common.Enums.ObjectState.Unchanged; } // transaction.Transactions = null; } payRecevie.Document.ObjectState = OMF.Common.Enums.ObjectState.Added; payRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added; this.BusinessRule.UnitOfWork.RepositoryAsync <PayRecevie>().InsertOrUpdateGraph(payRecevie); await this.BusinessRule.UnitOfWork.SaveChangesAsync(); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = payRecevie })); } catch (Exception ex) { throw; } }
private async Task <List <Transaction> > RegisterTransactionRecevie(Document document, PayRecevie payRecevie, int organId) { List <Transaction> transactions = new List <Transaction>(); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); foreach (var item in payRecevie.Items) { var transaction = new Transaction(); switch (payRecevie.Type) { case ZhivarEnums.PayRecevieType.AzShakhs: { var accountDareaftani = accounts.Where(x => x.ComplteCoding == "1104" + payRecevie.Contact.Code).SingleOrDefault(); transaction = new Transaction(); //transaction.AccDocument = document; //transaction.Account = accountDareaftani; transaction.AccountId = accountDareaftani.ID; transaction.Amount = item.Amount; //Contact = payRecevieVM.ContactVM, transaction.ContactId = payRecevie.Contact.ID; transaction.Credit = item.Amount; transaction.Debit = 0; transaction.IsCredit = true; transaction.IsDebit = false; transaction.DocumentId = document.ID; transaction.Date = PersianDateUtils.ToDateTime(payRecevie.DisplayDate); transaction.DisplayDate = payRecevie.DisplayDate; transaction.Description = document.Description; if (payRecevie.Invoice != null) { transaction.InvoiceId = payRecevie.Invoice.ID; } transactions.Add(transaction); break; } case ZhivarEnums.PayRecevieType.Daramd: case ZhivarEnums.PayRecevieType.Sir: { var accountDaramd = accounts.Where(x => x.ComplteCoding == payRecevie.Account.ComplteCoding).SingleOrDefault(); transactions.Add(new Transaction() { //AccDocument = document, //Account = accountDaramd, AccountId = accountDaramd.ID, Amount = item.Amount, Credit = item.Amount, Debit = 0, IsCredit = true, IsDebit = false, DocumentId = document.ID, Date = PersianDateUtils.ToDateTime(payRecevie.DisplayDate), DisplayDate = payRecevie.DisplayDate, Description = document.Description, }); break; } } if (item.Bank != null) { var bankAccount = accounts.Where(x => x.ComplteCoding == "1103" + item.Bank.Code).SingleOrDefault(); transaction = new Transaction(); //transaction.AccDocument = document; //transaction.Account = bankAccount; transaction.AccountId = bankAccount.ID; transaction.Amount = item.Amount; transaction.Credit = 0; transaction.Debit = item.Amount; transaction.Description = document.Description; transaction.DocumentId = document.ID; transaction.IsCredit = false; transaction.IsDebit = true; transaction.Date = PersianDateUtils.ToDateTime(payRecevie.DisplayDate); transaction.DisplayDate = payRecevie.DisplayDate; if (payRecevie.Invoice != null) { transaction.InvoiceId = payRecevie.Invoice.ID; } transactions.Add(transaction); } if (item.Cash != null) { var cashAccount = accounts.Where(x => x.ComplteCoding == "1101" + item.Cash.Code).SingleOrDefault(); transaction = new Transaction(); //transaction.AccDocument = document; //transaction.Account = cashAccount; transaction.AccountId = cashAccount.ID; transaction.Amount = item.Amount; transaction.Credit = 0; transaction.Debit = item.Amount; transaction.Description = document.Description; transaction.DocumentId = document.ID; transaction.IsCredit = false; transaction.IsDebit = true; transaction.Date = PersianDateUtils.ToDateTime(payRecevie.DisplayDate); transaction.DisplayDate = payRecevie.DisplayDate; if (payRecevie.Invoice != null) { transaction.InvoiceId = payRecevie.Invoice.ID; } transactions.Add(transaction); } if (item.Cheque != null) { var asnadDreaftaniAccount = accounts.Where(x => x.ComplteCoding == "1105" + payRecevie.Contact.Code).SingleOrDefault(); transaction = new Transaction(); // transaction.AccDocument = document; //transaction.Account = asnadDreaftaniAccount; transaction.AccountId = asnadDreaftaniAccount.ID; transaction.Amount = item.Amount; transaction.Credit = 0; transaction.Debit = item.Amount; transaction.Description = document.Description; transaction.DocumentId = document.ID; transaction.IsCredit = false; transaction.IsDebit = true; transaction.Date = PersianDateUtils.ToDateTime(payRecevie.DisplayDate); transaction.DisplayDate = payRecevie.DisplayDate; if (payRecevie.Invoice != null) { transaction.InvoiceId = payRecevie.Invoice.ID; } transactions.Add(transaction); } } return(transactions); }
public async Task <ActionResult <List <string> > > SubmitExcelColumns(SelectedExcelColumns req) { var errors = new List <string>(); var saveList = new List <ElecBill>(); var filePath = Path.Combine(Path.GetTempPath(), req.FileName); if (!System.IO.File.Exists(filePath)) { errors.Add("فایل موجود نیست! لطفا دوباره آپلود نمائید."); return(errors); } var columnMap = req.SelectedColumns.Select(kv => new { Column = kv.Key, Property = ElecBill.ValidImportProperties.First(p => p.Name == kv.Value) }) .ToDictionary(a => a.Column, a => a.Property); var billsDuplicateCheck = (await db.Aggregate <ElecBill>() .Group(k => new { k.SubsNum, k.Year, k.Period }, g => new { g.Key }) .ToCursorAsync()) .ToEnumerable().Select(k => new SubsNumYearPeriod(k.Key.SubsNum, k.Key.Year, k.Key.Period)) .ToList(); var file = new FileInfo(filePath); using var pkg = new ExcelPackage(file); var sheet = pkg.Workbook.Worksheets[pkg.Compatibility.IsWorksheets1Based ? 1 : 0]; int row = 2; while (row <= sheet.Dimension.Rows) { ElecBill obj = new ElecBill(); int subsNumCol = 1; foreach (int col in columnMap.Keys) { var prop = columnMap[col]; if (prop.Name == nameof(ElecBill.SubsNum)) { subsNumCol = col; } object value = null; try { value = sheet.GetValue(row, col); if (value == null) { continue; } Type ptype = prop.PropertyType; int intValue; float floatValue; long longValue; if (ptype == typeof(int) && (value is double || value is float)) { intValue = (int)(double)value; prop.SetValue(obj, intValue); } else if (ptype == typeof(float) && value is double) { floatValue = (float)(double)value; prop.SetValue(obj, floatValue); } else if (ptype == typeof(long) && value is double) { longValue = (long)(double)value; prop.SetValue(obj, longValue); } else if (ptype == typeof(DateTime) && (value is double || value is float)) { string strDate = value.ToString(); DateTime date = PersianDateUtils.ParseToPersianDate(strDate).ToDateTime(); date = new DateTime(date.Ticks, DateTimeKind.Utc); date = date.AddHours(12); prop.SetValue(obj, date); } else if (value is string && ptype == typeof(int) && int.TryParse((string)value, out intValue)) { prop.SetValue(obj, intValue); } else if (value is string && ptype == typeof(float)) { string strValue = (string)value; if (strValue.StartsWith(".")) { strValue = "0" + strValue; } prop.SetValue(obj, float.Parse(strValue)); } else if (ptype == typeof(long) && long.TryParse((string)value, out longValue)) { prop.SetValue(obj, longValue); } else if (ptype == typeof(DateTime) && value is string) { var date = PersianDateUtils.ParseToPersianDate((string)value).ToDateTime().AddHours(12); prop.SetValue(obj, date); } else { prop.SetValue(obj, value); } } catch { errors.Add($"سلول {ColumnAlphabet(col)}{row} دارای مقدار نامعتبر است ({value}). "); } } var subscriber = db.FindFirst <Subscriber>(s => s.ElecSub.ElecSubsNum == obj.SubsNum); if (subscriber == null) { errors.Add($"سلول {ColumnAlphabet(subsNumCol)}{row}: مشترک با شماره اشتراک {obj.SubsNum} تعریف نشده است."); } else { obj.CityId = subscriber.City; if (!req.OverwriteExistingBills) { var newCheck = new SubsNumYearPeriod(obj.SubsNum, obj.Year, obj.Period); if (billsDuplicateCheck.Contains(newCheck)) { errors.Add($"سطر {row}: قبض با شماره اشتراک {obj.SubsNum} در دوره {obj.Year}-{obj.Period} قبلا موجود است!"); } else { billsDuplicateCheck.Add(newCheck); } } } if (errors.Count == 0) { saveList.Add(obj); } row++; } if (errors.Count == 0) { if (req.OverwriteExistingBills) { foreach (var obj in saveList) { db.DeleteOne <ElecBill>(eb => eb.SubsNum == obj.SubsNum && eb.Year == obj.Year && eb.Period == obj.Period); } } await db.InsertManyAsync(saveList); } pkg.Dispose(); file.Delete(); return(errors); }
public async Task <List <string> > SaveContract(ContractVM contractVM) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); FinanYearRule finanYearRule = new FinanYearRule(); var finanYears = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanYears.Where(x => x.Closed == false && x.OrganId == organId); contractVM.Contract_Sazes = contractVM.Contract_Sazes.Where(x => x.Saze != null).ToList(); foreach (var contract_Saze in contractVM.Contract_Sazes) { if (contract_Saze.Saze != null) { contract_Saze.SazeId = contract_Saze.Saze.ID; } if (contract_Saze.NoeEjare != null) { contract_Saze.NoeEjareId = contract_Saze.NoeEjare.ID; } if (contract_Saze.DisplayTarikhShorou != null) { contract_Saze.TarikhShorou = PersianDateUtils.ToDateTime(contract_Saze.DisplayTarikhShorou); if (contract_Saze.NoeEjareId == 1) { contract_Saze.TarikhPayan = contract_Saze.TarikhShorou.AddDays((double)contract_Saze.Quantity); } else if (contract_Saze.NoeEjareId == 2) { PersianCalendar pc = new PersianCalendar(); contract_Saze.TarikhPayan = pc.AddMonths(contract_Saze.TarikhShorou, (int)contract_Saze.Quantity); contract_Saze.DisplayTarikhPayan = PersianDateUtils.ToPersianDate(contract_Saze.TarikhPayan); } } } if (contractVM.Contact != null) { contractVM.ContactId = contractVM.Contact.ID; } DomainClasses.Contract.Contract contract = new DomainClasses.Contract.Contract(); Mapper.Map(contractVM, contract); contract.OrganId = organId; contract.DateTime = PersianDateUtils.ToDateTime(contract.DisplayDate); ContractValidate validator = new ContractValidate(); FluentValidation.Results.ValidationResult results = validator.Validate(contract); List <string> failurs = new List <string>();; if (!results.IsValid) { foreach (var error in results.Errors) { failurs.Add(error.ErrorMessage); } return(failurs); } // contract = savePaymentForContract(contract, contractVM); if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") && contractVM.ContractType == ContractType.RentFrom) { contract.Status = Status.ConfirmationContract; } else if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") && contractVM.ContractType == ContractType.PreContract) { contract.Status = Status.ConfirmationPreContract; contract.ContractType = ContractType.RentTo; // contract.Contract_Sazes = uow.Repository<Contract_Saze>().Queryable().Where(x => x.ContractID == contract.ID).ToList(); foreach (var contract_Saze in contract.Contract_Sazes ?? new List <Contract_Saze>()) { contract_Saze.Status = Status.ConfirmationPreContract; //contract_Saze.ObjectState = OMF.Common.Enums.ObjectState.Modified; } } else if (contractVM.ContractType == ContractType.PreContract && contractVM.Status == Status.SendPreContract) { //nothing } else { contract.Status = Status.Temporary; } if (contract.ID > 0) { foreach (var contractSaze in contract.Contract_Sazes) { contractSaze.TarikhShorou = PersianDateUtils.ToDateTime(contractSaze.DisplayTarikhShorou); contractSaze.ContractID = contract.ID; if (contractSaze.ID > 0) { contractSaze.ContractID = contract.ID; contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { contractSaze.ContractID = contract.ID; contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Added; } foreach (var contarct_Saze_Bazareab in contractSaze.Contarct_Saze_Bazareabs) { contractSaze.HasBazareab = true; if (contarct_Saze_Bazareab.ID > 0) { contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID; contarct_Saze_Bazareab.ObjectState = ObjectState.Modified; } else { contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID; contarct_Saze_Bazareab.ObjectState = ObjectState.Added; } } foreach (var contract_Saze_Tarah in contractSaze.Contract_Saze_Tarahs) { contractSaze.HasTarah = true; if (contract_Saze_Tarah.ID > 0) { contract_Saze_Tarah.ContarctSazeID = contractSaze.ID; contract_Saze_Tarah.ObjectState = ObjectState.Modified; } else { contract_Saze_Tarah.ContarctSazeID = contractSaze.ID; contract_Saze_Tarah.ObjectState = ObjectState.Added; } } foreach (var contract_Saze_Chapkhane in contractSaze.Contract_Saze_Chapkhanes) { contractSaze.HasChap = true; if (contract_Saze_Chapkhane.ID > 0) { contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID; contract_Saze_Chapkhane.ObjectState = ObjectState.Modified; } else { contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID; contract_Saze_Chapkhane.ObjectState = ObjectState.Added; } } foreach (var contract_Saze_Nasab in contractSaze.Contract_Saze_Nasabs) { contractSaze.HasNasab = true; if (contract_Saze_Nasab.ID > 0) { contract_Saze_Nasab.ContarctSazeID = contractSaze.ID; contract_Saze_Nasab.ObjectState = ObjectState.Modified; } else { contract_Saze_Nasab.ContarctSazeID = contractSaze.ID; contract_Saze_Nasab.ObjectState = ObjectState.Added; } } } foreach (var contract_PayRecevie in contract.Contract_PayRecevies) { if (contract_PayRecevie.ID > 0) { contract_PayRecevie.ContractId = contract.ID; contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { contract_PayRecevie.ContractId = contract.ID; contract_PayRecevie.IsReceive = true; contract_PayRecevie.OrganId = organId; contract_PayRecevie.Status = Status.Temporary; contract_PayRecevie.Type = PayRecevieType.Sir; contract_PayRecevie.Date = DateTime.Now; contract_PayRecevie.ContactId = contract.ID; contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added; } foreach (var contract_DetailPayRecevie in contract_PayRecevie.Contract_DetailPayRecevies) { if (contract_DetailPayRecevie.ID > 0) { contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID; contract_DetailPayRecevie.ObjectState = ObjectState.Modified; } else { contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID; contract_DetailPayRecevie.ObjectState = ObjectState.Added; } } } contract.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { foreach (var contractSaze in contract.Contract_Sazes) { contractSaze.ContractID = contract.ID; contractSaze.TarikhShorou = PersianDateUtils.ToDateTime(contractSaze.DisplayTarikhShorou); if (contractSaze.ID > 0) { contractSaze.ContractID = contract.ID; contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { contractSaze.ContractID = contract.ID; contractSaze.ObjectState = OMF.Common.Enums.ObjectState.Added; } foreach (var contarct_Saze_Bazareab in contractSaze.Contarct_Saze_Bazareabs) { contractSaze.HasBazareab = true; if (contarct_Saze_Bazareab.NoeMozdBazryab == NoeMozd.Month) { contarct_Saze_Bazareab.Hazine = 0; } if (contarct_Saze_Bazareab.ID > 0) { contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID; contarct_Saze_Bazareab.ObjectState = ObjectState.Modified; } else { contarct_Saze_Bazareab.ContarctSazeID = contractSaze.ID; contarct_Saze_Bazareab.ObjectState = ObjectState.Added; } } foreach (var contract_Saze_Tarah in contractSaze.Contract_Saze_Tarahs) { contractSaze.HasTarah = true; if (contract_Saze_Tarah.NoeMozdTarah == NoeMozd.Month) { contract_Saze_Tarah.Hazine = 0; } if (contract_Saze_Tarah.ID > 0) { contract_Saze_Tarah.ContarctSazeID = contractSaze.ID; contract_Saze_Tarah.ObjectState = ObjectState.Modified; } else { contract_Saze_Tarah.ContarctSazeID = contractSaze.ID; contract_Saze_Tarah.ObjectState = ObjectState.Added; } } foreach (var contract_Saze_Chapkhane in contractSaze.Contract_Saze_Chapkhanes) { contractSaze.HasChap = true; if (contract_Saze_Chapkhane.ID > 0) { contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID; contract_Saze_Chapkhane.ObjectState = ObjectState.Modified; } else { contract_Saze_Chapkhane.ContarctSazeID = contractSaze.ID; contract_Saze_Chapkhane.ObjectState = ObjectState.Added; } } foreach (var contract_Saze_Nasab in contractSaze.Contract_Saze_Nasabs) { contractSaze.HasNasab = true; if (contract_Saze_Nasab.NoeMozdNasab == NoeMozd.Month) { contract_Saze_Nasab.Hazine = 0; } if (contract_Saze_Nasab.ID > 0) { contract_Saze_Nasab.ContarctSazeID = contractSaze.ID; contract_Saze_Nasab.ObjectState = ObjectState.Modified; } else { contract_Saze_Nasab.ContarctSazeID = contractSaze.ID; contract_Saze_Nasab.ObjectState = ObjectState.Added; } } } if (contract.Contract_PayRecevies != null && contract.Contract_PayRecevies.Count() > 0 && contract.Contract_PayRecevies[0].Contract_DetailPayRecevies != null && contract.Contract_PayRecevies[0].Contract_DetailPayRecevies.Count() > 0) { foreach (var contract_PayRecevie in contract.Contract_PayRecevies) { contract_PayRecevie.ContractId = contract.ID; contract_PayRecevie.Date = DateTime.Now; contract_PayRecevie.IsReceive = true; if (contract_PayRecevie.ID > 0) { contract_PayRecevie.ContractId = contract.ID; contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Modified; } else { contract_PayRecevie.ContractId = contract.ID; contract_PayRecevie.ObjectState = OMF.Common.Enums.ObjectState.Added; } foreach (var contract_DetailPayRecevie in contract_PayRecevie.Contract_DetailPayRecevies) { if (contract_DetailPayRecevie.ID > 0) { contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID; contract_DetailPayRecevie.ObjectState = ObjectState.Modified; } else { contract_DetailPayRecevie.Contract_PayRecevieId = contract_PayRecevie.ID; contract_DetailPayRecevie.ObjectState = ObjectState.Added; } } } } else { contract.Contract_PayRecevies = null; } contract.ObjectState = OMF.Common.Enums.ObjectState.Added; } this.UnitOfWork.RepositoryAsync <DomainClasses.Contract.Contract>().InsertOrUpdateGraph(contract); // ContactRule contactRule = new ContactRule(); // await contactRule.UpdateContact(invoice.InvoiceType, invoice.ContactId); await this.UnitOfWork.SaveChangesAsync(); if (contractVM.ID <= 0) { if ((SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") && contractVM.ContractType == ContractType.PreContract) || (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") && contractVM.Status == Status.ConfirmationContract)) { InvoiceRule invoiceRule = new InvoiceRule(); var invoice = invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentTo); var document = invoiceRule.RegisterDocument(invoice, invoice.OrganId); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(document, invoice.OrganId); await documentRule.SaveChangesAsync(); invoice.DocumentID = document.ID; invoiceRule.Update(invoice); await invoiceRule.SaveChangesAsync(); } else if (SecurityManager.CurrentUserContext.Roles.Any(x => x.RoleCode == "Manager") && contractVM.ContractType == ContractType.RentTo) { InvoiceRule invoiceRule = new InvoiceRule(); invoiceRule.ConvertContractToInvoice(contract.ID, NoeFactor.RentFrom); } } return(failurs); } catch (Exception ex) { var p = ex; throw; } }
public async Task <HttpResponseMessage> SaveReservation([FromBody] ReservationVM reservationVM) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); reservationVM.ReservationDetails = reservationVM.ReservationDetails.Where(x => x.Saze != null).ToList(); foreach (var reservationDetailVM in reservationVM.ReservationDetails) { if (reservationDetailVM.Saze != null) { reservationDetailVM.SazeID = reservationDetailVM.Saze.ID; } if (reservationDetailVM.NoeEjare != null) { reservationDetailVM.NoeEjareID = reservationDetailVM.NoeEjare.ID; } if (reservationDetailVM.StartDisplayDate != null) { reservationDetailVM.StartDate = PersianDateUtils.ToDateTime(reservationDetailVM.StartDisplayDate); } if (reservationDetailVM.NoeEjareID == 1) { reservationDetailVM.EndDate = reservationDetailVM.StartDate.AddDays((double)reservationDetailVM.Quantity - 1); } else if (reservationDetailVM.NoeEjareID == 2) { PersianCalendar pc = new PersianCalendar(); reservationDetailVM.EndDate = pc.AddMonths(reservationDetailVM.StartDate, (int)reservationDetailVM.Quantity); } reservationDetailVM.EndDisplayDate = PersianDateUtils.ToPersianDateTime(reservationDetailVM.EndDate); } if (reservationVM.Contact != null) { reservationVM.ContactID = reservationVM.Contact.ID; } Reservation reservation = new Reservation(); Mapper.Map(reservationVM, reservation); reservation.OrganID = organId; reservation.RegisterDate = DateTime.Now; reservation.DisplayRegisterDate = PersianDateUtils.ToPersianDateTime(DateTime.Now); ReservationValidate validator = new ReservationValidate(); FluentValidation.Results.ValidationResult results = validator.Validate(reservation); string failurs = ""; if (!results.IsValid) { foreach (var error in results.Errors) { failurs += "<br/>" + error.ErrorMessage; } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = failurs })); } foreach (var reservationDetailVM in reservationVM.ReservationDetails) { using (var uow = new UnitOfWork()) { reservationDetailVM.StartDate = PersianDateUtils.ToDateTime(reservationDetailVM.StartDisplayDate); if (reservationDetailVM.NoeEjareID == 1) { reservationDetailVM.EndDate = reservationDetailVM.StartDate.AddDays((double)reservationDetailVM.Quantity); reservationDetailVM.EndDate = reservationDetailVM.EndDate.AddDays(-1); } else if (reservationDetailVM.NoeEjareID == 2) { PersianCalendar pc = new PersianCalendar(); reservationDetailVM.EndDate = pc.AddMonths(reservationDetailVM.StartDate, (int)reservationDetailVM.Quantity); reservationDetailVM.EndDate = reservationDetailVM.EndDate.AddDays(-1); } var contractsRentFromIds = await uow.RepositoryAsync <DomainClasses.Contract.Contract>().Queryable().Where(x => (x.ContractType == ContractType.RentFrom) && x.OrganId == organId).Select(x => x.ID).ToListAsync2(); var allSazesRentFrom = uow.RepositoryAsync <Contract_Saze>().Queryable().Where(x => contractsRentFromIds.Contains(x.ContractID) && x.SazeId == reservationDetailVM.SazeID && ((x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhShorou <= reservationDetailVM.EndDate.Date) || (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) || (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) || (x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhPayan <= reservationDetailVM.EndDate.Date))); if (!await allSazesRentFrom.AnyAsync2()) { string str = " این سازه از تاریخ " + reservationDetailVM.StartDisplayDate + " تا تاریخ " + PersianDateUtils.ToPersianDate(reservationDetailVM.EndDate) + " در اجاره شرکت نمی باشد. "; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = str })); } var contractsIds = await uow.RepositoryAsync <DomainClasses.Contract.Contract>().Queryable().Where(x => (x.ContractType == ContractType.PreContract || x.ContractType == ContractType.RentTo) && x.OrganId == organId).Select(x => x.ID).ToListAsync2(); var allSazes = uow.RepositoryAsync <Contract_Saze>().Queryable().Where(x => contractsIds.Contains(x.ContractID) && x.SazeId == reservationDetailVM.SazeID && ((x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhShorou <= reservationDetailVM.EndDate.Date) || (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) || (x.TarikhShorou <= reservationDetailVM.StartDate.Date && x.TarikhPayan >= reservationDetailVM.StartDate.Date) || (x.TarikhShorou >= reservationDetailVM.StartDate.Date && x.TarikhPayan <= reservationDetailVM.EndDate.Date))); var contractStopDetails = uow.RepositoryAsync <ContractStopDetails>().Queryable().Where(x => x.SazeID == reservationDetailVM.SazeID && x.StartDate <= reservationDetailVM.StartDate.Date && x.EndDate > reservationDetailVM.EndDate.Date); //if (await contractStopDetails.AnyAsync2()) // return Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = "" }); if (await allSazes.AnyAsync2()) { var p = await allSazes.FirstOrDefaultAsync2(); var contract = await uow.RepositoryAsync <DomainClasses.Contract.Contract>().Queryable().Where(x => x.ID == p.ContractID).SingleOrDefaultAsync2(); string noeEjareStr = "ماه"; if (p.NoeEjareId == 1) { noeEjareStr = "روز"; } string str = " این سازه از تاریخ " + p.DisplayTarikhShorou + " به مدت " + ((int)p.Quantity).ToString() + " " + noeEjareStr + " در اجاره قرارداد شماره " + Convert.ToInt32(contract.Number).ToString() + " با عنوان " + contract.ContractTitle + " می باشد. "; //string str = " می باشد. " + contract.ContactTitle + " با عنوان " + contract.Number + " در اجاره قرارداد شماره " + noeEjareStr + p.Quantity + " به مدت " + p.DisplayTarikhShorou + " این سازه از تاریخ "; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = str })); } else { var reservationsIds = uow.RepositoryAsync <Reservation>().Queryable().Where(x => x.OrganID == organId).Select(x => x.ID).ToList(); var reservation_Details = uow.RepositoryAsync <Reservation_Detail>().Queryable().Where(x => reservationsIds.Contains(x.ReservationID) && x.SazeID == reservationDetailVM.SazeID && ((x.StartDate >= reservationDetailVM.StartDate.Date && x.StartDate <= reservationDetailVM.EndDate.Date) || (x.StartDate <= reservationDetailVM.StartDate.Date && x.EndDate >= reservationDetailVM.StartDate.Date) || (x.StartDate <= reservationDetailVM.StartDate.Date && x.EndDate >= reservationDetailVM.StartDate.Date) || (x.StartDate >= reservationDetailVM.StartDate.Date && x.EndDate <= reservationDetailVM.EndDate.Date))); if (await reservation_Details.AnyAsync2()) { var reservation_Detail = await reservation_Details.FirstOrDefaultAsync2(); var reservationTemp = await uow.RepositoryAsync <Reservation>().Queryable().Where(x => x.ID == reservation_Detail.ReservationID).SingleOrDefaultAsync2(); string noeEjareStr = "ماه"; if (reservation_Detail.NoeEjareID == 1) { noeEjareStr = "روز"; } string str = " این سازه از تاریخ " + reservation_Detail.StartDisplayDate + " به مدت " + ((int)reservation_Detail.Quantity).ToString() + " " + noeEjareStr + " رزرو می باشد. "; // + Convert.ToInt32(reservation.).ToString() + " با عنوان " + reservation. + " می باشد. "; //string str = " می باشد. " + contract.ContactTitle + " با عنوان " + contract.Number + " در اجاره قرارداد شماره " + noeEjareStr + p.Quantity + " به مدت " + p.DisplayTarikhShorou + " این سازه از تاریخ "; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.ValidationError, data = str })); } } } } if (reservation.ID > 0) { foreach (var reservationDetail in reservation.ReservationDetails) { reservationDetail.StartDate = PersianDateUtils.ToDateTime(reservationDetail.StartDisplayDate); reservationDetail.ReservationID = reservation.ID; if (reservationDetail.ID > 0) { reservationDetail.ReservationID = reservation.ID; reservationDetail.ObjectState = ObjectState.Modified; } else { reservationDetail.ReservationID = reservation.ID; reservationDetail.ObjectState = ObjectState.Added; } } reservation.ObjectState = ObjectState.Modified; } else { foreach (var reservationDetail in reservation.ReservationDetails) { reservationDetail.ReservationID = reservation.ID; reservationDetail.StartDate = PersianDateUtils.ToDateTime(reservationDetail.StartDisplayDate); if (reservationDetail.ID > 0) { reservationDetail.ReservationID = reservation.ID; reservationDetail.ObjectState = ObjectState.Modified; } else { reservationDetail.ReservationID = reservation.ID; reservationDetail.ObjectState = ObjectState.Added; } } reservation.ObjectState = ObjectState.Added; } this.BusinessRule.UnitOfWork.RepositoryAsync <Reservation>().InsertOrUpdateGraph(reservation); await this.BusinessRule.UnitOfWork.SaveChangesAsync(); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = reservation })); } catch (Exception ex) { var p = ex; throw; } }
private async Task <Document> CreateDocumentPaidChequeReceipt(ChequesAndStatsVM chequesAndStatsVM, int organId) { FinanYearRule finanYearRule = new FinanYearRule(); var finanYears = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanYears.Where(x => x.Closed == false).SingleOrDefault(); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); //var chequeBanks = await _chequeBankService.GetAllByOrganIdAsync(organId); var chequeBanks = this.BusinessRule.UnitOfWork.RepositoryAsync <ChequeBank>().Queryable().Where(x => x.OrganId == organId); var chequeBank = chequeBanks.Where(x => x.ChequeId == cheque.ID).SingleOrDefault(); BankRule bankRule = new BankRule(); var bank = await bankRule.FindAsync(chequeBank.BankId); DocumentRule documentRule = new DocumentRule(); Document document = new Document(); document.Credit = cheque.Amount; document.DateTime = PersianDateUtils.ToDateTime(chequesAndStatsVM.date); document.Debit = cheque.Amount; document.Description = chequesAndStatsVM.description; document.DisplayDate = chequesAndStatsVM.date; document.IsManual = false; document.Status = ZhivarEnums.DocumentStatus.TaeedShode; document.Number = await documentRule.createNumberDocumentAsync(organId); document.Number2 = await documentRule.createNumberDocumentAsync(organId); document.StatusString = "تایید شده"; document.OrganId = organId; document.FinanYear = finanYear; document.FinanYearId = finanYear.ID; document.Type = ZhivarEnums.NoeDoc.Recive; List <Transaction> transactions = new List <Transaction>(); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); var accountPay = accounts.Where(x => x.ComplteCoding == "2102" + bank.Code).SingleOrDefault(); transactions.Add(new Transaction() { //AccDocument = document, AccountId = accountPay.ID, Amount = cheque.Amount, Description = chequesAndStatsVM.description, Credit = 0, Debit = cheque.Amount, IsCredit = false, IsDebit = true, DocumentId = document.ID, Date = PersianDateUtils.ToDateTime(chequesAndStatsVM.date), DisplayDate = chequesAndStatsVM.date }); var accountBank = accounts.Where(x => x.ComplteCoding == "1103" + bank.Code).SingleOrDefault(); transactions.Add(new Transaction() { //AccDocument = document, AccountId = accountBank.ID, Amount = cheque.Amount, Credit = cheque.Amount, Debit = 0, Description = chequesAndStatsVM.description, DocumentId = document.ID, IsCredit = true, IsDebit = false, Date = PersianDateUtils.ToDateTime(chequesAndStatsVM.date), DisplayDate = chequesAndStatsVM.date }); document.Transactions = transactions; return(document); }
public async Task <HttpResponseMessage> loadInvoiceData([FromBody] int id) { try { } catch (Exception ex) { throw; } var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var resualt = new InvoiceData(); List <ContactVM> contacts = new List <ContactVM>(); ContactRule contactRule = new ContactRule(); var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); contactsSource = contactsSource.ToList(); contacts = TranslateHelper.TranslateEntityToEntityVMListContact(contactsSource); foreach (var contact in contacts) { contact.DetailAccount = new DetailAccount() { Code = contact.Code, Id = (int)contact.ID, Node = new Node() { FamilyTree = "اشخاص", Id = (int)contact.ID, Name = "اشخاص" } }; //var account1104 = await CalcAccountByCodeTafziliAsync(organId, "1104" + contact.Code); //var account1105 = await CalcAccountByCodeTafziliAsync(organId, "1105" + contact.Code); //var account2101 = await CalcAccountByCodeTafziliAsync(organId, "2101" + contact.Code); //contact.Balance = account1104.sumTotal + account1105.sumTotal + account2101.sumTotal; //contact.Credits = account1104.sumCredit + account1105.sumCredit + account2101.sumCredit; //contact.Liability = account1104.sumDebit + account1105.sumDebit + account2101.sumDebit; } resualt.contacts = contacts; resualt.invoiceSettings = new InvoiceSettings() { allowApproveWithoutStock = false, autoAddTax = true, bottomMargin = "20", businessLogo = "", font = "Iransans", fontSize = "Medium", footerNote = "", footerNoteDraft = "", hideZeroItems = false, onlineInvoiceEnabled = false, pageSize = "A4portrait", payReceiptTitle = "رسید پرداخت وجه / چک", purchaseInvoiceTitle = "فاکتور خرید", receiveReceiptTitle = "رسید دریافت وجه / چک", rowPerPage = "18", saleDraftInvoiceTitle = "پیش فاکتور", saleInvoiceTitle = "صورتحساب فروش کالا و خدمات", showAmountInWords = false, showCustomerBalance = false, showItemUnit = false, showSignaturePlace = true, showTransactions = true, showVendorInfo = true, topMargin = "10", updateBuyPrice = false, updateSellPrice = false }; ItemGroupRule itemGroupRule = new ItemGroupRule(); var itemGroups = await itemGroupRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); var items = new List <ItemVM>(); var item = new ItemVM(); foreach (var itemGroup in itemGroups) { foreach (var KalaKhadmat in itemGroup.Items) { item = new ItemVM() { Barcode = "", BuyPrice = KalaKhadmat.BuyPrice, DetailAccount = new DetailAccount() { Code = KalaKhadmat.Code, Id = KalaKhadmat.ID, Node = new Node() { FamilyTree = itemGroup.Name, Name = itemGroup.Name, Id = itemGroup.ID } }, ID = KalaKhadmat.ID, Name = KalaKhadmat.Name, UnitID = KalaKhadmat.UnitID, SalesTitle = KalaKhadmat.SalesTitle, PurchasesTitle = KalaKhadmat.PurchasesTitle, SellPrice = KalaKhadmat.SellPrice, ItemType = KalaKhadmat.ItemType, Stock = KalaKhadmat.Stock, Code = KalaKhadmat.Code, IsGoods = KalaKhadmat.IsGoods, IsService = KalaKhadmat.IsService, MoneyStock = KalaKhadmat.MoneyStock, OrganId = KalaKhadmat.OrganId, ItemGroupId = KalaKhadmat.ItemGroupId }; items.Add(item); } } resualt.items = items; var InvoiceItems = new List <InvoiceItemVM>(); if (id == 0) { InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 0, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 1, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 2, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); InvoiceItems.Add(new InvoiceItemVM() { Description = "", Discount = 0, ID = 0, Inv = null, Item = null, ItemInput = "", Quantity = 0, RowNumber = 3, Sum = 0, Tax = 0, TotalAmount = 0, Unit = 0, UnitPrice = 0 }); resualt.invoice = new InvoiceVM() { Contact = null, ContactTitle = "", DateTime = DateTime.Now, DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now), DisplayDueDate = PersianDateUtils.ToPersianDate(DateTime.Now), invoiceDueDate = PersianDateUtils.ToPersianDate(DateTime.Now), DueDate = DateTime.Now, ID = 0, InvoiceItems = InvoiceItems, InvoiceStatusString = "موقت", InvoiceType = 0, InvoiceTypeString = "فروش", IsDraft = true, IsPurchase = false, IsPurchaseReturn = false, IsSale = true, IsSaleReturn = false, IsWaste = false, Note = "", Number = await createNumberInvoice(organId), Paid = 0, Payable = 0, Profit = 0, Reference = "", Rest = 0, Returned = false, Sent = false, Status = 0, Sum = 0, Tag = "" }; } else { var invoice = await Rule.FindAsync(id); foreach (var invoiceItem in invoice.InvoiceItems ?? new List <InvoiceItem>()) { InvoiceItems.Add(new InvoiceItemVM() { Description = invoiceItem.Description, Discount = invoiceItem.Discount, ID = invoiceItem.ID, Inv = invoiceItem.Inv, Item = Mapper.Map <Item, ItemVM>(this.BusinessRule.UnitOfWork.Repository <Item>().Find(invoiceItem.ItemId)), ItemId = invoiceItem.ItemId, ItemInput = invoiceItem.ItemInput, Quantity = invoiceItem.Quantity, RowNumber = invoiceItem.RowNumber, Sum = invoiceItem.SumInvoiceItem, Tax = invoiceItem.Tax, TotalAmount = invoiceItem.TotalAmount, Unit = invoiceItem.UnitInvoiceItem, UnitPrice = invoiceItem.UnitPrice }); } resualt.invoice = new InvoiceVM() { Contact = Mapper.Map <Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository <Contact>().Find(invoice.ContactId)), ContactTitle = invoice.ContactTitle, DateTime = invoice.DateTime, DisplayDate = invoice.DisplayDate, DisplayDueDate = invoice.DisplayDueDate, invoiceDueDate = invoice.DisplayDueDate, DueDate = invoice.DueDate, ID = invoice.ID, InvoiceItems = InvoiceItems, InvoiceStatusString = invoice.InvoiceStatusString, InvoiceType = invoice.InvoiceType, InvoiceTypeString = invoice.InvoiceTypeString, IsDraft = invoice.IsDraft, IsPurchase = invoice.IsPurchase, IsPurchaseReturn = invoice.IsPurchaseReturn, IsSale = invoice.IsSale, IsSaleReturn = invoice.IsSaleReturn, IsWaste = false, Note = invoice.Note, Number = invoice.Number, Paid = invoice.Paid, Payable = invoice.Payable, Profit = invoice.Profit, Reference = invoice.Refrence, Rest = invoice.Rest, Returned = invoice.Returned, Sent = invoice.Sent, Status = invoice.Status, Sum = invoice.Sum, Tag = invoice.Tag }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); }
public async Task <HttpResponseMessage> GetRequiredDataToClosingFinanYear() { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); TransactionRule transactionRule = new TransactionRule(); var transactions = await transactionRule.GetAllByOrganIdAsync(organId); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); var incomeAccount = accounts.Where(x => x.ComplteCoding == "71" || x.ComplteCoding == "72").Select(x => x.ID).ToList(); var costAccount = accounts.Where(x => x.ComplteCoding == "81" || x.ComplteCoding == "82" || x.ComplteCoding == "83").Select(x => x.ID).ToList(); decimal incomeAmount = 0; decimal costAmount = 0; var accountsMoienQuery = accounts.AsQueryable().Where(x => incomeAccount.Contains(x.ParentId)); var allAccountQuery = accounts.AsQueryable(); List <int> childIds = (from account in accountsMoienQuery select account.ID).ToList(); List <int> childChildIds = (from account in allAccountQuery join accountsMoien in accountsMoienQuery on account.ParentId equals accountsMoien.ID select account.ID).ToList(); var selected = transactions.Where(a => incomeAccount.Contains(a.AccountId) || childIds.Contains(a.AccountId) || childChildIds.Contains(a.AccountId)).ToList(); if (selected.Any()) { var credit = selected.Sum(x => x.Credit); var debit = selected.Sum(x => x.Debit); incomeAmount = credit - debit; } var accountsMoienCostQuery = accounts.AsQueryable().Where(x => costAccount.Contains(x.ParentId)); List <int> childIdsCost = (from account in accountsMoienCostQuery select account.ID).ToList(); List <int> childChildIdsCost = (from account in allAccountQuery join accountsMoien in accountsMoienCostQuery on account.ParentId equals accountsMoien.ID select account.ID).ToList(); var selectedCost = transactions.Where(a => costAccount.Contains(a.AccountId) || childIdsCost.Contains(a.AccountId) || childChildIdsCost.Contains(a.AccountId)).ToList(); if (selectedCost.Any()) { var credit = selectedCost.Sum(x => x.Credit); var debit = selectedCost.Sum(x => x.Debit); costAmount = credit - debit; } FinanYearRule finanYearRule = new FinanYearRule(); var finanQuery = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanQuery.Where(x => x.FirstYear == true).SingleOrDefault(); ShareholderRule shareholderRule = new ShareholderRule(); var shareHolders = await shareholderRule.GetAllByOrganIdAsync(organId); var startDate = PersianDateUtils.ToDateTime(finanYear.DisplayStartDate); var endDate = PersianDateUtils.ToDateTime(finanYear.DisplayEndDate); double diff2 = (endDate - startDate).TotalDays; var startDateNew = endDate.AddDays(1); var endDateNew = endDate.AddDays(diff2); var displayEndDateNew = PersianDateUtils.ToPersianDateTime(endDateNew); var displayStartDateNew = PersianDateUtils.ToPersianDateTime(startDateNew); var startYear = Convert.ToInt32(displayStartDateNew.Substring(0, 4)); var startMonth = Convert.ToInt32(displayStartDateNew.Substring(5, 2)); var startDay = Convert.ToInt32(displayStartDateNew.Substring(8, 2)); var endYear = Convert.ToInt32(displayEndDateNew.Substring(0, 4)); var endMonth = Convert.ToInt32(displayEndDateNew.Substring(5, 2)); var endDay = Convert.ToInt32(displayEndDateNew.Substring(8, 2)); var isMoreThanYear = false; if (diff2 > 365) { isMoreThanYear = true; } var resualt = new DataToClosingFinanYear(); resualt.closingDate = finanYear.DisplayEndDate; resualt.netIncome = incomeAmount - costAmount; resualt.newFinanYear = new FinanYearVM() { Closed = false, DisplayEndDate = displayEndDateNew, DisplayStartDate = displayStartDateNew, EndDate = endDateNew, EndDateDay = endDay, EndDateMonth = endMonth, EndDateYear = endYear, FirstYear = false, Id = 0, IsMoreThanOneYear = isMoreThanYear, Name = endYear + " سال مال منتهی به", Note = "", StartDate = startDate, StartDateDay = startDay, StartDateMonth = startMonth, StartDateYear = startYear, }; resualt.shareholders = new List <ShareholderVM>(); foreach (var shareHolder in shareHolders) { resualt.shareholders.Add(new ShareholderVM() { Address = shareHolder.Address, City = shareHolder.City, Code = shareHolder.Code, ContactEmail = "", ContactType = shareHolder.ContactType, Credits = shareHolder.Credits, //DetailAccount = new DetailAccount() //{ // Accounts = null, // Balance = 0, // BalanceType = 0, // Code = "000001", // Id = 1, // Name = "مونا ابراهیمی", // Node = new Node() // { // FamilyTree = "اشخاص", // Id = 1, // Name = "اشخاص", // Parent = null, // Parents = ",1,", // SystemAccount = 1 // }, // RelatedAccounts = ",6,22,7,32,33,34,35,", // credit = 0, // debit = 0, //}, Email = shareHolder.Email, Fax = shareHolder.Fax, FirstName = shareHolder.FirstName, Id = (int)shareHolder.ID, IsCustomer = shareHolder.IsCustomer, IsEmployee = shareHolder.IsEmployee, IsShareHolder = shareHolder.IsShareHolder, IsVendor = shareHolder.IsVendor, LastName = shareHolder.LastName, Liability = shareHolder.Liability, Mobile = shareHolder.Mobile, Name = shareHolder.Name, NationalCode = shareHolder.NationalCode, Note = shareHolder.Note, People = shareHolder.People, Phone = shareHolder.Phone, PostalCode = shareHolder.PostalCode, Rating = shareHolder.Rating, RegistrationDate = shareHolder.RegistrationDate, RegistrationNumber = shareHolder.RegistrationNumber, SharePercent = shareHolder.SharePercent, State = shareHolder.State, Website = shareHolder.Website, }); } return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); }
public async Task <List <Transaction> > RegisterTransaction(Document document, CostVM cost, int organId) { AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); string contactCode = "2101" + cost.Contact.Code; var accountHesabPardakhtani = accounts.Where(x => x.ComplteCoding == contactCode).SingleOrDefault(); List <Transaction> transactions = new List <Transaction>(); transactions.Add(new Transaction() { AccountId = accountHesabPardakhtani.ID, ContactId = cost.Contact.ID, DocumentId = document.ID, CostId = cost.ID, //AccDocument = document, Account = accountHesabPardakhtani, Amount = cost.Sum, //Contact = cost.Contact, //Cost = cost, IsDebit = false, IsCredit = true, Debit = 0, Credit = cost.Sum, Description = document.Description, RowNumber = 1, DisplayDate = document.DisplayDate, Date = PersianDateUtils.ToDateTime(document.DisplayDate), }); foreach (var item in cost.CostItems) { var accoubtItem = new DomainClasses.Accounting.Account(); accoubtItem = accounts.Where(x => x.ComplteCoding == "8205").SingleOrDefault(); transactions.Add(new Transaction() { AccountId = accoubtItem.ID, ContactId = cost.Contact.ID, DocumentId = document.ID, CostId = cost.ID, //AccDocument = document, Account = accoubtItem, Amount = item.Sum, //Contact = cost.Contact, //Cost = cost, IsDebit = true, IsCredit = false, Debit = item.Sum, Credit = 0, Description = item.Description, //RowNumber = 1, DisplayDate = document.DisplayDate, Date = Utilities.PersianDateUtils.ToDateTime(document.DisplayDate), }); } return(transactions); }
private byte[] CreateExcelFile(List <EquipmentsPM> pms) { using var memStream = new MemoryStream(); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using var package = new ExcelPackage(memStream); var citiesDic = Cities.ToDictionary(i => i.Id); var centers = db.All <CommCenterX>().ToDictionary(i => i.Id); var usersName = GetUsersName(); // diesels sheet ExcelWorksheet sheet = package.Workbook.Worksheets.Add("دیزل ها"); sheet.View.RightToLeft = true; sheet.DefaultColWidth = 20; int col = 1; sheet.SetValue(1, col++, "شهر"); sheet.SetValue(1, col++, "مرکز"); sheet.SetValue(1, col++, "کاربر ثبت کننده"); sheet.SetValue(1, col++, "تاریخ ثبت"); sheet.SetValue(1, col++, "تاریخ تغییر"); Dictionary <PropertyInfo, int> columns = new Dictionary <PropertyInfo, int>(); PropertyInfo[] props = typeof(DieselPM).GetProperties(); for (int i = 0; i < 3; i++) { foreach (PropertyInfo p in props) { if (!columns.ContainsKey(p)) { columns.Add(p, col); } string dispName = DisplayUtils.DisplayName(p); sheet.SetValue(1, col++, (i + 1) + "-" + dispName); } } sheet.Row(1).Style.Font.Bold = true; int row = 2; foreach (var pm in pms) { if (centers.ContainsKey(pm.CenterId)) { if (citiesDic.ContainsKey(centers[pm.CenterId].City)) { sheet.SetValue(row, 1, citiesDic[centers[pm.CenterId].City].Name); } sheet.SetValue(row, 2, centers[pm.CenterId].Name); } if (usersName.ContainsKey(pm.ReportingUser)) { sheet.SetValue(row, 3, usersName[pm.ReportingUser]); } sheet.SetValue(row, 4, PersianDateUtils.GetPersianDateString(pm.SubmitDate)); sheet.SetValue(row, 5, PersianDateUtils.GetPersianDateString(pm.EditDate)); for (int i = 0; i < pm.DieselsPM.Count; i++) { int colOffset = i * (props.Length + 1); foreach (PropertyInfo prop in props) { object value = prop.GetValue(pm.DieselsPM[i]); if (value != null) { sheet.SetValue(row, columns[prop] + colOffset, value.ToString()); } } } row++; } // rectifiers sheet sheet = package.Workbook.Worksheets.Add("یکسوسازها"); sheet.View.RightToLeft = true; sheet.DefaultColWidth = 20; col = 1; sheet.SetValue(1, col++, "شهر"); sheet.SetValue(1, col++, "مرکز"); sheet.SetValue(1, col++, "کاربر ثبت کننده"); sheet.SetValue(1, col++, "تاریخ ثبت"); sheet.SetValue(1, col++, "تاریخ تغییر"); columns = new Dictionary <PropertyInfo, int>(); props = typeof(RectifierPM).GetProperties(); for (int i = 0; i < 3; i++) { foreach (PropertyInfo p in props) { if (!columns.ContainsKey(p)) { columns.Add(p, col); } string dispName = DisplayUtils.DisplayName(p); sheet.SetValue(1, col++, (i + 1) + "-" + dispName); } } sheet.Row(1).Style.Font.Bold = true; row = 2; foreach (var pm in pms) { if (centers.ContainsKey(pm.CenterId)) { if (citiesDic.ContainsKey(centers[pm.CenterId].City)) { sheet.SetValue(row, 1, citiesDic[centers[pm.CenterId].City].Name); } sheet.SetValue(row, 2, centers[pm.CenterId].Name); } if (usersName.ContainsKey(pm.ReportingUser)) { sheet.SetValue(row, 3, usersName[pm.ReportingUser]); } sheet.SetValue(row, 4, PersianDateUtils.GetPersianDateString(pm.SubmitDate)); sheet.SetValue(row, 5, PersianDateUtils.GetPersianDateString(pm.EditDate)); for (int i = 0; i < pm.RectifiersPM.Count; i++) { int colOffset = i * (props.Length + 1); foreach (PropertyInfo prop in props) { object value = prop.GetValue(pm.RectifiersPM[i]); if (value != null) { sheet.SetValue(row, columns[prop] + colOffset, value.ToString()); } } } row++; } // batteries sheet sheet = package.Workbook.Worksheets.Add("باتریها"); sheet.View.RightToLeft = true; sheet.DefaultColWidth = 20; col = 1; sheet.SetValue(1, col++, "شهر"); sheet.SetValue(1, col++, "مرکز"); sheet.SetValue(1, col++, "کاربر ثبت کننده"); sheet.SetValue(1, col++, "تاریخ ثبت"); sheet.SetValue(1, col++, "تاریخ تغییر"); for (int i = 0; i < 4; i++) { sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.DistilledWaterAdded)); sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.Temperature)); sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.OutputCurrent)); sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.Description)); for (int j = 1; j <= 25; j++) { sheet.SetValue(1, col++, "سری " + (i + 1) + " -ولتاژ سلول " + j); } for (int j = 1; j <= 25; j++) { sheet.SetValue(1, col++, "سری " + (i + 1) + " -غلظت سلول " + j); } } sheet.Row(1).Style.Font.Bold = true; row = 2; foreach (var pm in pms) { if (centers.ContainsKey(pm.CenterId)) { if (citiesDic.ContainsKey(centers[pm.CenterId].City)) { sheet.SetValue(row, 1, citiesDic[centers[pm.CenterId].City].Name); } sheet.SetValue(row, 2, centers[pm.CenterId].Name); } if (usersName.ContainsKey(pm.ReportingUser)) { sheet.SetValue(row, 3, usersName[pm.ReportingUser]); } sheet.SetValue(row, 4, PersianDateUtils.GetPersianDateString(pm.SubmitDate)); sheet.SetValue(row, 5, PersianDateUtils.GetPersianDateString(pm.EditDate)); col = 6; for (int i = 0; i < pm.BatteriesPM.Count; i++) { for (int j = 0; j < pm.BatteriesPM[i].Series.Count; j++) { sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].DistilledWaterAdded); sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Temperature); sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].OutputCurrent); sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Description); for (int k = 0; k < pm.BatteriesPM[i].Series[j].Voltages.Length; k++) { sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Voltages[k]); } for (int k = 0; k < pm.BatteriesPM[i].Series[j].Densities.Length; k++) { sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Densities[k]); } } } row++; } package.Save(); return(memStream.ToArray()); }
private IFindFluent <EquipmentsPM, EquipmentsPM> GetPmList(PmSearchVM search) { var filters = new List <FilterDefinition <EquipmentsPM> >(); var fb = Builders <EquipmentsPM> .Filter; if (!string.IsNullOrEmpty(search.City) || !string.IsNullOrEmpty(search.Center)) { if (!string.IsNullOrEmpty(search.Center)) { filters.Add(fb.Eq(pm => pm.CenterId, search.Center)); } else { var centersFilter = new List <FilterDefinition <EquipmentsPM> >(); foreach (var id in db.Find <CommCenterX>(c => c.City == search.City).Project(c => c.Id).ToEnumerable()) { centersFilter.Add(fb.Eq(pm => pm.CenterId, id)); } if (centersFilter.Count == 0) { return(null); } else if (centersFilter.Count == 1) { filters.Add(centersFilter[0]); } else if (centersFilter.Count > 1) { filters.Add(fb.Or(centersFilter)); } } } if (!string.IsNullOrEmpty(search.FromDate)) { var fromDate = PersianDateUtils.PersianDateTimeToGeorgian(search.FromDate); filters.Add(fb.Gte(pm => pm.SubmitDate, fromDate)); } if (!string.IsNullOrEmpty(search.ToDate)) { var toDate = PersianDateUtils.PersianDateTimeToGeorgian(search.ToDate); filters.Add(fb.Lte(pm => pm.SubmitDate, toDate)); } if (!string.IsNullOrEmpty(search.SubmittedUser)) { filters.Add(fb.Eq(pm => pm.ReportingUser, search.SubmittedUser)); } var totalFilter = fb.Empty; if (filters.Count == 1) { totalFilter = filters[0]; } else if (filters.Count > 1) { totalFilter = fb.And(filters); } return(db.Find(totalFilter) .Project <EquipmentsPM>(Builders <EquipmentsPM> .Projection .Include(pm => pm.Id) .Include(pm => pm.CenterId) .Include(pm => pm.PmDate) .Include(pm => pm.SubmitDate) .Include(pm => pm.EditDate) .Include(pm => pm.ReportingUser) .Include(pm => pm.TotalRate)) .SortByDescending(pm => pm.SubmitDate)); }
public virtual async Task <HttpResponseMessage> SaveTransfer([FromBody] TransferMoneyVM transferMoneyVM) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); if (!string.IsNullOrEmpty(transferMoneyVM.DisplayDate)) { var str = transferMoneyVM.DisplayDate.Replace("۰", "0").Replace("۱", "1").Replace("۲", "2").Replace("۳", "3").Replace("۴", "4").Replace("۵", "5").Replace("۶", "6").Replace("۷", "7").Replace("۸", "8").Replace("۹", "9"); transferMoneyVM.Date = PersianDateUtils.ToDateTime(str); } else { transferMoneyVM.Date = DateTime.Now; } if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.ValidationError, data = "" })); } var transferMoney = new TransferMoney(); Mapper.Map(transferMoneyVM, transferMoney); transferMoney.OrganId = organId; var fromName = string.Empty; var toName = string.Empty; AccountRule accountRule = new AccountRule(); if (transferMoneyVM.From == "bank") { var bankFrom = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.FromDetailAccountId)); fromName = bankFrom.Name; } else { var cashFrom = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.FromDetailAccountId)); fromName = cashFrom.Name; } if (transferMoneyVM.To == "bank") { var bankTo = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.ToDetailAccountId)); toName = bankTo.Name; } else { var cashTo = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.ToDetailAccountId)); toName = cashTo.Name; } transferMoney.Document = await createDocument(transferMoney, fromName, toName, organId); TransferMoneyRule transferMoneyRule = new TransferMoneyRule(); if (transferMoney.DocumentId != null && transferMoney.DocumentId > 0) { var oldTransfer = await transferMoneyRule.GetByDocIdAsync((int)transferMoney.DocumentId); //transferMoneyVM.ID = oldTransfer.ID; //transferMoney.ID = oldTransfer.ID; //transferMoney.Document.ID = oldTransfer.Document.ID; //transferMoney.DocumentId = oldTransfer.DocumentId; //transferMoney.Document.Transactions[0].ID = oldTransfer.Document.Transactions[0].ID; //transferMoney.Document.Transactions[1].ID = oldTransfer.Document.Transactions[1].ID; //transferMoney.Document.Transactions[0].DocumentId = oldTransfer.Document.ID; //transferMoney.Document.Transactions[1].DocumentId = oldTransfer.Document.ID; transferMoneyRule.Delete(oldTransfer.ID); await transferMoneyRule.SaveChangesAsync(); } //if (transferMoneyVM.ID.HasValue) //{ // transferMoneyRule.Update(transferMoney); //} //else //{ // transferMoneyRule.Insert(transferMoney); //} transferMoneyRule.Insert(transferMoney); await transferMoneyRule.SaveChangesAsync(); string result = transferMoneyVM.Amount + "," + fromName + "," + toName; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = result })); }
public DataTable Create <T>(DataTable table, IEnumerable <T> list, bool convertDateToPersian = true, bool includeTimeInDates = true, bool addIndexColumn = false, string[] excludeColumns = null, Dictionary <string, Dictionary <ObjectId, string> > valuesReferenceReplacement = null) { if (list == null) { return(null); } Dictionary <PropertyInfo, string> displayNames = CreateDataTableColumns <T>(table, convertDateToPersian, includeTimeInDates, addIndexColumn, excludeColumns); int i = 1; foreach (T item in list) { DataRow row = table.NewRow(); if (addIndexColumn) { row[INDEX_COLUMN] = i++; } foreach (PropertyInfo p in displayNames.Keys) { object value = p.GetValue(item); if (value is ObjectId) { if (valuesReferenceReplacement != null && valuesReferenceReplacement.ContainsKey(p.Name)) { if (valuesReferenceReplacement[p.Name].ContainsKey((ObjectId)value)) { value = valuesReferenceReplacement[p.Name][(ObjectId)value]; } else { value = null; } } else { value = value.ToString(); } } else if (p.PropertyType.IsEnum) { value = DisplayUtils.DisplayName(p.PropertyType, value.ToString()); } else if (value is DateTime && convertDateToPersian) { value = PersianDateUtils.GetPersianDateString((DateTime)value, includeTimeInDates); } else if (value is IEnumerable && !(value is string)) { StringBuilder sb = new StringBuilder(); Type itemsType = null; foreach (var v in (IEnumerable)value) { if (itemsType == null) { itemsType = v.GetType(); } sb.Append(DisplayUtils.DisplayName(itemsType, v.ToString())).Append(" ; "); } if (sb.Length > 3) { sb.Remove(sb.Length - 3, 3); } value = sb.ToString(); } row[displayNames[p]] = value == null ? DBNull.Value : value; } table.Rows.Add(row); } return(table); }
public virtual async Task <HttpResponseMessage> ChangeChequeStatus([FromBody] ChequesAndStatsVM chequesAndStatsVM) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); ChequeVM chequeVM = new ChequeVM(); switch (chequesAndStatsVM.change) { // وصول چک پرداختی case "PaidChequeReceipt": { chequesAndStatsVM.description = " وصول چک پرداختی"; var doucument = await CreateDocumentPaidChequeReceipt(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.Passed; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // وصول چک دریافتی case "ReceivedChequeReceipt": { chequesAndStatsVM.description = " وصول چک دریافتی"; var doucument = await CreateDocumentChangeChequeStatus(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.Passed; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // وصول چک واگذار شده به بانک case "DepositChequeReceipt": { chequesAndStatsVM.description = "وصول چک واگذار شده به بانک"; var doucument = await CreateDocumentDepositChequeReceipt(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.Passed; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // واگذاری چک به بانک case "ReceivedChequeDeposit": { chequesAndStatsVM.description = "واگذاری چک به بانک"; var doucument = await CreateDocumentReceivedChequeDeposit(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.InProgress; BankRule bankRule = new BankRule(); var banks = await bankRule.GetAllByOrganIdAsync(organId); var bank = banks.Where(x => x.Code == chequesAndStatsVM.detailAccount.Code).SingleOrDefault(); cheque.DepositBankId = bank.ID; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // عودت دادن چک پرداختی case "PaidChequeReturn": { //chequesAndStatsVM.description = "عودت دادن چک پرداختی"; var doucument = await CreateDocumentPaidChequeReturn(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.ChequeReturn; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // عودت دادن چک دریافتی case "ReceivedChequeReturn": { chequesAndStatsVM.description = "عودت دادن چک دریافتی"; var doucument = await CreateDocumentReceivedChequeReturn(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.ChequeReturn; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // تغییر وضعیت چک پرداختی به پاس نشده case "PaidChequeToNotPass": { chequesAndStatsVM.description = "تغییر وضعیت چک پرداختی به پاس نشده"; chequesAndStatsVM.date = PersianDateUtils.ToPersianDate(DateTime.Now); var doucument = await CreateDocumentPaidChequeToNotPass(chequesAndStatsVM, organId); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.Normal; chequeRule.Update(cheque); await chequeRule.SaveChangesAsync(); DocumentRule documentRule = new DocumentRule(); await documentRule.InsertAsync(doucument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } // تغییر وضعیت چک دریافتی به وصول نشده case "ReceivedChequeToNotPass": { chequesAndStatsVM.description = "تغییر وضعیت چک دریافتی به وصول نشده"; ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); PayRecevieRule payRecevieRule = new PayRecevieRule(); List <Document> doucuments = await payRecevieRule.GetDoucumentIDByChequeIdAsync(chequesAndStatsVM.chequeId); cheque.Status = ZhivarEnums.ChequeStatus.Normal; chequeRule.Update(cheque); Document newDocument = new Document(); DocumentRule documentRule = new DocumentRule(); foreach (var document in doucuments) { newDocument = new Document() { Credit = document.Credit, Description = chequesAndStatsVM.description, Debit = document.Debit, DateTime = DateTime.Now, DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now), FinanYear = document.FinanYear, FinanYearId = document.FinanYearId, IsFirsDocument = document.IsFirsDocument, IsManual = document.IsManual, Number = await documentRule.createNumberDocumentAsync(organId), Number2 = await documentRule.createNumberDocumentAsync(organId), OrganId = organId, Status = ZhivarEnums.DocumentStatus.TaeedShode, StatusString = document.StatusString, Type = ZhivarEnums.NoeDoc.Pay }; TransactionRule transactionRule = new TransactionRule(); var transactions = await transactionRule.GetAllByOrganIdAsync(organId); transactions = transactions.Where(x => x.DocumentId == document.ID).ToList(); newDocument.Transactions = new List <Transaction>(); Transaction newTransaction = new Transaction(); foreach (var transaction in transactions) { //newTransaction.AccDocument = newDocument; //newTransaction.Account = transaction.Account; newTransaction.AccountId = transaction.AccountId; newTransaction.Amount = transaction.Amount; newTransaction.Cheque = transaction.Cheque; newTransaction.ChequeId = transaction.ChequeId; newTransaction.ContactId = transaction.ContactId; newTransaction.Credit = transaction.Debit; newTransaction.Date = DateTime.Now; newTransaction.Debit = transaction.Credit; newTransaction.Description = chequesAndStatsVM.description; newTransaction.DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now); newTransaction.DocumentId = newDocument.ID; newTransaction.InvoiceId = transaction.InvoiceId; newTransaction.IsCredit = transaction.IsDebit; newTransaction.IsDebit = transaction.IsCredit; newTransaction.PaymentMethod = transaction.PaymentMethod; newTransaction.PaymentMethodString = transaction.PaymentMethodString; newTransaction.Reference = transaction.Reference; newTransaction.RefTrans = transaction.RefTrans; newTransaction.Remaining = transaction.Remaining; newTransaction.RemainingType = transaction.RemainingType; newTransaction.RowNumber = transaction.RowNumber; newTransaction.Stock = transaction.Stock; newTransaction.TransactionTypeString = transaction.TransactionTypeString; newTransaction.Type = transaction.Type; newTransaction.UnitPrice = transaction.UnitPrice; newDocument.Transactions.Add(newTransaction); } } await documentRule.InsertAsync(newDocument, organId); await documentRule.SaveChangesAsync(); //AccountNumber: "" chequeVM.Amount = cheque.Amount; chequeVM.BankBranch = cheque.BankBranch; //chequeVM.BankDetailAccount: null chequeVM.BankName = cheque.BankName; chequeVM.ChequeNumber = cheque.ChequeNumber; chequeVM.Contact = cheque.Contact; chequeVM.Date = cheque.Date; chequeVM.DepositBank = cheque.DepositBank; //chequeVM.DepositDate = cheque.DepositBank; chequeVM.DisplayDate = cheque.DisplayDate; chequeVM.ID = cheque.ID; //chequeVM.MyCheque = cheque.DepositBank; //chequeVM.Overdue = cheque.Overdue; //chequeVM.Payee = cheque.Payee; //chequeVM.Payer = cheque.Payer; chequeVM.ReceiptDate = cheque.ReceiptDate; //chequeVM.ReturnDate = cheque.ReturnDate; chequeVM.Status = cheque.Status; chequeVM.StatusString = "وصول شده"; break; } default: break; } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = chequeVM })); }
public async Task <HttpResponseMessage> loadCostData([FromBody] int id) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var resualt = new CostData(); List <ContactVM> contacts = new List <ContactVM>(); ContactRule contactRule = new ContactRule(); var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); contactsSource = contactsSource.ToList(); contacts = Mapper.Map <IList <Contact>, List <ContactVM> >(contactsSource); foreach (var contact in contacts) { contact.DetailAccount = new DetailAccount() { Code = contact.Code, Id = (int)contact.ID, Node = new Node() { FamilyTree = "اشخاص", Id = (int)contact.ID, Name = "اشخاص" } }; //var account1104 = await CalcAccountByCodeTafziliAsync(organId, "1104" + contact.Code); //var account1105 = await CalcAccountByCodeTafziliAsync(organId, "1105" + contact.Code); //var account2101 = await CalcAccountByCodeTafziliAsync(organId, "2101" + contact.Code); //contact.Balance = account1104.sumTotal + account1105.sumTotal + account2101.sumTotal; //contact.Credits = account1104.sumCredit + account1105.sumCredit + account2101.sumCredit; //contact.Liability = account1104.sumDebit + account1105.sumDebit + account2101.sumDebit; } resualt.contacts = contacts; resualt.costSettings = new InvoiceSettings() { allowApproveWithoutStock = false, autoAddTax = true, bottomMargin = "20", businessLogo = "", font = "Iransans", fontSize = "Medium", footerNote = "", footerNoteDraft = "", hideZeroItems = false, onlineInvoiceEnabled = false, pageSize = "A4portrait", payReceiptTitle = "رسید پرداخت وجه / چک", purchaseInvoiceTitle = "فاکتور خرید", receiveReceiptTitle = "رسید دریافت وجه / چک", rowPerPage = "18", saleDraftInvoiceTitle = "پیش فاکتور", saleInvoiceTitle = "صورتحساب فروش کالا و خدمات", showAmountInWords = false, showCustomerBalance = false, showItemUnit = false, showSignaturePlace = true, showTransactions = true, showVendorInfo = true, topMargin = "10", updateBuyPrice = false, updateSellPrice = false }; AccountRule accountRule = new AccountRule(); List <DomainClasses.Accounting.Account> accounts = await accountRule.GetAllByOrganIdAsync(organId); var parentAccount = accounts.Where(x => x.ComplteCoding == "8205").SingleOrDefault(); accounts = accounts.Where(x => x.ParentId == parentAccount.ID).ToList(); resualt.items = accounts; var CostItems = new List <CostItemVM>(); if (id == 0) { CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 0, Sum = 0, Rest = 0 }); CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 1, Sum = 0, Rest = 0 }); CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 2, Sum = 0, Rest = 0 }); CostItems.Add(new CostItemVM() { Description = "", ID = 0, RowNumber = 3, Sum = 0, Rest = 0 }); resualt.cost = new CostVM() { Contact = null, ContactTitle = "", DateTime = DateTime.Now, DisplayDate = PersianDateUtils.ToPersianDate(DateTime.Now), ID = 0, CostItems = CostItems, Number = await createNumberCost(organId), Paid = 0, Payable = 0, Rest = 0, Status = 0, Sum = 0, Explain = "" }; } else { CostRule costRule = new CostRule(); var cost = await costRule.FindAsync(id); foreach (var costItem in cost.CostItems ?? new List <CostItem>()) { CostItems.Add(new CostItemVM() { Description = costItem.Description, ID = costItem.ID, RowNumber = costItem.RowNumber, Sum = costItem.Sum, Rest = costItem.Rest, Item = accounts.Where(x => x.ID == costItem.ItemId).SingleOrDefault(), ItemId = costItem.ItemId }); } var contact = new Contact(); if (cost.ContactId > 0) { contact = await this.Rule.UnitOfWork.RepositoryAsync <Contact>().Queryable().Where(x => x.ID == cost.ContactId).SingleOrDefaultAsync2(); } resualt.cost = new CostVM() { Contact = Mapper.Map <Contact, ContactVM>(contact), ContactTitle = contact.Name, DateTime = cost.DateTime, DisplayDate = cost.DisplayDate, ID = cost.ID, CostItems = CostItems, Number = cost.Number, Paid = cost.Paid, Payable = cost.Payable, Rest = cost.Rest, Status = cost.Status, Sum = cost.Sum, Explain = cost.Explain }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); }
private async Task <Document> CreateDocumentChangeChequeStatus(ChequesAndStatsVM chequesAndStatsVM, int organId) { FinanYearRule finanYearRule = new FinanYearRule(); var finanYears = await finanYearRule.GetAllByOrganIdAsync(organId); var finanYear = finanYears.Where(x => x.Closed == false).SingleOrDefault(); ChequeRule chequeRule = new ChequeRule(); var cheque = await chequeRule.FindAsync(chequesAndStatsVM.chequeId); DocumentRule documentRule = new DocumentRule(); Document document = new Document(); document.Credit = cheque.Amount; document.DateTime = PersianDateUtils.ToDateTime(chequesAndStatsVM.date); document.Debit = cheque.Amount; document.Description = chequesAndStatsVM.description; document.DisplayDate = chequesAndStatsVM.date; document.IsManual = false; document.Status = ZhivarEnums.DocumentStatus.TaeedShode; document.Number = await documentRule.createNumberDocumentAsync(organId); document.Number2 = await documentRule.createNumberDocumentAsync(organId); document.StatusString = "تایید شده"; document.OrganId = organId; document.FinanYear = finanYear; document.FinanYearId = finanYear.ID; document.Type = ZhivarEnums.NoeDoc.Recive; List <Transaction> transactions = new List <Transaction>(); AccountRule accountRule = new AccountRule(); var accounts = await accountRule.GetAllByOrganIdAsync(organId); switch (chequesAndStatsVM.receiveType) { case "cash": { var accountCash = accounts.Where(x => x.ComplteCoding == "1101" + chequesAndStatsVM.detailAccount.Code).SingleOrDefault(); transactions.Add(new Transaction() { //AccDocument = document, AccountId = accountCash.ID, Amount = cheque.Amount, Description = chequesAndStatsVM.description, Credit = 0, Debit = cheque.Amount, IsCredit = false, IsDebit = true, DocumentId = document.ID, Date = PersianDateUtils.ToDateTime(chequesAndStatsVM.date), DisplayDate = chequesAndStatsVM.date }); break; } case "bank": { var accountBank = accounts.Where(x => x.ComplteCoding == "1103" + chequesAndStatsVM.detailAccount.Code).SingleOrDefault(); transactions.Add(new Transaction() { //AccDocument = document, AccountId = accountBank.ID, Amount = cheque.Amount, Description = chequesAndStatsVM.description, Credit = 0, Debit = cheque.Amount, IsCredit = false, IsDebit = true, DocumentId = document.ID, Date = PersianDateUtils.ToDateTime(chequesAndStatsVM.date), DisplayDate = chequesAndStatsVM.date }); break; } } var asnadDreaftaniAccount = accounts.Where(x => x.ComplteCoding == "1105" + cheque.Contact.Code).SingleOrDefault(); transactions.Add(new Transaction() { //AccDocument = document, AccountId = asnadDreaftaniAccount.ID, Amount = cheque.Amount, Credit = cheque.Amount, Debit = 0, Description = chequesAndStatsVM.description, DocumentId = document.ID, IsCredit = true, IsDebit = false, Date = PersianDateUtils.ToDateTime(chequesAndStatsVM.date), DisplayDate = chequesAndStatsVM.date }); document.Transactions = transactions; return(document); }
public async Task <HttpResponseMessage> loadReservationData([FromBody] loadReservationDataBusi reservationData) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var resualt = new ReservationData(); List <ContactVM> contacts = new List <ContactVM>(); ContactRule contactRule = new ContactRule(); var contactsSource = await contactRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); contactsSource = contactsSource.ToList(); contacts = TranslateHelper.TranslateEntityToEntityVMListContact(contactsSource); foreach (var contact in contacts) { contact.DetailAccount = new DetailAccount() { Code = contact.Code, Id = (int)contact.ID, Node = new Node() { FamilyTree = "اشخاص", Id = (int)contact.ID, Name = "اشخاص" } }; } resualt.contacts = contacts; NoeEjareRule noeEjareRule = new NoeEjareRule(); var noeEjares = await noeEjareRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); resualt.noeEjares = noeEjares; GoroheSazeRule goroheSazeRule = new GoroheSazeRule(); var itemGroups = await goroheSazeRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); var items = new List <SazeVM>(); var item = new SazeVM(); foreach (var itemGroup in itemGroups) { foreach (var KalaKhadmat in itemGroup.Items) { item = new SazeVM() { DetailAccount = new DetailAccount() { Code = KalaKhadmat.Code, Id = KalaKhadmat.ID, Node = new Node() { FamilyTree = itemGroup.Title, Name = itemGroup.Title, Id = itemGroup.ID } }, Code = KalaKhadmat.Code, OrganId = KalaKhadmat.OrganId, Address = KalaKhadmat.Address, Arz = KalaKhadmat.Arz, GoroheSazeID = KalaKhadmat.GoroheSazeID, ID = KalaKhadmat.ID, Title = KalaKhadmat.Title, Tol = KalaKhadmat.Tol, NoeSazeId = KalaKhadmat.NoeSazeId, NoeEjare = KalaKhadmat.NoeEjare, GoroheName = KalaKhadmat.GoroheName, NoeEjareName = KalaKhadmat.NoeEjareName, NoeSazeName = KalaKhadmat.NoeSazeName, Latitude = KalaKhadmat.Latitude, Longitude = KalaKhadmat.Longitude, NoorDard = KalaKhadmat.NoorDard, NoeEjareID = KalaKhadmat.NoeEjareID, }; items.Add(item); } } resualt.items = items; var Reservation_DetailVMs = new List <Reservation_DetailVM>(); var reservation_DetailVM = new List <Reservation_DetailVM>(); if (reservationData.id == 0) { var countRes = 0; if (reservationData.lstSaze != null && reservationData.lstSaze.Count > 0) { reservationData.lstSaze = reservationData.lstSaze.Where(x => x.sazeID != 0).ToList(); foreach (var lstSaze in reservationData.lstSaze) { var saze = Mapper.Map <Saze, SazeVM>(this.BusinessRule.UnitOfWork.Repository <Saze>().Find(lstSaze.sazeID)); var startDate = DateTime.Now; var displayStartDate = PersianDateUtils.ToPersianDateTime(DateTime.Now); bool minValue = false; bool maxValue = false; if (!string.IsNullOrEmpty(lstSaze.minDate) && !string.IsNullOrWhiteSpace(lstSaze.minDate)) { startDate = PersianDateUtils.ToDateTime(lstSaze.minDate); displayStartDate = lstSaze.minDate; minValue = true; } var endDate = DateTime.Now; var displayEndDate = PersianDateUtils.ToPersianDateTime(DateTime.Now); if (!string.IsNullOrEmpty(lstSaze.maxDate) && !string.IsNullOrWhiteSpace(lstSaze.maxDate)) { endDate = PersianDateUtils.ToDateTime(lstSaze.maxDate); displayStartDate = lstSaze.maxDate; maxValue = true; } var quantity = 0; if (minValue && maxValue) { var diff = endDate - startDate; var days = diff.TotalDays; quantity = Convert.ToInt32(days); } Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = quantity, Saze = saze, SazeID = saze.ID, NoeEjare = Mapper.Map <NoeEjare, NoeEjareVM>(this.BusinessRule.UnitOfWork.Repository <NoeEjare>().Find(saze.NoeEjareID)), NoeEjareID = saze.NoeEjareID, RowNumber = 0, StartDate = startDate, StartDisplayDate = displayStartDate, //EndDate = endDate, //EndDisplayDate = lstSaze.maxDate, }); countRes += 1; } if (countRes < 3) { for (int i = 0; i < 3 - countRes; i++) { Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, Saze = null, SazeID = 0, NoeEjare = null, NoeEjareID = 0, RowNumber = countRes + i, //StartDate = startDate, StartDisplayDate = "", //EndDate = endDate, //EndDisplayDate = lstSaze.maxDate, }); } } } else { Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 0 }); Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 1 }); Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 2 }); Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = 0, Quantity = 0, RowNumber = 3 }); } resualt.Reservation = new ReservationVM() { //Contact = Mapper.Map<Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository<Contact>().Find(reservation.ContactID)), ID = 0, DisplayRegisterDate = Utilities.PersianDateUtils.ToPersianDateTime(DateTime.Now), // ContactID = reservation.ContactID, OrganID = organId, RegisterDate = DateTime.Now, ReservationDetails = Reservation_DetailVMs }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } else { var reservation = await Rule.FindAsync(reservationData.id); foreach (var reservationDetail in reservation.ReservationDetails ?? new List <Reservation_Detail>()) { Reservation_DetailVMs.Add(new Reservation_DetailVM() { ID = reservationDetail.ID, Saze = Mapper.Map <Saze, SazeVM>(this.BusinessRule.UnitOfWork.Repository <Saze>().Find(reservationDetail.SazeID)), SazeID = reservationDetail.SazeID, Quantity = reservationDetail.Quantity, NoeEjare = Mapper.Map <NoeEjare, NoeEjareVM>(this.BusinessRule.UnitOfWork.Repository <NoeEjare>().Find(reservationDetail.NoeEjareID)), NoeEjareID = reservationDetail.NoeEjareID, EndDate = reservationDetail.EndDate, EndDisplayDate = reservationDetail.EndDisplayDate, ReservationID = reservationDetail.ReservationID, StartDate = reservationDetail.StartDate, StartDisplayDate = reservationDetail.StartDisplayDate, UnitPrice = reservationDetail.UnitPrice, PriceBazareab = reservationDetail.PriceBazareab, PriceTarah = reservationDetail.PriceTarah, PriceChap = reservationDetail.PriceChap, PriceNasab = reservationDetail.PriceNasab, RowNumber = reservationDetail.RowNumber }); } resualt.Reservation = new ReservationVM() { Contact = Mapper.Map <Contact, ContactVM>(this.BusinessRule.UnitOfWork.Repository <Contact>().Find(reservation.ContactID)), ID = reservation.ID, DisplayRegisterDate = reservation.DisplayRegisterDate, ContactID = reservation.ContactID, OrganID = reservation.OrganID, RegisterDate = reservation.RegisterDate, ValiditDuration = reservation.ValiditDuration, ReservationDetails = Reservation_DetailVMs }; return(Request.CreateResponse(HttpStatusCode.OK, new { resualtCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } } catch (Exception ex) { throw; } }