Exemplo n.º 1
0
        public long InsertUpdateTempReceiptPayment(PharmaBusinessObjects.Transaction.ReceiptPayment.ReceiptPaymentItem receiptPayment)
        {
            try
            {
                long receiptPaymentID = 0;

                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    var receiptPaymentDB = context.TempReceiptPayment.Where(x => x.ReceiptPaymentID == receiptPayment.ReceiptPaymentID).FirstOrDefault();

                    if (receiptPaymentDB != null)
                    {
                        receiptPaymentDB.PaymentMode = receiptPayment.PaymentMode;
                        receiptPaymentDB.Ammount     = receiptPayment.Amount;
                        receiptPaymentDB.BankAccountLedgerTypeCode = receiptPayment.BankAccountLedgerTypeCode;
                        receiptPaymentDB.BankAccountLedgerTypeName = receiptPayment.BankAccountLedgerTypeName;
                        receiptPaymentDB.ChequeNumber     = receiptPayment.ChequeNumber;
                        receiptPaymentDB.ChequeDate       = receiptPayment.ChequeDate;
                        receiptPaymentDB.UnadjustedAmount = receiptPayment.UnadjustedAmount;

                        context.SaveChanges();
                        receiptPaymentID = receiptPaymentDB.ReceiptPaymentID;
                    }
                    else
                    {
                        Entity.TempReceiptPayment receiptPaymentDBEntry = new Entity.TempReceiptPayment()
                        {
                            VoucherNumber             = "TPVOCHER",
                            VoucherTypeCode           = receiptPayment.VoucherTypeCode,
                            VoucherDate               = receiptPayment.VoucherDate,
                            LedgerType                = receiptPayment.LedgerType,
                            LedgerTypeCode            = receiptPayment.LedgerTypeCode,
                            LedgerTypeName            = receiptPayment.LedgerTypeName,
                            PaymentMode               = receiptPayment.PaymentMode,
                            BankAccountLedgerTypeCode = receiptPayment.BankAccountLedgerTypeCode,
                            BankAccountLedgerTypeName = receiptPayment.BankAccountLedgerTypeName,
                            CreatedBy = LoggedInUser.Username,
                            CreatedOn = DateTime.Now
                        };

                        context.TempReceiptPayment.Add(receiptPaymentDBEntry);
                        context.SaveChanges();
                        receiptPaymentID = receiptPaymentDBEntry.ReceiptPaymentID;
                    }
                }
                return(receiptPaymentID);
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public int UpdateUser(PharmaBusinessObjects.Master.UserMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var user = context.Users.Where(q => q.UserId == p.UserId).FirstOrDefault();

                    if (user != null)
                    {
                        user.Password   = p.Password;
                        user.Status     = p.Status;
                        user.FirstName  = p.FirstName;
                        user.LastName   = p.LastName;
                        user.RoleID     = p.RoleID;
                        user.IsSysAdmin = p.IsSystemAdmin;
                        user.ModifiedBy = this.LoggedInUser.Username;
                        user.ModifiedOn = System.DateTime.Now;
                    }

                    return(context.SaveChanges());
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 3
0
        public bool AddPrivledge(PharmaBusinessObjects.Master.Privledge privledge)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    int result = 0;

                    if (context.Privledges.Any(p => p.PriviledgeName.ToLower() == privledge.PrivledgeName.ToLower()))
                    {
                        throw new Exception("Privledge already exists");
                    }

                    Privledges priv = new Privledges()
                    {
                        PriviledgeName = privledge.PrivledgeName,
                        Status         = privledge.Status,
                        ControlName    = privledge.ControlName,
                        CreatedBy      = this.LoggedInUser.Username,
                        CreatedOn      = DateTime.Now
                    };

                    context.Privledges.Add(priv);
                    result = context.SaveChanges();

                    return(result > 0);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 4
0
        public int UpdateAccountLedger(PharmaBusinessObjects.Master.AccountLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var accountLedgerMaster = context.AccountLedgerMaster.Where(q => q.AccountLedgerID == p.AccountLedgerID).FirstOrDefault();

                    if (accountLedgerMaster != null)
                    {
                        accountLedgerMaster.AccountLedgerName   = p.AccountLedgerName;
                        accountLedgerMaster.AccountLedgerCode   = p.AccountLedgerCode;
                        accountLedgerMaster.AccountLedgerTypeId = p.AccountLedgerTypeId;
                        accountLedgerMaster.AccountTypeId       = p.AccountTypeId;
                        accountLedgerMaster.CreditControlCodeID = p.CreditControlCodeID;
                        accountLedgerMaster.DebitControlCodeID  = p.DebitControlCodeID;
                        accountLedgerMaster.OpeningBalance      = p.OpeningBalance;
                        accountLedgerMaster.CreditDebit         = p.CreditDebit;
                        accountLedgerMaster.Status = p.Status;
                        accountLedgerMaster.SalePurchaseTaxType = p.SalePurchaseTaxValue;
                        accountLedgerMaster.CreatedBy           = this.LoggedInUser.Username;
                        accountLedgerMaster.CreatedOn           = System.DateTime.Now;
                    }

                    return(context.SaveChanges());
                }
                catch (DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 5
0
        public bool UpdatePrivledges(PharmaBusinessObjects.Master.Privledge privledge)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    int result = 0;

                    Privledges priv = context.Privledges.Where(p => p.PrivledgeId == privledge.PrivledgeId).FirstOrDefault();

                    if (priv != null)
                    {
                        priv.PriviledgeName = privledge.PrivledgeName;
                        priv.Status         = privledge.Status;
                        priv.ControlName    = privledge.ControlName;
                        priv.ModifiedBy     = this.LoggedInUser.Username;
                        priv.ModifiedOn     = DateTime.Now;
                    }

                    result = context.SaveChanges();

                    return(result > 0);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 6
0
        public int AddCompany(PharmaBusinessObjects.Master.CompanyMaster company)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                List <string> companyCodeList = context.CompanyMaster.Select(p => p.CompanyCode).ToList();

                int maxCompanyCode = companyCodeList.Count > 0 ? companyCodeList.Max(p => Convert.ToInt32(p)) + 1 : 1;

                var companyCode = maxCompanyCode.ToString().PadLeft(6, '0');

                Entity.CompanyMaster table = new Entity.CompanyMaster()
                {
                    CompanyCode             = companyCode,
                    Status                  = company.Status,
                    StockSummaryRequired    = company.StockSummaryRequired,
                    IsDirect                = company.IsDirect,
                    OrderPreferenceRating   = company.OrderPreferenceRating,
                    BillingPreferenceRating = company.BillingPreferenceRating,
                    CompanyName             = company.CompanyName,
                    CreatedBy               = this.LoggedInUser.Username,
                    CreatedOn               = System.DateTime.Now
                };

                context.CompanyMaster.Add(table);

                if (context.SaveChanges() > 0)
                {
                    return(table.CompanyId);
                }
                else
                {
                    return(0);
                }
            }
        }
Exemplo n.º 7
0
        public int AddAccountLedger(PharmaBusinessObjects.Master.AccountLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var maxAccountLedgerID = context.AccountLedgerMaster.Count() > 0 ? context.AccountLedgerMaster.Max(q => q.AccountLedgerID) + 1 : 1;

                var accountLedgerCode = "L" + maxAccountLedgerID.ToString().PadLeft(6, '0');

                AccountLedgerMaster table = new AccountLedgerMaster()
                {
                    AccountLedgerName   = p.AccountLedgerName,
                    AccountLedgerCode   = accountLedgerCode,
                    AccountLedgerTypeId = p.AccountLedgerTypeId,
                    AccountTypeId       = p.AccountTypeId,
                    OpeningBalance      = p.OpeningBalance,
                    CreditDebit         = p.CreditDebit,
                    SalePurchaseTaxType = p.SalePurchaseTaxValue,
                    Status    = p.Status,
                    CreatedBy = this.LoggedInUser.Username,
                    CreatedOn = System.DateTime.Now
                };

                var accountLedger = new Common.CommonDao().GetAccountLedgerTypes().Where(q => q.AccountLedgerTypeID == p.AccountLedgerTypeId).FirstOrDefault();

                if (accountLedger.AccountLedgerTypeSystemName != Constants.AccountLedgerType.ControlCodes)
                {
                    table.CreditControlCodeID = p.CreditControlCodeID;
                    table.DebitControlCodeID  = p.DebitControlCodeID;
                }

                context.AccountLedgerMaster.Add(table);
                return(context.SaveChanges());
            }
        }
