using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace HH.YiDaSyncNC.Models
{
    class XSFP_SyncServiceModel
    {
        public class DataModel
        {
            public string pk_group { get; set; }
            public string pk_org { get; set; }
            public string pk_org_v { get; set; }

            public string ctrantypeid { get; set; }
            public string vtrantypecode { get; set; }
            public string cbiztypeid { get; set; }

            public string vbillcode { get; set; }
            public string dbilldate { get; set; }

            public string vprintcustname { get; set; }
            public string ccustbankid { get; set; }
            public string ccustbankaccid { get; set; }

            public string cdeptvid { get; set; }
            public string cdeptid { get; set; }
            public string cemployeeid { get; set; }
            public string corigcurrencyid { get; set; }
            public string cinvoicecustid { get; set; }

            public string cpaytermid { get; set; }
            public string approver { get; set; }
            public string taudittime { get; set; }

            public string billmaker { get; set; }
            public string dmakedate { get; set; }
            public string creator { get; set; }
            public string creationtime { get; set; }

            public string ntotalnum { get; set; }
            public string ntotalorigmny { get; set; }

            public List<OrderB> so_saleorder_b { get; set; }

            public class OrderB
            {
                public string carorgvid { get; set; }
                public string carorgid { get; set; }
                public string csendstockorgvid { get; set; }
                public string csendstockorgid { get; set; }

                public string creceivecustid { get; set; }
                public string crececountryid { get; set; }
                public string csendcountryid { get; set; }
                public string ctaxcountryid { get; set; }

                public string pk_group { get; set; }
                public string pk_org { get; set; }
                public string dbilldate { get; set; }

                public string crowno { get; set; }
                public string cprojectid { get; set; }

                public string cmaterialvid { get; set; }
                public string cmaterialid { get; set; }
                public string cunitid { get; set; }
                public string castunitid { get; set; }

                public string nastnum { get; set; }
                public string vchangerate { get; set; }
                public string cqtunitid { get; set; }
                public string nqtunitnum { get; set; }
                public string nnum { get; set; }
                public string vqtunitrate { get; set; }
                public string ctaxcodeid { get; set; }
                public string ntaxrate { get; set; }
                public string ccurrencyid { get; set; }

                public string norigtaxprice { get; set; }
                public string nqtorigtaxprice { get; set; }
                public string nqttaxprice { get; set; }
                public string ntaxprice { get; set; }

                public string nqtorigprice { get; set; }
                public string nqtorignetprice { get; set; }
                public string norigprice { get; set; }
                public string nprice { get; set; }
                public string nqtprice { get; set; }

                public string nqtorigtaxnetprc { get; set; }
                public string norigtaxnetprice { get; set; }
                public string nqttaxnetprice { get; set; }
                public string ntaxnetprice { get; set; }

                public string norignetprice { get; set; }
                public string nnetprice { get; set; }
                public string nqtnetprice { get; set; }

                public string ntax { get; set; }

                public string ncaltaxmny { get; set; }
                public string norigmny { get; set; }
                public string nmny { get; set; }

                public string norigtaxmny { get; set; }
                public string ntaxmny { get; set; }

                public string vsrctype { get; set; }
                public string vsrccode { get; set; }
                public string vsrctrantype { get; set; }
                public string vsrcrowno { get; set; }
            }
        }

        public class ImportXml
        {
            /// <summary>
            /// 模板头部份
            /// </summary>
            /// <returns></returns>
            public static XElement TemplateHeade()
            {

                return new XElement(new XElement("ufinterface", new object[]
                {
                new XAttribute("sender","dingding"),
                new XAttribute("roottag",""),
                new XAttribute("replace","Y"),
                new XAttribute("isexchange","Y"),
                new XAttribute("groupcode","0"),
                new XAttribute("filename",""),
                new XAttribute("billtype","32"),
                new XAttribute("account","develop")
                }));
            }

            /// <summary>
            /// 组建表头xml
            /// </summary>
            /// <param name="item">表头参数</param>
            /// <returns></returns>
            public static XElement Header(DataModel item, string id)
            {
                var so_saleorder_b = new List<XElement>();

                if (item.so_saleorder_b != null && item.so_saleorder_b.Count > 0)
                {
                    foreach (var itemData in item.so_saleorder_b)
                    {
                        so_saleorder_b.Add(new XElement("item", new object[] {
                            new XElement("carorgvid",itemData.carorgvid),
                            new XElement("carorgid",itemData.carorgid),
                            new XElement("csendstockorgvid",itemData.csendstockorgvid),
                            new XElement("csendstockorgid",itemData.csendstockorgid),

                            new XElement("creceivecustid",itemData.creceivecustid),
                            new XElement("crececountryid",itemData.crececountryid),
                            new XElement("csendcountryid",itemData.csendcountryid),
                            new XElement("ctaxcountryid",itemData.ctaxcountryid),

                            new XElement("pk_group",itemData.pk_group),
                            new XElement("pk_org",itemData.pk_org),
                            new XElement("dbilldate",itemData.dbilldate),

                            new XElement("crowno",itemData.crowno),
                            new XElement("cprojectid",itemData.cprojectid),
                            new XElement("fbuysellflag","1"),

                            new XElement("cmaterialvid",itemData.cmaterialvid),
                            new XElement("cmaterialid",itemData.cmaterialid),
                            new XElement("cunitid",itemData.cunitid),
                            new XElement("castunitid",itemData.castunitid),

                            new XElement("nastnum",itemData.nastnum),
                            new XElement("vchangerate",itemData.vchangerate),
                            new XElement("cqtunitid",itemData.cqtunitid),
                            new XElement("nqtunitnum",itemData.nqtunitnum),
                            new XElement("nnum",itemData.nnum),
                            new XElement("vqtunitrate",itemData.vqtunitrate),
                            new XElement("ctaxcodeid",itemData.ctaxcodeid),
                            new XElement("ntaxrate",itemData.ntaxrate),
                            new XElement("ftaxtypeflag","1"),
                            new XElement("ccurrencyid",itemData.ccurrencyid),
                            new XElement("nexchangerate","1"),
                            new XElement("ndiscount","0"),
                            new XElement("ndiscountrate","100"),
                            new XElement("nitemdiscountrate","100"),

                            new XElement("norigtaxprice",itemData.norigtaxprice),
                            new XElement("nqtorigtaxprice",itemData.nqtorigtaxprice),
                            new XElement("nqttaxprice",itemData.nqttaxprice),
                            new XElement("ntaxprice",itemData.ntaxprice),

                            new XElement("nqtorigprice",itemData.nqtorigprice),
                            new XElement("nqtorignetprice",itemData.nqtorignetprice),
                            new XElement("norigprice",itemData.norigprice),
                            new XElement("nprice",itemData.nprice),
                            new XElement("nqtprice",itemData.nqtprice),

                            new XElement("nqtorigtaxnetprc",itemData.nqtorigtaxnetprc),
                            new XElement("norigtaxnetprice",itemData.norigtaxnetprice),
                            new XElement("nqttaxnetprice",itemData.nqttaxnetprice),
                            new XElement("ntaxnetprice",itemData.ntaxnetprice),

                            new XElement("norignetprice",itemData.norignetprice),
                            new XElement("nnetprice",itemData.nnetprice),
                            new XElement("nqtnetprice",itemData.nqtnetprice),

                            new XElement("ntax",itemData.ntax),

                            new XElement("ncaltaxmny",itemData.ncaltaxmny),
                            new XElement("norigmny",itemData.norigmny),
                            new XElement("nmny",itemData.nmny),

                            new XElement("norigtaxmny",itemData.norigtaxmny),
                            new XElement("ntaxmny",itemData.ntaxmny),

                            new XElement("norigdiscount","0"),

                            new XElement("vsrctype",itemData.vsrctype),
                            new XElement("vsrccode",itemData.vsrccode),
                            new XElement("vsrctrantype",itemData.vsrctrantype),
                            new XElement("vsrcrowno",itemData.vsrcrowno),
                        }));
                    }
                }

                return new XElement("bill", new object[]
                {
                "",
                new XAttribute("id",id),
                new XElement("billhead", new object[]
                {
                    new XElement("pk_group",item.pk_group),
                    new XElement("pk_org",item.pk_org),
                    new XElement("pk_org_v",item.pk_org_v),

                    new XElement("ctrantypeid",item.ctrantypeid),
                    new XElement("vtrantypecode",item.vtrantypecode),
                    new XElement("cbiztypeid",item.cbiztypeid),

                    new XElement("vbillcode",item.vbillcode),
                    new XElement("dbilldate",item.dbilldate),

                    new XElement("vprintcustname",item.vprintcustname),
                    new XElement("ccustbankid",item.ccustbankid),
                    new XElement("ccustbankaccid",item.ccustbankaccid),

                    new XElement("cdeptvid",item.cdeptvid),
                    new XElement("cdeptid",item.cdeptid),
                    new XElement("cemployeeid",item.cemployeeid),
                    new XElement("corigcurrencyid",item.corigcurrencyid),
                    new XElement("cinvoicecustid",item.cinvoicecustid),

                    new XElement("cpaytermid",item.cpaytermid),
                    new XElement("fstatusflag","1"),
                    new XElement("approver",item.approver),
                    new XElement("taudittime",item.taudittime),

                    new XElement("billmaker",item.billmaker),
                    new XElement("dmakedate",item.dmakedate),
                    new XElement("creator",item.creator),
                    new XElement("creationtime",item.creationtime),

                    new XElement("ntotalnum",item.ntotalnum),
                    new XElement("ntotalorigmny",item.ntotalorigmny),

                    new XElement("csaleinvoicebid",so_saleorder_b),
                }),
                });
            }
        }
    }
}
