예제 #1
0
    private void InsertInv_Det(int docId, string docNo, int index, string sku, string lotNo, string des, int qty, decimal price, string cur, decimal exRate, decimal gst, string soNo, string doNo, string mastType, string docType)
    {
        try
        {
            C2.XAArInvoiceDet det = new C2.XAArInvoiceDet();
            det.DocId     = docId;
            det.DocLineNo = index;
            det.DocNo     = docNo;
            det.DocType   = docType;
            det.AcCode    = SafeValue.SafeString(ConnectSql.ExecuteScalar(string.Format("select ArCode from ref_product where Code='{0}'", sku)), System.Configuration.ConfigurationManager.AppSettings["LocalArCode"]);
            det.AcSource  = "CR";
            det.MastRefNo = soNo;
            det.JobRefNo  = lotNo;
            if (doNo.Length > 0)
            {
                det.MastRefNo = doNo;
                det.JobRefNo  = "";
            }
            det.MastType  = mastType;
            det.SplitType = "";



            det.ChgCode = sku + "(Product)";
            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;
            det.OtherAmt = 0;
            C2.Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted);
            C2.Manager.ORManager.PersistChanges(det);
        }
        catch
        {
        }
    }
예제 #2
0
    protected void btn_CreateInv_Click(object sender, EventArgs e)
    {
        string   invNo    = "";
        string   mastType = "WH";
        DateTime dt       = DateTime.Today;
        bool     isNew    = false;
        int      docId    = 0;

        if (list.Count > 0)
        {
            XAArInvoice iv = null;
            for (int i = 0; i < list.Count; i++)
            {
                string  counterType = "AR-IV";
                string  partyId     = list[i].partyId;
                string  product     = list[i].doNo;
                string  doNo        = list[i].doNo;
                int     qty         = list[i].qty;
                decimal surcharge   = list[i].surcharge;
                string  sql_cost    = string.Format(@"select * from(select mast.DoNo,CONVERT(VARCHAR(10),mast.DoDate,110) as DoDate,cost.ChgCode as ChargeCode, 
ChgCodeDes as Description,CONVERT(int,CostQty) as Qty,CostPrice as Price,StatusCode,
isnull(((CostQty)*(isnull((CostPrice),0) )),0) as TotalAmt,dbo.fun_GetPartyName(mast.PartyId) AS PartyName,mast.PartyId,
0 as Surcharge,0 as SurchageAmt,JobType as DoType,CONVERT(decimal(10,6),(isnull((CostQty*CostPrice),0)*CostGst)) as GstAmt,
ISNULL((select count(SequenceId) from XAArInvoiceDet det where det.ChgCode=cost.ChgCode and det.MastRefNo=RefNo),0) as CostCnt,
isnull((select count(Id) from Wh_Costing where RefNo=mast.DoNo and JobType=mast.DoType),0) as CostDoCnt
 from Wh_Costing cost left join Wh_DO mast on RefNo=mast.DoNo and JobType=mast.DoType and StatusCode='CLS'
 ) as tab where CostCnt=0 and CostDoCnt>0 and TotalAmt>0 and DoNo='{0}'", doNo);
                string  sql         = string.Format(@"select top 1 det.DocNo from XAArInvoiceDet det inner join XAArInvoice mast on det.DocNo=mast.DocNo where det.MastRefNo='{0}' and InvType='HANDLING' and CancelInd='N' order by det.DocNo desc", doNo);
                invNo = SafeValue.SafeString(C2.Manager.ORManager.ExecuteScalar(sql));

                if (invNo.Length == 0)
                {
                    iv    = new XAArInvoice();
                    invNo = C2Setup.GetNextNo("", counterType, dt);
                    isNew = true;
                }
                else
                {
                    Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(XAArInvoice), "DocNo='" + invNo + "'");
                    iv    = C2.Manager.ORManager.GetObject(query) as XAArInvoice;
                    isNew = false;
                }
                iv.DocType     = "IV";
                iv.DocDate     = dt;
                iv.DocNo       = invNo;
                iv.PartyTo     = partyId;
                iv.CurrencyId  = System.Configuration.ConfigurationManager.AppSettings["Currency"];
                iv.ExRate      = 1;
                iv.AcCode      = EzshipHelper.GetAccApCode(iv.PartyTo, iv.CurrencyId);
                iv.AcSource    = "DB";
                iv.Description = "";
                iv.Term        = "CASH";

                string[] currentPeriod = EzshipHelper.GetAccPeriod(iv.DocDate);
                iv.AcYear   = SafeValue.SafeInt(currentPeriod[1], iv.DocDate.Year);
                iv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], iv.DocDate.Month);

                iv.MastRefNo   = "";
                iv.JobRefNo    = "";
                iv.MastType    = mastType;
                iv.DocAmt      = 0;
                iv.LocAmt      = 0;
                iv.BalanceAmt  = 0;
                iv.CancelDate  = new DateTime(1900, 1, 1);
                iv.CancelInd   = "N";
                iv.DocDueDate  = dt;
                iv.ExportInd   = "N";
                iv.SpecialNote = "";
                iv.UserId      = EzshipHelper.GetUserName();
                iv.EntryDate   = DateTime.Now;
                iv.InvType     = "HANDLING";
                if (isNew)
                {
                    C2.Manager.ORManager.StartTracking(iv, Wilson.ORMapper.InitialState.Inserted);
                    C2.Manager.ORManager.PersistChanges(iv);
                    C2Setup.SetNextNo(iv.DocType, counterType, invNo, iv.DocDate);
                }
                else
                {
                    Manager.ORManager.StartTracking(iv, Wilson.ORMapper.InitialState.Updated);
                    Manager.ORManager.PersistChanges(iv);
                }

                try
                {
                    DataTable tab_Cost = ConnectSql.GetTab(sql_cost);
                    for (int a = 0; a < tab_Cost.Rows.Count; a++)
                    {
                        C2.XAArInvoiceDet det = new C2.XAArInvoiceDet();
                        det.DocId     = iv.SequenceId;
                        det.DocLineNo = i + 1;
                        det.DocNo     = invNo;
                        det.DocType   = "IV";
                        det.AcCode    = SafeValue.SafeString(ConnectSql.ExecuteScalar(string.Format("select ArCode from ref_product where Code='{0}'", product)), System.Configuration.ConfigurationManager.AppSettings["ItemArCode"]);
                        det.AcSource  = "CR";
                        det.MastRefNo = doNo;
                        det.JobRefNo  = "";
                        det.MastType  = mastType;
                        det.SplitType = "";


                        det.ChgCode = SafeValue.SafeString(tab_Cost.Rows[a]["ChargeCode"]);;
                        det.ChgDes1 = SafeValue.SafeString(tab_Cost.Rows[a]["Description"]);
                        det.ChgDes2 = "";
                        det.ChgDes3 = "";

                        det.Price    = SafeValue.SafeDecimal(tab_Cost.Rows[a]["Price"]);
                        det.Qty      = SafeValue.SafeInt(tab_Cost.Rows[a]["Qty"], 0);
                        det.Unit     = "";
                        det.Currency = iv.CurrencyId;
                        det.ExRate   = 1;
                        det.Gst      = 0;
                        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;
                        det.OtherAmt = 0;

                        C2.Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted);
                        C2.Manager.ORManager.PersistChanges(det);
                        if (surcharge != 0)
                        {
                            det.ChgCode = "HANDLE";
                            det.Qty     = 1;
                            det.Price   = surcharge;
                            sql         = string.Format(@"select * from XXChgCode where ChgcodeId='{0}'", det.ChgCode);
                            DataTable tab = ConnectSql.GetTab(sql);
                            for (int j = 0; j < tab.Rows.Count; j++)
                            {
                                det.AcCode  = SafeValue.SafeString(tab.Rows[j]["ArCode"]);
                                det.ChgDes1 = SafeValue.SafeString(tab.Rows[j]["ChgcodeDes"]);
                                det.GstType = SafeValue.SafeString(tab.Rows[j]["GstTypeId"]);
                                det.Gst     = SafeValue.SafeDecimal(tab.Rows[j]["GstP"]);
                            }


                            amt    = SafeValue.ChinaRound(det.Qty * det.Price, 2);
                            gstAmt = SafeValue.ChinaRound((amt * det.Gst), 2);

                            docAmt = amt + gstAmt;

                            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);
                        }
                        docId = iv.SequenceId;
                    }
                }
                catch
                {
                }
                UpdateMaster(docId);
            }
            // string script = string.Format('<script type="text/javascript" > parent.navTab.openTab("{0}","/opsAccount/ArInvoiceEdit.aspx?no="{0}"",{title:'', fresh:false, external:true});</script>", invNo);
            //string script = string.Format("<script type='text/javascript' >alert('{0}');</script>", refNo);
            //Response.Clear();
            //Response.Write(script);
            //<a href='javascript: parent.navTab.openTab("<%# Eval("DoNo") %>","/WareHouse/Job/DoOutEdit.aspx?no=<%# Eval("DoNo") %>",{title:"<%# Eval("DoNo") %>", fresh:false, external:true});'><%# Eval("DoNo") %></a>
            Response.Redirect("/opsAccount/ArInvoiceEdit.aspx?no=" + invNo);
        }
    }