Exemplo n.º 8
0
        public void UpdateSaleDiscount(PharmaBusinessObjects.Common.Enums.SaleEntryChangeType changeType, decimal discount, decimal specialDiscount, decimal volumeDiscount, string itemCode, string customerCode)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                CustomerLedger ledger = context.CustomerLedger.FirstOrDefault(p => p.CustomerLedgerCode == customerCode);
                ItemMaster     master = context.ItemMaster.FirstOrDefault(p => p.ItemCode == itemCode);

                if (changeType == PharmaBusinessObjects.Common.Enums.SaleEntryChangeType.CompanyWiseChange)
                {
                    var compItem = context.CustomerCompanyDiscountRef.Where(p => p.CustomerLedgerID == ledger.CustomerLedgerId && p.CompanyID == master.CompanyID && p.ItemID == null).FirstOrDefault();
                    if (compItem != null)
                    {
                        compItem.Normal = discount;
                    }
                }
                else
                {
                    var disItem = context.CustomerCompanyDiscountRef.Where(p => p.CustomerLedgerID == ledger.CustomerLedgerId && p.CompanyID == master.CompanyID && p.ItemID == master.ItemID).FirstOrDefault();
                    if (disItem != null)
                    {
                        disItem.Normal = discount;
                    }
                    master.SpecialDiscount = specialDiscount;
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public int UpdatePersonRoute(PharmaBusinessObjects.Master.PersonRouteMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var personRouteMaster = context.PersonRouteMaster.Where(q => q.PersonRouteID == p.PersonRouteID).FirstOrDefault();

                    if (personRouteMaster != null)
                    {
                        //personRouteMaster.PersonRouteCode = p.PersonRouteCode;
                        personRouteMaster.PersonRouteName = p.PersonRouteName;
                        personRouteMaster.ModifiedBy      = this.LoggedInUser.Username;
                        personRouteMaster.ModifiedOn      = System.DateTime.Now;
                        personRouteMaster.Status          = p.Status;
                    }

                    if (context.SaveChanges() > 0)
                    {
                        return(personRouteMaster.PersonRouteID);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 10
0
        public bool DeleteItem(PharmaBusinessObjects.Master.ItemMaster existingItem)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                int _result = 0;

                Entity.ItemMaster existingItemDB = context.ItemMaster.Where(p => p.ItemCode == existingItem.ItemCode && p.Status).FirstOrDefault();

                if (existingItemDB != null)
                {
                    existingItemDB.Status     = false;
                    existingItemDB.Status     = existingItem.Status;
                    existingItemDB.ModifiedBy = this.LoggedInUser.Username;
                    existingItemDB.ModifiedOn = System.DateTime.Now;
                }
                _result = context.SaveChanges();

                if (_result > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 11
0
        public int UpdateFifoBatchesByItemCode(FifoBatches fifoBatch)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                FIFO fifo = context.FIFO.Where(p => p.FifoID == fifoBatch.FifoID).FirstOrDefault();

                if (fifo != null)
                {
                    fifo.Batch         = fifoBatch.Batch;
                    fifo.SaleRate      = fifoBatch.SaleRate;
                    fifo.WholeSaleRate = fifoBatch.WholeSaleRate;
                    fifo.SpecialRate   = fifoBatch.SpecialRate;
                    fifo.MRP           = fifoBatch.MRP;
                    fifo.PurchaseRate  = fifoBatch.PurchaseRate;
                    fifo.IsOnHold      = fifoBatch.IsOnHold;
                    fifo.OnHoldRemarks = fifoBatch.OnHoldRemarks;
                    fifo.MfgDate       = fifoBatch.MfgDate;
                    fifo.ExpiryDate    = fifoBatch.ExpiryDate;

                    context.SaveChanges();



                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }
Exemplo n.º 12
0
        public int UpdatePersonalLedger(PharmaBusinessObjects.Master.PersonalLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var personlLedgerMaster = context.PersonalLedger.Where(q => q.PersonalLedgerId == p.PersonalLedgerId).FirstOrDefault();

                    if (personlLedgerMaster != null)
                    {
                        personlLedgerMaster.PersonalLedgerName      = p.PersonalLedgerName;
                        personlLedgerMaster.PersonalLedgerShortName = p.PersonalLedgerShortName;
                        personlLedgerMaster.Address       = p.Address;
                        personlLedgerMaster.ContactPerson = p.ContactPerson;
                        personlLedgerMaster.Mobile        = p.Mobile;
                        //personlLedgerMaster.Pager = p.Pager;
                        //personlLedgerMaster.Fax = p.Fax;
                        personlLedgerMaster.OfficePhone   = p.OfficePhone;
                        personlLedgerMaster.ResidentPhone = p.ResidentPhone;
                        personlLedgerMaster.EmailAddress  = p.EmailAddress;
                        personlLedgerMaster.Status        = p.Status;
                        personlLedgerMaster.ModifiedBy    = this.LoggedInUser.Username;
                        personlLedgerMaster.ModifiedOn    = System.DateTime.Now;
                    }

                    return(context.SaveChanges());
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 13
0
        public int AddPersonalLedger(PharmaBusinessObjects.Master.PersonalLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var maxAccountLedgerID = context.PersonalLedger.Count() > 0 ? context.PersonalLedger.Max(q => q.PersonalLedgerId) + 1 : 1;

                var personaltLedgerCode = "P" + maxAccountLedgerID.ToString().PadLeft(6, '0');

                PersonalLedger table = new PersonalLedger()
                {
                    PersonalLedgerCode      = personaltLedgerCode,
                    PersonalLedgerName      = p.PersonalLedgerName,
                    PersonalLedgerShortName = p.PersonalLedgerShortName,
                    Address       = p.Address,
                    ContactPerson = p.ContactPerson,
                    Mobile        = p.Mobile,
                    //Pager = p.Pager,
                    //Fax = p.Fax,
                    OfficePhone   = p.OfficePhone,
                    ResidentPhone = p.ResidentPhone,
                    EmailAddress  = p.EmailAddress,
                    Status        = p.Status,
                    CreatedBy     = this.LoggedInUser.Username,
                    CreatedOn     = System.DateTime.Now
                };

                context.PersonalLedger.Add(table);
                return(context.SaveChanges());
            }
        }
Exemplo n.º 14
0
        public bool DeleteUnSavedData(long purchaseSaleBookHeaderID)
        {
            try
            {
                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    var lineItems = context.TempPurchaseSaleBookLineItem.Where(p => p.PurchaseSaleBookHeaderID == purchaseSaleBookHeaderID).ToList();
                    var header    = context.TempPurchaseSaleBookHeader.Where(p => p.PurchaseSaleBookHeaderID == purchaseSaleBookHeaderID).FirstOrDefault();

                    if (lineItems != null && lineItems.Count > 0)
                    {
                        context.TempPurchaseSaleBookLineItem.RemoveRange(lineItems);
                    }

                    if (header != null)
                    {
                        context.TempPurchaseSaleBookHeader.Remove(header);
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }
Exemplo n.º 15
0
        public bool UpdateRole(PharmaBusinessObjects.Master.Role role)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    int result = 0;

                    Roles roles = context.Roles.Where(p => p.RoleId == role.RoleId).FirstOrDefault();

                    if (roles != null)
                    {
                        roles.RoleName  = role.RoleName;
                        roles.Status    = role.Status;
                        roles.CreatedBy = this.LoggedInUser.Username;
                        roles.CreatedOn = DateTime.Now;
                    }

                    result = context.SaveChanges();

                    var privledges = context.RolePrivledges.Where(p => p.RoleId == role.RoleId).ToList();

                    privledges.ForEach(p => context.RolePrivledges.Remove(p));

                    foreach (var item in role.PrivledgeList)
                    {
                        RolePrivledges priv = new RolePrivledges()
                        {
                            RoleId      = role.RoleId,
                            PrivledgeId = item.PrivledgeId
                        };
                    }

                    result = result + context.SaveChanges();

                    return(result > 0);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 16
0
        public int InsertRSMData()
        {
            try
            {
                string query = "select * from MASTERS where slcd = 'RS'";

                DataTable dtRSMMaster = dbConnection.GetData(query);

                List <PharmaDAL.Entity.PersonRouteMaster> listRSMMaster = new List <PharmaDAL.Entity.PersonRouteMaster>();
                int _result = 0;

                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    var systemName   = PharmaBusinessObjects.Common.Constants.RecordType.RSM;
                    int recordTypeID = context.RecordType.Where(q => q.SystemName == systemName).FirstOrDefault().RecordTypeId;
                    var maxRSMID     = context.PersonRouteMaster.Where(q => q.RecordTypeId == recordTypeID).Count();

                    if (dtRSMMaster != null && dtRSMMaster.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtRSMMaster.Rows)
                        {
                            maxRSMID++;
                            string originalPersonRouteCode = Convert.ToString(dr["ACNO"]).TrimEnd();
                            string mappedPersonRouteCode   = systemName + maxRSMID.ToString().PadLeft(3, '0');
                            Common.rsmCodeMap.Add(new RSMCodeMap()
                            {
                                OriginalRSMCode = originalPersonRouteCode, MappedRSMCode = mappedPersonRouteCode
                            });

                            PharmaDAL.Entity.PersonRouteMaster newRSMMaster = new PharmaDAL.Entity.PersonRouteMaster()
                            {
                                PersonRouteCode = mappedPersonRouteCode,
                                PersonRouteName = Convert.ToString(dr["ACName"]).TrimEnd(),
                                RecordTypeId    = recordTypeID,
                                CreatedBy       = "admin",
                                CreatedOn       = DateTime.Now,
                                Status          = Convert.ToChar(dr["ACSTS"]) == '*' ? false : true
                            };

                            listRSMMaster.Add(newRSMMaster);
                        }
                    }

                    context.PersonRouteMaster.AddRange(listRSMMaster);
                    _result = context.SaveChanges();

                    return(_result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 17
0
        public bool AddRole(PharmaBusinessObjects.Master.Role role)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    int result = 0;

                    if (context.Roles.Any(p => p.RoleName.ToLower() == role.RoleName.ToLower()))
                    {
                        throw new Exception("Role already exists");
                    }

                    Roles roles = new Roles()
                    {
                        RoleName  = role.RoleName,
                        Status    = role.Status,
                        CreatedBy = this.LoggedInUser.Username,
                        CreatedOn = DateTime.Now
                    };

                    context.Roles.Add(roles);
                    result = context.SaveChanges();

                    foreach (Privledge item in role.PrivledgeList)
                    {
                        RolePrivledges priv = new RolePrivledges();
                        priv.RoleId      = roles.RoleId;
                        priv.PrivledgeId = item.PrivledgeId;
                        context.RolePrivledges.Add(priv);
                    }
                    result = result + context.SaveChanges();
                    return(result > 0);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 18
0
        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;
            }
        }
Exemplo n.º 19
0
        public int DeletePersonalLedger(PharmaBusinessObjects.Master.PersonalLedgerMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var personalLedgerMaster = context.PersonalLedger.FirstOrDefault(q => q.PersonalLedgerCode == p.PersonalLedgerCode);

                if (personalLedgerMaster != null)
                {
                    personalLedgerMaster.Status     = false;
                    personalLedgerMaster.ModifiedBy = this.LoggedInUser.Username;
                    personalLedgerMaster.ModifiedOn = System.DateTime.Now;
                }

                return(context.SaveChanges());
            }
        }
Exemplo n.º 20
0
        public int DeleteCompany(int companyId)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var companyMaster = context.CompanyMaster.FirstOrDefault(p => p.CompanyId == companyId);

                if (companyMaster != null)
                {
                    companyMaster.Status     = false;
                    companyMaster.ModifiedBy = this.LoggedInUser.Username;
                    companyMaster.ModifiedOn = System.DateTime.Now;
                }

                return(context.SaveChanges());
            }
        }
Exemplo n.º 21
0
        public int DeleteCustomerLedger(int customerLedgerID)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var customerLedgerMaster = context.CustomerLedger.FirstOrDefault(p => p.CustomerLedgerId == customerLedgerID);

                if (customerLedgerMaster != null)
                {
                    customerLedgerMaster.Status     = false;
                    customerLedgerMaster.ModifiedBy = this.LoggedInUser.Username;
                    customerLedgerMaster.ModifiedOn = System.DateTime.Now;
                }

                return(context.SaveChanges());
            }
        }
Exemplo n.º 22
0
        public int UpdateCompany(PharmaBusinessObjects.Master.CompanyMaster company)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var companyMaster = context.CompanyMaster.FirstOrDefault(p => p.CompanyId == company.CompanyId);

                if (companyMaster != null)
                {
                    companyMaster.Status = company.Status;
                    companyMaster.StockSummaryRequired    = company.StockSummaryRequired;
                    companyMaster.IsDirect                = company.IsDirect;
                    companyMaster.OrderPreferenceRating   = company.OrderPreferenceRating;
                    companyMaster.BillingPreferenceRating = company.BillingPreferenceRating;
                    companyMaster.CompanyName             = company.CompanyName;
                    companyMaster.ModifiedBy              = this.LoggedInUser.Username;
                    companyMaster.ModifiedOn              = System.DateTime.Now;
                }

                return(context.SaveChanges());
            }
        }
