コード例 #1
0
        public ResponseDto UpdateProducts(FicheDto ficheDto)
        {
            ResponseDto responseDto = new ResponseDto();

            if (ficheDto == null || ficheDto.ProductList == null || ficheDto.ProductList.Count == 0)
            {
                responseDto.IsSuccess = false;
                responseDto.Message   = Business.Stc.GetDicValue("xNoProduct", Session.RealPerson.LanguageId);
                return(responseDto);
            }

            FicheBo ficheBo = new FicheBo()
            {
                DebtPersonId   = ficheDto.DebtPersonId,
                CreditPersonId = ficheDto.CreditPersonId,
                CurrencyId     = ficheDto.CurrencyId,

                // We do not need other fields.

                Session = Session
            };

            ficheBo.ProductList = (from x in ficheDto.ProductList
                                   //where !x.IsDeleted
                                   select new FicheProductBo
            {
                Id = x.Id,
                ProductId = x.ProductId,
                Quantity = x.Quantity,
                UnitPrice = x.UnitPrice,
                DiscountRate = x.DiscountRate,
                DiscountTotal = x.DiscountTotal,
                VatRate = x.VatRate,

                Notes = x.Notes,
                IsDeleted = x.IsDeleted
            }).ToList();

            ResponseBo responseBo = ficheProductBusiness.UpdateProducts(ficheBo);

            responseDto = responseBo.ToResponseDto();
            return(responseDto);
        }
コード例 #2
0
        public ResponseBo Save(FicheBo ficheBo)
        {
            ResponseBo responseBo = new ResponseBo();

            try
            {
                using (SqlConnection conn = DbAccess.Connection.GetConn())
                {
                    ficheBo.RowDiscountTotal = 0;

                    if (ficheBo.FicheTypeId != Enums.FicheTypes.xDebtCredit)
                    {
                        ficheBo.GrandTotal = 0;
                        ficheBo.Total      = 0;
                    }

                    if (ficheBo.FicheTypeId == Enums.FicheTypes.xMoneyTransfer ||
                        ficheBo.FicheTypeId == Enums.FicheTypes.xPayment)
                    {
                        ficheBo.UnderDiscountTotal = 0;
                        ficheBo.ProductList        = null;
                        ficheBo.VatTotalList       = null;

                        ficheBo.GrandTotal = ficheBo.MoneyList.Sum(x => x.Total);
                        ficheBo.Total      = ficheBo.GrandTotal;
                    }
                    else if (ficheBo.FicheTypeId == Enums.FicheTypes.xDebtCredit)
                    {
                        ficheBo.UnderDiscountTotal = 0;
                        ficheBo.ProductList        = null;
                        ficheBo.VatTotalList       = null;
                        ficheBo.MoneyList          = null;

                        ficheBo.Total = ficheBo.GrandTotal;
                    }
                    else if (ficheBo.FicheTypeId == Enums.FicheTypes.xReceipt || ficheBo.FicheTypeId == Enums.FicheTypes.xInvoice)
                    {
                        ficheBo.VatTotalList = new List <FicheVatTotalBo>();
                        foreach (FicheProductBo item in ficheBo.ProductList.Where(f => !f.IsDeleted))
                        {
                            item.Quantity     = item.Quantity <= 0 ? 1 : Math.Round(item.Quantity, 4, MidpointRounding.AwayFromZero);
                            item.UnitPrice    = item.UnitPrice < 0 ? 0 : Math.Round(item.UnitPrice, 4, MidpointRounding.AwayFromZero);
                            item.DiscountRate = item.DiscountRate < 0 ? 0 : Math.Round(item.DiscountRate, 2, MidpointRounding.AwayFromZero);
                            item.VatRate      = item.VatRate < 0 ? 0 : Math.Round(item.VatRate, 2, MidpointRounding.AwayFromZero);

                            item.Total = item.Quantity * item.UnitPrice;

                            item.VatTotal = ficheBo.IncludingVat ?
                                            item.Total - item.Total / (1 + item.VatRate / 100) :
                                            Math.Round(item.Total / (decimal)100 * item.VatRate, 4, MidpointRounding.AwayFromZero);

                            item.DiscountTotal = Math.Round((item.Total + (ficheBo.IncludingVat ? 0 : item.VatTotal)) / 100 * item.DiscountRate, 2, MidpointRounding.AwayFromZero);
                            item.GrandTotal    = item.Total + (ficheBo.IncludingVat ? 0 : item.VatTotal) - item.DiscountTotal;

                            if (item.GrandTotal < 0)
                            {
                                responseBo.IsSuccess = false;
                                responseBo.Message   = "Satır genel toplamı 0'dan küçük olamaz.";
                                return(responseBo);
                            }

                            ficheBo.RowDiscountTotal += item.DiscountTotal;
                            ficheBo.Total            += item.Total;
                            ficheBo.GrandTotal       += item.GrandTotal;

                            // Calculating vat totals.
                            if (item.VatRate > 0 && item.VatTotal > 0) // we do not want to see 0 value :)
                            {
                                if (ficheBo.VatTotalList.Count(v => v.VatRate == item.VatRate) == 0)
                                {
                                    ficheBo.VatTotalList.Add(new FicheVatTotalBo()
                                    {
                                        VatRate  = item.VatRate,
                                        VatTotal = 0
                                    });
                                }
                                ficheBo.VatTotalList.Find(v => v.VatRate == item.VatRate).VatTotal += item.VatTotal;
                            }
                        }


                        ficheBo.UnderDiscountTotal = Math.Round(ficheBo.GrandTotal / 100 * ficheBo.UnderDiscountRate, 2, MidpointRounding.AwayFromZero);

                        ficheBo.GrandTotal -= ficheBo.UnderDiscountTotal;
                    }

                    if (ficheBo.GrandTotal < 0)
                    {
                        responseBo.IsSuccess = false;
                        responseBo.Message   = "Genel toplam 0'dan küçük olamaz.";
                        return(responseBo);
                    }

                    if ((ficheBo.FicheTypeId == Enums.FicheTypes.xMoneyTransfer ||
                         ficheBo.FicheTypeId == Enums.FicheTypes.xPayment ||
                         ficheBo.FicheTypeId == Enums.FicheTypes.xDebtCredit) &&
                        ficheBo.GrandTotal == 0)
                    {
                        responseBo.IsSuccess = false;
                        responseBo.Message   = "Genel toplam 0'dan büyük olmalı.";
                        return(responseBo);
                    }

                    var p = new DynamicParameters();
                    p.Add("@Message", dbType: DbType.String, direction: ParameterDirection.Output, size: 255);
                    p.Add("@IsSuccess", dbType: DbType.Boolean, direction: ParameterDirection.Output);
                    p.Add("@NotifyPersonListJson", dbType: DbType.String, direction: ParameterDirection.Output, size: 1000);

                    p.Add("@FicheId", ficheBo.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@DebtPersonId", ficheBo.DebtPersonId, DbType.Int64, ParameterDirection.Input);
                    p.Add("@CreditPersonId", ficheBo.CreditPersonId, DbType.Int64, ParameterDirection.Input);

                    p.Add("@FicheTypeId", ficheBo.FicheTypeId, DbType.Int32, ParameterDirection.Input);
                    p.Add("@FicheContentId", ficheBo.FicheContentId, DbType.Int32, ParameterDirection.Input);
                    p.Add("@FicheContentGroupId", ficheBo.FicheContentGroupId, DbType.Int32, ParameterDirection.Input);

                    p.Add("@CurrencyId", ficheBo.CurrencyId, DbType.Int32, ParameterDirection.Input);
                    p.Add("@PrintedCode", ficheBo.PrintedCode, DbType.String, ParameterDirection.Input, 50);
                    p.Add("@IncludingVat", ficheBo.IncludingVat, DbType.Boolean, ParameterDirection.Input);

                    p.Add("@IssueDate", ficheBo.IssueDate, DbType.Date, ParameterDirection.Input);
                    p.Add("@DueDate", ficheBo.DueDate, DbType.Date, ParameterDirection.Input);

                    p.Add("@UnderDiscountRate", ficheBo.UnderDiscountRate, DbType.Decimal, ParameterDirection.Input);
                    p.Add("@UnderDiscountTotal", ficheBo.UnderDiscountTotal, DbType.Decimal, ParameterDirection.Input);

                    p.Add("@GrandTotal", ficheBo.GrandTotal, DbType.Decimal, ParameterDirection.Input);
                    p.Add("@RowDiscountTotal", ficheBo.RowDiscountTotal, DbType.Decimal, ParameterDirection.Input);
                    p.Add("@Total", ficheBo.Total, DbType.Decimal, ParameterDirection.Input);

                    p.Add("@Notes", ficheBo.Notes, DbType.String, ParameterDirection.Input, 255);

                    p.Add("@AcceptorPersonId", ficheBo.AcceptorPersonId, DbType.Int64, ParameterDirection.Input);

                    p.Add("@IsUncompleted", ficheBo.IsUncompleted, DbType.Boolean, ParameterDirection.Input);

                    p.Add("@OrderId", ficheBo.OrderId, DbType.Int64, ParameterDirection.Input);

                    p.Add("@MyPersonId", ficheBo.Session.MyPerson.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@OperatorRealId", ficheBo.Session.RealPerson.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@LanguageId", ficheBo.Session.RealPerson.LanguageId, DbType.Int32, ParameterDirection.Input);

                    List <long> PaymentTypeFicheRelationChildIdList = null;
                    if (ficheBo.RelationList != null)
                    {
                        if (ficheBo.RelationList.Count(x => x.FicheRelationTypeId == Enums.FicheRelationTypes.xPayment) > 0)
                        {
                            PaymentTypeFicheRelationChildIdList = (from y in ficheBo.RelationList
                                                                   where y.FicheRelationTypeId == Enums.FicheRelationTypes.xPayment
                                                                   select y.ChildFicheId).ToList();
                        }
                    }
                    p.Add("@PaymentTypeFicheRelationChildIdList", PaymentTypeFicheRelationChildIdList.ToStrSeparated(), DbType.String, ParameterDirection.Input, 4000);

                    DataTable dtMoney = new DataTable();
                    dtMoney.Columns.Add("Id", typeof(long));
                    dtMoney.Columns.Add("DebtPersonAccountId", typeof(long));
                    dtMoney.Columns.Add("CreditPersonAccountId", typeof(long));
                    dtMoney.Columns.Add("Total", typeof(decimal));
                    dtMoney.Columns.Add("DebtPersonAccountTypeId", typeof(int));
                    dtMoney.Columns.Add("CreditPersonAccountTypeId", typeof(int));
                    dtMoney.Columns.Add("Notes", typeof(string));
                    if (ficheBo.MoneyList != null && ficheBo.MoneyList.Count > 0)
                    {
                        foreach (FicheMoneyBo item in ficheBo.MoneyList)
                        {
                            DataRow dr = dtMoney.NewRow();
                            dr["Id"] = item.Id;
                            if (item.DebtPersonAccountId == null)
                            {
                                dr["DebtPersonAccountId"] = DBNull.Value;
                            }
                            else
                            {
                                dr["DebtPersonAccountId"] = item.DebtPersonAccountId;
                            }

                            if (item.CreditPersonAccountId == null)
                            {
                                dr["CreditPersonAccountId"] = DBNull.Value;
                            }
                            else
                            {
                                dr["CreditPersonAccountId"] = item.CreditPersonAccountId;
                            }

                            dr["Total"] = item.Total;
                            dr["DebtPersonAccountTypeId"]   = item.DebtPersonAccountTypeId;
                            dr["CreditPersonAccountTypeId"] = item.CreditPersonAccountTypeId;
                            dr["Notes"] = item.Notes;

                            dtMoney.Rows.Add(dr);
                        }

                        p.Add("@tvpFicheMoneyList", dtMoney.AsTableValuedParameter("tvpFicheMoney"));
                    }


                    DataTable dtProduct = new DataTable();
                    dtProduct.Columns.Add("Id", typeof(long));
                    dtProduct.Columns.Add("ProductId", typeof(long));
                    dtProduct.Columns.Add("Quantity", typeof(decimal));
                    dtProduct.Columns.Add("UnitPrice", typeof(decimal));
                    dtProduct.Columns.Add("DiscountRate", typeof(decimal));
                    dtProduct.Columns.Add("DiscountTotal", typeof(decimal));
                    dtProduct.Columns.Add("VatRate", typeof(decimal));
                    dtProduct.Columns.Add("Notes", typeof(string));
                    dtProduct.Columns.Add("Total", typeof(decimal));
                    dtProduct.Columns.Add("VatTotal", typeof(decimal));
                    dtProduct.Columns.Add("GrandTotal", typeof(decimal));
                    dtProduct.Columns.Add("IsDeleted", typeof(bool));
                    if (ficheBo.ProductList != null && ficheBo.ProductList.Count > 0)
                    {
                        foreach (FicheProductBo item in ficheBo.ProductList)
                        {
                            DataRow dr = dtProduct.NewRow();
                            dr["Id"]            = item.Id;
                            dr["ProductId"]     = item.ProductId;
                            dr["Quantity"]      = item.Quantity;
                            dr["UnitPrice"]     = item.UnitPrice;
                            dr["DiscountRate"]  = item.DiscountRate;
                            dr["DiscountTotal"] = item.DiscountTotal;
                            dr["VatRate"]       = item.VatRate;
                            dr["Notes"]         = item.Notes;
                            dr["Total"]         = item.Total;
                            dr["VatTotal"]      = item.VatTotal;
                            dr["GrandTotal"]    = item.GrandTotal;
                            dr["IsDeleted"]     = item.IsDeleted;

                            dtProduct.Rows.Add(dr);
                        }

                        p.Add("@tvpFicheProductList", dtProduct.AsTableValuedParameter("tvpFicheProduct"));
                    }

                    DataTable dtVatTotal = new DataTable();
                    dtVatTotal.Columns.Add("VatRate", typeof(decimal));
                    dtVatTotal.Columns.Add("VatTotal", typeof(decimal));
                    if (ficheBo.VatTotalList != null && ficheBo.VatTotalList.Count > 0)
                    {
                        foreach (FicheVatTotalBo item in ficheBo.VatTotalList)
                        {
                            DataRow dr = dtVatTotal.NewRow();
                            dr["VatRate"]  = item.VatRate;
                            dr["VatTotal"] = item.VatTotal;

                            dtVatTotal.Rows.Add(dr);
                        }

                        p.Add("@tvpFicheVatTotal", dtVatTotal.AsTableValuedParameter("tvpFicheVatTotal"));
                    }

                    conn.Execute("spFicheSave", p, commandType: CommandType.StoredProcedure);
                    responseBo.Message   = p.Get <string>("@Message");
                    responseBo.IsSuccess = p.Get <bool>("@IsSuccess");

                    string NotifyPersonListJson = p.Get <string>("@NotifyPersonListJson");
                    if (NotifyPersonListJson.IsNotNull())
                    {
                        responseBo.PersonNotifyList = JsonConvert.DeserializeObject <List <PersonNotifyListBo> >(NotifyPersonListJson);
                    }

                    dtMoney.Dispose();
                    dtProduct.Dispose();
                    dtVatTotal.Dispose();
                }
            }
            catch (Exception ex)
            {
                responseBo = base.SaveExLog(ex, this.GetType(), MethodBase.GetCurrentMethod().Name, ficheBo);
            }

            return(responseBo);
        }
コード例 #3
0
        public ResponseDto Save(FicheDto ficheDto)
        {
            ResponseDto responseDto = new ResponseDto();

            if (ficheDto == null)
            {
                responseDto.IsSuccess = false;
                responseDto.Message   = Business.Stc.GetDicValue("xInvalidData", Session.RealPerson.LanguageId);
                return(responseDto);
            }

            if ((ficheDto.FicheTypeId == Enums.FicheTypes.xReceipt || ficheDto.FicheTypeId == Enums.FicheTypes.xInvoice) &&
                (ficheDto.ProductList == null || ficheDto.ProductList.Count() == 0))
            {
                responseDto.IsSuccess = false;
                responseDto.Message   = Business.Stc.GetDicValue("xNoProduct", Session.RealPerson.LanguageId);
                return(responseDto);
            }

            if (ficheDto.IssueDateNumber < 0 || (ficheDto.DueDateNumber != null && ficheDto.DueDateNumber.Value < 0))
            {
                responseDto.IsSuccess = false;
                responseDto.Message   = Business.Stc.GetDicValue("xInvalidDate", Session.RealPerson.LanguageId);
                return(responseDto);
            }

            FicheBo ficheBo = new FicheBo()
            {
                Id             = ficheDto.Id,
                DebtPersonId   = ficheDto.DebtPersonId,
                CreditPersonId = ficheDto.CreditPersonId,

                FicheTypeId = ficheDto.FicheTypeId,
                CurrencyId  = ficheDto.CurrencyId,
                // FicheStatId sp will decide it.
                IncludingVat = ficheDto.IncludingVat,

                PrintedCode = ficheDto.PrintedCode,
                IssueDate   = ficheDto.IssueDateNumber.ToDateTimeFromNumber(),
                DueDate     = ficheDto.DueDateNumber.ToDateTimeFromNumberNull(),

                UnderDiscountRate  = ficheDto.UnderDiscountRate,
                UnderDiscountTotal = ficheDto.UnderDiscountTotal,

                FicheContentId      = ficheDto.FicheContentId,
                FicheContentGroupId = ficheDto.FicheContentGroupId,

                Notes = ficheDto.Notes,

                AcceptorPersonId = ficheDto.AcceptorPersonId,

                OrderId = ficheDto.OrderId,

                IsUncompleted = ficheDto.IsUncompleted,

                GrandTotal = ficheDto.GrandTotal, // Will not be calculated in case of fiche type is 'xDebtCredit'.

                Session = Session

                          // Business will calculate below values:
                          // GrandTotal
                          // Total
                          // RowDiscountTotal
                          // UnderDiscountTotal
                          // VatTotal
            };

            if (ficheDto.MoneyList != null && ficheDto.MoneyList.Count > 0)
            {
                ficheBo.MoneyList = (from x in ficheDto.MoneyList
                                     select new FicheMoneyBo
                {
                    Id = x.Id,
                    DebtPersonAccountId = x.DebtPersonAccountId,
                    CreditPersonAccountId = x.CreditPersonAccountId,
                    Total = x.Total,
                    DebtPersonAccountTypeId = x.DebtPersonAccountTypeId,
                    CreditPersonAccountTypeId = x.CreditPersonAccountTypeId,
                    Notes = x.Notes
                }).ToList();
            }

            if (ficheDto.ProductList != null && ficheDto.ProductList.Count > 0)
            {
                // ficheDto.ProductList.Count()
                foreach (var line in ficheDto.ProductList.Where(w => !w.IsDeleted).GroupBy(info => info.ProductId)
                         .Select(group => new
                {
                    Metric = group.Key,
                    Count = group.Count()
                })
                         .OrderBy(x => x.Metric))
                {
                    if (line.Count > 1)
                    {
                        responseDto.IsSuccess = false;
                        responseDto.Message   = "Birden fazla aynı ürün var hacı.";
                        return(responseDto);
                    }
                }


                ficheBo.ProductList = (from x in ficheDto.ProductList
                                       //where !x.IsDeleted
                                       select new FicheProductBo
                {
                    Id = x.Id,
                    ProductId = x.ProductId,
                    Quantity = x.Quantity,
                    UnitPrice = x.UnitPrice,
                    DiscountRate = x.DiscountRate,
                    DiscountTotal = x.DiscountTotal,
                    VatRate = x.VatRate,

                    Notes = x.Notes,
                    IsDeleted = x.IsDeleted

                                // Business will calculate below values:
                                // Total
                                // Discount total
                                // VatTotal
                                // GrandTotal
                }).ToList();
            }

            if (ficheDto.RelationList != null && ficheDto.RelationList.Count > 0)
            {
                ficheBo.RelationList = (from x in ficheDto.RelationList
                                        select new FicheRelationSaveBo
                {
                    ChildFicheId = x.ChildFicheId,
                    FicheRelationTypeId = x.FicheRelationTypeId
                }).ToList();
            }


            // No need to pass the 'VatTotalList'. Because business will calculate it.

            ResponseBo responseBo = ficheBusiness.Save(ficheBo);

            base.SendNotifyWsToList(responseBo.PersonNotifyList);

            responseDto = responseBo.ToResponseDto();
            return(responseDto);
        }
コード例 #4
0
        public ResponseBo UpdateProducts(FicheBo ficheBo)
        {
            ResponseBo responseBo = new ResponseBo();

            try
            {
                using (SqlConnection conn = DbAccess.Connection.GetConn())
                {
                    foreach (FicheProductBo item in ficheBo.ProductList.Where(f => !f.IsDeleted))
                    {
                        item.UnitPrice = item.UnitPrice < 0 ? 0 : Math.Round(item.UnitPrice, 4, MidpointRounding.AwayFromZero);
                        item.VatRate   = item.VatRate < 0 ? 0 : Math.Round(item.VatRate, 2, MidpointRounding.AwayFromZero);
                    }

                    var p = new DynamicParameters();
                    p.Add("@Message", dbType: DbType.String, direction: ParameterDirection.Output, size: 255);
                    p.Add("@IsSuccess", dbType: DbType.Boolean, direction: ParameterDirection.Output);

                    p.Add("@CurrencyId", ficheBo.CurrencyId, DbType.Int32, ParameterDirection.Input);
                    p.Add("@IsDebtor", ficheBo.DebtPersonId == ficheBo.Session.MyPerson.Id, DbType.Boolean, ParameterDirection.Input);


                    p.Add("@PersonId", ficheBo.Session.MyPerson.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@OperatorRealId", ficheBo.Session.RealPerson.Id, DbType.Int64, ParameterDirection.Input);
                    p.Add("@LanguageId", ficheBo.Session.RealPerson.LanguageId, DbType.Int32, ParameterDirection.Input);


                    DataTable dtProduct = new DataTable();
                    dtProduct.Columns.Add("Id", typeof(long));
                    dtProduct.Columns.Add("ProductId", typeof(long));
                    dtProduct.Columns.Add("Quantity", typeof(decimal));
                    dtProduct.Columns.Add("UnitPrice", typeof(decimal));
                    dtProduct.Columns.Add("DiscountRate", typeof(decimal));
                    dtProduct.Columns.Add("DiscountTotal", typeof(decimal));
                    dtProduct.Columns.Add("VatRate", typeof(decimal));
                    dtProduct.Columns.Add("Notes", typeof(string));
                    dtProduct.Columns.Add("Total", typeof(decimal));
                    dtProduct.Columns.Add("VatTotal", typeof(decimal));
                    dtProduct.Columns.Add("GrandTotal", typeof(decimal));
                    dtProduct.Columns.Add("IsDeleted", typeof(bool));
                    foreach (FicheProductBo item in ficheBo.ProductList)
                    {
                        DataRow dr = dtProduct.NewRow();
                        dr["Id"]            = item.Id;
                        dr["ProductId"]     = item.ProductId;
                        dr["Quantity"]      = item.Quantity;
                        dr["UnitPrice"]     = item.UnitPrice;
                        dr["DiscountRate"]  = item.DiscountRate;
                        dr["DiscountTotal"] = item.DiscountTotal;
                        dr["VatRate"]       = item.VatRate;
                        dr["Notes"]         = item.Notes;
                        dr["Total"]         = item.Total;
                        dr["VatTotal"]      = item.VatTotal;
                        dr["GrandTotal"]    = item.GrandTotal;
                        dr["IsDeleted"]     = item.IsDeleted;

                        dtProduct.Rows.Add(dr);
                    }
                    p.Add("@tvpFicheProductList", dtProduct.AsTableValuedParameter("tvpFicheProduct"));

                    conn.Execute("spFicheUpdateProducts", p, commandType: CommandType.StoredProcedure);
                    responseBo.Message   = p.Get <string>("@Message");
                    responseBo.IsSuccess = p.Get <bool>("@IsSuccess");

                    dtProduct.Dispose();
                }
            }
            catch (Exception ex)
            {
                responseBo = base.SaveExLog(ex, this.GetType(), MethodBase.GetCurrentMethod().Name, ficheBo);
            }

            return(responseBo);
        }