示例#1
0
        public bool Revise(int saleOrderID, ref object dtoItem, int setStatusBy, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "PI has been revised success"
            };
            DTO.SaleOrder dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SaleOrder>();
            try
            {
                //SAVE DATA
                Library.DTO.Notification save_nofication = new Library.DTO.Notification {
                    Type = Library.DTO.NotificationType.Success
                };
                if (!UpdateData(setStatusBy, saleOrderID, ref dtoItem, out save_nofication))
                {
                    notification = save_nofication;
                    return(false);
                }

                //VALIDATE && CONFIRM
                using (SaleOrderMngEntities context = CreateContext())
                {
                    SaleOrderStatus dbSaleOrderStatus = context.SaleOrderStatus.Where(o => o.SaleOrderID == saleOrderID && o.IsCurrentStatus == true).FirstOrDefault();
                    if (dbSaleOrderStatus.TrackingStatusID != Library.Helper.CONFIRMED && dbSaleOrderStatus.TrackingStatusID != Library.Helper.REVISION_CONFIRMED)
                    {
                        notification = new Library.DTO.Notification()
                        {
                            Message = "PI must be in CONFIRMED status before revise", Type = Library.DTO.NotificationType.Warning
                        };
                        return(false);
                    }

                    SetPIStatus(saleOrderID, Library.Helper.REVISED, setStatusBy);
                    dtoItems.TrackingStatusNM = Library.Helper.TEXT_STATUS_REVISED;
                    dtoItems.TrackingStatusID = Library.Helper.REVISED;

                    // add item to quotation if needed
                    context.FW_Quotation_function_AddFactoryOrderItem(null, saleOrderID, null); // table lockx and also check if item is available on sql server side

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }
示例#2
0
        private void SetPIStatus(int saleOrderID, int trackingStatusID, int setStatusBy)
        {
            using (SaleOrderMngEntities context = CreateContext())
            {
                foreach (SaleOrderStatus item in context.SaleOrderStatus.Where(o => o.SaleOrderID == saleOrderID))
                {
                    item.IsCurrentStatus = false;
                }

                SaleOrderStatus dbStatus = new SaleOrderStatus();
                dbStatus.SaleOrderID      = saleOrderID;
                dbStatus.TrackingStatusID = trackingStatusID;
                dbStatus.StatusDate       = DateTime.Now;
                dbStatus.UpdatedBy        = setStatusBy;
                dbStatus.IsCurrentStatus  = true;
                context.SaleOrderStatus.Add(dbStatus);

                context.SaveChanges();

                //// add item to quotation if needed
                //context.FW_Quotation_function_AddFactoryOrderItem(null, saleOrderID, null); // table lockx and also check if item is available on sql server side
            }
        }
示例#3
0
        public bool DeletePI(int id, int deletedBy, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "PI has been deleted"
            };
            try
            {
                using (SaleOrderMngEntities context = CreateContext())
                {
                    SaleOrderStatus dbStatus = context.SaleOrderStatus.Where(o => o.SaleOrderID == id && o.IsCurrentStatus == true).FirstOrDefault();
                    if (dbStatus.TrackingStatusID == Library.Helper.CONFIRMED || dbStatus.TrackingStatusID == Library.Helper.REVISION_CONFIRMED)
                    {
                        throw new Exception("PI was confirmed. You can not delete");
                    }

                    if (dbStatus.TrackingStatusID == Library.Helper.REVISED)
                    {
                        throw new Exception("PI was revised. You can not delete");
                    }

                    context.SaleOrderMng_function_DeleteSaleOrder(id, deletedBy);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }
示例#4
0
        public bool Confirm(int saleOrderID, ref object dtoItem, int setStatusBy, bool isConfirmWithoutSigned, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "PI has been confirmed success"
            };
            DTO.SaleOrder dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SaleOrder>();
            try
            {
                //SAVE DATA
                Library.DTO.Notification save_nofication = new Library.DTO.Notification {
                    Type = Library.DTO.NotificationType.Success
                };
                if (!UpdateData(setStatusBy, saleOrderID, ref dtoItem, out save_nofication))
                {
                    notification = save_nofication;
                    return(false);
                }

                //VALIDATE && CONFIRM
                using (SaleOrderMngEntities context = CreateContext())
                {
                    SaleOrder   dbSaleOrder   = context.SaleOrder.Where(o => o.SaleOrderID == saleOrderID).FirstOrDefault();
                    OfferStatus dbOfferStatus = context.OfferStatus.Where(o => o.OfferID == dbSaleOrder.OfferID && o.IsCurrentStatus == true).FirstOrDefault();

                    if (dbOfferStatus.TrackingStatusID != Library.Helper.CONFIRMED && dbOfferStatus.TrackingStatusID != Library.Helper.REVISION_CONFIRMED)
                    {
                        notification = new Library.DTO.Notification()
                        {
                            Message = "Offer must be in CONFIRMED status before confirm PI", Type = Library.DTO.NotificationType.Warning
                        };
                        return(false);
                    }
                    else if (isConfirmWithoutSigned)
                    {
                        if (string.IsNullOrEmpty(dbSaleOrder.PIReceivedRemark))
                        {
                            notification = new Library.DTO.Notification()
                            {
                                Message = "PI must be filled-in [Signed PI Remark] before confirm", Type = Library.DTO.NotificationType.Warning
                            };
                            return(false);
                        }
                    }
                    else
                    {
                        if (dbSaleOrder.IsPIReceived == null || dbSaleOrder.IsPIReceived == false)
                        {
                            notification = new Library.DTO.Notification()
                            {
                                Message = "PI must be check [Signed PI Received] before confirm", Type = Library.DTO.NotificationType.Warning
                            };
                            return(false);
                        }
                    }

                    SaleOrderStatus dbSaleOrderStatus = context.SaleOrderStatus.Where(o => o.SaleOrderID == saleOrderID && o.IsCurrentStatus == true).FirstOrDefault();
                    if (dbSaleOrderStatus.TrackingStatusID != Library.Helper.REVISED && dbSaleOrderStatus.TrackingStatusID != Library.Helper.CREATED)
                    {
                        notification = new Library.DTO.Notification()
                        {
                            Message = "PI must be in REVISED/CREATED status before confirm", Type = Library.DTO.NotificationType.Warning
                        };
                        return(false);
                    }
                    //set tracking status
                    int TrackingStatusID = (dbSaleOrderStatus.TrackingStatusID == Library.Helper.CREATED ? Library.Helper.CONFIRMED : Library.Helper.REVISION_CONFIRMED);
                    SetPIStatus(saleOrderID, TrackingStatusID, setStatusBy);

                    //frozend PI printout data
                    context.SaleOrderMng_function_FrozenSaleOrderPrintoutData(saleOrderID);
                    //get back data
                    dtoItems.TrackingStatusNM = (dbSaleOrderStatus.TrackingStatusID == Library.Helper.CREATED ? Library.Helper.TEXT_STATUS_CONFIRMED : Library.Helper.TEXT_STATUS_REVISION_CONFIRMED);
                    dtoItems.TrackingStatusID = TrackingStatusID;

                    //// add item to quotation if needed
                    //context.FW_Quotation_function_AddFactoryOrderItem(null, saleOrderID, null); // table lockx and also check if item is available on sql server side

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }
示例#5
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification      = new Notification();
            notification.Type = NotificationType.Success;
            DTO.SaleOrder dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SaleOrder>();
            try
            {
                using (SaleOrderMngEntities context = CreateContext())
                {
                    SaleOrder       dbItem   = null;
                    SaleOrderStatus dbStatus = null;
                    if (id == 0)
                    {
                        if (!dtoItems.OfferID.HasValue)
                        {
                            throw new Exception("Invalid offer!");
                        }
                        //else
                        //{
                        //    int offerID = dtoItem.OfferID.Value;
                        //    var dbOffer = context.SaleOrderMng_ApprovedOffer_View.FirstOrDefault(o => o.OfferID == offerID);
                        //    if (dbOffer == null)
                        //    {
                        //        throw new Exception("Offer has not been approved! Please contact your manager");
                        //    }
                        //}

                        dbItem = new SaleOrder();
                        context.SaleOrder.Add(dbItem);

                        //SET PI STATUS
                        dbStatus = new SaleOrderStatus();
                        dbStatus.TrackingStatusID = Library.Helper.CREATED;
                        dbStatus.StatusDate       = DateTime.Now;
                        dbStatus.UpdatedBy        = userId;
                        dbStatus.IsCurrentStatus  = true;
                        dbItem.SaleOrderStatus.Add(dbStatus);

                        //SET PI No
                        dtoItems.ProformaInvoiceNo = context.SaleOrderMng_function_GeneratePINo(dtoItems.UpdatedBy, dtoItems.OfferID).FirstOrDefault();

                        //SET TRACKING INFO
                        dtoItems.CreatedBy   = userId;
                        dtoItems.CreatedDate = DateTime.Now;
                    }
                    else
                    {
                        dbItem = context.SaleOrder.FirstOrDefault(o => o.SaleOrderID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "PI not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItems.ConcurrencyFlag_String)))
                        {
                            throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        if (id == 0)
                        {
                            int?offerTrackingStatusID = GetOfferTrackingStatus(dtoItems.OfferID, out notification);
                            if (!(offerTrackingStatusID == 3 || offerTrackingStatusID == 5))
                            {
                                throw new Exception("Offer should be confirmed before create new PI");
                            }
                        }

                        // check who update payment field
                        string oldPaymentDate = (dbItem.PaymentDate == null ? "" : dbItem.PaymentDate.Value.ToString("dd/MM/yyyy"));
                        string newPaymentDate = (dtoItems.paymentDateFormated == null ? "" : dtoItems.paymentDateFormated);
                        if (dtoItems.PaymentStatusID != dbItem.PaymentStatusID || dtoItems.PaymentRemark != dbItem.PaymentRemark || newPaymentDate != oldPaymentDate)
                        {
                            dbItem.PaymentUpdatedBy   = userId;
                            dbItem.PaymentUpdatedDate = DateTime.Now;
                        }

                        //check invoice data in season 2015/2016
                        DateTime?startDate   = new DateTime(Convert.ToInt32(dtoItems.Season.Substring(0, 4)), 10, 1);
                        DateTime?endDate     = new DateTime(Convert.ToInt32(dtoItems.Season.Substring(5, 4)), 9, 30);
                        DateTime?invoiceDate = dtoItems.InvoiceDateFormated.ConvertStringToDateTime();
                        if (invoiceDate < startDate || invoiceDate > endDate)
                        {
                            throw new Exception("Invoice Date must be between " + startDate.Value.ToString("dd/MM/yyyy") + " and " + endDate.Value.ToString("dd/MM/yyyy") + " because the season is " + dtoItems.Season);
                        }
                        //read dto to db
                        converter.DTO2DB_SaleOrder(dtoItems, ref dbItem);
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;
                        //remove orphan item
                        context.SaleOrderDetailExtend.Local.Where(o => o.SaleOrderDetail == null).ToList().ForEach(o => context.SaleOrderDetailExtend.Remove(o));
                        context.SaleOrderDetail.Local.Where(o => o.SaleOrder == null).ToList().ForEach(o => context.SaleOrderDetail.Remove(o));
                        context.SaleOrderExtend.Local.Where(o => o.SaleOrder == null).ToList().ForEach(o => context.SaleOrderExtend.Remove(o));
                        context.SaleOrderDetailSparepart.Local.Where(o => o.SaleOrder == null).ToList().ForEach(o => context.SaleOrderDetailSparepart.Remove(o));

                        //save data
                        context.SaveChanges();

                        //// add item to quotation if needed
                        //context.FW_Quotation_function_AddFactoryOrderItem(null, dbItem.SaleOrderID, null); // table lockx and also check if item is available on sql server side
                        int OfferID = Convert.ToInt32(dbItem.OfferID);
                        //reload data
                        dtoItem = GetDataContainer(dbItem.SaleOrderID, OfferID, dbItem.OrderType, out notification);
                        //if (id > 0)
                        //{
                        //    dtoItem = new DTO.SaleOrder { SaleOrderID = id };
                        //}
                        //else
                        //{
                        //    dtoItem = new DTO.SaleOrder { SaleOrderID = dbItem.SaleOrderID };
                        //}

                        //create reservation
                        //if (dtoItem.OrderType == "WAREHOUSE")
                        //{
                        //    context.SaleOrderMng_function_CreateReservation(dtoItem.SaleOrderID, dtoItem.UpdatedBy);
                        //}
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
                return(false);
            }
        }