Exemplo n.º 23
0
        public int AddUser(PharmaBusinessObjects.Master.UserMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                Entity.Users table = new Entity.Users()
                {
                    Username   = p.Username,
                    Password   = p.Password,
                    FirstName  = p.FirstName,
                    LastName   = p.LastName,
                    RoleID     = p.RoleID,
                    IsSysAdmin = p.IsSystemAdmin,
                    CreatedBy  = this.LoggedInUser.Username,
                    CreatedOn  = System.DateTime.Now,
                    Status     = p.Status
                };

                context.Users.Add(table);
                return(context.SaveChanges());
            }
        }
Exemplo n.º 24
0
        public int AddPersonRoute(PharmaBusinessObjects.Master.PersonRouteMaster p)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    var maxPersonRouteMasterID = context.PersonRouteMaster.Where(q => q.RecordTypeId == p.RecordTypeId).Count() + 1;

                    var systemName = context.RecordType.Where(q => q.RecordTypeId == p.RecordTypeId).FirstOrDefault().SystemName;

                    var personRouteCode = systemName + maxPersonRouteMasterID.ToString().PadLeft(3, '0');

                    Entity.PersonRouteMaster table = new Entity.PersonRouteMaster()
                    {
                        PersonRouteID   = p.PersonRouteID,
                        PersonRouteCode = personRouteCode,
                        PersonRouteName = p.PersonRouteName,
                        RecordTypeId    = p.RecordTypeId,
                        CreatedBy       = this.LoggedInUser.LastName,
                        CreatedOn       = System.DateTime.Now,
                        Status          = p.Status
                    };

                    context.PersonRouteMaster.Add(table);

                    if (context.SaveChanges() > 0)
                    {
                        return(table.PersonRouteID);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 25
0
        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;
            }
        }
