예제 #1
0
        public void ValidItem(Scale entity)
        {
            IEnumerable <ScaleDetails> scaleDetails;

            if (entity.ID <= 0)
            {
                scaleDetails = (IList <ScaleDetails>)Session["ScaleDetails"];
            }
            else
            {
                scaleDetails = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(entity.ID, new string[] { "Scale", "Item_Received" });
            }

            if (scaleDetails != null && scaleDetails.Count() > 0)
            {
                // Ticket Types are Receiving/Trading
                if (entity.Ticket_Type != null && new string[] { "receiving ticket", "trading" }.Any(s => s == entity.Ticket_Type.ToLower()))
                {
                    ValidatePOItem(entity, scaleDetails);
                }

                // Ticket Types are Shipping/Trading
                else if (entity.Ticket_Type != null && new string[] { "shipping ticket", "trading" }.Any(s => s == entity.Ticket_Type.ToLower()) && entity.Container_No != null)
                {
                    Container container = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(entity.Container_No.ID.ToString(), new string[] { "Booking.Sales_Order_No" });
                    if (container != null && container.Booking != null && container.Booking.Sales_Order_No != null)
                    {
                        ValidateSOItem(container.Booking.Sales_Order_No.ID, scaleDetails);
                    }
                }

                // Ticket Types is Local Sale
                else if (entity.Ticket_Type != null && entity.Ticket_Type.ToLower() == "local sale" && entity.Sales_Order != null)
                {
                    ValidateSOItem(entity.Sales_Order.ID, scaleDetails);
                }

                // Ticket Types is Brokerage.
                else if (entity.Ticket_Type != null && entity.Ticket_Type.ToLower() == "brokerage")
                {
                    // Validate SO Item
                    if (entity.Booking != null && entity.Booking.ID > 0)
                    {
                        BookingLibrary bookingLib = new BookingLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        Booking        booking    = bookingLib.GetByID(entity.Booking.ID.ToString(), new string[] { "Sales_Order_No" });
                        if (booking.Sales_Order_No != null)
                        {
                            ValidateSOItem(booking.Sales_Order_No.ID, scaleDetails);
                        }
                    }
                    // Validate PO Item
                    ValidatePOItem(entity, scaleDetails);
                }
            }
        }
