/// <summary>
 /// Genrate return bill number. -An
 /// </summary>
 /// <param name="returnBillNumber">pass pos bill number</param>
 /// <returns></returns>
 private string GetReturnBillNumber(string billNumber)
 {
     try
     {
         CompanyConfiguration companyConfiguration = _iCompanyRepository.GetCompanyConfigurationByCompanyId(MerchantContext.CompanyDetails.Id);
         if (companyConfiguration != null && MerchantContext.UserDetails.BranchId != null)
         {
             POSBill posBill = _iReturnBillRepository.GetPOSBillByBillNumber(billNumber, Convert.ToInt32(MerchantContext.UserDetails.BranchId));
             if (posBill != null)
             {
                 List <POSReturnBill> listOfPOSReturnBill = _iReturnBillRepository.GetListOfPOSRetunBill();
                 if (listOfPOSReturnBill.Any())
                 {
                     //genrate return bill numnber.
                     string newReturnNumber = ((billNumber) + (listOfPOSReturnBill.Count() + 1).ToString());
                     return(companyConfiguration.ReturnInvoiceNo + newReturnNumber);
                 }
                 else
                 {
                     return(companyConfiguration.ReturnInvoiceNo + "" + billNumber + "" + 1);
                 }
             }
         }
         return(string.Empty);
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
        public POSBill InsertPosBillData(POSBill posBill)
        {
            var jsonString  = JsonConvert.SerializeObject(posBill);
            var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
            var response    = httpClient.PostAsync("api/posprocess/insertposbilldata", httpContent);

            if (response.IsSuccessStatusCode)
            {
                return(response.Content.ReadAsAsync <POSBill>().Result);
            }
            return(null);
        }
Example #3
0
 public IHttpActionResult InsertPOSBillData(POSBill posBill)
 {
     try
     {
         var posBillData = _iPOSProcessRepository.InsertPOSBillData(posBill);
         return(Ok(posBillData));
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #4
0
 public POSBill InsertPOSBillData(POSBill posBill)
 {
     try
     {
         posBill.CreatedDateTime = DateTime.UtcNow;
         _posBillContext.Add(posBill);
         _posBillContext.SaveChanges();
         return(posBill);
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
 public IHttpActionResult GetReturnBillListByBillNumber(string billNumber)
 {
     try
     {
         if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
             List <POSReturnBillListAC> listOfPOSReturnBillListAC = new List <POSReturnBillListAC>();
             if (MerchantContext.UserDetails.BranchId != null)
             {
                 POSBill posBill = _iReturnBillRepository.GetPOSBillByBillNumber(billNumber, Convert.ToInt32(MerchantContext.UserDetails.BranchId));
                 if (posBill != null)
                 {
                     List <POSReturnBill> listOfPOSReturnBill = _iReturnBillRepository.GetListOfPOSReturnBillByPOSBillId(posBill.Id);
                     if (listOfPOSReturnBill.Any())
                     {
                         foreach (var posReturnBill in listOfPOSReturnBill)
                         {
                             POSReturnBillListAC posReturnBillAC = new POSReturnBillListAC();
                             posReturnBillAC.Cash                  = posReturnBill.ReturnedCash;
                             posReturnBillAC.IsProcessed           = posReturnBill.IsProcessed;
                             posReturnBillAC.IssueAt               = posReturnBill.BranchDetail.Name;
                             posReturnBillAC.ProcessAt             = posReturnBill.ProcessingBranch.Name;
                             posReturnBillAC.ProcessingDate        = posReturnBill.ProcessingDate;
                             posReturnBillAC.Processor             = posReturnBill.ProcesessorUser.UserName;
                             posReturnBillAC.ReturnBillNumber      = posReturnBill.ReturnedBillNo;
                             posReturnBillAC.ReturnBy              = posReturnBill.UserDetail.UserName;
                             posReturnBillAC.ReturningDate         = posReturnBill.ReturningDate;
                             posReturnBillAC.IsDeleted             = posReturnBill.IsDeleted;
                             posReturnBillAC.SubstituteItemsAmount = posReturnBill.SubstituteItemsAmount;
                             listOfPOSReturnBillListAC.Add(posReturnBillAC);
                         }
                     }
                 }
             }
             return(Ok(listOfPOSReturnBillListAC));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
 public IHttpActionResult BillDetailByBillNumberByBranch(string billNumber, int branchId)
 {
     try
     {
         if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
             POSBill posBill = _iReturnBillRepository.GetPOSBillByBillNumber(billNumber, branchId);
             return(GetReturnBill(posBill));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
        /// <summary>
        /// Used to fetch ReturnBill
        /// </summary>
        /// <param name="posBill"></param>
        /// <returns></returns>
        private IHttpActionResult GetReturnBill(POSBill posBill)
        {
            ReturnBillDetailAc returnBillDetailAC;

            if (posBill != null)
            {
                CompanyConfiguration companyConfiguration = _iCompanyRepository.GetCompanyConfigurationByCompanyId(MerchantContext.CompanyDetails.Id);
                if (companyConfiguration?.ValidNumberOfDaysForReturnItem != null)
                {
                    DateTime allowDate = posBill.BillDate.AddDays(Convert.ToInt32(companyConfiguration.ValidNumberOfDaysForReturnItem));
                    if (DateTime.UtcNow <= allowDate)
                    {
                        returnBillDetailAC = GetReturnBillDetailAC(posBill);
                        return(Ok(new { isResult = returnBillDetailAC }));
                    }
                    else
                    {
                        return(Ok(new { isResult = companyConfiguration.ValidNumberOfDaysForReturnItem }));
                    }
                }
                return(Ok(new { isResult = false }));
            }
            return(Ok(new { isResult = "NotExists" }));
        }
        /// <summary>
        /// This method used for get ReturnBillDetailAC. -An
        /// </summary>
        /// <param name="posBill"></param>
        /// <returns></returns>
        private ReturnBillDetailAc GetReturnBillDetailAC(POSBill posBill)
        {
            try
            {
                ReturnBillDetailAc  returnBillDetailAC = new ReturnBillDetailAc();
                List <ReturnBillAC> listOfReturnBillAC = new List <ReturnBillAC>();
                ReturnBillAC        retunBillAC        = new ReturnBillAC();
                retunBillAC.Amount       = posBill.TotalAmount;
                retunBillAC.BillDate     = posBill.BillDate;
                retunBillAC.BillId       = posBill.Id;
                retunBillAC.BillNumber   = posBill.BillNo;
                retunBillAC.Branch       = posBill.BranchDetail.Name;
                retunBillAC.CashierName  = posBill.UserDetail.UserName;
                retunBillAC.CustomerName = posBill.Customer.Name;
                listOfReturnBillAC.Add(retunBillAC);
                returnBillDetailAC.ReturnBillList = listOfReturnBillAC;
                List <POSBillItem> listOfPOSBillItem = _iReturnBillRepository.GetPOSBillItemListByBillId(posBill.Id);
                if (listOfPOSBillItem.Any())
                {
                    List <RetunrBillItemListAC> listOfRetunrBillItemListAC = new List <RetunrBillItemListAC>();
                    foreach (var posBillItem in listOfPOSBillItem)
                    {
                        RetunrBillItemListAC retunrBillItemListAC = new RetunrBillItemListAC();
                        retunrBillItemListAC.BarCode        = posBillItem.ItemProfile.Barcode;
                        retunrBillItemListAC.POSBillItemId  = posBillItem.Id;
                        retunrBillItemListAC.BillQunatity   = posBillItem.Quantity;
                        retunrBillItemListAC.Flavour        = posBillItem.ItemProfile.FlavourEn;
                        retunrBillItemListAC.Name           = posBillItem.ItemProfile.ItemNameEn;
                        retunrBillItemListAC.ReturnBillItem = posBillItem.ReturnedQuantity;
                        retunrBillItemListAC.SellPrice      = posBillItem.SellPrice;
                        retunrBillItemListAC.Unit           = posBillItem.ItemProfile.SystemParameter.ValueEn;
                        retunrBillItemListAC.ReturnQunatity = 0;

                        //this is used for check totale return qunatity
                        List <POSReturnBillItem> listOfPOSReturnBillItem = _iReturnBillRepository.GetListOfPOSRetunBillItemByPOSBillItemId(posBillItem.Id);
                        if (listOfPOSReturnBillItem.Count > 0)
                        {
                            int totalQunatity = 0;
                            foreach (var posRetunrBillItem in listOfPOSReturnBillItem)
                            {
                                totalQunatity = totalQunatity + posRetunrBillItem.ReturnedQuantity;
                            }
                            retunrBillItemListAC.ReturnedQunatity = totalQunatity;
                        }
                        listOfRetunrBillItemListAC.Add(retunrBillItemListAC);
                    }
                    returnBillDetailAC.ReturnBillItemList = listOfRetunrBillItemListAC;
                }
                List <POSBillPayment> listOfPOSBillPayment = _iReturnBillRepository.GetPOSBillPaymentListByBillId(posBill.Id);
                if (listOfPOSBillPayment.Any())
                {
                    List <ReturnBillPaymentTypeListAC> listOfReturnBillPaymentTypeListAC = new List <ReturnBillPaymentTypeListAC>();
                    foreach (var posBillPayment in listOfPOSBillPayment)
                    {
                        ReturnBillPaymentTypeListAC posBillPaymentAC = new ReturnBillPaymentTypeListAC();
                        posBillPaymentAC.BankTransactionNumber = posBillPayment.BankPOSTransNo;
                        posBillPaymentAC.PaymentType           = posBillPayment.ParamType.ValueEn;
                        posBillPaymentAC.PaymentId             = posBillPayment.Id;
                        if (posBillPaymentAC.PaymentType == "Cash")//when payment type is cash so check how much amount retunr by cashier to customer.
                        {
                            decimal amt = _iReturnBillRepository.GetCustomerPayTotalAmount(posBill.Id);
                            if (amt != posBill.TotalAmount)
                            {
                                posBillPaymentAC.Amount = posBillPayment.Amount - (amt - posBill.TotalAmount);
                            }
                            else
                            {
                                posBillPaymentAC.Amount = posBillPayment.Amount;
                            }
                        }
                        else
                        {
                            posBillPaymentAC.Amount = posBillPayment.Amount;
                        }
                        listOfReturnBillPaymentTypeListAC.Add(posBillPaymentAC);
                    }
                    returnBillDetailAC.ReturnBillPaymentTypeList = listOfReturnBillPaymentTypeListAC;
                }

                return(returnBillDetailAC);
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
Example #9
0
        /// <summary>
        /// This method is used for Insert PosBill related data at the time of Payment.
        /// </summary>
        private void InsertPOSBillData()
        {
            try
            {
                var accountingEntries = new List <DomainModel.Models.Accounting.DoubleEntry>();
                printParameters = new PrintParameters();
                //Get the total bill count of current date.
                string billNumber        = ""; //SettingHelpers.CompanyConfigruationObject.InvoiceNo + DateTime.UtcNow.ToString("dd/mm/yyyy") + "0001";
                var    billCountResponse = _posRepository.GetTotalBillDataByBillDate();
                if (billCountResponse < 9)
                {
                    billNumber = SettingHelpers.CompanyConfigruationObject.InvoiceNo + DateTime.UtcNow.ToString("dd/MM/yy") + "000" + (billCountResponse + 1);
                }
                else if (billCountResponse < 99)
                {
                    billNumber = SettingHelpers.CompanyConfigruationObject.InvoiceNo + DateTime.UtcNow.ToString("dd/MM/yy") + "00" + (billCountResponse + 1);
                }
                else if (billCountResponse < 999)
                {
                    billNumber = SettingHelpers.CompanyConfigruationObject.InvoiceNo + DateTime.UtcNow.ToString("dd/MM/yy") + "0" + (billCountResponse + 1);
                }
                else if (billCountResponse < 9999)
                {
                    billNumber = SettingHelpers.CompanyConfigruationObject.InvoiceNo + DateTime.UtcNow.ToString("dd/MM/yy") + (billCountResponse + 1);
                }
                else
                {
                    billNumber = SettingHelpers.CompanyConfigruationObject.InvoiceNo + DateTime.UtcNow.ToString("dd/MM/yy") + (billCountResponse + 1);
                }
                POSBill posBill = new POSBill();
                posBill.POSSessionID = SettingHelpers.CurrentPosSessionId;
                posBill.UserID       = SettingHelpers.CurrentUserId;
                posBill.BranchID     = SettingHelpers.CurrentBranchId;
                if (customerInfo == null || customerInfo.Customer.Id == 0 || customerInfo.Customer.Id == 1)
                {
                    printParameters.IsCustomer = false;
                    posBill.CustomerID         = 1;
                }
                else
                {
                    posBill.CustomerID         = customerInfo.Customer.Id;
                    printParameters.IsCustomer = true;
                }
                posBill.BillDate        = DateTime.UtcNow;
                posBill.TotalAmount     = TotalAmount;
                posBill.BillNo          = billNumber.Replace("/", "").Replace("-", "");
                posBill.CreatedDateTime = DateTime.UtcNow.Date;

                var billDetail = _posRepository.InsertPosBillData(posBill);
                if (billDetail != null)
                {
                    accountingEntries.Add(new DoubleEntry
                    {
                        Description     = "POS Sale Entry Bill No:" + posBill.BillNo,
                        LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.Sales).Id,
                        ActivityName    = StringConstants.PosSale,
                        Debit           = 0,
                        Credit          = TotalAmount + discount,
                        CreatedDateTime = DateTime.UtcNow,
                        TransactionDate = DateTime.UtcNow
                    });
                    _posRepository.InsertPosBillItemsData(_itemProfileCollection.ToList(), billDetail.Id);
                    if (!String.IsNullOrEmpty(CashAmount))
                    {
                        accountingEntries.Add(new DoubleEntry
                        {
                            Description     = "POS Sale by cash Entry Bill No:" + posBill.BillNo,
                            LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.CashInHand).Id,
                            ActivityName    = StringConstants.PosSale,
                            Debit           = Convert.ToDecimal(CashAmount),
                            Credit          = 0,
                            CreatedDateTime = DateTime.UtcNow,
                            TransactionDate = DateTime.UtcNow
                        });
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.Cash, string.Empty, Convert.ToDecimal(CashAmount));
                    }
                    if (!String.IsNullOrEmpty(DebitCardAmount))
                    {
                        accountingEntries.Add(new DoubleEntry
                        {
                            Description     = "POS Sale by Debit Card Entry Bill No:" + posBill.BillNo,
                            LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.Bank).Id,
                            ActivityName    = StringConstants.PosSale,
                            Debit           = Convert.ToDecimal(DebitCardAmount),
                            Credit          = 0,
                            CreatedDateTime = DateTime.UtcNow,
                            TransactionDate = DateTime.UtcNow
                        });
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.DebitCard, DebitCardReceiptNo, Convert.ToDecimal(DebitCardAmount));
                    }
                    if (!String.IsNullOrEmpty(CreditCardAmount))
                    {
                        accountingEntries.Add(new DoubleEntry
                        {
                            Description     = "POS Sale by Credit Card Entry Bill No:" + posBill.BillNo,
                            LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.Bank).Id,
                            ActivityName    = StringConstants.PosSale,
                            Debit           = Convert.ToDecimal(CreditCardAmount),
                            Credit          = 0,
                            CreatedDateTime = DateTime.UtcNow,
                            TransactionDate = DateTime.UtcNow
                        });
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.CreditCard, CreditCardReceiptNumber, Convert.ToDecimal(CreditCardAmount));
                    }
                    if (!String.IsNullOrEmpty(CouponAmount))
                    {
                        accountingEntries.Add(new DoubleEntry
                        {
                            Description     = "POS Sale by Coupan Entry Bill No:" + posBill.BillNo,
                            LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.Expenses).Id,
                            ActivityName    = StringConstants.PosSale,
                            Debit           = Convert.ToDecimal(CouponAmount),
                            Credit          = 0,
                            CreatedDateTime = DateTime.UtcNow,
                            TransactionDate = DateTime.UtcNow
                        });
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.Coupon, CouponNo, Convert.ToDecimal(CouponAmount));
                    }
                    if (!String.IsNullOrEmpty(chequeAmount))
                    {
                        accountingEntries.Add(new DoubleEntry
                        {
                            Description     = "POS Sale by Cheque Entry Bill No:" + posBill.BillNo,
                            LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.Bank).Id,
                            ActivityName    = StringConstants.PosSale,
                            Debit           = Convert.ToDecimal(chequeAmount),
                            Credit          = 0,
                            CreatedDateTime = DateTime.UtcNow,
                            TransactionDate = DateTime.UtcNow
                        });
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.Cheque, ChequeNo, Convert.ToDecimal(chequeAmount));
                    }
                    if (!String.IsNullOrEmpty(CreditAccountAmount))
                    {
                        //TODO: Customer Ledger
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.CreditAccount, string.Empty, Convert.ToDecimal(CreditAccountAmount));
                    }
                    if (!String.IsNullOrEmpty(DownPaymentAmount))
                    {
                        InsertPosBillPaymentData(billDetail.Id, POSBillPaymentType.DownPayment, string.Empty, Convert.ToDecimal(DownPaymentAmount));
                    }

                    //If Bill process for Customer PO then update Customer PO is collected in CustomerPruchaseOrder table.
                    if (SettingHelpers.IsCustomerPO)
                    {
                        //update CPO bill
                        var cpoObj = new CustomerPurchaseOrder
                        {
                            PurchaseOrderNo = customerInfo.CPO.PurchaseOrderNo,
                            IsCollected     = true
                        };
                        var httpClient         = new HttpClients();
                        var jsonCPO            = JsonConvert.SerializeObject(cpoObj);
                        var httpContentCpo     = new StringContent(jsonCPO, Encoding.UTF8, "application/json");
                        var responseCustomerPO = httpClient.PostAsync("api/customerpo/updatecustomerpurchseorderforpos", httpContentCpo);
                        if (responseCustomerPO.IsSuccessStatusCode)
                        {
                            var resultCpo = responseCustomerPO.Content.ReadAsAsync <int>().Result;
                            //add CPO Bill mapping
                            var cpoBill = new CPOBill();
                            cpoBill.CPOId     = resultCpo;
                            cpoBill.POSBillId = billDetail.Id;

                            jsonCPO        = JsonConvert.SerializeObject(cpoBill);
                            httpContentCpo = new StringContent(jsonCPO, Encoding.UTF8, "application/json");

                            var responseCpoBill = httpClient.PostAsync("api/customerpo/addcpobillforpos", httpContentCpo);
                            if (responseCpoBill.IsSuccessStatusCode)
                            {
                                resultCpo = responseCpoBill.Content.ReadAsAsync <int>().Result;
                            }
                        }
                        printParameters.IsCpo          = true;
                        printParameters.DownPayment    = DownPaymentAmount;
                        printParameters.AdditionalCost = AdditionalCost;
                        printParameters.CpoNumber      = cpoObj.PurchaseOrderNo;
                    }
                    // if bill process for Return Bill then updat the ReturnBill table for process successfully.
                    if (customerInfo.ReturnBill != null)
                    {
                        UpdateReuturnBill();
                        printParameters.IsReturnBill = true;
                        printParameters.ReturnBillNo = customerInfo.ReturnBill.ReturnedBillNo;
                        printParameters.Substitute   = customerInfo.ReturnBill.SubstituteItemsAmount;
                        printParameters.ReturnAmount = customerInfo.ReturnBill.ReturnedCash;

                        if (RemainingAmount != 0)
                        {
                            accountingEntries.Add(new DoubleEntry
                            {
                                Description     = "POS Sale cash return Bill No:" + customerInfo.ReturnBill.ReturnedBillNo,
                                LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.CashInHand).Id,
                                ActivityName    = StringConstants.PosSale,
                                Debit           = 0,
                                Credit          = RemainingAmount,
                                CreatedDateTime = DateTime.UtcNow,
                                TransactionDate = DateTime.UtcNow
                            });
                        }
                    }
                }
                if (discount > 0)
                {
                    accountingEntries.Add(new DoubleEntry
                    {
                        Description     = "POS Sale Discount Bill No:" + printParameters.InvoiceNo,
                        LedgerId        = SettingHelpers.Ledgers.First(x => x.Name == StringConstants.Expenses).Id,
                        ActivityName    = StringConstants.PosSale,
                        Debit           = discount,
                        Credit          = 0,
                        CreatedDateTime = DateTime.UtcNow,
                        TransactionDate = DateTime.UtcNow
                    });
                }

                #region "Set Print Parameters"
                printParameters.Tax           = 0;
                printParameters.Cash          = PaidAmount.Value;
                printParameters.CashReturn    = RemainingAmount;
                printParameters.Customer      = customerInfo.Customer;
                printParameters.Items         = _itemProfileCollection.ToList();
                printParameters.TotalQuantity = _itemProfileCollection.Sum(x => x.ItemQuantity);
                printParameters.TotalAmount   = posBill.TotalAmount + printParameters.Substitute;
                printParameters.Discount      = discount;
                printParameters.InvoiceNo     = posBill.BillNo;
                printParameters.SDateTime     = DateTime.UtcNow.ToString("dd-MM-yy hh:mm:ss");
                #endregion

                _posRepository.AddAccountingEntries(accountingEntries);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public POSBill InsertPosBillData(POSBill posBill)
 {
     _posBill.Add(posBill);
     _posBill.SaveChanges();
     return(posBill);
 }