Exemplo n.º 26
0
        public int InsertData(DataTable dtSalePur)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                int _result = 0;

                List <PharmaDAL.Entity.PurchaseSaleBookLineItem> listPurchaseSaleBookLineItem = new List <PharmaDAL.Entity.PurchaseSaleBookLineItem>();

                if (dtSalePur != null && dtSalePur.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtSalePur.Rows)
                    {
                        try
                        {
                            PharmaDAL.Entity.PurchaseSaleBookLineItem newPurchaseSaleBookLineItem = new PharmaDAL.Entity.PurchaseSaleBookLineItem();

                            string oldVNo  = string.Empty;
                            string oldPVNo = string.Empty;

                            oldVNo  = Convert.ToString(dr["vno"]).Trim();
                            oldPVNo = Convert.ToString(dr["PURVNO"]).Trim();

                            var header = Common.voucherNumberMap.Where(p => p.OriginalVoucherNumber == oldVNo).FirstOrDefault();

                            if (header != null)
                            {
                                string oldItemCode = Convert.ToString(dr["ITEMC"]).Trim();
                                string newItemCode = Common.itemCodeMap.Where(p => p.OriginalItemCode == oldItemCode).Select(p => p.MappedItemCode).FirstOrDefault();

                                if (string.IsNullOrEmpty(newItemCode))
                                {
                                    throw new Exception(string.Format("FIFO: Item Code Not found in Item Master {0}", oldItemCode));
                                }


                                string oldPSType = Convert.ToString(dr["PSTYPE"]);
                                if (!string.IsNullOrEmpty(oldPSType))
                                {
                                    string newPSType = Common.accountLedgerCodeMap.Where(p => p.OriginalAccountLedgerCode == oldPSType).Select(p => p.MappedAccountLedgerCode).FirstOrDefault();

                                    if (!string.IsNullOrEmpty(newPSType))
                                    {
                                        newPurchaseSaleBookLineItem.PurchaseSaleTypeCode = newPSType;
                                    }
                                }

                                newPurchaseSaleBookLineItem.PurchaseSaleBookHeaderID = header.MappedPurchaseHeaderID;


                                //newPurchaseSaleBookLineItem.FifoID = 0;

                                if (dr["PURVDT"] != null)
                                {
                                    newPurchaseSaleBookLineItem.PurchaseBillDate = CommonMethods.SafeConversionDatetime(Convert.ToString(dr["PURVDT"]));
                                }

                                if (!string.IsNullOrEmpty(oldPVNo))
                                {
                                    var pHeader = Common.voucherNumberMap.Where(p => p.OriginalVoucherNumber == oldPVNo).FirstOrDefault();

                                    if (pHeader != null)
                                    {
                                        newPurchaseSaleBookLineItem.PurchaseVoucherNumber = pHeader.MappedVoucherNumber;
                                    }
                                }

                                if (dr["PURSRLNO"] != null && !string.IsNullOrEmpty(Convert.ToString(dr["PURSRLNO"])))
                                {
                                    newPurchaseSaleBookLineItem.PurchaseSrlNo = Convert.ToInt32(Convert.ToString(dr["PURSRLNO"]).Trim());
                                }


                                newPurchaseSaleBookLineItem.ItemCode         = newItemCode;
                                newPurchaseSaleBookLineItem.Batch            = Convert.ToString(dr["BATCH"]);
                                newPurchaseSaleBookLineItem.BatchNew         = Convert.ToString(dr["BATCH1"]);
                                newPurchaseSaleBookLineItem.Quantity         = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["QTY"]));
                                newPurchaseSaleBookLineItem.FreeQuantity     = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["FQTY"]));
                                newPurchaseSaleBookLineItem.PurchaseSaleRate = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["PSRATE"]));


                                newPurchaseSaleBookLineItem.EffecivePurchaseSaleRate = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["EPSRATE"]))
                                                                                       + CommonMethods.SafeConversionDecimal(Convert.ToString(dr["EPCOST"]));

                                newPurchaseSaleBookLineItem.SurCharge       = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SC"]));
                                newPurchaseSaleBookLineItem.SalePurchaseTax = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["TAX"]));
                                newPurchaseSaleBookLineItem.TaxAmount       = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["TAXAMT"]));


                                newPurchaseSaleBookLineItem.LocalCentral = header.LocalCentral;

                                if (header.LocalCentral == "L")
                                {
                                    newPurchaseSaleBookLineItem.SGST = newPurchaseSaleBookLineItem.TaxAmount * (decimal)0.5;
                                    newPurchaseSaleBookLineItem.CGST = newPurchaseSaleBookLineItem.TaxAmount * (decimal)0.5;
                                }
                                else
                                {
                                    newPurchaseSaleBookLineItem.IGST = newPurchaseSaleBookLineItem.TaxAmount;
                                }


                                newPurchaseSaleBookLineItem.Amount = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SALEAMT"])); //  PSSRATE * QYTY = GROSS = SALEAMT

                                newPurchaseSaleBookLineItem.Discount         = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["DIS"]));
                                newPurchaseSaleBookLineItem.SpecialDiscount  = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SPLDIS"]));
                                newPurchaseSaleBookLineItem.DiscountQuantity = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["DISQTY"]));
                                newPurchaseSaleBookLineItem.VolumeDiscount   = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["VDIS"]));
                                newPurchaseSaleBookLineItem.Scheme1          = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SCHEME1"]));
                                newPurchaseSaleBookLineItem.Scheme2          = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SCHEME2"]));
                                newPurchaseSaleBookLineItem.IsHalfScheme     = false;// Convert.ToString(dr["HALF"]) == "Y" ? true : false;//  Convert.ToBoolean(dr["HALF"]); // ???
                                newPurchaseSaleBookLineItem.HalfSchemeRate   = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["HALFP"]));


                                newPurchaseSaleBookLineItem.CostAmount =
                                    CommonMethods.SafeConversionDecimal(Convert.ToString(dr["EPSRATE"]))
                                    + CommonMethods.SafeConversionDecimal(Convert.ToString(dr["EPCOST"]));//??

                                newPurchaseSaleBookLineItem.GrossAmount     = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SALEAMT"]));
                                newPurchaseSaleBookLineItem.SchemeAmount    = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SCAMT"]));
                                newPurchaseSaleBookLineItem.DiscountAmount  = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["DISAMT"]));
                                newPurchaseSaleBookLineItem.SurchargeAmount = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SCAMT"]));
                                newPurchaseSaleBookLineItem.ConversionRate  = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["CONVRATE"]));
                                newPurchaseSaleBookLineItem.MRP             = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["MRP"]));

                                // newPurchaseSaleBookLineItem.MfgDate = Convert.ToDateTime(dr["MRP"]);
                                newPurchaseSaleBookLineItem.ExpiryDate    = CommonMethods.SafeConversionDatetime(Convert.ToString(dr["EXPDT"]));
                                newPurchaseSaleBookLineItem.SaleRate      = 0;//Convert.ToDecimal(dr["MRP"]); //??
                                newPurchaseSaleBookLineItem.WholeSaleRate = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["WSRATE"]));
                                newPurchaseSaleBookLineItem.SpecialRate   = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["SPLRATE"]));


                                newPurchaseSaleBookLineItem.SpecialDiscountAmount = 0; // Convert.ToDecimal(dr["SPLRATE"]);
                                newPurchaseSaleBookLineItem.VolumeDiscountAmount  = 0; // Convert.ToDecimal(dr["SPLRATE"]);
                                newPurchaseSaleBookLineItem.TotalDiscountAmount   = (decimal)CommonMethods.SafeConversionDecimal(Convert.ToString(dr["DISAMT"]));

                                newPurchaseSaleBookLineItem.CreatedBy  = "admin";
                                newPurchaseSaleBookLineItem.CreatedOn  = DateTime.Now;
                                newPurchaseSaleBookLineItem.ModifiedBy = "admin";
                                newPurchaseSaleBookLineItem.ModifiedOn = DateTime.Now;

                                listPurchaseSaleBookLineItem.Add(newPurchaseSaleBookLineItem);
                            }
                            else
                            {
                                log.Info(string.Format("PurchaseSaleBookHeader: Error in VNo {0}}", Convert.ToString(dr["vno"]).Trim()));
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Info(string.Format("PurchaseSaleBookLineItem: Error in Voucher Number {0}", Convert.ToString(dr["vno"]).Trim()));
                            log.Info(ex.ToString());
                        }
                    }
                }

                context.PurchaseSaleBookLineItem.AddRange(listPurchaseSaleBookLineItem);
                _result = context.SaveChanges();

                return(_result);
            }
        }
