private void InsertPl_Det(int docId, string docNo, string docType, int index, string sku, string lotNo, string des, int qty, decimal price, string cur, decimal exRate, decimal gst, string soNo, string doNo, string mastType) { try { C2.XAApPayableDet det = new C2.XAApPayableDet(); det.DocId = docId; det.DocLineNo = index; det.DocNo = docNo; det.DocType = docType; det.AcCode = SafeValue.SafeString(ConnectSql.ExecuteScalar(string.Format("select ApCode from ref_product where Code='{0}'", sku)), System.Configuration.ConfigurationManager.AppSettings["ItemApCode"]); det.AcSource = "DB"; det.MastRefNo = soNo; det.JobRefNo = lotNo; det.MastType = mastType; det.SplitType = ""; det.ChgCode = sku; det.ChgDes1 = des; det.ChgDes2 = ""; det.ChgDes3 = ""; det.Price = price; det.Qty = qty; det.Unit = ""; det.Currency = cur; det.ExRate = 1; det.Gst = gst; if (det.ExRate == 0) { det.ExRate = 1; } if (det.Gst > 0) { det.GstType = "S"; } else if (det.Currency == System.Configuration.ConfigurationManager.AppSettings["Currency"]) { det.GstType = "E"; } else { det.GstType = "Z"; } decimal amt = SafeValue.ChinaRound(det.Qty * det.Price, 2); decimal gstAmt = SafeValue.ChinaRound((amt * det.Gst), 2); decimal docAmt = amt + gstAmt; decimal locAmt = SafeValue.ChinaRound(docAmt * det.ExRate, 2); det.GstAmt = gstAmt; det.DocAmt = docAmt; det.LocAmt = locAmt; C2.Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted); C2.Manager.ORManager.PersistChanges(det); } catch { } }
protected void grid_WhPo_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e) { string s = e.Parameters; ASPxPageControl pageControl = this.grid_WhPo.FindEditFormTemplateControl("pageControl") as ASPxPageControl; ASPxTextBox txt_Id = pageControl.FindControl("txt_Id") as ASPxTextBox; ASPxTextBox poNo = pageControl.FindControl("txt_PoNo") as ASPxTextBox; string sql = "select Count(*) from wh_PODet where PoNo='" + SafeValue.SafeString(poNo.Text) + "' and (StatusCode='Draft' or StatusCode='Waiting')"; int cnt = SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql), 0); if (cnt == 0) { if (s == "CloseJob") { #region close job ASPxLabel closeIndStr = pageControl.FindControl("lb_JobStatus") as ASPxLabel; sql = "select StatusCode from wh_PO where PoNo='" + poNo.Text + "'"; string closeInd = SafeValue.SafeString(C2.Manager.ORManager.ExecuteScalar(sql), "USE");// if (closeInd == "CLS") { sql = string.Format("update wh_PO set StatusCode='USE',UpdateBy='{1}',UpdateDateTime='{2}' where PoNo='{0}'", poNo.Text, EzshipHelper.GetUserName(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); int res = Manager.ORManager.ExecuteCommand(sql); if (res > 0) { e.Result = "Success"; } else { e.Result = "Fail"; } } else { sql = string.Format("update wh_PO set StatusCode='CLS',UpdateBy='{1}',UpdateDateTime='{2}' where PoNo='{0}'", poNo.Text, EzshipHelper.GetUserName(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); int res = Manager.ORManager.ExecuteCommand(sql); if (res > 0) { e.Result = "Success"; } else { e.Result = "Fail"; } } #endregion } } else { e.Result = "NotClose"; } if (s == "Void") { #region void master string sql_cnt = string.Format("select count(SequenceId) from XAArInvoiceDet where MastType='WH' and MastRefNo='{0}'", poNo.Text); cnt = SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql_cnt), 0); if (cnt > 0) { e.Result = "Billing"; return; } ASPxLabel closeIndStr = pageControl.FindControl("lb_JobStatus") as ASPxLabel; sql = "select StatusCode from wh_PO where PoNo='" + poNo.Text + "'"; string closeInd = SafeValue.SafeString(C2.Manager.ORManager.ExecuteScalar(sql), "N");// closeIndStr.Text; if (closeInd == "CNL") { sql = string.Format("update wh_PO set StatusCode='USE',UpdateBy='{1}',UpdateDateTime='{2}' where PoNo='{0}'", poNo.Text, EzshipHelper.GetUserName(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); int res = Manager.ORManager.ExecuteCommand(sql); if (res > 0) { e.Result = "Success"; } else { e.Result = "Fail"; } } else { sql = string.Format("update wh_PO set StatusCode='CNL',UpdateBy='{1}',UpdateDateTime='{2}' where PoNo='{0}'", poNo.Text, EzshipHelper.GetUserName(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); int res = Manager.ORManager.ExecuteCommand(sql); if (res > 0) { e.Result = "Success"; } else { e.Result = "Fail"; } } #endregion } if (s == "Invoice") { #region Ap Invoice sql = string.Format(@"select count(*) from XAApPayable where MastRefNo='{0}'", poNo.Text); int docId = 0; cnt = SafeValue.SafeInt(C2.Manager.ORManager.ExecuteScalar(sql), 0); if (cnt == 0) { ASPxTextBox partyTo = pageControl.FindControl("txt_PartyRefNo") as ASPxTextBox; ASPxDateEdit poDate = pageControl.FindControl("txt_PoDate") as ASPxDateEdit; string invN = ""; C2.XAApPayable inv = null; bool isNew = false; if (invN.Length < 1)// first insert invoice { isNew = true; inv = new XAApPayable(); inv.SupplierBillDate = SafeValue.SafeDate(poDate.Date, DateTime.Today); inv.DocDate = inv.SupplierBillDate; inv.DocType = "PL"; invN = C2Setup.GetNextNo(inv.DocType, "AP-PAYABLE", inv.DocDate); inv.PartyTo = SafeValue.SafeString(partyTo.Value, ""); inv.DocNo = invN.ToString(); inv.Term = "CASH"; inv.Description = ""; inv.CurrencyId = System.Configuration.ConfigurationManager.AppSettings["Currency"]; inv.ExRate = 1; inv.AcCode = EzshipHelper.GetAccApCode(inv.PartyTo, inv.CurrencyId); inv.AcSource = "CR"; inv.ExportInd = "N"; inv.UserId = HttpContext.Current.User.Identity.Name; inv.EntryDate = DateTime.Now; inv.CancelDate = new DateTime(1900, 1, 1); inv.CancelInd = "N"; inv.ChqNo = ""; inv.ChqDate = new DateTime(1900, 1, 1); inv.MastRefNo = poNo.Text; inv.JobRefNo = "0"; inv.MastType = "WH"; inv.Eta = DateTime.Now; string[] currentPeriod = EzshipHelper.GetAccPeriod(inv.DocDate); inv.AcYear = SafeValue.SafeInt(currentPeriod[1], inv.DocDate.Year); inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], inv.DocDate.Month); try { C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted); C2.Manager.ORManager.PersistChanges(inv); C2Setup.SetNextNo(inv.DocType, "AP-PAYABLE", invN, inv.DocDate); docId = inv.SequenceId; e.Result = "Success"; } catch { } } sql = "select * from wh_PODet where PoNo='" + poNo.Text + "'"; DataTable dt = C2.Manager.ORManager.GetDataSet(sql).Tables[0]; SavePayableDet(dt, inv.DocNo, docId); } else { DataTable tab = C2.Manager.ORManager.GetDataSet(string.Format(@"select Id from wh_PODet where PoNo='{0}'", poNo.Text)).Tables[0]; int id = 0; C2.XAApPayableDet inv = null; if (tab.Rows.Count > 0) { for (int i = 0; i < tab.Rows.Count; i++) { id = SafeValue.SafeInt(tab.Rows[i]["Id"], 0); Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(XAApPayableDet), "POlineId='" + id + "'"); inv = C2.Manager.ORManager.GetObject(query) as XAApPayableDet; if (inv == null) { SavePayableDet(tab, inv.DocNo, docId); } } } e.Result = "Success"; } #endregion } }