private CI CreateInvoiceObject(CO m_Order, List <CIBatchDetail> ListBatch, int m_UserID) { try { CI invoice = new CI(); invoice.InvoiceNo = string.Empty; invoice.CreatedBy = m_UserID; invoice.CustomerOrderNo = m_Order.CustomerOrderNo; invoice.InvoiceAmount = m_Order.OrderAmount; invoice.DistributorId = m_Order.DistributorId; invoice.BOId = m_Order.BOId; invoice.PCId = m_Order.PCId; invoice.InvoicePrinted = false; invoice.IsProcessed = 0; invoice.LogNo = m_Order.LogNo; invoice.ModifiedBy = m_UserID; invoice.ModifiedDate = DateTime.Today.ToString(); invoice.StaffId = m_UserID; invoice.Status = 1; invoice.TINNo = Common.TINNO; // ConfigurationManager.AppSettings["TINNO"]; invoice.CIDetailList = new List <CIDetail>(); foreach (CODetail detail in m_Order.CODetailList) { CIDetail ciDetail = new CIDetail(); ciDetail.ItemCode = detail.ItemCode; ciDetail.ItemId = detail.ItemId; var query = from q in ListBatch where q.ItemId == detail.ItemId && q.RecordNo == detail.RecordNo select q; if (query != null) { ciDetail.CIBatchList = query.ToList(); } foreach (CIBatchDetail batch in ciDetail.CIBatchList) { batch.RecordNo = detail.RecordNo; batch.CreatedBy = m_UserID; batch.ModifiedBy = m_UserID; } invoice.CIDetailList.Add(ciDetail); } return(invoice); } catch (Exception ex) { throw ex; } }
public bool ProcessLog(string logNo, int LocationID, int userID, List <CO> lstCo, ref String ErrorCode) { try { bool isSuccess = false; bool isValid = true; string errorMessage = string.Empty; //Check Batch Qty Not Available for all Items of orders //isValid = CI.CheckBatchForLog(logNo, LocationID, ref errorMessage); //if (isValid) { List <CI> CIList = new List <CI>(); errorMessage = string.Empty; if (lstCo != null && lstCo.Count > 0) { DataTaskManager dtManager = null; try { using (dtManager = new DataTaskManager()) { //dtManager.BeginTransaction(); try { foreach (CO o in lstCo) { dtManager.BeginTransaction(); CO COrder = new CO(); COrder.GetCOAllDetails(o.CustomerOrderNo, -1); errorMessage = string.Empty; List <CIBatchDetail> ListBatch = CIBatchDetail.GetDefaultBatch(COrder.CustomerOrderNo, LocationID, ref errorMessage); CI invoice = CreateInvoiceObject(COrder, ListBatch, userID); if (invoice != null) { string ValidationCode = string.Empty; isValid = invoice.ValidateInvoice(COrder.CODetailList, ListBatch, ref ValidationCode); errorMessage = errorMessage + ValidationCode; if (isValid) { bool isSaved = invoice.Save(ref ValidationCode); if (!isSaved) { isSuccess = false; ErrorCode = ValidationCode; dtManager.RollbackTransaction(); //return isSuccess; } else { dtManager.CommitTransaction(); ErrorCode = string.Empty; isSuccess = true; } } else { if (ValidationCode == "40007") { // Not sufficent Batch Qty present ErrorCode = "40008"; } else { ErrorCode = ValidationCode; } isSuccess = false; dtManager.RollbackTransaction(); //break; } } else { ErrorCode = "40029," + COrder.CustomerOrderNo; isSuccess = false; dtManager.RollbackTransaction(); break; } } //dtManager.CommitTransaction(); //ErrorCode = string.Empty; //isSuccess = true; //return isSuccess; } catch (Exception ex) { throw ex; } } //return isSuccess; } catch (Exception ex) { Common.LogException(ex); } } else { //No Order found in confirmed status ErrorCode = "40011"; } } // Error in batch qty check ////else if (!errorMessage.Trim().Equals(string.Empty)) //{ // if (errorMessage.Trim().IndexOf("30001:") >= 0) // { // throw new Exception(errorMessage.Trim()); // } // else // { // ErrorCode = errorMessage.Trim(); // } //} if (!errorMessage.Equals("")) { MessageBox.Show(errorMessage, Common.GetMessage("10004"), MessageBoxButtons.OK, MessageBoxIcon.Information); } return(isSuccess); } catch (Exception ex) { throw ex; } }
public bool ProcessLog(string logNo, int LocationID, int userID, ref String ErrorCode, ref DataTable dtItems) { try { bool isSuccess = false; bool isValid = true; string errorMessage = string.Empty; //Check Batch Qty Not Available for all Items of orders isValid = CI.CheckBatchForLog(logNo, LocationID, ref errorMessage, ref dtItems); if (isValid) { List <CI> CIList = new List <CI>(); CO order = new CO(); order.LogNo = logNo; order.Status = (int)Common.OrderStatus.Confirmed; errorMessage = string.Empty; List <CO> lstCo = order.Search(ref errorMessage); if (errorMessage.Equals(string.Empty) && lstCo != null && lstCo.Count > 0) { DataTaskManager dtManager = null; try { using (dtManager = new DataTaskManager()) { dtManager.BeginTransaction(); try { foreach (CO o in lstCo) { CO m_Order = new CO(); m_Order.GetCOAllDetails(o.CustomerOrderNo, -1); errorMessage = string.Empty; List <CIBatchDetail> ListBatch = CIBatchDetail.GetDefaultBatch(m_Order.CustomerOrderNo, LocationID, ref errorMessage); CI invoice = CreateInvoiceObject(m_Order, ListBatch, userID); if (invoice != null) { string ValidationCode = string.Empty; isValid = invoice.ValidateInvoice(m_Order.CODetailList, ListBatch, ref ValidationCode); if (isValid) { bool isSaved = invoice.Save(ref ValidationCode); if (!isSaved) { isSuccess = false; dtManager.RollbackTransaction(); } } else { if (ValidationCode == "40007") { // Not sufficent Batch Qty present ErrorCode = "40008"; } else { ErrorCode = ValidationCode; } isSuccess = false; dtManager.RollbackTransaction(); break; } } else { ErrorCode = "40029," + m_Order.CustomerOrderNo; isSuccess = false; dtManager.RollbackTransaction(); break; } } dtManager.CommitTransaction(); ErrorCode = string.Empty; isSuccess = true; } catch (Exception ex) { throw ex; } } } catch (Exception ex) { Common.LogException(ex); } } else { //No Order found in confirmed status ErrorCode = "40011"; } } // Error in batch qty check else if (!errorMessage.Trim().Equals(string.Empty)) { if (errorMessage.Trim().IndexOf("30001:") >= 0) { throw new Exception(errorMessage.Trim()); } else { ErrorCode = errorMessage.Trim(); } } return(isSuccess); } catch (Exception ex) { throw ex; } }