Пример #1
0
 public void DeleteScaleDetails(smART.ViewModel.SettlementDetails businessEntity, smART.Model.SettlementDetails modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try {
         smART.Model.ScaleDetails scaleDetails = dbContext.T_Scale_Details.FirstOrDefault(i => i.ID == modelEntity.Scale_Details_ID.ID);
         if (scaleDetails != null)
         {
             if (scaleDetails.Settlement_Diff_NetWeight != 0)
             {
                 AddInventory(scaleDetails, dbContext);
             }
             scaleDetails.NetWeight                 = scaleDetails.NetWeight - scaleDetails.Settlement_Diff_NetWeight;
             scaleDetails.Updated_By                = modelEntity.Updated_By;
             scaleDetails.Last_Updated_Date         = modelEntity.Last_Updated_Date;
             scaleDetails.Settlement_Diff_NetWeight = 0;
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex) {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #2
0
 public void UpdateContainer(smART.ViewModel.Scale businessEntity, smART.Model.Scale modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try
     {
         if (modelEntity.Ticket_Type.ToLower() == "shipping ticket")
         {
             smART.Model.Container container = dbContext.T_Container_Ref.Include("Booking").FirstOrDefault(m => m.ID == modelEntity.Container_No.ID);
             container.Seal1_No     = modelEntity.Seal_No;
             container.Chasis_No    = modelEntity.Trailer_Chasis_No;
             container.Gross_Weight = modelEntity.Gross_Weight;
             container.Tare_Weight  = modelEntity.Tare_Weight;
             container.Net_Weight   = modelEntity.Net_Weight;
             container.Status       = GetContainerStatus(modelEntity, container, dbContext);
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #3
0
 private void AuditLog(smART.ViewModel.Scale businessEntity, smART.Model.smARTDBContext dbContext)
 {
     try
     {
         smART.Model.AuditLog newModObject = new Model.AuditLog()
         {
             Entity_Name       = "Scale",
             Entity_ID         = businessEntity.ID,
             Field_Name        = "Scale_Reading",
             Old_Value         = businessEntity.Scale_Reading.ToString(),
             New_Value         = businessEntity.Scale_Reading.ToString(),
             Active_Ind        = true,
             Created_By        = businessEntity.Updated_By,
             Updated_By        = businessEntity.Updated_By,
             Created_Date      = businessEntity.Last_Updated_Date,
             Last_Updated_Date = businessEntity.Last_Updated_Date
         };
         dbContext.T_Audit_Log.Add(newModObject);
         dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #4
0
 private void UpdateExpenseAmountPaidTillDate(smART.ViewModel.PaymentReceiptDetails businessEntity, smART.Model.PaymentReceiptDetails modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try {
         smART.Model.ExpensesRequest exp = (from s in dbContext.T_Expenses
                                            where s.ID == businessEntity.ExpenseRequest.ID
                                            select s).FirstOrDefault();
         if (exp != null)
         {
             decimal appliedAmount = 0;
             var     prDetails     = dbContext.T_Payment_Receipt_Details.Where(p => p.ExpenseRequest.ID == businessEntity.ExpenseRequest.ID && p.Active_Ind == true);
             if (prDetails != null && prDetails.Count() > 0)
             {
                 appliedAmount = prDetails.Sum(p => p.Apply_Amount);
             }
             exp.Amount_Paid_Till_Date = Convert.ToDouble(appliedAmount);
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex) {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #5
0
        public void UpdateScaleDetailNetWeight(smART.Model.Scale modelScale, smART.Model.smARTDBContext dbContext)
        {
            try
            {
                IEnumerable <smART.Model.ScaleDetails> scaleDetails = from scaledetail in dbContext.T_Scale_Details
                                                                      where scaledetail.Scale.ID == modelScale.ID
                                                                      select scaledetail;

                if (scaleDetails != null)
                {
                    foreach (var modelEntity in scaleDetails)
                    {
                        modelEntity.GrossWeight = modelScale.Gross_Weight * (modelEntity.Split_Value / 100);
                        modelEntity.TareWeight  = modelScale.Tare_Weight * (modelEntity.Split_Value / 100);
                        modelEntity.NetWeight   = modelEntity.GrossWeight - modelEntity.TareWeight - modelEntity.Contamination_Weight + modelEntity.Settlement_Diff_NetWeight;
                    }
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                bool rethrow;
                rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelScale.Updated_By, modelScale.GetType().Name, modelScale.ID.ToString());
                if (rethrow)
                {
                    throw ex;
                }
            }
        }
Пример #6
0
        public void Deleted(smART.ViewModel.ScaleAttachments businessEntity, smART.Model.ScaleAttachments modelEntity, smART.Model.smARTDBContext dbContext)
        {
            if (businessEntity.Ref_Type == (int)EnumAttachmentRefType.Customer || businessEntity.Ref_Type == (int)EnumAttachmentRefType.Thumbprint1 || businessEntity.Ref_Type == (int)EnumAttachmentRefType.Thumbprint2)
            {
                smART.Model.ScaleAttachments attachment = dbContext.T_Scale_Attachments.Include("Parent.Party_ID").FirstOrDefault(m => m.ID == modelEntity.ID);

                if (attachment.Parent.Party_ID != null)
                {
                    smART.Model.Party party = dbContext.M_Party.FirstOrDefault(m => m.ID == attachment.Parent.Party_ID.ID);
                    if (businessEntity.Ref_Type == (int)EnumAttachmentRefType.Customer)
                    {
                        party.PhotoRefId = "";
                    }
                    else if (businessEntity.Ref_Type == (int)EnumAttachmentRefType.Thumbprint1)
                    {
                        party.ThumbImage1RefId = "";
                    }
                    else if (businessEntity.Ref_Type == (int)EnumAttachmentRefType.Thumbprint2)
                    {
                        party.ThumbImage2RefId = "";
                    }
                    else if (businessEntity.Ref_Type == (int)EnumAttachmentRefType.DriverLicense)
                    {
                        party.LicenseImageRefId = "";
                    }
                    else if (businessEntity.Ref_Type == (int)EnumAttachmentRefType.Signature)
                    {
                        party.SignatureImageRefId = "";
                    }

                    dbContext.SaveChanges();
                }
            }
        }
Пример #7
0
 public void UpdateContainer(smART.ViewModel.DispatcherRequest businessEntity, smART.Model.DispatcherRequest modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try {
         if (modelEntity.RequestCategory.ToLower() == "container" && !string.IsNullOrEmpty(businessEntity.Container_No))
         {
             Model.Booking modBooking = dbContext.T_Booking_Ref.FirstOrDefault(o => o.ID.Equals(modelEntity.Booking_Ref_No.ID));
             if (modBooking != null)
             {
                 Model.Container modContainer = dbContext.T_Container_Ref.Include("Booking").FirstOrDefault(o => o.Container_No == businessEntity.Container_No && o.Active_Ind == true);
                 if (modContainer == null)
                 {
                     smART.Model.Container modNewcontainer = new smART.Model.Container();
                     modNewcontainer.Booking           = modBooking;
                     modNewcontainer.Container_No      = businessEntity.Container_No;
                     modNewcontainer.Created_Date      = modelEntity.Time;
                     modNewcontainer.Last_Updated_Date = modelEntity.Time;
                     modNewcontainer.Created_By        = modelEntity.Created_By;
                     modNewcontainer.Updated_By        = modelEntity.Updated_By;
                     modNewcontainer.Date_In           = DateTime.Now;
                     modNewcontainer.Status            = GetContainerStatus(modBooking, modelEntity, dbContext);
                     modNewcontainer.Active_Ind        = true;
                     Model.Container insertedObject = dbContext.T_Container_Ref.Add(modNewcontainer);
                     modContainer = insertedObject;
                     dbContext.SaveChanges();
                     modelEntity.Container = modContainer;
                 }
                 else
                 {
                     modContainer.Last_Updated_Date = DateTime.Now;
                     modContainer.Updated_By        = modelEntity.Updated_By;
                     modelEntity.Container          = modContainer;
                     modelEntity.Booking_Ref_No     = dbContext.T_Booking_Ref.FirstOrDefault(o => o.ID == modContainer.Booking.ID);
                     modContainer.Status            = GetContainerStatus(modelEntity.Booking_Ref_No, modelEntity, dbContext);
                     dbContext.SaveChanges();
                 }
             }
         }
     }
     catch (Exception ex) {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #8
0
        internal virtual void DeleteInventory(smART.Model.ScaleDetails modelScaleDetails, smART.Model.smARTDBContext dbContext)
        {
            try {
                //If status is close then add inventory record
                if (modelScaleDetails.Scale != null && modelScaleDetails.Scale.Ticket_Status.ToLower().Equals("close") && modelScaleDetails.Apply_To_Item != null)
                {
                    //Get all scale inventory item by ticket id & item id
                    IQueryable <smART.Model.Inventory> inventories = dbContext.Set <smART.Model.Inventory>().AsQueryable().Where(i => i.Scale_Ticket_ID.ID == modelScaleDetails.Scale.ID &&
                                                                                                                                 i.Item_ID.ID == modelScaleDetails.Apply_To_Item.ID &&
                                                                                                                                 i.Trans_Type == "Scale ticket" &&
                                                                                                                                 i.Active_Ind == true);

                    //Get current balance from Item Master
                    smART.Model.Item item = dbContext.M_Item.FirstOrDefault(i => i.ID == modelScaleDetails.Apply_To_Item.ID);

                    if (item != null && inventories != null && inventories.Count() > 0)
                    {
                        foreach (var inventory in inventories)
                        {
                            // Update Invetory Active_Ind to false.
                            inventory.Updated_By        = modelScaleDetails.Updated_By;
                            inventory.Last_Updated_Date = modelScaleDetails.Last_Updated_Date;
                            inventory.Active_Ind        = false;
                            dbContext.Entry <smART.Model.Inventory>(inventory);
                        }

                        decimal itemCurrentBalance      = item.Current_Balance;
                        decimal scaleItemCurrentBalance = modelScaleDetails.NetWeight;

                        if (modelScaleDetails.Scale.Ticket_Type.ToLower().Equals("receiving ticket"))
                        {
                            itemCurrentBalance -= scaleItemCurrentBalance;
                        }
                        else
                        {
                            itemCurrentBalance += scaleItemCurrentBalance;
                        }

                        //Update Item current balance in Item Master
                        item.Current_Balance   = itemCurrentBalance;
                        item.Last_Updated_Date = DateTime.Now;
                        item.Updated_By        = modelScaleDetails.Updated_By;
                        dbContext.Entry <smART.Model.Item>(item);
                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex) {
                bool rethrow;
                rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelScaleDetails.Updated_By, modelScaleDetails.GetType().Name, modelScaleDetails.ID.ToString());
                if (rethrow)
                {
                    throw ex;
                }
            }
        }
Пример #9
0
 public void AddNewLocation(smART.Model.AssetAudit assetAudit, smART.Model.smARTDBContext dbContext)
 {
     smART.Model.AssetAudit modelAssetAudit = dbContext.T_Asset_Audit.Where(o => o.Asset.ID == assetAudit.Asset.ID && o.Party.ID == assetAudit.Party.ID && o.Location.ID == assetAudit.Location.ID && o.Dispatcher_Request.ID == assetAudit.Dispatcher_Request.ID && o.Asset_Current_Location_Flg == true).FirstOrDefault();
     if (modelAssetAudit == null)
     {
         UpdatePreviousLocation(assetAudit, dbContext);
         dbContext.T_Asset_Audit.Add(assetAudit);
         dbContext.SaveChanges();
     }
 }
Пример #10
0
 private void UpdateDefault(smART.ViewModel.PriceList businessEntity, smART.Model.PriceList modelEntity, smART.Model.smARTDBContext dbContext)
 {
     if (businessEntity.IsDefault == true)
     {
         smART.Model.PriceList price = dbContext.T_PriceList.FirstOrDefault(i => i.IsDefault == true);
         if (price != null)
         {
             price.IsDefault         = false;
             price.Last_Updated_Date = modelEntity.Last_Updated_Date;
             dbContext.SaveChanges();
         }
     }
 }
Пример #11
0
        //public void Added(smART.ViewModel.ScaleDetails businessEntity, smART.Model.ScaleDetails modelEntity, smART.Model.smARTDBContext dbContext) {
        //  //if (modelEntity.Scale != null && modelEntity.Scale.Ticket_Status.ToLower().Equals("close") && modelEntity.Apply_To_Item != null)
        //  //{
        //  //    AddInventory(modelEntity, dbContext);
        //  //    dbContext.SaveChanges();
        //  //}
        //}

        //public void Modified(smART.ViewModel.ScaleDetails businessEntity, smART.Model.ScaleDetails modelEntity, smART.Model.smARTDBContext dbContext) {
        //  //if (modelEntity.Scale != null && modelEntity.Scale.Ticket_Status.ToLower().Equals("close") && modelEntity.Apply_To_Item != null)
        //  //{
        //  //    AddInventory(modelEntity, dbContext);
        //  //    dbContext.SaveChanges();
        //  //}
        //}

        //public void Deleted(smART.ViewModel.ScaleDetails businessEntity, smART.Model.ScaleDetails modelEntity, smART.Model.smARTDBContext dbContext) {
        //  //IQueryable<smART.Model.ScaleDetails> scaleDetails = dbContext.Set<smART.Model.ScaleDetails>().AsQueryable().Where(o => o.ID == modelEntity.ID);

        //  //if (scaleDetails != null && scaleDetails.Count()>0)
        //  //{
        //  //    scaleDetails = scaleDetails.Include("Apply_To_Item");
        //  //    scaleDetails = scaleDetails.Include("Scale");

        //  //    smART.Model.ScaleDetails scaleDetail = scaleDetails.FirstOrDefault();

        //  //    if (scaleDetail.Scale != null && scaleDetail.Scale.Ticket_Status.ToLower().Equals("close") && scaleDetail.Apply_To_Item != null)
        //  //    {
        //  //        DeleteInventory(scaleDetail, dbContext);
        //  //    }
        //  //}
        //}

        public void UpdateWeight(smART.ViewModel.ScaleDetails businessEntity, smART.Model.ScaleDetails modelEntity, smART.Model.smARTDBContext dbContext, bool isDelete = false)
        {
            try {
                if (!modelEntity.Scale.QScale)
                {
                    modelEntity.GrossWeight = modelEntity.Scale.Gross_Weight * (modelEntity.Split_Value / 100);
                    modelEntity.TareWeight  = modelEntity.Scale.Tare_Weight * (modelEntity.Split_Value / 100);
                    modelEntity.NetWeight   = modelEntity.GrossWeight - modelEntity.TareWeight - modelEntity.Contamination_Weight + modelEntity.Settlement_Diff_NetWeight;
                }
                else
                {
                    IEnumerable <smART.Model.ScaleDetails> scaleDetails = from scaledetail in dbContext.T_Scale_Details
                                                                          where scaledetail.Scale.ID == businessEntity.Scale.ID && scaledetail.Active_Ind == true
                                                                          select scaledetail;
                    smART.Model.Scale scale = dbContext.T_Scale.FirstOrDefault(s => s.ID == businessEntity.Scale.ID);
                    if (scaleDetails != null)
                    {
                        scale.Gross_Weight = scaleDetails.Sum(s => s.GrossWeight);
                        scale.Tare_Weight  = scaleDetails.Sum(s => s.TareWeight);
                        scale.Net_Weight   = scaleDetails.Sum(s => s.NetWeight);

                        if (isDelete)
                        {
                            scale.Gross_Weight -= businessEntity.GrossWeight;
                            scale.Tare_Weight  -= businessEntity.TareWeight;
                            scale.Net_Weight   -= businessEntity.NetWeight;
                        }

                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex) {
                bool rethrow;
                rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelEntity.Updated_By, modelEntity.GetType().Name, modelEntity.ID.ToString());
                if (rethrow)
                {
                    throw ex;
                }
            }
        }
Пример #12
0
 public void DeleteSettlementScale(smART.ViewModel.Settlement businessEntity, smART.Model.Settlement modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try {
         smART.Model.Scale scale = dbContext.T_Scale.FirstOrDefault(i => i.ID == modelEntity.Scale.ID);
         if (scale != null)
         {
             scale.Updated_By                = modelEntity.Updated_By;
             scale.Last_Updated_Date         = modelEntity.Last_Updated_Date;
             scale.Ticket_Settled            = false;
             scale.Settlement_Diff_NetWeight = 0;
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex) {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #13
0
 /// <summary>
 /// Update Asset_Current_Location_Flg to false for all previous location records.
 /// </summary>
 /// <param name="businessEntity"></param>
 /// <param name="dbContext"></param>
 public void UpdatePreviousLocation(smART.Model.AssetAudit modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try {
         IEnumerable <Model.AssetAudit> results = dbContext.T_Asset_Audit.Where(o => o.Asset.ID == modelEntity.Asset.ID && o.Asset.Asset_Type == "Bin");
         if (results != null && results.Count() > 0)
         {
             foreach (var item in results)
             {
                 item.Asset_Current_Location_Flg = false;
             }
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex) {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelEntity.Updated_By, modelEntity.GetType().Name, "0");
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #14
0
 public void Deleted(smART.ViewModel.Invoice businessEntity, smART.Model.Invoice modelEntity, smART.Model.smARTDBContext dbContext)
 {
     try {
         if (businessEntity.Invoice_Type.Equals("local sales", StringComparison.InvariantCultureIgnoreCase))
         {
             IEnumerable <Model.Scale> scales = dbContext.T_Scale.Where(o => o.Invoice.ID == businessEntity.ID);
             foreach (var scale in scales)
             {
                 scale.Invoice = null;
             }
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex) {
         bool rethrow;
         rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelEntity.Updated_By, modelEntity.GetType().Name, modelEntity.ID.ToString());
         if (rethrow)
         {
             throw ex;
         }
     }
 }
Пример #15
0
        public void Inventory(smART.Model.Scale modelScale, smART.Model.smARTDBContext dbContext)
        {
            try
            {
                IQueryable <smART.Model.ScaleDetails> scaleDetails = dbContext.Set <smART.Model.ScaleDetails>().AsQueryable().Where(o => o.Scale.ID == modelScale.ID);

                if (scaleDetails != null)
                {
                    scaleDetails = scaleDetails.Include("Apply_To_Item");

                    foreach (var modelEntity in scaleDetails)
                    {
                        modelEntity.Old_Net_Weight = modelEntity.NetWeight;
                        modelEntity.GrossWeight    = modelScale.Gross_Weight * (modelEntity.Split_Value / 100);
                        modelEntity.TareWeight     = modelScale.Tare_Weight * (modelEntity.Split_Value / 100);
                        modelEntity.NetWeight      = modelEntity.GrossWeight - modelEntity.TareWeight - modelEntity.Contamination_Weight + modelEntity.Settlement_Diff_NetWeight;

                        if (modelEntity.Scale != null && modelEntity.Scale.Ticket_Status.ToLower().Equals("close") && modelEntity.Apply_To_Item != null)
                        {
                            AddInventory(modelEntity, dbContext);
                        }
                    }

                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                bool rethrow;
                rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelScale.Updated_By, modelScale.GetType().Name, modelScale.ID.ToString());
                if (rethrow)
                {
                    throw ex;
                }
            }
        }