コード例 #1
0
    private void SaveAndUpdate()
    {
        ASPxTextBox  invNCtr     = this.ASPxGridView1.FindEditFormTemplateControl("txt_Oid") as ASPxTextBox;
        ASPxComboBox partyTo     = this.ASPxGridView1.FindEditFormTemplateControl("cmb_PartyTo") as ASPxComboBox;
        ASPxTextBox  docN        = this.ASPxGridView1.FindEditFormTemplateControl("txt_DocNo") as ASPxTextBox;
        ASPxComboBox docType     = this.ASPxGridView1.FindEditFormTemplateControl("cbo_DocType") as ASPxComboBox;
        ASPxDateEdit docDate     = this.ASPxGridView1.FindEditFormTemplateControl("txt_DocDt") as ASPxDateEdit;
        ASPxMemo     remarks1    = this.ASPxGridView1.FindEditFormTemplateControl("txt_Remarks1") as ASPxMemo;
        ASPxComboBox termId      = this.ASPxGridView1.FindEditFormTemplateControl("txt_TermId") as ASPxComboBox;
        ASPxDateEdit dueDt       = this.ASPxGridView1.FindEditFormTemplateControl("txt_DueDt") as ASPxDateEdit;
        ASPxTextBox  docCurr     = this.ASPxGridView1.FindEditFormTemplateControl("txt_Currency") as ASPxTextBox;
        ASPxSpinEdit exRate      = this.ASPxGridView1.FindEditFormTemplateControl("txt_DocExRate") as ASPxSpinEdit;
        ASPxTextBox  acCode      = this.ASPxGridView1.FindEditFormTemplateControl("txt_AcCode") as ASPxTextBox;
        ASPxComboBox acSource    = this.ASPxGridView1.FindEditFormTemplateControl("txt_AcSource") as ASPxComboBox;
        ASPxTextBox  specialNote = this.ASPxGridView1.FindEditFormTemplateControl("txt_SpecialNote") as ASPxTextBox;

        ASPxTextBox mastRefNCtr = this.ASPxGridView1.FindEditFormTemplateControl("txt_MastRefNo") as ASPxTextBox;
        ASPxTextBox jobRefNCtr  = this.ASPxGridView1.FindEditFormTemplateControl("txt_JobRefNo") as ASPxTextBox;
        ASPxTextBox jobType     = this.ASPxGridView1.FindEditFormTemplateControl("txt_MastType") as ASPxTextBox;

        string invN = docN.Text;

        C2.XAArInvoice inv = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invNCtr.Text, 0)) as XAArInvoice;
        if (inv == null)// first insert invoice
        {
            string counterType = "AR-IV";
            if (docType.Value.ToString() == "DN")
            {
                counterType = "AR-DN";
            }

            inv         = new XAArInvoice();
            invN        = C2Setup.GetNextNo("", counterType, docDate.Date);
            inv.PartyTo = SafeValue.SafeString(partyTo.Value, "");
            inv.DocType = docType.Value.ToString();
            inv.DocNo   = invN.ToString();
            inv.DocDate = docDate.Date;
            string[] currentPeriod = EzshipHelper.GetAccPeriod(docDate.Date);

            inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], docDate.Date.Year);
            inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], docDate.Date.Month);

            //
            int dueDay = SafeValue.SafeInt(termId.Text.ToUpper().Replace("DAYS", "").Trim(), 0);
            inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
            inv.Description = remarks1.Text;
            inv.CurrencyId  = docCurr.Text.ToString();
            inv.ExRate      = SafeValue.SafeDecimal(exRate.Value, 1);
            if (inv.ExRate <= 0)
            {
                inv.ExRate = 1;
            }
            inv.AcCode = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
            if (inv.AcCode == "")
            {
                throw new Exception("Please frist set account code!");
            }
            inv.AcSource    = acSource.Value.ToString();
            inv.SpecialNote = specialNote.Text;

            inv.MastType  = jobType.Text;
            inv.MastRefNo = mastRefNCtr.Text;
            inv.JobRefNo  = jobRefNCtr.Text;

            inv.ExportInd  = "N";
            inv.UserId     = HttpContext.Current.User.Identity.Name;
            inv.EntryDate  = DateTime.Now;
            inv.CancelDate = new DateTime(1900, 1, 1);
            inv.CancelInd  = "N";
            try
            {
                C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                C2.Manager.ORManager.PersistChanges(inv);
                C2Setup.SetNextNo("", counterType, invN, inv.DocDate);
            }
            catch
            {
            }
        }
        else
        {
            inv.PartyTo = SafeValue.SafeString(partyTo.Value, "");

            inv.Term    = termId.Text;
            inv.DocDate = docDate.Date;
            string[] currentPeriod = EzshipHelper.GetAccPeriod(docDate.Date);

            inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], docDate.Date.Year);
            inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], docDate.Date.Month);

            int dueDay = SafeValue.SafeInt(termId.Text.ToUpper().Replace("DAYS", "").Trim(), 0);
            inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
            inv.Description = remarks1.Text;
            inv.CurrencyId  = docCurr.Text.ToString();
            inv.ExRate      = SafeValue.SafeDecimal(exRate.Value, 1);
            if (inv.ExRate <= 0)
            {
                inv.ExRate = 1;
            }
            inv.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
            inv.AcSource    = acSource.Text;
            inv.SpecialNote = specialNote.Text;

            inv.MastType  = jobType.Text;
            inv.MastRefNo = mastRefNCtr.Text;
            inv.JobRefNo  = jobRefNCtr.Text;
            try
            {
                Manager.ORManager.StartTracking(inv, InitialState.Updated);
                Manager.ORManager.PersistChanges(inv);
                UpdateMaster(inv.SequenceId);
            }
            catch
            {
            }
        }
        Session["SeaIvEditWhere"]         = "SequenceId=" + inv.SequenceId;
        this.dsArInvoice.FilterExpression = Session["SeaIvEditWhere"].ToString();
        if (this.ASPxGridView1.GetRow(0) != null)
        {
            this.ASPxGridView1.StartEdit(0);
        }
    }
