public virtual async Task <HttpResponseMessage> GetCashesAndBanks() { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); BankRule bankRule = new BankRule(); var banks = await bankRule.GetAllByOrganIdAsync(organId); CashRule cashRule = new CashRule(); var cashs = await cashRule.GetAllByOrganIdAsync(organId); var cashes = new Cashe(); cashes.banks = new List <BankVM>(); cashes.cashes = new List <CashVM>(); foreach (var bank in banks) { decimal balance = await CalcBalanceBank(bank.Code, organId); cashes.banks.Add(new BankVM() { AccountNumber = bank.AccountNumber, Balance = balance, Branch = bank.Branch, Code = bank.Code, FullName = bank.FullName, ID = bank.ID, Name = bank.Name, OrganId = bank.OrganId, //Id = bank.ID, DetailAccount = new DetailAccount() { Accounts = new List <AccountVM>(), Balance = bank.Balance, Name = bank.Name, Node = new Node(), } }); } foreach (var cash in cashs) { decimal balance = await CalcBalanceCash(cash.Code, organId); cashes.cashes.Add(new CashVM() { Balance = balance, Code = cash.Code, ID = cash.ID, Name = cash.Name, OrganId = cash.OrganId, //DetailAccount = new DetailAccount() { // Balance = cash.Balance, // Name = cash.Name, // Node = new Node() //} }); } return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = cashes })); }
public async Task <HttpResponseMessage> LoadInvoiceTransObj([FromBody] int id) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var invoice = await Rule.FindAsync(id); InvoiceTransObj invoiceTransObj = new InvoiceTransObj(); invoiceTransObj.invoice = Mapper.Map <InvoiceVM>(invoice); invoiceTransObj.invoiceItems = invoiceTransObj.invoice.InvoiceItems; //invoiceTransObj.payments = await transactionRule.GetAllByInvoiceIdAsync(id,true,false); PayRecevieRule payRecevieRule = new PayRecevieRule(); invoiceTransObj.tempPayments = await payRecevieRule.GetTempPaymentsByInvoiceIdAsync(id); for (int i = 0; i < invoiceTransObj.invoiceItems.Count; i++) { ItemRule itemRule = new ItemRule(); invoiceTransObj.invoiceItems[i].Item = Mapper.Map <ItemVM>(await itemRule.FindAsync(invoiceTransObj.invoiceItems[i].ItemId)); } ContactRule contactRule = new ContactRule(); invoiceTransObj.invoice.Contact = Mapper.Map <ContactVM>(await contactRule.FindAsync(invoice.ContactId)); CashRule cashRule = new CashRule(); var cashes = await cashRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); invoiceTransObj.cashes = Mapper.Map <List <CashVM> >(cashes); BankRule bankRule = new BankRule(); var banks = await bankRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); invoiceTransObj.banks = Mapper.Map <List <BankVM> >(banks); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = invoiceTransObj })); } catch (Exception ex) { throw; } }
public async Task <HttpResponseMessage> LoadCostTransObj([FromBody] int id) { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); var cost = await Rule.FindAsync(id); CostTransObj costTransObj = new CostTransObj(); costTransObj.cost = Mapper.Map <CostVM>(cost); costTransObj.costItems = costTransObj.cost.CostItems; TransactionRule transactionRule = new TransactionRule(); costTransObj.payments = await transactionRule.GetAllByCostIdAsync(id); for (int i = 0; i < costTransObj.costItems.Count; i++) { costTransObj.costItems[i].Item = await this.BusinessRule.UnitOfWork.RepositoryAsync <DomainClasses.Accounting.Account>().FindAsync(costTransObj.costItems[i].ItemId); } ContactRule contactRule = new ContactRule(); costTransObj.cost.Contact = Mapper.Map <ContactVM>(await contactRule.FindAsync(cost.ContactId)); CashRule cashRule = new CashRule(); var cashes = await cashRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); costTransObj.cashes = Mapper.Map <List <CashVM> >(cashes); BankRule bankRule = new BankRule(); var banks = await bankRule.GetAllByOrganIdAsync(Convert.ToInt32(organId)); costTransObj.banks = Mapper.Map <List <BankVM> >(banks); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = ZhivarEnums.ResultCode.Successful, data = costTransObj })); } catch (Exception ex) { throw; } }
public async Task <HttpResponseMessage> LoadReceiveAndPay([FromBody] int id) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); FinanYearRule finanYearRule = new FinanYearRule(); var finanYerar = await finanYearRule.GetCurrentFinanYear(organId); var payRecevie = await Rule.FindAsync(id); ReceiveAndPayVM receiveAndPayVM = new ReceiveAndPayVM(); //var account = await accountRule.FindAsync((int)payRecevie.AccountId); //receiveAndPayVM.Account = account; receiveAndPayVM.Amount = payRecevie.Amount; receiveAndPayVM.Contact = payRecevie.Contact; receiveAndPayVM.Description = payRecevie.Description; //receiveAndPayVM.DetailAccount = payRecevie.de receiveAndPayVM.DisplayDate = payRecevie.DisplayDate; receiveAndPayVM.Id = payRecevie.ID; receiveAndPayVM.Invoice = payRecevie.Invoice; receiveAndPayVM.Items = payRecevie.Items.ToList(); receiveAndPayVM.Number = payRecevie.Document.Number; receiveAndPayVM.Number2 = payRecevie.Document.Number2; //receiveAndPayVM.PayItems = payRecevie.pa receiveAndPayVM.Type = payRecevie.Type; if (payRecevie.Contact != null) { payRecevie.ContactId = payRecevie.Contact.ID; } if (payRecevie.Invoice != null) { payRecevie.InvoiceId = payRecevie.Invoice.ID; } decimal amount = 0; foreach (var item in payRecevie.Items) { amount += item.Amount; if (item.CashId > 0) { CashRule cashRule = new CashRule(); item.Cash = await cashRule.FindAsync((int)item.CashId); } else if (item.Bank != null) { item.BankId = item.Bank.ID; } else if (item.Cheque != null) { 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 = DateTime.Now,// item.Cheque.Date, OrganId = organId, Status = ZhivarEnums.ChequeStatus.Normal, DisplayDate = item.Cheque.DisplayDate, Type = ZhivarEnums.ChequeType.Pardakhtani, ReceiptDate = DateTime.Now, }; item.Cheque = cheque; item.ChequeId = item.Cheque.ID; } } payRecevie.Amount = amount; if (payRecevie.Contact != null) { var account1104 = await CalcAccountByCodeTafziliAsync(organId, "1104" + payRecevie.Contact.Code); var account1105 = await CalcAccountByCodeTafziliAsync(organId, "1105" + payRecevie.Contact.Code); var account2101 = await CalcAccountByCodeTafziliAsync(organId, "2101" + payRecevie.Contact.Code); payRecevie.Contact.Balance = account1104.sumTotal + account1105.sumTotal + account2101.sumTotal - amount; payRecevie.Contact.Credits = account1104.sumCredit + account1105.sumCredit + account2101.sumCredit - amount; payRecevie.Contact.Liability = account1104.sumDebit + account1105.sumDebit + account2101.sumDebit; } //if (payRecevie.Invoice != null) //{ // if (payRecevie.Invoice.Contact != null) // payRecevie.Invoice.ContactId = payRecevie.Invoice.Contact.ID; // //payRecevie.Invoice.FinanYear = finanYerar; // //payRecevie.Invoice.FinanYearId = finanYerar.ID; // var invoice = payRecevie.Invoice; // invoice.Rest -= amount; // invoice.Paid += amount; // invoiceRule.Update(invoice); //} return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = payRecevie })); }