Esempio n. 1
0
 private List <string> InsertRemainingImportedItems(int headerIserial, List <ImportedBankStatement> importedList, string company)
 {
     using (var entities = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         var           header = entities.TblBankStatHeaders.FirstOrDefault(ah => ah.Iserial == headerIserial);
         List <string> errors = new List <string>();
         try
         {
             foreach (var item in importedList)
             {
                 TblBankStatDetail detail = PrepareDetail(entities, header, item, errors);
                 if (detail != null)
                 {
                     // Add detail
                     header.TblBankStatDetails.Add(detail);
                 }
             }
             entities.SaveChanges();
             return(errors);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Esempio n. 2
0
        private List <BankStatMatchingModel> GetLedgerDetailForMatching(int headerId, string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var header = context.TblBankStatHeaders.Include(nameof(TblBankStatHeader.TblCurrency1)).FirstOrDefault(bs => bs.Iserial == headerId && !bs.MatchApproved);
                var query  = new List <BankStatMatchingModel>().AsQueryable();
                if (header != null)
                {
                    query = context.TblLedgerMainDetails.Where(v => v.TransDate <= header.ReconcileDate &&
                                                               (v.TblCurrency == header.TblCurrency || v.TblCurrency1.ExchangeRate == header.TblCurrency1.ExchangeRate) &&
                                                               v.TblJournalAccountType == 6 &&
                                                               v.EntityAccount == header.TblBank && !context.TblBankStatDetailTblLedgerDetails.Any(bsdld =>
                                                                                                                                                   bsdld.TblLedgerMainDetail == v.Iserial)).Select(bsd =>
                                                                                                                                                                                                   new BankStatMatchingModel()
                    {
                        IsLedger    = true,
                        Iserial     = bsd.Iserial,
                        IsChecked   = false,
                        DocDate     = bsd.TransDate ?? bsd.TblLedgerHeader1.DocDate,
                        Description = bsd.Description,
                        Amount      = bsd.DrOrCr ? bsd.Amount.Value : (bsd.Amount.Value * -1),
                        ChequeNo    = bsd.TblBankCheque1.Cheque,
                        DepositNo   = bsd.PaymentRef,
                    });
                }

                var result = query.ToList();
                //result.ForEach(r => r.Amount = Math.Round(r.Amount, roundFraction));
                return(result);
            }
        }
Esempio n. 3
0
        private List <BankStatMatchingModel> GetLedgerDetailMatchedByBankStatDetailId(
            int headerId, int bankStatDetailId, bool isChecked, string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var header = context.TblBankStatHeaders.First(bs => bs.Iserial == headerId);
                var query  = context.TblLedgerMainDetails.Where(v => v.TblJournalAccountType == 6 &&
                                                                v.EntityAccount == header.TblBank &&
                                                                context.TblBankStatDetailTblLedgerDetails.Any(bsdld =>
                                                                                                              bsdld.TblLedgerMainDetail == v.Iserial && bsdld.TblBankStatDetail == bankStatDetailId &&
                                                                                                              bsdld.TblBankStatDetail1.TblBankStatHeader == headerId)).Select(
                    bsd => new BankStatMatchingModel()
                {
                    IsLedger    = true,
                    Iserial     = bsd.Iserial,
                    IsChecked   = isChecked,
                    DocDate     = bsd.TransDate,
                    Description = bsd.Description,
                    Amount      = bsd.DrOrCr ? bsd.Amount.Value : (bsd.Amount.Value * -1),
                    ChequeNo    = bsd.TblBankCheque1.Cheque,
                    DepositNo   = bsd.PaymentRef,
                });

                var result = query.ToList();
                return(result);
            }
        }
Esempio n. 4
0
        private TblSalaryApprovalHeader UpdateOrInsertSalaryApprovalHeader(TblSalaryApprovalHeader newRow, int index, int userIserial, out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                try
                {
                    var oldRow = context.TblSalaryApprovalHeaders.FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        oldRow.StoreApproved = newRow.StoreApproved;
                        //foreach (var item in newRow.TblSalaryApprovalDetails.ToArray())
                        //{
                        //    // هشوف بقى الى اتعدل والجديد
                        //    int temp;
                        //    //headeriserial = item.TblSalaryApprovalHeader;
                        //    item.TblSalaryApprovalHeader1 = null;
                        //    item.TblSalaryApprovalHeader = newRow.Iserial;
                        //    UpdateOrInsertSalaryApprovalDetail(item, userIserial, 1, out temp,company);
                        //    item.TblSalaryApprovalHeader1Reference = null;
                        //}
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                    }
                    else// الهيدر ده جديد
                    {
                        context.TblSalaryApprovalHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex) { throw ex; }


                return(newRow);
            }
        }
Esempio n. 5
0
        private List <TblSalaryApprovalDetail> GetSalaryApprovalDetail(int skip, int take, int ledgerHeader, string sort, string filter, Dictionary <string, object> valuesObjects, out int fullCount, out List <TblEmployee> EmpList, string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                IQueryable <TblSalaryApprovalDetail> query;
                if (filter != null)
                {
                    filter = filter + " and it.TblSalaryApprovalHeader ==(@Group0)";
                    valuesObjects.Add("Group0", ledgerHeader);

                    var parameterCollection = SharedOperation.ConvertToParamters(valuesObjects);
                    fullCount = context.TblSalaryApprovalDetails.Where(filter, parameterCollection.ToArray()).Count();
                    query     = context.TblSalaryApprovalDetails.OrderBy(sort).Where(filter, parameterCollection.ToArray()).Skip(skip).Take(take);
                }
                else
                {
                    fullCount = context.TblSalaryApprovalDetails.Count(v => v.TblSalaryApprovalHeader == ledgerHeader);
                    query     = context.TblSalaryApprovalDetails.OrderBy(sort).Where(v => v.TblSalaryApprovalHeader == ledgerHeader).Skip(skip).Take(take);
                }

                List <int> intList = query.Select(x => x.TblEmployee).ToList();

                EmpList = context.TblEmployees.Where(x => intList.Contains(x.iserial)).ToList();


                return(query.ToList());
            }
        }
Esempio n. 6
0
 private TblBankStatHeader GetBankStatHeaderByIserial(int headerIserial, string company)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         return(context.TblBankStatHeaders.FirstOrDefault(ah => ah.Iserial == headerIserial));
     }
 }
Esempio n. 7
0
        private TblDyeingOrderInvoiceMarkupTransProd UpdateOrInsertDyeingOrderInvoiceMarkupTransProds(TblDyeingOrderInvoiceMarkupTransProd newRow, bool save, int index, out int outindex, string company)
        {
            outindex = index;
            using (var entity = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var entityrow = entity.Entities.Any(w => w.Iserial == newRow.TblMarkupProd && w.scope == 0 && w.TblJournalAccountType == 9 && w.AccountIserial != 0);

                if (!entityrow)
                {
                    newRow.Iserial = -1;
                    return(newRow);
                }
            }
            using (var entity = new WorkFlowManagerDBEntities())
            {
                newRow.TblMarkupProd1 = null;
                if (save)
                {
                    entity.TblDyeingOrderInvoiceMarkupTransProds.AddObject(newRow);
                }
                else
                {
                    var oldRow = (from e in entity.TblDyeingOrderInvoiceMarkupTransProds
                                  where e.Iserial == newRow.Iserial
                                  select e).SingleOrDefault();
                    if (oldRow != null)
                    {
                        SharedOperation.GenericUpdate(oldRow, newRow, entity);
                    }
                }
                entity.SaveChanges();
                return(newRow);
            }
        }
Esempio n. 8
0
 private TblStore GetUserDefaultStore(int user, string company, int tblStore)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         //var ccnewUserStore = context.TblUserWFMappings.FirstOrDefault(x => x.WFTblAuthUser == user).TblUser1.ActiveStore;
         var activeStore = context.TblStores.FirstOrDefault(x => x.iserial == tblStore);
         return(activeStore);
     }
 }
Esempio n. 9
0
        private List <TblBankTransactionType> GetLookUpBankTransactionType(string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                IQueryable <TblBankTransactionType> query;
                query = context.TblBankTransactionTypes;

                return(query.ToList());
            }
        }
Esempio n. 10
0
        private List <TblCurrencyTest> GetLookUpCurrency(string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                IQueryable <TblCurrencyTest> query;
                query = context.TblCurrencyTests;

                return(query.ToList());
            }
        }
Esempio n. 11
0
 private List <TblBankStatDetail> GetBankStatDetail(int skip, int take, int headerId, string company)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         var query = context.TblBankStatDetails.Include(nameof(TblBankStatDetail.TblBankStatHeader1
                                                               )).Where(v =>
                                                                        v.TblBankStatHeader == headerId).OrderBy(x => x.Iserial).Skip(skip).Take(take);
         var result = query.ToList();
         return(result);
     }
 }
Esempio n. 12
0
 private void DeleteBankStatByIserial(int headerIserial, string company)
 {
     using (var entities = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         var temp = entities.TblBankStatHeaders.FirstOrDefault(ah => ah.Iserial == headerIserial);
         if (temp != null)
         {
             entities.DeleteObject(temp);
         }
         entities.SaveChanges();
     }
 }
Esempio n. 13
0
 private int DeleteSalaryApprovalDetail(TblSalaryApprovalDetail row, int userIserial, string company)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         var oldRow = (from e in context.TblSalaryApprovalDetails
                       where e.Iserial == row.Iserial
                       select e).SingleOrDefault();
         if (oldRow != null)
         {
             context.DeleteObject(oldRow);
             context.SaveChanges();
         }
     }
     return(row.Iserial);
 }
Esempio n. 14
0
        private int DeleteBankStatHeader(TblBankStatHeader row, string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var oldRow = (from e in context.TblBankStatHeaders
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    context.DeleteObject(oldRow);
                }

                context.SaveChanges();
            }
            return(row.Iserial);
        }
Esempio n. 15
0
 public List <Models.Inv.AuthWarehouseModel> GetAuthJournalSetting(int userIserial, string company)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         return(context.TblJournalSettings.Select(w =>
                                                  new Models.Inv.AuthWarehouseModel()
         {
             WarehouseIserial = w.Iserial,
             WarehoseEname = w.Ename,
             WarehouseCode = w.Aname,
             IsGranted = context.TblAuthUserJournalSettings.Any(aw =>
                                                                aw.TblAuthUser == userIserial &&
                                                                aw.TblJournalSetting == w.Iserial)
         }).ToList());
     }
 }
Esempio n. 16
0
 private bool IsBankStatHeaderHasMatchedRows(int headerIserial, out int Iserial, string company)
 {
     Iserial = headerIserial;
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         var header = context.TblBankStatHeaders.Include(nameof(TblBankStatHeader.TblBankStatDetails)).FirstOrDefault(ah =>
                                                                                                                      ah.Iserial == headerIserial && ah.TblBankStatDetails.Any(d =>
                                                                                                                                                                               d.TblBankStatDetailTblLedgerDetails.Count > 0));
         if (header != null)
         {
             return(true);// header.TblBankStatDetails.Any(d =>
         }
         //d.TblBankStatDetailTblLedgerDetails.Count > 0);
         else
         {
             return(false);
         }
     }
 }
Esempio n. 17
0
 private bool InsertMatchedList(
     List <BankStatMatchingModel> BankStatDetailList,
     List <BankStatMatchingModel> LedgerDetailList,
     bool reload, out bool lastInsert, string company)
 {
     lastInsert = reload;
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         try
         {
             //var result = new List<BankStatMatchingModel>();
             foreach (var itemBankStat in BankStatDetailList)
             {
                 foreach (var itemLedger in LedgerDetailList)
                 {
                     //result.Add(itemLedger);
                     var newRec = new TblBankStatDetailTblLedgerDetail()
                     {
                         TblBankStatDetail   = itemBankStat.Iserial,
                         TblLedgerMainDetail = itemLedger.Iserial,
                     };
                     newRec.Amount = itemLedger.Amount;
                     if (itemBankStat.Amount > itemLedger.Amount)
                     {
                         newRec.Amount = itemLedger.Amount;
                     }
                     if (itemLedger.Amount > itemBankStat.Amount)
                     {
                         newRec.Amount = itemBankStat.Amount;
                     }
                     context.TblBankStatDetailTblLedgerDetails.AddObject(newRec);
                 }
                 //result.Add(itemBankStat);
             }
             context.SaveChanges();
         }
         catch (System.Exception)
         {
             throw;
         }
         return(true);// result;
     }
 }
Esempio n. 18
0
 private List <TblMarkup> GetTblMarkupProd(int skip, int take, string sort, string filter, Dictionary <string, object> valuesObjects, out int fullCount, string company)
 {
     using (var entity = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         IQueryable <TblMarkup> query;
         if (filter != null)
         {
             var parameterCollection = SharedOperation.ConvertToParamters(valuesObjects);
             fullCount = entity.TblMarkups.Where(filter, parameterCollection.ToArray()).Count();
             query     = entity.TblMarkups.Include("TblMarkupGroup1")
                         .Where(filter, parameterCollection.ToArray()).OrderBy(sort).Skip(skip).Take(take);
         }
         else
         {
             fullCount = entity.TblMarkups.Count();
             query     = entity.TblMarkups.Include("TblMarkupGroup1")
                         .OrderBy(sort).Skip(skip).Take(take);
         }
         return(query.ToList());
     }
 }
Esempio n. 19
0
        private List <BankStatMatchingModel> GetBankStatDetailMatched(int headerId, string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var query = context.TblBankStatDetails.Where(v =>
                                                             v.TblBankStatHeader == headerId && context.TblBankStatDetailTblLedgerDetails.Any(bsd =>
                                                                                                                                              bsd.TblBankStatDetail == v.Iserial)).Select(bsd => new BankStatMatchingModel()
                {
                    Iserial     = bsd.Iserial,
                    IsChecked   = false,
                    DocDate     = bsd.DocDate,
                    Description = bsd.Description,
                    Amount      = bsd.Amount,
                    ChequeNo    = bsd.ChequeNo,
                    DepositNo   = bsd.DepositNo,
                });

                var result = query.ToList();
                return(result);
            }
        }
Esempio n. 20
0
        private TblSalaryApprovalDetail UpdateOrInsertSalaryApprovalDetail(
            TblSalaryApprovalDetail newRow, int userIserial, int index, out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var oldRow = (from e in context.TblSalaryApprovalDetails
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    var result = SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    context.TblSalaryApprovalDetails.AddObject(newRow);
                }

                context.SaveChanges();
                return(newRow);
            }
        }
Esempio n. 21
0
        private TblBankStatDetail UpdateOrInsertBankStatDetail(TblBankStatDetail newRow, int index, out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var oldRow = (from e in context.TblBankStatDetails
                              where e.Iserial == newRow.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                    SharedOperation.GenericUpdate(oldRow, newRow, context);
                }
                else
                {
                    context.TblBankStatDetails.AddObject(newRow);
                }

                context.SaveChanges();
                return(newRow);
            }
        }
Esempio n. 22
0
 public void SaveAuthJournalSetting(int userIserial, string company,
                                    List <Models.Inv.AuthWarehouseModel> authList)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         var curruntAuthList = context.TblAuthUserJournalSettings.Where(aw =>
                                                                        aw.TblAuthUser == userIserial).ToList();
         foreach (var item in curruntAuthList)
         {
             context.DeleteObject(item);
         }
         var itemsToAdd = authList.Where(a => a.IsGranted);// &&
         foreach (var item in itemsToAdd)
         {
             context.TblAuthUserJournalSettings.AddObject(new TblAuthUserJournalSetting()
             {
                 TblJournalSetting = item.WarehouseIserial,
                 TblAuthUser       = userIserial,
             });
         }
         context.SaveChanges();
     }
 }
Esempio n. 23
0
 public tblCalliopeStoresDailySale SaveStoreDailySales(int user, string company, tblCalliopeStoresDailySale newrow)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         //if(newrow.Iserial == 0)
         //{
         newrow.CreatedBy    = user;
         newrow.CreationDate = DateTime.Now;
         context.tblCalliopeStoresDailySales.AddObject(newrow);
         //}
         //else
         //{
         //    var oldRow = context.tblCalliopeStoresDailySales.FirstOrDefault(x => x.Iserial == newrow.Iserial);
         //    oldRow.SalesAmount = newrow.SalesAmount;
         //    oldRow.LastUpdatedBy = user;
         //    oldRow.LastUpdatedDate = DateTime.Now;
         //    context.tblCalliopeStoresDailySales.AddObject(newrow);
         //}
         context.SaveChanges();
         var res = context.tblCalliopeStoresDailySales.FirstOrDefault(x => x.Iserial == newrow.Iserial);
         return(res);
     }
 }
Esempio n. 24
0
 private List <TblSalaryApprovalHeader> GetSalaryApprovalHeader(int skip, int take, string sort, string filter,
                                                                Dictionary <string, object> valuesObjects, int userIserial, out int fullCount, string company)
 {
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         IQueryable <TblSalaryApprovalHeader> query;
         if (filter != null)
         {
             //filter = filter + " and it.Code LIKE(@Code0)";
             //valuesObjects.Add("Code0", accCode);
             var parameterCollection = SharedOperation.ConvertToParamters(valuesObjects);
             fullCount = context.TblSalaryApprovalHeaders
                         .Where(filter, parameterCollection.ToArray()).Count();
             query = context.TblSalaryApprovalHeaders.Include(nameof(TblSalaryApprovalHeader.TblStore1)).Include(nameof(TblSalaryApprovalHeader.TblSalaryType1))
                     .Where(filter, parameterCollection.ToArray()).OrderBy(sort).Skip(skip).Take(take);
         }
         else
         {
             fullCount = context.TblSalaryApprovalHeaders.Count();
             query     = context.TblSalaryApprovalHeaders.Include(nameof(TblSalaryApprovalHeader.TblStore1)).Include(nameof(TblSalaryApprovalHeader.TblSalaryType1)).OrderBy(sort).Skip(skip).Take(take);
         }
         return(query.ToList());
     }
 }
Esempio n. 25
0
 private bool RemoveMatchedList(
     List <BankStatMatchingModel> BankStatDetailList,
     List <BankStatMatchingModel> LedgerDetailList,
     bool reload, out bool lastInsert, string company)
 {
     lastInsert = reload;
     using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
     {
         foreach (var itemBankStat in BankStatDetailList)
         {
             foreach (var itemLedger in LedgerDetailList)
             {
                 var tempRec = context.TblBankStatDetailTblLedgerDetails.FirstOrDefault(dl =>
                                                                                        dl.TblBankStatDetail == itemBankStat.Iserial &&
                                                                                        dl.TblLedgerMainDetail == itemLedger.Iserial);
                 if (tempRec != null)
                 {
                     context.DeleteObject(tempRec);
                 }
             }
         }
         return(context.SaveChanges() > 0);
     }
 }
