public ActionResult Validate(ScaleDetails data)
        {
            ModelState.Clear();
            // Set ApplyToItem to ItemReceived when ApplyToItem is null.
            if (data.Apply_To_Item.ID == 0)
            {
                data.Apply_To_Item = data.Item_Received;
            }

            if (data.Item_Received == null || data.Item_Received.ID == 0)
            {
                ModelState.AddModelError("ItemRecived", "Material is a required field.");
            }

            //if (data.Apply_To_Item == null || data.Apply_To_Item.ID == 0) {
            //  ModelState.AddModelError("ItemApply", "Apply To Item is required");
            //}

            //ValidateDuplicateItem(data);

            ValidItem(data);

            if (!ModelState.IsValid)
            {
                return(Json(new {
                    success = false,
                    errors = ModelState.Errors()
                }));
            }
            return(Json(new {
                success = true,
                errors = ""
            }));
        }
Exemple #2
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 _InsertUpdate(ScaleDetails data, GridCommand command, bool isNew = false)
 {
     data.Split_Value = 100;
     if (data.ID > 0)
     {
         return(_Update(data, command, isNew));
     }
     else
     {
         ScaleDetails tempItem = TempEntityList.FirstOrDefault(i => i.Item_Received.ID == data.Item_Received.ID);
         if (tempItem == null)
         {
             return(_Insert(data, command, isNew));
         }
         else
         {
             data.ID = tempItem.ID;
             return(_Update(data, command, isNew));
         }
     }
 }
 public override ActionResult _Insert(SettlementDetails data, GridCommand command, bool isNew = false)
 {
     ModelState.Clear();
     Validate(data);
     if (ModelState.IsValid)
     {
         ScaleDetailsLibrary ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
         ScaleDetails        scaleDetails        = ScaleDetailsLibrary.GetByID(data.Scale_Details_ID.ID.ToString(), new string[] { "Scale", "Scale.Purchase_Order", "Item_Received", "Apply_To_Item" });
         data.Scale_Details_ID.Scale.ID             = scaleDetails.Scale.ID;
         data.Scale_Details_ID.Apply_To_Item        = scaleDetails.Apply_To_Item;
         data.Scale_Details_ID.Scale                = scaleDetails.Scale;
         data.Scale_Details_ID.Contamination_Weight = scaleDetails.Contamination_Weight;
         data.Scale_Details_ID.Split_Value          = scaleDetails.Split_Value;
         if (string.IsNullOrWhiteSpace(data.Item_UOM) || data.Item_UOM == "LBS")
         {
             data.Item_UOM           = "LBS";
             data.Item_UOM_Conv_Fact = 1;
             data.Item_UOM_NetWeight = data.Actual_Net_Weight;
         }
         TempEntityList.SingleOrDefault(m => m.Scale_Details_ID.ID == data.Scale_Details_ID.ID).InjectFrom(data);
         ModelState.Clear();
     }
     return(Display(command, data.Scale_Details_ID.Scale.ID.ToString(), isNew));
 }
 protected override void ValidateEntity(ScaleDetails entity)
 {
     ModelState.Clear();
 }
        public HttpResponseMessage SaveTicket([FromBody] Ticket value)
        {
            try {
                if (value.Scale == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                // Start transaction.
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                })) {
                    smART.ViewModel.Scale newScale = new Scale();

                    // Add new party if already exists
                    if (!string.IsNullOrEmpty(value.Scale.License_No))
                    {
                        PartyLibrary partyLib = new PartyLibrary(ConString);
                        Party        party    = partyLib.GetByLicenseNo(value.Scale.License_No);
                        if (party != null)
                        {
                            newScale.Party_ID = party;
                        }
                        else
                        {
                            // Add new party
                            party                   = new Party();
                            party.Party_Name        = value.Scale.Customer_Name;
                            party.Party_Short_Name  = value.Scale.Customer_Name;
                            party.License_No        = value.Scale.License_No;
                            party.Party_Type        = "Individual";
                            party.Created_By        = value.Scale.Created_By;
                            party.Updated_By        = value.Scale.Created_By;
                            party.Created_Date      = value.Scale.Created_Date;
                            party.Last_Updated_Date = value.Scale.Created_Date;
                            party.Active_Ind        = true;
                            party.IsActive          = true;
                            party.State             = !string.IsNullOrEmpty(value.Scale.Customer_State) ? value.Scale.Customer_State.ToString().Trim() : "";
                            party.ACLicense_ID      = value.Scale.Customer_ACLicense_ID;
                            party.Party_DOB         = value.Scale.Customer_DOB;
                            //string dobString = value.Scale.Customer_DOB;
                            //DateTime dobDt;
                            //if (smART.Common.DateTimeHelper.IsValidDate(dobString, out dobDt))
                            //    party.Party_DOB = dobDt;

                            party             = partyLib.Add(party);
                            newScale.Party_ID = party;

                            // Add new Address
                            AddressBook address = new AddressBook();
                            address.Address1          = value.Scale.Customer_Address;
                            address.City              = value.Scale.Customer_City;
                            address.State             = value.Scale.Customer_State;
                            address.Country           = value.Scale.Customer_Country;
                            address.Party             = party;
                            address.Created_By        = value.Scale.Created_By;
                            address.Updated_By        = value.Scale.Created_By;
                            address.Created_Date      = value.Scale.Created_Date;
                            address.Last_Updated_Date = value.Scale.Created_Date;
                            address.Primary_Flag      = true;
                            address.Active_Ind        = true;
                            address.Zip_Code          = value.Scale.Customer_Zip;
                            AddressBookLibrary addressLib = new AddressBookLibrary(ConString);
                            addressLib.Add(address);
                        }
                    }

                    // Save Scale
                    ScaleLibrary lib = new ScaleLibrary(ConString);
                    newScale.Ticket_Status = "Open";
                    newScale.QScale        = true;
                    newScale.Gross_Weight  = value.ScaleDetails.Sum(s => s.GrossWeight);
                    newScale.Tare_Weight   = value.ScaleDetails.Sum(s => s.TareWeight);;
                    newScale.Net_Weight    = value.ScaleDetails.Sum(s => s.NetWeight);
                    value.Scale.MapServiceEntityToServerEntity(newScale);
                    smART.ViewModel.Scale scale = lib.Add(newScale);

                    // Save scale detail
                    if (value.ScaleDetails != null)
                    {
                        ScaleDetailsLibrary libScaleDetail = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        ItemLibrary         libItem        = new ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        foreach (var item in value.ScaleDetails)
                        {
                            smART.ViewModel.ScaleDetails newScaleDetails = new smART.ViewModel.ScaleDetails();
                            newScaleDetails.Apply_To_Item = libItem.GetByID(item.Item_ID.ToString());
                            newScaleDetails.Item_Received = libItem.GetByID(item.Item_ID.ToString());
                            newScaleDetails.Scale         = scale;
                            item.MapServiceEntityToServerEntity(newScaleDetails);
                            ScaleDetails scaleDetails = libScaleDetail.Add(newScaleDetails);

                            // Set docuent related id if document is related to item
                            if (value.ScaleAttachments != null && value.ScaleAttachments.Count > 0)
                            {
                                Model.ScaleAttachments modelAttach = value.ScaleAttachments.Where(w => w.Document_RelatedID == item.ID).FirstOrDefault();
                                if (modelAttach != null && modelAttach.Document_RelatedTo == 1)
                                {
                                    modelAttach.Document_RelatedID = scaleDetails.ID;
                                }
                            }
                        }
                    }

                    // Save Max Ticket ID in Device Settings
                    DeviceSettingLibrary deviceLib      = new DeviceSettingLibrary(ConString);
                    DeviceSettings       deviceSettings = deviceLib.GetByUniueID(scale.Unique_ID.Value);
                    deviceSettings.MaxTicket_ID = value.Scale.ID;
                    deviceLib.Modify(deviceSettings);


                    // Save Attachments
                    if (value.ScaleAttachments != null)
                    {
                        ScaleAttachmentsLibrary libAttach  = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        FilelHelper             fileHelper = new FilelHelper();

                        foreach (var item in value.ScaleAttachments)
                        {
                            smART.ViewModel.ScaleAttachments newScaleAttachment = new smART.ViewModel.ScaleAttachments();

                            // Save file
                            Guid   docRefId        = Guid.NewGuid();
                            string destinationPath = fileHelper.GetSourceDirByFileRefId(docRefId.ToString());
                            fileHelper.MoveFile(item.Document_Title, fileHelper.GetTempSourceDirByFileRefId(item.Document_Path), destinationPath);

                            // Save attachment
                            newScaleAttachment.Parent         = scale;
                            newScaleAttachment.Document_RefId = docRefId;
                            newScaleAttachment.Document_Path  = Path.Combine(destinationPath, item.Document_Title);
                            item.MapServiceEntityToServerEntity(newScaleAttachment);
                            libAttach.Add(newScaleAttachment);
                        }
                    }

                    // Complete transaction.
                    scope.Complete();
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex) {
                ExceptionHandler.HandleException(ex, "An error occured in SaveTicket.");
                //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicket", ex.Message, ex.StackTrace.ToString());
                //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }