예제 #1
0
        void ProcessReceipt(IUnitOfWork unitOfWork, Dictionary <int, LineOfWork> activeLinesOfWork,
                            DateTime workDate, int shiftId, List <Report103Line> receiptLines, List <int> result)
        {
            Report103Line firstLine   = receiptLines[0];
            DateTime      receiptDate = firstLine.DateAndTime; //date appears in the line before last

            if (firstLine.FunctionText.Contains("*** FACTURA ***"))
            {
                Sale newSale = new Sale();

                //FACTURA #
                newSale.Number = firstLine.Quantity;//first line shows factura #

                //MESA #
                int        tableNumber = receiptLines[1].Quantity;
                LineOfWork low         = activeLinesOfWork[tableNumber];

                //work date
                newSale.Date = workDate;
                //get date created from LineOfWork
                newSale.DateCreated = low.StartDate;
                //print ticket to client date
                newSale.DatePrinted = low.PrintTicketDate;
                //FACTURA DATE
                newSale.DateClosed = receiptDate;

                //TURNO
                newSale.ShiftId = shiftId;

                //CLIENTE #
                //sometimes this line doesn't appear
                if (receiptLines[2].FunctionText.Contains("CLIENTE #"))
                {
                    newSale.Persons = receiptLines[2].Quantity;
                }

                //LINEITEMS
                for (int i = 3; i < receiptLines.Count; i++)
                {
                    Report103Line line = receiptLines[i];

                    //los lineitems tienen 10000 ahí, no preguntes pq
                    if (line.FunctionType == 10000)
                    {
                        //check for new product
                        int     plu  = line.FunctionNumber;
                        Product prod = unitOfWork.ProductRepository.GetFromPLU(plu);

                        if (prod == null)
                        {
                            prod             = new Product();
                            prod.Code        = plu;
                            prod.Name        = line.FunctionText.Trim('"');
                            prod.SalePrice   = line.Amount / line.Quantity;
                            prod.ProductType = ProductType.FinishedGoods;//default

                            unitOfWork.ProductRepository.Add(prod);
                            //prod = new MainWindowViewModel().CreateProduct(plu, line.FunctionText.Trim('"'), line.Amount / line.Quantity);
                        }

                        SaleLineItem sli = new SaleLineItem();

                        sli.Quantity    = line.Quantity;
                        sli.UnitMeasure = unitOfWork.UMRepository.GetById(1);// appvm.UnitMeasureManager.Unit;
                        sli.Amount      = line.Amount;

                        //get product from PLU or create a new one

                        sli.Product = prod;

                        var invSVC = ServiceContainer.GetService <IInventoryService>();
                        //update total cost
                        newSale.TotalCost += sli.Cost = invSVC.GetProductCost(prod, sli.Quantity, sli.UnitMeasure);

                        newSale.LineItems.Add(sli);
                        newSale.SaleLineItems.Add(sli);
                    }
                    //DESCONTADO %
                    else if (line.FunctionType == 1000)
                    {
                        System.Diagnostics.Debug.Assert(line.FunctionText.Contains("DESCONTADO %"));

                        newSale.Discount = line.Amount;
                    }
                    //TOTAL
                    else if (line.FunctionNumber == 99)
                    {
                        System.Diagnostics.Debug.Assert(line.FunctionText.Contains("TOTAL"));

                        newSale.Total    = line.Amount;
                        newSale.SubTotal = newSale.Total + newSale.Discount;
                    }
                }

                //DESCONTADO %
                //Report103Line discount_line = receiptLines[receiptLines.Count - 6];
                //if (discount_line.FunctionText.Contains("DESCONTADO %"))
                //{
                //    newSale.Discount = discount_line.Amount;
                //}

                //TOTAL
                //Report103Line total_line = receiptLines[receiptLines.Count - 5];
                //if (total_line.FunctionText.Contains("TOTAL"))
                //{
                //    newSale.Total = total_line.Amount;
                //    newSale.SubTotal = newSale.Total + newSale.Discount;
                //}

                //VOIDS
                newSale.Voids             = low.VoidCount;
                newSale.VoidsAfterReceipt = low.CriticalVoidCount;

                //save changes
                //appvm.SaveChanges();
                unitOfWork.OrderRepository.Add(newSale);
                unitOfWork.SaveChanges();

                result.Add(newSale.Id);

                //remove line of work from active list
                activeLinesOfWork.Remove(low.TableNumber);
            }
            else if (firstLine.FunctionText.Contains("** RECIBO **"))
            {
                int tableNumber = receiptLines[1].Quantity;

                //Transfer Table
                if (receiptLines[2].FunctionText.Contains("Transfer Table"))
                {
                    int tableSource = receiptLines[1].Quantity;
                    int tableTarget = receiptLines[3].Quantity;

                    //GetTablesInTransfer(receiptLines, out tableSource, out tableTarget);

                    if (tableSource != tableTarget)
                    {
                        //change table number in line of work for future operations
                        LineOfWork low = activeLinesOfWork[tableSource];
                        low.TableNumber = tableTarget;

                        activeLinesOfWork.Remove(tableSource);

                        activeLinesOfWork[tableTarget] = low;
                    }
                }
                //Split Table
                else if (receiptLines[2].FunctionText.Contains("Split Table"))
                {
                    //3rd line bottom up show destination table
                    int tableDestination = receiptLines[receiptLines.Count - 3].Quantity;

                    //create a new LoW if it didn't exist
                    if (!activeLinesOfWork.ContainsKey(tableDestination))
                    {
                        LineOfWork temp = CreateLineOfWork(activeLinesOfWork, receiptDate, tableDestination);
                    }
                }
                //VOID
                else if (receiptLines[2].FunctionText.Contains("VOID"))
                {
                    //add a void operation to the line of work
                    LineOfWork low = activeLinesOfWork[tableNumber];

                    low.VoidCount++;
                    if (low.TicketPrinted)
                    {
                        low.CriticalVoidCount++;
                    }
                }
                //Print Ticket
                else if (receiptLines[receiptLines.Count - 1].FunctionText.Contains("TOTAL"))
                {
                    LineOfWork low = activeLinesOfWork[tableNumber];

                    if (!low.TicketPrinted)
                    {
                        //set the print date
                        low.PrintTicketDate = receiptDate;
                        low.TicketPrinted   = true;
                    }
                }
                else if (!activeLinesOfWork.ContainsKey(tableNumber))
                {
                    LineOfWork temp = CreateLineOfWork(activeLinesOfWork, receiptDate, tableNumber);
                }
            }
            //ABRIR CAJON
            else
            {
            }
        }