Esempio n. 26
0
        private int InsertImportedItems(TblBankStatHeader header,
                                        List <ImportedBankStatement> importedList, string company)
        {
            List <string> errors = new List <string>();

            using (var entities = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                try
                {
                    header.Approved = false;
                    foreach (var item in importedList)
                    {
                        TblBankStatDetail detail = PrepareDetail(entities, header, item, errors);
                        if (detail != null)
                        {
                            header.TblBankStatDetails.Add(detail);
                        }
                    }

                    header.TblBank1     = null;
                    header.TblCurrency1 = null;

                    header.CreationDate   = DateTime.Now;
                    header.LastChangeDate = DateTime.Now;
                    header.LastChangeUser = header.CreatedBy;

                    entities.TblBankStatHeaders.AddObject(header);
                    entities.SaveChanges();
                    return(header.Iserial);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 27
0
        private List <TblBankStatHeader> GetBankStatHeader(int skip, int take, string sort, string filter, Dictionary <string, object> valuesObjects,
                                                           out int fullCount, string company)
        {
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                var defaultQuery = context.TblBankStatHeaders.Include(
                    nameof(TblBankStatHeader.TblBank1)).Include(
                    nameof(TblBankStatHeader.TblCurrency1));
                IQueryable <TblBankStatHeader> query;
                if (filter != null)
                {
                    var parameterCollection = SharedOperation.ConvertToParamters(valuesObjects);

                    fullCount = defaultQuery.Where(filter, parameterCollection.ToArray()).Count();
                    query     = defaultQuery.Where(filter, parameterCollection.ToArray()).OrderBy(sort);
                }
                else
                {
                    fullCount = defaultQuery.Count();
                    query     = defaultQuery.OrderBy(sort);
                }
                return(query.Skip(skip).Take(take).ToList());
            }
        }
Esempio n. 28
0
        private List <TblContractHeader> GetContractHeader(int skip, int take, string sort, string filter,
                                                           Dictionary <string, object> valuesObjects, int userIserial, out int fullCount, string company)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                context.CommandTimeout = 0;

                var defaultQuery = context.TblContractHeaders.Include(
                    nameof(TblContractHeader.TblLkpSeason1)).Include(
                    nameof(TblContractHeader.TblLkpBrandSection1)).Include(
                    nameof(TblContractHeader.TblSubContractor1));
                IQueryable <TblContractHeader> query;
                if (valuesObjects == null)
                {
                    valuesObjects = new Dictionary <string, object>();
                }
                var    styleCodeFilter = valuesObjects.Where(o => o.Key.StartsWith("TblContractDetails_TblSalesOrderColor1_TblSalesOrder1_TblStyle1_StyleCode"));
                string styleCode       = string.Empty;
                if (styleCodeFilter.Count() > 0)
                {
                    styleCode = styleCodeFilter.ElementAt(0).Value.ToString().Replace("%", "");
                    styleCodeFilter.ToArray().ForEach(f =>
                    {
                        valuesObjects.Remove(f.Key);
                        filter = filter.Replace(
                            string.Format("it.TblContractDetails.TblSalesOrderColor1.TblSalesOrder1.TblStyle1.StyleCode LIKE(@{0})",
                                          f.Key), "");
                    });
                    filter = filter.Trim();
                    if (filter.ToLower().StartsWith("and"))
                    {
                        filter = filter.Remove(0, 3);
                    }
                    if (filter.ToLower().EndsWith("and"))
                    {
                        filter = filter.Remove(filter.Length - 3 - 1, 3);
                    }
                }
                if (!string.IsNullOrWhiteSpace(filter))
                {
                    filter = SharedOperation.GetBrandPerUser(filter, valuesObjects, userIserial, context)
                             .Replace("it.Brand", "it.BrandCode").Replace("it.BrandCodeCode", "it.BrandCode");
                    var parameterCollection = SharedOperation.ConvertToParamters(valuesObjects);
                    //var parameterCollection = valuesObjects.Select(valuesObject => new System.Data.Objects.ObjectParameter(valuesObject.Key, valuesObject.Value)).ToList();
                    fullCount = defaultQuery.Where(filter, parameterCollection.ToArray()).Count();
                    query     = defaultQuery.Where(filter, parameterCollection.ToArray()).OrderBy(sort);
                }
                else
                {
                    fullCount = defaultQuery.Count(x =>
                                                   x.TblLkpBrandSection1.TblUserBrandSections.Any(
                                                       e => e.TblAuthUser == userIserial && e.BrandCode == x.BrandCode));
                    query = defaultQuery.OrderBy(sort).Where(
                        x =>
                        x.TblLkpBrandSection1.TblUserBrandSections.Any(
                            e => e.TblAuthUser == userIserial && e.BrandCode == x.BrandCode));
                }

                List <TblContractHeader> result;
                if (!string.IsNullOrWhiteSpace(styleCode))
                {
                    query = query.Where(r =>
                                        r.TblContractDetails.Any(d => d.TblSalesOrderColor1.TblSalesOrder1.TblStyle1.StyleCode.Contains(styleCode)));
                    fullCount = query.Count();
                    try
                    {
                        //    var sql = ((System.Data.Objects.ObjectQuery)query).ToTraceString();

                        //result = query.AsNoTracking().ToList();
                        result = query.ToList();
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
                else
                {
                    result = query.Skip(skip).Take(take).ToList();
                }
                var db = new ccnewEntities(SharedOperation.GetSqlConnectionString(company));
                foreach (var item in result)
                {
                    item.Supplier = db.TBLsuppliers.FirstOrDefault(s => s.Iserial == item.SupplierIserial);
                    item.Currency = db.TblCurrencyTests.FirstOrDefault(c => c.Iserial == item.TblCurrency);
                }
                return(result);
            }
        }
Esempio n. 29
0
        private TblContractHeader UpdateOrInsertContractHeader(TblContractHeader newRow, int index, int userIserial, out int outindex, string company)
        {
            throw new Exception("Save Contracts On Stitch");

            outindex = index;
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    newRow.TblRetailOrderProductionType1 = null;
                    newRow.TblSubContractor1             = null;
                    newRow.TblLkpSeason1       = null;
                    newRow.TblLkpBrandSection1 = null;
                    var brandCode = newRow.BrandCode;
                    var report    = context.TblBrandContractReports.FirstOrDefault(bcr => bcr.BrandCode == brandCode);
                    if (report != null)
                    {
                        newRow.ContractReport = report.ReportName;
                    }
                    var oldRow = context.TblContractHeaders.FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    newRow.Amount = newRow.TblContractDetails.Sum(r => r.Total);



                    var budgetAmount = CalculateBudget(newRow, context);

                    var contractsAmount = context.TblContractDetails
                                          .Include(nameof(TblContractDetail.TblContractHeader1)).Where(r =>
                                                                                                       r.TblContractHeader1.BrandCode == newRow.BrandCode && r.TblLkpBrandSection == newRow.TblLkpBrandSection &&
                                                                                                       r.TblContractHeader1.TblLkpSeason == newRow.TblLkpSeason).ToList()
                                          .Select(r => new Tuple <int?, decimal>(r.TblLkpBrandSection,
                                                                                 r.TblContractHeader1.TblRetailOrderProductionType == 1 ?
                                                                                 (r.Qty * r.Cost) : r.TblContractHeader1.TblRetailOrderProductionType == 2 ?
                                                                                 (r.Qty * (r.Cost - r.AccCost)) : r.TblContractHeader1.TblRetailOrderProductionType == 3 ?
                                                                                 (r.Qty * (r.Cost - r.AccCost - r.FabricCost)) : (r.Qty * r.Cost)
                                                                                 )).GroupBy(r => r.Item1).Select(r => new Tuple <int?, decimal>(r.Key, r.Sum(d => d.Item2))).ToList();

                    var tblContractDetail = new List <TblContractDetail>();
                    newRow.TblContractDetails.ToArray().ForEach(d => tblContractDetail.Add(d));
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        CheckBudget(newRow, oldRow, budgetAmount, contractsAmount);

                        if (!oldRow.Approved && newRow.Approved)// كده لسه معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        foreach (var item in newRow.TblContractDetails.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp;
                            //headeriserial = item.TblContractHeader;
                            item.TblContractHeader1 = null;
                            item.TblContractHeader  = newRow.Iserial;
                            UpdateOrInsertContractDetail(item, userIserial, 1, out temp);
                            item.TblContractHeader1Reference = null;
                        }
                        foreach (var item in newRow.TblContractPaymentByPeriods.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp;
                            item.TblContractHeader1 = null;
                            item.TblContractHeader  = newRow.Iserial;
                            UpdateOrInsertContractPaymentDetail(item, userIserial, 1, out temp);
                            item.TblContractHeader1Reference = null;
                        }
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        var result = SharedOperation.GenericUpdate(oldRow, newRow, context);
                        if (result.Count() > 0)
                        {
                            newRow.LastChangeUser = userIserial;
                            newRow.LastChangeDate = DateTime.Now;
                        }
                    }
                    else// الهيدر ده جديد
                    {
                        CheckBudget(newRow, null, budgetAmount, contractsAmount);

                        var seqTo  = 443;//context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailTo");
                        var seqRow = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == seqTo);
                        newRow.Code = SharedOperation.HandelSequence(seqRow);
                        if (newRow.Approved)// كده معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        newRow.TblContractDetails.ForEach(cd => {
                            cd.TblColor1 = null; cd.TblSalesOrderColor1 = null;
                            cd.CreatedBy = userIserial; cd.CreationDate = DateTime.Now;
                        });
                        newRow.TblContractPaymentByPeriods.ForEach(cd => {
                            cd.CreatedBy = userIserial; cd.CreationDate = DateTime.Now;
                        });

                        if (newRow.TblContractDetails.FirstOrDefault() != null)
                        {
                            newRow.TblLkpBrandSection = newRow.TblContractDetails.FirstOrDefault().TblLkpBrandSection;
                        }

                        //   newRow.TblLkpBrandSection = null;
                        newRow.CreatedBy      = userIserial;
                        newRow.CreationDate   = DateTime.Now;
                        newRow.LastChangeDate = DateTime.Now;
                        newRow.LastChangeUser = userIserial;

                        context.TblContractHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex) { throw ex; }
                TblContractHeader rowTemp = newRow.Clone();
                try
                {
                    if (newRow.Approved)
                    {
                        try
                        {
                            var emailTo      = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailTo");
                            var emailFrom    = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailFrom");
                            var emailBody    = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailBody");
                            var emailSubject = context.tblChainSetups.FirstOrDefault(s => s.sGlobalSettingCode == "ContractApproveEmailSubject");
                            if (emailTo != null && emailFrom != null && emailBody != null &&
                                emailSubject != null &&
                                //!emailTo.sSetupValue.Split(';').Any(e => !SharedOperation.IsValidEmail(e)) &&
                                SharedOperation.IsValidEmail(emailFrom.sSetupValue))
                            {
                                string storeMail = emailTo.sSetupValue;
                                SharedOperation.SendEmail(null, emailFrom.sSetupValue,
                                                          emailTo.sSetupValue.Split(';').ToList(), string.Format(emailSubject.sSetupValue,
                                                                                                                 newRow.Code), string.Format(emailBody.sSetupValue, newRow.Code));
                            }
                        }
                        catch (Exception ex) { }
                    }
                    foreach (var item in GetContractDetail(0, int.MaxValue, newRow.Iserial))
                    {
                        var tblContractDetail = item.Clone();
                        tblContractDetail.TblLkpBrandSection1 = item.TblLkpBrandSection1;
                        tblContractDetail.TblSalesOrderColor1 = item.TblSalesOrderColor1;
                        rowTemp.TblContractDetails.Add(tblContractDetail);
                    }
                    foreach (var item in GetContractPaymentDetail(0, int.MaxValue, newRow.Iserial))
                    {
                        var tblContractPaymentByPeriod = item.Clone();
                        rowTemp.TblContractPaymentByPeriods.Add(tblContractPaymentByPeriod);
                    }
                    using (var db = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
                    {
                        rowTemp.Supplier = db.TBLsuppliers.FirstOrDefault(s => s.Iserial == newRow.SupplierIserial);
                        rowTemp.Currency = db.TblCurrencyTests.FirstOrDefault(c => c.Iserial == rowTemp.TblCurrency);
                    }
                }
                catch { }
                return(rowTemp);
            }
        }
Esempio n. 30
0
        private TblBankStatHeader UpdateOrInsertBankStatHeader(TblBankStatHeader newRow, int index, int userIserial,
                                                               out int outindex, string company)
        {
            outindex = index;
            using (var context = new ccnewEntities(SharedOperation.GetSqlConnectionString(company)))
            {
                try
                {
                    newRow.TblBank1     = null;
                    newRow.TblCurrency1 = null;
                    var oldRow = context.TblBankStatHeaders.Include(nameof(TblBankStatHeader.TblBankStatDetails)).FirstOrDefault(th => th.Iserial == newRow.Iserial);
                    if (oldRow != null)// الهيدر موجود قبل كده
                    {
                        newRow.LastChangeUser = userIserial;
                        newRow.LastChangeDate = DateTime.Now;
                        if (!oldRow.MatchApproved && newRow.MatchApproved)// كده لسه معموله ابروف
                        {
                            newRow.MatchApproveDate = DateTime.Now;
                            newRow.MatchApprovedBy  = userIserial;
                        }
                        if (!oldRow.Approved && newRow.Approved)// كده لسه معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        foreach (var item in newRow.TblBankStatDetails.ToArray())
                        {
                            // هشوف بقى الى اتعدل والجديد
                            int temp, headeriserial;
                            headeriserial           = item.TblBankStatHeader;
                            item.TblBankStatHeader1 = null;
                            item.TblBankStatHeader  = headeriserial;
                            UpdateOrInsertBankStatDetail(item, 1, out temp, company);
                            item.TblBankStatHeader1 = newRow;
                        }
                        //context.Entry(oldRow).CurrentValues.SetValues(newRow);
                        SharedOperation.GenericUpdate(oldRow, newRow, context);
                    }
                    else// الهيدر ده جديد
                    {
                        if (newRow.MatchApproved)// كده معموله ابروف
                        {
                            newRow.MatchApproveDate = DateTime.Now;
                            newRow.MatchApprovedBy  = userIserial;
                        }
                        if (newRow.Approved)// كده معموله ابروف
                        {
                            newRow.ApproveDate = DateTime.Now;
                            newRow.ApprovedBy  = userIserial;
                        }
                        newRow.CreatedBy      = userIserial;
                        newRow.CreationDate   = DateTime.Now;
                        newRow.LastChangeDate = DateTime.Now;
                        newRow.LastChangeUser = userIserial;

                        context.TblBankStatHeaders.AddObject(newRow);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex) { throw ex; }
                return(newRow);
            }
        }