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

namespace HH.YiDaSyncNC.Models
{
    public class FKYF_SyncServiceModel
    {
        #region 凭证数据模型
        /// <summary>
        /// 凭证模型
        /// </summary>
        public class DataModel
        {
            /// <summary>
            /// 头部
            /// </summary>
            public class voucher_header
            {
                /// <summary>
                /// 应付财务组织
                /// </summary>
                public string pk_org { get; set; }
                /// <summary>
                /// 创建时间 
                /// </summary>
                public string creationtime { get; set; }
                /// <summary>
                /// 创建人
                /// </summary>
                public string creator { get; set; }
                /// <summary>
                /// 单据日期
                /// </summary>
                public string billdate { get; set; }
                /// <summary>
                /// 制单人
                /// </summary>
                public string billmaker { get; set; }
                /// <summary>
                /// 单据号
                /// </summary>
                public string billno { get; set; }
                /// <summary>
                /// 原币金额
                /// </summary>
                public string money { get; set; }
                /// <summary>
                /// 组织本币金额
                /// </summary>
                public string local_money { get; set; }
                /// <summary>
                /// 单据会计年度
                /// </summary>
                public string billyear { get; set; }
                /// <summary>
                /// 单据会计期间
                /// </summary>
                public string billperiod { get; set; }
                /// <summary>
                /// 采购部门
                /// </summary>
                public string pu_deptid { get; set; }
                /// <summary>
                /// 采购业务员
                /// </summary>
                public string pu_psndoc { get; set; }
                /// <summary>
                /// 采购组织
                /// </summary>
                public string pu_org { get; set; }
            }

            /// <summary>
            /// 明细分录
            /// </summary>
            public class voucher_body
            {
                /// <summary>
                /// 应付财务组织
                /// </summary>
                public string pk_org { get; set; }
                /// <summary>
                /// 财务组织
                /// </summary>
                public string pk_fiorg { get; set; }
                /// <summary>
                /// 采购部门
                /// </summary>
                public string pu_deptid { get; set; }
                /// <summary>
                /// 采购组织
                /// </summary>
                public string pu_org { get; set; }
                /// <summary>
                /// 结算财务组织
                /// </summary>
                public string sett_org { get; set; }
                /// <summary>
                /// 物料
                /// </summary>
                public string material { get; set; }
                /// <summary>
                /// 供应商
                /// </summary>
                public string supplier { get; set; }
                /// <summary>
                /// 单据日期
                /// </summary>
                public string billdate { get; set; }
                /// <summary>
                /// 起算日期
                /// </summary>
                public string busidate { get; set; }
                /// <summary>
                /// 收支项目
                /// </summary>
                public string pk_subjcode { get; set; }
                /// <summary>
                /// 科目
                /// </summary>
                public string subjcode { get; set; }
                /// <summary>
                /// 单据分录号
                /// </summary>
                public string rowno { get; set; }
                /// <summary>
                /// 部门
                /// </summary>
                public string pk_deptid { get; set; }
                /// <summary>
                /// 业务员
                /// </summary>
                public string pk_psndoc { get; set; }
                /// <summary>
                /// 贷方数量
                /// </summary>
                public string quantity_cr { get; set; }
                /// <summary>
                /// 组织本币金额(贷方)
                /// </summary>
                public string local_money_cr { get; set; }
                /// <summary>
                /// 贷方原币金额
                /// </summary>
                public string money_cr { get; set; }
                /// <summary>
                /// 税额
                /// </summary>
                public string local_tax_cr { get; set; }
                /// <summary>
                /// 贷方原币无税金额
                /// </summary>
                public string notax_cr { get; set; }
                /// <summary>
                /// 组织本币无税金额(贷方)
                /// </summary>
                public string local_notax_cr { get; set; }
                /// <summary>
                /// 单价 无税
                /// </summary>
                public string price { get; set; }
                /// <summary>
                /// 含税单价
                /// </summary>
                public string taxprice { get; set; }
                /// <summary>
                /// 税率
                /// </summary>
                public string taxrate { get; set; }
                /// <summary>
                /// 订单供应商
                /// </summary>
                public string ordercubasdoc { get; set; }
                /// <summary>
                /// 发票号
                /// </summary>
                public string invoiceno { get; set; }
                /// <summary>
                /// 计税金额
                /// </summary>
                public string caltaxmny { get; set; }
            }

        }
        #endregion

