コード例 #1
0
    public static List<IMAVenderCostSeasonReportData> GetVenderClientCostBySeason(WoWiModel.WoWiEntities wowidb, int year)
    {
        List<IMAVenderCostSeasonReportData> list = new List<IMAVenderCostSeasonReportData>();
        IMAVenderCostSeasonReportData temp;
        try
        {

            var venders = (from pr in wowidb.PRs from pj in wowidb.Projects where pr.project_id == pj.Project_Id && pj.Create_Date.Year == year select pr.vendor_id).Distinct();
            decimal M1D = 0, M1Q = 0, M2D = 0, M2Q = 0, M3D = 0, M3Q = 0, M4D = 0, M4Q = 0, TotD = 0, TotQ = 0;

            foreach (var ven in venders)
            {
                try
                {
                    String vName = "";
                    var prs = from pr in wowidb.PRs where pr.vendor_id == ven select pr;
                    temp = new IMAVenderCostSeasonReportData();
                    var v = (from i in wowidb.vendors where i.id == ven select i).First();
                    temp.VenderName = String.IsNullOrEmpty(v.c_name) ? v.name : v.c_name;
                    vName = temp.VenderName;
                    decimal venM1D = 0, venM1Q = 0, venM2D = 0, venM2Q = 0, venM3D = 0, venM3Q = 0, venM4D = 0, venM4Q = 0, venTotD = 0, venTotQ = 0;
                    foreach (var p in prs)
                    {
                        try
                        {
                            var pj = (from proj in wowidb.Projects where proj.Project_Id == p.project_id select proj).First();
                            int month = pj.Create_Date.Month;
                            var quo = (from q in wowidb.Quotation_Version where q.Quotation_Version_Id == pj.Quotation_Id select q).First();
                            temp.Model = quo.Model_No;
                            int cid = (int)quo.Client_Id;
                            try
                            {
                                var client = (from cli in wowidb.clientapplicants where cli.id == cid select cli).First();
                                temp.Client = String.IsNullOrEmpty(client.c_companyname) ? client.companyname : client.c_companyname;
                            }
                            catch
                            {
                            }

                            var pri = (from pi in wowidb.PR_item where pi.pr_id == p.pr_id select pi).First();
                            try
                            {
                                //var tDesc = (from kk in wowidb.Quotation_Target from kkk in wowidb.Targets where pri.quotation_target_id == kk.Quotation_Target_Id && kk.target_id == kkk.target_id select kkk.target_description).First();
                                var tDesc = (from kk in wowidb.Quotation_Target where pri.quotation_target_id == kk.Quotation_Target_Id  select kk.target_description).First();
                                temp.Country = tDesc;

                            }
                            catch (Exception)
                            {
                            }
                            decimal avenM1D = 0, avenM1Q = 0, avenM2D = 0, avenM2Q = 0, avenM3D = 0, avenM3Q = 0, avenM4D = 0, avenM4Q = 0,  avenTotD = 0, avenTotQ = 0;

                            switch (month)
                            {
                                case 1:
                                case 2:
                                case 3:
                                    avenM1D = (decimal)pri.amount;
                                    avenM1Q = (decimal)pri.quantity;
                                    break;
                                case 4:
                                case 5:
                                case 6:
                                    avenM2D = (decimal)pri.amount;
                                    avenM2Q = (decimal)pri.quantity;
                                    break;
                                case 7:
                                case 8:
                                case 9:
                                    avenM3D = (decimal)pri.amount;
                                    avenM3Q = (decimal)pri.quantity;
                                    break;
                                case 10:
                                case 11:
                                case 12:
                                    avenM4D = (decimal)pri.amount;
                                    avenM4Q = (decimal)pri.quantity;
                                    break;

                            }
                            avenTotD = avenM1D + avenM2D + avenM3D + avenM4D ;
                            avenTotQ = avenM1Q + avenM2Q + avenM3Q + avenM4Q ;

                            venM1D += avenM1D;
                            venM1Q += avenM1Q;
                            venM2D += avenM2D;
                            venM2Q += avenM2Q;
                            venM3D += avenM3D;
                            venM3Q += avenM3Q;
                            venM4D += avenM4D;
                            venM4Q += avenM4Q;
                            venTotD += avenTotD;
                            venTotQ += avenTotQ;
                            temp.Season01USD = M1D.ToString("F2");
                            temp.Season02USD = M2D.ToString("F2");
                            temp.Season03USD = M3D.ToString("F2");
                            temp.Season04USD = M4D.ToString("F2");
                            temp.TotalUSD = avenTotD.ToString("F2");

                            temp.Season01QTY = M1Q.ToString("F0");
                            temp.Season02QTY = M2Q.ToString("F0");
                            temp.Season03QTY = M3Q.ToString("F0");
                            temp.Season04QTY = M4Q.ToString("F0");
                            temp.TotalQTY = avenTotQ.ToString("F0");
                            list.Add(temp);
                        }
                        catch (Exception)
                        {

                            //throw;
                        }

                    }//Single vender ends
                    M1D += venM1D;
                    M1Q += venM1Q;
                    M2D += venM2D;
                    M2Q += venM2Q;
                    M3D += venM3D;
                    M3Q += venM3Q;
                    M4D += venM4D;
                    M4Q += venM4Q;
                    TotD += venTotD;
                    TotQ += venTotQ;
                    if (venTotD != 0)
                    {
                        temp = new IMAVenderCostSeasonReportData()
                        {
                            VenderName = " Total : "
                        };
                        temp.Season01USD = M1D.ToString("F2");
                        temp.Season02USD = M2D.ToString("F2");
                        temp.Season03USD = M3D.ToString("F2");
                        temp.Season04USD = M4D.ToString("F2");
                        temp.TotalUSD = venTotD.ToString("F2");

                        temp.Season01QTY = M1Q.ToString("F0");
                        temp.Season02QTY = M2Q.ToString("F0");
                        temp.Season03QTY = M3Q.ToString("F0");
                        temp.Season04QTY = M4Q.ToString("F0");
                        temp.TotalQTY = venTotQ.ToString("F0");
                        list.Add(temp);
                    }
                }
                catch (Exception)
                {

                    //throw;
                }
            }//Vender ends

            if (TotD != 0)
            {
                temp = new IMAVenderCostSeasonReportData()
                {
                    VenderName = "Balance Total : "
                };
                temp.Season01USD = M1D.ToString("F2");
                temp.Season02USD = M2D.ToString("F2");
                temp.Season03USD = M3D.ToString("F2");
                temp.Season04USD = M4D.ToString("F2");
                temp.TotalUSD = TotD.ToString("F2");

                temp.Season01QTY = M1Q.ToString("F0");
                temp.Season02QTY = M2Q.ToString("F0");
                temp.Season03QTY = M3Q.ToString("F0");
                temp.Season04QTY = M4Q.ToString("F0");
                temp.TotalQTY = TotQ.ToString("F0");
                list.Add(temp);
            }

        }
        catch (Exception)
        {

            //throw;
        }
        return list;
    }
コード例 #2
0
    public static List<IMAVenderCostSeasonReportData> GetIMACostBySeason(WoWiModel.WoWiEntities wowidb, int year)
    {
        List<IMAVenderCostSeasonReportData> list = new List<IMAVenderCostSeasonReportData>();
        IMAVenderCostSeasonReportData temp;
        try
        {
            //Find all IMAs
            var imas = (from pr in wowidb.PRs from pj in wowidb.Projects where pr.project_id == pj.Project_Id && pj.Create_Date.Year == year select pr.create_user).Distinct();

            var venders = (from pr in wowidb.PRs from pj in wowidb.Projects where pr.project_id == pj.Project_Id && pj.Create_Date.Year == year select pr.vendor_id).Distinct();
            decimal M1D = 0, M1Q = 0, M2D = 0, M2Q = 0, M3D = 0, M3Q = 0, M4D = 0, M4Q = 0, TotD = 0, TotQ = 0;
            foreach (var ima in imas)
            {
                decimal imaM1D = 0, imaM1Q = 0, imaM2D = 0, imaM2Q = 0, imaM3D = 0, imaM3Q = 0, imaM4D = 0, imaM4Q = 0, imaTotD = 0, imaTotQ = 0;
                foreach (var ven in venders)
                {
                    decimal venM1D = 0, venM1Q = 0, venM2D = 0, venM2Q = 0, venM3D = 0, venM3Q = 0, venM4D = 0, venM4Q = 0, venTotD = 0, venTotQ = 0;
                    try
                    {
                        var prs = from pr in wowidb.PRs where pr.create_user == ima && pr.vendor_id == ven select pr;
                        temp = new IMAVenderCostSeasonReportData()
                        {
                            IMA = ima
                        };
                        var v = (from i in wowidb.vendors where i.id == ven select i).First();
                        temp.VenderName = String.IsNullOrEmpty(v.c_name) ? v.name : v.c_name;
                        foreach (var p in prs)
                        {
                            try
                            {
                                int month = (from proj in wowidb.Projects where proj.Project_Id == p.project_id select proj.Create_Date.Month).First();
                                var pri = (from pi in wowidb.PR_item where pi.pr_id == p.pr_id select pi).First();
                                switch (month)
                                {
                                    case 1:
                                    case 2:
                                    case 3:
                                        venM1D += (decimal)pri.amount;
                                        venM1Q += (decimal)pri.quantity;
                                        break;
                                    case 4:
                                    case 5:
                                    case 6:
                                        venM2D += (decimal)pri.amount;
                                        venM2Q += (decimal)pri.quantity;
                                        break;
                                    case 7:
                                    case 8:
                                    case 9:
                                        venM3D += (decimal)pri.amount;
                                        venM3Q += (decimal)pri.quantity;
                                        break;
                                    case 10:
                                    case 11:
                                    case 12:
                                        venM4D += (decimal)pri.amount;
                                        venM4Q += (decimal)pri.quantity;
                                        break;
                                }
                            }
                            catch (Exception)
                            {

                                //throw;
                            }

                        }//Single vender ends
                        venTotD = venM1D + venM2D + venM3D + venM4D;
                        venTotQ = venM1Q + venM2Q + venM3Q + venM4Q;
                        imaM1D += venM1D;
                        imaM1Q += venM1Q;
                        imaM2D += venM2D;
                        imaM2Q += venM2Q;
                        imaM3D += venM3D;
                        imaM3Q += venM3Q;
                        imaM4D += venM4D;
                        imaM4Q += venM4Q;

                        imaTotD += venTotD;
                        imaTotQ += venTotQ;
                        temp.Season01USD = venM1D.ToString("F2");
                        temp.Season02USD = venM2D.ToString("F2");
                        temp.Season03USD = venM3D.ToString("F2");
                        temp.Season04USD = venM4D.ToString("F2");

                        temp.TotalUSD = venTotD.ToString("F2");

                        temp.Season01QTY = venM1Q.ToString("F0");
                        temp.Season02QTY = venM2Q.ToString("F0");
                        temp.Season03QTY = venM3Q.ToString("F0");
                        temp.Season04QTY = venM4Q.ToString("F0");

                        temp.TotalQTY = venTotQ.ToString("F0");
                        list.Add(temp);
                    }
                    catch (Exception)
                    {

                        //throw;
                    }
                }//Vender ends
                if (imaTotD != 0)
                {
                    temp = new IMAVenderCostSeasonReportData()
                    {
                        IMA = ima + " Total : "
                    };
                    M1D += imaM1D;
                    M1Q += imaM1Q;
                    M2D += imaM2D;
                    M2Q += imaM2Q;
                    M3D += imaM3D;
                    M3Q += imaM3Q;
                    M4D += imaM4D;
                    M4Q += imaM4Q;

                    TotD += imaTotD;
                    TotQ += imaTotQ;
                    temp.Season01USD = imaM1D.ToString("F2");
                    temp.Season02USD = imaM2D.ToString("F2");
                    temp.Season03USD = imaM3D.ToString("F2");
                    temp.Season04USD = imaM4D.ToString("F2");

                    temp.TotalUSD = imaTotD.ToString("F2");

                    temp.Season01QTY = imaM1Q.ToString("F0");
                    temp.Season02QTY = imaM2Q.ToString("F0");
                    temp.Season03QTY = imaM3Q.ToString("F0");
                    temp.Season04QTY = imaM4Q.ToString("F0");

                    temp.TotalQTY = imaTotQ.ToString("F0");
                    list.Add(temp);
                }
            }//ima ends
            if (TotD != 0)
            {
                temp = new IMAVenderCostSeasonReportData()
                {
                    IMA = "Balance Total : "
                };
                temp.Season01USD = M1D.ToString("F2");
                temp.Season02USD = M2D.ToString("F2");
                temp.Season03USD = M3D.ToString("F2");
                temp.Season04USD = M4D.ToString("F2");

                temp.TotalUSD = TotD.ToString("F2");

                temp.Season01QTY = M1Q.ToString("F0");
                temp.Season02QTY = M2Q.ToString("F0");
                temp.Season03QTY = M3Q.ToString("F0");
                temp.Season04QTY = M4Q.ToString("F0");
                temp.TotalQTY = TotQ.ToString("F0");
                list.Add(temp);
            }

        }
        catch (Exception)
        {

            //throw;
        }
        return list;
    }