예제 #3
0
    protected void btn_CreateInv_Click(object sender, EventArgs e)
    {
        string   invNo    = "";
        string   mastType = "WH";
        DateTime dt       = DateTime.Today;
        bool     isNew    = false;
        int      docId    = 0;

        if (list.Count > 0)
        {
            XAArInvoice iv = null;
            for (int i = 0; i < list.Count; i++)
            {
                string  counterType = "AR-IV";
                string  partyId     = list[i].partyId;
                string  product     = list[i].code;
                string  doNo        = list[i].doNo;
                string  des         = list[i].des;
                string  lotNo       = list[i].lotNo;
                decimal qty         = list[i].qty;
                decimal price       = list[i].price;
                int     days        = list[i].days;
                decimal surcharge   = list[i].surcharge;
                //string sql = string.Format(@"select DocNo from XAArInvoice where MastRefNo='{0}' and InvType='STORAGE'", doNo);
                //invNo = SafeValue.SafeString(C2.Manager.ORManager.ExecuteScalar(sql));
                //if (invNo.Length==0)
                //{
                //    iv = new XAArInvoice();
                //    invNo = C2Setup.GetNextNo("", counterType, dt);
                //    isNew = true;
                //}
                //else
                //{
                //    Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(XAArInvoice), "DocNo='" + invNo + "'");
                //    iv = C2.Manager.ORManager.GetObject(query) as XAArInvoice;
                //    isNew = false;
                //}
                iv             = new XAArInvoice();
                invNo          = C2Setup.GetNextNo("", counterType, dt);
                isNew          = true;
                iv.DocType     = "IV";
                iv.DocDate     = dt;
                iv.DocNo       = invNo;
                iv.PartyTo     = partyId;
                iv.CurrencyId  = System.Configuration.ConfigurationManager.AppSettings["Currency"];
                iv.ExRate      = 1;
                iv.AcCode      = EzshipHelper.GetAccApCode(iv.PartyTo, iv.CurrencyId);
                iv.AcSource    = "DB";
                iv.Description = "";
                iv.Term        = "CASH";

                string[] currentPeriod = EzshipHelper.GetAccPeriod(iv.DocDate);
                iv.AcYear   = SafeValue.SafeInt(currentPeriod[1], iv.DocDate.Year);
                iv.AcPeriod = SafeValue.SafeInt(currentPeriod[0], iv.DocDate.Month);

                iv.MastRefNo   = doNo;
                iv.JobRefNo    = "";
                iv.MastType    = mastType;
                iv.DocAmt      = 0;
                iv.LocAmt      = 0;
                iv.BalanceAmt  = 0;
                iv.CancelDate  = new DateTime(1900, 1, 1);
                iv.CancelInd   = "N";
                iv.DocDueDate  = dt;
                iv.ExportInd   = "N";
                iv.SpecialNote = "";
                iv.UserId      = EzshipHelper.GetUserName();
                iv.EntryDate   = DateTime.Now;
                iv.InvType     = "STORAGE";
                //if (isNew)
                //{
                C2.Manager.ORManager.StartTracking(iv, Wilson.ORMapper.InitialState.Inserted);
                C2.Manager.ORManager.PersistChanges(iv);
                C2Setup.SetNextNo(iv.DocType, counterType, invNo, iv.DocDate);
                //}
                //else
                //{
                Manager.ORManager.StartTracking(iv, Wilson.ORMapper.InitialState.Updated);
                Manager.ORManager.PersistChanges(iv);
                //}

                try
                {
                    C2.XAArInvoiceDet det = new C2.XAArInvoiceDet();
                    det.DocId     = iv.SequenceId;
                    det.DocLineNo = i + 1;
                    det.DocNo     = invNo;
                    det.DocType   = "IV";
                    det.AcCode    = SafeValue.SafeString(ConnectSql.ExecuteScalar(string.Format("select ArCode from ref_product where Code='{0}'", product)), System.Configuration.ConfigurationManager.AppSettings["ItemArCode"]);
                    det.AcSource  = "CR";
                    det.MastRefNo = doNo;
                    det.JobRefNo  = lotNo;
                    det.MastType  = mastType;
                    det.SplitType = "";

                    //sql = string.Format(@"select * from XXChgCode where ChgcodeId='{0}'", product);
                    //DataTable tab_chg = ConnectSql.GetTab(sql);
                    //for (int j = 0; j < tab_chg.Rows.Count; j++)
                    //{
                    //    det.Gst = SafeValue.SafeDecimal(tab_chg.Rows[j]["GstP"]);
                    //}

                    det.ChgCode = product;
                    det.ChgDes1 = des;
                    det.ChgDes2 = "";
                    det.ChgDes3 = "";

                    det.Price    = price;
                    det.Qty      = qty;
                    det.Unit     = "";
                    det.Currency = iv.CurrencyId;
                    det.ExRate   = 1;
                    det.Gst      = 0;
                    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);//*days
                    decimal gstAmt      = SafeValue.ChinaRound((amt * det.Gst), 2);
                    decimal docAmt      = amt + gstAmt;
                    decimal locAmt      = SafeValue.ChinaRound(docAmt * det.ExRate, 2);
                    decimal surchageAmt = SafeValue.ChinaRound(surcharge * qty, 2);
                    det.GstAmt   = gstAmt;
                    det.DocAmt   = docAmt;
                    det.LocAmt   = locAmt;
                    det.OtherAmt = surchageAmt;
                    C2.Manager.ORManager.StartTracking(det, Wilson.ORMapper.InitialState.Inserted);
                    C2.Manager.ORManager.PersistChanges(det);
                    if (surcharge != 0)
                    {
                        det.ChgCode = "STORE";

                        det.Qty   = 1;
                        det.Price = surcharge;
                        string    sql = string.Format(@"select * from XXChgCode where ChgcodeId='{0}'", det.ChgCode);
                        DataTable tab = ConnectSql.GetTab(sql);
                        for (int j = 0; j < tab.Rows.Count; j++)
                        {
                            det.AcCode  = SafeValue.SafeString(tab.Rows[j]["ArCode"]);
                            det.ChgDes1 = SafeValue.SafeString(tab.Rows[j]["ChgcodeDes"]);
                            det.GstType = SafeValue.SafeString(tab.Rows[j]["GstTypeId"]);
                            det.Gst     = SafeValue.SafeDecimal(tab.Rows[j]["GstP"]);
                        }

                        amt    = SafeValue.ChinaRound(det.Qty * det.Price, 2);
                        gstAmt = SafeValue.ChinaRound((amt * det.Gst), 2);

                        docAmt = amt + gstAmt;

                        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);
                    }
                    docId = iv.SequenceId;
                }
                catch
                {
                }
                UpdateMaster(docId);
            }

            Response.Redirect("/opsAccount/ArInvoiceEdit.aspx?no=" + invNo);
        }
    }