Beispiel #1
0
        public List<Installments> DeleteDeleteInstallment(long Id, long bulkBuyID)
        {
            List<Installments> lstinstallments = new List<Installments>();
            using (ShopDevEntities db = new ShopDevEntities())
            {
                try
                {
                    BulkBuyInstallment installment = GetInstallment(db, Id);
                    var bulkbuy = db.BulkBuys.Where(m => m.BulkBuyID == bulkBuyID).FirstOrDefault();
                    var outstandingAmount = bulkbuy.OustandingAmont;
                    bulkbuy.OustandingAmont = outstandingAmount == null ? installment.Amount : outstandingAmount + installment.Amount;
                    var interstableAmount = bulkbuy.InterstableAmount;
                    bulkbuy.InterstableAmount = interstableAmount == null ? installment.Amount : interstableAmount + installment.Amount;
                   

                    db.BulkBuyInstallments.Remove(installment);
                    db.SaveChanges();
                    var lstproducts = db.BulkBuyInstallments.Where(m => m.BulkBuyID == bulkBuyID).ToList();
                    foreach (var cusprod in lstproducts)
                    {
                        Installments objInstallments = new Installments();
                        cusprod.CopyProperties(objInstallments);
                        lstinstallments.Add(objInstallments);
                    }
                }
                catch (Exception)
                {

                }
                return lstinstallments;
            }
        }
Beispiel #2
0
        public BulkBuyInstallment GetInstallment(ShopDevEntities db, long Id)
        {
            BulkBuyInstallment objinstllment = null;
            try
            {
                objinstllment = db.BulkBuyInstallments.Where(m => m.InstallmentID == Id).FirstOrDefault();
            }
            catch (Exception)
            {

            }
            return objinstllment;
        }
Beispiel #3
0
 public Installments GetInstallmentDetails(long Id)
 {
     Installments objModel = new Installments();
     using (ShopDevEntities db = new ShopDevEntities())
     {
         try
         {
             BulkBuyInstallment installment = GetInstallment(db, Id);
             installment.CopyProperties(objModel);
         }
         catch (Exception)
         {
         }
     }
     return objModel;
 }
Beispiel #4
0
 // installments
 public List<Installments> AddInstallment(Installments installment)
 {
     List<Installments> lstAllinstallments = new List<Installments>();
     using (ShopDevEntities db = new ShopDevEntities())
     {
         try
         {
             installment.BulkBuyID = installment.BulkBuyID == null ? 0 : installment.BulkBuyID;
             BulkBuyInstallment bulkinstDetail = null;
             if (installment.InstallmentID > 0)
             {
                 bulkinstDetail = db.BulkBuyInstallments.Where(m => m.InstallmentID == installment.InstallmentID).FirstOrDefault();
             }
             else
             {
                 bulkinstDetail = new BulkBuyInstallment();
             }
             installment.CopyProperties(bulkinstDetail);
             if (installment.InstallmentID == 0)
             {
                 var bulkBuy = db.BulkBuys.Where(m => m.BulkBuyID == installment.BulkBuyID).FirstOrDefault();
                 if (bulkBuy.InterstableAmount > 0)
                 {
                     if (bulkBuy.Interest != null && bulkBuy.Interest != 0)
                     {
                         if (installment.Amount > bulkBuy.Interest)
                         {
                             var interest = bulkBuy.Interest;
                             bulkBuy.OustandingAmont -= installment.Amount - interest;
                             bulkBuy.Interest = 0;
                             var interstableAmount = bulkBuy.InterstableAmount;
                             bulkBuy.InterstableAmount = interstableAmount == null ? installment.Amount - interest : interstableAmount - (installment.Amount - interest);
                             
                             bulkinstDetail.Description = "Amount cut for Interset" + Convert.ToString(interest) + " and adjust for amunt is " + Convert.ToString(installment.Amount - interest);
                         }
                         else
                         {
                             bulkBuy.Interest -= installment.Amount;
                             bulkinstDetail.Description = "Amount cut for Interset" + Convert.ToString(installment.Amount) + " and adjust for amunt is 0";
                         }
                     }
                     else
                     {
                         bulkBuy.OustandingAmont -= installment.Amount;
                         bulkBuy.InterstableAmount -= installment.Amount;
                         bulkinstDetail.Description = "Amount cut for Interset 0 and adjust for amunt is " + Convert.ToString(installment.Amount);
                     }
                     bulkBuy.LastInstallmentDate = DateTime.Now;
                     db.SaveChanges();
                 }
                 db.BulkBuyInstallments.Add(bulkinstDetail);
             }
             db.SaveChanges();
             var lstinstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == installment.BulkBuyID).ToList();
             foreach (var cusprod in lstinstallments)
             {
                 Installments objcsproduct = new Installments();
                 cusprod.CopyProperties(objcsproduct);
                 lstAllinstallments.Add(objcsproduct);
             }
         }
         catch { }
         return lstAllinstallments;
     }
 }