public void ClearTempTransaction(PharmaBusinessObjects.Transaction.TransactionEntity entity) { try { using (PharmaDBEntities context = new PharmaDBEntities()) { using (var transaction = context.Database.BeginTransaction()) { try { var tempAdjustments = context.TempBillOutStandingsAudjustment.Where(x => x.ReceiptPaymentID == entity.ReceiptPaymentID).ToList(); ///Rollback all amount deducted amount from OS amount from Bill outstanding /// foreach (var tempAdj in tempAdjustments) { if (tempAdj.TempReceiptPayment.OldReceiptPaymentID != null) { var billOutStanding = context.BillOutStandings.Where(p => p.BillOutStandingsID == tempAdj.TempReceiptPayment.OldReceiptPaymentID).FirstOrDefault(); if (billOutStanding != null) { billOutStanding.OSAmount = tempAdj.BillOutStandings.BillAmount - tempAdj.Amount; } // tempAdj.BillOutStandings.OSAmount = tempAdj.BillOutStandings.BillAmount - tempAdj.Amount; } else { tempAdj.BillOutStandings.OSAmount += tempAdj.Amount; } } context.TempBillOutStandingsAudjustment.RemoveRange(tempAdjustments); var tempReceipt = context.TempReceiptPayment.Where(x => x.ReceiptPaymentID == entity.ReceiptPaymentID).ToList(); context.TempReceiptPayment.RemoveRange(tempReceipt); context.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } } } catch (Exception ex) { throw ex; } }
public void ClearTempBillAdjustment(PharmaBusinessObjects.Transaction.TransactionEntity entity) { try { using (PharmaDBEntities context = new PharmaDBEntities()) { var tempBillAdjustmentForEntity = context.TempBillOutStandingsAudjustment.Where(q => q.ReceiptPaymentID == entity.ReceiptPaymentID && q.LedgerTypeCode == entity.EntityCode) .Select(q => q).ToList(); ///Rollback all amount deducted amount from OS amount from Bill outstanding /// foreach (var tempAdj in tempBillAdjustmentForEntity) { if (tempAdj.TempReceiptPayment.OldReceiptPaymentID != null) { var billOutStanding = context.BillOutStandings.Where(p => p.BillOutStandingsID == tempAdj.TempReceiptPayment.OldReceiptPaymentID).FirstOrDefault(); if (billOutStanding != null) { billOutStanding.OSAmount = tempAdj.BillOutStandings.BillAmount - tempAdj.Amount; } // tempAdj.BillOutStandings.OSAmount = tempAdj.BillOutStandings.BillAmount - tempAdj.Amount; } else { tempAdj.BillOutStandings.OSAmount += tempAdj.Amount; } } context.TempBillOutStandingsAudjustment.RemoveRange(tempBillAdjustmentForEntity); context.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public List <PharmaBusinessObjects.Transaction.ReceiptPayment.BillAdjusted> GetAllInitialBillAdjustmentForLedger(PharmaBusinessObjects.Transaction.TransactionEntity entity) { try { using (PharmaDBEntities context = new PharmaDBEntities()) { return(context.BillOutStandings.Where(q => q.LedgerType == entity.EntityType && q.LedgerTypeCode == entity.EntityCode && q.PurchaseSaleBookHeaderID != null ).OrderBy(x => x.BillOutStandingsID) .Select(p => new PharmaBusinessObjects.Transaction.ReceiptPayment.BillAdjusted() { BillOutStandingsID = p.BillOutStandingsID, PurchaseSaleBookHeaderID = p.PurchaseSaleBookHeaderID, VoucherNumber = p.VoucherNumber, VoucherTypeCode = p.VoucherTypeCode, VoucherDate = p.VoucherDate, InvoiceNumber = p.VoucherTypeCode == Constants.LedgerType.SupplierLedger ? p.PurchaseSaleBookHeader.PurchaseBillNo : p.VoucherNumber, InvoiceDate = p.PurchaseSaleBookHeader.VoucherDate, LedgerType = p.LedgerType, LedgerTypeCode = p.LedgerTypeCode, Amount = context.TempBillOutStandingsAudjustment.Where(x => x.ReceiptPaymentID == entity.ReceiptPaymentID && x.BillOutStandingsID == p.BillOutStandingsID).Select(x => x.Amount).FirstOrDefault(), OSAmount = p.OSAmount + context.TempBillOutStandingsAudjustment.Where(x => x.ReceiptPaymentID == entity.ReceiptPaymentID && x.BillOutStandingsID == p.BillOutStandingsID).Select(x => x.Amount).FirstOrDefault(), }).ToList()); } } catch (DbEntityValidationException ex) { throw ex; } catch (Exception ex) { throw ex; } }
public List <PharmaBusinessObjects.Transaction.ReceiptPayment.BillOutstanding> GetAllBillOutstandingForLedger(PharmaBusinessObjects.Transaction.TransactionEntity entity) { try { using (PharmaDBEntities context = new PharmaDBEntities()) { return(context.BillOutStandings.Where(q => q.LedgerType == entity.EntityType && q.LedgerTypeCode == entity.EntityCode && q.OSAmount != 0 && q.PurchaseSaleBookHeaderID != null) .OrderBy(x => x.BillOutStandingsID) .Select(p => new PharmaBusinessObjects.Transaction.ReceiptPayment.BillOutstanding() { BillOutStandingsID = p.BillOutStandingsID, PurchaseSaleBookHeaderID = (long)p.PurchaseSaleBookHeaderID, VoucherNumber = p.VoucherNumber, VoucherTypeCode = p.VoucherTypeCode, VoucherDate = p.VoucherDate, InvoiceNumber = p.VoucherTypeCode == Constants.LedgerType.SupplierLedger ? p.PurchaseSaleBookHeader.PurchaseBillNo : p.VoucherNumber, InvoiceDate = p.PurchaseSaleBookHeader.VoucherDate, LedgerType = p.LedgerType, LedgerTypeCode = p.LedgerTypeCode, BillAmount = p.BillAmount, OSAmount = p.OSAmount, IsHold = p.IsHold, HOLDRemarks = p.HOLDRemarks }).ToList()); } } catch (DbEntityValidationException ex) { throw ex; } catch (Exception ex) { throw ex; } }