Beispiel #1
0
        public bool SavePayment(PaymentVM paymentVM, int userID)
        {
            using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction())
            {
                try
                {
                    //Save Payment
                    tblPayment payment = new tblPayment();
                    payment.ClientID      = paymentVM.ClientID;
                    payment.PaymentAmount = paymentVM.PaymentAmount;
                    payment.CreatedBy     = userID;
                    payment.CreatedDate   = DateTime.Now;

                    unitOfWork.TblPaymentRepository.Insert(payment);
                    unitOfWork.Save();

                    //Save Debit Note
                    foreach (var debitNoteVM in paymentVM.DebitNoteList)
                    {
                        tblDebitNote debitNote = new tblDebitNote();
                        debitNote.TotalNonCommissionPremium = debitNoteVM.TotalNonCommissionPremium;
                        debitNote.TotalGrossPremium         = debitNoteVM.TotalGrossPremium;
                        debitNote.CreatedBy   = userID;
                        debitNote.CreatedDate = DateTime.Now;
                        unitOfWork.TblDebitNoteRepository.Insert(debitNote);
                        unitOfWork.Save();


                        //Save Policy Info Payments
                        foreach (var policyInfoPaymentVM in debitNoteVM.PolicyInfoPaymentLists)
                        {
                            tblBankTransactionDetail Bank = new tblBankTransactionDetail();
                            Bank.BankID          = policyInfoPaymentVM.BankID;
                            Bank.DraftNo         = policyInfoPaymentVM.DraftNo;
                            Bank.PaymentID       = policyInfoPaymentVM.PaymentMethodID;
                            Bank.Amount          = policyInfoPaymentVM.BankAmount;
                            Bank.AgentID         = policyInfoPaymentVM.AgentID;
                            Bank.AgentAmount     = policyInfoPaymentVM.AgentAmount;
                            Bank.ClientID        = paymentVM.ClientID;
                            Bank.PolicyInfoRecID = debitNoteVM.PolicyInfoRecID;
                            Bank.currencyType    = policyInfoPaymentVM.currencyType;
                            Bank.ExchangeRate    = policyInfoPaymentVM.ExchangeRate;
                            Bank.PaymentDate     = !string.IsNullOrEmpty(policyInfoPaymentVM.PaymentDate) ? DateTime.ParseExact(policyInfoPaymentVM.PaymentDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null;
                            //   Bank.IBSAmount = policyInfoPaymentVM.SGSAmount;
                            Bank.RequestDate = !string.IsNullOrEmpty(policyInfoPaymentVM.RequestDate) ? DateTime.ParseExact(policyInfoPaymentVM.RequestDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null;
                            unitOfWork.TblBankTransactionDetailRepository.Insert(Bank);
                            unitOfWork.Save();

                            tblPolicyInfoPayment policyInfoPayment = new tblPolicyInfoPayment();
                            policyInfoPayment.PolicyInfoRecID      = debitNoteVM.PolicyInfoRecID;
                            policyInfoPayment.NonCommissionPremium = debitNoteVM.TotalNonCommissionPremium;
                            policyInfoPayment.GrossPremium         = policyInfoPaymentVM.BankAmount;
                            policyInfoPayment.CreatedBy            = userID;
                            policyInfoPayment.CreatedDate          = DateTime.Now;
                            unitOfWork.TblPolicyInfoPaymentRepository.Insert(policyInfoPayment);
                            unitOfWork.Save();

                            //foreach (var policyInfoPaymentObj in debitNoteVM.PolicyInfoPaymentList)
                            //{
                            tblPolicyDebitNote policyDebitNote = new tblPolicyDebitNote();
                            policyDebitNote.PolicyInfoPaymentID = policyInfoPayment.PolicyInfoPaymentID;
                            policyDebitNote.DebitNoteID         = debitNote.DebitNoteID;
                            policyDebitNote.PaymentID           = payment.PaymentID;
                            unitOfWork.TblPolicyDebitNoteRepository.Insert(policyDebitNote);
                            unitOfWork.Save();
                            //  }

                            //   policyInfoPaymentVM.PolicyInfoPaymentID = policyInfoPayment.PolicyInfoPaymentID;

                            //Save Policy Info Charges
                            //foreach (var policyInfoChargeVM in policyInfoPaymentVM.PolicyInfoChargeList)
                            //{
                            //    tblPolicyInfoCharge policyInfoCharge = new tblPolicyInfoCharge();
                            //    policyInfoCharge.PolicyInfoPaymentID = policyInfoPaymentVM.PolicyInfoRecID;
                            //    policyInfoCharge.ChargeTypeID = policyInfoChargeVM.ChargeTypeID;
                            //    policyInfoCharge.Amount = policyInfoChargeVM.Amount;
                            //    policyInfoCharge.IsCR = policyInfoChargeVM.IsCR;
                            //    policyInfoCharge.CreatedBy = userID;
                            //    policyInfoCharge.CreatedDate = DateTime.Now;
                            //    unitOfWork.TblPolicyInfoChargeRepository.Insert(policyInfoCharge);
                            //    unitOfWork.Save();
                            //}
                            //}

                            //Save Policy Info Payment - Debit Note
                        }
                    }

                    //Complete the Transaction
                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Roll back the Transaction
                    dbTransaction.Rollback();
                    return(false);
                }
            }
        }
        //End By Alam

        //Debit Note
        public static DebitNoteModel ToModel(this tblDebitNote entity)
        {
            return(Mapper.Map <tblDebitNote, DebitNoteModel>(entity));
        }
Beispiel #3
0
        public bool UpdatePayment(PaymentVM paymentVM, int userID)
        {
            using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction())
            {
                try
                {
                    //Update Payment
                    tblPayment payment = unitOfWork.TblPaymentRepository.GetByID(paymentVM.PaymentID);
                    payment.ClientID      = paymentVM.ClientID;
                    payment.PaymentAmount = paymentVM.PaymentAmount;
                    payment.ModifiedBy    = userID;
                    payment.ModifiedDate  = DateTime.Now;
                    unitOfWork.TblPaymentRepository.Update(payment);
                    unitOfWork.Save();

                    List <tblPolicyDebitNote> policyDebitNoteList = unitOfWork.TblPolicyDebitNoteRepository.Get(x => x.PaymentID == payment.PaymentID).ToList();
                    List <int> debitNoteList         = policyDebitNoteList.GroupBy(x => x.DebitNoteID).Select(x => x.FirstOrDefault()).Select(x => (int)x.DebitNoteID).ToList();
                    List <int> policyInfoPaymentList = policyDebitNoteList.GroupBy(x => x.PolicyInfoPaymentID).Select(x => x.FirstOrDefault()).Select(x => (int)x.PolicyInfoPaymentID).ToList();

                    //Delete Existing Policy Debit Note Details
                    foreach (var policyDebitNote in policyDebitNoteList)
                    {
                        unitOfWork.TblPolicyDebitNoteRepository.Delete(policyDebitNote.PolicyDebitNoteID);
                        unitOfWork.Save();
                    }

                    //Delete Existing Debit Note Details
                    foreach (var debitNote in debitNoteList)
                    {
                        unitOfWork.TblDebitNoteRepository.Delete(debitNote);
                        unitOfWork.Save();
                    }

                    //Delete Policy Info Payment and Policy Info Charge Details
                    foreach (var policyInfoPayment in policyInfoPaymentList)
                    {
                        List <tblPolicyInfoCharge> policyInfoChargeList = unitOfWork.TblPolicyInfoChargeRepository.Get(x => x.PolicyInfoPaymentID == policyInfoPayment).ToList();

                        foreach (var policyInfoCharge in policyInfoChargeList)
                        {
                            unitOfWork.TblPolicyInfoChargeRepository.Delete(policyInfoCharge);
                            unitOfWork.Save();
                        }

                        unitOfWork.TblPolicyInfoPaymentRepository.Delete(policyInfoPayment);
                        unitOfWork.Save();
                    }

                    //Save Debit Note
                    foreach (var debitNoteVM in paymentVM.DebitNoteList)
                    {
                        tblDebitNote debitNote = new tblDebitNote();
                        debitNote.TotalNonCommissionPremium = debitNoteVM.TotalNonCommissionPremium;
                        debitNote.TotalGrossPremium         = debitNoteVM.TotalGrossPremium;
                        debitNote.CreatedBy    = payment.CreatedBy;
                        debitNote.CreatedDate  = payment.CreatedDate;
                        debitNote.ModifiedBy   = userID;
                        debitNote.ModifiedDate = DateTime.Now;
                        unitOfWork.TblDebitNoteRepository.Insert(debitNote);
                        unitOfWork.Save();

                        //Save Policy Info Payments
                        //foreach (var policyInfoPaymentVM in debitNoteVM.PolicyInfoPaymentList)
                        //{
                        //    tblPolicyInfoPayment policyInfoPayment = new tblPolicyInfoPayment();
                        //    policyInfoPayment.PolicyInfoRecID = policyInfoPaymentVM.PolicyInfoRecID;
                        //    unitOfWork.TblBankTransactionDetailRepository.Delete(policyInfoPayment.PolicyInfoRecID);
                        //    unitOfWork.Save();
                        //    policyInfoPayment.NonCommissionPremium = policyInfoPaymentVM.NonCommissionPremium;
                        //    policyInfoPayment.GrossPremium = policyInfoPaymentVM.GrossPremium;
                        //    policyInfoPayment.CreatedBy = payment.CreatedBy;
                        //    policyInfoPayment.CreatedDate = payment.CreatedDate;
                        //    policyInfoPayment.ModifiedBy = userID;
                        //    policyInfoPayment.ModifiedDate = DateTime.Now;
                        //    unitOfWork.TblPolicyInfoPaymentRepository.Insert(policyInfoPayment);
                        //    unitOfWork.Save();

                        //    policyInfoPaymentVM.PolicyInfoPaymentID = policyInfoPayment.PolicyInfoPaymentID;
                        List <tblBankTransactionDetail> BankTransactionDetailList = unitOfWork.TblBankTransactionDetailRepository.Get(x => x.PolicyInfoRecID == debitNoteVM.PolicyInfoRecID).ToList();
                        foreach (var BankTransactionDetail in BankTransactionDetailList)
                        {
                            unitOfWork.TblBankTransactionDetailRepository.Delete(BankTransactionDetail);
                            unitOfWork.Save();
                        }


                        foreach (var policyInfoPaymentVMs in debitNoteVM.PolicyInfoPaymentLists)
                        {
                            tblBankTransactionDetail Bank = new tblBankTransactionDetail();
                            Bank.BankID          = policyInfoPaymentVMs.BankID;
                            Bank.DraftNo         = policyInfoPaymentVMs.DraftNo;
                            Bank.PaymentID       = policyInfoPaymentVMs.PaymentMethodID;
                            Bank.Amount          = policyInfoPaymentVMs.BankAmount;
                            Bank.AgentID         = policyInfoPaymentVMs.AgentID;
                            Bank.AgentAmount     = policyInfoPaymentVMs.AgentAmount;
                            Bank.ClientID        = paymentVM.ClientID;
                            Bank.PolicyInfoRecID = policyInfoPaymentVMs.PolicyInfoRecID;
                            Bank.PolicyInfoRecID = debitNoteVM.PolicyInfoRecID;
                            //   Bank.IBSAmount = policyInfoPaymentVM.SGSAmount;
                            Bank.RequestDate = !string.IsNullOrEmpty(policyInfoPaymentVMs.RequestDate) ? DateTime.ParseExact(policyInfoPaymentVMs.RequestDate, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null;
                            unitOfWork.TblBankTransactionDetailRepository.Insert(Bank);
                            unitOfWork.Save();
                            tblPolicyInfoPayment policyInfoPayment = new tblPolicyInfoPayment();
                            policyInfoPayment.PolicyInfoRecID      = policyInfoPaymentVMs.PolicyInfoRecID;
                            policyInfoPayment.NonCommissionPremium = debitNoteVM.TotalNonCommissionPremium;
                            policyInfoPayment.GrossPremium         = policyInfoPaymentVMs.BankAmount;
                            policyInfoPayment.CreatedBy            = userID;
                            policyInfoPayment.CreatedDate          = DateTime.Now;
                            unitOfWork.TblPolicyInfoPaymentRepository.Insert(policyInfoPayment);
                            unitOfWork.Save();

                            //foreach (var policyInfoPaymentObj in debitNoteVM.PolicyInfoPaymentList)
                            //{
                            tblPolicyDebitNote policyDebitNote = new tblPolicyDebitNote();
                            policyDebitNote.PolicyInfoPaymentID = policyInfoPayment.PolicyInfoPaymentID;
                            policyDebitNote.DebitNoteID         = debitNote.DebitNoteID;
                            policyDebitNote.PaymentID           = payment.PaymentID;
                            unitOfWork.TblPolicyDebitNoteRepository.Insert(policyDebitNote);
                            unitOfWork.Save();
                            //}
                        }
                        //Save Policy Info Charges
                        //    foreach (var policyInfoChargeVM in policyInfoPaymentVM.PolicyInfoChargeList)
                        //{
                        //    tblPolicyInfoCharge policyInfoCharge = new tblPolicyInfoCharge();
                        //    policyInfoCharge.PolicyInfoPaymentID = policyInfoPaymentVM.PolicyInfoRecID;
                        //    policyInfoCharge.ChargeTypeID = policyInfoChargeVM.ChargeTypeID;
                        //    policyInfoCharge.Amount = policyInfoChargeVM.Amount;
                        //    policyInfoCharge.IsCR = policyInfoChargeVM.IsCR;
                        //    policyInfoCharge.CreatedBy = payment.CreatedBy;
                        //    policyInfoCharge.CreatedDate = payment.CreatedDate;
                        //    policyInfoCharge.ModifiedBy = userID;
                        //    policyInfoCharge.ModifiedDate = DateTime.Now;
                        //    unitOfWork.TblPolicyInfoChargeRepository.Insert(policyInfoCharge);
                        //    unitOfWork.Save();
                        //}
                        // }

                        //Save Policy Info Payment - Debit Note
                    }

                    //Complete the Transaction
                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Roll back the Transaction
                    dbTransaction.Rollback();
                    return(false);
                }
            }
        }
Beispiel #4
0
        public int Update(EntityDebitNote lstEdited, List <EntityDebitNoteDetails> lst)
        {
            int i = 0;

            try
            {
                tblDebitNote objTest = (from tbl in objData.tblDebitNotes
                                        where tbl.IsDelete == false &&
                                        tbl.DNNo == lstEdited.DNNo
                                        select tbl).FirstOrDefault();

                if (objTest != null)
                {
                    objTest.Amount     = lstEdited.Amount;
                    objTest.NetAmount  = lstEdited.NetAmount;
                    objTest.SupplierId = lstEdited.SupplierId;
                    objTest.DNDate     = lstEdited.DNDate;
                    objTest.Discount   = lstEdited.Discount;
                    objTest.Tax1       = lstEdited.Tax1;
                    objTest.Tax2       = lstEdited.Tax2;
                }
                foreach (EntityDebitNoteDetails item in lst)
                {
                    if (item.DNSrNo == 0)
                    {
                        tblDebitNoteDetail objNewAdded = new tblDebitNoteDetail()
                        {
                            DNNo        = lstEdited.DNNo,
                            ProductCode = item.ProductCode,
                            Quantity    = item.Quantity,
                            Price       = item.Price,
                            Amount      = item.Amount,
                            BatchNo     = item.BatchNo,
                            ExpiryDate  = item.ExpiryDate,
                            IsDelete    = false
                        };
                        objData.tblDebitNoteDetails.InsertOnSubmit(objNewAdded);
                        tblStockDetail stock = new tblStockDetail()
                        {
                            ProductId       = Convert.ToInt32(item.ProductCode),
                            OpeningQty      = 0,
                            InwardQty       = 0,
                            InwardPrice     = 0,
                            InwardAmount    = 0,
                            BatchNo         = item.BatchNo,
                            ExpiryDate      = item.ExpiryDate,
                            OutwardQty      = item.Quantity,
                            OutwardPrice    = item.Price,
                            OutwardAmount   = item.Amount,
                            TransactionType = "DebitNote",
                            IsDelete        = false,
                        };
                        objData.tblStockDetails.InsertOnSubmit(stock);
                    }
                    else
                    {
                        tblDebitNoteDetail cnt = (from tbl in objData.tblDebitNoteDetails
                                                  where tbl.IsDelete == false &&
                                                  tbl.DNSrNo == item.DNSrNo
                                                  select tbl).FirstOrDefault();
                        if (cnt != null)
                        {
                            cnt.BatchNo     = item.BatchNo;
                            cnt.ExpiryDate  = item.ExpiryDate;
                            cnt.ProductCode = Convert.ToInt32(item.ProductCode);
                            cnt.Quantity    = item.Quantity;
                            cnt.Price       = item.Price;
                            cnt.Amount      = Convert.ToDecimal(item.Amount);
                            cnt.IsDelete    = item.IsDelete;
                        }
                        tblStockDetail stock = (from tbl in objData.tblStockDetails
                                                where tbl.IsDelete == false &&
                                                tbl.DocumentNo == lstEdited.DNNo &&
                                                tbl.ProductId == item.ProductCode &&
                                                tbl.TransactionType.Equals("DebitNote")
                                                select tbl).FirstOrDefault();
                        if (stock != null)
                        {
                            stock.ProductId     = Convert.ToInt32(item.ProductCode);
                            stock.OpeningQty    = 0;
                            stock.InwardQty     = 0;
                            stock.InwardPrice   = 0;
                            stock.InwardAmount  = 0;
                            stock.BatchNo       = item.BatchNo;
                            stock.ExpiryDate    = item.ExpiryDate;
                            stock.OutwardQty    = item.Quantity;
                            stock.OutwardPrice  = item.Price;
                            stock.OutwardAmount = item.Amount;
                            stock.IsDelete      = Convert.ToBoolean(item.IsDelete);
                        }
                    }
                }

                #region Update Status of Order and Transaction
                tblCustomerTransaction transact = (from tbl in objData.tblCustomerTransactions
                                                   where tbl.SupplierId == lstEdited.SupplierId &&
                                                   tbl.IsDelete == false &&
                                                   tbl.TransactionDocNo == lstEdited.DNNo &&
                                                   tbl.TransactionType.Equals("DebitNote")
                                                   select tbl).FirstOrDefault();
                if (transact != null)
                {
                    transact.PayAmount   = lstEdited.NetAmount;
                    transact.ReceiptDate = lstEdited.DNDate;
                }



                objData.SubmitChanges();
                #endregion

                i++;
            }
            catch (Exception ex)
            {
                i = 0;
                throw ex;
            }
            return(i);
        }