コード例 #2
0
    public static DataSet DsImpTs(string orderNo, string docType)
    {
        DataSet set = new DataSet();

        if (docType == "IV" || docType == "IV1")
        {
            ObjectQuery query  = new ObjectQuery(typeof(C2.XAArInvoice), "DocNo='" + orderNo + "'", "");
            ObjectSet   objSet = C2.Manager.ORManager.GetObjectSet(query);
            if (objSet.Count == 0 || objSet[0] == null)
            {
                return(new DataSet());
            }
            C2.XAArInvoice obj = objSet[0] as C2.XAArInvoice;
            #region Invoice
            DataTable mast      = InitMastDataTable();
            DataRow   row       = mast.NewRow();
            string    mastRefNo = obj.MastRefNo;
            string    mastType  = obj.MastType;

            Wilson.ORMapper.OPathQuery job = new Wilson.ORMapper.OPathQuery(typeof(C2.CtmJob), "JobNo='" + mastRefNo + "'");

            C2.CtmJob ctmJob = C2.Manager.ORManager.GetObject(job) as C2.CtmJob;
            if (ctmJob != null)
            {
                row["Vessel"]    = ctmJob.Vessel;
                row["Voyage"]    = ctmJob.Voyage;
                row["Eta"]       = ctmJob.EtaDate.ToString("dd.MM.yy");
                row["CustRefNo"] = ctmJob.ClientRefNo;
                row["Pol"]       = ctmJob.Pol;
                row["Pod"]       = ctmJob.Pod;
                row["CrBkgNo"]   = ctmJob.CarrierBkgNo;
                row["HblNo"]     = ctmJob.CarrierBlNo;
            }
            row["JobNo"]      = mastRefNo;
            row["BillType"]   = "TAX INVOICE";
            row["DocNo"]      = obj.DocNo;
            row["DocDate"]    = obj.DocDate.ToString("dd/MM/yyyy");
            row["DocDueDate"] = obj.DocDueDate.ToString("dd/MM/yyyy");
            row["UserId"]     = HttpContext.Current.User.Identity.Name;
            row["PartyName"]  = obj.PartyName;
            row["PartyTo"]    = obj.PartyTo;
            string    sql = string.Format(@"select Address,Contact1,Fax1,Tel1,CrNo from XXParty where PartyId='{0}'", obj.PartyTo);
            DataTable tab = ConnectSql_mb.GetDataTable(sql);
            if (tab.Rows.Count > 0)
            {
                row["PartyAdd"] = tab.Rows[0]["Address"].ToString();
                row["Contact1"] = tab.Rows[0]["Contact1"].ToString();
                row["Fax1"]     = tab.Rows[0]["Fax1"].ToString();
                row["Tel1"]     = tab.Rows[0]["Tel1"].ToString();
                row["CrNo"]     = tab.Rows[0]["CrNo"].ToString();
            }
            row["Terms"]       = obj.Term;
            row["Terms"]       = obj.Term;
            row["CompanyName"] = System.Configuration.ConfigurationManager.AppSettings["CompanyName"];
            row["MoneyWords"]  = "";
            row["Remark"]      = SafeValue.SafeString(ConnectSql.ExecuteScalar(string.Format(@"select Description from XAArInvoice where MastRefNo='{0}'", mastRefNo)));
            decimal subTotal = 0;
            decimal gstTotal = obj.TaxAmt;


            DataTable details = InitDetailDataTable();
            sql = string.Format(@"select ChgCode,Qty,MastType,DocNo,ChgDes1,Price,Gst,GstAmt,Unit,
 LineLocAmt, Currency,ExRate,
LocAmt,JobRefNo,GstType from XAArInvoiceDet where DocId={0}  order by Gst desc", obj.SequenceId);
            DataTable det = ConnectSql.GetTab(sql);
            for (int i = 0; i < det.Rows.Count; i++)
            {
                DataRow row1    = details.NewRow();
                string  cntType = SafeValue.SafeString(det.Rows[i]["JobRefNo"]);
                string  chgCode = SafeValue.SafeString(det.Rows[i]["ChgCode"]);
                row1["No"]       = i + 1;
                row1["DocNo"]    = SafeValue.SafeString(det.Rows[i]["DocNo"]);
                row1["ChgDes1"]  = SafeValue.SafeString(det.Rows[i]["ChgDes1"]);
                row1["ChgCode"]  = SafeValue.SafeString(det.Rows[i]["ChgCode"]);
                row1["LineAmt"]  = SafeValue.SafeString(det.Rows[i]["LineLocAmt"]);
                row1["Unit"]     = SafeValue.SafeString(det.Rows[i]["Unit"]);
                row1["Currency"] = SafeValue.SafeString(det.Rows[i]["Currency"]);
                row1["ExRate"]   = SafeValue.SafeString(det.Rows[i]["ExRate"]);
                row1["Price"]    = string.Format("{0:#,##0.00}", SafeValue.SafeString(det.Rows[i]["Price"]));
                row1["Gst"]      = SafeValue.SafeInt(SafeValue.SafeDecimal(det.Rows[i]["Gst"]) * 100, 0) + "% " + det.Rows[i]["GstType"] + "R";
                decimal amt    = SafeValue.ChinaRound(SafeValue.SafeInt(det.Rows[i]["Qty"], 0) * SafeValue.SafeDecimal(det.Rows[i]["Price"], 0), 2);
                decimal gstAmt = SafeValue.ChinaRound((amt * SafeValue.SafeDecimal(det.Rows[i]["Gst"], 0)), 2);
                row1["Amt"]    = amt;
                row1["GstAmt"] = SafeValue.SafeString(det.Rows[i]["GstAmt"]);
                row1["LocAmt"] = SafeValue.SafeString(det.Rows[i]["LocAmt"]);
                row1["Qty"]    = SafeValue.SafeInt(det.Rows[i]["Qty"], 0);
                details.Rows.Add(row1);


                subTotal += amt;
            }
            sql = string.Format(@"select ContainerNo,SealNo,ContainerType from CTM_JobDet1 where JobNo='{0}' ", mastRefNo);
            DataTable cnt = ConnectSql.GetTab(sql);
            for (int i = 0; i < cnt.Rows.Count; i++)
            {
                if (cnt.Rows.Count - i > 1)
                {
                    row["ContainerNo"] += SafeValue.SafeString(cnt.Rows[i]["ContainerNo"]) + " / " + SafeValue.SafeString(cnt.Rows[i]["SealNo"])
                                          + " / " + SafeValue.SafeString(cnt.Rows[i]["ContainerType"]) + "\n";
                }
                else
                {
                    row["ContainerNo"] += SafeValue.SafeString(cnt.Rows[i]["ContainerNo"]) + " / " + SafeValue.SafeString(cnt.Rows[i]["SealNo"])
                                          + " / " + SafeValue.SafeString(cnt.Rows[i]["ContainerType"]);
                }
            }

            row["SubTotal"] = subTotal;
            row["GstTotal"] = gstTotal;
            row["TotalAmt"] = subTotal + gstTotal;
            mast.Rows.Add(row);

            #endregion

            set.Tables.Add(mast);
            set.Tables.Add(details);
        }
        if (docType == "PL" || docType == "PL1")
        {
            ObjectQuery query  = new ObjectQuery(typeof(C2.XAApPayable), "DocNo='" + orderNo + "'", "");
            ObjectSet   objSet = C2.Manager.ORManager.GetObjectSet(query);
            if (objSet.Count == 0 || objSet[0] == null)
            {
                return(new DataSet());
            }
            C2.XAApPayable obj = objSet[0] as C2.XAApPayable;
            #region PL
            DataTable mast      = InitMastDataTable();
            DataRow   row       = mast.NewRow();
            string    mastRefNo = obj.MastRefNo;
            string    mastType  = obj.MastType;
            if (mastType == "CTM")
            {
                Wilson.ORMapper.OPathQuery job = new Wilson.ORMapper.OPathQuery(typeof(C2.CtmJob), "JobNo='" + mastRefNo + "'");

                C2.CtmJob ctmJob = C2.Manager.ORManager.GetObject(job) as C2.CtmJob;
                row["Vessel"] = ctmJob.Vessel;
                row["Voyage"] = ctmJob.Voyage;
                row["Eta"]    = ctmJob.EtaDate.ToString("dd.MM.yy");
            }
            row["DocNo"]            = obj.DocNo;
            row["DocDate"]          = obj.DocDate.ToString("dd/MM/yyyy");
            row["SupplierBillNo"]   = obj.SupplierBillNo;
            row["SupplierBillDate"] = obj.SupplierBillDate.ToString("dd/MM/yyyy");

            row["PartyName"] = obj.PartyName;
            string sql = string.Format(@"select Address from XXParty where PartyId='{0}'", obj.PartyTo);
            row["PartyAdd"] = C2.Manager.ORManager.ExecuteScalar(sql);
            row["Terms"]    = obj.Term;

            decimal subTotal = 0;
            decimal gstTotal = 0;


            DataTable details = InitDetailDataTable();
            sql = string.Format(@"select ChgCode,sum(Qty) as Qty,MastType,max(DocNo) DocNo,max(ChgDes1) as ChgDes1,Price,max(Gst) Gst,max(GstAmt) GstAmt,
max(LocAmt) LocAmt,max(JobRefNo) JobRefNo,max(GstType) GstType from XAApPayableDet where DocId={0} group by ChgCode,MastType,Price order by Gst desc", obj.SequenceId);
            DataTable det = ConnectSql.GetTab(sql);
            for (int i = 0; i < det.Rows.Count; i++)
            {
                DataRow row1    = details.NewRow();
                string  cntType = SafeValue.SafeString(det.Rows[i]["JobRefNo"]);
                string  chgCode = SafeValue.SafeString(det.Rows[i]["ChgCode"]);
                row1["DocNo"]   = SafeValue.SafeString(det.Rows[i]["DocNo"]);
                row1["ChgDes1"] = SafeValue.SafeString(det.Rows[i]["ChgDes1"]);
                row1["ChgCode"] = SafeValue.SafeString(det.Rows[i]["ChgCode"]);
                row1["Price"]   = string.Format("{0:#,##0.00}", SafeValue.SafeString(det.Rows[i]["Price"]));
                row1["Gst"]     = SafeValue.SafeInt(SafeValue.SafeDecimal(det.Rows[i]["Gst"]) * 100, 0) + "% " + det.Rows[i]["GstType"] + "R";
                decimal amt    = SafeValue.ChinaRound(SafeValue.SafeInt(det.Rows[i]["Qty"], 0) * SafeValue.SafeDecimal(det.Rows[i]["Price"], 0), 2);
                decimal gstAmt = SafeValue.ChinaRound((amt * SafeValue.SafeDecimal(det.Rows[i]["Gst"], 0)), 2);
                row1["Amt"]    = amt;
                row1["GstAmt"] = SafeValue.SafeString(det.Rows[i]["GstAmt"]);
                row1["LocAmt"] = SafeValue.SafeString(det.Rows[i]["LocAmt"]);
                row1["Qty"]    = SafeValue.SafeInt(det.Rows[i]["Qty"], 0);
                details.Rows.Add(row1);


                subTotal += amt;
                gstTotal += gstAmt;
            }

            row["SubTotal"] = subTotal;
            row["GstTotal"] = gstTotal;
            row["Total"]    = subTotal + gstTotal;
            mast.Rows.Add(row);

            #endregion

            set.Tables.Add(mast);
            set.Tables.Add(details);
        }
        return(set);
    }
コード例 #3
0
    protected void grid_SKULine_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e)
    {
        string s      = e.Parameters;
        string soNo   = SafeValue.SafeString(Request.QueryString["no"].ToString());
        string schId  = SafeValue.SafeString(Request.QueryString["SchId"].ToString());
        string userId = HttpContext.Current.User.Identity.Name;

        if (s == "Save")
        {
            bool      result = false;
            string    issueN = "";
            string    sql    = string.Format(@"select * from Wh_TransDet where DoNo='{0}'", soNo);
            DataTable tab    = ConnectSql.GetTab(sql);
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                if (SafeValue.SafeInt(tab.Rows[i]["Qty1"], 0) == 0)
                {
                    e.Result = "Fail,Please keyin Qty ";
                    return;
                }
            }
            C2.XAArInvoice inv    = null;
            C2.XAArInvoice inv_Do = null;
            if (tab.Rows.Count > 0)
            {
                //Get SO
                #region Get So
                bool isNew = false;
                Wilson.ORMapper.OPathQuery query1 = new Wilson.ORMapper.OPathQuery(typeof(WhTrans), "DoNo='" + soNo + "'");
                WhTrans   so     = C2.Manager.ORManager.GetObject(query1) as WhTrans;
                string    sql1   = string.Format("select doNo from wh_do where DoType='Out' and PoNo='{0}'", soNo);
                DataTable tab_do = ConnectSql.GetTab(sql1);
                string where = "(1=0";
                for (int i = 0; i < tab_do.Rows.Count; i++)
                {
                    where += string.Format(" or DoNo='{0}' ", tab_do.Rows[i][0]);
                }
                where += ")";

                int cnt = 0;
                sql = string.Format("select count(*) from wh_transDet where DoNo='{0}' and DoType='SO' and isnull(LotNo,'')='' ", soNo);
                cnt = SafeValue.SafeInt(ConnectSql.ExecuteSql(sql), 0);
                if (cnt > 0)
                {
                    e.Result = "No Balance Qty or No Lot No!";
                    return;
                }
                string update = string.Format(@"update Wh_Schedule set StatusCode='Closed' where Id='{1}'", soNo, schId);
                C2.Manager.ORManager.ExecuteCommand(update);
                #endregion
                #region Create SO Invoice
                int    invId = 0;
                string invN  = "";
                inv = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv         = new XAArInvoice();
                    invN        = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv.DocType = "IV";
                    inv.DocNo   = invN.ToString();
                    inv.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv.Description = so.Remark;
                    inv.CurrencyId  = so.Currency;
                    inv.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv.ExRate <= 0)
                    {
                        inv.ExRate = 1;
                    }
                    inv.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv.AcSource    = "DB";
                    inv.SpecialNote = "";

                    inv.MastType  = "WH";
                    inv.MastRefNo = so.DoNo;
                    inv.JobRefNo  = "";

                    inv.ExportInd  = "N";
                    inv.UserId     = HttpContext.Current.User.Identity.Name;
                    inv.EntryDate  = DateTime.Now;
                    inv.CancelDate = new DateTime(1900, 1, 1);
                    inv.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv);
                        C2Setup.SetNextNo("", counterType, invN, inv.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
                #region Create DO
                //Create DoNo
                string doId = "";
                Wilson.ORMapper.OPathQuery query2 = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "Id='" + doId + "'");
                WhDo whDo = C2.Manager.ORManager.GetObject(query2) as WhDo;

                if (whDo == null)
                {
                    whDo        = new WhDo();
                    isNew       = true;
                    issueN      = C2Setup.GetNextNo("", "DOOUT", so.DoDate);
                    whDo.DoType = "OUT";
                }
                whDo.DoNo           = issueN;
                whDo.PoNo           = so.DoNo;
                whDo.DoDate         = so.DoDate;
                whDo.PoDate         = so.DoDate;
                whDo.StatusCode     = "CLS";
                whDo.PartyId        = so.PartyId;
                whDo.PartyName      = so.PartyName;
                whDo.AgentId        = so.AgentId;
                whDo.AgentName      = so.AgentName;
                whDo.AgentTel       = so.AgentTel;
                whDo.AgentZip       = so.AgentZip;
                whDo.AgentCountry   = so.AgentCountry;
                whDo.AgentCity      = so.AgentCity;
                whDo.NotifyId       = so.NotifyId;
                whDo.NotifyName     = so.NotifyName;
                whDo.WareHouseId    = so.WareHouseId;
                whDo.CreateBy       = so.CreateBy;
                whDo.CreateDateTime = so.CreateDateTime;
                whDo.UpdateBy       = so.UpdateBy;
                whDo.UpdateDateTime = so.UpdateDateTime;
                if (isNew)
                {
                    Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(whDo);
                    C2Setup.SetNextNo("", "DOOUT", issueN, DateTime.Now);
                }
                #endregion
                #region Create DO Invoice
                inv_Do = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv_Do == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv_Do         = new XAArInvoice();
                    invN           = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv_Do.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv_Do.DocType = "IV";
                    inv_Do.DocNo   = invN.ToString();
                    inv_Do.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv_Do.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv_Do.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv_Do.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv_Do.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv_Do.Description = so.Remark;
                    inv_Do.CurrencyId  = so.Currency;
                    inv_Do.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv_Do.ExRate <= 0)
                    {
                        inv_Do.ExRate = 1;
                    }
                    inv_Do.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv_Do.AcSource    = "DB";
                    inv_Do.SpecialNote = "";

                    inv_Do.MastType  = "WH";
                    inv_Do.MastRefNo = whDo.DoNo;
                    inv_Do.JobRefNo  = "";

                    inv_Do.ExportInd  = "N";
                    inv_Do.UserId     = HttpContext.Current.User.Identity.Name;
                    inv_Do.EntryDate  = DateTime.Now;
                    inv_Do.CancelDate = new DateTime(1900, 1, 1);
                    inv_Do.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv_Do, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv_Do);
                        C2Setup.SetNextNo("", counterType, invN, inv_Do.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
            }
            #region Create Transfer
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                string  product  = SafeValue.SafeString(tab.Rows[i]["ProductCode"]);
                string  lotNo    = SafeValue.SafeString(tab.Rows[i]["LotNo"]);
                int     qty      = SafeValue.SafeInt(tab.Rows[i]["Qty1"], 0);
                decimal price    = SafeValue.SafeDecimal(tab.Rows[i]["Price"]);
                string  des1     = SafeValue.SafeString(tab.Rows[i]["Des1"]);
                string  location = SafeValue.SafeString(tab.Rows[i]["LocationCode"]);

                sql  = @"Insert Into wh_DoDet(JobStatus,DoNo, DoType,ProductCode,ExpiredDate,Price,Qty1,Qty2,Qty3,Qty4,Qty5,LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],DoInId)";
                sql += string.Format(@" select * from (select 'Picked' as JobStatus,'{1}'as DoNo, 'Out' as DoType,ProductCode,ExpiredDate,Price
,Qty1 as Qty1
,0 as Qty2
,0 as Qty3
,Qty1 as Qty4
,0 as Qty5
, LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,'{2}' as CreateBy,getdate() as CreateDateTime,'{2}' as UpdateBy,getdate() as UpdateDateTime,Id as DoInId from Wh_TransDet where DoNo='{0}' and ProductCode='{4}' and LotNo='{5}' and DoType='SO' and LocationCode='{3}'
 ) as tab_aa where qty4>0  ", soNo, issueN, userId, location, product, lotNo);

                C2.Manager.ORManager.ExecuteCommand(sql);

                sql  = @"Insert Into Wh_DoDet2(DoNo,DoType,Product,Qty1,Qty2,Qty3,Price,LotNo,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],Att1,Att2,Att3,Att4,Att5,Att6,Des1,Packing,Location,ProcessStatus)";
                sql += string.Format(@"select '{0}'as DoNo, 'OUT' as DoType,'{1}' as Sku
 ,'{2}' as Qty1
 ,0 as Qty2
 ,0 as Qty3
 ,'{3}' as Price
,'{4}' as LotNo
,ref.UomPacking as Uom1,ref.UomWhole as Uom2,ref.UomLoose as Uom3,ref.UomBase as Uom4
,ref.QtyPackingWhole as QtyPackWhole,ref.QtyWholeLoose as  QtyWholeLoose,ref.QtyLooseBase as QtyLooseBase
,'{5}' as CreateBy,getdate() as CreateDateTime,'{5}' as UpdateBy,getdate() as UpdateDateTime
,ref.Att4 as Att1,ref.Att5 as Att2,ref.att6 as Att3,ref.att7 as Att4,ref.att8 as Att5,ref.att9 as Att6,ref.Description as Des1,'' as Packing,'{6}' as Location,'Delivered' as ProcessStatus
from (select '{1}' as Sku) as tab inner join ref_product ref on ref.Code=tab.Sku", issueN, product, qty, price, lotNo, userId, location);
                C2.Manager.ORManager.ExecuteCommand(sql);
                InsertInv_Det(inv.SequenceId, inv.DocNo, i + 1, product, lotNo, des1, qty, price, inv.CurrencyId, inv.ExRate, 0, inv.MastRefNo, "", inv.MastType, "IV");
                UpdateMaster(inv.SequenceId);

                InsertInv_Det(inv_Do.SequenceId, inv_Do.DocNo, i + 1, product, lotNo, des1, qty, price, inv_Do.CurrencyId, inv_Do.ExRate, 0, inv_Do.MastRefNo, "", inv_Do.MastType, "IV");
                UpdateMaster(inv_Do.SequenceId);
                if (soNo.Length > 0)
                {
                    result = true;
                }
            }
            #endregion
            if (result)
            {
                e.Result = issueN;
            }
            else
            {
                e.Result = "Fail,Please keyin select product ";
            }
        }
    }
