public static SingletonVender Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonVender();
             var data = db.Vendor.Include("POCostType").Where(w => w.Enable == true).OrderBy(w => w.Id).ToList();
             _instance.Vendors = data;
         }
     }
     return(_instance);
 }
Exemplo n.º 2
0
 public static SingletonShareMonth Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonShareMonth();
             var data = db.ShareMonth.ToList();
             _instance.ShareMonth = data;
         }
     }
     return(_instance);
 }
 public static SingletonThisBudgetYear Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonThisBudgetYear();
             BudgetYear data = db.BudgetYear.FirstOrDefault(w => w.Enable == true && w.IsCurrent == true);
             _instance.ThisYear = data;
         }
     }
     return(_instance);
 }
Exemplo n.º 4
0
 public static SingletonEmployee Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonEmployee();
             var data = db.Employee.Where(w => w.Enable == true).OrderBy(w => w.Id).ToList();
             _instance.Employee = data;
         }
     }
     return(_instance);
 }
Exemplo n.º 5
0
 public static SingletonShared Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonShared();
             var share = db.Share.FirstOrDefault(w => w.Enable == true);
             _instance.Share = share;
         }
     }
     return(_instance);
 }
Exemplo n.º 6
0
 public static SingletonPromotionActive Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonPromotionActive();
             var data = db.PriceSchedule.Include("SellingPrice").Where(w => w.Enable == true && w.IsStop == false &&
                                                                       w.FKCampaign == MyConstant.CampaignType.DiscountDay).OrderBy(w => w.StartDate).ToList();
             _instance.PriceScheduleDiscountDay = data;
         }
     }
     return(_instance);
 }
Exemplo n.º 7
0
 public static SingletonProductCategory Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     //if (_instance == null)
     //{
     using (SSLsEntities db = new SSLsEntities())
     {
         _instance = new SingletonProductCategory();
         //var data = db.ProductCategory.OrderBy(w => w.Id).ToList();
         var data = db.ProductCategory.Where(w => w.Enable == true).OrderBy(w => w.Id).ToList();
         _instance.ProductCategories = data;
     }
     //}
     return(_instance);
 }
Exemplo n.º 8
0
        /// <summary>
        /// รายการของเสีย
        /// </summary>
        /// <param name="code">รหัสใบของเสีย</param>
        /// <returns></returns>
        public static List <c_WastManage_Details> getList(string code)
        {
            try
            {
                List <c_WastManage_Details> ls      = new List <c_WastManage_Details>();
                List <c_WastManage_Details> lsGroup = new List <c_WastManage_Details>();
                using (SSLsEntities db = new SSLsEntities())
                {
                    var getHead = db.StoreFrontTransferWaste.FirstOrDefault(w => w.Enable == true && w.Code == code);

                    foreach (var sf in getHead.StoreFrontTransferWasteDtl.Where(w => w.Enable == true).ToList())
                    {
                        c_WastManage_Details wm = new c_WastManage_Details();
                        wm.ProductNo     = sf.ProductDetails.Code; // รหัสสินค้า
                        wm.ProductDetail = sf.ProductDetails.Products.ThaiName;
                        wm.ProductUnit   = sf.ProductDetails.ProductUnit.Name;
                        wm.QTY           = sf.Qty;         // ชิ้น
                        wm.Price         = sf.CostPerUnit; // ราคาต่อหน่วย
                        wm.Packsize      = sf.ProductDetails.PackSize;
                        // หมายเหตุ
                        wm.DescriptionList = sf.Description;
                        ls.Add(wm);
                    }
                    var groupData = ls.GroupBy(a => new { a.ProductNo })
                                    .Select(g => new { Key = g.Key, Count = g.Count() });
                    foreach (var dt in groupData)
                    {
                        c_WastManage_Details wm = new c_WastManage_Details();
                        wm.ProductNo     = ls.FirstOrDefault(w => w.ProductNo == dt.Key.ProductNo).ProductNo;
                        wm.ProductDetail = ls.FirstOrDefault(w => w.ProductNo == dt.Key.ProductNo).ProductDetail;
                        wm.ProductUnit   = ls.FirstOrDefault(w => w.ProductNo == dt.Key.ProductNo).ProductUnit;
                        wm.QTY           = ls.Where(w => w.ProductNo == dt.Key.ProductNo).Sum(w => w.QTY);   // ชิ้น
                        wm.Price         = ls.Where(w => w.ProductNo == dt.Key.ProductNo).Sum(w => w.Price); // ราคาต่อหน่วย
                        wm.Packsize      = ls.Where(w => w.ProductNo == dt.Key.ProductNo).Sum(w => w.Packsize);
                        // หมายเหตุ
                        wm.DescriptionList = ls.FirstOrDefault(w => w.ProductNo == dt.Key.ProductNo).DescriptionList;
                        lsGroup.Add(wm);
                    }
                }
                return(lsGroup);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "แจ้งเตือนจากระบบ!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
 /// <summary>
 /// ข้อมูลส่วน head // สามาชิก ลูกหนี้ เลขที่เอกสาร ชื่อร้าน
 /// </summary>
 /// <param name="code">code ที่เลือกจาก datagrid</param>
 /// <returns></returns>
 public static List <c_SaleOrderWarehouse_Header> getHead(string code)
 {
     try
     {
         List <c_SaleOrderWarehouse_Header> ls = new List <c_SaleOrderWarehouse_Header>();
         using (SSLsEntities db = new SSLsEntities())
         {
             var getData = db.SaleOrderWarehouse
                           .Include("Branch")
                           .Include("Member")
                           .Include("Debtor")
                           .Include("DeliveryType")
                           .FirstOrDefault(w => w.Code.Equals(code) && w.Enable == true);
             c_SaleOrderWarehouse_Header c = new c_SaleOrderWarehouse_Header();
             // head //
             c.NameShop    = getData.Branch.Name;
             c.AddressShop = getData.Branch.Address;
             c.TelShop     = getData.Branch.Tel;
             c.FaxShop     = getData.Branch.Fax;
             c.TaxNoShop   = getData.Branch.TaxNo;
             c.Email       = getData.Branch.Email;
             //c.GenBarcode =
             // member //
             c.NameMember = getData.Member.Name;
             c.NoMember   = getData.Member.Code;
             // Debtop //
             c.NameDebtor    = getData.Debtor.Name;
             c.AddressDebtor = getData.Debtor.Address;
             c.NoDebtor      = getData.Debtor.Code;
             // invoice no //
             c.InvoiceNo    = getData.Code;
             c.InvoicDate   = getData.CreateDate.ToString("dd/MM/yyyy");
             c.TaxInvoice   = getData.InvoiceNo;
             c.CodeRefer    = getData.CodeRefer;
             c.DeliveryType = getData.DeliveryType.Name;
             c.CreateBy     = getData.CreateBy;
             c.PrintDate    = DateTime.Now.ToString("dd/MM/yyyy");
             ls.Add(c);
             return(ls);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "แจ้งเตือนจากระบบ!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         throw;
     }
 }
Exemplo n.º 10
0
 public static SingletonAgeOfShare Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             int thisBudget = SingletonThisBudgetYear.Instance().ThisYear.Id;
             _instance = new SingletonAgeOfShare();
             var data = db.AgeOfShare.Where(w => w.Enable == true)
                        .OrderBy(w => w.TermStart).ToList();
             _instance.AgeOfShare = data;
         }
     }
     return(_instance);
 }
 public static SingletonMember Instance()
 {
     // Uses lazy initialization.
     // Note: this is not thread safe.
     if (_instance == null)
     {
         using (SSLsEntities db = new SSLsEntities())
         {
             _instance = new SingletonMember();
             var data = db.Member.Include("Sex").Include("MemberShare.Share").Include("MemberShare.AgeOfShare")
                        .Where(w => w.Enable == true)
                        .ToList();
             _instance.Members = data;
         }
     }
     return(_instance);
 }
        public static System.Data.DataTable getData(List <classCheckStock> dataList)
        {
            var PrintDate = Library.ConvertDateToThaiDate(DateTime.Now, true);
            var getShop   = Singleton.SingletonAuthen.Instance().MyBranch;
            var Name      = Singleton.SingletonAuthen.Instance().Name;

            using (SSLsEntities db = new SSLsEntities())
            {
                List <StoreFrontValueDoc> list = new List <StoreFrontValueDoc>();
                var TotalQty       = dataList.Sum(w => w.TotalQtyUnit);
                var TotalCost      = dataList.Sum(w => w.TotalCostOnly);
                var ThaiBath       = Library.ThaiBaht(TotalCost.ToString());
                var TotalCountList = dataList.Count();
                var getDate        = dataList
                                     .Select(a => new
                {
                    NameShop    = getShop.Name + " " + getShop.BranchNo,
                    NameAddress = getShop.Address,
                    TelShop     = getShop.Tel,
                    FaxShop     = getShop.Fax,
                    EmailShop   = getShop.Email,
                    TaxNo       = getShop.TaxNo,

                    PrintBy            = Name,      // ผู้พิมพ์
                    PrintDate          = PrintDate, // วันที่พิมพ์
                    Check              = a.check,
                    DocNo              = a.DocNo,
                    DocDate            = a.DocDate,
                    CreateBy           = a.CreateBy,
                    SaveNumber         = a.SaveNumber,
                    StoreFrontValueSet = a.StoreFrontValueSet,
                    TotalQtyUnit       = a.TotalQtyUnit,
                    Total              = a.TotalCostOnly,
                    Description        = a.Description,
                    TotalQty           = TotalQty,  // รวมชิ้น
                    TotalCost          = TotalCost, // รวมราคา
                    ThaiBath           = ThaiBath,
                    TotalCountList     = TotalCountList
                }).ToList();
                var dt = Library.ConvertToDataTable(getDate);
                return(dt);
            }
        }
Exemplo n.º 13
0
        public static SingletonAuthen Instance()
        {
            // Uses lazy initialization.
            // Note: this is not thread safe.
            if (_instance == null)
            {
                _instance      = new SingletonAuthen();
                _instance.Id   = LoginId;
                _instance.Name = FullName;

                using (SSLsEntities db = new SSLsEntities())
                {
                    var user = db.Users.Include("Role.MenuAccess.Menu").SingleOrDefault(w => w.Id == LoginId);
                    _instance.Users    = user;
                    _instance.MyBranch = user.Branch;
                }
            }
            return(_instance);
        }
Exemplo n.º 14
0
        public static DataTable getData(string code)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                var ad = db.AdjustStoreFrontDetail.Where(w => w.Enable == true &&
                                                         w.AdjustStoreFront.Enable == true && w.AdjustStoreFront.Code == code).ToList();

                var convertInvoiceData    = Library.ConvertDateToThaiDate(ad.FirstOrDefault().CreateDate, true);
                var TotalList             = ad.Count();
                var TotalPiece            = ad.Sum(s => s.Qty);
                var TotalCostPerUnit      = ad.Sum(s => s.Qty * s.CostPerUnit);
                var TotalSellPricePerUnit = ad.Sum(s => s.Qty * s.SellPricePerUnit);
                var createBy   = Library.GetFullNameUserById(ad.FirstOrDefault().CreateBy);
                var selectData = ad.Select(s =>
                                           new
                {
                    InvoiceNo   = s.AdjustStoreFront.Code,
                    InvoiceDate = convertInvoiceData,
                    CreateBy    = createBy,

                    ProductNo        = s.ProductDetails.Code,
                    ProductName      = s.ProductDetails.Products.ThaiName,
                    ProductUnit      = s.ProductDetails.ProductUnit.Name + "x" + s.ProductDetails.PackSize,
                    QTY              = s.Qty,
                    Packsize         = s.ProductDetails.PackSize,
                    CostPerUnit      = s.CostPerUnit,
                    SellPricePerUnit = s.SellPricePerUnit,
                    Warehouse        = "หน้าร้าน",

                    TotalCostPerUnit      = TotalCostPerUnit,
                    TotalSellPricePerUnit = TotalSellPricePerUnit,

                    TotalPiece = TotalPiece,
                    TotalList  = TotalList,

                    Description = s.AdjustStoreFront.Description,
                    ThaiBath    = Library.ThaiBaht(s.AdjustStoreFront.TotalBalance.ToString())
                }).ToList();
                var dt = Library.ConvertToDataTable(selectData);
                return(dt);
            }
        }
        //public List<Shelf> Shelfs { get; set; }

        public static SingletonPriority1 Instance()
        {
            // Uses lazy initialization.
            // Note: this is not thread safe.
            if (_instance == null)
            {
                using (SSLsEntities db = new SSLsEntities())
                {
                    _instance = new SingletonPriority1();
                    //var data = db.ProductDetails
                    //        .Include("Products")
                    //    .Include("Products.Supplier")
                    //        .Include("Products.ProductBrands")
                    //    .Include("Products.ProductVatType")
                    //    .Include("ProductUnit").ToList();

                    //_instance.Branchs = db.Branch.ToList();

                    _instance.BudgetYears = db.BudgetYear.ToList();
                    //_instance.ThisBudgetYear = budgetYears.FirstOrDefault(w => w.Enable == true && w.IsCurrent == true);

                    _instance.PaymentTypes = db.PaymentType.ToList();

                    _instance.ProductVatType = db.ProductVatType.Where(w => w.Enable == true).ToList();
                    _instance.CostType       = db.CostType.ToList();
                    //_instance.ProductCategory = db.ProductCategory.ToList();
                    //_instance.ProductGroups = db.ProductGroups.ToList();
                    _instance.Supplier = db.Supplier.ToList();
                    //_instance.Vendor = db.Vendor.Include("POCostType").ToList();
                    //_instance.ProductBrands = db.ProductBrands.ToList();
                    _instance.ProductSize   = db.ProductSize.ToList();
                    _instance.ProductColor  = db.ProductColor.ToList();
                    _instance.Zone          = db.Zone.ToList();
                    _instance.DeliveryTypes = db.DeliveryType.Where(w => w.Enable == true).ToList();
                    //_instance.ProductUnit = db.ProductUnit.ToList();
                    _instance.Users = db.Users.ToList();
                    //_instance.Shelfs = db.Shelf.ToList();
                }
            }
            return(_instance);
        }
Exemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code">PONo</param>
        public static DataTable getData(string code)
        {
            try
            {
                using (SSLsEntities db = new SSLsEntities())
                {
                    var PrintDate = Library.ConvertDateToThaiDate(DateTime.Now, true);

                    List <PORcvDetails> data = db.PORcvDetails
                                               .Where(w => w.Enable == true && w.PORcv.Code == code && w.PORcv.Enable == true).ToList();
                    var getTotalQty = data
                                      .Where(w => w.Enable == true && w.PORcv.Code == code && w.PORcv.Enable == true).Sum(w => w.RcvQuantity);
                    var getTotalGiftQty = data
                                          .Where(w => w.Enable == true && w.PORcv.Code == code && w.PORcv.Enable == true).Sum(w => w.GiftQty);
                    var getTotalPrice = data
                                        .Where(w => w.Enable == true && w.PORcv.Code == code && w.PORcv.Enable == true).Sum(w => w.TotalPrice);
                    var TotalCountList = data
                                         .Where(w => w.Enable == true && w.PORcv.Code == code && w.PORcv.Enable == true &&
                                                w.RcvQuantity > 0 || w.GiftQty > 0).GroupBy(a => a.ProductDetails.Code).Count();
                    var TotalDiscount = data
                                        .Where(w => w.Enable == true && w.PORcv.Code == code && w.PORcv.Enable == true).Sum(w => w.DiscountBath);

                    var conCreateDate  = Library.ConvertDateToThaiDate(data.FirstOrDefault().CreateDate, true);
                    var conInvoiceDate = Library.ConvertDateToThaiDate(data.FirstOrDefault().PORcv.InvoiceDate, true);
                    var conCreateBy    = Library.GetFullNameUserById(data.FirstOrDefault().CreateBy);
                    var conThaiBath    = Library.ThaiBaht((data.FirstOrDefault().PORcv.TotalBUnVat + data.FirstOrDefault().PORcv.TotalBHasVat + data.FirstOrDefault().PORcv.TotalVat).ToString());
                    var getData        = data.Where(w => w.RcvQuantity > 0 || w.GiftQty > 0).OrderBy(w => w.SequenceNumber)
                                         .Select(a => new
                    {
                        NameShop    = a.PORcv.POHeader.Branch.Name + " " + a.PORcv.POHeader.Branch.BranchNo,
                        AddressShop = a.PORcv.POHeader.Branch.Address,
                        TelShop     = a.PORcv.POHeader.Branch.Tel,
                        FaxShop     = a.PORcv.POHeader.Branch.Fax,
                        TaxNoShop   = a.PORcv.POHeader.Branch.TaxNo,
                        EmailShop   = a.PORcv.POHeader.Branch.Email,

                        //เลขที่เอกสาร
                        PORcvNo = a.PORcv.Code,
                        // วันที่เอกสาร
                        PORcvCreateDate = conCreateDate,
                        // เลขที่ PO
                        PoNo = a.PORcv.PORefer,
                        // เลขที่ใบรับเข้า
                        PODate    = a.PORcv.POHeader.PODate,
                        CreateBy  = conCreateBy,
                        PrintDate = PrintDate, // วันที่ปริ้น

                        VenderName    = a.PORcv.Vendor.Name,
                        VenderAddress = a.PORcv.Vendor.Address,
                        VenderTel     = a.PORcv.Vendor.Tel,
                        VenderFax     = a.PORcv.Vendor.Fax,

                        InvoiceNo    = a.PORcv.InvoiceNo,
                        InvoiceDate  = conInvoiceDate,
                        Number       = a.SequenceNumber,
                        ProductNo    = a.ProductDetails.Code,
                        ProductsName = a.ProductDetails.Products.ThaiName,
                        ProductUnit  = a.ProductDetails.ProductUnit.Name,
                        GiftQty      = a.GiftQty,     // จำนวนแถม ใบรับเข้าสินค้า
                        Qty          = a.RcvQuantity, // จำนวนที่รับเข้า ใบรับเข้าสินค้า

                        PricePerUnit     = a.NewCost,
                        Discount         = a.DiscountBath,
                        TotalPrice       = a.TotalPrice,
                        TotalPriceList   = getTotalPrice,
                        Discription      = a.Description,
                        TotalQty         = getTotalQty + getTotalGiftQty, // จำนวน + ของแถม
                        TotalCountList   = TotalCountList,
                        TotalDiscount    = TotalDiscount,
                        TotalVat         = a.PORcv.TotalVat,
                        TotalBefDiscount = getTotalPrice - TotalDiscount,
                        TotalBUnVat      = a.PORcv.TotalBUnVat,
                        TotalBHasVat     = a.PORcv.TotalBHasVat,
                        Total            = a.PORcv.TotalBUnVat + a.PORcv.TotalBHasVat + a.PORcv.TotalVat,
                        ThaiBath         = conThaiBath
                    })
                                         .ToList();
                    var dt = Library.ConvertToDataTable(getData);
                    return(dt);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("" + ex.ToString());
            }
            return(null);
        }
Exemplo n.º 17
0
        public static DataTable getData(string code)
        {
            try
            {
                using (SSLsEntities db = new SSLsEntities())
                {
                    var getShop = Singleton.SingletonAuthen.Instance().MyBranch;

                    var getData = db.CNWarehouseDetails
                                  .Where(w => w.CNWarehouse.Enable == true && w.CNWarehouse.Code == code).ToList();

                    //var _TotalQty = getData.Sum(w => w.Qty);
                    var _CountList      = getData.Count();
                    var _TotalPriceList = getData.FirstOrDefault().CNWarehouse.TotalBalance;
                    var _TotalVat       = getData.Sum(w => w.Vat);
                    var _TotalBeforeVat = getData.Sum(w => w.BeforeVat);
                    var GetThaiBath     = Library.ThaiBaht(_TotalPriceList.ToString());
                    var InvoiceDate     = Library.ConvertDateToThaiDate(getData.FirstOrDefault().CreateDate, true);
                    var PrintDate       = Library.ConvertDateToThaiDate(DateTime.Now, true);

                    string name = Library.GetFullNameUserById(getData.FirstOrDefault().CreateBy);
                    var    list = getData.Select(w => new
                    {
                        NameShop    = getShop.Name + " " + getShop.BranchNo,
                        AddressShop = getShop.Address,
                        TelShop     = getShop.Tel,
                        FaxShop     = getShop.Fax,
                        EmailShop   = getShop.Email,
                        TaxNoShop   = getShop.TaxNo,

                        NoVendor      = w.CNWarehouse.Vendor.Code,
                        NameVendor    = w.CNWarehouse.Vendor.Name,
                        AddressVendor = w.CNWarehouse.Vendor.Address,

                        InvoiceNo           = w.CNWarehouse.Code,
                        InvoiceDate         = InvoiceDate,
                        CreateBy            = name,
                        PrintDate           = PrintDate,
                        Description         = w.CNWarehouse.WasteReason.Name + " - " + w.CNWarehouse.Description,
                        ProductNo           = w.ProductDetails.Code,
                        ProductName         = w.ProductDetails.Products.ThaiName,
                        ProductUnit         = w.ProductDetails.ProductUnit.Name + "x" + w.ProductDetails.PackSize,
                        Packsize            = w.ProductDetails.PackSize,
                        PricePerUnit        = w.PricePerUnit,
                        PriceBeforeVat      = w.BeforeVat,
                        Vat                 = w.Vat,
                        QTY                 = w.Qty,
                        TotalPrice          = w.TotalPrice,                                    // ราคารวม
                        TotalQTY            = w.CNWarehouse.TotalQtyUnit,                      // ผลรวมจำนวน
                        CountList           = _CountList,                                      // จำนวนรายการ
                        TotalPriceList      = _TotalPriceList,                                 // ราคารวม
                        TotalVat            = _TotalVat,                                       // รวมภาษี
                        TotalPriceBeforeVat = _TotalBeforeVat,                                 // รวมก่อนภาษี
                        TotalNetValues      = _TotalPriceList + ((_TotalPriceList * 7) / 100), //ราคาสุทธิ
                        ThaiBath            = GetThaiBath
                    }).ToList();

                    var dt = Library.ConvertToDataTable(list);
                    return(dt);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "แจ้งเตือนจากระบบ!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Exemplo n.º 18
0
        public static DataTable getHead(string code)
        {
            try
            {
                using (SSLsEntities db = new SSLsEntities())
                {
                    var getListData = db.GetGoodsStoreFrontDetails
                                      .Where(w => w.Enable == true && w.GetGoodsStoreFront.Enable == true & w.GetGoodsStoreFront.Code == code).ToList();

                    var getShop     = Singleton.SingletonAuthen.Instance().MyBranch;
                    var getWhoPrint = Singleton.SingletonAuthen.Instance().Name;

                    var TotalCostPerUnit = getListData.Sum(w => w.CostPerUnit);
                    var TotalQTY         = getListData.Sum(w => w.Qty);
                    var TotalSalePrice   = getListData.Sum(w => w.SellPricePerUnit * w.Qty);

                    var    TotalCountList = getListData.Count();
                    var    PrintDate      = Library.ConvertDateToThaiDate(DateTime.Now, true);
                    string InvoiceDate    = "";
                    string userCreate     = "";
                    if (getListData.Count() > 0)
                    {
                        InvoiceDate = Library.ConvertDateToThaiDate(getListData.FirstOrDefault().GetGoodsStoreFront.CreateDate, true);
                        userCreate  = Library.GetFullNameUserById(getListData.FirstOrDefault().CreateBy);
                    }
                    else
                    {
                        InvoiceDate = "";
                        userCreate  = "";
                    }
                    var getData = getListData
                                  .Select(w => new
                    {
                        NameShop          = getShop.Name + " " + getShop.BranchNo,
                        AddressShop       = getShop.Address,
                        TelShop           = getShop.Tel,
                        Email             = getShop.Email,
                        TaxNoShop         = getShop.TaxNo,
                        FaxShop           = getShop.Fax,
                        BranchSource      = getShop.Name + " " + getShop.BranchNo,
                        BranchDestination = "",
                        CreateBy          = userCreate,
                        InvoiceNo         = w.GetGoodsStoreFront.Code,
                        InvoiceDate       = InvoiceDate,
                        PrintDate         = PrintDate,
                        PrintBy           = getWhoPrint,
                        ProductNo         = w.ProductDetails.Code,
                        ProductName       = w.ProductDetails.Products.ThaiName,
                        ProductUnti       = w.ProductDetails.ProductUnit.Name + "x" + w.ProductDetails.PackSize,
                        QTY              = w.Qty,
                        Packsize         = w.ProductDetails.PackSize,
                        CostPerUnit      = w.CostPerUnit,
                        TypeTax          = w.ProductDetails.Products.ProductVatType.Name,
                        SalePrice        = w.SellPricePerUnit,
                        TotalSalePrice   = TotalSalePrice,
                        TotalQTY         = TotalQTY,                          // จำนวนรวม
                        TotalCostPerUnit = w.GetGoodsStoreFront.TotalBalance, // ราคารวม
                        TotalCountList   = TotalCountList,
                        ThaiBath         = Library.ThaiBaht(w.GetGoodsStoreFront.TotalBalance.ToString()),
                        Warehouse        = "หน้าร้าน",
                        Description      = w.GetGoodsStoreFront.Description
                    }).ToList();
                    var dt = Library.ConvertToDataTable(getData);
                    return(dt);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "แจ้งเตือนจากระบบ!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
        /// <summary>
        /// เลขที่เอกสาร
        /// </summary>
        /// <param name="DocNo"></param>
        public static DataTable getData(string DocNo)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                var getDoc          = db.StoreFrontValueDoc.SingleOrDefault(w => w.DocNo == DocNo);
                var sumQty1         = Library.ConvertDecimalToStringForm(getDoc.StoreFrontValueSet.Where(w => w.Enable == true).Sum(a => a.QtyUnit1));
                var sumQty2         = Library.ConvertDecimalToStringForm(getDoc.StoreFrontValueSet.Where(w => w.Enable == true).Sum(a => a.QtyUnit2));
                var sumPrice        = Library.ConvertDecimalToStringForm(getDoc.StoreFrontValueSet.Where(w => w.Enable == true).Sum(a => a.Total));
                var conThaiBath     = Library.ThaiBaht(sumPrice.ToString());
                var con             = getDoc.StoreFrontValueSet.FirstOrDefault(w => w.Enable == true);
                var conDocDate      = Library.ConvertDateToThaiDate(con.StoreFrontValueDoc.DocDate, true);
                var conNameCreateby = Library.GetFullNameUserById(con.StoreFrontValueDoc.CreateBy);
                var getBranch       = Singleton.SingletonAuthen.Instance().MyBranch;
                var getName         = Singleton.SingletonAuthen.Instance().Name;
                var PrintDate       = Library.ConvertDateToThaiDate(DateTime.Now, true);
                var countList       = getDoc.StoreFrontValueSet.Where(w => w.Enable == true).ToList().Count();
                var conCountList    = Convert.ToInt32(countList);
                if (getDoc.ConfirmCheck1Date == null)
                {
                    var data = getDoc.StoreFrontValueSet.Where(w => w.Enable == true)
                               .Select(a => new
                    {
                        NameShop    = getBranch.Name + " " + getBranch.BranchNo,
                        AddressShop = getBranch.Address,
                        TelShop     = getBranch.Tel,
                        FaxShop     = getBranch.Fax,
                        Email       = getBranch.Email,
                        TaxNoShop   = getBranch.TaxNo,
                        // ชื่อผู้พิพม์
                        NamePrint = getName,
                        // วันที่พิมพ์
                        PrintDate = PrintDate,
                        // ชื่อผู้บันทึก
                        NameRecode = conNameCreateby,
                        // ปริ้นครั้งที่
                        PrintNumber = a.StoreFrontValueDoc.PrintNumber,

                        DocNo            = a.StoreFrontValueDoc.DocNo,
                        DocDate          = conDocDate,
                        ProductNo        = a.ProductDetails.Code,
                        ProductName      = a.ProductDetails.Products.ThaiName,
                        ProductUnti      = a.ProductDetails.ProductUnit.Name + "x" + a.ProductDetails.PackSize,
                        Number           = a.Number,
                        Packsize         = a.Packsize,
                        Qty1             = a.QtyUnit1, // จำนวนนับครั้งที่ 1
                        Qty2             = "",         // จำนวนนับครั้งที่ 2
                        CostOnlyPerUnit  = a.CostOnlyPerUnit,
                        SellPricePerUnit = a.SellPricePerUnit,
                        Total            = a.Total,
                        Warehouse        = "หน้าร้าน",
                        Description      = a.StoreFrontValueDoc.Description,
                        TotalQty1        = sumQty1,
                        TotalQty2        = "",
                        TotalPrice       = sumPrice,
                        TotalList        = conCountList,
                        ThaiBath         = conThaiBath
                    }).OrderBy(a => a.Number).ToList();

                    var dt = Library.ConvertToDataTable(data);
                    return(dt);
                }
                //else if (getDoc.ConfirmCheck1Date != null && getDoc.ConfirmCheck2Date == null)
                //{
                //    var data = getDoc.StoreFrontValueSet.Where(w => w.Enable == true)
                //    .Select(a => new
                //    {
                //        NameShop = getBranch.Name + " " + getBranch.BranchNo,
                //        AddressShop = getBranch.Address,
                //        TelShop = getBranch.Tel,
                //        FaxShop = getBranch.Fax,
                //        Email = getBranch.Email,
                //        TaxNoShop = getBranch.TaxNo,
                //        // ชื่อผู้พิพม์
                //        NamePrint = getName,
                //        // วันที่พิมพ์
                //        PrintDate = PrintDate,
                //        // ชื่อผู้บันทึก
                //        NameRecode = conNameCreateby,
                //        // ปริ้นครั้งที่
                //        PrintNumber = a.StoreFrontValueDoc.PrintNumber,

                //        DocNo = a.StoreFrontValueDoc.DocNo,
                //        DocDate = conDocDate,
                //        ProductNo = a.ProductDetails.Code,
                //        ProductName = a.ProductDetails.Products.ThaiName,
                //        ProductUnti = a.ProductDetails.ProductUnit.Name + "x" + a.ProductDetails.PackSize,
                //        Number = a.Number,
                //        Packsize = a.Packsize,
                //        Qty1 = a.QtyUnit1, // จำนวนนับครั้งที่ 1
                //        Qty2 = , // จำนวนนับครั้งที่ 2
                //        CostOnlyPerUnit = a.CostOnlyPerUnit,
                //        SellPricePerUnit = a.SellPricePerUnit,
                //        Total = a.Total,
                //        Warehouse = "หน้าร้าน",
                //        Description = a.StoreFrontValueDoc.Description,
                //        TotalQty1 = sumQty1,
                //        TotalQty2 = sumQty2,
                //        TotalPrice = sumPrice,
                //        TotalList = conCountList,
                //        ThaiBath = conThaiBath

                //    }).OrderBy(a => a.Number).ToList();

                //    var dt = Library.ConvertToDataTable(data);
                //    return dt;
                //}
                else
                {
                    var data = getDoc.StoreFrontValueSet.Where(w => w.Enable == true)
                               .Select(a => new
                    {
                        NameShop    = getBranch.Name + " " + getBranch.BranchNo,
                        AddressShop = getBranch.Address,
                        TelShop     = getBranch.Tel,
                        FaxShop     = getBranch.Fax,
                        Email       = getBranch.Email,
                        TaxNoShop   = getBranch.TaxNo,
                        // ชื่อผู้พิพม์
                        NamePrint = getName,
                        // วันที่พิมพ์
                        PrintDate = PrintDate,
                        // ชื่อผู้บันทึก
                        NameRecode = conNameCreateby,
                        // ปริ้นครั้งที่
                        PrintNumber = a.StoreFrontValueDoc.PrintNumber,

                        DocNo            = a.StoreFrontValueDoc.DocNo,
                        DocDate          = conDocDate,
                        ProductNo        = a.ProductDetails.Code,
                        ProductName      = a.ProductDetails.Products.ThaiName,
                        ProductUnti      = a.ProductDetails.ProductUnit.Name + "x" + a.ProductDetails.PackSize,
                        Number           = a.Number,
                        Packsize         = a.Packsize,
                        Qty1             = a.QtyUnit1, // จำนวนนับครั้งที่ 1
                        Qty2             = a.QtyUnit2, // จำนวนนับครั้งที่ 2
                        CostOnlyPerUnit  = a.CostOnlyPerUnit,
                        SellPricePerUnit = a.SellPricePerUnit,
                        Total            = a.Total,
                        Warehouse        = "หน้าร้าน",
                        Description      = a.StoreFrontValueDoc.Description,
                        TotalQty1        = sumQty1,
                        TotalQty2        = sumQty2,
                        TotalPrice       = sumPrice,
                        TotalList        = conCountList,
                        ThaiBath         = conThaiBath
                    }).OrderBy(a => a.Number).ToList();

                    var dt = Library.ConvertToDataTable(data);
                    return(dt);
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// ปริ้นใบ PO 1 ใบ
        /// </summary>
        /// <param name="poNo"></param>
        public static POHeader GetPOFormPrint(int id)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                try
                {
                    List <POProductDetails> details = new List <POProductDetails>();

                    var     data            = db.POHeader.FirstOrDefault(w => w.Id == id);
                    int     i               = 1;
                    decimal sumPricePerUnit = 0;
                    decimal sumTotal        = 0;
                    decimal sumDiscount     = 0;
                    decimal TotalList       = 0;
                    foreach (var item in data.PODetail.Where(w => w.Enable == true).ToList())
                    {
                        decimal price = 0;
                        if (item.POHeader.Vendor.POCostType.Id == MyConstant.POCostType.CostOnly)
                        {
                            // หาก Vendor ยึดราคา ทุนเปล่า ใช้ ราคา ทุนเปล่า
                            price = item.CostOnly;
                        }
                        else
                        {
                            price = item.CostAndVat;
                        }
                        details.Add(new Repository.POProductDetails()
                        {
                            Number   = i,
                            Code     = item.ProductDetails.Code,
                            Name     = item.ProductDetails.Products.ThaiName,
                            Discount = Library.ConvertDecimalToStringForm(item.DiscountBath),
                            Gift     = Library.ConvertDecimalToStringForm(item.GiftQty),
                            Price    = Library.ConvertDecimalToStringForm(price),
                            Qty      = Library.ConvertDecimalToStringForm(item.Qty),
                            Total    = Library.ConvertDecimalToStringForm(item.TotalCost),
                            Unit     = item.ProductDetails.ProductUnit.Name
                        });
                        sumPricePerUnit += price;
                        sumTotal        += item.TotalCost;
                        sumDiscount     += item.DiscountBath;
                        TotalList        = data.PODetail.Where(w => w.Enable == true).ToList().Count();
                        i++;
                    }

                    Repository.POHeader hd = new Repository.POHeader();
                    hd.PODetails       = details;
                    hd.CompName        = data.Branch.Name + " สาขา " + data.Branch.BranchNo;
                    hd.CompAddress     = data.Branch.Address;
                    hd.CompTax         = data.Branch.TaxNo;
                    hd.CompTel         = data.Branch.Tel;
                    hd.CompEmail       = data.Branch.Email;
                    hd.CompFax         = data.Branch.Fax;
                    hd.CompDescription = data.Branch.Description;

                    hd.VendorCode    = data.Vendor.Code;
                    hd.VendorName    = data.Vendor.Name;
                    hd.VendorAddress = data.Vendor.Address;
                    hd.TargetName    = hd.CompName;
                    hd.TargetAddress = hd.CompAddress;

                    hd.PONo        = data.PONo;
                    hd.PODate      = Library.ConvertDateToThaiDate(DateTime.Now, true);
                    hd.BudgetYear  = data.BudgetYear.Name;
                    hd.ReferNo     = data.ReferenceNo;
                    hd.DuaDate     = Library.ConvertDateToThaiDate(data.DueDate);
                    hd.POExpire    = Library.ConvertDateToThaiDate(data.POExpire);
                    hd.PaymentType = data.PaymentType.Name;

                    hd.CreateBy = Library.GetFullNameUserById(data.CreateBy);
                    if (MyConstant.CostType.Vat == 1)
                    {
                        hd.VatType = "ไม่มีภาษี";
                    }
                    hd.VatType = "มีภาษี";
                    hd.SumQty  = Library.ConvertDecimalToStringForm(data.TotalQty);
                    // ใช้ชื่อ SumGift ขี้เกียจรีเครื่อง ใช้เป็นตัวนับรายการทั้งหมด
                    hd.SumGift     = TotalList.ToString(); /*Library.ConvertDecimalToStringForm(data.TotalGift);*/
                    hd.SumPrice    = Library.ConvertDecimalToStringForm(sumPricePerUnit);
                    hd.SumDiscount = Library.ConvertDecimalToStringForm(sumDiscount);
                    hd.SumTotal    = Library.ConvertDecimalToStringForm(sumTotal);
                    hd.Remark      = data.Description;
                    hd.ThaiBath    = "(" + Library.ThaiBaht(data.TotalBalance + "") + ")";

                    hd.TotalAmount     = Library.ConvertDecimalToStringForm(data.TotalPrice);
                    hd.DiscountPercent = Library.ConvertDecimalToStringForm(data.TotalDiscount * 100 / (data.TotalUnVat + data.TotalHasVat)) + "%";
                    hd.TotalDiscount   = Library.ConvertDecimalToStringForm(data.TotalDiscount);
                    hd.TotalAfterDis   = Library.ConvertDecimalToStringForm(data.TotalPriceDiscount);
                    hd.TotalVat        = Library.ConvertDecimalToStringForm(data.TotalVat);
                    hd.TotalBalance    = Library.ConvertDecimalToStringForm(data.TotalBalance);
                    return(hd);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }