public static bool SavePO(PurchaseOrder PO) { if (PO.Id == Guid.Empty) { Guid newPOId = PurchaseDataManager.CreatePO(POMap.reMapPOData(PO)); PO.Id = newPOId; } else { PurchaseDataManager.UpdatePO(POMap.reMapPOData(PO)); } foreach (PODetail pod in PO.PODetailsList) { if (pod.Id == Guid.Empty) { pod.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; Guid newPODId = PurchaseDataManager.CreatePODetail(POMap.reMapPODetailData(pod)); pod.Id = newPODId; } else { PurchaseDataManager.UpdatePODetail(POMap.reMapPODetailData(pod)); } } ResetCache(); return(true); }
public static bool CreatePO(PurchaseOrder PO) { try { Guid poid = PurchaseDataManager.CreatePO(POMap.reMapPOData(PO)); if (poid != Guid.Empty) { PO.Id = poid; foreach (PODetail pod in PO.PODetailsList) { if (pod.Id == Guid.Empty) { pod.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; Guid newPODId = PurchaseDataManager.CreatePODetail(POMap.reMapPODetailData(pod)); pod.Id = newPODId; } else { PurchaseDataManager.UpdatePODetail(POMap.reMapPODetailData(pod)); } } } ResetCache(); return(true); } catch (Exception ex) { ExceptionHandler.Error("Something went wrong. Details: " + ex.Message, ex); } return(false); }
public static void CompleteOrder(PurchaseOrder PO) { PO = PurchaseDataManager.CalculatePO(PO); if (PO.isValid) { PO.Status = POStatus.Completed; SavePO(PO); } else { ExceptionHandler.Error("PO not valid"); } }
public static bool CreateGRN(GRN grn) { try { if (grn.PO != null && grn.PO.Id != Guid.Empty && grn.PODetail != null && grn.PODetail.Id != Guid.Empty) { PurchaseDataManager.CreateGRN(POMap.reMapGRNData(grn)); ResetCache(); /*PurchaseOrder PO = GetPO(grn.PO.Name); * PODetail POD = null; * foreach (PODetail pod in PO.PODetailsList) * { * if (pod.Id == grn.PODetail.Id) * POD = pod; * } * if (POD != null) * { * GRN Grn = NewGRN(); * Grn.PO = new Reference() { Id = PO.Id, Name = PO.PONumber }; * Grn.PODetail = new Reference() { Id = POD.Id, Name = PO.PONumber }; * Grn.GRNDate = keyvalues.ContainsKey("GRNDate") ? DateTime.Parse(keyvalues["GRNDate"]) : DateTime.Now; * if (keyvalues.ContainsKey("Store")) * Grn.Store = StoreManager.GetStoreRef(keyvalues["Store"].ToString()); * Grn.Quantity = keyvalues.ContainsKey("Quantity") ? decimal.Parse(keyvalues["Quantity"]) : 0; * Grn.InvoiceNo = keyvalues.ContainsKey("Invoice") ? keyvalues["Invoice"] : ""; * Grn.AdjPrice = keyvalues.ContainsKey("Price") ? decimal.Parse(keyvalues["Price"]) : 0; * Grn.Remarks = keyvalues.ContainsKey("Remarks") ? keyvalues["Remarks"] : ""; * * POD.GRNsList.Add(Grn); * PurchaseDataManager.CalculatePO(PO); * if (PO.isValid) * PurchaseDataManager.CreateGRN(POMap.reMapGRNData(Grn)); * else * { * ExceptionHandler.Error("Something went wrong! PO Quantity is not valid."); * PurchaseDataManager.ResetCache(); * return null; * } * PurchaseDataManager.ResetCache(); * return Grn; * }*/ } return(true); } catch (Exception ex) { ExceptionHandler.Error("Something went wrong. Details: " + ex.Message, ex); } return(false); }
public static List <PurchaseOrder> ReadAllPO() { DataTable DTpo = PurchaseDataManager.GetAllPOs(); DataTable DTpod = PurchaseDataManager.GetAllPODs(); DataTable DTgrn = PurchaseDataManager.GetAllGRNs(); DataTable DTdcl = PurchaseDataManager.GetAllDCLs(); List <PurchaseOrder> allPOs = POMap.MapPOData(DTpo, DTpod, DTgrn, DTdcl); List <PurchaseOrder> calculatedPOs = new List <PurchaseOrder>(); foreach (PurchaseOrder PO in allPOs) { PurchaseOrder po = PurchaseDataManager.CalculatePO(PO); calculatedPOs.Add(po); } HttpContext.Current.Session.Add(SessionManager.POSession, calculatedPOs); _AllPOs = calculatedPOs; return(calculatedPOs); }
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 UpdateGRN(GRN grn) { try { if (grn.Id != Guid.Empty && grn.PO != null && grn.PO.Id != Guid.Empty && grn.PODetail != null && grn.PODetail.Id != Guid.Empty) { PurchaseDataManager.UpdateGRN(POMap.reMapGRNData(grn)); ResetCache(); } return(true); } catch (Exception ex) { ExceptionHandler.Error("Something went wrong. Details: " + ex.Message, ex); } return(false); /* string PONumber = keyvalues["ponumber"]; * string GRNNumber = keyvalues["grnnumber"]; * string GRNId = keyvalues["grnid"]; * * PurchaseOrder PO = GetPO(PONumber); * GRN Grn = GetGRN(GRNNumber); * if (PO != null && Grn != null) * { * Grn.GRNDate = keyvalues.ContainsKey("GRNDate") ? DateTime.Parse(keyvalues["GRNDate"]) : DateTime.Now; * Grn.PODetail = new Reference() { Id = new Guid(keyvalues["Customer"]), Name = PO.PONumber }; * Grn.Store = StoreManager.GetStoreRef(keyvalues["Store"]); * Grn.Quantity = keyvalues.ContainsKey("Quantity") ? decimal.Parse(keyvalues["Quantity"]) : 0; * Grn.InvoiceNo = keyvalues.ContainsKey("Invoice") ? keyvalues["Invoice"] : ""; * Grn.AdjPrice = keyvalues.ContainsKey("Price") ? decimal.Parse(keyvalues["Price"]) : 0; * Grn.Remarks = keyvalues.ContainsKey("Remarks") ? keyvalues["Remarks"] : ""; * Grn.ModifiedOn = DateTime.Now; * Grn.ModifiedBy = UserManager.GetUserRef(Common.CurrentUser.Id.ToString()); * foreach (PODetail pod in PO.PODetailsList) * { * foreach (GRN grn in pod.GRNsList) * if (grn.Id.ToString() == GRNId || grn.GRNNumber == GRNNumber) * { * pod.GRNsList.Remove(grn); * break; * } * if (pod.Id == Grn.PODetail.Id) * { * pod.GRNsList.Add(Grn); * break; * } * } * PurchaseDataManager.CalculatePO(PO); * if (PO.isValid) * PurchaseDataManager.UpdateGRN(POMap.reMapGRNData(Grn)); * else * { * ExceptionHandler.Error("Something went wrong! PO Quantity is not valid."); * return null; * } * ResetCache(); * * return Grn; * } * 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 PurchaseOrder ValidatePOForm(Dictionary <string, string> values) { try { string ErrorMessage = string.Empty; if (values["Origin"] == "0") { ErrorMessage += "Origin, "; } if (values["Size"] == "0") { ErrorMessage += "Size, "; } if (values["Vessel"] == "0") { ErrorMessage += "Vessel, "; } if (string.IsNullOrEmpty(values["PODate"])) { ErrorMessage += "PO Date, "; } if (string.IsNullOrEmpty(values["TargetDays"])) { ErrorMessage += "Target Days, "; } if (string.IsNullOrEmpty(values["Supplier"])) { ErrorMessage += "Supplier, "; } if (string.IsNullOrEmpty(values["Lead"])) { ErrorMessage += "Lead, "; } // if (key == "PaymentTerms" && string.IsNullOrEmpty(value)) throw new Exception("PaymentTerms is required"); if (string.IsNullOrEmpty(values["BufferMin"])) { ErrorMessage += "Buffer Min %, "; } if (string.IsNullOrEmpty(values["BufferMax"])) { ErrorMessage += "Buffer Max %, "; } if (values["Customer_1"] == "0") { ErrorMessage += "Customer, "; } if (string.IsNullOrEmpty(ErrorMessage)) { bool error = false; for (int i = 1; i <= 10; i++) { if (values["Customer_" + i] == "0") { continue; } if (string.IsNullOrEmpty(values["Quantity_" + i])) { error = true; } if (string.IsNullOrEmpty(values["Rate_" + i])) { error = true; } if (string.IsNullOrEmpty(values["AllowedWastage_" + i])) { error = true; } if (string.IsNullOrEmpty(values["CostPerTon_" + i])) { error = true; } DateTime tdate = new DateTime(); if (!DateTime.TryParse(values["TargetDate_" + i], out tdate)) { error = true; } if (error) { ErrorMessage += "PO Detail"; break; } } } if (string.IsNullOrEmpty(ErrorMessage)) { PurchaseOrder PO = NewPO(); PO.Lead = UserManager.GetUserRef(values["Lead"]); PO.PODate = values.ContainsKey("PODate") ? DateTime.Parse(values["PODate"]) : DateTime.Now; PO.Origin = Common.GetOrigin(values["Origin"]); PO.Size = Common.GetSize(values["Size"]); PO.Vessel = Common.GetVessel(values["Vessel"]); PO.TargetDays = values.ContainsKey("TargetDays") ? int.Parse(values["TargetDays"]) : 0; PO.Supplier = Common.GetSupplier(values["Supplier"]); PO.TermsOfPayment = values["PaymentTerms"]; PO.BufferQuantityMin = values.ContainsKey("BufferMin") ? decimal.Parse(values["BufferMin"]) : 10; PO.BufferQuantityMax = values.ContainsKey("BufferMax") ? decimal.Parse(values["BufferMax"]) : 10; for (int i = 1; i <= 10; i++) { if (values.ContainsKey("Customer_" + i.ToString())) { if (values["Customer_" + i.ToString()] != "0") { PODetail pod = NewPODetail(PO); pod.Customer = CustomerManager.GetCustomerRef(values["Customer_" + i.ToString()]); pod.Quantity = values.ContainsKey("Quantity_" + i.ToString()) ? decimal.Parse(values["Quantity_" + i.ToString()]) : 0; pod.Rate = values.ContainsKey("Rate_" + i.ToString()) ? decimal.Parse(values["Rate_" + i.ToString()]) : 0; pod.AllowedWaistage = values.ContainsKey("AllowedWastage_" + i.ToString()) ? decimal.Parse(values["AllowedWastage_" + i.ToString()]) : 0; pod.CostPerTon = values.ContainsKey("CostPerTon_" + i.ToString()) ? decimal.Parse(values["CostPerTon_" + i.ToString()]) : 0; pod.TargetDate = values.ContainsKey("TargetDate_" + i.ToString()) ? DateTime.Parse(values["TargetDate_" + i.ToString()]) : DateTime.MaxValue; PO.PODetailsList.Add(pod); } } } PO = PurchaseDataManager.CalculatePO(PO); if (PO.isValid) { return(PO); } } throw new Exception("Enter required fields: " + ErrorMessage); } catch (Exception ex) { ExceptionHandler.Error(ex.Message); } return(null); }