コード例 #4
0
    protected void ASPxGridView1_CustomDataCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomDataCallbackEventArgs e)
    {
        string s     = e.Parameters;
        string schId = SafeValue.SafeString(Request.QueryString["SchId"].ToString());
        //string code = SafeValue.SafeString(Request.QueryString["Loc"].ToString());
        string salesman = SafeValue.SafeString(Request.QueryString["Salesman"].ToString());
        string location = SafeValue.SafeString(cmb_Location.Text.Trim());
        string userId   = HttpContext.Current.User.Identity.Name;

        if (s == "Save")
        {
            bool   result = false;
            string soNo   = "";
            string issueN = "";
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].qty == 0)
                {
                    e.Result = "Fail,Please keyin Qty ";
                    return;
                }
            }
            C2.XAArInvoice inv    = null;
            C2.XAArInvoice inv_Do = null;
            if (list.Count > 0)
            {
                //Create SO
                #region Create So
                Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(WhSchedule), "Id='" + schId + "'");
                WhSchedule sch   = C2.Manager.ORManager.GetObject(query) as WhSchedule;
                bool       isNew = false;
                Wilson.ORMapper.OPathQuery query1 = new Wilson.ORMapper.OPathQuery(typeof(WhTrans), "DoNo='" + 0 + "'");
                WhTrans so = C2.Manager.ORManager.GetObject(query1) as WhTrans;
                if (so == null)
                {
                    isNew = true;
                    so    = new WhTrans();
                    soNo  = C2Setup.GetNextNo("", "SaleOrders", DateTime.Now);
                }


                so.DoNo           = soNo;
                so.DoDate         = DateTime.Now;
                so.PartyId        = sch.PartyId;
                so.PartyName      = sch.PartyName;
                so.Pic            = sch.PartyContact;
                so.PartyAdd       = sch.PartyAdd;
                so.AgentId        = sch.DoctorId;
                so.AgentName      = EzshipHelper.GetPartyName(sch.DoctorId);
                so.NotifyId       = sch.Patient;
                so.NotifyName     = GetPatientName(sch.Patient);
                so.Currency       = "SGD";
                so.DoType         = "SO";
                so.DoStatus       = "Draft";
                so.ExRate         = 1;
                so.SalesId        = salesman;
                so.CreateBy       = userId;
                so.CreateDateTime = DateTime.Now;
                so.UpdateBy       = userId;
                so.UpdateDateTime = DateTime.Now;
                if (isNew)
                {
                    Manager.ORManager.StartTracking(so, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(so);
                    C2Setup.SetNextNo("", "SaleOrders", soNo, DateTime.Now);
                }
                else
                {
                    Manager.ORManager.StartTracking(so, Wilson.ORMapper.InitialState.Updated);
                    Manager.ORManager.PersistChanges(so);
                }
                sch.DoNo = soNo;
                string update = string.Format(@"update Wh_Schedule set DoNo='{0}',StatusCode='Finished' where Id='{1}'", soNo, schId);
                C2.Manager.ORManager.ExecuteCommand(update);
                #endregion
                #region Create SO Invoice
                int    invId = 0;
                string invN  = "";
                inv = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv         = new XAArInvoice();
                    invN        = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv.DocType = "IV";
                    inv.DocNo   = invN.ToString();
                    inv.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv.Description = so.Remark;
                    inv.CurrencyId  = so.Currency;
                    inv.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv.ExRate <= 0)
                    {
                        inv.ExRate = 1;
                    }
                    inv.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv.AcSource    = "DB";
                    inv.SpecialNote = "";

                    inv.MastType  = "WH";
                    inv.MastRefNo = so.DoNo;
                    inv.JobRefNo  = "";

                    inv.ExportInd  = "N";
                    inv.UserId     = HttpContext.Current.User.Identity.Name;
                    inv.EntryDate  = DateTime.Now;
                    inv.CancelDate = new DateTime(1900, 1, 1);
                    inv.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv);
                        C2Setup.SetNextNo("", counterType, invN, inv.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
                #region Create DO
                //Create DoNo
                string doId = "";
                Wilson.ORMapper.OPathQuery query2 = new Wilson.ORMapper.OPathQuery(typeof(WhDo), "Id='" + doId + "'");
                WhDo whDo = C2.Manager.ORManager.GetObject(query2) as WhDo;

                if (whDo == null)
                {
                    whDo        = new WhDo();
                    isNew       = true;
                    issueN      = C2Setup.GetNextNo("", "DOOUT", so.DoDate);
                    whDo.DoType = "OUT";
                }
                whDo.DoNo           = issueN;
                whDo.PoNo           = so.DoNo;
                whDo.DoDate         = so.DoDate;
                whDo.PoDate         = so.DoDate;
                whDo.StatusCode     = "CLS";
                whDo.PartyId        = so.PartyId;
                whDo.PartyName      = so.PartyName;
                whDo.AgentId        = so.AgentId;
                whDo.AgentName      = so.AgentName;
                whDo.AgentTel       = so.AgentTel;
                whDo.AgentZip       = so.AgentZip;
                whDo.AgentCountry   = so.AgentCountry;
                whDo.AgentCity      = so.AgentCity;
                whDo.NotifyId       = so.NotifyId;
                whDo.NotifyName     = so.NotifyName;
                whDo.WareHouseId    = location;
                whDo.CreateBy       = so.CreateBy;
                whDo.CreateDateTime = so.CreateDateTime;
                whDo.UpdateBy       = so.UpdateBy;
                whDo.UpdateDateTime = so.UpdateDateTime;
                if (isNew)
                {
                    Manager.ORManager.StartTracking(whDo, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(whDo);
                    C2Setup.SetNextNo("", "DOOUT", issueN, DateTime.Now);
                }
                #endregion
                #region Create DO Invoice
                inv_Do = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invId, 0)) as XAArInvoice;
                if (inv_Do == null)// first insert invoice
                {
                    string counterType = "AR-IV";
                    inv_Do         = new XAArInvoice();
                    invN           = C2Setup.GetNextNo("", counterType, so.DoDate);
                    inv_Do.PartyTo = SafeValue.SafeString(so.PartyId, "");
                    inv_Do.DocType = "IV";
                    inv_Do.DocNo   = invN.ToString();
                    inv_Do.DocDate = so.DoDate;
                    string[] currentPeriod = EzshipHelper.GetAccPeriod(so.DoDate);

                    inv_Do.AcYear   = SafeValue.SafeInt(currentPeriod[1], so.DoDate.Year);
                    inv_Do.AcPeriod = SafeValue.SafeInt(currentPeriod[0], so.DoDate.Month);
                    inv_Do.Term     = so.PayTerm;

                    //
                    int dueDay = 0;
                    if (so.PayTerm != null)
                    {
                        dueDay = SafeValue.SafeInt(so.PayTerm.ToUpper().Replace("DAYS", ""), 0);
                    }

                    inv_Do.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                    inv_Do.Description = so.Remark;
                    inv_Do.CurrencyId  = so.Currency;
                    inv_Do.ExRate      = SafeValue.SafeDecimal(so.ExRate, 1);
                    if (inv_Do.ExRate <= 0)
                    {
                        inv_Do.ExRate = 1;
                    }
                    inv_Do.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                    inv_Do.AcSource    = "DB";
                    inv_Do.SpecialNote = "";

                    inv_Do.MastType  = "WH";
                    inv_Do.MastRefNo = whDo.DoNo;
                    inv_Do.JobRefNo  = "";

                    inv_Do.ExportInd  = "N";
                    inv_Do.UserId     = HttpContext.Current.User.Identity.Name;
                    inv_Do.EntryDate  = DateTime.Now;
                    inv_Do.CancelDate = new DateTime(1900, 1, 1);
                    inv_Do.CancelInd  = "N";
                    try
                    {
                        C2.Manager.ORManager.StartTracking(inv_Do, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(inv_Do);
                        C2Setup.SetNextNo("", counterType, invN, inv_Do.DocDate);
                    }
                    catch
                    {
                    }
                }
                #endregion
            }
            #region Create Transfer
            for (int i = 0; i < list.Count; i++)
            {
                string  id      = list[i].id;
                string  product = list[i].product;
                string  lotNo   = list[i].lotNo;
                int     qty     = list[i].qty;
                decimal price   = list[i].price;
                //string loction = list[i].location;
                string des1   = list[i].des1;
                int    hanQty = list[i].hanQty;
                if (qty > hanQty)
                {
                    e.Result = "Fail,Please keyin the correct qty ";
                    return;
                }
                //string salesman = list[i].salesman;
                string sql = @"Insert Into Wh_TransDet(DoNo, DoType,ProductCode,Qty1,Qty2,Qty3,Price,LotNo,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],Att1,Att2,Att3,Att4,Att5,Att6,Des1,LocationCode,DocAmt)";
                sql += string.Format(@"select '{0}'as DoNo, 'SO' as DoType,'{1}' as ProductCode
 ,'{2}' as Qty1
 ,0 as Qty2
 ,0 as Qty3
 ,'{3}' as Price
,'{4}' as LotNo
,ref.UomPacking as Uom1,ref.UomWhole as Uom2,ref.UomLoose as Uom3,ref.UomBase as Uom4
,ref.QtyPackingWhole as QtyPackWhole,ref.QtyWholeLoose as  QtyWholeLoose,ref.QtyLooseBase as QtyLooseBase
,'{5}' as CreateBy,getdate() as CreateDateTime,'{5}' as UpdateBy,getdate() as UpdateDateTime
,ref.Att4 as Att1,ref.Att5 as Att2,ref.att6 as Att3,ref.att7 as Att4,ref.att8 as Att5,ref.att9 as Att6,ref.Description as Des1,'{6}' as LocationCode,{2}*{3} as DocAmt
from (select '{1}' as Sku) as tab inner join ref_product ref on ref.Code=tab.Sku", soNo, product, qty, price, lotNo, EzshipHelper.GetUserName(), location);
                C2.Manager.ORManager.ExecuteCommand(sql);

                sql  = @"Insert Into wh_DoDet(JobStatus,DoNo, DoType,ProductCode,ExpiredDate,Price,Qty1,Qty2,Qty3,Qty4,Qty5,LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],DoInId)";
                sql += string.Format(@" select * from (select 'Picked' as JobStatus,'{1}'as DoNo, 'Out' as DoType,ProductCode,ExpiredDate,Price
,Qty1 as Qty1
,0 as Qty2
,0 as Qty3
,Qty1 as Qty4
,0 as Qty5
, LotNo,BatchNo,CustomsLot,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],Att1,Att2,Att3,Att4,Att5,Att6,Att7,Att8,Att9,Att10,Des1,Packing,'{2}' as CreateBy,getdate() as CreateDateTime,'{2}' as UpdateBy,getdate() as UpdateDateTime,Id as DoInId from Wh_TransDet where DoNo='{0}' and ProductCode='{4}' and LotNo='{5}' and DoType='SO' and LocationCode='{3}'
 ) as tab_aa where qty4>0  ", soNo, issueN, userId, location, product, lotNo);

                C2.Manager.ORManager.ExecuteCommand(sql);

                sql  = @"Insert Into Wh_DoDet2(DoNo,DoType,Product,Qty1,Qty2,Qty3,Price,LotNo,Uom1,Uom2,Uom3,Uom4,[QtyPackWhole],[QtyWholeLoose],[QtyLooseBase],[CreateBy],[CreateDateTime],[UpdateBy],[UpdateDateTime],Att1,Att2,Att3,Att4,Att5,Att6,Des1,Packing,Location,ProcessStatus)";
                sql += string.Format(@"select '{0}'as DoNo, 'OUT' as DoType,'{1}' as Sku
 ,'{2}' as Qty1
 ,0 as Qty2
 ,0 as Qty3
 ,'{3}' as Price
,'{4}' as LotNo
,ref.UomPacking as Uom1,ref.UomWhole as Uom2,ref.UomLoose as Uom3,ref.UomBase as Uom4
,ref.QtyPackingWhole as QtyPackWhole,ref.QtyWholeLoose as  QtyWholeLoose,ref.QtyLooseBase as QtyLooseBase
,'{5}' as CreateBy,getdate() as CreateDateTime,'{5}' as UpdateBy,getdate() as UpdateDateTime
,ref.Att4 as Att1,ref.Att5 as Att2,ref.att6 as Att3,ref.att7 as Att4,ref.att8 as Att5,ref.att9 as Att6,ref.Description as Des1,'' as Packing,'{6}' as Location,'Delivered' as ProcessStatus
from (select '{1}' as Sku) as tab inner join ref_product ref on ref.Code=tab.Sku", issueN, product, qty, price, lotNo, userId, location);
                C2.Manager.ORManager.ExecuteCommand(sql);
                InsertInv_Det(inv.SequenceId, inv.DocNo, i + 1, product, lotNo, des1, qty, price, inv.CurrencyId, inv.ExRate, 0, inv.MastRefNo, "", inv.MastType, "IV");
                UpdateMaster(inv.SequenceId);

                InsertInv_Det(inv_Do.SequenceId, inv_Do.DocNo, i + 1, product, lotNo, des1, qty, price, inv_Do.CurrencyId, inv_Do.ExRate, 0, inv_Do.MastRefNo, "", inv_Do.MastType, "IV");
                UpdateMaster(inv_Do.SequenceId);
                if (soNo.Length > 0)
                {
                    result = true;
                }
            }
            #endregion
            if (result)
            {
                e.Result = soNo;
            }
            else
            {
                e.Result = "Fail,Please keyin select product ";
            }
        }
    }
コード例 #5
0
ファイル: ArCnEdit.aspx.cs プロジェクト: felix-wei/tsllog1806
    protected void ASPxGridView1_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        ASPxTextBox  invNCtr  = this.ASPxGridView1.FindEditFormTemplateControl("txt_Oid") as ASPxTextBox;
        ASPxComboBox partyTo  = this.ASPxGridView1.FindEditFormTemplateControl("cmb_PartyTo") as ASPxComboBox;
        ASPxTextBox  docN     = this.ASPxGridView1.FindEditFormTemplateControl("txt_DocNo") as ASPxTextBox;
        ASPxComboBox docType  = this.ASPxGridView1.FindEditFormTemplateControl("cbo_DocType") as ASPxComboBox;
        ASPxDateEdit docDate  = this.ASPxGridView1.FindEditFormTemplateControl("txt_DocDt") as ASPxDateEdit;
        ASPxMemo     remarks1 = this.ASPxGridView1.FindEditFormTemplateControl("txt_Remarks1") as ASPxMemo;
        ASPxComboBox termId   = this.ASPxGridView1.FindEditFormTemplateControl("txt_TermId") as ASPxComboBox;
        ASPxDateEdit dueDt    = this.ASPxGridView1.FindEditFormTemplateControl("txt_DueDt") as ASPxDateEdit;
        ASPxTextBox  docCurr  = this.ASPxGridView1.FindEditFormTemplateControl("txt_Currency") as ASPxTextBox;
        ASPxSpinEdit exRate   = this.ASPxGridView1.FindEditFormTemplateControl("txt_DocExRate") as ASPxSpinEdit;
        ASPxTextBox  acCode   = this.ASPxGridView1.FindEditFormTemplateControl("txt_AcCode") as ASPxTextBox;
        ASPxComboBox acSource = this.ASPxGridView1.FindEditFormTemplateControl("txt_AcSource") as ASPxComboBox;
        string       invN     = docN.Text;

        C2.XAArInvoice inv   = Manager.ORManager.GetObject(typeof(XAArInvoice), SafeValue.SafeInt(invNCtr.Text, 0)) as XAArInvoice;
        bool           isNew = false;

        if (inv == null)        // first insert invoice
        {
            isNew = true;
            string counterType = "AR-CN";

            inv         = new XAArInvoice();
            invN        = C2Setup.GetNextNo(counterType);
            inv.PartyTo = SafeValue.SafeString(partyTo.Value, "");
            inv.DocType = docType.Value.ToString();
            inv.DocNo   = invN.ToString();
            inv.DocDate = docDate.Date;
            string[] currentPeriod = EzshipHelper.GetAccPeriod(docDate.Date);

            inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], docDate.Date.Year);
            inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], docDate.Date.Month);
            inv.Term     = termId.Text;
            int dueDay = SafeValue.SafeInt(termId.Text.ToUpper().Replace("DAYS", "").Trim(), 0);
            inv.DocDueDate  = inv.DocDate.AddDays(dueDay);           //SafeValue.SafeDate(dueDt.Text, DateTime.Now);
            inv.Description = remarks1.Text;
            inv.CurrencyId  = docCurr.Text.ToString();
            inv.ExRate      = SafeValue.SafeDecimal(exRate.Value, 1);
            if (inv.ExRate <= 0)
            {
                inv.ExRate = 1;
            }
            inv.AcSource = acSource.Value.ToString();

            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.MastRefNo  = "0";
            inv.JobRefNo   = "0";
            inv.MastType   = "";

            inv.AcCode = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
            try
            {
                C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                C2.Manager.ORManager.PersistChanges(inv);
                C2Setup.SetNextNo(counterType, invN);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + ex.StackTrace);
            }
        }
        else
        {
            inv.PartyTo = SafeValue.SafeString(partyTo.Value, "");

            inv.Term    = termId.Text;
            inv.DocDate = docDate.Date;
            string[] currentPeriod = EzshipHelper.GetAccPeriod(docDate.Date);

            inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], docDate.Date.Year);
            inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], docDate.Date.Month);
            int dueDay = SafeValue.SafeInt(termId.Text.ToUpper().Replace("DAYS", "").Trim(), 0);
            inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
            inv.Description = remarks1.Text;
            inv.CurrencyId  = docCurr.Text.ToString();
            inv.ExRate      = SafeValue.SafeDecimal(exRate.Value, 1);
            if (inv.ExRate <= 0)
            {
                inv.ExRate = 1;
            }
            inv.AcSource = acSource.Text;

            inv.AcCode = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
            try
            {
                Manager.ORManager.StartTracking(inv, InitialState.Updated);
                Manager.ORManager.PersistChanges(inv);
                UpdateMaster(inv.SequenceId);
            }
            catch
            {
            }
        }
        if (isNew)
        {
            Session["CnEditWhere"]            = "SequenceId=" + inv.SequenceId;
            this.dsArInvoice.FilterExpression = Session["CnEditWhere"].ToString();
            if (this.ASPxGridView1.GetRow(0) != null)
            {
                this.ASPxGridView1.StartEdit(0);
            }
        }
    }
コード例 #6
0
    private string InsertInv(string mastType, string soNo, string doNo, string docType)
    {
        string sql = string.Format(@"select mast.PartyId,p.termid as Term
,det.ProductCode as Sku,det.LotNo,det.Qty1 as Qty,det.Price,mast.Currency,mast.ExRate,det.Gst
,det.Des1
from wh_transDet det inner join wh_trans mast on mast.DoNO=det.DoNo and mast.DoType=det.DoType
left join xxparty p on p.partyid=mast.partyid 
where mast.DoNO='{0}' ", soNo);

        if (doNo.Length > 0)
        {
            sql = string.Format(@"select mast.PartyId,p.termid as Term
,det.ProductCode as Sku,det.LotNo,det.Qty1 as Qty,tsDet.Price,tsMast.Currency,tsMast.ExRate,tsDet.Gst
,det.Des1
from wh_DoDet det inner join wh_do mast on mast.DoNO=det.DoNo and mast.DoType=det.DoType
left join xxparty p on p.partyid=mast.partyid
left join wh_transdet tsDet on tsDet.ProductCode=det.ProductCode and tsDet.LotNo=det.LotNo
left join wh_trans tsMast on tsMast.doNO=tsDet.DoNo and tsMast.DoType=tsDet.DoType
where mast.DoNO='{1}'  and tsDet.DoNO='{0}' ", soNo, doNo);
        }
        string    invN  = "";
        int       invId = 0;
        DataTable tab   = ConnectSql.GetTab(sql);

        for (int i = 0; i < tab.Rows.Count; i++)
        {
            if (i == 0)
            {
                string partyId = SafeValue.SafeString(tab.Rows[0]["PartyId"]);
                string term    = SafeValue.SafeString(tab.Rows[0]["Term"]);
                #region invoice mast
                string counterType = "AR-IV";
                if (docType == "CN")
                {
                    counterType = "AR-CN";
                }

                C2.XAArInvoice inv = new C2.XAArInvoice();

                inv.DocDate = DateTime.Today;
                invN        = C2Setup.GetNextNo("", counterType, inv.DocDate);
                inv.PartyTo = partyId;
                inv.DocType = docType;
                inv.DocNo   = invN.ToString();
                string[] currentPeriod = EzshipHelper.GetAccPeriod(inv.DocDate);

                inv.AcYear   = SafeValue.SafeInt(currentPeriod[1], inv.DocDate.Year);
                inv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], inv.DocDate.Month);
                inv.Term     = term;

                //
                int dueDay = SafeValue.SafeInt(inv.Term.ToUpper().Replace("DAYS", "").Trim(), 0);
                inv.DocDueDate  = inv.DocDate.AddDays(dueDay);//SafeValue.SafeDate(dueDt.Text, DateTime.Now);
                inv.Description = "";
                inv.CurrencyId  = System.Configuration.ConfigurationManager.AppSettings["Currency"];
                inv.ExRate      = 1;
                inv.AcCode      = EzshipHelper.GetAccArCode(inv.PartyTo, inv.CurrencyId);
                inv.AcSource    = "DB";
                inv.SpecialNote = "";

                inv.MastType  = mastType;
                inv.MastRefNo = soNo;
                inv.JobRefNo  = doNo;
                if (doNo.Length > 0)
                {
                    inv.MastRefNo = doNo;
                    inv.JobRefNo  = "";
                }
                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.InvType    = "ACCOUNT";
                try
                {
                    C2.Manager.ORManager.StartTracking(inv, Wilson.ORMapper.InitialState.Inserted);
                    C2.Manager.ORManager.PersistChanges(inv);
                    C2Setup.SetNextNo("", counterType, invN, inv.DocDate);
                    invId = inv.SequenceId;
                }
                catch
                {
                }
                #endregion
                if (invId < 1)
                {
                    return("");
                }
            }
            string  sku    = SafeValue.SafeString(tab.Rows[i]["Sku"]);
            string  des    = SafeValue.SafeString(tab.Rows[i]["Des1"]);
            string  lotNo  = SafeValue.SafeString(tab.Rows[i]["LotNo"]);
            int     qty    = SafeValue.SafeInt(tab.Rows[i]["Qty"], 0);
            decimal price  = SafeValue.SafeDecimal(tab.Rows[i]["Price"], 0);
            string  cur    = SafeValue.SafeString(tab.Rows[i]["Currency"]);
            decimal exRate = SafeValue.SafeDecimal(tab.Rows[i]["ExRate"], 0);
            decimal gst    = SafeValue.SafeDecimal(tab.Rows[i]["Gst"], 0);
            InsertInv_Det(invId, invN, i + 1, sku, lotNo, des, qty, price, cur, exRate, gst, soNo, doNo, mastType, docType);
        }
        if (invId > 0)
        {
            if (docType == "IV")
            {
                UpdateMaster(invId);
            }
            if (docType == "CN")
            {
                UpdateCN_Master(invId);
            }
            sql = string.Format("update Wh_Trans set DoStatus='Closed',UpdateBy='{1}',UpdateDateTime='{2}' where DoNo='{0}'", soNo, EzshipHelper.GetUserName(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            int res = Manager.ORManager.ExecuteCommand(sql);
            if (res > 0)
            {
                EzshipLog.Log(soNo, "", "SO", "Closed");
            }
        }
        return(invN);
    }