示例#1
0
    /// <summary>
    /// 运单导出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExport_Click(object sender, EventArgs e)
    {
        TransportationBill tb = TheTransportationBillMgr.LoadTransportationBill(this.BillNo, true);
        IList <TransportationBillDetail> detail = tb.TransportationBillDetails;

        getExcel(tb, detail, true);
    }
示例#2
0
    protected void CostCenterCal()
    {
        CostString  = string.Empty;
        ErrorString = string.Empty;
        // string billno = ((com.Sconit.Control.ReadonlyTextBox)(FV_TransportationBill.FindControl("tbBillNo"))).Text;
        string billno = this.BillNo;

        if (billno != string.Empty)
        {
            #region Sql语句
            StringBuilder cc = new StringBuilder();
            cc.Append("select c.orderno,sum(vol) as V,plant,tactbill.billedqty*tactbill.unitprice as cost1,min(tbilldet.amount) as cost from " +
                      "(select a.orderno,orderdet.packvol,qty,orderdet.packvol*qty as vol,item.plant  from (" +
                      "select orderloctransid,ipdet.ipno,sum(abs(qty)) as  QTY ,orderno " +
                      "from torderdet  join ipdet on torderdet.ipno=ipdet.ipno " +
                      "where orderno in(" +
                      "select tordermstr.orderno from tactbill " +
                      "left join tordermstr  on tactbill.orderno=tordermstr.orderno " +
                      "where id in(" +
                      "select distinct transid from tbillmstr  join tbilldet on tbillmstr.billno=tbilldet.billno ");
            cc.Append(
                "where tbillmstr.billno='" + billno + "'))" +
                "group by orderloctransid,ipdet.ipno,orderno    ) a " +
                "left join orderloctrans on a.orderloctransid=id " +
                "left join orderdet on orderdet.id=orderloctrans.orderdetid " +
                "left join item on item.code=orderdet.item " +
                ") c  left join tactbill on c.orderno=tactbill.orderno left join tbilldet on transid=tactbill.id and tbilldet.billno='" + billno + "' " +
                "group by c.orderno,plant,tactbill.billedqty,tactbill.unitprice,tactbill.id " +
                " having   min(tbilldet.amount) is not null " +
                "order by c.orderno");
            #endregion
            string        sql    = cc.ToString();
            XmlTextReader reader = new XmlTextReader(Server.MapPath("Config/properties.config"));
            XmlDocument   doc    = new XmlDocument();
            doc.Load(reader); //
            reader.Close();   //
            string  ConnString = doc.SelectSingleNode("/configuration/properties/connectionString").InnerText.Trim();
            DataSet result     = SqlHelper.ExecuteDataset(ConnString, CommandType.Text, sql);
            Dictionary <string, decimal> orderTotal = new Dictionary <string, decimal>();
            Dictionary <string, decimal> plantcost  = new Dictionary <string, decimal>();
            Dictionary <string, string>  error      = new Dictionary <string, string>();
            Dictionary <string, string>  noplant    = new Dictionary <string, string>();
            // Dictionary<string, decimal> lxcost = new Dictionary<string, decimal>();
            Dictionary <string, string> filter = new Dictionary <string, string>();
            #region 处理常规的
            foreach (DataRow i in result.Tables[0].Rows)
            {
                if (error.ContainsKey(i["orderno"].ToString()) || noplant.ContainsKey(i["orderno"].ToString()))
                {
                    continue;
                }
                if (i["V"].ToString() == "")
                {
                    error.Add(i["orderno"].ToString(), "");
                    continue;
                }
                if (i["plant"].ToString() == "")
                {
                    noplant.Add(i["orderno"].ToString(), "");
                    continue;
                }
                if (orderTotal.ContainsKey(i["orderno"].ToString()) == false)
                {
                    orderTotal.Add(i["orderno"].ToString(), decimal.Parse(i["V"].ToString()));
                }
                else
                {
                    orderTotal[i["orderno"].ToString()] = orderTotal[i["orderno"].ToString()] + decimal.Parse(i["V"].ToString());
                }
            }
            foreach (DataRow i in result.Tables[0].Rows)
            {
                if (error.ContainsKey(i["orderno"].ToString()) || noplant.ContainsKey(i["orderno"].ToString()))
                {
                    continue;
                }
                decimal cost = decimal.Parse(i["V"].ToString()) / orderTotal[i["orderno"].ToString()] * decimal.Parse(i["cost"].ToString());
                cost = Math.Round(cost, 2);
                if (plantcost.ContainsKey(mappingCC(i["plant"].ToString())) == false)
                {
                    plantcost.Add(mappingCC(i["plant"].ToString()), cost);
                }
                else
                {
                    plantcost[mappingCC(i["plant"].ToString())] = plantcost[mappingCC(i["plant"].ToString())] + cost;
                }
            }
            #endregion
            #region 零星运单
            StringBuilder lxsb = new StringBuilder();
            lxsb.Append("select tordermstr.orderno,torderdet.ipno,expense from tordermstr left join torderdet on tordermstr.orderno=torderdet.orderno  " +
                        "where tordermstr.orderno in (" +
                        "select distinct  tordermstr.orderno from tactbill " +
                        "left join tordermstr  on tactbill.orderno=tordermstr.orderno " +
                        "where id in( " +
                        "select distinct transid from tbillmstr  join tbilldet on tbillmstr.billno=tbilldet.billno " +
                        "where tbillmstr.billno='" + billno + "')) " +
                        "and   (left(ipno,1)='W' or expense is not null)");

            string  lxsql = lxsb.ToString();
            DataSet lxdt  = SqlHelper.ExecuteDataset(ConnString, CommandType.Text, lxsql);
            foreach (DataRow r in lxdt.Tables[0].Rows)
            {
                TransportationOrder to = TheTransportationOrderMgr.LoadTransportationOrder(r["orderno"].ToString(), true);
                IList <TransportationOrderDetail> tods = to.OrderDetails;
                if (tods.Count == 0)
                {
                    string        wfcon   = @"Data Source=192.168.210.190\SQL2005;Initial Catalog=EPROCESS;Persist Security Info=true;User ID=sa;PWD=temp100;Packet Size=4096;";
                    string        sqltext = "select esportran_costsrc+'_'+cast(esportran_totalcost as nvarchar(50)) from  dbo.eSporadicTran_mstr where esportran_nbr='" + r["expense"].ToString() + "'";
                    SqlConnection con     = new SqlConnection(wfcon);
                    SqlCommand    cmd     = new SqlCommand(sqltext, con);
                    object        obj     = null;
                    try
                    {
                        con.Open();
                        obj = cmd.ExecuteScalar();
                        con.Close();
                    }
                    catch
                    {
                        con.Close();
                    }
                    if (obj != null)
                    {
                        string _obj = obj.ToString();
                        if (_obj.StartsWith("AR"))
                        {
                            string  obj_cc = _obj.Split(new char[] { '_' })[0].Substring(3);
                            decimal cost   = decimal.Parse(_obj.Split(new char[] { '_' })[1]);
                            if (plantcost.ContainsKey(obj_cc))
                            {
                                plantcost[obj_cc] = plantcost[obj_cc] + Math.Round(cost, 2);
                            }
                            else
                            {
                                plantcost.Add(obj_cc, Math.Round(cost, 2));
                            }
                        }
                        if (_obj.StartsWith("CC"))
                        {
                            string  obj_cc = mappingCC(_obj.Substring(3, 4)).Trim();
                            decimal cost   = decimal.Parse(_obj.Split(new char[] { '_' })[1]);
                            if (plantcost.ContainsKey(obj_cc))
                            {
                                plantcost[obj_cc] = plantcost[obj_cc] + Math.Round(cost, 2);
                            }
                            else
                            {
                                plantcost.Add(obj_cc, Math.Round(cost, 2));
                            }
                        }
                    }
                    continue;
                }
                #endregion

                if (tods != null)
                {
                    var l = (from i in tods where i.InProcessLocation.IpNo.Substring(0, 1) == "W" select i).ToList();
                    if (l != null && l.Count == tods.Count)
                    {
                        if (filter.ContainsKey(r["orderno"].ToString()) == true)
                        {
                            continue;
                        }
                        filter.Add(r["orderno"].ToString(), r["ipno"].ToString());
                        InProcessLocation ip             = TheInProcessLocationMgr.LoadInProcessLocation(r["ipno"].ToString());
                        string            orderAmountsql = "select top 1 BilledAmount from tactbill where orderno='" + r["orderno"].ToString() + "' order by lastmodifydate desc ";//and status='Close'
                        SqlConnection     ordercon       = new SqlConnection(ConnString);
                        SqlCommand        ordercmd       = new SqlCommand(orderAmountsql, ordercon);
                        object            amount         = null;
                        try
                        {
                            ordercon.Open();
                            amount = ordercmd.ExecuteScalar();
                            ordercon.Close();
                        }
                        catch
                        {
                            ordercon.Close();
                        }
                        string ip_cc = mappingCC(ip.HuTemplate);
                        if (amount != null)
                        {
                            if (plantcost.ContainsKey(ip_cc))
                            {
                                plantcost[ip_cc] = plantcost[ip_cc] + Math.Round(decimal.Parse(amount.ToString()), 2);
                            }
                            else
                            {
                                plantcost.Add(ip_cc, Math.Round(decimal.Parse(amount.ToString()), 2));
                            }
                        }
                    }
                }
            }


            var disacct = TheCarrierMgr.LoadCarrier(TheTransportationBillMgr.LoadTransportationBill(BillNo).BillAddress.Party.Code).TradeTerm;

            int di = 0;
            if (string.IsNullOrEmpty(disacct))
            {
                disacct = "0";
            }
            foreach (KeyValuePair <string, decimal> key in plantcost)
            {
                decimal tax = 0;
                if (disacct.StartsWith("$"))
                {
                    tax = Math.Round(key.Value / (1 + decimal.Parse(disacct.Substring(1)) * (decimal)0.01) * decimal.Parse(disacct.Substring(1)) * (decimal)0.01, 2);
                }
                else
                {
                    tax = Math.Round(key.Value * (decimal.Parse(disacct) * (decimal)0.01), 2);
                }
                decimal outTax = key.Value - tax;
                TaxTotal    += tax;
                OutTaxTotal += outTax;
                if (di % 2 == 0)
                {
                    CostString += "<tr style='background-color:white;text-align:center'><td>" + key.Key + "</td><td>" + mappingAcc(key.Key) + "</td><td>" + outTax + "</td><td>" + tax + "</td></tr>";
                }

                if (di % 2 == 1)
                {
                    CostString += "<tr style='background-color:#DAD6C5;text-align:center'><td>" + key.Key + "</td><td>" + mappingAcc(key.Key) + "</td><td>" + outTax + "</td><td>" + tax + "</td></tr>";
                }
                // CostString += key.Key + ":" + key.Value + "<br/>";
                di++;
            }
            if (error.Count > 0)
            {
                ErrorString = "以下运单货物存在未设置体积不予计算:<br/>";
            }
            foreach (KeyValuePair <string, string> key in error)
            {
                ErrorString += key.Key + "<br/>";
            }
            if (noplant.Count > 0)
            {
                ErrorString += "以下运单中含有为设置工厂的零件不予计算:<br/>";
            }
            foreach (KeyValuePair <string, string> key in noplant)
            {
                ErrorString += key.Key + "<br/>";
            }
        }
    }