예제 #2
0
        bool TryParseReport103Line(string line, out Report103Line result)
        {
            result = new Report103Line();

            string[] pieces = line.Split(';');

            //each line has 16 values
            if (pieces.Length != 16)
            {
                return(false);
            }

            int eJournalId;

            if (!int.TryParse(pieces[0], out eJournalId))
            {
                return(false);
            }
            result.EJournalId = eJournalId;

            DateTime dateAndTime;

            if (!TryParseDateAndTime(pieces[3], pieces[4], out dateAndTime))
            {
                return(false);
            }
            result.DateAndTime = dateAndTime;

            int receiptNumber;

            if (!int.TryParse(pieces[5], out receiptNumber))
            {
                return(false);
            }
            result.ReceiptNumber = receiptNumber;

            int salesPerson;

            if (!string.IsNullOrWhiteSpace(pieces[6]))
            {
                if (!int.TryParse(pieces[6], out salesPerson))
                {
                    return(false);
                }
                result.SalesPerson = salesPerson;
            }

            int clerkNumber;

            if (!int.TryParse(pieces[10], out clerkNumber))
            {
                return(false);
            }
            result.ClerkNumber = clerkNumber;

            int functionType;

            if (!int.TryParse(pieces[11], out functionType))
            {
                return(false);
            }
            result.FunctionType = functionType;

            int functionNumber;

            if (!int.TryParse(pieces[12], out functionNumber))
            {
                return(false);
            }
            result.FunctionNumber = functionNumber;

            string functionText = pieces[13];

            result.FunctionText = functionText;

            int quantity;

            if (!string.IsNullOrWhiteSpace(pieces[14]))
            {
                if (!int.TryParse(pieces[14], out quantity))
                {
                    return(false);
                }
                result.Quantity = quantity;
            }

            decimal amount;

            if (!string.IsNullOrWhiteSpace(pieces[15]))
            {
                if (!decimal.TryParse(pieces[15], NumberStyles.Currency, CultureInfo.InvariantCulture, out amount))
                {
                    return(false);
                }
                //if (!decimal.TryParse(pieces[15], out amount)) return false;
                result.Amount = amount;
            }

            return(true);
        }