        public class ImportXml_应付单
        {
            public static XElement TemplateHeade(DataModel.voucher_header item)
            {

                return new XElement(new XElement("ufinterface", new object[]
                {
                    new XAttribute("billtype","F1"),
                    new XAttribute("sender","dingding"),
                    new XAttribute("receiver",""),
                    new XAttribute("roottag",""),
                    new XAttribute("replace","N"),
                    new XAttribute("orgcode",""),
                    new XAttribute("isexchange",""),
                    new XAttribute("groupcode","0"),
                    new XAttribute("filename",""),
                    new XAttribute("businessunitcode","develop"),
                    new XAttribute("account","develop")
                }));
            }
            /// <summary>
            /// 组建表头xml
            /// </summary>
            /// <param name="item">表头参数</param>
            /// <returns></returns>
            public static XElement Header(DataModel.voucher_header item)
            {
                return new XElement("bill", new object[]
                {
                "",
                new XElement("billhead", new object[]
                {
                    new XElement("pk_group","0"),
                    new XElement("pk_org",item.pk_org),
                    new XElement("pk_fiorg",item.pk_org),
                    new XElement("sett_org",item.pk_org),
                    new XElement("creationtime",item.creationtime),
                    new XElement("creator",item.creator),
                    new XElement("billno",item.billno),
                    new XElement("billdate",item.billdate),
                    new XElement("billmaker",item.billmaker),
                    new XElement("money",item.money),
                    new XElement("local_money",item.local_money),
                    new XElement("billyear",item.billyear),
                    new XElement("billperiod",item.billperiod),
                    new XElement("pu_deptid",item.pu_deptid),
                    new XElement("pu_psndoc",item.pu_psndoc),
                    new XElement("pu_org",item.pu_org),
                    new XElement("isreded","N"),
                    new XElement("pk_billtype","F1"),
                    new XElement("pk_tradetype","D1"),
                    new XElement("billclass","yf"),
                    new XElement("accessorynum","0"),
                    new XElement("isflowbill","N"),
                    new XElement("isinit","N"),
                    new XElement("syscode","1"),
                    new XElement("src_syscode","1"),
                    new XElement("billstatus","1"),
                    new XElement("grouplocal","0.00000000"),
                    new XElement("globallocal","0.00000000"),
                    new XElement("grouprate","0.00000000"),
                    new XElement("globalrate","0.00000000"),
                    new XElement("rate","0.00000000"),
                    new XElement("ispuadjust","N"),
                    new XElement("coordflag","0"),
                    new XElement("pk_currtype","CNY"),
                    new XElement("bodys","")
                }),
                });
            }

            /// <summary>
            /// 组建表体xml
            /// </summary>
            /// <param name="items">表体</param>
            /// <returns></returns>
            public static List<XElement> Body(List<DataModel.voucher_body> items)
            {
                List<XElement> list = new List<XElement>();

                foreach (DataModel.voucher_body current in items)
                {

                    XElement item = new XElement("item", new object[]
                    {
                    new XElement("pk_org",current.pk_org),
                    new XElement("pk_fiorg",current.pk_fiorg),
                    new XElement("pu_deptid",current.pu_deptid),
                    new XElement("pu_org",current.pu_org),
                    new XElement("material",current.material),
                    new XElement("sett_org",current.sett_org),
                    new XElement("supplier",current.supplier),
                    new XElement("supplier",current.billdate),
                    new XElement("busidate",current.busidate),
                    new XElement("pk_subjcode",current.pk_subjcode),
                    new XElement("rowno",current.rowno),
                    new XElement("pk_deptid",current.pk_deptid),
                    new XElement("pk_psndoc",current.pk_psndoc),
                    new XElement("quantity_cr",current.quantity_cr),
                    new XElement("local_money_cr",current.local_money_cr),
                    new XElement("money_cr",current.money_cr),
                    new XElement("notax_cr",current.notax_cr),
                    new XElement("local_notax_cr",current.local_notax_cr),
                    new XElement("price",current.price),
                    new XElement("taxprice",current.taxprice),
                    new XElement("taxrate",current.taxrate),
                    new XElement("ordercubasdoc",current.ordercubasdoc),
                    new XElement("invoiceno",current.invoiceno),
                    new XElement("caltaxmny",current.caltaxmny),
                    new XElement("local_tax_cr",current.local_tax_cr),
                    new XElement("subjcode",current.subjcode),
                    new XElement("coordflag","0"),
                    new XElement("pk_group","0"),
                    new XElement("direction","0"),
                    new XElement("rowtype","0"),
                    new XElement("pk_billtype","F1"),
                    new XElement("billclass","yf"),
                    new XElement("pk_tradetype","D1"),
                    new XElement("objtype","1"),
                    new XElement("pk_currtype","CNY"),
                    new XElement("rate","1"),
                    new XElement("money_bal","0"),
                    new XElement("local_money_bal","0"),
                    new XElement("quantity_bal","0"),
                    new XElement("taxtype","0"),
                    new XElement("buysellflag","2"),
                    new XElement("grouprate","0.00000000"),
                    new XElement("globalrate","0.00000000"),
                    new XElement("groupcrebit","0.00000000"),
                    new XElement("globalcrebit","0.00000000"),
                    new XElement("groupbalance","0.00000000"),
                    new XElement("globalbalance","0.00000000"),
                    new XElement("groupnotax_cre","0.00000000"),
                    new XElement("globalnotax_cre","0.00000000"),
                    new XElement("occupationmny","0.00000000"),




                        });


                    list.Add(item);
                }
                return list;
            }
        }
    }
}