예제 #2
0
        protected override void DeleteChildEntities(string[] childEntityList, string parentID)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "Container":
                    if (Convert.ToInt32(parentID) > 0)
                    {
                        ContainerLibrary        containerLibrary = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <Container> resultList       = containerLibrary.GetAllByParentID(Convert.ToInt32(parentID));
                        foreach (Container continer in resultList)
                        {
                            string errorMsg;
                            if (containerLibrary.IsRefExits(continer.ID, out errorMsg))
                            {
                                throw new Exception(errorMsg);
                            }
                            containerLibrary.Delete(continer.ID.ToString());
                        }
                    }
                    break;

                case "BookingNotes":
                    if (Convert.ToInt32(parentID) > 0)
                    {
                        BookingNotesLibrary        BookingNotesLibrary = new BookingNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <BookingNotes> resultList          = BookingNotesLibrary.GetAllByParentID(Convert.ToInt32(parentID));
                        foreach (BookingNotes BookingNote in resultList)
                        {
                            BookingNotesLibrary.Delete(BookingNote.ID.ToString());
                        }
                    }
                    break;

                case "BookingAttachments":
                    if (Convert.ToInt32(parentID) > 0)
                    {
                        BookingAttachmentsLibrary        bookingAttachmentLibrary = new BookingAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <BookingAttachments> resultList = bookingAttachmentLibrary.GetAllByParentID(Convert.ToInt32(parentID));

                        foreach (BookingAttachments bookingAttachment in resultList)
                        {
                            bookingAttachmentLibrary.Delete(bookingAttachment.ID.ToString());
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
예제 #3
0
        public ActionResult SelectOpneBookingItem(int?id)
        {
            if (id.HasValue)
            {
                // Update Container details
                Container container = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(id.ToString(), new string[] { "Booking.Sales_Order_No.Party" });
                if (container != null)
                {
                    ClearChildEntities(new string[] { "ScaleDetails", "ScaleNotes", "ScaleAttachments", "ScaleExpense" });

                    Scale result = new Scale();
                    result.Ticket_Type  = "Shipping Ticket";
                    result.Container_No = new Container();
                    result.Container_No = container;

                    // Update Scale Items
                    if (container.Booking != null && container.Booking.Sales_Order_No != null)
                    {
                        IEnumerable <SalesOrderItem> soItems = new SalesOrderItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString())
                                                               .GetAllBySalesOrderID(container.Booking.Sales_Order_No.ID,
                                                                                     new string[] { "SalesOrder.Party", "Item" }
                                                                                     );
                        List <ScaleDetails> scaleDetails = new List <ScaleDetails>();
                        int count = 0;
                        foreach (var soItem in soItems)
                        {
                            count += 1;
                            ScaleDetails scaleDetail = new ScaleDetails()
                            {
                                ID                = count,
                                Item_Received     = soItem.Item,
                                Apply_To_Item     = soItem.Item,
                                Split_Value       = 100,
                                Scale             = new Scale(),
                                Created_By        = HttpContext.User.Identity.Name,
                                Updated_By        = HttpContext.User.Identity.Name,
                                Created_Date      = DateTime.Now,
                                Last_Updated_Date = DateTime.Now
                            };
                            scaleDetails.Add(scaleDetail);
                        }
                        Session["ScaleDetails"] = scaleDetails;
                    }
                    ViewBag.IsFromOpneBooking = true;
                    result.ID = 0;
                    return(Display(result));
                }
            }

            return(RedirectToAction("New"));
        }
        public ActionResult SelectContainerItem(int?id)
        {
            if (id.HasValue)
            {
                Container container = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(id.ToString(), new string[] { "Booking.Sales_Order_No.Party", "Booking.Shipping_Company" });
                if (container != null)
                {
                    DispatcherRequest result = new DispatcherRequest();
                    result.RequestCategory        = "Container";
                    result.RequestType            = "Drop off only";
                    result.Booking_Ref_No         = new Booking();
                    result.Booking_Ref_No         = container.Booking;
                    result.Container_No           = container.Container_No;
                    result.Shipper                = container.Booking.Shipping_Company;
                    result.Sales_Order_No         = container.Booking.Sales_Order_No;
                    ViewBag.IsFromLoadedContainer = true;
                    result.ID = 0;
                    return(Display(result));
                }
            }

            return(RedirectToAction("New"));
        }
예제 #5
0
        protected override void ValidateEntity(Invoice entity)
        {
            ModelState.Clear();

            if (entity.ID == 0 && new string[] { "exports", "brokerage" }.Any(s => s == entity.Invoice_Type.ToLower()) && entity.Booking.ID == 0)
            {
                ModelState.AddModelError("Booking", "Booking is required");
            }
            if (entity.ID == 0 && new string[] { "local sales", "trading" }.Any(s => s == entity.Invoice_Type.ToLower()) && entity.Sales_Order_No.ID == 0)
            {
                ModelState.AddModelError("SalesOrder", "Sales Order is required");
            }
            if (entity.Net_Amt <= 0)
            {
                ModelState.AddModelError("Net_Amt", "Net invoice amount is required.");
            }
            if (new string[] { "brokerage" }.Any(s => s == entity.Invoice_Type.ToLower()) && entity.Booking != null && entity.Booking.ID > 0)
            {
                ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                Scale        scale    = scaleLib.GetScaleByBookingId(entity.Booking.ID);
                if (scale == null)
                {
                    ModelState.AddModelError("Brokerage1", "To generate a Invoice, valid scale ticket has to be created and closed.");
                }
                else if (scale != null)
                {
                    ContainerLibrary        contLib    = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    IEnumerable <Container> containers = contLib.GetAllByParentID(entity.Booking.ID, new string[] { "Booking" });
                    decimal totalContNetWeight         = containers.Sum(s => s.Net_Weight);
                    if (totalContNetWeight != scale.Net_Weight || scale.Ticket_Status != "Close")
                    {
                        ModelState.AddModelError("Booking2", "Net weight on scale ticket should match with total net weight of all containers for this invoice.");
                    }
                }
            }
        }
예제 #6
0
        protected override void SaveChildEntities(string[] childEntityList, Booking entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "Container":
                    if (Session[ChildEntity] != null)
                    {
                        ContainerLibrary        containerLibrary = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <Container> resultList       = (IList <Container>)Session[ChildEntity];
                        foreach (Container continer in resultList)
                        {
                            continer.Booking = new Booking {
                                ID = entity.ID
                            };
                            containerLibrary.Add(continer);
                        }
                    }
                    break;

                case "BookingNotes":
                    if (Session[ChildEntity] != null)
                    {
                        BookingNotesLibrary        BookingNotesLibrary = new BookingNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <BookingNotes> resultList          = (IList <BookingNotes>)Session[ChildEntity];
                        foreach (BookingNotes BookingNote in resultList)
                        {
                            BookingNote.Parent = new Booking {
                                ID = entity.ID
                            };
                            //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes);
                            BookingNotesLibrary.Add(BookingNote);
                        }
                    }
                    break;

                case "BookingAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        BookingAttachmentsLibrary        BookingLibrary = new BookingAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <BookingAttachments> resultList     = (IList <BookingAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (BookingAttachments Booking in resultList)
                        {
                            destinationPath       = fileHelper.GetSourceDirByFileRefId(Booking.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Booking.Document_RefId.ToString());
                            sourcePath            = fileHelper.GetTempSourceDirByFileRefId(Booking.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Booking.Document_RefId.ToString());
                            Booking.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(Booking.Document_Name, sourcePath, destinationPath);

                            Booking.Parent = new Booking {
                                ID = entity.ID
                            };
                            BookingLibrary.Add(Booking);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }