Exemplo n.º 1
0
        public override bool DeleteData(int userId, int id, out Notification notification)
        {
            notification = new Library.DTO.Notification {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    var dbItem = context.FactorySaleInvoice.Where(o => o.FactorySaleInvoiceID == id).FirstOrDefault();
                    context.FactorySaleInvoice.Remove(dbItem);

                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
        public DTO.FactorySaleOrderSearchFromData GetFactorySaleOrderData(int userId, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            DTO.FactorySaleOrderSearchFromData data = new DTO.FactorySaleOrderSearchFromData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;
            try
            {
                string factorySaleOrderUD   = null;
                string documentDate         = null;
                string productionItemUD     = null;
                string productionItemNM     = null;
                int?   factoryRawMaterialID = null;

                if (filters.ContainsKey("factorySaleOrderUD") && !string.IsNullOrEmpty(filters["factorySaleOrderUD"].ToString()))
                {
                    factorySaleOrderUD = filters["factorySaleOrderUD"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("factorySaleOrderDate") && !string.IsNullOrEmpty(filters["factorySaleOrderDate"].ToString()))
                {
                    documentDate = filters["factorySaleOrderDate"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("productionItemUD") && !string.IsNullOrEmpty(filters["productionItemUD"].ToString()))
                {
                    productionItemUD = filters["productionItemUD"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("productionItemNM") && !string.IsNullOrEmpty(filters["productionItemNM"].ToString()))
                {
                    productionItemNM = filters["productionItemNM"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("factoryRawMaterialID") && !string.IsNullOrEmpty(filters["factoryRawMaterialID"].ToString()))
                {
                    factoryRawMaterialID = Convert.ToInt32(filters["factoryRawMaterialID"].ToString());
                }
                DateTime?valFactorySaleOrderDate = documentDate.ConvertStringToDateTime();
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    totalRows = context.FactorySaleInvoice_function_SearchFactorySaleOrderItem(orderBy, orderDirection, factorySaleOrderUD, valFactorySaleOrderDate, productionItemUD, productionItemNM, factoryRawMaterialID).Count();
                    var result = context.FactorySaleInvoice_function_SearchFactorySaleOrderItem(orderBy, orderDirection, factorySaleOrderUD, valFactorySaleOrderDate, productionItemUD, productionItemNM, factoryRawMaterialID).OrderByDescending(o => o.FactorySaleOrderUD).OrderByDescending(o => o.DocumentDate);
                    data.Data      = converter.DB2DTO_SearchFactorySaleOrderData(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                    data.TotalRows = totalRows;
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }
            return(data);
        }
        public List <DTO.PaymentTermDTO> GetSupplierPaymentTerm(int factoryRawMaterialID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            var dbItems = new List <FactorySaleInvoice_SupplierPaymentTerm_View>();

            using (FactorySaleInvoiceEntities context = CreateContext())
            {
                dbItems = context.FactorySaleInvoice_SupplierPaymentTerm_View.Where(o => o.FactoryRawMaterialID == factoryRawMaterialID).ToList();
            }
            return(AutoMapper.Mapper.Map <List <FactorySaleInvoice_SupplierPaymentTerm_View>, List <DTO.PaymentTermDTO> >(dbItems));
        }
        public List <DTO.ProductionItemDTO> GetProductionItem(int userId, Hashtable filters)
        {
            List <DTO.ProductionItemDTO> result = new List <DTO.ProductionItemDTO>();

            using (FactorySaleInvoiceEntities context = CreateContext())
            {
                Module.Framework.DAL.DataFactory fw_factory = new Framework.DAL.DataFactory();
                string searchQuery = filters["searchQuery"].ToString();
                int?   type        = Convert.ToInt32(filters["itemType"]);
                var    dbItems     = new List <FactorySaleInvoice_ProductionItem_View>();
                if (type == 0)
                {
                    dbItems = context.FactorySaleInvoice_ProductionItem_View.Where(o => (o.ProductionItemNM.Contains(searchQuery) || o.ProductionItemUD.Contains(searchQuery))).ToList();
                }
                if (type == 1)
                {
                    dbItems = context.FactorySaleInvoice_ProductionItem_View.Where(o => o.ProductionItemTypeID == 7 && (o.ProductionItemNM.Contains(searchQuery) || o.ProductionItemUD.Contains(searchQuery))).ToList();
                }
                return(AutoMapper.Mapper.Map <List <FactorySaleInvoice_ProductionItem_View>, List <DTO.ProductionItemDTO> >(dbItems));
            }
        }
Exemplo n.º 5
0
 public override EditFormData GetData(int userId, int id, Hashtable param, out Notification notification)
 {
     DTO.EditFormData editFormData = new DTO.EditFormData();
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     Module.Support.DAL.DataFactory supportFactory = new Support.DAL.DataFactory();
     try
     {
         using (FactorySaleInvoiceEntities context = CreateContext())
         {
             if (id > 0)
             {
                 var dbItem = context.FactorySaleInvoice_FactorySaleInvoice_View.Where(o => o.FactorySaleInvoiceID == id).FirstOrDefault();
                 editFormData.Data = converter.DB2DTO_FactorySaleInvoice(dbItem);
             }
             else
             {
                 //initialize
                 editFormData.Data.FactorySaleInvoiceStatusID = 1;
                 editFormData.Data.VAT         = 0;
                 editFormData.Data.InvoiceDate = DateTime.Now.ToString("dd/MM/yyyy");
                 editFormData.Data.PostingDate = DateTime.Now.ToString("dd/MM/yyyy");
             }
             //get support data
             editFormData.FactorySaleInvoiceStatus = AutoMapper.Mapper.Map <List <SupportMng_FactorySaleInvoiceStatus_View>, List <FactorySaleInvoiceStatusDTO> >(context.SupportMng_FactorySaleInvoiceStatus_View.ToList());
             editFormData.FactoryRawMaterialDTOs   = converter.DB2DTO_GetFactoryRawMaterial(context.SupportMng_SubSupplier_View.ToList());
             editFormData.PaymentTermDTOs          = AutoMapper.Mapper.Map <List <FactorySaleInvoice_SupplierPaymentTerm_View>, List <DTO.PaymentTermDTO> >(context.FactorySaleInvoice_SupplierPaymentTerm_View.Where(o => o.FactoryRawMaterialID == editFormData.Data.FactoryRawMaterialID).ToList());
             editFormData.Seasons = supportFactory.GetSeason();
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = Library.Helper.GetInnerException(ex).Message;
     }
     return(editFormData);
 }
        //Status
        public int SetFactorySaleInvoiceStatus(int userId, int factorySaleInvoiceID, int factorySaleInvoiceStatusID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int?oldFactorySaleInvoiceStatusID = null;

            try
            {
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    var purchaseInvoiceStatuses   = context.SupportMng_FactorySaleInvoiceStatus_View.ToList();
                    var currentFactorySaleInvoice = context.FactorySaleInvoice.Where(o => o.FactorySaleInvoiceID == factorySaleInvoiceID).FirstOrDefault();
                    oldFactorySaleInvoiceStatusID = currentFactorySaleInvoice.FactorySaleInvoiceStatusID;
                    Hashtable input = new Hashtable();
                    DTO.FactorySaleInvoiceDTO dtoItem = GetData(userId, currentFactorySaleInvoice.FactorySaleInvoiceID, input, out notification).Data;


                    //check valid status
                    int?oldDisplayOrder = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == oldFactorySaleInvoiceStatusID).FirstOrDefault().DisplayOrder;
                    int?newDisplayOrder = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().DisplayOrder;

                    if (newDisplayOrder <= oldDisplayOrder)
                    {
                        var checkinvoice = context.ReceiptNoteSaleInvoice.Where(o => o.FactorySaleInvoiceID == factorySaleInvoiceID).Count();
                        if (newDisplayOrder == 1 && oldDisplayOrder == 2 && checkinvoice == 0)
                        {
                            notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                            currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                            currentFactorySaleInvoice.UpdatedBy   = userId;
                            currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                            context.SaveChanges();
                        }
                        else
                        {
                            string currentStatusName = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == oldFactorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM;
                            string newStatusName     = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM;
                            if (checkinvoice > 0)
                            {
                                throw new Exception("Invoice has been created Receipt Note .Can not set status from " + currentStatusName + " to " + newStatusName);
                            }
                            else
                            {
                                throw new Exception("Can not set status from " + currentStatusName + " to " + newStatusName);
                            }
                        }
                    }
                    else
                    {
                        if (newDisplayOrder == 2)
                        {
                            notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                            currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                            //currentFactorySaleInvoice.SetStatusBy = userId;
                            //currentFactorySaleInvoice.SetStatusDate = DateTime.Now;
                            currentFactorySaleInvoice.UpdatedBy   = userId;
                            currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                            context.SaveChanges();
                        }
                        else
                        {
                            if (newDisplayOrder == 3)
                            {
                                notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                                currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                                //currentFactorySaleInvoice.SetStatusBy = userId;
                                //currentFactorySaleInvoice.SetStatusDate = DateTime.Now;
                                //currentFactorySaleInvoice.FinishDate = DateTime.Now;
                                currentFactorySaleInvoice.UpdatedBy   = userId;
                                currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                                context.SaveChanges();
                            }
                            else
                            {
                                notification.Message = purchaseInvoiceStatuses.Where(o => o.FactorySaleInvoiceStatusID == factorySaleInvoiceStatusID).FirstOrDefault().FactorySaleInvoiceStatusNM + " success !!!";
                                currentFactorySaleInvoice.FactorySaleInvoiceStatusID = factorySaleInvoiceStatusID;
                                //currentFactorySaleInvoice.SetStatusBy = userId;
                                //currentFactorySaleInvoice.SetStatusDate = DateTime.Now;
                                currentFactorySaleInvoice.UpdatedBy   = userId;
                                currentFactorySaleInvoice.UpdatedDate = DateTime.Now;
                                context.SaveChanges();
                            }
                        }
                    }
                    return(factorySaleInvoiceStatusID);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(oldFactorySaleInvoiceStatusID.Value);
            }
        }
Exemplo n.º 7
0
        public override SearchFormData GetDataWithFilter(int userId, Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Notification notification)
        {
            DTO.SearchFormData searchFormData = new DTO.SearchFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;
            Module.Support.DAL.DataFactory supportFactory = new Support.DAL.DataFactory();

            try
            {
                string DocCode              = null;
                string PostingDate          = null;
                int?   FactoryRawMaterialID = null;
                string InvoiceStatusID      = null;
                int?   InvoiceTypeID        = null;
                string Season   = null;
                string fromDate = null;
                string toDate   = null;

                if (filters.ContainsKey("docCode") && !string.IsNullOrEmpty(filters["docCode"].ToString()))
                {
                    DocCode = filters["docCode"].ToString().Replace("'", "''");
                }

                if (filters.ContainsKey("postingDate") && !string.IsNullOrEmpty(filters["postingDate"].ToString()))
                {
                    PostingDate = filters["postingDate"].ToString().Replace("'", "''");
                }

                if (filters.ContainsKey("factoryRawMaterialID") && filters["factoryRawMaterialID"] != null)
                {
                    FactoryRawMaterialID = Convert.ToInt32(filters["factoryRawMaterialID"]);
                }

                if (filters.ContainsKey("invoiceStatusID") && filters["invoiceStatusID"] != null)
                {
                    InvoiceStatusID = filters["invoiceStatusID"].ToString().Replace("'", "''");
                }

                if (filters.ContainsKey("invoiceTypeID") && filters["invoiceTypeID"] != null)
                {
                    InvoiceTypeID = Convert.ToInt32(filters["invoiceTypeID"]);
                }

                if (filters.ContainsKey("season") && filters["season"] != null)
                {
                    Season = filters["season"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("FromDate") && !string.IsNullOrEmpty(filters["FromDate"].ToString()))
                {
                    fromDate = filters["FromDate"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("ToDate") && !string.IsNullOrEmpty(filters["ToDate"].ToString()))
                {
                    toDate = filters["ToDate"].ToString().Replace("'", "''");
                }
                //DateTime? valInvoiceDate = InvoicedDate.ConvertStringToDateTime();
                DateTime?valpostingDate = PostingDate.ConvertStringToDateTime();

                DateTime?_fromDate = fromDate.ConvertStringToDateTime();
                DateTime?_toDate   = toDate.ConvertStringToDateTime();
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    var result1 = context.FactorySaleInvoice_function_SearchFactorySaleInvoice(DocCode, valpostingDate, FactoryRawMaterialID, InvoiceStatusID, InvoiceTypeID, Season, _fromDate, _toDate, orderBy, orderDirection).ToList();
                    totalRows = result1.Count();

                    searchFormData.TotalAmountDTO.totalAmountVND    = result1.Where(x => x.Currency == "VND").Sum(x => x.Amount);
                    searchFormData.TotalAmountDTO.totalAMountUSD    = result1.Where(x => x.Currency == "USD").Sum(x => x.Amount);
                    searchFormData.TotalAmountDTO.totalVATAmount    = result1.Sum(x => x.VATAmount);
                    searchFormData.TotalAmountDTO.totalAllAmountVND = searchFormData.TotalAmountDTO.totalVATAmount + searchFormData.TotalAmountDTO.totalAmountVND + (searchFormData.TotalAmountDTO.totalAMountUSD * result1[0].ExchangeRate);

                    //totalRows = context.FactorySaleInvoice_function_SearchFactorySaleInvoice(DocCode, valpostingDate, FactoryRawMaterialID, InvoiceStatusID, InvoiceTypeID, Season, _fromDate, _toDate, orderBy, orderDirection).Count();
                    var result = context.FactorySaleInvoice_function_SearchFactorySaleInvoice(DocCode, valpostingDate, FactoryRawMaterialID, InvoiceStatusID, InvoiceTypeID, Season, _fromDate, _toDate, orderBy, orderDirection);
                    searchFormData.Data = converter.DB2DTO_Search(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());

                    //get support list
                    searchFormData.FactorySaleInvoiceStatusDTOs = AutoMapper.Mapper.Map <List <SupportMng_FactorySaleInvoiceStatus_View>, List <DTO.FactorySaleInvoiceStatusDTO> >(context.SupportMng_FactorySaleInvoiceStatus_View.ToList());
                    //    //searchFormData.PurchaseInvoiceTypeDTOs = AutoMapper.Mapper.Map<List<SupportMng_PurchaseInvoiceType_View>, List<DTO.PurchaseInvoiceTypeDTO>>(context.SupportMng_PurchaseInvoiceType_View.ToList());
                    searchFormData.FactoryRawMaterialDTOs = AutoMapper.Mapper.Map <List <SupportMng_SubSupplier_View>, List <DTO.FactoryRawMaterialDTO> >(context.SupportMng_SubSupplier_View.ToList());
                    searchFormData.Seasons = supportFactory.GetSeason();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }
            return(searchFormData);
        }
Exemplo n.º 8
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactorySaleInvoiceDTO dtoFactorySaleInvoice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactorySaleInvoiceDTO>();
            try
            {
                using (FactorySaleInvoiceEntities context = CreateContext())
                {
                    FactorySaleInvoice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactorySaleInvoice();
                        context.FactorySaleInvoice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactorySaleInvoice.Where(o => o.FactorySaleInvoiceID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //upload file
                        Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory();
                        string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\";
                        if (dtoFactorySaleInvoice.File_HasChange.HasValue && dtoFactorySaleInvoice.File_HasChange.Value)
                        {
                            dtoFactorySaleInvoice.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoFactorySaleInvoice.File_NewFile, dtoFactorySaleInvoice.AttachedFile, dtoFactorySaleInvoice.FriendlyName);
                        }

                        //convert dto to db
                        converter.DTO2DB_FactorySaleInvoice(dtoFactorySaleInvoice, ref dbItem, userId);

                        if (id == 0)
                        {
                            dbItem.FactorySaleInvoiceStatusID = 1;
                            //dbItem.SetStatusBy = userId;
                            //dbItem.SetStatusDate = DateTime.Now;
                        }
                        //remove orphan
                        context.FactorySaleInvoiceDetail.Local.Where(o => o.FactorySaleInvoice == null).ToList().ForEach(o => context.FactorySaleInvoiceDetail.Remove(o));

                        //save data
                        context.SaveChanges();

                        //generate purchase invoice code
                        if (string.IsNullOrEmpty(dbItem.DocCode))
                        {
                            context.FactorySaleInvoice_function_GenerateFactorySaleInvoiceUD(dbItem.FactorySaleInvoiceID, dbItem.InvoiceDate.Value.Year, dbItem.InvoiceDate.Value.Month);
                        }

                        //get return data
                        dtoItem = GetData(userId, dbItem.FactorySaleInvoiceID, null, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(false);
            }
        }