Пример #1
0
        public int AddSupplierLedger(PharmaBusinessObjects.Master.SupplierLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var maxSupplierLedgerID = context.SupplierLedger.Count() + 1;
                    var supplierLedgerCode  = "S" + maxSupplierLedgerID.ToString().PadLeft(6, '0');

                    Entity.SupplierLedger table = new Entity.SupplierLedger()
                    {
                        SupplierLedgerCode      = supplierLedgerCode,
                        SupplierLedgerName      = p.SupplierLedgerName,
                        SupplierLedgerShortName = p.SupplierLedgerShortName,
                        Address        = p.Address,
                        ContactPerson  = p.ContactPerson,
                        Mobile         = p.Mobile,
                        OfficePhone    = p.OfficePhone,
                        ResidentPhone  = p.ResidentPhone,
                        EmailAddress   = p.EmailAddress,
                        AreaId         = p.AreaId,
                        CreditDebit    = p.CreditDebit,
                        OpeningBal     = p.OpeningBal,
                        TaxRetail      = p.TaxRetail,
                        PurchaseTypeID = p.PurchaseTypeId,
                        DLNo           = p.DLNo,
                        GSTNo          = p.GSTNo,
                        CINNo          = p.CINNo,
                        LINNo          = p.LINNo,
                        ServiceTaxNo   = p.ServiceTaxNo,
                        PANNo          = p.PANNo,
                        Status         = p.Status,
                        CreatedBy      = this.LoggedInUser.Username,
                        CreatedOn      = System.DateTime.Now
                    };

                    context.SupplierLedger.Add(table);


                    ///Add Supplier Company discount data
                    ///
                    var previousMappings = context.SupplierCompanyDiscountRef.Where(x => x.SupplierLedgerID == p.SupplierLedgerId).ToList();
                    context.SupplierCompanyDiscountRef.RemoveRange(previousMappings);

                    foreach (var newEntry in p.SupplierCompanyDiscountList)
                    {
                        context.SupplierCompanyDiscountRef.Add(new Entity.SupplierCompanyDiscountRef()
                        {
                            SupplierLedgerID = p.SupplierLedgerId,
                            CompanyID        = newEntry.CompanyID,
                            Normal           = newEntry.Normal,
                            Breakage         = newEntry.Breakage,
                            Expired          = newEntry.Expired
                        });

                        ///All entry for item mappings
                        ///

                        if (newEntry.SupplierItemDiscountMapping != null)
                        {
                            foreach (var newItem in newEntry.SupplierItemDiscountMapping)
                            {
                                context.SupplierCompanyDiscountRef.Add(new Entity.SupplierCompanyDiscountRef()
                                {
                                    SupplierLedgerID = table.SupplierLedgerId,
                                    CompanyID        = newEntry.CompanyID,
                                    ItemID           = newItem.ItemID,
                                    Normal           = newItem.Normal,
                                    Breakage         = newItem.Breakage,
                                    Expired          = newItem.Expired
                                });
                            }
                        }
                    }

                    return(context.SaveChanges());
                }
                catch (DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
 internal int UpdateSupplierLedger(PharmaBusinessObjects.Master.SupplierLedgerMaster p)
 {
     return(new SupplierLedgerMasterDao(this.LoggedInUser).UpdateSupplierLedger(p));
 }
Пример #3
0
        public int UpdateSupplierLedger(PharmaBusinessObjects.Master.SupplierLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var supplierLedgerMaster = context.SupplierLedger.Where(q => q.SupplierLedgerId == p.SupplierLedgerId).FirstOrDefault();

                    if (supplierLedgerMaster != null)
                    {
                        supplierLedgerMaster.SupplierLedgerName      = p.SupplierLedgerName;
                        supplierLedgerMaster.SupplierLedgerShortName = p.SupplierLedgerShortName;
                        supplierLedgerMaster.Address       = p.Address;
                        supplierLedgerMaster.ContactPerson = p.ContactPerson;
                        supplierLedgerMaster.Mobile        = p.Mobile;
                        supplierLedgerMaster.OfficePhone   = p.OfficePhone;
                        supplierLedgerMaster.ResidentPhone = p.ResidentPhone;
                        supplierLedgerMaster.EmailAddress  = p.EmailAddress;
                        supplierLedgerMaster.AreaId        = p.AreaId;
                        supplierLedgerMaster.CreditDebit   = p.CreditDebit;
                        supplierLedgerMaster.OpeningBal    = p.OpeningBal;
                        supplierLedgerMaster.TaxRetail     = p.TaxRetail;
                        supplierLedgerMaster.DLNo          = p.DLNo;
                        supplierLedgerMaster.GSTNo         = p.GSTNo;
                        supplierLedgerMaster.CINNo         = p.CINNo;
                        supplierLedgerMaster.LINNo         = p.LINNo;
                        supplierLedgerMaster.ServiceTaxNo  = p.ServiceTaxNo;
                        supplierLedgerMaster.PANNo         = p.PANNo;
                        supplierLedgerMaster.Status        = p.Status;
                        supplierLedgerMaster.ModifiedBy    = this.LoggedInUser.Username;
                        supplierLedgerMaster.ModifiedOn    = System.DateTime.Now;
                    }

                    ///Add Supplier Company discount data
                    ///
                    var previousMappings = context.SupplierCompanyDiscountRef.Where(x => x.SupplierLedgerID == p.SupplierLedgerId).ToList();
                    context.SupplierCompanyDiscountRef.RemoveRange(previousMappings);

                    foreach (var newEntry in p.SupplierCompanyDiscountList)
                    {
                        context.SupplierCompanyDiscountRef.Add(new Entity.SupplierCompanyDiscountRef()
                        {
                            SupplierLedgerID = p.SupplierLedgerId,
                            CompanyID        = newEntry.CompanyID,
                            Normal           = newEntry.Normal,
                            Breakage         = newEntry.Breakage,
                            Expired          = newEntry.Expired
                        });

                        ///All entry for item mappings
                        ///

                        if (newEntry.SupplierItemDiscountMapping != null)
                        {
                            foreach (var newItem in newEntry.SupplierItemDiscountMapping)
                            {
                                context.SupplierCompanyDiscountRef.Add(new Entity.SupplierCompanyDiscountRef()
                                {
                                    SupplierLedgerID = p.SupplierLedgerId,
                                    CompanyID        = newEntry.CompanyID,
                                    ItemID           = newItem.ItemID,
                                    Normal           = newItem.Normal,
                                    Breakage         = newItem.Breakage,
                                    Expired          = newItem.Expired
                                });
                            }
                        }
                    }

                    return(context.SaveChanges());
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }