Esempio n. 1
0
        public string RePrintManaulInvoice(eStoreDbContext db, RegularInvoice invoice, int StoreId = 1)
        {
            ReceiptHeader             header         = PrinterHelper.GetReceiptHeader(db, StoreId);
            ReceiptDetails            details        = PrinterHelper.GetReceiptDetails(invoice.InvoiceNo, invoice.OnDate, DateTime.Now.ToShortTimeString(), invoice.Customer.FullName);
            ReceiptItemTotal          itemtotal      = PrinterHelper.GetReceiptItemTotal(invoice);
            List <ReceiptItemDetails> itemDetailList = PrinterHelper.GetInvoiceDetails(db, invoice.SaleItems.ToList());

            return(InvoicePrinter.PrintManaulInvoice(header, itemtotal, details, itemDetailList, true));
        }
Esempio n. 2
0
        public InvoiceSaveReturn OnInsert(eStoreDbContext db, SaveOrderDTO sales, string userName, int StoreId = 1)
        {
            Customer cust = db.Customers.Where(c => c.MobileNo == sales.MobileNo).FirstOrDefault();

            if (cust == null)
            {
                string[] names = sales.Name.Split(" ");
                string   FName = names[0];
                string   LName = "";
                for (int i = 1; i < names.Length; i++)
                {
                    LName += names[i] + " ";
                }

                cust = new Customer
                {
                    City        = sales.Address,
                    Age         = 30,
                    FirstName   = FName,
                    Gender      = Gender.Male,
                    LastName    = LName,
                    MobileNo    = sales.MobileNo,
                    NoOfBills   = 0,
                    TotalAmount = 0,
                    CreatedDate = DateTime.Now.Date
                };
                db.Customers.Add(cust);
            }
            string InvNo = GenerateInvoiceNo(db, StoreId, true);
            List <RegularSaleItem> itemList  = new List <RegularSaleItem>();
            List <Stock>           stockList = new List <Stock>();

            foreach (var item in sales.SaleItems)
            {
                RegularSaleItem sItem = new RegularSaleItem
                {
                    BarCode       = item.BarCode,
                    MRP           = item.Price,
                    Qty           = item.Quantity,
                    Discount      = 0,
                    SalesmanId    = item.Salesman,
                    Units         = item.Units,
                    InvoiceNo     = InvNo,
                    BasicAmount   = item.Amount,
                    TaxAmount     = 0,
                    ProductItemId = -1,
                    BillAmount    = 0,
                    SaleTaxTypeId = 1, //TODO: default tax id needed
                };
                ProductItem pItem = db.ProductItems.Where(c => c.Barcode == item.BarCode).FirstOrDefault();
                Stock       stock = db.Stocks.Where(c => c.ProductItemId == pItem.ProductItemId && c.StoreId == StoreId).FirstOrDefault();

                sItem.ProductItemId = pItem.ProductItemId;
                decimal amt = (decimal)item.Quantity * item.Price;
                sItem.BasicAmount = (amt * 100) / (100 + pItem.TaxRate);
                sItem.TaxAmount   = (sItem.BasicAmount * pItem.TaxRate) / 100;
                sItem.BillAmount  = sItem.BasicAmount + sItem.TaxAmount;
                //SaleTax Id
                var taxid = db.SaleTaxTypes.Where(c => c.CompositeRate == pItem.TaxRate).Select(c => c.SaleTaxTypeId).FirstOrDefault();
                if (taxid <= 0)
                {
                    taxid = 1; //TODO: Handle it for creating new saletax id
                }
                sItem.SaleTaxTypeId = taxid;

                itemList.Add(sItem);


                stock.SaleQty  += item.Quantity;
                stock.Quantity -= item.Quantity;
                stockList.Add(stock);
            }
            var           totalBillamt  = itemList.Sum(c => c.BillAmount);
            var           totaltaxamt   = itemList.Sum(c => c.TaxAmount);
            var           totalDiscount = itemList.Sum(c => c.Discount);
            var           totalQty      = itemList.Sum(c => c.Qty);
            var           totalitem     = itemList.Count;
            decimal       roundoffamt   = Math.Round(totalBillamt) - totalBillamt;
            PaymentDetail pd            = new PaymentDetail
            {
                CardAmount   = sales.PaymentInfo.CardAmount,
                CashAmount   = sales.PaymentInfo.CashAmount,
                InvoiceNo    = InvNo,
                IsManualBill = true,
                MixAmount    = 0,
                PayMode      = SalePayMode.Cash
            };

            if (sales.PaymentInfo.CardAmount > 0)
            {
                if (sales.PaymentInfo.CashAmount > 0)
                {
                    pd.PayMode = SalePayMode.Mix;
                }
                else
                {
                    pd.PayMode = SalePayMode.Card;
                }

                CardDetail cd = new CardDetail
                {
                    CardCode  = CardType.Visa,//TODO: default
                    Amount    = sales.PaymentInfo.CardAmount,
                    AuthCode  = (int)Int64.Parse(sales.PaymentInfo.AuthCode),
                    InvoiceNo = InvNo,
                    LastDigit = (int)Int64.Parse(sales.PaymentInfo.CardNo),
                    CardType  = CardMode.DebitCard//TODO: default
                };

                if (sales.PaymentInfo.CardType.Contains("Debit") || sales.PaymentInfo.CardType.Contains("debit") || sales.PaymentInfo.CardType.Contains("DEBIT"))
                {
                    cd.CardType = CardMode.DebitCard;
                }
                else if (sales.PaymentInfo.CardType.Contains("Credit") || sales.PaymentInfo.CardType.Contains("credit") || sales.PaymentInfo.CardType.Contains("CREDIT"))
                {
                    cd.CardType = CardMode.CreditCard;
                }

                if (sales.PaymentInfo.CardType.Contains("visa") || sales.PaymentInfo.CardType.Contains("Visa") || sales.PaymentInfo.CardType.Contains("VISA"))
                {
                    cd.CardCode = CardType.Visa;
                }
                else if (sales.PaymentInfo.CardType.Contains("MasterCard") || sales.PaymentInfo.CardType.Contains("mastercard") || sales.PaymentInfo.CardType.Contains("MASTERCARD"))
                {
                    cd.CardCode = CardType.MasterCard;
                }
                else if (sales.PaymentInfo.CardType.Contains("Rupay") || sales.PaymentInfo.CardType.Contains("rupay") || sales.PaymentInfo.CardType.Contains("RUPAY"))
                {
                    cd.CardCode = CardType.Rupay;
                }
                else if (sales.PaymentInfo.CardType.Contains("MASTRO") || sales.PaymentInfo.CardType.Contains("mastro") || sales.PaymentInfo.CardType.Contains("Mastro"))
                {
                    cd.CardCode = CardType.Rupay;
                }

                pd.CardDetail = cd;
            }
            RegularInvoice Invoice = new RegularInvoice
            {
                Customer            = cust,
                InvoiceNo           = InvNo,
                OnDate              = sales.OnDate,
                IsManualBill        = true,
                StoreId             = StoreId,
                SaleItems           = itemList,
                CustomerId          = cust.CustomerId,
                TotalBillAmount     = totalBillamt + roundoffamt,
                TotalDiscountAmount = totalDiscount,
                TotalItems          = totalitem,
                TotalQty            = totalQty,
                TotalTaxAmount      = totaltaxamt,
                RoundOffAmount      = roundoffamt,
                PaymentDetail       = pd,
                UserId              = userName
            };

            db.RegularInvoices.Add(Invoice);
            db.Stocks.UpdateRange(stockList);
            InvoiceSaveReturn returnData = new InvoiceSaveReturn
            {
                NoOfRecord = db.SaveChanges(),
                FileName   = "NotSaved"
            };

            if (returnData.NoOfRecord > 0)
            {
                ReceiptHeader             header         = PrinterHelper.GetReceiptHeader(db, StoreId);
                ReceiptDetails            details        = PrinterHelper.GetReceiptDetails(Invoice.InvoiceNo, Invoice.OnDate, DateTime.Now.ToShortTimeString(), sales.Name);
                ReceiptItemTotal          itemtotal      = PrinterHelper.GetReceiptItemTotal(Invoice);
                List <ReceiptItemDetails> itemDetailList = PrinterHelper.GetInvoiceDetails(db, itemList);
                returnData.FileName = "/" + InvoicePrinter.PrintManaulInvoice(header, itemtotal, details, itemDetailList, false);
            }
            return(returnData);
        }