Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="customerLedger"></param>
        public void Add(CustomerLedger customerLedger)
        {
            try
            {
                var identity = (LoginIdentity)Thread.CurrentPrincipal.Identity;
                if (string.IsNullOrEmpty(customerLedger.CompanyId))
                {
                    customerLedger.CompanyId = identity.CompanyId;
                }
                if (string.IsNullOrEmpty(customerLedger.BranchId))
                {
                    customerLedger.BranchId = identity.BranchId;
                }
                customerLedger.Id       = GenerateAutoId(customerLedger.CompanyId, customerLedger.BranchId, "CustomerLedger");
                customerLedger.Sequence = GetAutoSequence("CustomerLedger");
                Customer customer = _customerRepository.GetOne(x => x.Id == customerLedger.CustomerId);
                customerLedger.TrackingNo           = GenerateTrackingNo(customerLedger.CompanyId, customerLedger.BranchId, "CustomerLedger");
                customerLedger.MoneyReceiveNo       = GenerateMoneyReceiveNo(customerLedger.CompanyId, customerLedger.BranchId, "CustomerLedger");
                customerLedger.TransactionDate      = DateTime.Now;
                customerLedger.CustomerMobileNumber = customer.Phone1;

                customerLedger.Active = true;
                customerLedger.SynchronizationType = SynchronizationType.Server.ToString();
                customerLedger.AddedBy             = identity.Name;
                customerLedger.AddedDate           = DateTime.Now;
                customerLedger.AddedFromIp         = identity.IpAddress;
                _customerLedgerRepository.Add(customerLedger);
                _unitOfWork.SaveChanges();
                _rawSqlService.UpdateCustomerLedgerRunningBalance(customer.Id);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
        public void Add(Customer customer)
        {
            var flag = false;

            try
            {
                Check(customer);
                _unitOfWork.BeginTransaction();
                flag = true;
                var identity = (LoginIdentity)Thread.CurrentPrincipal.Identity;
                #region Customer
                if (string.IsNullOrEmpty(customer.CompanyId))
                {
                    customer.CompanyId = identity.CompanyId;
                }
                if (string.IsNullOrEmpty(customer.BranchId))
                {
                    customer.BranchId = identity.BranchId;
                }
                customer.Id                  = GenerateAutoId(customer.CompanyId, customer.BranchId, "Customer");
                customer.Sequence            = GetAutoSequence("Customer");
                customer.SynchronizationType = SynchronizationType.Server.ToString();
                customer.AddedBy             = identity.Name;
                customer.AddedDate           = DateTime.Now;
                customer.AddedFromIp         = identity.IpAddress;
                _customerRepository.Add(customer);
                #endregion

                #region CustomerLedger
                if (customer.AccountsPayable > 0 || customer.AccountsReceivable > 0)
                {
                    CustomerLedger customerLedger = new CustomerLedger
                    {
                        Id                   = GenerateAutoId(customer.CompanyId, customer.BranchId, "CustomerLedger"),
                        Sequence             = GetAutoSequence("CustomerLedger"),
                        TrackingNo           = GenerateTrackingNo(customer.CompanyId, customer.BranchId, "CustomerLedger"),
                        MoneyReceiveNo       = GenerateMoneyReceiveNo(customer.CompanyId, customer.BranchId, "CustomerLedger"),
                        TransactionDate      = DateTime.Now,
                        CustomerId           = customer.Id,
                        CustomerMobileNumber = customer.Phone1
                    };
                    customerLedger.TransactionType = TransactionType.OpeningBalance.ToString();
                    customerLedger.TransactionDate = DateTime.Now;
                    if (customer.AccountsPayable > 0)
                    {
                        customerLedger.Particulars  = "Accounts Payable";
                        customerLedger.DebitAmount  = customer.AccountsPayable;
                        customerLedger.CreditAmount = 0;
                    }
                    else if (customer.AccountsReceivable > 0)
                    {
                        customerLedger.Particulars  = "Accounts Receivable";
                        customerLedger.DebitAmount  = 0;
                        customerLedger.CreditAmount = customer.AccountsReceivable;
                    }
                    customerLedger.Active = true;
                    customerLedger.SynchronizationType = SynchronizationType.Server.ToString();
                    customerLedger.AddedBy             = identity.Name;
                    customerLedger.AddedDate           = DateTime.Now;
                    customerLedger.AddedFromIp         = identity.IpAddress;
                    _customerLedgerRepository.Add(customerLedger);
                }

                #endregion
                _unitOfWork.SaveChanges();
                flag = false;
                _unitOfWork.Commit();
                _rawSqlService.UpdateCustomerLedgerRunningBalance(customer.Id);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (flag)
                {
                    _unitOfWork.Rollback();
                }
            }
        }
Пример #3
0
        public void Add(SaleReturn saleReturn, string type)
        {
            var flag = false;

            try
            {
                _unitOfWork.BeginTransaction();
                flag = true;
                #region saleReturn
                decimal totalQty = 0m;
                decimal totalAmt = 0m;
                var     identity = (LoginIdentity)Thread.CurrentPrincipal.Identity;
                saleReturn.Id                  = GenerateAutoId(identity.CompanyId, identity.BranchId, "SaleReturn");
                saleReturn.Sequence            = GetAutoSequence("SaleReturn");
                saleReturn.Active              = true;
                saleReturn.SynchronizationType = SynchronizationType.Server.ToString();
                saleReturn.CompanyId           = identity.CompanyId;
                saleReturn.BranchId            = identity.BranchId;
                saleReturn.AddedBy             = identity.Name;
                saleReturn.AddedDate           = DateTime.Now;
                saleReturn.AddedFromIp         = identity.IpAddress;
                #endregion

                #region saleReturn Items
                var detailId = Convert.ToInt32(GenerateAutoId(identity.CompanyId, identity.BranchId, "SaleReturnDetail"));
                if (saleReturn.SaleReturnDetails != null)
                {
                    var sqnc = GetAutoSequence("SaleReturnDetail");
                    foreach (var saleReturnDetail in saleReturn.SaleReturnDetails)
                    {
                        var productDb = _productRepository.GetOne(x => x.Id == saleReturnDetail.ProductId);
                        totalQty                                    += saleReturnDetail.ReturnQuantity;
                        totalAmt                                    += saleReturnDetail.ReturnAmount;
                        saleReturnDetail.Id                          = detailId.ToString();
                        saleReturnDetail.Sequence                    = sqnc;
                        saleReturnDetail.SaleReturnId                = saleReturn.Id;
                        saleReturnDetail.ProductCode                 = productDb.Code;
                        saleReturnDetail.ProductName                 = productDb.Name;
                        saleReturnDetail.UOMId                       = productDb.UOMId;
                        saleReturnDetail.GradeId                     = productDb.GradeId;
                        saleReturnDetail.SizeId                      = productDb.SizeId;
                        saleReturnDetail.ColorId                     = productDb.ColorId;
                        saleReturnDetail.SupplierId                  = productDb.SupplierId;
                        saleReturnDetail.ProductCategoryId           = productDb.ProductCategoryId;
                        saleReturnDetail.ProductSubCategoryId        = productDb.ProductSubCategoryId;
                        saleReturnDetail.ProductSubsidiaryCategoryId = productDb.ProductSubsidiaryCategoryId;

                        SaleDetail saleDetail       = _saleDetailRepository.GetOne(r => r.Id == saleReturnDetail.SaleDetailId);
                        decimal    alreadyReturnQty = GetSumOfAlreadyReturnQty(saleReturnDetail.SaleId, saleReturnDetail.ProductId);
                        saleReturnDetail.RemainingQuantity = saleReturnDetail.SoldQuantity - (alreadyReturnQty + saleReturnDetail.ReturnQuantity);
                        saleDetail.IsReturned = saleDetail.Quantity == alreadyReturnQty + saleReturnDetail.ReturnQuantity;
                        if (type == "Return")
                        {
                            saleReturnDetail.IsDamage = true;
                        }
                        saleReturnDetail.IsReturned = saleDetail.IsReturned;

                        saleReturnDetail.SalesReturnDate      = saleReturn.SalesReturnDate;
                        saleReturnDetail.SaleReturnDetailDate = DateTime.Now;
                        saleReturnDetail.CompanyId            = identity.CompanyId;
                        saleReturnDetail.BranchId             = identity.BranchId;
                        saleReturnDetail.Active = true;
                        saleReturnDetail.SynchronizationType = SynchronizationType.Server.ToString();
                        saleReturnDetail.AddedBy             = identity.Name;
                        saleReturnDetail.AddedDate           = DateTime.Now;
                        saleReturnDetail.AddedFromIp         = identity.IpAddress;
                        _saleReturnDetailRepository.Add(saleReturnDetail);
                        _saleDetailRepository.Update(saleDetail);
                        detailId++;
                        sqnc++;
                    }
                }
                #endregion

                #region CustomerLedger
                saleReturn.TotalAmount = totalAmt;
                Customer customer = _customerRepository.GetOne(x => x.Id == saleReturn.CustomerId);
                //if (saleReturn.CustomerId != null)
                //{
                //    CustomerLedger customerLedger = new CustomerLedger
                //    {
                //        Id = GenerateAutoId(identity.CompanyId, identity.BranchId, "CustomerLedger"),
                //        Sequence = GetAutoSequence("CustomerLedger"),
                //        TrackingNo = GenerateTrackingNo(identity.CompanyId, identity.BranchId, "CustomerLedger"),
                //        SaleId = saleReturn.SaleId,
                //        CustomerId = customer.Id,
                //        CustomerMobileNumber = customer.Phone1,
                //        TransactionType = TransactionType.Sales.ToString(),
                //        Particulars = TransactionType.Sales.ToString(),
                //        TransactionDate = DateTime.Now,
                //        DebitAmount = saleReturn.TotalAmount,
                //        CreditAmount = 0,
                //        RunningBalance=0,
                //        CompanyId = identity.CompanyId,
                //        BranchId = identity.BranchId,
                //        Active = true,
                //        SynchronizationType = SynchronizationType.Server.ToString(),
                //        AddedBy = identity.Name,
                //        AddedDate = DateTime.Now,
                //        AddedFromIp = identity.IpAddress
                //    };
                //    _customerLedgerRepository.Add(customerLedger);
                //}
                #endregion
                saleReturn.TotalQuantity = totalQty;
                saleReturn.TotalAmount   = totalAmt;
                _saleReturnRepository.Add(saleReturn);

                _unitOfWork.SaveChanges();
                ChangeSaleStatus(saleReturn.SaleId);
                ChangeSaleReturnStatus(saleReturn.Id, type);
                flag = false;
                _unitOfWork.Commit();
                _rawSqlService.UpdateCustomerLedgerRunningBalance(customer?.Id);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (flag)
                {
                    _unitOfWork.Rollback();
                }
            }
        }