Exemplo n.º 27
0
        public int InsertFIFOData()
        {
            try
            {
                string    query  = "select * from FIFO";
                DataTable dtFIFO = dbConnection.GetData(query);

                List <PharmaDAL.Entity.FIFO> listFIFO = new List <PharmaDAL.Entity.FIFO>();
                int _result = 0;

                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    if (dtFIFO != null && dtFIFO.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtFIFO.Rows)
                        {
                            try
                            {
                                string originalItemCode = Convert.ToString(dr["itemc"]).TrimEnd();
                                string mappedItemCode   = Common.itemCodeMap.Where(x => x.OriginalItemCode == originalItemCode).Select(x => x.MappedItemCode).FirstOrDefault();

                                if (mappedItemCode == null)
                                {
                                    log.Error(string.Format("FIFO: Item Code Not found in Item Master {0}", originalItemCode));
                                    throw new Exception();
                                }

                                PharmaDAL.Entity.FIFO newFIFO = new PharmaDAL.Entity.FIFO();

                                newFIFO.PurchaseSaleBookHeaderID = null;
                                newFIFO.VoucherNumber            = (Convert.ToString(dr["vno"]).TrimEnd()).PadLeft(8, '0');
                                newFIFO.VoucherDate           = Convert.ToDateTime(dr["vdt"]);
                                newFIFO.SRLNO                 = Convert.ToInt32(dr["srlno"]);
                                newFIFO.ItemCode              = mappedItemCode;
                                newFIFO.PurchaseBillNo        = Convert.ToString(dr["pbillno"]).TrimEnd();
                                newFIFO.Batch                 = Convert.ToString(dr["batch"]).TrimEnd();
                                newFIFO.ExpiryDate            = CommonMethods.SafeConversionDatetime(Convert.ToString(dr["expdt"]).TrimEnd());
                                newFIFO.Quantity              = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["qty"]).TrimEnd()) ?? default(decimal);
                                newFIFO.BalanceQuanity        = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["bqty"]).TrimEnd()) ?? default(decimal);
                                newFIFO.PurchaseTypeId        = null;
                                newFIFO.PurchaseRate          = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["prate"]).TrimEnd()) ?? default(decimal);
                                newFIFO.EffectivePurchaseRate = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["eprate"]).TrimEnd());
                                newFIFO.SaleRate              = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["srate"]).TrimEnd()) ?? default(decimal);
                                newFIFO.WholeSaleRate         = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["wsrate"]).TrimEnd());
                                newFIFO.SpecialRate           = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["splrate"]).TrimEnd());
                                newFIFO.MRP           = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["mrp"]).TrimEnd()) ?? default(decimal);
                                newFIFO.Scheme1       = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["scheme1"]).TrimEnd());
                                newFIFO.Scheme2       = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["scheme2"]).TrimEnd());
                                newFIFO.IsOnHold      = Convert.ToString(dr["hold"]).TrimEnd() == "Y" ? true : false;
                                newFIFO.OnHoldRemarks = null;
                                newFIFO.MfgDate       = CommonMethods.SafeConversionDatetime(Convert.ToString(dr["mfgdt"]).TrimEnd());
                                newFIFO.UPC           = Convert.ToString(dr["barcode"]).TrimEnd();


                                listFIFO.Add(newFIFO);
                            }
                            catch (Exception ex)
                            {
                                log.Info(string.Format("FIFO: Error in Voucher Number {0}", Convert.ToString(dr["vno"]).TrimEnd()));
                            }
                        }
                    }

                    context.FIFO.AddRange(listFIFO);
                    _result = context.SaveChanges();

                    return(_result);
                }
            }
            catch (DbEntityValidationException ex)
            {
                log.Info(string.Format("FIFO: Error {0}", ex.Message));
                throw ex;
            }
            catch (Exception ex)
            {
                log.Info(string.Format("FIFO: Error {0}", ex.Message));
                throw ex;
            }
        }
Exemplo n.º 28
0
        public int InsertBillOutstandingData()
        {
            try
            {
                string    query             = "select * from BILLOS";
                DataTable dtBillOutstanding = dbConnection.GetData(query);

                List <PharmaDAL.Entity.BillOutStandings> listBillOutstandings = new List <PharmaDAL.Entity.BillOutStandings>();
                int _result = 0;

                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    if (dtBillOutstanding != null && dtBillOutstanding.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtBillOutstanding.Rows)
                        {
                            try
                            {
                                string ledgerType     = string.Empty;
                                string ledgerTypeCode = string.Empty;

                                if (string.IsNullOrWhiteSpace(Convert.ToString(dr["vno"]).Trim()))
                                {
                                    throw new Exception();
                                }
                                else if (Convert.ToString(dr["vno"]).Trim().Length > 8)
                                {
                                    log.Error("BillOS : VNO Length is greater than 8 -->" + Convert.ToString(dr["vno"]).Trim());
                                    throw new Exception();
                                }

                                string originalVoucherTypeCode = Convert.ToString(dr["vtyp"]).Trim();
                                string mappedVoucherTypeCode   = Common.voucherTypeMap.Where(x => x.OriginalVoucherType == originalVoucherTypeCode).Select(x => x.MappedVoucherType).FirstOrDefault();

                                if (Convert.ToString(dr["slcd"]).Trim() == "SL")
                                {
                                    ledgerType     = Common.ledgerTypeMap.Where(p => p.OriginaLedgerType == "SL").Select(p => p.MappedLedgerType).FirstOrDefault();
                                    ledgerTypeCode = Common.supplierLedgerCodeMap.Where(p => p.OriginalSupplierLedgerCode == Convert.ToString(dr["ACNO"]).Trim()).Select(x => x.MappedSupplierLedgerCode).FirstOrDefault();
                                }
                                else if (Convert.ToString(dr["slcd"]).Trim() == "CL")
                                {
                                    ledgerType     = Common.ledgerTypeMap.Where(p => p.OriginaLedgerType == "CL").Select(p => p.MappedLedgerType).FirstOrDefault();
                                    ledgerTypeCode = Common.customerLedgerCodeMap.Where(p => p.OriginalCustomerLedgerCode == Convert.ToString(dr["ACNO"]).Trim()).Select(x => x.MappedCustomerLedgerCode).FirstOrDefault();
                                }

                                string oldVNo = Convert.ToString(dr["vno"]).Trim();
                                var    header = Common.voucherNumberMap.Where(p => p.OriginalVoucherNumber == oldVNo).FirstOrDefault();

                                PharmaDAL.Entity.BillOutStandings newBillOS = new PharmaDAL.Entity.BillOutStandings();

                                if (header != null)
                                {
                                    newBillOS.PurchaseSaleBookHeaderID = header.MappedPurchaseHeaderID;
                                    newBillOS.VoucherNumber            = header.MappedVoucherNumber;
                                }
                                else
                                {
                                    newBillOS.VoucherNumber = (Convert.ToString(dr["vno"]).Trim()).PadLeft(8, '0');
                                    //log.Info(string.Format("BILLOS: Voucher No  Not found in for VNO {0}", oldVNo));
                                }

                                newBillOS.VoucherTypeCode = mappedVoucherTypeCode;
                                newBillOS.VoucherDate     = (DateTime)CommonMethods.SafeConversionDatetime(Convert.ToString(dr["vdt"]));
                                newBillOS.DueDate         = CommonMethods.SafeConversionDatetime(Convert.ToString(dr["duedt"]));
                                newBillOS.LedgerType      = ledgerType;
                                newBillOS.LedgerTypeCode  = ledgerTypeCode;
                                newBillOS.BillAmount      = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["osamt"])) ?? default(decimal);
                                newBillOS.OSAmount        = CommonMethods.SafeConversionDecimal(Convert.ToString(dr["osamt"])) ?? default(decimal);
                                newBillOS.IsHold          = Convert.ToString(dr["vno"]).Trim() == "Y" ? true : false;
                                newBillOS.HOLDRemarks     = null;


                                listBillOutstandings.Add(newBillOS);
                            }
                            catch (Exception)
                            {
                                log.Info(string.Format("BILL OUTSTANDING: Error in Voucher Number {0}", Convert.ToString(dr["vno"]).Trim()));
                            }
                        }
                    }

                    context.BillOutStandings.AddRange(listBillOutstandings);
                    _result = context.SaveChanges();
                }

                FillBillOsId();

                return(_result);
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 29
0
        public int InsertSupplierCompanyReferenceData()
        {
            try
            {
                //string query = "select * from DIS where Icode not in (select distinct acno from masters where slcd = 'IT') and Ccode not in (select distinct acno from masters where slcd = 'CO')";
                string query = "select * from DIS1 WHERE Disamt > 0";

                DataTable dtSupplierCompanyRef = dbConnection.GetData(query);

                List <SupplierCompanyDiscountRef> listSupplierCompanyRef = new List <SupplierCompanyDiscountRef>();

                int _result = 0;

                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    if (dtSupplierCompanyRef != null && dtSupplierCompanyRef.Rows.Count > 0)
                    {
                        var companyList        = context.CompanyMaster.Select(p => p).ToList();
                        var supplierLedgerList = context.SupplierLedger.Select(p => p).ToList();
                        var itemList           = context.ItemMaster.Select(p => p).ToList();

                        foreach (DataRow dr in dtSupplierCompanyRef.Rows)
                        {
                            try
                            {
                                if (dr["Disamt"] != null && Convert.ToDecimal(dr["Disamt"]) > 0)
                                {
                                    string supplierLedgerCode = Common.supplierLedgerCodeMap.Where(p => p.OriginalSupplierLedgerCode == Convert.ToString(dr["PCode"]).TrimEnd()).FirstOrDefault().MappedSupplierLedgerCode;
                                    int    supplierLedgerID   = supplierLedgerList.Where(p => p.SupplierLedgerCode == supplierLedgerCode).FirstOrDefault().SupplierLedgerId;
                                    string companyCode        = string.Empty;

                                    var company = Common.companyCodeMap.Where(p => p.OriginalCompanyCode == Convert.ToString(dr["Ccode"]).TrimEnd()).FirstOrDefault();

                                    if (company == null)
                                    {
                                        continue;
                                    }

                                    companyCode = company.MappedCompanyCode;
                                    int companyID = companyList.Where(p => p.CompanyCode == companyCode).FirstOrDefault().CompanyId;

                                    string itemCode = string.IsNullOrEmpty(Convert.ToString(dr["ICode"]).TrimEnd()) ? null : Common.itemCodeMap.Where(p => p.OriginalItemCode == Convert.ToString(dr["ICode"]).TrimEnd()).FirstOrDefault().MappedItemCode;
                                    int?   itemID   = itemCode == null ? (int?)null : itemList.Where(p => p.ItemCode == itemCode).FirstOrDefault().ItemID;

                                    SupplierCompanyDiscountRef newSupplierCompanyRef = new SupplierCompanyDiscountRef()
                                    {
                                        SupplierLedgerID = supplierLedgerID,
                                        CompanyID        = companyID,
                                        ItemID           = itemID,
                                        Normal           = Convert.ToDecimal(dr["Disamt"]),
                                        Breakage         = Convert.ToDecimal(dr["Disamtbe"]),
                                        Expired          = Convert.ToDecimal(dr["Disamtex"]),
                                        IsLessEcise      = Convert.ToString(dr["Less_ex"]) == "Y" ? true : false
                                    };

                                    listSupplierCompanyRef.Add(newSupplierCompanyRef);
                                }
                            }
                            catch (Exception)
                            {
                                //throw ex;
                            }
                        }
                    }

                    context.SupplierCompanyDiscountRef.AddRange(listSupplierCompanyRef);
                    _result = context.SaveChanges();

                    return(_result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 30
0
        public int InsertSupplierLedgerMasterData()
        {
            try
            {
                string query = "select * from ACM where slcd = 'SL'";

                DataTable dtSupplierLedgerMaster = dbConnection.GetData(query);

                List <SupplierLedger> listSupplierLedgerMaster = new List <SupplierLedger>();

                int _result = 0;

                using (PharmaDBEntities context = new PharmaDBEntities())
                {
                    var maxSupplierLedgerID = context.SupplierLedger.Count();

                    if (dtSupplierLedgerMaster != null && dtSupplierLedgerMaster.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtSupplierLedgerMaster.Rows)
                        {
                            try
                            {
                                maxSupplierLedgerID++;

                                string supplierLedgerCode         = "S" + maxSupplierLedgerID.ToString().PadLeft(6, '0');
                                string originalSupplierLedgerCode = Convert.ToString(dr["ACNO"]).TrimEnd();
                                Common.supplierLedgerCodeMap.Add(new SupplierLedgerCodeMap()
                                {
                                    OriginalSupplierLedgerCode = originalSupplierLedgerCode, MappedSupplierLedgerCode = supplierLedgerCode
                                });

                                string areaCode           = Common.areaCodeMap.Where(p => p.OriginalAreaCode == Convert.ToString(dr["PAREA"]).TrimEnd()).FirstOrDefault().MappedAreaCode;
                                int    areaID             = context.PersonRouteMaster.Where(q => q.PersonRouteCode == areaCode).FirstOrDefault().PersonRouteID;
                                string purchaseLedgerCode = Common.accountLedgerCodeMap.Where(q => q.OriginalAccountLedgerCode == Convert.ToString(dr["PCODE"]).TrimEnd()).FirstOrDefault().MappedAccountLedgerCode;
                                int    purchaseTypeID     = context.AccountLedgerMaster.Where(p => p.AccountLedgerCode == purchaseLedgerCode).FirstOrDefault().AccountLedgerID;

                                SupplierLedger newSupplierLedgerMaster = new SupplierLedger()
                                {
                                    SupplierLedgerCode      = supplierLedgerCode,
                                    SupplierLedgerName      = Convert.ToString(dr["ACName"]).TrimEnd(),
                                    SupplierLedgerShortName = Convert.ToString(dr["Alt_name_1"]).TrimEnd(),
                                    SupplierLedgerShortDesc = Convert.ToString(dr["Alt_name_2"]).TrimEnd(),
                                    Address       = string.Concat(Convert.ToString(dr["ACAD1"]).TrimEnd(), " ", Convert.ToString(dr["ACAD2"]).TrimEnd(), " ", Convert.ToString(dr["ACAD3"]).TrimEnd()),
                                    ContactPerson = Convert.ToString(dr["ACAD4"]).TrimEnd(),
                                    Mobile        = Convert.ToString(dr["Mobile"]).TrimEnd(),
                                    //Pager = Convert.ToString(dr["Pager"]).TrimEnd(),
                                    //Fax = Convert.ToString(dr["Fax"]).TrimEnd(),
                                    OfficePhone    = Convert.ToString(dr["Telo"]).TrimEnd(),
                                    ResidentPhone  = Convert.ToString(dr["Telr"]).TrimEnd(),
                                    EmailAddress   = Convert.ToString(dr["Email"]).TrimEnd(),
                                    AreaId         = areaID,
                                    CreditDebit    = Convert.ToDecimal(dr["Abop"]) > 0 ? Convert.ToString(PharmaBusinessObjects.Common.Enums.TransType.D) : Convert.ToString(PharmaBusinessObjects.Common.Enums.TransType.C),
                                    DLNo           = "test", // Convert.ToString(dr["Stnol"]).TrimEnd(),
                                    OpeningBal     = Convert.ToDecimal(dr["Abop"]),
                                    TaxRetail      = Convert.ToString(dr["Vat"]).TrimEnd(),
                                    Status         = Convert.ToChar(dr["ACSTS"]) == '*' ? false : true,
                                    PurchaseTypeID = purchaseTypeID,
                                    CreatedBy      = "admin",
                                    CreatedOn      = DateTime.Now
                                };

                                listSupplierLedgerMaster.Add(newSupplierLedgerMaster);
                            }
                            catch (Exception)
                            {
                                log.Info("SuPPLIER LEDGER : Error in ACName --> " + Convert.ToString(dr["ACName"]).TrimEnd());
                            }
                        }
                    }

                    context.SupplierLedger.AddRange(listSupplierLedgerMaster);
                    _result = context.SaveChanges();

                    return(_result);
                }
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }