Exemplo n.º 1
0
        private void SaveProductPrice(Guid productId, string priceType, string currencyCode, string price)
        {
            using (var ctx = new EF6.RT2020Entities())
            {
                var priceTypeId = ProductPriceTypeEx.GetIdByPriceType(priceType);
                //string sql = "ProductId = '" + productId.ToString() + "' AND PriceTypeId = '" + priceTypeId.ToString() + "'";

                var oPrice = ctx.ProductPrice.Where(x => x.ProductId == productId && x.ProductPriceId == priceTypeId).FirstOrDefault();
                if (oPrice == null)
                {
                    oPrice = new EF6.ProductPrice();
                    oPrice.ProductPriceId = Guid.NewGuid();
                    oPrice.ProductId      = productId;

                    ctx.ProductPrice.Add(oPrice);
                }
                oPrice.PriceTypeId  = ProductPriceTypeEx.GetIdByPriceType(priceType);
                oPrice.CurrencyCode = currencyCode;
                oPrice.Price        = Convert.ToDecimal((price == string.Empty) ? "0" : price);

                ctx.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void CreateADJTx(ListViewItem listItem)
        {
            using (var ctx = new EF6.RT2020Entities())
            {
                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        Guid headerId = Guid.Empty;
                        if (Guid.TryParse(listItem.Text, out headerId))
                        {
                            var oBatchHeader = ctx.InvtBatchADJ_Header.Find(headerId);
                            if (oBatchHeader != null)
                            {
                                // Update Product Info
                                #region UpdateProduct(oBatchHeader.HeaderId, oBatchHeader.WorkplaceId);
                                Guid txHeaderId  = oBatchHeader.HeaderId;
                                Guid workplaceId = oBatchHeader.WorkplaceId;

                                var detailsList = ctx.InvtBatchADJ_Details.Where(x => x.HeaderId == txHeaderId);
                                foreach (var item in detailsList)
                                {
                                    Guid    productId = item.ProductId;
                                    decimal qty       = item.Qty.Value;

                                    #region UpdateProductCurrentSummary(item.ProductId, item.Qty.Value);
                                    var currProd = ctx.ProductCurrentSummary.Where(x => x.ProductId == productId).FirstOrDefault();
                                    if (currProd == null)
                                    {
                                        currProd = new EF6.ProductCurrentSummary();
                                        currProd.CurrentSummaryId = Guid.NewGuid();
                                        currProd.ProductId        = productId;
                                        ctx.ProductCurrentSummary.Add(currProd);
                                    }
                                    currProd.CDQTY += qty;
                                    #endregion

                                    #region UpdateProductQty(item.ProductId, workplaceId, item.Qty.Value);
                                    var wpProd = ctx.ProductWorkplace.Where(x => x.ProductId == productId && x.WorkplaceId == workplaceId).FirstOrDefault();
                                    if (wpProd == null)
                                    {
                                        wpProd = new EF6.ProductWorkplace();
                                        wpProd.ProductWorkplaceId = Guid.NewGuid();
                                        wpProd.ProductId          = productId;
                                        wpProd.WorkplaceId        = workplaceId;

                                        ctx.ProductWorkplace.Add(wpProd);
                                    }
                                    wpProd.CDQTY += qty;
                                    #endregion

                                    ctx.SaveChanges();
                                }
                                #endregion

                                // Create ADJ SubLedger
                                string txNumber_SubLedger = oBatchHeader.TxNumber;
                                #region Guid subLedgerHeaderId = CreateADJSubLedgerHeader(txNumber_SubLedger, oBatchHeader.TxDate, oBatchHeader.WorkplaceId, oBatchHeader.StaffId, oBatchHeader.Remarks, oBatchHeader.Reference + "\t" + oBatchHeader.TxNumber);
                                string   txnumber = txNumber_SubLedger;
                                DateTime txDate   = oBatchHeader.TxDate.Value;
                                //Guid workplaceId = oBatchHeader.WorkplaceId;
                                Guid   staffId   = oBatchHeader.StaffId;
                                string remarks   = oBatchHeader.Remarks;
                                string reference = oBatchHeader.Reference + "\t" + oBatchHeader.TxNumber;

                                var oSubADJ = new EF6.InvtSubLedgerADJ_Header();
                                oSubADJ.HeaderId    = Guid.NewGuid();
                                oSubADJ.TxNumber    = txnumber;
                                oSubADJ.TxType      = EnumHelper.TxType.ADJ.ToString();
                                oSubADJ.WorkplaceId = workplaceId;
                                oSubADJ.TxDate      = txDate;
                                oSubADJ.Reference   = reference;
                                oSubADJ.Remarks     = remarks;
                                oSubADJ.StaffId     = staffId;
                                oSubADJ.Status      = Convert.ToInt32(EnumHelper.Status.Active.ToString("d"));

                                oSubADJ.CreatedBy  = ConfigHelper.CurrentUserId;
                                oSubADJ.CreatedOn  = DateTime.Now;
                                oSubADJ.ModifiedBy = ConfigHelper.CurrentUserId;
                                oSubADJ.ModifiedOn = DateTime.Now;

                                ctx.InvtSubLedgerADJ_Header.Add(oSubADJ);
                                ctx.SaveChanges();

                                Guid subLedgerHeaderId = oSubADJ.HeaderId;
                                #endregion

                                #region CreateADJSubLedgerDetail(txNumber_SubLedger, oBatchHeader.HeaderId, subLedgerHeaderId);
                                //string txnumber = txNumber_SubLedger;
                                Guid batchHeaderId = oBatchHeader.HeaderId;

                                decimal  ttlAmt        = 0;
                                string   sql           = "HeaderId = '" + batchHeaderId.ToString() + "'";
                                string[] orderBy       = new string[] { "LineNumber" };
                                var      oBatchDetails = ctx.InvtBatchADJ_Details.Where(x => x.HeaderId == batchHeaderId).OrderBy(x => x.LineNumber);
                                foreach (var oBDetail in oBatchDetails)
                                {
                                    var oSubLedgerDetail = new EF6.InvtSubLedgerADJ_Details();
                                    oSubLedgerDetail.DetailsId   = Guid.NewGuid();
                                    oSubLedgerDetail.HeaderId    = subLedgerHeaderId;
                                    oSubLedgerDetail.LineNumber  = oBDetail.LineNumber.Value;
                                    oSubLedgerDetail.ProductId   = oBDetail.ProductId;
                                    oSubLedgerDetail.Qty         = oBDetail.Qty.Value;
                                    oSubLedgerDetail.TxNumber    = txnumber;
                                    oSubLedgerDetail.TxType      = EnumHelper.TxType.ADJ.ToString();
                                    oSubLedgerDetail.AverageCost = oBDetail.AverageCost.Value;
                                    oSubLedgerDetail.ReasonCode  = oBDetail.ReasonCode;
                                    oSubLedgerDetail.Remarks     = oBDetail.Remarks;

                                    ctx.InvtSubLedgerADJ_Details.Add(oSubLedgerDetail);

                                    ttlAmt += oSubLedgerDetail.Qty.Value * oSubLedgerDetail.AverageCost.Value;
                                }

                                var oSubLedgerHeader = ctx.InvtSubLedgerADJ_Header.Find(subLedgerHeaderId);
                                if (oSubLedgerHeader != null)
                                {
                                    oSubLedgerHeader.TotalAmount = ttlAmt;

                                    oSubLedgerHeader.ModifiedOn = DateTime.Now;
                                    oSubLedgerHeader.ModifiedBy = ConfigHelper.CurrentUserId;
                                }
                                ctx.SaveChanges();
                                #endregion

                                // Create Ledger for TxType 'ADJ'
                                string txNumber_Ledger = oBatchHeader.TxNumber;
                                #region Guid ledgerHeaderId = CreateLedgerHeader(txNumber_Ledger, oBatchHeader.TxDate, subLedgerHeaderId, oBatchHeader.WorkplaceId, oBatchHeader.StaffId, oBatchHeader.Reference + "\t" + txNumber_SubLedger, oBatchHeader.Remarks);
                                //string txnumber = txNumber_Ledger;
                                //DateTime txDate = oBatchHeader.TxDate.Value;
                                //Guid subLedgerHeaderId = subLedgerHeaderId;
                                //Guid workplaceId = oBatchHeader.WorkplaceId;
                                //Guid staffId = oBatchHeader.StaffId;
                                //string reference = oBatchHeader.Reference + "\t" + txNumber_SubLedger;
                                //string remarks = oBatchHeader.Remarks;

                                var oLedgerHeader = new EF6.InvtLedgerHeader();
                                oLedgerHeader.HeaderId          = Guid.NewGuid();
                                oLedgerHeader.TxNumber          = txnumber;
                                oLedgerHeader.TxType            = EnumHelper.TxType.ADJ.ToString();
                                oLedgerHeader.TxDate            = txDate;
                                oLedgerHeader.SubLedgerHeaderId = subLedgerHeaderId;
                                oLedgerHeader.WorkplaceId       = workplaceId;
                                oLedgerHeader.StaffId           = staffId;
                                oLedgerHeader.Reference         = reference;
                                oLedgerHeader.Remarks           = remarks;
                                oLedgerHeader.Status            = Convert.ToInt32(EnumHelper.Status.Active.ToString("d"));
                                oLedgerHeader.CreatedBy         = ConfigHelper.CurrentUserId;
                                oLedgerHeader.CreatedOn         = DateTime.Now;
                                oLedgerHeader.ModifiedBy        = ConfigHelper.CurrentUserId;
                                oLedgerHeader.ModifiedOn        = DateTime.Now;

                                ctx.InvtLedgerHeader.Add(oLedgerHeader);
                                ctx.SaveChanges();

                                Guid ledgerHeaderId = oLedgerHeader.HeaderId;
                                #endregion

                                #region CreateLedgerDetails(txNumber_Ledger, subLedgerHeaderId, ledgerHeaderId, oBatchHeader);
                                //string txnumber = txNumber_Ledger;
                                //Guid subledgerHeaderId = subLedgerHeaderId;
                                //Guid ledgerHeaderId = ledgerHeaderId;
                                //InvtBatchADJ_Header oBatchHeader

                                //string sql = "HeaderId = '" + subledgerHeaderId.ToString() + "'";
                                //string[] orderBy = new string[] { "LineNumber" };

                                var oSubLedgerDetails = ctx.InvtSubLedgerADJ_Details.Where(x => x.HeaderId == subLedgerHeaderId).OrderBy(x => x.LineNumber);
                                foreach (var oSDetail in oSubLedgerDetails)
                                {
                                    var oLedgerDetail = new EF6.InvtLedgerDetails();
                                    oLedgerDetail.DetailsId          = Guid.NewGuid();
                                    oLedgerDetail.HeaderId           = ledgerHeaderId;
                                    oLedgerDetail.SubLedgerDetailsId = oSDetail.DetailsId;
                                    oLedgerDetail.LineNumber         = oSDetail.LineNumber.Value;
                                    oLedgerDetail.ProductId          = oSDetail.ProductId;
                                    oLedgerDetail.Qty          = oSDetail.Qty.Value;
                                    oLedgerDetail.TxNumber     = txnumber;
                                    oLedgerDetail.TxType       = EnumHelper.TxType.ADJ.ToString();
                                    oLedgerDetail.TxDate       = oBatchHeader.TxDate.Value;
                                    oLedgerDetail.Amount       = oLedgerDetail.Qty * oLedgerDetail.AverageCost;
                                    oLedgerDetail.Notes        = string.Empty;
                                    oLedgerDetail.SerialNumber = string.Empty;
                                    oLedgerDetail.SHOP         = WorkplaceEx.GetWorkplaceCodeById(oBatchHeader.WorkplaceId);
                                    oLedgerDetail.OPERATOR     = StaffEx.GetStaffNumberById(oBatchHeader.StaffId);

                                    // Product Info
                                    var oItem = ctx.Product.Find(oSDetail.ProductId);
                                    if (oItem != null)
                                    {
                                        oLedgerDetail.BasicPrice  = oItem.RetailPrice.Value;
                                        oLedgerDetail.UnitAmount  = ProductCurrentSummaryEx.GetAverageCode(oItem.ProductId);
                                        oLedgerDetail.Discount    = oItem.NormalDiscount;
                                        oLedgerDetail.Amount      = oLedgerDetail.UnitAmount * oLedgerDetail.Qty;
                                        oLedgerDetail.AverageCost = ProductCurrentSummaryEx.GetAverageCode(oItem.ProductId);

                                        var priceTypeId = ProductPriceTypeEx.GetIdByPriceType(ProductHelper.Prices.VPRC.ToString());
                                        //sql = "ProductId = '" + oSDetail.ProductId.ToString() + "' AND PriceTypeId = '" + priceTypeId.ToString() + "'";

                                        var oPrice = ctx.ProductPrice.Where(x => x.ProductId == oSDetail.ProductId && x.PriceTypeId == priceTypeId).FirstOrDefault();
                                        if (oPrice != null)
                                        {
                                            oLedgerDetail.VendorRef = oPrice.CurrencyCode;
                                        }
                                    }
                                    ctx.InvtLedgerDetails.Add(oLedgerDetail);

                                    var oLedgerHeader2 = ctx.InvtLedgerHeader.Find(ledgerHeaderId);
                                    if (oLedgerHeader2 != null)
                                    {
                                        oLedgerHeader2.TotalAmount += oLedgerDetail.Amount;
                                    }

                                    ctx.SaveChanges();
                                }
                                #endregion

                                oBatchHeader.PostedBy   = ConfigHelper.CurrentUserId;
                                oBatchHeader.PostedOn   = DateTime.Now;
                                oBatchHeader.ModifiedBy = ConfigHelper.CurrentUserId;
                                oBatchHeader.ModifiedOn = DateTime.Now;
                                ctx.SaveChanges();

                                #region ClearBatchTransaction(oBatchHeader);
                                string query      = "HeaderId = '" + oBatchHeader.HeaderId.ToString() + "'";
                                var    detailList = ctx.InvtBatchADJ_Details.Where(x => x.HeaderId == oBatchHeader.HeaderId);
                                foreach (var detail in detailList)
                                {
                                    ctx.InvtBatchADJ_Details.Remove(detail);
                                }

                                ctx.InvtBatchADJ_Header.Remove(oBatchHeader);
                                ctx.SaveChanges();
                                #endregion
                            }
                        }
                        scope.Commit();
                    }
                    catch (Exception ex)
                    {
                        scope.Rollback();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void LoadData()
        {
            using (var ctx = new EF6.RT2020Entities())
            {
                var oItem = ctx.Product.Where(x => x.ProductId == this.ProductId).AsNoTracking().FirstOrDefault();
                if (oItem != null)
                {
                    cboClass1.Text = oItem.CLASS1;
                    cboClass2.Text = oItem.CLASS2;
                    cboClass3.Text = oItem.CLASS3;
                    cboClass4.Text = oItem.CLASS4;
                    cboClass5.Text = oItem.CLASS5;
                    cboClass6.Text = oItem.CLASS6;

                    txtProductName.Text    = oItem.ProductName;
                    txtProductNameChs.Text = oItem.ProductName_Chs;
                    txtProductNameCht.Text = oItem.ProductName_Cht;
                    txtRemarks.Text        = oItem.Remarks;

                    txtWholesalesPrice.Text     = oItem.WholesalePrice.Value.ToString("n2");
                    txtOriginalRetailPrice.Text = oItem.OriginalRetailPrice.Value.ToString("n2");
                    txtCurrentRetailPrice.Text  = oItem.RetailPrice.Value.ToString("n2");
                    txtRetailDiscount.Text      = oItem.NormalDiscount.ToString("n2");
                    txtUnit.Text            = oItem.UOM;
                    cboNature.SelectedValue = oItem.NatureId.HasValue ? oItem.NatureId : Guid.Empty;

                    txtStatus_Counter.Text = "";
                    txtStatus_Office.Text  = "";
                    txtCreatedOn.Text      = DateTimeHelper.DateTimeToString(oItem.CreatedOn, false);
                    txtModifiedOn.Text     = DateTimeHelper.DateTimeToString(oItem.ModifiedOn, false);
                    txtModifiedBy.Text     = StaffEx.GetStaffNumberById(oItem.ModifiedBy);

                    #region LoadProductBasicPrice();
                    var priceTypeId = ProductPriceTypeEx.GetIdByPriceType(ProductHelper.Prices.BASPRC.ToString());
                    var oBPrice     = ctx.ProductPrice.Where(x => x.ProductId == this.ProductId && x.PriceTypeId == priceTypeId).AsNoTracking().FirstOrDefault();
                    if (oBPrice != null)
                    {
                        txtCurrentRetailCurrency.Text = oBPrice.CurrencyCode;
                        txtCurrentRetailPrice.Text    = oBPrice.Price.Value.ToString("n2");
                    }
                    #endregion

                    #region LoadProductOriginalPrice();
                    priceTypeId = ProductPriceTypeEx.GetIdByPriceType(ProductHelper.Prices.ORIPRC.ToString());
                    var oOPrice = ctx.ProductPrice.Where(x => x.ProductId == this.ProductId && x.PriceTypeId == priceTypeId).AsNoTracking().FirstOrDefault();
                    if (oOPrice != null)
                    {
                        txtOriginalRetailCurrency.Text = oOPrice.CurrencyCode;
                        txtOriginalRetailPrice.Text    = oOPrice.Price.Value.ToString("n2");
                    }
                    #endregion

                    #region LoadProductVendorPrice();
                    priceTypeId = ProductPriceTypeEx.GetIdByPriceType(ProductHelper.Prices.VPRC.ToString());
                    var oVPrice = ctx.ProductPrice.Where(x => x.ProductId == this.ProductId && x.PriceTypeId == priceTypeId).AsNoTracking().FirstOrDefault();
                    if (oVPrice != null)
                    {
                        cboVendorCurrency.Text = oVPrice.CurrencyCode;
                        txtVendorPrice.Text    = oVPrice.Price.Value.ToString("n2");
                    }
                    #endregion

                    #region LoadProductWholesalesPrice();
                    priceTypeId = ProductPriceTypeEx.GetIdByPriceType(ProductHelper.Prices.WHLPRC.ToString());
                    var oWPrice = ctx.ProductPrice.Where(x => x.ProductId == this.ProductId && x.PriceTypeId == priceTypeId).AsNoTracking().FirstOrDefault();
                    if (oWPrice != null)
                    {
                        txtWholesalesCurrency.Text = oWPrice.CurrencyCode;
                        txtWholesalesPrice.Text    = oWPrice.Price.Value.ToString("n2");
                    }
                    #endregion

                    txtCurrentRetailPrice.Text = oItem.RetailPrice.Value.ToString("n2");

                    #region LoadProductSupplement
                    var oProdSupp = ctx.ProductSupplement.Where(x => x.ProductId == this._ProductId).AsNoTracking().FirstOrDefault();
                    if (oProdSupp != null)
                    {
                        cboVendorCurrency.Text = oProdSupp.VendorCurrencyCode;
                        txtVendorPrice.Text    = oProdSupp.VendorPrice.Value.ToString("n2");
                        txtMemo.Text           = oProdSupp.ProductName_Memo;
                        txtPole.Text           = oProdSupp.ProductName_Pole;
                    }
                    #endregion

                    #region LoadProductRemarks
                    var oRemarks = ctx.ProductRemarks.Where(x => x.ProductId == _ProductId).AsNoTracking().FirstOrDefault();
                    if (oRemarks != null)
                    {
                        txtBin_X.Text = oRemarks.BinX;
                        txtBin_Y.Text = oRemarks.BinY;
                        txtBin_Z.Text = oRemarks.BinZ;

                        chkRetailItem.Checked     = oRemarks.DownloadToShop;
                        chkOffDisplayItem.Checked = oRemarks.OffDisplayItem;
                        chkCounterItem.Checked    = oRemarks.DownloadToCounter;

                        txtRemarks1.Text = oRemarks.REMARK1;
                        txtRemarks2.Text = oRemarks.REMARK2;
                        txtRemarks3.Text = oRemarks.REMARK3;
                        txtRemarks4.Text = oRemarks.REMARK4;
                        txtRemarks5.Text = oRemarks.REMARK5;
                        txtRemarks6.Text = oRemarks.REMARK6;
                    }
                    #endregion
                }
            }
        }
Exemplo n.º 4
0
        private void CreateLedgerDetails(string txnumber, Guid ledgerHeaderId, Guid stkHeaderId, string staff, string workplace)
        {
            int iCount = 1;

            using (var ctx = new EF6.RT2020Entities())
            {
                using (var scope = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        var stkDetailsList = ctx.StockTakeDetails.Where(x => x.HeaderId == stkHeaderId);
                        foreach (var stkDetail in stkDetailsList)
                        {
                            var oLedgerDetail = new EF6.InvtLedgerDetails();
                            oLedgerDetail.DetailsId          = Guid.NewGuid();
                            oLedgerDetail.HeaderId           = ledgerHeaderId;
                            oLedgerDetail.SubLedgerDetailsId = stkDetail.DetailsId;
                            oLedgerDetail.LineNumber         = iCount;
                            oLedgerDetail.ProductId          = stkDetail.ProductId.Value;
                            oLedgerDetail.Qty          = (stkDetail.Book1Qty + stkDetail.Book2Qty + stkDetail.Book3Qty + stkDetail.Book4Qty + stkDetail.Book5Qty + stkDetail.HHTQty) - stkDetail.CapturedQty;
                            oLedgerDetail.TxNumber     = txnumber;
                            oLedgerDetail.TxType       = EnumHelper.TxType.ADJ.ToString();
                            oLedgerDetail.TxDate       = DateTime.Now;
                            oLedgerDetail.Amount       = 0;
                            oLedgerDetail.UnitAmount   = 0;
                            oLedgerDetail.AverageCost  = stkDetail.AverageCost.Value;
                            oLedgerDetail.Notes        = string.Empty;
                            oLedgerDetail.SerialNumber = string.Empty;
                            oLedgerDetail.OPERATOR     = staff;
                            oLedgerDetail.SHOP         = workplace;

                            #region lookup & fill BasicPrice & VedorRef
                            var oItem = ctx.Product.Find(stkDetail.ProductId.Value);
                            if (oItem != null)
                            {
                                oLedgerDetail.BasicPrice = oItem.RetailPrice;

                                var priceTypeId = ProductPriceTypeEx.GetIdByPriceType(ProductHelper.Prices.VPRC.ToString());
                                var oPrice      = ctx.ProductPrice
                                                  .Where(x => x.ProductId == stkDetail.ProductId && x.PriceTypeId == priceTypeId)
                                                  .AsNoTracking()
                                                  .FirstOrDefault();
                                if (oPrice != null)
                                {
                                    oLedgerDetail.VendorRef = oPrice.CurrencyCode;
                                }
                            }
                            #endregion

                            ctx.InvtLedgerDetails.Add(oLedgerDetail);
                            ctx.SaveChanges();

                            iCount++;
                        }
                        scope.Commit();
                    }
                    catch (Exception ex)
                    {
                        scope.Rollback();
                    }
                }
            }
        }