Example #1
0
        public DTO.EditFormData GetData(int userId, int id, out Library.DTO.Notification notification)
        {
            DTO.EditFormData editFormData = new DTO.EditFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            Module.Support.DAL.DataFactory   support_factory = new Support.DAL.DataFactory();
            Module.Framework.DAL.DataFactory fwFactory       = new Module.Framework.DAL.DataFactory();
            //Details
            editFormData.Data = new DTO.LabelingPackaging();
            editFormData.Data.LabelingPackagingDetails          = new List <DTO.LabelingPackagingDetail>();
            editFormData.Data.LabelingPackagingSparepartDetails = new List <DTO.LabelingPackagingSparepartDetail>();
            editFormData.Data.LabelingPackagingRemarks          = new List <DTO.LabelingPackagingRemark>();

            try
            {
                using (LPOverviewEntities context = CreateContext())
                {
                    if (id > 0)
                    {
                        LabelingPackagingMng_LabelingPackaging_View dbItem;
                        dbItem = context.LabelingPackagingMng_LabelingPackaging_View.FirstOrDefault(o => o.LabelingPackagingID == id);

                        //check permission on factory
                        int FactoryID = Convert.ToInt32(dbItem.FactoryID);
                        if (fwFactory.CheckFactoryPermission(userId, FactoryID) == 0)
                        {
                            throw new Exception("You do not have access permission on this factory");
                        }
                        editFormData.Data = converter.DB2DTO_LabelingPackaging(dbItem);
                    }
                    else
                    {
                        editFormData.Data = new DTO.LabelingPackaging();
                        editFormData.Data.LabelingPackagingDetails          = new List <DTO.LabelingPackagingDetail>();
                        editFormData.Data.LabelingPackagingSparepartDetails = new List <DTO.LabelingPackagingSparepartDetail>();
                        editFormData.Data.LabelingPackagingRemarks          = new List <DTO.LabelingPackagingRemark>();
                        editFormData.Data.LabelingPackagingOtherFiles       = new List <DTO.LabelingPackagingOtherFile>();
                    }
                    //editFormData.Factories = support_factory.GetFactory(userId);
                    return(editFormData);
                }
            }
            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(editFormData);
            }
        }
Example #2
0
        public DTO.EditFormData GetData(int userId, int id, out Library.DTO.Notification notification)
        {
            DTO.EditFormData editFormData = new DTO.EditFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            Module.Support.DAL.DataFactory   support_factory = new Support.DAL.DataFactory();
            Module.Framework.DAL.DataFactory fwFactory       = new Module.Framework.DAL.DataFactory();
            try
            {
                using (FactoryStockReceiptEntities context = CreateContext())
                {
                    //auto create production item
                    context.FactoryStockReceiptMng_function_CreateProductionItem();
                    if (id > 0)
                    {
                        FactoryStockReceiptMng_FactoryStockReceipt_View dbItem;
                        dbItem = context.FactoryStockReceiptMng_FactoryStockReceipt_View.FirstOrDefault(o => o.FactoryStockReceiptID == id);
                        //check permission on factory
                        if (fwFactory.CheckFactoryPermission(userId, dbItem.FactoryID.Value) == 0)
                        {
                            throw new Exception("You do not have access permission on this factory");
                        }
                        editFormData.Data = converter.DB2DTO_FactoryStockReceipt(dbItem);
                    }
                    else
                    {
                        editFormData.Data = new DTO.FactoryStockReceipt();
                        editFormData.Data.FactoryStockReceiptDetails = new List <DTO.FactoryStockReceiptDetail>();
                    }
                    editFormData.Factories = support_factory.GetFactory(userId);

                    return(editFormData);
                }
            }
            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(editFormData);
            }
        }
Example #3
0
        //
        // CUSTOM MODULES
        //
        public DTO.FactoryProformaInvoiceMng.EditFormData GetData(int userId, int id, int factoryId, string season, int factoryOrderId, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryProformaInvoiceMng.EditFormData data = new DTO.FactoryProformaInvoiceMng.EditFormData();
            data.Data         = new DTO.FactoryProformaInvoiceMng.FactoryProformaInvoice();
            data.Data.Details = new List <DTO.FactoryProformaInvoiceMng.FactoryProformaInvoiceDetail>();

            //try to get data
            try
            {
                // check permission
                if (id > 0 && fwFactory.CheckFactoryProformaInvoicePermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected proforma invoice data!");
                }

                if (id <= 0 && fwFactory.CheckFactoryPermission(userId, factoryId) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected factory data!");
                }

                if (id <= 0 && fwFactory.CheckFactoryOrderPermission(userId, factoryOrderId) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected factory order data!");
                }

                using (FactoryProformaInvoiceMngEntities context = CreateContext())
                {
                    if (id == 0)
                    {
                        data.Data.Season    = season;
                        data.Data.FactoryID = factoryId;
                        DTO.Support.Factory dtoFactory = supportFactory.GetFactory().FirstOrDefault(o => o.FactoryID == factoryId);
                        FactoryProformaInvoiceMng_FactoryOrderSearchResult_View dbFactoryOrder = context.FactoryProformaInvoiceMng_FactoryOrderSearchResult_View.FirstOrDefault(o => o.FactoryOrderID == factoryOrderId);
                        if (dtoFactory != null)
                        {
                            data.Data.FactoryUD = dtoFactory.FactoryUD;
                        }
                        else
                        {
                            throw new Exception("Factory not found!");
                        }

                        if (dbFactoryOrder != null)
                        {
                            data.Data.FactoryOrderID = factoryOrderId;
                            data.Data.FactoryOrderUD = dbFactoryOrder.FactoryOrderUD;

                            // get products
                            int index = -1;
                            foreach (FactoryProformaInvoiceMng_FactoryOrderItemSearchResult_View dbDetail in context.FactoryProformaInvoiceMng_FactoryOrderItemSearchResult_View.Where(o => o.FactoryOrderID == factoryOrderId))
                            {
                                data.Data.Details.Add(new DTO.FactoryProformaInvoiceMng.FactoryProformaInvoiceDetail()
                                {
                                    FactoryProformaInvoiceDetailID = index,
                                    FactoryOrderDetailID           = dbDetail.FactoryOrderDetailID,
                                    FactoryOrderSparepartDetailID  = dbDetail.FactoryOrderSparepartDetailID,
                                    ArticleCode      = dbDetail.ArticleCode,
                                    Description      = dbDetail.Description,
                                    ClientUD         = dbDetail.ClientUD,
                                    FactoryOrderUD   = dbDetail.FactoryOrderUD,
                                    LDS              = dbDetail.LDS.Value.ToString("dd/MM/yyyy"),
                                    OrderQnt         = dbDetail.OrderQnt,
                                    ProductionStatus = dbDetail.ProductionStatus,
                                    PurchasingPrice  = dbDetail.PurchasingPrice,
                                    Remark           = string.Empty,
                                    UnitPrice        = dbDetail.PurchasingPrice
                                });
                                index--;
                            }
                        }
                        else
                        {
                            throw new Exception("Factory order not found!");
                        }
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_FactoryProformaInvoice(context.FactoryProformaInvoiceMng_FactoryProformaInvoice_View.FirstOrDefault(o => o.FactoryProformaInvoiceID == id));
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Example #4
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryProductionStatusDTO dtoFactoryProductionStatus = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryProductionStatusDTO>();
            try
            {
                using (FactoryProductionStatusEntities context = CreateContext())
                {
                    FactoryProductionStatus dbItem = null;
                    if (id > 0)
                    {
                        dbItem = context.FactoryProductionStatus.Where(o => o.FactoryProductionStatusID == id).FirstOrDefault();
                        if (dbItem.WeekNo != dtoFactoryProductionStatus.WeekNo)
                        {
                            throw new Exception("You can not change week");
                        }
                    }
                    else
                    {
                        dbItem = new FactoryProductionStatus();
                        context.FactoryProductionStatus.Add(dbItem);
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //calculate Produced Cont for every order
                        decimal totalCont = 0;
                        foreach (var item in dtoFactoryProductionStatus.FactoryProductionStatusDetailDTOs)
                        {
                            totalCont = 0;
                            foreach (var sItem in item.FactoryProductionStatusOrderDetailDTOs)
                            {
                                if (sItem.Qnt40HC.HasValue && sItem.Qnt40HC != 0 && sItem.ProducedQnt.HasValue)
                                {
                                    sItem.ProducedCont = Math.Round(Convert.ToDecimal(sItem.ProducedQnt.Value) / Convert.ToDecimal(sItem.Qnt40HC), 2);
                                    totalCont         += Math.Round(Convert.ToDecimal(sItem.ProducedQnt.Value) / Convert.ToDecimal(sItem.Qnt40HC), 2);
                                }
                            }
                            item.ProducedContainerQnt = totalCont;
                        }
                        //convert dto to db
                        converter.DTO2DB_FactoryProductionStatus(dtoFactoryProductionStatus, ref dbItem);
                        dbItem.UpdatedBy = userId;
                        //check permission on factory
                        if (fwFactory.CheckFactoryPermission(userId, dbItem.FactoryID.Value) == 0)
                        {
                            throw new Exception("You do not have access permission on this factory");
                        }
                        //check week
                        //int curentWeek = Library.Helper.GetCurrentWeek();
                        //if (curentWeek - dbItem.WeekNo.Value >= 2)
                        //{
                        //    throw new Exception("You can not update because this week is over 2 weeks compare with current week (" + curentWeek.ToString() + " )");
                        //}
                        //remove orphan
                        context.FactoryProductionStatusDetail.Local.Where(o => o.FactoryProductionStatus == null).ToList().ForEach(o => context.FactoryProductionStatusDetail.Remove(o));
                        //save data
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.FactoryProductionStatusID, out notification).Data;

                        //auto create production item
                        context.FactoryStockReceiptMng_function_CreateProductionItem();

                        //get total output procduce all week
                        //List<int> factoryOrderDetailIDs = new List<int>();
                        //foreach (var item in dbItem.FactoryProductionStatusDetail.ToList())
                        //{
                        //    foreach (var sItem in item.FactoryProductionStatusOrderDetail.Where(o =>o.FactoryOrderDetailID.HasValue).ToList())
                        //    {
                        //        factoryOrderDetailIDs.Add(sItem.FactoryOrderDetailID.Value);
                        //    }
                        //}
                        //var factoryOrderDetails = from item in context.FactoryProductionStatusOrderDetail.Where(o =>factoryOrderDetailIDs.Contains(o.FactoryOrderDetailID.Value)).ToList()
                        //                         group item by new { item.FactoryOrderDetailID } into g
                        //                         select new { g.Key.FactoryOrderDetailID, TotalOutputProduced = g.Sum(o => o.OutputProducedQnt) };
                        ////var factoryStock = context.FactoryStockReceiptDetail.Where(o => o.FactoryOrderDetailID.HasValue && factoryOrderDetails.Select(s => s.FactoryOrderDetailID).Contains(o.FactoryOrderDetailID));
                        //foreach (var item in context.FactoryStockReceiptDetail.Where(o => o.FactoryOrderDetailID.HasValue && factoryOrderDetailIDs.Contains(o.FactoryOrderDetailID.Value)))
                        //{
                        //    var x = factoryOrderDetails.Where(o => o.FactoryOrderDetailID == item.FactoryOrderDetailID).FirstOrDefault();
                        //    if (x != null)
                        //    {
                        //        item.ProducedQnt = x.TotalOutputProduced;
                        //    }
                        //}
                        //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);
            }
        }
Example #5
0
        public bool UpdateData(int userId, object dtoItems, out Library.DTO.Notification notification)
        {
            List <DTO.FactoryQuotationSearchResultDTO> dtoOffers = ((Newtonsoft.Json.Linq.JArray)dtoItems).ToObject <List <DTO.FactoryQuotationSearchResultDTO> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            List <int> confirmedQuotationDetailIDs = new List <int>();

            try
            {
                //
                // check factory access permission
                //
                foreach (DTO.FactoryQuotationSearchResultDTO dtoOffer in dtoOffers)
                {
                    if (fwFactory.CheckFactoryPermission(userId, dtoOffer.FactoryID.Value) <= 0)
                    {
                        throw new Exception("You dont have permission for accessing factory data for [" + dtoOffer.FactoryUD + "]!");
                    }
                }

                using (FactoryQuotation2MngEntities context = CreateContext())
                {
                    // get similar item: same offerlineid, same factoryid
                    int[] existingIDs = dtoOffers.Where(o => o.NewPurchasingPrice.HasValue).Select(o => o.QuotationDetailID.Value).ToArray();
                    List <DTO.FactoryQuotationSearchResultDTO> additionalItems = new List <DTO.FactoryQuotationSearchResultDTO>();
                    foreach (DTO.FactoryQuotationSearchResultDTO dtoItem in dtoOffers.Where(o => o.NewPurchasingPrice.HasValue && o.OfferSeasonDetailID.HasValue && o.StatusID != 3).ToList())
                    {
                        additionalItems = converter.DB2DTO_SimilarItems(context.FactoryQuotation2Mng_SimilarItem_View.Where(o =>
                                                                                                                            !existingIDs.Contains(o.QuotationDetailID) &&
                                                                                                                            o.OfferSeasonDetailID == dtoItem.OfferSeasonDetailID &&
                                                                                                                            o.FactoryID == dtoItem.FactoryID &&
                                                                                                                            o.StatusID != 3).ToList());

                        if (additionalItems.Count() > 0)
                        {
                            additionalItems.ForEach(o => { o.NewPurchasingPrice = dtoItem.NewPurchasingPrice.Value; o.NewPurchasingComment = dtoItem.NewPurchasingComment; });
                            dtoOffers.AddRange(additionalItems);
                        }
                    }

                    foreach (DTO.FactoryQuotationSearchResultDTO dtoItem in dtoOffers.Where(o => o.NewPurchasingPrice.HasValue && o.QuotationStatusNM != "WAITING REJECT"))
                    {
                        QuotationDetail dbQuotationDetail = context.QuotationDetail.FirstOrDefault(o => o.QuotationDetailID == dtoItem.QuotationDetailID);
                        if (dbQuotationDetail == null)
                        {
                            throw new Exception("Quotation item: [" + dtoItem.ArticleCode + "] [" + dtoItem.FactoryUD + "] not found!");
                        }
                        var dbDiff = context.PriceDifference.FirstOrDefault(o => o.PriceDifferenceUD == dtoItem.PriceDifferenceCode && o.Season == dtoItem.Season);
                        if (dbDiff == null)
                        {
                            throw new Exception("Quality code: [" + dtoItem.PriceDifferenceCode + "] [" + dtoItem.Season + "] not found!");
                        }

                        dbQuotationDetail.PurchasingPrice  = dtoItem.NewPurchasingPrice.Value;
                        dbQuotationDetail.PriceUpdatedDate = DateTime.Now;
                        dbQuotationDetail.SalePrice        = dtoItem.NewPurchasingPrice.Value * (1 + Math.Round(dbDiff.Rate.Value / 100, 2, MidpointRounding.AwayFromZero));

                        // check if can confirm
                        if (dbQuotationDetail.TargetPrice == null)
                        {
                            dbQuotationDetail.TargetPrice = 0;
                        }
                        if (dbQuotationDetail.SalePrice == Math.Round(dbQuotationDetail.TargetPrice.Value / (1 + dbDiff.Rate.Value), 2, MidpointRounding.AwayFromZero))
                        {
                            dbQuotationDetail.StatusID          = 3; // confirm status;
                            dbQuotationDetail.StatusUpdatedBy   = userId;
                            dbQuotationDetail.StatusUpdatedDate = DateTime.Now;
                            //confirmedQuotationDetailIDs.Add(dbQuotationDetail.QuotationDetailID);
                            if (dbQuotationDetail.OfferSeasonQuotationRequestDetailID.HasValue)
                            {
                                confirmedQuotationDetailIDs.Add(dbQuotationDetail.QuotationDetailID);
                            }
                        }

                        QuotationOffer dbOffer = new QuotationOffer();
                        context.QuotationOffer.Add(dbOffer);
                        dbOffer.QuotationOfferVersion     = context.QuotationOffer.Count(o => o.QuotationID == dbQuotationDetail.QuotationID) + 1;
                        dbOffer.QuotationID               = dbQuotationDetail.QuotationID;
                        dbOffer.QuotationOfferDate        = DateTime.Now;
                        dbOffer.QuotationOfferDirectionID = 1;
                        dbOffer.UpdatedBy   = userId;
                        dbOffer.UpdatedDate = DateTime.Now;

                        QuotationOfferDetail dbOfferDetail = new QuotationOfferDetail();
                        dbOffer.QuotationOfferDetail.Add(dbOfferDetail);
                        dbOfferDetail.QuotationDetailID = dtoItem.QuotationDetailID;
                        dbOfferDetail.Price             = dtoItem.NewPurchasingPrice.Value;
                        if (!string.IsNullOrEmpty(dtoItem.NewPurchasingComment))
                        {
                            dbOfferDetail.Remark = dtoItem.NewPurchasingComment;
                        }
                    }

                    foreach (DTO.FactoryQuotationSearchResultDTO dtoItem in dtoOffers.Where(o => o.QuotationStatusNM == "WAITING REJECT"))
                    {
                        QuotationDetail dbQuotationDetail = context.QuotationDetail.FirstOrDefault(o => o.QuotationDetailID == dtoItem.QuotationDetailID);
                        if (dbQuotationDetail == null)
                        {
                            throw new Exception("Quotation item: [" + dtoItem.ArticleCode + "] [" + dtoItem.FactoryUD + "] not found!");
                        }

                        dbQuotationDetail.StatusID          = 5; //REJECTED
                        dbQuotationDetail.StatusUpdatedBy   = userId;
                        dbQuotationDetail.StatusUpdatedDate = DateTime.Now;

                        //reset data OfferSeasonDetail
                        context.FactoryQuotation2Mng_function_AfterUnConfirm(dtoItem.QuotationDetailID);
                    }
                    context.SaveChanges();

                    // update offer season planing purchasing price
                    foreach (int quotationDetailID in confirmedQuotationDetailIDs)
                    {
                        context.FW_function_UpdateOfferSeasonDetailPurchasingPriceFromQuotationConfirmed(quotationDetailID, userId);
                    }

                    // refresh cached data
                    foreach (DTO.FactoryQuotationSearchResultDTO dtoItem in dtoOffers.ToList())
                    {
                        context.FW_function_RefreshPriceCacheRow(dtoItem.Season, dtoItem.QuotationDetailID, null);
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Example #6
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryStockReceipt dtoFactoryStockReceipt = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryStockReceipt>();
            dtoFactoryStockReceipt.UpdatedBy = userId;
            Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory();
            try
            {
                using (FactoryStockReceiptEntities context = CreateContext())
                {
                    FactoryStockReceipt dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryStockReceipt();
                        context.FactoryStockReceipt.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactoryStockReceipt.Where(o => o.FactoryStockReceiptID == id).FirstOrDefault();
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //
                        if (!dtoFactoryStockReceipt.FactoryID.HasValue) // 2 : Export
                        {
                            throw new Exception("Factory is empty. You should fill-in factory");
                        }
                        //check permission on factory
                        if (fwFactory.CheckFactoryPermission(userId, dtoFactoryStockReceipt.FactoryID.Value) == 0)
                        {
                            throw new Exception("You do not have access permission on this factory");
                        }

                        //validate quantity
                        if (dtoFactoryStockReceipt.ReceiptTypeID == 1) //import
                        {
                            ValidateQntImport(dtoFactoryStockReceipt);
                        }
                        else if (dtoFactoryStockReceipt.ReceiptTypeID == 2)  //export
                        {
                            ValidateQntExport(dtoFactoryStockReceipt);
                        }

                        //convert dto to db
                        converter.DTO2DB_FactoryStockReceipt(dtoFactoryStockReceipt, ref dbItem);
                        //remove orphan item
                        context.FactoryStockReceiptDetail.Local.Where(o => o.FactoryStockReceipt == null).ToList().ForEach(o => context.FactoryStockReceiptDetail.Remove(o));
                        //save data
                        context.SaveChanges();
                        //update receipt no
                        context.FactoryStockReceiptMng_function_GenerateReceipNo(dbItem.FactoryStockReceiptID, dbItem.ReceiptTypeID);
                        //get return data
                        dtoItem = GetData(userId, dbItem.FactoryStockReceiptID, out notification).Data;
                        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);
            }
        }