public static Dictionary <string, object> reMapDCLData(DutyClear DCL) { Dictionary <string, object> keyValues = new Dictionary <string, object>(); if (DCL.Id != Guid.Empty) { keyValues.Add("@id", DCL.Id); } keyValues.Add("@Status", 1); if (DCL.CreatedOn == DateTime.MinValue) { keyValues.Add("@CreatedOn", DBNull.Value); } else { keyValues.Add("@CreatedOn", DCL.CreatedOn); } keyValues.Add("@CreatedBy", DCL.CreatedBy == null ? Guid.Empty : DCL.CreatedBy.Id); if (DCL.ModifiedOn == DateTime.MinValue) { keyValues.Add("@ModifiedOn", DBNull.Value); } else { keyValues.Add("@ModifiedOn", DCL.ModifiedOn); } keyValues.Add("@ModifiedBy", DCL.ModifiedBy == null ? Guid.Empty : DCL.ModifiedBy.Id); //if (DCL.CompletedOn == DateTime.MinValue) keyValues.Add("@CompletedOn", DBNull.Value); //else // keyValues.Add("@CompletedOn", GRN.CompletedOn); keyValues.Add("@DCLNumber", DCL.DCLNumber); if (DCL.DCLDate == DateTime.MinValue) { keyValues.Add("@DCLDate", DBNull.Value); } else { keyValues.Add("@DCLDate", DCL.DCLDate); } keyValues.Add("@PODetailId", DCL.PODetail == null ? Guid.Empty : DCL.PODetail.Id); keyValues.Add("@Store", DCL.Store == null ? Guid.Empty : DCL.Store.Id); keyValues.Add("@Quantity", DCL.Quantity); keyValues.Add("@Remarks", DCL.Remarks); return(keyValues); }
private static DutyClear NewDCL() { DutyClear dcl = new DutyClear(); Reference currUser = new Reference() { Id = Common.CurrentUser.Id, Name = Common.CurrentUser.Name }; dcl.Id = Guid.Empty; dcl.CreatedOn = dcl.ModifiedOn = dcl.DCLDate = DateTime.Now; dcl.CreatedBy = dcl.ModifiedBy = currUser; dcl.DCLNumber = GenerateNextDCLNumber(); dcl.PO = dcl.PODetail = dcl.Store = new Reference() { Id = Guid.Empty, Name = "" }; return(dcl); }
public static List <PurchaseOrder> MapPOData(DataTable DTpo, DataTable dTpod, DataTable dTgrn, DataTable dTdcl) { List <PurchaseOrder> AllPOs = new List <PurchaseOrder>(); foreach (DataRow DRpo in DTpo.Rows) { PurchaseOrder PO = new PurchaseOrder(); PO.Id = DRpo["Id"] != null ? new Guid(DRpo["Id"].ToString()) : Guid.Empty; PO.Status = DRpo["Status"] != null?MapPOStatus(DRpo["Status"].ToString()) : POStatus.Created; PO.CreatedOn = DRpo["CreatedOn"] != DBNull.Value ? DateTime.Parse(DRpo["CreatedOn"].ToString()) : DateTime.MinValue; PO.CreatedBy = DRpo["CreatedBy"] != null?UserManager.GetUserRef(DRpo["CreatedBy"].ToString()) : UserManager.GetDefaultRef(); PO.ModifiedOn = DRpo["ModifiedOn"] != DBNull.Value ? DateTime.Parse(DRpo["ModifiedOn"].ToString()) : DateTime.MinValue; PO.ModifiedBy = DRpo["ModifiedBy"] != null?UserManager.GetUserRef(DRpo["ModifiedBy"].ToString()) : UserManager.GetDefaultRef(); PO.CompletedOn = DRpo["CompletedOn"] != DBNull.Value ? DateTime.Parse(DRpo["CompletedOn"].ToString()) : DateTime.MinValue; PO.Lead = DRpo["LeadId"] != null?UserManager.GetUserRef(DRpo["LeadId"].ToString()) : UserManager.GetDefaultRef(); PO.ApprovedDate = DRpo["ApprovedDate"] != DBNull.Value ? DateTime.Parse(DRpo["ApprovedDate"].ToString()) : DateTime.MinValue; PO.ApprovedBy = DRpo["ApprovedBy"] != null?UserManager.GetUserRef(DRpo["LeadId"].ToString()) : UserManager.GetDefaultRef(); PO.PONumber = DRpo["PONumber"] != null ? DRpo["PONumber"].ToString() : ""; PO.PODate = DRpo["PODate"] != DBNull.Value ? DateTime.Parse(DRpo["PODate"].ToString()) : DateTime.MinValue; PO.Origin = DRpo["Origin"] != null?CommonDataManager.GetOrigin(DRpo["Origin"].ToString()) : CommonDataManager.GetDefaultRef(); PO.Size = DRpo["Size"] != null?CommonDataManager.GetSize(DRpo["Size"].ToString()) : CommonDataManager.GetDefaultRef(); PO.Vessel = DRpo["Vessel"] != null?CommonDataManager.GetVessel(DRpo["Vessel"].ToString()) : CommonDataManager.GetDefaultRef(); PO.TargetDays = DRpo["TargetDays"] != null?int.Parse(DRpo["TargetDays"].ToString()) : 0; PO.Supplier = DRpo["Supplier"] != null?CommonDataManager.GetSupplier(DRpo["Supplier"].ToString()) : CommonDataManager.GetDefaultRef(); PO.TermsOfPayment = DRpo["TermsOfPayment"] != null ? DRpo["TermsOfPayment"].ToString() : ""; PO.BufferQuantityMax = DRpo["BufferQuantityMax"] != null?decimal.Parse(DRpo["BufferQuantityMax"].ToString()) : 10; PO.BufferQuantityMin = DRpo["BufferQuantityMin"] != null?decimal.Parse(DRpo["BufferQuantityMin"].ToString()) : 10; PO.PODetailsList = new List <PODetail>(); foreach (DataRow DRpod in dTpod.Rows) { Guid poId = DRpod["POId"] != null ? new Guid(DRpod["POId"].ToString()) : Guid.Empty; if (poId != Guid.Empty && poId == PO.Id) { PODetail PODetail = new PODetail(); PODetail.Id = DRpod["Id"] != null ? new Guid(DRpod["Id"].ToString()) : Guid.Empty; PODetail.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; PODetail.Customer = DRpod["CustomerId"] != null?CustomerManager.GetCustomerRef(DRpod["CustomerId"].ToString()) : CustomerManager.GetDefaultRef(); PODetail.Quantity = DRpod["Quantity"] != null?decimal.Parse(DRpod["Quantity"].ToString()) : 0; PODetail.Rate = DRpod["Rate"] != null?decimal.Parse(DRpod["Rate"].ToString()) : 0; PODetail.CostPerTon = DRpod["CostPerTon"] != null?decimal.Parse(DRpod["CostPerTon"].ToString()) : 0; PODetail.AllowedWaistage = DRpod["AllowedWastage"] != null?decimal.Parse(DRpod["AllowedWastage"].ToString()) : 0; PODetail.TargetDate = DRpod["TargetDate"] != DBNull.Value ? DateTime.Parse(DRpod["TargetDate"].ToString()) : DateTime.MinValue; PODetail.Remarks = DRpod["Remarks"] != null ? DRpod["Remarks"].ToString() : ""; PODetail.GRNsList = new List <GRN>(); foreach (DataRow DRgrn in dTgrn.Rows) { Guid podId = DRgrn["PODetailId"] != null ? new Guid(DRgrn["PODetailId"].ToString()) : Guid.Empty; if (podId != Guid.Empty && podId == PODetail.Id) { GRN Grn = new GRN(); Grn.Id = DRgrn["Id"] != null ? new Guid(DRgrn["Id"].ToString()) : Guid.Empty; Grn.Status = DRgrn["Status"] != null?MapGRNStatus(DRgrn["Status"].ToString()) : GRNStatus.Recieved; Grn.CreatedOn = DRgrn["CreatedOn"] != DBNull.Value ? DateTime.Parse(DRgrn["CreatedOn"].ToString()) : DateTime.MinValue; Grn.CreatedBy = DRgrn["CreatedBy"] != null?UserManager.GetUserRef(DRgrn["CreatedBy"].ToString()) : UserManager.GetDefaultRef(); Grn.ModifiedOn = DRgrn["ModifiedOn"] != DBNull.Value ? DateTime.Parse(DRgrn["ModifiedOn"].ToString()) : DateTime.MinValue; Grn.ModifiedBy = DRgrn["ModifiedBy"] != null?UserManager.GetUserRef(DRgrn["ModifiedBy"].ToString()) : UserManager.GetDefaultRef(); Grn.CompletedOn = DRgrn["CompletedOn"] != DBNull.Value ? DateTime.Parse(DRgrn["CompletedOn"].ToString()) : DateTime.MinValue; Grn.GRNNumber = DRgrn["GRNNumber"] != null ? DRgrn["GRNNumber"].ToString() : ""; Grn.GRNDate = DRgrn["GRNDate"] != DBNull.Value ? DateTime.Parse(DRgrn["GRNDate"].ToString()) : DateTime.MinValue; Grn.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; Grn.PODetail = new Reference() { Id = PODetail.Id, Name = PO.PONumber }; Grn.Store = DRgrn["Store"] != null?StoreManager.GetStoreRef(DRgrn["Store"].ToString()) : StoreManager.GetDefaultRef(); Grn.InvoiceNo = DRgrn["InvoiceNo"] != null ? DRgrn["InvoiceNo"].ToString() : ""; Grn.AdjPrice = DRgrn["AdjPrice"] != null?decimal.Parse(DRgrn["AdjPrice"].ToString()) : 0; Grn.Quantity = DRgrn["Quantity"] != null?decimal.Parse(DRgrn["Quantity"].ToString()) : 0; Grn.Remarks = DRpod["Remarks"] != null ? DRpod["Remarks"].ToString() : ""; PODetail.GRNsList.Add(Grn); } } PODetail.DutyClearsList = new List <DutyClear>(); foreach (DataRow DRdcl in dTdcl.Rows) { Guid podId = DRdcl["PODetailId"] != null ? new Guid(DRdcl["PODetailId"].ToString()) : Guid.Empty; if (podId != Guid.Empty && podId == PODetail.Id) { DutyClear Dcl = new DutyClear(); Dcl.Id = DRdcl["Id"] != null ? new Guid(DRdcl["Id"].ToString()) : Guid.Empty; Dcl.CreatedOn = DRdcl["CreatedOn"] != DBNull.Value ? DateTime.Parse(DRdcl["CreatedOn"].ToString()) : DateTime.MinValue; Dcl.CreatedBy = DRdcl["CreatedBy"] != null?UserManager.GetUserRef(DRdcl["CreatedBy"].ToString()) : UserManager.GetDefaultRef(); Dcl.ModifiedOn = DRdcl["ModifiedOn"] != DBNull.Value ? DateTime.Parse(DRdcl["ModifiedOn"].ToString()) : DateTime.MinValue; Dcl.ModifiedBy = DRdcl["ModifiedBy"] != null?UserManager.GetUserRef(DRdcl["ModifiedBy"].ToString()) : UserManager.GetDefaultRef(); Dcl.DCLNumber = DRdcl["DCLNumber"] != null ? DRdcl["DCLNumber"].ToString() : ""; Dcl.DCLDate = DRdcl["DCLDate"] != DBNull.Value ? DateTime.Parse(DRdcl["DCLDate"].ToString()) : DateTime.MinValue; Dcl.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; Dcl.PODetail = new Reference() { Id = PODetail.Id, Name = PO.PONumber }; Dcl.Store = DRdcl["Store"] != null?StoreManager.GetStoreRef(DRdcl["Store"].ToString()) : StoreManager.GetDefaultRef(); Dcl.Quantity = DRdcl["Quantity"] != null?decimal.Parse(DRdcl["Quantity"].ToString()) : 0; Dcl.Remarks = DRpod["Remarks"] != null ? DRpod["Remarks"].ToString() : ""; PODetail.DutyClearsList.Add(Dcl); } } PO.PODetailsList.Add(PODetail); } } AllPOs.Add(PO); } return(AllPOs); }
public static bool UpdateDCL(DutyClear dcl) { try { if (dcl.Id != Guid.Empty && dcl.PO != null && dcl.PO.Id != Guid.Empty && dcl.PODetail != null && dcl.PODetail.Id != Guid.Empty) { PurchaseDataManager.UpdateDCL(POMap.reMapDCLData(dcl)); ResetCache(); } return(true); } catch (Exception ex) { ExceptionHandler.Error("Something went wrong. Details: " + ex.Message, ex); } return(false); /*string PONumber = keyvalues["ponumber"]; * string DCLNumber = keyvalues["dclnumber"]; * string DCLId = keyvalues["dclid"]; * * PurchaseOrder PO = GetPO(PONumber); * DutyClear Dcl = GetDCL(DCLNumber); * if (PO != null && Dcl != null) * { * Dcl.DCLDate = keyvalues.ContainsKey("DCLDate") ? DateTime.Parse(keyvalues["DCLDate"]) : DateTime.Now; * Dcl.PODetail = new Reference() { Id = new Guid(keyvalues["Customer"]), Name = PO.PONumber }; * Dcl.Store = StoreManager.GetStoreRef(keyvalues["Store"]); * Dcl.Quantity = keyvalues.ContainsKey("Quantity") ? decimal.Parse(keyvalues["Quantity"]) : 0; * Dcl.Remarks = keyvalues.ContainsKey("Remarks") ? keyvalues["Remarks"] : ""; * Dcl.ModifiedOn = DateTime.Now; * Dcl.ModifiedBy = UserManager.GetUserRef(Common.CurrentUser.Id.ToString()); * foreach (PODetail pod in PO.PODetailsList) * { * foreach (DutyClear dcl in pod.DutyClearsList) * if (dcl.Id.ToString() == DCLId || dcl.DCLNumber == DCLNumber) * { * pod.DutyClearsList.Remove(dcl); * break; * } * if (pod.Id == Dcl.PODetail.Id) * { * pod.DutyClearsList.Add(Dcl); * break; * } * } * * PurchaseDataManager.CalculatePO(PO); * if (PO.isValid) * PurchaseDataManager.UpdateDCL(POMap.reMapDCLData(Dcl)); * else * { * ExceptionHandler.Error("Something went wrong! PO Quantity is not valid."); * return null; * } * ResetCache(); * * * return Dcl; * } * return null;*/ }
public static bool CreateDutyClear(DutyClear dcl) { try { if (dcl.PO != null && dcl.PO.Id != Guid.Empty && dcl.PODetail != null && dcl.PODetail.Id != Guid.Empty) { Guid dclId = PurchaseDataManager.CreateDCL(POMap.reMapDCLData(dcl)); dcl.Id = dclId; PurchaseOrder po = GetPO(dcl.PO.Name); StoreDataManager.CreateStockMovement(StoreMap.reMapStockMovementData(po, dcl)); //TODO ResetCache(); } return(true); } catch (Exception ex) { ExceptionHandler.Error("Something went wrong. Details: " + ex.Message, ex); } return(false); /*string poNumber = keyvalues.ContainsKey("PO") ? keyvalues["PO"] : ""; * string cusId = keyvalues.ContainsKey("Customer") ? keyvalues["Customer"] : ""; * * if (poNumber != "" && cusId != "") * { * PurchaseOrder PO = GetPO(poNumber); * PODetail POD = null; * foreach (PODetail pod in PO.PODetailsList) * { * if (pod.Customer.Id == new Guid(cusId)) * POD = pod; * } * if (POD != null) * { * if (POD.DutyClearsList == null) * POD.DutyClearsList = new List<DutyClear>(); * DutyClear Dcl = NewDCL(); * Dcl.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; * Dcl.PODetail = new Reference() { Id = POD.Id, Name = PO.PONumber }; * if (keyvalues.ContainsKey("Store")) * Dcl.Store = StoreManager.GetStoreRef(keyvalues["Store"].ToString()); * Dcl.Quantity = keyvalues.ContainsKey("Quantity") ? decimal.Parse(keyvalues["Quantity"]) : 0; * Dcl.Remarks = keyvalues.ContainsKey("Remarks") ? keyvalues["Remarks"] : ""; * POD.DutyClearsList.Add(Dcl); * * PurchaseDataManager.CalculatePO(PO); * if (PO.isValid) * { * PurchaseDataManager.CreateDCL(POMap.reMapDCLData(Dcl)); * //todo stock movement * } * else * { * ExceptionHandler.Error("Something went wrong! PO Quantity is not valid."); * PurchaseDataManager.ResetCache(); * return null; * } * PurchaseDataManager.ResetCache(); * return Dcl; * } * } * return null;*/ }
public static DutyClear ValidateCreateDutyClearForm(Dictionary <string, string> values) { try { string ErrorMessage = string.Empty; if (values["PO"] == "0") { ErrorMessage += "PO, "; } if (values["Customer"] == "0") { ErrorMessage += "Customer, "; } if (string.IsNullOrEmpty(values["DCLDate"])) { ErrorMessage += "DCL Date, "; } if (values["Store"] == "0") { ErrorMessage += "Store, "; } if (values["Quantity"] == "0") { ErrorMessage += "Quantity, "; } PurchaseOrder po = GetPO(values["PO"]); if (po != null && po.PODetailsList.Count > 0) { foreach (PODetail pod in po.PODetailsList) { if (pod.Customer.Id.ToString() == values["Customer"]) { DutyClear Dcl = NewDCL(); Dcl.PO = new Reference() { Id = po.Id, Name = po.PONumber }; Dcl.PODetail = new Reference() { Id = pod.Id, Name = po.PONumber }; Dcl.DCLDate = values.ContainsKey("DCLDate") ? DateTime.Parse(values["DCLDate"]) : DateTime.Now; if (values.ContainsKey("Store")) { Dcl.Store = StoreManager.GetStoreRef(values["Store"].ToString()); } Dcl.Quantity = values.ContainsKey("Quantity") ? decimal.Parse(values["Quantity"]) : 0; Dcl.Remarks = values.ContainsKey("Remarks") ? values["Remarks"] : ""; return(Dcl); } } } } catch (Exception ex) { ExceptionHandler.Error(ex.Message); } return(null); }
public static Dictionary <string, object> reMapStockMovementData(PurchaseOrder PO, DutyClear DCL) { Dictionary <string, object> keyValues = new Dictionary <string, object>(); keyValues.Add("@Store", DCL.Store.Id); foreach (PODetail pod in PO.PODetailsList) { if (pod.Id == DCL.PODetail.Id) { keyValues.Add("@CustomerId", pod.Customer.Id); break; } } keyValues.Add("@Type", StMovType.DCSuccess); keyValues.Add("@Quantity", DCL.Quantity); keyValues.Add("@InOut", true); keyValues.Add("@Reference", DCL.Id); keyValues.Add("@Date", DCL.DCLDate); keyValues.Add("@Vessel", PO.Vessel.Index); keyValues.Add("@Origin", PO.Origin.Index); keyValues.Add("@Size", PO.Size.Index); keyValues.Add("@Remarks", DCL.Remarks); return(keyValues); }